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

Unified Diff: content/browser/web_contents/web_contents_android.cc

Issue 2808383004: Refactor and send voice interaction structure (Closed)
Patch Set: fix WmShell position Created 3 years, 8 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/browser/web_contents/web_contents_android.cc
diff --git a/content/browser/web_contents/web_contents_android.cc b/content/browser/web_contents/web_contents_android.cc
index 033dcee5d2183e3567339f0af22c3d73d4cc43da..99ab35b20ed82b6d3583316c2d1d1f445bd77f51 100644
--- a/content/browser/web_contents/web_contents_android.cc
+++ b/content/browser/web_contents/web_contents_android.cc
@@ -38,6 +38,7 @@
#include "jni/WebContentsImpl_jni.h"
#include "net/android/network_library.h"
#include "ui/accessibility/ax_node_data.h"
+#include "ui/accessibility/platform/ax_android_snapshot.h"
#include "ui/android/overscroll_refresh_handler.h"
#include "ui/android/window_android.h"
#include "ui/gfx/android/java_bitmap.h"
@@ -82,90 +83,29 @@ void SmartClipCallback(const ScopedJavaGlobalRef<jobject>& callback,
Java_WebContentsImpl_onSmartClipDataExtracted(env, jtext, jhtml, callback);
}
-struct AccessibilitySnapshotParams {
- AccessibilitySnapshotParams()
- : has_tree_data(false), should_select_leaf_nodes(false) {}
-
- bool has_tree_data;
- // The current text selection within this tree, if any, expressed as the
- // node ID and character offset of the anchor (selection start) and focus
- // (selection end).
- int32_t sel_anchor_object_id;
- int32_t sel_anchor_offset;
- int32_t sel_focus_object_id;
- int32_t sel_focus_offset;
- // if the flag is true, mark the leaf node as selected.
- bool should_select_leaf_nodes;
-};
-
-ScopedJavaLocalRef<jobject> WalkAXTreeDepthFirst(
+ScopedJavaLocalRef<jobject> CreateJavaAXSnapshot(
JNIEnv* env,
- BrowserAccessibilityAndroid* node,
- const gfx::Rect& parent_rect,
- AccessibilitySnapshotParams* params) {
+ const ui::AXSnapshotNodeAndroid* node,
+ bool is_root) {
ScopedJavaLocalRef<jstring> j_text =
- ConvertUTF16ToJavaString(env, node->GetText());
+ ConvertUTF16ToJavaString(env, node->text);
ScopedJavaLocalRef<jstring> j_class =
- ConvertUTF8ToJavaString(env, node->GetClassName());
- // The style attributes exists and valid if size attribute exists. Otherwise,
- // they are not. Use a negative size information to indicate the existence
- // of style information.
- float size = -1.0;
- int color = 0;
- int bgcolor = 0;
- int text_style = 0;
-
- if (node->HasFloatAttribute(ui::AX_ATTR_FONT_SIZE)) {
- color = node->GetIntAttribute(ui::AX_ATTR_COLOR);
- bgcolor = node->GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR);
- text_style = node->GetIntAttribute(ui::AX_ATTR_TEXT_STYLE);
-
- // The font size is just the computed style for that element; apply
- // transformations to get the actual pixel size.
- gfx::RectF text_size_rect(
- 0, 0, 1, node->GetFloatAttribute(ui::AX_ATTR_FONT_SIZE));
- gfx::Rect scaled_text_size_rect = node->RelativeToAbsoluteBounds(
- text_size_rect, false);
- size = scaled_text_size_rect.height();
- }
-
- const gfx::Rect& absolute_rect = node->GetPageBoundsRect();
- gfx::Rect parent_relative_rect = absolute_rect;
- bool is_root = node->PlatformGetParent() == nullptr;
- if (!is_root) {
- parent_relative_rect.Offset(-parent_rect.OffsetFromOrigin());
- }
+ ConvertUTF8ToJavaString(env, node->class_name);
ScopedJavaLocalRef<jobject> j_node =
Java_WebContentsImpl_createAccessibilitySnapshotNode(
- env, parent_relative_rect.x(), parent_relative_rect.y(),
- absolute_rect.width(), absolute_rect.height(), is_root, j_text, color,
- bgcolor, size, text_style, j_class);
-
- if (params->has_tree_data && node->PlatformIsLeaf()) {
- int start_selection = 0;
- int end_selection = 0;
- if (params->sel_anchor_object_id == node->GetId()) {
- start_selection = params->sel_anchor_offset;
- params->should_select_leaf_nodes = true;
- }
- if (params->should_select_leaf_nodes)
- end_selection = node->GetText().length();
-
- if (params->sel_focus_object_id == node->GetId()) {
- end_selection = params->sel_focus_offset;
- params->should_select_leaf_nodes = false;
- }
- if (end_selection > 0)
- Java_WebContentsImpl_setAccessibilitySnapshotSelection(
- env, j_node, start_selection, end_selection);
+ env, node->rect.x(), node->rect.y(), node->rect.width(),
+ node->rect.height(), is_root, j_text, node->color, node->bgcolor,
+ node->text_size, node->bold, node->italic, node->underline,
+ node->line_through, j_class);
+
+ if (node->has_selection) {
+ Java_WebContentsImpl_setAccessibilitySnapshotSelection(
+ env, j_node, node->start_selection, node->end_selection);
}
- for (uint32_t i = 0; i < node->PlatformChildCount(); i++) {
- BrowserAccessibilityAndroid* child =
- static_cast<BrowserAccessibilityAndroid*>(
- node->PlatformGetChild(i));
+ for (auto& child : node->children) {
Java_WebContentsImpl_addAccessibilityNodeAsChild(
- env, j_node, WalkAXTreeDepthFirst(env, child, absolute_rect, params));
+ env, j_node, CreateJavaAXSnapshot(env, child.get(), false));
}
return j_node;
}
@@ -178,23 +118,9 @@ void AXTreeSnapshotCallback(const ScopedJavaGlobalRef<jobject>& callback,
Java_WebContentsImpl_onAccessibilitySnapshot(env, nullptr, callback);
return;
}
- std::unique_ptr<BrowserAccessibilityManagerAndroid> manager(
- static_cast<BrowserAccessibilityManagerAndroid*>(
- BrowserAccessibilityManager::Create(result, nullptr)));
- manager->set_prune_tree_for_screen_reader(false);
- BrowserAccessibilityAndroid* root =
- static_cast<BrowserAccessibilityAndroid*>(manager->GetRoot());
- AccessibilitySnapshotParams params;
- if (result.has_tree_data) {
- params.has_tree_data = true;
- params.sel_anchor_object_id = result.tree_data.sel_anchor_object_id;
- params.sel_anchor_offset = result.tree_data.sel_anchor_offset;
- params.sel_focus_object_id = result.tree_data.sel_focus_object_id;
- params.sel_focus_offset = result.tree_data.sel_focus_offset;
- }
- gfx::Rect parent_rect;
+ auto snapshot = ui::AXSnapshotNodeAndroid::Create(result);
ScopedJavaLocalRef<jobject> j_root =
- WalkAXTreeDepthFirst(env, root, parent_rect, &params);
+ CreateJavaAXSnapshot(env, snapshot.get(), true);
Java_WebContentsImpl_onAccessibilitySnapshot(env, j_root, callback);
}

Powered by Google App Engine
This is Rietveld 408576698