OLD | NEW |
| (Empty) |
1 // Copyright (c) 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/aura/window_tree_host_mojo.h" | |
6 | |
7 #include "mojo/aura/context_factory_mojo.h" | |
8 #include "mojo/public/c/gles2/gles2.h" | |
9 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | |
10 #include "ui/aura/env.h" | |
11 #include "ui/aura/window.h" | |
12 #include "ui/aura/window_event_dispatcher.h" | |
13 #include "ui/compositor/compositor.h" | |
14 #include "ui/events/event.h" | |
15 #include "ui/events/event_constants.h" | |
16 #include "ui/gfx/geometry/insets.h" | |
17 #include "ui/gfx/geometry/rect.h" | |
18 | |
19 namespace mojo { | |
20 | |
21 // static | |
22 mojo::ContextFactoryMojo* WindowTreeHostMojo::context_factory_ = NULL; | |
23 | |
24 //////////////////////////////////////////////////////////////////////////////// | |
25 // WindowTreeHostMojo, public: | |
26 | |
27 WindowTreeHostMojo::WindowTreeHostMojo( | |
28 NativeViewportPtr viewport, | |
29 const gfx::Rect& bounds, | |
30 const base::Callback<void()>& compositor_created_callback) | |
31 : native_viewport_(viewport.Pass()), | |
32 compositor_created_callback_(compositor_created_callback), | |
33 bounds_(bounds) { | |
34 native_viewport_.set_client(this); | |
35 native_viewport_->Create(Rect::From(bounds)); | |
36 | |
37 MessagePipe pipe; | |
38 native_viewport_->CreateGLES2Context( | |
39 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); | |
40 | |
41 // The ContextFactory must exist before any Compositors are created. | |
42 if (context_factory_) { | |
43 delete context_factory_; | |
44 context_factory_ = NULL; | |
45 } | |
46 context_factory_ = new ContextFactoryMojo(pipe.handle1.Pass()); | |
47 aura::Env::GetInstance()->set_context_factory(context_factory_); | |
48 CHECK(context_factory_) << "No GL bindings."; | |
49 } | |
50 | |
51 WindowTreeHostMojo::~WindowTreeHostMojo() { | |
52 DestroyCompositor(); | |
53 DestroyDispatcher(); | |
54 } | |
55 | |
56 //////////////////////////////////////////////////////////////////////////////// | |
57 // WindowTreeHostMojo, aura::WindowTreeHost implementation: | |
58 | |
59 ui::EventSource* WindowTreeHostMojo::GetEventSource() { | |
60 return this; | |
61 } | |
62 | |
63 gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() { | |
64 NOTIMPLEMENTED() << "GetAcceleratedWidget"; | |
65 return gfx::kNullAcceleratedWidget; | |
66 } | |
67 | |
68 void WindowTreeHostMojo::Show() { | |
69 window()->Show(); | |
70 native_viewport_->Show(); | |
71 } | |
72 | |
73 void WindowTreeHostMojo::Hide() { | |
74 native_viewport_->Hide(); | |
75 window()->Hide(); | |
76 } | |
77 | |
78 gfx::Rect WindowTreeHostMojo::GetBounds() const { | |
79 return bounds_; | |
80 } | |
81 | |
82 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { | |
83 native_viewport_->SetBounds(Rect::From(bounds)); | |
84 } | |
85 | |
86 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { | |
87 return gfx::Point(0, 0); | |
88 } | |
89 | |
90 void WindowTreeHostMojo::SetCapture() { | |
91 NOTIMPLEMENTED(); | |
92 } | |
93 | |
94 void WindowTreeHostMojo::ReleaseCapture() { | |
95 NOTIMPLEMENTED(); | |
96 } | |
97 | |
98 void WindowTreeHostMojo::PostNativeEvent( | |
99 const base::NativeEvent& native_event) { | |
100 NOTIMPLEMENTED(); | |
101 } | |
102 | |
103 void WindowTreeHostMojo::OnDeviceScaleFactorChanged(float device_scale_factor) { | |
104 NOTIMPLEMENTED(); | |
105 } | |
106 | |
107 void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) { | |
108 NOTIMPLEMENTED(); | |
109 } | |
110 | |
111 void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) { | |
112 NOTIMPLEMENTED(); | |
113 } | |
114 | |
115 void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) { | |
116 NOTIMPLEMENTED(); | |
117 } | |
118 | |
119 //////////////////////////////////////////////////////////////////////////////// | |
120 // WindowTreeHostMojo, ui::EventSource implementation: | |
121 | |
122 ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() { | |
123 return dispatcher(); | |
124 } | |
125 | |
126 //////////////////////////////////////////////////////////////////////////////// | |
127 // WindowTreeHostMojo, NativeViewportClient implementation: | |
128 | |
129 void WindowTreeHostMojo::OnCreated() { | |
130 CreateCompositor(GetAcceleratedWidget()); | |
131 compositor_created_callback_.Run(); | |
132 } | |
133 | |
134 void WindowTreeHostMojo::OnBoundsChanged(RectPtr bounds) { | |
135 bounds_ = bounds.To<gfx::Rect>(); | |
136 window()->SetBounds(gfx::Rect(bounds_.size())); | |
137 OnHostResized(bounds_.size()); | |
138 } | |
139 | |
140 void WindowTreeHostMojo::OnDestroyed() { | |
141 base::MessageLoop::current()->Quit(); | |
142 } | |
143 | |
144 void WindowTreeHostMojo::OnEvent(EventPtr event, | |
145 const mojo::Callback<void()>& callback) { | |
146 switch (event->action) { | |
147 case ui::ET_MOUSE_PRESSED: | |
148 case ui::ET_MOUSE_DRAGGED: | |
149 case ui::ET_MOUSE_RELEASED: | |
150 case ui::ET_MOUSE_MOVED: | |
151 case ui::ET_MOUSE_ENTERED: | |
152 case ui::ET_MOUSE_EXITED: { | |
153 gfx::Point location(event->location->x, event->location->y); | |
154 ui::MouseEvent ev(static_cast<ui::EventType>(event->action), location, | |
155 location, event->flags, 0); | |
156 SendEventToProcessor(&ev); | |
157 break; | |
158 } | |
159 case ui::ET_KEY_PRESSED: | |
160 case ui::ET_KEY_RELEASED: { | |
161 ui::KeyEvent ev( | |
162 static_cast<ui::EventType>(event->action), | |
163 static_cast<ui::KeyboardCode>(event->key_data->key_code), | |
164 event->flags, event->key_data->is_char); | |
165 SendEventToProcessor(&ev); | |
166 break; | |
167 } | |
168 // TODO(beng): touch, etc. | |
169 } | |
170 callback.Run(); | |
171 }; | |
172 | |
173 } // namespace mojo | |
OLD | NEW |