Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentView.java b/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| index 5852968f79c6f9f234316343aace0e805265941c..e5921bc0bc1d84a04deeea2c67211dbca9e9385d 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| @@ -14,6 +14,7 @@ import android.os.Message; |
| import android.view.KeyEvent; |
| import android.view.MotionEvent; |
| import android.view.View; |
| +import android.view.ViewStructure; |
| import android.view.accessibility.AccessibilityNodeProvider; |
| import android.view.inputmethod.EditorInfo; |
| import android.view.inputmethod.InputConnection; |
| @@ -21,6 +22,10 @@ import android.widget.FrameLayout; |
| import org.chromium.base.Log; |
| import org.chromium.base.TraceEvent; |
| +import org.chromium.content_public.browser.AccessibilitySnapshotCallback; |
| +import org.chromium.content_public.browser.AccessibilitySnapshotNode; |
| + |
| +import java.util.Iterator; |
| /** |
| * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and |
| @@ -31,6 +36,14 @@ public class ContentView extends FrameLayout |
| private static final String TAG = "cr.ContentView"; |
| + /** |
| + * TODO(sgurun) remove these and use public API. crbug/512264 |
| + */ |
| + private static final int TEXT_STYLE_BOLD = 1 << 0; |
| + private static final int TEXT_STYLE_ITALIC = 1 << 1; |
| + private static final int TEXT_STYLE_UNDERLINE = 1 << 2; |
| + private static final int TEXT_STYLE_STRIKE_THRU = 1 << 3; |
| + |
| protected final ContentViewCore mContentViewCore; |
| /** |
| @@ -72,6 +85,48 @@ public class ContentView extends FrameLayout |
| } |
| } |
| + public void onProvideVirtualStructure(final ViewStructure structure) { |
|
Ted C
2015/07/21 00:35:48
I would add something like just so we know why it'
sgurun-gerrit only
2015/07/21 20:22:15
Done.
|
| + structure.setChildCount(1); |
| + final ViewStructure viewRoot = structure.asyncNewChild(0); |
| + mContentViewCore.getWebContents().requestAccessibilitySnapshot( |
| + new AccessibilitySnapshotCallback() { |
| + @Override |
| + public void onAccessibilitySnapshot(AccessibilitySnapshotNode root) { |
| + viewRoot.setClassName(""); |
| + if (root == null) { |
| + viewRoot.asyncCommit(); |
| + return; |
| + } |
| + createVirtualStructure(viewRoot, root, 0, 0); |
| + } |
| + }); |
| + } |
| + |
| + // When creating the View structure, the left and top are relative to the parent node. |
| + // The X scroll is not used, rather compensated through X-position, while the Y scroll |
| + // is provided. |
| + private void createVirtualStructure(ViewStructure viewNode, AccessibilitySnapshotNode node, |
| + int parentX, int parentY) { |
| + viewNode.setClassName(node.className); |
| + viewNode.setText(node.text); |
| + viewNode.setDimens(node.x - parentX - node.scrollX, node.y - parentY, 0, node.scrollY, |
| + node.width, node.height); |
| + viewNode.setChildCount(node.children.size()); |
| + if (node.hasStyle) { |
| + int style = (node.bold ? TEXT_STYLE_BOLD : 0) |
| + | (node.italic ? TEXT_STYLE_ITALIC : 0) |
| + | (node.underline ? TEXT_STYLE_UNDERLINE : 0) |
| + | (node.lineThrough ? TEXT_STYLE_STRIKE_THRU : 0); |
| + viewNode.setTextStyle(node.textSize, node.color, node.bgcolor, style); |
| + } |
| + final Iterator<AccessibilitySnapshotNode> children = node.children.listIterator(); |
| + int i = 0; |
| + while (children.hasNext()) { |
|
Ted C
2015/07/21 00:35:48
why not:
for (int i = 0; i < node.children.size()
sgurun-gerrit only
2015/07/21 20:22:15
Done.
|
| + createVirtualStructure(viewNode.asyncNewChild(i++), children.next(), node.x, node.y); |
| + } |
| + viewNode.asyncCommit(); |
| + } |
| + |
| // Needed by ContentViewCore.InternalAccessDelegate |
| @Override |
| public boolean drawChild(Canvas canvas, View child, long drawingTime) { |