OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/menu/menu_host_gtk.h" | 5 #include "views/controls/menu/menu_host_gtk.h" |
6 | 6 |
7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
8 | 8 |
9 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 9 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // window now, it means AcceleratorHandler attempts to use a window that has | 89 // window now, it means AcceleratorHandler attempts to use a window that has |
90 // been destroyed. | 90 // been destroyed. |
91 Close(); | 91 Close(); |
92 } | 92 } |
93 | 93 |
94 void MenuHostGtk::SetMenuHostBounds(const gfx::Rect& bounds) { | 94 void MenuHostGtk::SetMenuHostBounds(const gfx::Rect& bounds) { |
95 SetBounds(bounds); | 95 SetBounds(bounds); |
96 } | 96 } |
97 | 97 |
98 void MenuHostGtk::ReleaseMenuHostCapture() { | 98 void MenuHostGtk::ReleaseMenuHostCapture() { |
99 ReleaseNativeCapture(); | 99 ReleaseMouseCapture(); |
100 } | 100 } |
101 | 101 |
102 gfx::NativeWindow MenuHostGtk::GetMenuHostWindow() { | 102 gfx::NativeWindow MenuHostGtk::GetMenuHostWindow() { |
103 return GTK_WINDOW(GetNativeView()); | 103 return GTK_WINDOW(GetNativeView()); |
104 } | 104 } |
105 | 105 |
106 RootView* MenuHostGtk::CreateRootView() { | 106 RootView* MenuHostGtk::CreateRootView() { |
107 return new MenuHostRootView(this, submenu_); | 107 return new MenuHostRootView(this, submenu_); |
108 } | 108 } |
109 | 109 |
110 bool MenuHostGtk::ReleaseCaptureOnMouseReleased() { | 110 bool MenuHostGtk::ShouldReleaseCaptureOnMouseReleased() const { |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 void MenuHostGtk::ReleaseNativeCapture() { | 114 void MenuHostGtk::ReleaseMouseCapture() { |
115 WidgetGtk::ReleaseNativeCapture(); | 115 WidgetGtk::ReleaseMouseCapture(); |
116 if (did_input_grab_) { | 116 if (did_input_grab_) { |
117 did_input_grab_ = false; | 117 did_input_grab_ = false; |
118 gdk_pointer_ungrab(GDK_CURRENT_TIME); | 118 gdk_pointer_ungrab(GDK_CURRENT_TIME); |
119 gdk_keyboard_ungrab(GDK_CURRENT_TIME); | 119 gdk_keyboard_ungrab(GDK_CURRENT_TIME); |
120 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) | 120 #if defined(HAVE_XINPUT2) && defined(TOUCH_UI) |
121 TouchFactory::GetInstance()->UngrabTouchDevices( | 121 TouchFactory::GetInstance()->UngrabTouchDevices( |
122 GDK_WINDOW_XDISPLAY(window_contents()->window)); | 122 GDK_WINDOW_XDISPLAY(window_contents()->window)); |
123 #endif | 123 #endif |
124 } | 124 } |
125 } | 125 } |
(...skipping 13 matching lines...) Expand all Loading... |
139 if (did_input_grab_ && !destroying_) { | 139 if (did_input_grab_ && !destroying_) { |
140 did_input_grab_ = false; | 140 did_input_grab_ = false; |
141 CancelAllIfNoDrag(); | 141 CancelAllIfNoDrag(); |
142 } | 142 } |
143 WidgetGtk::HandleXGrabBroke(); | 143 WidgetGtk::HandleXGrabBroke(); |
144 } | 144 } |
145 | 145 |
146 void MenuHostGtk::HandleGtkGrabBroke() { | 146 void MenuHostGtk::HandleGtkGrabBroke() { |
147 // Grab can be broken by drag & drop, other menu or screen locker. | 147 // Grab can be broken by drag & drop, other menu or screen locker. |
148 if (did_input_grab_ && !destroying_) { | 148 if (did_input_grab_ && !destroying_) { |
149 ReleaseNativeCapture(); | 149 ReleaseMouseCapture(); |
150 CancelAllIfNoDrag(); | 150 CancelAllIfNoDrag(); |
151 } | 151 } |
152 WidgetGtk::HandleGtkGrabBroke(); | 152 WidgetGtk::HandleGtkGrabBroke(); |
153 } | 153 } |
154 | 154 |
155 void MenuHostGtk::DoCapture() { | 155 void MenuHostGtk::DoCapture() { |
156 DCHECK(!did_input_grab_); | 156 DCHECK(!did_input_grab_); |
157 | 157 |
158 // Release the current grab. | 158 // Release the current grab. |
159 GtkWidget* current_grab_window = gtk_grab_get_current(); | 159 GtkWidget* current_grab_window = gtk_grab_get_current(); |
160 if (current_grab_window) | 160 if (current_grab_window) |
161 gtk_grab_remove(current_grab_window); | 161 gtk_grab_remove(current_grab_window); |
162 | 162 |
163 // Make sure all app mouse/keyboard events are targetted at us only. | 163 // Make sure all app mouse/keyboard events are targetted at us only. |
164 SetNativeCapture(); | 164 SetMouseCapture(); |
165 | 165 |
166 // And do a grab. NOTE: we do this to ensure we get mouse/keyboard | 166 // And do a grab. NOTE: we do this to ensure we get mouse/keyboard |
167 // events from other apps, a grab done with gtk_grab_add doesn't get | 167 // events from other apps, a grab done with gtk_grab_add doesn't get |
168 // events from other apps. | 168 // events from other apps. |
169 GdkGrabStatus pointer_grab_status = | 169 GdkGrabStatus pointer_grab_status = |
170 gdk_pointer_grab(window_contents()->window, FALSE, | 170 gdk_pointer_grab(window_contents()->window, FALSE, |
171 static_cast<GdkEventMask>( | 171 static_cast<GdkEventMask>( |
172 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | 172 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | |
173 GDK_POINTER_MOTION_MASK), | 173 GDK_POINTER_MOTION_MASK), |
174 NULL, NULL, GDK_CURRENT_TIME); | 174 NULL, NULL, GDK_CURRENT_TIME); |
(...skipping 20 matching lines...) Expand all Loading... |
195 | 195 |
196 void MenuHostGtk::CancelAllIfNoDrag() { | 196 void MenuHostGtk::CancelAllIfNoDrag() { |
197 MenuController* menu_controller = | 197 MenuController* menu_controller = |
198 submenu_->GetMenuItem()->GetMenuController(); | 198 submenu_->GetMenuItem()->GetMenuController(); |
199 if (menu_controller && | 199 if (menu_controller && |
200 !menu_controller->drag_in_progress()) | 200 !menu_controller->drag_in_progress()) |
201 menu_controller->CancelAll(); | 201 menu_controller->CancelAll(); |
202 } | 202 } |
203 | 203 |
204 } // namespace views | 204 } // namespace views |
OLD | NEW |