Chromium Code Reviews| Index: ui/views/controls/button/menu_button.cc |
| diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc |
| index 192264032bd71f42aaaf39214d7d74618eab181c..3b8a69f6c654408241736b822c000fd40f64c5c0 100644 |
| --- a/ui/views/controls/button/menu_button.cc |
| +++ b/ui/views/controls/button/menu_button.cc |
| @@ -72,8 +72,9 @@ MenuButton::MenuButton(const base::string16& text, |
| menu_marker_(ui::ResourceBundle::GetSharedInstance() |
| .GetImageNamed(IDR_MENU_DROPARROW) |
| .ToImageSkia()), |
| - destroyed_flag_(NULL), |
| + destroyed_flag_(nullptr), |
| pressed_lock_count_(0), |
| + increment_pressed_lock_called_(nullptr), |
| should_disable_after_press_(false), |
| weak_factory_(this) { |
| SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| @@ -117,17 +118,20 @@ bool MenuButton::Activate(const ui::Event* event) { |
| // matter where the user pressed. To force RootView to recalculate the |
| // mouse target during the mouse press we explicitly set the mouse handler |
| // to NULL. |
| - static_cast<internal::RootView*>(GetWidget()->GetRootView())-> |
| - SetMouseHandler(NULL); |
| + static_cast<internal::RootView*>(GetWidget()->GetRootView()) |
| + ->SetMouseHandler(nullptr); |
| bool destroyed = false; |
| destroyed_flag_ = &destroyed; |
| + DCHECK(increment_pressed_lock_called_ == nullptr); |
| + // Observe if IncrementPressedLocked() was called so we can trigger the |
| + // correct ink drop animations. |
| + bool increment_pressed_lock_called = false; |
| + increment_pressed_lock_called_ = &increment_pressed_lock_called; |
| + |
| // We don't set our state here. It's handled in the MenuController code or |
| // by our click listener. |
| - |
| - if (ink_drop_delegate()) |
| - ink_drop_delegate()->OnAction(InkDropState::QUICK_ACTION); |
| listener_->OnMenuButtonClicked(this, menu_position, event); |
| if (destroyed) { |
| @@ -135,10 +139,14 @@ bool MenuButton::Activate(const ui::Event* event) { |
| return false; |
| } |
| - destroyed_flag_ = NULL; |
| + increment_pressed_lock_called_ = nullptr; |
| + destroyed_flag_ = nullptr; |
| menu_closed_time_ = TimeTicks::Now(); |
| + if (ink_drop_delegate() && !increment_pressed_lock_called) |
| + ink_drop_delegate()->OnAction(InkDropState::QUICK_ACTION); |
| + |
| // We must return false here so that the RootView does not get stuck |
| // sending all mouse pressed events to us instead of the appropriate |
| // target. |
| @@ -198,10 +206,10 @@ bool MenuButton::OnMousePressed(const ui::MouseEvent& event) { |
| RequestFocus(); |
| if (state() != STATE_DISABLED && HitTestPoint(event.location()) && |
| IsTriggerableEventType(event)) { |
| - if (IsTriggerableEvent(event)) |
| - return Activate(&event); |
| if (ink_drop_delegate()) |
| ink_drop_delegate()->OnAction(InkDropState::ACTION_PENDING); |
| + if (IsTriggerableEvent(event)) |
| + return Activate(&event); |
| } |
| return true; |
| } |
| @@ -359,8 +367,14 @@ void MenuButton::NotifyClick(const ui::Event& event) { |
| void MenuButton::IncrementPressedLocked() { |
| ++pressed_lock_count_; |
| + if (increment_pressed_lock_called_) |
| + *increment_pressed_lock_called_ = true; |
| should_disable_after_press_ = state() == STATE_DISABLED; |
| + const ButtonState previous_state = state(); |
|
varkha
2016/03/08 21:47:58
Could you not call OnAction here? SetState doesn't
bruthig
2016/03/09 01:52:57
Done.
|
| SetState(STATE_PRESSED); |
| + if (previous_state != STATE_PRESSED && ink_drop_delegate()) { |
|
varkha
2016/03/08 21:47:58
nit: no need for parentheses.
bruthig
2016/03/09 01:52:57
Done.
|
| + ink_drop_delegate()->OnAction(InkDropState::ACTIVATED); |
| + } |
| } |
| void MenuButton::DecrementPressedLocked() { |
| @@ -377,6 +391,11 @@ void MenuButton::DecrementPressedLocked() { |
| desired_state = STATE_HOVERED; |
| } |
| SetState(desired_state); |
| + if (ink_drop_delegate() && |
| + (desired_state == STATE_NORMAL || desired_state == STATE_HOVERED || |
|
varkha
2016/03/08 21:47:58
Is this same as desired_state != STATE_PRESSED?
bruthig
2016/03/09 01:52:57
This has changed a bit, varkha@, please take a loo
|
| + desired_state == STATE_DISABLED)) { |
| + ink_drop_delegate()->OnAction(InkDropState::DEACTIVATED); |
| + } |
| } |
| } |