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