Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: ui/views/controls/menu/menu_controller.cc

Issue 1608733002: Remove ui/gfx/screen_type_delegate.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-4
Patch Set: and another rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 2275
2273 #if defined(OS_WIN) || defined(OS_CHROMEOS) 2276 #if defined(OS_WIN) || defined(OS_CHROMEOS)
2274 gfx::NativeView native_view = source->GetWidget()->GetNativeView(); 2277 gfx::NativeView native_view = source->GetWidget()->GetNativeView();
2275 gfx::NativeWindow window = nullptr; 2278 gfx::NativeWindow window = nullptr;
2276 if (native_view) { 2279 if (native_view) {
2277 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); 2280 gfx::Screen* screen = gfx::Screen::GetScreen();
2278 window = screen->GetWindowAtScreenPoint(screen_loc); 2281 window = screen->GetWindowAtScreenPoint(screen_loc);
2279 } 2282 }
2280 #endif 2283 #endif
2281 2284
2282 #if defined(OS_WIN) 2285 #if defined(OS_WIN)
2283 // We're going to close and we own the event capture. We need to repost the 2286 // We're going to close and we own the event capture. We need to repost the
2284 // event, otherwise the window the user clicked on won't get the event. 2287 // event, otherwise the window the user clicked on won't get the event.
2285 RepostEvent(source, event, screen_loc, native_view, window); 2288 RepostEvent(source, event, screen_loc, native_view, window);
2286 #endif 2289 #endif
2287 2290
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 pending_state_.item->GetParentMenuItem() && 2567 pending_state_.item->GetParentMenuItem() &&
2565 (!pending_state_.item->HasSubmenu() || 2568 (!pending_state_.item->HasSubmenu() ||
2566 !pending_state_.item->GetSubmenu()->IsShowing())) { 2569 !pending_state_.item->GetSubmenu()->IsShowing())) {
2567 // On exit if the user hasn't selected an item with a submenu, move the 2570 // On exit if the user hasn't selected an item with a submenu, move the
2568 // selection back to the parent menu item. 2571 // selection back to the parent menu item.
2569 SetSelection(pending_state_.item->GetParentMenuItem(), 2572 SetSelection(pending_state_.item->GetParentMenuItem(),
2570 SELECTION_OPEN_SUBMENU); 2573 SELECTION_OPEN_SUBMENU);
2571 } 2574 }
2572 } 2575 }
2573 2576
2574 gfx::Screen* MenuController::GetScreen() {
2575 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2576 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2577 : gfx::Screen::GetNativeScreen();
2578 }
2579
2580 } // namespace views 2577 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/scrollbar/base_scroll_bar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698