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