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