| 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/overscroll_controller.h" | 9 #include "content/browser/renderer_host/overscroll_controller.h" |
| 10 #include "content/browser/renderer_host/render_view_host_factory.h" | 10 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 12 #include "content/browser/web_contents/interstitial_page_impl.h" | 12 #include "content/browser/web_contents/interstitial_page_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 19 #include "content/public/browser/render_widget_host.h" | 19 #include "content/public/browser/render_widget_host.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | 20 #include "content/public/browser/render_widget_host_view.h" |
| 21 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "content/public/browser/web_contents_view_delegate.h" | 22 #include "content/public/browser/web_contents_view_delegate.h" |
| 23 #include "content/public/browser/web_drag_dest_delegate.h" | 23 #include "content/public/browser/web_drag_dest_delegate.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 25 #include "ui/aura/client/aura_constants.h" | 25 #include "ui/aura/client/aura_constants.h" |
| 26 #include "ui/aura/client/drag_drop_client.h" | 26 #include "ui/aura/client/drag_drop_client.h" |
| 27 #include "ui/aura/client/drag_drop_delegate.h" | 27 #include "ui/aura/client/drag_drop_delegate.h" |
| 28 #include "ui/aura/root_window.h" | 28 #include "ui/aura/root_window.h" |
| 29 #include "ui/aura/root_window_observer.h" |
| 29 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_observer.h" |
| 30 #include "ui/base/clipboard/custom_data_helper.h" | 32 #include "ui/base/clipboard/custom_data_helper.h" |
| 31 #include "ui/base/dragdrop/drag_drop_types.h" | 33 #include "ui/base/dragdrop/drag_drop_types.h" |
| 32 #include "ui/base/dragdrop/os_exchange_data.h" | 34 #include "ui/base/dragdrop/os_exchange_data.h" |
| 33 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" | 35 #include "ui/base/dragdrop/os_exchange_data_provider_aura.h" |
| 34 #include "ui/base/events/event.h" | 36 #include "ui/base/events/event.h" |
| 35 #include "ui/base/events/event_utils.h" | 37 #include "ui/base/events/event_utils.h" |
| 36 #include "ui/base/hit_test.h" | 38 #include "ui/base/hit_test.h" |
| 37 #include "ui/compositor/layer.h" | 39 #include "ui/compositor/layer.h" |
| 38 #include "ui/compositor/scoped_layer_animation_settings.h" | 40 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 39 #include "ui/gfx/screen.h" | 41 #include "ui/gfx/screen.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 web_input_event_modifiers |= WebKit::WebInputEvent::ControlKey; | 229 web_input_event_modifiers |= WebKit::WebInputEvent::ControlKey; |
| 228 if (aura_event_flags & ui::EF_ALT_DOWN) | 230 if (aura_event_flags & ui::EF_ALT_DOWN) |
| 229 web_input_event_modifiers |= WebKit::WebInputEvent::AltKey; | 231 web_input_event_modifiers |= WebKit::WebInputEvent::AltKey; |
| 230 if (aura_event_flags & ui::EF_COMMAND_DOWN) | 232 if (aura_event_flags & ui::EF_COMMAND_DOWN) |
| 231 web_input_event_modifiers |= WebKit::WebInputEvent::MetaKey; | 233 web_input_event_modifiers |= WebKit::WebInputEvent::MetaKey; |
| 232 return web_input_event_modifiers; | 234 return web_input_event_modifiers; |
| 233 } | 235 } |
| 234 | 236 |
| 235 } // namespace | 237 } // namespace |
| 236 | 238 |
| 239 class WebContentsViewAura::WindowObserver |
| 240 : public aura::WindowObserver, public aura::RootWindowObserver { |
| 241 public: |
| 242 explicit WindowObserver(WebContentsViewAura* view) |
| 243 : view_(view), |
| 244 parent_(NULL) { |
| 245 } |
| 246 |
| 247 virtual ~WindowObserver() { |
| 248 if (parent_) |
| 249 parent_->RemoveObserver(this); |
| 250 } |
| 251 |
| 252 // Overridden from aura::WindowObserver: |
| 253 virtual void OnWindowParentChanged(aura::Window* window, |
| 254 aura::Window* parent) OVERRIDE { |
| 255 if (parent_) |
| 256 parent_->RemoveObserver(this); |
| 257 parent_ = parent; |
| 258 if (parent) |
| 259 parent->AddObserver(this); |
| 260 } |
| 261 |
| 262 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 263 const gfx::Rect& old_bounds, |
| 264 const gfx::Rect& new_bounds) { |
| 265 // This is for the Ash case. |
| 266 SendScreenRects(); |
| 267 } |
| 268 |
| 269 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
| 270 window->GetRootWindow()->AddRootWindowObserver(this); |
| 271 } |
| 272 |
| 273 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
| 274 window->GetRootWindow()->RemoveRootWindowObserver(this); |
| 275 } |
| 276 |
| 277 // Overridden RootWindowObserver: |
| 278 virtual void OnRootWindowMoved(const aura::RootWindow* root, |
| 279 const gfx::Point& new_origin) OVERRIDE { |
| 280 // This is for the desktop case (i.e. Aura desktop). |
| 281 SendScreenRects(); |
| 282 } |
| 283 |
| 284 private: |
| 285 void SendScreenRects() { |
| 286 if (!view_->view_) |
| 287 return; |
| 288 RenderWidgetHostImpl::From(view_->view_->GetRenderWidgetHost())-> |
| 289 SendScreenRects(); |
| 290 } |
| 291 |
| 292 WebContentsViewAura* view_; |
| 293 |
| 294 // We cache the old parent so that we can unregister when it's not the parent |
| 295 // anymore. |
| 296 aura::Window* parent_; |
| 297 |
| 298 DISALLOW_COPY_AND_ASSIGN(WindowObserver); |
| 299 }; |
| 300 |
| 237 | 301 |
| 238 //////////////////////////////////////////////////////////////////////////////// | 302 //////////////////////////////////////////////////////////////////////////////// |
| 239 // WebContentsViewAura, public: | 303 // WebContentsViewAura, public: |
| 240 | 304 |
| 241 WebContentsViewAura::WebContentsViewAura( | 305 WebContentsViewAura::WebContentsViewAura( |
| 242 WebContentsImpl* web_contents, | 306 WebContentsImpl* web_contents, |
| 243 WebContentsViewDelegate* delegate) | 307 WebContentsViewDelegate* delegate) |
| 244 : web_contents_(web_contents), | 308 : web_contents_(web_contents), |
| 245 view_(NULL), | 309 view_(NULL), |
| 246 delegate_(delegate), | 310 delegate_(delegate), |
| 247 current_drag_op_(WebKit::WebDragOperationNone), | 311 current_drag_op_(WebKit::WebDragOperationNone), |
| 248 drag_dest_delegate_(NULL), | 312 drag_dest_delegate_(NULL), |
| 249 current_rvh_for_drag_(NULL), | 313 current_rvh_for_drag_(NULL), |
| 250 current_overscroll_gesture_(OVERSCROLL_NONE), | 314 current_overscroll_gesture_(OVERSCROLL_NONE), |
| 251 completed_overscroll_gesture_(OVERSCROLL_NONE) { | 315 completed_overscroll_gesture_(OVERSCROLL_NONE) { |
| 252 } | 316 } |
| 253 | 317 |
| 254 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
| 255 // WebContentsViewAura, private: | 319 // WebContentsViewAura, private: |
| 256 | 320 |
| 257 WebContentsViewAura::~WebContentsViewAura() { | 321 WebContentsViewAura::~WebContentsViewAura() { |
| 322 if (!window_) |
| 323 return; |
| 324 |
| 325 window_->RemoveObserver(window_observer_.get()); |
| 258 // Window needs a valid delegate during its destructor, so we explicitly | 326 // Window needs a valid delegate during its destructor, so we explicitly |
| 259 // delete it here. | 327 // delete it here. |
| 260 window_.reset(); | 328 window_.reset(); |
| 261 } | 329 } |
| 262 | 330 |
| 263 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 331 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
| 264 if (web_contents_->GetInterstitialPage()) | 332 if (web_contents_->GetInterstitialPage()) |
| 265 web_contents_->GetInterstitialPage()->SetSize(size); | 333 web_contents_->GetInterstitialPage()->SetSize(size); |
| 266 RenderWidgetHostView* rwhv = | 334 RenderWidgetHostView* rwhv = |
| 267 web_contents_->GetRenderWidgetHostView(); | 335 web_contents_->GetRenderWidgetHostView(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 | 481 |
| 414 window_.reset(new aura::Window(this)); | 482 window_.reset(new aura::Window(this)); |
| 415 window_->set_owned_by_parent(false); | 483 window_->set_owned_by_parent(false); |
| 416 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 484 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
| 417 window_->SetTransparent(false); | 485 window_->SetTransparent(false); |
| 418 window_->Init(ui::LAYER_NOT_DRAWN); | 486 window_->Init(ui::LAYER_NOT_DRAWN); |
| 419 window_->SetParent(NULL); | 487 window_->SetParent(NULL); |
| 420 window_->layer()->SetMasksToBounds(true); | 488 window_->layer()->SetMasksToBounds(true); |
| 421 window_->SetName("WebContentsViewAura"); | 489 window_->SetName("WebContentsViewAura"); |
| 422 | 490 |
| 491 window_observer_.reset(new WindowObserver(this)); |
| 492 window_->AddObserver(window_observer_.get()); |
| 493 |
| 423 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 494 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
| 424 // Hence, we save a reference to it locally. Similar model is used on other | 495 // Hence, we save a reference to it locally. Similar model is used on other |
| 425 // platforms as well. | 496 // platforms as well. |
| 426 if (delegate_.get()) | 497 if (delegate_.get()) |
| 427 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 498 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
| 428 } | 499 } |
| 429 | 500 |
| 430 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 501 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
| 431 RenderWidgetHost* render_widget_host) { | 502 RenderWidgetHost* render_widget_host) { |
| 432 if (render_widget_host->GetView()) { | 503 if (render_widget_host->GetView()) { |
| 433 // During testing, the view will already be set up in most cases to the | 504 // During testing, the view will already be set up in most cases to the |
| 434 // test view, so we don't want to clobber it with a real one. To verify that | 505 // test view, so we don't want to clobber it with a real one. To verify that |
| 435 // this actually is happening (and somebody isn't accidentally creating the | 506 // this actually is happening (and somebody isn't accidentally creating the |
| 436 // view twice), we check for the RVH Factory, which will be set when we're | 507 // view twice), we check for the RVH Factory, which will be set when we're |
| 437 // making special ones (which go along with the special views). | 508 // making special ones (which go along with the special views). |
| 438 DCHECK(RenderViewHostFactory::has_factory()); | 509 DCHECK(RenderViewHostFactory::has_factory()); |
| 439 return render_widget_host->GetView(); | 510 return render_widget_host->GetView(); |
| 440 } | 511 } |
| 441 | 512 |
| 442 view_ = RenderWidgetHostView::CreateViewForWidget( | 513 view_ = RenderWidgetHostView::CreateViewForWidget(render_widget_host); |
| 443 render_widget_host); | |
| 444 view_->InitAsChild(NULL); | 514 view_->InitAsChild(NULL); |
| 445 GetNativeView()->AddChild(view_->GetNativeView()); | 515 GetNativeView()->AddChild(view_->GetNativeView()); |
| 446 view_->Show(); | 516 view_->Show(); |
| 447 | 517 |
| 448 // We listen to drag drop events in the newly created view's window. | 518 // We listen to drag drop events in the newly created view's window. |
| 449 aura::client::SetDragDropDelegate(view_->GetNativeView(), this); | 519 aura::client::SetDragDropDelegate(view_->GetNativeView(), this); |
| 450 | 520 |
| 451 RenderWidgetHostImpl* host_impl = | 521 RenderWidgetHostImpl* host_impl = |
| 452 RenderWidgetHostImpl::From(render_widget_host); | 522 RenderWidgetHostImpl::From(render_widget_host); |
| 453 if (host_impl->overscroll_controller()) | 523 if (host_impl->overscroll_controller()) |
| 454 host_impl->overscroll_controller()->set_delegate(this); | 524 host_impl->overscroll_controller()->set_delegate(this); |
| 455 | 525 |
| 456 return view_; | 526 return view_; |
| 457 } | 527 } |
| 458 | 528 |
| 529 void WebContentsViewAura::SetView(RenderWidgetHostView* view) { |
| 530 view_ = view; |
| 531 } |
| 532 |
| 459 gfx::NativeView WebContentsViewAura::GetNativeView() const { | 533 gfx::NativeView WebContentsViewAura::GetNativeView() const { |
| 460 return window_.get(); | 534 return window_.get(); |
| 461 } | 535 } |
| 462 | 536 |
| 463 gfx::NativeView WebContentsViewAura::GetContentNativeView() const { | 537 gfx::NativeView WebContentsViewAura::GetContentNativeView() const { |
| 464 return view_->GetNativeView(); | 538 return view_->GetNativeView(); |
| 465 } | 539 } |
| 466 | 540 |
| 467 gfx::NativeWindow WebContentsViewAura::GetTopLevelNativeWindow() const { | 541 gfx::NativeWindow WebContentsViewAura::GetTopLevelNativeWindow() const { |
| 468 return window_->GetToplevelWindow(); | 542 return window_->GetToplevelWindow(); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 event.location(), | 959 event.location(), |
| 886 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 960 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 887 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 961 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 888 if (drag_dest_delegate_) | 962 if (drag_dest_delegate_) |
| 889 drag_dest_delegate_->OnDrop(); | 963 drag_dest_delegate_->OnDrop(); |
| 890 current_drop_data_.reset(); | 964 current_drop_data_.reset(); |
| 891 return current_drag_op_; | 965 return current_drag_op_; |
| 892 } | 966 } |
| 893 | 967 |
| 894 } // namespace content | 968 } // namespace content |
| OLD | NEW |