[Libreoffice-commits] core.git: Branch 'distro/escriba/escriba-5.2' - 16 commits - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Aug 24 07:57:03 UTC 2017


 sw/qa/extras/odfimport/data/i61225.sxw                   |binary
 sw/qa/extras/odfimport/odfimport.cxx                     |    8 +
 sw/qa/extras/uiwriter/data/i95698.odt                    |binary
 sw/qa/extras/uiwriter/data/lines-in-section-in-table.odt |binary
 sw/qa/extras/uiwriter/data/rhbz739252-3.odt              |binary
 sw/qa/extras/uiwriter/data/table-in-sect.odt             |binary
 sw/qa/extras/uiwriter/data/tdf108524.odt                 |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                       |  103 +++++++++++++++
 sw/source/core/inc/cellfrm.hxx                           |    1 
 sw/source/core/layout/findfrm.cxx                        |   20 +-
 sw/source/core/layout/flowfrm.cxx                        |    5 
 sw/source/core/layout/sectfrm.cxx                        |   66 ++++++++-
 sw/source/core/layout/tabfrm.cxx                         |   39 +++++
 13 files changed, 225 insertions(+), 17 deletions(-)

New commits:
commit 0d644aeba1580865173840f6b41e6f2f0ac5ccf0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Aug 16 17:19:05 2017 +0200

    i#95698 sw: fix crash on splitting in-table section containing a nested table
    
    Found by crashtesting, ooo95698-1.odt crashed sw layout on load. The
    intended use-case is splitting section frames inside a table frame, so
    can just blacklist the non-interesting table-in-section-in-table case
    that causes the problem here.
    
    Reviewed-on: https://gerrit.libreoffice.org/41224
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 802477ae75b39194442d9c01a1342d068c7b9300)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: Ic47cd8c46cc71f7eaa36b03ec2c4a5df8ca8051c

diff --git a/sw/qa/extras/uiwriter/data/i95698.odt b/sw/qa/extras/uiwriter/data/i95698.odt
new file mode 100644
index 000000000000..9fe3ec207648
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/i95698.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index fd9031de8516..7d5bb5982431 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -205,6 +205,7 @@ public:
     void testTdf108524();
     void testTableInSection();
     void testTableInNestedSection();
+    void testTableInSectionInTable();
     void testLinesInSectionInTable();
     void testLinesMoveBackwardsInSectionInTable();
 
@@ -316,6 +317,7 @@ public:
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST(testTableInNestedSection);
     CPPUNIT_TEST(testLinesInSectionInTable);
+    CPPUNIT_TEST(testTableInSectionInTable);
     CPPUNIT_TEST(testLinesMoveBackwardsInSectionInTable);
     CPPUNIT_TEST_SUITE_END();
 
@@ -3846,6 +3848,14 @@ void SwUiWriterTest::testTableInNestedSection()
     assertXPath(pXmlDoc, "//page[2]//section/tab", 1);
 }
 
+void SwUiWriterTest::testTableInSectionInTable()
+{
+    // The document has a table, containing a section, containing a nested
+    // table.
+    // This crashed the layout.
+    createDoc("i95698.odt");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 45282d886929..0c6db983d50d 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -916,9 +916,21 @@ static bool lcl_FindSectionsInRow( const SwRowFrame& rRow )
                         if (const SwFrame* pSectionLower = pTmpFrame->GetLower())
                         {
                             if (!pSectionLower->IsColumnFrame())
+                            {
                                 // Section has a single column only, try to
                                 // split that.
                                 bRet = false;
+
+                                for (const SwFrame* pFrame = pSectionLower; pFrame; pFrame = pFrame->GetNext())
+                                {
+                                    if (pFrame->IsTabFrame())
+                                    {
+                                        // Section contains a table, no split in that case.
+                                        bRet = true;
+                                        break;
+                                    }
+                                }
+                            }
                         }
                     }
                 }
commit d67b100f44f7c320af713355dc6022451347447d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jul 14 16:05:10 2017 +0200

    CppunitTest_sw_uiwriter: disable testLinesMoveBackwards... on macOS
    
    No idea off the top of my head what is the problem here, seeing Linux
    and Windows is happy; clang on Linux as well.
    
    Change-Id: I56c79b37a5648d9afd02d8e161ea4a279cc89744
    (cherry picked from commit 39dd0121f5994dee56f95bc57fae3323bf849a20)

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index ef555d8b3ac4..fd9031de8516 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -3795,6 +3795,7 @@ void SwUiWriterTest::testLinesInSectionInTable()
 
 void SwUiWriterTest::testLinesMoveBackwardsInSectionInTable()
 {
+#ifndef MACOSX
     // Assert that paragraph "4" is on page 1 and "5" is on page 2.
     SwDoc* pDoc = createDoc("lines-in-section-in-table.odt");
     xmlDocPtr pXmlDoc = parseLayoutDump();
@@ -3818,6 +3819,7 @@ void SwUiWriterTest::testLinesMoveBackwardsInSectionInTable()
     sal_uInt32 nPage1LastNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32();
     // This was "3", paragraph "4" was deleted, but "5" was not moved backwards from page 2.
     CPPUNIT_ASSERT_EQUAL(OUString("5"), pDoc->GetNodes()[nPage1LastNode]->GetTextNode()->GetText());
+#endif
 }
 
 void SwUiWriterTest::testTableInSection()
commit af65d584b2c62752bfb37e39048ee76dffad525b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jul 14 14:20:36 2017 +0200

    tdf#108524 sw: handle sections inside tables in SwFrame::GetPrevSctLeaf()
    
    This addresses the sub-problem described in comment 12 of the bug, i.e.
    text frames are now moved to the first page from the second one when
    text frames are deleted on the first page.
    
    Change-Id: Ic0ede45381fb84b13d1ac02e4d1f39d817650616
    Reviewed-on: https://gerrit.libreoffice.org/39946
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 850bf99e7d1abcf2e0cce731b6715f87420d0ee6)

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 0f88de7187e3..ef555d8b3ac4 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -206,6 +206,7 @@ public:
     void testTableInSection();
     void testTableInNestedSection();
     void testLinesInSectionInTable();
+    void testLinesMoveBackwardsInSectionInTable();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -315,6 +316,7 @@ public:
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST(testTableInNestedSection);
     CPPUNIT_TEST(testLinesInSectionInTable);
+    CPPUNIT_TEST(testLinesMoveBackwardsInSectionInTable);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3791,6 +3793,33 @@ void SwUiWriterTest::testLinesInSectionInTable()
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
 }
 
+void SwUiWriterTest::testLinesMoveBackwardsInSectionInTable()
+{
+    // Assert that paragraph "4" is on page 1 and "5" is on page 2.
+    SwDoc* pDoc = createDoc("lines-in-section-in-table.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    assertXPath(pXmlDoc, "/root/page", 2);
+    sal_uInt32 nPara4Node = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32();
+    CPPUNIT_ASSERT_EQUAL(OUString("4"), pDoc->GetNodes()[nPara4Node]->GetTextNode()->GetText());
+    sal_uInt32 nPara5Node = getXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell[1]/section/txt[1]", "txtNodeIndex").toUInt32();
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), pDoc->GetNodes()[nPara5Node]->GetTextNode()->GetText());
+
+    // Remove paragraph "4".
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    while (pWrtShell->GetCursor()->GetNode().GetIndex() < nPara4Node)
+        pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->EndPara();
+    pWrtShell->Up(/*bSelect=*/true);
+    pWrtShell->DelLeft();
+
+    // Assert that paragraph "5" is now moved back to page 1 and is the last paragraph there.
+    discardDumpedLayout();
+    pXmlDoc = parseLayoutDump();
+    sal_uInt32 nPage1LastNode = getXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell[1]/section/txt[last()]", "txtNodeIndex").toUInt32();
+    // This was "3", paragraph "4" was deleted, but "5" was not moved backwards from page 2.
+    CPPUNIT_ASSERT_EQUAL(OUString("5"), pDoc->GetNodes()[nPage1LastNode]->GetTextNode()->GetText());
+}
+
 void SwUiWriterTest::testTableInSection()
 {
     // The document has a section, containing a table that spans over 2 pages.
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index ed15376a99ef..dcf60c14df3c 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -1726,11 +1726,24 @@ SwLayoutFrame *SwFrame::GetPrevSctLeaf( MakePageType )
     if( bJump )     // Did we skip a blank page?
         SwFlowFrame::SetMoveBwdJump( true );
 
+    SwSectionFrame *pSect = FindSctFrame();
+    if (!pCol && pSect && IsInTab() && !IsInTableInSection(this))
+    {
+        // We don't have a previous section yet, and we're in a
+        // section-in-table.
+        if (SwFlowFrame* pPrecede = pSect->GetPrecede())
+        {
+            // Our section has a precede, work with that.
+            if (pPrecede->GetFrame().IsLayoutFrame())
+                pCol = static_cast<SwLayoutFrame*>(&pPrecede->GetFrame());
+        }
+    }
+
     // Within sections in tables or section in headers/footers there can
     // be only one column change be made, one of the above shortcuts should
     // have applied, also when the section has a pPrev.
     // Now we even consider an empty column...
-    OSL_ENSURE( FindSctFrame(), "GetNextSctLeaf: Missing SectionFrame" );
+    OSL_ENSURE( pSect, "GetNextSctLeaf: Missing SectionFrame" );
     if( ( IsInTab() && !IsTabFrame() ) || FindFooterOrHeader() )
         return pCol;
 
@@ -1738,7 +1751,6 @@ SwLayoutFrame *SwFrame::GetPrevSctLeaf( MakePageType )
     // Precondition, which needs to be hold, is that the <this> frame can be
     // inside a table, but then the found section frame <pSect> is also inside
     // this table.
-    SwSectionFrame *pSect = FindSctFrame();
 
     // #i95698#
     // A table cell containing directly a section does not break - see lcl_FindSectionsInRow(..)
commit 08e39d3c72f6e5eac041caac8b2219247c35b6b8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 13 15:54:23 2017 +0200

    tdf#108524 sw: allow frames in follow sect-in-tables in SwFlowFrame::MoveBwd()
    
    The intention is to filter out text frames directly inside tables; since
    tables in general reflow by moving all of the content to the first page,
    then moving not fitting content to the next pages.  Section frames are
    different, there we explicitly move content backwards, similarly to page
    body frames.
    
    Teach SwFlowFrame::MoveFwd() that a text frame inside a section-in-table
    is the section situation, not the table situation, since what matters
    here is the direct parent. To be on the safe side allow this for follow
    section frames only.
    
    This is necessary, but not enough to address the sub-problem described
    in comment 12 of the bug. At least SwFrame::GetPrevSctLeaf() is invoked
    to consider a precede section frame, though.
    
    Change-Id: Ic88602cffefbbc81ecc90e3880be2a098f60fb04
    (cherry picked from commit 4908d6d6742e2f0700ea4ccd9d636d91ea281046)

diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index c48029a3244f..e6915db4c908 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -2010,7 +2010,10 @@ bool SwFlowFrame::MoveBwd( bool &rbReformat )
             {
                 return false;
             }
-            if ( pUpperFrame->IsColumnFrame() && pUpperFrame->IsInSct() )
+            // If the text frame is a follow-section-in-table, that can move
+            // backward as well.
+            bool bIsFollowSection = pUpperFrame->IsSctFrame() && static_cast<const SwSectionFrame*>(pUpperFrame)->GetPrecede();
+            if ( ( pUpperFrame->IsColumnFrame() && pUpperFrame->IsInSct() ) || bIsFollowSection )
             {
                 break;
             }
commit 92310c27d6b23aa04d218a585d5010db6afe088c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Jul 12 17:53:40 2017 +0200

    tdf#108524 sw: allow frames in growable follow sects in SwFrame::IsMoveable()
    
    In general the move of frames inside growable sections is not allowed,
    so that the behavior is deterministic: either the section grows or
    content is moved to a follow section frame.
    
    But in case of split sections it is necessary to allow the move of text
    frames inside growable section frames, otherwise it is impossible to
    move text frames from the last follow of a section frame to the previous
    one.
    
    This is necessary, but not enough to address the sub-problem described
    in comment 12 of the bug. At least now SwFlowFrame::MoveBwd() is invoked
    to consider moving the frame backwards, though.
    
    Change-Id: I0b79e9db72a4e335701491dd6f7745058901e176
    Reviewed-on: https://gerrit.libreoffice.org/39873
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 5b9edf5d5779b9ce578084250a6c87808ddc5fa8)

diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index 3ad50a012d13..116ccd430d63 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -1264,8 +1264,12 @@ static bool lcl_IsInSectionDirectly( const SwFrame *pUp )
         if( pUp->IsColumnFrame() )
             bSeenColumn = true;
         else if( pUp->IsSctFrame() )
+        {
+            auto pSection = static_cast<const SwSectionFrame*>(pUp);
             // Allow move of frame in case our only column is not growable.
-            return bSeenColumn || !static_cast<const SwSectionFrame*>(pUp)->Growable();
+            // Also allow if there is a previous section frame (to move back).
+            return bSeenColumn || !pSection->Growable() || pSection->GetPrecede();
+        }
         else if( pUp->IsTabFrame() )
             return false;
         pUp = pUp->GetUpper();
commit ebe38430d3119c1923c6d949c4815a53268c621f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jul 7 14:04:28 2017 +0200

    rhbz#739252 sw: fix crash on split tables inside nested sections
    
    Commit b5e0a143308e976b4165ff6181f4dccc3db0bd31 (tdf#108524 sw: attempt
    to split section frames inside table cells, take two, 2017-07-03)
    checked for tables in SwFrame::GetNextSctLeaf() when it considered
    looking up the next "follow" cell frame.
    
    But this is too general, in practice it is only necessary to look for
    follow cell frames in case the frame in question is in a table, but not
    in a table-in-section. This at the same time avoids a crash with tables
    inside nested sections, as it happens in the bugdoc.
    
    Reviewed-on: https://gerrit.libreoffice.org/39692
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 652556ec3e9218655a67b4c4de4e26fbe81855de)
    
    Conflicts:
            sw/source/core/layout/sectfrm.cxx
    
    Change-Id: If648cb477be5492c7158f89934435ca7021a6a63

diff --git a/sw/qa/extras/uiwriter/data/rhbz739252-3.odt b/sw/qa/extras/uiwriter/data/rhbz739252-3.odt
new file mode 100644
index 000000000000..e457c035b662
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/rhbz739252-3.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 8a856d822e20..0f88de7187e3 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -204,6 +204,7 @@ public:
     void testParagraphOfTextRange();
     void testTdf108524();
     void testTableInSection();
+    void testTableInNestedSection();
     void testLinesInSectionInTable();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
@@ -312,6 +313,7 @@ public:
     CPPUNIT_TEST(testTdf108524);
     CPPUNIT_TEST(testTdf108524);
     CPPUNIT_TEST(testTableInSection);
+    CPPUNIT_TEST(testTableInNestedSection);
     CPPUNIT_TEST(testLinesInSectionInTable);
     CPPUNIT_TEST_SUITE_END();
 
@@ -3802,6 +3804,17 @@ void SwUiWriterTest::testTableInSection()
     assertXPath(pXmlDoc, "/root/page[2]/body/section/tab/row/cell", 2);
 }
 
+void SwUiWriterTest::testTableInNestedSection()
+{
+    // The document has a nested section, containing a table that spans over 2 pages.
+    // This crashed the layout.
+    createDoc("rhbz739252-3.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // Make sure the table is inside a section and spans over 2 pages.
+    assertXPath(pXmlDoc, "//page[1]//section/tab", 1);
+    assertXPath(pXmlDoc, "//page[2]//section/tab", 1);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 5a11d6bfed66..ed15376a99ef 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -1515,9 +1515,10 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
     SwLayoutFrame *pLayLeaf;
 
     SwLayoutFrame* pCellLeaf = nullptr;
-    if (IsInTab())
+    if (IsInTab() && !IsInTableInSection(this))
     {
-        // We are in a table, see if there is a follow cell frame created already.
+        // We are in a table (which is itself not in a section), see if there
+        // is a follow cell frame created already.
         pCellLeaf = GetNextCellLeaf(MAKEPAGE_NONE);
         if (!pCellLeaf)
         {
commit e4a5d83949d5a3c071735196213d143e338a36b1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 6 14:07:45 2017 +0200

    i#61225 sw: fix layout loop with growable single-column sections
    
    Commit 6ade80cf142664e78954c7544534e9436ceb90c7 (tdf#108524 sw: allow
    move of frame inside section without columns, 2017-06-16) relaxed
    lcl_IsInSectionDirectly() used in SwFrame::IsMoveable() to allow move
    for all section frame contents if it has a single column.  That looked
    safe, as the multiple column case was already allowed.
    
    There is one situation where this still causes a problem: when the
    section has a single column and the section frame is growable -- as in
    that case we should grow the section frame, not move the contents.
    
    So go back to unconditionally allowing multi-column section contents and
    allow single-column section contents only in case the section frame is
    now growable.
    
    With this, ooo61225-1.sxw from the crashtesting corpus can be opened
    again without a layout loop.
    
    Reviewed-on: https://gerrit.libreoffice.org/39653
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 972fbddf80510f7daaf2128dbfda01c0e7535020)
    
    Conflicts:
            sw/qa/extras/odfimport/odfimport.cxx
    
    Change-Id: Ib2d3702a33da8e62b9bbf468d558ae16db8aa94b

diff --git a/sw/qa/extras/odfimport/data/i61225.sxw b/sw/qa/extras/odfimport/data/i61225.sxw
new file mode 100644
index 000000000000..4f43541995c3
Binary files /dev/null and b/sw/qa/extras/odfimport/data/i61225.sxw differ
diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx
index 92069c00808c..f8dc61d68d81 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -646,5 +646,13 @@ DECLARE_ODFIMPORT_TEST(testTdf96113, "tdf96113.odt")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0x00ff00), getProperty<sal_Int32>(getShape(1), "BackColor"));
 }
 
+DECLARE_ODFIMPORT_TEST(testI61225, "i61225.sxw")
+{
+    // Part of ooo61225-1.sxw from crashtesting.
+
+    // This never returned.
+    calcLayout();
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index fb5854a80c9c..3ad50a012d13 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -1257,10 +1257,15 @@ void SwFrame::InvalidateNextPrtArea()
 ///     but not if it sits in a table which itself sits in a section.
 static bool lcl_IsInSectionDirectly( const SwFrame *pUp )
 {
+    bool bSeenColumn = false;
+
     while( pUp )
     {
-        if( pUp->IsSctFrame() )
-            return true;
+        if( pUp->IsColumnFrame() )
+            bSeenColumn = true;
+        else if( pUp->IsSctFrame() )
+            // Allow move of frame in case our only column is not growable.
+            return bSeenColumn || !static_cast<const SwSectionFrame*>(pUp)->Growable();
         else if( pUp->IsTabFrame() )
             return false;
         pUp = pUp->GetUpper();
commit 68a53c5023cb72f4cb512bbe87e973bb730f2bb8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 6 11:16:54 2017 +0200

    tdf#108524 sw: split section frames inside table cells, non-split text frames
    
    Commit f991b842addddeada6dc45c4054deeca5aa7f17b (tdf#108524 sw: attempt
    to split section frames inside table cells, 2017-06-19) added initial
    support for multi-page sections inside a table cell, but turns out this
    only worked in case at the split point there was a long enough
    paragraph, so it was split into two (a "master" text frame and a
    "follow" one), and then the follow was moved to the next page by
    SwContentFrame::MakeAll(), with the MoveFwd() call in the "If a Follow
    sits next to its Master and doesn't fit, we know it can be moved right
    now." block.
    
    However, if the section contains lots of one-liner text frames, then all
    of them are masters, so the above code doesn't move them to the next
    page; so the section frame is still not split. Fix the problem by
    allowing the move of frames inside table-in-sections in
    SwSectionFrame::MoveAllowed(), that way SwTextFrame::AdjustFrame() will
    not set the text frame as undersized, so at the end
    SwContentFrame::MakeAll() will call MoveFwd() in the "If a column
    section can't find any space for its first ContentFrame" block.
    
    With this the split of text frames in section-in-table frames is
    consistent regardless if they are of multiple or single lines.
    
    Change-Id: Ief9d62da3fd8a5c707e1f9489a92f7a81e7b38ac
    Reviewed-on: https://gerrit.libreoffice.org/39623
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit f8a76d218305a56d15b82b9dac4fafa558872780)

diff --git a/sw/qa/extras/uiwriter/data/lines-in-section-in-table.odt b/sw/qa/extras/uiwriter/data/lines-in-section-in-table.odt
new file mode 100644
index 000000000000..4f0abd6e5e88
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/lines-in-section-in-table.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 7ba2fef47f27..8a856d822e20 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -204,6 +204,7 @@ public:
     void testParagraphOfTextRange();
     void testTdf108524();
     void testTableInSection();
+    void testLinesInSectionInTable();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -311,6 +312,7 @@ public:
     CPPUNIT_TEST(testTdf108524);
     CPPUNIT_TEST(testTdf108524);
     CPPUNIT_TEST(testTableInSection);
+    CPPUNIT_TEST(testLinesInSectionInTable);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3771,6 +3773,22 @@ void SwUiWriterTest::testTdf108524()
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
 }
 
+void SwUiWriterTest::testLinesInSectionInTable()
+{
+    // This is similar to testTdf108524(), but the page boundary now is not in
+    // the middle of a multi-line paragraph: the section only contains oneliner
+    // paragraphs instead.
+    createDoc("lines-in-section-in-table.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // In total we expect two cells containing a section.
+    assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/section", 2);
+
+    assertXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell/section", 1);
+    // This was 0, section wasn't split, instead it was only on the first page
+    // and it was cut off.
+    assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
+}
+
 void SwUiWriterTest::testTableInSection()
 {
     // The document has a section, containing a table that spans over 2 pages.
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 69dba7ed0438..5a11d6bfed66 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -590,7 +590,7 @@ namespace
     }
 
     /// Checks if pFrame is in a table, which itself is in a section.
-    bool IsInTableInSection(SwFrame* pFrame)
+    bool IsInTableInSection(const SwFrame* pFrame)
     {
         if (!pFrame->IsInTab())
             return false;
@@ -2161,8 +2161,8 @@ bool SwSectionFrame::MoveAllowed( const SwFrame* pFrame) const
         return false;
     // Now it has to be examined whether there is a layout sheet wherein
     // a section Follow can be created
-    if( IsInTab() || ( !IsInDocBody() && FindFooterOrHeader() ) )
-        return false; // It doesn't work in tables/headers/footers
+    if( IsInTableInSection(this) || ( !IsInDocBody() && FindFooterOrHeader() ) )
+        return false; // It doesn't work in table-in-sections/headers/footers
     if( IsInFly() ) // In column based or chained frames
         return nullptr != const_cast<SwFrame*>(static_cast<SwFrame const *>(GetUpper()))->GetNextLeaf( MAKEPAGE_NONE );
     return true;
commit 13c9e075abd3ef472375ef7f5c7833ebfd67d2af
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jul 3 13:53:28 2017 +0200

    tdf#108524 sw: attempt to split section frames inside table cells, take two
    
    Tables-in-sections were already split across multiple pages, but not
    secions-in-tables. To be safe still don't allow
    sections-in-tables-in-sections, so you can combine these in both orders
    now, but not recursively.
    
    To achieve this, relax two "not in table" conditions to just require
    "not in a table that is already in a section", and define that in case a
    section-in-table is to be split, the follow section frame should be
    inserted under the follow of its cell.
    
    With this, finally the section frame in the bugdoc is split into two,
    and the second section frame is moved to the second page as expected.
    
    This restores commit f991b842addddeada6dc45c4054deeca5aa7f17b, but this second
    take makes sure that we do not crash while laying out ooo61225-1.sxw.
    GetNextSctLeaf() used to assume that SwTableFrame::Split() created the
    follow cell frames; and when that wasn't the case, it crashed. Still
    don't attempt to create the cell frame in GetNextSctLeaf(), but handle
    when the cell follow frame is missing, and return early, as it used to
    be the case before this commit.
    
    Reviewed-on: https://gerrit.libreoffice.org/39471
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit b5e0a143308e976b4165ff6181f4dccc3db0bd31)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: I9dcc76b4c61b39b9d23b140b84420e89cf274cf3

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index f919fe41e3bd..7ba2fef47f27 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -202,9 +202,7 @@ public:
     void testTdf78727();
     void testTdf104814();
     void testParagraphOfTextRange();
-#if 0
     void testTdf108524();
-#endif
     void testTableInSection();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
@@ -311,9 +309,7 @@ public:
     CPPUNIT_TEST(testTdf104814);
     CPPUNIT_TEST(testParagraphOfTextRange);
     CPPUNIT_TEST(testTdf108524);
-#if 0
     CPPUNIT_TEST(testTdf108524);
-#endif
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST_SUITE_END();
 
@@ -3762,7 +3758,6 @@ void SwUiWriterTest::testParagraphOfTextRange()
     CPPUNIT_ASSERT_EQUAL(OUString("In section"), xParagraph->getString());
 }
 
-#if 0
 void SwUiWriterTest::testTdf108524()
 {
     createDoc("tdf108524.odt");
@@ -3775,7 +3770,6 @@ void SwUiWriterTest::testTdf108524()
     // and it was cut off.
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
 }
-#endif
 
 void SwUiWriterTest::testTableInSection()
 {
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 86dac9e92664..69dba7ed0438 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -22,6 +22,7 @@
 #include <fmtftn.hxx>
 #include <fmtclbl.hxx>
 #include "sectfrm.hxx"
+#include "cellfrm.hxx"
 #include "section.hxx"
 #include <IDocumentSettingAccess.hxx>
 #include "rootfrm.hxx"
@@ -587,6 +588,16 @@ namespace
             return pLayFrame->GetNextLayoutLeaf();
         return pLayFrame;
     }
+
+    /// Checks if pFrame is in a table, which itself is in a section.
+    bool IsInTableInSection(SwFrame* pFrame)
+    {
+        if (!pFrame->IsInTab())
+            return false;
+
+        // The frame is in a table, see if the table is in a section.
+        return pFrame->FindTabFrame()->IsInSct();
+    }
 }
 
 void SwSectionFrame::MoveContentAndDelete( SwSectionFrame* pDel, bool bSave )
@@ -1439,9 +1450,9 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetNext())->Lower());
     if( GetUpper()->IsColBodyFrame() && GetUpper()->GetUpper()->GetNext() )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetUpper()->GetNext())->Lower());
-    // Inside a section, in tables, or sections of headers/footers, there can be only
+    // Inside a table-in-section, or sections of headers/footers, there can be only
     // one column shift be made, one of the above shortcuts should have applied!
-    if( GetUpper()->IsInTab() || FindFooterOrHeader() )
+    if( IsInTableInSection(GetUpper()) || FindFooterOrHeader() )
         return nullptr;
 
     SwSectionFrame *pSect = FindSctFrame();
@@ -1498,7 +1509,23 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
     const bool bBody = IsInDocBody();
     const bool bFootnotePage = FindPageFrame()->IsFootnotePage();
 
+    // The "pLayLeaf is in a table" case is rejected by default, so that it
+    // can't happen that we try to move a table to one of its own cells.
+    bool bLayLeafTableAllowed = false;
     SwLayoutFrame *pLayLeaf;
+
+    SwLayoutFrame* pCellLeaf = nullptr;
+    if (IsInTab())
+    {
+        // We are in a table, see if there is a follow cell frame created already.
+        pCellLeaf = GetNextCellLeaf(MAKEPAGE_NONE);
+        if (!pCellLeaf)
+        {
+            SAL_WARN("sw.layout", "section is in table, but the table is not split");
+            return nullptr;
+        }
+    }
+
     // A shortcut for TabFrames such that not all cells need to be visited
     if( bWrongPage )
         pLayLeaf = nullptr;
@@ -1507,6 +1534,16 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         SwContentFrame* pTmpCnt = static_cast<SwTabFrame*>(this)->FindLastContent();
         pLayLeaf = pTmpCnt ? pTmpCnt->GetUpper() : nullptr;
     }
+    else if (pCellLeaf && !IsInTableInSection(this))
+    {
+        // This frame is in a table-not-in-section, its follow should be
+        // inserted under the follow of the frame's cell.
+        pLayLeaf = pCellLeaf;
+        if (pLayLeaf->FindTabFrame() == FindTabFrame())
+            SAL_WARN("sw.layout", "my table frame and my follow's table frame is the same");
+        // In this case pLayLeaf pointing to an in-table frame is OK.
+        bLayLeafTableAllowed = true;
+    }
     else
     {
         pLayLeaf = GetNextLayoutLeaf();
@@ -1534,10 +1571,10 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
                 pLayLeaf = nullptr;
                 continue;
             }
-            // Once inBody always inBody, don't step into tables and not into other sections
+            // Once inBody always inBody, don't step into tables-in-sections and not into other sections
             if ( (bBody && !pLayLeaf->IsInDocBody()) ||
                  (IsInFootnote() != pLayLeaf->IsInFootnote() ) ||
-                 pLayLeaf->IsInTab() ||
+                 (pLayLeaf->IsInTab() && !bLayLeafTableAllowed) ||
                  ( pLayLeaf->IsInSct() && ( !pSect->HasFollow()
                    || pSect->GetFollow() != pLayLeaf->FindSctFrame() ) ) )
             {
commit 8dc914c2dcb4ad2df7b6a28cd265185dc7796246
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Jun 26 17:31:36 2017 +0200

    Avoid loplugin:unreffun
    
    ...after 272d5a02a3de2350f8af7a93281b651316b24ae5 "Revert 'tdf#108524 sw:
    attempt to split section frames inside table cells'"
    
    (cherry picked from commit 12ca907139c05ded23cb22aab2e03a52645adfa0)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: Ic1ec8cd3284e2ba98630552c80d99b5d67fc7efd

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6b952616316a..f919fe41e3bd 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -202,7 +202,9 @@ public:
     void testTdf78727();
     void testTdf104814();
     void testParagraphOfTextRange();
+#if 0
     void testTdf108524();
+#endif
     void testTableInSection();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
@@ -309,7 +311,9 @@ public:
     CPPUNIT_TEST(testTdf104814);
     CPPUNIT_TEST(testParagraphOfTextRange);
     CPPUNIT_TEST(testTdf108524);
-//    CPPUNIT_TEST(testTdf108524);
+#if 0
+    CPPUNIT_TEST(testTdf108524);
+#endif
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST_SUITE_END();
 
@@ -3758,6 +3762,7 @@ void SwUiWriterTest::testParagraphOfTextRange()
     CPPUNIT_ASSERT_EQUAL(OUString("In section"), xParagraph->getString());
 }
 
+#if 0
 void SwUiWriterTest::testTdf108524()
 {
     createDoc("tdf108524.odt");
@@ -3770,6 +3775,7 @@ void SwUiWriterTest::testTdf108524()
     // and it was cut off.
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
 }
+#endif
 
 void SwUiWriterTest::testTableInSection()
 {
commit 65c58e9eacc7032087567ef5ac17779bad523839
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Jun 26 15:01:36 2017 +0200

    Revert "tdf#108524 sw: attempt to split section frames inside table cells"
    
    This reverts commit f991b842addddeada6dc45c4054deeca5aa7f17b.
    
    It doesn't really work and crashes on ooo61225-1.sxw in
    
    1 in SwFrame::FindTabFrame() (this=0x0) at sw/source/core/inc/frame.hxx:913
    2 in SwFrame::GetNextSctLeaf(MakePageType) (this=0x3137130, eMakePage=MAKEPAGE_INSERT) at sw/source/core/layout/sectfrm.cxx:1529
    3 in SwFrame::GetLeaf(MakePageType, bool) (this=0x3137130, eMakePage=MAKEPAGE_INSERT, bFwd=true) at sw/source/core/layout/flowfrm.cxx:805
    4 in SwFlowFrame::MoveFwd(bool, bool, bool) (this=0x31371d8, bMakePage=true, bPageBreak=false, bMoveAlways=false) at sw/source/core/layout/flowfrm.cxx:1861
    
    The code added in GetNextSctLeaf() looks unfinished to me: it assumes that
    something else has added a follow-frame for the SwCellFrame containing
    the SwSectionFrame already, but AFAICT the GetNextSctLeaf() function
    is responsible for creating that SwCellFrame follow.
    
    The caller (in GetLeaf()) specifically checks for this condition and
    avoids calling GetNextCellLeaf().
    
    (cherry picked from commit 272d5a02a3de2350f8af7a93281b651316b24ae5)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: I51875830771f07f5d2fec293f6063c73fc68d468

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 54fedd55ddd6..6b952616316a 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -309,6 +309,7 @@ public:
     CPPUNIT_TEST(testTdf104814);
     CPPUNIT_TEST(testParagraphOfTextRange);
     CPPUNIT_TEST(testTdf108524);
+//    CPPUNIT_TEST(testTdf108524);
     CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST_SUITE_END();
 
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index 1ddc12bf8283..331e47e71baf 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -42,7 +42,6 @@ class SwFootnoteFrame;
 class SwFootnoteBossFrame;
 class SwTabFrame;
 class SwRowFrame;
-class SwCellFrame;
 class SwFlowFrame;
 class SwContentFrame;
 class SfxPoolItem;
@@ -228,7 +227,6 @@ class SW_DLLPUBLIC SwFrame: public SwClient, public SfxBroadcaster
     const SwLayoutFrame* ImplGetNextLayoutLeaf( bool bFwd ) const;
 
     SwPageFrame* ImplFindPageFrame();
-    SwCellFrame* ImplFindCellFrame();
 
 protected:
     SwSortedObjs* mpDrawObjs;    // draw objects, can be 0
@@ -772,12 +770,6 @@ public:
     virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const;
     void dumpChildrenAsXml(xmlTextWriterPtr writer) const;
     bool IsCollapse() const;
-
-    /// Find the nearest table cell frame that contains us, if any.
-    SwCellFrame* FindCellFrame()
-    {
-        return IsInTab() ? ImplFindCellFrame() : nullptr;
-    }
 };
 
 inline bool SwFrame::IsInDocBody() const
diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index d0981628b2eb..fb5854a80c9c 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -459,18 +459,6 @@ SwTabFrame* SwFrame::ImplFindTabFrame()
     return static_cast<SwTabFrame*>(pRet);
 }
 
-SwCellFrame* SwFrame::ImplFindCellFrame()
-{
-    SwFrame *pRet = this;
-    while (!pRet->IsCellFrame())
-    {
-        pRet = pRet->GetUpper();
-        if (!pRet)
-            return nullptr;
-    }
-    return static_cast<SwCellFrame*>(pRet);
-}
-
 SwSectionFrame* SwFrame::ImplFindSctFrame()
 {
     SwFrame *pRet = this;
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index f23a93c3ebd3..86dac9e92664 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -22,7 +22,6 @@
 #include <fmtftn.hxx>
 #include <fmtclbl.hxx>
 #include "sectfrm.hxx"
-#include "cellfrm.hxx"
 #include "section.hxx"
 #include <IDocumentSettingAccess.hxx>
 #include "rootfrm.hxx"
@@ -588,16 +587,6 @@ namespace
             return pLayFrame->GetNextLayoutLeaf();
         return pLayFrame;
     }
-
-    /// Checks if pFrame is in a table, which itself is in a section.
-    bool IsInTableInSection(SwFrame* pFrame)
-    {
-        if (!pFrame->IsInTab())
-            return false;
-
-        // The frame is in a table, see if the table is in a section.
-        return pFrame->FindTabFrame()->IsInSct();
-    }
 }
 
 void SwSectionFrame::MoveContentAndDelete( SwSectionFrame* pDel, bool bSave )
@@ -1450,9 +1439,9 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetNext())->Lower());
     if( GetUpper()->IsColBodyFrame() && GetUpper()->GetUpper()->GetNext() )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetUpper()->GetNext())->Lower());
-    // Inside a table-in-section, or sections of headers/footers, there can be only
+    // Inside a section, in tables, or sections of headers/footers, there can be only
     // one column shift be made, one of the above shortcuts should have applied!
-    if( IsInTableInSection(GetUpper()) || FindFooterOrHeader() )
+    if( GetUpper()->IsInTab() || FindFooterOrHeader() )
         return nullptr;
 
     SwSectionFrame *pSect = FindSctFrame();
@@ -1509,9 +1498,6 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
     const bool bBody = IsInDocBody();
     const bool bFootnotePage = FindPageFrame()->IsFootnotePage();
 
-    // The "pLayLeaf is in a table" case is rejected by default, so that it
-    // can't happen that we try to move a table to one of its own cells.
-    bool bLayLeafTableAllowed = false;
     SwLayoutFrame *pLayLeaf;
     // A shortcut for TabFrames such that not all cells need to be visited
     if( bWrongPage )
@@ -1521,16 +1507,6 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         SwContentFrame* pTmpCnt = static_cast<SwTabFrame*>(this)->FindLastContent();
         pLayLeaf = pTmpCnt ? pTmpCnt->GetUpper() : nullptr;
     }
-    else if (IsInTab() && !IsInTableInSection(this))
-    {
-        // This frame is in a table-not-in-section, its follow should be
-        // inserted under the follow of the frame's cell.
-        pLayLeaf = FindCellFrame()->GetFollowCell();
-        if (pLayLeaf->FindTabFrame() == FindTabFrame())
-            SAL_WARN("sw.layout", "my table frame and my follow's table frame is the same");
-        // In this case pLayLeaf pointing to an in-table frame is OK.
-        bLayLeafTableAllowed = true;
-    }
     else
     {
         pLayLeaf = GetNextLayoutLeaf();
@@ -1558,10 +1534,10 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
                 pLayLeaf = nullptr;
                 continue;
             }
-            // Once inBody always inBody, don't step into tables-in-sections and not into other sections
+            // Once inBody always inBody, don't step into tables and not into other sections
             if ( (bBody && !pLayLeaf->IsInDocBody()) ||
                  (IsInFootnote() != pLayLeaf->IsInFootnote() ) ||
-                 (pLayLeaf->IsInTab() && !bLayLeafTableAllowed) ||
+                 pLayLeaf->IsInTab() ||
                  ( pLayLeaf->IsInSct() && ( !pSect->HasFollow()
                    || pSect->GetFollow() != pLayLeaf->FindSctFrame() ) ) )
             {
commit b50c8680f36ea89fcd1411a9c37a139aa55a30cd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jun 20 09:21:10 2017 +0200

    tdf#108524 sw: add split section in table testcase
    
    And if we're at it, test the other way around as well, I almost broke
    it.
    
    Reviewed-on: https://gerrit.libreoffice.org/38999
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit e9d2016648c7fdfc57932ac0793547cf099749be)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: Ia81e46f218336e5db13dafdbad7b896d8dadaf46

diff --git a/sw/qa/extras/uiwriter/data/table-in-sect.odt b/sw/qa/extras/uiwriter/data/table-in-sect.odt
new file mode 100644
index 000000000000..f439edef997e
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/table-in-sect.odt differ
diff --git a/sw/qa/extras/uiwriter/data/tdf108524.odt b/sw/qa/extras/uiwriter/data/tdf108524.odt
new file mode 100644
index 000000000000..d8978b269cab
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf108524.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 36c1a5a10199..54fedd55ddd6 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -202,6 +202,8 @@ public:
     void testTdf78727();
     void testTdf104814();
     void testParagraphOfTextRange();
+    void testTdf108524();
+    void testTableInSection();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -306,6 +308,8 @@ public:
     CPPUNIT_TEST(testTdf78727);
     CPPUNIT_TEST(testTdf104814);
     CPPUNIT_TEST(testParagraphOfTextRange);
+    CPPUNIT_TEST(testTdf108524);
+    CPPUNIT_TEST(testTableInSection);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3753,6 +3757,32 @@ void SwUiWriterTest::testParagraphOfTextRange()
     CPPUNIT_ASSERT_EQUAL(OUString("In section"), xParagraph->getString());
 }
 
+void SwUiWriterTest::testTdf108524()
+{
+    createDoc("tdf108524.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // In total we expect two cells containing a section.
+    assertXPath(pXmlDoc, "/root/page/body/tab/row/cell/section", 2);
+
+    assertXPath(pXmlDoc, "/root/page[1]/body/tab/row/cell/section", 1);
+    // This was 0, section wasn't split, instead it was only on the first page
+    // and it was cut off.
+    assertXPath(pXmlDoc, "/root/page[2]/body/tab/row/cell/section", 1);
+}
+
+void SwUiWriterTest::testTableInSection()
+{
+    // The document has a section, containing a table that spans over 2 pages.
+    createDoc("table-in-sect.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // In total we expect 4 cells.
+    assertXPath(pXmlDoc, "/root/page/body/section/tab/row/cell", 4);
+
+    // Assert that on both pages the section contains 2 cells.
+    assertXPath(pXmlDoc, "/root/page[1]/body/section/tab/row/cell", 2);
+    assertXPath(pXmlDoc, "/root/page[2]/body/section/tab/row/cell", 2);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
commit 7824d47b66d820fb4b48ebc0a356017b707b73a1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jun 19 15:24:12 2017 +0200

    tdf#108524 sw: attempt to split section frames inside table cells
    
    Tables-in-sections were already split across multiple pages, but not
    secions-in-tables. To be safe still don't allow
    sections-in-tables-in-sections, so you can combine these in both orders
    now, but not recursively.
    
    To achieve this, relax two "not in table" conditions to just require
    "not in a table that is already in a section", and define that in case a
    section-in-table is to be split, the follow section frame should be
    inserted under the follow of its cell.
    
    With this, finally the section frame in the bugdoc is split into two,
    and the second section frame is moved to the second page as expected.
    
    Change-Id: I16ebb2d30870b145a2378d46603324ab267b0dd3
    Reviewed-on: https://gerrit.libreoffice.org/38965
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit f991b842addddeada6dc45c4054deeca5aa7f17b)

diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index 331e47e71baf..1ddc12bf8283 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -42,6 +42,7 @@ class SwFootnoteFrame;
 class SwFootnoteBossFrame;
 class SwTabFrame;
 class SwRowFrame;
+class SwCellFrame;
 class SwFlowFrame;
 class SwContentFrame;
 class SfxPoolItem;
@@ -227,6 +228,7 @@ class SW_DLLPUBLIC SwFrame: public SwClient, public SfxBroadcaster
     const SwLayoutFrame* ImplGetNextLayoutLeaf( bool bFwd ) const;
 
     SwPageFrame* ImplFindPageFrame();
+    SwCellFrame* ImplFindCellFrame();
 
 protected:
     SwSortedObjs* mpDrawObjs;    // draw objects, can be 0
@@ -770,6 +772,12 @@ public:
     virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const;
     void dumpChildrenAsXml(xmlTextWriterPtr writer) const;
     bool IsCollapse() const;
+
+    /// Find the nearest table cell frame that contains us, if any.
+    SwCellFrame* FindCellFrame()
+    {
+        return IsInTab() ? ImplFindCellFrame() : nullptr;
+    }
 };
 
 inline bool SwFrame::IsInDocBody() const
diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index fb5854a80c9c..d0981628b2eb 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -459,6 +459,18 @@ SwTabFrame* SwFrame::ImplFindTabFrame()
     return static_cast<SwTabFrame*>(pRet);
 }
 
+SwCellFrame* SwFrame::ImplFindCellFrame()
+{
+    SwFrame *pRet = this;
+    while (!pRet->IsCellFrame())
+    {
+        pRet = pRet->GetUpper();
+        if (!pRet)
+            return nullptr;
+    }
+    return static_cast<SwCellFrame*>(pRet);
+}
+
 SwSectionFrame* SwFrame::ImplFindSctFrame()
 {
     SwFrame *pRet = this;
diff --git a/sw/source/core/layout/sectfrm.cxx b/sw/source/core/layout/sectfrm.cxx
index 86dac9e92664..f23a93c3ebd3 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -22,6 +22,7 @@
 #include <fmtftn.hxx>
 #include <fmtclbl.hxx>
 #include "sectfrm.hxx"
+#include "cellfrm.hxx"
 #include "section.hxx"
 #include <IDocumentSettingAccess.hxx>
 #include "rootfrm.hxx"
@@ -587,6 +588,16 @@ namespace
             return pLayFrame->GetNextLayoutLeaf();
         return pLayFrame;
     }
+
+    /// Checks if pFrame is in a table, which itself is in a section.
+    bool IsInTableInSection(SwFrame* pFrame)
+    {
+        if (!pFrame->IsInTab())
+            return false;
+
+        // The frame is in a table, see if the table is in a section.
+        return pFrame->FindTabFrame()->IsInSct();
+    }
 }
 
 void SwSectionFrame::MoveContentAndDelete( SwSectionFrame* pDel, bool bSave )
@@ -1439,9 +1450,9 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetNext())->Lower());
     if( GetUpper()->IsColBodyFrame() && GetUpper()->GetUpper()->GetNext() )
         return static_cast<SwLayoutFrame*>(static_cast<SwLayoutFrame*>(GetUpper()->GetUpper()->GetNext())->Lower());
-    // Inside a section, in tables, or sections of headers/footers, there can be only
+    // Inside a table-in-section, or sections of headers/footers, there can be only
     // one column shift be made, one of the above shortcuts should have applied!
-    if( GetUpper()->IsInTab() || FindFooterOrHeader() )
+    if( IsInTableInSection(GetUpper()) || FindFooterOrHeader() )
         return nullptr;
 
     SwSectionFrame *pSect = FindSctFrame();
@@ -1498,6 +1509,9 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
     const bool bBody = IsInDocBody();
     const bool bFootnotePage = FindPageFrame()->IsFootnotePage();
 
+    // The "pLayLeaf is in a table" case is rejected by default, so that it
+    // can't happen that we try to move a table to one of its own cells.
+    bool bLayLeafTableAllowed = false;
     SwLayoutFrame *pLayLeaf;
     // A shortcut for TabFrames such that not all cells need to be visited
     if( bWrongPage )
@@ -1507,6 +1521,16 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
         SwContentFrame* pTmpCnt = static_cast<SwTabFrame*>(this)->FindLastContent();
         pLayLeaf = pTmpCnt ? pTmpCnt->GetUpper() : nullptr;
     }
+    else if (IsInTab() && !IsInTableInSection(this))
+    {
+        // This frame is in a table-not-in-section, its follow should be
+        // inserted under the follow of the frame's cell.
+        pLayLeaf = FindCellFrame()->GetFollowCell();
+        if (pLayLeaf->FindTabFrame() == FindTabFrame())
+            SAL_WARN("sw.layout", "my table frame and my follow's table frame is the same");
+        // In this case pLayLeaf pointing to an in-table frame is OK.
+        bLayLeafTableAllowed = true;
+    }
     else
     {
         pLayLeaf = GetNextLayoutLeaf();
@@ -1534,10 +1558,10 @@ SwLayoutFrame *SwFrame::GetNextSctLeaf( MakePageType eMakePage )
                 pLayLeaf = nullptr;
                 continue;
             }
-            // Once inBody always inBody, don't step into tables and not into other sections
+            // Once inBody always inBody, don't step into tables-in-sections and not into other sections
             if ( (bBody && !pLayLeaf->IsInDocBody()) ||
                  (IsInFootnote() != pLayLeaf->IsInFootnote() ) ||
-                 pLayLeaf->IsInTab() ||
+                 (pLayLeaf->IsInTab() && !bLayLeafTableAllowed) ||
                  ( pLayLeaf->IsInSct() && ( !pSect->HasFollow()
                    || pSect->GetFollow() != pLayLeaf->FindSctFrame() ) ) )
             {
commit 4f04538beb9049ed3dcc5a50b04b9acadd95a0ac
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 16 08:35:05 2017 +0200

    tdf#108524 sw: allow move of frame inside section without columns
    
    The intention here is to deny the move of a frame that's inside a table
    inside a section.  But the code also checked if there a column frame
    in-between, so it allowed the move for a frame in a section with 2 cols,
    but not without columns (which does not sound intentional, since that's
    a simpler case). So drop the requirement to have a column frame between
    the argument and the section frame, just check that there is no table
    frame in between.
    
    This is needed, but not enough to split the section in the bugdoc (but
    at least now the content of the section is marked as movable).
    
    Change-Id: I9155b291a19c692efc30f01f8e206fac5f1ccf81
    Reviewed-on: https://gerrit.libreoffice.org/38858
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 6ade80cf142664e78954c7544534e9436ceb90c7)

diff --git a/sw/source/core/layout/findfrm.cxx b/sw/source/core/layout/findfrm.cxx
index 89cf31663e2c..fb5854a80c9c 100644
--- a/sw/source/core/layout/findfrm.cxx
+++ b/sw/source/core/layout/findfrm.cxx
@@ -1253,17 +1253,14 @@ void SwFrame::InvalidateNextPrtArea()
     }
 }
 
-/// @returns true if the frame _directly_ sits in a section with columns
-///     but not if it sits in a table which itself sits in a section with columns.
-static bool lcl_IsInColSct( const SwFrame *pUp )
+/// @returns true if the frame _directly_ sits in a section
+///     but not if it sits in a table which itself sits in a section.
+static bool lcl_IsInSectionDirectly( const SwFrame *pUp )
 {
-    bool bRet = false;
     while( pUp )
     {
-        if( pUp->IsColumnFrame() )
-            bRet = true;
-        else if( pUp->IsSctFrame() )
-            return bRet;
+        if( pUp->IsSctFrame() )
+            return true;
         else if( pUp->IsTabFrame() )
             return false;
         pUp = pUp->GetUpper();
@@ -1290,7 +1287,7 @@ bool SwFrame::IsMoveable( const SwLayoutFrame* _pLayoutFrame ) const
 
     if ( _pLayoutFrame && IsFlowFrame() )
     {
-        if ( _pLayoutFrame->IsInSct() && lcl_IsInColSct( _pLayoutFrame ) )
+        if ( _pLayoutFrame->IsInSct() && lcl_IsInSectionDirectly( _pLayoutFrame ) )
         {
             bRetVal = true;
         }
commit bcaabbd8c589b469fbbb5a409a5c63355251c4b6
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 15 12:18:31 2017 +0200

    tdf#108524 sw: try to split rows that contain 1-col sections
    
    We used to not even attempt to split a row that contains sections. Relax
    this condition and try to split the row in case the table itself is not
    in a section (to avoid recursion) and the section has no columns.
    
    This is needed, but not enough to split the section in the bugdoc.
    
    Change-Id: I6ad0d6eb18611f108ae29e4feea7101ffe552c48
    Reviewed-on: https://gerrit.libreoffice.org/38824
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 336ec28195da1917c22494a24dbaf10b846d3141)

diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 2230a4920e14..45282d886929 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -906,7 +906,22 @@ static bool lcl_FindSectionsInRow( const SwRowFrame& rRow )
             else
             {
                 // #i26945# - search only for sections
-                bRet = pTmpFrame->IsSctFrame();
+                if (pTmpFrame->IsSctFrame())
+                {
+                    bRet = true;
+
+                    if (!rRow.IsInSct())
+                    {
+                        // This row is not in a section.
+                        if (const SwFrame* pSectionLower = pTmpFrame->GetLower())
+                        {
+                            if (!pSectionLower->IsColumnFrame())
+                                // Section has a single column only, try to
+                                // split that.
+                                bRet = false;
+                        }
+                    }
+                }
             }
 
             if ( bRet )
commit 6b569bd8d6a5a2219aaad9b3e42e0d60ca6d39dd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 15 11:08:48 2017 +0200

    Related: tdf#108524 sw: dump follow/precede of cell frames in layout xml dump
    
    These point to the other cell frame on the previous/next page (in case
    the cell frame is split across multiple pages).
    
    Change-Id: Ic03cf9a194a49320d84dbdb5176fa737e5d6520d
    Reviewed-on: https://gerrit.libreoffice.org/38818
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 835c1586f60e6bc03e045e8210e38876e0fe1abc)

diff --git a/sw/source/core/inc/cellfrm.hxx b/sw/source/core/inc/cellfrm.hxx
index 8ddc89ffd404..ba2ae774519d 100644
--- a/sw/source/core/inc/cellfrm.hxx
+++ b/sw/source/core/inc/cellfrm.hxx
@@ -60,6 +60,7 @@ public:
     const SwCellFrame& FindStartEndOfRowSpanCell( bool bStart ) const;
     long GetLayoutRowSpan() const;
 
+    void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override;
     DECL_FIXEDMEMPOOL_NEWDEL(SwCellFrame)
 };
 
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 138fa1a2ff95..2230a4920e14 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -5028,6 +5028,16 @@ long SwCellFrame::GetLayoutRowSpan() const
     return  nRet;
 }
 
+void SwCellFrame::dumpAsXmlAttributes(xmlTextWriterPtr pWriter) const
+{
+    SwFrame::dumpAsXmlAttributes(pWriter);
+    if (SwCellFrame* pFollow = GetFollowCell())
+        xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("follow"), "%" SAL_PRIuUINT32, pFollow->GetFrameId());
+
+    if (SwCellFrame* pPrevious = GetPreviousCell())
+        xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("precede"), "%" SAL_PRIuUINT32, pPrevious->GetFrameId());
+}
+
 // #i103961#
 void SwCellFrame::Cut()
 {


More information about the Libreoffice-commits mailing list