mirror of
https://gitee.com/openharmony/accessibility
synced 2024-11-30 02:21:35 +00:00
KeyCode
Signed-off-by: Caozheng <caozheng18@h-partners.com>
This commit is contained in:
parent
80e5f7c309
commit
b02aa80e92
@ -636,6 +636,30 @@ HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_003, TestSize.Level1)
|
||||
GTEST_LOG_(INFO) << "ExecuteAction_003 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ExecuteAction_004
|
||||
* @tc.name: ExecuteAction
|
||||
* @tc.desc: Test function ExecuteAction
|
||||
*/
|
||||
HWTEST_F(AccessibleAbilityClientImplTest, ExecuteAction_004, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ExecuteAction_004 start";
|
||||
Connect();
|
||||
AccessibilityElementInfo elementInfo {};
|
||||
std::vector<ActionType> actions;
|
||||
actions.push_back(ACCESSIBILITY_ACTION_HOME);
|
||||
actions.push_back(ACCESSIBILITY_ACTION_BACK);
|
||||
actions.push_back(ACCESSIBILITY_ACTION_RECENTTASK);
|
||||
actions.push_back(ACCESSIBILITY_ACTION_NOTIFICATIONCENTER);
|
||||
actions.push_back(ACCESSIBILITY_ACTION_CONTROLCENTER);
|
||||
for (int32_t i = 0; i < actions.size(); i++) {
|
||||
std::map<std::string, std::string> actionArguments {};
|
||||
EXPECT_EQ(instance_->ExecuteAction(elementInfo, actions[i], actionArguments), RET_ERR_TIME_OUT);
|
||||
GTEST_LOG_(INFO) << "ExecuteAction_004 action=" << actions[i];
|
||||
}
|
||||
GTEST_LOG_(INFO) << "ExecuteAction_004 end";
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: ResetAAClient_001
|
||||
* @tc.name: ResetAAClient
|
||||
|
@ -179,6 +179,11 @@ enum ActionType : int32_t {
|
||||
ACCESSIBILITY_ACTION_PREVIOUS_HTML_ITEM = 0x04000000,
|
||||
ACCESSIBILITY_ACTION_DELETED = 0x08000000,
|
||||
ACCESSIBILITY_ACTION_COMMON = 0x10000000,
|
||||
ACCESSIBILITY_ACTION_HOME = 0x00010000,
|
||||
ACCESSIBILITY_ACTION_BACK = 0x00020000,
|
||||
ACCESSIBILITY_ACTION_RECENTTASK = 0x00040000,
|
||||
ACCESSIBILITY_ACTION_NOTIFICATIONCENTER = 0x00080000,
|
||||
ACCESSIBILITY_ACTION_CONTROLCENTER = 0x00008000,
|
||||
ACCESSIBILITY_ACTION_TYPE_MASK = 0x1FFFFFFF,
|
||||
};
|
||||
|
||||
|
@ -732,7 +732,12 @@ ActionType ConvertStringToAccessibleOperationType(const std::string &type)
|
||||
{"setSelection", ActionType::ACCESSIBILITY_ACTION_SET_SELECTION},
|
||||
{"common", ActionType::ACCESSIBILITY_ACTION_COMMON},
|
||||
{"setText", ActionType::ACCESSIBILITY_ACTION_SET_TEXT},
|
||||
{"delete", ActionType::ACCESSIBILITY_ACTION_DELETED}};
|
||||
{"delete", ActionType::ACCESSIBILITY_ACTION_DELETED},
|
||||
{"home", ActionType::ACCESSIBILITY_ACTION_HOME},
|
||||
{"back", ActionType::ACCESSIBILITY_ACTION_BACK},
|
||||
{"recentTask", ActionType::ACCESSIBILITY_ACTION_RECENTTASK},
|
||||
{"notificationCenter", ActionType::ACCESSIBILITY_ACTION_NOTIFICATIONCENTER},
|
||||
{"controlCenter", ActionType::ACCESSIBILITY_ACTION_CONTROLCENTER}};
|
||||
|
||||
if (accessibleOperationTypeTable.find(type) == accessibleOperationTypeTable.end()) {
|
||||
HILOG_WARN("invalid key[%{public}s]", type.c_str());
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "accessible_ability_channel_stub.h"
|
||||
#include "event_handler.h"
|
||||
#include "i_accessibility_element_operator.h"
|
||||
#include "key_event.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Accessibility {
|
||||
@ -64,6 +65,10 @@ private:
|
||||
static RetError GetElementOperator(int32_t accountId, int32_t windowId, int32_t focusType,
|
||||
const std::string &clientName, sptr<IAccessibilityElementOperator> &elementOperator);
|
||||
RetError GetWindows(uint64_t displayId, std::vector<AccessibilityWindowInfo> &windows) const;
|
||||
RetError TransmitActionToMmi(const int32_t action);
|
||||
static void SetKeyCodeMulti(std::shared_ptr<MMI::KeyEvent>& keyEvent,
|
||||
const int32_t keyCodePre, const int32_t keyCodeNext);
|
||||
static void SetKeyCodeSingle(std::shared_ptr<MMI::KeyEvent>& keyEvent, const int32_t keyCode);
|
||||
|
||||
std::string clientName_ = "";
|
||||
int32_t accountId_ = -1;
|
||||
|
@ -24,6 +24,18 @@ namespace OHOS {
|
||||
namespace Accessibility {
|
||||
namespace {
|
||||
constexpr uint32_t TIME_OUT_OPERATOR = 5000;
|
||||
MMI::InputManager* inputManager_ = MMI::InputManager::GetInstance();
|
||||
std::map<int32_t, std::pair<bool, std::pair<int32_t, int32_t>>> accessibleKeyCodeTable = {
|
||||
{ActionType::ACCESSIBILITY_ACTION_HOME,
|
||||
{false, {MMI::KeyEvent::KEYCODE_META_LEFT, MMI::KeyEvent::KEYCODE_D}}},
|
||||
{ActionType::ACCESSIBILITY_ACTION_RECENTTASK,
|
||||
{false, {MMI::KeyEvent::KEYCODE_META_LEFT, MMI::KeyEvent::KEYCODE_TAB}}},
|
||||
{ActionType::ACCESSIBILITY_ACTION_BACK,
|
||||
{true, {MMI::KeyEvent::KEYCODE_BACK, MMI::KeyEvent::KEYCODE_BACK}}},
|
||||
{ActionType::ACCESSIBILITY_ACTION_NOTIFICATIONCENTER,
|
||||
{true, {MMI::KeyEvent::KEYCODE_NOTIFICATION, MMI::KeyEvent::KEYCODE_NOTIFICATION}}},
|
||||
{ActionType::ACCESSIBILITY_ACTION_CONTROLCENTER,
|
||||
{true, {MMI::KeyEvent::KEYCODE_CONTROLPANEL, MMI::KeyEvent::KEYCODE_CONTROLPANEL}}}};
|
||||
} // namespace
|
||||
|
||||
AccessibleAbilityChannel::AccessibleAbilityChannel(const int32_t accountId, const std::string &clientName)
|
||||
@ -185,6 +197,74 @@ RetError AccessibleAbilityChannel::FocusMoveSearch(const int32_t accessibilityWi
|
||||
return syncFuture.get();
|
||||
}
|
||||
|
||||
void AccessibleAbilityChannel::SetKeyCodeSingle(std::shared_ptr<MMI::KeyEvent>& keyEvent, const int32_t keyCode)
|
||||
{
|
||||
HILOG_DEBUG();
|
||||
if (!keyEvent) {
|
||||
HILOG_ERROR("KeyEvent is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
keyEvent->SetKeyCode(keyCode);
|
||||
keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
|
||||
|
||||
MMI::KeyEvent::KeyItem item;
|
||||
item.SetKeyCode(keyCode);
|
||||
item.SetPressed(true);
|
||||
|
||||
keyEvent->AddKeyItem(item);
|
||||
}
|
||||
|
||||
void AccessibleAbilityChannel::SetKeyCodeMulti(std::shared_ptr<MMI::KeyEvent>& keyEvent, const int32_t keyCodePre,
|
||||
const int32_t keyCodeNext)
|
||||
{
|
||||
HILOG_DEBUG();
|
||||
if (!keyEvent) {
|
||||
HILOG_ERROR("KeyEvent is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
keyEvent->SetKeyCode(keyCodeNext);
|
||||
keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_DOWN);
|
||||
|
||||
MMI::KeyEvent::KeyItem item1;
|
||||
item1.SetKeyCode(keyCodePre);
|
||||
item1.SetPressed(true);
|
||||
keyEvent->AddKeyItem(item1);
|
||||
|
||||
MMI::KeyEvent::KeyItem item2;
|
||||
item2.SetKeyCode(keyCodeNext);
|
||||
item2.SetPressed(true);
|
||||
keyEvent->AddKeyItem(item2);
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityChannel::TransmitActionToMmi(const int32_t action)
|
||||
{
|
||||
HILOG_DEBUG("The action is %{public}d", action);
|
||||
std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
|
||||
if (!keyEvent) {
|
||||
HILOG_ERROR("KeyEvent is nullptr");
|
||||
return RET_ERR_NULLPTR;
|
||||
}
|
||||
|
||||
if (!inputManager_) {
|
||||
HILOG_ERROR("inputManager_ is nullptr");
|
||||
return RET_ERR_NULLPTR;
|
||||
}
|
||||
|
||||
HILOG_DEBUG("Transmit keycode to MMI");
|
||||
|
||||
if (accessibleKeyCodeTable.at(action).first) {
|
||||
SetKeyCodeSingle(keyEvent, accessibleKeyCodeTable.at(action).second.first);
|
||||
} else {
|
||||
SetKeyCodeMulti(keyEvent, accessibleKeyCodeTable.at(action).second.first,
|
||||
accessibleKeyCodeTable.at(action).second.second);
|
||||
}
|
||||
|
||||
inputManager_->SimulateInputEvent(keyEvent);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWindowId, const int64_t elementId,
|
||||
const int32_t action, const std::map<std::string, std::string> &actionArguments, const int32_t requestId,
|
||||
const sptr<IAccessibilityElementOperatorCallback> &callback)
|
||||
@ -196,6 +276,15 @@ RetError AccessibleAbilityChannel::ExecuteAction(const int32_t accessibilityWind
|
||||
return RET_ERR_NULLPTR;
|
||||
}
|
||||
|
||||
if (accessibleKeyCodeTable.find(action) != accessibleKeyCodeTable.end()) {
|
||||
RetError ret = TransmitActionToMmi(action);
|
||||
if (ret != RET_OK) {
|
||||
HILOG_ERROR("Transmit Action To Mmi failed!");
|
||||
return RET_ERR_FAILED;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
std::shared_ptr<std::promise<RetError>> syncPromise = std::make_shared<std::promise<RetError>>();
|
||||
std::future syncFuture = syncPromise->get_future();
|
||||
eventHandler_->PostTask(std::bind([syncPromise, accessibilityWindowId, elementId, action,
|
||||
|
Loading…
Reference in New Issue
Block a user