| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // Period of the scroll timer (in milliseconds). | 43 // Period of the scroll timer (in milliseconds). |
| 44 static const int kScrollTimerMS = 30; | 44 static const int kScrollTimerMS = 30; |
| 45 | 45 |
| 46 // Delay, in ms, between when menus are selected are moused over and the menu | 46 // Delay, in ms, between when menus are selected are moused over and the menu |
| 47 // appears. | 47 // appears. |
| 48 static const int kShowDelay = 400; | 48 static const int kShowDelay = 400; |
| 49 | 49 |
| 50 // Amount of time from when the drop exits the menu and the menu is hidden. | 50 // Amount of time from when the drop exits the menu and the menu is hidden. |
| 51 static const int kCloseOnExitTime = 1200; | 51 static const int kCloseOnExitTime = 1200; |
| 52 | 52 |
| 53 // If a context menu is invoked by touch, we shift the menu by this offset so |
| 54 // that the finger does not obscure the menu. |
| 55 static const int kCenteredContextMenuYOffset = -15; |
| 56 |
| 53 namespace views { | 57 namespace views { |
| 54 | 58 |
| 55 namespace { | 59 namespace { |
| 56 | 60 |
| 57 // Returns true if the mnemonic of |menu| matches key. | 61 // Returns true if the mnemonic of |menu| matches key. |
| 58 bool MatchesMnemonic(MenuItemView* menu, char16 key) { | 62 bool MatchesMnemonic(MenuItemView* menu, char16 key) { |
| 59 return menu->GetMnemonic() == key; | 63 return menu->GetMnemonic() == key; |
| 60 } | 64 } |
| 61 | 65 |
| 62 // Returns true if |menu| doesn't have a mnemonic and first character of the its | 66 // Returns true if |menu| doesn't have a mnemonic and first character of the its |
| (...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 const gfx::Rect& bounds, | 1088 const gfx::Rect& bounds, |
| 1085 MenuItemView::AnchorPosition position, | 1089 MenuItemView::AnchorPosition position, |
| 1086 bool context_menu) { | 1090 bool context_menu) { |
| 1087 pending_state_.context_menu = context_menu; | 1091 pending_state_.context_menu = context_menu; |
| 1088 pending_state_.initial_bounds = bounds; | 1092 pending_state_.initial_bounds = bounds; |
| 1089 if (bounds.height() > 1) { | 1093 if (bounds.height() > 1) { |
| 1090 // Inset the bounds slightly, otherwise drag coordinates don't line up | 1094 // Inset the bounds slightly, otherwise drag coordinates don't line up |
| 1091 // nicely and menus close prematurely. | 1095 // nicely and menus close prematurely. |
| 1092 pending_state_.initial_bounds.Inset(0, 1); | 1096 pending_state_.initial_bounds.Inset(0, 1); |
| 1093 } | 1097 } |
| 1098 if (position == MenuItemView::BOTTOMCENTER) |
| 1099 pending_state_.initial_bounds.Offset(0, kCenteredContextMenuYOffset); |
| 1094 | 1100 |
| 1095 // Reverse anchor position for RTL languages. | 1101 // Reverse anchor position for RTL languages. |
| 1096 if (base::i18n::IsRTL()) { | 1102 if (base::i18n::IsRTL()) { |
| 1097 pending_state_.anchor = position == MenuItemView::TOPRIGHT ? | 1103 pending_state_.anchor = position == MenuItemView::TOPRIGHT ? |
| 1098 MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT; | 1104 MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT; |
| 1099 } else { | 1105 } else { |
| 1100 pending_state_.anchor = position; | 1106 pending_state_.anchor = position; |
| 1101 } | 1107 } |
| 1102 | 1108 |
| 1103 // Calculate the bounds of the monitor we'll show menus on. Do this once to | 1109 // Calculate the bounds of the monitor we'll show menus on. Do this once to |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2122 | 2128 |
| 2123 #if defined(USE_AURA) | 2129 #if defined(USE_AURA) |
| 2124 void MenuController::OnWindowActivated(aura::Window* active, | 2130 void MenuController::OnWindowActivated(aura::Window* active, |
| 2125 aura::Window* old_active) { | 2131 aura::Window* old_active) { |
| 2126 if (!drag_in_progress_) | 2132 if (!drag_in_progress_) |
| 2127 Cancel(EXIT_ALL); | 2133 Cancel(EXIT_ALL); |
| 2128 } | 2134 } |
| 2129 #endif | 2135 #endif |
| 2130 | 2136 |
| 2131 } // namespace views | 2137 } // namespace views |
| OLD | NEW |