sw/qa/extras/tiledrendering/data/image-comment.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 48 +++++++++++++++++++++ sw/source/uibase/docvw/PostItMgr.cxx | 22 ++++++++- 3 files changed, 68 insertions(+), 2 deletions(-)
New commits: commit 5e2977d3a93a2145333102e91e490ec9226aa519 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Aug 2 12:31:00 2019 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Aug 2 17:36:22 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. ] Change-Id: I060303806a6611b113b4813300ed1cafd0b654fa Reviewed-on: https://gerrit.libreoffice.org/76869 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@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 04069f6f904b..3605ede97e71 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -95,6 +95,7 @@ public: void testCreateViewTextSelection(); void testRedlineColors(); void testCommentEndTextEdit(); + void testCommentInsert(); void testCursorPosition(); void testPaintCallbacks(); void testUndoRepairResult(); @@ -152,6 +153,7 @@ public: CPPUNIT_TEST(testCreateViewTextSelection); CPPUNIT_TEST(testRedlineColors); CPPUNIT_TEST(testCommentEndTextEdit); + CPPUNIT_TEST(testCommentInsert); CPPUNIT_TEST(testCursorPosition); CPPUNIT_TEST(testPaintCallbacks); CPPUNIT_TEST(testUndoRepairResult); @@ -702,6 +704,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), @@ -836,6 +840,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; } } }; @@ -1673,6 +1685,42 @@ void SwTiledRenderingTest::testCommentEndTextEdit() comphelper::LibreOfficeKit::setActive(false); } +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::Reference<frame::XFrame> xFrame = pView->GetViewFrame()->GetFrame().GetFrameInterface(); + 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", xFrame, 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 c15d9c0bd8e4..797684d0f4d0 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -154,10 +154,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()) { @@ -171,7 +178,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()); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits