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

Unified Diff: Source/core/rendering/RenderView.cpp

Issue 190973007: Reland "Avoid layout/full-repaint on view height change if possible" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: New CL Created 6 years, 9 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: Source/core/rendering/RenderView.cpp
diff --git a/Source/core/rendering/RenderView.cpp b/Source/core/rendering/RenderView.cpp
index 1656814b743940e98071c60f4aafacabb0e2487e..7a296e6607c9630001fb13136cee04caf5e3ac3f 100644
--- a/Source/core/rendering/RenderView.cpp
+++ b/Source/core/rendering/RenderView.cpp
@@ -997,4 +997,77 @@ double RenderView::layoutViewportHeight() const
return viewHeight(IncludeScrollbars) / scale;
}
+void RenderView::viewResized()
+{
+ if (needsLayout())
+ return;
+
+ if (width() != viewWidth() || !trySimplifiedLayoutOnHeightChange())
+ setNeedsLayout();
+}
+
+bool RenderView::trySimplifiedLayoutOnHeightChange()
+{
+ // FIXME: Move logics that are generic to RenderBox or RenderBlock into these classes
+ // so that this function can be also used to optimize layout of them.
+
+ if (document().inQuirksMode() || document().paginated() || shouldUsePrintingLayout())
esprehn 2014/03/10 21:32:30 Why not in quirks?
Xianzhu 2014/03/11 00:55:13 Added comments.
+ return false;
+
+ // Optimize layout in horizontal writing mode only to simplify the logic.
+ if (!style()->isHorizontalWritingMode())
+ return false;
+
+ if (hasPercentHeightDescendants())
+ return false;
+
+ // If the height is decreasing and the view isn't vertically scrollable, fallback to
+ // full layout to calculate the new layout overflow rect.
+ LayoutRect layoutOverflow = layoutOverflowRect();
+ if (layoutOverflow.maxY() <= noOverflowRect().maxY() && viewHeight() < height())
+ return false;
+
+ if (document().ensureStyleResolver().mediaQueryAffectedByViewportChange() || document().hasViewportUnits())
esprehn 2014/03/10 21:32:30 Doesn't this exclude all responsive websites?
Xianzhu 2014/03/11 00:55:13 Optimized viewport media query and viewport sizes
+ return false;
+
+ // Needs layout if there is no body element (e.g. there is frameset).
+ Element* body = document().body();
+ if (!body || !body->hasTagName(HTMLNames::bodyTag))
esprehn 2014/03/10 21:32:30 Why is frameset special?
Xianzhu 2014/03/11 00:55:13 Added comment.
+ return false;
+
+ // Root background image may be stretched related to the viewport size.
+ Element* documentElement = document().documentElement();
+ if (!documentElement || !documentElement->renderer()
+ || documentElement->renderer()->rendererForRootBackground()->style()->hasBackgroundImage())
esprehn 2014/03/10 21:32:30 You can't do this, the style might be dirty and yo
Xianzhu 2014/03/11 00:55:13 Now update style in FrameView::setLayoutSizeIntern
+ return false;
+
+ if (TrackedRendererListHashSet* positionedObjects = this->positionedObjects()) {
+ TrackedRendererListHashSet::iterator end = positionedObjects->end();
+ for (TrackedRendererListHashSet::iterator it = positionedObjects->begin(); it != end; ++it) {
+ if ((*it)->node() && (*it)->node()->hasTagName(HTMLNames::dialogTag))
+ return false;
+
+ RenderStyle* childStyle = (*it)->style();
+ // Fixed position element may change compositing state when viewport height changes.
+ if (childStyle->position() == FixedPosition)
+ return false;
+ if (childStyle->top().isPercent() || childStyle->height().isPercent() || childStyle->minHeight().isPercent() || childStyle->maxHeight().isPercent() || !childStyle->bottom().isAuto())
esprehn 2014/03/10 21:32:30 Same, you never updated style so this is all stale
Xianzhu 2014/03/11 00:55:13 Ditto.
+ return false;
+ }
+ }
+
+ // Do a simplified layout on height change.
+ setHeight(viewHeight());
+
+ // During a normal layout, change of height may cause creating or destroying the overflow.
+ // The following code mimics the normal layout for overflow.
+ m_overflow.clear();
+ addLayoutOverflow(layoutOverflow);
+
+ // FIXME: There may be an more efficient way to adjust the size of the root layer.
+ layer()->updateLayerPositionsAfterLayout(layer(), RenderLayer::defaultFlags);
+
+ return true;
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698