mirror of
https://gitee.com/openharmony/accessibility
synced 2024-11-23 15:01:17 +00:00
add keyEvent
Signed-off-by: yichengzhao <yichengzhao1@huawei.com>
This commit is contained in:
parent
1a5cf66edf
commit
72746fd879
@ -166,7 +166,7 @@ bool JsAccessibilityExtension::OnKeyPressEvent(const MMI::KeyEvent& keyEvent)
|
||||
ConvertKeyEventToJS(reinterpret_cast<napi_env>(nativeEngine), napiEventInfo, const_cast<MMI::KeyEvent&>(keyEvent));
|
||||
NativeValue* nativeEventInfo = reinterpret_cast<NativeValue*>(napiEventInfo);
|
||||
NativeValue* argv[] = {nativeEventInfo};
|
||||
NativeValue* nativeResult = CallObjectMethod("onAccessibilityEvent", argv, 1);
|
||||
NativeValue* nativeResult = CallObjectMethod("onKeyPressEvent", argv, 1);
|
||||
|
||||
// unwrap result
|
||||
bool result = false;
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
void OnPointerEvent(MMI::PointerEvent &event) override;
|
||||
void SetAvailableFunctions(uint32_t availableFunctions);
|
||||
void NotifyAccessibilityEvent(AccessibilityEventInfo &event) const;
|
||||
static void InterceptKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent);
|
||||
|
||||
private:
|
||||
AccessibilityInputInterceptor();
|
||||
@ -80,8 +81,10 @@ private:
|
||||
sptr<EventTransmission> keyEventTransmitters_ = nullptr;
|
||||
uint32_t availableFunctions_ = 0;
|
||||
int32_t interceptorId_ = -1;
|
||||
int32_t keyEventInterceptorId_ = -1;
|
||||
MMI::InputManager *inputManager_ = nullptr;
|
||||
std::shared_ptr<AccessibilityInputEventConsumer> inputEventConsumer_ = nullptr;
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
|
||||
};
|
||||
} // namespace Accessibility
|
||||
} // namespace OHOS
|
||||
|
@ -52,6 +52,7 @@ AccessibilityInputInterceptor::AccessibilityInputInterceptor()
|
||||
HILOG_DEBUG("ams_ is null.");
|
||||
}
|
||||
inputManager_ = MMI::InputManager::GetInstance();
|
||||
eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(ams_->GetMainRunner());
|
||||
}
|
||||
|
||||
AccessibilityInputInterceptor::~AccessibilityInputInterceptor()
|
||||
@ -64,6 +65,7 @@ AccessibilityInputInterceptor::~AccessibilityInputInterceptor()
|
||||
pointerEventTransmitters_ = nullptr;
|
||||
keyEventTransmitters_ = nullptr;
|
||||
interceptorId_ = -1;
|
||||
keyEventInterceptorId_ = -1;
|
||||
inputManager_ = nullptr;
|
||||
inputEventConsumer_ = nullptr;
|
||||
}
|
||||
@ -164,11 +166,31 @@ void AccessibilityInputInterceptor::CreateInterceptor()
|
||||
HILOG_DEBUG("Interceptor is already added, id is %{public}d.", interceptorId_);
|
||||
return;
|
||||
}
|
||||
|
||||
inputEventConsumer_ = std::make_shared<AccessibilityInputEventConsumer>();
|
||||
interceptorId_ = inputManager_->AddInterceptor(inputEventConsumer_);
|
||||
|
||||
if (availableFunctions_ & FEATURE_TOUCH_EXPLORATION ||
|
||||
availableFunctions_ & FEATURE_INJECT_TOUCH_EVENTS ||
|
||||
availableFunctions_ & FEATURE_TOUCH_EXPLORATION) {
|
||||
interceptorId_ = inputManager_->AddInterceptor(inputEventConsumer_);
|
||||
}
|
||||
HILOG_DEBUG("interceptorId_ is %{public}d.", interceptorId_);
|
||||
|
||||
if (availableFunctions_ & FEATURE_FILTER_KEY_EVENTS) {
|
||||
keyEventInterceptorId_ = inputManager_->AddInterceptor(InterceptKeyEventCallback);
|
||||
HILOG_DEBUG("keyEventInterceptorId_ is %{public}d.", keyEventInterceptorId_);
|
||||
}
|
||||
}
|
||||
|
||||
void AccessibilityInputInterceptor::InterceptKeyEventCallback(std::shared_ptr<MMI::KeyEvent> keyEvent)
|
||||
{
|
||||
HILOG_DEBUG(" start.");
|
||||
|
||||
if ((instance_ == nullptr) || (instance_->eventHandler_ == nullptr)) {
|
||||
HILOG_ERROR("eventHandler is nullptr.");
|
||||
|
||||
}
|
||||
auto task = std::bind(&AccessibilityInputInterceptor::ProcessKeyEvent, instance_, keyEvent);
|
||||
instance_->eventHandler_->PostTask(task, AppExecFwk::EventQueue::Priority::LOW);
|
||||
HILOG_DEBUG(" end.");
|
||||
}
|
||||
|
||||
void AccessibilityInputInterceptor::DestroyInterceptor()
|
||||
@ -179,6 +201,9 @@ void AccessibilityInputInterceptor::DestroyInterceptor()
|
||||
HILOG_DEBUG("inputManager_ is null.");
|
||||
return;
|
||||
}
|
||||
if (keyEventInterceptorId_ != -1) {
|
||||
inputManager_->RemoveInterceptor(keyEventInterceptorId_);
|
||||
}
|
||||
|
||||
if (interceptorId_ == -1) {
|
||||
HILOG_DEBUG("Interceptor is not added.");
|
||||
|
@ -674,7 +674,8 @@ void AccessibleAbilityManagerService::UpdateAbilities()
|
||||
if (accountData->GetEnabledAbilities().count(elementName)) {
|
||||
if (!connection) {
|
||||
// this is a temp deal for ace test
|
||||
installAbility.SetCapabilityValues(Capability::CAPABILITY_RETRIEVE);
|
||||
installAbility.SetCapabilityValues(Capability::CAPABILITY_RETRIEVE |
|
||||
Capability::CAPABILITY_KEY_EVENT_OBSERVER);
|
||||
connection = new AccessibleAbilityConnection(accountData, connectCounter_++, installAbility);
|
||||
connection->Connect(element);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user