| 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" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 const int MenuButton::kMenuMarkerPaddingLeft = 3; | 40 const int MenuButton::kMenuMarkerPaddingLeft = 3; |
| 41 const int MenuButton::kMenuMarkerPaddingRight = -1; | 41 const int MenuButton::kMenuMarkerPaddingRight = -1; |
| 42 | 42 |
| 43 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 44 // | 44 // |
| 45 // MenuButton::PressedLock | 45 // MenuButton::PressedLock |
| 46 // | 46 // |
| 47 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 48 | 48 |
| 49 MenuButton::PressedLock::PressedLock(MenuButton* menu_button) | 49 MenuButton::PressedLock::PressedLock(MenuButton* menu_button) |
| 50 : PressedLock(menu_button, false) {} |
| 51 |
| 52 MenuButton::PressedLock::PressedLock(MenuButton* menu_button, |
| 53 bool is_sibling_menu_show) |
| 50 : menu_button_(menu_button->weak_factory_.GetWeakPtr()) { | 54 : menu_button_(menu_button->weak_factory_.GetWeakPtr()) { |
| 51 menu_button_->IncrementPressedLocked(); | 55 menu_button_->IncrementPressedLocked(is_sibling_menu_show); |
| 52 } | 56 } |
| 53 | 57 |
| 54 MenuButton::PressedLock::~PressedLock() { | 58 MenuButton::PressedLock::~PressedLock() { |
| 55 if (menu_button_.get()) | 59 if (menu_button_.get()) |
| 56 menu_button_->DecrementPressedLocked(); | 60 menu_button_->DecrementPressedLocked(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
| 60 // | 64 // |
| 61 // MenuButton - constructors, destructors, initialization | 65 // MenuButton - constructors, destructors, initialization |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 LabelButton::StateChanged(); | 365 LabelButton::StateChanged(); |
| 362 } | 366 } |
| 363 } | 367 } |
| 364 | 368 |
| 365 void MenuButton::NotifyClick(const ui::Event& event) { | 369 void MenuButton::NotifyClick(const ui::Event& event) { |
| 366 // We don't forward events to the normal button listener, instead using the | 370 // We don't forward events to the normal button listener, instead using the |
| 367 // MenuButtonListener. | 371 // MenuButtonListener. |
| 368 Activate(&event); | 372 Activate(&event); |
| 369 } | 373 } |
| 370 | 374 |
| 371 void MenuButton::IncrementPressedLocked() { | 375 void MenuButton::IncrementPressedLocked(bool snap_ink_drop_to_activated) { |
| 372 ++pressed_lock_count_; | 376 ++pressed_lock_count_; |
| 373 if (increment_pressed_lock_called_) | 377 if (increment_pressed_lock_called_) |
| 374 *increment_pressed_lock_called_ = true; | 378 *increment_pressed_lock_called_ = true; |
| 375 should_disable_after_press_ = state() == STATE_DISABLED; | 379 should_disable_after_press_ = state() == STATE_DISABLED; |
| 376 if (state() != STATE_PRESSED && ink_drop_delegate()) | 380 if (state() != STATE_PRESSED && ink_drop_delegate()) { |
| 377 ink_drop_delegate()->OnAction(InkDropState::ACTIVATED); | 381 if (snap_ink_drop_to_activated) |
| 382 ink_drop_delegate()->SnapToActivated(); |
| 383 else |
| 384 ink_drop_delegate()->OnAction(InkDropState::ACTIVATED); |
| 385 } |
| 378 SetState(STATE_PRESSED); | 386 SetState(STATE_PRESSED); |
| 379 } | 387 } |
| 380 | 388 |
| 381 void MenuButton::DecrementPressedLocked() { | 389 void MenuButton::DecrementPressedLocked() { |
| 382 --pressed_lock_count_; | 390 --pressed_lock_count_; |
| 383 DCHECK_GE(pressed_lock_count_, 0); | 391 DCHECK_GE(pressed_lock_count_, 0); |
| 384 | 392 |
| 385 // If this was the last lock, manually reset state to the desired state. | 393 // If this was the last lock, manually reset state to the desired state. |
| 386 if (pressed_lock_count_ == 0) { | 394 if (pressed_lock_count_ == 0) { |
| 387 ButtonState desired_state = STATE_NORMAL; | 395 ButtonState desired_state = STATE_NORMAL; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 401 if (!GetWidget()) { | 409 if (!GetWidget()) { |
| 402 NOTREACHED(); | 410 NOTREACHED(); |
| 403 return 0; | 411 return 0; |
| 404 } | 412 } |
| 405 | 413 |
| 406 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); | 414 gfx::Rect monitor_bounds = GetWidget()->GetWorkAreaBoundsInScreen(); |
| 407 return monitor_bounds.right() - 1; | 415 return monitor_bounds.right() - 1; |
| 408 } | 416 } |
| 409 | 417 |
| 410 } // namespace views | 418 } // namespace views |
| OLD | NEW |