Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 54623007: Make code path for bounds changes getting to renderer less brittle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rewrote to track all ancestors of the view's window Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <set>
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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 ImageLayerDelegate layer_delegate_; 643 ImageLayerDelegate layer_delegate_;
642 644
643 // During tests, the aura windows don't get any paint updates. So the overlay 645 // 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 646 // container keeps waiting for a paint update it never receives, causing a
645 // timeout. So during tests, disable the wait for paint updates. 647 // timeout. So during tests, disable the wait for paint updates.
646 bool need_paint_update_; 648 bool need_paint_update_;
647 649
648 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay); 650 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlay);
649 }; 651 };
650 652
651 class WebContentsViewAura::WindowObserver 653 class WebContentsViewAura::WindowObserver
sky 2013/11/04 21:33:23 Can you move this into its own standalone object s
rharrison 2013/11/06 19:26:17 Done.
652 : public aura::WindowObserver, public aura::RootWindowObserver { 654 : public aura::WindowObserver, public aura::RootWindowObserver {
653 public: 655 public:
654 explicit WindowObserver(WebContentsViewAura* view) 656 explicit WindowObserver(WebContentsViewAura* view)
655 : view_(view), 657 : view_(view) {
656 parent_(NULL) {
657 view_->window_->AddObserver(this); 658 view_->window_->AddObserver(this);
659 std::set<aura::Window*> ancestors = GenerateAncestors(view_->window_.get());
660 AddToObserved(ancestors);
658 } 661 }
659 662
660 virtual ~WindowObserver() { 663 virtual ~WindowObserver() {
661 view_->window_->RemoveObserver(this); 664 view_->window_->RemoveObserver(this);
662 if (view_->window_->GetDispatcher()) 665 if (view_->window_->GetDispatcher())
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); 666 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this);
664 if (parent_) 667 RemoveFromObserved(observed_);
665 parent_->RemoveObserver(this);
666 } 668 }
667 669
668 // Overridden from aura::WindowObserver: 670 // Overridden from aura::WindowObserver:
669 virtual void OnWindowParentChanged(aura::Window* window, 671 virtual void OnWindowParentChanged(aura::Window* window,
670 aura::Window* parent) OVERRIDE { 672 aura::Window* parent) OVERRIDE {
671 if (window == parent_) 673 std::set<aura::Window*> ancestors = GenerateAncestors(view_->window_.get());
672 return; 674 RemoveFromObserved(RelativeComplement(ancestors, observed_));
673 if (parent_) 675 AddToObserved(RelativeComplement(observed_, ancestors));
674 parent_->RemoveObserver(this);
675 parent_ = parent;
676 if (parent)
677 parent->AddObserver(this);
678 } 676 }
679 677
680 virtual void OnWindowBoundsChanged(aura::Window* window, 678 virtual void OnWindowBoundsChanged(aura::Window* window,
681 const gfx::Rect& old_bounds, 679 const gfx::Rect& old_bounds,
682 const gfx::Rect& new_bounds) OVERRIDE { 680 const gfx::Rect& new_bounds) OVERRIDE {
683 SendScreenRects(); 681 SendScreenRects();
684 if (view_->touch_editable_) 682 if (view_->touch_editable_)
685 view_->touch_editable_->UpdateEditingController(); 683 view_->touch_editable_->UpdateEditingController();
sky 2013/11/04 21:33:23 Does this really need to be done any time the boun
rharrison 2013/11/06 19:26:17 Talked to varunjain@ about this and I think it doe
686 } 684 }
687 685
688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { 686 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
689 if (window != parent_) 687 if (window == view_->window_.get())
690 window->GetDispatcher()->AddRootWindowObserver(this); 688 window->GetDispatcher()->AddRootWindowObserver(this);
691 } 689 }
692 690
693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { 691 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
694 if (window != parent_) 692 if (window == view_->window_.get())
695 window->GetDispatcher()->RemoveRootWindowObserver(this); 693 window->GetDispatcher()->RemoveRootWindowObserver(this);
696 } 694 }
697 695
698 // Overridden RootWindowObserver: 696 // Overridden RootWindowObserver:
699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, 697 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
700 const gfx::Point& new_origin) OVERRIDE { 698 const gfx::Point& new_origin) OVERRIDE {
701 // This is for the desktop case (i.e. Aura desktop). 699 // This is for the desktop case (i.e. Aura desktop).
702 SendScreenRects(); 700 SendScreenRects();
703 } 701 }
704 702
705 private: 703 private:
706 void SendScreenRects() { 704 void SendScreenRects() {
707 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> 705 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
708 SendScreenRects(); 706 SendScreenRects();
709 } 707 }
710 708
709 std::set<aura::Window*> GenerateAncestors(aura::Window* window) {
710 std::set<aura::Window*> ret_val;
711 while (window->parent()) {
712 ret_val.insert(window->parent());
713 window = window->parent();
714 }
715 return ret_val;
716 }
717
718 void AddToObserved(std::set<aura::Window*> windows) {
sky 2013/11/04 21:34:01 const std::set&
rharrison 2013/11/06 19:26:17 Done.
719 for (std::set<aura::Window*>::iterator iter = windows.begin();
720 iter != windows.end();
721 ++iter) {
722 if (observed_.end() == observed_.find(*iter)) {
723 (*iter)->AddObserver(this);
724 observed_.insert(*iter);
725 }
726 }
727 }
728
729 void RemoveFromObserved(std::set<aura::Window*> windows) {
sky 2013/11/04 21:34:01 const std::set&
rharrison 2013/11/06 19:26:17 Done.
730 for (std::set<aura::Window*>::iterator iter = windows.begin();
731 iter != windows.end();
732 ++iter) {
733 if (observed_.end() != observed_.find(*iter)) {
734 (*iter)->RemoveObserver(this);
735 observed_.erase(*iter);
736 }
737 }
738 }
739
740 // Calculates the set of items in |set_b|, but not in |set_a|.
741 std::set<aura::Window*> RelativeComplement(std::set<aura::Window*> set_a,
sky 2013/11/04 21:33:23 Does std offer some function that does this?
sky 2013/11/04 21:34:01 const std::set&
rharrison 2013/11/06 19:26:17 Apparently it is std::set_difference... I probably
742 std::set<aura::Window*> set_b) {
743 std::set<aura::Window*> ret_val;
744 for (std::set<aura::Window*>::iterator iter = set_b.begin();
745 iter != set_b.end();
746 ++iter) {
747 if (set_a.end() == set_a.find(*iter))
748 ret_val.insert(*iter);
749 }
750 return ret_val;
751 }
752
711 WebContentsViewAura* view_; 753 WebContentsViewAura* view_;
712 754 std::set<aura::Window*> observed_;
713 // We cache the old parent so that we can unregister when it's not the parent
714 // anymore.
715 aura::Window* parent_;
716 755
717 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 756 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
718 }; 757 };
719 758
720 #if defined(OS_WIN) 759 #if defined(OS_WIN)
721 // Constrained windows are added as children of the WebContent's view which may 760 // 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 761 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it
723 // can update the plugins' cutout rects accordingly. 762 // can update the plugins' cutout rects accordingly.
724 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver, 763 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver,
725 public WebContentsObserver { 764 public WebContentsObserver {
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 event.location(), 1685 event.location(),
1647 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1686 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1648 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1687 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1649 if (drag_dest_delegate_) 1688 if (drag_dest_delegate_)
1650 drag_dest_delegate_->OnDrop(); 1689 drag_dest_delegate_->OnDrop();
1651 current_drop_data_.reset(); 1690 current_drop_data_.reset();
1652 return current_drag_op_; 1691 return current_drag_op_;
1653 } 1692 }
1654 1693
1655 } // namespace content 1694 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698