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

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 2860433002: Update WebView/FrameView size from LayoutView::UpdateAfterLayout (Closed)
Patch Set: nits Created 3 years, 7 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 /* 1 /*
2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 2 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 * 1999 Lars Knoll <knoll@kde.org> 3 * 1999 Lars Knoll <knoll@kde.org>
4 * 1999 Antti Koivisto <koivisto@kde.org> 4 * 1999 Antti Koivisto <koivisto@kde.org>
5 * 2000 Dirk Mueller <mueller@kde.org> 5 * 2000 Dirk Mueller <mueller@kde.org>
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com) 7 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 8 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
9 * Copyright (C) 2009 Google Inc. All rights reserved. 9 * Copyright (C) 2009 Google Inc. All rights reserved.
10 * 10 *
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 547 }
548 548
549 void FrameView::SetFrameRect(const IntRect& frame_rect) { 549 void FrameView::SetFrameRect(const IntRect& frame_rect) {
550 if (frame_rect == frame_rect_) 550 if (frame_rect == frame_rect_)
551 return; 551 return;
552 552
553 const bool width_changed = frame_rect_.Width() != frame_rect.Width(); 553 const bool width_changed = frame_rect_.Width() != frame_rect.Width();
554 const bool height_changed = frame_rect_.Height() != frame_rect.Height(); 554 const bool height_changed = frame_rect_.Height() != frame_rect.Height();
555 frame_rect_ = frame_rect; 555 frame_rect_ = frame_rect;
556 556
557 needs_scrollbars_update_ = width_changed || height_changed; 557 needs_scrollbars_update_ |= width_changed || height_changed;
bokan 2017/05/10 21:30:07 This change is subtle, is this maybe what fixes th
szager1 2017/05/11 12:50:54 With the old code, I couldn't see a path where nee
bokan 2017/05/11 16:51:08 Ah, you're right, UpdateScrollbarsIfNeeded below w
558 // TODO(wjmaclean): find out why scrollbars fail to resize for complex 558
559 // subframes after changing the zoom level. For now always calling 559 // If this is not the main frame, then we got here via
560 // updateScrollbarsIfNeeded() here fixes the issue, but it would be good to 560 // LayoutPart::UpdateGeometryInternal. In that case, we can't clamp the
561 // discover the deeper cause of this. http://crbug.com/607987. 561 // scroll offset yet, because we still need to run UpdateLayout(), so our
bokan 2017/05/10 21:30:07 Does this CL fix the linked issue? e.g. if you run
szager1 2017/05/11 12:50:54 Yes, that appears to work correctly now. I'll add
562 UpdateScrollbarsIfNeeded(); 562 // clamping boundaries may yet change.
563 if (GetFrame().IsMainFrame()) {
564 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
565 if (LayoutView* lv = GetLayoutView())
566 lv->GetScrollableArea()->ClampScrollOffsetAfterOverflowChange();
bokan 2017/05/10 21:30:07 Why do we need to special case the main frame here
szager1 2017/05/11 12:50:54 Without this, I get a unit test failure VisualVie
bokan 2017/05/11 16:51:08 Right, because hiding top controls will change the
szager1 2017/05/11 20:12:00 Done.
567 } else {
568 AdjustScrollOffsetFromUpdateScrollbars();
569 }
570 }
563 571
564 FrameRectsChanged(); 572 FrameRectsChanged();
565 573
566 UpdateParentScrollableAreaSet(); 574 UpdateParentScrollableAreaSet();
567 575
568 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled() && 576 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled() &&
569 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 577 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
570 // The overflow clip property depends on the frame size and the pre 578 // The overflow clip property depends on the frame size and the pre
571 // translation property depends on the frame location. 579 // translation property depends on the frame location.
572 SetNeedsPaintPropertyUpdate(); 580 SetNeedsPaintPropertyUpdate();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 711
704 Scrollbar* FrameView::CreateScrollbar(ScrollbarOrientation orientation) { 712 Scrollbar* FrameView::CreateScrollbar(ScrollbarOrientation orientation) {
705 return scrollbar_manager_.CreateScrollbar(orientation); 713 return scrollbar_manager_.CreateScrollbar(orientation);
706 } 714 }
707 715
708 void FrameView::SetContentsSize(const IntSize& size) { 716 void FrameView::SetContentsSize(const IntSize& size) {
709 if (size == ContentsSize()) 717 if (size == ContentsSize())
710 return; 718 return;
711 719
712 contents_size_ = size; 720 contents_size_ = size;
713 UpdateScrollbars(); 721 needs_scrollbars_update_ = true;
714 ScrollableArea::ContentsResized(); 722 ScrollableArea::ContentsResized();
715 723
716 Page* page = GetFrame().GetPage(); 724 Page* page = GetFrame().GetPage();
717 if (!page) 725 if (!page)
718 return; 726 return;
719 727
720 UpdateParentScrollableAreaSet();
721
722 page->GetChromeClient().ContentsSizeChanged(frame_.Get(), size); 728 page->GetChromeClient().ContentsSizeChanged(frame_.Get(), size);
723 729
724 // Ensure the scrollToFragmentAnchor is called before 730 // Ensure the scrollToFragmentAnchor is called before
725 // restoreScrollPositionAndViewState when reload 731 // restoreScrollPositionAndViewState when reload
726 ScrollToFragmentAnchor(); 732 ScrollToFragmentAnchor();
727 GetFrame().Loader().RestoreScrollPositionAndViewState(); 733 GetFrame().Loader().RestoreScrollPositionAndViewState();
728 } 734 }
729 735
730 void FrameView::AdjustViewSize() { 736 void FrameView::AdjustViewSize() {
731 if (suppress_adjust_view_size_) 737 if (suppress_adjust_view_size_)
732 return; 738 return;
733 739
734 LayoutViewItem layout_view_item = this->GetLayoutViewItem(); 740 LayoutViewItem layout_view_item = this->GetLayoutViewItem();
735 if (layout_view_item.IsNull()) 741 if (layout_view_item.IsNull())
736 return; 742 return;
737 743
738 ASSERT(frame_->View() == this); 744 ASSERT(frame_->View() == this);
739 745
740 const IntRect rect = layout_view_item.DocumentRect(); 746 const IntRect rect = layout_view_item.DocumentRect();
741 const IntSize& size = rect.Size(); 747 const IntSize& size = rect.Size();
742 748
743 const IntPoint origin(-rect.X(), -rect.Y()); 749 const IntPoint origin(-rect.X(), -rect.Y());
744 if (ScrollOrigin() != origin) { 750 if (ScrollOrigin() != origin) {
bokan 2017/05/10 21:30:07 Nit: remove braces
szager1 2017/05/11 12:50:54 Done.
745 SetScrollOrigin(origin); 751 SetScrollOrigin(origin);
746 // setContentSize (below) also calls updateScrollbars so we can avoid
747 // updating scrollbars twice by skipping the call here when the content
748 // size does not change.
749 if (!frame_->GetDocument()->Printing() && size == ContentsSize())
750 UpdateScrollbars();
751 } 752 }
752 753
753 SetContentsSize(size); 754 SetContentsSize(size);
754 } 755 }
755 756
756 void FrameView::AdjustViewSizeAndLayout() { 757 void FrameView::AdjustViewSizeAndLayout() {
757 AdjustViewSize(); 758 AdjustViewSize();
758 if (NeedsLayout()) { 759 if (NeedsLayout()) {
759 AutoReset<bool> suppress_adjust_view_size(&suppress_adjust_view_size_, 760 AutoReset<bool> suppress_adjust_view_size(&suppress_adjust_view_size_,
760 true); 761 true);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 bool has_horizontal_scrollbar = HorizontalScrollbar(); 879 bool has_horizontal_scrollbar = HorizontalScrollbar();
879 bool has_vertical_scrollbar = VerticalScrollbar(); 880 bool has_vertical_scrollbar = VerticalScrollbar();
880 if (has_horizontal_scrollbar != should_have_horizontal_scrollbar || 881 if (has_horizontal_scrollbar != should_have_horizontal_scrollbar ||
881 has_vertical_scrollbar != should_have_vertical_scrollbar) { 882 has_vertical_scrollbar != should_have_vertical_scrollbar) {
882 SetNeedsLayout(); 883 SetNeedsLayout();
883 return; 884 return;
884 } 885 }
885 886
886 AdjustViewSize(); 887 AdjustViewSize();
887 UpdateScrollbarGeometry(); 888 UpdateScrollbarGeometry();
889 SetNeedsPaintPropertyUpdate();
888 890
889 if (ScrollOriginChanged()) 891 if (ScrollOriginChanged())
890 SetNeedsLayout(); 892 SetNeedsLayout();
891 } 893 }
892 894
893 bool FrameView::UsesCompositedScrolling() const { 895 bool FrameView::UsesCompositedScrolling() const {
894 LayoutViewItem layout_view = this->GetLayoutViewItem(); 896 LayoutViewItem layout_view = this->GetLayoutViewItem();
895 if (layout_view.IsNull()) 897 if (layout_view.IsNull())
896 return false; 898 return false;
897 if (frame_->GetSettings() && 899 if (frame_->GetSettings() &&
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 else if (root_layout_object && 1303 else if (root_layout_object &&
1302 root_layout_object->StretchesToViewport()) 1304 root_layout_object->StretchesToViewport())
1303 root_layout_object->SetChildNeedsLayout(); 1305 root_layout_object->SetChildNeedsLayout();
1304 } 1306 }
1305 } 1307 }
1306 1308
1307 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 1309 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
1308 TRACE_DISABLED_BY_DEFAULT("blink.debug.layout.trees"), "LayoutTree", 1310 TRACE_DISABLED_BY_DEFAULT("blink.debug.layout.trees"), "LayoutTree",
1309 this, TracedLayoutObject::Create(*GetLayoutView(), false)); 1311 this, TracedLayoutObject::Create(*GetLayoutView(), false));
1310 1312
1313 IntSize old_size(Size());
1314
1311 PerformLayout(in_subtree_layout); 1315 PerformLayout(in_subtree_layout);
1316 UpdateScrollbars();
1317 UpdateParentScrollableAreaSet();
1312 1318
1313 if (!in_subtree_layout && !document->Printing()) 1319 IntSize new_size(Size());
1314 AdjustViewSizeAndLayout(); 1320 if (old_size != new_size) {
1321 needs_scrollbars_update_ = true;
1322 SetNeedsLayout();
1323 MarkViewportConstrainedObjectsForLayout(
bokan 2017/05/10 21:30:07 Will ViewportConstrainedObjects still get laid out
szager1 2017/05/11 12:50:54 Yes, because UpdateScrollbars() above will recursi
bokan 2017/05/11 16:51:08 Got it, thanks.
1324 old_size.Width() != new_size.Width(),
1325 old_size.Height() != new_size.Height());
1326 }
1327
1328 if (NeedsLayout()) {
1329 AutoReset<bool> suppress(&suppress_adjust_view_size_, true);
1330 UpdateLayout();
1331 }
1315 1332
1316 ASSERT(layout_subtree_root_list_.IsEmpty()); 1333 ASSERT(layout_subtree_root_list_.IsEmpty());
1317 } // Reset m_layoutSchedulingEnabled to its previous value. 1334 } // Reset m_layoutSchedulingEnabled to its previous value.
1318 CheckDoesNotNeedLayout(); 1335 CheckDoesNotNeedLayout();
1319 1336
1320 frame_timing_requests_dirty_ = true; 1337 frame_timing_requests_dirty_ = true;
1321 1338
1322 // FIXME: Could find the common ancestor layer of all dirty subtrees and mark 1339 // FIXME: Could find the common ancestor layer of all dirty subtrees and mark
1323 // from there. crbug.com/462719 1340 // from there. crbug.com/462719
1324 GetLayoutViewItem().EnclosingLayer()->UpdateLayerPositionsAfterLayout(); 1341 GetLayoutViewItem().EnclosingLayer()->UpdateLayerPositionsAfterLayout();
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) 1681 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled())
1665 SetNeedsPaintPropertyUpdate(); 1682 SetNeedsPaintPropertyUpdate();
1666 } else { 1683 } else {
1667 layout_view.Compositor()->FrameViewDidChangeSize(); 1684 layout_view.Compositor()->FrameViewDidChangeSize();
1668 } 1685 }
1669 } 1686 }
1670 } 1687 }
1671 1688
1672 ShowOverlayScrollbars(); 1689 ShowOverlayScrollbars();
1673 1690
1674 if (root_layer_scrolling_enabled) {
1675 // The background must be repainted when the FrameView is resized, even if
1676 // the initial containing block does not change (so we can't rely on layout
1677 // to issue the invalidation). This is because the background fills the
1678 // main GraphicsLayer, which takes the size of the layout viewport.
1679 // TODO(skobes): Paint non-fixed backgrounds into the scrolling contents
1680 // layer and avoid this invalidation (http://crbug.com/568847).
1681 LayoutViewItem lvi = GetLayoutViewItem();
1682 if (!lvi.IsNull())
1683 lvi.SetShouldDoFullPaintInvalidation();
bokan 2017/05/10 21:30:07 Why do we no longer need this? There's cases where
szager1 2017/05/11 12:50:54 The background paint invalidation issue was fixed
bokan 2017/05/11 16:51:08 Acknowledged.
1684 }
1685
1686 if (RuntimeEnabledFeatures::inertTopControlsEnabled() && GetLayoutView() && 1691 if (RuntimeEnabledFeatures::inertTopControlsEnabled() && GetLayoutView() &&
1687 frame_->IsMainFrame() && 1692 frame_->IsMainFrame() &&
1688 frame_->GetPage()->GetBrowserControls().Height()) { 1693 frame_->GetPage()->GetBrowserControls().Height()) {
1689 if (GetLayoutView()->Style()->HasFixedBackgroundImage()) { 1694 if (GetLayoutView()->Style()->HasFixedBackgroundImage()) {
1690 // In the case where we don't change layout size from top control resizes, 1695 // In the case where we don't change layout size from top control resizes,
1691 // we wont perform a layout. If we have a fixed background image however, 1696 // we wont perform a layout. If we have a fixed background image however,
1692 // the background layer needs to get resized so we should request a layout 1697 // the background layer needs to get resized so we should request a layout
1693 // explicitly. 1698 // explicitly.
1694 PaintLayer* layer = GetLayoutView()->Layer(); 1699 PaintLayer* layer = GetLayoutView()->Layer();
1695 if (GetLayoutView()->Compositor()->NeedsFixedRootBackgroundLayer(layer)) { 1700 if (GetLayoutView()->Compositor()->NeedsFixedRootBackgroundLayer(layer)) {
1696 SetNeedsLayout(); 1701 SetNeedsLayout();
1697 } else if (!root_layer_scrolling_enabled) { 1702 } else {
1698 // If root layer scrolls is on, we've already issued a full invalidation 1703 // If root layer scrolls is on, we've already issued a full invalidation
1699 // above. 1704 // above.
1700 GetLayoutView()->SetShouldDoFullPaintInvalidationOnResizeIfNeeded( 1705 GetLayoutView()->SetShouldDoFullPaintInvalidationOnResizeIfNeeded(
1701 width_changed, height_changed); 1706 width_changed, height_changed);
1702 } 1707 }
1703 } else if (height_changed && !root_layer_scrolling_enabled) { 1708 } else if (height_changed) {
1704 // If the document rect doesn't fill the full view height, hiding the 1709 // If the document rect doesn't fill the full view height, hiding the
1705 // URL bar will expose area outside the current LayoutView so we need to 1710 // URL bar will expose area outside the current LayoutView so we need to
1706 // paint additional background. If RLS is on, we've already invalidated 1711 // paint additional background. If RLS is on, we've already invalidated
1707 // above. 1712 // above.
1708 LayoutViewItem lvi = GetLayoutViewItem(); 1713 LayoutViewItem lvi = GetLayoutViewItem();
1709 DCHECK(!lvi.IsNull()); 1714 DCHECK(!lvi.IsNull());
1710 if (lvi.DocumentRect().Height() < lvi.ViewRect().Height()) 1715 if (lvi.DocumentRect().Height() < lvi.ViewRect().Height())
1711 lvi.SetShouldDoFullPaintInvalidation(); 1716 lvi.SetShouldDoFullPaintInvalidation();
1712 } 1717 }
1713 } 1718 }
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 // frame(). 2169 // frame().
2165 if (!GetFrame().View()) 2170 if (!GetFrame().View())
2166 return; 2171 return;
2167 2172
2168 Element* custom_scrollbar_element = nullptr; 2173 Element* custom_scrollbar_element = nullptr;
2169 2174
2170 bool uses_overlay_scrollbars = 2175 bool uses_overlay_scrollbars =
2171 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() && 2176 ScrollbarTheme::GetTheme().UsesOverlayScrollbars() &&
2172 !ShouldUseCustomScrollbars(custom_scrollbar_element); 2177 !ShouldUseCustomScrollbars(custom_scrollbar_element);
2173 2178
2174 // FIXME: this call to layout() could be called within FrameView::layout(),
2175 // but before performLayout(), causing double-layout. See also
2176 // crbug.com/429242.
2177 if (!uses_overlay_scrollbars && NeedsLayout()) 2179 if (!uses_overlay_scrollbars && NeedsLayout())
2178 UpdateLayout(); 2180 UpdateLayout();
2179 2181
2180 if (!GetLayoutViewItem().IsNull() && GetLayoutViewItem().UsesCompositing()) { 2182 if (!GetLayoutViewItem().IsNull() && GetLayoutViewItem().UsesCompositing()) {
2181 GetLayoutViewItem().Compositor()->FrameViewScrollbarsExistenceDidChange(); 2183 GetLayoutViewItem().Compositor()->FrameViewScrollbarsExistenceDidChange();
2182 2184
2183 if (!uses_overlay_scrollbars) 2185 if (!uses_overlay_scrollbars)
2184 GetLayoutViewItem().Compositor()->FrameViewDidChangeSize(); 2186 GetLayoutViewItem().Compositor()->FrameViewDidChangeSize();
2185 } 2187 }
2186 } 2188 }
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 if (!horizontal_writing_mode) 3594 if (!horizontal_writing_mode)
3593 overflow = overflow.TransposedRect(); 3595 overflow = overflow.TransposedRect();
3594 AdjustViewSizeAndLayout(); 3596 AdjustViewSizeAndLayout();
3595 // This is how we clip in case we overflow again. 3597 // This is how we clip in case we overflow again.
3596 layout_view->ClearLayoutOverflow(); 3598 layout_view->ClearLayoutOverflow();
3597 layout_view->AddLayoutOverflow(overflow); 3599 layout_view->AddLayoutOverflow(overflow);
3598 return; 3600 return;
3599 } 3601 }
3600 } 3602 }
3601 3603
3604 if (TextAutosizer* text_autosizer = frame_->GetDocument()->GetTextAutosizer())
3605 text_autosizer->UpdatePageInfo();
3602 AdjustViewSizeAndLayout(); 3606 AdjustViewSizeAndLayout();
3603 } 3607 }
3604 3608
3605 IntRect FrameView::ConvertFromLayoutItem( 3609 IntRect FrameView::ConvertFromLayoutItem(
3606 const LayoutItem& layout_item, 3610 const LayoutItem& layout_item,
3607 const IntRect& layout_object_rect) const { 3611 const IntRect& layout_object_rect) const {
3608 // Convert from page ("absolute") to FrameView coordinates. 3612 // Convert from page ("absolute") to FrameView coordinates.
3609 LayoutRect rect = EnclosingLayoutRect( 3613 LayoutRect rect = EnclosingLayoutRect(
3610 layout_item.LocalToAbsoluteQuad(FloatRect(layout_object_rect)) 3614 layout_item.LocalToAbsoluteQuad(FloatRect(layout_object_rect))
3611 .BoundingBox()); 3615 .BoundingBox());
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
4305 if (!scrollbar_existence_changed) 4309 if (!scrollbar_existence_changed)
4306 return false; 4310 return false;
4307 4311
4308 scrollbar_manager_.SetHasHorizontalScrollbar(new_has_horizontal_scrollbar); 4312 scrollbar_manager_.SetHasHorizontalScrollbar(new_has_horizontal_scrollbar);
4309 scrollbar_manager_.SetHasVerticalScrollbar(new_has_vertical_scrollbar); 4313 scrollbar_manager_.SetHasVerticalScrollbar(new_has_vertical_scrollbar);
4310 4314
4311 if (scrollbars_suppressed_) 4315 if (scrollbars_suppressed_)
4312 return true; 4316 return true;
4313 4317
4314 if (!HasOverlayScrollbars()) 4318 if (!HasOverlayScrollbars())
4315 ContentsResized(); 4319 SetNeedsLayout();
4316 ScrollbarExistenceDidChange(); 4320 ScrollbarExistenceDidChange();
4317 return true; 4321 return true;
4318 } 4322 }
4319 4323
4320 bool FrameView::NeedsScrollbarReconstruction() const { 4324 bool FrameView::NeedsScrollbarReconstruction() const {
4321 Scrollbar* scrollbar = HorizontalScrollbar(); 4325 Scrollbar* scrollbar = HorizontalScrollbar();
4322 if (!scrollbar) 4326 if (!scrollbar)
4323 scrollbar = VerticalScrollbar(); 4327 scrollbar = VerticalScrollbar();
4324 if (!scrollbar) { 4328 if (!scrollbar) {
4325 // We have no scrollbar to reconstruct. 4329 // We have no scrollbar to reconstruct.
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
5383 void FrameView::SetAnimationHost( 5387 void FrameView::SetAnimationHost(
5384 std::unique_ptr<CompositorAnimationHost> host) { 5388 std::unique_ptr<CompositorAnimationHost> host) {
5385 animation_host_ = std::move(host); 5389 animation_host_ = std::move(host);
5386 } 5390 }
5387 5391
5388 LayoutUnit FrameView::CaretWidth() const { 5392 LayoutUnit FrameView::CaretWidth() const {
5389 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1)); 5393 return LayoutUnit(GetChromeClient()->WindowToViewportScalar(1));
5390 } 5394 }
5391 5395
5392 } // namespace blink 5396 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698