Chromium Code Reviews| Index: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp |
| diff --git a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp |
| index 369c698d49d2110cfbf4f75847053dc6c4230762..19f9dbdaf2c1b35079a711e58902fc98d5a36df7 100644 |
| --- a/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp |
| +++ b/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp |
| @@ -1765,8 +1765,13 @@ bool AXNodeObject::nameFromLabelElement() const |
| LayoutRect AXNodeObject::elementRect() const |
| { |
| // First check if it has a custom rect, for example if this element is tied to a canvas path. |
| - if (!m_explicitElementRect.isEmpty()) |
| - return m_explicitElementRect; |
| + if (!m_explicitElementRect.isEmpty()) { |
| + LayoutRect bounds = m_explicitElementRect; |
| + AXObject* canvas = axObjectCache().objectFromAXID(m_explicitContainerID); |
| + if (canvas) |
| + bounds.moveBy(canvas->elementRect().location()); |
| + return bounds; |
| + } |
| // FIXME: If there are a lot of elements in the canvas, it will be inefficient. |
| // We can avoid the inefficient calculations by using AXComputedObjectAttributeCache. |
| @@ -1806,6 +1811,58 @@ LayoutRect AXNodeObject::elementRect() const |
| return boundingBox; |
| } |
| +void AXNodeObject::getRelativeBounds(AXObject** outContainer, FloatRect& outBoundsInContainer, SkMatrix44& outContainerTransform) const |
| +{ |
| + *outContainer = nullptr; |
| + outBoundsInContainer = FloatRect(); |
| + outContainerTransform.setIdentity(); |
| + |
| + // First check if it has a custom rect, for example if this element is tied to a canvas path. |
| + if (!m_explicitElementRect.isEmpty()) { |
| + *outContainer = axObjectCache().objectFromAXID(m_explicitContainerID); |
| + if (*outContainer) { |
| + outBoundsInContainer = FloatRect(m_explicitElementRect); |
| + return; |
| + } |
| + } |
| + |
| + // If it's in a canvas but doesn't have an explicit rect, get the bounding rect of its children. |
| + if (getNode()->parentElement()->isInCanvasSubtree()) { |
| + Vector<FloatRect> rects; |
| + for (Node& child : NodeTraversal::childrenOf(*getNode())) { |
| + if (child.isHTMLElement()) { |
| + if (AXObject* obj = axObjectCache().get(&child)) { |
| + AXObject* container; |
| + FloatRect bounds; |
| + obj->getRelativeBounds(&container, bounds, outContainerTransform); |
| + if (container) { |
| + *outContainer = container; |
| + rects.append(bounds); |
| + } |
| + } |
| + } |
| + } |
| + |
| + if (*outContainer) { |
| + outBoundsInContainer = unionRect(rects); |
| + return; |
| + } |
| + } |
| + |
| + // If this object doesn't have an explicit element rect or computable from its children, |
| + // for now, let's return the position of the ancestor that does have a position, |
| + // and make it the width of that parent, and about the height of a line of text, so that |
| + // it's clear the object is a child of the parent. |
| + for (AXObject* positionProvider = parentObject(); positionProvider; positionProvider = positionProvider->parentObject()) { |
| + if (positionProvider->isAXLayoutObject()) { |
| + positionProvider->getRelativeBounds(outContainer, outBoundsInContainer, outContainerTransform); |
| + if (*outContainer) |
| + outBoundsInContainer.setSize(FloatSize(outBoundsInContainer.width(), std::min(10.0f, outBoundsInContainer.height()))); |
|
aboxhall
2016/07/28 18:40:43
Is there a test for this behaviour?
dmazzoni
2016/07/28 21:43:16
Yes, this was covered by existing canvas accessibi
|
| + break; |
| + } |
| + } |
| +} |
| + |
| static Node* getParentNodeForComputeParent(Node* node) |
| { |
| if (!node) |