sw/source/core/inc/tabfrm.hxx    |    1 +
 sw/source/core/layout/fly.cxx    |    7 ++++++-
 sw/source/core/layout/tabfrm.cxx |   24 ++++++++++++++++++++++--
 3 files changed, 29 insertions(+), 3 deletions(-)

New commits:
commit 1808306db7bec6cd668b5840eb8a0121ee89991f
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Tue Aug 8 12:21:20 2023 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Aug 14 11:21:58 2023 +0200

    tdf#156551 tdf#150606 sw: layout: only invalidate SwTabFrame if it...
    
    ... wants to move back.
    
    In this document, the table 1709 splits across 3 columns of the section
    1702 with 1 row each, and when its follows are invalidated in
    CalcContent(), the later SwTabFrame::MakeAll() of the 1st follow joins
    the 2nd follow and invalidates the size of the section frame, causing a
    loop.
    
    So only invalidate if that actually looks necessary.
    
    (regression from commit 59987d3c77ec7dbf59fbea9f47cc226f4e8903f9)
    
    Change-Id: I360c8f697a7666a19a08d8ebcabbcfa3a7cdf844
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155452
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit a9b19f78f3cdcbf5c949a85b45877e903114cc54)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155408
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/core/inc/tabfrm.hxx b/sw/source/core/inc/tabfrm.hxx
index 7e7a590c7907..a249f6c1f845 100644
--- a/sw/source/core/inc/tabfrm.hxx
+++ b/sw/source/core/inc/tabfrm.hxx
@@ -61,6 +61,7 @@ class SW_DLLPUBLIC SwTabFrame final: public SwLayoutFrame, 
public SwFlowFrame
     bool m_bCalcLowers      :1; /// For stability of the content in MakeAll
     bool m_bLowersFormatted :1; /// Communication between MakeAll and Layact
     bool m_bLockBackMove    :1; /// The Master took care of the BackMove test
+    bool m_bWantBackMove    :1; /// Table wants to move back but was locked
     bool m_bResizeHTMLTable :1; /// Call the Resize of the HTMLTableLayout in 
the MakeAll
                                 /// This is an optimization, so that we don't 
have to call
                                 /// it in ContentFrame::Grow; there it might 
be called for
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
index 4022e1995fe8..c2d27eaf2f0e 100644
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -1843,7 +1843,12 @@ void CalcContent( SwLayoutFrame *pLay, bool bNoColl )
                 {
                     assert(static_cast<SwTabFrame*>(pFrame)->IsFollow());
                     static_cast<SwTabFrame*>(pFrame)->m_bLockBackMove = false;
-                    pFrame->InvalidatePos();
+                    // tdf#150606 encourage it to move back in FormatLayout()
+                    if (static_cast<SwTabFrame*>(pFrame)->m_bWantBackMove)
+                    {
+                        static_cast<SwTabFrame*>(pFrame)->m_bWantBackMove = 
false;
+                        pFrame->InvalidatePos();
+                    }
                 }
             }
 
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index a4dddec2ec83..02e3dbdc187d 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -79,6 +79,7 @@ SwTabFrame::SwTabFrame( SwTable &rTab, SwFrame* pSib )
     , m_bCalcLowers(false)
     , m_bLowersFormatted(false)
     , m_bLockBackMove(false)
+    , m_bWantBackMove(false)
     , m_bResizeHTMLTable(false)
     , m_bONECalcLowers(false)
     , m_bHasFollowFlowLine(false)
@@ -124,6 +125,7 @@ SwTabFrame::SwTabFrame( SwTabFrame &rTab )
     , m_bCalcLowers(false)
     , m_bLowersFormatted(false)
     , m_bLockBackMove(false)
+    , m_bWantBackMove(false)
     , m_bResizeHTMLTable(false)
     , m_bONECalcLowers(false)
     , m_bHasFollowFlowLine(false)
@@ -3820,9 +3822,17 @@ bool SwTabFrame::ShouldBwdMoved( SwLayoutFrame 
*pNewUpper, bool &rReformat )
             }
             else if (!m_bLockBackMove)
                 bMoveAnyway = true;
+            else
+            {
+                m_bWantBackMove = true;
+            }
         }
         else if (!m_bLockBackMove)
             bMoveAnyway = true;
+        else
+        {
+            m_bWantBackMove = true;
+        }
 
         if ( bMoveAnyway )
         {
@@ -3835,7 +3845,7 @@ bool SwTabFrame::ShouldBwdMoved( SwLayoutFrame 
*pNewUpper, bool &rReformat )
             // This frame fits into pNewUpper in case it has no space, but this
             // frame is empty.
             bFits = nSpace >= 0;
-        if (!m_bLockBackMove && bFits)
+        if (bFits)
         {
             // #i26945# - check, if follow flow line
             // contains frame, which are moved forward due to its object
@@ -3854,7 +3864,17 @@ bool SwTabFrame::ShouldBwdMoved( SwLayoutFrame 
*pNewUpper, bool &rReformat )
             // 'return nHeight <= nSpace' to 'return nTmpHeight < nSpace'.
             // This obviously results in problems with table frames in
             // sections. Remember: Every twip is sacred.
-            return nTmpHeight <= nSpace;
+            if (nTmpHeight <= nSpace)
+            {
+                if (m_bLockBackMove)
+                {
+                    m_bWantBackMove = true;
+                }
+                else
+                {
+                    return true;
+                }
+            }
         }
     }
     return false;

Reply via email to