Chromium Code Reviews| 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 45e429b658cf89c1f67c7609cd6fd1629cc0b303..ced73c960f3f4423bfe620f0f29c8ce1c0aebf81 100644 |
| --- a/chrome/browser/ui/views/toolbar/toolbar_button.cc |
| +++ b/chrome/browser/ui/views/toolbar/toolbar_button.cc |
| @@ -19,6 +19,7 @@ |
| #include "ui/gfx/screen.h" |
| #include "ui/strings/grit/ui_strings.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_item_view.h" |
| #include "ui/views/controls/menu/menu_model_adapter.h" |
| @@ -32,18 +33,21 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener, |
| menu_showing_(false), |
| y_position_on_lbuttondown_(0), |
| show_menu_factory_(this) { |
| -#if defined(OS_CHROMEOS) |
| - // 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()) { |
| - ink_drop_animation_controller_.reset( |
| - new views::InkDropAnimationController(this)); |
| - layer()->SetFillsBoundsOpaquely(false); |
| + SetPaintToLayer(true); |
|
sadrul
2015/08/17 14:33:06
Is this only so you can add the ink-drop layers? C
bruthig
2015/08/17 17:43:39
Yes. I'm not sure how else to do it without creat
|
| image()->SetPaintToLayer(true); |
| image()->SetFillsBoundsOpaquely(false); |
| } |
| -#endif // defined(OS_CHROMEOS) |
| - |
| + // TODO(bruthig): |ink_drop_animation_controller_| has to be initialized after |
| + // SetPaintToLayer(true) becuase the InkDropAnimationControllerImpl |
| + // constructor calls back in to AddInkDropLayer() to add the ink drop layer to |
| + // layer(). This will be reworked so the InkDropAnimationController will call |
| + // AddInkDropLayer() right before the ink drop becomes visible and then |
| + // |ink_drop_animation_controller_| can be initialized in the initializer |
| + // list. |
| + |
| + ink_drop_animation_controller_ = views::InkDropAnimationControllerFactory:: |
| + CreateInkDropAnimationController(this); |
| set_context_menu_controller(this); |
| } |
| @@ -86,6 +90,11 @@ gfx::Size ToolbarButton::GetPreferredSize() const { |
| return size; |
| } |
| +void ToolbarButton::Layout() { |
| + LabelButton::Layout(); |
| + LayoutInkDrop(); |
| +} |
| + |
| bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| if (enabled() && ShouldShowMenu() && |
| IsTriggerableEvent(event) && HitTestPoint(event.location())) { |
| @@ -102,6 +111,10 @@ bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { |
| ui::GetMenuSourceTypeForEvent(event)), |
| base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); |
| } |
| + |
| + ink_drop_animation_controller_->AnimateToState( |
| + views::InkDropState::ACTION_PENDING); |
| + |
| return LabelButton::OnMousePressed(event); |
| } |
| @@ -129,6 +142,8 @@ void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| if (IsTriggerableEvent(event)) |
| show_menu_factory_.InvalidateWeakPtrs(); |
| + |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| } |
| void ToolbarButton::OnMouseCaptureLost() { |
| @@ -150,6 +165,29 @@ void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
| } |
| LabelButton::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; |
| + break; |
| + case ui::ET_GESTURE_TAP: |
| + ink_drop_state = views::InkDropState::QUICK_ACTION; |
| + break; |
| + case ui::ET_GESTURE_END: |
| + case ui::ET_GESTURE_TAP_CANCEL: |
| + ink_drop_state = views::InkDropState::HIDDEN; |
| + break; |
| + default: |
| + return; |
| + } |
| + ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| } |
| void ToolbarButton::GetAccessibleState(ui::AXViewState* state) { |
| @@ -185,6 +223,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); |
| +} |
| + |
| 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. |
| @@ -269,6 +316,8 @@ void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) { |
| return; |
| } |
| + ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| + |
| menu_showing_ = false; |
| // Need to explicitly clear mouse handler so that events get sent |
| @@ -281,6 +330,10 @@ void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) { |
| SetState(STATE_NORMAL); |
| } |
| +void ToolbarButton::LayoutInkDrop() { |
| + ink_drop_animation_controller_->SetInkDropSize(size()); |
| +} |
| + |
| const char* ToolbarButton::GetClassName() const { |
| return "ToolbarButton"; |
| } |