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..e7c7c097e340653d65d9622053083459471b0e02 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,9 @@ ToolbarActionView::ToolbarActionView( |
| delegate_(delegate), |
| called_register_command_(false), |
| wants_to_run_(false), |
| + ink_drop_animation_controller_( |
| + views::InkDropAnimationControllerFactory:: |
| + CreateInkDropAnimationController(this)), |
| weak_factory_(this) { |
| set_id(VIEW_ID_BROWSER_ACTION); |
| view_controller_->SetDelegate(this); |
| @@ -68,6 +73,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 +109,53 @@ 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::Button actions are only triggered by left and middle mouse clicks. |
| + if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { |
|
bruthig
2015/10/19 19:29:15
Does Middle mouse button actually trigger any acti
varkha
2015/10/20 15:23:04
It seems MenuButtons only trigger actions on left
|
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::ACTION_PENDING); |
| + } |
| + return MenuButton::OnMousePressed(event); |
| +} |
| + |
| +void ToolbarActionView::OnMouseReleased(const ui::MouseEvent& event) { |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
|
bruthig
2015/10/19 19:29:15
You might need to guard this with "if (!HitTestPoi
varkha
2015/10/20 15:23:04
I've wired this with a help of MenuButtonListener:
|
| + MenuButton::OnMouseReleased(event); |
| +} |
| + |
| void ToolbarActionView::OnDragDone() { |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| views::MenuButton::OnDragDone(); |
| delegate_->OnToolbarActionViewDragDone(); |
| } |
| @@ -127,6 +184,8 @@ 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); |
| } |
| } |
| @@ -285,8 +344,10 @@ void ToolbarActionView::DoShowContextMenu( |
| delegate_->GetOverflowReferenceView()->GetWidget() : |
| GetWidget(); |
| - menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); |
| + 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 +355,8 @@ void ToolbarActionView::DoShowContextMenu( |
| source_type) == views::MenuRunner::MENU_DELETED) { |
| return; |
| } |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::DEACTIVATED); |
| context_menu_owner = nullptr; |
| menu_runner_.reset(); |