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

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

Issue 1280953003: Enhance the material design ripple API so the ripple's state can be controlled by it's owning View. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed some comments from patch set 1. Created 5 years, 4 months 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_button.cc
diff --git a/chrome/browser/ui/views/toolbar/toolbar_button.cc b/chrome/browser/ui/views/toolbar/toolbar_button.cc
index 1c85d9a85d1f6753d74424d2fcfdd05a60ad7fa2..0c6d51254f78083f9feb15543542c366312fd9ae 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_button.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_button.cc
@@ -36,6 +36,7 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener,
// The ink drop animation is only targeted at ChromeOS because there is
// concern it will conflict with OS level touch feedback in a bad way.
if (ui::MaterialDesignController::IsModeMaterial()) {
+ SetPaintToLayer(true);
ink_drop_animation_controller_.reset(
new views::InkDropAnimationController(this));
layer()->SetFillsBoundsOpaquely(false);
@@ -86,6 +87,12 @@ gfx::Size ToolbarButton::GetPreferredSize() const {
return size;
}
+void ToolbarButton::Layout() {
+ LabelButton::Layout();
+ if (ui::MaterialDesignController::IsModeMaterial())
+ LayoutInkDrop();
+}
+
bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
if (enabled() && ShouldShowMenu() &&
IsTriggerableEvent(event) && HitTestPoint(event.location())) {
@@ -102,6 +109,11 @@ bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
ui::GetMenuSourceTypeForEvent(event)),
base::TimeDelta::FromMilliseconds(kMenuTimerDelay));
}
+
+ if (ui::MaterialDesignController::IsModeMaterial())
tdanderson 2015/08/10 16:31:01 nit: use {} since body is more than one line.
bruthig 2015/08/10 21:57:15 Done.
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTION_PENDING);
+
return LabelButton::OnMousePressed(event);
}
@@ -129,6 +141,9 @@ void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) {
if (IsTriggerableEvent(event))
show_menu_factory_.InvalidateWeakPtrs();
+
+ if (ui::MaterialDesignController::IsModeMaterial())
tdanderson 2015/08/10 16:31:01 What do you think of containing all of the IsModeM
bruthig 2015/08/10 21:57:15 I've implemented this with a factory, take a look
+ ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
}
void ToolbarButton::OnMouseCaptureLost() {
@@ -149,6 +164,31 @@ void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) {
return;
}
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ switch (event->type()) {
+ case ui::ET_GESTURE_TAP_DOWN:
+ ink_drop_animation_controller_->AnimateToState(
tdanderson 2015/08/10 16:31:01 [I think this is a repeat of one of Jon's question
bruthig 2015/08/10 21:57:15 Yes I can imagine that it would be very useful for
+ views::InkDropState::ACTION_PENDING);
+ event->SetHandled();
+ break;
+ case ui::ET_GESTURE_LONG_PRESS:
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::SLOW_ACTION);
+ break;
+ case ui::ET_GESTURE_TAP:
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::QUICK_ACTION);
+ break;
+ case ui::ET_GESTURE_END:
+ case ui::ET_GESTURE_TAP_CANCEL:
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::HIDDEN);
+ break;
+ default:
+ break;
+ }
+ }
+
LabelButton::OnGestureEvent(event);
}
@@ -201,6 +241,15 @@ void ToolbarButton::ShowContextMenuForView(View* source,
ShowDropDownMenu(source_type);
}
+void ToolbarButton::AddInkDropLayer(ui::Layer* ink_drop_layer) {
+ layer()->Add(ink_drop_layer);
+ layer()->StackAtBottom(ink_drop_layer);
+}
+
+void ToolbarButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
+ layer()->Remove(ink_drop_layer);
tdanderson 2015/08/10 16:31:01 How will the implementations of AddInkDropLayer()
bruthig 2015/08/10 21:57:15 The most important thing that I can see changing b
tdanderson 2015/08/11 12:57:36 OK, sounds good to leave as is and have it evolve
+}
+
bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) {
// Enter PUSHED state on press with Left or Right mouse button or on taps.
// Remain in this state while the context menu is open.
@@ -285,6 +334,9 @@ void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
return;
}
+ if (ui::MaterialDesignController::IsModeMaterial())
+ ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
+
menu_showing_ = false;
// Need to explicitly clear mouse handler so that events get sent
@@ -297,6 +349,10 @@ void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
SetState(STATE_NORMAL);
}
+void ToolbarButton::LayoutInkDrop() {
+ ink_drop_animation_controller_->SetSize(gfx::Size(width(), height()));
+}
+
const char* ToolbarButton::GetClassName() const {
return "ToolbarButton";
}

Powered by Google App Engine
This is Rietveld 408576698