Commit 928e6b9c authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Move "paint as active changed" subscription from Button to LabelButton.

This was the only consumer of it, so this scopes the usage more
narrowly.

Bug: none
Change-Id: I200653b423e6538ee8d0b42a28ea7195853a6c49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283401
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarThomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786142}
parent 00c77e7e
...@@ -185,14 +185,6 @@ void Button::SetState(ButtonState state) { ...@@ -185,14 +185,6 @@ void Button::SetState(ButtonState state) {
OnPropertyChanged(&state_, kPropertyEffectsPaint); OnPropertyChanged(&state_, kPropertyEffectsPaint);
} }
Button::ButtonState Button::GetVisualState() const {
if (PlatformStyle::kInactiveWidgetControlsAppearDisabled && GetWidget() &&
!GetWidget()->ShouldPaintAsActive()) {
return STATE_DISABLED;
}
return state();
}
void Button::StartThrobbing(int cycles_til_stop) { void Button::StartThrobbing(int cycles_til_stop) {
if (!animate_on_state_change_) if (!animate_on_state_change_)
return; return;
...@@ -480,18 +472,6 @@ void Button::OnBlur() { ...@@ -480,18 +472,6 @@ void Button::OnBlur() {
SchedulePaint(); SchedulePaint();
} }
void Button::AddedToWidget() {
if (PlatformStyle::kInactiveWidgetControlsAppearDisabled) {
paint_as_active_subscription_ =
GetWidget()->RegisterPaintAsActiveChangedCallback(base::BindRepeating(
&Button::WidgetPaintAsActiveChanged, base::Unretained(this)));
}
}
void Button::RemovedFromWidget() {
paint_as_active_subscription_.reset();
}
std::unique_ptr<InkDrop> Button::CreateInkDrop() { std::unique_ptr<InkDrop> Button::CreateInkDrop() {
std::unique_ptr<InkDrop> ink_drop = InkDropHostView::CreateInkDrop(); std::unique_ptr<InkDrop> ink_drop = InkDropHostView::CreateInkDrop();
ink_drop->SetShowHighlightOnFocus(!focus_ring_); ink_drop->SetShowHighlightOnFocus(!focus_ring_);
...@@ -606,10 +586,6 @@ void Button::OnEnabledChanged() { ...@@ -606,10 +586,6 @@ void Button::OnEnabledChanged() {
} }
} }
void Button::WidgetPaintAsActiveChanged() {
StateChanged(state());
}
DEFINE_ENUM_CONVERTERS( DEFINE_ENUM_CONVERTERS(
Button::ButtonState, Button::ButtonState,
{Button::STATE_NORMAL, base::ASCIIToUTF16("STATE_NORMAL")}, {Button::STATE_NORMAL, base::ASCIIToUTF16("STATE_NORMAL")},
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/views/controls/button/button_controller_delegate.h" #include "ui/views/controls/button/button_controller_delegate.h"
#include "ui/views/controls/focus_ring.h" #include "ui/views/controls/focus_ring.h"
#include "ui/views/painter.h" #include "ui/views/painter.h"
#include "ui/views/widget/widget.h"
namespace views { namespace views {
namespace test { namespace test {
...@@ -120,9 +119,6 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -120,9 +119,6 @@ class VIEWS_EXPORT Button : public InkDropHostView,
// like event dispatching, focus traversals, etc. Calling SetEnabled(false) // like event dispatching, focus traversals, etc. Calling SetEnabled(false)
// will also set the state of |this| to STATE_DISABLED. // will also set the state of |this| to STATE_DISABLED.
void SetState(ButtonState state); void SetState(ButtonState state);
// Returns the visual appearance state of the button. This takes into account
// both the button's display state and the state of the containing widget.
ButtonState GetVisualState() const;
// Starts throbbing. See HoverAnimation for a description of cycles_til_stop. // Starts throbbing. See HoverAnimation for a description of cycles_til_stop.
// This method does nothing if |animate_on_state_change_| is false. // This method does nothing if |animate_on_state_change_| is false.
...@@ -214,8 +210,6 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -214,8 +210,6 @@ class VIEWS_EXPORT Button : public InkDropHostView,
const ViewHierarchyChangedDetails& details) override; const ViewHierarchyChangedDetails& details) override;
void OnFocus() override; void OnFocus() override;
void OnBlur() override; void OnBlur() override;
void AddedToWidget() override;
void RemovedFromWidget() override;
// Overridden from InkDropHostView: // Overridden from InkDropHostView:
std::unique_ptr<InkDrop> CreateInkDrop() override; std::unique_ptr<InkDrop> CreateInkDrop() override;
...@@ -309,9 +303,6 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -309,9 +303,6 @@ class VIEWS_EXPORT Button : public InkDropHostView,
void OnEnabledChanged(); void OnEnabledChanged();
// Called when the widget's "paint as active" state has changed.
void WidgetPaintAsActiveChanged();
// The text shown in a tooltip. // The text shown in a tooltip.
base::string16 tooltip_text_; base::string16 tooltip_text_;
...@@ -358,9 +349,6 @@ class VIEWS_EXPORT Button : public InkDropHostView, ...@@ -358,9 +349,6 @@ class VIEWS_EXPORT Button : public InkDropHostView,
std::unique_ptr<Painter> focus_painter_; std::unique_ptr<Painter> focus_painter_;
std::unique_ptr<Widget::PaintAsActiveCallbackList::Subscription>
paint_as_active_subscription_;
// ButtonController is responsible for handling events sent to the Button and // ButtonController is responsible for handling events sent to the Button and
// related state changes from the events. // related state changes from the events.
// TODO(cyan): Make sure all state changes are handled within // TODO(cyan): Make sure all state changes are handled within
......
...@@ -466,6 +466,18 @@ void LabelButton::ChildPreferredSizeChanged(View* child) { ...@@ -466,6 +466,18 @@ void LabelButton::ChildPreferredSizeChanged(View* child) {
PreferredSizeChanged(); PreferredSizeChanged();
} }
void LabelButton::AddedToWidget() {
if (PlatformStyle::kInactiveWidgetControlsAppearDisabled) {
paint_as_active_subscription_ =
GetWidget()->RegisterPaintAsActiveChangedCallback(base::BindRepeating(
&LabelButton::PaintAsActiveChanged, base::Unretained(this)));
}
}
void LabelButton::RemovedFromWidget() {
paint_as_active_subscription_.reset();
}
void LabelButton::OnFocus() { void LabelButton::OnFocus() {
Button::OnFocus(); Button::OnFocus();
// Typically the border renders differently when focused. // Typically the border renders differently when focused.
...@@ -544,6 +556,17 @@ gfx::Size LabelButton::GetUnclampedSizeWithoutLabel() const { ...@@ -544,6 +556,17 @@ gfx::Size LabelButton::GetUnclampedSizeWithoutLabel() const {
return size; return size;
} }
Button::ButtonState LabelButton::GetVisualState() const {
const bool force_disabled =
PlatformStyle::kInactiveWidgetControlsAppearDisabled && GetWidget() &&
!GetWidget()->ShouldPaintAsActive();
return force_disabled ? STATE_DISABLED : state();
}
void LabelButton::PaintAsActiveChanged() {
StateChanged(state());
}
void LabelButton::ResetColorsFromNativeTheme() { void LabelButton::ResetColorsFromNativeTheme() {
const ui::NativeTheme* theme = GetNativeTheme(); const ui::NativeTheme* theme = GetNativeTheme();
// Since this is a LabelButton, use the label colors. // Since this is a LabelButton, use the label colors.
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/views/layout/layout_provider.h" #include "ui/views/layout/layout_provider.h"
#include "ui/views/native_theme_delegate.h" #include "ui/views/native_theme_delegate.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
#include "ui/views/widget/widget.h"
namespace views { namespace views {
...@@ -160,6 +161,8 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate { ...@@ -160,6 +161,8 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// Button: // Button:
void ChildPreferredSizeChanged(View* child) override; void ChildPreferredSizeChanged(View* child) override;
void AddedToWidget() override;
void RemovedFromWidget() override;
void OnFocus() override; void OnFocus() override;
void OnBlur() override; void OnBlur() override;
void OnThemeChanged() override; void OnThemeChanged() override;
...@@ -179,6 +182,14 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate { ...@@ -179,6 +182,14 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// height as total height, and clamp to min/max sizes as appropriate. // height as total height, and clamp to min/max sizes as appropriate.
gfx::Size GetUnclampedSizeWithoutLabel() const; gfx::Size GetUnclampedSizeWithoutLabel() const;
// Returns the current visual appearance of the button. This takes into
// account both the button's underlying state and the state of the containing
// widget.
ButtonState GetVisualState() const;
// Called when the widget's "paint as active" state has changed.
void PaintAsActiveChanged();
// Resets colors from the NativeTheme, explicitly set colors are unchanged. // Resets colors from the NativeTheme, explicitly set colors are unchanged.
void ResetColorsFromNativeTheme(); void ResetColorsFromNativeTheme();
...@@ -240,6 +251,9 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate { ...@@ -240,6 +251,9 @@ class VIEWS_EXPORT LabelButton : public Button, public NativeThemeDelegate {
// UI direction). // UI direction).
gfx::HorizontalAlignment horizontal_alignment_ = gfx::ALIGN_LEFT; gfx::HorizontalAlignment horizontal_alignment_ = gfx::ALIGN_LEFT;
std::unique_ptr<Widget::PaintAsActiveCallbackList::Subscription>
paint_as_active_subscription_;
DISALLOW_COPY_AND_ASSIGN(LabelButton); DISALLOW_COPY_AND_ASSIGN(LabelButton);
}; };
......
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