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/menu/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 // If we are already showing, this new menu is being nested. Such as context | 419 // If we are already showing, this new menu is being nested. Such as context |
420 // menus on top of normal menus. | 420 // menus on top of normal menus. |
421 if (showing_) { | 421 if (showing_) { |
422 // Only support nesting of blocking_run menus, nesting of | 422 // Only support nesting of blocking_run menus, nesting of |
423 // blocking/non-blocking shouldn't be needed. | 423 // blocking/non-blocking shouldn't be needed. |
424 DCHECK(blocking_run_); | 424 DCHECK(blocking_run_); |
425 | 425 |
426 state_.hot_button = hot_button_; | 426 state_.hot_button = hot_button_; |
427 hot_button_ = nullptr; | 427 hot_button_ = nullptr; |
428 // We're already showing, push the current state. | 428 // We're already showing, push the current state. |
429 menu_stack_.push_back( | 429 menu_stack_.push_back(std::make_pair(state_, std::move(pressed_lock_))); |
430 std::make_pair(state_, make_linked_ptr(pressed_lock_.release()))); | |
431 | 430 |
432 // The context menu should be owned by the same parent. | 431 // The context menu should be owned by the same parent. |
433 DCHECK_EQ(owner_, parent); | 432 DCHECK_EQ(owner_, parent); |
434 } else { | 433 } else { |
435 showing_ = true; | 434 showing_ = true; |
436 | 435 |
437 if (owner_) | 436 if (owner_) |
438 owner_->RemoveObserver(this); | 437 owner_->RemoveObserver(this); |
439 owner_ = parent; | 438 owner_ = parent; |
440 if (owner_) | 439 if (owner_) |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 if (!details.is_add) { | 848 if (!details.is_add) { |
850 // If the current mouse handler is removed, remove it as the handler. | 849 // If the current mouse handler is removed, remove it as the handler. |
851 if (details.child == current_mouse_event_target_) { | 850 if (details.child == current_mouse_event_target_) { |
852 current_mouse_event_target_ = nullptr; | 851 current_mouse_event_target_ = nullptr; |
853 current_mouse_pressed_state_ = 0; | 852 current_mouse_pressed_state_ = 0; |
854 } | 853 } |
855 // Update |hot_button_| (both in |this| and in |menu_stack_| if it gets | 854 // Update |hot_button_| (both in |this| and in |menu_stack_| if it gets |
856 // removed while a menu is up. | 855 // removed while a menu is up. |
857 if (details.child == hot_button_) { | 856 if (details.child == hot_button_) { |
858 hot_button_ = nullptr; | 857 hot_button_ = nullptr; |
859 for (auto nested_state : menu_stack_) { | 858 for (auto&& nested_state : menu_stack_) { |
sky
2016/12/06 14:16:06
optional: const on 858 and 859?
Sunny
2016/12/07 04:57:38
Hi, thanks for the review
Since 861 changes membe
sky
2016/12/07 16:48:24
You are right.
| |
860 State& state = nested_state.first; | 859 State& state = nested_state.first; |
861 if (details.child == state.hot_button) | 860 if (details.child == state.hot_button) |
862 state.hot_button = nullptr; | 861 state.hot_button = nullptr; |
863 } | 862 } |
864 } | 863 } |
865 } | 864 } |
866 } | 865 } |
867 | 866 |
868 bool MenuController::GetDropFormats( | 867 bool MenuController::GetDropFormats( |
869 SubmenuView* source, | 868 SubmenuView* source, |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1556 | 1555 |
1557 if (menu_item->GetDelegate()->ShowContextMenu( | 1556 if (menu_item->GetDelegate()->ShowContextMenu( |
1558 menu_item, menu_item->GetCommand(), screen_location, source_type)) { | 1557 menu_item, menu_item->GetCommand(), screen_location, source_type)) { |
1559 SendMouseCaptureLostToActiveView(); | 1558 SendMouseCaptureLostToActiveView(); |
1560 return true; | 1559 return true; |
1561 } | 1560 } |
1562 return false; | 1561 return false; |
1563 } | 1562 } |
1564 | 1563 |
1565 void MenuController::CloseAllNestedMenus() { | 1564 void MenuController::CloseAllNestedMenus() { |
1566 for (std::list<NestedState>::iterator i = menu_stack_.begin(); | 1565 for (auto&& nested_menu : menu_stack_) { |
1567 i != menu_stack_.end(); ++i) { | 1566 State& state = nested_menu.first; |
1568 State& state = i->first; | |
1569 MenuItemView* last_item = state.item; | 1567 MenuItemView* last_item = state.item; |
1570 for (MenuItemView* item = last_item; item; | 1568 for (MenuItemView* item = last_item; item; |
1571 item = item->GetParentMenuItem()) { | 1569 item = item->GetParentMenuItem()) { |
1572 CloseMenu(item); | 1570 CloseMenu(item); |
1573 last_item = item; | 1571 last_item = item; |
1574 } | 1572 } |
1575 state.submenu_open = false; | 1573 state.submenu_open = false; |
1576 state.item = last_item; | 1574 state.item = last_item; |
1577 } | 1575 } |
1578 } | 1576 } |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2607 POINT cursor_pos; | 2605 POINT cursor_pos; |
2608 ::GetCursorPos(&cursor_pos); | 2606 ::GetCursorPos(&cursor_pos); |
2609 HWND window = ::WindowFromPoint(cursor_pos); | 2607 HWND window = ::WindowFromPoint(cursor_pos); |
2610 if (::GetWindowThreadProcessId(window, nullptr) == ::GetCurrentThreadId()) { | 2608 if (::GetWindowThreadProcessId(window, nullptr) == ::GetCurrentThreadId()) { |
2611 ::SetProp(window, ui::kIgnoreTouchMouseActivateForWindow, | 2609 ::SetProp(window, ui::kIgnoreTouchMouseActivateForWindow, |
2612 reinterpret_cast<HANDLE>(true)); | 2610 reinterpret_cast<HANDLE>(true)); |
2613 } | 2611 } |
2614 } | 2612 } |
2615 #endif | 2613 #endif |
2616 | 2614 |
2617 linked_ptr<MenuButton::PressedLock> nested_pressed_lock; | 2615 std::unique_ptr<MenuButton::PressedLock> nested_pressed_lock; |
2618 bool nested_menu = !menu_stack_.empty(); | 2616 bool nested_menu = !menu_stack_.empty(); |
2619 if (nested_menu) { | 2617 if (nested_menu) { |
2620 DCHECK(!menu_stack_.empty()); | 2618 DCHECK(!menu_stack_.empty()); |
2621 // We're running from within a menu, restore the previous state. | 2619 // We're running from within a menu, restore the previous state. |
2622 // The menus are already showing, so we don't have to show them. | 2620 // The menus are already showing, so we don't have to show them. |
2623 state_ = menu_stack_.back().first; | 2621 state_ = menu_stack_.back().first; |
2624 pending_state_ = menu_stack_.back().first; | 2622 pending_state_ = menu_stack_.back().first; |
2625 hot_button_ = state_.hot_button; | 2623 hot_button_ = state_.hot_button; |
2626 nested_pressed_lock = menu_stack_.back().second; | 2624 nested_pressed_lock = std::move(menu_stack_.back().second); |
2627 menu_stack_.pop_back(); | 2625 menu_stack_.pop_back(); |
2628 // Even though the menus are nested, there may not be nested delegates. | 2626 // Even though the menus are nested, there may not be nested delegates. |
2629 if (delegate_stack_.size() > 1) { | 2627 if (delegate_stack_.size() > 1) { |
2630 delegate_stack_.pop_back(); | 2628 delegate_stack_.pop_back(); |
2631 delegate_ = delegate_stack_.back().first; | 2629 delegate_ = delegate_stack_.back().first; |
2632 async_run_ = delegate_stack_.back().second; | 2630 async_run_ = delegate_stack_.back().second; |
2633 } | 2631 } |
2634 } else { | 2632 } else { |
2635 #if defined(USE_AURA) | 2633 #if defined(USE_AURA) |
2636 menu_pre_target_handler_.reset(); | 2634 menu_pre_target_handler_.reset(); |
(...skipping 20 matching lines...) Expand all Loading... | |
2657 // Set exit_all_, which makes sure all nested loops exit immediately. | 2655 // Set exit_all_, which makes sure all nested loops exit immediately. |
2658 if (exit_type_ != EXIT_DESTROYED) | 2656 if (exit_type_ != EXIT_DESTROYED) |
2659 SetExitType(EXIT_ALL); | 2657 SetExitType(EXIT_ALL); |
2660 } else { | 2658 } else { |
2661 TerminateNestedMessageLoopIfNecessary(); | 2659 TerminateNestedMessageLoopIfNecessary(); |
2662 } | 2660 } |
2663 } | 2661 } |
2664 | 2662 |
2665 // Reset our pressed lock and hot-tracked state to the previous state's, if | 2663 // Reset our pressed lock and hot-tracked state to the previous state's, if |
2666 // they were active. The lock handles the case if the button was destroyed. | 2664 // they were active. The lock handles the case if the button was destroyed. |
2667 pressed_lock_.reset(nested_pressed_lock.release()); | 2665 pressed_lock_ = std::move(nested_pressed_lock); |
2668 if (hot_button_) | 2666 if (hot_button_) |
2669 hot_button_->SetHotTracked(true); | 2667 hot_button_->SetHotTracked(true); |
2670 | 2668 |
2671 return result; | 2669 return result; |
2672 } | 2670 } |
2673 | 2671 |
2674 void MenuController::HandleMouseLocation(SubmenuView* source, | 2672 void MenuController::HandleMouseLocation(SubmenuView* source, |
2675 const gfx::Point& mouse_location) { | 2673 const gfx::Point& mouse_location) { |
2676 if (showing_submenu_) | 2674 if (showing_submenu_) |
2677 return; | 2675 return; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2726 if (hot_button_) | 2724 if (hot_button_) |
2727 hot_button_->SetHotTracked(false); | 2725 hot_button_->SetHotTracked(false); |
2728 hot_button_ = hot_button; | 2726 hot_button_ = hot_button; |
2729 if (hot_button) { | 2727 if (hot_button) { |
2730 hot_button->SetHotTracked(true); | 2728 hot_button->SetHotTracked(true); |
2731 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); | 2729 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
2732 } | 2730 } |
2733 } | 2731 } |
2734 | 2732 |
2735 } // namespace views | 2733 } // namespace views |
OLD | NEW |