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