| 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 else | 882 else |
| 883 OnKeyDown(key_code); | 883 OnKeyDown(key_code); |
| 884 | 884 |
| 885 TerminateNestedMessageLoopIfNecessary(); | 885 TerminateNestedMessageLoopIfNecessary(); |
| 886 | 886 |
| 887 return ui::POST_DISPATCH_NONE; | 887 return ui::POST_DISPATCH_NONE; |
| 888 } | 888 } |
| 889 | 889 |
| 890 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { | 890 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { |
| 891 if (submenu->IsShowing()) { | 891 if (submenu->IsShowing()) { |
| 892 gfx::Point point = GetScreen()->GetCursorScreenPoint(); | 892 gfx::Point point = gfx::Screen::GetScreen()->GetCursorScreenPoint(); |
| 893 const SubmenuView* root_submenu = | 893 const SubmenuView* root_submenu = |
| 894 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); | 894 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); |
| 895 View::ConvertPointFromScreen( | 895 View::ConvertPointFromScreen( |
| 896 root_submenu->GetWidget()->GetRootView(), &point); | 896 root_submenu->GetWidget()->GetRootView(), &point); |
| 897 HandleMouseLocation(submenu, point); | 897 HandleMouseLocation(submenu, point); |
| 898 } | 898 } |
| 899 } | 899 } |
| 900 | 900 |
| 901 void MenuController::OnWidgetDestroying(Widget* widget) { | 901 void MenuController::OnWidgetDestroying(Widget* widget) { |
| 902 DCHECK_EQ(owner_, widget); | 902 DCHECK_EQ(owner_, widget); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 (position == MENU_ANCHOR_TOPRIGHT || position == MENU_ANCHOR_TOPLEFT)) { | 1228 (position == MENU_ANCHOR_TOPRIGHT || position == MENU_ANCHOR_TOPLEFT)) { |
| 1229 pending_state_.anchor = position == MENU_ANCHOR_TOPRIGHT | 1229 pending_state_.anchor = position == MENU_ANCHOR_TOPRIGHT |
| 1230 ? MENU_ANCHOR_TOPLEFT | 1230 ? MENU_ANCHOR_TOPLEFT |
| 1231 : MENU_ANCHOR_TOPRIGHT; | 1231 : MENU_ANCHOR_TOPRIGHT; |
| 1232 } else { | 1232 } else { |
| 1233 pending_state_.anchor = position; | 1233 pending_state_.anchor = position; |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 // Calculate the bounds of the monitor we'll show menus on. Do this once to | 1236 // Calculate the bounds of the monitor we'll show menus on. Do this once to |
| 1237 // avoid repeated system queries for the info. | 1237 // avoid repeated system queries for the info. |
| 1238 pending_state_.monitor_bounds = GetScreen()->GetDisplayNearestPoint( | 1238 pending_state_.monitor_bounds = gfx::Screen::GetScreen() |
| 1239 bounds.origin()).work_area(); | 1239 ->GetDisplayNearestPoint(bounds.origin()) |
| 1240 .work_area(); |
| 1240 | 1241 |
| 1241 if (!pending_state_.monitor_bounds.Contains(bounds)) { | 1242 if (!pending_state_.monitor_bounds.Contains(bounds)) { |
| 1242 // Use the monitor area if the work area doesn't contain the bounds. This | 1243 // Use the monitor area if the work area doesn't contain the bounds. This |
| 1243 // handles showing a menu from the launcher. | 1244 // handles showing a menu from the launcher. |
| 1244 gfx::Rect monitor_area = GetScreen()->GetDisplayNearestPoint( | 1245 gfx::Rect monitor_area = gfx::Screen::GetScreen() |
| 1245 bounds.origin()).bounds(); | 1246 ->GetDisplayNearestPoint(bounds.origin()) |
| 1247 .bounds(); |
| 1246 if (monitor_area.Contains(bounds)) | 1248 if (monitor_area.Contains(bounds)) |
| 1247 pending_state_.monitor_bounds = monitor_area; | 1249 pending_state_.monitor_bounds = monitor_area; |
| 1248 } | 1250 } |
| 1249 } | 1251 } |
| 1250 | 1252 |
| 1251 void MenuController::Accept(MenuItemView* item, int event_flags) { | 1253 void MenuController::Accept(MenuItemView* item, int event_flags) { |
| 1252 DCHECK(IsBlockingRun()); | 1254 DCHECK(IsBlockingRun()); |
| 1253 result_ = item; | 1255 result_ = item; |
| 1254 if (item && !menu_stack_.empty() && | 1256 if (item && !menu_stack_.empty() && |
| 1255 !item->GetDelegate()->ShouldCloseAllMenusOnExecute(item->GetCommand())) { | 1257 !item->GetDelegate()->ShouldCloseAllMenusOnExecute(item->GetCommand())) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1268 | 1270 |
| 1269 View* source_view = source->GetScrollViewContainer(); | 1271 View* source_view = source->GetScrollViewContainer(); |
| 1270 if (mouse_location.x() >= 0 && | 1272 if (mouse_location.x() >= 0 && |
| 1271 mouse_location.x() < source_view->width() && | 1273 mouse_location.x() < source_view->width() && |
| 1272 mouse_location.y() >= 0 && | 1274 mouse_location.y() >= 0 && |
| 1273 mouse_location.y() < source_view->height()) { | 1275 mouse_location.y() < source_view->height()) { |
| 1274 // The mouse is over the menu, no need to continue. | 1276 // The mouse is over the menu, no need to continue. |
| 1275 return false; | 1277 return false; |
| 1276 } | 1278 } |
| 1277 | 1279 |
| 1278 gfx::NativeWindow window_under_mouse = GetScreen()->GetWindowUnderCursor(); | 1280 gfx::NativeWindow window_under_mouse = |
| 1281 gfx::Screen::GetScreen()->GetWindowUnderCursor(); |
| 1279 // TODO(oshima): Replace with views only API. | 1282 // TODO(oshima): Replace with views only API. |
| 1280 if (!owner_ || window_under_mouse != owner_->GetNativeWindow()) | 1283 if (!owner_ || window_under_mouse != owner_->GetNativeWindow()) |
| 1281 return false; | 1284 return false; |
| 1282 | 1285 |
| 1283 // The user moved the mouse outside the menu and over the owning window. See | 1286 // The user moved the mouse outside the menu and over the owning window. See |
| 1284 // if there is a sibling menu we should show. | 1287 // if there is a sibling menu we should show. |
| 1285 gfx::Point screen_point(mouse_location); | 1288 gfx::Point screen_point(mouse_location); |
| 1286 View::ConvertPointToScreen(source_view, &screen_point); | 1289 View::ConvertPointToScreen(source_view, &screen_point); |
| 1287 MenuAnchorPosition anchor; | 1290 MenuAnchorPosition anchor; |
| 1288 bool has_mnemonics; | 1291 bool has_mnemonics; |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2265 | 2268 |
| 2266 void MenuController::RepostEventAndCancel(SubmenuView* source, | 2269 void MenuController::RepostEventAndCancel(SubmenuView* source, |
| 2267 const ui::LocatedEvent* event) { | 2270 const ui::LocatedEvent* event) { |
| 2268 // Cancel can lead to the deletion |source| so we save the view and window to | 2271 // Cancel can lead to the deletion |source| so we save the view and window to |
| 2269 // be used when reposting the event. | 2272 // be used when reposting the event. |
| 2270 gfx::Point screen_loc(event->location()); | 2273 gfx::Point screen_loc(event->location()); |
| 2271 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); | 2274 View::ConvertPointToScreen(source->GetScrollViewContainer(), &screen_loc); |
| 2272 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); | 2275 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); |
| 2273 gfx::NativeWindow window = nullptr; | 2276 gfx::NativeWindow window = nullptr; |
| 2274 if (native_view) { | 2277 if (native_view) { |
| 2275 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); | 2278 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 2276 window = screen->GetWindowAtScreenPoint(screen_loc); | 2279 window = screen->GetWindowAtScreenPoint(screen_loc); |
| 2277 } | 2280 } |
| 2278 | 2281 |
| 2279 #if defined(OS_WIN) | 2282 #if defined(OS_WIN) |
| 2280 // We're going to close and we own the event capture. We need to repost the | 2283 // We're going to close and we own the event capture. We need to repost the |
| 2281 // event, otherwise the window the user clicked on won't get the event. | 2284 // event, otherwise the window the user clicked on won't get the event. |
| 2282 RepostEvent(source, event, screen_loc, native_view, window); | 2285 RepostEvent(source, event, screen_loc, native_view, window); |
| 2283 #endif | 2286 #endif |
| 2284 | 2287 |
| 2285 // Determine target to see if a complete or partial close of the menu should | 2288 // Determine target to see if a complete or partial close of the menu should |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2561 pending_state_.item->GetParentMenuItem() && | 2564 pending_state_.item->GetParentMenuItem() && |
| 2562 (!pending_state_.item->HasSubmenu() || | 2565 (!pending_state_.item->HasSubmenu() || |
| 2563 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2566 !pending_state_.item->GetSubmenu()->IsShowing())) { |
| 2564 // On exit if the user hasn't selected an item with a submenu, move the | 2567 // On exit if the user hasn't selected an item with a submenu, move the |
| 2565 // selection back to the parent menu item. | 2568 // selection back to the parent menu item. |
| 2566 SetSelection(pending_state_.item->GetParentMenuItem(), | 2569 SetSelection(pending_state_.item->GetParentMenuItem(), |
| 2567 SELECTION_OPEN_SUBMENU); | 2570 SELECTION_OPEN_SUBMENU); |
| 2568 } | 2571 } |
| 2569 } | 2572 } |
| 2570 | 2573 |
| 2571 gfx::Screen* MenuController::GetScreen() { | |
| 2572 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; | |
| 2573 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) | |
| 2574 : gfx::Screen::GetNativeScreen(); | |
| 2575 } | |
| 2576 | |
| 2577 } // namespace views | 2574 } // namespace views |
| OLD | NEW |