summaryrefslogtreecommitdiff
path: root/chromium/ui/views/controls/button/button.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/controls/button/button.cc')
-rw-r--r--chromium/ui/views/controls/button/button.cc61
1 files changed, 50 insertions, 11 deletions
diff --git a/chromium/ui/views/controls/button/button.cc b/chromium/ui/views/controls/button/button.cc
index ebf086404e3..ad5ab5f0470 100644
--- a/chromium/ui/views/controls/button/button.cc
+++ b/chromium/ui/views/controls/button/button.cc
@@ -15,7 +15,6 @@
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
-#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h"
@@ -44,6 +43,30 @@ const int kHoverFadeDurationMs = 150;
} // namespace
////////////////////////////////////////////////////////////////////////////////
+// WidgetObserverButtonBridge:
+Button::WidgetObserverButtonBridge::WidgetObserverButtonBridge(Button* button)
+ : owner_(button) {
+ DCHECK(button->GetWidget());
+ button->GetWidget()->AddObserver(this);
+}
+
+Button::WidgetObserverButtonBridge::~WidgetObserverButtonBridge() {
+ if (owner_)
+ owner_->GetWidget()->RemoveObserver(this);
+}
+
+void Button::WidgetObserverButtonBridge::OnWidgetActivationChanged(
+ Widget* widget,
+ bool active) {
+ owner_->WidgetActivationChanged(widget, active);
+}
+
+void Button::WidgetObserverButtonBridge::OnWidgetDestroying(Widget* widget) {
+ widget->RemoveObserver(this);
+ owner_ = nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// Button, static public:
// static
@@ -89,8 +112,6 @@ void Button::SetFocusForPlatform() {
void Button::SetTooltipText(const base::string16& tooltip_text) {
tooltip_text_ = tooltip_text;
- if (accessible_name_.empty())
- accessible_name_ = tooltip_text_;
OnSetTooltipText(tooltip_text);
TooltipTextChanged();
}
@@ -100,6 +121,10 @@ void Button::SetAccessibleName(const base::string16& name) {
NotifyAccessibilityEvent(ax::mojom::Event::kTextChanged, true);
}
+const base::string16& Button::GetAccessibleName() const {
+ return accessible_name_.empty() ? tooltip_text_ : accessible_name_;
+}
+
void Button::SetState(ButtonState state) {
if (state == state_)
return;
@@ -129,6 +154,14 @@ void Button::SetState(ButtonState state) {
SchedulePaint();
}
+Button::ButtonState Button::GetVisualState() const {
+ if (PlatformStyle::kInactiveWidgetControlsAppearDisabled && GetWidget() &&
+ !GetWidget()->IsActive()) {
+ return STATE_DISABLED;
+ }
+ return state();
+}
+
void Button::StartThrobbing(int cycles_til_stop) {
if (!animate_on_state_change_)
return;
@@ -318,11 +351,6 @@ bool Button::OnKeyReleased(const ui::KeyEvent& event) {
}
void Button::OnGestureEvent(ui::GestureEvent* event) {
- if (state_ == STATE_DISABLED) {
- InkDropHostView::OnGestureEvent(event);
- return;
- }
-
if (event->type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(*event)) {
// Set the button state to hot and start the animation fully faded in. The
// GESTURE_END event issued immediately after will set the state to
@@ -341,8 +369,6 @@ void Button::OnGestureEvent(ui::GestureEvent* event) {
event->type() == ui::ET_GESTURE_END) {
SetState(STATE_NORMAL);
}
- if (!event->handled())
- InkDropHostView::OnGestureEvent(event);
}
bool Button::AcceleratorPressed(const ui::Accelerator& accelerator) {
@@ -399,7 +425,7 @@ void Button::OnPaint(gfx::Canvas* canvas) {
void Button::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kButton;
- node_data->SetName(accessible_name_);
+ node_data->SetName(GetAccessibleName());
if (!enabled())
node_data->SetRestriction(ax::mojom::Restriction::kDisabled);
@@ -456,6 +482,15 @@ void Button::OnBlur() {
SchedulePaint();
}
+void Button::AddedToWidget() {
+ if (PlatformStyle::kInactiveWidgetControlsAppearDisabled)
+ widget_observer_ = std::make_unique<WidgetObserverButtonBridge>(this);
+}
+
+void Button::RemovedFromWidget() {
+ widget_observer_.reset();
+}
+
std::unique_ptr<InkDrop> Button::CreateInkDrop() {
std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl();
ink_drop->SetShowHighlightOnFocus(!focus_ring_);
@@ -568,4 +603,8 @@ bool Button::ShouldEnterHoveredState() {
return check_mouse_position && IsMouseHovered();
}
+void Button::WidgetActivationChanged(Widget* widget, bool active) {
+ StateChanged(state());
+}
+
} // namespace views