summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta <ananta@chromium.org>2015-04-10 18:42:30 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-11 01:42:53 +0000
commite6a9b7fff4802ac6796250987be4d52204716392 (patch)
tree239febc39529d39e69c626507be0453f8635a998
parenta473689bf790b2622ccd5c220695c74f76779cdb (diff)
downloadchromium_src-e6a9b7fff4802ac6796250987be4d52204716392.zip
chromium_src-e6a9b7fff4802ac6796250987be4d52204716392.tar.gz
chromium_src-e6a9b7fff4802ac6796250987be4d52204716392.tar.bz2
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 Review URL: https://codereview.chromium.org/1062273002 Cr-Commit-Position: refs/heads/master@{#324743}
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.cc71
-rw-r--r--content/browser/renderer_host/render_widget_host_view_aura.h12
-rw-r--r--content/browser/web_contents/web_contents_view_aura.cc15
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