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 "base/geometry/ng/size_t.h" 25 #include "core/common/container.h" 26 #include "core/components_ng/pattern/stack/stack_pattern.h" 27 #include "core/image/image_source_info.h" 28 29 #include "core/components_ng/pattern/window_scene/helper/starting_window_layout_helper.h" 30 #include "core/components_ng/pattern/window_scene/scene/window_layout_algorithm.h" 31 32 namespace OHOS::Ace::NG { 33 class WindowPattern : public StackPattern { 34 DECLARE_ACE_TYPE(WindowPattern, StackPattern); 35 36 public: WindowPattern()37 WindowPattern() 38 { 39 startingWindowLayoutHelper_ = AceType::MakeRefPtr<StartingWindowLayoutHelper>(); 40 } ~WindowPattern()41 ~WindowPattern() 42 { 43 startingWindowLayoutHelper_.Reset(); 44 } 45 46 bool BorderUnoccupied() const override; 47 std::vector<Rosen::Rect> GetHotAreas(); 48 sptr<Rosen::Session> GetSession(); 49 void CheckAndMeasureStartingWindow(const SizeF& currentParentSize); 50 CreateLayoutAlgorithm()51 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 52 { 53 return MakeRefPtr<WindowLayoutAlgorithm>(); 54 } 55 56 protected: 57 void OnAttachToFrameNode() override; 58 59 void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 60 void DispatchKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 61 void DispatchKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed); 62 void DisPatchFocusActiveEvent(bool isFocusActive); 63 void TransferFocusState(bool focusState); 64 65 virtual bool HasStartingPage() = 0; 66 bool IsMainWindow() const; 67 68 void RegisterLifecycleListener(); 69 void UnregisterLifecycleListener(); 70 71 #ifdef ATOMIC_SERVICE_ATTRIBUTION_ENABLE 72 RefPtr<FrameNode> BuildTextNode(const std::string& appNameInfo); 73 RefPtr<FrameNode> BuildAnimateNode(const std::string& base64Resource); 74 RefPtr<FrameNode> BuildStaticImageNode(const std::string& base64Resource); 75 void CreateASStartingWindow(); 76 #endif 77 78 void CreateAppWindow(); 79 void CreateBlankWindow(RefPtr<FrameNode>& window); 80 void CreateStartingWindow(); 81 void CreateSnapshotWindow(std::optional<std::shared_ptr<Media::PixelMap>> snapshot = std::nullopt); 82 void ClearImageCache(const ImageSourceInfo& sourceInfo, Rosen::SnapshotStatus key, bool freeMultiWindow); 83 bool AddPersistentImage(const std::shared_ptr<Rosen::RSSurfaceNode>& surfaceNode, 84 const RefPtr<NG::FrameNode>& host); 85 86 void AddChild(const RefPtr<FrameNode>& host, const RefPtr<FrameNode>& child, 87 const std::string& nodeType, int32_t index = DEFAULT_NODE_SLOT); 88 void RemoveChild(const RefPtr<FrameNode>& host, const RefPtr<FrameNode>& child, 89 const std::string& nodeType, bool allowTransition = false); 90 91 ImageRotateOrientation TransformOrientationForMatchSnapshot(uint32_t lastRotation, uint32_t windowRotation); 92 ImageRotateOrientation TransformOrientationForDisMatchSnapshot(uint32_t lastRotation, uint32_t windowRotation, 93 uint32_t snapshotRotation); 94 uint32_t TransformOrientation(uint32_t lastRotation, uint32_t windowRotation, uint32_t count); 95 OnActivation()96 virtual void OnActivation() {} OnConnect()97 virtual void OnConnect() {} OnForeground()98 virtual void OnForeground() {} OnBackground()99 virtual void OnBackground() {} OnDisconnect()100 virtual void OnDisconnect() {} OnLayoutFinished()101 virtual void OnLayoutFinished() {} OnDrawingCompleted()102 virtual void OnDrawingCompleted() {} OnRemoveBlank()103 virtual void OnRemoveBlank() {} OnAddSnapshot()104 virtual void OnAddSnapshot() {} OnRemoveSnapshot()105 virtual void OnRemoveSnapshot() {} OnAppRemoveStartingWindow()106 virtual void OnAppRemoveStartingWindow() {} OnUpdateSnapshotWindow()107 virtual void OnUpdateSnapshotWindow() {} OnPreLoadStartingWindowFinished()108 virtual void OnPreLoadStartingWindowFinished() {} 109 110 RefPtr<FrameNode> startingWindow_; 111 RefPtr<StartingWindowLayoutHelper> startingWindowLayoutHelper_; 112 SizeF lastParentSize_ = { 0.0f, 0.0f }; 113 RefPtr<FrameNode> appWindow_; 114 RefPtr<FrameNode> snapshotWindow_; 115 RefPtr<FrameNode> blankWindow_; 116 RefPtr<FrameNode> newAppWindow_; 117 std::string startingWindowName_ = "StartingWindow"; 118 std::string appWindowName_ = "AppWindow"; 119 std::string snapshotWindowName_ = "SnapshotWindow"; 120 std::string blankWindowName_ = "BlankWindow"; 121 const std::string newAppWindowName_ = "NewAppWindow"; 122 bool attachToFrameNodeFlag_ = false; 123 bool isBlankForSnapshot_ = false; 124 125 sptr<Rosen::Session> session_; 126 int32_t instanceId_ = Container::CurrentId(); 127 std::function<void()> callback_; 128 std::function<void(const Rosen::Vector4f&)> boundsChangedCallback_; 129 130 private: 131 void UpdateSnapshotWindowProperty(); 132 bool IsSnapshotSizeChanged(); 133 void UpdateStartingWindowProperty(const Rosen::SessionInfo& sessionInfo, 134 Color &color, ImageSourceInfo &sourceInfo); 135 bool CheckAndAddStartingWindowAboveLocked(); 136 void HideStartingWindow(); 137 void AddBackgroundColorDelayed(); 138 CancelableCallback<void()> interruptStartingTask_; 139 CancelableCallback<void()> addBackgroundColorTask_; 140 141 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 142 bool needAddBackgroundColor_ = true; 143 friend class LifecycleListener; 144 friend class WindowEventProcess; 145 146 ACE_DISALLOW_COPY_AND_MOVE(WindowPattern); 147 }; 148 } // namespace OHOS::Ace::NG 149 150 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_PATTERN_H 151