| 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/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 Loading... |
| 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 ToLocatedEventOrNull(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, ToLocatedEventOrNull(event)); |
| 160 return true; | 163 return true; |
| 161 } | 164 } |
| 162 | 165 |
| 163 bool MenuButton::IsTriggerableEventType(const ui::Event& event) { | 166 bool MenuButton::IsTriggerableEventType(const ui::Event& event) { |
| 164 if (event.IsMouseEvent()) { | 167 if (event.IsMouseEvent()) { |
| 165 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event); | 168 const ui::MouseEvent& mouseev = static_cast<const ui::MouseEvent&>(event); |
| 166 // Active on left mouse button only, to prevent a menu from being activated | 169 // Active on left mouse button only, to prevent a menu from being activated |
| 167 // when a right-click would also activate a context menu. | 170 // when a right-click would also activate a context menu. |
| 168 if (!mouseev.IsOnlyLeftMouseButton()) | 171 if (!mouseev.IsOnlyLeftMouseButton()) |
| 169 return false; | 172 return false; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 return Activate(&event); | 218 return Activate(&event); |
| 216 } | 219 } |
| 217 return true; | 220 return true; |
| 218 } | 221 } |
| 219 | 222 |
| 220 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { | 223 void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 221 if (state() != STATE_DISABLED && IsTriggerableEvent(event) && | 224 if (state() != STATE_DISABLED && IsTriggerableEvent(event) && |
| 222 HitTestPoint(event.location()) && !InDrag()) { | 225 HitTestPoint(event.location()) && !InDrag()) { |
| 223 Activate(&event); | 226 Activate(&event); |
| 224 } else { | 227 } else { |
| 225 AnimateInkDrop(InkDropState::HIDDEN); | 228 AnimateInkDrop(InkDropState::HIDDEN, &event); |
| 226 LabelButton::OnMouseReleased(event); | 229 LabelButton::OnMouseReleased(event); |
| 227 } | 230 } |
| 228 } | 231 } |
| 229 | 232 |
| 230 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { | 233 void MenuButton::OnMouseEntered(const ui::MouseEvent& event) { |
| 231 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. | 234 if (pressed_lock_count_ == 0) // Ignore mouse movement if state is locked. |
| 232 LabelButton::OnMouseEntered(event); | 235 LabelButton::OnMouseEntered(event); |
| 233 } | 236 } |
| 234 | 237 |
| 235 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { | 238 void MenuButton::OnMouseExited(const ui::MouseEvent& event) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 372 |
| 370 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { | 373 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { |
| 371 ++pressed_lock_count_; | 374 ++pressed_lock_count_; |
| 372 if (increment_pressed_lock_called_) | 375 if (increment_pressed_lock_called_) |
| 373 *increment_pressed_lock_called_ = true; | 376 *increment_pressed_lock_called_ = true; |
| 374 should_disable_after_press_ = state() == STATE_DISABLED; | 377 should_disable_after_press_ = state() == STATE_DISABLED; |
| 375 if (state() != STATE_PRESSED) { | 378 if (state() != STATE_PRESSED) { |
| 376 if (snap_ink_drop_to_activated) | 379 if (snap_ink_drop_to_activated) |
| 377 ink_drop()->SnapToActivated(); | 380 ink_drop()->SnapToActivated(); |
| 378 else | 381 else |
| 379 AnimateInkDrop(InkDropState::ACTIVATED); | 382 AnimateInkDrop(InkDropState::ACTIVATED, nullptr /* event */); |
| 380 } | 383 } |
| 381 SetState(STATE_PRESSED); | 384 SetState(STATE_PRESSED); |
| 382 } | 385 } |
| 383 | 386 |
| 384 void MenuButton::DecrementPressedLocked() { | 387 void MenuButton::DecrementPressedLocked() { |
| 385 --pressed_lock_count_; | 388 --pressed_lock_count_; |
| 386 DCHECK_GE(pressed_lock_count_, 0); | 389 DCHECK_GE(pressed_lock_count_, 0); |
| 387 | 390 |
| 388 // If this was the last lock, manually reset state to the desired state. | 391 // If this was the last lock, manually reset state to the desired state. |
| 389 if (pressed_lock_count_ == 0) { | 392 if (pressed_lock_count_ == 0) { |
| 390 ButtonState desired_state = STATE_NORMAL; | 393 ButtonState desired_state = STATE_NORMAL; |
| 391 if (should_disable_after_press_) { | 394 if (should_disable_after_press_) { |
| 392 desired_state = STATE_DISABLED; | 395 desired_state = STATE_DISABLED; |
| 393 should_disable_after_press_ = false; | 396 should_disable_after_press_ = false; |
| 394 } else if (ShouldEnterHoveredState()) { | 397 } else if (ShouldEnterHoveredState()) { |
| 395 desired_state = STATE_HOVERED; | 398 desired_state = STATE_HOVERED; |
| 396 } | 399 } |
| 397 SetState(desired_state); | 400 SetState(desired_state); |
| 398 // The widget may be null during shutdown. If so, it doesn't make sense to | 401 // The widget may be null during shutdown. If so, it doesn't make sense to |
| 399 // try to add an ink drop effect. | 402 // try to add an ink drop effect. |
| 400 if (GetWidget() && state() != STATE_PRESSED) | 403 if (GetWidget() && state() != STATE_PRESSED) |
| 401 AnimateInkDrop(InkDropState::DEACTIVATED); | 404 AnimateInkDrop(InkDropState::DEACTIVATED, nullptr /* event */); |
| 402 } | 405 } |
| 403 } | 406 } |
| 404 | 407 |
| 405 int MenuButton::GetMaximumScreenXCoordinate() { | 408 int MenuButton::GetMaximumScreenXCoordinate() { |
| 406 if (!GetWidget()) { | 409 if (!GetWidget()) { |
| 407 NOTREACHED(); | 410 NOTREACHED(); |
| 408 return 0; | 411 return 0; |
| 409 } | 412 } |
| 410 | 413 |
| 411 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 414 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
| 412 return monitor_bounds.right() - 1; | 415 return monitor_bounds.right() - 1; |
| 413 } | 416 } |
| 414 | 417 |
| 415 } // namespace views | 418 } // namespace views |
| OLD | NEW |