Chromium Code Reviews| 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/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/browser/renderer_host/dip_util.h" | 9 #include "content/browser/renderer_host/dip_util.h" |
| 10 #include "content/browser/renderer_host/overscroll_controller.h" | 10 #include "content/browser/renderer_host/overscroll_controller.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace | 253 } // namespace |
| 254 | 254 |
| 255 class WebContentsViewAura::WindowObserver | 255 class WebContentsViewAura::WindowObserver |
| 256 : public aura::WindowObserver, public aura::RootWindowObserver { | 256 : public aura::WindowObserver, public aura::RootWindowObserver { |
| 257 public: | 257 public: |
| 258 explicit WindowObserver(WebContentsViewAura* view) | 258 explicit WindowObserver(WebContentsViewAura* view) |
| 259 : view_(view), | 259 : view_(view), |
| 260 parent_(NULL) { | 260 parent_(NULL) { |
| 261 view_->window_->AddObserver(this); | |
| 261 } | 262 } |
| 262 | 263 |
| 263 virtual ~WindowObserver() { | 264 virtual ~WindowObserver() { |
| 265 view_->window_->RemoveObserver(this); | |
| 264 if (parent_) | 266 if (parent_) |
| 265 parent_->RemoveObserver(this); | 267 parent_->RemoveObserver(this); |
| 266 } | 268 } |
| 267 | 269 |
| 268 // Overridden from aura::WindowObserver: | 270 // Overridden from aura::WindowObserver: |
| 269 virtual void OnWindowParentChanged(aura::Window* window, | 271 virtual void OnWindowParentChanged(aura::Window* window, |
| 270 aura::Window* parent) OVERRIDE { | 272 aura::Window* parent) OVERRIDE { |
| 273 if (window == parent_) | |
| 274 return; | |
| 271 if (parent_) | 275 if (parent_) |
| 272 parent_->RemoveObserver(this); | 276 parent_->RemoveObserver(this); |
| 273 parent_ = parent; | 277 parent_ = parent; |
| 274 if (parent) | 278 if (parent) |
| 275 parent->AddObserver(this); | 279 parent->AddObserver(this); |
| 276 } | 280 } |
| 277 | 281 |
| 278 virtual void OnWindowBoundsChanged(aura::Window* window, | 282 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 279 const gfx::Rect& old_bounds, | 283 const gfx::Rect& old_bounds, |
| 280 const gfx::Rect& new_bounds) { | 284 const gfx::Rect& new_bounds) { |
| 281 // This is for the Ash case. | |
|
oshima
2012/11/20 23:21:03
This is necessary for non ash as well. WebContentV
| |
| 282 SendScreenRects(); | 285 SendScreenRects(); |
| 283 } | 286 } |
| 284 | 287 |
| 285 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | 288 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
| 286 window->GetRootWindow()->AddRootWindowObserver(this); | 289 if (window != parent_) |
| 290 window->GetRootWindow()->AddRootWindowObserver(this); | |
| 287 } | 291 } |
| 288 | 292 |
| 289 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | 293 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
| 290 window->GetRootWindow()->RemoveRootWindowObserver(this); | 294 if (window != parent_) |
| 295 window->GetRootWindow()->RemoveRootWindowObserver(this); | |
| 291 } | 296 } |
| 292 | 297 |
| 293 // Overridden RootWindowObserver: | 298 // Overridden RootWindowObserver: |
| 294 virtual void OnRootWindowMoved(const aura::RootWindow* root, | 299 virtual void OnRootWindowMoved(const aura::RootWindow* root, |
| 295 const gfx::Point& new_origin) OVERRIDE { | 300 const gfx::Point& new_origin) OVERRIDE { |
| 296 // This is for the desktop case (i.e. Aura desktop). | 301 // This is for the desktop case (i.e. Aura desktop). |
| 297 SendScreenRects(); | 302 SendScreenRects(); |
| 298 } | 303 } |
| 299 | 304 |
| 300 private: | 305 private: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 331 completed_overscroll_gesture_(OVERSCROLL_NONE) { | 336 completed_overscroll_gesture_(OVERSCROLL_NONE) { |
| 332 } | 337 } |
| 333 | 338 |
| 334 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 335 // WebContentsViewAura, private: | 340 // WebContentsViewAura, private: |
| 336 | 341 |
| 337 WebContentsViewAura::~WebContentsViewAura() { | 342 WebContentsViewAura::~WebContentsViewAura() { |
| 338 if (!window_) | 343 if (!window_) |
| 339 return; | 344 return; |
| 340 | 345 |
| 341 window_->RemoveObserver(window_observer_.get()); | 346 window_observer_.reset(); |
| 342 // Window needs a valid delegate during its destructor, so we explicitly | 347 // Window needs a valid delegate during its destructor, so we explicitly |
| 343 // delete it here. | 348 // delete it here. |
| 344 window_.reset(); | 349 window_.reset(); |
| 345 } | 350 } |
| 346 | 351 |
| 347 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 352 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
| 348 if (web_contents_->GetInterstitialPage()) | 353 if (web_contents_->GetInterstitialPage()) |
| 349 web_contents_->GetInterstitialPage()->SetSize(size); | 354 web_contents_->GetInterstitialPage()->SetSize(size); |
| 350 RenderWidgetHostView* rwhv = | 355 RenderWidgetHostView* rwhv = |
| 351 web_contents_->GetRenderWidgetHostView(); | 356 web_contents_->GetRenderWidgetHostView(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 window_.reset(new aura::Window(this)); | 502 window_.reset(new aura::Window(this)); |
| 498 window_->set_owned_by_parent(false); | 503 window_->set_owned_by_parent(false); |
| 499 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 504 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
| 500 window_->SetTransparent(false); | 505 window_->SetTransparent(false); |
| 501 window_->Init(ui::LAYER_NOT_DRAWN); | 506 window_->Init(ui::LAYER_NOT_DRAWN); |
| 502 window_->SetParent(NULL); | 507 window_->SetParent(NULL); |
| 503 window_->layer()->SetMasksToBounds(true); | 508 window_->layer()->SetMasksToBounds(true); |
| 504 window_->SetName("WebContentsViewAura"); | 509 window_->SetName("WebContentsViewAura"); |
| 505 | 510 |
| 506 window_observer_.reset(new WindowObserver(this)); | 511 window_observer_.reset(new WindowObserver(this)); |
| 507 window_->AddObserver(window_observer_.get()); | |
| 508 | 512 |
| 509 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 513 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
| 510 // Hence, we save a reference to it locally. Similar model is used on other | 514 // Hence, we save a reference to it locally. Similar model is used on other |
| 511 // platforms as well. | 515 // platforms as well. |
| 512 if (delegate_.get()) | 516 if (delegate_.get()) |
| 513 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 517 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
| 514 } | 518 } |
| 515 | 519 |
| 516 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 520 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
| 517 RenderWidgetHost* render_widget_host) { | 521 RenderWidgetHost* render_widget_host) { |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 980 event.location(), | 984 event.location(), |
| 981 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 985 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 982 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 986 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 983 if (drag_dest_delegate_) | 987 if (drag_dest_delegate_) |
| 984 drag_dest_delegate_->OnDrop(); | 988 drag_dest_delegate_->OnDrop(); |
| 985 current_drop_data_.reset(); | 989 current_drop_data_.reset(); |
| 986 return current_drag_op_; | 990 return current_drag_op_; |
| 987 } | 991 } |
| 988 | 992 |
| 989 } // namespace content | 993 } // namespace content |
| OLD | NEW |