From ee70ca8d539e4849aae82ac14ecf09cfb96a990e Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Mon, 5 Mar 2018 08:50:34 +0100 Subject: bccu#3100: Writer: Change tracking boxes aren't repositioned with editing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emit a notification related to the node position change, so the track changes comment box is repositioned when the text node changes it's position. Reviewed-on: https://gerrit.libreoffice.org/50640 Tested-by: Jenkins Reviewed-by: Tamás Zolnai (cherry picked from commit b687cebfb1488341853824de1a15c06175c94258) Change-Id: I34b5ec453b3dc43895865f15d71aaead46ae6f24 Reviewed-on: https://gerrit.libreoffice.org/50766 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky --- sw/inc/redline.hxx | 5 + .../data/removenode_redline_callback.fodt | 306 +++++++++++++++++++++ .../data/splitnode_redline_callback.fodt | 294 ++++++++++++++++++++ sw/qa/extras/tiledrendering/tiledrendering.cxx | 126 +++++++++ sw/source/core/doc/docredln.cxx | 12 + sw/source/core/inc/frame.hxx | 2 +- sw/source/core/inc/txtfrm.hxx | 2 + sw/source/core/text/frmform.cxx | 21 ++ 8 files changed, 767 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/tiledrendering/data/removenode_redline_callback.fodt create mode 100644 sw/qa/extras/tiledrendering/data/splitnode_redline_callback.fodt diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx index dae29e6e7e7f..3414415bb9d8 100644 --- a/sw/inc/redline.hxx +++ b/sw/inc/redline.hxx @@ -28,6 +28,7 @@ #include #include +#include class SfxItemSet; class SwView; @@ -173,6 +174,8 @@ class SW_DLLPUBLIC SwRangeRedline : public SwPaM bool bIsVisible : 1; sal_uInt32 m_nId; + boost::optional m_oLOKLastNodeTop; + void MoveToSection(); void CopyToSection(); void DelCopyOfSection(size_t nMyPos); @@ -271,6 +274,8 @@ public: bool operator<( const SwRangeRedline& ) const; void dumpAsXml(struct _xmlTextWriter* pWriter) const; + + void MaybeNotifyRedlinePositionModification(long nTop); }; SW_DLLPUBLIC void MaybeNotifyRedlineModification(SwRangeRedline* pRedline, SwDoc* pDoc); diff --git a/sw/qa/extras/tiledrendering/data/removenode_redline_callback.fodt b/sw/qa/extras/tiledrendering/data/removenode_redline_callback.fodt new file mode 100644 index 000000000000..ed06348cc423 --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/removenode_redline_callback.fodt @@ -0,0 +1,306 @@ + + + + 2016-05-17T06:56:18.472497792LibreOfficeDev/6.1.0.0.alpha0$Linux_X86_64 LibreOffice_project/8b89db9127aaac53e19b884c3d546be4127ee38ePT1H57M33S322018-03-05T02:20:39.602490321 + + + 0 + 0 + 32228 + 20348 + true + false + + + view2 + 7613 + 5962 + 0 + 0 + 32226 + 20346 + 0 + 1 + false + 100 + false + false + + + + + false + true + true + true + true + 0 + true + + false + false + true + false + false + false + false + false + false + false + false + false + false + true + true + false + false + true + 24907 + false + + false + true + false + false + + false + false + false + false + true + 1961503 + false + true + true + false + true + true + false + 0 + false + high-resolution + false + true + false + false + false + true + false + false + true + false + false + true + true + true + + true + false + false + true + false + false + false + + false + false + false + 1 + true + false + false + 0 + false + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Aron Budea + 2018-02-23T13:32:12 + + + + + + + Aron Budea + 2018-02-23T13:32:15 + + + + + + + + + + + + + + + abcd + + + + + + + + + + + + + + abcd + + + + + \ No newline at end of file diff --git a/sw/qa/extras/tiledrendering/data/splitnode_redline_callback.fodt b/sw/qa/extras/tiledrendering/data/splitnode_redline_callback.fodt new file mode 100644 index 000000000000..bffc3a42c9dd --- /dev/null +++ b/sw/qa/extras/tiledrendering/data/splitnode_redline_callback.fodt @@ -0,0 +1,294 @@ + + + + 2016-05-17T06:56:18.472497792LibreOfficeDev/6.1.0.0.alpha0$Linux_X86_64 LibreOffice_project/d64ce643275e0b2b0dea9e532fc261391dc8793cPT1H57M11S312018-03-01T05:44:45.452664252 + + + 0 + 0 + 32228 + 20348 + true + false + + + view2 + 7613 + 8846 + 0 + 0 + 32226 + 20346 + 0 + 1 + false + 100 + false + false + + + + + false + true + true + true + true + 0 + true + + false + false + true + false + false + false + false + false + false + false + false + false + false + true + true + false + false + true + 24907 + false + + false + true + false + false + + false + false + false + false + true + 1952207 + false + true + true + false + true + true + false + 0 + false + high-resolution + false + true + false + false + false + true + false + false + true + false + false + true + true + true + + true + false + false + true + false + false + false + + false + false + false + 1 + true + false + false + 0 + false + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Aron Budea + 2018-02-23T13:32:12 + + + + + + + Aron Budea + 2018-02-23T13:32:15 + + + + + + + + + + + + + abcd + + + + + + + abcd + + + + + \ No newline at end of file diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index b437016afb5f..338dd302620d 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -97,6 +97,8 @@ public: void testPageFooter(); void testRedlineField(); void testIMESupport(); + void testSplitNodeRedlineCallback(); + void testDeleteNodeRedlineCallback(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -148,6 +150,8 @@ public: CPPUNIT_TEST(testPageFooter); CPPUNIT_TEST(testRedlineField); CPPUNIT_TEST(testIMESupport); + CPPUNIT_TEST(testSplitNodeRedlineCallback); + CPPUNIT_TEST(testDeleteNodeRedlineCallback); CPPUNIT_TEST_SUITE_END(); private: @@ -2097,6 +2101,128 @@ void SwTiledRenderingTest::testIMESupport() comphelper::LibreOfficeKit::setActive(false); } +void SwTiledRenderingTest::testSplitNodeRedlineCallback() +{ + // Load a document. + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("splitnode_redline_callback.fodt"); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this); + + // 1. test case + // Move cursor between the two tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + Scheduler::ProcessEventsToIdle(); + + // Add a new line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN); + Scheduler::ProcessEventsToIdle(); + + // Assert that we get a notification about redline modification + // The redline after the inserted node gets a different vertical positon + CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified); + + // 2. test case + // Move cursor back to the first line, so adding new line will affect both tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1); + Scheduler::ProcessEventsToIdle(); + + // Add a new line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(2, m_nRedlineTableEntryModified); + + // 3. test case + // Move cursor to the end of the document, so adding a new line won't affect any tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_END | KEY_MOD1); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_END | KEY_MOD1); + Scheduler::ProcessEventsToIdle(); + + // Add a new line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RETURN); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(0, m_nRedlineTableEntryModified); + + comphelper::LibreOfficeKit::setActive(false); +} + +void SwTiledRenderingTest::testDeleteNodeRedlineCallback() +{ + // Load a document. + comphelper::LibreOfficeKit::setActive(); + SwXTextDocument* pXTextDocument = createDoc("removenode_redline_callback.fodt"); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&SwTiledRenderingTest::callback, this); + + // 1. test case + // Move cursor between the two tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN); + Scheduler::ProcessEventsToIdle(); + + // Remove one (empty) line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE); + Scheduler::ProcessEventsToIdle(); + + // Assert that we get a notification about redline modification + // The redline after the removed node gets a different vertical positon + CPPUNIT_ASSERT_EQUAL(1, m_nRedlineTableEntryModified); + + // 2. test case + // Move cursor back to the first line, so removing one line will affect both tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1); + Scheduler::ProcessEventsToIdle(); + + // Remove a new line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(2, m_nRedlineTableEntryModified); + + // 3. test case + // Move cursor to the end of the document, so removing one line won't affect any tracked changes + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_END | KEY_MOD1); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_END | KEY_MOD1); + Scheduler::ProcessEventsToIdle(); + + // Remove a line + m_nRedlineTableEntryModified = 0; + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_BACKSPACE); + pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_BACKSPACE); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(0, m_nRedlineTableEntryModified); + + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 2d24fe55fdbd..cc268b235748 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -1074,6 +1074,18 @@ void MaybeNotifyRedlineModification(SwRangeRedline* pRedline, SwDoc* pDoc) } } +void SwRangeRedline::MaybeNotifyRedlinePositionModification(long nTop) +{ + if (!comphelper::LibreOfficeKit::isActive()) + return; + + if(!m_oLOKLastNodeTop || *m_oLOKLastNodeTop != nTop) + { + m_oLOKLastNodeTop = nTop; + SwRedlineTable::LOKRedlineNotification(RedlineNotification::Modify, this); + } +} + void SwRangeRedline::SetStart( const SwPosition& rPos, SwPosition* pSttPtr ) { if( !pSttPtr ) pSttPtr = Start(); diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx index c4d132890e66..5a8302aa9fcd 100644 --- a/sw/source/core/inc/frame.hxx +++ b/sw/source/core/inc/frame.hxx @@ -277,7 +277,7 @@ protected: SwPageFrame *InsertPage( SwPageFrame *pSibling, bool bFootnote ); void PrepareMake(vcl::RenderContext* pRenderContext); void OptPrepareMake(); - void MakePos(); + virtual void MakePos(); // Format next frame of table frame to assure keeping attributes. // In case of nested tables method is called to // avoid formatting of superior table frame. diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index 811800edd5f2..4bf8c6d59a6a 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -148,6 +148,8 @@ class SwTextFrame: public SwContentFrame // Formats the Follow and ensures disposing on orphans bool CalcFollow( const sal_Int32 nTextOfst ); + virtual void MakePos() override; + // Corrects the position from which we need to format static sal_Int32 FindBrk(const OUString &rText, const sal_Int32 nStart, const sal_Int32 nEnd); diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx index e25792532a13..a0c92ebd4550 100644 --- a/sw/source/core/text/frmform.cxx +++ b/sw/source/core/text/frmform.cxx @@ -52,6 +52,8 @@ #include #include #include +#include +#include // Tolerance in formatting and text output #define SLOPPY_TWIPS 5 @@ -341,6 +343,25 @@ bool SwTextFrame::CalcFollow( const sal_Int32 nTextOfst ) return false; } +void SwTextFrame::MakePos() +{ + SwFrame::MakePos(); + // Inform LOK clients about change in position of redlines (if any) + if(comphelper::LibreOfficeKit::isActive()) + { + const SwTextNode& rTextNode = *GetTextNode(); + const SwRedlineTable& rTable = rTextNode.getIDocumentRedlineAccess().GetRedlineTable(); + for (SwRedlineTable::size_type nRedlnPos = 0; nRedlnPos < rTable.size(); ++nRedlnPos) + { + SwRangeRedline* pRedln = rTable[nRedlnPos]; + if (rTextNode.GetIndex() == pRedln->GetPoint()->nNode.GetNode().GetIndex()) + { + pRedln->MaybeNotifyRedlinePositionModification(Frame().Top()); + } + } + } +} + void SwTextFrame::AdjustFrame( const SwTwips nChgHght, bool bHasToFit ) { vcl::RenderContext* pRenderContext = getRootFrame()->GetCurrShell()->GetOut(); -- cgit