Sets aria attributes directly for overflow button.

This CL changes the overflow button to use by aria attributes instead of
explicitly creating accessibility nodes.

Bug: 836549
Change-Id: Ic122585cacb2c2279f380f844475edc196be451b
Reviewed-on: https://chromium-review.googlesource.com/c/1391909
Commit-Queue: CJ DiMeglio <lethalantidote@chromium.org>
Reviewed-by: Aaron Leventhal <aleventhal@chromium.org>
Reviewed-by: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633541}
diff --git a/third_party/blink/renderer/modules/accessibility/ax_media_controls.cc b/third_party/blink/renderer/modules/accessibility/ax_media_controls.cc
index 0043a22..bcb6d24 100644
--- a/third_party/blink/renderer/modules/accessibility/ax_media_controls.cc
+++ b/third_party/blink/renderer/modules/accessibility/ax_media_controls.cc
@@ -60,7 +60,6 @@
 
     case kMediaSliderThumb:
     case kMediaTimelineContainer:
-    case kMediaOverflowButton:
     case kMediaOverflowList:
       return MakeGarbageCollected<AccessibilityMediaControl>(layout_object,
                                                              ax_object_cache);
@@ -102,8 +101,6 @@
     AXRelatedObjectVector* related_objects,
     NameSources* name_sources) const {
   switch (ControlType()) {
-    case kMediaOverflowButton:
-      return QueryString(WebLocalizedString::kAXMediaOverflowButton);
     case kMediaSliderThumb:
     case kMediaTimelineContainer:
     case kMediaOverflowList:
@@ -124,8 +121,6 @@
     ax::mojom::DescriptionFrom& description_from,
     AXObjectVector* description_objects) const {
   switch (ControlType()) {
-    case kMediaOverflowButton:
-      return QueryString(WebLocalizedString::kAXMediaOverflowButtonHelp);
     case kMediaSliderThumb:
     case kMediaTimelineContainer:
     case kMediaOverflowList:
@@ -153,9 +148,6 @@
 
 ax::mojom::Role AccessibilityMediaControl::RoleValue() const {
   switch (ControlType()) {
-    case kMediaOverflowButton:
-      return ax::mojom::Role::kButton;
-
     case kMediaTimelineContainer:
     case kMediaOverflowList:
       return ax::mojom::Role::kGroup;
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.cc
index 1b91c6c..f3726e1 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.cc
@@ -55,6 +55,10 @@
   return true;
 }
 
+bool MediaControlDownloadButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 void MediaControlDownloadButtonElement::Trace(blink::Visitor* visitor) {
   MediaControlInputElement::Trace(visitor);
 }
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.h
index 0db13de..a499019 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_download_button_element.h
@@ -25,6 +25,7 @@
   // TODO(mlamouri): add WillRespondToMouseClickEvents
   WebLocalizedString::Name GetOverflowStringName() const final;
   bool HasOverflowButton() const final;
+  bool IsControlPanelButton() const final;
 
   void Trace(blink::Visitor*) override;
 
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_element_type.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_element_type.h
index 90d6bfa..e1773e2 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_element_type.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_element_type.h
@@ -12,7 +12,6 @@
   kMediaSlider,
   kMediaSliderThumb,
   kMediaTimelineContainer,
-  kMediaOverflowButton,
   kMediaOverflowList,
   kMediaIgnore
 };
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.cc
index 4e1bae1..71a560d 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.cc
@@ -52,6 +52,10 @@
   return true;
 }
 
+bool MediaControlFullscreenButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 const char* MediaControlFullscreenButtonElement::GetNameForHistograms() const {
   return IsOverflowElement() ? "FullscreenOverflowButton" : "FullscreenButton";
 }
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.h
index 776b111..12b5099 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_fullscreen_button_element.h
@@ -24,6 +24,7 @@
   bool WillRespondToMouseClickEvents() override;
   WebLocalizedString::Name GetOverflowStringName() const override;
   bool HasOverflowButton() const override;
+  bool IsControlPanelButton() const override;
 
  protected:
   const char* GetNameForHistograms() const override;
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.cc
index 9a59e2b..4ad03e4 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.cc
@@ -273,9 +273,7 @@
 }
 
 WebSize MediaControlInputElement::GetSizeOrDefault() const {
-  if (HasOverflowButton() || DisplayType() == kMediaOverflowButton) {
-    // If this has an overflow button then it is a button control and therefore
-    // has a default size of kDefaultButtonSize.
+  if (IsControlPanelButton()) {
     return MediaControlElementsHelper::GetSizeOrDefault(
         *this, WebSize(kDefaultButtonSize, kDefaultButtonSize));
   }
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.h
index 5079d9d..5d99c2a 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_input_element.h
@@ -75,6 +75,9 @@
 
   virtual void UpdateDisplayType();
 
+  // Returns whether element is a button on the control panel.
+  virtual bool IsControlPanelButton() const { return false; }
+
  private:
   friend class MediaControlInputElementTest;
 
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.cc
index fff3a88..7018582 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.cc
@@ -50,6 +50,10 @@
   return true;
 }
 
+bool MediaControlMuteButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 const char* MediaControlMuteButtonElement::GetNameForHistograms() const {
   return IsOverflowElement() ? "MuteOverflowButton" : "MuteButton";
 }
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.h
index 10e9e75..f9fbeb8 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_mute_button_element.h
@@ -21,6 +21,7 @@
   void UpdateDisplayType() override;
   WebLocalizedString::Name GetOverflowStringName() const override;
   bool HasOverflowButton() const override;
+  bool IsControlPanelButton() const override;
 
  protected:
   const char* GetNameForHistograms() const override;
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.cc
index 882d66a..e8082e4 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.cc
@@ -8,13 +8,20 @@
 #include "third_party/blink/renderer/core/dom/events/event.h"
 #include "third_party/blink/renderer/core/input_type_names.h"
 #include "third_party/blink/renderer/modules/media_controls/media_controls_impl.h"
+#include "third_party/blink/renderer/platform/text/platform_locale.h"
 
 namespace blink {
 
 MediaControlOverflowMenuButtonElement::MediaControlOverflowMenuButtonElement(
     MediaControlsImpl& media_controls)
-    : MediaControlInputElement(media_controls, kMediaOverflowButton) {
+    : MediaControlInputElement(media_controls, kMediaIgnore) {
   setType(input_type_names::kButton);
+  setAttribute(html_names::kAriaLabelAttr,
+               WTF::AtomicString(GetLocale().QueryString(
+                   WebLocalizedString::kAXMediaOverflowButton)));
+  setAttribute(html_names::kTitleAttr,
+               WTF::AtomicString(GetLocale().QueryString(
+                   WebLocalizedString::kAXMediaOverflowButtonHelp)));
   SetShadowPseudoId(AtomicString("-internal-media-controls-overflow-button"));
   SetIsWanted(false);
 }
@@ -23,6 +30,10 @@
   return true;
 }
 
+bool MediaControlOverflowMenuButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 const char* MediaControlOverflowMenuButtonElement::GetNameForHistograms()
     const {
   return "OverflowButton";
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.h
index 73aac4e..89a33b2 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_overflow_menu_button_element.h
@@ -21,6 +21,7 @@
 
   // MediaControlInputElement overrides.
   bool WillRespondToMouseClickEvents() override;
+  bool IsControlPanelButton() const final;
 
  protected:
   const char* GetNameForHistograms() const override;
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.cc
index 11ebb65..8151ffa 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.cc
@@ -67,6 +67,10 @@
   return true;
 }
 
+bool MediaControlPictureInPictureButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 const char* MediaControlPictureInPictureButtonElement::GetNameForHistograms()
     const {
   return IsOverflowElement() ? "PictureInPictureOverflowButton"
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.h
index 548a3c3..54a30d5 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_picture_in_picture_button_element.h
@@ -22,6 +22,7 @@
   void UpdateDisplayType() override;
   WebLocalizedString::Name GetOverflowStringName() const override;
   bool HasOverflowButton() const override;
+  bool IsControlPanelButton() const override;
 
   void OnMediaKeyboardEvent(Event* event) { DefaultEventHandler(*event); }
 
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.cc b/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.cc
index 5d1246b..293b789 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.cc
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.cc
@@ -48,6 +48,10 @@
   return true;
 }
 
+bool MediaControlPlayButtonElement::IsControlPanelButton() const {
+  return true;
+}
+
 const char* MediaControlPlayButtonElement::GetNameForHistograms() const {
   return IsOverflowElement() ? "PlayPauseOverflowButton" : "PlayPauseButton";
 }
diff --git a/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.h b/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.h
index 279d966..1248bf8 100644
--- a/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.h
+++ b/third_party/blink/renderer/modules/media_controls/elements/media_control_play_button_element.h
@@ -21,6 +21,7 @@
   void UpdateDisplayType() override;
   WebLocalizedString::Name GetOverflowStringName() const override;
   bool HasOverflowButton() const override;
+  bool IsControlPanelButton() const override;
 
   void OnMediaKeyboardEvent(Event* event) { DefaultEventHandler(*event); }
 
diff --git a/third_party/blink/web_tests/media/controls/accessibility-overflow-button.html b/third_party/blink/web_tests/media/controls/accessibility-overflow-button.html
new file mode 100644
index 0000000..d9c332a
--- /dev/null
+++ b/third_party/blink/web_tests/media/controls/accessibility-overflow-button.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<title>Media Controls: overflow button accessibility tests</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../media-controls.js"></script>
+<video controls></video>
+<script>
+async_test(t => {
+  var video = document.querySelector('video');
+  video.src = '../content/test.ogv';
+
+  video.oncanplaythrough = t.step_func_done(_ => {
+    var overflow_button = overflowButton(video);
+
+    assert_equals(overflow_button.getAttribute('aria-label'),
+                  'show more media controls');
+    assert_equals(overflow_button.getAttribute('title'), 'more options');
+  });
+});
+</script>
+</html>