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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/test_runner/web_ax_object_proxy.cc
diff --git a/components/test_runner/web_ax_object_proxy.cc b/components/test_runner/web_ax_object_proxy.cc
index c9803b4ec5af2c2d7b3db29abeb6f378eeb0dd73..233607ff8a42cae39a7baafe0c9f81b3e097a1d4 100644
--- a/components/test_runner/web_ax_object_proxy.cc
+++ b/components/test_runner/web_ax_object_proxy.cc
@@ -9,11 +9,15 @@
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "gin/handle.h"
+#include "third_party/WebKit/public/platform/WebFloatRect.h"
#include "third_party/WebKit/public/platform/WebPoint.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebKit.h"
+#include "third_party/skia/include/core/SkMatrix44.h"
+#include "ui/gfx/geometry/rect_f.h"
+#include "ui/gfx/transform.h"
namespace test_runner {
@@ -310,6 +314,30 @@ std::string GetAttributes(const blink::WebAXObject& object) {
return attributes;
}
+// New bounds calculation algorithm. Retrieves the frame-relative bounds
+// of an object by calling getRelativeBounds and then applying the offsets
+// and transforms recursively on each container of this object.
+blink::WebRect BoundsForObject(const blink::WebAXObject& object) {
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ object.getRelativeBounds(container, bounds, matrix);
+ 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
+ while (!container.isDetached()) {
+ boundsf.Offset(bounds.x, bounds.y);
+ boundsf.Offset(-container.scrollOffset().x, -container.scrollOffset().y);
+ if (!matrix.isIdentity()) {
+ gfx::Transform transform(matrix);
+ transform.TransformRect(&boundsf);
+ }
+ container.getRelativeBounds(container, bounds, matrix);
+ }
+ return blink::WebRect(boundsf.x(),
+ boundsf.y(),
+ boundsf.width(),
+ boundsf.height());
+}
+
blink::WebRect BoundsForCharacter(const blink::WebAXObject& object,
int characterIndex) {
DCHECK_EQ(object.role(), blink::WebAXRoleStaticText);
@@ -551,6 +579,13 @@ WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount)
.SetProperty("isClickable", &WebAXObjectProxy::IsClickable)
.SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed)
+ //
+ // NEW bounding rect calculation - high-level interface
+ //
+ .SetProperty("boundsX", &WebAXObjectProxy::BoundsX)
+ .SetProperty("boundsY", &WebAXObjectProxy::BoundsY)
+ .SetProperty("boundsWidth", &WebAXObjectProxy::BoundsWidth)
+ .SetProperty("boundsHeight", &WebAXObjectProxy::BoundsHeight)
.SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes)
.SetMethod("attributesOfChildren",
&WebAXObjectProxy::AttributesOfChildren)
@@ -596,6 +631,8 @@ WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetMethod("scrollToMakeVisibleWithSubFocus",
&WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus)
.SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint)
+ .SetMethod("scrollX", &WebAXObjectProxy::ScrollX)
+ .SetMethod("scrollY", &WebAXObjectProxy::ScrollY)
.SetMethod("wordStart", &WebAXObjectProxy::WordStart)
.SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
.SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine)
@@ -619,7 +656,22 @@ WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetMethod("descriptionElementCount",
&WebAXObjectProxy::DescriptionElementCount)
.SetMethod("descriptionElementAtIndex",
- &WebAXObjectProxy::DescriptionElementAtIndex);
+ &WebAXObjectProxy::DescriptionElementAtIndex)
+ //
+ // NEW bounding rect calculation - low-level interface
+ //
+ .SetMethod("offsetContainer",
+ &WebAXObjectProxy::OffsetContainer)
+ .SetMethod("boundsInContainerX",
+ &WebAXObjectProxy::BoundsInContainerX)
+ .SetMethod("boundsInContainerY",
+ &WebAXObjectProxy::BoundsInContainerY)
+ .SetMethod("boundsInContainerWidth",
+ &WebAXObjectProxy::BoundsInContainerWidth)
+ .SetMethod("boundsInContainerHeight",
+ &WebAXObjectProxy::BoundsInContainerHeight)
+ .SetMethod("hasNonIdentityTransform",
+ &WebAXObjectProxy::HasNonIdentityTransform);
}
v8::Local<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) {
@@ -1290,6 +1342,32 @@ void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) {
accessibility_object_.scrollToGlobalPoint(blink::WebPoint(x, y));
}
+int WebAXObjectProxy::ScrollX() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ return accessibility_object_.scrollOffset().x;
+}
+
+int WebAXObjectProxy::ScrollY() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ return accessibility_object_.scrollOffset().y;
+}
+
+int WebAXObjectProxy::BoundsX() {
+ return BoundsForObject(accessibility_object_).x;
+}
+
+int WebAXObjectProxy::BoundsY() {
+ return BoundsForObject(accessibility_object_).y;
+}
+
+int WebAXObjectProxy::BoundsWidth() {
+ return BoundsForObject(accessibility_object_).width;
+}
+
+int WebAXObjectProxy::BoundsHeight() {
+ return BoundsForObject(accessibility_object_).height;
+}
+
int WebAXObjectProxy::WordStart(int character_index) {
accessibility_object_.updateLayoutAndCheckValidity();
if (accessibility_object_.role() != blink::WebAXRoleStaticText)
@@ -1458,6 +1536,61 @@ v8::Local<v8::Object> WebAXObjectProxy::DescriptionElementAtIndex(
return factory_->GetOrCreate(descriptionObjects[index]);
}
+v8::Local<v8::Object> WebAXObjectProxy::OffsetContainer() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return factory_->GetOrCreate(container);
+}
+
+int WebAXObjectProxy::BoundsInContainerX() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return bounds.x;
+}
+
+int WebAXObjectProxy::BoundsInContainerY() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return bounds.y;
+}
+
+int WebAXObjectProxy::BoundsInContainerWidth() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return bounds.width;
+}
+
+int WebAXObjectProxy::BoundsInContainerHeight() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return bounds.height;
+}
+
+bool WebAXObjectProxy::HasNonIdentityTransform() {
+ accessibility_object_.updateLayoutAndCheckValidity();
+ accessibility_object_.updateLayoutAndCheckValidity();
+ blink::WebAXObject container;
+ blink::WebFloatRect bounds;
+ SkMatrix44 matrix;
+ accessibility_object_.getRelativeBounds(container, bounds, matrix);
+ return !matrix.isIdentity();
+}
+
RootWebAXObjectProxy::RootWebAXObjectProxy(
const blink::WebAXObject &object, Factory *factory)
: WebAXObjectProxy(object, factory) {

Powered by Google App Engine
This is Rietveld 408576698