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

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 (comments in c/b/ui/views/) 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..5a6ee0979c818d05945c41deb23f3ef96472efc5 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,29 +109,27 @@ ToolbarActionView::~ToolbarActionView() {
view_controller_->SetDelegate(nullptr);
}
-gfx::Size ToolbarActionView::GetPreferredSize() const {
- return gfx::Size(ToolbarActionsBar::IconWidth(false),
- ToolbarActionsBar::IconHeight());
+void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) {
+ views::MenuButton::GetAccessibleState(state);
+ state->role = ui::AX_ROLE_BUTTON;
}
-void ToolbarActionView::OnDragDone() {
- views::MenuButton::OnDragDone();
- delegate_->OnToolbarActionViewDragDone();
+scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const {
+ scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder();
+ border->set_insets(gfx::Insets(kBorderInset, kBorderInset,
+ kBorderInset, kBorderInset));
+ return border.Pass();
}
-void ToolbarActionView::ViewHierarchyChanged(
- const ViewHierarchyChangedDetails& details) {
- if (details.is_add && !called_register_command_ && GetFocusManager()) {
- view_controller_->RegisterCommand();
- called_register_command_ = true;
- }
-
- MenuButton::ViewHierarchyChanged(details);
+void ToolbarActionView::OnMouseEntered(const ui::MouseEvent& event) {
+ delegate_->OnMouseEnteredToolbarActionView();
+ views::MenuButton::OnMouseEntered(event);
}
-void ToolbarActionView::GetAccessibleState(ui::AXViewState* state) {
- views::MenuButton::GetAccessibleState(state);
- state->role = ui::AX_ROLE_BUTTON;
+bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) {
+ return views::MenuButton::ShouldEnterPushedState(event) &&
+ (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() >
+ views::kMinimumMsBetweenButtonClicks;
}
void ToolbarActionView::OnMenuButtonClicked(views::View* sender,
@@ -137,6 +145,17 @@ void ToolbarActionView::OnMenuButtonClicked(views::View* sender,
}
}
+void ToolbarActionView::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
+ UpdateState();
+}
+
+content::WebContents* ToolbarActionView::GetCurrentWebContents() const {
+ return delegate_->GetCurrentWebContents();
+}
+
void ToolbarActionView::UpdateState() {
content::WebContents* web_contents = GetCurrentWebContents();
if (SessionTabHelper::IdForTab(web_contents) < 0)
@@ -170,29 +189,22 @@ void ToolbarActionView::UpdateState() {
SchedulePaint();
}
-void ToolbarActionView::Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
- UpdateState();
-}
+void ToolbarActionView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
+ SetPaintToLayer(true);
+ SetFillsBoundsOpaquely(false);
+ image()->SetPaintToLayer(true);
+ image()->SetFillsBoundsOpaquely(false);
-void ToolbarActionView::OnMouseEntered(const ui::MouseEvent& event) {
- delegate_->OnMouseEnteredToolbarActionView();
- views::MenuButton::OnMouseEntered(event);
+ layer()->Add(ink_drop_layer);
+ layer()->StackAtBottom(ink_drop_layer);
}
-bool ToolbarActionView::ShouldEnterPushedState(const ui::Event& event) {
- return views::MenuButton::ShouldEnterPushedState(event) &&
- (base::TimeTicks::Now() - popup_closed_time_).InMilliseconds() >
- views::kMinimumMsBetweenButtonClicks;
-}
+void ToolbarActionView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
+ layer()->Remove(ink_drop_layer);
-scoped_ptr<LabelButtonBorder> ToolbarActionView::CreateDefaultBorder() const {
- scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder();
- border->set_insets(gfx::Insets(kBorderInset, kBorderInset,
- kBorderInset, kBorderInset));
- return border.Pass();
+ image()->SetFillsBoundsOpaquely(true);
+ image()->SetPaintToLayer(false);
+ SetPaintToLayer(false);
}
gfx::ImageSkia ToolbarActionView::GetIconForTest() {
@@ -204,6 +216,45 @@ void ToolbarActionView::set_context_menu_callback_for_testing(
context_menu_callback = callback;
}
+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) {
+ // While dropdown menu is showing the button should not handle gestures.
Peter Kasting 2015/11/24 22:27:16 Nit: Add "the" before "dropdown" and comma after "
varkha 2015/11/25 18:53:23 Done.
+ if (menu_)
+ event->StopPropagation();
+ else
+ MenuButton::OnGestureEvent(event);
+}
+
+void ToolbarActionView::OnDragDone() {
+ views::MenuButton::OnDragDone();
+ delegate_->OnToolbarActionViewDragDone();
+}
+
+void ToolbarActionView::ViewHierarchyChanged(
+ const ViewHierarchyChangedDetails& details) {
+ if (details.is_add && !called_register_command_ && GetFocusManager()) {
+ view_controller_->RegisterCommand();
+ called_register_command_ = true;
+ }
+
+ MenuButton::ViewHierarchyChanged(details);
+}
+
+views::InkDropDelegate* ToolbarActionView::GetInkDropDelegate() const {
+ return ink_drop_delegate_.get();
+}
+
views::View* ToolbarActionView::GetAsView() {
return this;
}
@@ -223,10 +274,6 @@ bool ToolbarActionView::IsMenuRunning() const {
return menu_ != nullptr;
}
-content::WebContents* ToolbarActionView::GetCurrentWebContents() const {
- return delegate_->GetCurrentWebContents();
-}
-
void ToolbarActionView::OnPopupShown(bool by_user) {
// If this was through direct user action, we press the menu button.
if (by_user) {
@@ -271,6 +318,10 @@ void ToolbarActionView::ShowContextMenuForView(
DoShowContextMenu(source_type);
}
+gfx::Point ToolbarActionView::CalculateInkDropCenter() const {
+ return GetLocalBounds().CenterPoint();
+}
+
void ToolbarActionView::DoShowContextMenu(
ui::MenuSourceType source_type) {
ui::MenuModel* context_menu_model = view_controller_->GetContextMenu();
@@ -295,6 +346,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));
@@ -306,6 +359,7 @@ void ToolbarActionView::DoShowContextMenu(
source_type) == views::MenuRunner::MENU_DELETED) {
return;
}
+ GetInkDropDelegate()->OnAction(views::InkDropState::DEACTIVATED);
menu_runner_.reset();
menu_ = nullptr;

Powered by Google App Engine
This is Rietveld 408576698