Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 10832104: Start upstreaming accessibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Dan's Nits Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 6365569e2f3dbfa1bc62fec12aebfe06b3fcb947..2b98b6174351c122051cfd0923bee1c1780e3259 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -7,6 +7,7 @@ package org.chromium.content.browser;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Canvas;
+import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
@@ -14,6 +15,8 @@ import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityNodeInfo;
import android.webkit.DownloadListener;
import org.chromium.base.CalledByNative;
@@ -24,6 +27,7 @@ import org.chromium.content.browser.TouchPoint;
import org.chromium.content.browser.ZoomManager;
import org.chromium.content.common.TraceEvent;
+import org.chromium.content.browser.accessibility.AccessibilityInjector;
import org.chromium.content.browser.ContentViewGestureHandler.MotionEventDelegate;
/**
@@ -164,6 +168,9 @@ public class ContentViewCore implements MotionEventDelegate {
// over DownloadListener.
private ContentViewDownloadDelegate mDownloadDelegate;
+ // The AccessibilityInjector that handles loading Accessibility scripts into the web page.
+ private final AccessibilityInjector mAccessibilityInjector;
+
/**
* Enable multi-process ContentView. This should be called by the application before
* constructing any ContentView instances. If enabled, ContentView will run renderers in
@@ -221,6 +228,9 @@ public class ContentViewCore implements MotionEventDelegate {
AndroidBrowserProcess.initContentViewProcess(
context, AndroidBrowserProcess.MAX_RENDERERS_SINGLE_PROCESS);
+ mAccessibilityInjector = AccessibilityInjector.newInstance(this);
+ mAccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary();
+
initialize(context, nativeWebContents, personality);
}
@@ -356,6 +366,7 @@ public class ContentViewCore implements MotionEventDelegate {
* omnibox can report suggestions correctly.
*/
public void loadUrlWithoutUrlSanitization(String url, int pageTransition) {
+ mAccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary();
if (mNativeContentViewCore != 0) {
if (isPersonalityView()) {
nativeLoadUrlWithoutUrlSanitizationWithUserAgentOverride(
@@ -472,6 +483,7 @@ public class ContentViewCore implements MotionEventDelegate {
* Reload the current page.
*/
public void reload() {
+ mAccessibilityInjector.addOrRemoveAccessibilityApisIfNecessary();
if (mNativeContentViewCore != 0) nativeReload(mNativeContentViewCore);
}
@@ -593,19 +605,35 @@ public class ContentViewCore implements MotionEventDelegate {
}
/**
- * This method should be called when the containing activity is paused
+ * This method should be called when the containing activity is paused.
*/
public void onActivityPause() {
TraceEvent.begin();
hidePopupDialog();
+ setAccessibilityState(false);
TraceEvent.end();
}
/**
- * Called when the ContentView is hidden.
+ * This method should be called when the containing activity is resumed.
+ */
+ public void onActivityResume() {
+ setAccessibilityState(true);
+ }
+
+ /**
+ * To be called when the ContentView is shown.
+ */
+ public void onShow() {
+ setAccessibilityState(true);
+ }
+
+ /**
+ * To be called when the ContentView is hidden.
*/
public void onHide() {
hidePopupDialog();
+ setAccessibilityState(false);
}
/**
@@ -633,6 +661,22 @@ public class ContentViewCore implements MotionEventDelegate {
SelectPopupDialog.hide(this);
}
+ /**
+ * @see View#onAttachedToWindow()
+ */
+ @SuppressWarnings("javadoc")
+ protected void onAttachedToWindow() {
+ setAccessibilityState(true);
+ }
+
+ /**
+ * @see View#onDetachedFromWindow()
+ */
+ @SuppressWarnings("javadoc")
+ protected void onDetachedFromWindow() {
+ setAccessibilityState(false);
+ }
+
// End FrameLayout overrides.
/**
@@ -1000,6 +1044,57 @@ public class ContentViewCore implements MotionEventDelegate {
getContentViewClient().onStartContentIntent(getContext(), contentUrl);
}
+ /**
+ * Determines whether or not this ContentViewCore can handle this accessibility action.
+ * @param action The action to perform.
+ * @return Whether or not this action is supported.
+ */
+ public boolean supportsAccessibilityAction(int action) {
+ return mAccessibilityInjector.supportsAccessibilityAction(action);
+ }
+
+ /**
+ * Attempts to perform an accessibility action on the web content. If the accessibility action
+ * cannot be processed, it returns {@code null}, allowing the caller to know to call the
+ * super {@link View#performAccessibilityAction(int, Bundle)} method and use that return value.
+ * Otherwise the return value from this method should be used.
+ * @param action The action to perform.
+ * @param arguments Optional action arguments.
+ * @return Whether the action was performed or {@code null} if the call should be delegated to
+ * the super {@link View} class.
+ */
+ public boolean performAccessibilityAction(int action, Bundle arguments) {
+ if (mAccessibilityInjector.supportsAccessibilityAction(action)) {
+ return mAccessibilityInjector.performAccessibilityAction(action, arguments);
+ }
+
+ return false;
+ }
+
+ /**
+ * @see View#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)
+ */
+ public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
+ mAccessibilityInjector.onInitializeAccessibilityNodeInfo(info);
+
+ // TODO(dtrainor): Upstream accessibility scrolling event information once that data is
+ // available in ContentViewCore. Currently internal scrolling variables aren't upstreamed.
+ }
+
+ /**
+ * @see View#onInitializeAccessibilityEvent(AccessibilityEvent)
+ */
+ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+ event.setClassName(this.getClass().getName());
+ }
+
+ /**
+ * Enable or disable accessibility features.
+ */
+ public void setAccessibilityState(boolean state) {
+ mAccessibilityInjector.setScriptEnabled(state);
+ }
+
// The following methods are implemented at native side.
/**

Powered by Google App Engine
This is Rietveld 408576698