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 <algorithm> | |
8 | |
7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "content/browser/frame_host/interstitial_page_impl.h" | 13 #include "content/browser/frame_host/interstitial_page_impl.h" |
12 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
13 #include "content/browser/renderer_host/dip_util.h" | 15 #include "content/browser/renderer_host/dip_util.h" |
14 #include "content/browser/renderer_host/overscroll_controller.h" | 16 #include "content/browser/renderer_host/overscroll_controller.h" |
15 #include "content/browser/renderer_host/render_view_host_factory.h" | 17 #include "content/browser/renderer_host/render_view_host_factory.h" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
36 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
37 #include "content/public/common/drop_data.h" | 39 #include "content/public/common/drop_data.h" |
38 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
39 #include "third_party/WebKit/public/web/WebInputEvent.h" | 41 #include "third_party/WebKit/public/web/WebInputEvent.h" |
40 #include "ui/aura/client/aura_constants.h" | 42 #include "ui/aura/client/aura_constants.h" |
41 #include "ui/aura/client/drag_drop_client.h" | 43 #include "ui/aura/client/drag_drop_client.h" |
42 #include "ui/aura/client/drag_drop_delegate.h" | 44 #include "ui/aura/client/drag_drop_delegate.h" |
43 #include "ui/aura/client/window_tree_client.h" | 45 #include "ui/aura/client/window_tree_client.h" |
44 #include "ui/aura/env.h" | 46 #include "ui/aura/env.h" |
45 #include "ui/aura/root_window.h" | 47 #include "ui/aura/root_window.h" |
46 #include "ui/aura/root_window_observer.h" | |
47 #include "ui/aura/window.h" | 48 #include "ui/aura/window.h" |
48 #include "ui/aura/window_observer.h" | |
49 #include "ui/base/clipboard/clipboard.h" | 49 #include "ui/base/clipboard/clipboard.h" |
50 #include "ui/base/clipboard/custom_data_helper.h" | 50 #include "ui/base/clipboard/custom_data_helper.h" |
51 #include "ui/base/dragdrop/drag_drop_types.h" | 51 #include "ui/base/dragdrop/drag_drop_types.h" |
52 #include "ui/base/dragdrop/drag_utils.h" | 52 #include "ui/base/dragdrop/drag_utils.h" |
53 #include "ui/base/dragdrop/drop_target_event.h" | 53 #include "ui/base/dragdrop/drop_target_event.h" |
54 #include "ui/base/dragdrop/os_exchange_data.h" | 54 #include "ui/base/dragdrop/os_exchange_data.h" |
55 #include "ui/base/hit_test.h" | 55 #include "ui/base/hit_test.h" |
56 #include "ui/compositor/layer.h" | 56 #include "ui/compositor/layer.h" |
57 #include "ui/compositor/scoped_layer_animation_settings.h" | 57 #include "ui/compositor/scoped_layer_animation_settings.h" |
58 #include "ui/events/event.h" | 58 #include "ui/events/event.h" |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 } | 410 } |
411 | 411 |
412 gfx::Image image_; | 412 gfx::Image image_; |
413 gfx::Size image_size_; | 413 gfx::Size image_size_; |
414 | 414 |
415 DISALLOW_COPY_AND_ASSIGN(ImageLayerDelegate); | 415 DISALLOW_COPY_AND_ASSIGN(ImageLayerDelegate); |
416 }; | 416 }; |
417 | 417 |
418 } // namespace | 418 } // namespace |
419 | 419 |
420 WebContentsViewAuraWindowObserver::WebContentsViewAuraWindowObserver( | |
421 WebContentsViewAuraWindowObserverDelegate* delegate) | |
422 : delegate_(delegate) { | |
423 DCHECK(delegate); | |
424 delegate_->AddDelegateWindowObserver(this); | |
425 std::set<aura::Window*> ancestors = GenerateAncestors( | |
426 delegate_->GetDelegateWindow()); | |
427 AddToObserved(ancestors); | |
428 } | |
429 | |
430 WebContentsViewAuraWindowObserver::~WebContentsViewAuraWindowObserver() { | |
431 RemoveFromObserved(observed_); | |
432 delegate_->RemoveRootWindowObserver(this); | |
433 delegate_->RemoveDelegateWindowObserver(this); | |
434 } | |
435 | |
436 void WebContentsViewAuraWindowObserver::OnWindowParentChanged( | |
437 aura::Window* window, | |
438 aura::Window* parent) { | |
439 std::set<aura::Window*> ancestors = GenerateAncestors( | |
440 delegate_->GetDelegateWindow()); | |
441 std::set<aura::Window*> difference; | |
442 std::set_difference( | |
443 observed_.begin(), | |
444 observed_.end(), | |
445 ancestors.begin(), | |
446 ancestors.end(), | |
447 std::inserter(difference, difference.end())); | |
448 RemoveFromObserved(difference); | |
449 | |
450 difference.clear(); | |
451 std::set_difference( | |
452 ancestors.begin(), | |
453 ancestors.end(), | |
454 observed_.begin(), | |
455 observed_.end(), | |
456 std::inserter(difference, difference.end())); | |
457 AddToObserved(difference); | |
458 } | |
459 | |
460 void WebContentsViewAuraWindowObserver::OnWindowBoundsChanged | |
461 (aura::Window* window, | |
462 const gfx::Rect& old_bounds, | |
463 const gfx::Rect& new_bounds) { | |
464 delegate_->SendScreenRects(); | |
465 delegate_->UpdateEditingController(); | |
466 } | |
467 | |
468 void WebContentsViewAuraWindowObserver::OnWindowAddedToRootWindow( | |
469 aura::Window* window) { | |
470 if (window == delegate_->GetDelegateWindow()) | |
471 delegate_->AddRootWindowObserver(this); | |
472 } | |
473 | |
474 void WebContentsViewAuraWindowObserver::OnWindowRemovingFromRootWindow( | |
475 aura::Window* window) { | |
476 if (window == delegate_->GetDelegateWindow()) | |
477 delegate_->RemoveRootWindowObserver(this); | |
478 } | |
479 | |
480 void WebContentsViewAuraWindowObserver::OnRootWindowHostMoved( | |
481 const aura::RootWindow* root, | |
482 const gfx::Point& new_origin) { | |
483 // This is for the desktop case (i.e. Aura desktop). | |
484 delegate_->SendScreenRects(); | |
485 } | |
486 | |
487 std::set<aura::Window*> WebContentsViewAuraWindowObserver::GenerateAncestors( | |
488 aura::Window* window) { | |
489 std::set<aura::Window*> ret_val; | |
490 while (window->parent()) { | |
491 ret_val.insert(window->parent()); | |
492 window = window->parent(); | |
493 } | |
494 return ret_val; | |
495 } | |
496 | |
497 void WebContentsViewAuraWindowObserver::AddToObserved( | |
498 const std::set<aura::Window*>& windows) { | |
499 for (std::set<aura::Window*>::iterator iter = windows.begin(); | |
500 iter != windows.end(); | |
501 ++iter) { | |
502 if (observed_.end() == observed_.find(*iter)) { | |
503 (*iter)->AddObserver(this); | |
504 observed_.insert(*iter); | |
505 } | |
506 } | |
507 } | |
508 | |
509 void WebContentsViewAuraWindowObserver::RemoveFromObserved( | |
510 const std::set<aura::Window*>& windows) { | |
511 // Since windows can possibly be observer_ we cannot blindly iterate and | |
512 // delete, since that breaks the iterators. | |
513 for (std::set<aura::Window*>::iterator iter = windows.begin(); | |
514 iter != windows.end();) { | |
515 std::set<aura::Window*>::iterator next = iter; | |
516 next++; | |
517 if (observed_.end() != observed_.find(*iter)) { | |
518 (*iter)->RemoveObserver(this); | |
519 observed_.erase(*iter); | |
520 } | |
521 iter = next; | |
522 } | |
523 } | |
524 | |
420 // When a history navigation is triggered at the end of an overscroll | 525 // When a history navigation is triggered at the end of an overscroll |
421 // navigation, it is necessary to show the history-screenshot until the page is | 526 // navigation, it is necessary to show the history-screenshot until the page is |
422 // done navigating and painting. This class accomplishes this by showing the | 527 // done navigating and painting. This class accomplishes this by showing the |
423 // screenshot window on top of the page until the page has completed loading and | 528 // screenshot window on top of the page until the page has completed loading and |
424 // painting. | 529 // painting. |
425 class OverscrollNavigationOverlay : | 530 class OverscrollNavigationOverlay : |
426 public RenderWidgetHostViewAura::PaintObserver, | 531 public RenderWidgetHostViewAura::PaintObserver, |
427 public WindowSlider::Delegate { | 532 public WindowSlider::Delegate { |
428 public: | 533 public: |
429 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents) | 534 explicit OverscrollNavigationOverlay(WebContentsImpl* web_contents) |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 ImageLayerDelegate layer_delegate_; | 746 ImageLayerDelegate layer_delegate_; |
642 | 747 |
643 // During tests, the aura windows don't get any paint updates. So the overlay | 748 // During tests, the aura windows don't get any paint updates. So the overlay |
644 // container keeps waiting for a paint update it never receives, causing a | 749 // container keeps waiting for a paint update it never receives, causing a |
645 // timeout. So during tests, disable the wait for paint updates. | 750 // timeout. So during tests, disable the wait for paint updates. |
646 bool need_paint_update_; | 751 bool need_paint_update_; |
647 | 752 |
648 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); | 753 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
649 }; | 754 }; |
650 | 755 |
651 class WebContentsViewAura::WindowObserver | |
652 : public aura::WindowObserver, public aura::RootWindowObserver { | |
653 public: | |
654 explicit WindowObserver(WebContentsViewAura* view) | |
655 : view_(view), | |
656 parent_(NULL) { | |
657 view_->window_->AddObserver(this); | |
658 } | |
659 | |
660 virtual ~WindowObserver() { | |
661 view_->window_->RemoveObserver(this); | |
662 if (view_->window_->GetDispatcher()) | |
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); | |
664 if (parent_) | |
665 parent_->RemoveObserver(this); | |
666 } | |
667 | |
668 // Overridden from aura::WindowObserver: | |
669 virtual void OnWindowParentChanged(aura::Window* window, | |
670 aura::Window* parent) OVERRIDE { | |
671 if (window == parent_) | |
672 return; | |
673 if (parent_) | |
674 parent_->RemoveObserver(this); | |
675 parent_ = parent; | |
676 if (parent) | |
677 parent->AddObserver(this); | |
678 } | |
679 | |
680 virtual void OnWindowBoundsChanged(aura::Window* window, | |
681 const gfx::Rect& old_bounds, | |
682 const gfx::Rect& new_bounds) OVERRIDE { | |
683 SendScreenRects(); | |
684 if (view_->touch_editable_) | |
685 view_->touch_editable_->UpdateEditingController(); | |
686 } | |
687 | |
688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | |
689 if (window != parent_) | |
690 window->GetDispatcher()->AddRootWindowObserver(this); | |
691 } | |
692 | |
693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | |
694 if (window != parent_) | |
695 window->GetDispatcher()->RemoveRootWindowObserver(this); | |
696 } | |
697 | |
698 // Overridden RootWindowObserver: | |
699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, | |
700 const gfx::Point& new_origin) OVERRIDE { | |
701 // This is for the desktop case (i.e. Aura desktop). | |
702 SendScreenRects(); | |
703 } | |
704 | |
705 private: | |
706 void SendScreenRects() { | |
707 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> | |
708 SendScreenRects(); | |
709 } | |
710 | |
711 WebContentsViewAura* view_; | |
712 | |
713 // We cache the old parent so that we can unregister when it's not the parent | |
714 // anymore. | |
715 aura::Window* parent_; | |
716 | |
717 DISALLOW_COPY_AND_ASSIGN(WindowObserver); | |
718 }; | |
719 | |
720 #if defined(OS_WIN) | 756 #if defined(OS_WIN) |
721 // Constrained windows are added as children of the WebContent's view which may | 757 // Constrained windows are added as children of the WebContent's view which may |
722 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it | 758 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it |
723 // can update the plugins' cutout rects accordingly. | 759 // can update the plugins' cutout rects accordingly. |
724 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver, | 760 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver, |
725 public WebContentsObserver { | 761 public WebContentsObserver { |
726 public: | 762 public: |
727 explicit ChildWindowObserver(WebContentsViewAura* view) | 763 explicit ChildWindowObserver(WebContentsViewAura* view) |
728 : WebContentsObserver(view->web_contents_), | 764 : WebContentsObserver(view->web_contents_), |
729 view_(view), | 765 view_(view), |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 // explicitly add this WebContentsViewAura to their tree after they create | 1193 // explicitly add this WebContentsViewAura to their tree after they create |
1158 // us. | 1194 // us. |
1159 if (root_window) { | 1195 if (root_window) { |
1160 aura::client::ParentWindowWithContext( | 1196 aura::client::ParentWindowWithContext( |
1161 window_.get(), root_window, root_window->GetBoundsInScreen()); | 1197 window_.get(), root_window, root_window->GetBoundsInScreen()); |
1162 } | 1198 } |
1163 } | 1199 } |
1164 window_->layer()->SetMasksToBounds(true); | 1200 window_->layer()->SetMasksToBounds(true); |
1165 window_->SetName("WebContentsViewAura"); | 1201 window_->SetName("WebContentsViewAura"); |
1166 | 1202 |
1167 window_observer_.reset(new WindowObserver(this)); | 1203 window_observer_.reset(new WebContentsViewAuraWindowObserver(this)); |
sadrul
2013/11/06 20:24:06
I was thinking of something more like a NativeView
| |
1168 #if defined(OS_WIN) | 1204 #if defined(OS_WIN) |
1169 child_window_observer_.reset(new ChildWindowObserver(this)); | 1205 child_window_observer_.reset(new ChildWindowObserver(this)); |
1170 #endif | 1206 #endif |
1171 | 1207 |
1172 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1208 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1173 // Hence, we save a reference to it locally. Similar model is used on other | 1209 // Hence, we save a reference to it locally. Similar model is used on other |
1174 // platforms as well. | 1210 // platforms as well. |
1175 if (delegate_) | 1211 if (delegate_) |
1176 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1212 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1177 } | 1213 } |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1645 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1681 web_contents_->GetRenderViewHost()->DragTargetDrop( |
1646 event.location(), | 1682 event.location(), |
1647 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1683 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1648 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1684 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1649 if (drag_dest_delegate_) | 1685 if (drag_dest_delegate_) |
1650 drag_dest_delegate_->OnDrop(); | 1686 drag_dest_delegate_->OnDrop(); |
1651 current_drop_data_.reset(); | 1687 current_drop_data_.reset(); |
1652 return current_drag_op_; | 1688 return current_drag_op_; |
1653 } | 1689 } |
1654 | 1690 |
1691 //////////////////////////////////////////////////////////////////////////////// | |
1692 // WebContentsViewAura, WebContentsViewAuraWindowObserverDelgate implementation: | |
1693 | |
1694 aura::Window* WebContentsViewAura::GetDelegateWindow() { | |
1695 return window_.get(); | |
1696 } | |
1697 | |
1698 void WebContentsViewAura::AddDelegateWindowObserver( | |
1699 aura::WindowObserver* observer) { | |
1700 window_->AddObserver(observer); | |
1701 } | |
1702 | |
1703 void WebContentsViewAura::RemoveDelegateWindowObserver( | |
1704 aura::WindowObserver* observer) { | |
1705 window_->RemoveObserver(observer); | |
1706 } | |
1707 | |
1708 void WebContentsViewAura::RemoveRootWindowObserver( | |
1709 aura::RootWindowObserver* observer) { | |
1710 if (window_->GetDispatcher()) | |
1711 window_->GetDispatcher()->RemoveRootWindowObserver(observer); | |
1712 } | |
1713 | |
1714 void WebContentsViewAura::AddRootWindowObserver( | |
1715 aura::RootWindowObserver* observer) { | |
1716 if (window_->GetDispatcher()) | |
1717 window_->GetDispatcher()->AddRootWindowObserver(observer); | |
1718 } | |
1719 | |
1720 void WebContentsViewAura::UpdateEditingController() { | |
1721 if (touch_editable_) | |
1722 touch_editable_->UpdateEditingController(); | |
1723 } | |
1724 | |
1725 void WebContentsViewAura::SendScreenRects() { | |
1726 RenderWidgetHostImpl::From(web_contents_->GetRenderViewHost())-> | |
1727 SendScreenRects(); | |
1728 } | |
1729 | |
1655 } // namespace content | 1730 } // namespace content |
OLD | NEW |