Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
4602dc79
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4602dc79
编写于
11月 24, 2022
作者:
L
lanyill
提交者:
lanyi
11月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed
b8da581d
from
https://gitee.com/lanyill/xts_acts/pulls/6679
XComponent xts增加用例 Signed-off-by:
N
lanyill
<
lanyi3@huawei.com
>
上级
d77301b9
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
252 addition
and
2 deletion
+252
-2
arkui/ace_ets_xcomponent/entry/src/main/cpp/render/plugin_render.cpp
...ts_xcomponent/entry/src/main/cpp/render/plugin_render.cpp
+122
-1
arkui/ace_ets_xcomponent/entry/src/main/cpp/render/plugin_render.h
..._ets_xcomponent/entry/src/main/cpp/render/plugin_render.h
+13
-1
arkui/ace_ets_xcomponent/entry/src/main/ets/MainAbility/pages/index.ets
...xcomponent/entry/src/main/ets/MainAbility/pages/index.ets
+6
-0
arkui/ace_ets_xcomponent/entry/src/main/ets/test/XComponentTest.ets
...ets_xcomponent/entry/src/main/ets/test/XComponentTest.ets
+111
-0
未找到文件。
arkui/ace_ets_xcomponent/entry/src/main/cpp/render/plugin_render.cpp
浏览文件 @
4602dc79
...
...
@@ -35,8 +35,14 @@ uint32_t PluginRender::xcHeight_ = 0;
uint32_t
PluginRender
::
xcWidth_
=
0
;
double
PluginRender
::
off_x
=
0
;
double
PluginRender
::
off_y
=
0
;
uint32_t
PluginRender
::
toolType_
=
5
;
uint32_t
PluginRender
::
mousecallback_
=
0
;
float
PluginRender
::
tiltX_
=
0
;
float
PluginRender
::
tiltY_
=
0
;
uint32_t
PluginRender
::
touchType
=
4
;
OH_NativeXComponent_TouchEvent
PluginRender
::
testTouchEvent_
;
OH_NativeXComponent_MouseEvent
PluginRender
::
testMouseEvent_
;
OH_NativeXComponent_MouseEvent_Callback
PluginRender
::
mouseEventcallback_
;
void
OnSurfaceCreatedCB
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
...
...
@@ -101,7 +107,7 @@ void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
void
DispatchMouseEventCB
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
LOG
E
(
"DispatchMouseEventCB"
);
LOG
D
(
"DispatchMouseEventCB"
);
int32_t
ret
;
char
idStr
[
OH_XCOMPONENT_ID_LEN_MAX
+
1
]
=
{};
uint64_t
idSize
=
OH_XCOMPONENT_ID_LEN_MAX
+
1
;
...
...
@@ -110,6 +116,8 @@ void DispatchMouseEventCB(OH_NativeXComponent* component, void* window)
return
;
}
std
::
string
id
(
idStr
);
auto
render
=
PluginRender
::
GetInstance
(
id
);
render
->
DispatchMouseEvent
(
component
,
window
);
}
PluginRender
::
PluginRender
(
std
::
string
&
id
)
...
...
@@ -122,6 +130,8 @@ PluginRender::PluginRender(std::string& id)
renderCallback
->
OnSurfaceChanged
=
OnSurfaceChangedCB
;
renderCallback
->
OnSurfaceDestroyed
=
OnSurfaceDestroyedCB
;
renderCallback
->
DispatchTouchEvent
=
DispatchTouchEventCB
;
auto
renderMouseEventCallback
=
PluginRender
::
GetNXComponentMouseEventCallback
();
renderMouseEventCallback
->
DispatchMouseEvent
=
DispatchMouseEventCB
;
}
PluginRender
*
PluginRender
::
GetInstance
(
std
::
string
&
id
)
...
...
@@ -140,10 +150,17 @@ OH_NativeXComponent_Callback* PluginRender::GetNXComponentCallback()
return
&
PluginRender
::
callback_
;
}
OH_NativeXComponent_MouseEvent_Callback
*
PluginRender
::
GetNXComponentMouseEventCallback
()
{
return
&
PluginRender
::
mouseEventcallback_
;
}
void
PluginRender
::
SetNativeXComponent
(
OH_NativeXComponent
*
component
)
{
component_
=
component
;
OH_NativeXComponent_RegisterCallback
(
component_
,
&
PluginRender
::
callback_
);
uint32_t
mousecallback
=
OH_NativeXComponent_RegisterMouseEventCallback
(
component_
,
&
PluginRender
::
mouseEventcallback_
);
mousecallback_
=
mousecallback
;
}
void
PluginRender
::
OnSurfaceCreated
(
OH_NativeXComponent
*
component
,
void
*
window
)
...
...
@@ -209,6 +226,19 @@ void PluginRender::DispatchTouchEvent(OH_NativeXComponent* component, void* wind
touchEvent_
.
touchPoints
[
i
].
id
,
touchEvent_
.
touchPoints
[
i
].
x
,
touchEvent_
.
touchPoints
[
i
].
y
);
LOGE
(
"Touch Info : screenx = %{public}f, screeny = %{public}f"
,
touchEvent_
.
touchPoints
[
i
].
screenX
,
touchEvent_
.
touchPoints
[
i
].
screenY
);
OH_NativeXComponent_TouchPointToolType
toolType
=
OH_NativeXComponent_TouchPointToolType
::
OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN
;
float
tiltX
=
123.0
;
float
tiltY
=
321.0
;
int32_t
ret1
;
int32_t
ret2
;
int32_t
ret3
;
ret1
=
OH_NativeXComponent_GetTouchPointToolType
(
component
,
i
,
&
toolType
);
ret2
=
OH_NativeXComponent_GetTouchPointTiltX
(
component
,
i
,
&
tiltX
);
ret3
=
OH_NativeXComponent_GetTouchPointTiltY
(
component
,
i
,
&
tiltY
);
toolType_
=
toolType
;
tiltX_
=
tiltX
;
tiltY_
=
tiltY
;
LOGE
(
"Touch Info : DispatchTouchEvent dots[%{public}d] toolType=%{public}u, tiltX=%{public}f, tiltY=%{public}f"
,
i
,
toolType
,
tiltX
,
tiltY
);
}
}
else
{
LOGE
(
"Touch fail"
);
...
...
@@ -230,12 +260,32 @@ napi_value PluginRender::Export(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION
(
"TestGetXComponentOffset_x"
,
PluginRender
::
TestGetXComponentOffset_x
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponentOffset_y"
,
PluginRender
::
TestGetXComponentOffset_y
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponent_TouchEvent"
,
PluginRender
::
TestGetXComponent_TouchEvent
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponent_MouseEvent"
,
PluginRender
::
TestGetXComponent_MouseEvent
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponentpointtool_tilty"
,
PluginRender
::
TestGetXComponentpointtool_tilty
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponentpointtool_type"
,
PluginRender
::
TestGetXComponentpointtool_type
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponentpointtool_tiltx"
,
PluginRender
::
TestGetXComponentpointtool_tiltx
),
DECLARE_NAPI_FUNCTION
(
"TestGetXComponent_RegisterMouseEventCallback"
,
PluginRender
::
TestGetXComponent_RegisterMouseEventCallback
),
};
NAPI_CALL
(
env
,
napi_define_properties
(
env
,
exports
,
sizeof
(
desc
)
/
sizeof
(
desc
[
0
]),
desc
));
return
exports
;
}
void
PluginRender
::
DispatchMouseEvent
(
OH_NativeXComponent
*
component
,
void
*
window
)
{
LOGE
(
"----------TestMouse Mouse Info DispatchMouseEvent 11"
);
int32_t
ret
=
OH_NativeXComponent_GetMouseEvent
(
component
,
window
,
&
mouseEvent_
);
LOGE
(
"----------TestMouse Mouse Info DispatchMouseEvent"
);
if
(
ret
==
OH_NATIVEXCOMPONENT_RESULT_SUCCESS
)
{
testMouseEvent_
=
mouseEvent_
;
LOGE
(
"TestMouse Mouse Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f"
,
mouseEvent_
.
x
,
mouseEvent_
.
y
,
mouseEvent_
.
screenX
,
mouseEvent_
.
screenY
);
LOGE
(
"TestMouse Mouse Info : action = %{public}d, button = %{public}d, time = %{public}lld"
,
mouseEvent_
.
action
,
mouseEvent_
.
button
,
mouseEvent_
.
timestamp
);
LOGE
(
"TestMouse Mouse Info : action = %{public}d, button = %{public}d"
,
mouseEvent_
.
action
,
mouseEvent_
.
button
);
}
else
{
LOGE
(
"Mouse Info fail"
);
}
}
napi_value
PluginRender
::
NapiChangeShape
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"NapiChangeShape"
);
...
...
@@ -425,6 +475,39 @@ napi_value PluginRender::TestGetXComponentOffset_y(napi_env env, napi_callback_i
return
output
;
}
napi_value
PluginRender
::
TestGetXComponentpointtool_tiltx
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponentpointtool_tiltx"
);
napi_value
output
;
NAPI_CALL
(
env
,
napi_create_double
(
env
,
tiltX_
,
&
output
));
LOGE
(
"xclog TestGetXComponentpointtool_tiltx : %{public}f"
,
tiltX_
);
return
output
;
}
napi_value
PluginRender
::
TestGetXComponentpointtool_tilty
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponentpointtool_tilty"
);
napi_value
output
;
NAPI_CALL
(
env
,
napi_create_double
(
env
,
tiltY_
,
&
output
));
LOGE
(
"xclog TestGetXComponentpointtool_tilty : %{public}f"
,
tiltY_
);
return
output
;
}
napi_value
PluginRender
::
TestGetXComponentpointtool_type
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponentpointtool_type"
);
napi_value
output
;
NAPI_CALL
(
env
,
napi_create_double
(
env
,
toolType_
,
&
output
));
LOGE
(
"xclog TestGetXComponentpointtool_type : %{public}u"
,
toolType_
);
return
output
;
}
napi_value
PluginRender
::
TestGetXComponent_TouchEvent
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponent_TouchEvent"
);
...
...
@@ -446,6 +529,44 @@ napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callbac
return
obj
;
}
napi_value
PluginRender
::
TestGetXComponent_MouseEvent
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponent_MouseEvent"
);
napi_value
surf_x
;
napi_value
surf_y
;
napi_value
t_button
;
NAPI_CALL
(
env
,
napi_create_double
(
env
,
testMouseEvent_
.
x
,
&
(
surf_x
)));
NAPI_CALL
(
env
,
napi_create_double
(
env
,
testMouseEvent_
.
y
,
&
(
surf_y
)));
NAPI_CALL
(
env
,
napi_create_uint32
(
env
,
testMouseEvent_
.
button
,
&
(
t_button
)));
napi_value
obj
;
NAPI_CALL
(
env
,
napi_create_object
(
env
,
&
obj
));
NAPI_CALL
(
env
,
napi_set_named_property
(
env
,
obj
,
"surface_X1"
,
surf_x
));
// float x
NAPI_CALL
(
env
,
napi_set_named_property
(
env
,
obj
,
"surface_Y1"
,
surf_y
));
// float y
NAPI_CALL
(
env
,
napi_set_named_property
(
env
,
obj
,
"mousebutton"
,
t_button
));
// int32_t
return
obj
;
}
napi_value
PluginRender
::
TestGetXComponent_RegisterMouseEventCallback
(
napi_env
env
,
napi_callback_info
info
)
{
LOGE
(
"xclog running PluginRender::TestGetXComponent_RegisterMouseEventCallback"
);
napi_value
callback_
;
NAPI_CALL
(
env
,
napi_create_double
(
env
,
mousecallback_
,
&
(
callback_
)));
napi_value
obj
;
NAPI_CALL
(
env
,
napi_create_object
(
env
,
&
obj
));
NAPI_CALL
(
env
,
napi_set_named_property
(
env
,
obj
,
"MouseCallback_"
,
callback_
));
// float x
return
obj
;
}
#ifdef __cplusplus
}
#endif
\ No newline at end of file
arkui/ace_ets_xcomponent/entry/src/main/cpp/render/plugin_render.h
浏览文件 @
4602dc79
...
...
@@ -29,6 +29,7 @@ public:
explicit
PluginRender
(
std
::
string
&
id
);
static
PluginRender
*
GetInstance
(
std
::
string
&
id
);
static
OH_NativeXComponent_Callback
*
GetNXComponentCallback
();
static
OH_NativeXComponent_MouseEvent_Callback
*
GetNXComponentMouseEventCallback
();
void
SetNativeXComponent
(
OH_NativeXComponent
*
component
);
...
...
@@ -50,7 +51,11 @@ public:
static
napi_value
TestGetXComponentOffset_x
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponentOffset_y
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponent_TouchEvent
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponent_MouseEvent
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponentpointtool_tiltx
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponentpointtool_tilty
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponentpointtool_type
(
napi_env
env
,
napi_callback_info
info
);
static
napi_value
TestGetXComponent_RegisterMouseEventCallback
(
napi_env
env
,
napi_callback_info
info
);
// Callback, called by ACE XComponent
void
OnSurfaceCreated
(
OH_NativeXComponent
*
component
,
void
*
window
);
...
...
@@ -68,10 +73,16 @@ public:
static
uint32_t
isCreated_
;
static
uint32_t
xcHeight_
;
static
uint32_t
xcWidth_
;
static
uint32_t
toolType_
;
static
float
tiltX_
;
static
float
tiltY_
;
static
uint32_t
mousecallback_
;
static
double
off_x
;
static
double
off_y
;
static
uint32_t
touchType
;
static
OH_NativeXComponent_TouchEvent
testTouchEvent_
;
static
OH_NativeXComponent_MouseEvent
testMouseEvent_
;
static
OH_NativeXComponent_MouseEvent_Callback
mouseEventcallback_
;
OH_NativeXComponent
*
component_
;
EGLCore
*
eglCore_
;
...
...
@@ -83,6 +94,7 @@ public:
double
x_
;
double
y_
;
OH_NativeXComponent_TouchEvent
touchEvent_
;
OH_NativeXComponent_MouseEvent
mouseEvent_
;
};
#endif // _PLUGIN_RENDER_H_
arkui/ace_ets_xcomponent/entry/src/main/ets/MainAbility/pages/index.ets
浏览文件 @
4602dc79
...
...
@@ -30,6 +30,9 @@ struct XComponentTest {
@State private xcomponentWidth:number = 720;
private offset_x:double = 0.000;
private offset_y:double = 610.000;
private index:number = 0;
private callback_:number = 0;
private type_:number = 5;
private touchTypeDown:number = 0;
private touchTypeUp:number = 1;
private touchTypeMove:number = 2;
...
...
@@ -70,6 +73,8 @@ struct XComponentTest {
globalThis.xcomponentWidth = this.xcomponentWidth;
globalThis.touchTypeDown = this.touchTypeDown;
globalThis.touchTypeUp = this.touchTypeUp;
globalThis.type_ = this.type_;
globalThis.index = this.index;
globalThis.touchTypeMove = this.touchTypeMove;
globalThis.touchTypeCancel = this.touchTypeCancel;
globalThis.offset_x = this.offset_x;
...
...
@@ -124,6 +129,7 @@ struct XComponentTest {
globalThis.xcomponentContext2 = this.xcomponentContext2;
globalThis.xcomponentId2 = this.xcomponentId2;
globalThis.xcomponentHeight = this.xcomponentHeight;
globalThis.callback_ = this.callback_;
globalThis.xcomponentWidth = this.xcomponentWidth;
globalThis.offset_x = this.offset_x;
globalThis.offset_y = this.offset_y;
...
...
arkui/ace_ets_xcomponent/entry/src/main/ets/test/XComponentTest.ets
浏览文件 @
4602dc79
...
...
@@ -200,5 +200,116 @@ export default function XComponentTestJsunit() {
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0600
* @tc.name XComponentTest006
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest006', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest006 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext1= globalThis.xcomponentContext1;
var insidex = globalThis.index;
if (!xcomponentContext1) {
console.error('xclog xcomponentContext null')
result = false;
} else {
result = true;
var result;
var inside_x;
var inside_y;
var button_t;
await Utils.sleep(1000);
inside_x = xcomponentContext1.TestGetXComponent_MouseEvent().surface_X1;
inside_y = xcomponentContext1.TestGetXComponent_MouseEvent().surface_Y1;
button_t = xcomponentContext1.TestGetXComponent_MouseEvent().mousebutton;
console.info('xclog ets touchEvent: surf_x1 is '+ inside_x + ', surf_y1 is '+ inside_y + ', button_t is ' + button_t );
}
expect(inside_x).assertEqual(insidex);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0700
* @tc.name XComponentTest007
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest007', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest007 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext2= globalThis.xcomponentContext2;
var callback_ = globalThis.callback_;
if (!xcomponentContext2) {
console.error('xclog xcomponentContext null')
tilty = false;
} else {
result = true;
var result;
var callback;
await Utils.sleep(1000);
callback = xcomponentContext2.TestGetXComponent_RegisterMouseEventCallback().MouseCallback_;
console.info('xclog ets touchEvent: callback is ' + callback );
}
expect(callback).assertEqual(callback_);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0800
* @tc.name XComponentTest008
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest008', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest008 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext1= globalThis.xcomponentContext1;
var type_ = globalThis.type_;
if (!xcomponentContext1) {
console.error('xclog xcomponentContext null')
result = false;
} else {
result = true;
var result;
var tilty;
var tiltx;
var type_t;
await Utils.sleep(1000);
tilty = xcomponentContext1.TestGetXComponentpointtool_tilty();
type_t = xcomponentContext1.TestGetXComponentpointtool_type();
tiltx = xcomponentContext1.TestGetXComponentpointtool_tiltx();
console.info('xclog ets touchEvent: surf_x is '+ tiltx + ', surf_y is '+ tilty + ', type_t is ' + type_t );
}
expect(type_t).assertEqual(type_);
done();
});
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录