1 /* 2 * Copyright (c) 2024 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_UI_EXTENSION_PLATFORM_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_PLATFORM_PATTERN_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <list> 22 #include <memory> 23 #include <optional> 24 #include <refbase.h> 25 #include <vector> 26 27 #include "base/memory/referenced.h" 28 #include "base/want/want_wrap.h" 29 #include "core/common/container.h" 30 #include "core/components_ng/event/gesture_event_hub.h" 31 #include "core/components_ng/pattern/pattern.h" 32 #include "core/event/mouse_event.h" 33 #include "core/event/touch_event.h" 34 35 #define PLATFORM_LOGD(fmt, ...) \ 36 TAG_LOGD(tag_, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, platformId_, \ 37 ##__VA_ARGS__) 38 #define PLATFORM_LOGI(fmt, ...) \ 39 TAG_LOGI(tag_, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, platformId_, \ 40 ##__VA_ARGS__) 41 #define PLATFORM_LOGW(fmt, ...) \ 42 TAG_LOGW(tag_, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, platformId_, \ 43 ##__VA_ARGS__) 44 #define PLATFORM_LOGE(fmt, ...) \ 45 TAG_LOGE(tag_, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, platformId_, \ 46 ##__VA_ARGS__) 47 #define PLATFORM_LOGF(fmt, ...) \ 48 TAG_LOGF(tag_, "[@%{public}d][ID: %{public}d] " fmt, __LINE__, platformId_, \ 49 ##__VA_ARGS__) 50 51 namespace OHOS::MMI { 52 class KeyEvent; 53 class PointerEvent; 54 } // namespace OHOS::MMI 55 56 namespace OHOS::Ace { 57 class ModalUIExtensionProxy; 58 } // namespace OHOS::Ace 59 60 namespace OHOS::Rosen { 61 class AvoidArea; 62 class RSTransaction; 63 } // namespace OHOS::Rosen 64 65 namespace OHOS::Ace::NG { 66 class UIExtensionProxy; 67 class PlatformPattern : public Pattern { 68 DECLARE_ACE_TYPE(PlatformPattern, Pattern); 69 70 public: 71 explicit PlatformPattern(AceLogTag tag, int32_t platformId); 72 ~PlatformPattern() override; 73 74 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override; 75 FocusPattern GetFocusPattern() const override; 76 void OnMountToParentDone() override; 77 void HandleDragEvent(const DragPointerEvent& info) override; 78 79 virtual void SetOnErrorCallback(const std::function<void(int32_t code, 80 const std::string& name, const std::string& message)>&& callback); 81 virtual void FireOnErrorCallback( 82 int32_t code, const std::string& name, const std::string& message); 83 84 int32_t GetInstanceId(); 85 int32_t GetNodeId(); 86 virtual bool HandleTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 87 88 protected: DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)89 virtual void DispatchPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) {} DispatchFocusActiveEvent(bool isFocusActive)90 virtual void DispatchFocusActiveEvent(bool isFocusActive) {} 91 virtual bool HandleKeyEvent(const KeyEvent& event); 92 virtual void HandleFocusEvent(); 93 virtual void HandleBlurEvent(); 94 95 AceLogTag tag_ = AceLogTag::ACE_DEFAULT_DOMAIN; 96 int32_t platformId_ = -1; 97 int32_t instanceId_ = Container::CurrentId(); 98 99 protected: 100 struct ErrorMsg { 101 int32_t code = 0; 102 std::string name; 103 std::string message; 104 }; 105 106 void OnModifyDone() override; 107 108 void InitKeyEvent(const RefPtr<FocusHub>& focusHub); 109 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 110 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 111 void InitHoverEvent(const RefPtr<InputEventHub>& inputHub); 112 virtual void HandleTouchEvent(const TouchEventInfo& info); 113 virtual void HandleMouseEvent(const MouseInfo& info); 114 void HandleHoverEvent(bool isHover); 115 116 RefPtr<TouchEventImpl> touchEvent_; 117 RefPtr<InputEvent> mouseEvent_; 118 RefPtr<InputEvent> hoverEvent_; 119 std::shared_ptr<MMI::PointerEvent> lastPointerEvent_ = nullptr; 120 ErrorMsg lastError_; 121 122 std::function<void(int32_t code, const std::string& name, const std::string& message)> onErrorCallback_; 123 ACE_DISALLOW_COPY_AND_MOVE(PlatformPattern); 124 }; 125 } // namespace OHOS::Ace::NG 126 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_PLATFORM_PATTERN_H 127