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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); | 648 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); |
649 }; | 649 }; |
650 | 650 |
651 class WebContentsViewAura::WindowObserver | 651 class WebContentsViewAura::WindowObserver |
652 : public aura::WindowObserver, public aura::RootWindowObserver { | 652 : public aura::WindowObserver, public aura::RootWindowObserver { |
653 public: | 653 public: |
654 explicit WindowObserver(WebContentsViewAura* view) | 654 explicit WindowObserver(WebContentsViewAura* view) |
655 : view_(view), | 655 : view_(view), |
656 parent_(NULL) { | 656 parent_(NULL) { |
657 view_->window_->AddObserver(this); | 657 view_->window_->AddObserver(this); |
| 658 |
| 659 #if defined(OS_WIN) |
| 660 if (view_->window_->GetRootWindow()) |
| 661 view_->window_->GetRootWindow()->AddObserver(this); |
| 662 #endif |
658 } | 663 } |
659 | 664 |
660 virtual ~WindowObserver() { | 665 virtual ~WindowObserver() { |
661 view_->window_->RemoveObserver(this); | 666 view_->window_->RemoveObserver(this); |
662 if (view_->window_->GetDispatcher()) | 667 if (view_->window_->GetDispatcher()) |
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); | 668 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); |
664 if (parent_) | 669 if (parent_) |
665 parent_->RemoveObserver(this); | 670 parent_->RemoveObserver(this); |
666 | 671 |
667 #if defined(OS_WIN) | 672 #if defined(OS_WIN) |
668 if (parent_) { | 673 if (parent_) { |
669 const aura::Window::Windows& children = parent_->children(); | 674 const aura::Window::Windows& children = parent_->children(); |
670 for (size_t i = 0; i < children.size(); ++i) | 675 for (size_t i = 0; i < children.size(); ++i) |
671 children[i]->RemoveObserver(this); | 676 children[i]->RemoveObserver(this); |
672 } | 677 } |
| 678 |
| 679 if (view_->window_->GetRootWindow()) |
| 680 view_->window_->GetRootWindow()->RemoveObserver(this); |
673 #endif | 681 #endif |
674 } | 682 } |
675 | 683 |
676 // Overridden from aura::WindowObserver: | 684 // Overridden from aura::WindowObserver: |
677 #if defined(OS_WIN) | 685 #if defined(OS_WIN) |
678 // Constrained windows are added as children of the parent's parent's view | 686 // Constrained windows are added as children of the parent's parent's view |
679 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV | 687 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV |
680 // so that it can update the plugins' cutout rects accordingly. | 688 // so that it can update the plugins' cutout rects accordingly. |
681 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is | 689 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is |
682 // going to be deprecated in a year, this is ok for now. The test for this is | 690 // going to be deprecated in a year, this is ok for now. The test for this is |
683 // PrintPreviewTest.WindowedNPAPIPluginHidden. | 691 // PrintPreviewTest.WindowedNPAPIPluginHidden. |
684 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | 692 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { |
685 if (new_window->parent() != parent_) | 693 if (new_window == view_->window_) |
686 return; | 694 return; |
687 | 695 |
688 new_window->AddObserver(this); | 696 // Observe sibling windows of the WebContents, or children of the root |
689 UpdateConstrainedWindows(NULL); | 697 // window. |
| 698 if (new_window->parent() == parent_ || |
| 699 new_window->parent() == view_->window_->GetRootWindow()) { |
| 700 new_window->AddObserver(this); |
| 701 UpdateConstrainedWindows(NULL); |
| 702 } |
690 } | 703 } |
691 | 704 |
692 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | 705 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { |
693 if (window->parent() == parent_ && window != view_->window_) { | 706 if (window == view_->window_) |
694 window->RemoveObserver(this); | 707 return; |
695 UpdateConstrainedWindows(window); | 708 |
696 } | 709 window->RemoveObserver(this); |
| 710 UpdateConstrainedWindows(window); |
697 } | 711 } |
698 | 712 |
699 virtual void OnWindowVisibilityChanged(aura::Window* window, | 713 virtual void OnWindowVisibilityChanged(aura::Window* window, |
700 bool visible) OVERRIDE { | 714 bool visible) OVERRIDE { |
701 if (window->parent() == parent_ && window != view_->window_) | 715 if (window == view_->window_) |
| 716 return; |
| 717 |
| 718 if (window->parent() == parent_ || |
| 719 window->parent() == view_->window_->GetRootWindow()) { |
702 UpdateConstrainedWindows(NULL); | 720 UpdateConstrainedWindows(NULL); |
| 721 } |
703 } | 722 } |
704 #endif | 723 #endif |
705 | 724 |
706 virtual void OnWindowParentChanged(aura::Window* window, | 725 virtual void OnWindowParentChanged(aura::Window* window, |
707 aura::Window* parent) OVERRIDE { | 726 aura::Window* parent) OVERRIDE { |
708 if (window != view_->window_) | 727 if (window != view_->window_) |
709 return; | 728 return; |
710 if (parent_) | 729 if (parent_) |
711 parent_->RemoveObserver(this); | 730 parent_->RemoveObserver(this); |
712 | 731 |
713 #if defined(OS_WIN) | 732 #if defined(OS_WIN) |
714 if (parent_) { | 733 if (parent_) { |
715 const aura::Window::Windows& children = parent_->children(); | 734 const aura::Window::Windows& children = parent_->children(); |
716 for (size_t i = 0; i < children.size(); ++i) | 735 for (size_t i = 0; i < children.size(); ++i) |
717 children[i]->RemoveObserver(this); | 736 children[i]->RemoveObserver(this); |
718 | 737 |
719 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | 738 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
720 view_->web_contents_->GetRenderWidgetHostView()); | 739 view_->web_contents_->GetRenderWidgetHostView()); |
721 if (view) | 740 if (view) |
722 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); | 741 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>()); |
723 } | 742 } |
| 743 |
| 744 // When we get parented to the root window, the code below will watch the |
| 745 // parent, aka root window. Since we already watch the root window on |
| 746 // Windows, unregister first so that the debug check doesn't fire. |
| 747 if (parent && parent == window->GetRootWindow()) |
| 748 parent->RemoveObserver(this); |
724 #endif | 749 #endif |
725 | 750 |
726 parent_ = parent; | 751 parent_ = parent; |
727 if (parent) { | 752 if (parent) { |
728 parent->AddObserver(this); | 753 parent->AddObserver(this); |
729 #if defined(OS_WIN) | 754 #if defined(OS_WIN) |
730 const aura::Window::Windows& children = parent_->children(); | 755 if (parent != window->GetRootWindow()) { |
731 for (size_t i = 0; i < children.size(); ++i) { | 756 const aura::Window::Windows& children = parent->children(); |
732 if (children[i] != view_->window_) | 757 for (size_t i = 0; i < children.size(); ++i) { |
733 children[i]->AddObserver(this); | 758 if (children[i] != view_->window_) |
| 759 children[i]->AddObserver(this); |
| 760 } |
734 } | 761 } |
735 #endif | 762 #endif |
736 } | 763 } |
737 } | 764 } |
738 | 765 |
739 virtual void OnWindowBoundsChanged(aura::Window* window, | 766 virtual void OnWindowBoundsChanged(aura::Window* window, |
740 const gfx::Rect& old_bounds, | 767 const gfx::Rect& old_bounds, |
741 const gfx::Rect& new_bounds) OVERRIDE { | 768 const gfx::Rect& new_bounds) OVERRIDE { |
742 if (window == parent_ || window == view_->window_) { | 769 if (window == parent_ || window == view_->window_) { |
743 SendScreenRects(); | 770 SendScreenRects(); |
744 if (view_->touch_editable_) | 771 if (view_->touch_editable_) |
745 view_->touch_editable_->UpdateEditingController(); | 772 view_->touch_editable_->UpdateEditingController(); |
746 #if defined(OS_WIN) | 773 #if defined(OS_WIN) |
747 } else { | 774 } else { |
748 UpdateConstrainedWindows(NULL); | 775 UpdateConstrainedWindows(NULL); |
749 #endif | 776 #endif |
750 } | 777 } |
751 } | 778 } |
752 | 779 |
753 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { | 780 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { |
754 if (window == view_->window_) | 781 if (window == view_->window_) { |
755 window->GetDispatcher()->AddRootWindowObserver(this); | 782 window->GetDispatcher()->AddRootWindowObserver(this); |
| 783 #if defined(OS_WIN) |
| 784 window->GetRootWindow()->AddObserver(this); |
| 785 #endif |
| 786 } |
756 } | 787 } |
757 | 788 |
758 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { | 789 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { |
759 if (window == view_->window_) | 790 if (window == view_->window_) { |
760 window->GetDispatcher()->RemoveRootWindowObserver(this); | 791 window->GetDispatcher()->RemoveRootWindowObserver(this); |
| 792 #if defined(OS_WIN) |
| 793 window->GetRootWindow()->RemoveObserver(this); |
| 794 #endif |
| 795 } |
761 } | 796 } |
762 | 797 |
763 // Overridden RootWindowObserver: | 798 // Overridden RootWindowObserver: |
764 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, | 799 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, |
765 const gfx::Point& new_origin) OVERRIDE { | 800 const gfx::Point& new_origin) OVERRIDE { |
766 TRACE_EVENT1("ui", | 801 TRACE_EVENT1("ui", |
767 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved", | 802 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved", |
768 "new_origin", new_origin.ToString()); | 803 "new_origin", new_origin.ToString()); |
769 | 804 |
770 // This is for the desktop case (i.e. Aura desktop). | 805 // This is for the desktop case (i.e. Aura desktop). |
771 SendScreenRects(); | 806 SendScreenRects(); |
772 } | 807 } |
773 | 808 |
774 private: | 809 private: |
775 void SendScreenRects() { | 810 void SendScreenRects() { |
776 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> | 811 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> |
777 SendScreenRects(); | 812 SendScreenRects(); |
778 } | 813 } |
779 | 814 |
780 #if defined(OS_WIN) | 815 #if defined(OS_WIN) |
781 void UpdateConstrainedWindows(aura::Window* exclude) { | 816 void UpdateConstrainedWindows(aura::Window* exclude) { |
782 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( | 817 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura( |
783 view_->web_contents_->GetRenderWidgetHostView()); | 818 view_->web_contents_->GetRenderWidgetHostView()); |
784 if (!view) | 819 if (!view) |
785 return; | 820 return; |
786 | 821 |
787 std::vector<gfx::Rect> constrained_windows; | 822 std::vector<gfx::Rect> constrained_windows; |
788 const aura::Window::Windows& children = parent_->children(); | 823 if (parent_) { |
789 for (size_t i = 0; i < children.size(); ++i) { | 824 const aura::Window::Windows& children = parent_->children(); |
790 if (children[i] != view_->window_ && | 825 for (size_t i = 0; i < children.size(); ++i) { |
791 children[i] != exclude && | 826 if (children[i] != view_->window_ && |
792 children[i]->IsVisible()) { | 827 children[i] != exclude && |
793 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); | 828 children[i]->IsVisible()) { |
| 829 constrained_windows.push_back(children[i]->GetBoundsInRootWindow()); |
| 830 } |
| 831 } |
| 832 } |
| 833 |
| 834 aura::Window* root_window = view_->window_->GetRootWindow(); |
| 835 const aura::Window::Windows& root_children = root_window->children(); |
| 836 if (root_window) { |
| 837 for (size_t i = 0; i < root_children.size(); ++i) { |
| 838 if (root_children[i]->IsVisible() && |
| 839 !root_children[i]->Contains(view_->window_.get())) { |
| 840 constrained_windows.push_back( |
| 841 root_children[i]->GetBoundsInRootWindow()); |
| 842 } |
794 } | 843 } |
795 } | 844 } |
796 | 845 |
797 view->UpdateConstrainedWindowRects(constrained_windows); | 846 view->UpdateConstrainedWindowRects(constrained_windows); |
798 } | 847 } |
799 #endif | 848 #endif |
800 | 849 |
801 WebContentsViewAura* view_; | 850 WebContentsViewAura* view_; |
802 | 851 |
803 // We cache the old parent so that we can unregister when it's not the parent | 852 // We cache the old parent so that we can unregister when it's not the parent |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 event.location(), | 1690 event.location(), |
1642 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1691 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1643 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1692 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1644 if (drag_dest_delegate_) | 1693 if (drag_dest_delegate_) |
1645 drag_dest_delegate_->OnDrop(); | 1694 drag_dest_delegate_->OnDrop(); |
1646 current_drop_data_.reset(); | 1695 current_drop_data_.reset(); |
1647 return current_drag_op_; | 1696 return current_drag_op_; |
1648 } | 1697 } |
1649 | 1698 |
1650 } // namespace content | 1699 } // namespace content |
OLD | NEW |