• 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_SYSTEM_WINDOW_SCENE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SYSTEM_WINDOW_SCENE_H
18 
19 #include "common/rs_vector4.h"
20 #include "session/host/include/session.h"
21 
22 #include "core/common/container.h"
23 #include "core/components_ng/manager/focus/focus_view.h"
24 #include "core/components_ng/pattern/overlay/overlay_manager.h"
25 #include "core/components_ng/pattern/stack/stack_pattern.h"
26 
27 namespace OHOS::Ace::NG {
28 class SystemWindowScene : public StackPattern, public FocusView {
29     DECLARE_ACE_TYPE(SystemWindowScene, StackPattern, FocusView);
30 
31 public:
32     explicit SystemWindowScene(const sptr<Rosen::Session>& session);
33     ~SystemWindowScene() override = default;
34 
GetContextParam()35     std::optional<RenderContext::ContextParam> GetContextParam() const override
36     {
37         return RenderContext::ContextParam {
38             .type = RenderContext::ContextType::EXTERNAL,
39             .surfaceName = std::nullopt};
40     }
41 
42     sptr<Rosen::Session> GetSession();
43 
44     void OnVisibleChange(bool visible) override;
45 
GetRouteOfFirstScope()46     std::list<int32_t> GetRouteOfFirstScope() override
47     {
48         return { 0 };
49     }
50 
51     void LostViewFocus() override;
52 
53     void RegisterVisibleChangeCallback(int32_t nodeId, const std::function<void(bool)>& callback);
54     void UnRegisterVisibleChangeCallback(int32_t nodeId);
55     void HandleVisibleChangeCallback(bool visible);
56 
CreateOverlayManager(bool isShow,const RefPtr<FrameNode> & target)57     void CreateOverlayManager(bool isShow, const RefPtr<FrameNode>& target)
58     {
59         if (!overlayManager_ && isShow) {
60             overlayManager_ = MakeRefPtr<OverlayManager>(target);
61             overlayManager_->SetIsAttachToCustomNode(true);
62         }
63     }
64 
GetOverlayManager()65     const RefPtr<OverlayManager>& GetOverlayManager()
66     {
67         return overlayManager_;
68     }
69 
DeleteOverlayManager()70     void DeleteOverlayManager()
71     {
72         overlayManager_.Reset();
73     }
74     uint32_t GetWindowPatternType() const override;
75 
76 protected:
77     void OnAttachToFrameNode() override;
78     void OnDetachFromFrameNode(FrameNode* frameNode) override;
79     std::function<void(const Rosen::Vector4f&)> boundsChangedCallback_;
80     sptr<Rosen::Session> session_;
81 
82 private:
83     void OnAttachToMainTree() override;
84     void OnDetachFromMainTree() override;
85 
86     void OnBoundsChanged(const Rosen::Vector4f& bounds);
87     void RegisterFocusCallback();
88     void RegisterEventCallback();
89     void RegisterResponseRegionCallback();
90     void PostCheckContextTransparentTask();
91     void PostFaultInjectTask();
92     void SetWindowScenePosition();
93     void InsertSurfaceNodeId(uint64_t nodeId);
94     void ClearSurfaceNodeId(uint64_t nodeId);
95 
96     int32_t instanceId_ = Container::CurrentId();
97 
98     CancelableCallback<void()> checkContextTransparentTask_;
99     RefPtr<OverlayManager> overlayManager_;
100     std::map<int32_t, std::function<void(bool)>> visibleChangeCallbackMap_;
101 
102     ACE_DISALLOW_COPY_AND_MOVE(SystemWindowScene);
103 };
104 } // namespace OHOS::Ace::NG
105 
106 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SYSTEM_WINDOW_SCENE_H
107