Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/bar_control_button.h" | 5 #include "chrome/browser/ui/views/bar_control_button.h" |
| 6 | 6 |
| 7 #include "ui/gfx/color_utils.h" | 7 #include "ui/gfx/color_utils.h" |
| 8 #include "ui/gfx/paint_vector_icon.h" | 8 #include "ui/gfx/paint_vector_icon.h" |
| 9 #include "ui/gfx/vector_icons_public.h" | 9 #include "ui/gfx/vector_icons_public.h" |
| 10 #include "ui/views/animation/ink_drop_animation_controller.h" | 10 #include "ui/views/animation/button_ink_drop_delegate.h" |
| 11 #include "ui/views/animation/ink_drop_animation_controller_factory.h" | |
| 12 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 // Extra space around the buttons to increase their event target size. | 15 // Extra space around the buttons to increase their event target size. |
| 17 const int kButtonExtraTouchSize = 4; | 16 const int kButtonExtraTouchSize = 4; |
| 18 | 17 |
| 19 } // namespace | 18 } // namespace |
| 20 | 19 |
| 21 BarControlButton::BarControlButton(views::ButtonListener* listener) | 20 BarControlButton::BarControlButton(views::ButtonListener* listener) |
| 22 : views::ImageButton(listener), | 21 : views::ImageButton(listener), id_(gfx::VectorIconId::VECTOR_ICON_NONE) { |
| 23 id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 22 scoped_ptr<views::InkDropDelegate> new_ink_drop_delegate( |
| 24 ink_drop_animation_controller_( | 23 new views::ButtonInkDropDelegate(this, this)); |
| 25 views::InkDropAnimationControllerFactory:: | 24 SetInkDropDelegate(new_ink_drop_delegate.Pass()); |
| 26 CreateInkDropAnimationController(this)) { | 25 |
| 27 const int kInkDropLargeSize = 32; | 26 const int kInkDropLargeSize = 32; |
| 28 const int kInkDropLargeCornerRadius = 4; | 27 const int kInkDropLargeCornerRadius = 4; |
| 29 const int kInkDropSmallSize = 24; | 28 const int kInkDropSmallSize = 24; |
| 30 const int kInkDropSmallCornerRadius = 2; | 29 const int kInkDropSmallCornerRadius = 2; |
| 31 ink_drop_animation_controller_->SetInkDropSize( | 30 ink_drop_delegate()->SetInkDropSize( |
| 32 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), | 31 kInkDropLargeSize, kInkDropLargeCornerRadius, kInkDropSmallSize, |
| 33 kInkDropLargeCornerRadius, | |
| 34 gfx::Size(kInkDropSmallSize, kInkDropSmallSize), | |
| 35 kInkDropSmallCornerRadius); | 32 kInkDropSmallCornerRadius); |
| 36 } | 33 } |
| 37 | 34 |
| 38 BarControlButton::~BarControlButton() {} | 35 BarControlButton::~BarControlButton() {} |
| 39 | 36 |
| 40 void BarControlButton::SetIcon( | 37 void BarControlButton::SetIcon( |
| 41 gfx::VectorIconId id, | 38 gfx::VectorIconId id, |
| 42 const base::Callback<SkColor(void)>& get_text_color_callback) { | 39 const base::Callback<SkColor(void)>& get_text_color_callback) { |
| 43 id_ = id; | 40 id_ = id; |
| 44 get_text_color_callback_ = get_text_color_callback; | 41 get_text_color_callback_ = get_text_color_callback; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 56 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); | 53 gfx::ImageSkia image = gfx::CreateVectorIcon(id_, 16, icon_color); |
| 57 SetImage(views::CustomButton::STATE_NORMAL, &image); | 54 SetImage(views::CustomButton::STATE_NORMAL, &image); |
| 58 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); | 55 image = gfx::CreateVectorIcon(id_, 16, SkColorSetA(icon_color, 0xff / 2)); |
| 59 SetImage(views::CustomButton::STATE_DISABLED, &image); | 56 SetImage(views::CustomButton::STATE_DISABLED, &image); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 59 void BarControlButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 63 OnThemeChanged(); | 60 OnThemeChanged(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 void BarControlButton::Layout() { | |
| 67 ImageButton::Layout(); | |
| 68 | |
| 69 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); | |
| 70 } | |
| 71 | |
| 72 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 63 void BarControlButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 73 // TODO(estade|tdanderson): The ink drop layer should be positioned behind | 64 // TODO(estade|tdanderson): The ink drop layer should be positioned behind |
| 74 // the button's image. | 65 // the button's image. |
| 75 SetPaintToLayer(true); | 66 SetPaintToLayer(true); |
| 76 SetFillsBoundsOpaquely(false); | 67 SetFillsBoundsOpaquely(false); |
| 77 layer()->Add(ink_drop_layer); | 68 layer()->Add(ink_drop_layer); |
| 78 layer()->StackAtBottom(ink_drop_layer); | 69 layer()->StackAtBottom(ink_drop_layer); |
| 79 } | 70 } |
| 80 | 71 |
| 81 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 72 void BarControlButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 82 layer()->Remove(ink_drop_layer); | 73 layer()->Remove(ink_drop_layer); |
| 83 SetFillsBoundsOpaquely(true); | 74 SetFillsBoundsOpaquely(true); |
| 84 SetPaintToLayer(false); | 75 SetPaintToLayer(false); |
| 85 } | 76 } |
| 86 | 77 |
| 87 gfx::Point BarControlButton::CalculateInkDropCenter() const { | 78 gfx::Point BarControlButton::CalculateInkDropCenter() const { |
| 88 return GetLocalBounds().CenterPoint(); | 79 return GetLocalBounds().CenterPoint(); |
| 89 } | 80 } |
| 90 | 81 |
| 91 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) { | 82 bool BarControlButton::OnMousePressed(const ui::MouseEvent& event) { |
| 92 if (IsTriggerableEvent(event)) { | 83 if (IsTriggerableEvent(event)) |
| 93 ink_drop_animation_controller_->AnimateToState( | 84 ink_drop_delegate()->OnAction(views::InkDropState::ACTION_PENDING); |
| 94 views::InkDropState::ACTION_PENDING); | |
| 95 } | |
| 96 | 85 |
| 97 return ImageButton::OnMousePressed(event); | 86 return ImageButton::OnMousePressed(event); |
| 98 } | 87 } |
| 99 | 88 |
| 100 void BarControlButton::OnGestureEvent(ui::GestureEvent* event) { | |
| 101 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; | |
| 102 switch (event->type()) { | |
| 103 case ui::ET_GESTURE_TAP_DOWN: | |
| 104 ink_drop_state = views::InkDropState::ACTION_PENDING; | |
| 105 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so | |
| 106 // that subsequent events for the gesture are sent to |this|. | |
| 107 event->SetHandled(); | |
| 108 break; | |
| 109 case ui::ET_GESTURE_LONG_PRESS: | |
| 110 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; | |
| 111 break; | |
| 112 case ui::ET_GESTURE_TAP: | |
| 113 ink_drop_state = views::InkDropState::QUICK_ACTION; | |
| 114 break; | |
| 115 case ui::ET_GESTURE_LONG_TAP: | |
| 116 ink_drop_state = views::InkDropState::SLOW_ACTION; | |
| 117 break; | |
| 118 case ui::ET_GESTURE_END: | |
| 119 case ui::ET_GESTURE_TAP_CANCEL: | |
| 120 ink_drop_state = views::InkDropState::HIDDEN; | |
| 121 break; | |
| 122 default: | |
| 123 return; | |
| 124 } | |
| 125 ink_drop_animation_controller_->AnimateToState(ink_drop_state); | |
| 126 | |
| 127 ImageButton::OnGestureEvent(event); | |
| 128 } | |
| 129 | |
| 130 void BarControlButton::OnMouseReleased(const ui::MouseEvent& event) { | 89 void BarControlButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 131 if (!HitTestPoint(event.location())) | 90 if (!HitTestPoint(event.location())) |
| 132 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | 91 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); |
|
varkha
2015/11/27 22:07:50
Just heads up. I think with https://codereview.chr
bruthig
2015/12/07 18:44:46
Done.
| |
| 133 | 92 |
| 134 ImageButton::OnMouseReleased(event); | 93 ImageButton::OnMouseReleased(event); |
| 135 } | 94 } |
| 136 | |
| 137 void BarControlButton::NotifyClick(const ui::Event& event) { | |
| 138 ink_drop_animation_controller_->AnimateToState( | |
| 139 views::InkDropState::QUICK_ACTION); | |
| 140 | |
| 141 ImageButton::NotifyClick(event); | |
| 142 } | |
| OLD | NEW |