OLD | NEW |
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/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
19 #include "ui/resources/grit/ui_resources.h" | 19 #include "ui/resources/grit/ui_resources.h" |
20 #include "ui/strings/grit/ui_strings.h" | 20 #include "ui/strings/grit/ui_strings.h" |
21 #include "ui/views/animation/ink_drop_delegate.h" | |
22 #include "ui/views/controls/button/button.h" | 21 #include "ui/views/controls/button/button.h" |
23 #include "ui/views/controls/button/menu_button_listener.h" | 22 #include "ui/views/controls/button/menu_button_listener.h" |
24 #include "ui/views/mouse_constants.h" | 23 #include "ui/views/mouse_constants.h" |
25 #include "ui/views/resources/grit/views_resources.h" | 24 #include "ui/views/resources/grit/views_resources.h" |
26 #include "ui/views/widget/root_view.h" | 25 #include "ui/views/widget/root_view.h" |
27 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
28 | 27 |
29 using base::TimeTicks; | 28 using base::TimeTicks; |
30 using base::TimeDelta; | 29 using base::TimeDelta; |
31 | 30 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 if (destroyed) { | 140 if (destroyed) { |
142 // The menu was deleted while showing. Don't attempt any processing. | 141 // The menu was deleted while showing. Don't attempt any processing. |
143 return false; | 142 return false; |
144 } | 143 } |
145 | 144 |
146 increment_pressed_lock_called_ = nullptr; | 145 increment_pressed_lock_called_ = nullptr; |
147 destroyed_flag_ = nullptr; | 146 destroyed_flag_ = nullptr; |
148 | 147 |
149 menu_closed_time_ = TimeTicks::Now(); | 148 menu_closed_time_ = TimeTicks::Now(); |
150 | 149 |
151 if (ink_drop_delegate() && !increment_pressed_lock_called && | 150 if (!increment_pressed_lock_called && pressed_lock_count_ == 0) |
152 pressed_lock_count_ == 0) { | 151 AnimateInkDrop(InkDropState::ACTION_TRIGGERED); |
153 ink_drop_delegate()->OnAction(InkDropState::ACTION_TRIGGERED); | |
154 } | |
155 | 152 |
156 // We must return false here so that the RootView does not get stuck | 153 // We must return false here so that the RootView does not get stuck |
157 // sending all mouse pressed events to us instead of the appropriate | 154 // sending all mouse pressed events to us instead of the appropriate |
158 // target. | 155 // target. |
159 return false; | 156 return false; |
160 } | 157 } |
161 | 158 |
162 if (ink_drop_delegate()) | 159 AnimateInkDrop(InkDropState::HIDDEN); |
163 ink_drop_delegate()->OnAction(InkDropState::HIDDEN); | |
164 return true; | 160 return true; |
165 } | 161 } |
166 | 162 |
167 bool MenuButton::IsTriggerableEventType(const ui::Event& event) { | 163 bool MenuButton::IsTriggerableEventType(const ui::Event& event) { |
168 if (event.IsMouseEvent()) { | 164 if (event.IsMouseEvent()) { |
169 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event); | 165 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event); |
170 // Active on left mouse button only, to prevent a menu from being activated | 166 // Active on left mouse button only, to prevent a menu from being activated |
171 // when a right-click would also activate a context menu. | 167 // when a right-click would also activate a context menu. |
172 if (!mouseev.IsOnlyLeftMouseButton()) | 168 if (!mouseev.IsOnlyLeftMouseButton()) |
173 return false; | 169 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return Activate(&event); | 215 return Activate(&event); |
220 } | 216 } |
221 return true; | 217 return true; |
222 } | 218 } |
223 | 219 |
224 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { | 220 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { |
225 if (state() != STATE_DISABLED && IsTriggerableEvent(event) && | 221 if (state() != STATE_DISABLED && IsTriggerableEvent(event) && |
226 HitTestPoint(event.location()) && !InDrag()) { | 222 HitTestPoint(event.location()) && !InDrag()) { |
227 Activate(&event); | 223 Activate(&event); |
228 } else { | 224 } else { |
229 if (ink_drop_delegate()) | 225 AnimateInkDrop(InkDropState::HIDDEN); |
230 ink_drop_delegate()->OnAction(InkDropState::HIDDEN); | |
231 LabelButton::OnMouseReleased(event); | 226 LabelButton::OnMouseReleased(event); |
232 } | 227 } |
233 } | 228 } |
234 | 229 |
235 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { | 230 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { |
236 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. | 231 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. |
237 LabelButton::OnMouseEntered(event); | 232 LabelButton::OnMouseEntered(event); |
238 } | 233 } |
239 | 234 |
240 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { | 235 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // We don't forward events to the normal button listener, instead using the | 365 // We don't forward events to the normal button listener, instead using the |
371 // MenuButtonListener. | 366 // MenuButtonListener. |
372 Activate(&event); | 367 Activate(&event); |
373 } | 368 } |
374 | 369 |
375 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { | 370 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { |
376 ++pressed_lock_count_; | 371 ++pressed_lock_count_; |
377 if (increment_pressed_lock_called_) | 372 if (increment_pressed_lock_called_) |
378 *increment_pressed_lock_called_ = true; | 373 *increment_pressed_lock_called_ = true; |
379 should_disable_after_press_ = state() == STATE_DISABLED; | 374 should_disable_after_press_ = state() == STATE_DISABLED; |
380 if (state() != STATE_PRESSED && ink_drop_delegate()) { | 375 if (state() != STATE_PRESSED) { |
381 if (snap_ink_drop_to_activated) | 376 if (snap_ink_drop_to_activated) |
382 ink_drop_delegate()->SnapToActivated(); | 377 ink_drop()->SnapToActivated(); |
383 else | 378 else |
384 ink_drop_delegate()->OnAction(InkDropState::ACTIVATED); | 379 AnimateInkDrop(InkDropState::ACTIVATED); |
385 } | 380 } |
386 SetState(STATE_PRESSED); | 381 SetState(STATE_PRESSED); |
387 } | 382 } |
388 | 383 |
389 void MenuButton::DecrementPressedLocked() { | 384 void MenuButton::DecrementPressedLocked() { |
390 --pressed_lock_count_; | 385 --pressed_lock_count_; |
391 DCHECK_GE(pressed_lock_count_, 0); | 386 DCHECK_GE(pressed_lock_count_, 0); |
392 | 387 |
393 // If this was the last lock, manually reset state to the desired state. | 388 // If this was the last lock, manually reset state to the desired state. |
394 if (pressed_lock_count_ == 0) { | 389 if (pressed_lock_count_ == 0) { |
395 ButtonState desired_state = STATE_NORMAL; | 390 ButtonState desired_state = STATE_NORMAL; |
396 if (should_disable_after_press_) { | 391 if (should_disable_after_press_) { |
397 desired_state = STATE_DISABLED; | 392 desired_state = STATE_DISABLED; |
398 should_disable_after_press_ = false; | 393 should_disable_after_press_ = false; |
399 } else if (ShouldEnterHoveredState()) { | 394 } else if (ShouldEnterHoveredState()) { |
400 desired_state = STATE_HOVERED; | 395 desired_state = STATE_HOVERED; |
401 } | 396 } |
402 SetState(desired_state); | 397 SetState(desired_state); |
403 if (ink_drop_delegate() && state() != STATE_PRESSED) | 398 if (state() != STATE_PRESSED) |
404 ink_drop_delegate()->OnAction(InkDropState::DEACTIVATED); | 399 AnimateInkDrop(InkDropState::DEACTIVATED); |
405 } | 400 } |
406 } | 401 } |
407 | 402 |
408 int MenuButton::GetMaximumScreenXCoordinate() { | 403 int MenuButton::GetMaximumScreenXCoordinate() { |
409 if (!GetWidget()) { | 404 if (!GetWidget()) { |
410 NOTREACHED(); | 405 NOTREACHED(); |
411 return 0; | 406 return 0; |
412 } | 407 } |
413 | 408 |
414 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 409 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
415 return monitor_bounds.right() - 1; | 410 return monitor_bounds.right() - 1; |
416 } | 411 } |
417 | 412 |
418 } // namespace views | 413 } // namespace views |
OLD | NEW |