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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_button.cc

Issue 1373983002: Enhanced the InkDropRippleImpl to create/destroy InkDropAnimations as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reworked patch to use new LayerAnimationObserver::OnAnimationStarted() event. Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_animation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 #include "ui/views/controls/menu/menu_runner.h" 26 #include "ui/views/controls/menu/menu_runner.h"
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 show_menu_factory_(this) { 35 show_menu_factory_(this) {
36 // Sizes for the the ink drop.
37 const int kInkDropLargeSize = 32;
38 const int kInkDropLargeCornerRadius = 5;
39 const int kInkDropSmallSize = 24;
40 const int kInkDropSmallCornerRadius = 2;
Peter Kasting 2015/10/05 21:01:54 Is there some way to calculate these sizes based o
bruthig 2015/10/06 15:31:38 The sizes were given by the designers. I don't th
41
36 ink_drop_animation_controller_ = views::InkDropAnimationControllerFactory:: 42 ink_drop_animation_controller_ = views::InkDropAnimationControllerFactory::
37 CreateInkDropAnimationController(this); 43 CreateInkDropAnimationController(this);
44 ink_drop_animation_controller_->SetInkDropSize(
45 gfx::Size(kInkDropLargeSize, kInkDropLargeSize),
46 kInkDropLargeCornerRadius,
47 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
48 kInkDropSmallCornerRadius);
38 set_context_menu_controller(this); 49 set_context_menu_controller(this);
39 } 50 }
40 51
41 ToolbarButton::~ToolbarButton() { 52 ToolbarButton::~ToolbarButton() {
42 } 53 }
43 54
44 void ToolbarButton::Init() { 55 void ToolbarButton::Init() {
45 SetFocusable(false); 56 SetFocusable(false);
46 SetAccessibilityFocusable(true); 57 SetAccessibilityFocusable(true);
47 image()->EnableCanvasFlippingForRTLUI(true); 58 image()->EnableCanvasFlippingForRTLUI(true);
(...skipping 23 matching lines...) Expand all
71 if (provider) { 82 if (provider) {
72 gfx::Insets insets(GetLayoutInsets(TOOLBAR_BUTTON)); 83 gfx::Insets insets(GetLayoutInsets(TOOLBAR_BUTTON));
73 size.Enlarge(insets.width(), insets.height()); 84 size.Enlarge(insets.width(), insets.height());
74 } 85 }
75 } 86 }
76 return size; 87 return size;
77 } 88 }
78 89
79 void ToolbarButton::Layout() { 90 void ToolbarButton::Layout() {
80 LabelButton::Layout(); 91 LabelButton::Layout();
81
82 // Sizes for the the ink drop.
83 const int kInkDropLargeSize = 32;
84 const int kInkDropLargeCornerRadius = 5;
85 const int kInkDropSmallSize = 24;
86 const int kInkDropSmallCornerRadius = 2;
87
88 ink_drop_animation_controller_->SetInkDropSize(
89 gfx::Size(kInkDropLargeSize, kInkDropLargeSize),
90 kInkDropLargeCornerRadius,
91 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
92 kInkDropSmallCornerRadius);
93 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); 92 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter());
94 } 93 }
95 94
96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { 95 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
97 if (enabled() && ShouldShowMenu() && 96 if (enabled() && ShouldShowMenu() &&
98 IsTriggerableEvent(event) && HitTestPoint(event.location())) { 97 IsTriggerableEvent(event) && HitTestPoint(event.location())) {
99 // Store the y pos of the mouse coordinates so we can use them later to 98 // Store the y pos of the mouse coordinates so we can use them later to
100 // determine if the user dragged the mouse down (which should pop up the 99 // determine if the user dragged the mouse down (which should pop up the
101 // drag down menu immediately, instead of waiting for the timer) 100 // drag down menu immediately, instead of waiting for the timer)
102 y_position_on_lbuttondown_ = event.y(); 101 y_position_on_lbuttondown_ = event.y();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 136
138 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { 137 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) {
139 if (IsTriggerableEvent(event) || 138 if (IsTriggerableEvent(event) ||
140 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { 139 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) {
141 LabelButton::OnMouseReleased(event); 140 LabelButton::OnMouseReleased(event);
142 } 141 }
143 142
144 if (IsTriggerableEvent(event)) 143 if (IsTriggerableEvent(event))
145 show_menu_factory_.InvalidateWeakPtrs(); 144 show_menu_factory_.InvalidateWeakPtrs();
146 145
147 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); 146 if (!HitTestPoint(event.location())) {
147 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
148 return;
Peter Kasting 2015/10/05 21:01:54 Why this return statement?
bruthig 2015/10/06 15:31:38 Removed.
149 }
148 } 150 }
149 151
150 void ToolbarButton::OnMouseCaptureLost() { 152 void ToolbarButton::OnMouseCaptureLost() {
151 } 153 }
152 154
153 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { 155 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) {
154 // Starting a drag results in a MouseExited, we need to ignore it. 156 // Starting a drag results in a MouseExited, we need to ignore it.
155 // A right click release triggers an exit event. We want to 157 // A right click release triggers an exit event. We want to
156 // remain in a PUSHED state until the drop down menu closes. 158 // remain in a PUSHED state until the drop down menu closes.
157 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) 159 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED)
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 SetState(STATE_NORMAL); 343 SetState(STATE_NORMAL);
342 } 344 }
343 345
344 gfx::Point ToolbarButton::CalculateInkDropCenter() const { 346 gfx::Point ToolbarButton::CalculateInkDropCenter() const {
345 return GetLocalBounds().CenterPoint(); 347 return GetLocalBounds().CenterPoint();
346 } 348 }
347 349
348 const char* ToolbarButton::GetClassName() const { 350 const char* ToolbarButton::GetClassName() const {
349 return "ToolbarButton"; 351 return "ToolbarButton";
350 } 352 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_animation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698