Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
| diff --git a/chrome/browser/ui/views/toolbar/toolbar_action_view.cc b/chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
| index 3e142b44381bf2bf0f575da3c97de098a4e521e3..c63639310fba5c095803aa50412d6b341c362326 100644 |
| --- a/chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
| +++ b/chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
| @@ -25,6 +25,8 @@ |
| #include "ui/gfx/image/image_skia_operations.h" |
| #include "ui/gfx/image/image_skia_source.h" |
| #include "ui/resources/grit/ui_resources.h" |
| +#include "ui/views/animation/ink_drop_animation_controller.h" |
| +#include "ui/views/animation/ink_drop_animation_controller_factory.h" |
| #include "ui/views/controls/button/label_button_border.h" |
| #include "ui/views/controls/menu/menu_controller.h" |
| #include "ui/views/controls/menu/menu_runner.h" |
| @@ -60,6 +62,10 @@ ToolbarActionView::ToolbarActionView( |
| delegate_(delegate), |
| called_register_command_(false), |
| wants_to_run_(false), |
| + menu_showing_(false), |
| + ink_drop_animation_controller_( |
| + views::InkDropAnimationControllerFactory:: |
| + CreateInkDropAnimationController(this)), |
| weak_factory_(this) { |
| set_id(VIEW_ID_BROWSER_ACTION); |
| view_controller_->SetDelegate(this); |
| @@ -68,6 +74,17 @@ ToolbarActionView::ToolbarActionView( |
| set_context_menu_controller(this); |
| + const int kInkDropLargeSize = 32; |
| + const int kInkDropLargeCornerRadius = 5; |
| + const int kInkDropSmallSize = 24; |
| + const int kInkDropSmallCornerRadius = 2; |
| + |
| + ink_drop_animation_controller_->SetInkDropSize( |
| + gfx::Size(kInkDropLargeSize, kInkDropLargeSize), |
| + kInkDropLargeCornerRadius, |
| + gfx::Size(kInkDropSmallSize, kInkDropSmallSize), |
| + kInkDropSmallCornerRadius); |
| + |
| // We also listen for browser theme changes on linux because a switch from or |
| // to GTK requires that we regrab our browser action images. |
| registrar_.Add( |
| @@ -93,12 +110,84 @@ ToolbarActionView::~ToolbarActionView() { |
| view_controller_->SetDelegate(nullptr); |
| } |
| +void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| + SetPaintToLayer(true); |
| + image()->SetPaintToLayer(true); |
| + image()->SetFillsBoundsOpaquely(false); |
| + |
| + layer()->Add(ink_drop_layer); |
| + layer()->StackAtBottom(ink_drop_layer); |
| +} |
| + |
| +void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| + layer()->Remove(ink_drop_layer); |
| + |
| + image()->SetFillsBoundsOpaquely(true); |
| + image()->SetPaintToLayer(false); |
| + SetPaintToLayer(false); |
| +} |
| + |
| +gfx::Point ToolbarActionView::CalculateInkDropCenter() const { |
| + return GetLocalBounds().CenterPoint(); |
| +} |
| + |
| gfx::Size ToolbarActionView::GetPreferredSize() const { |
| return gfx::Size(ToolbarActionsBar::IconWidth(false), |
| ToolbarActionsBar::IconHeight()); |
| } |
| +void ToolbarActionView::Layout() { |
| + MenuButton::Layout(); |
| + ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); |
| +} |
| + |
| +bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) { |
| + // views::MenuButton actions are only triggered by left mouse clicks. |
| + if (event.IsLeftMouseButton()) { |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::ACTION_PENDING); |
| + } |
| + return MenuButton::OnMousePressed(event); |
| +} |
| + |
| +void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) { |
| + if (menu_showing_) { |
| + // While dropdown menu is showing the button should not handle gestures. |
| + event->StopPropagation(); |
| + return; |
| + } |
| + |
| + MenuButton::OnGestureEvent(event); |
| + |
| + views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; |
| + switch (event->type()) { |
| + case ui::ET_GESTURE_TAP_DOWN: |
| + ink_drop_state = views::InkDropState::ACTION_PENDING; |
| + // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so that |
| + // subsequent events for the gesture are sent to |this|. |
| + event->SetHandled(); |
| + break; |
| + case ui::ET_GESTURE_LONG_PRESS: |
| + ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; |
| + break; |
| + case ui::ET_GESTURE_TAP: |
|
bruthig
2015/10/20 17:42:30
It might not be necessary to animate to the QUICK_
varkha
2015/10/20 20:37:44
Done.
|
| + ink_drop_state = views::InkDropState::QUICK_ACTION; |
| + break; |
| + case ui::ET_GESTURE_LONG_TAP: |
| + ink_drop_state = views::InkDropState::SLOW_ACTION; |
| + break; |
| + case ui::ET_GESTURE_END: |
| + case ui::ET_GESTURE_TAP_CANCEL: |
| + ink_drop_state = views::InkDropState::HIDDEN; |
| + break; |
| + default: |
| + return; |
| + } |
| + ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| +} |
| + |
| void ToolbarActionView::OnDragDone() { |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| views::MenuButton::OnDragDone(); |
| delegate_->OnToolbarActionViewDragDone(); |
| } |
| @@ -127,10 +216,16 @@ void ToolbarActionView::OnMenuButtonClicked(views::View* sender, |
| context_menu_controller()->ShowContextMenuForView(this, point, |
| ui::MENU_SOURCE_NONE); |
| } else { |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::QUICK_ACTION); |
| view_controller_->ExecuteAction(true); |
| } |
| } |
| +void ToolbarActionView::OnMenuButtonReleasedWithoutClick(views::View* sender) { |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| +} |
| + |
| void ToolbarActionView::UpdateState() { |
| content::WebContents* web_contents = GetCurrentWebContents(); |
| if (SessionTabHelper::IdForTab(web_contents) < 0) |
| @@ -285,8 +380,11 @@ void ToolbarActionView::DoShowContextMenu( |
| delegate_->GetOverflowReferenceView()->GetWidget() : |
| GetWidget(); |
| - menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); |
| + menu_showing_ = true; |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::ACTIVATED); |
| + menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); |
| if (menu_runner_->RunMenuAt(parent, |
| this, |
| gfx::Rect(screen_loc, size()), |
| @@ -294,6 +392,9 @@ void ToolbarActionView::DoShowContextMenu( |
| source_type) == views::MenuRunner::MENU_DELETED) { |
| return; |
| } |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::DEACTIVATED); |
| + menu_showing_ = false; |
| context_menu_owner = nullptr; |
| menu_runner_.reset(); |