Commit d8089343 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Fixes for "show LabelButtons as disabled in inactive widgets".

* Update the visual state when getting added to the widget.  Otherwise
  the state may be incorrect until the first time GetVisualState() is
  called for some other reason (e.g. the button is hovered).
* Don't consider widgets "inactive" for this purpose if they can't be
  activated to begin with (e.g. menus).

Bug: 1106631
Change-Id: I9238498d91e515b03b6c04bc22014e84aff7057c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2325273
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793062}
parent f6257d0c
...@@ -466,6 +466,8 @@ void LabelButton::AddedToWidget() { ...@@ -466,6 +466,8 @@ void LabelButton::AddedToWidget() {
paint_as_active_subscription_ = paint_as_active_subscription_ =
GetWidget()->RegisterPaintAsActiveChangedCallback(base::BindRepeating( GetWidget()->RegisterPaintAsActiveChangedCallback(base::BindRepeating(
&LabelButton::VisualStateChanged, base::Unretained(this))); &LabelButton::VisualStateChanged, base::Unretained(this)));
// Set the initial state correctly.
VisualStateChanged();
} }
} }
...@@ -546,10 +548,11 @@ gfx::Size LabelButton::GetUnclampedSizeWithoutLabel() const { ...@@ -546,10 +548,11 @@ gfx::Size LabelButton::GetUnclampedSizeWithoutLabel() const {
} }
Button::ButtonState LabelButton::GetVisualState() const { Button::ButtonState LabelButton::GetVisualState() const {
const bool force_disabled = const auto* widget = GetWidget();
PlatformStyle::kInactiveWidgetControlsAppearDisabled && GetWidget() && if (PlatformStyle::kInactiveWidgetControlsAppearDisabled && widget &&
!GetWidget()->ShouldPaintAsActive(); widget->CanActivate() && !widget->ShouldPaintAsActive())
return force_disabled ? STATE_DISABLED : GetState(); return STATE_DISABLED;
return GetState();
} }
void LabelButton::VisualStateChanged() { void LabelButton::VisualStateChanged() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment