• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "frameworks/bridge/declarative_frontend/engine/functions/js_hover_function.h"
17 
18 #include "frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 #include "frameworks/bridge/declarative_frontend/engine/functions/js_common_utils.h"
20 
21 namespace OHOS::Ace::Framework {
22 using namespace OHOS::Ace::Framework::CommonUtils;
HoverExecute(bool isHover,HoverInfo & hoverInfo)23 void JsHoverFunction::HoverExecute(bool isHover, HoverInfo& hoverInfo)
24 {
25     JSRef<JSVal> isHoverParam = JSRef<JSVal>::Make(ToJSValue(isHover));
26 
27     JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
28     objectTemplate->SetInternalFieldCount(1);
29     JSRef<JSObject> hoverObj = objectTemplate->NewInstance();
30     hoverObj->SetPropertyObject("stopPropagation", JSRef<JSFunc>::New<FunctionCallback>(JsStopPropagation));
31     hoverObj->SetPropertyObject(
32         "getModifierKeyState", JSRef<JSFunc>::New<FunctionCallback>(NG::ArkTSUtils::JsGetModifierKeyState));
33     hoverObj->SetProperty<double>(
34         "timestamp", static_cast<double>(hoverInfo.GetTimeStamp().time_since_epoch().count()));
35     hoverObj->SetProperty<double>("source", static_cast<int32_t>(hoverInfo.GetSourceDevice()));
36     auto target = CreateEventTargetObject(hoverInfo);
37     hoverObj->SetPropertyObject("target", target);
38     hoverObj->SetProperty<double>("sourceTool", static_cast<int32_t>(hoverInfo.GetSourceTool()));
39     hoverObj->SetProperty<double>("axisVertical", 0.0f);
40     hoverObj->SetProperty<double>("axisHorizontal", 0.0f);
41     hoverObj->SetProperty<double>("tiltX", hoverInfo.GetTiltX().value_or(0.0f));
42     hoverObj->SetProperty<double>("tiltY", hoverInfo.GetTiltY().value_or(0.0f));
43     hoverObj->SetProperty<double>("rollAngle", hoverInfo.GetRollAngle().value_or(0.0f));
44     hoverObj->SetProperty<double>("deviceId", hoverInfo.GetDeviceId());
45     hoverObj->SetProperty<int32_t>("targetDisplayId", hoverInfo.GetTargetDisplayId());
46     hoverObj->SetProperty<int32_t>("pressure", 0.0f);
47     const OHOS::Ace::Offset& globalLocation = hoverInfo.GetGlobalLocation();
48     const OHOS::Ace::Offset& localLocation = hoverInfo.GetLocalLocation();
49     const OHOS::Ace::Offset& screenLocation = hoverInfo.GetScreenLocation();
50     const OHOS::Ace::Offset& globalDisplayLocation = hoverInfo.GetGlobalDisplayLocation();
51     hoverObj->SetProperty<double>(
52         "globalDisplayX", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetX()));
53     hoverObj->SetProperty<double>(
54         "globalDisplayY", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetY()));
55     hoverObj->SetProperty<double>("displayX", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX()));
56     hoverObj->SetProperty<double>("displayY", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY()));
57     hoverObj->SetProperty<double>("windowX", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX()));
58     hoverObj->SetProperty<double>("windowY", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY()));
59     hoverObj->SetProperty<double>("x", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX()));
60     hoverObj->SetProperty<double>("y", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY()));
61     hoverObj->Wrap<HoverInfo>(&hoverInfo);
62     JSRef<JSVal> hoverVal = JSRef<JSObject>::Cast(hoverObj);
63     JSRef<JSVal> params[] = { isHoverParam, hoverVal };
64     JsFunction::ExecuteJS((sizeof(params) / sizeof(params[0])), params);
65 }
66 
HoverMoveExecute(HoverInfo & hoverInfo)67 void JsHoverFunction::HoverMoveExecute(HoverInfo& hoverInfo)
68 {
69     JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
70     objectTemplate->SetInternalFieldCount(1);
71     JSRef<JSObject> hoverObj = objectTemplate->NewInstance();
72     hoverObj->SetPropertyObject("stopPropagation", JSRef<JSFunc>::New<FunctionCallback>(JsStopPropagation));
73     hoverObj->SetPropertyObject(
74         "getModifierKeyState", JSRef<JSFunc>::New<FunctionCallback>(NG::ArkTSUtils::JsGetModifierKeyState));
75     hoverObj->SetProperty<double>(
76         "timestamp", static_cast<double>(hoverInfo.GetTimeStamp().time_since_epoch().count()));
77     hoverObj->SetProperty<double>("source", static_cast<int32_t>(hoverInfo.GetSourceDevice()));
78     auto target = CreateEventTargetObject(hoverInfo);
79     hoverObj->SetPropertyObject("target", target);
80     hoverObj->SetProperty<double>("sourceTool", static_cast<int32_t>(hoverInfo.GetSourceTool()));
81     hoverObj->SetProperty<double>("axisVertical", 0.0f);
82     hoverObj->SetProperty<double>("axisHorizontal", 0.0f);
83     hoverObj->SetProperty<double>("tiltX", hoverInfo.GetTiltX().value_or(0.0f));
84     hoverObj->SetProperty<double>("tiltY", hoverInfo.GetTiltY().value_or(0.0f));
85     hoverObj->SetProperty<double>("rollAngle", hoverInfo.GetRollAngle().value_or(0.0f));
86     hoverObj->SetProperty<double>("deviceId", hoverInfo.GetDeviceId());
87     hoverObj->SetProperty<int32_t>("targetDisplayId", hoverInfo.GetTargetDisplayId());
88     hoverObj->SetProperty<int32_t>("pressure", 0.0f);
89     const OHOS::Ace::Offset& globalLocation = hoverInfo.GetGlobalLocation();
90     const OHOS::Ace::Offset& localLocation = hoverInfo.GetLocalLocation();
91     const OHOS::Ace::Offset& screenLocation = hoverInfo.GetScreenLocation();
92     const OHOS::Ace::Offset& globalDisplayLocation = hoverInfo.GetGlobalDisplayLocation();
93     hoverObj->SetProperty<double>(
94         "globalDisplayX", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetX()));
95     hoverObj->SetProperty<double>(
96         "globalDisplayY", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetY()));
97     hoverObj->SetProperty<double>("displayX", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX()));
98     hoverObj->SetProperty<double>("displayY", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY()));
99     hoverObj->SetProperty<double>("windowX", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX()));
100     hoverObj->SetProperty<double>("windowY", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY()));
101     hoverObj->SetProperty<double>("x", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX()));
102     hoverObj->SetProperty<double>("y", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY()));
103     hoverObj->Wrap<HoverInfo>(&hoverInfo);
104     JSRef<JSVal> hoverVal = JSRef<JSObject>::Cast(hoverObj);
105     JSRef<JSVal> params[] = { hoverVal };
106     JsFunction::ExecuteJS((sizeof(params) / sizeof(params[0])), params);
107 }
108 
AccessibilityHoverExecute(bool isHover,AccessibilityHoverInfo & hoverInfo)109 void JsHoverFunction::AccessibilityHoverExecute(bool isHover, AccessibilityHoverInfo& hoverInfo)
110 {
111     JSRef<JSVal> isHoverParam = JSRef<JSVal>::Make(ToJSValue(isHover));
112 
113     JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
114     objectTemplate->SetInternalFieldCount(1);
115     JSRef<JSObject> hoverObj = objectTemplate->NewInstance();
116     hoverObj->SetPropertyObject(
117         "getModifierKeyState", JSRef<JSFunc>::New<FunctionCallback>(NG::ArkTSUtils::JsGetModifierKeyState));
118     hoverObj->SetProperty<double>(
119         "timestamp", static_cast<double>(hoverInfo.GetTimeStamp().time_since_epoch().count()));
120     hoverObj->SetProperty<double>("source", static_cast<int32_t>(hoverInfo.GetSourceDevice()));
121     auto target = CreateEventTargetObject(hoverInfo);
122     hoverObj->SetPropertyObject("target", target);
123     hoverObj->SetProperty<double>("sourceTool", static_cast<int32_t>(hoverInfo.GetSourceTool()));
124     hoverObj->SetProperty<double>("axisVertical", 0.0f);
125     hoverObj->SetProperty<double>("axisHorizontal", 0.0f);
126     hoverObj->SetProperty<double>("tiltX", 0.0f);
127     hoverObj->SetProperty<double>("tiltY", 0.0f);
128     hoverObj->SetProperty<double>("rollAngle", 0.0f);
129 
130     const OHOS::Ace::Offset& globalLocation = hoverInfo.GetGlobalLocation();
131     const OHOS::Ace::Offset& localLocation = hoverInfo.GetLocalLocation();
132     const OHOS::Ace::Offset& screenLocation = hoverInfo.GetScreenLocation();
133     const OHOS::Ace::Offset& globalDisplayLocation = hoverInfo.GetGlobalDisplayLocation();
134     hoverObj->SetProperty<double>(
135         "globalDisplayX", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetX()));
136     hoverObj->SetProperty<double>(
137         "globalDisplayY", PipelineBase::Px2VpWithCurrentDensity(globalDisplayLocation.GetY()));
138     hoverObj->SetProperty<int32_t>("type", static_cast<int32_t>(hoverInfo.GetActionType()));
139     hoverObj->SetProperty<double>("displayX", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetX()));
140     hoverObj->SetProperty<double>("displayY", PipelineBase::Px2VpWithCurrentDensity(screenLocation.GetY()));
141     hoverObj->SetProperty<double>("windowX", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetX()));
142     hoverObj->SetProperty<double>("windowY", PipelineBase::Px2VpWithCurrentDensity(globalLocation.GetY()));
143     hoverObj->SetProperty<double>("x", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetX()));
144     hoverObj->SetProperty<double>("y", PipelineBase::Px2VpWithCurrentDensity(localLocation.GetY()));
145     hoverObj->SetProperty<int32_t>("targetDisplayId", hoverInfo.GetTargetDisplayId());
146 
147     hoverObj->Wrap<AccessibilityHoverInfo>(&hoverInfo);
148     JSRef<JSVal> hoverVal = JSRef<JSObject>::Cast(hoverObj);
149     JSRef<JSVal> params[] = { isHoverParam, hoverVal };
150     JsFunction::ExecuteJS((sizeof(params) / sizeof(params[0])), params);
151 }
152 
153 } // namespace OHOS::Ace::Framework
154