https://bugs.webkit.org/show_bug.cgi?id=68543
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 17:58:22 +0000 (17:58 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Sep 2011 17:58:22 +0000 (17:58 +0000)
Make sure that when regions change dimensions we recompute pagination slices.

Reviewed by Simon Fraser.

Source/WebCore:

Added new tests in fast/regions.

* rendering/LayoutState.cpp:
(WebCore::LayoutState::LayoutState):
* rendering/LayoutState.h:
* rendering/RenderFlowThread.cpp:
(WebCore::RenderFlowThread::layout):
(WebCore::RenderFlowThread::renderRegionForLine):
(WebCore::RenderFlowThread::regionLogicalWidthForLine):
* rendering/RenderRegion.cpp:
(WebCore::RenderRegion::layout):
* rendering/RenderView.cpp:
(WebCore::RenderView::pushLayoutState):
* rendering/RenderView.h:
(WebCore::LayoutStateMaintainer::LayoutStateMaintainer):
(WebCore::LayoutStateMaintainer::push):

LayoutTests:

* fast/regions/text-region-split-after-resize-expected.txt: Added.
* fast/regions/text-region-split-after-resize.html: Added.
* fast/regions/webkit-flow-floats-inside-regions-bounds-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95648 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/regions/text-region-split-after-resize-expected.txt [new file with mode: 0644]
LayoutTests/fast/regions/text-region-split-after-resize.html [new file with mode: 0644]
LayoutTests/fast/regions/webkit-flow-floats-inside-regions-bounds-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/rendering/LayoutState.cpp
Source/WebCore/rendering/LayoutState.h
Source/WebCore/rendering/RenderFlowThread.cpp
Source/WebCore/rendering/RenderRegion.cpp
Source/WebCore/rendering/RenderView.cpp
Source/WebCore/rendering/RenderView.h

index 196f9c5..c4b8043 100644 (file)
@@ -1,3 +1,15 @@
+2011-09-21  David Hyatt  <hyatt@apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=68543
+        
+        Make sure that when regions change dimensions we recompute pagination slices.
+
+        Reviewed by Simon Fraser.
+
+        * fast/regions/text-region-split-after-resize-expected.txt: Added.
+        * fast/regions/text-region-split-after-resize.html: Added.
+        * fast/regions/webkit-flow-floats-inside-regions-bounds-expected.txt:
+
 2011-09-20  Ryosuke Niwa  <rniwa@webkit.org>
 
         Span element gets produced using backspace/delete to merge header with paragraph
diff --git a/LayoutTests/fast/regions/text-region-split-after-resize-expected.txt b/LayoutTests/fast/regions/text-region-split-after-resize-expected.txt
new file mode 100644 (file)
index 0000000..7ef22e9
--- /dev/null
@@ -0,0 +1 @@
+PASS
diff --git a/LayoutTests/fast/regions/text-region-split-after-resize.html b/LayoutTests/fast/regions/text-region-split-after-resize.html
new file mode 100644 (file)
index 0000000..ded1852
--- /dev/null
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<head>
+<style>
+    #content { -webkit-flow: 'flow'; }
+    .region { content: -webkit-from-flow("flow"); border:2px solid black; margin:1em 0}
+    .finished #content, .finished .region { display: none; }
+
+    #region1 { width: 200px; height: 30px; }
+    #region2 { width: 200px; height: 50px; }
+    #region3 { width: 200px; height: 50px; }
+    #region4 { width: 200px; height: 50px; }
+    #region5 { width: 200px; height: 100px; }
+    #region6 { width: 200px; height: 60px; }
+</style>
+</head>
+<div id="content">
+    <p style="-webkit-region-break-after: always"><b class="check region1">Text in region 1.</b> This paragraph has "<i>-webkit-region-break-after: always</i>". <b class="check region2">There should be nothing in this region after this line.</b></p>
+    
+    <p><b class="check region3">First element in the region 3.</b> Some text inside a flow. Some text inside a flow. Some text inside a flow. <br><b class="check region4">Text in region 4.</b> </p>
+    
+    <p>
+        <!-- Using the paragraph element to test nested blocks region-breaks. -->
+        <div><span class="check region4">Simple line in region 4.</span></div>
+        <div style="margin-top:50px;"><b class="check region5">First line in region 5.</b> This paragraph displays in region 5 because it has a margin-top, which is too high to fit in the previous region.</div>
+        <div style="-webkit-region-break-before: always"><b class="check region6">First line in region 6.</b> This paragraph uses "<i>-webkit-region-break-before: always</i>".</div>
+    </p>
+</div>
+
+<div id="region1" class="region"></div>
+<div id="region2" class="region"></div>
+<div id="region3" class="region"></div>
+<div id="region4" class="region"></div>
+<div id="region5" class="region"></div>
+<div id="region6" class="region"></div>
+
+<script src="resources/helper.js"></script>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    document.body.offsetLeft;
+    document.getElementById('region1').style.height = "60px";
+    document.getElementById('region2').style.height = "100px";
+    document.getElementById('region3').style.height = "100px";
+    document.getElementById('region4').style.height = "100px";
+    document.getElementById('region5').style.height = "200px";
+    document.getElementById('region6').style.height = "120px";
+    document.body.offsetLeft;
+    if (testContentToRegionsMapping())
+        document.body.className = "finished";
+</script>
\ No newline at end of file
index 4bf5166..51ca2cc 100644 (file)
@@ -11,9 +11,9 @@ Flow Threads
   Thread with flow-name 'flow1'
     layer at (0,0) size 300x400
       RenderFlowThread at (0,0) size 300x400
-        RenderBlock {DIV} at (0,0) size 300x631
-          RenderBlock {DIV} at (5,5) size 290x621 [border: (1px solid #0000FF)]
-            RenderBlock {DIV} at (11,11) size 268x599 [border: (1px solid #008000)]
+        RenderBlock {DIV} at (0,0) size 300x505
+          RenderBlock {DIV} at (5,5) size 290x495 [border: (1px solid #0000FF)]
+            RenderBlock {DIV} at (11,11) size 268x473 [border: (1px solid #008000)]
               RenderBlock {P} at (1,17) size 266x36
                 RenderText {#text} at (0,0) size 166x36
                   text run at (0,0) width 166: "This line of text should"
@@ -41,19 +41,12 @@ Flow Threads
                   text run at (0,110) width 86: "should not"
                   text run at (0,128) width 86: "get out of the"
                   text run at (0,146) width 44: "region."
-              RenderBlock {P} at (1,384) size 266x198
-                RenderText {#text} at (0,0) size 44x198
-                  text run at (0,0) width 28: "This"
-                  text run at (0,18) width 23: "line"
-                  text run at (0,36) width 13: "of"
-                  text run at (0,54) width 23: "text"
-                  text run at (0,72) width 42: "should"
-                  text run at (0,90) width 20: "not"
-                  text run at (0,108) width 19: "get"
-                  text run at (0,126) width 20: "out"
-                  text run at (0,144) width 13: "of"
-                  text run at (0,162) width 19: "the"
-                  text run at (0,180) width 44: "region."
+              RenderBlock {P} at (1,384) size 266x72
+                RenderText {#text} at (0,0) size 86x72
+                  text run at (0,0) width 86: "This line of"
+                  text run at (0,18) width 86: "text should"
+                  text run at (0,36) width 86: "not get out of"
+                  text run at (0,54) width 67: "the region."
   Regions for flow 'flow1'
     RenderRegion {DIV} #region1 with index 0
     RenderRegion {DIV} #region2 with index 0
index c9183c7..ce3b4d0 100644 (file)
@@ -1,3 +1,28 @@
+2011-09-21  David Hyatt  <hyatt@apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=68543
+        
+        Make sure that when regions change dimensions we recompute pagination slices.
+
+        Reviewed by Simon Fraser.
+
+        Added new tests in fast/regions.
+
+        * rendering/LayoutState.cpp:
+        (WebCore::LayoutState::LayoutState):
+        * rendering/LayoutState.h:
+        * rendering/RenderFlowThread.cpp:
+        (WebCore::RenderFlowThread::layout):
+        (WebCore::RenderFlowThread::renderRegionForLine):
+        (WebCore::RenderFlowThread::regionLogicalWidthForLine):
+        * rendering/RenderRegion.cpp:
+        (WebCore::RenderRegion::layout):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::pushLayoutState):
+        * rendering/RenderView.h:
+        (WebCore::LayoutStateMaintainer::LayoutStateMaintainer):
+        (WebCore::LayoutStateMaintainer::push):
+
 2011-09-21  Xianzhu Wang  <wangxianzhu@chromium.org>
 
         Ensure TestWebKitAPI works on mac, win, chromium-mac and chromium-linux
index 07fdfda..1ac9a8d 100644 (file)
@@ -109,11 +109,11 @@ LayoutState::LayoutState(LayoutState* prev, RenderBox* renderer, const LayoutSiz
     // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present.
 }
 
-LayoutState::LayoutState(LayoutState* prev, RenderFlowThread* flowThread)
+LayoutState::LayoutState(LayoutState* prev, RenderFlowThread* flowThread, bool regionsChanged)
     : m_clipped(false)
     , m_isPaginated(true)
     , m_pageLogicalHeight(1) // Use a fake height here. That value is not important, just needs to be non-zero.
-    , m_pageLogicalHeightChanged(false)
+    , m_pageLogicalHeightChanged(regionsChanged)
     , m_columnInfo(0)
     , m_next(prev)
 #ifndef NDEBUG
index 14dfabc..efd785f 100644 (file)
@@ -54,7 +54,7 @@ public:
     }
 
     LayoutState(LayoutState*, RenderBox*, const LayoutSize& offset, LayoutUnit pageHeight, bool pageHeightChanged, ColumnInfo*);
-    LayoutState(LayoutState*, RenderFlowThread*);
+    LayoutState(LayoutState*, RenderFlowThread*, bool regionsChanged);
     LayoutState(RenderObject*);
 
     void destroy(RenderArena*);
index 42cad18..47fbd90 100644 (file)
@@ -300,6 +300,7 @@ private:
 
 void RenderFlowThread::layout()
 {
+    bool regionsChanged = m_regionsInvalidated && m_everHadLayout;
     if (m_regionsInvalidated) {
         m_regionsInvalidated = false;
         if (hasRegions()) {
@@ -329,7 +330,7 @@ void RenderFlowThread::layout()
     }
 
     CurrentRenderFlowThreadMaintainer currentFlowThreadSetter(this);
-    LayoutStateMaintainer statePusher(view(), this);
+    LayoutStateMaintainer statePusher(view(), this, regionsChanged);
     RenderBlock::layout();
     statePusher.pop();
 }
@@ -489,15 +490,10 @@ RenderRegion* RenderFlowThread::renderRegionForLine(LayoutUnit position, bool ex
 
         LayoutRect regionRect = region->regionRect();
 
-        if (useHorizontalWritingMode) {
-            if (regionRect.y() <= position && position < regionRect.maxY())
-                return region;
-            continue;
-        }
-
-        if (regionRect.x() <= position && position < regionRect.maxX())
+        if ((useHorizontalWritingMode && regionRect.y() <= position && position < regionRect.maxY())
+            || (!useHorizontalWritingMode && regionRect.x() <= position && position < regionRect.maxX()))
             return region;
-        
+
         if (extendLastRegion)
             lastValidRegion = region;
     }
@@ -510,7 +506,7 @@ LayoutUnit RenderFlowThread::regionLogicalWidthForLine(LayoutUnit position) cons
     const bool extendLastRegion = true;
     RenderRegion* region = renderRegionForLine(position, extendLastRegion);
     if (!region)
-        return 0;
+        return contentLogicalWidth();
 
     return isHorizontalWritingMode() ? region->regionRect().width() : region->regionRect().height();
 }
index 563191f..d844fcf 100644 (file)
@@ -85,8 +85,10 @@ bool RenderRegion::nodeAtPoint(const HitTestRequest& request, HitTestResult& res
 void RenderRegion::layout()
 {
     RenderReplaced::layout();
-    if (m_flowThread && isValid())
-        m_flowThread->invalidateRegions();
+    if (m_flowThread && isValid()) {
+        if (regionRect().width() != contentWidth() || regionRect().height() != contentHeight())
+            m_flowThread->invalidateRegions();
+    }
 }
 
 void RenderRegion::attachRegion()
index 4fefaa1..1fefac4 100644 (file)
@@ -713,9 +713,9 @@ void RenderView::pushLayoutState(RenderObject* root)
     m_layoutState = new (renderArena()) LayoutState(root);
 }
 
-void RenderView::pushLayoutState(RenderFlowThread* flowThread)
+void RenderView::pushLayoutState(RenderFlowThread* flowThread, bool regionsChanged)
 {
-    m_layoutState = new (renderArena()) LayoutState(m_layoutState, flowThread);
+    m_layoutState = new (renderArena()) LayoutState(m_layoutState, flowThread, regionsChanged);
 }
 
 bool RenderView::shouldDisableLayoutStateForSubtree(RenderObject* renderer) const
index 8d431e6..e6d7d8f 100644 (file)
@@ -195,7 +195,7 @@ private:
     bool shouldRepaint(const IntRect& r) const;
 
     // These functions may only be accessed by LayoutStateMaintainer.
-    void pushLayoutState(RenderFlowThread*);
+    void pushLayoutState(RenderFlowThread*, bool regionsChanged);
     bool pushLayoutState(RenderBox* renderer, const LayoutSize& offset, LayoutUnit pageHeight = 0, bool pageHeightChanged = false, ColumnInfo* colInfo = 0)
     {
         // We push LayoutState even if layoutState is disabled because it stores layoutDelta too.
@@ -312,14 +312,14 @@ public:
     {
     }
     
-    LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread)
+    LayoutStateMaintainer(RenderView* view, RenderFlowThread* flowThread, bool regionsChanged)
         : m_view(view)
         , m_disabled(false)
         , m_didStart(false)
         , m_didEnd(false)
         , m_didCreateLayoutState(false)
     {
-        push(flowThread);
+        push(flowThread, regionsChanged);
     }
     
     ~LayoutStateMaintainer()
@@ -337,10 +337,10 @@ public:
         m_didStart = true;
     }
     
-    void push(RenderFlowThread* flowThread)
+    void push(RenderFlowThread* flowThread, bool regionsChanged)
     {
         ASSERT(!m_didStart);
-        m_view->pushLayoutState(flowThread);
+        m_view->pushLayoutState(flowThread, regionsChanged);
         m_didCreateLayoutState = true;
         m_didStart = true;
     }