[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 5 commits - desktop/qa sc/qa sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Sep 27 08:24:40 UTC 2016


 desktop/qa/desktop_lib/test_desktop_lib.cxx  |   48 ++++++++++++++++++++++++++-
 sc/qa/unit/tiledrendering/tiledrendering.cxx |    4 +-
 sw/qa/extras/uiwriter/uiwriter.cxx           |   25 ++++++++++++++
 sw/source/core/crsr/viscrs.cxx               |   10 +++++
 sw/source/core/txtnode/ndtxt.cxx             |   26 ++++++++++++++
 5 files changed, 109 insertions(+), 4 deletions(-)

New commits:
commit 69e7adc64ae3834213896f73c286848b1108d32a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 26 17:51:17 2016 +0200

    CppunitTest_sw_uiwriter: avoid SfxLokHelper
    
    It assumes that the process has only a single document opened
    (createView() creates a new window on the frame returned by
    SfxViewFrame::First()), while it's possible that in this test an other
    testcase forgot to dispose its component.
    
    This way testCursorWindows() depends less on other testcases, and
    ideally all testcases should be entirely independent of each other.
    
    Reviewed-on: https://gerrit.libreoffice.org/29300
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit c8968b12f9ae88f592d8a8d17cdecfae8aa8722e)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    
    Change-Id: I35decb0b69aeebd3984f4da4386c696a63fe3e04

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index cb55d49..208efa4 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -88,7 +88,8 @@
 #include <comphelper/propertysequence.hxx>
 #include <sfx2/classificationhelper.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
-#include <sfx2/lokhelper.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/dispatch.hxx>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
 
@@ -3408,7 +3409,7 @@ void SwUiWriterTest::testCursorWindows()
     SwWrtShell* pWrtShell1 = pDocShell->GetWrtShell();
 
     // Create a second view and type something.
-    SfxLokHelper::createView();
+    pDocShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute(SID_NEWWINDOW, SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
     SwWrtShell* pWrtShell2 = pDocShell->GetWrtShell();
     OUString aText("foo");
     pWrtShell2->Insert(aText);
commit c102627a72d1650a19affd20b76ae74bb1b13de4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 26 14:31:54 2016 +0200

    CppunitTest_sw_rtfimport: fix ASan/UBSan build failure
    
    pDocShell->GetWrtShell() can be nullptr, even if pDocShell is not.
    
    (cherry picked from commit 56cda453daf71a368f316cb559e3e1f529e1c4fa)
    
    Conflicts:
    	sw/source/core/txtnode/ndtxt.cxx
    
    Change-Id: I2d60475abe545c2dbb13ede74d2d65432a3c93a7

diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index e4eaef8..22f9ef3 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1165,21 +1165,24 @@ void SwTextNode::Update(
         // The cursors of other shells shouldn't be moved, either.
         if (SwDocShell* pDocShell = GetDoc()->GetDocShell())
         {
-            for (SwViewShell& rShell : pDocShell->GetWrtShell()->GetRingContainer())
+            if (pDocShell->GetWrtShell())
             {
-                auto pWrtShell = dynamic_cast<SwWrtShell*>(&rShell);
-                if (!pWrtShell || pWrtShell == pDocShell->GetWrtShell())
-                    continue;
+                for (SwViewShell& rShell : pDocShell->GetWrtShell()->GetRingContainer())
+                {
+                    auto pWrtShell = dynamic_cast<SwWrtShell*>(&rShell);
+                    if (!pWrtShell || pWrtShell == pDocShell->GetWrtShell())
+                        continue;
 
-                SwShellCursor* pCursor = pWrtShell->_GetCursor();
-                if (!pCursor)
-                    continue;
+                    SwShellCursor* pCursor = pWrtShell->_GetCursor();
+                    if (!pCursor)
+                        continue;
 
-                SwIndex& rIndex = const_cast<SwIndex&>(pCursor->Start()->nContent);
-                if (&pCursor->Start()->nNode.GetNode() == this && rIndex.GetIndex() == rPos.GetIndex())
-                {
-                    // The cursor position of this other shell is exactly our insert position.
-                    rIndex.Assign(&aTmpIdxReg, rIndex.GetIndex());
+                    SwIndex& rIndex = const_cast<SwIndex&>(pCursor->Start()->nContent);
+                    if (&pCursor->Start()->nNode.GetNode() == this && rIndex.GetIndex() == rPos.GetIndex())
+                    {
+                        // The cursor position of this other shell is exactly our insert position.
+                        rIndex.Assign(&aTmpIdxReg, rIndex.GetIndex());
+                    }
                 }
             }
         }
commit 9eea58e8027fa8c17bbeaf43141d29db966c5d2a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 26 14:18:17 2016 +0200

    sw lok: fix cursor position after inserting a comment
    
    Make sure SwVisibleCursor::SetPosAndShow() doesn't emit LOK callbacks
    till a comment window is active.
    
    Need to invoke the unit test from desktop/, as the sw tests have the
    status bar disabled.
    
    (cherry picked from commit b9cc6653606c829805c6c01b9613a3a25d81c20b)
    
    Conflicts:
    	desktop/qa/desktop_lib/test_desktop_lib.cxx
    
    Change-Id: Iab26024e9bb4da9c939bbd6cf769ec5c4dcb9a19

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 0a2d823..b3d4461 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -33,6 +33,7 @@
 #include <sfx2/viewsh.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/bindings.hxx>
+#include <comphelper/string.hxx>
 
 #include <lib/init.hxx>
 
@@ -100,6 +101,7 @@ public:
     void testTrackChanges();
     void testRedlineCalc();
     void testPaintPartTile();
+    void testWriterCommentInsertCursor();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testModifiedStatus);
@@ -131,6 +133,7 @@ public:
     CPPUNIT_TEST(testTrackChanges);
     CPPUNIT_TEST(testRedlineCalc);
     CPPUNIT_TEST(testPaintPartTile);
+    CPPUNIT_TEST(testWriterCommentInsertCursor);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1253,6 +1256,7 @@ class ViewCallback
 {
 public:
     bool m_bTilesInvalidated;
+    Rectangle m_aOwnCursor;
 
     ViewCallback()
         : m_bTilesInvalidated(false)
@@ -1264,8 +1268,9 @@ public:
         static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
     }
 
-    void callbackImpl(int nType, const char* /*pPayload*/)
+    void callbackImpl(int nType, const char* pPayload)
     {
+        OString aPayload(pPayload);
         switch (nType)
         {
         case LOK_CALLBACK_INVALIDATE_TILES:
@@ -1273,6 +1278,18 @@ public:
             m_bTilesInvalidated = true;
         }
         break;
+        case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
+        {
+            uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::fromUtf8(aPayload));
+            if (OString("EMPTY") == pPayload)
+                return;
+            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength());
+            m_aOwnCursor.setX(aSeq[0].toInt32());
+            m_aOwnCursor.setY(aSeq[1].toInt32());
+            m_aOwnCursor.setWidth(aSeq[2].toInt32());
+            m_aOwnCursor.setHeight(aSeq[3].toInt32());
+        }
+        break;
         }
     }
 };
@@ -1321,6 +1338,35 @@ void DesktopLOKTest::testPaintPartTile()
     mxComponent.clear();
     comphelper::LibreOfficeKit::setActive(false);
 }
+
+void DesktopLOKTest::testWriterCommentInsertCursor()
+{
+    // Load a document and type a character into the body text.
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    ViewCallback aView1;
+    pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView1);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'x', 0);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'x', 0);
+    Scheduler::ProcessEventsToIdle();
+    Rectangle aBodyCursor = aView1.m_aOwnCursor;
+
+    // Now insert a comment and make sure that the comment's cursor is shown,
+    // not the body text's one.
+    const int nCtrlAltC = KEY_MOD1 + KEY_MOD2 + 512 + 'c' - 'a';
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'c', nCtrlAltC);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'c', nCtrlAltC);
+    Scheduler::ProcessEventsToIdle();
+    // Wait for SfxBindings to actually update the state, which updated the
+    // cursor as well.
+    osl::Thread::wait(std::chrono::seconds(1));
+    Scheduler::ProcessEventsToIdle();
+    // This failed: the body cursor was shown right after inserting a comment.
+    CPPUNIT_ASSERT(aView1.m_aOwnCursor.getX() > aBodyCursor.getX());
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 01c851d..19e3762 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -59,6 +59,7 @@
 #include <sfx2/lokhelper.hxx>
 #include <comphelper/string.hxx>
 #include <paintfrm.hxx>
+#include <PostItMgr.hxx>
 
 // Here static members are defined. They will get changed on alteration of the
 // MapMode. This is done so that on ShowCursor the same size does not have to be
@@ -182,7 +183,14 @@ void SwVisibleCursor::_SetPosAndShow(SfxViewShell* pViewShell)
 
     m_aTextCursor.SetPos( aRect.Pos() );
 
-    if (comphelper::LibreOfficeKit::isActive())
+    bool bPostItActive = false;
+    if (auto pView = dynamic_cast<SwView*>(m_pCursorShell->GetSfxViewShell()))
+    {
+        if (SwPostItMgr* pPostItMgr = pView->GetPostItMgr())
+            bPostItActive = pPostItMgr->GetActiveSidebarWin() != nullptr;
+    }
+
+    if (comphelper::LibreOfficeKit::isActive() && !bPostItActive)
     {
         // notify about page number change (if that happened)
         sal_uInt16 nPage, nVirtPage;
commit 1b7be810383f959a1278233ea70f45c0fc234408
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 26 10:46:55 2016 +0200

    CppunitTest_sc_tiledrendering: std::string::find -> OString::startsWith
    
    Change-Id: Ic7185cc0430e7007b1e4f27ba5c43d947405e198
    Reviewed-on: https://gerrit.libreoffice.org/29292
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit 5bc4bcfde4955e3e48255310500102775ba4af23)

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index be7e78d..25af056 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -418,8 +418,8 @@ public:
         break;
         case LOK_CALLBACK_INVALIDATE_TILES:
         {
-            std::string text(pPayload);
-            if (text.find("EMPTY") != std::string::npos)
+            OString text(pPayload);
+            if (text.startsWith("EMPTY"))
             {
                 m_bFullInvalidateTiles = true;
             }
commit 197d78c533307bd110e9b03fe94fb2f2d5240337
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 23 18:15:14 2016 +0200

    tdf#102384 sw: avoid moving cursors of other windows in SwTextNode::Update()
    
    There is a list of exceptional SwIndex containers in that member
    function, like bookmarks, at-char anchored fly frames, etc. If we're
    growing (so basically in the safe case), don't touch the cursors of
    other windows, either.
    
    This helps to avoid the surprising "I didn't do anything and my cursor
    moved" behavior.
    
    (cherry picked from commit ecdec24c035513dbf2ee1814eb437e2a9d9a3d6c)
    
    Conflicts:
    	sw/qa/extras/uiwriter/uiwriter.cxx
    	sw/source/core/txtnode/ndtxt.cxx
    
    Change-Id: I9941fdcb6b7ad4b6e18a321cecc72fdf73d917fd

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index f68d292..cb55d49 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -88,6 +88,7 @@
 #include <comphelper/propertysequence.hxx>
 #include <sfx2/classificationhelper.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <sfx2/lokhelper.hxx>
 
 static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";
 
@@ -191,6 +192,7 @@ public:
     void testRedlineParam();
     void testRedlineViewAuthor();
     void testRedlineTimestamp();
+    void testCursorWindows();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -287,6 +289,7 @@ public:
     CPPUNIT_TEST(testRedlineParam);
     CPPUNIT_TEST(testRedlineViewAuthor);
     CPPUNIT_TEST(testRedlineTimestamp);
+    CPPUNIT_TEST(testCursorWindows);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3397,6 +3400,27 @@ void SwUiWriterTest::testRedlineTimestamp()
     CPPUNIT_ASSERT(nSec1 != 0 || nSec2 != 0);
 }
 
+void SwUiWriterTest::testCursorWindows()
+{
+    // Create a new document with one window.
+    SwDoc* pDoc = createDoc();
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell1 = pDocShell->GetWrtShell();
+
+    // Create a second view and type something.
+    SfxLokHelper::createView();
+    SwWrtShell* pWrtShell2 = pDocShell->GetWrtShell();
+    OUString aText("foo");
+    pWrtShell2->Insert(aText);
+
+    // Assert that only the cursor of the actual window move, not other cursors.
+    SwShellCursor* pShellCursor1 = pWrtShell1->getShellCursor(false);
+    SwShellCursor* pShellCursor2 = pWrtShell2->getShellCursor(false);
+    // This was 3, not 0 -- cursor of the other window moved.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), pShellCursor1->Start()->nContent.GetIndex());
+    CPPUNIT_ASSERT_EQUAL(aText.getLength(), pShellCursor2->Start()->nContent.GetIndex());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index bf1711a..e4eaef8 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -86,6 +86,7 @@
 #include <calbck.hxx>
 #include <attrhint.hxx>
 #include <memory>
+#include <wrtsh.hxx>
 
 //UUUU
 #include <svx/sdr/attribute/sdrallfillattributeshelper.hxx>
@@ -1160,6 +1161,28 @@ void SwTextNode::Update(
 #if OSL_DEBUG_LEVEL > 0
         assert( checkFormats.empty());
 #endif
+
+        // The cursors of other shells shouldn't be moved, either.
+        if (SwDocShell* pDocShell = GetDoc()->GetDocShell())
+        {
+            for (SwViewShell& rShell : pDocShell->GetWrtShell()->GetRingContainer())
+            {
+                auto pWrtShell = dynamic_cast<SwWrtShell*>(&rShell);
+                if (!pWrtShell || pWrtShell == pDocShell->GetWrtShell())
+                    continue;
+
+                SwShellCursor* pCursor = pWrtShell->_GetCursor();
+                if (!pCursor)
+                    continue;
+
+                SwIndex& rIndex = const_cast<SwIndex&>(pCursor->Start()->nContent);
+                if (&pCursor->Start()->nNode.GetNode() == this && rIndex.GetIndex() == rPos.GetIndex())
+                {
+                    // The cursor position of this other shell is exactly our insert position.
+                    rIndex.Assign(&aTmpIdxReg, rIndex.GetIndex());
+                }
+            }
+        }
     }
 
     // base class


More information about the Libreoffice-commits mailing list