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

Side by Side 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: Observe all ancestors. 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 unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | 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/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <map>
8
7 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
8 #include "base/basictypes.h" 10 #include "base/basictypes.h"
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
11 #include "base/command_line.h" 13 #include "base/command_line.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
16 #include "cc/layers/layer.h" 18 #include "cc/layers/layer.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // Note: popup_parent_host_view_ may be NULL when there are multiple 326 // Note: popup_parent_host_view_ may be NULL when there are multiple
325 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup(). 327 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
326 Shutdown(); 328 Shutdown();
327 } 329 }
328 } 330 }
329 331
330 // We have to implement the WindowObserver interface on a separate object 332 // We have to implement the WindowObserver interface on a separate object
331 // because clang doesn't like implementing multiple interfaces that have 333 // because clang doesn't like implementing multiple interfaces that have
332 // methods with the same name. This object is owned by the 334 // methods with the same name. This object is owned by the
333 // RenderWidgetHostViewAura. 335 // RenderWidgetHostViewAura.
334 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { 336 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver {
sky 2015/04/09 00:01:14 Using the same class for two very different purpos
ananta 2015/04/09 03:36:05 Done.
335 public: 337 public:
336 explicit WindowObserver(RenderWidgetHostViewAura* view) 338 explicit WindowObserver(RenderWidgetHostViewAura* view)
337 : view_(view) { 339 : view_(view) {
338 view_->window_->AddObserver(this); 340 view_->window_->AddObserver(this);
339 } 341 }
340 342
341 ~WindowObserver() override { view_->window_->RemoveObserver(this); } 343 ~WindowObserver() override {
344 RemoveAncestorObservers();
345 view_->window_->RemoveObserver(this);
346 }
342 347
343 // Overridden from aura::WindowObserver: 348 // Overridden from aura::WindowObserver:
344 void OnWindowAddedToRootWindow(aura::Window* window) override { 349 void OnWindowAddedToRootWindow(aura::Window* window) override {
sky 2015/04/09 00:01:14 I don't think you're handling the case of ancestor
ananta 2015/04/09 03:36:05 Done.
345 if (window == view_->window_) 350 if (window == view_->window_) {
351 // We observe the ancestors for bounds changes and snap the RWHVA
352 // instance to pixel boundaries. Reason for doing this is there are
353 // cases like the fast resize code path for bookmarks where in the
354 // parent of RWHVA which is WCV has its bounds changed before the
355 // bookmark is hidden. This results in it reporting the old bounds
356 // which includes the bookmark. Eventually when it does get the correct
357 // bounds after the bar is hidden, the layer ignores the bounds changed
358 // call as the bounds are the same. To work around this we observe the
359 // parent of WCV for bounds changed notifications and snap when we
360 // receive them.
361 aura::Window* parent = window->parent();
362 while (parent) {
363 parent->AddObserver(this);
364 ancestor_observer_map_[parent] = true;
365 parent = parent->parent();
366 }
346 view_->AddedToRootWindow(); 367 view_->AddedToRootWindow();
368 }
347 } 369 }
348 370
349 void OnWindowRemovingFromRootWindow(aura::Window* window, 371 void OnWindowRemovingFromRootWindow(aura::Window* window,
350 aura::Window* new_root) override { 372 aura::Window* new_root) override {
351 if (window == view_->window_) 373 if (window == view_->window_) {
374 RemoveAncestorObservers();
352 view_->RemovingFromRootWindow(); 375 view_->RemovingFromRootWindow();
376 }
377 }
378
379 void OnWindowBoundsChanged(aura::Window* window,
380 const gfx::Rect& old_bounds,
381 const gfx::Rect& new_bounds) override {
382 if (ancestor_observer_map_.find(window) != ancestor_observer_map_.end())
383 view_->HandleParentBoundsChanged();
353 } 384 }
354 385
355 private: 386 private:
387 void RemoveAncestorObservers() {
388 for (auto ancestor_iterator : ancestor_observer_map_)
389 ancestor_iterator.first->RemoveObserver(this);
390 ancestor_observer_map_.clear();
391 }
392
356 RenderWidgetHostViewAura* view_; 393 RenderWidgetHostViewAura* view_;
394 std::map<aura::Window*, bool> ancestor_observer_map_;
sky 2015/04/09 00:01:14 I don't think you need a map, how about a set?
ananta 2015/04/09 03:36:05 Done.
357 395
358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 396 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
359 }; 397 };
360 398
361 //////////////////////////////////////////////////////////////////////////////// 399 ////////////////////////////////////////////////////////////////////////////////
362 // RenderWidgetHostViewAura, public: 400 // RenderWidgetHostViewAura, public:
363 401
364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, 402 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host,
365 bool is_guest_view_hack) 403 bool is_guest_view_hack)
366 : host_(RenderWidgetHostImpl::From(host)), 404 : host_(RenderWidgetHostImpl::From(host)),
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 ui::EF_RIGHT_MOUSE_BUTTON; 765 ui::EF_RIGHT_MOUSE_BUTTON;
728 return (event->flags() & kAllowedButtons) != 0; 766 return (event->flags() & kAllowedButtons) != 0;
729 } 767 }
730 default: 768 default:
731 break; 769 break;
732 } 770 }
733 #endif 771 #endif
734 return true; 772 return true;
735 } 773 }
736 774
775 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
776 SnapToPhysicalPixelBoundary();
sky 2015/04/09 00:01:14 Does this mean we can remove some calls to SnapToP
ananta 2015/04/09 03:36:05 Removed the call from WCVA.
777 #if defined(OS_WIN)
778 if (legacy_render_widget_host_HWND_) {
779 legacy_render_widget_host_HWND_->SetBounds(
780 window_->GetBoundsInRootWindow());
781 }
782 #endif
783 }
784
737 void RenderWidgetHostViewAura::MovePluginWindows( 785 void RenderWidgetHostViewAura::MovePluginWindows(
738 const std::vector<WebPluginGeometry>& plugin_window_moves) { 786 const std::vector<WebPluginGeometry>& plugin_window_moves) {
739 #if defined(OS_WIN) 787 #if defined(OS_WIN)
740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw 788 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
741 // over the browser UI. 789 // over the browser UI.
742 if (!window_->GetRootWindow()) { 790 if (!window_->GetRootWindow()) {
743 DCHECK(plugin_window_moves.empty()); 791 DCHECK(plugin_window_moves.empty());
744 return; 792 return;
745 } 793 }
746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); 794 HWND parent = window_->GetHost()->GetAcceleratedWidget();
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 2741
2694 //////////////////////////////////////////////////////////////////////////////// 2742 ////////////////////////////////////////////////////////////////////////////////
2695 // RenderWidgetHostViewBase, public: 2743 // RenderWidgetHostViewBase, public:
2696 2744
2697 // static 2745 // static
2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2746 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2699 GetScreenInfoForWindow(results, NULL); 2747 GetScreenInfoForWindow(results, NULL);
2700 } 2748 }
2701 2749
2702 } // namespace content 2750 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698