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

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


 sw/qa/extras/tiledrendering/data/image-comment.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx     |   47 +++++++++++++++++++++
 sw/source/uibase/docvw/PostItMgr.cxx               |   22 ++++++++-
 3 files changed, 67 insertions(+), 2 deletions(-)

New commits:
commit d2f4a7518946ac195505308e74f411c25a459fcc
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Aug 2 12:31:00 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Aug 2 19:04:40 2019 +0200

    sw comments on frames: no overlay in the LOK API, either: insert case
    
    This is similar to commit 28fcb7d86765194b4015e7023449333f43aba0c5 (sw
    comments on frames: no overlay in the LOK API, either, 2019-07-16), but
    that one handled the initial fetch of comment states, while this one
    does the incremental updates.
    
    With this, there is no overlay on commented images right after inserting
    them.
    
    (cherry picked from commit 225930119543975697d3f5f042e271f0ec6c6b15)
    
    [ cp-6.2 backport note: added explicit IsEmpty() check, otherwise we
    would expose negative width/height for empty rectangles via LOK, which
    doesn't happen on master. ]
    
    [ cp-6.2 backport note: use the comphelper::dispatchCommand() variant
    that takes no explicit frames, the default frame seems to working here
    and we can't be explicit on this branch. ]
    
    Change-Id: I060303806a6611b113b4813300ed1cafd0b654fa
    Reviewed-on: https://gerrit.libreoffice.org/76880
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/tiledrendering/data/image-comment.odt b/sw/qa/extras/tiledrendering/data/image-comment.odt
new file mode 100644
index 000000000000..0852bedabf7f
Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/image-comment.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 9b2984b7af9f..701c135a579e 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -98,6 +98,7 @@ public:
     void testCreateViewTextSelection();
     void testRedlineColors();
     void testCommentEndTextEdit();
+    void testCommentInsert();
     void testCursorPosition();
     void testPaintCallbacks();
     void testUndoRepairResult();
@@ -156,6 +157,7 @@ public:
     CPPUNIT_TEST(testCreateViewTextSelection);
     CPPUNIT_TEST(testRedlineColors);
     CPPUNIT_TEST(testCommentEndTextEdit);
+    CPPUNIT_TEST(testCommentInsert);
     CPPUNIT_TEST(testCursorPosition);
     CPPUNIT_TEST(testPaintCallbacks);
     CPPUNIT_TEST(testUndoRepairResult);
@@ -727,6 +729,8 @@ public:
     boost::property_tree::ptree m_aRedlineTableChanged;
     /// Redline table modified payload
     boost::property_tree::ptree m_aRedlineTableModified;
+    /// Post-it / annotation payload.
+    boost::property_tree::ptree m_aComment;
 
     ViewCallback()
         : m_bOwnCursorInvalidated(false),
@@ -861,6 +865,14 @@ public:
             m_aRedlineTableModified = m_aRedlineTableModified.get_child("redline");
         }
         break;
+        case LOK_CALLBACK_COMMENT:
+        {
+            m_aComment.clear();
+            std::stringstream aStream(pPayload);
+            boost::property_tree::read_json(aStream, m_aComment);
+            m_aComment = m_aComment.get_child("comment");
+        }
+        break;
         }
     }
 };
@@ -1721,6 +1733,41 @@ void SwTiledRenderingTest::testCommentEndTextEdit()
     CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
 }
 
+void SwTiledRenderingTest::testCommentInsert()
+{
+    // Load a document with an as-char image in it.
+    comphelper::LibreOfficeKit::setActive();
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+    SwXTextDocument* pXTextDocument = createDoc("image-comment.odt");
+    SwDoc* pDoc = pXTextDocument->GetDocShell()->GetDoc();
+    SwView* pView = pDoc->GetDocShell()->GetView();
+
+    // Select the image.
+    pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
+    // Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the
+    // SwView ctor.
+    pView->StopShellTimer();
+
+    // Add a comment.
+    uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence(
+    {
+        {"Text", uno::makeAny(OUString("some text"))},
+        {"Author", uno::makeAny(OUString("me"))},
+    });
+    ViewCallback aView;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView);
+    comphelper::dispatchCommand(".uno:InsertAnnotation", aPropertyValues);
+    Scheduler::ProcessEventsToIdle();
+    OString aAnchorPos(aView.m_aComment.get_child("anchorPos").get_value<std::string>().c_str());
+    // Without the accompanying fix in place, this test would have failed with
+    // - Expected: 1418, 1418, 0, 0
+    // - Actual  : 1418, 1418, 1024, 1024
+    // i.e. the anchor position was a non-empty rectangle.
+    CPPUNIT_ASSERT_EQUAL(OString("1418, 1418, 0, 0"), aAnchorPos);
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
+}
+
 void SwTiledRenderingTest::testCursorPosition()
 {
     // Load a document and register a callback, should get an own cursor.
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index 473978dd1689..74599af05b2f 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -152,10 +152,17 @@ namespace {
 
             const SwPostItField* pField = pWin->GetPostItField();
             const SwRect& aRect = pWin->GetAnchorRect();
-            const tools::Rectangle aSVRect(aRect.Pos().getX(),
+            tools::Rectangle aSVRect(aRect.Pos().getX(),
                                     aRect.Pos().getY(),
                                     aRect.Pos().getX() + aRect.SSize().Width(),
                                     aRect.Pos().getY() + aRect.SSize().Height());
+
+            if (!pItem->maLayoutInfo.mPositionFromCommentAnchor)
+            {
+                // Comments on frames: anchor position is the corner position, not the whole frame.
+                aSVRect.SetSize(Size(0, 0));
+            }
+
             std::vector<OString> aRects;
             for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
             {
@@ -169,7 +176,18 @@ namespace {
             aAnnotation.put("author", pField->GetPar1().toUtf8().getStr());
             aAnnotation.put("text", pField->GetPar2().toUtf8().getStr());
             aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
-            aAnnotation.put("anchorPos", aSVRect.toString());
+            {
+                std::stringstream ss;
+                if (aSVRect.IsEmpty())
+                {
+                    ss << aSVRect.getX() << ", " << aSVRect.getY() << ", 0, 0";
+                }
+                else
+                {
+                    ss << aSVRect.getX() << ", " << aSVRect.getY() << ", " << aSVRect.getWidth() << ", " << aSVRect.getHeight();
+                }
+                aAnnotation.put("anchorPos", ss.str());
+            }
             aAnnotation.put("textRange", sRects.getStr());
         }
 


More information about the Libreoffice-commits mailing list