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

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: Separate out one change that broke existing tests 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::WebRect 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 boundsf(0, 0, bounds.width, bounds.height);
aboxhall 2016/06/09 23:05:30 What does the 'f' in 'boundsf' connote? Just that
dmazzoni 2016/06/10 16:55:39 Yeah, that could be more clear. Changed to compute
326 while (!container.isDetached()) {
327 boundsf.Offset(bounds.x, bounds.y);
328 boundsf.Offset(-container.scrollOffset().x, -container.scrollOffset().y);
329 if (!matrix.isIdentity()) {
330 gfx::Transform transform(matrix);
331 transform.TransformRect(&boundsf);
332 }
333 container.getRelativeBounds(container, bounds, matrix);
334 }
335 return blink::WebRect(boundsf.x(),
336 boundsf.y(),
337 boundsf.width(),
338 boundsf.height());
339 }
340
313 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object, 341 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object,
314 int characterIndex) { 342 int characterIndex) {
315 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText); 343 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText);
316 int end = 0; 344 int end = 0;
317 for (unsigned i = 0; i < object.childCount(); i++) { 345 for (unsigned i = 0; i < object.childCount(); i++) {
318 blink::WebAXObject inline_text_box = object.childAt(i); 346 blink::WebAXObject inline_text_box = object.childAt(i);
319 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox); 347 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox);
320 int start = end; 348 int start = end;
321 blink::WebString name = inline_text_box.name(); 349 blink::WebString name = inline_text_box.name();
322 end += name.length(); 350 end += name.length();
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet) 572 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet)
545 .SetProperty("setSize", &WebAXObjectProxy::SetSize) 573 .SetProperty("setSize", &WebAXObjectProxy::SetSize)
546 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX) 574 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX)
547 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY) 575 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY)
548 .SetProperty("rowCount", &WebAXObjectProxy::RowCount) 576 .SetProperty("rowCount", &WebAXObjectProxy::RowCount)
549 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount) 577 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount)
550 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount) 578 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount)
551 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount) 579 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount)
552 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable) 580 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable)
553 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed) 581 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed)
582 //
583 // NEW bounding rect calculation - high-level interface
584 //
585 .SetProperty("boundsX", &WebAXObjectProxy::BoundsX)
586 .SetProperty("boundsY", &WebAXObjectProxy::BoundsY)
587 .SetProperty("boundsWidth", &WebAXObjectProxy::BoundsWidth)
588 .SetProperty("boundsHeight", &WebAXObjectProxy::BoundsHeight)
554 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes) 589 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes)
555 .SetMethod("attributesOfChildren", 590 .SetMethod("attributesOfChildren",
556 &WebAXObjectProxy::AttributesOfChildren) 591 &WebAXObjectProxy::AttributesOfChildren)
557 .SetMethod("ariaControlsElementAtIndex", 592 .SetMethod("ariaControlsElementAtIndex",
558 &WebAXObjectProxy::AriaControlsElementAtIndex) 593 &WebAXObjectProxy::AriaControlsElementAtIndex)
559 .SetMethod("ariaFlowToElementAtIndex", 594 .SetMethod("ariaFlowToElementAtIndex",
560 &WebAXObjectProxy::AriaFlowToElementAtIndex) 595 &WebAXObjectProxy::AriaFlowToElementAtIndex)
561 .SetMethod("ariaOwnsElementAtIndex", 596 .SetMethod("ariaOwnsElementAtIndex",
562 &WebAXObjectProxy::AriaOwnsElementAtIndex) 597 &WebAXObjectProxy::AriaOwnsElementAtIndex)
563 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex) 598 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex)
(...skipping 25 matching lines...) Expand all
589 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual) 624 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual)
590 .SetMethod("setNotificationListener", 625 .SetMethod("setNotificationListener",
591 &WebAXObjectProxy::SetNotificationListener) 626 &WebAXObjectProxy::SetNotificationListener)
592 .SetMethod("unsetNotificationListener", 627 .SetMethod("unsetNotificationListener",
593 &WebAXObjectProxy::UnsetNotificationListener) 628 &WebAXObjectProxy::UnsetNotificationListener)
594 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus) 629 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus)
595 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible) 630 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible)
596 .SetMethod("scrollToMakeVisibleWithSubFocus", 631 .SetMethod("scrollToMakeVisibleWithSubFocus",
597 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus) 632 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus)
598 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint) 633 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint)
634 .SetMethod("scrollX", &WebAXObjectProxy::ScrollX)
635 .SetMethod("scrollY", &WebAXObjectProxy::ScrollY)
599 .SetMethod("wordStart", &WebAXObjectProxy::WordStart) 636 .SetMethod("wordStart", &WebAXObjectProxy::WordStart)
600 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd) 637 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
601 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine) 638 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine)
602 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine) 639 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine)
603 .SetMethod("misspellingAtIndex", &WebAXObjectProxy::MisspellingAtIndex) 640 .SetMethod("misspellingAtIndex", &WebAXObjectProxy::MisspellingAtIndex)
604 // TODO(hajimehoshi): This is for backward compatibility. Remove them. 641 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
605 .SetMethod("addNotificationListener", 642 .SetMethod("addNotificationListener",
606 &WebAXObjectProxy::SetNotificationListener) 643 &WebAXObjectProxy::SetNotificationListener)
607 .SetMethod("removeNotificationListener", 644 .SetMethod("removeNotificationListener",
608 &WebAXObjectProxy::UnsetNotificationListener) 645 &WebAXObjectProxy::UnsetNotificationListener)
609 // 646 //
610 // NEW accessible name and description accessors 647 // NEW accessible name and description accessors
611 // 648 //
612 .SetProperty("name", &WebAXObjectProxy::Name) 649 .SetProperty("name", &WebAXObjectProxy::Name)
613 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom) 650 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom)
614 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount) 651 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount)
615 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex) 652 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex)
616 .SetProperty("description", &WebAXObjectProxy::Description) 653 .SetProperty("description", &WebAXObjectProxy::Description)
617 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom) 654 .SetProperty("descriptionFrom", &WebAXObjectProxy::DescriptionFrom)
618 .SetProperty("misspellingsCount", &WebAXObjectProxy::MisspellingsCount) 655 .SetProperty("misspellingsCount", &WebAXObjectProxy::MisspellingsCount)
619 .SetMethod("descriptionElementCount", 656 .SetMethod("descriptionElementCount",
620 &WebAXObjectProxy::DescriptionElementCount) 657 &WebAXObjectProxy::DescriptionElementCount)
621 .SetMethod("descriptionElementAtIndex", 658 .SetMethod("descriptionElementAtIndex",
622 &WebAXObjectProxy::DescriptionElementAtIndex); 659 &WebAXObjectProxy::DescriptionElementAtIndex)
660 //
661 // NEW bounding rect calculation - low-level interface
662 //
663 .SetMethod("offsetContainer",
664 &WebAXObjectProxy::OffsetContainer)
665 .SetMethod("boundsInContainerX",
666 &WebAXObjectProxy::BoundsInContainerX)
667 .SetMethod("boundsInContainerY",
668 &WebAXObjectProxy::BoundsInContainerY)
669 .SetMethod("boundsInContainerWidth",
670 &WebAXObjectProxy::BoundsInContainerWidth)
671 .SetMethod("boundsInContainerHeight",
672 &WebAXObjectProxy::BoundsInContainerHeight)
673 .SetMethod("hasNonIdentityTransform",
674 &WebAXObjectProxy::HasNonIdentityTransform);
623 } 675 }
624 676
625 v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) { 677 v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) {
626 return factory_->GetOrCreate(accessibility_object_.childAt(index)); 678 return factory_->GetOrCreate(accessibility_object_.childAt(index));
627 } 679 }
628 680
629 bool WebAXObjectProxy::IsRoot() const { 681 bool WebAXObjectProxy::IsRoot() const {
630 return false; 682 return false;
631 } 683 }
632 684
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 accessibility_object_.updateLayoutAndCheckValidity(); 1335 accessibility_object_.updateLayoutAndCheckValidity();
1284 accessibility_object_.scrollToMakeVisibleWithSubFocus( 1336 accessibility_object_.scrollToMakeVisibleWithSubFocus(
1285 blink::WebRect(x, y, width, height)); 1337 blink::WebRect(x, y, width, height));
1286 } 1338 }
1287 1339
1288 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) { 1340 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) {
1289 accessibility_object_.updateLayoutAndCheckValidity(); 1341 accessibility_object_.updateLayoutAndCheckValidity();
1290 accessibility_object_.scrollToGlobalPoint(blink::WebPoint(x, y)); 1342 accessibility_object_.scrollToGlobalPoint(blink::WebPoint(x, y));
1291 } 1343 }
1292 1344
1345 int WebAXObjectProxy::ScrollX() {
1346 accessibility_object_.updateLayoutAndCheckValidity();
1347 return accessibility_object_.scrollOffset().x;
1348 }
1349
1350 int WebAXObjectProxy::ScrollY() {
1351 accessibility_object_.updateLayoutAndCheckValidity();
1352 return accessibility_object_.scrollOffset().y;
1353 }
1354
1355 int WebAXObjectProxy::BoundsX() {
1356 return BoundsForObject(accessibility_object_).x;
1357 }
1358
1359 int WebAXObjectProxy::BoundsY() {
1360 return BoundsForObject(accessibility_object_).y;
1361 }
1362
1363 int WebAXObjectProxy::BoundsWidth() {
1364 return BoundsForObject(accessibility_object_).width;
1365 }
1366
1367 int WebAXObjectProxy::BoundsHeight() {
1368 return BoundsForObject(accessibility_object_).height;
1369 }
1370
1293 int WebAXObjectProxy::WordStart(int character_index) { 1371 int WebAXObjectProxy::WordStart(int character_index) {
1294 accessibility_object_.updateLayoutAndCheckValidity(); 1372 accessibility_object_.updateLayoutAndCheckValidity();
1295 if (accessibility_object_.role() != blink::WebAXRoleStaticText) 1373 if (accessibility_object_.role() != blink::WebAXRoleStaticText)
1296 return -1; 1374 return -1;
1297 1375
1298 int word_start = 0, word_end = 0; 1376 int word_start = 0, word_end = 0;
1299 GetBoundariesForOneWord(accessibility_object_, character_index, 1377 GetBoundariesForOneWord(accessibility_object_, character_index,
1300 word_start, word_end); 1378 word_start, word_end);
1301 return word_start; 1379 return word_start;
1302 } 1380 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 accessibility_object_.name(nameFrom, nameObjects); 1529 accessibility_object_.name(nameFrom, nameObjects);
1452 blink::WebAXDescriptionFrom descriptionFrom; 1530 blink::WebAXDescriptionFrom descriptionFrom;
1453 blink::WebVector<blink::WebAXObject> descriptionObjects; 1531 blink::WebVector<blink::WebAXObject> descriptionObjects;
1454 accessibility_object_.description( 1532 accessibility_object_.description(
1455 nameFrom, descriptionFrom, descriptionObjects); 1533 nameFrom, descriptionFrom, descriptionObjects);
1456 if (index >= descriptionObjects.size()) 1534 if (index >= descriptionObjects.size())
1457 return v8::Local<v8::Object>(); 1535 return v8::Local<v8::Object>();
1458 return factory_->GetOrCreate(descriptionObjects[index]); 1536 return factory_->GetOrCreate(descriptionObjects[index]);
1459 } 1537 }
1460 1538
1539 v8::Local<v8::Object> WebAXObjectProxy::OffsetContainer() {
1540 accessibility_object_.updateLayoutAndCheckValidity();
1541 blink::WebAXObject container;
1542 blink::WebFloatRect bounds;
1543 SkMatrix44 matrix;
1544 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1545 return factory_->GetOrCreate(container);
1546 }
1547
1548 int WebAXObjectProxy::BoundsInContainerX() {
1549 accessibility_object_.updateLayoutAndCheckValidity();
1550 blink::WebAXObject container;
1551 blink::WebFloatRect bounds;
1552 SkMatrix44 matrix;
1553 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1554 return bounds.x;
1555 }
1556
1557 int WebAXObjectProxy::BoundsInContainerY() {
1558 accessibility_object_.updateLayoutAndCheckValidity();
1559 blink::WebAXObject container;
1560 blink::WebFloatRect bounds;
1561 SkMatrix44 matrix;
1562 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1563 return bounds.y;
1564 }
1565
1566 int WebAXObjectProxy::BoundsInContainerWidth() {
1567 accessibility_object_.updateLayoutAndCheckValidity();
1568 blink::WebAXObject container;
1569 blink::WebFloatRect bounds;
1570 SkMatrix44 matrix;
1571 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1572 return bounds.width;
1573 }
1574
1575 int WebAXObjectProxy::BoundsInContainerHeight() {
1576 accessibility_object_.updateLayoutAndCheckValidity();
1577 blink::WebAXObject container;
1578 blink::WebFloatRect bounds;
1579 SkMatrix44 matrix;
1580 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1581 return bounds.height;
1582 }
1583
1584 bool WebAXObjectProxy::HasNonIdentityTransform() {
1585 accessibility_object_.updateLayoutAndCheckValidity();
1586 accessibility_object_.updateLayoutAndCheckValidity();
1587 blink::WebAXObject container;
1588 blink::WebFloatRect bounds;
1589 SkMatrix44 matrix;
1590 accessibility_object_.getRelativeBounds(container, bounds, matrix);
1591 return !matrix.isIdentity();
1592 }
1593
1461 RootWebAXObjectProxy::RootWebAXObjectProxy( 1594 RootWebAXObjectProxy::RootWebAXObjectProxy(
1462 const blink::WebAXObject &object, Factory *factory) 1595 const blink::WebAXObject &object, Factory *factory)
1463 : WebAXObjectProxy(object, factory) { 1596 : WebAXObjectProxy(object, factory) {
1464 } 1597 }
1465 1598
1466 v8::Local<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) { 1599 v8::Local<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) {
1467 if (index) 1600 if (index)
1468 return v8::Local<v8::Object>(); 1601 return v8::Local<v8::Object>();
1469 1602
1470 return factory()->GetOrCreate(accessibility_object()); 1603 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( 1651 v8::Local<v8::Value> value_handle = gin::CreateHandle(
1519 isolate, new WebAXObjectProxy(object, this)).ToV8(); 1652 isolate, new WebAXObjectProxy(object, this)).ToV8();
1520 if (value_handle.IsEmpty()) 1653 if (value_handle.IsEmpty())
1521 return v8::Local<v8::Object>(); 1654 return v8::Local<v8::Object>();
1522 v8::Local<v8::Object> handle = value_handle->ToObject(isolate); 1655 v8::Local<v8::Object> handle = value_handle->ToObject(isolate);
1523 elements_.Append(handle); 1656 elements_.Append(handle);
1524 return handle; 1657 return handle;
1525 } 1658 }
1526 1659
1527 } // namespace test_runner 1660 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698