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

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

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (Moving more generic functionality into ScopedTargetHandler) 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
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..15829ca7085279e63ecc5ee3e4afb7beb9835929 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_action_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_action_view.cc
@@ -26,6 +26,7 @@
#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/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_model_adapter.h"
@@ -66,6 +67,7 @@ ToolbarActionView::ToolbarActionView(
called_register_command_(false),
wants_to_run_(false),
menu_(nullptr),
+ ink_drop_delegate_(new views::ToolbarInkDropDelegate(this, this)),
weak_factory_(this) {
set_id(VIEW_ID_BROWSER_ACTION);
view_controller_->SetDelegate(this);
@@ -74,6 +76,14 @@ ToolbarActionView::ToolbarActionView(
set_context_menu_controller(this);
+ const int kInkDropLargeSize = 32;
+ const int kInkDropLargeCornerRadius = 5;
+ const int kInkDropSmallSize = 24;
+ const int kInkDropSmallCornerRadius = 2;
+ GetInkDropDelegate()->SetInkDropSize(
+ kInkDropLargeSize, kInkDropLargeCornerRadius, 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,11 +109,53 @@ ToolbarActionView::~ToolbarActionView() {
view_controller_->SetDelegate(nullptr);
}
+void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
bruthig 2015/11/23 15:04:02 nit: I think there should either be a mirror call
varkha 2015/11/23 15:14:13 Is same true for changes in https://codereview.chr
tdanderson 2015/11/23 15:38:05 AFICT the call is not needed since the separate la
varkha 2015/11/23 16:06:48 Acknowledged.
+ 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());
}
+bool ToolbarActionView::OnMousePressed(const ui::MouseEvent& event) {
+ // views::MenuButton actions are only triggered by left mouse clicks.
+ if (event.IsOnlyLeftMouseButton())
+ GetInkDropDelegate()->OnAction(views::InkDropState::ACTION_PENDING);
+ return MenuButton::OnMousePressed(event);
+}
+
+void ToolbarActionView::OnGestureEvent(ui::GestureEvent* event) {
+ if (menu_) {
+ // While dropdown menu is showing the button should not handle gestures.
+ event->StopPropagation();
+ return;
+ }
+ MenuButton::OnGestureEvent(event);
+}
+
void ToolbarActionView::OnDragDone() {
views::MenuButton::OnDragDone();
delegate_->OnToolbarActionViewDragDone();
@@ -295,6 +347,8 @@ void ToolbarActionView::DoShowContextMenu(
delegate_->GetOverflowReferenceView()->GetWidget() :
GetWidget();
+ GetInkDropDelegate()->OnAction(views::InkDropState::ACTIVATED);
+
views::MenuModelAdapter adapter(context_menu_model);
menu_ = adapter.CreateMenu();
menu_runner_.reset(new views::MenuRunner(menu_, run_types));
@@ -304,8 +358,10 @@ 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;
}
+ GetInkDropDelegate()->OnAction(views::InkDropState::DEACTIVATED);
menu_runner_.reset();
menu_ = nullptr;
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view.h ('k') | chrome/browser/ui/views/toolbar/toolbar_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698