• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_PATTERN_H
18 
19 #include "common/rs_vector4.h"
20 #include "key_event.h"
21 #include "pointer_event.h"
22 #include "session/host/include/session.h"
23 
24 #include "core/common/container.h"
25 #include "core/components_ng/pattern/stack/stack_pattern.h"
26 #include "core/image/image_source_info.h"
27 
28 namespace OHOS::Ace::NG {
29 class WindowPattern : public StackPattern {
30     DECLARE_ACE_TYPE(WindowPattern, StackPattern);
31 
32 public:
33     WindowPattern() = default;
34     ~WindowPattern() override = default;
35 
36     std::vector<Rosen::Rect> GetHotAreas();
37     sptr<Rosen::Session> GetSession();
38 
39 protected:
40     void OnAttachToFrameNode() override;
41 
42     void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
43     void DispatchKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
44     void DispatchKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed);
45     void DisPatchFocusActiveEvent(bool isFocusActive);
46     void TransferFocusState(bool focusState);
47 
48     virtual bool HasStartingPage() = 0;
49     bool IsMainWindow() const;
50 
51     void RegisterLifecycleListener();
52     void UnregisterLifecycleListener();
53 
54 #ifdef ATOMIC_SERVICE_ATTRIBUTION_ENABLE
55     RefPtr<FrameNode> BuildTextNode(const std::string& appNameInfo);
56     RefPtr<FrameNode> BuildAnimateNode(const std::string& base64Resource);
57     RefPtr<FrameNode> BuildStaticImageNode(const std::string& base64Resource);
58     void CreateASStartingWindow();
59 #endif
60 
61     void CreateAppWindow();
62     void CreateBlankWindow(RefPtr<FrameNode>& window);
63     void CreateStartingWindow();
64     void CreateSnapshotWindow(std::optional<std::shared_ptr<Media::PixelMap>> snapshot = std::nullopt);
65     void ClearImageCache(const ImageSourceInfo& sourceInfo);
66 
67     void AddChild(const RefPtr<FrameNode>& host, const RefPtr<FrameNode>& child,
68         const std::string& nodeType, int32_t index = DEFAULT_NODE_SLOT);
69     void RemoveChild(const RefPtr<FrameNode>& host, const RefPtr<FrameNode>& child,
70         const std::string& nodeType, bool allowTransition = false);
71 
OnActivation()72     virtual void OnActivation() {}
OnConnect()73     virtual void OnConnect() {}
OnForeground()74     virtual void OnForeground() {}
OnBackground()75     virtual void OnBackground() {}
OnDisconnect()76     virtual void OnDisconnect() {}
OnLayoutFinished()77     virtual void OnLayoutFinished() {}
OnDrawingCompleted()78     virtual void OnDrawingCompleted() {}
OnRemoveBlank()79     virtual void OnRemoveBlank() {}
OnAddSnapshot()80     virtual void OnAddSnapshot() {}
OnRemoveSnapshot()81     virtual void OnRemoveSnapshot() {}
OnAppRemoveStartingWindow()82     virtual void OnAppRemoveStartingWindow() {}
83 
84     RefPtr<FrameNode> startingWindow_;
85     RefPtr<FrameNode> appWindow_;
86     RefPtr<FrameNode> snapshotWindow_;
87     RefPtr<FrameNode> blankWindow_;
88     std::string startingWindowName_ = "StartingWindow";
89     std::string appWindowName_ = "AppWindow";
90     std::string snapshotWindowName_ = "SnapshotWindow";
91     std::string blankWindowName_ = "BlankWindow";
92     bool attachToFrameNodeFlag_ = false;
93     bool isBlankForSnapshot_ = false;
94 
95     sptr<Rosen::Session> session_;
96     int32_t instanceId_ = Container::CurrentId();
97     std::function<void()> callback_;
98     std::function<void(const Rosen::Vector4f&)> boundsChangedCallback_;
99 
100 private:
101     void UpdateSnapshotWindowProperty();
102     bool IsSnapshotSizeChanged();
103     void UpdateStartingWindowProperty(const Rosen::SessionInfo& sessionInfo,
104         Color &color, ImageSourceInfo &sourceInfo);
105     bool CheckAndAddStartingWindowAboveLocked();
106 
107     std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_;
108     friend class LifecycleListener;
109     friend class WindowEventProcess;
110 
111     ACE_DISALLOW_COPY_AND_MOVE(WindowPattern);
112 };
113 } // namespace OHOS::Ace::NG
114 
115 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_PATTERN_H
116