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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 } | 697 } |
698 | 698 |
699 void MenuController::OnDragExitedScrollButton(SubmenuView* source) { | 699 void MenuController::OnDragExitedScrollButton(SubmenuView* source) { |
700 StartCancelAllTimer(); | 700 StartCancelAllTimer(); |
701 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE); | 701 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE); |
702 StopScrolling(); | 702 StopScrolling(); |
703 } | 703 } |
704 | 704 |
705 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { | 705 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { |
706 if (submenu->IsShowing()) { | 706 if (submenu->IsShowing()) { |
707 gfx::Point point = gfx::Screen::GetCursorScreenPoint(); | 707 gfx::Point point = gfx::Screen::GetCursorScreenPoint( |
| 708 gfx::Screen::BadTwoWorldsContext()); |
708 const SubmenuView* root_submenu = | 709 const SubmenuView* root_submenu = |
709 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); | 710 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); |
710 views::View::ConvertPointFromScreen( | 711 views::View::ConvertPointFromScreen( |
711 root_submenu->GetWidget()->GetRootView(), &point); | 712 root_submenu->GetWidget()->GetRootView(), &point); |
712 HandleMouseLocation(submenu, point); | 713 HandleMouseLocation(submenu, point); |
713 } | 714 } |
714 } | 715 } |
715 | 716 |
716 void MenuController::SetSelection(MenuItemView* menu_item, | 717 void MenuController::SetSelection(MenuItemView* menu_item, |
717 int selection_types) { | 718 int selection_types) { |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 if (base::i18n::IsRTL()) { | 1103 if (base::i18n::IsRTL()) { |
1103 pending_state_.anchor = position == MenuItemView::TOPRIGHT ? | 1104 pending_state_.anchor = position == MenuItemView::TOPRIGHT ? |
1104 MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT; | 1105 MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT; |
1105 } else { | 1106 } else { |
1106 pending_state_.anchor = position; | 1107 pending_state_.anchor = position; |
1107 } | 1108 } |
1108 | 1109 |
1109 // Calculate the bounds of the monitor we'll show menus on. Do this once to | 1110 // Calculate the bounds of the monitor we'll show menus on. Do this once to |
1110 // avoid repeated system queries for the info. | 1111 // avoid repeated system queries for the info. |
1111 pending_state_.monitor_bounds = gfx::Screen::GetDisplayNearestPoint( | 1112 pending_state_.monitor_bounds = gfx::Screen::GetDisplayNearestPoint( |
1112 bounds.origin()).work_area(); | 1113 gfx::Screen::BadTwoWorldsContext(), bounds.origin()).work_area(); |
1113 #if defined(USE_ASH) | 1114 #if defined(USE_ASH) |
1114 if (!pending_state_.monitor_bounds.Contains(bounds)) { | 1115 if (!pending_state_.monitor_bounds.Contains(bounds)) { |
1115 // Use the monitor area if the work area doesn't contain the bounds. This | 1116 // Use the monitor area if the work area doesn't contain the bounds. This |
1116 // handles showing a menu from the launcher. | 1117 // handles showing a menu from the launcher. |
1117 gfx::Rect monitor_area = | 1118 gfx::Rect monitor_area = |
1118 gfx::Screen::GetDisplayNearestPoint(bounds.origin()).bounds(); | 1119 gfx::Screen::GetDisplayNearestPoint( |
| 1120 gfx::Screen::BadTwoWorldsContext(), bounds.origin()).bounds(); |
1119 if (monitor_area.Contains(bounds)) | 1121 if (monitor_area.Contains(bounds)) |
1120 pending_state_.monitor_bounds = monitor_area; | 1122 pending_state_.monitor_bounds = monitor_area; |
1121 } | 1123 } |
1122 #endif | 1124 #endif |
1123 } | 1125 } |
1124 | 1126 |
1125 void MenuController::Accept(MenuItemView* item, int mouse_event_flags) { | 1127 void MenuController::Accept(MenuItemView* item, int mouse_event_flags) { |
1126 DCHECK(IsBlockingRun()); | 1128 DCHECK(IsBlockingRun()); |
1127 result_ = item; | 1129 result_ = item; |
1128 if (item && !menu_stack_.empty() && | 1130 if (item && !menu_stack_.empty() && |
(...skipping 13 matching lines...) Expand all Loading... |
1142 View* source_view = source->GetScrollViewContainer(); | 1144 View* source_view = source->GetScrollViewContainer(); |
1143 if (mouse_location.x() >= 0 && | 1145 if (mouse_location.x() >= 0 && |
1144 mouse_location.x() < source_view->width() && | 1146 mouse_location.x() < source_view->width() && |
1145 mouse_location.y() >= 0 && | 1147 mouse_location.y() >= 0 && |
1146 mouse_location.y() < source_view->height()) { | 1148 mouse_location.y() < source_view->height()) { |
1147 // The mouse is over the menu, no need to continue. | 1149 // The mouse is over the menu, no need to continue. |
1148 return false; | 1150 return false; |
1149 } | 1151 } |
1150 | 1152 |
1151 gfx::NativeWindow window_under_mouse = | 1153 gfx::NativeWindow window_under_mouse = |
1152 gfx::Screen::GetWindowAtCursorScreenPoint(); | 1154 gfx::Screen::GetWindowAtCursorScreenPoint( |
| 1155 gfx::Screen::BadTwoWorldsContext()); |
1153 // TODO(oshima): Replace with views only API. | 1156 // TODO(oshima): Replace with views only API. |
1154 if (window_under_mouse != owner_->GetNativeWindow()) | 1157 if (window_under_mouse != owner_->GetNativeWindow()) |
1155 return false; | 1158 return false; |
1156 | 1159 |
1157 // The user moved the mouse outside the menu and over the owning window. See | 1160 // The user moved the mouse outside the menu and over the owning window. See |
1158 // if there is a sibling menu we should show. | 1161 // if there is a sibling menu we should show. |
1159 gfx::Point screen_point(mouse_location); | 1162 gfx::Point screen_point(mouse_location); |
1160 View::ConvertPointToScreen(source_view, &screen_point); | 1163 View::ConvertPointToScreen(source_view, &screen_point); |
1161 MenuItemView::AnchorPosition anchor; | 1164 MenuItemView::AnchorPosition anchor; |
1162 bool has_mnemonics; | 1165 bool has_mnemonics; |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 | 2131 |
2129 #if defined(USE_AURA) | 2132 #if defined(USE_AURA) |
2130 void MenuController::OnWindowActivated(aura::Window* active, | 2133 void MenuController::OnWindowActivated(aura::Window* active, |
2131 aura::Window* old_active) { | 2134 aura::Window* old_active) { |
2132 if (!drag_in_progress_) | 2135 if (!drag_in_progress_) |
2133 Cancel(EXIT_ALL); | 2136 Cancel(EXIT_ALL); |
2134 } | 2137 } |
2135 #endif | 2138 #endif |
2136 | 2139 |
2137 } // namespace views | 2140 } // namespace views |
OLD | NEW |