• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "core/components_ng/event/input_event_hub.h"
17 
18 #include "core/pipeline_ng/pipeline_context.h"
19 
20 namespace OHOS::Ace::NG {
21 
InputEventHub(const WeakPtr<EventHub> & eventHub)22 InputEventHub::InputEventHub(const WeakPtr<EventHub>& eventHub) : eventHub_(eventHub) {}
23 
GetFrameNode() const24 RefPtr<FrameNode> InputEventHub::GetFrameNode() const
25 {
26     auto eventHub = eventHub_.Upgrade();
27     return eventHub ? eventHub->GetFrameNode() : nullptr;
28 }
29 
ProcessMouseTestHit(const OffsetF & coordinateOffset,TouchTestResult & result)30 bool InputEventHub::ProcessMouseTestHit(const OffsetF& coordinateOffset, TouchTestResult& result)
31 {
32     auto eventHub = eventHub_.Upgrade();
33     auto getEventTargetImpl = eventHub ? eventHub->CreateGetEventTargetImpl() : nullptr;
34 
35     if (mouseEventActuator_) {
36         mouseEventActuator_->OnCollectMouseEvent(coordinateOffset, getEventTargetImpl, result);
37     }
38     if (hoverEventActuator_) {
39         hoverEventActuator_->OnCollectHoverEvent(coordinateOffset, getEventTargetImpl, result);
40     }
41     if (hoverEffectActuator_) {
42         hoverEffectActuator_->OnCollectHoverEffect(coordinateOffset, getEventTargetImpl, result);
43     }
44     auto host = GetFrameNode();
45     CHECK_NULL_RETURN(host, false);
46     if (accessibilityHoverEventActuator_) {
47         accessibilityHoverEventActuator_->OnCollectAccessibilityHoverEvent(
48             coordinateOffset, getEventTargetImpl, result, host);
49     }
50     return false;
51 }
52 
ProcessTipsMouseTestHit(const OffsetF & coordinateOffset,TouchTestResult & result)53 bool InputEventHub::ProcessTipsMouseTestHit(const OffsetF& coordinateOffset, TouchTestResult& result)
54 {
55     auto eventHub = eventHub_.Upgrade();
56     auto getEventTargetImpl = eventHub ? eventHub->CreateGetEventTargetImpl() : nullptr;
57     if (hoverEventActuator_) {
58         hoverEventActuator_->OnCollectHoverEventForTips(coordinateOffset, getEventTargetImpl, result);
59     }
60     if (mouseEventActuator_) {
61         mouseEventActuator_->OnCollectMouseEventForTips(coordinateOffset, getEventTargetImpl, result);
62     }
63     return false;
64 }
65 
ProcessPenHoverTestHit(const OffsetF & coordinateOffset,TouchTestResult & result)66 bool InputEventHub::ProcessPenHoverTestHit(const OffsetF& coordinateOffset, TouchTestResult& result)
67 {
68     auto eventHub = eventHub_.Upgrade();
69     auto getEventTargetImpl = eventHub ? eventHub->CreateGetEventTargetImpl() : nullptr;
70     auto host = GetFrameNode();
71     CHECK_NULL_RETURN(host, false);
72     if (hoverEventActuator_) {
73         hoverEventActuator_->OnCollectPenHoverEvent(coordinateOffset, getEventTargetImpl, result, host);
74     }
75 
76     if (hoverMoveEventActuator_) {
77         hoverMoveEventActuator_->OnCollectPenHoverMoveEvent(coordinateOffset, getEventTargetImpl, result, host);
78     }
79 
80     return false;
81 }
82 
ProcessAxisTestHit(const OffsetF & coordinateOffset,AxisTestResult & onAxisResult)83 bool InputEventHub::ProcessAxisTestHit(const OffsetF& coordinateOffset, AxisTestResult& onAxisResult)
84 {
85     auto eventHub = eventHub_.Upgrade();
86     auto getEventTargetImpl = eventHub ? eventHub->CreateGetEventTargetImpl() : nullptr;
87 
88     if (axisEventActuator_) {
89         axisEventActuator_->OnCollectAxisEvent(coordinateOffset, getEventTargetImpl, onAxisResult);
90     }
91     return false;
92 }
93 
94 // register showMenu callback (always replace)
BindContextMenu(OnMouseEventFunc && showMenu)95 void InputEventHub::BindContextMenu(OnMouseEventFunc&& showMenu)
96 {
97     if (showMenu_) {
98         RemoveOnMouseEvent(showMenu_);
99     }
100     showMenu_ = MakeRefPtr<InputEvent>(std::move(showMenu));
101     AddOnMouseEvent(showMenu_);
102 }
103 
GetHoverEffectStr() const104 std::string InputEventHub::GetHoverEffectStr() const
105 {
106     switch (hoverEffectType_) {
107         case HoverEffectType::AUTO:
108             return "HoverEffect.Auto";
109         case HoverEffectType::SCALE:
110             return "HoverEffect.Scale";
111         case HoverEffectType::BOARD:
112             return "HoverEffect.Highlight";
113         case HoverEffectType::NONE:
114             return "HoverEffect.None";
115         default:
116             return "HoverEffect.Auto";
117     }
118 }
119 
SetHoverEffect(HoverEffectType type)120 void InputEventHub::SetHoverEffect(HoverEffectType type)
121 {
122     if (!hoverEffectActuator_) {
123         hoverEffectActuator_ = MakeRefPtr<InputEventActuator>(WeakClaim(this));
124     }
125     auto frameNode = GetFrameNode();
126     if (frameNode && hoverEffectType_ != type) {
127         frameNode->AnimateHoverEffect(false);
128     }
129     hoverEffectType_ = type;
130 }
131 
132 } // namespace OHOS::Ace::NG