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

Side by Side Diff: ui/views/controls/menu/menu_host.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_host.h" 5 #include "ui/views/controls/menu/menu_host.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ui/events/gestures/gesture_recognizer.h" 10 #include "ui/events/gestures/gesture_recognizer.h"
11 #include "ui/gfx/path.h" 11 #include "ui/gfx/path.h"
12 #include "ui/native_theme/native_theme.h" 12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/controls/menu/menu_controller.h" 13 #include "ui/views/controls/menu/menu_controller.h"
14 #include "ui/views/controls/menu/menu_host_root_view.h" 14 #include "ui/views/controls/menu/menu_host_root_view.h"
15 #include "ui/views/controls/menu/menu_item_view.h" 15 #include "ui/views/controls/menu/menu_item_view.h"
16 #include "ui/views/controls/menu/menu_scroll_view_container.h" 16 #include "ui/views/controls/menu/menu_scroll_view_container.h"
17 #include "ui/views/controls/menu/submenu_view.h" 17 #include "ui/views/controls/menu/submenu_view.h"
18 #include "ui/views/round_rect_painter.h" 18 #include "ui/views/round_rect_painter.h"
19 #include "ui/views/widget/native_widget_private.h" 19 #include "ui/views/widget/native_widget_private.h"
20 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
21 21
22 #if !defined(OS_MACOSX)
23 #include "ui/aura/window.h"
24 #endif
25
22 namespace views { 26 namespace views {
23 27
28 namespace internal {
29
30 #if !defined(OS_MACOSX)
31 // This class adds itself as the pre target handler for the |window|
32 // passed in. It currently handles touch events and forwards them to the
33 // controller. Reason for this approach is views does not get raw touch
34 // events which we need to determine if a touch happened outside the bounds
35 // of the menu.
36 class PreMenuEventDispatchHandler : public ui::EventHandler {
37 public:
38 explicit PreMenuEventDispatchHandler(const MenuController* controller,
39 SubmenuView* submenu,
40 aura::Window* window)
41 : menu_controller_(const_cast<MenuController*>(controller)),
42 submenu_(submenu),
43 window_(window) {
44 window_->AddPreTargetHandler(this);
45 }
46
47 ~PreMenuEventDispatchHandler() override {
48 window_->RemovePreTargetHandler(this);
49 }
50
51 // ui::EventHandler overrides.
52 void OnTouchEvent(ui::TouchEvent* event) override {
53 menu_controller_->OnTouchEvent(submenu_, event);
54 }
55
56 private:
57 MenuController* menu_controller_;
58 SubmenuView* submenu_;
59 aura::Window* window_;
60
61 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler);
62 };
63 #endif // OS_MACOSX
64
65 } // namespace internal
66
24 //////////////////////////////////////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////////////
25 // MenuHost, public: 68 // MenuHost, public:
26 69
27 MenuHost::MenuHost(SubmenuView* submenu) 70 MenuHost::MenuHost(SubmenuView* submenu)
28 : submenu_(submenu), 71 : submenu_(submenu),
29 destroying_(false), 72 destroying_(false),
30 ignore_capture_lost_(false) { 73 ignore_capture_lost_(false) {
31 set_auto_release_capture(false); 74 set_auto_release_capture(false);
32 } 75 }
33 76
(...skipping 20 matching lines...) Expand all
54 params.parent = parent ? parent->GetNativeView() : NULL; 97 params.parent = parent ? parent->GetNativeView() : NULL;
55 params.bounds = bounds; 98 params.bounds = bounds;
56 #if defined(OS_WIN) 99 #if defined(OS_WIN)
57 // On Windows use the software compositor to ensure that we don't block 100 // On Windows use the software compositor to ensure that we don't block
58 // the UI thread blocking issue during command buffer creation. We can 101 // the UI thread blocking issue during command buffer creation. We can
59 // revert this change once http://crbug.com/125248 is fixed. 102 // revert this change once http://crbug.com/125248 is fixed.
60 params.force_software_compositing = true; 103 params.force_software_compositing = true;
61 #endif 104 #endif
62 Init(params); 105 Init(params);
63 106
107 #if !defined(OS_MACOSX)
108 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler(
109 menu_controller, submenu_, GetNativeView()));
110 #endif
111
64 SetContentsView(contents_view); 112 SetContentsView(contents_view);
65 ShowMenuHost(do_capture); 113 ShowMenuHost(do_capture);
66 } 114 }
67 115
68 bool MenuHost::IsMenuHostVisible() { 116 bool MenuHost::IsMenuHostVisible() {
69 return IsVisible(); 117 return IsVisible();
70 } 118 }
71 119
72 void MenuHost::ShowMenuHost(bool do_capture) { 120 void MenuHost::ShowMenuHost(bool do_capture) {
73 // Doing a capture may make us get capture lost. Ignore it while we're in the 121 // Doing a capture may make us get capture lost. Ignore it while we're in the
(...skipping 12 matching lines...) Expand all
86 ignore_capture_lost_ = true; 134 ignore_capture_lost_ = true;
87 ReleaseMenuHostCapture(); 135 ReleaseMenuHostCapture();
88 Hide(); 136 Hide();
89 ignore_capture_lost_ = false; 137 ignore_capture_lost_ = false;
90 } 138 }
91 139
92 void MenuHost::DestroyMenuHost() { 140 void MenuHost::DestroyMenuHost() {
93 HideMenuHost(); 141 HideMenuHost();
94 destroying_ = true; 142 destroying_ = true;
95 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); 143 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
144 #if !defined(OS_MACOSX)
145 pre_dispatch_handler_.reset();
146 #endif
96 Close(); 147 Close();
97 } 148 }
98 149
99 void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) { 150 void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) {
100 SetBounds(bounds); 151 SetBounds(bounds);
101 } 152 }
102 153
103 void MenuHost::ReleaseMenuHostCapture() { 154 void MenuHost::ReleaseMenuHostCapture() {
104 if (native_widget_private()->HasCapture()) 155 if (native_widget_private()->HasCapture())
105 native_widget_private()->ReleaseCapture(); 156 native_widget_private()->ReleaseCapture();
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 217 }
167 menu_controller->OnDragComplete(should_close); 218 menu_controller->OnDragComplete(should_close);
168 219
169 // We may have lost capture in the drag and drop, but are remaining open. 220 // We may have lost capture in the drag and drop, but are remaining open.
170 // Return capture so we get MouseCaptureLost events. 221 // Return capture so we get MouseCaptureLost events.
171 if (!should_close) 222 if (!should_close)
172 native_widget_private()->SetCapture(); 223 native_widget_private()->SetCapture();
173 } 224 }
174 225
175 } // namespace views 226 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698