<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[224612] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/224612">224612</a></dd>
<dt>Author</dt> <dd>zalan@apple.com</dd>
<dt>Date</dt> <dd>2017-11-08 17:32:17 -0800 (Wed, 08 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[LayoutState cleanup] LayoutContext should own the stack of LayoutState objects
https://bugs.webkit.org/show_bug.cgi?id=179408
<rdar://problem/35423075>

Reviewed by Antti Koivisto.

No change in functionality.

* page/LayoutContext.cpp:
(WebCore::LayoutContext::layoutDelta const):
(WebCore::LayoutContext::addLayoutDelta):
(WebCore::LayoutContext::layoutDeltaMatches):
(WebCore::LayoutContext::layoutState const):
(WebCore::LayoutContext::pushLayoutState):
(WebCore::LayoutContext::pushLayoutStateForPaginationIfNeeded):
(WebCore::LayoutContext::popLayoutState):
* page/LayoutContext.h:
(WebCore::LayoutContext::isPaintOffsetCacheEnabled const):
(WebCore::LayoutContext::layoutState const): Deleted.
* rendering/LayoutState.cpp:
(WebCore::LayoutState::LayoutState):
(WebCore::LayoutState::computeOffsets):
(WebCore::LayoutState::computeClipRect):
(WebCore::LayoutState::computePaginationInformation):
(WebCore::LayoutState::propagateLineGridInfo):
(WebCore::LayoutState::establishLineGrid):
(WebCore::LayoutState::clearPaginationInformation): Deleted.
* rendering/LayoutState.h:
(WebCore::LayoutState::setIsPaginated):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageLayoutContextcpp">trunk/Source/WebCore/page/LayoutContext.cpp</a></li>
<li><a href="#trunkSourceWebCorepageLayoutContexth">trunk/Source/WebCore/page/LayoutContext.h</a></li>
<li><a href="#trunkSourceWebCorerenderingLayoutStatecpp">trunk/Source/WebCore/rendering/LayoutState.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingLayoutStateh">trunk/Source/WebCore/rendering/LayoutState.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224611 => 224612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-09 01:13:27 UTC (rev 224611)
+++ trunk/Source/WebCore/ChangeLog      2017-11-09 01:32:17 UTC (rev 224612)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2017-11-08  Zalan Bujtas  <zalan@apple.com>
+
+        [LayoutState cleanup] LayoutContext should own the stack of LayoutState objects
+        https://bugs.webkit.org/show_bug.cgi?id=179408
+        <rdar://problem/35423075>
+
+        Reviewed by Antti Koivisto.
+
+        No change in functionality.
+
+        * page/LayoutContext.cpp:
+        (WebCore::LayoutContext::layoutDelta const):
+        (WebCore::LayoutContext::addLayoutDelta):
+        (WebCore::LayoutContext::layoutDeltaMatches):
+        (WebCore::LayoutContext::layoutState const):
+        (WebCore::LayoutContext::pushLayoutState):
+        (WebCore::LayoutContext::pushLayoutStateForPaginationIfNeeded):
+        (WebCore::LayoutContext::popLayoutState):
+        * page/LayoutContext.h:
+        (WebCore::LayoutContext::isPaintOffsetCacheEnabled const):
+        (WebCore::LayoutContext::layoutState const): Deleted.
+        * rendering/LayoutState.cpp:
+        (WebCore::LayoutState::LayoutState):
+        (WebCore::LayoutState::computeOffsets):
+        (WebCore::LayoutState::computeClipRect):
+        (WebCore::LayoutState::computePaginationInformation):
+        (WebCore::LayoutState::propagateLineGridInfo):
+        (WebCore::LayoutState::establishLineGrid):
+        (WebCore::LayoutState::clearPaginationInformation): Deleted.
+        * rendering/LayoutState.h:
+        (WebCore::LayoutState::setIsPaginated):
+
</ins><span class="cx"> 2017-11-08  Brady Eidson  <beidson@apple.com>
</span><span class="cx"> 
</span><span class="cx">         ServiceWorkerRegistration::updateStateFromServer fix! (Don't always create a new ServiceWorker every time).
</span></span></pre></div>
<a id="trunkSourceWebCorepageLayoutContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/LayoutContext.cpp (224611 => 224612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/LayoutContext.cpp      2017-11-09 01:13:27 UTC (rev 224611)
+++ trunk/Source/WebCore/page/LayoutContext.cpp 2017-11-09 01:32:17 UTC (rev 224612)
</span><span class="lines">@@ -530,43 +530,49 @@
</span><span class="cx"> 
</span><span class="cx"> LayoutSize LayoutContext::layoutDelta() const
</span><span class="cx"> {
</span><del>-    if (!m_layoutState)
-        return { };
-    return m_layoutState->layoutDelta();
</del><ins>+    if (auto* layoutState = this->layoutState())
+        return layoutState->layoutDelta();
+    return { };
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> void LayoutContext::addLayoutDelta(const LayoutSize& delta)
</span><span class="cx"> {
</span><del>-    if (!m_layoutState)
-        return;
-    m_layoutState->addLayoutDelta(delta);
</del><ins>+    if (auto* layoutState = this->layoutState())
+        layoutState->addLayoutDelta(delta);
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx"> bool LayoutContext::layoutDeltaMatches(const LayoutSize& delta)
</span><span class="cx"> {
</span><del>-    if (!m_layoutState)
-        return false;
-    return m_layoutState->layoutDeltaMatches(delta);
</del><ins>+    if (auto* layoutState = this->layoutState())
+        return layoutState->layoutDeltaMatches(delta);
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><del>-    
</del><ins>+
+LayoutState* LayoutContext::layoutState() const
+{
+    if (m_layoutStateStack.isEmpty())
+        return nullptr;
+    return m_layoutStateStack.last().get();
+}
+
</ins><span class="cx"> void LayoutContext::pushLayoutState(RenderElement& root)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_paintOffsetCacheDisableCount);
</span><del>-    ASSERT(!m_layoutState);
</del><ins>+    ASSERT(!layoutState());
</ins><span class="cx"> 
</span><del>-    m_layoutState = std::make_unique<LayoutState>(root);
</del><ins>+    m_layoutStateStack.append(std::make_unique<LayoutState>(root));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool LayoutContext::pushLayoutStateForPaginationIfNeeded(RenderBlockFlow& layoutRoot)
</span><span class="cx"> {
</span><del>-    if (m_layoutState)
</del><ins>+    if (layoutState())
</ins><span class="cx">         return false;
</span><del>-    m_layoutState = std::make_unique<LayoutState>(layoutRoot);
-    m_layoutState->setIsPaginated();
</del><ins>+    m_layoutStateStack.append(std::make_unique<LayoutState>(layoutRoot));
+    layoutState()->setIsPaginated();
</ins><span class="cx">     // This is just a flag for known page height (see RenderBlockFlow::checkForPaginationLogicalHeightChange).
</span><del>-    m_layoutState->setPageLogicalHeight(1);
</del><ins>+    layoutState()->setPageLogicalHeight(1);
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx">     
</span><span class="lines">@@ -578,9 +584,10 @@
</span><span class="cx"> bool LayoutContext::pushLayoutState(RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged)
</span><span class="cx"> {
</span><span class="cx">     // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
</span><del>-    if (!m_layoutState || !needsFullRepaint() || m_layoutState->isPaginated() || renderer.enclosingFragmentedFlow()
-        || m_layoutState->lineGrid() || (renderer.style().lineGrid() != RenderStyle::initialLineGrid() && renderer.isRenderBlockFlow())) {
-        m_layoutState = std::make_unique<LayoutState>(WTFMove(m_layoutState), renderer, offset, pageHeight, pageHeightChanged);
</del><ins>+    auto* layoutState = this->layoutState();
+    if (!layoutState || !needsFullRepaint() || layoutState->isPaginated() || renderer.enclosingFragmentedFlow()
+        || layoutState->lineGrid() || (renderer.style().lineGrid() != RenderStyle::initialLineGrid() && renderer.isRenderBlockFlow())) {
+        m_layoutStateStack.append(std::make_unique<LayoutState>(m_layoutStateStack, renderer, offset, pageHeight, pageHeightChanged));
</ins><span class="cx">         return true;
</span><span class="cx">     }
</span><span class="cx">     return false;
</span><span class="lines">@@ -588,7 +595,7 @@
</span><span class="cx">     
</span><span class="cx"> void LayoutContext::popLayoutState()
</span><span class="cx"> {
</span><del>-    m_layoutState = WTFMove(m_layoutState->m_ancestor);
</del><ins>+    m_layoutStateStack.removeLast();
</ins><span class="cx"> }
</span><span class="cx">     
</span><span class="cx"> #ifndef NDEBUG
</span></span></pre></div>
<a id="trunkSourceWebCorepageLayoutContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/LayoutContext.h (224611 => 224612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/LayoutContext.h        2017-11-09 01:13:27 UTC (rev 224611)
+++ trunk/Source/WebCore/page/LayoutContext.h   2017-11-09 01:32:17 UTC (rev 224612)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include "LayoutUnit.h"
</ins><span class="cx"> #include "Timer.h"
</span><span class="cx"> 
</span><span class="cx"> #include <wtf/WeakPtr.h>
</span><span class="lines">@@ -35,8 +36,11 @@
</span><span class="cx"> class Frame;
</span><span class="cx"> class FrameView;
</span><span class="cx"> class LayoutScope;
</span><ins>+class LayoutSize;
</ins><span class="cx"> class LayoutState;
</span><span class="cx"> class RenderBlockFlow;
</span><ins>+class RenderBox;
+class RenderObject;
</ins><span class="cx"> class RenderElement;
</span><span class="cx"> class RenderView;
</span><span class="cx">     
</span><span class="lines">@@ -92,9 +96,9 @@
</span><span class="cx">     void pushLayoutState(RenderElement&);
</span><span class="cx">     bool pushLayoutStateForPaginationIfNeeded(RenderBlockFlow&);
</span><span class="cx">     void popLayoutState(RenderObject&);
</span><del>-    LayoutState* layoutState() const { return m_layoutState.get(); }
</del><ins>+    LayoutState* layoutState() const;
</ins><span class="cx">     // Returns true if layoutState should be used for its cached offset and clip.
</span><del>-    bool isPaintOffsetCacheEnabled() const { return !m_paintOffsetCacheDisableCount && m_layoutState; }
</del><ins>+    bool isPaintOffsetCacheEnabled() const { return !m_paintOffsetCacheDisableCount && layoutState(); }
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     void checkLayoutState();
</span><span class="cx"> #endif
</span><span class="lines">@@ -106,6 +110,7 @@
</span><span class="cx"> #if !ASSERT_DISABLED
</span><span class="cx">     bool layoutDeltaMatches(const LayoutSize& delta);
</span><span class="cx"> #endif
</span><ins>+    using LayoutStateStack = Vector<std::unique_ptr<LayoutState>>;
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     friend class LayoutScope;
</span><span class="lines">@@ -166,7 +171,7 @@
</span><span class="cx">     unsigned m_disableSetNeedsLayoutCount { 0 };
</span><span class="cx">     int m_layoutDisallowedCount { 0 };
</span><span class="cx">     WeakPtr<RenderElement> m_subtreeLayoutRoot;
</span><del>-    std::unique_ptr<LayoutState> m_layoutState;
</del><ins>+    LayoutStateStack m_layoutStateStack;
</ins><span class="cx">     unsigned m_paintOffsetCacheDisableCount { 0 };
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingLayoutStatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/LayoutState.cpp (224611 => 224612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/LayoutState.cpp   2017-11-09 01:13:27 UTC (rev 224611)
+++ trunk/Source/WebCore/rendering/LayoutState.cpp      2017-11-09 01:32:17 UTC (rev 224612)
</span><span class="lines">@@ -26,7 +26,6 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "LayoutState.h"
</span><span class="cx"> 
</span><del>-#include "LayoutContext.h"
</del><span class="cx"> #include "RenderFragmentedFlow.h"
</span><span class="cx"> #include "RenderInline.h"
</span><span class="cx"> #include "RenderLayer.h"
</span><span class="lines">@@ -60,9 +59,8 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutState::LayoutState(std::unique_ptr<LayoutState> ancestor, RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged)
-    : m_ancestor(WTFMove(ancestor))
-    , m_clipped(false)
</del><ins>+LayoutState::LayoutState(const LayoutContext::LayoutStateStack& layoutStateStack, RenderBox& renderer, const LayoutSize& offset, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged)
+    : m_clipped(false)
</ins><span class="cx">     , m_isPaginated(false)
</span><span class="cx">     , m_pageLogicalHeightChanged(false)
</span><span class="cx"> #if !ASSERT_DISABLED
</span><span class="lines">@@ -73,23 +71,22 @@
</span><span class="cx">     , m_renderer(&renderer)
</span><span class="cx"> #endif
</span><span class="cx"> {
</span><del>-    if (m_ancestor) {
-        computeOffsets(renderer, offset);
-        computeClipRect(renderer);
</del><ins>+    if (!layoutStateStack.isEmpty()) {
+        auto& ancestor = *layoutStateStack.last().get();
+        computeOffsets(ancestor, renderer, offset);
+        computeClipRect(ancestor, renderer);
</ins><span class="cx">     }
</span><del>-    computePaginationInformation(renderer, pageLogicalHeight, pageLogicalHeightChanged);
</del><ins>+    computePaginationInformation(layoutStateStack, renderer, pageLogicalHeight, pageLogicalHeightChanged);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::computeOffsets(RenderBox& renderer, LayoutSize offset)
</del><ins>+void LayoutState::computeOffsets(const LayoutState& ancestor, RenderBox& renderer, LayoutSize offset)
</ins><span class="cx"> {
</span><del>-    ASSERT(m_ancestor);
-
</del><span class="cx">     bool fixed = renderer.isFixedPositioned();
</span><span class="cx">     if (fixed) {
</span><span class="cx">         FloatPoint fixedOffset = renderer.view().localToAbsolute(FloatPoint(), IsFixed);
</span><span class="cx">         m_paintOffset = LayoutSize(fixedOffset.x(), fixedOffset.y()) + offset;
</span><span class="cx">     } else
</span><del>-        m_paintOffset = m_ancestor->m_paintOffset + offset;
</del><ins>+        m_paintOffset = ancestor.paintOffset() + offset;
</ins><span class="cx"> 
</span><span class="cx">     if (renderer.isOutOfFlowPositioned() && !fixed) {
</span><span class="cx">         if (auto* container = renderer.container()) {
</span><span class="lines">@@ -106,20 +103,18 @@
</span><span class="cx">     if (renderer.hasOverflowClip())
</span><span class="cx">         m_paintOffset -= toLayoutSize(renderer.scrollPosition());
</span><span class="cx"> 
</span><del>-    m_layoutDelta = m_ancestor->m_layoutDelta;
</del><ins>+    m_layoutDelta = ancestor.layoutDelta();
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><del>-    m_layoutDeltaXSaturated = m_ancestor->m_layoutDeltaXSaturated;
-    m_layoutDeltaYSaturated = m_ancestor->m_layoutDeltaYSaturated;
</del><ins>+    m_layoutDeltaXSaturated = ancestor.m_layoutDeltaXSaturated;
+    m_layoutDeltaYSaturated = ancestor.m_layoutDeltaYSaturated;
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::computeClipRect(RenderBox& renderer)
</del><ins>+void LayoutState::computeClipRect(const LayoutState& ancestor, RenderBox& renderer)
</ins><span class="cx"> {
</span><del>-    ASSERT(m_ancestor);
-
-    m_clipped = !renderer.isFixedPositioned() && m_ancestor->m_clipped;
</del><ins>+    m_clipped = !renderer.isFixedPositioned() && ancestor.isClipped();
</ins><span class="cx">     if (m_clipped)
</span><del>-        m_clipRect = m_ancestor->m_clipRect;
</del><ins>+        m_clipRect = ancestor.clipRect();
</ins><span class="cx">     if (!renderer.hasOverflowClip())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -132,10 +127,11 @@
</span><span class="cx">     // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::computePaginationInformation(RenderBox& renderer, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged)
</del><ins>+void LayoutState::computePaginationInformation(const LayoutContext::LayoutStateStack& layoutStateStack, RenderBox& renderer, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged)
</ins><span class="cx"> {
</span><ins>+    auto* ancestor = layoutStateStack.isEmpty() ? nullptr : layoutStateStack.last().get();
</ins><span class="cx">     // If we establish a new page height, then cache the offset to the top of the first page.
</span><del>-    // We can compare this later on to figure out what part of the page we're actually on,
</del><ins>+    // We can compare this later on to figure out what part of the page we're actually on.
</ins><span class="cx">     if (pageLogicalHeight || renderer.isRenderFragmentedFlow()) {
</span><span class="cx">         m_pageLogicalHeight = pageLogicalHeight;
</span><span class="cx">         bool isFlipped = renderer.style().isFlippedBlocksWritingMode();
</span><span class="lines">@@ -142,11 +138,11 @@
</span><span class="cx">         m_pageOffset = LayoutSize(m_layoutOffset.width() + (!isFlipped ? renderer.borderLeft() + renderer.paddingLeft() : renderer.borderRight() + renderer.paddingRight()), m_layoutOffset.height() + (!isFlipped ? renderer.borderTop() + renderer.paddingTop() : renderer.borderBottom() + renderer.paddingBottom()));
</span><span class="cx">         m_pageLogicalHeightChanged = pageLogicalHeightChanged;
</span><span class="cx">         m_isPaginated = true;
</span><del>-    } else if (m_ancestor) {
</del><ins>+    } else if (ancestor) {
</ins><span class="cx">         // If we don't establish a new page height, then propagate the old page height and offset down.
</span><del>-        m_pageLogicalHeight = m_ancestor->m_pageLogicalHeight;
-        m_pageLogicalHeightChanged = m_ancestor->m_pageLogicalHeightChanged;
-        m_pageOffset = m_ancestor->m_pageOffset;
</del><ins>+        m_pageLogicalHeight = ancestor->pageLogicalHeight();
+        m_pageLogicalHeightChanged = ancestor->pageLogicalHeightChanged();
+        m_pageOffset = ancestor->pageOffset();
</ins><span class="cx"> 
</span><span class="cx">         // Disable pagination for objects we don't support. For now this includes overflow:scroll/auto, inline blocks and writing mode roots.
</span><span class="cx">         if (renderer.isUnsplittableForPagination()) {
</span><span class="lines">@@ -157,7 +153,8 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Propagate line grid information.
</span><del>-    propagateLineGridInfo(renderer);
</del><ins>+    if (ancestor)
+        propagateLineGridInfo(*ancestor, renderer);
</ins><span class="cx"> 
</span><span class="cx">     if (lineGrid() && (lineGrid()->style().writingMode() == renderer.style().writingMode()) && is<RenderMultiColumnFlow>(renderer))
</span><span class="cx">         downcast<RenderMultiColumnFlow>(renderer).computeLineGridPaginationOrigin(*this);
</span><span class="lines">@@ -164,15 +161,9 @@
</span><span class="cx"> 
</span><span class="cx">     // If we have a new grid to track, then add it to our set.
</span><span class="cx">     if (renderer.style().lineGrid() != RenderStyle::initialLineGrid() && is<RenderBlockFlow>(renderer))
</span><del>-        establishLineGrid(downcast<RenderBlockFlow>(renderer));
</del><ins>+        establishLineGrid(layoutStateStack, downcast<RenderBlockFlow>(renderer));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::clearPaginationInformation()
-{
-    m_pageLogicalHeight = m_ancestor->m_pageLogicalHeight;
-    m_pageOffset = m_ancestor->m_pageOffset;
-}
-
</del><span class="cx"> LayoutUnit LayoutState::pageLogicalOffset(RenderBox* child, LayoutUnit childLogicalOffset) const
</span><span class="cx"> {
</span><span class="cx">     if (child->isHorizontalWritingMode())
</span><span class="lines">@@ -180,34 +171,36 @@
</span><span class="cx">     return m_layoutOffset.width() + childLogicalOffset - m_pageOffset.width();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::propagateLineGridInfo(RenderBox& renderer)
</del><ins>+void LayoutState::propagateLineGridInfo(const LayoutState& ancestor, RenderBox& renderer)
</ins><span class="cx"> {
</span><span class="cx">     // Disable line grids for objects we don't support. For now this includes overflow:scroll/auto, inline blocks and
</span><span class="cx">     // writing mode roots.
</span><del>-    if (!m_ancestor || renderer.isUnsplittableForPagination())
</del><ins>+    if (renderer.isUnsplittableForPagination())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_lineGrid = m_ancestor->m_lineGrid;
-    m_lineGridOffset = m_ancestor->m_lineGridOffset;
-    m_lineGridPaginationOrigin = m_ancestor->m_lineGridPaginationOrigin;
</del><ins>+    m_lineGrid = ancestor.lineGrid();
+    m_lineGridOffset = ancestor.lineGridOffset();
+    m_lineGridPaginationOrigin = ancestor.lineGridPaginationOrigin();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LayoutState::establishLineGrid(RenderBlockFlow& renderer)
</del><ins>+void LayoutState::establishLineGrid(const LayoutContext::LayoutStateStack& layoutStateStack, RenderBlockFlow& renderer)
</ins><span class="cx"> {
</span><ins>+    // FIXME: webkit.org/b/179440 This logic should be part of the LayoutContext.
</ins><span class="cx">     // First check to see if this grid has been established already.
</span><span class="cx">     if (m_lineGrid) {
</span><span class="cx">         if (m_lineGrid->style().lineGrid() == renderer.style().lineGrid())
</span><span class="cx">             return;
</span><span class="cx">         RenderBlockFlow* currentGrid = m_lineGrid;
</span><del>-        for (LayoutState* currentState = m_ancestor.get(); currentState; currentState = currentState->m_ancestor.get()) {
-            if (currentState->m_lineGrid == currentGrid)
</del><ins>+        for (int i = layoutStateStack.size() - 1; i <= 0; --i) {
+            auto& currentState = *layoutStateStack[i].get();
+            if (currentState.m_lineGrid == currentGrid)
</ins><span class="cx">                 continue;
</span><del>-            currentGrid = currentState->m_lineGrid;
</del><ins>+            currentGrid = currentState.m_lineGrid;
</ins><span class="cx">             if (!currentGrid)
</span><span class="cx">                 break;
</span><span class="cx">             if (currentGrid->style().lineGrid() == renderer.style().lineGrid()) {
</span><span class="cx">                 m_lineGrid = currentGrid;
</span><del>-                m_lineGridOffset = currentState->m_lineGridOffset;
</del><ins>+                m_lineGridOffset = currentState.m_lineGridOffset;
</ins><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingLayoutStateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/LayoutState.h (224611 => 224612)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/LayoutState.h     2017-11-09 01:13:27 UTC (rev 224611)
+++ trunk/Source/WebCore/rendering/LayoutState.h        2017-11-09 01:32:17 UTC (rev 224612)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include "LayoutContext.h"
</ins><span class="cx"> #include "LayoutRect.h"
</span><span class="cx"> #include <wtf/Noncopyable.h>
</span><span class="cx"> 
</span><span class="lines">@@ -51,13 +52,11 @@
</span><span class="cx"> #endif
</span><span class="cx">     {
</span><span class="cx">     }
</span><del>-
-    LayoutState(std::unique_ptr<LayoutState> ancestor, RenderBox&, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged);
</del><ins>+    LayoutState(const LayoutContext::LayoutStateStack&, RenderBox&, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged);
</ins><span class="cx">     explicit LayoutState(RenderElement&);
</span><span class="cx"> 
</span><span class="cx">     bool isPaginated() const { return m_isPaginated; }
</span><span class="cx">     void setIsPaginated() { m_isPaginated = true; }
</span><del>-    void clearPaginationInformation();
</del><span class="cx"> 
</span><span class="cx">     // The page logical offset is the object's offset from the top of the page in the page progression
</span><span class="cx">     // direction (so an x-offset in vertical text and a y-offset for horizontal text).
</span><span class="lines">@@ -93,15 +92,12 @@
</span><span class="cx">     bool layoutDeltaMatches(LayoutSize);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    // FIXME: webkit.org/b/179408 LayoutContext should own the stack of LayoutState objects
-    std::unique_ptr<LayoutState> m_ancestor;
-
</del><span class="cx"> private:
</span><del>-    void computeOffsets(RenderBox&, LayoutSize offset);
-    void computeClipRect(RenderBox&);
-    void computePaginationInformation(RenderBox&, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged);
-    void propagateLineGridInfo(RenderBox&);
-    void establishLineGrid(RenderBlockFlow&);
</del><ins>+    void computeOffsets(const LayoutState& ancestor, RenderBox&, LayoutSize offset);
+    void computeClipRect(const LayoutState& ancestor, RenderBox&);
+    void computePaginationInformation(const LayoutContext::LayoutStateStack&, RenderBox&, LayoutUnit pageLogicalHeight, bool pageLogicalHeightChanged);
+    void propagateLineGridInfo(const LayoutState& ancestor, RenderBox&);
+    void establishLineGrid(const LayoutContext::LayoutStateStack&, RenderBlockFlow&);
</ins><span class="cx"> 
</span><span class="cx">     // Do not add anything apart from bitfields. See https://bugs.webkit.org/show_bug.cgi?id=100173
</span><span class="cx">     bool m_clipped : 1;
</span><span class="lines">@@ -112,7 +108,6 @@
</span><span class="cx">     bool m_layoutDeltaXSaturated : 1;
</span><span class="cx">     bool m_layoutDeltaYSaturated : 1;
</span><span class="cx"> #endif
</span><del>-
</del><span class="cx">     // The current line grid that we're snapping to and the offset of the start of the grid.
</span><span class="cx">     RenderBlockFlow* m_lineGrid { nullptr };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>