OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "content/browser/renderer_host/dip_util.h" | 8 #include "content/browser/renderer_host/dip_util.h" |
9 #include "content/browser/renderer_host/render_view_host_factory.h" | 9 #include "content/browser/renderer_host/render_view_host_factory.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
10 #include "content/browser/web_contents/interstitial_page_impl.h" | 11 #include "content/browser/web_contents/interstitial_page_impl.h" |
11 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
14 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
16 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/render_widget_host.h" | 18 #include "content/public/browser/render_widget_host.h" |
18 #include "content/public/browser/render_widget_host_view.h" | 19 #include "content/public/browser/render_widget_host_view.h" |
19 #include "content/public/browser/web_contents_delegate.h" | 20 #include "content/public/browser/web_contents_delegate.h" |
20 #include "content/public/browser/web_contents_view_delegate.h" | 21 #include "content/public/browser/web_contents_view_delegate.h" |
21 #include "content/public/browser/web_drag_dest_delegate.h" | 22 #include "content/public/browser/web_drag_dest_delegate.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
23 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
24 #include "ui/aura/client/drag_drop_client.h" | 25 #include "ui/aura/client/drag_drop_client.h" |
25 #include "ui/aura/client/drag_drop_delegate.h" | 26 #include "ui/aura/client/drag_drop_delegate.h" |
26 #include "ui/aura/root_window.h" | 27 #include "ui/aura/root_window.h" |
28 #include "ui/aura/root_window_observer.h" | |
27 #include "ui/aura/window.h" | 29 #include "ui/aura/window.h" |
30 #include "ui/aura/window_observer.h" | |
28 #include "ui/base/clipboard/custom_data_helper.h" | 31 #include "ui/base/clipboard/custom_data_helper.h" |
29 #include "ui/base/dragdrop/drag_drop_types.h" | 32 #include "ui/base/dragdrop/drag_drop_types.h" |
30 #include "ui/base/dragdrop/os_exchange_data.h" | 33 #include "ui/base/dragdrop/os_exchange_data.h" |
31 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 34 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
32 #include "ui/base/events/event.h" | 35 #include "ui/base/events/event.h" |
33 #include "ui/base/events/event_utils.h" | 36 #include "ui/base/events/event_utils.h" |
34 #include "ui/base/hit_test.h" | 37 #include "ui/base/hit_test.h" |
35 #include "ui/compositor/layer.h" | 38 #include "ui/compositor/layer.h" |
36 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
37 #include "webkit/glue/webdropdata.h" | 40 #include "webkit/glue/webdropdata.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 web_input_event_modifiers |= WebKit::WebInputEvent::ControlKey; | 227 web_input_event_modifiers |= WebKit::WebInputEvent::ControlKey; |
225 if (aura_event_flags & ui::EF_ALT_DOWN) | 228 if (aura_event_flags & ui::EF_ALT_DOWN) |
226 web_input_event_modifiers |= WebKit::WebInputEvent::AltKey; | 229 web_input_event_modifiers |= WebKit::WebInputEvent::AltKey; |
227 if (aura_event_flags & ui::EF_COMMAND_DOWN) | 230 if (aura_event_flags & ui::EF_COMMAND_DOWN) |
228 web_input_event_modifiers |= WebKit::WebInputEvent::MetaKey; | 231 web_input_event_modifiers |= WebKit::WebInputEvent::MetaKey; |
229 return web_input_event_modifiers; | 232 return web_input_event_modifiers; |
230 } | 233 } |
231 | 234 |
232 } // namespace | 235 } // namespace |
233 | 236 |
237 class WebContentsViewAura::WindowObserver | |
238 : public aura::WindowObserver, public aura::RootWindowObserver { | |
239 public: | |
240 explicit WindowObserver(WebContentsViewAura* view) | |
241 : view_(view), parent_(NULL) {} | |
sky
2012/11/19 15:04:54
nit: each param on its own line.
jam
2012/11/19 18:53:06
the style guide says it's ok to put them on one li
sky
2012/11/19 22:45:24
But this is 2 lines, right? The second example sho
jam
2012/11/20 01:08:01
ah, I misunderstood that comment to mean that if a
| |
242 virtual ~WindowObserver() { | |
243 if (parent_) | |
244 parent_->RemoveObserver(this); | |
245 } | |
246 | |
247 // Overridden from aura::WindowObserver: | |
248 virtual void OnWindowParentChanged(aura::Window* window, | |
249 aura::Window* parent) OVERRIDE { | |
250 if (parent_) | |
251 parent_->RemoveObserver(this); | |
252 parent_ = parent; | |
253 if (parent) | |
254 parent->AddObserver(this); | |
255 } | |
256 | |
257 virtual void OnWindowBoundsChanged(aura::Window* window, | |
258 const gfx::Rect& old_bounds, | |
259 const gfx::Rect& new_bounds) { | |
260 // This is for the Ash case. | |
261 SendScreenRects(); | |
262 } | |
263 | |
264 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | |
265 window->GetRootWindow()->AddRootWindowObserver(this); | |
266 } | |
267 | |
268 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | |
269 window->GetRootWindow()->RemoveRootWindowObserver(this); | |
270 } | |
271 | |
272 // Overridden RootWindowObserver: | |
273 virtual void OnRootWindowMoved(const aura::RootWindow* root, | |
274 const gfx::Point& new_origin) OVERRIDE { | |
275 // This is for the desktop case (i.e. Aura desktop). | |
276 SendScreenRects(); | |
277 } | |
278 | |
279 private: | |
280 void SendScreenRects() { | |
281 if (!view_->view_) | |
282 return; | |
283 RenderWidgetHostImpl::From(view_->view_->GetRenderWidgetHost())-> | |
284 SendScreenRects(); | |
285 } | |
286 | |
287 WebContentsViewAura* view_; | |
288 | |
289 // We cache the old parent so that we can unregister when it's not the parent | |
290 // anymore. | |
291 aura::Window* parent_; | |
292 | |
293 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | |
294 }; | |
295 | |
234 | 296 |
235 //////////////////////////////////////////////////////////////////////////////// | 297 //////////////////////////////////////////////////////////////////////////////// |
236 // WebContentsViewAura, public: | 298 // WebContentsViewAura, public: |
237 | 299 |
238 WebContentsViewAura::WebContentsViewAura( | 300 WebContentsViewAura::WebContentsViewAura( |
239 WebContentsImpl* web_contents, | 301 WebContentsImpl* web_contents, |
240 WebContentsViewDelegate* delegate) | 302 WebContentsViewDelegate* delegate) |
241 : web_contents_(web_contents), | 303 : web_contents_(web_contents), |
242 view_(NULL), | 304 view_(NULL), |
243 delegate_(delegate), | 305 delegate_(delegate), |
244 current_drag_op_(WebKit::WebDragOperationNone), | 306 current_drag_op_(WebKit::WebDragOperationNone), |
245 drag_dest_delegate_(NULL), | 307 drag_dest_delegate_(NULL), |
246 current_rvh_for_drag_(NULL) { | 308 current_rvh_for_drag_(NULL) { |
247 } | 309 } |
248 | 310 |
249 //////////////////////////////////////////////////////////////////////////////// | 311 //////////////////////////////////////////////////////////////////////////////// |
250 // WebContentsViewAura, private: | 312 // WebContentsViewAura, private: |
251 | 313 |
252 WebContentsViewAura::~WebContentsViewAura() { | 314 WebContentsViewAura::~WebContentsViewAura() { |
315 if (!window_) | |
316 return; | |
317 | |
318 window_->RemoveObserver(window_observer_.get()); | |
253 // Window needs a valid delegate during its destructor, so we explicitly | 319 // Window needs a valid delegate during its destructor, so we explicitly |
254 // delete it here. | 320 // delete it here. |
255 window_.reset(); | 321 window_.reset(); |
256 } | 322 } |
257 | 323 |
258 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 324 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
259 if (web_contents_->GetInterstitialPage()) | 325 if (web_contents_->GetInterstitialPage()) |
260 web_contents_->GetInterstitialPage()->SetSize(size); | 326 web_contents_->GetInterstitialPage()->SetSize(size); |
261 RenderWidgetHostView* rwhv = | 327 RenderWidgetHostView* rwhv = |
262 web_contents_->GetRenderWidgetHostView(); | 328 web_contents_->GetRenderWidgetHostView(); |
(...skipping 23 matching lines...) Expand all Loading... | |
286 | 352 |
287 window_.reset(new aura::Window(this)); | 353 window_.reset(new aura::Window(this)); |
288 window_->set_owned_by_parent(false); | 354 window_->set_owned_by_parent(false); |
289 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 355 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
290 window_->SetTransparent(false); | 356 window_->SetTransparent(false); |
291 window_->Init(ui::LAYER_NOT_DRAWN); | 357 window_->Init(ui::LAYER_NOT_DRAWN); |
292 window_->SetParent(NULL); | 358 window_->SetParent(NULL); |
293 window_->layer()->SetMasksToBounds(true); | 359 window_->layer()->SetMasksToBounds(true); |
294 window_->SetName("WebContentsViewAura"); | 360 window_->SetName("WebContentsViewAura"); |
295 | 361 |
362 window_observer_.reset(new WindowObserver(this)); | |
363 window_->AddObserver(window_observer_.get()); | |
364 | |
296 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 365 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
297 // Hence, we save a reference to it locally. Similar model is used on other | 366 // Hence, we save a reference to it locally. Similar model is used on other |
298 // platforms as well. | 367 // platforms as well. |
299 if (delegate_.get()) | 368 if (delegate_.get()) |
300 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 369 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
301 } | 370 } |
302 | 371 |
303 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 372 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
304 RenderWidgetHost* render_widget_host) { | 373 RenderWidgetHost* render_widget_host) { |
305 if (render_widget_host->GetView()) { | 374 if (render_widget_host->GetView()) { |
306 // During testing, the view will already be set up in most cases to the | 375 // During testing, the view will already be set up in most cases to the |
307 // test view, so we don't want to clobber it with a real one. To verify that | 376 // test view, so we don't want to clobber it with a real one. To verify that |
308 // this actually is happening (and somebody isn't accidentally creating the | 377 // this actually is happening (and somebody isn't accidentally creating the |
309 // view twice), we check for the RVH Factory, which will be set when we're | 378 // view twice), we check for the RVH Factory, which will be set when we're |
310 // making special ones (which go along with the special views). | 379 // making special ones (which go along with the special views). |
311 DCHECK(RenderViewHostFactory::has_factory()); | 380 DCHECK(RenderViewHostFactory::has_factory()); |
312 return render_widget_host->GetView(); | 381 return render_widget_host->GetView(); |
313 } | 382 } |
314 | 383 |
315 view_ = RenderWidgetHostView::CreateViewForWidget( | 384 view_ = RenderWidgetHostView::CreateViewForWidget(render_widget_host); |
316 render_widget_host); | |
317 view_->InitAsChild(NULL); | 385 view_->InitAsChild(NULL); |
318 GetNativeView()->AddChild(view_->GetNativeView()); | 386 GetNativeView()->AddChild(view_->GetNativeView()); |
319 view_->Show(); | 387 view_->Show(); |
320 | 388 |
321 // We listen to drag drop events in the newly created view's window. | 389 // We listen to drag drop events in the newly created view's window. |
322 aura::client::SetDragDropDelegate(view_->GetNativeView(), this); | 390 aura::client::SetDragDropDelegate(view_->GetNativeView(), this); |
323 return view_; | 391 return view_; |
324 } | 392 } |
325 | 393 |
326 gfx::NativeView WebContentsViewAura::GetNativeView() const { | 394 gfx::NativeView WebContentsViewAura::GetNativeView() const { |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 event.location(), | 752 event.location(), |
685 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 753 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
686 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 754 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
687 if (drag_dest_delegate_) | 755 if (drag_dest_delegate_) |
688 drag_dest_delegate_->OnDrop(); | 756 drag_dest_delegate_->OnDrop(); |
689 current_drop_data_.reset(); | 757 current_drop_data_.reset(); |
690 return current_drag_op_; | 758 return current_drag_op_; |
691 } | 759 } |
692 | 760 |
693 } // namespace content | 761 } // namespace content |
OLD | NEW |