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/pattern.h" 26 27 namespace OHOS::Ace::NG { 28 class WindowPattern : public Pattern { 29 DECLARE_ACE_TYPE(WindowPattern, Pattern); 30 31 public: 32 WindowPattern() = default; 33 ~WindowPattern() override = default; 34 35 std::vector<Rosen::Rect> GetHotAreas(); 36 sptr<Rosen::Session> GetSession(); 37 38 static int32_t CalculateTranslateDegree(int32_t hostId); 39 40 protected: 41 void OnModifyDone() override; 42 void OnAttachToFrameNode() override; 43 44 void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 45 void DispatchKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 46 void DispatchKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed); 47 void DisPatchFocusActiveEvent(bool isFocusActive); 48 void TransferFocusState(bool focusState); 49 50 virtual bool HasStartingPage() = 0; 51 bool IsMainWindow() const; 52 53 void RegisterLifecycleListener(); 54 void UnregisterLifecycleListener(); 55 56 void CreateStartingNode(); 57 void CreateContentNode(); 58 void CreateSnapshotNode(std::optional<std::shared_ptr<Media::PixelMap>> snapshot = std::nullopt); 59 OnActivation()60 virtual void OnActivation() {} OnConnect()61 virtual void OnConnect() {} OnForeground()62 virtual void OnForeground() {} OnBackground()63 virtual void OnBackground() {} OnDisconnect()64 virtual void OnDisconnect() {} 65 66 RefPtr<FrameNode> startingNode_; 67 RefPtr<FrameNode> contentNode_; 68 RefPtr<FrameNode> snapshotNode_; 69 70 sptr<Rosen::Session> session_; 71 int32_t instanceId_ = Container::CurrentId(); 72 std::function<void()> callback_; 73 std::function<void(const Rosen::Vector4f&)> boundsChangedCallback_; 74 75 private: 76 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 77 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 78 void HandleMouseEvent(const MouseInfo& info); 79 void HandleTouchEvent(const TouchEventInfo& info); 80 bool IsFilterTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 81 bool IsFilterMouseEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 82 void SetWindowSceneConsumed(int32_t action); 83 void FilterInvalidPointerItem(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 84 85 std::shared_ptr<Rosen::ILifecycleListener> lifecycleListener_; 86 RefPtr<TouchEventImpl> touchEvent_; 87 RefPtr<InputEvent> mouseEvent_; 88 89 friend class LifecycleListener; 90 friend class WindowEventProcess; 91 92 ACE_DISALLOW_COPY_AND_MOVE(WindowPattern); 93 }; 94 } // namespace OHOS::Ace::NG 95 96 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_WINDOW_PATTERN_H 97