| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 return size; | 88 return size; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ToolbarButton::Layout() { | 91 void ToolbarButton::Layout() { |
| 92 LabelButton::Layout(); | 92 LabelButton::Layout(); |
| 93 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); | 93 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { | 96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 97 if (enabled() && ShouldShowMenu() && | 97 if (IsTriggerableEvent(event)) { |
| 98 IsTriggerableEvent(event) && HitTestPoint(event.location())) { | 98 if (enabled() && ShouldShowMenu() && HitTestPoint(event.location())) { |
| 99 // Store the y pos of the mouse coordinates so we can use them later to | 99 // Store the y pos of the mouse coordinates so we can use them later to |
| 100 // determine if the user dragged the mouse down (which should pop up the | 100 // determine if the user dragged the mouse down (which should pop up the |
| 101 // drag down menu immediately, instead of waiting for the timer) | 101 // drag down menu immediately, instead of waiting for the timer) |
| 102 y_position_on_lbuttondown_ = event.y(); | 102 y_position_on_lbuttondown_ = event.y(); |
| 103 | 103 |
| 104 // Schedule a task that will show the menu. | 104 // Schedule a task that will show the menu. |
| 105 const int kMenuTimerDelay = 500; | 105 const int kMenuTimerDelay = 500; |
| 106 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 107 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, | 107 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, |
| 108 show_menu_factory_.GetWeakPtr(), | 108 show_menu_factory_.GetWeakPtr(), |
| 109 ui::GetMenuSourceTypeForEvent(event)), | 109 ui::GetMenuSourceTypeForEvent(event)), |
| 110 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); | 110 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); |
| 111 } | 111 } |
| 112 | |
| 113 // views::Button actions are only triggered by left and middle mouse clicks. | |
| 114 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { | |
| 115 ink_drop_animation_controller_->AnimateToState( | 112 ink_drop_animation_controller_->AnimateToState( |
| 116 views::InkDropState::ACTION_PENDING); | 113 views::InkDropState::ACTION_PENDING); |
| 117 } | 114 } |
| 118 | 115 |
| 119 return LabelButton::OnMousePressed(event); | 116 return LabelButton::OnMousePressed(event); |
| 120 } | 117 } |
| 121 | 118 |
| 122 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { | 119 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 123 bool result = LabelButton::OnMouseDragged(event); | 120 bool result = LabelButton::OnMouseDragged(event); |
| 124 | 121 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 136 } | 133 } |
| 137 | 134 |
| 138 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { | 135 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 139 if (IsTriggerableEvent(event) || | 136 if (IsTriggerableEvent(event) || |
| 140 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { | 137 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { |
| 141 LabelButton::OnMouseReleased(event); | 138 LabelButton::OnMouseReleased(event); |
| 142 } | 139 } |
| 143 | 140 |
| 144 if (IsTriggerableEvent(event)) | 141 if (IsTriggerableEvent(event)) |
| 145 show_menu_factory_.InvalidateWeakPtrs(); | 142 show_menu_factory_.InvalidateWeakPtrs(); |
| 146 | |
| 147 if (!HitTestPoint(event.location())) | |
| 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
| 149 } | 143 } |
| 150 | 144 |
| 151 void ToolbarButton::OnMouseCaptureLost() { | 145 void ToolbarButton::OnMouseCaptureLost() { |
| 152 } | 146 } |
| 153 | 147 |
| 154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 148 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 155 // Starting a drag results in a MouseExited, we need to ignore it. | 149 // Starting a drag results in a MouseExited, we need to ignore it. |
| 156 // A right click release triggers an exit event. We want to | 150 // A right click release triggers an exit event. We want to |
| 157 // remain in a PUSHED state until the drop down menu closes. | 151 // remain in a PUSHED state until the drop down menu closes. |
| 158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 152 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | | 248 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | |
| 255 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); | 249 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); |
| 256 } | 250 } |
| 257 | 251 |
| 258 void ToolbarButton::NotifyClick(const ui::Event& event) { | 252 void ToolbarButton::NotifyClick(const ui::Event& event) { |
| 259 LabelButton::NotifyClick(event); | 253 LabelButton::NotifyClick(event); |
| 260 ink_drop_animation_controller_->AnimateToState( | 254 ink_drop_animation_controller_->AnimateToState( |
| 261 views::InkDropState::QUICK_ACTION); | 255 views::InkDropState::QUICK_ACTION); |
| 262 } | 256 } |
| 263 | 257 |
| 258 void ToolbarButton::OnClickCanceled(const ui::Event& event) { |
| 259 LabelButton::OnClickCanceled(event); |
| 260 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| 261 } |
| 262 |
| 264 bool ToolbarButton::ShouldShowMenu() { | 263 bool ToolbarButton::ShouldShowMenu() { |
| 265 return model_ != nullptr; | 264 return model_ != nullptr; |
| 266 } | 265 } |
| 267 | 266 |
| 268 void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) { | 267 void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) { |
| 269 if (!ShouldShowMenu()) | 268 if (!ShouldShowMenu()) |
| 270 return; | 269 return; |
| 271 | 270 |
| 272 gfx::Rect lb = GetLocalBounds(); | 271 gfx::Rect lb = GetLocalBounds(); |
| 273 | 272 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 SetState(STATE_NORMAL); | 346 SetState(STATE_NORMAL); |
| 348 } | 347 } |
| 349 | 348 |
| 350 const char* ToolbarButton::GetClassName() const { | 349 const char* ToolbarButton::GetClassName() const { |
| 351 return "ToolbarButton"; | 350 return "ToolbarButton"; |
| 352 } | 351 } |
| 353 | 352 |
| 354 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | 353 gfx::Point ToolbarButton::CalculateInkDropCenter() const { |
| 355 return GetLocalBounds().CenterPoint(); | 354 return GetLocalBounds().CenterPoint(); |
| 356 } | 355 } |
| OLD | NEW |