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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // notification when the drag has finished. | 354 // notification when the drag has finished. |
355 StartCancelAllTimer(); | 355 StartCancelAllTimer(); |
356 } | 356 } |
357 return NULL; | 357 return NULL; |
358 } | 358 } |
359 | 359 |
360 if (button) | 360 if (button) |
361 pressed_lock_.reset(new MenuButton::PressedLock(button)); | 361 pressed_lock_.reset(new MenuButton::PressedLock(button)); |
362 | 362 |
363 // Make sure Chrome doesn't attempt to shut down while the menu is showing. | 363 // Make sure Chrome doesn't attempt to shut down while the menu is showing. |
364 if (ViewsDelegate::views_delegate) | 364 if (ViewsDelegate::GetInstance()) |
365 ViewsDelegate::views_delegate->AddRef(); | 365 ViewsDelegate::GetInstance()->AddRef(); |
366 | 366 |
367 // We need to turn on nestable tasks as in some situations (pressing alt-f for | 367 // We need to turn on nestable tasks as in some situations (pressing alt-f for |
368 // one) the menus are run from a task. If we don't do this and are invoked | 368 // one) the menus are run from a task. If we don't do this and are invoked |
369 // from a task none of the tasks we schedule are processed and the menu | 369 // from a task none of the tasks we schedule are processed and the menu |
370 // appears totally broken. | 370 // appears totally broken. |
371 message_loop_depth_++; | 371 message_loop_depth_++; |
372 DCHECK_LE(message_loop_depth_, 2); | 372 DCHECK_LE(message_loop_depth_, 2); |
373 RunMessageLoop(nested_menu); | 373 RunMessageLoop(nested_menu); |
374 message_loop_depth_--; | 374 message_loop_depth_--; |
375 | 375 |
376 if (ViewsDelegate::views_delegate) | 376 if (ViewsDelegate::GetInstance()) |
377 ViewsDelegate::views_delegate->ReleaseRef(); | 377 ViewsDelegate::GetInstance()->ReleaseRef(); |
378 | 378 |
379 // Close any open menus. | 379 // Close any open menus. |
380 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); | 380 SetSelection(NULL, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); |
381 | 381 |
382 #if defined(OS_WIN) | 382 #if defined(OS_WIN) |
383 // On Windows, if we select the menu item by touch and if the window at the | 383 // On Windows, if we select the menu item by touch and if the window at the |
384 // location is another window on the same thread, that window gets a | 384 // location is another window on the same thread, that window gets a |
385 // WM_MOUSEACTIVATE message and ends up activating itself, which is not | 385 // WM_MOUSEACTIVATE message and ends up activating itself, which is not |
386 // correct. We workaround this by setting a property on the window at the | 386 // correct. We workaround this by setting a property on the window at the |
387 // current cursor location. We check for this property in our | 387 // current cursor location. We check for this property in our |
(...skipping 1730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 | 2118 |
2119 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); | 2119 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); |
2120 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); | 2120 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); |
2121 | 2121 |
2122 #if defined(OS_WIN) | 2122 #if defined(OS_WIN) |
2123 // Convert screen_loc to pixels for the Win32 API's like WindowFromPoint, | 2123 // Convert screen_loc to pixels for the Win32 API's like WindowFromPoint, |
2124 // PostMessage/SendMessage to work correctly. These API's expect the | 2124 // PostMessage/SendMessage to work correctly. These API's expect the |
2125 // coordinates to be in pixels. | 2125 // coordinates to be in pixels. |
2126 // PostMessage() to metro windows isn't allowed (access will be denied). Don't | 2126 // PostMessage() to metro windows isn't allowed (access will be denied). Don't |
2127 // try to repost with Win32 if the window under the mouse press is in metro. | 2127 // try to repost with Win32 if the window under the mouse press is in metro. |
2128 if (!ViewsDelegate::views_delegate || | 2128 if (!ViewsDelegate::GetInstance() || |
2129 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) { | 2129 !ViewsDelegate::GetInstance()->IsWindowInMetro(window)) { |
2130 gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc); | 2130 gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc); |
2131 HWND target_window = window ? HWNDForNativeWindow(window) : | 2131 HWND target_window = window ? HWNDForNativeWindow(window) : |
2132 WindowFromPoint(screen_loc_pixels.ToPOINT()); | 2132 WindowFromPoint(screen_loc_pixels.ToPOINT()); |
2133 HWND source_window = HWNDForNativeView(native_view); | 2133 HWND source_window = HWNDForNativeView(native_view); |
2134 if (!target_window || !source_window || | 2134 if (!target_window || !source_window || |
2135 GetWindowThreadProcessId(source_window, NULL) != | 2135 GetWindowThreadProcessId(source_window, NULL) != |
2136 GetWindowThreadProcessId(target_window, NULL)) { | 2136 GetWindowThreadProcessId(target_window, NULL)) { |
2137 // Even though we have mouse capture, windows generates a mouse event if | 2137 // Even though we have mouse capture, windows generates a mouse event if |
2138 // the other window is in a separate thread. Only repost an event if | 2138 // the other window is in a separate thread. Only repost an event if |
2139 // |target_window| and |source_window| were created on the same thread, | 2139 // |target_window| and |source_window| were created on the same thread, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2357 } | 2357 } |
2358 } | 2358 } |
2359 | 2359 |
2360 gfx::Screen* MenuController::GetScreen() { | 2360 gfx::Screen* MenuController::GetScreen() { |
2361 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; | 2361 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; |
2362 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) | 2362 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) |
2363 : gfx::Screen::GetNativeScreen(); | 2363 : gfx::Screen::GetNativeScreen(); |
2364 } | 2364 } |
2365 | 2365 |
2366 } // namespace views | 2366 } // namespace views |
OLD | NEW |