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

Unified Diff: content/browser/accessibility/browser_accessibility_manager_android.cc

Issue 290633002: Implement Android accessible hit testing using an IPC to the renderer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@better_logging_2
Patch Set: Remove unused function Created 6 years, 7 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/accessibility/browser_accessibility_manager_android.cc
diff --git a/content/browser/accessibility/browser_accessibility_manager_android.cc b/content/browser/accessibility/browser_accessibility_manager_android.cc
index 21c29c0aab53296e749b8bc4654e689a9031755c..07f04e71b45e90feba8e21b13b9ca89d3901ab27 100644
--- a/content/browser/accessibility/browser_accessibility_manager_android.cc
+++ b/content/browser/accessibility/browser_accessibility_manager_android.cc
@@ -33,11 +33,6 @@ enum AndroidHtmlElementType {
HTML_ELEMENT_TYPE_ANY
};
-// Restricts |val| to the range [min, max].
-int Clamp(int val, int min, int max) {
- return std::min(std::max(val, min), max);
-}
-
// These are special unofficial strings sent from TalkBack/BrailleBack
// to jump to certain categories of web elements.
AndroidHtmlElementType HtmlElementTypeFromString(base::string16 element_type) {
@@ -127,6 +122,11 @@ void BrowserAccessibilityManagerAndroid::NotifyAccessibilityEvent(
if (event_type == ui::AX_EVENT_HIDE)
return;
+ if (event_type == ui::AX_EVENT_HOVER) {
+ HandleHoverEvent(node);
+ return;
+ }
+
// Always send AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED to notify
// the Android system that the accessibility hierarchy rooted at this
// node has changed.
@@ -196,25 +196,10 @@ jboolean BrowserAccessibilityManagerAndroid::IsNodeValid(
return GetFromID(id) != NULL;
}
-jint BrowserAccessibilityManagerAndroid::HitTest(
+void BrowserAccessibilityManagerAndroid::HitTest(
JNIEnv* env, jobject obj, jint x, jint y) {
- BrowserAccessibilityAndroid* result =
- static_cast<BrowserAccessibilityAndroid*>(
- GetRoot()->BrowserAccessibilityForPoint(gfx::Point(x, y)));
-
- if (!result)
- return GetRoot()->GetId();
-
- if (result->IsFocusable())
- return result->GetId();
-
- // Examine the children of |result| to find the nearest accessibility focus
- // candidate
- BrowserAccessibility* nearest_node = FuzzyHitTest(x, y, result);
- if (nearest_node)
- return nearest_node->GetId();
-
- return GetRoot()->GetId();
+ if (delegate())
+ delegate()->AccessibilityHitTest(gfx::Point(x, y));
}
jboolean BrowserAccessibilityManagerAndroid::PopulateAccessibilityNodeInfo(
@@ -416,55 +401,27 @@ void BrowserAccessibilityManagerAndroid::ScrollToMakeNodeVisible(
ScrollToMakeVisible(*node, gfx::Rect(node->GetLocation().size()));
}
-BrowserAccessibility* BrowserAccessibilityManagerAndroid::FuzzyHitTest(
- int x, int y, BrowserAccessibility* start_node) {
- BrowserAccessibility* nearest_node = NULL;
- int min_distance = INT_MAX;
- FuzzyHitTestImpl(x, y, start_node, &nearest_node, &min_distance);
- return nearest_node;
-}
-
-// static
-void BrowserAccessibilityManagerAndroid::FuzzyHitTestImpl(
- int x, int y, BrowserAccessibility* start_node,
- BrowserAccessibility** nearest_candidate, int* nearest_distance) {
- BrowserAccessibilityAndroid* node =
- static_cast<BrowserAccessibilityAndroid*>(start_node);
- int distance = CalculateDistanceSquared(x, y, node);
-
- if (node->IsFocusable()) {
- if (distance < *nearest_distance) {
- *nearest_candidate = node;
- *nearest_distance = distance;
- }
- // Don't examine any more children of focusable node
- // TODO(aboxhall): what about focusable children?
+void BrowserAccessibilityManagerAndroid::HandleHoverEvent(
+ BrowserAccessibility* node) {
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null())
return;
- }
- if (!node->GetText().empty()) {
- if (distance < *nearest_distance) {
- *nearest_candidate = node;
- *nearest_distance = distance;
+ BrowserAccessibilityAndroid* ancestor =
+ static_cast<BrowserAccessibilityAndroid*>(node->GetParent());
+ while (ancestor) {
+ if (ancestor->PlatformIsLeaf() ||
+ (ancestor->IsFocusable() && !ancestor->HasFocusableChild())) {
+ node = ancestor;
+ // Don't break - we want the highest ancestor that's focusable or a
+ // leaf node.
}
- return;
- }
-
- for (uint32 i = 0; i < node->PlatformChildCount(); i++) {
- BrowserAccessibility* child = node->PlatformGetChild(i);
- FuzzyHitTestImpl(x, y, child, nearest_candidate, nearest_distance);
+ ancestor = static_cast<BrowserAccessibilityAndroid*>(ancestor->GetParent());
}
-}
-// static
-int BrowserAccessibilityManagerAndroid::CalculateDistanceSquared(
- int x, int y, BrowserAccessibility* node) {
- gfx::Rect node_bounds = node->GetLocalBoundsRect();
- int nearest_x = Clamp(x, node_bounds.x(), node_bounds.right());
- int nearest_y = Clamp(y, node_bounds.y(), node_bounds.bottom());
- int dx = std::abs(x - nearest_x);
- int dy = std::abs(y - nearest_y);
- return dx * dx + dy * dy;
+ Java_BrowserAccessibilityManager_handleHover(
+ env, obj.obj(), node->GetId());
}
jint BrowserAccessibilityManagerAndroid::FindElementType(

Powered by Google App Engine
This is Rietveld 408576698