Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 | 92 |
| 93 // Schedule a task that will show the menu. | 93 // Schedule a task that will show the menu. |
| 94 const int kMenuTimerDelay = 500; | 94 const int kMenuTimerDelay = 500; |
| 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 95 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 96 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, | 96 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, |
| 97 show_menu_factory_.GetWeakPtr(), | 97 show_menu_factory_.GetWeakPtr(), |
| 98 ui::GetMenuSourceTypeForEvent(event)), | 98 ui::GetMenuSourceTypeForEvent(event)), |
| 99 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); | 99 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 ink_drop_animation_controller_->AnimateToState( | 102 // Button actions are only triggered by left and middle mouse clicks. |
|
tdanderson
2015/08/19 22:11:18
Don't we also want to show feedback when pressing
bruthig
2015/08/20 20:35:35
That will be triggered by the AnimateToState(ACTIV
| |
| 103 views::InkDropState::ACTION_PENDING); | 103 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { |
|
jonross
2015/08/19 22:13:36
Do you need to check the exclusivity of these clic
bruthig
2015/08/20 20:35:35
Negative, actions are still triggered when a butto
jonross
2015/08/21 15:14:48
Acknowledged.
| |
| 104 ink_drop_animation_controller_->AnimateToState( | |
| 105 views::InkDropState::ACTION_PENDING); | |
| 106 } | |
| 104 | 107 |
| 105 return LabelButton::OnMousePressed(event); | 108 return LabelButton::OnMousePressed(event); |
| 106 } | 109 } |
| 107 | 110 |
| 108 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { | 111 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 109 bool result = LabelButton::OnMouseDragged(event); | 112 bool result = LabelButton::OnMouseDragged(event); |
| 110 | 113 |
| 111 if (show_menu_factory_.HasWeakPtrs()) { | 114 if (show_menu_factory_.HasWeakPtrs()) { |
| 112 // If the mouse is dragged to a y position lower than where it was when | 115 // If the mouse is dragged to a y position lower than where it was when |
| 113 // clicked then we should not wait for the menu to appear but show | 116 // clicked then we should not wait for the menu to appear but show |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 | 158 |
| 156 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; | 159 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; |
| 157 switch (event->type()) { | 160 switch (event->type()) { |
| 158 case ui::ET_GESTURE_TAP_DOWN: | 161 case ui::ET_GESTURE_TAP_DOWN: |
| 159 ink_drop_state = views::InkDropState::ACTION_PENDING; | 162 ink_drop_state = views::InkDropState::ACTION_PENDING; |
| 160 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that | 163 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that |
| 161 // subsequent events for the gesture are sent to |this|. | 164 // subsequent events for the gesture are sent to |this|. |
| 162 event->SetHandled(); | 165 event->SetHandled(); |
| 163 break; | 166 break; |
| 164 case ui::ET_GESTURE_LONG_PRESS: | 167 case ui::ET_GESTURE_LONG_PRESS: |
| 165 ink_drop_state = views::InkDropState::SLOW_ACTION; | 168 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; |
| 166 break; | 169 break; |
| 167 case ui::ET_GESTURE_TAP: | 170 case ui::ET_GESTURE_TAP: |
| 168 ink_drop_state = views::InkDropState::QUICK_ACTION; | 171 ink_drop_state = views::InkDropState::QUICK_ACTION; |
| 169 break; | 172 break; |
| 173 case ui::ET_GESTURE_LONG_TAP: | |
| 174 ink_drop_state = views::InkDropState::SLOW_ACTION; | |
| 175 break; | |
| 170 case ui::ET_GESTURE_END: | 176 case ui::ET_GESTURE_END: |
| 171 case ui::ET_GESTURE_TAP_CANCEL: | 177 case ui::ET_GESTURE_TAP_CANCEL: |
| 172 ink_drop_state = views::InkDropState::HIDDEN; | 178 ink_drop_state = views::InkDropState::HIDDEN; |
| 173 break; | 179 break; |
| 174 default: | 180 default: |
| 175 return; | 181 return; |
| 176 } | 182 } |
| 177 ink_drop_animation_controller_->AnimateToState(ink_drop_state); | 183 ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| 178 } | 184 } |
| 179 | 185 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 SetState(STATE_PRESSED); | 287 SetState(STATE_PRESSED); |
| 282 | 288 |
| 283 menu_showing_ = true; | 289 menu_showing_ = true; |
| 284 | 290 |
| 285 // Create and run menu. Display an empty menu if model is NULL. | 291 // Create and run menu. Display an empty menu if model is NULL. |
| 286 if (model_.get()) { | 292 if (model_.get()) { |
| 287 views::MenuModelAdapter menu_delegate(model_.get()); | 293 views::MenuModelAdapter menu_delegate(model_.get()); |
| 288 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); | 294 menu_delegate.set_triggerable_event_flags(triggerable_event_flags()); |
| 289 menu_runner_.reset(new views::MenuRunner(menu_delegate.CreateMenu(), | 295 menu_runner_.reset(new views::MenuRunner(menu_delegate.CreateMenu(), |
| 290 views::MenuRunner::HAS_MNEMONICS)); | 296 views::MenuRunner::HAS_MNEMONICS)); |
| 297 ink_drop_animation_controller_->AnimateToState( | |
| 298 views::InkDropState::ACTIVATED); | |
|
jonross
2015/08/19 22:13:36
Consider refactoring these animations to be around
bruthig
2015/08/20 20:35:35
Done.
| |
| 291 views::MenuRunner::RunResult result = | 299 views::MenuRunner::RunResult result = |
| 292 menu_runner_->RunMenuAt(GetWidget(), | 300 menu_runner_->RunMenuAt(GetWidget(), |
|
jonross
2015/08/19 22:13:36
Blocking iirc?
bruthig
2015/08/20 20:35:35
Correct.
jonross
2015/08/21 15:14:48
Acknowledged.
| |
| 293 NULL, | 301 NULL, |
| 294 gfx::Rect(menu_position, gfx::Size(0, 0)), | 302 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 295 views::MENU_ANCHOR_TOPLEFT, | 303 views::MENU_ANCHOR_TOPLEFT, |
| 296 source_type); | 304 source_type); |
| 305 ink_drop_animation_controller_->AnimateToState( | |
| 306 views::InkDropState::DEACTIVATED); | |
| 297 if (result == views::MenuRunner::MENU_DELETED) | 307 if (result == views::MenuRunner::MENU_DELETED) |
| 298 return; | 308 return; |
| 299 } else { | 309 } else { |
| 300 views::MenuDelegate menu_delegate; | 310 views::MenuDelegate menu_delegate; |
| 301 views::MenuItemView* menu = new views::MenuItemView(&menu_delegate); | 311 views::MenuItemView* menu = new views::MenuItemView(&menu_delegate); |
| 302 menu_runner_.reset( | 312 menu_runner_.reset( |
| 303 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); | 313 new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS)); |
| 314 ink_drop_animation_controller_->AnimateToState( | |
| 315 views::InkDropState::ACTIVATED); | |
| 304 views::MenuRunner::RunResult result = | 316 views::MenuRunner::RunResult result = |
| 305 menu_runner_->RunMenuAt(GetWidget(), | 317 menu_runner_->RunMenuAt(GetWidget(), |
| 306 NULL, | 318 NULL, |
| 307 gfx::Rect(menu_position, gfx::Size(0, 0)), | 319 gfx::Rect(menu_position, gfx::Size(0, 0)), |
| 308 views::MENU_ANCHOR_TOPLEFT, | 320 views::MENU_ANCHOR_TOPLEFT, |
| 309 source_type); | 321 source_type); |
| 322 ink_drop_animation_controller_->AnimateToState( | |
| 323 views::InkDropState::DEACTIVATED); | |
| 310 if (result == views::MenuRunner::MENU_DELETED) | 324 if (result == views::MenuRunner::MENU_DELETED) |
| 311 return; | 325 return; |
| 312 } | 326 } |
| 313 | 327 |
| 314 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
| 315 | |
| 316 menu_showing_ = false; | 328 menu_showing_ = false; |
| 317 | 329 |
| 318 // Need to explicitly clear mouse handler so that events get sent | 330 // Need to explicitly clear mouse handler so that events get sent |
| 319 // properly after the menu finishes running. If we don't do this, then | 331 // properly after the menu finishes running. If we don't do this, then |
| 320 // the first click to other parts of the UI is eaten. | 332 // the first click to other parts of the UI is eaten. |
| 321 SetMouseHandler(NULL); | 333 SetMouseHandler(NULL); |
| 322 | 334 |
| 323 // Set the state back to normal after the drop down menu is closed. | 335 // Set the state back to normal after the drop down menu is closed. |
| 324 if (state_ != STATE_DISABLED) | 336 if (state_ != STATE_DISABLED) |
| 325 SetState(STATE_NORMAL); | 337 SetState(STATE_NORMAL); |
| 326 } | 338 } |
| 327 | 339 |
| 328 void ToolbarButton::LayoutInkDrop() { | 340 void ToolbarButton::LayoutInkDrop() { |
| 329 ink_drop_animation_controller_->SetInkDropSize(size()); | 341 // TODO(bruthig): Get the constants from the theme provider. |
|
jonross
2015/08/19 22:13:36
If you don't do this in the current review, please
bruthig
2015/08/20 20:35:35
Done.
| |
| 342 gfx::Size ink_drop_size = gfx::Size(32, 32); | |
| 343 ink_drop_animation_controller_->SetInkDropSize(ink_drop_size, 5, | |
| 344 gfx::Size(24, 24), 2); | |
| 345 ink_drop_animation_controller_->SetInkDropOrigin( | |
| 346 gfx::Point((width() - ink_drop_size.width()) / 2, | |
| 347 (height() - ink_drop_size.height()) / 2)); | |
| 348 } | |
| 349 | |
| 350 void ToolbarButton::NotifyClick(const ui::Event& event) { | |
| 351 ink_drop_animation_controller_->AnimateToState( | |
| 352 views::InkDropState::QUICK_ACTION); | |
| 353 LabelButton::NotifyClick(event); | |
| 330 } | 354 } |
| 331 | 355 |
| 332 const char* ToolbarButton::GetClassName() const { | 356 const char* ToolbarButton::GetClassName() const { |
| 333 return "ToolbarButton"; | 357 return "ToolbarButton"; |
| 334 } | 358 } |
| OLD | NEW |