Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b84b94e1 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Scroll accessibility events should not populate text.

Scroll events are used to report position change and should not
contain the text content of the view that fires them because it
is usiually a containter for many other views and the text will
be long and not informative for accessibility purposes. Also
such evens are fired relatively frequently. If a client wants
to fetch some textual content for a scroll event he can use
the interrogation APIs.

bug:5352059

Change-Id: I43e02aca895c8ab16ba82ebe1cee3aea8ce7711a
parent 04ef5b8d
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3900,6 +3900,12 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     * Note: Called from the default {@link AccessibilityDelegate}.
     */
    boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        // Do not populate text to scroll events. They describe position change
        // and usually come from container with a lot of text which is not very
        // informative for accessibility purposes. Also they are fired frequently.
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            return true;
        }
        onPopulateAccessibilityEvent(event);
        return false;
    }
+5 −3
Original line number Diff line number Diff line
@@ -2176,13 +2176,15 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager

    @Override
    boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        // We first get a chance to populate the event.
        super.dispatchPopulateAccessibilityEventInternal(event);
        boolean handled = super.dispatchPopulateAccessibilityEventInternal(event);
        if (handled) {
            return handled;
        }
        // Let our children have a shot in populating the event.
        for (int i = 0, count = getChildCount(); i < count; i++) {
            View child = getChildAt(i);
            if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
                boolean handled = getChildAt(i).dispatchPopulateAccessibilityEvent(event);
                handled = getChildAt(i).dispatchPopulateAccessibilityEvent(event);
                if (handled) {
                    return handled;
                }
+0 −10
Original line number Diff line number Diff line
@@ -1304,16 +1304,6 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }
    }

    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        // Do not append text content to scroll events they are fired frequently
        // and the client has already received another event type with the text.
        if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            super.dispatchPopulateAccessibilityEvent(event);
        }
        return false;
    }

    /**
     * Indicates whether the children's drawing cache is used during a scroll.
     * By default, the drawing cache is enabled but this will consume more memory.
+15 −16
Original line number Diff line number Diff line
@@ -881,6 +881,12 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {

    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        final int eventType = event.getEventType();
        switch (eventType) {
            case AccessibilityEvent.TYPE_VIEW_SCROLLED:
                // Do not populate the text of scroll events.
                return true;
            case AccessibilityEvent.TYPE_VIEW_FOCUSED:
                // This is an exceptional case which occurs when a window gets the
                // focus and sends a focus event via its focused child to announce
                // current focus/selection. AdapterView fires selection but not focus
@@ -888,23 +894,16 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
                if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
                    event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
                }
                break;
        }

        View selectedView = getSelectedView();
        if (selectedView != null && selectedView.getVisibility() == VISIBLE) {
            // We first get a chance to populate the event.
            onPopulateAccessibilityEvent(event);
            getSelectedView().dispatchPopulateAccessibilityEvent(event);
        }
        return false;
    }

    @Override
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);
        // We send selection events only from AdapterView to avoid
        // generation of such event for each child.
        getSelectedView().dispatchPopulateAccessibilityEvent(event);
    }

    @Override
    public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
        if (super.onRequestSendAccessibilityEvent(child, event)) {