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