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

Commit 12bed78d authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Fixing bugs 3315632 3235958, performing a clean up of the WebView...

Fixing bugs 3315632 3235958, performing a clean up of the WebView accessibility feature. Updated event hadndling to deliver all key events to javaScript if a screen reader is injected since the latter is responsible for the full set of navigation and exploration actions.

Change-Id: Id1639828559161e0850dee04baa0a7afb2576ea8
parent 47fc50e5
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -139,9 +139,8 @@ class AccessibilityInjector {
                    break;
                case ACTION_TRAVERSE_CURRENT_AXIS:
                    int direction = binding.getFirstArgument(i);
                    // on second null selection string in same direction => WebView handle the event
                    // on second null selection string in same direction - WebView handles the event
                    if (direction == mLastDirection && mIsLastSelectionStringNull) {
                        mLastDirection = direction;
                        mIsLastSelectionStringNull = false;
                        return false;
                    }
@@ -259,7 +258,13 @@ class AccessibilityInjector {
     * Called when the <code>selectionString</code> has changed.
     */
    public void onSelectionStringChange(String selectionString) {
        if (DEBUG) {
            Log.d(LOG_TAG, "Selection string: " + selectionString);
        }
        mIsLastSelectionStringNull = (selectionString == null);
        if (mScheduledEventStack.isEmpty()) {
            return;
        }
        AccessibilityEvent event = mScheduledEventStack.pop();
        if (event != null) {
            event.getText().add(selectionString);
@@ -312,25 +317,22 @@ class AccessibilityInjector {
        while (semiColonSplitter.hasNext()) {
            String bindingString = semiColonSplitter.next();
            if (TextUtils.isEmpty(bindingString)) {
                Log.e(LOG_TAG, "Malformed Web content key binding: "
                Log.e(LOG_TAG, "Disregarding malformed Web content key binding: "
                        + webContentKeyBindingsString);
                continue;
            }
            String[] keyValueArray = bindingString.split("=");
            if (keyValueArray.length != 2) {
                Log.e(LOG_TAG, "Disregarding malformed Web content key binding: " +
                        bindingString);
                Log.e(LOG_TAG, "Disregarding malformed Web content key binding: " + bindingString);
                continue;
            }
            try {
                SimpleStringSplitter colonSplitter = new SimpleStringSplitter(':');//remove
                int key = Integer.decode(keyValueArray[0].trim());
                String[] actionStrings = keyValueArray[1].split(":");
                int[] actions = new int[actionStrings.length];
                for (int i = 0, count = actions.length; i < count; i++) {
                    actions[i] = Integer.decode(actionStrings[i].trim());
                }

                bindings.add(new AccessibilityWebContentKeyBinding(key, actions));
            } catch (NumberFormatException nfe) {
                Log.e(LOG_TAG, "Disregarding malformed key binding: " + bindingString);
+31 −10
Original line number Diff line number Diff line
@@ -3270,6 +3270,9 @@ public class WebView extends AbsoluteLayout
     * @param url The URL loaded by this {@link WebView}.
     */
    private void injectAccessibilityForUrl(String url) {
        if (mWebViewCore == null) {
            return;
        }
        AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(mContext);

        if (!accessibilityManager.isEnabled()) {
@@ -3318,8 +3321,10 @@ public class WebView extends AbsoluteLayout
     * @param present True to ensure an insance, false to ensure no instance.
     */
    private void ensureAccessibilityScriptInjectorInstance(boolean present) {
        if (present && mAccessibilityInjector == null) {
        if (present) {
            if (mAccessibilityInjector == null) {
                mAccessibilityInjector = new AccessibilityInjector(this);
            }
        } else {
            mAccessibilityInjector = null;
        }
@@ -4513,9 +4518,17 @@ public class WebView extends AbsoluteLayout
            return false;
        }

        // if an accessibility script is injected we delegate to it the key handling.
        // this script is a screen reader which is a fully fledged solution for blind
        // users to navigate in and interact with web pages.
        if (accessibilityScriptInjected()) {
            mWebViewCore.sendMessage(EventHub.KEY_DOWN, event);
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
                || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
            if (!pageShouldHandleShiftAndArrows() && !nativeCursorWantsKeyEvents()
            if (!nativePageShouldHandleShiftAndArrows() && !nativeCursorWantsKeyEvents()
                    && !mSelectingText) {
                setUpSelect();
            }
@@ -4534,7 +4547,7 @@ public class WebView extends AbsoluteLayout
        if (keyCode >= KeyEvent.KEYCODE_DPAD_UP
                && keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT) {
            switchOutDrawHistory();
            if (pageShouldHandleShiftAndArrows()) {
            if (nativePageShouldHandleShiftAndArrows()) {
                letPageHandleNavKey(keyCode, event.getEventTime(), true, event.getMetaState());
                return true;
            }
@@ -4665,9 +4678,17 @@ public class WebView extends AbsoluteLayout
            return false;
        }

        // if an accessibility script is injected we delegate to it the key handling.
        // this script is a screen reader which is a fully fledged solution for blind
        // users to navigate in and interact with web pages.
        if (accessibilityScriptInjected()) {
            mWebViewCore.sendMessage(EventHub.KEY_UP, event);
            return true;
        }

        if (keyCode == KeyEvent.KEYCODE_SHIFT_LEFT
                || keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT) {
            if (!pageShouldHandleShiftAndArrows() && copySelection()) {
            if (!nativePageShouldHandleShiftAndArrows() && copySelection()) {
                selectionDone();
                return true;
            }
@@ -4675,7 +4696,7 @@ public class WebView extends AbsoluteLayout

        if (keyCode >= KeyEvent.KEYCODE_DPAD_UP
                && keyCode <= KeyEvent.KEYCODE_DPAD_RIGHT) {
            if (pageShouldHandleShiftAndArrows()) {
            if (nativePageShouldHandleShiftAndArrows()) {
                letPageHandleNavKey(keyCode, event.getEventTime(), false, event.getMetaState());
                return true;
            }
@@ -6003,7 +6024,7 @@ public class WebView extends AbsoluteLayout
            return false; // let common code in onKeyUp at it
        }
        if ((mMapTrackballToArrowKeys && (ev.getMetaState() & KeyEvent.META_SHIFT_ON) == 0) ||
                (mAccessibilityInjector != null || mAccessibilityScriptInjected)) {
                AccessibilityManager.getInstance(mContext).isEnabled()) {
            if (DebugFlags.WEB_VIEW) Log.v(LOGTAG, "onTrackballEvent gmail quit");
            return false;
        }
@@ -7859,13 +7880,13 @@ public class WebView extends AbsoluteLayout
    }

    /**
     * @return If the page should receive Shift and arrows.
     * @return Whether accessibility script has been injected.
     */
    private boolean pageShouldHandleShiftAndArrows() {
    private boolean accessibilityScriptInjected() {
        // TODO: Maybe the injected script should announce its presence in
        // the page meta-tag so the nativePageShouldHandleShiftAndArrows
        // will check that as one of the conditions it looks for
        return (nativePageShouldHandleShiftAndArrows() || mAccessibilityScriptInjected);
        return mAccessibilityScriptInjected;
    }

    /**