- Revision
- 288018
- Author
- [email protected]
- Date
- 2022-01-14 08:40:31 -0800 (Fri, 14 Jan 2022)
Log Message
AX: Move methods that are unnecessarily in AccessibilityRenderObject to AccessibilityNodeObject (part 1 of n)
https://bugs.webkit.org/show_bug.cgi?id=235204
Reviewed by Chris Fleizach.
Many methods in AccessibilityRenderObject don't actually do anything renderer-specific,
and thus should be in the base class AccessibilityNodeObject. This will help improve our support
for AX objects that normally have renderers, but don't because of CSS or ARIA markup (e.g. display: contents).
* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::isFileUploadButton const):
(WebCore::AccessibilityNodeObject::correspondingControlForLabelElement const):
(WebCore::AccessibilityNodeObject::correspondingLabelForControlElement const):
(WebCore::AccessibilityNodeObject::labelElementContainer const):
(WebCore::AccessibilityNodeObject::exposesTitleUIElement const):
(WebCore::AccessibilityNodeObject::hasTextAlternative const):
* accessibility/AccessibilityNodeObject.h:
Add all of the above methods from AccessibilityRenderObject.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::determineDropEffects const):
(WebCore::AccessibilityRenderObject::isFileUploadButton const):
(WebCore::AccessibilityRenderObject::labelElementContainer const):
(WebCore::AccessibilityRenderObject::hasTextAlternative const):
(WebCore::AccessibilityRenderObject::exposesTitleUIElement const):
(WebCore::AccessibilityRenderObject::correspondingControlForLabelElement const):
(WebCore::AccessibilityRenderObject::correspondingLabelForControlElement const):
* accessibility/AccessibilityRenderObject.h:
Move all of the above methods to AccessibilityNodeObject.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (288017 => 288018)
--- trunk/Source/WebCore/ChangeLog 2022-01-14 15:23:24 UTC (rev 288017)
+++ trunk/Source/WebCore/ChangeLog 2022-01-14 16:40:31 UTC (rev 288018)
@@ -1,3 +1,35 @@
+2022-01-14 Tyler Wilcock <[email protected]>
+
+ AX: Move methods that are unnecessarily in AccessibilityRenderObject to AccessibilityNodeObject (part 1 of n)
+ https://bugs.webkit.org/show_bug.cgi?id=235204
+
+ Reviewed by Chris Fleizach.
+
+ Many methods in AccessibilityRenderObject don't actually do anything renderer-specific,
+ and thus should be in the base class AccessibilityNodeObject. This will help improve our support
+ for AX objects that normally have renderers, but don't because of CSS or ARIA markup (e.g. display: contents).
+
+ * accessibility/AccessibilityNodeObject.cpp:
+ (WebCore::AccessibilityNodeObject::isFileUploadButton const):
+ (WebCore::AccessibilityNodeObject::correspondingControlForLabelElement const):
+ (WebCore::AccessibilityNodeObject::correspondingLabelForControlElement const):
+ (WebCore::AccessibilityNodeObject::labelElementContainer const):
+ (WebCore::AccessibilityNodeObject::exposesTitleUIElement const):
+ (WebCore::AccessibilityNodeObject::hasTextAlternative const):
+ * accessibility/AccessibilityNodeObject.h:
+ Add all of the above methods from AccessibilityRenderObject.
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::determineDropEffects const):
+ (WebCore::AccessibilityRenderObject::isFileUploadButton const):
+ (WebCore::AccessibilityRenderObject::labelElementContainer const):
+ (WebCore::AccessibilityRenderObject::hasTextAlternative const):
+ (WebCore::AccessibilityRenderObject::exposesTitleUIElement const):
+ (WebCore::AccessibilityRenderObject::correspondingControlForLabelElement const):
+ (WebCore::AccessibilityRenderObject::correspondingLabelForControlElement const):
+ * accessibility/AccessibilityRenderObject.h:
+ Move all of the above methods to AccessibilityNodeObject.
+
2022-01-14 Antoine Quint <[email protected]>
Reduce use of KeyframeEffect::targetElementOrPseudoElement()
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp (288017 => 288018)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-01-14 15:23:24 UTC (rev 288017)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp 2022-01-14 16:40:31 UTC (rev 288018)
@@ -32,6 +32,7 @@
#include "AXLogger.h"
#include "AXObjectCache.h"
#include "AccessibilityImageMapLink.h"
+#include "AccessibilityLabel.h"
#include "AccessibilityList.h"
#include "AccessibilityListBox.h"
#include "AccessibilitySpinButton.h"
@@ -562,6 +563,13 @@
}
}
+bool AccessibilityNodeObject::isFileUploadButton() const
+{
+ if (is<HTMLInputElement>(m_node))
+ return downcast<HTMLInputElement>(m_node)->isFileUpload();
+ return false;
+}
+
bool AccessibilityNodeObject::isNativeCheckboxOrRadio() const
{
Node* node = this->node();
@@ -1174,6 +1182,37 @@
return true;
}
+AccessibilityObject* AccessibilityNodeObject::correspondingControlForLabelElement() const
+{
+ auto* labelElement = labelElementContainer();
+ if (!labelElement)
+ return nullptr;
+
+ auto correspondingControl = labelElement->control();
+ if (!correspondingControl)
+ return nullptr;
+
+ // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
+ if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
+ return nullptr;
+
+ return axObjectCache()->getOrCreate(correspondingControl.get());
+}
+
+AccessibilityObject* AccessibilityNodeObject::correspondingLabelForControlElement() const
+{
+ // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
+ // override the "label" element association.
+ if (hasTextAlternative())
+ return nullptr;
+
+ if (is<HTMLElement>(m_node)) {
+ if (HTMLLabelElement* label = labelForElement(downcast<HTMLElement>(m_node)))
+ return axObjectCache()->getOrCreate(label);
+ }
+ return nullptr;
+}
+
HTMLLabelElement* AccessibilityNodeObject::labelForElement(Element* element) const
{
if (!is<HTMLElement>(*element) || !downcast<HTMLElement>(*element).isLabelable())
@@ -1309,7 +1348,21 @@
return !result.isEmpty() ? result : accessibleNameForNode(label);
}
-
+
+HTMLLabelElement* AccessibilityNodeObject::labelElementContainer() const
+{
+ // The control element should not be considered part of the label.
+ if (isControl())
+ return nullptr;
+
+ // Find an ancestor label element.
+ for (auto* parentNode = m_node; parentNode; parentNode = parentNode->parentNode()) {
+ if (is<HTMLLabelElement>(*parentNode))
+ return downcast<HTMLLabelElement>(parentNode);
+ }
+ return nullptr;
+}
+
void AccessibilityNodeObject::titleElementText(Vector<AccessibilityText>& textOrder) const
{
Node* node = this->node();
@@ -1333,6 +1386,47 @@
textOrder.append(AccessibilityText(String(), AccessibilityTextSource::LabelByElement));
}
+bool AccessibilityNodeObject::exposesTitleUIElement() const
+{
+ if (!isControl() && !isFigureElement())
+ return false;
+
+ // If this control is ignored (because it's invisible),
+ // then the label needs to be exposed so it can be visible to accessibility.
+ if (accessibilityIsIgnored())
+ return true;
+
+ // When controls have their own descriptions, the title element should be ignored.
+ if (hasTextAlternative())
+ return false;
+
+ // When <label> element has aria-label or aria-labelledby on it, we shouldn't expose it as the
+ // titleUIElement, otherwise its inner text will be announced by a screenreader.
+ if (isLabelable()) {
+ if (HTMLLabelElement* label = labelForElement(downcast<Element>(m_node))) {
+ if (!label->attributeWithoutSynchronization(aria_labelAttr).isEmpty())
+ return false;
+ if (AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label)) {
+ if (!labelObject->ariaLabeledByAttribute().isEmpty())
+ return false;
+ // To simplify instances where the labeling element includes widget descendants
+ // which it does not label.
+ if (is<AccessibilityLabel>(*labelObject)
+ && downcast<AccessibilityLabel>(*labelObject).containsUnrelatedControls())
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool AccessibilityNodeObject::hasTextAlternative() const
+{
+ // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
+ // override the "label" element association.
+ return ariaAccessibilityDescription().length();
+}
+
void AccessibilityNodeObject::alternativeText(Vector<AccessibilityText>& textOrder) const
{
if (isWebArea()) {
Modified: trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h (288017 => 288018)
--- trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h 2022-01-14 15:23:24 UTC (rev 288017)
+++ trunk/Source/WebCore/accessibility/AccessibilityNodeObject.h 2022-01-14 16:40:31 UTC (rev 288018)
@@ -66,6 +66,7 @@
bool isMenuButton() const override;
bool isMenuItem() const override;
bool isMenuRelated() const override;
+ bool isFileUploadButton() const override;
bool isMultiSelectable() const override;
virtual bool isNativeCheckboxOrRadio() const;
bool isNativeImage() const override;
@@ -164,9 +165,14 @@
void changeValueByStep(bool increase);
// This returns true if it's focusable but it's not content editable and it's not a control or ARIA control.
bool isGenericFocusableElement() const;
+
bool isLabelable() const;
+ AccessibilityObject* correspondingControlForLabelElement() const override;
+ AccessibilityObject* correspondingLabelForControlElement() const override;
HTMLLabelElement* labelForElement(Element*) const;
String textForLabelElement(Element*) const;
+ HTMLLabelElement* labelElementContainer() const;
+
String ariaAccessibilityDescription() const;
void ariaLabeledByElements(Vector<Element*>& elements) const;
String accessibilityDescriptionForElements(Vector<Element*> &elements) const;
@@ -178,6 +184,7 @@
AccessibilityObject* menuButtonForMenu() const;
AccessibilityObject* captionForFigure() const;
virtual void titleElementText(Vector<AccessibilityText>&) const;
+ bool exposesTitleUIElement() const override;
private:
bool isAccessibilityNodeObject() const final { return true; }
@@ -191,6 +198,7 @@
bool postKeyboardKeysForValueChange(bool increase);
void setNodeValue(bool increase, float value);
bool performDismissAction() final;
+ bool hasTextAlternative() const;
Node* m_node;
};
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (288017 => 288018)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2022-01-14 15:23:24 UTC (rev 288017)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2022-01-14 16:40:31 UTC (rev 288018)
@@ -32,7 +32,6 @@
#include "AXLogger.h"
#include "AXObjectCache.h"
#include "AccessibilityImageMapLink.h"
-#include "AccessibilityLabel.h"
#include "AccessibilityListBox.h"
#include "AccessibilitySVGRoot.h"
#include "AccessibilitySpinButton.h"
@@ -547,16 +546,6 @@
return isWidget && ariaRoleAttribute() == AccessibilityRole::Unknown;
}
-bool AccessibilityRenderObject::isFileUploadButton() const
-{
- if (m_renderer && is<HTMLInputElement>(m_renderer->node())) {
- HTMLInputElement& input = downcast<HTMLInputElement>(*m_renderer->node());
- return input.isFileUpload();
- }
-
- return false;
-}
-
bool AccessibilityRenderObject::isOffScreen() const
{
if (!m_renderer)
@@ -817,24 +806,6 @@
return isARIAStaticText() || is<RenderText>(*m_renderer) || isTextControl();
}
-HTMLLabelElement* AccessibilityRenderObject::labelElementContainer() const
-{
- if (!m_renderer)
- return nullptr;
-
- // the control element should not be considered part of the label
- if (isControl())
- return nullptr;
-
- // find if this has a parent that is a label
- for (Node* parentNode = m_renderer->node(); parentNode; parentNode = parentNode->parentNode()) {
- if (is<HTMLLabelElement>(*parentNode))
- return downcast<HTMLLabelElement>(parentNode);
- }
-
- return nullptr;
-}
-
// The boundingBox for elements within the remote SVG element needs to be offset by its position
// within the parent page, otherwise they are in relative coordinates only.
void AccessibilityRenderObject::offsetBoundingBoxForRemoteSVGElement(LayoutRect& rect) const
@@ -1100,13 +1071,6 @@
addRadioButtonGroupMembers(linkedUIElements);
}
-bool AccessibilityRenderObject::hasTextAlternative() const
-{
- // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
- // override the "label" element association.
- return ariaAccessibilityDescription().length();
-}
-
bool AccessibilityRenderObject::hasPopup() const
{
// Return true if this has the aria-haspopup attribute, or if it has an ancestor of type link with the aria-haspopup attribute.
@@ -1157,42 +1121,7 @@
return { };
}
-
-bool AccessibilityRenderObject::exposesTitleUIElement() const
-{
- if (!isControl() && !isFigureElement())
- return false;
- // If this control is ignored (because it's invisible),
- // then the label needs to be exposed so it can be visible to accessibility.
- if (accessibilityIsIgnored())
- return true;
-
- // When controls have their own descriptions, the title element should be ignored.
- if (hasTextAlternative())
- return false;
-
- // When <label> element has aria-label or aria-labelledby on it, we shouldn't expose it as the
- // titleUIElement, otherwise its inner text will be announced by a screenreader.
- if (isLabelable()) {
- if (HTMLLabelElement* label = labelForElement(downcast<Element>(node()))) {
- if (!label->attributeWithoutSynchronization(aria_labelAttr).isEmpty())
- return false;
- if (AccessibilityObject* labelObject = axObjectCache()->getOrCreate(label)) {
- if (!labelObject->ariaLabeledByAttribute().isEmpty())
- return false;
- // To simplify instances where the labeling element includes widget descendants
- // which it does not label.
- if (is<AccessibilityLabel>(*labelObject)
- && downcast<AccessibilityLabel>(*labelObject).containsUnrelatedControls())
- return false;
- }
- }
- }
-
- return true;
-}
-
#if ENABLE(APPLE_PAY)
String AccessibilityRenderObject::applePayButtonDescription() const
{
@@ -2821,42 +2750,6 @@
}
}
-AccessibilityObject* AccessibilityRenderObject::correspondingControlForLabelElement() const
-{
- HTMLLabelElement* labelElement = labelElementContainer();
- if (!labelElement)
- return nullptr;
-
- auto correspondingControl = labelElement->control();
- if (!correspondingControl)
- return nullptr;
-
- // Make sure the corresponding control isn't a descendant of this label that's in the middle of being destroyed.
- if (correspondingControl->renderer() && !correspondingControl->renderer()->parent())
- return nullptr;
-
- return axObjectCache()->getOrCreate(correspondingControl.get());
-}
-
-AccessibilityObject* AccessibilityRenderObject::correspondingLabelForControlElement() const
-{
- if (!m_renderer)
- return nullptr;
-
- // ARIA: section 2A, bullet #3 says if aria-labeledby or aria-label appears, it should
- // override the "label" element association.
- if (hasTextAlternative())
- return nullptr;
-
- Node* node = m_renderer->node();
- if (is<HTMLElement>(node)) {
- if (HTMLLabelElement* label = labelForElement(downcast<HTMLElement>(node)))
- return axObjectCache()->getOrCreate(label);
- }
-
- return nullptr;
-}
-
bool AccessibilityRenderObject::renderObjectIsObservable(RenderObject& renderer) const
{
// AX clients will listen for AXValueChange on a text control.
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h (288017 => 288018)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h 2022-01-14 15:23:24 UTC (rev 288017)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.h 2022-01-14 16:40:31 UTC (rev 288018)
@@ -59,8 +59,6 @@
void init() override;
bool isAttachment() const override;
- bool isFileUploadButton() const override;
-
bool isSelected() const override;
bool isFocused() const override;
bool isLoaded() const override;
@@ -96,8 +94,6 @@
AccessibilityObject* observableObject() const override;
void linkedUIElements(AccessibilityChildrenVector&) const override;
AccessibilityObject* titleUIElement() const override;
- AccessibilityObject* correspondingControlForLabelElement() const override;
- AccessibilityObject* correspondingLabelForControlElement() const override;
bool supportsARIAOwns() const override;
bool isPresentationalChildOfAriaRole() const override;
@@ -121,7 +117,6 @@
RenderView* topRenderer() const;
RenderTextControl* textControl() const;
- HTMLLabelElement* labelElementContainer() const;
URL url() const override;
PlainTextRange selectedTextRange() const override;
@@ -211,8 +206,6 @@
AccessibilityRole determineAccessibilityRole() override;
bool computeAccessibilityIsIgnored() const override;
- bool exposesTitleUIElement() const override;
-
#if ENABLE(MATHML)
virtual bool isIgnoredElementWithinMathTree() const;
#endif
@@ -224,7 +217,6 @@
void ariaListboxSelectedChildren(AccessibilityChildrenVector&);
void ariaListboxVisibleChildren(AccessibilityChildrenVector&);
bool isAllowedChildOfTree() const;
- bool hasTextAlternative() const;
String positionalDescriptionForMSAA() const;
PlainTextRange documentBasedSelectedTextRange() const;
Element* rootEditableElementForPosition(const Position&) const;