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

Side by Side Diff: components/test_runner/web_ax_object_proxy.cc

Issue 1417213006: Switch all LayoutTests to use new AX name calculation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix canvas-fallback-content-labels-expected.txt Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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 "components/test_runner/web_ax_object_proxy.h" 5 #include "components/test_runner/web_ax_object_proxy.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "gin/handle.h" 8 #include "gin/handle.h"
9 #include "third_party/WebKit/public/platform/WebPoint.h" 9 #include "third_party/WebKit/public/platform/WebPoint.h"
10 #include "third_party/WebKit/public/platform/WebRect.h" 10 #include "third_party/WebKit/public/platform/WebRect.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return result.append("UserInterfaceTooltip"); 252 return result.append("UserInterfaceTooltip");
253 case blink::WebAXRoleWebArea: 253 case blink::WebAXRoleWebArea:
254 return result.append("WebArea"); 254 return result.append("WebArea");
255 case blink::WebAXRoleWindow: 255 case blink::WebAXRoleWindow:
256 return result.append("Window"); 256 return result.append("Window");
257 default: 257 default:
258 return result.append("Unknown"); 258 return result.append("Unknown");
259 } 259 }
260 } 260 }
261 261
262 std::string DeprecatedGetDescription(const blink::WebAXObject& object) {
263 std::string description = object.deprecatedAccessibilityDescription().utf8();
264 return description.insert(0, "AXDescription: ");
265 }
266
267 std::string DeprecatedGetHelpText(const blink::WebAXObject& object) {
268 std::string help_text = object.deprecatedHelpText().utf8();
269 return help_text.insert(0, "AXHelp: ");
270 }
271
272 std::string GetStringValue(const blink::WebAXObject& object) { 262 std::string GetStringValue(const blink::WebAXObject& object) {
273 std::string value; 263 std::string value;
274 if (object.role() == blink::WebAXRoleColorWell) { 264 if (object.role() == blink::WebAXRoleColorWell) {
275 unsigned int color = object.colorValue(); 265 unsigned int color = object.colorValue();
276 unsigned int red = (color >> 16) & 0xFF; 266 unsigned int red = (color >> 16) & 0xFF;
277 unsigned int green = (color >> 8) & 0xFF; 267 unsigned int green = (color >> 8) & 0xFF;
278 unsigned int blue = color & 0xFF; 268 unsigned int blue = color & 0xFF;
279 value = base::StringPrintf("rgba(%d, %d, %d, 1)", 269 value = base::StringPrintf("rgba(%d, %d, %d, 1)",
280 red, green, blue); 270 red, green, blue);
281 } else { 271 } else {
282 value = object.stringValue().utf8(); 272 value = object.stringValue().utf8();
283 } 273 }
284 return value.insert(0, "AXValue: "); 274 return value.insert(0, "AXValue: ");
285 } 275 }
286 276
287 std::string GetRole(const blink::WebAXObject& object) { 277 std::string GetRole(const blink::WebAXObject& object) {
288 std::string role_string = RoleToString(object.role()); 278 std::string role_string = RoleToString(object.role());
289 279
290 // Special-case canvas with fallback content because Chromium wants to treat 280 // Special-case canvas with fallback content because Chromium wants to treat
291 // this as essentially a separate role that it can map differently depending 281 // this as essentially a separate role that it can map differently depending
292 // on the platform. 282 // on the platform.
293 if (object.role() == blink::WebAXRoleCanvas && 283 if (object.role() == blink::WebAXRoleCanvas &&
294 object.canvasHasFallbackContent()) { 284 object.canvasHasFallbackContent()) {
295 role_string += "WithFallbackContent"; 285 role_string += "WithFallbackContent";
296 } 286 }
297 287
298 return role_string; 288 return role_string;
299 } 289 }
300 290
301 std::string DeprecatedGetTitle(const blink::WebAXObject& object) {
302 std::string title = object.deprecatedTitle().utf8();
303 return title.insert(0, "AXTitle: ");
304 }
305
306 std::string GetValueDescription(const blink::WebAXObject& object) { 291 std::string GetValueDescription(const blink::WebAXObject& object) {
307 std::string value_description = object.valueDescription().utf8(); 292 std::string value_description = object.valueDescription().utf8();
308 return value_description.insert(0, "AXValueDescription: "); 293 return value_description.insert(0, "AXValueDescription: ");
309 } 294 }
310 295
311 std::string GetLanguage(const blink::WebAXObject& object) { 296 std::string GetLanguage(const blink::WebAXObject& object) {
312 std::string language = object.language().utf8(); 297 std::string language = object.language().utf8();
313 return language.insert(0, "AXLanguage: "); 298 return language.insert(0, "AXLanguage: ");
314 } 299 }
315 300
316 std::string GetAttributes(const blink::WebAXObject& object) { 301 std::string GetAttributes(const blink::WebAXObject& object) {
317 // FIXME: Concatenate all attributes of the AXObject. 302 blink::WebAXNameFrom nameFrom;
318 std::string attributes(DeprecatedGetTitle(object)); 303 blink::WebVector<blink::WebAXObject> nameObjects;
304 std::string attributes(object.name(nameFrom, nameObjects).utf8());
319 attributes.append("\n"); 305 attributes.append("\n");
320 attributes.append(GetRole(object)); 306 attributes.append(GetRole(object));
321 attributes.append("\n");
322 attributes.append(DeprecatedGetDescription(object));
323 return attributes; 307 return attributes;
324 } 308 }
325 309
326 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object, 310 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object,
327 int characterIndex) { 311 int characterIndex) {
328 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText); 312 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText);
329 int end = 0; 313 int end = 0;
330 for (unsigned i = 0; i < object.childCount(); i++) { 314 for (unsigned i = 0; i < object.childCount(); i++) {
331 blink::WebAXObject inline_text_box = object.childAt(i); 315 blink::WebAXObject inline_text_box = object.childAt(i);
332 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); 316 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 .SetMethod("wordStart", &WebAXObjectProxy::WordStart) 573 .SetMethod("wordStart", &WebAXObjectProxy::WordStart)
590 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd) 574 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
591 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine) 575 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine)
592 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine) 576 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine)
593 // TODO(hajimehoshi): This is for backward compatibility. Remove them. 577 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
594 .SetMethod("addNotificationListener", 578 .SetMethod("addNotificationListener",
595 &WebAXObjectProxy::SetNotificationListener) 579 &WebAXObjectProxy::SetNotificationListener)
596 .SetMethod("removeNotificationListener", 580 .SetMethod("removeNotificationListener",
597 &WebAXObjectProxy::UnsetNotificationListener) 581 &WebAXObjectProxy::UnsetNotificationListener)
598 // 582 //
599 // DEPRECATED accessible name and description accessors
600 //
601 .SetProperty("deprecatedTitle",
602 &WebAXObjectProxy::DeprecatedTitle)
603 .SetProperty("deprecatedDescription",
604 &WebAXObjectProxy::DeprecatedDescription)
605 .SetProperty("deprecatedHelpText",
606 &WebAXObjectProxy::DeprecatedHelpText)
607 .SetMethod("deprecatedTitleUIElement",
608 &WebAXObjectProxy::DeprecatedTitleUIElement)
609 //
610 // NEW accessible name and description accessors 583 // NEW accessible name and description accessors
611 // 584 //
612 .SetProperty("name", &WebAXObjectProxy::Name) 585 .SetProperty("name", &WebAXObjectProxy::Name)
613 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom) 586 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom)
614 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount) 587 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount)
615 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex) 588 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex)
616 .SetProperty("description", &WebAXObjectProxy::Description) 589 .SetProperty("description", &WebAXObjectProxy::Description)
617 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom) 590 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom)
618 .SetMethod("descriptionElementCount", 591 .SetMethod("descriptionElementCount",
619 &WebAXObjectProxy::DescriptionElementCount) 592 &WebAXObjectProxy::DescriptionElementCount)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 633
661 void WebAXObjectProxy::Reset() { 634 void WebAXObjectProxy::Reset() {
662 notification_callback_.Reset(); 635 notification_callback_.Reset();
663 } 636 }
664 637
665 std::string WebAXObjectProxy::Role() { 638 std::string WebAXObjectProxy::Role() {
666 accessibility_object_.updateLayoutAndCheckValidity(); 639 accessibility_object_.updateLayoutAndCheckValidity();
667 return GetRole(accessibility_object_); 640 return GetRole(accessibility_object_);
668 } 641 }
669 642
670 std::string WebAXObjectProxy::DeprecatedTitle() {
671 accessibility_object_.updateLayoutAndCheckValidity();
672 return DeprecatedGetTitle(accessibility_object_);
673 }
674
675 std::string WebAXObjectProxy::DeprecatedDescription() {
676 accessibility_object_.updateLayoutAndCheckValidity();
677 return DeprecatedGetDescription(accessibility_object_);
678 }
679
680 std::string WebAXObjectProxy::DeprecatedHelpText() {
681 accessibility_object_.updateLayoutAndCheckValidity();
682 return DeprecatedGetHelpText(accessibility_object_);
683 }
684
685 std::string WebAXObjectProxy::StringValue() { 643 std::string WebAXObjectProxy::StringValue() {
686 accessibility_object_.updateLayoutAndCheckValidity(); 644 accessibility_object_.updateLayoutAndCheckValidity();
687 return GetStringValue(accessibility_object_); 645 return GetStringValue(accessibility_object_);
688 } 646 }
689 647
690 std::string WebAXObjectProxy::Language() { 648 std::string WebAXObjectProxy::Language() {
691 accessibility_object_.updateLayoutAndCheckValidity(); 649 accessibility_object_.updateLayoutAndCheckValidity();
692 return GetLanguage(accessibility_object_); 650 return GetLanguage(accessibility_object_);
693 } 651 }
694 652
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 int column, int row) { 1116 int column, int row) {
1159 accessibility_object_.updateLayoutAndCheckValidity(); 1117 accessibility_object_.updateLayoutAndCheckValidity();
1160 blink::WebAXObject obj = 1118 blink::WebAXObject obj =
1161 accessibility_object_.cellForColumnAndRow(column, row); 1119 accessibility_object_.cellForColumnAndRow(column, row);
1162 if (obj.isNull()) 1120 if (obj.isNull())
1163 return v8::Local<v8::Object>(); 1121 return v8::Local<v8::Object>();
1164 1122
1165 return factory_->GetOrCreate(obj); 1123 return factory_->GetOrCreate(obj);
1166 } 1124 }
1167 1125
1168 v8::Local<v8::Object> WebAXObjectProxy::DeprecatedTitleUIElement() {
1169 accessibility_object_.updateLayoutAndCheckValidity();
1170 blink::WebAXObject obj = accessibility_object_.deprecatedTitleUIElement();
1171 if (obj.isNull())
1172 return v8::Local<v8::Object>();
1173
1174 return factory_->GetOrCreate(obj);
1175 }
1176
1177 void WebAXObjectProxy::SetSelectedTextRange(int selection_start, 1126 void WebAXObjectProxy::SetSelectedTextRange(int selection_start,
1178 int length) { 1127 int length) {
1179 accessibility_object_.updateLayoutAndCheckValidity(); 1128 accessibility_object_.updateLayoutAndCheckValidity();
1180 accessibility_object_.setSelectedTextRange(selection_start, 1129 accessibility_object_.setSelectedTextRange(selection_start,
1181 selection_start + length); 1130 selection_start + length);
1182 } 1131 }
1183 1132
1184 void WebAXObjectProxy::SetSelection( 1133 void WebAXObjectProxy::SetSelection(
1185 v8::Local<v8::Value> anchor_object, int anchor_offset, 1134 v8::Local<v8::Value> anchor_object, int anchor_offset,
1186 v8::Local<v8::Value> focus_object, int focus_offset) { 1135 v8::Local<v8::Value> focus_object, int focus_offset) {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 v8::Local<v8::Value> value_handle = gin::CreateHandle( 1475 v8::Local<v8::Value> value_handle = gin::CreateHandle(
1527 isolate, new WebAXObjectProxy(object, this)).ToV8(); 1476 isolate, new WebAXObjectProxy(object, this)).ToV8();
1528 if (value_handle.IsEmpty()) 1477 if (value_handle.IsEmpty())
1529 return v8::Local<v8::Object>(); 1478 return v8::Local<v8::Object>();
1530 v8::Local<v8::Object> handle = value_handle->ToObject(isolate); 1479 v8::Local<v8::Object> handle = value_handle->ToObject(isolate);
1531 elements_.Append(handle); 1480 elements_.Append(handle);
1532 return handle; 1481 return handle;
1533 } 1482 }
1534 1483
1535 } // namespace test_runner 1484 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/web_ax_object_proxy.h ('k') | content/test/data/accessibility/html/area-expected-mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698