Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/toolbar_button.h" | 5 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 28 | 28 |
| 29 ToolbarButton::ToolbarButton(views::ButtonListener* listener, | 29 ToolbarButton::ToolbarButton(views::ButtonListener* listener, |
| 30 ui::MenuModel* model) | 30 ui::MenuModel* model) |
| 31 : views::LabelButton(listener, base::string16()), | 31 : views::LabelButton(listener, base::string16()), |
| 32 model_(model), | 32 model_(model), |
| 33 menu_showing_(false), | 33 menu_showing_(false), |
| 34 y_position_on_lbuttondown_(0), | 34 y_position_on_lbuttondown_(0), |
| 35 ink_drop_animation_controller_( | 35 ink_drop_animation_controller_( |
| 36 views::InkDropAnimationControllerFactory:: | 36 views::InkDropAnimationControllerFactory:: |
| 37 CreateInkDropAnimationController(this)), | 37 CreateInkDropAnimationController(this, this)), |
| 38 show_menu_factory_(this) { | 38 show_menu_factory_(this) { |
| 39 set_context_menu_controller(this); | 39 set_context_menu_controller(this); |
| 40 | 40 |
| 41 const int kInkDropLargeSize = 32; | 41 const int kInkDropLargeSize = 32; |
| 42 const int kInkDropLargeCornerRadius = 5; | 42 const int kInkDropLargeCornerRadius = 5; |
| 43 const int kInkDropSmallSize = 24; | 43 const int kInkDropSmallSize = 24; |
| 44 const int kInkDropSmallCornerRadius = 2; | 44 const int kInkDropSmallCornerRadius = 2; |
| 45 | 45 |
| 46 ink_drop_animation_controller_->SetInkDropSize( | 46 ink_drop_animation_controller_->SetInkDropSize( |
| 47 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), | 47 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 if (IsTriggerableEvent(event)) | 144 if (IsTriggerableEvent(event)) |
| 145 show_menu_factory_.InvalidateWeakPtrs(); | 145 show_menu_factory_.InvalidateWeakPtrs(); |
| 146 | 146 |
| 147 if (!HitTestPoint(event.location())) | 147 if (!HitTestPoint(event.location())) |
| 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | 148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ToolbarButton::OnMouseCaptureLost() { | 151 void ToolbarButton::OnMouseCaptureLost() { |
| 152 } | 152 } |
| 153 | 153 |
| 154 void ToolbarButton::OnMouseEntered(const ui::MouseEvent& event) { | |
| 155 UpdateInkDropHoverState(); | |
| 156 } | |
| 157 | |
| 154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { | 158 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { |
| 159 UpdateInkDropHoverState(); | |
|
Peter Kasting
2015/11/11 22:08:24
Nit: It might be better to do this below the SetSt
bruthig
2015/11/12 18:21:08
It certainly would make more sense, good thinking!
| |
| 160 | |
| 155 // Starting a drag results in a MouseExited, we need to ignore it. | 161 // Starting a drag results in a MouseExited, we need to ignore it. |
| 156 // A right click release triggers an exit event. We want to | 162 // A right click release triggers an exit event. We want to |
| 157 // remain in a PUSHED state until the drop down menu closes. | 163 // remain in a PUSHED state until the drop down menu closes. |
| 158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) | 164 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) |
| 159 SetState(STATE_NORMAL); | 165 SetState(STATE_NORMAL); |
| 160 } | 166 } |
| 161 | 167 |
| 162 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { | 168 void ToolbarButton::OnGestureEvent(ui::GestureEvent* event) { |
| 163 if (menu_showing_) { | 169 if (menu_showing_) { |
| 164 // While dropdown menu is showing the button should not handle gestures. | 170 // While dropdown menu is showing the button should not handle gestures. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 scoped_ptr<views::LabelButtonBorder> border = | 213 scoped_ptr<views::LabelButtonBorder> border = |
| 208 views::LabelButton::CreateDefaultBorder(); | 214 views::LabelButton::CreateDefaultBorder(); |
| 209 | 215 |
| 210 ui::ThemeProvider* provider = GetThemeProvider(); | 216 ui::ThemeProvider* provider = GetThemeProvider(); |
| 211 if (provider && provider->UsingSystemTheme()) | 217 if (provider && provider->UsingSystemTheme()) |
| 212 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); | 218 border->set_insets(GetLayoutInsets(TOOLBAR_BUTTON)); |
| 213 | 219 |
| 214 return border.Pass(); | 220 return border.Pass(); |
| 215 } | 221 } |
| 216 | 222 |
| 223 void ToolbarButton::OnEnabledChanged() { | |
| 224 UpdateInkDropHoverState(); | |
| 225 } | |
| 226 | |
| 217 void ToolbarButton::ShowContextMenuForView(View* source, | 227 void ToolbarButton::ShowContextMenuForView(View* source, |
| 218 const gfx::Point& point, | 228 const gfx::Point& point, |
| 219 ui::MenuSourceType source_type) { | 229 ui::MenuSourceType source_type) { |
| 220 if (!enabled()) | 230 if (!enabled()) |
| 221 return; | 231 return; |
| 222 | 232 |
| 223 show_menu_factory_.InvalidateWeakPtrs(); | 233 show_menu_factory_.InvalidateWeakPtrs(); |
| 224 ShowDropDownMenu(source_type); | 234 ShowDropDownMenu(source_type); |
| 225 } | 235 } |
| 226 | 236 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 | 349 |
| 340 // Set the state back to normal after the drop down menu is closed. | 350 // Set the state back to normal after the drop down menu is closed. |
| 341 if (state_ != STATE_DISABLED) | 351 if (state_ != STATE_DISABLED) |
| 342 SetState(STATE_NORMAL); | 352 SetState(STATE_NORMAL); |
| 343 } | 353 } |
| 344 | 354 |
| 345 gfx::Point ToolbarButton::CalculateInkDropCenter() const { | 355 gfx::Point ToolbarButton::CalculateInkDropCenter() const { |
| 346 return GetLocalBounds().CenterPoint(); | 356 return GetLocalBounds().CenterPoint(); |
| 347 } | 357 } |
| 348 | 358 |
| 359 void ToolbarButton::UpdateInkDropHoverState() { | |
| 360 ink_drop_animation_controller_->SetHovered(ShouldShowInkDropHover()); | |
| 361 } | |
| 362 | |
| 349 const char* ToolbarButton::GetClassName() const { | 363 const char* ToolbarButton::GetClassName() const { |
| 350 return "ToolbarButton"; | 364 return "ToolbarButton"; |
| 351 } | 365 } |
| OLD | NEW |