OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "content/browser/renderer_host/render_widget_host_view_mus.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "build/build_config.h" | |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
12 #include "content/common/render_widget_window_tree_client_factory.mojom.h" | |
13 #include "content/common/text_input_state.h" | |
14 #include "content/public/common/service_manager_connection.h" | |
15 #include "services/service_manager/public/cpp/connector.h" | |
16 #include "services/ui/public/cpp/property_type_converters.h" | |
17 #include "services/ui/public/cpp/window.h" | |
18 #include "services/ui/public/cpp/window_property.h" | |
19 #include "services/ui/public/cpp/window_tree_client.h" | |
20 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | |
21 #include "ui/aura/client/screen_position_client.h" | |
22 #include "ui/aura/window.h" | |
23 #include "ui/base/hit_test.h" | |
24 | |
25 namespace content { | |
26 | |
27 RenderWidgetHostViewMus::RenderWidgetHostViewMus(ui::Window* parent_window, | |
28 RenderWidgetHostImpl* host) | |
29 : host_(host), aura_window_(nullptr) { | |
30 DCHECK(parent_window); | |
31 ui::Window* window = parent_window->window_tree()->NewWindow(); | |
32 window->SetVisible(true); | |
33 window->SetBounds(gfx::Rect(300, 300)); | |
34 window->set_input_event_handler(this); | |
35 parent_window->AddChild(window); | |
36 mus_window_.reset(new ui::ScopedWindowPtr(window)); | |
37 host_->SetView(this); | |
38 | |
39 // Connect to the renderer, pass it a WindowTreeClient interface request | |
40 // and embed that client inside our mus window. | |
41 mojom::RenderWidgetWindowTreeClientFactoryPtr factory; | |
42 host_->GetProcess()->GetRemoteInterfaces()->GetInterface(&factory); | |
43 | |
44 ui::mojom::WindowTreeClientPtr window_tree_client; | |
45 factory->CreateWindowTreeClientForRenderWidget( | |
46 host_->GetRoutingID(), mojo::GetProxy(&window_tree_client)); | |
47 mus_window_->window()->Embed(std::move(window_tree_client), | |
48 ui::mojom::kEmbedFlagEmbedderInterceptsEvents); | |
49 } | |
50 | |
51 RenderWidgetHostViewMus::~RenderWidgetHostViewMus() {} | |
52 | |
53 void RenderWidgetHostViewMus::InternalSetBounds(const gfx::Rect& rect) { | |
54 aura_window_->SetBounds(rect); | |
55 gfx::Rect bounds = aura_window_->GetBoundsInRootWindow(); | |
56 mus_window_->window()->SetBounds(bounds); | |
57 host_->WasResized(); | |
58 } | |
59 | |
60 void RenderWidgetHostViewMus::Show() { | |
61 // TODO(fsamuel): Update visibility in Mus. | |
62 // There is some interstitial complexity that we'll need to figure out here. | |
63 host_->WasShown(ui::LatencyInfo()); | |
64 } | |
65 | |
66 void RenderWidgetHostViewMus::Hide() { | |
67 host_->WasHidden(); | |
68 } | |
69 | |
70 bool RenderWidgetHostViewMus::IsShowing() { | |
71 return !host_->is_hidden(); | |
72 } | |
73 | |
74 void RenderWidgetHostViewMus::SetSize(const gfx::Size& size) { | |
75 // For a SetSize operation, we don't care what coordinate system the origin | |
76 // of the window is in, it's only important to make sure that the origin | |
77 // remains constant after the operation. | |
78 InternalSetBounds(gfx::Rect(aura_window_->bounds().origin(), size)); | |
79 } | |
80 | |
81 void RenderWidgetHostViewMus::SetBounds(const gfx::Rect& rect) { | |
82 gfx::Point relative_origin(rect.origin()); | |
83 | |
84 // RenderWidgetHostViewMus::SetBounds() takes screen coordinates, but | |
85 // Window::SetBounds() takes parent coordinates, so do the conversion here. | |
86 aura::Window* root = aura_window_->GetRootWindow(); | |
87 if (root) { | |
88 aura::client::ScreenPositionClient* screen_position_client = | |
89 aura::client::GetScreenPositionClient(root); | |
90 if (screen_position_client) { | |
91 screen_position_client->ConvertPointFromScreen(aura_window_->parent(), | |
92 &relative_origin); | |
93 } | |
94 } | |
95 | |
96 InternalSetBounds(gfx::Rect(relative_origin, rect.size())); | |
97 } | |
98 | |
99 void RenderWidgetHostViewMus::Focus() { | |
100 // TODO(fsamuel): Request focus for the associated Mus::Window | |
101 // We need to be careful how we propagate focus as we navigate to and | |
102 // from interstitials. | |
103 } | |
104 | |
105 bool RenderWidgetHostViewMus::HasFocus() const { | |
106 return true; | |
107 } | |
108 | |
109 bool RenderWidgetHostViewMus::IsSurfaceAvailableForCopy() const { | |
110 NOTIMPLEMENTED(); | |
111 return false; | |
112 } | |
113 | |
114 gfx::Rect RenderWidgetHostViewMus::GetViewBounds() const { | |
115 return aura_window_->GetBoundsInScreen(); | |
116 } | |
117 | |
118 gfx::Vector2dF RenderWidgetHostViewMus::GetLastScrollOffset() const { | |
119 return gfx::Vector2dF(); | |
120 } | |
121 | |
122 void RenderWidgetHostViewMus::RenderProcessGone(base::TerminationStatus status, | |
123 int error_code) { | |
124 NOTIMPLEMENTED(); | |
125 } | |
126 | |
127 void RenderWidgetHostViewMus::Destroy() { | |
128 delete aura_window_; | |
129 } | |
130 | |
131 gfx::Size RenderWidgetHostViewMus::GetPhysicalBackingSize() const { | |
132 return RenderWidgetHostViewBase::GetPhysicalBackingSize(); | |
133 } | |
134 | |
135 base::string16 RenderWidgetHostViewMus::GetSelectedText() { | |
136 NOTIMPLEMENTED(); | |
137 return base::string16(); | |
138 } | |
139 | |
140 void RenderWidgetHostViewMus::SetTooltipText( | |
141 const base::string16& tooltip_text) { | |
142 // TOOD(fsamuel): Ask window manager for tooltip? | |
143 } | |
144 | |
145 void RenderWidgetHostViewMus::InitAsChild(gfx::NativeView parent_view) { | |
146 aura_window_ = new aura::Window(nullptr); | |
147 aura_window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | |
148 aura_window_->Init(ui::LAYER_SOLID_COLOR); | |
149 aura_window_->SetName("RenderWidgetHostViewMus"); | |
150 aura_window_->layer()->SetColor(background_color_); | |
151 | |
152 if (parent_view) | |
153 parent_view->AddChild(GetNativeView()); | |
154 } | |
155 | |
156 RenderWidgetHost* RenderWidgetHostViewMus::GetRenderWidgetHost() const { | |
157 return host_; | |
158 } | |
159 | |
160 void RenderWidgetHostViewMus::InitAsPopup( | |
161 RenderWidgetHostView* parent_host_view, | |
162 const gfx::Rect& bounds) { | |
163 // TODO(fsamuel): Implement popups in Mus. | |
164 } | |
165 | |
166 void RenderWidgetHostViewMus::InitAsFullscreen( | |
167 RenderWidgetHostView* reference_host_view) { | |
168 // TODO(fsamuel): Implement full screen windows in Mus. | |
169 } | |
170 | |
171 gfx::NativeView RenderWidgetHostViewMus::GetNativeView() const { | |
172 return aura_window_; | |
173 } | |
174 | |
175 gfx::NativeViewAccessible RenderWidgetHostViewMus::GetNativeViewAccessible() { | |
176 return gfx::NativeViewAccessible(); | |
177 } | |
178 | |
179 void RenderWidgetHostViewMus::UpdateCursor(const WebCursor& cursor) { | |
180 // TODO(fsamuel): Implement cursors in Mus. | |
181 NOTIMPLEMENTED(); | |
182 } | |
183 | |
184 void RenderWidgetHostViewMus::SetIsLoading(bool is_loading) { | |
185 } | |
186 | |
187 void RenderWidgetHostViewMus::TextInputStateChanged( | |
188 const TextInputState& params) { | |
189 // TODO(fsamuel): Implement an IME service. | |
190 } | |
191 | |
192 void RenderWidgetHostViewMus::ImeCancelComposition() { | |
193 // TODO(fsamuel): Implement an IME service. | |
194 } | |
195 | |
196 void RenderWidgetHostViewMus::ImeCompositionRangeChanged( | |
197 const gfx::Range& range, | |
198 const std::vector<gfx::Rect>& character_bounds) { | |
199 // TODO(fsamuel): Implement IME. | |
200 } | |
201 | |
202 void RenderWidgetHostViewMus::SelectionChanged(const base::string16& text, | |
203 size_t offset, | |
204 const gfx::Range& range) { | |
205 } | |
206 | |
207 void RenderWidgetHostViewMus::SelectionBoundsChanged( | |
208 const ViewHostMsg_SelectionBounds_Params& params) { | |
209 // TODO(fsamuel): Implement selection. | |
210 } | |
211 | |
212 void RenderWidgetHostViewMus::SetBackgroundColor(SkColor color) { | |
213 // TODO(fsamuel): Implement background color and opacity. | |
214 } | |
215 | |
216 void RenderWidgetHostViewMus::CopyFromCompositingSurface( | |
217 const gfx::Rect& /* src_subrect */, | |
218 const gfx::Size& /* dst_size */, | |
219 const ReadbackRequestCallback& callback, | |
220 const SkColorType /* preferred_color_type */) { | |
221 // TODO(fsamuel): Implement read back. | |
222 NOTIMPLEMENTED(); | |
223 callback.Run(SkBitmap(), READBACK_FAILED); | |
224 } | |
225 | |
226 void RenderWidgetHostViewMus::CopyFromCompositingSurfaceToVideoFrame( | |
227 const gfx::Rect& src_subrect, | |
228 const scoped_refptr<media::VideoFrame>& target, | |
229 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | |
230 NOTIMPLEMENTED(); | |
231 callback.Run(gfx::Rect(), false); | |
232 } | |
233 | |
234 bool RenderWidgetHostViewMus::CanCopyToVideoFrame() const { | |
235 return false; | |
236 } | |
237 | |
238 bool RenderWidgetHostViewMus::HasAcceleratedSurface( | |
239 const gfx::Size& desired_size) { | |
240 return false; | |
241 } | |
242 | |
243 bool RenderWidgetHostViewMus::LockMouse() { | |
244 // TODO(fsamuel): Implement mouse lock in Mus. | |
245 return false; | |
246 } | |
247 | |
248 void RenderWidgetHostViewMus::UnlockMouse() { | |
249 // TODO(fsamuel): Implement mouse lock in Mus. | |
250 } | |
251 | |
252 gfx::Rect RenderWidgetHostViewMus::GetBoundsInRootWindow() { | |
253 aura::Window* top_level = aura_window_->GetToplevelWindow(); | |
254 gfx::Rect bounds(top_level->GetBoundsInScreen()); | |
255 return bounds; | |
256 } | |
257 | |
258 void RenderWidgetHostViewMus::SetNeedsBeginFrames(bool needs_begin_frames) { | |
259 // TODO(enne): Implement this. | |
260 } | |
261 | |
262 #if defined(OS_MACOSX) | |
263 ui::AcceleratedWidgetMac* RenderWidgetHostViewMus::GetAcceleratedWidgetMac() | |
264 const { | |
265 return nullptr; | |
266 } | |
267 | |
268 void RenderWidgetHostViewMus::SetActive(bool active) { | |
269 } | |
270 | |
271 void RenderWidgetHostViewMus::ShowDefinitionForSelection() { | |
272 // TODO(fsamuel): Implement this on Mac. | |
273 } | |
274 | |
275 bool RenderWidgetHostViewMus::SupportsSpeech() const { | |
276 // TODO(fsamuel): Implement this on mac. | |
277 return false; | |
278 } | |
279 | |
280 void RenderWidgetHostViewMus::SpeakSelection() { | |
281 // TODO(fsamuel): Implement this on Mac. | |
282 } | |
283 | |
284 bool RenderWidgetHostViewMus::IsSpeaking() const { | |
285 // TODO(fsamuel): Implement this on Mac. | |
286 return false; | |
287 } | |
288 | |
289 void RenderWidgetHostViewMus::StopSpeaking() { | |
290 // TODO(fsamuel): Implement this on Mac. | |
291 } | |
292 #endif // defined(OS_MACOSX) | |
293 | |
294 void RenderWidgetHostViewMus::LockCompositingSurface() { | |
295 NOTIMPLEMENTED(); | |
296 } | |
297 | |
298 void RenderWidgetHostViewMus::UnlockCompositingSurface() { | |
299 NOTIMPLEMENTED(); | |
300 } | |
301 | |
302 void RenderWidgetHostViewMus::OnWindowInputEvent( | |
303 ui::Window* window, | |
304 const ui::Event& event, | |
305 std::unique_ptr<base::Callback<void(ui::mojom::EventResult)>>* | |
306 ack_callback) { | |
307 // TODO(sad): Dispatch |event| to the RenderWidgetHost. | |
308 } | |
309 | |
310 } // namespace content | |
OLD | NEW |