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

Side by Side Diff: ui/views/controls/button/menu_button.cc

Issue 2042073002: Centered flood fill style ink drop ripples on mouse/touch points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from patch set 6. Created 4 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/controls/button/menu_button.h" 5 #include "ui/views/controls/button/menu_button.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/dragdrop/drag_drop_types.h" 9 #include "ui/base/dragdrop/drag_drop_types.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/ui_base_switches_util.h" 12 #include "ui/base/ui_base_switches_util.h"
13 #include "ui/display/screen.h" 13 #include "ui/display/screen.h"
14 #include "ui/events/event.h" 14 #include "ui/events/event.h"
15 #include "ui/events/event_constants.h" 15 #include "ui/events/event_constants.h"
16 #include "ui/events/event_utils.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
18 #include "ui/gfx/text_constants.h" 19 #include "ui/gfx/text_constants.h"
19 #include "ui/resources/grit/ui_resources.h" 20 #include "ui/resources/grit/ui_resources.h"
20 #include "ui/strings/grit/ui_strings.h" 21 #include "ui/strings/grit/ui_strings.h"
21 #include "ui/views/controls/button/button.h" 22 #include "ui/views/controls/button/button.h"
22 #include "ui/views/controls/button/menu_button_listener.h" 23 #include "ui/views/controls/button/menu_button_listener.h"
23 #include "ui/views/mouse_constants.h" 24 #include "ui/views/mouse_constants.h"
24 #include "ui/views/resources/grit/views_resources.h" 25 #include "ui/views/resources/grit/views_resources.h"
25 #include "ui/views/widget/root_view.h" 26 #include "ui/views/widget/root_view.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (destroyed) { 141 if (destroyed) {
141 // The menu was deleted while showing. Don't attempt any processing. 142 // The menu was deleted while showing. Don't attempt any processing.
142 return false; 143 return false;
143 } 144 }
144 145
145 increment_pressed_lock_called_ = nullptr; 146 increment_pressed_lock_called_ = nullptr;
146 destroyed_flag_ = nullptr; 147 destroyed_flag_ = nullptr;
147 148
148 menu_closed_time_ = TimeTicks::Now(); 149 menu_closed_time_ = TimeTicks::Now();
149 150
150 if (!increment_pressed_lock_called && pressed_lock_count_ == 0) 151 if (!increment_pressed_lock_called && pressed_lock_count_ == 0) {
151 AnimateInkDrop(InkDropState::ACTION_TRIGGERED); 152 AnimateInkDrop(InkDropState::ACTION_TRIGGERED,
153 ui::LocatedEvent::AsLocatedEventIfLocatedEvent(event));
154 }
152 155
153 // We must return false here so that the RootView does not get stuck 156 // We must return false here so that the RootView does not get stuck
154 // sending all mouse pressed events to us instead of the appropriate 157 // sending all mouse pressed events to us instead of the appropriate
155 // target. 158 // target.
156 return false; 159 return false;
157 } 160 }
158 161
159 AnimateInkDrop(InkDropState::HIDDEN); 162 AnimateInkDrop(InkDropState::HIDDEN,
163 ui::LocatedEvent::AsLocatedEventIfLocatedEvent(event));
160 return true; 164 return true;
161 } 165 }
162 166
163 bool MenuButton::IsTriggerableEventType(const ui::Event& event) { 167 bool MenuButton::IsTriggerableEventType(const ui::Event& event) {
164 if (event.IsMouseEvent()) { 168 if (event.IsMouseEvent()) {
165 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event); 169 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event);
166 // Active on left mouse button only, to prevent a menu from being activated 170 // Active on left mouse button only, to prevent a menu from being activated
167 // when a right-click would also activate a context menu. 171 // when a right-click would also activate a context menu.
168 if (!mouseev.IsOnlyLeftMouseButton()) 172 if (!mouseev.IsOnlyLeftMouseButton())
169 return false; 173 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return Activate(&event); 219 return Activate(&event);
216 } 220 }
217 return true; 221 return true;
218 } 222 }
219 223
220 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { 224 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) {
221 if (state() != STATE_DISABLED && IsTriggerableEvent(event) && 225 if (state() != STATE_DISABLED && IsTriggerableEvent(event) &&
222 HitTestPoint(event.location()) && !InDrag()) { 226 HitTestPoint(event.location()) && !InDrag()) {
223 Activate(&event); 227 Activate(&event);
224 } else { 228 } else {
225 AnimateInkDrop(InkDropState::HIDDEN); 229 AnimateInkDrop(InkDropState::HIDDEN, &event);
226 LabelButton::OnMouseReleased(event); 230 LabelButton::OnMouseReleased(event);
227 } 231 }
228 } 232 }
229 233
230 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { 234 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) {
231 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. 235 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked.
232 LabelButton::OnMouseEntered(event); 236 LabelButton::OnMouseEntered(event);
233 } 237 }
234 238
235 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { 239 void MenuButton::OnMouseExited(const ui::MouseEvent& event) {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 373
370 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { 374 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) {
371 ++pressed_lock_count_; 375 ++pressed_lock_count_;
372 if (increment_pressed_lock_called_) 376 if (increment_pressed_lock_called_)
373 *increment_pressed_lock_called_ = true; 377 *increment_pressed_lock_called_ = true;
374 should_disable_after_press_ = state() == STATE_DISABLED; 378 should_disable_after_press_ = state() == STATE_DISABLED;
375 if (state() != STATE_PRESSED) { 379 if (state() != STATE_PRESSED) {
376 if (snap_ink_drop_to_activated) 380 if (snap_ink_drop_to_activated)
377 ink_drop()->SnapToActivated(); 381 ink_drop()->SnapToActivated();
378 else 382 else
379 AnimateInkDrop(InkDropState::ACTIVATED); 383 AnimateInkDrop(InkDropState::ACTIVATED, nullptr /* event */);
380 } 384 }
381 SetState(STATE_PRESSED); 385 SetState(STATE_PRESSED);
382 } 386 }
383 387
384 void MenuButton::DecrementPressedLocked() { 388 void MenuButton::DecrementPressedLocked() {
385 --pressed_lock_count_; 389 --pressed_lock_count_;
386 DCHECK_GE(pressed_lock_count_, 0); 390 DCHECK_GE(pressed_lock_count_, 0);
387 391
388 // If this was the last lock, manually reset state to the desired state. 392 // If this was the last lock, manually reset state to the desired state.
389 if (pressed_lock_count_ == 0) { 393 if (pressed_lock_count_ == 0) {
390 ButtonState desired_state = STATE_NORMAL; 394 ButtonState desired_state = STATE_NORMAL;
391 if (should_disable_after_press_) { 395 if (should_disable_after_press_) {
392 desired_state = STATE_DISABLED; 396 desired_state = STATE_DISABLED;
393 should_disable_after_press_ = false; 397 should_disable_after_press_ = false;
394 } else if (ShouldEnterHoveredState()) { 398 } else if (ShouldEnterHoveredState()) {
395 desired_state = STATE_HOVERED; 399 desired_state = STATE_HOVERED;
396 } 400 }
397 SetState(desired_state); 401 SetState(desired_state);
398 // The widget may be null during shutdown. If so, it doesn't make sense to 402 // The widget may be null during shutdown. If so, it doesn't make sense to
399 // try to add an ink drop effect. 403 // try to add an ink drop effect.
400 if (GetWidget() && state() != STATE_PRESSED) 404 if (GetWidget() && state() != STATE_PRESSED)
401 AnimateInkDrop(InkDropState::DEACTIVATED); 405 AnimateInkDrop(InkDropState::DEACTIVATED, nullptr /* event */);
402 } 406 }
403 } 407 }
404 408
405 int MenuButton::GetMaximumScreenXCoordinate() { 409 int MenuButton::GetMaximumScreenXCoordinate() {
406 if (!GetWidget()) { 410 if (!GetWidget()) {
407 NOTREACHED(); 411 NOTREACHED();
408 return 0; 412 return 0;
409 } 413 }
410 414
411 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); 415 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen();
412 return monitor_bounds.right() - 1; 416 return monitor_bounds.right() - 1;
413 } 417 }
414 418
415 } // namespace views 419 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698