!60 预览支持调试Part4:通过对多模事件的Mock,重构预览事件传递方式

Merge pull request !60 from ZhangYu/event
This commit is contained in:
openharmony_ci
2023-06-01 02:44:46 +00:00
committed by Gitee
7 changed files with 67 additions and 48 deletions
+28 -1
View File
@@ -542,6 +542,33 @@ void JsAppImpl::LoadDocument(const std::string filePath,
}
}
void JsAppImpl::InitializeClipboard(OHOS::Ace::Platform::CallbackSetClipboardData cbkSetData,
OHOS::Ace::Platform::CallbackGetClipboardData cbkGetData) const
{
ability->InitializeClipboard(cbkSetData, cbkGetData);
}
void JsAppImpl::DispatchBackPressedEvent() const
{
ability->OnBackPressed();
}
void JsAppImpl::DispatchKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) const
{
ability->OnInputEvent(keyEvent);
}
void JsAppImpl::DispatchPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) const
{
ability->OnInputEvent(pointerEvent);
}
void JsAppImpl::DispatchAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) const
{
ability->OnInputEvent(axisEvent);
}
void JsAppImpl::DispatchInputMethodEvent(const unsigned int code_point) const
{
ability->OnInputMethodEvent(code_point);
}
string JsAppImpl::GetDeviceTypeName(const OHOS::Ace::DeviceType type) const
{
switch (type) {
@@ -558,4 +585,4 @@ string JsAppImpl::GetDeviceTypeName(const OHOS::Ace::DeviceType type) const
default:
return "";
}
}
}
+8
View File
@@ -54,6 +54,14 @@ public:
bool MemoryRefresh(const std::string memoryRefreshArgs) const override;
void LoadDocument(const std::string, const std::string, const Json::Value) override;
void InitializeClipboard(OHOS::Ace::Platform::CallbackSetClipboardData cbkSetData,
OHOS::Ace::Platform::CallbackGetClipboardData cbkGetData) const;
void DispatchBackPressedEvent() const;
void DispatchKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) const;
void DispatchPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) const;
void DispatchAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) const;
void DispatchInputMethodEvent(const unsigned int code_point) const;
protected:
void SetJsAppArgs(OHOS::Ace::Platform::AceRunArgs& args);
void RunJsApp();
+2
View File
@@ -25,6 +25,8 @@ ohos_static_library("mock_rich") {
".",
"../util/",
"../cli/",
"../jsapp/rich",
"../jsapp",
]
include_dirs += os_include_dirs
+14 -24
View File
@@ -19,13 +19,10 @@
#include "PreviewerEngineLog.h"
#include "ClipboardHelper.h"
#include "KeyboardHelper.h"
#include "ace_ability.h"
#include "event_dispatcher.h"
#include "clipboard_proxy.h"
#include "clipboard_proxy_impl.h"
#include "JsAppImpl.h"
using namespace std;
using namespace OHOS::Ace;
using namespace OHOS::MMI;
KeyInputImpl::KeyInputImpl() : KeyInput(), pressedCodes(0)
{
@@ -45,33 +42,26 @@ void KeyInputImpl::SetDelegate()
auto callbackGetClipboardData = []() {
return ClipboardHelper::GetClipboardData();
};
auto callbackGetCapsLockStatus = []() {
return KeyboardHelper::GetKeyStateByKeyName("CapsLock");
};
auto callbackGetNumLockStatus = []() {
return KeyboardHelper::GetKeyStateByKeyName("NumLock");
};
Platform::EventDispatcher::GetInstance().RegisterCallbackGetCapsLockStatus(callbackGetCapsLockStatus);
Platform::EventDispatcher::GetInstance().RegisterCallbackGetNumLockStatus(callbackGetNumLockStatus);
ClipboardProxy::GetInstance()->SetDelegate(
std::make_unique<Platform::ClipboardProxyImpl>(callbackSetClipboardData, callbackGetClipboardData));
JsAppImpl::GetInstance().InitializeClipboard(callbackSetClipboardData, callbackGetClipboardData);
ILOG("Bind key event callback function to ace successed.");
}
void KeyInputImpl::DispatchOsInputMethodEvent() const
{
Platform::EventDispatcher::GetInstance().DispatchInputMethodEvent(codePoint);
JsAppImpl::GetInstance().DispatchInputMethodEvent(codePoint);
}
void KeyInputImpl::DispatchOsKeyEvent() const
{
KeyEvent keyEvent;
keyEvent.code = KeyCode(keyCode);
keyEvent.action = KeyAction(keyAction);
keyEvent.pressedCodes = pressedCodes;
keyEvent.timeStamp = chrono::high_resolution_clock::now();
keyEvent.key = keyString.c_str();
Platform::EventDispatcher::GetInstance().DispatchKeyEvent(keyEvent);
auto keyEvent = std::make_shared<OHOS::MMI::KeyEvent>();
keyEvent->code = KeyCode(keyCode);
keyEvent->action = KeyAction(keyAction);
keyEvent->pressedCodes = pressedCodes;
keyEvent->timeStamp = chrono::high_resolution_clock::now();
keyEvent->key = keyString.c_str();
keyEvent->enableCapsLock_ = KeyboardHelper::GetKeyStateByKeyName("CapsLock");
keyEvent->enableNumLock_ = KeyboardHelper::GetKeyStateByKeyName("NumLock");
JsAppImpl::GetInstance().DispatchKeyEvent(keyEvent);
}
void KeyInputImpl::SetKeyEvent(const int32_t keyCodeVal, const int32_t keyActionVal,
@@ -89,4 +79,4 @@ void KeyInputImpl::SetKeyEvent(const int32_t keyCodeVal, const int32_t keyAction
void KeyInputImpl::SetCodePoint(const unsigned int codePointVal)
{
codePoint = codePointVal;
}
}
+3 -3
View File
@@ -17,7 +17,7 @@
#define KEYINPUTIMPL_H
#include "KeyInput.h"
#include "key_event.h"
#include "adapter/preview/external/multimodalinput/key_event.h"
class KeyInputImpl : public KeyInput {
public:
@@ -32,7 +32,7 @@ public:
private:
KeyInputImpl();
virtual ~KeyInputImpl() {};
std::vector<OHOS::Ace::KeyCode> pressedCodes;
std::vector<OHOS::MMI::KeyCode> pressedCodes;
};
#endif // KEYINPUTIMPL_H
#endif // KEYINPUTIMPL_H
+10 -17
View File
@@ -19,14 +19,11 @@
#include <vector>
#include <chrono>
#include "ace_ability.h"
#include "event_dispatcher.h"
#include "PreviewerEngineLog.h"
using namespace std;
using namespace OHOS::Ace;
using namespace OHOS::MMI;
MouseInputImpl::MouseInputImpl()
{
@@ -52,27 +49,23 @@ TouchType MouseInputImpl::ConvertToOsType(MouseInput::MouseStatus status) const
}
void MouseInputImpl::DispatchOsTouchEvent() const
{
TouchEvent touchEvent;
touchEvent.time = std::chrono::high_resolution_clock::now();
touchEvent.id = 1;
touchEvent.x = mouseXPosition;
touchEvent.y = mouseYPosition;
touchEvent.type = ConvertToOsType(mouseStatus);
touchEvent.size = sizeof (TouchEvent);
auto pointerEvent = std::make_shared<PointerEvent>();
pointerEvent->time = std::chrono::high_resolution_clock::now();
pointerEvent->id = 1;
pointerEvent->x = mouseXPosition;
pointerEvent->y = mouseYPosition;
pointerEvent->type = ConvertToOsType(mouseStatus);
pointerEvent->size = sizeof (PointerEvent);
ILOG("MouseInputImpl::DispatchEvent x: %f y:%f", mouseXPosition, mouseYPosition);
ILOG("current thread: %d", this_thread::get_id());
if (!Platform::EventDispatcher::GetInstance().DispatchTouchEvent(touchEvent)) {
ILOG("MouseInputImpl::DispatchEvent failed, x: %f y:%f", mouseXPosition, mouseYPosition);
}
JsAppImpl::GetInstance().DispatchPointerEvent(pointerEvent);
}
void MouseInputImpl::DispatchOsBackEvent() const
{
ILOG("DispatchBackPressedEvent run.");
ILOG("current thread: %d", this_thread::get_id());
if (!Platform::EventDispatcher::GetInstance().DispatchBackPressedEvent()) {
ELOG("DispatchBackPressedEvent failed.");
}
JsAppImpl::GetInstance().DispatchBackPressedEvent();
}
MouseInputImpl& MouseInputImpl::GetInstance()
+2 -3
View File
@@ -16,8 +16,7 @@
#ifndef MOUSEINPUTIMPL_H
#define MOUSEINPUTIMPL_H
#include "touch_event.h"
#include "JsAppImpl.h"
#include "MouseInput.h"
class MouseInputImpl : public MouseInput {
@@ -30,7 +29,7 @@ public:
private:
MouseInputImpl();
virtual ~MouseInputImpl() {}
OHOS::Ace::TouchType ConvertToOsType(MouseStatus status) const;
OHOS::MMI::TouchType ConvertToOsType(MouseStatus status) const;
};
#endif // MOUSEINPUTIMPL_H