sw/qa/extras/layout/data/tdf143239-1-min.odt |binary
 sw/qa/extras/layout/layout.cxx               |   58 +++++++++++++++++++++++++++
 sw/source/core/layout/layact.cxx             |    3 +
 3 files changed, 61 insertions(+)

New commits:
commit bfb19a4ec7c43680358fe81e33bdfcb0ca47c91c
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Mar 1 10:12:15 2022 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Mar 10 10:32:19 2022 +0100

    Fix flaky test on Win64
    
    Obviously the left values are unstable; they were excluded on macOS,
    and they fail exactly on the same lines for me locally on Win64 build.
    So just test that the values are restored after delete and undo.
    
    Change-Id: I63dc50d223edb052a0ada200189cef94c2e0f8e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130738
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit da77aec27e3121c895a6c6c287225216489cc8bc)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131024
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 5fbecf5be3c1..f48117661d9c 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -1280,29 +1280,27 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf143239)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf143239-1-min.odt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
 
+    // These are unstable on macOS and Win64 builds,
+    // so only test that they restore original values for now
+    OUString p2txt1Left, p2txt2Left, p3txt1Left;
+
     {
         xmlDocUniquePtr pXmlDoc = parseLayoutDump();
         assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
                     "18540");
-#ifndef MACOSX
-        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
-                    "3559");
-#endif
+        p2txt1Left
+            = getXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "left");
         assertXPath(pXmlDoc, "/root/page[2]/body/txt[2]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "top",
                     "23894");
-#ifndef MACOSX
-        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "left",
-                    "1964");
-#endif
+        p2txt2Left
+            = getXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "left");
         assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
                     "35662");
-#ifndef MACOSX
-        assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
-                    "3129");
-#endif
+        p3txt1Left
+            = getXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "left");
         assertXPath(pXmlDoc, "/root/page", 3);
         discardDumpedLayout();
     }
@@ -1318,24 +1316,18 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf143239)
         assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
                     "18540");
-#ifndef MACOSX
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
-                    "3559");
-#endif
+                    p2txt1Left);
         assertXPath(pXmlDoc, "/root/page[2]/body/txt[2]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "top",
                     "23894");
-#ifndef MACOSX
         assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "left",
-                    "1964");
-#endif
+                    p2txt2Left);
         assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/anchored/fly", 1);
         assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
                     "35662");
-#ifndef MACOSX
         assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
-                    "3129");
-#endif
+                    p3txt1Left);
         assertXPath(pXmlDoc, "/root/page", 3);
         discardDumpedLayout();
     }
commit cd60a2d31737f491088cfb0789bc014b1e0aad5f
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Feb 25 13:43:56 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Mar 10 10:32:02 2022 +0100

    tdf#143239 sw: layout: invalidate fly position when moving off page
    
    It's possible that flags on the fly are all valid when it is moved off page
    when SwLayAction::FormatContent() returns and then it may not be positioned
    again, keeping its (wrong) position on the old page and will appear to be
    invisible unless you click on it.
    
    (regression from commits c799de145f7e289f31e3669646e5bd12814e6c5e
     and eb85de8e6b61fb3fcb6c03ae0145f7fe5478bccf)
    
    Change-Id: If07d5af7b47eb288bef71d1b9e3459197b50fdc9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130535
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit b14bb255199e7d6db6ec9155b5d9237cb35fdba7)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130776
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/extras/layout/data/tdf143239-1-min.odt 
b/sw/qa/extras/layout/data/tdf143239-1-min.odt
new file mode 100644
index 000000000000..4271bfba775b
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf143239-1-min.odt differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 00d565d648ca..5fbecf5be3c1 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -1275,6 +1275,72 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysInFootnote)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf143239)
+{
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf143239-1-min.odt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
+                    "18540");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
+                    "3559");
+#endif
+        assertXPath(pXmlDoc, "/root/page[2]/body/txt[2]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "top",
+                    "23894");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "left",
+                    "1964");
+#endif
+        assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
+                    "35662");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
+                    "3129");
+#endif
+        assertXPath(pXmlDoc, "/root/page", 3);
+        discardDumpedLayout();
+    }
+
+    pWrtShell->SelAll();
+    pWrtShell->Delete();
+    pWrtShell->Undo();
+    Scheduler::ProcessEventsToIdle();
+
+    {
+        xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+        // now the 1st fly was on page 1, and the fly on page 2 was the 2nd one
+        assertXPath(pXmlDoc, "/root/page[2]/body/txt[1]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
+                    "18540");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
+                    "3559");
+#endif
+        assertXPath(pXmlDoc, "/root/page[2]/body/txt[2]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "top",
+                    "23894");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[2]/body/txt[2]/anchored/fly[1]/infos/bounds", "left",
+                    "1964");
+#endif
+        assertXPath(pXmlDoc, "/root/page[3]/body/txt[1]/anchored/fly", 1);
+        assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "top",
+                    "35662");
+#ifndef MACOSX
+        assertXPath(pXmlDoc, 
"/root/page[3]/body/txt[1]/anchored/fly[1]/infos/bounds", "left",
+                    "3129");
+#endif
+        assertXPath(pXmlDoc, "/root/page", 3);
+        discardDumpedLayout();
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTableOverlapFooterFly)
 {
     // Load a document that has a fly anchored in the footer.
diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index cb5b818881b9..b26293ce73d0 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -1606,6 +1606,9 @@ bool SwLayAction::FormatContent(SwPageFrame *const pPage)
             {
                 SAL_INFO("sw.layout", "SwLayAction::FormatContent: move 
anchored " << pObj << " from " << pPage->GetPhyPageNum() << " to " << 
pAnchorPage->GetPhyPageNum());
                 pObj->RegisterAtPage(*pAnchorPage);
+                // tdf#143239 if the position remains valid, it may not be
+                // positioned again so would remain on the wrong page!
+                pObj->InvalidateObjPos();
                 ::Notify_Background(pObj->GetDrawObj(), pPage,
                     pObj->GetObjRect(), PrepareHint::FlyFrameLeave, false);
             }

Reply via email to