diff options
Diffstat (limited to 'chrome/browser/accessibility')
3 files changed, 22 insertions, 5 deletions
diff --git a/chrome/browser/accessibility/browser_accessibility_win.cc b/chrome/browser/accessibility/browser_accessibility_win.cc index 80e4e48..a217f05 100644 --- a/chrome/browser/accessibility/browser_accessibility_win.cc +++ b/chrome/browser/accessibility/browser_accessibility_win.cc @@ -640,6 +640,10 @@ STDMETHODIMP BrowserAccessibilityWin::get_text( const string16& text_str = TextForIAccessibleText(); + // Handle special text offsets. + HandleSpecialTextOffset(text_str, &start_offset); + HandleSpecialTextOffset(text_str, &end_offset); + // The spec allows the arguments to be reversed. if (start_offset > end_offset) { LONG tmp = start_offset; @@ -1205,6 +1209,15 @@ const string16& BrowserAccessibilityWin::TextForIAccessibleText() { } } +void BrowserAccessibilityWin::HandleSpecialTextOffset( + const string16& text, LONG* offset) { + if (*offset == IA2_TEXT_OFFSET_LENGTH) { + *offset = static_cast<LONG>(text.size()); + } else if (*offset == IA2_TEXT_OFFSET_CARET) { + get_caretOffset(offset); + } +} + LONG BrowserAccessibilityWin::FindBoundary( const string16& text, IA2TextBoundaryType boundary, @@ -1216,11 +1229,7 @@ LONG BrowserAccessibilityWin::FindBoundary( start_offset == IA2_TEXT_OFFSET_CARET); DCHECK(direction == 1 || direction == -1); - if (start_offset == IA2_TEXT_OFFSET_LENGTH) { - start_offset = text_size; - } else if (start_offset == IA2_TEXT_OFFSET_CARET) { - get_caretOffset(&start_offset); - } + HandleSpecialTextOffset(text, &start_offset); if (boundary == IA2_TEXT_BOUNDARY_CHAR) { if (direction == 1 && start_offset < text_size) diff --git a/chrome/browser/accessibility/browser_accessibility_win.h b/chrome/browser/accessibility/browser_accessibility_win.h index 879a7dc..78d0ecd 100644 --- a/chrome/browser/accessibility/browser_accessibility_win.h +++ b/chrome/browser/accessibility/browser_accessibility_win.h @@ -470,6 +470,10 @@ class BrowserAccessibilityWin // be the name, it may be the value, etc. depending on the role. const string16& TextForIAccessibleText(); + // If offset is a member of IA2TextSpecialOffsets this function updates the + // value of offset and returns, otherwise offset remains unchanged. + void HandleSpecialTextOffset(const string16& text, LONG* offset); + // Search forwards (direction == 1) or backwards (direction == -1) from // the given offset until the given IAccessible2 boundary (like word, // sentence) is found, and return its offset. diff --git a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc index 4875130..e40d505 100644 --- a/chrome/browser/accessibility/browser_accessibility_win_unittest.cc +++ b/chrome/browser/accessibility/browser_accessibility_win_unittest.cc @@ -358,6 +358,10 @@ TEST_F(BrowserAccessibilityTest, TestTextBoundaries) { ASSERT_EQ(text, string16(L"One two three")); SysFreeString(text); + ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); + ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); + SysFreeString(text); + // Delete the manager and test that all BrowserAccessibility instances are // deleted. delete manager; |