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

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

Issue 2047873002: Add interface to get relative bounding box rect of AX objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from aboxhall, add aria-owns test Created 4 years, 6 months 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "gin/handle.h" 11 #include "gin/handle.h"
12 #include "third_party/WebKit/public/platform/WebFloatRect.h"
12 #include "third_party/WebKit/public/platform/WebPoint.h" 13 #include "third_party/WebKit/public/platform/WebPoint.h"
13 #include "third_party/WebKit/public/platform/WebRect.h" 14 #include "third_party/WebKit/public/platform/WebRect.h"
14 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
15 #include "third_party/WebKit/public/web/WebFrame.h" 16 #include "third_party/WebKit/public/web/WebFrame.h"
16 #include "third_party/WebKit/public/web/WebKit.h" 17 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "third_party/skia/include/core/SkMatrix44.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/transform.h"
17 21
18 namespace test_runner { 22 namespace test_runner {
19 23
20 namespace { 24 namespace {
21 25
22 // Map role value to string, matching Safari/Mac platform implementation to 26 // Map role value to string, matching Safari/Mac platform implementation to
23 // avoid rebaselining layout tests. 27 // avoid rebaselining layout tests.
24 std::string RoleToString(blink::WebAXRole role) 28 std::string RoleToString(blink::WebAXRole role)
25 { 29 {
26 std::string result = "AXRole: AX"; 30 std::string result = "AXRole: AX";
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return language.insert(0, "AXLanguage: "); 307 return language.insert(0, "AXLanguage: ");
304 } 308 }
305 309
306 std::string GetAttributes(const blink::WebAXObject& object) { 310 std::string GetAttributes(const blink::WebAXObject& object) {
307 std::string attributes(object.name().utf8()); 311 std::string attributes(object.name().utf8());
308 attributes.append("\n"); 312 attributes.append("\n");
309 attributes.append(GetRole(object)); 313 attributes.append(GetRole(object));
310 return attributes; 314 return attributes;
311 } 315 }
312 316
317 // New bounds calculation algorithm. Retrieves the frame-relative bounds
318 // of an object by calling getRelativeBounds and then applying the offsets
319 // and transforms recursively on each container of this object.
320 blink::WebFloatRect BoundsForObject(const blink::WebAXObject& object) {
321 blink::WebAXObject container;
322 blink::WebFloatRect bounds;
323 SkMatrix44 matrix;
324 object.getRelativeBounds(container, bounds, matrix);
325 gfx::RectF computedBounds(0, 0, bounds.width, bounds.height);
326 while (!container.isDetached()) {
327 computedBounds.Offset(bounds.x, bounds.y);
328 computedBounds.Offset(
329 -container.scrollOffset().x, -container.scrollOffset().y);
330 if (!matrix.isIdentity()) {
331 gfx::Transform transform(matrix);
332 transform.TransformRect(&computedBounds);
333 }
334 container.getRelativeBounds(container, bounds, matrix);
335 }
336 return blink::WebFloatRect(computedBounds.x(),
337 computedBounds.y(),
338 computedBounds.width(),
339 computedBounds.height());
340 }
341
313 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object, 342 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object,
314 int characterIndex) { 343 int characterIndex) {
315 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText); 344 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText);
316 int end = 0; 345 int end = 0;
317 for (unsigned i = 0; i < object.childCount(); i++) { 346 for (unsigned i = 0; i < object.childCount(); i++) {
318 blink::WebAXObject inline_text_box = object.childAt(i); 347 blink::WebAXObject inline_text_box = object.childAt(i);
319 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); 348 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox);
320 int start = end; 349 int start = end;
321 blink::WebString name = inline_text_box.name(); 350 blink::WebString name = inline_text_box.name();
322 end += name.length(); 351 end += name.length();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet) 573 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet)
545 .SetProperty("setSize", &WebAXObjectProxy::SetSize) 574 .SetProperty("setSize", &WebAXObjectProxy::SetSize)
546 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX) 575 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX)
547 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY) 576 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY)
548 .SetProperty("rowCount", &WebAXObjectProxy::RowCount) 577 .SetProperty("rowCount", &WebAXObjectProxy::RowCount)
549 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount) 578 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount)
550 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount) 579 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount)
551 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount) 580 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount)
552 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable) 581 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable)
553 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed) 582 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed)
583 //
584 // NEW bounding rect calculation - high-level interface
585 //
586 .SetProperty("boundsX", &WebAXObjectProxy::BoundsX)
587 .SetProperty("boundsY", &WebAXObjectProxy::BoundsY)
588 .SetProperty("boundsWidth", &WebAXObjectProxy::BoundsWidth)
589 .SetProperty("boundsHeight", &WebAXObjectProxy::BoundsHeight)
554 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes) 590 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes)
555 .SetMethod("attributesOfChildren", 591 .SetMethod("attributesOfChildren",
556 &WebAXObjectProxy::AttributesOfChildren) 592 &WebAXObjectProxy::AttributesOfChildren)
557 .SetMethod("ariaControlsElementAtIndex", 593 .SetMethod("ariaControlsElementAtIndex",
558 &WebAXObjectProxy::AriaControlsElementAtIndex) 594 &WebAXObjectProxy::AriaControlsElementAtIndex)
559 .SetMethod("ariaFlowToElementAtIndex", 595 .SetMethod("ariaFlowToElementAtIndex",
560 &WebAXObjectProxy::AriaFlowToElementAtIndex) 596 &WebAXObjectProxy::AriaFlowToElementAtIndex)
561 .SetMethod("ariaOwnsElementAtIndex", 597 .SetMethod("ariaOwnsElementAtIndex",
562 &WebAXObjectProxy::AriaOwnsElementAtIndex) 598 &WebAXObjectProxy::AriaOwnsElementAtIndex)
563 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex) 599 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex)
(...skipping 25 matching lines...) Expand all
589 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual) 625 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual)
590 .SetMethod("setNotificationListener", 626 .SetMethod("setNotificationListener",
591 &WebAXObjectProxy::SetNotificationListener) 627 &WebAXObjectProxy::SetNotificationListener)
592 .SetMethod("unsetNotificationListener", 628 .SetMethod("unsetNotificationListener",
593 &WebAXObjectProxy::UnsetNotificationListener) 629 &WebAXObjectProxy::UnsetNotificationListener)
594 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus) 630 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus)
595 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible) 631 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible)
596 .SetMethod("scrollToMakeVisibleWithSubFocus", 632 .SetMethod("scrollToMakeVisibleWithSubFocus",
597 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus) 633 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus)
598 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint) 634 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint)
635 .SetMethod("scrollX", &WebAXObjectProxy::ScrollX)
636 .SetMethod("scrollY", &WebAXObjectProxy::ScrollY)
599 .SetMethod("wordStart", &WebAXObjectProxy::WordStart) 637 .SetMethod("wordStart", &WebAXObjectProxy::WordStart)
600 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd) 638 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
601 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine) 639 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine)
602 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine) 640 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine)
603 .SetMethod("misspellingAtIndex", &WebAXObjectProxy::MisspellingAtIndex) 641 .SetMethod("misspellingAtIndex", &WebAXObjectProxy::MisspellingAtIndex)
604 // TODO(hajimehoshi): This is for backward compatibility. Remove them. 642 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
605 .SetMethod("addNotificationListener", 643 .SetMethod("addNotificationListener",
606 &WebAXObjectProxy::SetNotificationListener) 644 &WebAXObjectProxy::SetNotificationListener)
607 .SetMethod("removeNotificationListener", 645 .SetMethod("removeNotificationListener",
608 &WebAXObjectProxy::UnsetNotificationListener) 646 &WebAXObjectProxy::UnsetNotificationListener)
609 // 647 //
610 // NEW accessible name and description accessors 648 // NEW accessible name and description accessors
611 // 649 //
612 .SetProperty("name", &WebAXObjectProxy::Name) 650 .SetProperty("name", &WebAXObjectProxy::Name)
613 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom) 651 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom)
614 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount) 652 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount)
615 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex) 653 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex)
616 .SetProperty("description", &WebAXObjectProxy::Description) 654 .SetProperty("description", &WebAXObjectProxy::Description)
617 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom) 655 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom)
618 .SetProperty("misspellingsCount", &WebAXObjectProxy::MisspellingsCount) 656 .SetProperty("misspellingsCount", &WebAXObjectProxy::MisspellingsCount)
619 .SetMethod("descriptionElementCount", 657 .SetMethod("descriptionElementCount",
620 &WebAXObjectProxy::DescriptionElementCount) 658 &WebAXObjectProxy::DescriptionElementCount)
621 .SetMethod("descriptionElementAtIndex", 659 .SetMethod("descriptionElementAtIndex",
622 &WebAXObjectProxy::DescriptionElementAtIndex); 660 &WebAXObjectProxy::DescriptionElementAtIndex)
661 //
662 // NEW bounding rect calculation - low-level interface
663 //
664 .SetMethod("offsetContainer",
665 &WebAXObjectProxy::OffsetContainer)
666 .SetMethod("boundsInContainerX",
667 &WebAXObjectProxy::BoundsInContainerX)
668 .SetMethod("boundsInContainerY",
669 &WebAXObjectProxy::BoundsInContainerY)
670 .SetMethod("boundsInContainerWidth",
671 &WebAXObjectProxy::BoundsInContainerWidth)
672 .SetMethod("boundsInContainerHeight",
673 &WebAXObjectProxy::BoundsInContainerHeight)
674 .SetMethod("hasNonIdentityTransform",
675 &WebAXObjectProxy::HasNonIdentityTransform);
623 } 676 }
624 677
625 v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) { 678 v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) {
626 return factory_->GetOrCreate(accessibility_object_.childAt(index)); 679 return factory_->GetOrCreate(accessibility_object_.childAt(index));
627 } 680 }
628 681
629 bool WebAXObjectProxy::IsRoot() const { 682 bool WebAXObjectProxy::IsRoot() const {
630 return false; 683 return false;
631 } 684 }
632 685
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 accessibility_object_.updateLayoutAndCheckValidity(); 1336 accessibility_object_.updateLayoutAndCheckValidity();
1284 accessibility_object_.scrollToMakeVisibleWithSubFocus( 1337 accessibility_object_.scrollToMakeVisibleWithSubFocus(
1285 blink::WebRect(x, y, width, height)); 1338 blink::WebRect(x, y, width, height));
1286 } 1339 }
1287 1340
1288 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) { 1341 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) {
1289 accessibility_object_.updateLayoutAndCheckValidity(); 1342 accessibility_object_.updateLayoutAndCheckValidity();
1290 accessibility_object_.scrollToGlobalPoint(blink::WebPoint(x, y)); 1343 accessibility_object_.scrollToGlobalPoint(blink::WebPoint(x, y));
1291 } 1344 }
1292 1345
1346 int WebAXObjectProxy::ScrollX() {
1347 accessibility_object_.updateLayoutAndCheckValidity();
1348 return accessibility_object_.scrollOffset().x;
1349 }
1350
1351 int WebAXObjectProxy::ScrollY() {
1352 accessibility_object_.updateLayoutAndCheckValidity();
1353 return accessibility_object_.scrollOffset().y;
1354 }
1355
1356 float WebAXObjectProxy::BoundsX() {
1357 return BoundsForObject(accessibility_object_).x;
1358 }
1359
1360 float WebAXObjectProxy::BoundsY() {
1361 return BoundsForObject(accessibility_object_).y;
1362 }
1363
1364 float WebAXObjectProxy::BoundsWidth() {
1365 return BoundsForObject(accessibility_object_).width;
1366 }
1367
1368 float WebAXObjectProxy::BoundsHeight() {
1369 return BoundsForObject(accessibility_object_).height;
1370 }
1371
1293 int WebAXObjectProxy::WordStart(int character_index) { 1372 int WebAXObjectProxy::WordStart(int character_index) {
1294 accessibility_object_.updateLayoutAndCheckValidity(); 1373 accessibility_object_.updateLayoutAndCheckValidity();
1295 if (accessibility_object_.role() != blink::WebAXRoleStaticText) 1374 if (accessibility_object_.role() != blink::WebAXRoleStaticText)
1296 return -1; 1375 return -1;
1297 1376
1298 int word_start = 0, word_end = 0; 1377 int word_start = 0, word_end = 0;
1299 GetBoundariesForOneWord(accessibility_object_, character_index, 1378 GetBoundariesForOneWord(accessibility_object_, character_index,
1300 word_start, word_end); 1379 word_start, word_end);
1301 return word_start; 1380 return word_start;
1302 } 1381 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 accessibility_object_.name(nameFrom, nameObjects); 1530 accessibility_object_.name(nameFrom, nameObjects);
1452 blink::WebAXDescriptionFrom descriptionFrom; 1531 blink::WebAXDescriptionFrom descriptionFrom;
1453 blink::WebVector<blink::WebAXObject> descriptionObjects; 1532 blink::WebVector<blink::WebAXObject> descriptionObjects;
1454 accessibility_object_.description( 1533 accessibility_object_.description(
1455 nameFrom, descriptionFrom, descriptionObjects); 1534 nameFrom, descriptionFrom, descriptionObjects);
1456 if (index >= descriptionObjects.size()) 1535 if (index >= descriptionObjects.size())
1457 return v8::Local<v8::Object>(); 1536 return v8::Local<v8::Object>();
1458 return factory_->GetOrCreate(descriptionObjects[index]); 1537 return factory_->GetOrCreate(descriptionObjects[index]);
1459 } 1538 }
1460 1539
1540 v8::Local<v8::Object> WebAXObjectProxy::OffsetContainer() {
1541 accessibility_object_.updateLayoutAndCheckValidity();
1542 blink::WebAXObject container;
1543 blink::WebFloatRect bounds;
1544 SkMatrix44 matrix;
1545 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1546 return factory_->GetOrCreate(container);
1547 }
1548
1549 float WebAXObjectProxy::BoundsInContainerX() {
1550 accessibility_object_.updateLayoutAndCheckValidity();
1551 blink::WebAXObject container;
1552 blink::WebFloatRect bounds;
1553 SkMatrix44 matrix;
1554 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1555 return bounds.x;
1556 }
1557
1558 float WebAXObjectProxy::BoundsInContainerY() {
1559 accessibility_object_.updateLayoutAndCheckValidity();
1560 blink::WebAXObject container;
1561 blink::WebFloatRect bounds;
1562 SkMatrix44 matrix;
1563 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1564 return bounds.y;
1565 }
1566
1567 float WebAXObjectProxy::BoundsInContainerWidth() {
1568 accessibility_object_.updateLayoutAndCheckValidity();
1569 blink::WebAXObject container;
1570 blink::WebFloatRect bounds;
1571 SkMatrix44 matrix;
1572 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1573 return bounds.width;
1574 }
1575
1576 float WebAXObjectProxy::BoundsInContainerHeight() {
1577 accessibility_object_.updateLayoutAndCheckValidity();
1578 blink::WebAXObject container;
1579 blink::WebFloatRect bounds;
1580 SkMatrix44 matrix;
1581 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1582 return bounds.height;
1583 }
1584
1585 bool WebAXObjectProxy::HasNonIdentityTransform() {
1586 accessibility_object_.updateLayoutAndCheckValidity();
1587 accessibility_object_.updateLayoutAndCheckValidity();
1588 blink::WebAXObject container;
1589 blink::WebFloatRect bounds;
1590 SkMatrix44 matrix;
1591 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1592 return !matrix.isIdentity();
1593 }
1594
1461 RootWebAXObjectProxy::RootWebAXObjectProxy( 1595 RootWebAXObjectProxy::RootWebAXObjectProxy(
1462 const blink::WebAXObject &object, Factory *factory) 1596 const blink::WebAXObject &object, Factory *factory)
1463 : WebAXObjectProxy(object, factory) { 1597 : WebAXObjectProxy(object, factory) {
1464 } 1598 }
1465 1599
1466 v8::Local<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) { 1600 v8::Local<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) {
1467 if (index) 1601 if (index)
1468 return v8::Local<v8::Object>(); 1602 return v8::Local<v8::Object>();
1469 1603
1470 return factory()->GetOrCreate(accessibility_object()); 1604 return factory()->GetOrCreate(accessibility_object());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 v8::Local<v8::Value> value_handle = gin::CreateHandle( 1652 v8::Local<v8::Value> value_handle = gin::CreateHandle(
1519 isolate, new WebAXObjectProxy(object, this)).ToV8(); 1653 isolate, new WebAXObjectProxy(object, this)).ToV8();
1520 if (value_handle.IsEmpty()) 1654 if (value_handle.IsEmpty())
1521 return v8::Local<v8::Object>(); 1655 return v8::Local<v8::Object>();
1522 v8::Local<v8::Object> handle = value_handle->ToObject(isolate); 1656 v8::Local<v8::Object> handle = value_handle->ToObject(isolate);
1523 elements_.Append(handle); 1657 elements_.Append(handle);
1524 return handle; 1658 return handle;
1525 } 1659 }
1526 1660
1527 } // namespace test_runner 1661 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/web_ax_object_proxy.h ('k') | third_party/WebKit/LayoutTests/accessibility/bounds-calc.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698