1 /* 2 * Copyright (c) 2021 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_MOUSE_LISTENER_MOUSE_LISTENER_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MOUSE_LISTENER_MOUSE_LISTENER_COMPONENT_H 18 19 #include <string> 20 21 #include "core/components/mouse_listener/mouse_listener_element.h" 22 #include "core/components/mouse_listener/render_mouse_listener.h" 23 #include "core/pipeline/base/sole_child_component.h" 24 25 namespace OHOS::Ace { 26 27 using OnHoverCallback = std::function<void(bool, HoverInfo& info)>; 28 29 class ACE_EXPORT MouseListenerComponent final : public SoleChildComponent { 30 DECLARE_ACE_TYPE(MouseListenerComponent, SoleChildComponent); 31 32 public: 33 MouseListenerComponent() = default; MouseListenerComponent(const RefPtr<Component> & child)34 explicit MouseListenerComponent(const RefPtr<Component>& child) : SoleChildComponent(child) {} 35 ~MouseListenerComponent() override = default; 36 CreateElement()37 RefPtr<Element> CreateElement() override 38 { 39 return MakeRefPtr<MouseListenerElement>(); 40 } 41 CreateRenderNode()42 RefPtr<RenderNode> CreateRenderNode() override 43 { 44 return RenderMouseListener::Create(); 45 } 46 SetOnMouseId(const EventMarker & onMouseId)47 void SetOnMouseId(const EventMarker& onMouseId) 48 { 49 onMouseId_ = onMouseId; 50 } 51 GetOnMouseId()52 const EventMarker& GetOnMouseId() const 53 { 54 return onMouseId_; 55 } 56 SetOnMouseHoverId(const EventMarker & onMouseHoverId)57 void SetOnMouseHoverId(const EventMarker& onMouseHoverId) 58 { 59 onMouseHoverId_ = onMouseHoverId; 60 } 61 SetOnHoverId(const OnHoverCallback & onHoverId)62 void SetOnHoverId(const OnHoverCallback& onHoverId) 63 { 64 onHoverId_ = std::make_unique<OnHoverCallback>(onHoverId); 65 } 66 GetOnHoverId()67 OnHoverCallback GetOnHoverId() const 68 { 69 if (!onHoverId_) { 70 return nullptr; 71 } 72 return *onHoverId_; 73 } 74 GetOnMouseHoverId()75 const EventMarker& GetOnMouseHoverId() const 76 { 77 return onMouseHoverId_; 78 } 79 SetOnMouseHoverExitId(const EventMarker & onMouseHoverExitId)80 void SetOnMouseHoverExitId(const EventMarker& onMouseHoverExitId) 81 { 82 onMouseHoverExitId_ = onMouseHoverExitId; 83 } 84 GetOnMouseHoverExitId()85 const EventMarker& GetOnMouseHoverExitId() const 86 { 87 return onMouseHoverExitId_; 88 } 89 90 private: 91 EventMarker onMouseId_; 92 EventMarker onMouseHoverId_; 93 EventMarker onMouseHoverExitId_; 94 std::unique_ptr<OnHoverCallback> onHoverId_; 95 }; 96 97 } // namespace OHOS::Ace 98 99 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MOUSE_LISTENER_MOUSE_LISTENER_COMPONENT_H 100