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..98d5b3950a8e7b7e4ab82ed3f328d681d65ae18f 100644 |
--- a/chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
+++ b/chrome/browser/ui/views/toolbar/toolbar_action_view.cc |
@@ -25,6 +25,9 @@ |
#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/animation/toolbar_ink_drop_delegate.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 +63,12 @@ ToolbarActionView::ToolbarActionView( |
delegate_(delegate), |
called_register_command_(false), |
wants_to_run_(false), |
+ menu_showing_(false), |
+ ink_drop_animation_controller_( |
+ views::InkDropAnimationControllerFactory:: |
+ CreateInkDropAnimationController(this)), |
+ ink_drop_delegate_(new views::ToolbarInkDropDelegate( |
+ ink_drop_animation_controller_.get())), |
weak_factory_(this) { |
set_id(VIEW_ID_BROWSER_ACTION); |
view_controller_->SetDelegate(this); |
@@ -68,6 +77,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 +113,64 @@ 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(); |
+} |
+ |
+views::InkDropDelegate* ToolbarActionView::GetInkDropDelegate() const { |
+ return ink_drop_delegate_.get(); |
+} |
+ |
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) { |
bruthig
2015/11/06 20:29:10
Is this an example of how the View can override an
varkha
2015/11/06 20:51:50
No, this is same as in "parent" CL (I know, I shou
|
+ // 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) { |
+ // TODO(varkha): refactor similar implementations in ToolbarButton, |
+ // FindBarButton and here. |
+ if (menu_showing_) { |
bruthig
2015/11/06 20:29:10
Is this View state logic currently captured in the
varkha
2015/11/06 20:51:50
Not sure I follow you on this one. In this code pa
bruthig
2015/11/09 16:51:22
My mistake, I was thinking of OnGestureEvent() as
|
+ // While dropdown menu is showing the button should not handle gestures. |
+ event->StopPropagation(); |
+ return; |
+ } |
+ |
+ MenuButton::OnGestureEvent(event); |
+} |
+ |
void ToolbarActionView::OnDragDone() { |
+ ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
views::MenuButton::OnDragDone(); |
delegate_->OnToolbarActionViewDragDone(); |
} |
@@ -127,10 +199,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::OnMenuButtonClickCanceled(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 +363,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 +375,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(); |