OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/accessibility/platform/ax_platform_node_base.h" | 5 #include "ui/accessibility/platform/ax_platform_node_base.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/accessibility/ax_action_data.h" | 8 #include "ui/accessibility/ax_action_data.h" |
9 #include "ui/accessibility/ax_node_data.h" | 9 #include "ui/accessibility/ax_node_data.h" |
10 #include "ui/accessibility/ax_role_properties.h" | 10 #include "ui/accessibility/ax_role_properties.h" |
11 #include "ui/accessibility/platform/ax_platform_node_delegate.h" | 11 #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
12 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) { | 16 void AXPlatformNodeBase::Init(AXPlatformNodeDelegate* delegate) { |
17 delegate_ = delegate; | 17 delegate_ = delegate; |
18 } | 18 } |
19 | 19 |
20 const AXNodeData& AXPlatformNodeBase::GetData() const { | 20 const AXNodeData& AXPlatformNodeBase::GetData() const { |
21 CHECK(delegate_); | 21 CR_DEFINE_STATIC_LOCAL(ui::AXNodeData, empty_data, ()); |
22 return delegate_->GetData(); | 22 if (delegate_) |
| 23 return delegate_->GetData(); |
| 24 return empty_data; |
23 } | 25 } |
24 | 26 |
25 gfx::Rect AXPlatformNodeBase::GetBoundsInScreen() const { | 27 gfx::Rect AXPlatformNodeBase::GetBoundsInScreen() const { |
26 CHECK(delegate_); | 28 if (delegate_) |
27 return delegate_->GetScreenBoundsRect(); | 29 return delegate_->GetScreenBoundsRect(); |
| 30 return gfx::Rect(); |
28 } | 31 } |
29 | 32 |
30 gfx::NativeViewAccessible AXPlatformNodeBase::GetParent() { | 33 gfx::NativeViewAccessible AXPlatformNodeBase::GetParent() { |
31 CHECK(delegate_); | 34 if (delegate_) |
32 return delegate_->GetParent(); | 35 return delegate_->GetParent(); |
| 36 return nullptr; |
33 } | 37 } |
34 | 38 |
35 int AXPlatformNodeBase::GetChildCount() { | 39 int AXPlatformNodeBase::GetChildCount() { |
36 CHECK(delegate_); | 40 if (delegate_) |
37 return delegate_->GetChildCount(); | 41 return delegate_->GetChildCount(); |
| 42 return 0; |
38 } | 43 } |
39 | 44 |
40 gfx::NativeViewAccessible AXPlatformNodeBase::ChildAtIndex(int index) { | 45 gfx::NativeViewAccessible AXPlatformNodeBase::ChildAtIndex(int index) { |
41 CHECK(delegate_); | 46 if (delegate_) |
42 return delegate_->ChildAtIndex(index); | 47 return delegate_->ChildAtIndex(index); |
| 48 return nullptr; |
43 } | 49 } |
44 | 50 |
45 // AXPlatformNode overrides. | 51 // AXPlatformNode overrides. |
46 | 52 |
47 void AXPlatformNodeBase::Destroy() { | 53 void AXPlatformNodeBase::Destroy() { |
48 AXPlatformNode::Destroy(); | 54 AXPlatformNode::Destroy(); |
49 delegate_ = nullptr; | 55 delegate_ = nullptr; |
50 Dispose(); | 56 Dispose(); |
51 } | 57 } |
52 | 58 |
53 void AXPlatformNodeBase::Dispose() { | 59 void AXPlatformNodeBase::Dispose() { |
54 delete this; | 60 delete this; |
55 } | 61 } |
56 | 62 |
57 gfx::NativeViewAccessible AXPlatformNodeBase::GetNativeViewAccessible() { | 63 gfx::NativeViewAccessible AXPlatformNodeBase::GetNativeViewAccessible() { |
58 return nullptr; | 64 return nullptr; |
59 } | 65 } |
60 | 66 |
61 AXPlatformNodeDelegate* AXPlatformNodeBase::GetDelegate() const { | 67 AXPlatformNodeDelegate* AXPlatformNodeBase::GetDelegate() const { |
62 return delegate_; | 68 return delegate_; |
63 } | 69 } |
64 | 70 |
65 // Helpers. | 71 // Helpers. |
66 | 72 |
67 AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() { | 73 AXPlatformNodeBase* AXPlatformNodeBase::GetPreviousSibling() { |
68 CHECK(delegate_); | 74 if (!delegate_) |
| 75 return nullptr; |
69 gfx::NativeViewAccessible parent_accessible = GetParent(); | 76 gfx::NativeViewAccessible parent_accessible = GetParent(); |
70 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); | 77 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); |
71 if (!parent) | 78 if (!parent) |
72 return nullptr; | 79 return nullptr; |
73 | 80 |
74 int previous_index = GetIndexInParent() - 1; | 81 int previous_index = GetIndexInParent() - 1; |
75 if (previous_index >= 0 && | 82 if (previous_index >= 0 && |
76 previous_index < parent->GetChildCount()) { | 83 previous_index < parent->GetChildCount()) { |
77 return FromNativeViewAccessible(parent->ChildAtIndex(previous_index)); | 84 return FromNativeViewAccessible(parent->ChildAtIndex(previous_index)); |
78 } | 85 } |
79 return nullptr; | 86 return nullptr; |
80 } | 87 } |
81 | 88 |
82 AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() { | 89 AXPlatformNodeBase* AXPlatformNodeBase::GetNextSibling() { |
83 CHECK(delegate_); | 90 if (!delegate_) |
| 91 return nullptr; |
84 gfx::NativeViewAccessible parent_accessible = GetParent(); | 92 gfx::NativeViewAccessible parent_accessible = GetParent(); |
85 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); | 93 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); |
86 if (!parent) | 94 if (!parent) |
87 return nullptr; | 95 return nullptr; |
88 | 96 |
89 int next_index = GetIndexInParent() + 1; | 97 int next_index = GetIndexInParent() + 1; |
90 if (next_index >= 0 && next_index < parent->GetChildCount()) | 98 if (next_index >= 0 && next_index < parent->GetChildCount()) |
91 return FromNativeViewAccessible(parent->ChildAtIndex(next_index)); | 99 return FromNativeViewAccessible(parent->ChildAtIndex(next_index)); |
92 return nullptr; | 100 return nullptr; |
93 } | 101 } |
94 | 102 |
95 bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) { | 103 bool AXPlatformNodeBase::IsDescendant(AXPlatformNodeBase* node) { |
96 CHECK(delegate_); | 104 if (!delegate_) |
| 105 return false; |
97 if (!node) | 106 if (!node) |
98 return false; | 107 return false; |
99 if (node == this) | 108 if (node == this) |
100 return true; | 109 return true; |
101 gfx::NativeViewAccessible native_parent = node->GetParent(); | 110 gfx::NativeViewAccessible native_parent = node->GetParent(); |
102 if (!native_parent) | 111 if (!native_parent) |
103 return false; | 112 return false; |
104 AXPlatformNodeBase* parent = FromNativeViewAccessible(native_parent); | 113 AXPlatformNodeBase* parent = FromNativeViewAccessible(native_parent); |
105 return IsDescendant(parent); | 114 return IsDescendant(parent); |
106 } | 115 } |
107 | 116 |
108 bool AXPlatformNodeBase::HasBoolAttribute( | 117 bool AXPlatformNodeBase::HasBoolAttribute( |
109 ui::AXBoolAttribute attribute) const { | 118 ui::AXBoolAttribute attribute) const { |
110 CHECK(delegate_); | 119 if (!delegate_) |
| 120 return false; |
111 return GetData().HasBoolAttribute(attribute); | 121 return GetData().HasBoolAttribute(attribute); |
112 } | 122 } |
113 | 123 |
114 bool AXPlatformNodeBase::GetBoolAttribute( | 124 bool AXPlatformNodeBase::GetBoolAttribute( |
115 ui::AXBoolAttribute attribute) const { | 125 ui::AXBoolAttribute attribute) const { |
116 CHECK(delegate_); | 126 if (!delegate_) |
| 127 return false; |
117 return GetData().GetBoolAttribute(attribute); | 128 return GetData().GetBoolAttribute(attribute); |
118 } | 129 } |
119 | 130 |
120 bool AXPlatformNodeBase::GetBoolAttribute( | 131 bool AXPlatformNodeBase::GetBoolAttribute( |
121 ui::AXBoolAttribute attribute, bool* value) const { | 132 ui::AXBoolAttribute attribute, bool* value) const { |
122 CHECK(delegate_); | 133 if (!delegate_) |
| 134 return false; |
123 return GetData().GetBoolAttribute(attribute, value); | 135 return GetData().GetBoolAttribute(attribute, value); |
124 } | 136 } |
125 | 137 |
126 bool AXPlatformNodeBase::HasFloatAttribute( | 138 bool AXPlatformNodeBase::HasFloatAttribute( |
127 ui::AXFloatAttribute attribute) const { | 139 ui::AXFloatAttribute attribute) const { |
128 CHECK(delegate_); | 140 if (!delegate_) |
| 141 return false; |
129 return GetData().HasFloatAttribute(attribute); | 142 return GetData().HasFloatAttribute(attribute); |
130 } | 143 } |
131 | 144 |
132 float AXPlatformNodeBase::GetFloatAttribute( | 145 float AXPlatformNodeBase::GetFloatAttribute( |
133 ui::AXFloatAttribute attribute) const { | 146 ui::AXFloatAttribute attribute) const { |
134 CHECK(delegate_); | 147 if (!delegate_) |
| 148 return false; |
135 return GetData().GetFloatAttribute(attribute); | 149 return GetData().GetFloatAttribute(attribute); |
136 } | 150 } |
137 | 151 |
138 bool AXPlatformNodeBase::GetFloatAttribute( | 152 bool AXPlatformNodeBase::GetFloatAttribute( |
139 ui::AXFloatAttribute attribute, float* value) const { | 153 ui::AXFloatAttribute attribute, float* value) const { |
140 CHECK(delegate_); | 154 if (!delegate_) |
| 155 return false; |
141 return GetData().GetFloatAttribute(attribute, value); | 156 return GetData().GetFloatAttribute(attribute, value); |
142 } | 157 } |
143 | 158 |
144 bool AXPlatformNodeBase::HasIntAttribute( | 159 bool AXPlatformNodeBase::HasIntAttribute( |
145 ui::AXIntAttribute attribute) const { | 160 ui::AXIntAttribute attribute) const { |
146 CHECK(delegate_); | 161 if (!delegate_) |
| 162 return false; |
147 return GetData().HasIntAttribute(attribute); | 163 return GetData().HasIntAttribute(attribute); |
148 } | 164 } |
149 | 165 |
150 int AXPlatformNodeBase::GetIntAttribute( | 166 int AXPlatformNodeBase::GetIntAttribute( |
151 ui::AXIntAttribute attribute) const { | 167 ui::AXIntAttribute attribute) const { |
152 CHECK(delegate_); | 168 if (!delegate_) |
| 169 return false; |
153 return GetData().GetIntAttribute(attribute); | 170 return GetData().GetIntAttribute(attribute); |
154 } | 171 } |
155 | 172 |
156 bool AXPlatformNodeBase::GetIntAttribute( | 173 bool AXPlatformNodeBase::GetIntAttribute( |
157 ui::AXIntAttribute attribute, int* value) const { | 174 ui::AXIntAttribute attribute, int* value) const { |
158 CHECK(delegate_); | 175 if (!delegate_) |
| 176 return false; |
159 return GetData().GetIntAttribute(attribute, value); | 177 return GetData().GetIntAttribute(attribute, value); |
160 } | 178 } |
161 | 179 |
162 bool AXPlatformNodeBase::HasStringAttribute( | 180 bool AXPlatformNodeBase::HasStringAttribute( |
163 ui::AXStringAttribute attribute) const { | 181 ui::AXStringAttribute attribute) const { |
164 CHECK(delegate_); | 182 if (!delegate_) |
| 183 return false; |
165 return GetData().HasStringAttribute(attribute); | 184 return GetData().HasStringAttribute(attribute); |
166 } | 185 } |
167 | 186 |
168 const std::string& AXPlatformNodeBase::GetStringAttribute( | 187 const std::string& AXPlatformNodeBase::GetStringAttribute( |
169 ui::AXStringAttribute attribute) const { | 188 ui::AXStringAttribute attribute) const { |
170 CHECK(delegate_); | 189 CR_DEFINE_STATIC_LOCAL(std::string, empty_data, ()); |
| 190 if (!delegate_) |
| 191 return empty_data; |
171 return GetData().GetStringAttribute(attribute); | 192 return GetData().GetStringAttribute(attribute); |
172 } | 193 } |
173 | 194 |
174 bool AXPlatformNodeBase::GetStringAttribute( | 195 bool AXPlatformNodeBase::GetStringAttribute( |
175 ui::AXStringAttribute attribute, std::string* value) const { | 196 ui::AXStringAttribute attribute, std::string* value) const { |
176 CHECK(delegate_); | 197 if (!delegate_) |
| 198 return false; |
177 return GetData().GetStringAttribute(attribute, value); | 199 return GetData().GetStringAttribute(attribute, value); |
178 } | 200 } |
179 | 201 |
180 base::string16 AXPlatformNodeBase::GetString16Attribute( | 202 base::string16 AXPlatformNodeBase::GetString16Attribute( |
181 ui::AXStringAttribute attribute) const { | 203 ui::AXStringAttribute attribute) const { |
182 CHECK(delegate_); | 204 if (!delegate_) |
| 205 return base::string16(); |
183 return GetData().GetString16Attribute(attribute); | 206 return GetData().GetString16Attribute(attribute); |
184 } | 207 } |
185 | 208 |
186 bool AXPlatformNodeBase::GetString16Attribute( | 209 bool AXPlatformNodeBase::GetString16Attribute( |
187 ui::AXStringAttribute attribute, | 210 ui::AXStringAttribute attribute, |
188 base::string16* value) const { | 211 base::string16* value) const { |
189 CHECK(delegate_); | 212 if (!delegate_) |
| 213 return false; |
190 return GetData().GetString16Attribute(attribute, value); | 214 return GetData().GetString16Attribute(attribute, value); |
191 } | 215 } |
192 | 216 |
193 bool AXPlatformNodeBase::HasIntListAttribute( | 217 bool AXPlatformNodeBase::HasIntListAttribute( |
194 ui::AXIntListAttribute attribute) const { | 218 ui::AXIntListAttribute attribute) const { |
| 219 if (!delegate_) |
| 220 return false; |
195 return GetData().HasIntListAttribute(attribute); | 221 return GetData().HasIntListAttribute(attribute); |
196 } | 222 } |
197 | 223 |
198 const std::vector<int32_t>& AXPlatformNodeBase::GetIntListAttribute( | 224 const std::vector<int32_t>& AXPlatformNodeBase::GetIntListAttribute( |
199 ui::AXIntListAttribute attribute) const { | 225 ui::AXIntListAttribute attribute) const { |
| 226 CR_DEFINE_STATIC_LOCAL(std::vector<int32_t>, empty_data, ()); |
| 227 if (!delegate_) |
| 228 return empty_data; |
200 return GetData().GetIntListAttribute(attribute); | 229 return GetData().GetIntListAttribute(attribute); |
201 } | 230 } |
202 | 231 |
203 bool AXPlatformNodeBase::GetIntListAttribute( | 232 bool AXPlatformNodeBase::GetIntListAttribute( |
204 ui::AXIntListAttribute attribute, | 233 ui::AXIntListAttribute attribute, |
205 std::vector<int32_t>* value) const { | 234 std::vector<int32_t>* value) const { |
| 235 if (!delegate_) |
| 236 return false; |
206 return GetData().GetIntListAttribute(attribute, value); | 237 return GetData().GetIntListAttribute(attribute, value); |
207 } | 238 } |
208 | 239 |
209 AXPlatformNodeBase::AXPlatformNodeBase() { | 240 AXPlatformNodeBase::AXPlatformNodeBase() { |
210 } | 241 } |
211 | 242 |
212 AXPlatformNodeBase::~AXPlatformNodeBase() { | 243 AXPlatformNodeBase::~AXPlatformNodeBase() { |
213 CHECK(!delegate_); | |
214 } | 244 } |
215 | 245 |
216 // static | 246 // static |
217 AXPlatformNodeBase* AXPlatformNodeBase::FromNativeViewAccessible( | 247 AXPlatformNodeBase* AXPlatformNodeBase::FromNativeViewAccessible( |
218 gfx::NativeViewAccessible accessible) { | 248 gfx::NativeViewAccessible accessible) { |
219 return static_cast<AXPlatformNodeBase*>( | 249 return static_cast<AXPlatformNodeBase*>( |
220 AXPlatformNode::FromNativeViewAccessible(accessible)); | 250 AXPlatformNode::FromNativeViewAccessible(accessible)); |
221 } | 251 } |
222 | 252 |
223 bool AXPlatformNodeBase::SetTextSelection(int start_offset, int end_offset) { | 253 bool AXPlatformNodeBase::SetTextSelection(int start_offset, int end_offset) { |
224 ui::AXActionData action_data; | 254 ui::AXActionData action_data; |
225 action_data.action = ui::AX_ACTION_SET_SELECTION; | 255 action_data.action = ui::AX_ACTION_SET_SELECTION; |
226 action_data.anchor_node_id = action_data.focus_node_id = GetData().id; | 256 action_data.anchor_node_id = action_data.focus_node_id = GetData().id; |
227 action_data.anchor_offset = start_offset; | 257 action_data.anchor_offset = start_offset; |
228 action_data.focus_offset = end_offset; | 258 action_data.focus_offset = end_offset; |
229 DCHECK(delegate_); | 259 if (!delegate_) |
| 260 return false; |
| 261 |
230 return delegate_->AccessibilityPerformAction(action_data); | 262 return delegate_->AccessibilityPerformAction(action_data); |
231 } | 263 } |
232 | 264 |
233 bool AXPlatformNodeBase::IsTextOnlyObject() const { | 265 bool AXPlatformNodeBase::IsTextOnlyObject() const { |
234 return GetData().role == ui::AX_ROLE_STATIC_TEXT || | 266 return GetData().role == ui::AX_ROLE_STATIC_TEXT || |
235 GetData().role == ui::AX_ROLE_LINE_BREAK || | 267 GetData().role == ui::AX_ROLE_LINE_BREAK || |
236 GetData().role == ui::AX_ROLE_INLINE_TEXT_BOX; | 268 GetData().role == ui::AX_ROLE_INLINE_TEXT_BOX; |
237 } | 269 } |
238 | 270 |
239 bool AXPlatformNodeBase::IsNativeTextControl() const { | 271 bool AXPlatformNodeBase::IsNativeTextControl() const { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 case ui::AX_ROLE_SCROLL_BAR: | 331 case ui::AX_ROLE_SCROLL_BAR: |
300 return true; | 332 return true; |
301 case ui::AX_ROLE_SPLITTER: | 333 case ui::AX_ROLE_SPLITTER: |
302 return GetData().HasState(ui::AX_STATE_FOCUSABLE); | 334 return GetData().HasState(ui::AX_STATE_FOCUSABLE); |
303 default: | 335 default: |
304 return false; | 336 return false; |
305 } | 337 } |
306 } | 338 } |
307 | 339 |
308 AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const { | 340 AXPlatformNodeBase* AXPlatformNodeBase::GetTable() const { |
| 341 if (!delegate_) |
| 342 return nullptr; |
309 AXPlatformNodeBase* table = const_cast<AXPlatformNodeBase*>(this); | 343 AXPlatformNodeBase* table = const_cast<AXPlatformNodeBase*>(this); |
310 while (table && !ui::IsTableLikeRole(table->GetData().role)) { | 344 while (table && !ui::IsTableLikeRole(table->GetData().role)) { |
311 gfx::NativeViewAccessible parent_accessible = table->GetParent(); | 345 gfx::NativeViewAccessible parent_accessible = table->GetParent(); |
312 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); | 346 AXPlatformNodeBase* parent = FromNativeViewAccessible(parent_accessible); |
313 | 347 |
314 table = parent; | 348 table = parent; |
315 } | 349 } |
316 return table; | 350 return table; |
317 } | 351 } |
318 | 352 |
319 AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int index) const { | 353 AXPlatformNodeBase* AXPlatformNodeBase::GetTableCell(int index) const { |
320 DCHECK(delegate_); | 354 if (!delegate_) |
321 | 355 return nullptr; |
322 if (!ui::IsTableLikeRole(GetData().role) && | 356 if (!ui::IsTableLikeRole(GetData().role) && |
323 !ui::IsCellOrTableHeaderRole(GetData().role)) | 357 !ui::IsCellOrTableHeaderRole(GetData().role)) |
324 return nullptr; | 358 return nullptr; |
325 | 359 |
326 AXPlatformNodeBase* table = GetTable(); | 360 AXPlatformNodeBase* table = GetTable(); |
327 if (!table) | 361 if (!table) |
328 return nullptr; | 362 return nullptr; |
329 const std::vector<int32_t>& unique_cell_ids = | 363 const std::vector<int32_t>& unique_cell_ids = |
330 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); | 364 table->GetIntListAttribute(ui::AX_ATTR_UNIQUE_CELL_IDS); |
331 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) | 365 if (index < 0 || index >= static_cast<int>(unique_cell_ids.size())) |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 if (!ui::IsCellOrTableHeaderRole(GetData().role)) | 454 if (!ui::IsCellOrTableHeaderRole(GetData().role)) |
421 return 0; | 455 return 0; |
422 | 456 |
423 int row_span; | 457 int row_span; |
424 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) | 458 if (GetIntAttribute(ui::AX_ATTR_TABLE_CELL_ROW_SPAN, &row_span)) |
425 return row_span; | 459 return row_span; |
426 return 1; | 460 return 1; |
427 } | 461 } |
428 | 462 |
429 } // namespace ui | 463 } // namespace ui |
OLD | NEW |