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" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "ui/aura/client/aura_constants.h" |
| 14 #include "ui/aura/window_tree_host.h" |
13 #include "ui/base/dragdrop/drag_utils.h" | 15 #include "ui/base/dragdrop/drag_utils.h" |
14 #include "ui/base/dragdrop/os_exchange_data.h" | 16 #include "ui/base/dragdrop/os_exchange_data.h" |
15 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
16 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
17 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
19 #include "ui/gfx/geometry/vector2d.h" | 21 #include "ui/gfx/geometry/vector2d.h" |
20 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
21 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
22 #include "ui/native_theme/native_theme.h" | 24 #include "ui/native_theme/native_theme.h" |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 DCHECK(!showing_); | 1210 DCHECK(!showing_); |
1209 if (owner_) | 1211 if (owner_) |
1210 owner_->RemoveObserver(this); | 1212 owner_->RemoveObserver(this); |
1211 if (active_instance_ == this) | 1213 if (active_instance_ == this) |
1212 active_instance_ = NULL; | 1214 active_instance_ = NULL; |
1213 StopShowTimer(); | 1215 StopShowTimer(); |
1214 StopCancelAllTimer(); | 1216 StopCancelAllTimer(); |
1215 } | 1217 } |
1216 | 1218 |
1217 void MenuController::RunMessageLoop(bool nested_menu) { | 1219 void MenuController::RunMessageLoop(bool nested_menu) { |
| 1220 #if defined(OS_WIN) |
| 1221 // Menus should be dismissed if we touch outside their bounds. |
| 1222 if (owner_ && owner_->GetNativeView()) { |
| 1223 owner_->GetNativeView()->SetProperty( |
| 1224 aura::client::kReleaseCaptureOnTouchOutside, true); |
| 1225 } |
| 1226 #endif |
1218 message_loop_->Run(this, owner_, nested_menu); | 1227 message_loop_->Run(this, owner_, nested_menu); |
1219 } | 1228 } |
1220 | 1229 |
1221 bool MenuController::SendAcceleratorToHotTrackedView() { | 1230 bool MenuController::SendAcceleratorToHotTrackedView() { |
1222 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); | 1231 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); |
1223 if (!hot_view) | 1232 if (!hot_view) |
1224 return false; | 1233 return false; |
1225 | 1234 |
1226 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 1235 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
1227 hot_view->AcceleratorPressed(accelerator); | 1236 hot_view->AcceleratorPressed(accelerator); |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 MenuItemView* MenuController::ExitMenuRun() { | 2430 MenuItemView* MenuController::ExitMenuRun() { |
2422 // Release the lock which prevents Chrome from shutting down while the menu is | 2431 // Release the lock which prevents Chrome from shutting down while the menu is |
2423 // showing. | 2432 // showing. |
2424 if (async_run_ && ViewsDelegate::GetInstance()) | 2433 if (async_run_ && ViewsDelegate::GetInstance()) |
2425 ViewsDelegate::GetInstance()->ReleaseRef(); | 2434 ViewsDelegate::GetInstance()->ReleaseRef(); |
2426 | 2435 |
2427 // Close any open menus. | 2436 // Close any open menus. |
2428 SetSelection(nullptr, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); | 2437 SetSelection(nullptr, SELECTION_UPDATE_IMMEDIATELY | SELECTION_EXIT); |
2429 | 2438 |
2430 #if defined(OS_WIN) | 2439 #if defined(OS_WIN) |
| 2440 if (owner_ && owner_->GetNativeView()) { |
| 2441 owner_->GetNativeView()->ClearProperty( |
| 2442 aura::client::kReleaseCaptureOnTouchOutside); |
| 2443 } |
2431 // On Windows, if we select the menu item by touch and if the window at the | 2444 // On Windows, if we select the menu item by touch and if the window at the |
2432 // location is another window on the same thread, that window gets a | 2445 // location is another window on the same thread, that window gets a |
2433 // WM_MOUSEACTIVATE message and ends up activating itself, which is not | 2446 // WM_MOUSEACTIVATE message and ends up activating itself, which is not |
2434 // correct. We workaround this by setting a property on the window at the | 2447 // correct. We workaround this by setting a property on the window at the |
2435 // current cursor location. We check for this property in our | 2448 // current cursor location. We check for this property in our |
2436 // WM_MOUSEACTIVATE handler and don't activate the window if the property is | 2449 // WM_MOUSEACTIVATE handler and don't activate the window if the property is |
2437 // set. | 2450 // set. |
2438 if (item_selected_by_touch_) { | 2451 if (item_selected_by_touch_) { |
2439 item_selected_by_touch_ = false; | 2452 item_selected_by_touch_ = false; |
2440 POINT cursor_pos; | 2453 POINT cursor_pos; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2531 } | 2544 } |
2532 } | 2545 } |
2533 | 2546 |
2534 gfx::Screen* MenuController::GetScreen() { | 2547 gfx::Screen* MenuController::GetScreen() { |
2535 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; | 2548 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; |
2536 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) | 2549 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) |
2537 : gfx::Screen::GetNativeScreen(); | 2550 : gfx::Screen::GetNativeScreen(); |
2538 } | 2551 } |
2539 | 2552 |
2540 } // namespace views | 2553 } // namespace views |
OLD | NEW |