From 02747d4e2fcd7211cf2fe0851d15d7c8a9341b54 Mon Sep 17 00:00:00 2001 From: "ctguil@chromium.org" Date: Wed, 3 Nov 2010 19:10:00 +0000 Subject: Add basic support for accessibility hit testing within web contents. BUG=59890 TEST=Manual. Inspect32. Review URL: http://codereview.chromium.org/4292001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64943 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/accessibility/browser_accessibility.cc | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'chrome/browser/accessibility/browser_accessibility.cc') diff --git a/chrome/browser/accessibility/browser_accessibility.cc b/chrome/browser/accessibility/browser_accessibility.cc index 21a1dc0..42cc878 100644 --- a/chrome/browser/accessibility/browser_accessibility.cc +++ b/chrome/browser/accessibility/browser_accessibility.cc @@ -5,6 +5,7 @@ #include "chrome/browser/accessibility/browser_accessibility.h" #include "base/logging.h" +#include "base/string_number_conversions.h" #include "chrome/browser/accessibility/browser_accessibility_manager.h" BrowserAccessibility::BrowserAccessibility() @@ -110,3 +111,65 @@ BrowserAccessibility* BrowserAccessibility::GetNextSibling() { return NULL; } + +gfx::Rect BrowserAccessibility::GetBoundsRect() { + gfx::Rect bounds = location_; + + // Adjust the bounds by the top left corner of the containing view's bounds + // in screen coordinates. + gfx::Point top_left = manager_->GetViewBounds().origin(); + bounds.Offset(top_left); + + // Adjust top left position by the root document's scroll offset. + BrowserAccessibility* root = manager_->GetRoot(); + int scroll_x = 0; + int scroll_y = 0; + root->GetAttributeAsInt( + WebAccessibility::ATTR_DOC_SCROLLX, &scroll_x); + root->GetAttributeAsInt( + WebAccessibility::ATTR_DOC_SCROLLY, &scroll_y); + bounds.Offset(-scroll_x, -scroll_y); + + return bounds; +} + +BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( + const gfx::Point& point) { + // Walk the children recursively looking for the BrowserAccessibility that + // most tightly encloses the specified point. + for (int i = children_.size() - 1; i >= 0; --i) { + BrowserAccessibility* child = children_[i]; + if (child->GetBoundsRect().Contains(point)) + return child->BrowserAccessibilityForPoint(point); + } + return this; +} + +bool BrowserAccessibility::HasAttribute( + WebAccessibility::Attribute attribute) { + return (attributes_.find(attribute) != attributes_.end()); +} + +bool BrowserAccessibility::GetAttribute( + WebAccessibility::Attribute attribute, string16* value) { + std::map::iterator iter = attributes_.find(attribute); + if (iter != attributes_.end()) { + *value = iter->second; + return true; + } + + return false; +} + +bool BrowserAccessibility::GetAttributeAsInt( + WebAccessibility::Attribute attribute, int* value_int) { + string16 value_str; + + if (!GetAttribute(attribute, &value_str)) + return false; + + if (!base::StringToInt(value_str, value_int)) + return false; + + return true; +} -- cgit v1.1