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

Side by Side Diff: mojo/services/native_viewport/platform_viewport_x11.cc

Issue 769173002: Move native_viewport and gles2 service impls to //services (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
OLDNEW
(Empty)
1 // Copyright 2013 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 "mojo/services/native_viewport/platform_viewport.h"
6
7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/converters/input_events/mojo_extended_key_event_data.h"
10 #include "ui/events/event.h"
11 #include "ui/events/event_utils.h"
12 #include "ui/events/platform/platform_event_dispatcher.h"
13 #include "ui/events/platform/platform_event_source.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/platform_window/platform_window.h"
16 #include "ui/platform_window/platform_window_delegate.h"
17 #include "ui/platform_window/x11/x11_window.h"
18
19 namespace mojo {
20
21 class PlatformViewportX11 : public PlatformViewport,
22 public ui::PlatformWindowDelegate {
23 public:
24 explicit PlatformViewportX11(Delegate* delegate) : delegate_(delegate) {
25 }
26
27 ~PlatformViewportX11() override {
28 // Destroy the platform-window while |this| is still alive.
29 platform_window_.reset();
30 }
31
32 private:
33 // Overridden from PlatformViewport:
34 void Init(const gfx::Rect& bounds) override {
35 CHECK(!event_source_);
36 CHECK(!platform_window_);
37
38 event_source_ = ui::PlatformEventSource::CreateDefault();
39
40 platform_window_.reset(new ui::X11Window(this));
41 platform_window_->SetBounds(bounds);
42 }
43
44 void Show() override { platform_window_->Show(); }
45
46 void Hide() override { platform_window_->Hide(); }
47
48 void Close() override { platform_window_->Close(); }
49
50 gfx::Size GetSize() override { return bounds_.size(); }
51
52 void SetBounds(const gfx::Rect& bounds) override {
53 platform_window_->SetBounds(bounds);
54 }
55
56 void SetCapture() override { platform_window_->SetCapture(); }
57
58 void ReleaseCapture() override { platform_window_->ReleaseCapture(); }
59
60 // ui::PlatformWindowDelegate:
61 void OnBoundsChanged(const gfx::Rect& new_bounds) override {
62 bounds_ = new_bounds;
63 delegate_->OnBoundsChanged(new_bounds);
64 }
65
66 void OnDamageRect(const gfx::Rect& damaged_region) override {}
67
68 void DispatchEvent(ui::Event* event) override {
69 delegate_->OnEvent(event);
70
71 // We want to emulate the WM_CHAR generation behaviour of Windows.
72 //
73 // On Linux, we've previously inserted characters by having
74 // InputMethodAuraLinux take all key down events and send a character event
75 // to the TextInputClient. This causes a mismatch in code that has to be
76 // shared between Windows and Linux, including blink code. Now that we're
77 // trying to have one way of doing things, we need to standardize on and
78 // emulate Windows character events.
79 //
80 // This is equivalent to what we're doing in the current Linux port, but
81 // done once instead of done multiple times in different places.
82 if (event->type() == ui::ET_KEY_PRESSED) {
83 ui::KeyEvent* key_press_event = static_cast<ui::KeyEvent*>(event);
84 ui::KeyEvent char_event(key_press_event->GetCharacter(),
85 key_press_event->key_code(),
86 key_press_event->flags());
87
88 DCHECK_EQ(key_press_event->GetCharacter(), char_event.GetCharacter());
89 DCHECK_EQ(key_press_event->key_code(), char_event.key_code());
90 DCHECK_EQ(key_press_event->flags(), char_event.flags());
91
92 char_event.SetExtendedKeyEventData(scoped_ptr<ui::ExtendedKeyEventData>(
93 new MojoExtendedKeyEventData(
94 key_press_event->GetLocatedWindowsKeyboardCode(),
95 key_press_event->GetText(),
96 key_press_event->GetUnmodifiedText())));
97 char_event.set_platform_keycode(key_press_event->platform_keycode());
98
99 delegate_->OnEvent(&char_event);
100 }
101 }
102
103 void OnCloseRequest() override { platform_window_->Close(); }
104
105 void OnClosed() override { delegate_->OnDestroyed(); }
106
107 void OnWindowStateChanged(ui::PlatformWindowState state) override {}
108
109 void OnLostCapture() override {}
110
111 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
112 delegate_->OnAcceleratedWidgetAvailable(widget);
113 }
114
115 void OnActivationChanged(bool active) override {}
116
117 scoped_ptr<ui::PlatformEventSource> event_source_;
118 scoped_ptr<ui::PlatformWindow> platform_window_;
119 Delegate* delegate_;
120 gfx::Rect bounds_;
121
122 DISALLOW_COPY_AND_ASSIGN(PlatformViewportX11);
123 };
124
125 // static
126 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) {
127 return scoped_ptr<PlatformViewport>(new PlatformViewportX11(delegate)).Pass();
128 }
129
130 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/platform_viewport_win.cc ('k') | mojo/services/native_viewport/viewport_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698