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

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

Issue 1598583002: Fixed algorithms that compute bounding rectangles and word start offsets to take into account IA2 h… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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.cc
diff --git a/content/browser/accessibility/browser_accessibility.cc b/content/browser/accessibility/browser_accessibility.cc
index 9f528bd0de10cb7f8c7624574c6b619cce9a763e..73312dcc09dca2c2094b8842038b877a842ae04f 100644
--- a/content/browser/accessibility/browser_accessibility.cc
+++ b/content/browser/accessibility/browser_accessibility.cc
@@ -104,7 +104,7 @@ bool BrowserAccessibility::IsTextOnlyObject() const {
BrowserAccessibility* BrowserAccessibility::PlatformGetChild(
uint32_t child_index) const {
- DCHECK(child_index < PlatformChildCount());
+ DCHECK_LT(child_index, PlatformChildCount());
BrowserAccessibility* result = nullptr;
if (HasIntAttribute(ui::AX_ATTR_CHILD_TREE_ID)) {
@@ -261,19 +261,25 @@ gfx::Rect BrowserAccessibility::GetGlobalBoundsRect() const {
gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len)
const {
if (GetRole() != ui::AX_ROLE_STATIC_TEXT) {
- // Apply recursively to all static text descendants. For example, if
- // you call it on a div with two text node children, it just calls
- // GetLocalBoundsForRange on each of the two children (adjusting
- // |start| for each one) and unions the resulting rects.
gfx::Rect bounds;
- for (size_t i = 0; i < InternalChildCount(); ++i) {
+ for (size_t i = 0; i < InternalChildCount() && start >= 0; ++i) {
BrowserAccessibility* child = InternalGetChild(i);
- int child_len = child->GetInnerTextLength();
- if (start < child_len && start + len > 0) {
- gfx::Rect child_rect = child->GetLocalBoundsForRange(start, len);
+ // Embedded objects are of length one, since they are represented only by
dmazzoni 2016/01/20 01:10:43 This comment confuses me. It talks about embedded
+ // a special character.
+ int child_length_in_parent =
+ child->IsTextOnlyObject() ? static_cast<int>(child->GetText().size())
+ : 1;
+ if (start < child_length_in_parent) {
+ gfx::Rect child_rect;
+ if (child->IsTextOnlyObject())
+ child_rect = child->GetLocalBoundsForRange(start, len);
+ else
dmazzoni 2016/01/20 01:10:43 nit: Need braces around both blocks
+ child_rect = child->GetLocalBoundsForRange(
+ start, static_cast<int>(child->GetText().size()));
bounds.Union(child_rect);
+ len -= child_length_in_parent;
}
- start -= child_len;
+ start -= child_length_in_parent;
}
return ElementBoundsToLocalBounds(bounds);
}
@@ -291,9 +297,7 @@ gfx::Rect BrowserAccessibility::GetLocalBoundsForRange(int start, int len)
continue;
}
- std::string child_text;
- child->GetStringAttribute(ui::AX_ATTR_NAME, &child_text);
- int child_len = static_cast<int>(child_text.size());
+ int child_len = static_cast<int>(GetText().size());
child_start = child_end;
child_end += child_len;
@@ -382,7 +386,7 @@ int BrowserAccessibility::GetWordStartBoundary(
int start, ui::TextBoundaryDirection direction) const {
DCHECK_GE(start, -1);
// Special offset that indicates that a word boundary has not been found.
- int word_start_not_found = GetInnerTextLength();
+ int word_start_not_found = static_cast<int>(GetText().size());
int word_start = word_start_not_found;
switch (GetRole()) {
@@ -397,9 +401,7 @@ int BrowserAccessibility::GetWordStartBoundary(
child_start = child_end;
BrowserAccessibility* child = InternalGetChild(i);
DCHECK_EQ(child->GetRole(), ui::AX_ROLE_INLINE_TEXT_BOX);
- const std::string& child_text = child->GetStringAttribute(
- ui::AX_ATTR_NAME);
- int child_len = static_cast<int>(child_text.size());
+ int child_len = static_cast<int>(GetText().size());
child_end += child_len; // End is one past the last character.
const std::vector<int32_t>& word_starts =
@@ -455,19 +457,23 @@ int BrowserAccessibility::GetWordStartBoundary(
int child_start = 0;
for (size_t i = 0; i < InternalChildCount(); ++i) {
BrowserAccessibility* child = InternalGetChild(i);
- int child_len = child->GetInnerTextLength();
- int child_word_start = child->GetWordStartBoundary(start, direction);
- if (child_word_start < child_len) {
- // We have found a possible word boundary.
- word_start = child_start + child_word_start;
- }
+ // An embedded object is always represented by a single special
+ // character.
+ int child_len = 1;
+ if (child->IsTextOnlyObject()) {
+ child_len = static_cast<int>(child->GetText().size());
+ int child_word_start = child->GetWordStartBoundary(start, direction);
+ if (child_word_start < child_len) {
+ // We have found a possible word boundary.
+ word_start = child_start + child_word_start;
+ }
- // Decide when to stop searching.
- if ((word_start != word_start_not_found &&
- direction == ui::FORWARDS_DIRECTION) ||
- (start < child_len &&
- direction == ui::BACKWARDS_DIRECTION)) {
- break;
+ // Decide when to stop searching.
+ if ((word_start != word_start_not_found &&
+ direction == ui::FORWARDS_DIRECTION) ||
+ (start < child_len && direction == ui::BACKWARDS_DIRECTION)) {
+ break;
+ }
}
child_start += child_len;
@@ -656,7 +662,7 @@ bool BrowserAccessibility::GetAriaTristate(
if (base::EqualsASCII(value, "mixed"))
*is_mixed = true;
- return false; // Not set
+ return false; // Not set.
}
bool BrowserAccessibility::HasState(ui::AXState state_enum) const {
@@ -670,7 +676,8 @@ bool BrowserAccessibility::IsCellOrTableHeaderRole() const {
}
bool BrowserAccessibility::HasCaret() const {
- if (IsEditableText() && !HasState(ui::AX_STATE_RICHLY_EDITABLE) &&
+ if (HasState(ui::AX_STATE_EDITABLE) &&
+ !HasState(ui::AX_STATE_RICHLY_EDITABLE) &&
HasIntAttribute(ui::AX_ATTR_TEXT_SEL_START) &&
HasIntAttribute(ui::AX_ATTR_TEXT_SEL_END)) {
return true;
@@ -688,10 +695,6 @@ bool BrowserAccessibility::HasCaret() const {
return true;
}
-bool BrowserAccessibility::IsEditableText() const {
- return HasState(ui::AX_STATE_EDITABLE);
-}
-
bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const {
if (GetRole() != ui::AX_ROLE_WEB_AREA &&
GetRole() != ui::AX_ROLE_ROOT_WEB_AREA) {
@@ -792,10 +795,6 @@ base::string16 BrowserAccessibility::GetInnerText() const {
return text;
}
-int BrowserAccessibility::GetInnerTextLength() const {
- return static_cast<int>(GetInnerText().size());
-}
-
void BrowserAccessibility::FixEmptyBounds(gfx::Rect* bounds) const
{
if (bounds->width() > 0 && bounds->height() > 0)

Powered by Google App Engine
This is Rietveld 408576698