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