OLD | NEW |
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_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_win.h" |
6 | 6 |
7 #include <UIAutomationClient.h> | 7 #include <UIAutomationClient.h> |
8 #include <UIAutomationCoreApi.h> | 8 #include <UIAutomationCoreApi.h> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2084 enum IA2TextBoundaryType boundary_type, | 2084 enum IA2TextBoundaryType boundary_type, |
2085 LONG* start_offset, | 2085 LONG* start_offset, |
2086 LONG* end_offset, | 2086 LONG* end_offset, |
2087 BSTR* text) { | 2087 BSTR* text) { |
2088 if (!instance_active()) | 2088 if (!instance_active()) |
2089 return E_FAIL; | 2089 return E_FAIL; |
2090 | 2090 |
2091 if (!start_offset || !end_offset || !text) | 2091 if (!start_offset || !end_offset || !text) |
2092 return E_INVALIDARG; | 2092 return E_INVALIDARG; |
2093 | 2093 |
| 2094 const base::string16& text_str = TextForIAccessibleText(); |
| 2095 HandleSpecialTextOffset(text_str, &offset); |
| 2096 if (offset < 0) |
| 2097 return E_INVALIDARG; |
| 2098 |
| 2099 LONG text_len = text_str.length(); |
| 2100 if (offset > text_len) |
| 2101 return E_INVALIDARG; |
| 2102 |
2094 // The IAccessible2 spec says we don't have to implement the "sentence" | 2103 // The IAccessible2 spec says we don't have to implement the "sentence" |
2095 // boundary type, we can just let the screenreader handle it. | 2104 // boundary type, we can just let the screenreader handle it. |
2096 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) { | 2105 if (boundary_type == IA2_TEXT_BOUNDARY_SENTENCE) { |
2097 *start_offset = 0; | 2106 *start_offset = 0; |
2098 *end_offset = 0; | 2107 *end_offset = 0; |
2099 *text = NULL; | 2108 *text = NULL; |
2100 return S_FALSE; | 2109 return S_FALSE; |
2101 } | 2110 } |
2102 | 2111 |
2103 const base::string16& text_str = TextForIAccessibleText(); | 2112 // According to the IA2 Spec, only line boundaries should succeed when |
| 2113 // the offset is one past the end of the text. |
| 2114 if (offset == text_len && boundary_type != IA2_TEXT_BOUNDARY_LINE) { |
| 2115 *start_offset = 0; |
| 2116 *end_offset = 0; |
| 2117 *text = nullptr; |
| 2118 return S_FALSE; |
| 2119 } |
2104 | 2120 |
2105 *start_offset = FindBoundary( | 2121 *start_offset = FindBoundary( |
2106 text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION); | 2122 text_str, boundary_type, offset, ui::BACKWARDS_DIRECTION); |
2107 *end_offset = FindBoundary( | 2123 *end_offset = FindBoundary( |
2108 text_str, boundary_type, offset, ui::FORWARDS_DIRECTION); | 2124 text_str, boundary_type, offset, ui::FORWARDS_DIRECTION); |
2109 return get_text(*start_offset, *end_offset, text); | 2125 return get_text(*start_offset, *end_offset, text); |
2110 } | 2126 } |
2111 | 2127 |
2112 STDMETHODIMP BrowserAccessibilityWin::get_textBeforeOffset( | 2128 STDMETHODIMP BrowserAccessibilityWin::get_textBeforeOffset( |
2113 LONG offset, | 2129 LONG offset, |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3553 } | 3569 } |
3554 return ui::CHAR_BOUNDARY; | 3570 return ui::CHAR_BOUNDARY; |
3555 } | 3571 } |
3556 | 3572 |
3557 LONG BrowserAccessibilityWin::FindBoundary( | 3573 LONG BrowserAccessibilityWin::FindBoundary( |
3558 const base::string16& text, | 3574 const base::string16& text, |
3559 IA2TextBoundaryType ia2_boundary, | 3575 IA2TextBoundaryType ia2_boundary, |
3560 LONG start_offset, | 3576 LONG start_offset, |
3561 ui::TextBoundaryDirection direction) { | 3577 ui::TextBoundaryDirection direction) { |
3562 HandleSpecialTextOffset(text, &start_offset); | 3578 HandleSpecialTextOffset(text, &start_offset); |
| 3579 if (ia2_boundary == IA2_TEXT_BOUNDARY_WORD && |
| 3580 GetRole() == ui::AX_ROLE_TEXT_FIELD) { |
| 3581 return GetWordStartBoundary(static_cast<int>(start_offset), direction); |
| 3582 } |
| 3583 |
3563 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); | 3584 ui::TextBoundaryType boundary = IA2TextBoundaryToTextBoundary(ia2_boundary); |
3564 const std::vector<int32>& line_breaks = GetIntListAttribute( | 3585 const std::vector<int32>& line_breaks = GetIntListAttribute( |
3565 ui::AX_ATTR_LINE_BREAKS); | 3586 ui::AX_ATTR_LINE_BREAKS); |
3566 return ui::FindAccessibleTextBoundary( | 3587 return ui::FindAccessibleTextBoundary( |
3567 text, line_breaks, boundary, start_offset, direction); | 3588 text, line_breaks, boundary, start_offset, direction); |
3568 } | 3589 } |
3569 | 3590 |
3570 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32 id) { | 3591 BrowserAccessibilityWin* BrowserAccessibilityWin::GetFromID(int32 id) { |
3571 return manager()->GetFromID(id)->ToBrowserAccessibilityWin(); | 3592 return manager()->GetFromID(id)->ToBrowserAccessibilityWin(); |
3572 } | 3593 } |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4111 ia2_role = ia_role; | 4132 ia2_role = ia_role; |
4112 | 4133 |
4113 win_attributes_->ia_role = ia_role; | 4134 win_attributes_->ia_role = ia_role; |
4114 win_attributes_->ia_state = ia_state; | 4135 win_attributes_->ia_state = ia_state; |
4115 win_attributes_->role_name = role_name; | 4136 win_attributes_->role_name = role_name; |
4116 win_attributes_->ia2_role = ia2_role; | 4137 win_attributes_->ia2_role = ia2_role; |
4117 win_attributes_->ia2_state = ia2_state; | 4138 win_attributes_->ia2_state = ia2_state; |
4118 } | 4139 } |
4119 | 4140 |
4120 } // namespace content | 4141 } // namespace content |
OLD | NEW |