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

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

Issue 1411523009: Adds OnClickCanceled callback to views::Button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds NotifyReleasedWithoutClick callback to views::Button (corrections) 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 87 }
88 return size; 88 return size;
89 } 89 }
90 90
91 void ToolbarButton::Layout() { 91 void ToolbarButton::Layout() {
92 LabelButton::Layout(); 92 LabelButton::Layout();
93 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter()); 93 ink_drop_animation_controller_->SetInkDropCenter(CalculateInkDropCenter());
94 } 94 }
95 95
96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) { 96 bool ToolbarButton::OnMousePressed(const ui::MouseEvent& event) {
97 if (enabled() && ShouldShowMenu() && 97 if (IsTriggerableEvent(event)) {
98 IsTriggerableEvent(event) && HitTestPoint(event.location())) { 98 if (enabled() && ShouldShowMenu() && HitTestPoint(event.location())) {
99 // Store the y pos of the mouse coordinates so we can use them later to 99 // 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 100 // determine if the user dragged the mouse down (which should pop up the
101 // drag down menu immediately, instead of waiting for the timer) 101 // drag down menu immediately, instead of waiting for the timer)
102 y_position_on_lbuttondown_ = event.y(); 102 y_position_on_lbuttondown_ = event.y();
103 103
104 // Schedule a task that will show the menu. 104 // Schedule a task that will show the menu.
105 const int kMenuTimerDelay = 500; 105 const int kMenuTimerDelay = 500;
106 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 106 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
107 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu, 107 FROM_HERE, base::Bind(&ToolbarButton::ShowDropDownMenu,
108 show_menu_factory_.GetWeakPtr(), 108 show_menu_factory_.GetWeakPtr(),
109 ui::GetMenuSourceTypeForEvent(event)), 109 ui::GetMenuSourceTypeForEvent(event)),
110 base::TimeDelta::FromMilliseconds(kMenuTimerDelay)); 110 base::TimeDelta::FromMilliseconds(kMenuTimerDelay));
111 } 111 }
112
113 // views::Button actions are only triggered by left and middle mouse clicks.
114 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) {
115 ink_drop_animation_controller_->AnimateToState( 112 ink_drop_animation_controller_->AnimateToState(
116 views::InkDropState::ACTION_PENDING); 113 views::InkDropState::ACTION_PENDING);
117 } 114 }
118 115
119 return LabelButton::OnMousePressed(event); 116 return LabelButton::OnMousePressed(event);
120 } 117 }
121 118
122 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) { 119 bool ToolbarButton::OnMouseDragged(const ui::MouseEvent& event) {
123 bool result = LabelButton::OnMouseDragged(event); 120 bool result = LabelButton::OnMouseDragged(event);
124 121
(...skipping 11 matching lines...) Expand all
136 } 133 }
137 134
138 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) { 135 void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) {
139 if (IsTriggerableEvent(event) || 136 if (IsTriggerableEvent(event) ||
140 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) { 137 (event.IsRightMouseButton() && !HitTestPoint(event.location()))) {
141 LabelButton::OnMouseReleased(event); 138 LabelButton::OnMouseReleased(event);
142 } 139 }
143 140
144 if (IsTriggerableEvent(event)) 141 if (IsTriggerableEvent(event))
145 show_menu_factory_.InvalidateWeakPtrs(); 142 show_menu_factory_.InvalidateWeakPtrs();
146
147 if (!HitTestPoint(event.location()))
148 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
149 } 143 }
150 144
151 void ToolbarButton::OnMouseCaptureLost() { 145 void ToolbarButton::OnMouseCaptureLost() {
152 } 146 }
153 147
154 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) { 148 void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) {
155 // Starting a drag results in a MouseExited, we need to ignore it. 149 // Starting a drag results in a MouseExited, we need to ignore it.
156 // A right click release triggers an exit event. We want to 150 // A right click release triggers an exit event. We want to
157 // remain in a PUSHED state until the drop down menu closes. 151 // remain in a PUSHED state until the drop down menu closes.
158 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED) 152 if (state_ != STATE_DISABLED && !InDrag() && state_ != STATE_PRESSED)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | 243 (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON |
250 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); 244 ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0);
251 } 245 }
252 246
253 void ToolbarButton::NotifyClick(const ui::Event& event) { 247 void ToolbarButton::NotifyClick(const ui::Event& event) {
254 LabelButton::NotifyClick(event); 248 LabelButton::NotifyClick(event);
255 ink_drop_animation_controller_->AnimateToState( 249 ink_drop_animation_controller_->AnimateToState(
256 views::InkDropState::QUICK_ACTION); 250 views::InkDropState::QUICK_ACTION);
257 } 251 }
258 252
253 void ToolbarButton::NotifyReleasedWithoutClick(const ui::Event& event) {
254 LabelButton::NotifyReleasedWithoutClick(event);
255 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN);
256 }
257
259 bool ToolbarButton::ShouldShowMenu() { 258 bool ToolbarButton::ShouldShowMenu() {
260 return model_ != nullptr; 259 return model_ != nullptr;
261 } 260 }
262 261
263 void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) { 262 void ToolbarButton::ShowDropDownMenu(ui::MenuSourceType source_type) {
264 if (!ShouldShowMenu()) 263 if (!ShouldShowMenu())
265 return; 264 return;
266 265
267 gfx::Rect lb = GetLocalBounds(); 266 gfx::Rect lb = GetLocalBounds();
268 267
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 SetState(STATE_NORMAL); 341 SetState(STATE_NORMAL);
343 } 342 }
344 343
345 gfx::Point ToolbarButton::CalculateInkDropCenter() const { 344 gfx::Point ToolbarButton::CalculateInkDropCenter() const {
346 return GetLocalBounds().CenterPoint(); 345 return GetLocalBounds().CenterPoint();
347 } 346 }
348 347
349 const char* ToolbarButton::GetClassName() const { 348 const char* ToolbarButton::GetClassName() const {
350 return "ToolbarButton"; 349 return "ToolbarButton";
351 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698