[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sw/CppunitTest_sw_layoutwriter.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 2 09:46:17 UTC 2019


 sw/CppunitTest_sw_layoutwriter.mk          |    1 
 sw/qa/extras/layout/data/image-comment.odt |binary
 sw/qa/extras/layout/layout.cxx             |   44 +++++++++++++++++++++++++++++
 sw/source/core/text/itrcrsr.cxx            |   30 +++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletion(-)

New commits:
commit 315c0c50506c8b2608fd49008a55145db675209e
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Aug 1 15:31:10 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Aug 2 11:45:30 2019 +0200

    sw comments on frames: improve doc coordinates -> doc model pos conversion
    
    In case an as-char image at the end of a paragraph was commented and the
    user clicked past the end of the paragraph, we defaulted to extending
    that comment, rather appending content. (The cursor was placed between
    the as-char image and the comment anchor, not past the comment anchor.)
    
    This doesn't seem to be useful, probably the expectation is that if the
    user clicks before the comment anchor then we extend the comment range,
    and if the click is after the comment anchor, then we don't. In both
    cases we used to *select* the comment anchor, so typing a character
    deleted the comment instead.
    
    This commit is a step in the direction of never selecting the comment
    anchor: now if you click past the comment anchor, then we place the
    cursor after the comment anchor.
    
    (But clicking before the comment anchor results in unchanged behavior
    for now.)
    
    (cherry picked from commit 27c46ecf34b32bae1806d3fc0e1684179301feb8)
    
    Conflicts:
            sw/qa/extras/layout/layout.cxx
            sw/source/core/text/itrcrsr.cxx
    
    Change-Id: I6c36ec4344591fdf330a73bcd3cdd6fd0610e339
    Reviewed-on: https://gerrit.libreoffice.org/76839
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/CppunitTest_sw_layoutwriter.mk b/sw/CppunitTest_sw_layoutwriter.mk
index e5f5a180920e..99eee6c12b40 100644
--- a/sw/CppunitTest_sw_layoutwriter.mk
+++ b/sw/CppunitTest_sw_layoutwriter.mk
@@ -44,6 +44,7 @@ $(eval $(call gb_CppunitTest_use_externals,sw_layoutwriter,\
 $(eval $(call gb_CppunitTest_set_include,sw_layoutwriter,\
     -I$(SRCDIR)/sw/inc \
     -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
     -I$(SRCDIR)/sw/qa/extras/inc \
     $$(INCLUDE) \
 ))
diff --git a/sw/qa/extras/layout/data/image-comment.odt b/sw/qa/extras/layout/data/image-comment.odt
new file mode 100644
index 000000000000..d861d3a9aa03
Binary files /dev/null and b/sw/qa/extras/layout/data/image-comment.odt differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 59f73e0b78bd..0087f49c76f8 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -10,6 +10,13 @@
 #include <comphelper/propertysequence.hxx>
 #include <swmodeltestbase.hxx>
 #include <test/mtfxmldump.hxx>
+#include <pagefrm.hxx>
+#include <bodyfrm.hxx>
+#include <sortedobjs.hxx>
+#include <anchoredobject.hxx>
+#include <ndtxt.hxx>
+#include <wrtsh.hxx>
+#include <txtfrm.hxx>
 
 static char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/";
 
@@ -25,6 +32,7 @@ public:
     void testTdf117188();
     void testTdf119875();
     void testTdf123651();
+    void testImageComment();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testTdf116830);
@@ -35,6 +43,7 @@ public:
     CPPUNIT_TEST(testTdf117188);
     CPPUNIT_TEST(testTdf119875);
     CPPUNIT_TEST(testTdf123651);
+    CPPUNIT_TEST(testImageComment);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -182,6 +191,41 @@ void SwLayoutWriter::testTdf123651()
     assertXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds", "top", "7639");
 }
 
+void SwLayoutWriter::testImageComment()
+{
+    // Load a document that has "aaa" in it, then a commented image (4th char is the as-char image,
+    // 5th char is the comment anchor).
+    SwDoc* pDoc = createDoc("image-comment.odt");
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+
+    // Look up a layout position which is on the right of the image.
+    SwRootFrame* pRoot = pWrtShell->GetLayout();
+    CPPUNIT_ASSERT(pRoot->GetLower()->IsPageFrame());
+    SwPageFrame* pPage = static_cast<SwPageFrame*>(pRoot->GetLower());
+    CPPUNIT_ASSERT(pPage->GetLower()->IsBodyFrame());
+    SwBodyFrame* pBody = static_cast<SwBodyFrame*>(pPage->GetLower());
+    CPPUNIT_ASSERT(pBody->GetLower()->IsTextFrame());
+    SwTextFrame* pTextFrame = static_cast<SwTextFrame*>(pBody->GetLower());
+    CPPUNIT_ASSERT(pTextFrame->GetDrawObjs());
+    SwSortedObjs& rDrawObjs = *pTextFrame->GetDrawObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rDrawObjs.size());
+    SwAnchoredObject* pDrawObj = rDrawObjs[0];
+    const SwRect& rDrawObjRect = pDrawObj->GetObjRect();
+    Point aPoint = rDrawObjRect.Center();
+    aPoint.setX(aPoint.getX() + rDrawObjRect.Width() / 2);
+
+    // Ask for the doc model pos of this layout point.
+    SwPosition aPosition(*pTextFrame->GetTextNode());
+    pTextFrame->GetCursorOfst(&aPosition, aPoint);
+
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 5
+    // - Actual  : 4
+    // i.e. the cursor got positioned between the image and its comment, so typing extended the
+    // comment, instead of adding content after the commented image.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aPosition.nContent.GetIndex());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/text/itrcrsr.cxx b/sw/source/core/text/itrcrsr.cxx
index 373350c2f6d1..d4a64de77d45 100644
--- a/sw/source/core/text/itrcrsr.cxx
+++ b/sw/source/core/text/itrcrsr.cxx
@@ -1246,6 +1246,27 @@ bool SwTextCursor::GetCharRect( SwRect* pOrig, const sal_Int32 nOfst,
     return true;
 }
 
+/**
+ * Determines if SwTextCursor::GetCursorOfst() should consider the next portion when calculating the
+ * doc model position from a Point.
+ */
+static bool ConsiderNextPortionForCursorOffset(SwLinePortion* pPor, sal_uInt16 nWidth30, sal_uInt16 nX)
+{
+    if (!pPor->GetPortion())
+    {
+        return false;
+    }
+
+    // If we're poast the target position, stop the iteration in general.
+    // Exception: don't stop the iteration between as-char fly portions and their comments.
+    if (nWidth30 >= nX && (!pPor->IsFlyCntPortion() || !pPor->GetPortion()->IsPostItsPortion()))
+    {
+        return false;
+    }
+
+    return !pPor->IsBreakPortion();
+}
+
 // Return: Offset in String
 sal_Int32 SwTextCursor::GetCursorOfst( SwPosition *pPos, const Point &rPoint,
                                     bool bChgNode, SwCursorMoveState* pCMS ) const
@@ -1333,7 +1354,7 @@ sal_Int32 SwTextCursor::GetCursorOfst( SwPosition *pPos, const Point &rPoint,
                      30 :
                      nWidth;
 
-    while( pPor->GetPortion() && nWidth30 < nX && !pPor->IsBreakPortion() )
+    while (ConsiderNextPortionForCursorOffset(pPor, nWidth30, nX))
     {
         nX = nX - nWidth;
         nCurrStart = nCurrStart + pPor->GetLen();
@@ -1507,7 +1528,14 @@ sal_Int32 SwTextCursor::GetCursorOfst( SwPosition *pPos, const Point &rPoint,
         {
             if ( pPor->IsPostItsPortion() || pPor->IsBreakPortion() ||
                  pPor->InToxRefGrp() )
+            {
+                if (pPor->IsPostItsPortion())
+                {
+                    // Offset would be nCurrStart + nLength below, do the same for post-it portions.
+                    nCurrStart += pPor->GetLen();
+                }
                 return nCurrStart;
+            }
             if ( pPor->InFieldGrp() )
             {
                 if( bRightOver && !static_cast<SwFieldPortion*>(pPor)->HasFollow() )


More information about the Libreoffice-commits mailing list