From bc23271e2ca9cde5b47247685c42eb1cf91d8884 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Sun, 8 May 2022 17:42:44 +0000 Subject: [PATCH] Set expanded on buttons with popup triggering attributes This CL sets kExpandedExpanded and kExpandedCollapsed for any HTMLButtonElement that contains a popup triggering attribute (togglepopup, showpopup, or hidepopup), and for which the target element is a valid kPopup popup (i.e. not a popup=hint or popup=async). Note that per guidance [1] this CL does not set HasPopup::kMenu at all. [1] https://github.com/openui/open-ui/issues/329 Bug: 1307772 Change-Id: I7a344e49cfc7667c379937d19a636e29804879b7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3617148 Auto-Submit: Mason Freed Reviewed-by: Aaron Leventhal Commit-Queue: Mason Freed Cr-Commit-Position: refs/heads/main@{#1000811} NOKEYCHECK=True GitOrigin-RevId: 2e924a036dc1806ab62d2561abf6736e635469bc --- .../renderer/core/html/forms/html_button_element.h | 2 +- .../modules/accessibility/ax_node_object.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/blink/renderer/core/html/forms/html_button_element.h b/blink/renderer/core/html/forms/html_button_element.h index 8cfd2e38afb..0829f822ab4 100644 --- a/blink/renderer/core/html/forms/html_button_element.h +++ b/blink/renderer/core/html/forms/html_button_element.h @@ -29,7 +29,7 @@ namespace blink { -class HTMLButtonElement final : public HTMLFormControlElement { +class CORE_EXPORT HTMLButtonElement final : public HTMLFormControlElement { DEFINE_WRAPPERTYPEINFO(); public: diff --git a/blink/renderer/modules/accessibility/ax_node_object.cc b/blink/renderer/modules/accessibility/ax_node_object.cc index a62d90b2e43..229b61032bb 100644 --- a/blink/renderer/modules/accessibility/ax_node_object.cc +++ b/blink/renderer/modules/accessibility/ax_node_object.cc @@ -66,6 +66,7 @@ #include "third_party/blink/renderer/core/html/canvas/image_data.h" #include "third_party/blink/renderer/core/html/custom/element_internals.h" #include "third_party/blink/renderer/core/html/fenced_frame/html_fenced_frame_element.h" +#include "third_party/blink/renderer/core/html/forms/html_button_element.h" #include "third_party/blink/renderer/core/html/forms/html_field_set_element.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/html_label_element.h" @@ -1835,6 +1836,18 @@ AccessibilityExpanded AXNodeObject::IsExpanded() const { : kExpandedCollapsed; } + // For buttons that contain the |togglepopup|, |showpopup|, or |hidepopup| + // popup triggering attributes, and the pointed-to element is a valid popup + // with type kPopup, then set aria-expanded=false when the popup is hidden, + // and aria-expanded=true when it is showing. + if (auto* button = DynamicTo(element)) { + if (auto* popup = button->togglePopupElement()) { + if (popup->PopupType() == PopupValueType::kPopup) { + return popup->popupOpen() ? kExpandedExpanded : kExpandedCollapsed; + } + } + } + if (IsA(*element)) { if (element->parentNode() && IsA(element->parentNode())) {