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

Side by Side Diff: chrome/browser/chromeos/login/screen_locker.cc

Issue 5043002: A workaround to close currently opened menu. Send escape key if screen locker fails to grab input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 10 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/screen_locker.h" 5 #include "chrome/browser/chromeos/login/screen_locker.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 #include <X11/extensions/XTest.h>
10 #include <X11/keysym.h>
9 11
10 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "app/x11_util.h"
Daniel Erat 2010/11/16 21:58:06 still needs to be sorted
oshima 2010/11/17 01:00:43 Done.
11 #include "app/resource_bundle.h" 14 #include "app/resource_bundle.h"
12 #include "base/command_line.h" 15 #include "base/command_line.h"
13 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
14 #include "base/message_loop.h" 17 #include "base/message_loop.h"
15 #include "base/singleton.h" 18 #include "base/singleton.h"
16 #include "base/string_util.h" 19 #include "base/string_util.h"
17 #include "base/timer.h" 20 #include "base/timer.h"
18 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
19 #include "chrome/browser/browser_list.h" 22 #include "chrome/browser/browser_list.h"
20 #include "chrome/browser/browser_thread.h" 23 #include "chrome/browser/browser_thread.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 kbd_grab_status_(GDK_GRAB_INVALID_TIME), 272 kbd_grab_status_(GDK_GRAB_INVALID_TIME),
270 mouse_grab_status_(GDK_GRAB_INVALID_TIME) { 273 mouse_grab_status_(GDK_GRAB_INVALID_TIME) {
271 } 274 }
272 275
273 virtual void Show() { 276 virtual void Show() {
274 views::WidgetGtk::Show(); 277 views::WidgetGtk::Show();
275 } 278 }
276 279
277 void ClearGrab() { 280 void ClearGrab() {
278 GtkWidget* current_grab_window; 281 GtkWidget* current_grab_window;
279 // Grab gtk input first so that the menu holding grab will close itself. 282 // Grab gtk input first so that the menu holding gtk grab will
283 // close itself.
280 gtk_grab_add(window_contents()); 284 gtk_grab_add(window_contents());
281 285
282 // Make sure there is no grab widget so that gtk simply propagates 286 // Make sure there is no gtl grab widget so that gtk simply propagates
Daniel Erat 2010/11/16 21:58:06 s/gtl/gtk/
oshima 2010/11/17 01:00:43 Done.
283 // an event. This is necessary to allow message bubble and password 287 // an event. This is necessary to allow message bubble and password
284 // field, button to process events simultaneously. GTK 288 // field, button to process events simultaneously. GTK
285 // maintains grab widgets in a linked-list, so we need to remove 289 // maintains grab widgets in a linked-list, so we need to remove
286 // until it's empty. 290 // until it's empty.
287 while ((current_grab_window = gtk_grab_get_current()) != NULL) 291 while ((current_grab_window = gtk_grab_get_current()) != NULL)
288 gtk_grab_remove(current_grab_window); 292 gtk_grab_remove(current_grab_window);
293
294 #if !defined(NDEBUG)
295 {
296 int event_base, error_base;
297 int major, minor;
298 // Make sure we have XTest extension.
299 DCHECK(XTestQueryExtension(x11_util::GetXDisplay(),
300 &event_base, &error_base,
301 &major, &minor));
302 }
303 #endif
304
305 // The following code is an attempt to grab inputs by closing
306 // supposedly opened menu. This happens when a plugin has a menu
307 // opened.
308 if (kbd_grab_status_ == GDK_GRAB_ALREADY_GRABBED ||
309 kbd_grab_status_ == GDK_GRAB_FROZEN) {
310 // Send escape key if the keyboard is grabbed by other client.
311 Display* display = x11_util::GetXDisplay();
Daniel Erat 2010/11/16 21:58:06 So the reason for adding a server grab around this
312 KeyCode escape = XKeysymToKeycode(display, XK_Escape); // escape
313 XTestFakeKeyEvent(display, escape, True, CurrentTime);
314 XTestFakeKeyEvent(display, escape, False, CurrentTime);
315 XFlush(display);
316 } else if (mouse_grab_status_ == GDK_GRAB_ALREADY_GRABBED ||
Daniel Erat 2010/11/16 21:58:06 why 'else if' instead of keeping this as an indepe
317 mouse_grab_status_ == GDK_GRAB_FROZEN) {
Daniel Erat 2010/11/16 21:58:06 nit: indent this to line up with the mouse_grab_st
318 // Successfully grabbed the keyboard, but pointer is still
319 // grabbed by other client. Another attempt to close supposedly
320 // opened menu by emulating keypress at the left top corner.
321 Display* display = x11_util::GetXDisplay();
322 Window root, child;
323 int root_x, root_y, win_x, winy;
324 unsigned int mask;
325 XQueryPointer(display,
326 x11_util::GetX11WindowFromGtkWidget(window_contents()),
327 &root, &child, &root_x, &root_y,
328 &win_x, &winy, &mask);
329 XTestFakeMotionEvent(display, -1, -1, -1, CurrentTime);
Daniel Erat 2010/11/16 21:58:06 I'm a bit nervous about (-1, -1) being used; there
oshima 2010/11/17 01:00:43 changed to -10000, -10000
330 XTestFakeButtonEvent(display, 1, True, CurrentTime);
331 XTestFakeButtonEvent(display, 1, False, CurrentTime);
332 // Move the pointer back.
333 XTestFakeMotionEvent(display, -1, root_x, root_y, CurrentTime);
334 XFlush(display);
335 }
289 } 336 }
290 337
291 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) { 338 virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event) {
292 WidgetGtk::OnButtonPress(widget, event); 339 WidgetGtk::OnButtonPress(widget, event);
293 // Never propagate event to parent. 340 // Never propagate event to parent.
294 return true; 341 return true;
295 } 342 }
296 343
297 // Try to grab all inputs. It initiates another try if it fails to 344 // Try to grab all inputs. It initiates another try if it fails to
298 // grab and the retry count is within a limit, or fails with CHECK. 345 // grab and the retry count is within a limit, or fails with CHECK.
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 972
926 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) { 973 bool ScreenLocker::AcceleratorPressed(const views::Accelerator& accelerator) {
927 if (!background_view_->IsScreenSaverVisible()) { 974 if (!background_view_->IsScreenSaverVisible()) {
928 StartScreenSaver(); 975 StartScreenSaver();
929 return true; 976 return true;
930 } 977 }
931 return false; 978 return false;
932 } 979 }
933 980
934 } // namespace chromeos 981 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698