Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtAccessibilityDelegate.java
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
5package org.qtproject.qt.android;
6
7import android.graphics.Rect;
8import android.os.Build;
9import android.os.Bundle;
10import android.system.Os;
11import android.text.SpannableString;
12import android.text.Spanned;
13import android.text.style.LocaleSpan;
14import android.text.TextUtils;
15import android.util.Log;
16import android.view.MotionEvent;
17import android.view.View;
18import android.view.ViewGroup;
19import android.view.ViewParent;
20import android.view.accessibility.AccessibilityEvent;
21import android.view.accessibility.AccessibilityManager;
22import android.view.accessibility.AccessibilityNodeInfo;
23import android.view.accessibility.AccessibilityNodeProvider;
24import java.util.Locale;
25
26class QtAccessibilityDelegate extends View.AccessibilityDelegate
27{
28 private static final String TAG = "Qt A11Y";
29
30 // Qt uses the upper half of the unsigned integers
31 // all low positive ints should be fine.
32 static final int INVALID_ID = 333; // half evil
33
34 private View m_view = null;
35 private AccessibilityManager m_manager;
36 private QtLayout m_layout;
37
38 // The accessible object that currently has the "accessibility focus"
39 // usually indicated by a yellow rectangle on screen.
40 private int m_focusedVirtualViewId = INVALID_ID;
41 // When exploring the screen by touch, the item "hovered" by the finger.
42 private int m_hoveredVirtualViewId = INVALID_ID;
43
44 // Cache coordinates of the view to know the global offset
45 // this is because the Android platform window does not take
46 // the offset of the view on screen into account (eg status bar on top)
47 private final int[] m_globalOffset = new int[2];
48 private int m_oldOffsetX = 0;
49 private int m_oldOffsetY = 0;
50
51 private class HoverEventListener implements View.OnHoverListener
52 {
54 public boolean onHover(View v, MotionEvent event)
55 {
56 return dispatchHoverEvent(event);
57 }
58 }
59 // TODO do we want to have one QtAccessibilityDelegate for the whole app (QtRootLayout) or
60 // e.g. one per window?
61 // FIXME make QtAccessibilityDelegate window based or verify current way works
62 // also for child windows: QTBUG-120685
63 QtAccessibilityDelegate() { }
64
65 void initLayoutAccessibility(QtLayout layout)
66 {
67 if (layout == null) {
68 Log.w(TAG, "Unable to initialize the accessibility delegate with a null layout");
69 return;
70 }
71
72 m_layout = layout;
73
74 m_manager = m_layout.getContext().getSystemService(AccessibilityManager.class);
75 if (m_manager != null) {
76 AccessibilityManagerListener accServiceListener = new AccessibilityManagerListener();
77 if (!m_manager.addAccessibilityStateChangeListener(accServiceListener))
78 Log.w("Qt A11y", "Could not register a11y state change listener");
79 if (m_manager.isEnabled())
80 accServiceListener.onAccessibilityStateChanged(true);
81 }
82 }
83
84 private class AccessibilityManagerListener
85 implements AccessibilityManager.AccessibilityStateChangeListener
86 {
88 public void onAccessibilityStateChanged(boolean enabled)
89 {
90 if (m_layout == null)
91 return;
92
93 final String isA11yOff = Os.getenv("QT_ANDROID_DISABLE_ACCESSIBILITY");
94 if (isA11yOff != null && (isA11yOff.equalsIgnoreCase("true") || isA11yOff.equals("1")))
95 return;
96
97 if (!enabled) {
98 if (m_view != null) {
99 m_layout.removeView(m_view);
100 m_view = null;
101 }
102 QtNativeAccessibility.setActive(enabled);
103 return;
104 }
105
106 try {
107 View view = m_view;
108 if (view == null) {
109 view = new View(m_layout.getContext());
110 view.setId(View.NO_ID);
111 }
112
113 // ### Keep this for debugging for a while. It allows us to visually see that our View
114 // ### is on top of the surface(s)
115 //noinspection CommentedOutCode
116 {
117 // ColorDrawable color = new ColorDrawable(0x80ff8080); //0xAARRGGBB
118 // view.setBackground(color);
119 }
120 view.setAccessibilityDelegate(QtAccessibilityDelegate.this);
121
122 // if all is fine, add it to the layout
123 if (m_view == null) {
124 //m_layout.addAccessibilityView(view);
125 m_layout.addView(view, m_layout.getChildCount(),
126 new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
127 ViewGroup.LayoutParams.MATCH_PARENT));
128 }
129 m_view = view;
130
131 m_view.setOnHoverListener(new HoverEventListener());
132 } catch (Exception e) {
133 // Unknown exception means something went wrong.
134 Log.w("Qt A11y", "Unknown exception: " + e);
135 }
136
137 QtNativeAccessibility.setActive(enabled);
138 }
139 }
140
141 @Override
142 public AccessibilityNodeProvider getAccessibilityNodeProvider(View host)
143 {
144 return m_nodeProvider;
145 }
146
147 // For "explore by touch" we need all movement events here first
148 // (user moves finger over screen to discover items on screen).
149 private boolean dispatchHoverEvent(MotionEvent event)
150 {
151 if (m_manager == null || !m_manager.isTouchExplorationEnabled()) {
152 return false;
153 }
154
155 int virtualViewId = QtNativeAccessibility.hitTest(event.getX(), event.getY());
156 if (virtualViewId == INVALID_ID) {
157 virtualViewId = View.NO_ID;
158 }
159
160 switch (event.getAction()) {
161 case MotionEvent.ACTION_HOVER_ENTER:
162 case MotionEvent.ACTION_HOVER_MOVE:
163 case MotionEvent.ACTION_HOVER_EXIT:
164 setHoveredVirtualViewId(virtualViewId);
165 break;
166 }
167
168 return true;
169 }
170
171 SpannableString addLocaleSpan(int viewId, String value)
172 {
173 SpannableString localeValue = new SpannableString(value);
174 LocaleSpan localeSpan =
175 new LocaleSpan(Locale.forLanguageTag(QtNativeAccessibility.languageTag(viewId)));
176 localeValue.setSpan(localeSpan, 0, localeValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
177 return localeValue;
178 }
179
180 void notifyScrolledEvent(int viewId)
181 {
182 QtNative.runAction(() -> sendEventForVirtualViewId(viewId,
183 AccessibilityEvent.TYPE_VIEW_SCROLLED));
184 }
185
186 void notifyLocationChange(int viewId)
187 {
188 QtNative.runAction(() -> {
189 if (m_focusedVirtualViewId == viewId)
190 invalidateVirtualViewId(m_focusedVirtualViewId);
191 });
192 }
193
194 void notifyObjectHide(int viewId, int parentId)
195 {
196 QtNative.runAction(() -> {
197 // If the object had accessibility focus, we need to clear it.
198 // Note: This code is mostly copied from
199 // AccessibilityNodeProvider::performAction, but we remove the
200 // focus only if the focused view id matches the one that was hidden.
201 if (m_view != null && m_focusedVirtualViewId == viewId) {
202 m_focusedVirtualViewId = INVALID_ID;
203 m_view.invalidate();
204 sendEventForVirtualViewId(viewId,
205 AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
206 }
207 // When the object is hidden, we need to notify its parent about
208 // content change, not the hidden object itself
209 invalidateVirtualViewId(parentId);
210 });
211 }
212
213 void notifyObjectShow(int parentId)
214 {
215 QtNative.runAction(() -> {
216 // When the object is shown, we need to notify its parent about
217 // content change, not the shown object itself
218 invalidateVirtualViewId(parentId);
219 });
220 }
221
222 void notifyObjectFocus(int viewId)
223 {
224 QtNative.runAction(() -> {
225 if (m_view == null || m_focusedVirtualViewId == viewId)
226 return;
227 m_focusedVirtualViewId = viewId;
228 m_view.invalidate();
229 sendEventForVirtualViewId(viewId,
230 AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
231 });
232 }
233
234 void notifyObjectDestroyed(int viewId, int parentId)
235 {
236 QtNative.runAction(() -> {
237 if (m_view != null && m_focusedVirtualViewId == viewId) {
238 m_focusedVirtualViewId = INVALID_ID;
239 m_view.invalidate();
240 sendEventForVirtualViewId(viewId,
241 AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
242 }
243 invalidateVirtualViewId(parentId);
244 });
245 }
246
247 void notifyObjectCreated(int parentId)
248 {
249 QtNative.runAction(() -> {
250 invalidateVirtualViewId(parentId);
251 });
252 }
253
254 void notifyValueChanged(int viewId)
255 {
256 notifyContentChanged(viewId, AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
257 }
258
259 private void notifyContentChanged(int viewId, int contentChangeType)
260 {
261 if (m_manager == null)
262 return;
263
264 QtNative.runAction(() -> {
265 if (m_view == null)
266 return;
267
268 if ((viewId == INVALID_ID) || !m_manager.isEnabled()) {
269 Log.w(TAG, "notifyContentChanged() for invalid view");
270 return;
271 }
272
273 final AccessibilityNodeInfo node = getNodeForVirtualViewId(viewId);
274 final AccessibilityEvent event =
275 obtainAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
276
277 event.setEnabled(true);
278 event.setClassName(node.getClassName());
279 event.setContentDescription(node.getContentDescription());
280 event.setContentChangeTypes(contentChangeType);
281
282 if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
283 Log.w(TAG, "No value to announce for " + event.getClassName());
284 return;
285 }
286
287 event.setPackageName(m_view.getContext().getPackageName());
288 event.setSource(m_view, viewId);
289
290 sendAccessibilityEvent(event);
291 });
292 }
293
294 void notifyDescriptionOrNameChanged(int viewId)
295 {
296 if (viewId == m_focusedVirtualViewId) {
297 notifyContentChanged(viewId,
298 AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION);
299 }
300 }
301
302 void notifyAnnouncementEvent(int viewId, String message)
303 {
304 QtNative.runAction(() -> {
305 if (m_view == null)
306 return;
307
308 if (viewId == INVALID_ID) {
309 Log.w(TAG, "notifyAnnouncementEvent() for invalid view");
310 return;
311 }
312
313 if (!m_manager.isEnabled()) {
314 Log.w(TAG, "notifyAnnouncementEvent for disabled AccessibilityManager");
315 return;
316 }
317
318 final AccessibilityEvent event =
319 obtainAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
320 event.getText().add(message);
321 event.setClassName(getNodeForVirtualViewId(viewId).getClassName());
322 event.setPackageName(m_view.getContext().getPackageName());
323 sendAccessibilityEvent(event);
324 });
325 }
326
327 void notifyTextChanged(int viewId, String text, String beforeText,
328 int fromIndex, int addedCount, int removedCount)
329 {
330 QtNative.runAction(() -> {
331 if (m_view == null || m_manager == null || !m_manager.isEnabled())
332 return;
333
334 // Source the event from the node that has accessibility focus, not
335 // the input-method focus object id (the two may differ).
336 final int targetId =
337 (m_focusedVirtualViewId != INVALID_ID) ? m_focusedVirtualViewId : viewId;
338 if (targetId == INVALID_ID) {
339 Log.w(TAG, "notifyTextChanged() with no focused view");
340 return;
341 }
342
343 // An editable view fires two events on each keystroke and a screen
344 // reader uses both to echo typing: TYPE_VIEW_TEXT_CHANGED (what
345 // changed) and TYPE_VIEW_TEXT_SELECTION_CHANGED (where the caret moved
346 // to). Both are sourced from the input-focused editable, which is what
347 // lets the screen reader speak typed/deleted characters even while
348 // accessibility focus is on the soft keyboard rather than the field.
349 final CharSequence className = getNodeForVirtualViewId(targetId).getClassName();
350 final String packageName = m_view.getContext().getPackageName();
351
352 final AccessibilityEvent event =
353 obtainAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
354 event.setSource(m_view, targetId);
355 event.setClassName(className);
356 event.setPackageName(packageName);
357 event.getText().add(text);
358 event.setBeforeText(beforeText);
359 event.setFromIndex(fromIndex);
360 event.setAddedCount(addedCount);
361 event.setRemovedCount(removedCount);
362 sendAccessibilityEvent(event);
363
364 // Companion caret/selection event (collapsed selection at the new
365 // caret = fromIndex + addedCount).
366 final int caret = fromIndex + addedCount;
367 final AccessibilityEvent selEvent =
368 obtainAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED);
369 selEvent.setSource(m_view, targetId);
370 selEvent.setClassName(className);
371 selEvent.setPackageName(packageName);
372 selEvent.getText().add(text);
373 selEvent.setFromIndex(caret);
374 selEvent.setToIndex(caret);
375 selEvent.setItemCount(text != null ? text.length() : 0);
376 selEvent.setCurrentItemIndex(caret);
377 sendAccessibilityEvent(selEvent);
378 });
379 }
380
381 void sendEventForVirtualViewId(int virtualViewId, int eventType)
382 {
383 final AccessibilityEvent event = getEventForVirtualViewId(virtualViewId, eventType);
384 sendAccessibilityEvent(event);
385 }
386
387 void sendAccessibilityEvent(AccessibilityEvent event)
388 {
389 if (m_view == null || event == null)
390 return;
391
392 final ViewGroup group = (ViewGroup) m_view.getParent();
393 if (group == null) {
394 Log.w(TAG, "Could not send AccessibilityEvent because group was null. " +
395 "This should really not happen.");
396 return;
397 }
398
399 group.requestSendAccessibilityEvent(m_view, event);
400 }
401
402 void invalidateVirtualViewId(int virtualViewId)
403 {
404 final AccessibilityEvent event = getEventForVirtualViewId(virtualViewId,
405 AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
406
407 if (event == null)
408 return;
409
410 event.setContentChangeTypes(AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE);
411 sendAccessibilityEvent(event);
412 }
413
414 private void setHoveredVirtualViewId(int virtualViewId)
415 {
416 if (m_hoveredVirtualViewId == virtualViewId) {
417 return;
418 }
419
420 final int previousVirtualViewId = m_hoveredVirtualViewId;
421 m_hoveredVirtualViewId = virtualViewId;
422 sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
423 sendEventForVirtualViewId(previousVirtualViewId, AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
424 }
425
426 private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType)
427 {
428 final boolean isManagerEnabled = m_manager != null && m_manager.isEnabled();
429 if (m_view == null || !isManagerEnabled || (virtualViewId == INVALID_ID)) {
430 Log.w(TAG, "getEventForVirtualViewId for invalid view");
431 return null;
432 }
433
434 if (m_layout == null || m_layout.getChildCount() == 0)
435 return null;
436
437 final AccessibilityEvent event = obtainAccessibilityEvent(eventType);
438
439 event.setEnabled(true);
440 event.setClassName(getNodeForVirtualViewId(virtualViewId).getClassName());
441
442 String description = QtNativeAccessibility.descriptionForAccessibleObject(virtualViewId);
443 event.setContentDescription(addLocaleSpan(virtualViewId, description));
444
445 if (eventType == AccessibilityEvent.TYPE_VIEW_SCROLLED)
446 QtNativeAccessibility.populateScrollEvent(virtualViewId, event);
447
448 if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription()))
449 Log.w(TAG, "AccessibilityEvent with empty description");
450
451 event.setPackageName(m_view.getContext().getPackageName());
452 event.setSource(m_view, virtualViewId);
453 return event;
454 }
455
456 // This can be used for debug by performActionForVirtualViewId()
458 private void dumpNodes(int parentId)
459 {
460 Log.i(TAG, "A11Y hierarchy: " + parentId + " parent: " + QtNativeAccessibility.parentId(parentId));
461 Log.i(TAG, " desc: " + QtNativeAccessibility.descriptionForAccessibleObject(parentId) + " rect: " + QtNativeAccessibility.screenRect(parentId));
462 Log.i(TAG, " NODE: " + getNodeForVirtualViewId(parentId));
463 int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(parentId);
464 for (int id : ids) {
465 Log.i(TAG, parentId + " has child: " + id);
466 dumpNodes(id);
467 }
468 }
469
470 private AccessibilityNodeInfo getNodeForView()
471 {
472 if (m_view == null || m_layout == null)
473 return obtainAccessibilityNodeInfo();
474
475 // Since we don't want the parent to be focusable, but we can't remove
476 // actions from a node, copy over the necessary fields.
477 final AccessibilityNodeInfo result = obtainAccessibilityNodeInfo(m_view);
478 final AccessibilityNodeInfo source = obtainAccessibilityNodeInfo(m_view);
479 m_view.onInitializeAccessibilityNodeInfo(source);
480
481 // Get the actual position on screen, taking the status bar into account.
482 m_view.getLocationOnScreen(m_globalOffset);
483 final int offsetX = m_globalOffset[0];
484 final int offsetY = m_globalOffset[1];
485
486 // Copy over parent and screen bounds.
487 final Rect m_tempParentRect = new Rect();
488 getBoundsInParent(source, m_tempParentRect);
489 setBoundsInParent(result, m_tempParentRect);
490
491 final Rect m_tempScreenRect = new Rect();
492 source.getBoundsInScreen(m_tempScreenRect);
493 m_tempScreenRect.offset(offsetX, offsetY);
494 result.setBoundsInScreen(m_tempScreenRect);
495
496 // Set up the parent view, if applicable.
497 final ViewParent parent = m_view.getParent();
498 if (parent instanceof View) {
499 result.setParent((View) parent);
500 }
501
502 result.setVisibleToUser(source.isVisibleToUser());
503 result.setPackageName(source.getPackageName());
504 result.setClassName(source.getClassName());
505
506 // Spit out the entire hierarchy for debugging purposes
507 // dumpNodes(-1);
508
509 if (m_layout.getChildCount() != 0) {
510 int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(-1);
511 for (int id : ids)
512 result.addChild(m_view, id);
513 }
514
515 // The offset values have changed, so we need to re-focus the
516 // currently focused item, otherwise it will have an incorrect
517 // focus frame
518 if ((m_oldOffsetX != offsetX) || (m_oldOffsetY != offsetY)) {
519 m_oldOffsetX = offsetX;
520 m_oldOffsetY = offsetY;
521 if (m_focusedVirtualViewId != INVALID_ID) {
522 m_nodeProvider.performAction(m_focusedVirtualViewId,
523 AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
524 new Bundle());
525 m_nodeProvider.performAction(m_focusedVirtualViewId,
526 AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS,
527 new Bundle());
528 }
529 }
530
531 return result;
532 }
533
534 private AccessibilityNodeInfo getNodeForVirtualViewId(int virtualViewId)
535 {
536 if (m_view == null || m_layout == null)
537 return obtainAccessibilityNodeInfo();
538
539 final AccessibilityNodeInfo node = obtainAccessibilityNodeInfo();
540
541 node.setPackageName(m_view.getContext().getPackageName());
542
543 if (m_layout.getChildCount() == 0 || !QtNativeAccessibility.populateNode(virtualViewId, node)) {
544 return node;
545 }
546
547 // set only if valid, otherwise we return a node that is invalid and will crash when accessed
548 node.setSource(m_view, virtualViewId);
549
550 CharSequence contentDescription = node.getContentDescription();
551 if (!TextUtils.isEmpty(contentDescription))
552 node.setContentDescription(addLocaleSpan(virtualViewId, contentDescription.toString()));
553 else if (TextUtils.isEmpty(node.getText()))
554 Log.w(TAG, "AccessibilityNodeInfo with empty contentDescription: " + virtualViewId);
555
556 int parentId = QtNativeAccessibility.parentId(virtualViewId);
557 node.setParent(m_view, parentId);
558
559 Rect screenRect = QtNativeAccessibility.screenRect(virtualViewId);
560 final int offsetX = m_globalOffset[0];
561 final int offsetY = m_globalOffset[1];
562 screenRect.offset(offsetX, offsetY);
563 node.setBoundsInScreen(screenRect);
564
565 Rect parentScreenRect = QtNativeAccessibility.screenRect(parentId);
566 screenRect.offset(-parentScreenRect.left, -parentScreenRect.top);
567 setBoundsInParent(node, screenRect);
568
569 node.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SHOW_ON_SCREEN);
570
571 // Manage internal accessibility focus state.
572 if (m_focusedVirtualViewId == virtualViewId) {
573 node.setAccessibilityFocused(true);
574 node.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
575 } else {
576 node.setAccessibilityFocused(false);
577 node.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_ACCESSIBILITY_FOCUS);
578 }
579
580 int[] ids = QtNativeAccessibility.childIdListForAccessibleObject(virtualViewId);
581 for (int id : ids)
582 node.addChild(m_view, id);
583
584 return node;
585 }
586
587 private final AccessibilityNodeProvider m_nodeProvider = new AccessibilityNodeProvider()
588 {
589 @Override
590 public AccessibilityNodeInfo createAccessibilityNodeInfo(int virtualViewId)
591 {
592 if (virtualViewId == View.NO_ID || m_layout.getChildCount() == 0) {
593 return getNodeForView();
594 }
595 return getNodeForVirtualViewId(virtualViewId);
596 }
597
598 @Override
599 public boolean performAction(int virtualViewId, int action, Bundle arguments)
600 {
601 if (m_view == null) {
602 Log.e(TAG, "Unable to perform action with a null view");
603 return false;
604 }
605
606 boolean handled = false;
607 //Log.i(TAG, "PERFORM ACTION: " + action + " on " + virtualViewId);
608 if (action == AccessibilityNodeInfo.AccessibilityAction.ACTION_SHOW_ON_SCREEN.getId()) {
609 handled = QtNativeAccessibility.showOnScreen(virtualViewId);
610 notifyScrolledEvent(virtualViewId);
611 }
612 switch (action) {
613 case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
614 if (m_focusedVirtualViewId == virtualViewId) {
615 m_focusedVirtualViewId = INVALID_ID;
616 }
617 // Since we're managing focus at the parent level, we are
618 // likely to receive a FOCUS action before a CLEAR_FOCUS
619 // action. We'll give the benefit of the doubt to the
620 // framework and always handle FOCUS_CLEARED.
621 m_view.invalidate();
622 sendEventForVirtualViewId(virtualViewId,
623 AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
624 handled |= true;
625 break;
626 default:
627 // Let the node provider handle focus for the view node.
628 if (virtualViewId == View.NO_ID) {
629 return m_view.performAccessibilityAction(action, arguments);
630 }
631 }
632 handled |= performActionForVirtualViewId(virtualViewId, action);
633
634 return handled;
635 }
636 };
637
638 protected boolean performActionForVirtualViewId(int virtualViewId, int action)
639 {
640 //noinspection CommentedOutCode
641 {
642 // Log.i(TAG, "ACTION " + action + " on " + virtualViewId);
643 // dumpNodes(virtualViewId);
644 }
645 boolean success = false;
646 switch (action) {
647 case AccessibilityNodeInfo.ACTION_CLICK:
648 success = QtNativeAccessibility.clickAction(virtualViewId);
649 if (success)
650 sendEventForVirtualViewId(virtualViewId, AccessibilityEvent.TYPE_VIEW_CLICKED);
651 break;
652 case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
653 if (m_focusedVirtualViewId != virtualViewId) {
654 QtNativeAccessibility.focusAction(virtualViewId);
655 } else {
656 // Focus is returning from another window (e.g. the TalkBack menu)
657 // without prior CLEAR_FOCUS. Reset to force notifyObjectFocus() to
658 // go through.
659 m_focusedVirtualViewId = INVALID_ID;
660 }
661 notifyObjectFocus(virtualViewId);
662 success = true;
663 break;
664 case AccessibilityNodeInfo.ACTION_SCROLL_FORWARD:
665 success = QtNativeAccessibility.scrollForward(virtualViewId);
666 break;
667 case AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD:
668 success = QtNativeAccessibility.scrollBackward(virtualViewId);
669 break;
670 case AccessibilityNodeInfo.ACTION_EXPAND:
671 success = QtNativeAccessibility.expand(virtualViewId);
672 break;
673 case AccessibilityNodeInfo.ACTION_COLLAPSE:
674 success = QtNativeAccessibility.collapse(virtualViewId);
675 break;
676 }
677 return success;
678 }
679
680 @SuppressWarnings("deprecation")
681 private AccessibilityEvent obtainAccessibilityEvent(int eventType) {
682 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
683 return new AccessibilityEvent(eventType);
684 } else {
685 return AccessibilityEvent.obtain(eventType);
686 }
687 }
688
689 @SuppressWarnings("deprecation")
690 private AccessibilityNodeInfo obtainAccessibilityNodeInfo() {
691 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
692 return new AccessibilityNodeInfo();
693 } else {
694 return AccessibilityNodeInfo.obtain();
695 }
696 }
697
698 @SuppressWarnings("deprecation")
699 private AccessibilityNodeInfo obtainAccessibilityNodeInfo(View source) {
700 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
701 return new AccessibilityNodeInfo(source);
702 } else {
703 return AccessibilityNodeInfo.obtain(source);
704 }
705 }
706
707 @SuppressWarnings("deprecation")
708 private void getBoundsInParent(AccessibilityNodeInfo node, Rect outBounds) {
709 node.getBoundsInParent(outBounds);
710 }
711
712 @SuppressWarnings("deprecation")
713 private void setBoundsInParent(AccessibilityNodeInfo node, Rect bounds) {
714 node.setBoundsInParent(bounds);
715 }
716}
QList< QVariant > arguments
QMap< Name, StatePointer > Bundle
Definition lalr.h:46
Napi::String String
Definition qnapi_p.h:70
EGLOutputLayerEXT EGLint EGLAttrib value
[3]
GLenum GLenum GLsizei const GLuint * ids
[qttrid_noop]
GLuint GLsizei const GLchar * message
GLboolean GLuint group
GLsizei const GLfloat * v
GLsizei GLsizei GLchar * source
struct _cl_event * event
GLuint64EXT * result
[6]
#define enabled
QQuickView * view
[0]