Repository: electron/electron
Pull request: fix: tooltips in WCO caption buttons

Backport of #44721

See that PR for details.


Notes: Fixed an issue where buttons shown under the Window Controls Overlay API were missing tooltips.


Changed files:
filename: shell/browser/ui/views/win_caption_button_container.cc
patch: @@ -19,6 +19,7 @@
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/compositor/layer.h"
 #include "ui/strings/grit/ui_strings.h"
+#include "ui/views/accessibility/view_accessibility.h"
 #include "ui/views/background.h"
 #include "ui/views/layout/flex_layout.h"
 #include "ui/views/view_class_properties.h"
@@ -83,6 +84,7 @@ WinCaptionButtonContainer::WinCaptionButtonContainer(WinFrameView* frame_view)
                                    views::MaximumFlexSizeRule::kPreferred,
                                    /* adjust_width_for_height */ false,
                                    views::MinimumFlexSizeRule::kScaleToZero));
+  UpdateButtonToolTipsForWindowControlsOverlay();
 }
 
 WinCaptionButtonContainer::~WinCaptionButtonContainer() {}
@@ -105,18 +107,6 @@ int WinCaptionButtonContainer::NonClientHitTest(const gfx::Point& point) const {
   return HTCAPTION;
 }
 
-gfx::Size WinCaptionButtonContainer::GetButtonSize() const {
-  // Close button size is set the same as all the buttons
-  return close_button_->GetSize();
-}
-
-void WinCaptionButtonContainer::SetButtonSize(gfx::Size size) {
-  minimize_button_->SetSize(size);
-  maximize_button_->SetSize(size);
-  restore_button_->SetSize(size);
-  close_button_->SetSize(size);
-}
-
 void WinCaptionButtonContainer::ResetWindowControls() {
   minimize_button_->SetState(views::Button::STATE_NORMAL);
   maximize_button_->SetState(views::Button::STATE_NORMAL);
@@ -132,10 +122,7 @@ void WinCaptionButtonContainer::AddedToWidget() {
   widget_observation_.Observe(widget);
 
   UpdateButtons();
-
-  if (frame_view_->window()->IsWindowControlsOverlayEnabled()) {
-    UpdateBackground();
-  }
+  UpdateBackground();
 }
 
 void WinCaptionButtonContainer::RemovedFromWidget() {
@@ -183,6 +170,24 @@ void WinCaptionButtonContainer::UpdateButtons() {
   InvalidateLayout();
 }
 
+void WinCaptionButtonContainer::UpdateButtonToolTipsForWindowControlsOverlay() {
+  minimize_button_->SetTooltipText(
+      minimize_button_->GetViewAccessibility().GetCachedName());
+  maximize_button_->SetTooltipText(
+      maximize_button_->GetViewAccessibility().GetCachedName());
+  restore_button_->SetTooltipText(
+      restore_button_->GetViewAccessibility().GetCachedName());
+  close_button_->SetTooltipText(
+      close_button_->GetViewAccessibility().GetCachedName());
+}
+
+void WinCaptionButtonContainer::SetButtonSize(gfx::Size size) {
+  minimize_button_->SetSize(size);
+  maximize_button_->SetSize(size);
+  restore_button_->SetSize(size);
+  close_button_->SetSize(size);
+}
+
 BEGIN_METADATA(WinCaptionButtonContainer)
 END_METADATA
 

filename: shell/browser/ui/views/win_caption_button_container.h
patch: @@ -42,9 +42,11 @@ class WinCaptionButtonContainer : public views::View,
   // See also ClientView::NonClientHitTest.
   int NonClientHitTest(const gfx::Point& point) const;
 
-  gfx::Size GetButtonSize() const;
   void SetButtonSize(gfx::Size size);
 
+  // Add tooltip text to caption buttons.
+  void UpdateButtonToolTipsForWindowControlsOverlay();
+
   // Sets caption button container background color.
   void UpdateBackground();