| 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 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 5 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 6 | 6 |
| 7 #include <execinfo.h> | 7 #include <execinfo.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "content/browser/accessibility/ax_platform_position.h" | 22 #include "content/browser/accessibility/ax_platform_position.h" |
| 23 #include "content/browser/accessibility/browser_accessibility_mac.h" | 23 #include "content/browser/accessibility/browser_accessibility_mac.h" |
| 24 #include "content/browser/accessibility/browser_accessibility_manager.h" | 24 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" | 25 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" |
| 26 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" | 26 #include "content/browser/accessibility/one_shot_accessibility_tree_search.h" |
| 27 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/accessibility/ax_range.h" | 29 #include "ui/accessibility/ax_range.h" |
| 30 #import "ui/accessibility/platform/ax_platform_node_mac.h" | 30 #import "ui/accessibility/platform/ax_platform_node_mac.h" |
| 31 | 31 |
| 32 using AXAbstractPositionInstance = |
| 33 content::AXPlatformPosition::AXPositionInstance; |
| 32 using AXPlatformPositionInstance = | 34 using AXPlatformPositionInstance = |
| 33 content::AXPlatformPosition::AXPositionInstance; | 35 content::AXPlatformPosition::ConcreteInstance; |
| 34 using AXPlatformRange = ui::AXRange<AXPlatformPositionInstance::element_type>; | 36 using AXPlatformRange = ui::AXRange<AXPlatformPositionInstance::element_type>; |
| 35 using AXTextMarkerRangeRef = CFTypeRef; | 37 using AXTextMarkerRangeRef = CFTypeRef; |
| 36 using AXTextMarkerRef = CFTypeRef; | 38 using AXTextMarkerRef = CFTypeRef; |
| 37 using StringAttribute = ui::AXStringAttribute; | 39 using StringAttribute = ui::AXStringAttribute; |
| 38 using content::AXPlatformPosition; | 40 using content::AXPlatformPosition; |
| 39 using content::AccessibilityMatchPredicate; | 41 using content::AccessibilityMatchPredicate; |
| 40 using content::BrowserAccessibility; | 42 using content::BrowserAccessibility; |
| 41 using content::BrowserAccessibilityDelegate; | 43 using content::BrowserAccessibilityDelegate; |
| 42 using content::BrowserAccessibilityManager; | 44 using content::BrowserAccessibilityManager; |
| 43 using content::BrowserAccessibilityManagerMac; | 45 using content::BrowserAccessibilityManagerMac; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 AXTextMarkerRef AXTextMarkerRangeCopyStartMarker( | 135 AXTextMarkerRef AXTextMarkerRangeCopyStartMarker( |
| 134 AXTextMarkerRangeRef text_marker_range); | 136 AXTextMarkerRangeRef text_marker_range); |
| 135 | 137 |
| 136 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( | 138 AXTextMarkerRef AXTextMarkerRangeCopyEndMarker( |
| 137 AXTextMarkerRangeRef text_marker_range); | 139 AXTextMarkerRangeRef text_marker_range); |
| 138 | 140 |
| 139 #endif // MAC_OS_X_VERSION_10_11 | 141 #endif // MAC_OS_X_VERSION_10_11 |
| 140 | 142 |
| 141 } // extern "C" | 143 } // extern "C" |
| 142 | 144 |
| 145 static_assert(sizeof(AXPlatformPosition) == sizeof(ui::AXPositionBase), |
| 146 "AXPosition size mismatch"); |
| 147 constexpr size_t kAXPositionSize = sizeof(ui::AXPositionBase); |
| 148 |
| 143 // to call |release| on it to transfer ownership of the position to the text | 149 // to call |release| on it to transfer ownership of the position to the text |
| 144 // marker object. | 150 // marker object. |
| 145 id CreateTextMarker(AXPlatformPositionInstance position) { | 151 id CreateTextMarker(AXAbstractPositionInstance position) { |
| 146 AXTextMarkerRef text_marker = AXTextMarkerCreate( | 152 AXTextMarkerRef text_marker = AXTextMarkerCreate( |
| 147 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(position.release()), | 153 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(position.release()), |
| 148 sizeof(AXPlatformPosition)); | 154 kAXPositionSize); |
| 149 return static_cast<id>( | 155 return static_cast<id>( |
| 150 base::mac::CFTypeRefToNSObjectAutorelease(text_marker)); | 156 base::mac::CFTypeRefToNSObjectAutorelease(text_marker)); |
| 151 } | 157 } |
| 152 | 158 |
| 153 // |range| is destructed at the end of this method and ownership of its |anchor| | 159 // |range| is destructed at the end of this method and ownership of its |anchor| |
| 154 // and |focus| are transfered to the marker range object. | 160 // and |focus| are transfered to the marker range object. |
| 155 id CreateTextMarkerRange(const AXPlatformRange range) { | 161 id CreateTextMarkerRange(const ui::AXAbstractRange range) { |
| 156 AXTextMarkerRef start_marker = AXTextMarkerCreate( | 162 AXTextMarkerRef start_marker = AXTextMarkerCreate( |
| 157 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(range.anchor()), | 163 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(range.anchor()), |
| 158 sizeof(AXPlatformPosition)); | 164 kAXPositionSize); |
| 159 AXTextMarkerRef end_marker = AXTextMarkerCreate( | 165 AXTextMarkerRef end_marker = AXTextMarkerCreate( |
| 160 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(range.focus()), | 166 kCFAllocatorDefault, reinterpret_cast<const UInt8*>(range.focus()), |
| 161 sizeof(AXPlatformPosition)); | 167 kAXPositionSize); |
| 162 AXTextMarkerRangeRef marker_range = | 168 AXTextMarkerRangeRef marker_range = |
| 163 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker); | 169 AXTextMarkerRangeCreate(kCFAllocatorDefault, start_marker, end_marker); |
| 164 return static_cast<id>( | 170 return static_cast<id>( |
| 165 base::mac::CFTypeRefToNSObjectAutorelease(marker_range)); | 171 base::mac::CFTypeRefToNSObjectAutorelease(marker_range)); |
| 166 } | 172 } |
| 167 | 173 |
| 168 AXPlatformPositionInstance CreatePositionFromTextMarker( | 174 AXPlatformPositionInstance CreateConcretePositionFromTextMarker( |
| 169 AXTextMarkerRef text_marker) { | 175 AXTextMarkerRef text_marker) { |
| 170 DCHECK(text_marker); | 176 DCHECK(text_marker); |
| 171 if (AXTextMarkerGetLength(text_marker) != sizeof(AXPlatformPosition)) | 177 if (AXTextMarkerGetLength(text_marker) != kAXPositionSize) |
| 172 return AXPlatformPosition::CreateNullPosition(); | 178 return AXPlatformPosition::CreateConcreteNullPosition(); |
| 173 const UInt8* source_buffer = AXTextMarkerGetBytePtr(text_marker); | 179 const UInt8* source_buffer = AXTextMarkerGetBytePtr(text_marker); |
| 174 if (!source_buffer) | 180 if (!source_buffer) |
| 175 return AXPlatformPosition::CreateNullPosition(); | 181 return AXPlatformPosition::CreateConcreteNullPosition(); |
| 176 UInt8* destination_buffer = new UInt8[sizeof(AXPlatformPosition)]; | 182 UInt8* destination_buffer = new UInt8[kAXPositionSize]; |
| 177 std::memcpy(destination_buffer, source_buffer, sizeof(AXPlatformPosition)); | 183 std::memcpy(destination_buffer, source_buffer, kAXPositionSize); |
| 178 AXPlatformPosition::AXPositionInstance position( | 184 AXPlatformPositionInstance position( |
| 179 reinterpret_cast<AXPlatformPosition::AXPositionInstance::pointer>( | 185 reinterpret_cast<AXPlatformPositionInstance::pointer>( |
| 180 destination_buffer)); | 186 destination_buffer)); |
| 181 if (!position) | 187 if (!position) |
| 182 return AXPlatformPosition::CreateNullPosition(); | 188 return AXPlatformPosition::CreateConcreteNullPosition(); |
| 183 return position; | 189 return position; |
| 184 } | 190 } |
| 185 | 191 |
| 192 AXAbstractPositionInstance CreatePositionFromTextMarker( |
| 193 AXTextMarkerRef text_marker) { |
| 194 return base::WrapUnique( |
| 195 CreateConcretePositionFromTextMarker(text_marker).release()); |
| 196 } |
| 197 |
| 186 AXPlatformRange CreateRangeFromTextMarkerRange( | 198 AXPlatformRange CreateRangeFromTextMarkerRange( |
| 187 AXTextMarkerRangeRef marker_range) { | 199 AXTextMarkerRangeRef marker_range) { |
| 188 DCHECK(marker_range); | 200 DCHECK(marker_range); |
| 189 base::ScopedCFTypeRef<AXTextMarkerRef> start_marker( | 201 base::ScopedCFTypeRef<AXTextMarkerRef> start_marker( |
| 190 AXTextMarkerRangeCopyStartMarker(marker_range)); | 202 AXTextMarkerRangeCopyStartMarker(marker_range)); |
| 191 base::ScopedCFTypeRef<AXTextMarkerRef> end_marker( | 203 base::ScopedCFTypeRef<AXTextMarkerRef> end_marker( |
| 192 AXTextMarkerRangeCopyEndMarker(marker_range)); | 204 AXTextMarkerRangeCopyEndMarker(marker_range)); |
| 193 if (!start_marker.get() || !end_marker.get()) | 205 if (!start_marker.get() || !end_marker.get()) |
| 194 return AXPlatformRange(); | 206 return AXPlatformRange(); |
| 195 | 207 |
| 196 AXPlatformPositionInstance anchor = | 208 AXPlatformPositionInstance anchor = |
| 197 CreatePositionFromTextMarker(start_marker.get()); | 209 CreateConcretePositionFromTextMarker(start_marker.get()); |
| 198 AXPlatformPositionInstance focus = | 210 AXPlatformPositionInstance focus = |
| 199 CreatePositionFromTextMarker(end_marker.get()); | 211 CreateConcretePositionFromTextMarker(end_marker.get()); |
| 200 // |AXPlatformRange| takes ownership of its anchor and focus. | 212 // |AXPlatformRange| takes ownership of its anchor and focus. |
| 201 return AXPlatformRange(std::move(anchor), std::move(focus)); | 213 return AXPlatformRange(std::move(anchor), std::move(focus)); |
| 202 } | 214 } |
| 203 | 215 |
| 204 AXPlatformPositionInstance CreateTextPosition( | 216 AXPlatformPositionInstance CreateTextPosition( |
| 205 const BrowserAccessibility& object, | 217 const BrowserAccessibility& object, |
| 206 int offset, | 218 int offset, |
| 207 ui::AXTextAffinity affinity) { | 219 ui::AXTextAffinity affinity) { |
| 208 if (!object.instance_active()) | 220 if (!object.instance_active()) |
| 209 return AXPlatformPosition::CreateNullPosition(); | 221 return AXPlatformPosition::CreateConcreteNullPosition(); |
| 210 | 222 |
| 211 const BrowserAccessibilityManager* manager = object.manager(); | 223 const BrowserAccessibilityManager* manager = object.manager(); |
| 212 DCHECK(manager); | 224 DCHECK(manager); |
| 213 return AXPlatformPosition::CreateTextPosition( | 225 return AXPlatformPosition::CreateConcreteTextPosition( |
| 214 manager->ax_tree_id(), object.GetId(), offset, affinity); | 226 manager->ax_tree_id(), object.GetId(), offset, affinity); |
| 215 } | 227 } |
| 216 | 228 |
| 217 AXPlatformRange CreateTextRange(const BrowserAccessibility& start_object, | 229 AXPlatformRange CreateTextRange(const BrowserAccessibility& start_object, |
| 218 int start_offset, | 230 int start_offset, |
| 219 ui::AXTextAffinity start_affinity, | 231 ui::AXTextAffinity start_affinity, |
| 220 const BrowserAccessibility& end_object, | 232 const BrowserAccessibility& end_object, |
| 221 int end_offset, | 233 int end_offset, |
| 222 ui::AXTextAffinity end_affinity) { | 234 ui::AXTextAffinity end_affinity) { |
| 223 AXPlatformPositionInstance anchor = | 235 AXPlatformPositionInstance anchor = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 279 |
| 268 NSAttributedString* GetAttributedTextForTextMarkerRange( | 280 NSAttributedString* GetAttributedTextForTextMarkerRange( |
| 269 AXTextMarkerRangeRef marker_range) { | 281 AXTextMarkerRangeRef marker_range) { |
| 270 BrowserAccessibility* start_object; | 282 BrowserAccessibility* start_object; |
| 271 BrowserAccessibility* end_object; | 283 BrowserAccessibility* end_object; |
| 272 int start_offset, end_offset; | 284 int start_offset, end_offset; |
| 273 ui::AXTextAffinity start_affinity, end_affinity; | 285 ui::AXTextAffinity start_affinity, end_affinity; |
| 274 AXPlatformRange ax_range = CreateRangeFromTextMarkerRange(marker_range); | 286 AXPlatformRange ax_range = CreateRangeFromTextMarkerRange(marker_range); |
| 275 if (ax_range.IsNull()) | 287 if (ax_range.IsNull()) |
| 276 return nil; | 288 return nil; |
| 277 start_object = ax_range.anchor()->GetAnchor(); | 289 start_object = ax_range.GetAnchorNode(); |
| 278 end_object = ax_range.focus()->GetAnchor(); | 290 end_object = ax_range.GetFocusNode(); |
| 279 start_offset = ax_range.anchor()->text_offset(); | 291 start_offset = ax_range.anchor()->text_offset(); |
| 280 end_offset = ax_range.focus()->text_offset(); | 292 end_offset = ax_range.focus()->text_offset(); |
| 281 start_affinity = ax_range.anchor()->affinity(); | 293 start_affinity = ax_range.anchor()->affinity(); |
| 282 end_affinity = ax_range.focus()->affinity(); | 294 end_affinity = ax_range.focus()->affinity(); |
| 283 | 295 |
| 284 NSString* text = base::SysUTF16ToNSString( | 296 NSString* text = base::SysUTF16ToNSString( |
| 285 BrowserAccessibilityManager::GetTextForRange(*start_object, *end_object)); | 297 BrowserAccessibilityManager::GetTextForRange(*start_object, *end_object)); |
| 286 if ([text length] == 0) | 298 if ([text length] == 0) |
| 287 return nil; | 299 return nil; |
| 288 | 300 |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 } | 980 } |
| 969 | 981 |
| 970 // Returns a text marker that points to the last character in the document that | 982 // Returns a text marker that points to the last character in the document that |
| 971 // can be selected with VoiceOver. | 983 // can be selected with VoiceOver. |
| 972 - (id)endTextMarker { | 984 - (id)endTextMarker { |
| 973 const BrowserAccessibility* root = | 985 const BrowserAccessibility* root = |
| 974 browserAccessibility_->manager()->GetRoot(); | 986 browserAccessibility_->manager()->GetRoot(); |
| 975 if (!root) | 987 if (!root) |
| 976 return nil; | 988 return nil; |
| 977 | 989 |
| 978 AXPlatformPositionInstance position = root->CreatePositionAt(0); | 990 AXAbstractPositionInstance position = root->CreatePositionAt(0); |
| 979 return CreateTextMarker(position->CreatePositionAtEndOfAnchor()); | 991 return CreateTextMarker(position->CreatePositionAtEndOfAnchor()); |
| 980 } | 992 } |
| 981 | 993 |
| 982 - (NSNumber*)expanded { | 994 - (NSNumber*)expanded { |
| 983 if (![self instanceActive]) | 995 if (![self instanceActive]) |
| 984 return nil; | 996 return nil; |
| 985 return [NSNumber numberWithBool: | 997 return [NSNumber numberWithBool: |
| 986 GetState(browserAccessibility_, ui::AX_STATE_EXPANDED)]; | 998 GetState(browserAccessibility_, ui::AX_STATE_EXPANDED)]; |
| 987 } | 999 } |
| 988 | 1000 |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 } | 1745 } |
| 1734 | 1746 |
| 1735 // Returns a text marker that points to the first character in the document that | 1747 // Returns a text marker that points to the first character in the document that |
| 1736 // can be selected with VoiceOver. | 1748 // can be selected with VoiceOver. |
| 1737 - (id)startTextMarker { | 1749 - (id)startTextMarker { |
| 1738 const BrowserAccessibility* root = | 1750 const BrowserAccessibility* root = |
| 1739 browserAccessibility_->manager()->GetRoot(); | 1751 browserAccessibility_->manager()->GetRoot(); |
| 1740 if (!root) | 1752 if (!root) |
| 1741 return nil; | 1753 return nil; |
| 1742 | 1754 |
| 1743 AXPlatformPositionInstance position = root->CreatePositionAt(0); | 1755 AXAbstractPositionInstance position = root->CreatePositionAt(0); |
| 1744 return CreateTextMarker(position->CreatePositionAtStartOfAnchor()); | 1756 return CreateTextMarker(position->CreatePositionAtStartOfAnchor()); |
| 1745 } | 1757 } |
| 1746 | 1758 |
| 1747 // Returns a subrole based upon the role. | 1759 // Returns a subrole based upon the role. |
| 1748 - (NSString*) subrole { | 1760 - (NSString*) subrole { |
| 1749 if (![self instanceActive]) | 1761 if (![self instanceActive]) |
| 1750 return nil; | 1762 return nil; |
| 1751 ui::AXRole browserAccessibilityRole = [self internalRole]; | 1763 ui::AXRole browserAccessibilityRole = [self internalRole]; |
| 1752 if (browserAccessibilityRole == ui::AX_ROLE_TEXT_FIELD && | 1764 if (browserAccessibilityRole == ui::AX_ROLE_TEXT_FIELD && |
| 1753 GetState(browserAccessibility_, ui::AX_STATE_PROTECTED)) { | 1765 GetState(browserAccessibility_, ui::AX_STATE_PROTECTED)) { |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2125 return ToBrowserAccessibilityCocoa(cell); | 2137 return ToBrowserAccessibilityCocoa(cell); |
| 2126 if (colIndex > column) | 2138 if (colIndex > column) |
| 2127 break; | 2139 break; |
| 2128 } | 2140 } |
| 2129 } | 2141 } |
| 2130 return nil; | 2142 return nil; |
| 2131 } | 2143 } |
| 2132 | 2144 |
| 2133 if ([attribute isEqualToString:@"AXUIElementForTextMarker"]) { | 2145 if ([attribute isEqualToString:@"AXUIElementForTextMarker"]) { |
| 2134 AXPlatformPositionInstance position = | 2146 AXPlatformPositionInstance position = |
| 2135 CreatePositionFromTextMarker(parameter); | 2147 CreateConcretePositionFromTextMarker(parameter); |
| 2136 if (!position->IsNullPosition()) | 2148 if (!position->IsNullPosition()) |
| 2137 return ToBrowserAccessibilityCocoa(position->GetAnchor()); | 2149 return ToBrowserAccessibilityCocoa(position->GetAnchor()); |
| 2138 | 2150 |
| 2139 return nil; | 2151 return nil; |
| 2140 } | 2152 } |
| 2141 | 2153 |
| 2142 if ([attribute isEqualToString:@"AXTextMarkerRangeForUIElement"]) { | 2154 if ([attribute isEqualToString:@"AXTextMarkerRangeForUIElement"]) { |
| 2143 AXPlatformPositionInstance startPosition = | 2155 AXAbstractPositionInstance startPosition = |
| 2144 browserAccessibility_->CreatePositionAt(0); | 2156 browserAccessibility_->CreatePositionAt(0); |
| 2145 AXPlatformPositionInstance endPosition = | 2157 AXAbstractPositionInstance endPosition = |
| 2146 startPosition->CreatePositionAtEndOfAnchor(); | 2158 startPosition->CreatePositionAtEndOfAnchor(); |
| 2147 AXPlatformRange range = | 2159 ui::AXAbstractRange range = |
| 2148 AXPlatformRange(std::move(startPosition), std::move(endPosition)); | 2160 ui::AXAbstractRange(std::move(startPosition), std::move(endPosition)); |
| 2149 return CreateTextMarkerRange(std::move(range)); | 2161 return CreateTextMarkerRange(std::move(range)); |
| 2150 } | 2162 } |
| 2151 | 2163 |
| 2152 if ([attribute isEqualToString:@"AXStringForTextMarkerRange"]) | 2164 if ([attribute isEqualToString:@"AXStringForTextMarkerRange"]) |
| 2153 return GetTextForTextMarkerRange(parameter); | 2165 return GetTextForTextMarkerRange(parameter); |
| 2154 | 2166 |
| 2155 if ([attribute isEqualToString:@"AXAttributedStringForTextMarkerRange"]) | 2167 if ([attribute isEqualToString:@"AXAttributedStringForTextMarkerRange"]) |
| 2156 return GetAttributedTextForTextMarkerRange(parameter); | 2168 return GetAttributedTextForTextMarkerRange(parameter); |
| 2157 | 2169 |
| 2158 if ([attribute isEqualToString:@"AXNextTextMarkerForTextMarker"]) { | 2170 if ([attribute isEqualToString:@"AXNextTextMarkerForTextMarker"]) { |
| 2159 AXPlatformPositionInstance position = | 2171 AXAbstractPositionInstance position = |
| 2160 CreatePositionFromTextMarker(parameter); | 2172 CreatePositionFromTextMarker(parameter); |
| 2161 if (position->IsNullPosition()) | 2173 if (position->IsNullPosition()) |
| 2162 return nil; | 2174 return nil; |
| 2163 return CreateTextMarker(position->CreateNextCharacterPosition()); | 2175 return CreateTextMarker(position->CreateNextCharacterPosition()); |
| 2164 } | 2176 } |
| 2165 | 2177 |
| 2166 if ([attribute isEqualToString:@"AXPreviousTextMarkerForTextMarker"]) { | 2178 if ([attribute isEqualToString:@"AXPreviousTextMarkerForTextMarker"]) { |
| 2167 AXPlatformPositionInstance position = | 2179 AXAbstractPositionInstance position = |
| 2168 CreatePositionFromTextMarker(parameter); | 2180 CreatePositionFromTextMarker(parameter); |
| 2169 if (position->IsNullPosition()) | 2181 if (position->IsNullPosition()) |
| 2170 return nil; | 2182 return nil; |
| 2171 return CreateTextMarker(position->CreatePreviousCharacterPosition()); | 2183 return CreateTextMarker(position->CreatePreviousCharacterPosition()); |
| 2172 } | 2184 } |
| 2173 | 2185 |
| 2174 if ([attribute isEqualToString:@"AXLeftWordTextMarkerRangeForTextMarker"]) { | 2186 if ([attribute isEqualToString:@"AXLeftWordTextMarkerRangeForTextMarker"]) { |
| 2175 AXPlatformPositionInstance endPosition = | 2187 AXAbstractPositionInstance endPosition = |
| 2176 CreatePositionFromTextMarker(parameter); | 2188 CreatePositionFromTextMarker(parameter); |
| 2177 if (endPosition->IsNullPosition()) | 2189 if (endPosition->IsNullPosition()) |
| 2178 return nil; | 2190 return nil; |
| 2179 | 2191 |
| 2180 AXPlatformPositionInstance startWordPosition = | 2192 AXAbstractPositionInstance startWordPosition = |
| 2181 endPosition->CreatePreviousWordStartPosition(); | 2193 endPosition->CreatePreviousWordStartPosition(); |
| 2182 AXPlatformPositionInstance endWordPosition = | 2194 AXAbstractPositionInstance endWordPosition = |
| 2183 endPosition->CreatePreviousWordEndPosition(); | 2195 endPosition->CreatePreviousWordEndPosition(); |
| 2184 AXPlatformPositionInstance startPosition = | 2196 AXAbstractPositionInstance startPosition = |
| 2185 *startWordPosition <= *endWordPosition ? std::move(endWordPosition) | 2197 *startWordPosition <= *endWordPosition ? std::move(endWordPosition) |
| 2186 : std::move(startWordPosition); | 2198 : std::move(startWordPosition); |
| 2187 AXPlatformRange range(std::move(startPosition), std::move(endPosition)); | 2199 ui::AXAbstractRange range(std::move(startPosition), std::move(endPosition)); |
| 2188 return CreateTextMarkerRange(std::move(range)); | 2200 return CreateTextMarkerRange(std::move(range)); |
| 2189 } | 2201 } |
| 2190 | 2202 |
| 2191 if ([attribute isEqualToString:@"AXRightWordTextMarkerRangeForTextMarker"]) { | 2203 if ([attribute isEqualToString:@"AXRightWordTextMarkerRangeForTextMarker"]) { |
| 2192 AXPlatformPositionInstance startPosition = | 2204 AXAbstractPositionInstance startPosition = |
| 2193 CreatePositionFromTextMarker(parameter); | 2205 CreatePositionFromTextMarker(parameter); |
| 2194 if (startPosition->IsNullPosition()) | 2206 if (startPosition->IsNullPosition()) |
| 2195 return nil; | 2207 return nil; |
| 2196 | 2208 |
| 2197 AXPlatformPositionInstance endWordPosition = | 2209 AXAbstractPositionInstance endWordPosition = |
| 2198 startPosition->CreateNextWordEndPosition(); | 2210 startPosition->CreateNextWordEndPosition(); |
| 2199 AXPlatformPositionInstance startWordPosition = | 2211 AXAbstractPositionInstance startWordPosition = |
| 2200 startPosition->CreateNextWordStartPosition(); | 2212 startPosition->CreateNextWordStartPosition(); |
| 2201 AXPlatformPositionInstance endPosition = | 2213 AXAbstractPositionInstance endPosition = |
| 2202 *startWordPosition <= *endWordPosition ? std::move(startWordPosition) | 2214 *startWordPosition <= *endWordPosition ? std::move(startWordPosition) |
| 2203 : std::move(endWordPosition); | 2215 : std::move(endWordPosition); |
| 2204 AXPlatformRange range(std::move(startPosition), std::move(endPosition)); | 2216 ui::AXAbstractRange range(std::move(startPosition), std::move(endPosition)); |
| 2205 return CreateTextMarkerRange(std::move(range)); | 2217 return CreateTextMarkerRange(std::move(range)); |
| 2206 } | 2218 } |
| 2207 | 2219 |
| 2208 if ([attribute isEqualToString:@"AXNextWordEndTextMarkerForTextMarker"]) { | 2220 if ([attribute isEqualToString:@"AXNextWordEndTextMarkerForTextMarker"]) { |
| 2209 AXPlatformPositionInstance position = | 2221 AXAbstractPositionInstance position = |
| 2210 CreatePositionFromTextMarker(parameter); | 2222 CreatePositionFromTextMarker(parameter); |
| 2211 if (position->IsNullPosition()) | 2223 if (position->IsNullPosition()) |
| 2212 return nil; | 2224 return nil; |
| 2213 return CreateTextMarker(position->CreateNextWordEndPosition()); | 2225 return CreateTextMarker(position->CreateNextWordEndPosition()); |
| 2214 } | 2226 } |
| 2215 | 2227 |
| 2216 if ([attribute | 2228 if ([attribute |
| 2217 isEqualToString:@"AXPreviousWordStartTextMarkerForTextMarker"]) { | 2229 isEqualToString:@"AXPreviousWordStartTextMarkerForTextMarker"]) { |
| 2218 AXPlatformPositionInstance position = | 2230 AXAbstractPositionInstance position = |
| 2219 CreatePositionFromTextMarker(parameter); | 2231 CreatePositionFromTextMarker(parameter); |
| 2220 if (position->IsNullPosition()) | 2232 if (position->IsNullPosition()) |
| 2221 return nil; | 2233 return nil; |
| 2222 return CreateTextMarker(position->CreatePreviousWordStartPosition()); | 2234 return CreateTextMarker(position->CreatePreviousWordStartPosition()); |
| 2223 } | 2235 } |
| 2224 | 2236 |
| 2225 if ([attribute isEqualToString:@"AXTextMarkerRangeForLine"]) { | 2237 if ([attribute isEqualToString:@"AXTextMarkerRangeForLine"]) { |
| 2226 AXPlatformPositionInstance position = | 2238 AXAbstractPositionInstance position = |
| 2227 CreatePositionFromTextMarker(parameter); | 2239 CreatePositionFromTextMarker(parameter); |
| 2228 if (position->IsNullPosition()) | 2240 if (position->IsNullPosition()) |
| 2229 return nil; | 2241 return nil; |
| 2230 | 2242 |
| 2231 AXPlatformPositionInstance startPosition = | 2243 AXAbstractPositionInstance startPosition = |
| 2232 position->CreatePreviousLineStartPosition(); | 2244 position->CreatePreviousLineStartPosition(); |
| 2233 AXPlatformPositionInstance endPosition = | 2245 AXAbstractPositionInstance endPosition = |
| 2234 position->CreateNextLineEndPosition(); | 2246 position->CreateNextLineEndPosition(); |
| 2235 AXPlatformRange range(std::move(startPosition), std::move(endPosition)); | 2247 ui::AXAbstractRange range(std::move(startPosition), std::move(endPosition)); |
| 2236 return CreateTextMarkerRange(std::move(range)); | 2248 return CreateTextMarkerRange(std::move(range)); |
| 2237 } | 2249 } |
| 2238 | 2250 |
| 2239 if ([attribute isEqualToString:@"AXLeftLineTextMarkerRangeForTextMarker"]) { | 2251 if ([attribute isEqualToString:@"AXLeftLineTextMarkerRangeForTextMarker"]) { |
| 2240 AXPlatformPositionInstance endPosition = | 2252 AXAbstractPositionInstance endPosition = |
| 2241 CreatePositionFromTextMarker(parameter); | 2253 CreatePositionFromTextMarker(parameter); |
| 2242 if (endPosition->IsNullPosition()) | 2254 if (endPosition->IsNullPosition()) |
| 2243 return nil; | 2255 return nil; |
| 2244 | 2256 |
| 2245 AXPlatformPositionInstance startLinePosition = | 2257 AXAbstractPositionInstance startLinePosition = |
| 2246 endPosition->CreatePreviousLineStartPosition(); | 2258 endPosition->CreatePreviousLineStartPosition(); |
| 2247 AXPlatformPositionInstance endLinePosition = | 2259 AXAbstractPositionInstance endLinePosition = |
| 2248 endPosition->CreatePreviousLineEndPosition(); | 2260 endPosition->CreatePreviousLineEndPosition(); |
| 2249 AXPlatformPositionInstance startPosition = | 2261 AXAbstractPositionInstance startPosition = |
| 2250 *startLinePosition <= *endLinePosition ? std::move(endLinePosition) | 2262 *startLinePosition <= *endLinePosition ? std::move(endLinePosition) |
| 2251 : std::move(startLinePosition); | 2263 : std::move(startLinePosition); |
| 2252 AXPlatformRange range(std::move(startPosition), std::move(endPosition)); | 2264 ui::AXAbstractRange range(std::move(startPosition), std::move(endPosition)); |
| 2253 return CreateTextMarkerRange(std::move(range)); | 2265 return CreateTextMarkerRange(std::move(range)); |
| 2254 } | 2266 } |
| 2255 | 2267 |
| 2256 if ([attribute isEqualToString:@"AXRightLineTextMarkerRangeForTextMarker"]) { | 2268 if ([attribute isEqualToString:@"AXRightLineTextMarkerRangeForTextMarker"]) { |
| 2257 AXPlatformPositionInstance startPosition = | 2269 AXAbstractPositionInstance startPosition = |
| 2258 CreatePositionFromTextMarker(parameter); | 2270 CreatePositionFromTextMarker(parameter); |
| 2259 if (startPosition->IsNullPosition()) | 2271 if (startPosition->IsNullPosition()) |
| 2260 return nil; | 2272 return nil; |
| 2261 | 2273 |
| 2262 AXPlatformPositionInstance startLinePosition = | 2274 AXAbstractPositionInstance startLinePosition = |
| 2263 startPosition->CreateNextLineStartPosition(); | 2275 startPosition->CreateNextLineStartPosition(); |
| 2264 AXPlatformPositionInstance endLinePosition = | 2276 AXAbstractPositionInstance endLinePosition = |
| 2265 startPosition->CreateNextLineEndPosition(); | 2277 startPosition->CreateNextLineEndPosition(); |
| 2266 AXPlatformPositionInstance endPosition = | 2278 AXAbstractPositionInstance endPosition = |
| 2267 *startLinePosition <= *endLinePosition ? std::move(startLinePosition) | 2279 *startLinePosition <= *endLinePosition ? std::move(startLinePosition) |
| 2268 : std::move(endLinePosition); | 2280 : std::move(endLinePosition); |
| 2269 AXPlatformRange range(std::move(startPosition), std::move(endPosition)); | 2281 ui::AXAbstractRange range(std::move(startPosition), std::move(endPosition)); |
| 2270 return CreateTextMarkerRange(std::move(range)); | 2282 return CreateTextMarkerRange(std::move(range)); |
| 2271 } | 2283 } |
| 2272 | 2284 |
| 2273 if ([attribute isEqualToString:@"AXNextLineEndTextMarkerForTextMarker"]) { | 2285 if ([attribute isEqualToString:@"AXNextLineEndTextMarkerForTextMarker"]) { |
| 2274 AXPlatformPositionInstance position = | 2286 AXAbstractPositionInstance position = |
| 2275 CreatePositionFromTextMarker(parameter); | 2287 CreatePositionFromTextMarker(parameter); |
| 2276 if (position->IsNullPosition()) | 2288 if (position->IsNullPosition()) |
| 2277 return nil; | 2289 return nil; |
| 2278 return CreateTextMarker(position->CreateNextLineEndPosition()); | 2290 return CreateTextMarker(position->CreateNextLineEndPosition()); |
| 2279 } | 2291 } |
| 2280 | 2292 |
| 2281 if ([attribute | 2293 if ([attribute |
| 2282 isEqualToString:@"AXPreviousLineStartTextMarkerForTextMarker"]) { | 2294 isEqualToString:@"AXPreviousLineStartTextMarkerForTextMarker"]) { |
| 2283 AXPlatformPositionInstance position = | 2295 AXAbstractPositionInstance position = |
| 2284 CreatePositionFromTextMarker(parameter); | 2296 CreatePositionFromTextMarker(parameter); |
| 2285 if (position->IsNullPosition()) | 2297 if (position->IsNullPosition()) |
| 2286 return nil; | 2298 return nil; |
| 2287 return CreateTextMarker(position->CreatePreviousLineStartPosition()); | 2299 return CreateTextMarker(position->CreatePreviousLineStartPosition()); |
| 2288 } | 2300 } |
| 2289 | 2301 |
| 2290 if ([attribute isEqualToString:@"AXLengthForTextMarkerRange"]) { | 2302 if ([attribute isEqualToString:@"AXLengthForTextMarkerRange"]) { |
| 2291 NSString* text = GetTextForTextMarkerRange(parameter); | 2303 NSString* text = GetTextForTextMarkerRange(parameter); |
| 2292 return [NSNumber numberWithInt:[text length]]; | 2304 return [NSNumber numberWithInt:[text length]]; |
| 2293 } | 2305 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2323 BrowserAccessibility* match = search.GetMatchAtIndex(i); | 2335 BrowserAccessibility* match = search.GetMatchAtIndex(i); |
| 2324 [result addObject:ToBrowserAccessibilityCocoa(match)]; | 2336 [result addObject:ToBrowserAccessibilityCocoa(match)]; |
| 2325 } | 2337 } |
| 2326 return result; | 2338 return result; |
| 2327 } | 2339 } |
| 2328 return nil; | 2340 return nil; |
| 2329 } | 2341 } |
| 2330 | 2342 |
| 2331 if ([attribute isEqualToString: | 2343 if ([attribute isEqualToString: |
| 2332 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute
]) { | 2344 NSAccessibilityLineTextMarkerRangeForTextMarkerParameterizedAttribute
]) { |
| 2333 AXPlatformPositionInstance position = | 2345 AXAbstractPositionInstance position = |
| 2334 CreatePositionFromTextMarker(parameter); | 2346 CreatePositionFromTextMarker(parameter); |
| 2335 if (position->IsNullPosition()) | 2347 if (position->IsNullPosition()) |
| 2336 return nil; | 2348 return nil; |
| 2337 | 2349 |
| 2338 AXPlatformRange range(position->CreatePreviousLineStartPosition(), | 2350 ui::AXAbstractRange range(position->CreatePreviousLineStartPosition(), |
| 2339 position->CreateNextLineEndPosition()); | 2351 position->CreateNextLineEndPosition()); |
| 2340 return CreateTextMarkerRange(std::move(range)); | 2352 return CreateTextMarkerRange(std::move(range)); |
| 2341 } | 2353 } |
| 2342 | 2354 |
| 2343 if ([attribute isEqualToString: | 2355 if ([attribute isEqualToString: |
| 2344 NSAccessibilityBoundsForTextMarkerRangeParameterizedAttribute]) { | 2356 NSAccessibilityBoundsForTextMarkerRangeParameterizedAttribute]) { |
| 2345 BrowserAccessibility* startObject; | 2357 BrowserAccessibility* startObject; |
| 2346 BrowserAccessibility* endObject; | 2358 BrowserAccessibility* endObject; |
| 2347 int startOffset, endOffset; | 2359 int startOffset, endOffset; |
| 2348 AXPlatformRange range = CreateRangeFromTextMarkerRange(parameter); | 2360 AXPlatformRange range = CreateRangeFromTextMarkerRange(parameter); |
| 2349 if (range.IsNull()) | 2361 if (range.IsNull()) |
| 2350 return nil; | 2362 return nil; |
| 2351 | 2363 |
| 2352 startObject = range.anchor()->GetAnchor(); | 2364 startObject = range.GetAnchorNode(); |
| 2353 endObject = range.focus()->GetAnchor(); | 2365 endObject = range.GetFocusNode(); |
| 2354 startOffset = range.anchor()->text_offset(); | 2366 startOffset = range.anchor()->text_offset(); |
| 2355 endOffset = range.focus()->text_offset(); | 2367 endOffset = range.focus()->text_offset(); |
| 2356 DCHECK(startObject && endObject); | 2368 DCHECK(startObject && endObject); |
| 2357 DCHECK_GE(startOffset, 0); | 2369 DCHECK_GE(startOffset, 0); |
| 2358 DCHECK_GE(endOffset, 0); | 2370 DCHECK_GE(endOffset, 0); |
| 2359 | 2371 |
| 2360 gfx::Rect rect = BrowserAccessibilityManager::GetPageBoundsForRange( | 2372 gfx::Rect rect = BrowserAccessibilityManager::GetPageBoundsForRange( |
| 2361 *startObject, startOffset, *endObject, endOffset); | 2373 *startObject, startOffset, *endObject, endOffset); |
| 2362 NSPoint origin = NSMakePoint(rect.x(), rect.y()); | 2374 NSPoint origin = NSMakePoint(rect.x(), rect.y()); |
| 2363 NSSize size = NSMakeSize(rect.width(), rect.height()); | 2375 NSSize size = NSMakeSize(rect.width(), rect.height()); |
| 2364 NSPoint pointInScreen = [self pointInScreen:origin size:size]; | 2376 NSPoint pointInScreen = [self pointInScreen:origin size:size]; |
| 2365 NSRect nsrect = NSMakeRect( | 2377 NSRect nsrect = NSMakeRect( |
| 2366 pointInScreen.x, pointInScreen.y, rect.width(), rect.height()); | 2378 pointInScreen.x, pointInScreen.y, rect.width(), rect.height()); |
| 2367 return [NSValue valueWithRect:nsrect]; | 2379 return [NSValue valueWithRect:nsrect]; |
| 2368 } | 2380 } |
| 2369 | 2381 |
| 2370 if ([attribute isEqualToString: | 2382 if ([attribute isEqualToString: |
| 2371 NSAccessibilityTextMarkerRangeForUnorderedTextMarkersParameterizedAtt
ribute]) { | 2383 NSAccessibilityTextMarkerRangeForUnorderedTextMarkersParameterizedAtt
ribute]) { |
| 2372 if (![parameter isKindOfClass:[NSArray class]]) | 2384 if (![parameter isKindOfClass:[NSArray class]]) |
| 2373 return nil; | 2385 return nil; |
| 2374 | 2386 |
| 2375 NSArray* text_marker_array = parameter; | 2387 NSArray* text_marker_array = parameter; |
| 2376 if ([text_marker_array count] != 2) | 2388 if ([text_marker_array count] != 2) |
| 2377 return nil; | 2389 return nil; |
| 2378 | 2390 |
| 2379 AXPlatformPositionInstance startPosition = | 2391 AXAbstractPositionInstance startPosition = |
| 2380 CreatePositionFromTextMarker([text_marker_array objectAtIndex:0]); | 2392 CreatePositionFromTextMarker([text_marker_array objectAtIndex:0]); |
| 2381 AXPlatformPositionInstance endPosition = | 2393 AXAbstractPositionInstance endPosition = |
| 2382 CreatePositionFromTextMarker([text_marker_array objectAtIndex:1]); | 2394 CreatePositionFromTextMarker([text_marker_array objectAtIndex:1]); |
| 2383 if (*startPosition <= *endPosition) { | 2395 if (*startPosition <= *endPosition) { |
| 2384 return CreateTextMarkerRange( | 2396 return CreateTextMarkerRange(ui::AXAbstractRange(std::move(startPosition), |
| 2385 AXPlatformRange(std::move(startPosition), std::move(endPosition))); | 2397 std::move(endPosition))); |
| 2386 } else { | 2398 } else { |
| 2387 return CreateTextMarkerRange( | 2399 return CreateTextMarkerRange(ui::AXAbstractRange( |
| 2388 AXPlatformRange(std::move(endPosition), std::move(startPosition))); | 2400 std::move(endPosition), std::move(startPosition))); |
| 2389 } | 2401 } |
| 2390 } | 2402 } |
| 2391 | 2403 |
| 2392 if ([attribute isEqualToString: | 2404 if ([attribute isEqualToString: |
| 2393 NSAccessibilityIndexForChildUIElementParameterizedAttribute]) { | 2405 NSAccessibilityIndexForChildUIElementParameterizedAttribute]) { |
| 2394 if (![parameter isKindOfClass:[BrowserAccessibilityCocoa class]]) | 2406 if (![parameter isKindOfClass:[BrowserAccessibilityCocoa class]]) |
| 2395 return nil; | 2407 return nil; |
| 2396 | 2408 |
| 2397 BrowserAccessibilityCocoa* childCocoaObj = | 2409 BrowserAccessibilityCocoa* childCocoaObj = |
| 2398 (BrowserAccessibilityCocoa*)parameter; | 2410 (BrowserAccessibilityCocoa*)parameter; |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 } | 2891 } |
| 2880 | 2892 |
| 2881 - (BOOL)accessibilityNotifiesWhenDestroyed { | 2893 - (BOOL)accessibilityNotifiesWhenDestroyed { |
| 2882 // Indicate that BrowserAccessibilityCocoa will post a notification when it's | 2894 // Indicate that BrowserAccessibilityCocoa will post a notification when it's |
| 2883 // destroyed (see -detach). This allows VoiceOver to do some internal things | 2895 // destroyed (see -detach). This allows VoiceOver to do some internal things |
| 2884 // more efficiently. | 2896 // more efficiently. |
| 2885 return YES; | 2897 return YES; |
| 2886 } | 2898 } |
| 2887 | 2899 |
| 2888 @end | 2900 @end |
| OLD | NEW |