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

Side by Side Diff: views/controls/menu/menu_host_gtk.cc

Issue 6756043: Consolidate Widget Event code, other cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Additional code consolidation, move base defs, nix MakeMSG, TooltipManager cleanup, etc. Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 29
30 MenuHostGtk::MenuHostGtk(SubmenuView* submenu) 30 MenuHostGtk::MenuHostGtk(SubmenuView* submenu)
31 : WidgetGtk(WidgetGtk::TYPE_POPUP), 31 : WidgetGtk(WidgetGtk::TYPE_POPUP),
32 destroying_(false), 32 destroying_(false),
33 submenu_(submenu), 33 submenu_(submenu),
34 did_input_grab_(false) { 34 did_input_grab_(false) {
35 GdkEvent* event = gtk_get_current_event(); 35 GdkEvent* event = gtk_get_current_event();
36 if (event) { 36 if (event) {
37 if (event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS || 37 if (event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS ||
38 event->type == GDK_3BUTTON_PRESS) { 38 event->type == GDK_3BUTTON_PRESS) {
39 set_mouse_down(true); 39 is_mouse_button_pressed_ = true;
40 } 40 }
41 gdk_event_free(event); 41 gdk_event_free(event);
42 } 42 }
43 CreateParams params; 43 CreateParams params;
44 params.type = CreateParams::TYPE_MENU; 44 params.type = CreateParams::TYPE_MENU;
45 params.has_dropshadow = true; 45 params.has_dropshadow = true;
46 SetCreateParams(params); 46 SetCreateParams(params);
47 } 47 }
48 48
49 MenuHostGtk::~MenuHostGtk() { 49 MenuHostGtk::~MenuHostGtk() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698