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

Unified Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 1062273002: Snap RWHVA and resize the legacy window on Windows whenever the ancestor window's bounds change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DCHECK in WindowAncestorObserver::OnWindowBoundsChanged Created 5 years, 8 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host_view_aura.cc
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 146355707f08f247446929d5c6c0d22d7b5e11e2..bd7e516724a66502668348c5e67b2c38d897e1d0 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)
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | content/browser/web_contents/web_contents_view_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698