diff options
author | thakis <thakis@chromium.org> | 2015-04-12 19:58:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-13 02:59:30 +0000 |
commit | 144ff57dc021b068d0df1100406c59c25f724b99 (patch) | |
tree | ff31520b77418f018c7772c7e469249633d9d2d9 /content | |
parent | 75a87ee977a373eb0e180ff62bd46149ba4f9727 (diff) | |
download | chromium_src-144ff57dc021b068d0df1100406c59c25f724b99.zip chromium_src-144ff57dc021b068d0df1100406c59c25f724b99.tar.gz chromium_src-144ff57dc021b068d0df1100406c59c25f724b99.tar.bz2 |
Revert of Revert of Snap RWHVA and resize the legacy window on Windows whenever the ancestor window's bounds change. (patchset #1 id:1 of https://codereview.chromium.org/1063083003/)
Reason for revert:
Reverting this didn't help, relanding.
Original issue's description:
> Revert of Snap RWHVA and resize the legacy window on Windows whenever the ancestor window's bounds change. (patchset #12 id:220001 of https://codereview.chromium.org/1062273002/)
>
> Reason for revert:
> Speculative, possibly caused lots of browsert_tests redness on a bot that runs browser_tests with an official build (and a different compiler, but all the redness we fixed on official builds so far were caused by the builds being official, not because of the compiler): http://build.chromium.org/p/chromium.fyi/builders/CrWinClang%20tester/builds/285 (see http://crbug.com/467929)
>
> Original issue's description:
> > Snap RWHVA and resize the legacy window on Windows whenever the ancestor window's bounds change.
> >
> > The bookmark bar is hidden through the fast resize code path where in the Renderer is informed about
> > the actual size minus the bookmar bar before the bookmark bar is hidden. To ensure that the RWHVA is snapped
> > to pixel boundaries and the legacy window is resized we observe bounds changed events on the parent of the WCVA
> > window which is the NativeViewHost clipping window. Reason for doing this is the layer for the window hosted by WCVA
> > verifies if the stored bounds is the same as the one coming in and ignores the change if yes.
> >
> > For more context and a general discussion of the reason why this bug happens please visit this link
> > https://codereview.chromium.org/1009533005/
> >
> > BUG=469857, 468669
> >
> > Committed: https://crrev.com/e6a9b7fff4802ac6796250987be4d52204716392
> > Cr-Commit-Position: refs/heads/master@{#324743}
>
> TBR=sky@chromium.org,scottmg@chromium.org,cpu@chromium.org,ananta@chromium.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=469857, 468669
>
> Committed: https://crrev.com/67bcbf34229acff21e300e630ee871b0a64871b4
> Cr-Commit-Position: refs/heads/master@{#324804}
TBR=sky@chromium.org,scottmg@chromium.org,cpu@chromium.org,ananta@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=469857, 468669
Review URL: https://codereview.chromium.org/1050203004
Cr-Commit-Position: refs/heads/master@{#324808}
Diffstat (limited to 'content')
3 files changed, 83 insertions, 15 deletions
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index 1463557..fd85fcc 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -4,6 +4,8 @@ #include "content/browser/renderer_host/render_widget_host_view_aura.h" +#include <set> + #include "base/auto_reset.h" #include "base/basictypes.h" #include "base/bind.h" @@ -352,12 +354,64 @@ class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { view_->RemovingFromRootWindow(); } + void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override { + view_->ParentHierarchyChanged(); + } + private: RenderWidgetHostViewAura* view_; DISALLOW_COPY_AND_ASSIGN(WindowObserver); }; +// This class provides functionality to observe the ancestors of the RWHVA for +// bounds changes. This is done to snap the RWHVA window to a pixel boundary, +// which could change when the bounds relative to the root changes. +// An example where this happens is below:- +// The fast resize code path for bookmarks where in the parent of RWHVA which +// is WCV has its bounds changed before the bookmark is hidden. This results in +// the traditional bounds change notification for the WCV reporting the old +// bounds as the bookmark is still around. Observing all the ancestors of the +// RWHVA window enables us to know when the bounds of the window relative to +// root changes and allows us to snap accordingly. +class RenderWidgetHostViewAura::WindowAncestorObserver + : public aura::WindowObserver { + public: + explicit WindowAncestorObserver(RenderWidgetHostViewAura* view) + : view_(view) { + aura::Window* parent = view_->window_->parent(); + while (parent) { + parent->AddObserver(this); + ancestors_.insert(parent); + parent = parent->parent(); + } + } + + ~WindowAncestorObserver() override { + RemoveAncestorObservers(); + } + + void OnWindowBoundsChanged(aura::Window* window, + const gfx::Rect& old_bounds, + const gfx::Rect& new_bounds) override { + DCHECK(ancestors_.find(window) != ancestors_.end()); + if (new_bounds.origin() != old_bounds.origin()) + view_->HandleParentBoundsChanged(); + } + + private: + void RemoveAncestorObservers() { + for (auto ancestor : ancestors_) + ancestor->RemoveObserver(this); + ancestors_.clear(); + } + + RenderWidgetHostViewAura* view_; + std::set<aura::Window*> ancestors_; + + DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver); +}; + //////////////////////////////////////////////////////////////////////////////// // RenderWidgetHostViewAura, public: @@ -395,6 +449,7 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, host_->SetView(this); window_observer_.reset(new WindowObserver(this)); + aura::client::SetTooltipText(window_, &tooltip_); aura::client::SetActivationDelegate(window_, this); aura::client::SetFocusChangeObserver(window_, this); @@ -734,6 +789,22 @@ bool RenderWidgetHostViewAura::CanRendererHandleEvent( return true; } +void RenderWidgetHostViewAura::HandleParentBoundsChanged() { + SnapToPhysicalPixelBoundary(); +#if defined(OS_WIN) + if (legacy_render_widget_host_HWND_) { + legacy_render_widget_host_HWND_->SetBounds( + window_->GetBoundsInRootWindow()); + } +#endif +} + +void RenderWidgetHostViewAura::ParentHierarchyChanged() { + ancestor_window_observer_.reset(new WindowAncestorObserver(this)); + // Snap when we receive a hierarchy changed. http://crbug.com/388908. + HandleParentBoundsChanged(); +} + void RenderWidgetHostViewAura::MovePluginWindows( const std::vector<WebPluginGeometry>& plugin_window_moves) { #if defined(OS_WIN) diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index 89bead7..d9e1201 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -401,6 +401,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAura class WindowObserver; friend class WindowObserver; + class WindowAncestorObserver; + friend class WindowAncestorObserver; + void UpdateCursorIfOverSelf(); // Tracks whether SnapToPhysicalPixelBoundary() has been called. @@ -500,6 +503,12 @@ class CONTENT_EXPORT RenderWidgetHostViewAura bool mouse_locked, bool selection_popup); + // Called when the parent window bounds change. + void HandleParentBoundsChanged(); + + // Called when the parent window hierarchy for our window changes. + void ParentHierarchyChanged(); + // The model object. RenderWidgetHostImpl* host_; @@ -509,6 +518,9 @@ class CONTENT_EXPORT RenderWidgetHostViewAura scoped_ptr<WindowObserver> window_observer_; + // Tracks the ancestors of the RWHVA window for window location changes. + scoped_ptr<WindowAncestorObserver> ancestor_window_observer_; + // Are we in the process of closing? Tracked so fullscreen views can avoid // sending a second shutdown request to the host when they lose the focus // after requesting shutdown for another reason (e.g. Escape key). diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc index ce104f2..f0d20fa 100644 --- a/content/browser/web_contents/web_contents_view_aura.cc +++ b/content/browser/web_contents/web_contents_view_aura.cc @@ -429,21 +429,6 @@ class WebContentsViewAura::WindowObserver #endif } - // Overridden from aura::WindowObserver: - void OnWindowHierarchyChanged( - const aura::WindowObserver::HierarchyChangeParams& params) override { - if (params.receiver != view_->window_.get() || - !params.target->Contains(view_->window_.get())) { - return; - } - - // Use the new parent's root window for calculating HiDPI subpixel offset. - RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura( - view_->web_contents_->GetRenderWidgetHostView()); - if (rwhv) - rwhv->SnapToPhysicalPixelBoundary(); - } - #if defined(OS_WIN) // Constrained windows are added as children of the parent's parent's view // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV |