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

Side by Side Diff: ui/wm/core/nested_accelerator_dispatcher_linux.cc

Issue 301743002: Revert of Refactor and move ash independent nested accelerator code to ui/wm/core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 "ui/wm/core/nested_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 #include "ui/wm/core/nested_accelerator_delegate.h"
14
15 #if defined(USE_X11)
16 #include <X11/Xlib.h>
17 #endif
18
19 namespace wm {
20
21 namespace {
22
23 #if defined(USE_OZONE)
24 bool IsKeyEvent(const base::NativeEvent& native_event) {
25 const ui::KeyEvent* event = static_cast<const ui::KeyEvent*>(native_event);
26 return event->IsKeyEvent();
27 }
28 #elif defined(USE_X11)
29 bool IsKeyEvent(const XEvent* xev) {
30 return xev->type == KeyPress || xev->type == KeyRelease;
31 }
32 #else
33 #error Unknown build platform: you should have either use_ozone or use_x11.
34 #endif
35
36 scoped_ptr<ui::ScopedEventDispatcher> OverrideDispatcher(
37 ui::PlatformEventDispatcher* dispatcher) {
38 ui::PlatformEventSource* source = ui::PlatformEventSource::GetInstance();
39 return source ? source->OverrideDispatcher(dispatcher)
40 : scoped_ptr<ui::ScopedEventDispatcher>();
41 }
42
43 } // namespace
44
45 class NestedAcceleratorDispatcherLinux : public NestedAcceleratorDispatcher,
46 public ui::PlatformEventDispatcher {
47 public:
48 explicit NestedAcceleratorDispatcherLinux(NestedAcceleratorDelegate* delegate)
49 : NestedAcceleratorDispatcher(delegate),
50 restore_dispatcher_(OverrideDispatcher(this)) {}
51
52 virtual ~NestedAcceleratorDispatcherLinux() {}
53
54 private:
55 // AcceleratorDispatcher:
56 virtual scoped_ptr<base::RunLoop> CreateRunLoop() OVERRIDE {
57 return scoped_ptr<base::RunLoop>(new base::RunLoop());
58 }
59
60 // ui::PlatformEventDispatcher:
61 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
62 return true;
63 }
64
65 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE {
66 if (IsKeyEvent(event)) {
67 ui::KeyEvent key_event(event, false);
68 if (!delegate_->ShouldProcessEventNow(key_event)) {
69 #if defined(USE_X11)
70 XPutBackEvent(event->xany.display, event);
71 #else
72 NOTIMPLEMENTED();
73 #endif
74 return ui::POST_DISPATCH_NONE;
75 }
76
77 if (delegate_->ProcessEvent(key_event))
78 return ui::POST_DISPATCH_NONE;
79 }
80 ui::PlatformEventDispatcher* prev = *restore_dispatcher_;
81
82 return prev ? prev->DispatchEvent(event)
83 : ui::POST_DISPATCH_PERFORM_DEFAULT;
84 }
85
86 scoped_ptr<ui::ScopedEventDispatcher> restore_dispatcher_;
87
88 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDispatcherLinux);
89 };
90
91 scoped_ptr<NestedAcceleratorDispatcher> NestedAcceleratorDispatcher::Create(
92 NestedAcceleratorDelegate* delegate,
93 base::MessagePumpDispatcher* nested_dispatcher) {
94 return scoped_ptr<NestedAcceleratorDispatcher>(
95 new NestedAcceleratorDispatcherLinux(delegate));
96 }
97
98 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/nested_accelerator_dispatcher.cc ('k') | ui/wm/core/nested_accelerator_dispatcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698