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