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

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

Issue 1565013002: Don't send touch events to windows like menus when the touch occurs outside the menu bounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build redness 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 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 672 }
673 673
674 if (event->stopped_propagation()) 674 if (event->stopped_propagation())
675 return; 675 return;
676 676
677 if (!part.submenu) 677 if (!part.submenu)
678 return; 678 return;
679 part.submenu->OnGestureEvent(event); 679 part.submenu->OnGestureEvent(event);
680 } 680 }
681 681
682 void MenuController::OnTouchEvent(SubmenuView* source, ui::TouchEvent* event) {
683 if (event->type() == ui::ET_TOUCH_PRESSED) {
684 MenuPart part = GetMenuPart(source, event->location());
685 if (part.type == MenuPart::NONE) {
686 RepostEvent(source, *event);
sky 2016/01/12 21:16:42 If you repostevent don't you need to stop propagat
ananta 2016/01/13 01:21:24 Done.
687 }
688 }
689 }
690
682 View* MenuController::GetTooltipHandlerForPoint(SubmenuView* source, 691 View* MenuController::GetTooltipHandlerForPoint(SubmenuView* source,
683 const gfx::Point& point) { 692 const gfx::Point& point) {
684 MenuHostRootView* root_view = GetRootView(source, point); 693 MenuHostRootView* root_view = GetRootView(source, point);
685 return root_view ? root_view->ProcessGetTooltipHandlerForPoint(point) 694 return root_view ? root_view->ProcessGetTooltipHandlerForPoint(point)
686 : nullptr; 695 : nullptr;
687 } 696 }
688 697
689 void MenuController::ViewHierarchyChanged( 698 void MenuController::ViewHierarchyChanged(
690 SubmenuView* source, 699 SubmenuView* source,
691 const View::ViewHierarchyChangedDetails& details) { 700 const View::ViewHierarchyChangedDetails& details) {
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 972
964 // Notify an accessibility focus event on all menu items except for the root. 973 // Notify an accessibility focus event on all menu items except for the root.
965 if (menu_item && 974 if (menu_item &&
966 (MenuDepth(menu_item) != 1 || 975 (MenuDepth(menu_item) != 1 ||
967 menu_item->GetType() != MenuItemView::SUBMENU)) { 976 menu_item->GetType() != MenuItemView::SUBMENU)) {
968 menu_item->NotifyAccessibilityEvent( 977 menu_item->NotifyAccessibilityEvent(
969 ui::AX_EVENT_FOCUS, true); 978 ui::AX_EVENT_FOCUS, true);
970 } 979 }
971 } 980 }
972 981
982 template<class EventType>
973 void MenuController::SetSelectionOnPointerDown(SubmenuView* source, 983 void MenuController::SetSelectionOnPointerDown(SubmenuView* source,
974 const ui::LocatedEvent& event) { 984 const EventType& event) {
975 if (!blocking_run_) 985 if (!blocking_run_)
976 return; 986 return;
977 987
978 DCHECK(!GetActiveMouseView()); 988 DCHECK(!GetActiveMouseView());
979 989
980 MenuPart part = GetMenuPart(source, event.location()); 990 MenuPart part = GetMenuPart(source, event.location());
981 if (part.is_scroll()) 991 if (part.is_scroll())
982 return; // Ignore presses on scroll buttons. 992 return; // Ignore presses on scroll buttons.
983 993
984 // When this menu is opened through a touch event, a simulated right-click 994 // When this menu is opened through a touch event, a simulated right-click
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 if (is_combobox_) { 2185 if (is_combobox_) {
2176 item->GetSubmenu()->GetPrefixSelector()->InsertText(char_array); 2186 item->GetSubmenu()->GetPrefixSelector()->InsertText(char_array);
2177 } else { 2187 } else {
2178 // If no mnemonics found, look at first character of titles. 2188 // If no mnemonics found, look at first character of titles.
2179 details = FindChildForMnemonic(item, key, &TitleMatchesMnemonic); 2189 details = FindChildForMnemonic(item, key, &TitleMatchesMnemonic);
2180 if (details.first_match != -1) 2190 if (details.first_match != -1)
2181 AcceptOrSelect(item, details); 2191 AcceptOrSelect(item, details);
2182 } 2192 }
2183 } 2193 }
2184 2194
2195 template<class EventType>
2185 void MenuController::RepostEvent(SubmenuView* source, 2196 void MenuController::RepostEvent(SubmenuView* source,
2186 const ui::LocatedEvent& event) { 2197 const EventType& event) {
2187 if (!event.IsMouseEvent()) { 2198 if (!event.IsMouseEvent() && !event.IsTouchEvent()) {
2188 // TODO(rbyers): Gesture event repost is tricky to get right 2199 // TODO(rbyers): Gesture event repost is tricky to get right
2189 // crbug.com/170987. 2200 // crbug.com/170987.
2190 DCHECK(event.IsGestureEvent()); 2201 DCHECK(event.IsGestureEvent());
2191 return; 2202 return;
2192 } 2203 }
2193 2204
2194 #if defined(OS_WIN) 2205 #if defined(OS_WIN)
2195 if (!state_.item) { 2206 if (!state_.item) {
2196 // We some times get an event after closing all the menus. Ignore it. Make 2207 // We some times get an event after closing all the menus. Ignore it. Make
2197 // sure the menu is in fact not visible. If the menu is visible, then 2208 // sure the menu is in fact not visible. If the menu is visible, then
(...skipping 13 matching lines...) Expand all
2211 2222
2212 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view); 2223 gfx::Screen* screen = gfx::Screen::GetScreenFor(native_view);
2213 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc); 2224 gfx::NativeWindow window = screen->GetWindowAtScreenPoint(screen_loc);
2214 2225
2215 #if defined(OS_WIN) 2226 #if defined(OS_WIN)
2216 // Convert screen_loc to pixels for the Win32 API's like WindowFromPoint, 2227 // Convert screen_loc to pixels for the Win32 API's like WindowFromPoint,
2217 // PostMessage/SendMessage to work correctly. These API's expect the 2228 // PostMessage/SendMessage to work correctly. These API's expect the
2218 // coordinates to be in pixels. 2229 // coordinates to be in pixels.
2219 // PostMessage() to metro windows isn't allowed (access will be denied). Don't 2230 // PostMessage() to metro windows isn't allowed (access will be denied). Don't
2220 // try to repost with Win32 if the window under the mouse press is in metro. 2231 // try to repost with Win32 if the window under the mouse press is in metro.
2221 if (!ViewsDelegate::GetInstance() || 2232 if (event.IsMouseEvent() && (!ViewsDelegate::GetInstance() ||
2222 !ViewsDelegate::GetInstance()->IsWindowInMetro(window)) { 2233 !ViewsDelegate::GetInstance()->IsWindowInMetro(window))) {
2223 gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc); 2234 gfx::Point screen_loc_pixels = gfx::win::DIPToScreenPoint(screen_loc);
2224 HWND target_window = window ? HWNDForNativeWindow(window) : 2235 HWND target_window = window ? HWNDForNativeWindow(window) :
2225 WindowFromPoint(screen_loc_pixels.ToPOINT()); 2236 WindowFromPoint(screen_loc_pixels.ToPOINT());
2226 HWND source_window = HWNDForNativeView(native_view); 2237 HWND source_window = HWNDForNativeView(native_view);
2227 if (!target_window || !source_window || 2238 if (!target_window || !source_window ||
2228 GetWindowThreadProcessId(source_window, NULL) != 2239 GetWindowThreadProcessId(source_window, NULL) !=
2229 GetWindowThreadProcessId(target_window, NULL)) { 2240 GetWindowThreadProcessId(target_window, NULL)) {
2230 // Even though we have mouse capture, windows generates a mouse event if 2241 // Even though we have mouse capture, windows generates a mouse event if
2231 // the other window is in a separate thread. Only repost an event if 2242 // the other window is in a separate thread. Only repost an event if
2232 // |target_window| and |source_window| were created on the same thread, 2243 // |target_window| and |source_window| were created on the same thread,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result; 2279 WPARAM target = client_area ? event.native_event().wParam : nc_hit_result;
2269 LPARAM window_coords = MAKELPARAM(window_x, window_y); 2280 LPARAM window_coords = MAKELPARAM(window_x, window_y);
2270 PostMessage(target_window, event_type, target, window_coords); 2281 PostMessage(target_window, event_type, target, window_coords);
2271 return; 2282 return;
2272 } 2283 }
2273 #endif 2284 #endif
2274 // Non-Windows Aura or |window| is in metro mode. 2285 // Non-Windows Aura or |window| is in metro mode.
2275 if (!window) 2286 if (!window)
2276 return; 2287 return;
2277 2288
2278 MenuMessageLoop::RepostEventToWindow(event, window, screen_loc); 2289 if (event.IsTouchEvent()) {
2290 // Handle touch events in a posted task, as we don't want them to get
2291 // dispatched in the context of the menu message pump.
2292 base::MessageLoop::current()->PostTask(
2293 FROM_HERE,
2294 base::Bind(&MenuMessageLoop::RepostEventToWindow<EventType>,
sky 2016/01/12 21:16:42 RepostEventtoWindow() should post after a delay. Y
ananta 2016/01/13 01:21:24 Done.
2295 event, window, screen_loc));
2296 } else {
2297 MenuMessageLoop::RepostEventToWindow(event, window, screen_loc);
2298 }
2279 } 2299 }
2280 2300
2281 void MenuController::SetDropMenuItem( 2301 void MenuController::SetDropMenuItem(
2282 MenuItemView* new_target, 2302 MenuItemView* new_target,
2283 MenuDelegate::DropPosition new_position) { 2303 MenuDelegate::DropPosition new_position) {
2284 if (new_target == drop_target_ && new_position == drop_position_) 2304 if (new_target == drop_target_ && new_position == drop_position_)
2285 return; 2305 return;
2286 2306
2287 if (drop_target_) { 2307 if (drop_target_) {
2288 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem( 2308 drop_target_->GetParentMenuItem()->GetSubmenu()->SetDropMenuItem(
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 } 2551 }
2532 } 2552 }
2533 2553
2534 gfx::Screen* MenuController::GetScreen() { 2554 gfx::Screen* MenuController::GetScreen() {
2535 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; 2555 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2536 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) 2556 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2537 : gfx::Screen::GetNativeScreen(); 2557 : gfx::Screen::GetNativeScreen();
2538 } 2558 }
2539 2559
2540 } // namespace views 2560 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698