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

Side by Side Diff: content/browser/accessibility/browser_accessibility.cc

Issue 25987002: Accessible boundsForRange common impl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/accessibility/browser_accessibility.h" 5 #include "content/browser/accessibility/browser_accessibility.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const { 182 gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const {
183 gfx::Rect bounds = GetLocalBoundsRect(); 183 gfx::Rect bounds = GetLocalBoundsRect();
184 184
185 // Adjust the bounds by the top left corner of the containing view's bounds 185 // Adjust the bounds by the top left corner of the containing view's bounds
186 // in screen coordinates. 186 // in screen coordinates.
187 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin()); 187 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
188 188
189 return bounds; 189 return bounds;
190 } 190 }
191 191
192 gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len)
193 const {
194 DCHECK_EQ(role_, WebKit::WebAXRoleStaticText);
195 int end = start + len;
196 int child_start = 0;
197 int child_end = 0;
198
199 gfx::Rect bounds;
200 for (size_t i = 0; i < children_.size(); i++) {
David Tseng 2013/10/17 21:32:02 You only need to iterate up to text length "end",
dmazzoni 2013/10/21 17:25:38 Good point. I added a condition to the for loop so
David Tseng 2013/10/23 17:00:50 nit: ++i
dmazzoni 2013/11/01 18:39:37 Done.
201 BrowserAccessibility* child = children_[i];
202 DCHECK_EQ(child->role(), WebKit::WebAXRoleInlineTextBox);
203 std::string child_text;
204 child->GetStringAttribute(AccessibilityNodeData::ATTR_VALUE, &child_text);
205 int child_len = static_cast<int>(child_text.size());
206 child_start = child_end;
207 child_end += child_len;
208
209 int overlap_start = std::max(start, child_start);
aboxhall 2013/10/04 18:53:07 Could we just do if (start > child_end || end < ch
dmazzoni 2013/10/21 17:25:38 Done.
210 int overlap_end = std::min(end, child_end);
211
212 if (overlap_end <= overlap_start)
213 continue;
214
215 int local_start = overlap_start - child_start;
216 int local_end = overlap_end - child_start;
217
218 gfx::Rect child_rect = child->location();
219 int text_direction = child->GetIntAttribute(
220 AccessibilityNodeData::ATTR_TEXT_DIRECTION);
221 const std::vector<int32>& character_offsets = child->GetIntListAttribute(
222 AccessibilityNodeData::ATTR_CHARACTER_OFFSETS);
223 int start_pixel_offset =
224 local_start > 0 ? character_offsets[local_start - 1] : 0;
225 int end_pixel_offset =
226 local_end > 0 ? character_offsets[local_end - 1] : 0;
227
228 gfx::Rect child_overlap_rect;
229 switch (text_direction) {
230 default:
David Tseng 2013/10/23 17:00:50 Do you expect to get anything other than the four
dmazzoni 2013/11/01 18:39:37 No. Changed to NOTREACHED.
231 case WebKit::WebAXTextDirectionLR: {
232 int left = child_rect.x() + start_pixel_offset;
233 int right = child_rect.x() + end_pixel_offset;
234 child_overlap_rect = gfx::Rect(left, child_rect.y(),
235 right - left, child_rect.height());
236 break;
237 }
238 case WebKit::WebAXTextDirectionRL: {
239 int right = child_rect.right() - start_pixel_offset;
240 int left = child_rect.right() - end_pixel_offset;
241 child_overlap_rect = gfx::Rect(left, child_rect.y(),
242 right - left, child_rect.height());
243 break;
244 }
245 case WebKit::WebAXTextDirectionTB: {
246 int top = child_rect.y() + start_pixel_offset;
247 int bottom = child_rect.y() + end_pixel_offset;
248 child_overlap_rect = gfx::Rect(child_rect.x(), top,
249 child_rect.width(), bottom - top);
250 break;
251 }
252 case WebKit::WebAXTextDirectionBT: {
253 int bottom = child_rect.bottom() - start_pixel_offset;
254 int top = child_rect.bottom() - end_pixel_offset;
255 child_overlap_rect = gfx::Rect(child_rect.x(), top,
256 child_rect.width(), bottom - top);
257 break;
258 }
259 }
260
261 if (bounds.width() == 0 && bounds.height() == 0)
aboxhall 2013/10/04 18:53:07 Would IsEmpty() do here? Or is it conceivable that
dmazzoni 2013/10/21 17:25:38 It will happen - a common example is a space chara
262 bounds = child_overlap_rect;
263 else
264 bounds.Union(child_overlap_rect);
265 }
266
267 return bounds;
268 }
269
270 gfx::Rect BrowserAccessibility::GetGlobalBoundsForRange(int start, int len)
271 const {
272 gfx::Rect bounds = GetLocalBoundsForRange(start, len);
273
274 // Adjust the bounds by the top left corner of the containing view's bounds
275 // in screen coordinates.
276 bounds.Offset(manager_->GetViewBounds().OffsetFromOrigin());
277
278 return bounds;
279 }
280
192 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint( 281 BrowserAccessibility* BrowserAccessibility::BrowserAccessibilityForPoint(
193 const gfx::Point& point) { 282 const gfx::Point& point) {
194 // Walk the children recursively looking for the BrowserAccessibility that 283 // Walk the children recursively looking for the BrowserAccessibility that
195 // most tightly encloses the specified point. 284 // most tightly encloses the specified point.
196 for (int i = children_.size() - 1; i >= 0; --i) { 285 for (int i = children_.size() - 1; i >= 0; --i) {
197 BrowserAccessibility* child = children_[i]; 286 BrowserAccessibility* child = children_[i];
198 if (child->GetGlobalBoundsRect().Contains(point)) 287 if (child->GetGlobalBoundsRect().Contains(point))
199 return child->BrowserAccessibilityForPoint(point); 288 return child->BrowserAccessibilityForPoint(point);
200 } 289 }
201 return this; 290 return this;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 return name_; 574 return name_;
486 } 575 }
487 576
488 std::string result; 577 std::string result;
489 for (size_t i = 0; i < children_.size(); ++i) 578 for (size_t i = 0; i < children_.size(); ++i)
490 result += children_[i]->GetTextRecursive(); 579 result += children_[i]->GetTextRecursive();
491 return result; 580 return result;
492 } 581 }
493 582
494 } // namespace content 583 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698