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