OLD | NEW |
| (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/native_viewport.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "ui/events/event.h" | |
10 #include "ui/events/event_utils.h" | |
11 #include "ui/events/platform/platform_event_dispatcher.h" | |
12 #include "ui/events/platform/platform_event_source.h" | |
13 #include "ui/gfx/rect.h" | |
14 #include "ui/platform_window/platform_window.h" | |
15 #include "ui/platform_window/platform_window_delegate.h" | |
16 #include "ui/platform_window/x11/x11_window.h" | |
17 | |
18 namespace mojo { | |
19 namespace services { | |
20 | |
21 class NativeViewportX11 : public NativeViewport, | |
22 public ui::PlatformWindowDelegate { | |
23 public: | |
24 explicit NativeViewportX11(NativeViewportDelegate* delegate) | |
25 : delegate_(delegate) { | |
26 } | |
27 | |
28 virtual ~NativeViewportX11() { | |
29 // Destroy the platform-window while |this| is still alive. | |
30 platform_window_.reset(); | |
31 } | |
32 | |
33 private: | |
34 // Overridden from NativeViewport: | |
35 virtual void Init(const gfx::Rect& bounds) OVERRIDE { | |
36 CHECK(!event_source_); | |
37 CHECK(!platform_window_); | |
38 | |
39 event_source_ = ui::PlatformEventSource::CreateDefault(); | |
40 | |
41 platform_window_.reset(new ui::X11Window(this)); | |
42 platform_window_->SetBounds(bounds); | |
43 } | |
44 | |
45 virtual void Show() OVERRIDE { | |
46 platform_window_->Show(); | |
47 } | |
48 | |
49 virtual void Hide() OVERRIDE { | |
50 platform_window_->Hide(); | |
51 } | |
52 | |
53 virtual void Close() OVERRIDE { | |
54 platform_window_->Close(); | |
55 } | |
56 | |
57 virtual gfx::Size GetSize() OVERRIDE { | |
58 return bounds_.size(); | |
59 } | |
60 | |
61 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { | |
62 platform_window_->SetBounds(bounds); | |
63 } | |
64 | |
65 virtual void SetCapture() OVERRIDE { | |
66 platform_window_->SetCapture(); | |
67 } | |
68 | |
69 virtual void ReleaseCapture() OVERRIDE { | |
70 platform_window_->ReleaseCapture(); | |
71 } | |
72 | |
73 // ui::PlatformWindowDelegate: | |
74 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { | |
75 bounds_ = new_bounds; | |
76 delegate_->OnBoundsChanged(new_bounds); | |
77 } | |
78 | |
79 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE { | |
80 } | |
81 | |
82 virtual void DispatchEvent(ui::Event* event) OVERRIDE { | |
83 delegate_->OnEvent(event); | |
84 } | |
85 | |
86 virtual void OnCloseRequest() OVERRIDE { | |
87 platform_window_->Close(); | |
88 } | |
89 | |
90 virtual void OnClosed() OVERRIDE { | |
91 delegate_->OnDestroyed(); | |
92 } | |
93 | |
94 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE { | |
95 } | |
96 | |
97 virtual void OnLostCapture() OVERRIDE { | |
98 } | |
99 | |
100 virtual void OnAcceleratedWidgetAvailable( | |
101 gfx::AcceleratedWidget widget) OVERRIDE { | |
102 delegate_->OnAcceleratedWidgetAvailable(widget); | |
103 } | |
104 | |
105 virtual void OnActivationChanged(bool active) OVERRIDE {} | |
106 | |
107 scoped_ptr<ui::PlatformEventSource> event_source_; | |
108 scoped_ptr<ui::PlatformWindow> platform_window_; | |
109 NativeViewportDelegate* delegate_; | |
110 gfx::Rect bounds_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(NativeViewportX11); | |
113 }; | |
114 | |
115 // static | |
116 scoped_ptr<NativeViewport> NativeViewport::Create( | |
117 NativeViewportDelegate* delegate) { | |
118 return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass(); | |
119 } | |
120 | |
121 } // namespace services | |
122 } // namespace mojo | |
OLD | NEW |