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

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

Issue 1298513003: Implemented prototype for new ink drop specs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed concerns from patch set 7. Created 5 years, 3 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 835ccf2aa79112641295f60337ad902f7a8b45f1..5f90eb3b3df04f29f48c009188f2a635c85db140 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_button.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_button.cc
@@ -79,7 +79,19 @@ gfx::Size ToolbarButton::GetPreferredSize() const {
void ToolbarButton::Layout() {
LabelButton::Layout();
- LayoutInkDrop();
+
+ // Sizes for the the ink drop.
+ 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);
+ ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter());
}
bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
@@ -99,8 +111,11 @@ bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
base::TimeDelta::FromMilliseconds(kMenuTimerDelay));
}
- ink_drop_animation_controller_->AnimateToState(
- views::InkDropState::ACTION_PENDING);
+ // views::Button actions are only triggered by left and middle mouse clicks.
+ if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) {
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTION_PENDING);
+ }
return LabelButton::OnMousePressed(event);
}
@@ -162,11 +177,14 @@ void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) {
event->SetHandled();
break;
case ui::ET_GESTURE_LONG_PRESS:
- ink_drop_state = views::InkDropState::SLOW_ACTION;
+ ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING;
break;
case ui::ET_GESTURE_TAP:
ink_drop_state = views::InkDropState::QUICK_ACTION;
break;
+ case ui::ET_GESTURE_LONG_TAP:
+ ink_drop_state = views::InkDropState::SLOW_ACTION;
+ break;
case ui::ET_GESTURE_END:
case ui::ET_GESTURE_TAP_CANCEL:
ink_drop_state = views::InkDropState::HIDDEN;
@@ -237,7 +255,7 @@ bool ToolbarButton::ShouldEnterPushedState(const ui::Event& event) {
}
bool ToolbarButton::ShouldShowMenu() {
- return model_ != NULL;
+ return model_ != nullptr;
}
void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
@@ -282,51 +300,57 @@ void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
menu_showing_ = true;
+ views::MenuRunner::RunResult result = views::MenuRunner::MENU_DELETED;
Peter Kasting 2015/09/09 22:50:46 Nit: For clarity, I'd move this line to be between
bruthig 2015/09/10 14:57:38 Done.
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::ACTIVATED);
+
// Create and run menu. Display an empty menu if model is NULL.
if (model_.get()) {
views::MenuModelAdapter menu_delegate(model_.get());
menu_delegate.set_triggerable_event_flags(triggerable_event_flags());
menu_runner_.reset(new views::MenuRunner(menu_delegate.CreateMenu(),
views::MenuRunner::HAS_MNEMONICS));
- views::MenuRunner::RunResult result =
- menu_runner_->RunMenuAt(GetWidget(),
- NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- views::MENU_ANCHOR_TOPLEFT,
- source_type);
- if (result == views::MenuRunner::MENU_DELETED)
- return;
+ result = menu_runner_->RunMenuAt(GetWidget(), nullptr,
+ gfx::Rect(menu_position, gfx::Size(0, 0)),
+ views::MENU_ANCHOR_TOPLEFT, source_type);
} else {
views::MenuDelegate menu_delegate;
views::MenuItemView* menu = new views::MenuItemView(&menu_delegate);
menu_runner_.reset(
new views::MenuRunner(menu, views::MenuRunner::HAS_MNEMONICS));
- views::MenuRunner::RunResult result =
- menu_runner_->RunMenuAt(GetWidget(),
- NULL,
- gfx::Rect(menu_position, gfx::Size(0, 0)),
- views::MENU_ANCHOR_TOPLEFT,
- source_type);
- if (result == views::MenuRunner::MENU_DELETED)
- return;
+ result = menu_runner_->RunMenuAt(GetWidget(), nullptr,
+ gfx::Rect(menu_position, gfx::Size(0, 0)),
+ views::MENU_ANCHOR_TOPLEFT, source_type);
}
- ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
+ // RunMenuAt() will return MENU_DELETED if the |menu_runner_| was destroyed as
+ // a result of the ToolbarButton's destructor being called.
Peter Kasting 2015/09/09 22:50:46 Nit: You probably don't need this as this ought to
bruthig 2015/09/10 14:57:38 Done.
+ if (result == views::MenuRunner::MENU_DELETED)
+ return;
+
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::DEACTIVATED);
menu_showing_ = false;
// Need to explicitly clear mouse handler so that events get sent
// properly after the menu finishes running. If we don't do this, then
// the first click to other parts of the UI is eaten.
- SetMouseHandler(NULL);
+ SetMouseHandler(nullptr);
// Set the state back to normal after the drop down menu is closed.
if (state_ != STATE_DISABLED)
SetState(STATE_NORMAL);
}
-void ToolbarButton::LayoutInkDrop() {
- ink_drop_animation_controller_->SetInkDropSize(size());
+gfx::Point ToolbarButton::CalculateInkDropCenter() const {
+ return gfx::Point(width() / 2, height() / 2);
Peter Kasting 2015/09/09 22:50:46 Nit: Or just: return GetLocalBounds().CenterPoi
bruthig 2015/09/10 14:57:38 Done.
+}
+
+void ToolbarButton::NotifyClick(const ui::Event& event) {
+ LabelButton::NotifyClick(event);
+ ink_drop_animation_controller_->AnimateToState(
+ views::InkDropState::QUICK_ACTION);
}
const char* ToolbarButton::GetClassName() const {

Powered by Google App Engine
This is Rietveld 408576698