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

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: Fixed comments 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
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 <set>
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if (window == view_->window_) 347 if (window == view_->window_)
346 view_->AddedToRootWindow(); 348 view_->AddedToRootWindow();
347 } 349 }
348 350
349 void OnWindowRemovingFromRootWindow(aura::Window* window, 351 void OnWindowRemovingFromRootWindow(aura::Window* window,
350 aura::Window* new_root) override { 352 aura::Window* new_root) override {
351 if (window == view_->window_) 353 if (window == view_->window_)
352 view_->RemovingFromRootWindow(); 354 view_->RemovingFromRootWindow();
353 } 355 }
354 356
357 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
358 view_->ParentHierarchyChanged();
359 }
360
355 private: 361 private:
356 RenderWidgetHostViewAura* view_; 362 RenderWidgetHostViewAura* view_;
357 363
358 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 364 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
359 }; 365 };
360 366
367 // This class provides functionality to observe the ancestors of the RWHVA
sky 2015/04/10 15:20:21 This comment is misleading. Isn't the issue that w
ananta 2015/04/10 17:51:22 Reworded
368 // window for bounds changes and snap the RWHVA instance to pixel boundaries.
369 // Reason for doing this is there are cases like the fast resize code path for
370 // bookmarks where in the parent of RWHVA which is WCV has its bounds changed
371 // before the bookmark is hidden. This results in it reporting the old bounds
372 // which includes the bookmark. Eventually when it does get the correct bounds
373 // after the bar is hidden, the layer ignores the bounds changed call as the
374 // bounds are the same. To work around this we observe the
375 // ancestors of the RWHVA window for bounds changed notifications and snap when
376 // we receive them.
377 class RenderWidgetHostViewAura::WindowAncestorObserver
378 : public aura::WindowObserver {
379 public:
380 explicit WindowAncestorObserver(RenderWidgetHostViewAura* view)
381 : view_(view) {
382 aura::Window* parent = view_->window_->parent();
sky 2015/04/10 15:20:21 Isn't this a lot simpler!
ananta 2015/04/10 17:51:21 Yes. Thanks
383 while (parent) {
sky 2015/04/10 15:20:21 Who handles positioning when the bounds of view_->
ananta 2015/04/10 17:51:22 RWHVA in its OnBoundsChanged function via the Wind
384 parent->AddObserver(this);
385 ancestor_observer_tracker_.insert(parent);
386 parent = parent->parent();
387 }
388 }
389
390 ~WindowAncestorObserver() override {
391 RemoveAncestorObservers();
392 }
393
394 void OnWindowBoundsChanged(aura::Window* window,
395 const gfx::Rect& old_bounds,
396 const gfx::Rect& new_bounds) override {
397 if (ancestor_observer_tracker_.find(window) !=
sky 2015/04/10 15:20:21 Shouldn't this be a DCHECK?
ananta 2015/04/10 17:51:21 There is a DCHECK in the else. Were you indicating
sky 2015/04/10 19:36:25 I'm saying you should convert the if to a DCHECK a
398 ancestor_observer_tracker_.end()) {
399 if (new_bounds.origin() != old_bounds.origin())
400 view_->HandleParentBoundsChanged();
401 } else {
402 DCHECK(false);
403 }
404 }
405
406 private:
407 void RemoveAncestorObservers() {
408 for (auto ancestor : ancestor_observer_tracker_)
409 ancestor->RemoveObserver(this);
410 ancestor_observer_tracker_.clear();
411 }
412
413 RenderWidgetHostViewAura* view_;
414 std::set<aura::Window*> ancestor_observer_tracker_;
sky 2015/04/10 15:20:21 Why the observer_tracker_? How about just ancestor
ananta 2015/04/10 17:51:21 Done.
415
416 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver);
417 };
418
361 //////////////////////////////////////////////////////////////////////////////// 419 ////////////////////////////////////////////////////////////////////////////////
362 // RenderWidgetHostViewAura, public: 420 // RenderWidgetHostViewAura, public:
363 421
364 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, 422 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host,
365 bool is_guest_view_hack) 423 bool is_guest_view_hack)
366 : host_(RenderWidgetHostImpl::From(host)), 424 : host_(RenderWidgetHostImpl::From(host)),
367 window_(new aura::Window(this)), 425 window_(new aura::Window(this)),
368 delegated_frame_host_(new DelegatedFrameHost(this)), 426 delegated_frame_host_(new DelegatedFrameHost(this)),
369 in_shutdown_(false), 427 in_shutdown_(false),
370 in_bounds_changed_(false), 428 in_bounds_changed_(false),
(...skipping 17 matching lines...) Expand all
388 showing_context_menu_(false), 446 showing_context_menu_(false),
389 #endif 447 #endif
390 has_snapped_to_boundary_(false), 448 has_snapped_to_boundary_(false),
391 touch_editing_client_(NULL), 449 touch_editing_client_(NULL),
392 is_guest_view_hack_(is_guest_view_hack), 450 is_guest_view_hack_(is_guest_view_hack),
393 weak_ptr_factory_(this) { 451 weak_ptr_factory_(this) {
394 if (!is_guest_view_hack_) 452 if (!is_guest_view_hack_)
395 host_->SetView(this); 453 host_->SetView(this);
396 454
397 window_observer_.reset(new WindowObserver(this)); 455 window_observer_.reset(new WindowObserver(this));
456
398 aura::client::SetTooltipText(window_, &tooltip_); 457 aura::client::SetTooltipText(window_, &tooltip_);
399 aura::client::SetActivationDelegate(window_, this); 458 aura::client::SetActivationDelegate(window_, this);
400 aura::client::SetFocusChangeObserver(window_, this); 459 aura::client::SetFocusChangeObserver(window_, this);
401 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 460 window_->set_layer_owner_delegate(delegated_frame_host_.get());
402 gfx::Screen::GetScreenFor(window_)->AddObserver(this); 461 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
403 462
404 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()-> 463 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
405 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; 464 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
406 SetOverscrollControllerEnabled(overscroll_enabled); 465 SetOverscrollControllerEnabled(overscroll_enabled);
407 } 466 }
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 ui::EF_RIGHT_MOUSE_BUTTON; 786 ui::EF_RIGHT_MOUSE_BUTTON;
728 return (event->flags() & kAllowedButtons) != 0; 787 return (event->flags() & kAllowedButtons) != 0;
729 } 788 }
730 default: 789 default:
731 break; 790 break;
732 } 791 }
733 #endif 792 #endif
734 return true; 793 return true;
735 } 794 }
736 795
796 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
797 SnapToPhysicalPixelBoundary();
798 #if defined(OS_WIN)
799 if (legacy_render_widget_host_HWND_) {
800 legacy_render_widget_host_HWND_->SetBounds(
801 window_->GetBoundsInRootWindow());
802 }
803 #endif
804 }
805
806 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
807 ancestor_window_observer_.reset(new WindowAncestorObserver(this));
808 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
sky 2015/04/10 15:20:21 I shouldn't have to look at a bug to see why we ne
809 HandleParentBoundsChanged();
810 }
811
737 void RenderWidgetHostViewAura::MovePluginWindows( 812 void RenderWidgetHostViewAura::MovePluginWindows(
738 const std::vector<WebPluginGeometry>& plugin_window_moves) { 813 const std::vector<WebPluginGeometry>& plugin_window_moves) {
739 #if defined(OS_WIN) 814 #if defined(OS_WIN)
740 // We need to clip the rectangle to the tab's viewport, otherwise we will draw 815 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
741 // over the browser UI. 816 // over the browser UI.
742 if (!window_->GetRootWindow()) { 817 if (!window_->GetRootWindow()) {
743 DCHECK(plugin_window_moves.empty()); 818 DCHECK(plugin_window_moves.empty());
744 return; 819 return;
745 } 820 }
746 HWND parent = window_->GetHost()->GetAcceleratedWidget(); 821 HWND parent = window_->GetHost()->GetAcceleratedWidget();
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after
2693 2768
2694 //////////////////////////////////////////////////////////////////////////////// 2769 ////////////////////////////////////////////////////////////////////////////////
2695 // RenderWidgetHostViewBase, public: 2770 // RenderWidgetHostViewBase, public:
2696 2771
2697 // static 2772 // static
2698 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2773 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2699 GetScreenInfoForWindow(results, NULL); 2774 GetScreenInfoForWindow(results, NULL);
2700 } 2775 }
2701 2776
2702 } // namespace content 2777 } // namespace content
OLDNEW
« 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