Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4909)

Unified Diff: chrome/browser/ui/views/toolbar/toolbar_action_view.cc

Issue 1409183003: Adds ripple animation to extension buttons on a toolbar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds ripple animation to extension buttons on a toolbar (rebased) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.h ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2843f70437ac9c56e74b22e35113a71b86e3fd36..f2e5a4232ff539e9e490e82a63f8a2526326ddb5 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_action_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_action_view.cc
@@ -26,6 +26,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_model_adapter.h"
@@ -66,6 +68,9 @@ ToolbarActionView::ToolbarActionView(
called_register_command_(false),
wants_to_run_(false),
menu_(nullptr),
+ ink_drop_animation_controller_(
+ views::InkDropAnimationControllerFactory::
+ CreateInkDropAnimationController(this)),
weak_factory_(this) {
set_id(VIEW_ID_BROWSER_ACTION);
view_controller_->SetDelegate(this);
@@ -74,6 +79,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(
@@ -99,12 +115,96 @@ ToolbarActionView::~ToolbarActionView() {
view_controller_->SetDelegate(nullptr);
}
+void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
tdanderson 2015/11/18 16:08:21 Note that you should change this implementation to
varkha 2015/11/18 18:58:05 Done. Thanks for watching this!
+ 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) {
+ // TODO(varkha): refactor similar implementations in ToolbarButton,
+ // FindBarButton and here.
+ if (menu_) {
+ // 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_LONG_TAP:
+ ink_drop_state = views::InkDropState::SLOW_ACTION;
+ break;
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ case ui::ET_GESTURE_END:
+ ink_drop_state = views::InkDropState::HIDDEN;
+ break;
+ default:
+ return;
+ }
+
+ views::InkDropState current_ink_drop_state =
+ ink_drop_animation_controller_->GetInkDropState();
+
+ if (ink_drop_state == views::InkDropState::HIDDEN &&
+ (current_ink_drop_state == views::InkDropState::QUICK_ACTION ||
+ current_ink_drop_state == views::InkDropState::SLOW_ACTION ||
+ current_ink_drop_state == views::InkDropState::DEACTIVATED)) {
+ // These InkDropStates automatically transition to the HIDDEN state so we
+ // don't make an explicit call. Explicitly animating to HIDDEN in this case
+ // would prematurely pre-empt these animations.
+ 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();
}
@@ -133,10 +233,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)
@@ -295,6 +401,9 @@ void ToolbarActionView::DoShowContextMenu(
delegate_->GetOverflowReferenceView()->GetWidget() :
GetWidget();
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTIVATED);
+
views::MenuModelAdapter adapter(context_menu_model);
menu_ = adapter.CreateMenu();
menu_runner_.reset(new views::MenuRunner(menu_, run_types));
@@ -304,8 +413,11 @@ void ToolbarActionView::DoShowContextMenu(
if (menu_runner_->RunMenuAt(parent, this, gfx::Rect(screen_loc, size()),
views::MENU_ANCHOR_TOPLEFT,
source_type) == views::MenuRunner::MENU_DELETED) {
+ menu_ = nullptr;
return;
}
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::DEACTIVATED);
menu_runner_.reset();
menu_ = nullptr;
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.h ('k') | ui/views/controls/button/menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698