summaryrefslogtreecommitdiffstats
path: root/chrome/browser/accessibility/browser_accessibility.cc
diff options
context:
space:
mode:
authorctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 19:10:00 +0000
committerctguil@chromium.org <ctguil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 19:10:00 +0000
commit02747d4e2fcd7211cf2fe0851d15d7c8a9341b54 (patch)
tree9f3db8a5df43293cb5ac1f8612d48273009ff641 /chrome/browser/accessibility/browser_accessibility.cc
parent604890c160d3f9383907b80585491fa282abbbd8 (diff)
downloadchromium_src-02747d4e2fcd7211cf2fe0851d15d7c8a9341b54.zip
chromium_src-02747d4e2fcd7211cf2fe0851d15d7c8a9341b54.tar.gz
chromium_src-02747d4e2fcd7211cf2fe0851d15d7c8a9341b54.tar.bz2
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
Diffstat (limited to 'chrome/browser/accessibility/browser_accessibility.cc')
-rw-r--r--chrome/browser/accessibility/browser_accessibility.cc63
1 files changed, 63 insertions, 0 deletions
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<int32, string16>::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;
+}