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

Side by Side Diff: chrome/browser/accessibility/browser_accessibility_win.cc

Issue 4292001: Add basic support for accessibility hit testing within web contents.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/accessibility/browser_accessibility_win.h" 5 #include "chrome/browser/accessibility/browser_accessibility_win.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/accessibility/browser_accessibility_manager_win.h" 10 #include "chrome/browser/accessibility/browser_accessibility_manager_win.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return E_FAIL; 46 return E_FAIL;
47 47
48 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 48 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id);
49 if (!target) 49 if (!target)
50 return E_INVALIDARG; 50 return E_INVALIDARG;
51 51
52 manager_->DoDefaultAction(*target); 52 manager_->DoDefaultAction(*target);
53 return S_OK; 53 return S_OK;
54 } 54 }
55 55
56 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left, LONG y_top, 56 STDMETHODIMP BrowserAccessibilityWin::accHitTest(
57 VARIANT* child) { 57 LONG x_left, LONG y_top, VARIANT* child) {
58 if (!instance_active_) 58 if (!instance_active_)
59 return E_FAIL; 59 return E_FAIL;
60 60
61 if (!child) 61 if (!child)
62 return E_INVALIDARG; 62 return E_INVALIDARG;
63 63
64 return E_NOTIMPL; 64 gfx::Point point(x_left, y_top);
65 if (!GetBoundsRect().Contains(point)) {
66 // Return S_FALSE and VT_EMPTY when the outside the object's boundaries.
67 child->vt = VT_EMPTY;
68 return S_FALSE;
69 }
70
71 BrowserAccessibility* result = BrowserAccessibilityForPoint(point);
72 if (result == this) {
73 // Point is within this object.
74 child->vt = VT_I4;
75 child->lVal = CHILDID_SELF;
76 } else {
77 child->vt = VT_DISPATCH;
78 child->pdispVal = result->toBrowserAccessibilityWin()->NewReference();
79 }
80 return S_OK;
65 } 81 }
66 82
67 STDMETHODIMP BrowserAccessibilityWin::accLocation(LONG* x_left, LONG* y_top, 83 STDMETHODIMP BrowserAccessibilityWin::accLocation(LONG* x_left, LONG* y_top,
68 LONG* width, LONG* height, 84 LONG* width, LONG* height,
69 VARIANT var_id) { 85 VARIANT var_id) {
70 if (!instance_active_) 86 if (!instance_active_)
71 return E_FAIL; 87 return E_FAIL;
72 88
73 if (!x_left || !y_top || !width || !height) 89 if (!x_left || !y_top || !width || !height)
74 return E_INVALIDARG; 90 return E_INVALIDARG;
75 91
76 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 92 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id);
77 if (!target) 93 if (!target)
78 return E_INVALIDARG; 94 return E_INVALIDARG;
79 95
80 // Find the top left corner of the containing window in screen coords, and 96 gfx::Rect bounds = target->GetBoundsRect();
81 // adjust the output position by this amount. 97 *x_left = bounds.x();
82 HWND parent_hwnd = manager_->GetParentView(); 98 *y_top = bounds.y();
83 POINT top_left = {0, 0}; 99 *width = bounds.width();
84 ::ClientToScreen(parent_hwnd, &top_left); 100 *height = bounds.height();
85
86 *x_left = target->location_.x + top_left.x;
87 *y_top = target->location_.y + top_left.y;
88 *width = target->location_.width;
89 *height = target->location_.height;
90 101
91 return S_OK; 102 return S_OK;
92 } 103 }
93 104
94 STDMETHODIMP BrowserAccessibilityWin::accNavigate( 105 STDMETHODIMP BrowserAccessibilityWin::accNavigate(
95 LONG nav_dir, VARIANT start, VARIANT* end) { 106 LONG nav_dir, VARIANT start, VARIANT* end) {
96 BrowserAccessibilityWin* target = GetTargetFromChildID(start); 107 BrowserAccessibilityWin* target = GetTargetFromChildID(start);
97 if (!target) 108 if (!target)
98 return E_INVALIDARG; 109 return E_INVALIDARG;
99 110
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 LONG child_id = var_id.lVal; 1160 LONG child_id = var_id.lVal;
1150 if (child_id == CHILDID_SELF) 1161 if (child_id == CHILDID_SELF)
1151 return this; 1162 return this;
1152 1163
1153 if (child_id >= 1 && child_id <= static_cast<LONG>(children_.size())) 1164 if (child_id >= 1 && child_id <= static_cast<LONG>(children_.size()))
1154 return children_[child_id - 1]->toBrowserAccessibilityWin(); 1165 return children_[child_id - 1]->toBrowserAccessibilityWin();
1155 1166
1156 return manager_->GetFromChildID(child_id)->toBrowserAccessibilityWin(); 1167 return manager_->GetFromChildID(child_id)->toBrowserAccessibilityWin();
1157 } 1168 }
1158 1169
1159 bool BrowserAccessibilityWin::HasAttribute(
1160 WebAccessibility::Attribute attribute) {
1161 return (attributes_.find(attribute) != attributes_.end());
1162 }
1163
1164 bool BrowserAccessibilityWin::GetAttribute(
1165 WebAccessibility::Attribute attribute, string16* value) {
1166 std::map<int32, string16>::iterator iter = attributes_.find(attribute);
1167 if (iter != attributes_.end()) {
1168 *value = iter->second;
1169 return true;
1170 }
1171
1172 return false;
1173 }
1174
1175 HRESULT BrowserAccessibilityWin::GetAttributeAsBstr( 1170 HRESULT BrowserAccessibilityWin::GetAttributeAsBstr(
1176 WebAccessibility::Attribute attribute, BSTR* value_bstr) { 1171 WebAccessibility::Attribute attribute, BSTR* value_bstr) {
1177 string16 str; 1172 string16 str;
1178 1173
1179 if (!GetAttribute(attribute, &str)) 1174 if (!GetAttribute(attribute, &str))
1180 return S_FALSE; 1175 return S_FALSE;
1181 1176
1182 if (str.empty()) 1177 if (str.empty())
1183 return S_FALSE; 1178 return S_FALSE;
1184 1179
1185 *value_bstr = SysAllocString(str.c_str()); 1180 *value_bstr = SysAllocString(str.c_str());
1186 DCHECK(*value_bstr); 1181 DCHECK(*value_bstr);
1187 1182
1188 return S_OK; 1183 return S_OK;
1189 } 1184 }
1190 1185
1191 bool BrowserAccessibilityWin::GetAttributeAsInt(
1192 WebAccessibility::Attribute attribute, int* value_int) {
1193 string16 value_str;
1194
1195 if (!GetAttribute(attribute, &value_str))
1196 return false;
1197
1198 if (!base::StringToInt(value_str, value_int))
1199 return false;
1200
1201 return true;
1202 }
1203
1204 string16 BrowserAccessibilityWin::Escape(string16 str) { 1186 string16 BrowserAccessibilityWin::Escape(string16 str) {
1205 return EscapeQueryParamValueUTF8(str, false); 1187 return EscapeQueryParamValueUTF8(str, false);
1206 } 1188 }
1207 1189
1208 const string16& BrowserAccessibilityWin::TextForIAccessibleText() { 1190 const string16& BrowserAccessibilityWin::TextForIAccessibleText() {
1209 if (role_ == WebAccessibility::ROLE_TEXT_FIELD) { 1191 if (role_ == WebAccessibility::ROLE_TEXT_FIELD) {
1210 return value_; 1192 return value_;
1211 } else { 1193 } else {
1212 return name_; 1194 return name_;
1213 } 1195 }
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 } 1548 }
1567 1549
1568 // The role should always be set. 1550 // The role should always be set.
1569 DCHECK(!role_name_.empty() || ia_role_); 1551 DCHECK(!role_name_.empty() || ia_role_);
1570 1552
1571 // If we didn't explicitly set the IAccessible2 role, make it the same 1553 // If we didn't explicitly set the IAccessible2 role, make it the same
1572 // as the MSAA role. 1554 // as the MSAA role.
1573 if (!ia2_role_) 1555 if (!ia2_role_)
1574 ia2_role_ = ia_role_; 1556 ia2_role_ = ia_role_;
1575 } 1557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698