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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // the menu item on the subsequent mouse up. To prevent this, we add the | 66 // the menu item on the subsequent mouse up. To prevent this, we add the |
67 // following delay before the user is able to select an item. | 67 // following delay before the user is able to select an item. |
68 int menu_selection_hold_time_ms = kMinimumMsPressedToActivate; | 68 int menu_selection_hold_time_ms = kMinimumMsPressedToActivate; |
69 | 69 |
70 // Period of the scroll timer (in milliseconds). | 70 // Period of the scroll timer (in milliseconds). |
71 const int kScrollTimerMS = 30; | 71 const int kScrollTimerMS = 30; |
72 | 72 |
73 // Amount of time from when the drop exits the menu and the menu is hidden. | 73 // Amount of time from when the drop exits the menu and the menu is hidden. |
74 const int kCloseOnExitTime = 1200; | 74 const int kCloseOnExitTime = 1200; |
75 | 75 |
76 // If a context menu is invoked by touch, we shift the menu by this offset so | |
77 // that the finger does not obscure the menu. | |
78 const int kCenteredContextMenuYOffset = -15; | |
minch1
2017/05/04 16:44:15
Sorry, not quite sure about here. This is not need
msw
2017/05/05 17:34:19
This seems wrong, it'll change the positioning of
| |
79 | |
80 // The spacing offset for the bubble tip. | 76 // The spacing offset for the bubble tip. |
81 const int kBubbleTipSizeLeftRight = 12; | 77 const int kBubbleTipSizeLeftRight = 12; |
82 const int kBubbleTipSizeTopBottom = 11; | 78 const int kBubbleTipSizeTopBottom = 11; |
83 | 79 |
84 // The maximum distance (in DIPS) that the mouse can be moved before it should | 80 // The maximum distance (in DIPS) that the mouse can be moved before it should |
85 // trigger a mouse menu item activation (regardless of how long the menu has | 81 // trigger a mouse menu item activation (regardless of how long the menu has |
86 // been showing). | 82 // been showing). |
87 const float kMaximumLengthMovedToActivate = 4.0f; | 83 const float kMaximumLengthMovedToActivate = 4.0f; |
88 | 84 |
89 // Returns true if the mnemonic of |menu| matches key. | 85 // Returns true if the mnemonic of |menu| matches key. |
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1944 if (menu_config.offset_context_menus && state_.context_menu) | 1940 if (menu_config.offset_context_menus && state_.context_menu) |
1945 x += 1; | 1941 x += 1; |
1946 | 1942 |
1947 y = state_.initial_bounds.bottom(); | 1943 y = state_.initial_bounds.bottom(); |
1948 if (state_.anchor == MENU_ANCHOR_TOPRIGHT) { | 1944 if (state_.anchor == MENU_ANCHOR_TOPRIGHT) { |
1949 x = x + state_.initial_bounds.width() - pref.width(); | 1945 x = x + state_.initial_bounds.width() - pref.width(); |
1950 if (menu_config.offset_context_menus && state_.context_menu) | 1946 if (menu_config.offset_context_menus && state_.context_menu) |
1951 x -= 1; | 1947 x -= 1; |
1952 } else if (state_.anchor == MENU_ANCHOR_BOTTOMCENTER) { | 1948 } else if (state_.anchor == MENU_ANCHOR_BOTTOMCENTER) { |
1953 x = x - (pref.width() - state_.initial_bounds.width()) / 2; | 1949 x = x - (pref.width() - state_.initial_bounds.width()) / 2; |
1954 if (pref.height() > | 1950 // If menu does not fit above the anchor. We move it to below. |
msw
2017/05/05 17:34:19
nit: "Place the menu below the anchor if it does n
| |
1955 state_.initial_bounds.y() + kCenteredContextMenuYOffset) { | 1951 y = pref.height() > state_.initial_bounds.y() |
1956 // Menu does not fit above the anchor. We move it to below. | 1952 ? state_.initial_bounds.y() |
1957 y = state_.initial_bounds.y() - kCenteredContextMenuYOffset; | 1953 : (state_.initial_bounds.y() - pref.height()); |
1958 } else { | 1954 } else if (state_.anchor == MENU_ANCHOR_SIDECENTER) { |
1959 y = std::max(0, state_.initial_bounds.y() - pref.height()) + | 1955 y = y - (pref.height() - state_.initial_bounds.height()) / 2; |
msw
2017/05/05 17:34:19
nit: y -= (or += with subtraction reversed might b
| |
1960 kCenteredContextMenuYOffset; | |
1961 } | |
1962 } | 1956 } |
1963 | 1957 |
1964 if (!state_.monitor_bounds.IsEmpty() && | 1958 if (!state_.monitor_bounds.IsEmpty() && |
1965 y + pref.height() > state_.monitor_bounds.bottom()) { | 1959 y + pref.height() > state_.monitor_bounds.bottom()) { |
1966 // The menu doesn't fit fully below the button on the screen. The menu | 1960 // The menu doesn't fit fully below the button on the screen. The menu |
1967 // position with respect to the bounds will be preserved if it has | 1961 // position with respect to the bounds will be preserved if it has |
1968 // already been drawn. When the requested positioning is below the bounds | 1962 // already been drawn. When the requested positioning is below the bounds |
1969 // it will shrink the menu to make it fit below. | 1963 // it will shrink the menu to make it fit below. |
1970 // If the requested positioning is best fit, it will first try to fit the | 1964 // If the requested positioning is best fit, it will first try to fit the |
1971 // menu below. If that does not fit it will try to place it above. If | 1965 // menu below. If that does not fit it will try to place it above. If |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2710 if (hot_button_) | 2704 if (hot_button_) |
2711 hot_button_->SetHotTracked(false); | 2705 hot_button_->SetHotTracked(false); |
2712 hot_button_ = hot_button; | 2706 hot_button_ = hot_button; |
2713 if (hot_button) { | 2707 if (hot_button) { |
2714 hot_button->SetHotTracked(true); | 2708 hot_button->SetHotTracked(true); |
2715 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); | 2709 hot_button->NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); |
2716 } | 2710 } |
2717 } | 2711 } |
2718 | 2712 |
2719 } // namespace views | 2713 } // namespace views |
OLD | NEW |