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

Side by Side Diff: ash/accelerators/accelerator_dispatcher_linux.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/accelerators/accelerator_dispatcher.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h"
9 #include "ui/events/event.h"
10 #include "ui/events/platform/platform_event_dispatcher.h"
11 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/events/platform/scoped_event_dispatcher.h"
13
14 #if defined(USE_X11)
15 #include <X11/Xlib.h>
16 #endif
17
18 namespace ash {
19
20 namespace {
21
22 #if defined(USE_OZONE)
23 bool IsKeyEvent(const base::NativeEvent& native_event) {
24 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
25 return event->IsKeyEvent();
26 }
27 #elif defined(USE_X11)
28 bool IsKeyEvent(const XEvent* xev) {
29 return xev->type == KeyPress || xev->type == KeyRelease;
30 }
31 #else
32 #error Unknown build platform: you should have either use_ozone or use_x11.
33 #endif
34
35 scoped_ptr<ui::ScopedEventDispatcher> OverrideDispatcher(
36 ui::PlatformEventDispatcher* dispatcher) {
37 ui::PlatformEventSource* source = ui::PlatformEventSource::GetInstance();
38 return source ? source->OverrideDispatcher(dispatcher)
39 : scoped_ptr<ui::ScopedEventDispatcher>();
40 }
41
42 } // namespace
43
44 class AcceleratorDispatcherLinux : public AcceleratorDispatcher,
45 public ui::PlatformEventDispatcher {
46 public:
47 AcceleratorDispatcherLinux()
48 : restore_dispatcher_(OverrideDispatcher(this)) {}
49
50 virtual ~AcceleratorDispatcherLinux() {}
51
52 private:
53 // AcceleratorDispatcher:
54 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE {
55 return scoped_ptr<base::RunLoop>(new base::RunLoop());
56 }
57
58 // ui::PlatformEventDispatcher:
59 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
60 return true;
61 }
62
63 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
64 if (IsKeyEvent(event)) {
65 ui::KeyEvent key_event(event, false);
66 if (MenuClosedForPossibleAccelerator(key_event)) {
67 XPutBackEvent(event->xany.display, event);
68 return ui::POST_DISPATCH_QUIT_LOOP;
69 }
70
71 if (AcceleratorProcessedForKeyEvent(key_event))
72 return ui::POST_DISPATCH_NONE;
73 }
74
75 ui::PlatformEventDispatcher* prev = *restore_dispatcher_;
76 return prev ? prev->DispatchEvent(event)
77 : ui::POST_DISPATCH_PERFORM_DEFAULT;
78 }
79
80 scoped_ptr<ui::ScopedEventDispatcher> restore_dispatcher_;
81
82 DISALLOW_COPY_AND_ASSIGN(AcceleratorDispatcherLinux);
83 };
84
85 scoped_ptr<AcceleratorDispatcher> AcceleratorDispatcher::Create(
86 base::MessagePumpDispatcher* nested_dispatcher) {
87 return scoped_ptr<AcceleratorDispatcher>(new AcceleratorDispatcherLinux());
88 }
89
90 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_dispatcher.cc ('k') | ash/accelerators/accelerator_dispatcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698