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: chrome/browser/ui/libgtk2ui/gtk2_event_loop.cc

Issue 610523002: linux: Fixes a racy crash by key input at termination. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_event_loop.h ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/libgtk2ui/gtk2_event_loop.h" 5 #include "chrome/browser/ui/libgtk2ui/gtk2_event_loop.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkx.h> 8 #include <gdk/gdkx.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 #include <X11/X.h> 10 #include <X11/X.h>
11 11
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "ui/gfx/x/x11_types.h" 13 #include "ui/gfx/x/x11_types.h"
14 14
15 namespace libgtk2ui { 15 namespace libgtk2ui {
16 16
17 // static 17 // static
18 Gtk2EventLoop* Gtk2EventLoop::GetInstance() { 18 Gtk2EventLoop* Gtk2EventLoop::GetInstance() {
19 return Singleton<Gtk2EventLoop>::get(); 19 return Singleton<Gtk2EventLoop>::get();
20 } 20 }
21 21
22 Gtk2EventLoop::Gtk2EventLoop() { 22 Gtk2EventLoop::Gtk2EventLoop() {
23 gdk_event_handler_set(GdkEventTrampoline, this, NULL); 23 gdk_event_handler_set(DispatchGdkEvent, NULL, NULL);
24 } 24 }
25 25
26 Gtk2EventLoop::~Gtk2EventLoop() { 26 Gtk2EventLoop::~Gtk2EventLoop() {
27 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event), 27 gdk_event_handler_set(reinterpret_cast<GdkEventFunc>(gtk_main_do_event),
28 NULL, NULL); 28 NULL, NULL);
29 } 29 }
30 30
31 // static 31 // static
32 void Gtk2EventLoop::GdkEventTrampoline(GdkEvent* event, gpointer data) { 32 void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event, gpointer) {
33 Gtk2EventLoop* loop = reinterpret_cast<Gtk2EventLoop*>(data);
34 loop->DispatchGdkEvent(event);
35 }
36
37 void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event) {
38 switch (gdk_event->type) { 33 switch (gdk_event->type) {
39 case GDK_KEY_PRESS: 34 case GDK_KEY_PRESS:
40 case GDK_KEY_RELEASE: 35 case GDK_KEY_RELEASE:
41 ProcessGdkEventKey(gdk_event->key); 36 ProcessGdkEventKey(gdk_event->key);
42 break; 37 break;
43 default: 38 default:
44 break; // Do nothing. 39 break; // Do nothing.
45 } 40 }
46 41
47 gtk_main_do_event(gdk_event); 42 gtk_main_do_event(gdk_event);
48 } 43 }
49 44
45 // static
50 void Gtk2EventLoop::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) { 46 void Gtk2EventLoop::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) {
51 // This function translates GdkEventKeys into XKeyEvents and puts them to 47 // This function translates GdkEventKeys into XKeyEvents and puts them to
52 // the X event queue. 48 // the X event queue.
53 // 49 //
54 // base::MessagePumpX11 is using the X11 event queue and all key events should 50 // base::MessagePumpX11 is using the X11 event queue and all key events should
55 // be processed there. However, there are cases(*1) that GdkEventKeys are 51 // be processed there. However, there are cases(*1) that GdkEventKeys are
56 // created instead of XKeyEvents. In these cases, we have to translate 52 // created instead of XKeyEvents. In these cases, we have to translate
57 // GdkEventKeys to XKeyEvents and puts them to the X event queue so our main 53 // GdkEventKeys to XKeyEvents and puts them to the X event queue so our main
58 // event loop can handle those key events. 54 // event loop can handle those key events.
59 // 55 //
(...skipping 11 matching lines...) Expand all
71 x_event.xkey.root = DefaultRootWindow(x_event.xkey.display); 67 x_event.xkey.root = DefaultRootWindow(x_event.xkey.display);
72 x_event.xkey.time = gdk_event_key.time; 68 x_event.xkey.time = gdk_event_key.time;
73 x_event.xkey.state = gdk_event_key.state; 69 x_event.xkey.state = gdk_event_key.state;
74 x_event.xkey.keycode = gdk_event_key.hardware_keycode; 70 x_event.xkey.keycode = gdk_event_key.hardware_keycode;
75 x_event.xkey.same_screen = true; 71 x_event.xkey.same_screen = true;
76 72
77 XPutBackEvent(x_event.xkey.display, &x_event); 73 XPutBackEvent(x_event.xkey.display, &x_event);
78 } 74 }
79 75
80 } // namespace libgtk2ui 76 } // namespace libgtk2ui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/gtk2_event_loop.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698