[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - 3 commits - desktop/qa desktop/source sd/qa sfx2/source svx/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Sep 14 17:52:06 UTC 2016


 desktop/qa/data/2slides.odp                  |binary
 desktop/qa/desktop_lib/test_desktop_lib.cxx  |   74 +++++++++++++++++++++++++++
 desktop/source/lib/init.cxx                  |   24 ++++++++
 sd/qa/unit/tiledrendering/tiledrendering.cxx |   69 +++++++++++++++++++++++++
 sfx2/source/view/lokhelper.cxx               |    6 --
 svx/source/svdraw/svdedxv.cxx                |    2 
 6 files changed, 171 insertions(+), 4 deletions(-)

New commits:
commit 106cd072747a48ba064d8522cc15f581abffab51
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 14 19:47:47 2016 +0200

    desktop lok: avoid unnecessary setPart() in paintPartTile()
    
    If possible, switch views, not parts, that way started Impress text
    edits don't end as a side-effect.
    
    Change-Id: I3f18d4dda6bc24235bf1219416f153248a867fa4
    (cherry picked from commit bee4ff508a456a1552aacdf6fc838b8b7cffb9ec)

diff --git a/desktop/qa/data/2slides.odp b/desktop/qa/data/2slides.odp
new file mode 100644
index 0000000..8be376f
Binary files /dev/null and b/desktop/qa/data/2slides.odp differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 5485da3..a6c256d 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -99,6 +99,7 @@ public:
     void testRedlineWriter();
     void testTrackChanges();
     void testRedlineCalc();
+    void testPaintPartTile();
 
     CPPUNIT_TEST_SUITE(DesktopLOKTest);
     CPPUNIT_TEST(testModifiedStatus);
@@ -129,6 +130,7 @@ public:
     CPPUNIT_TEST(testRedlineWriter);
     CPPUNIT_TEST(testTrackChanges);
     CPPUNIT_TEST(testRedlineCalc);
+    CPPUNIT_TEST(testPaintPartTile);
     CPPUNIT_TEST_SUITE_END();
 
     uno::Reference<lang::XComponent> mxComponent;
@@ -1241,6 +1243,78 @@ void DesktopLOKTest::testRedlineCalc()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+class ViewCallback
+{
+public:
+    bool m_bTilesInvalidated;
+
+    ViewCallback()
+        : m_bTilesInvalidated(false)
+    {
+    }
+
+    static void callback(int nType, const char* pPayload, void* pData)
+    {
+        static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
+    }
+
+    void callbackImpl(int nType, const char* /*pPayload*/)
+    {
+        switch (nType)
+        {
+        case LOK_CALLBACK_INVALIDATE_TILES:
+        {
+            m_bTilesInvalidated = true;
+        }
+        break;
+        }
+    }
+};
+
+void DesktopLOKTest::testPaintPartTile()
+{
+    // Load an impress doc of 2 slides.
+    comphelper::LibreOfficeKit::setActive();
+    LibLODocument_Impl* pDocument = loadDoc("2slides.odp");
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    ViewCallback aView1;
+    pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView1);
+    int nView1 = pDocument->m_pDocumentClass->getView(pDocument);
+
+    // Create a second view.
+    pDocument->m_pDocumentClass->createView(pDocument);
+    pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+    ViewCallback aView2;
+    pDocument->m_pDocumentClass->registerCallback(pDocument, &ViewCallback::callback, &aView2);
+
+    // Go to the second slide in the second view.
+    pDocument->m_pDocumentClass->setPart(pDocument, 1);
+
+    // Switch back to the first view and start typing.
+    pDocument->m_pDocumentClass->setView(pDocument, nView1);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'x', 0);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'x', 0);
+
+    // Call paintPartTile() to paint the second part (in whichever view it finds suitable for this).
+    unsigned char pPixels[256 * 256 * 4];
+    pDocument->m_pDocumentClass->paintPartTile(pDocument, pPixels, 1, 256, 256, 0, 0, 256, 256);
+
+    // Type again.
+    Scheduler::ProcessEventsToIdle();
+    aView1.m_bTilesInvalidated = false;
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, 'x', 0);
+    pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, 'x', 0);
+    Scheduler::ProcessEventsToIdle();
+    // This failed: paintPartTile() (as a side-effect) ended the text edit of
+    // the first view, so there were no invalidations.
+    CPPUNIT_ASSERT(aView1.m_bTilesInvalidated);
+
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setActive(false);
+}
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f678d69..582c52c 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1486,6 +1486,7 @@ void doc_paintPartTile(LibreOfficeKitDocument* pThis,
                        const int nTilePosX, const int nTilePosY,
                        const int nTileWidth, const int nTileHeight)
 {
+    SolarMutexGuard aGuard;
     SAL_INFO( "lok.tiledrendering", "paintPartTile: painting @ " << nPart << " ["
                << nTileWidth << "x" << nTileHeight << "]@("
                << nTilePosX << ", " << nTilePosY << ") to ["
@@ -1503,8 +1504,27 @@ void doc_paintPartTile(LibreOfficeKitDocument* pThis,
         // Text documents have a single coordinate system; don't change part.
         int nOrigPart = 0;
         const bool isText = (doc_getDocumentType(pThis) == LOK_DOCTYPE_TEXT);
+        int nOrigViewId = doc_getView(pThis);
+        int nViewId = nOrigViewId;
         if (!isText)
         {
+            // Check if just switching to an other view is enough, that has
+            // less side-effects.
+            if (nPart != doc_getPart(pThis))
+            {
+                SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+                while (pViewShell)
+                {
+                    if (pViewShell->getPart() == nPart)
+                    {
+                        nViewId = pViewShell->GetViewShellId();
+                        doc_setView(pThis, nViewId);
+                        break;
+                    }
+                    pViewShell = SfxViewShell::GetNext(*pViewShell);
+                }
+            }
+
             nOrigPart = doc_getPart(pThis);
             if (nPart != nOrigPart)
             {
@@ -1518,6 +1538,10 @@ void doc_paintPartTile(LibreOfficeKitDocument* pThis,
         {
             doc_setPart(pThis, nOrigPart);
         }
+        if (!isText && nViewId != nOrigViewId)
+        {
+            doc_setView(pThis, nOrigViewId);
+        }
     }
     catch (const std::exception&)
     {
commit 80fc0074689d657fbbf479da534f782bb9cc3cca
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 14 12:51:05 2016 +0200

    sd lok draw text: make sure watching views have no cursors
    
    These additional views are only created to follow the updates done in
    the editing view, not to contribute additional cursors.
    
    With this, if the first view edits a shape text and the second view is
    created, then no unwanted text view cursor is created in the first view
    for the shape text from the second view.
    
    Be precise in the unit test and make sure that cursors from all views
    are hidden, because even without a fix the cursor of view #2 is hidden,
    but not from view #3, so the test wouldn't fail without the fix. (But
    hardcoding the 0-1 and 2-3 view IDs exposed by Impress before/after
    initializeForRendering() would be ugly.)
    
    Change-Id: Idf64f7bfcc35c98a5eada9a0a523a9b45b65a211
    (cherry picked from commit eefccb4a103729e73ba7dcb512c615bc161d7b2b)

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index e9208a7..38c79b4 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -71,6 +71,7 @@ public:
     void testViewLock();
     void testUndoLimiting();
     void testCreateViewGraphicSelection();
+    void testCreateViewTextCursor();
 
     CPPUNIT_TEST_SUITE(SdTiledRenderingTest);
     CPPUNIT_TEST(testRegisterCallback);
@@ -97,6 +98,7 @@ public:
     CPPUNIT_TEST(testViewLock);
     CPPUNIT_TEST(testUndoLimiting);
     CPPUNIT_TEST(testCreateViewGraphicSelection);
+    CPPUNIT_TEST(testCreateViewTextCursor);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -866,6 +868,8 @@ public:
     bool m_bCursorVisibleChanged;
     bool m_bViewLock;
     bool m_bTilesInvalidated;
+    std::map<int, bool> m_aViewCursorInvalidations;
+    std::map<int, bool> m_aViewCursorVisibilities;
 
     ViewCallback()
         : m_bGraphicSelectionInvalidated(false),
@@ -919,6 +923,24 @@ public:
             m_bViewLock = aTree.get_child("rectangle").get_value<std::string>() != "EMPTY";
         }
         break;
+        case LOK_CALLBACK_INVALIDATE_VIEW_CURSOR:
+        {
+            std::stringstream aStream(pPayload);
+            boost::property_tree::ptree aTree;
+            boost::property_tree::read_json(aStream, aTree);
+            int nViewId = aTree.get_child("viewId").get_value<int>();
+            m_aViewCursorInvalidations[nViewId] = true;
+        }
+        break;
+        case LOK_CALLBACK_VIEW_CURSOR_VISIBLE:
+        {
+            std::stringstream aStream(pPayload);
+            boost::property_tree::ptree aTree;
+            boost::property_tree::read_json(aStream, aTree);
+            int nViewId = aTree.get_child("viewId").get_value<int>();
+            m_aViewCursorVisibilities[nViewId] = OString("true") == pPayload;
+        }
+        break;
         }
     }
 };
@@ -1148,6 +1170,53 @@ void SdTiledRenderingTest::testCreateViewGraphicSelection()
     comphelper::LibreOfficeKit::setActive(false);
 }
 
+void SdTiledRenderingTest::testCreateViewTextCursor()
+{
+    comphelper::LibreOfficeKit::setActive();
+
+    // Load a document and register a callback.
+    SdXImpressDocument* pXImpressDocument = createDoc("title-shape.odp");
+    ViewCallback aView1;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
+
+    // Begin text edit.
+    pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::TAB);
+    pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::TAB);
+    pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
+    pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
+    Scheduler::ProcessEventsToIdle();
+    sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+    SdrView* pSdrView = pViewShell->GetView();
+    CPPUNIT_ASSERT(pSdrView->IsTextEdit());
+
+    // Make sure that creating a new view either doesn't affect the previous
+    // one, or at least the effect is not visible at the end.
+    aView1.m_aViewCursorInvalidations.clear();
+    aView1.m_aViewCursorVisibilities.clear();
+    SfxLokHelper::createView();
+    pXImpressDocument->initializeForTiledRendering({});
+    ViewCallback aView2;
+    SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
+    bool bFoundCursor = false;
+    for (const auto& rInvalidation : aView1.m_aViewCursorInvalidations)
+    {
+        auto itVisibility = aView1.m_aViewCursorVisibilities.find(rInvalidation.first);
+        // For each cursor invalidation: if there is no visibility or the visibility is true, that's a problem.
+        if (itVisibility == aView1.m_aViewCursorVisibilities.end() || (itVisibility != aView1.m_aViewCursorVisibilities.end() && itVisibility->second))
+        {
+            bFoundCursor = true;
+            break;
+        }
+    }
+    // This failed: the second view created an unexpected view cursor in the
+    // first view.
+    CPPUNIT_ASSERT(!bFoundCursor);
+
+    mxComponent->dispose();
+    mxComponent.clear();
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index 8960aee..eca77ec 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -159,6 +159,7 @@ SdrPageView* SdrObjEditView::ShowSdrPage(SdrPage* pPage)
             // registers the view shell of this draw view, and not the view
             // shell of pView.
             OutlinerView* pOutlinerView = pView->ImpMakeOutlinerView(static_cast<vcl::Window*>(pOutDev), !bEmpty, nullptr, GetSfxViewShell());
+            pOutlinerView->HideCursor();
             pView->GetTextEditOutliner()->InsertView(pOutlinerView);
         }
     }
@@ -912,6 +913,7 @@ bool SdrObjEditView::SdrBeginTextEdit(
                             if(&rOutDev != pWin && OUTDEV_WINDOW == rOutDev.GetOutDevType())
                             {
                                 OutlinerView* pOutlView = ImpMakeOutlinerView(static_cast<vcl::Window*>(&rOutDev), !bEmpty, nullptr);
+                                pOutlView->HideCursor();
                                 pTextEditOutliner->InsertView(pOutlView);
                             }
                         }
commit 5f81b7a3a2db50b1ead2b07f86be94613b781c67
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 14 09:12:44 2016 +0200

    sfx2: use range-based for loop in lokhelper
    
    Change-Id: I7c3421231dd74c8d1e2678a6aee92288fdd3221a
    (cherry picked from commit ecc29bf323a83b0379ffed31057c8ab409e0d2d2)

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 0e7af55..59cdb83 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -36,9 +36,8 @@ void SfxLokHelper::destroyView(int nId)
     unsigned nViewShellId = nId;
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
 
-    for (std::size_t i = 0; i < rViewArr.size(); ++i)
+    for (SfxViewShell* pViewShell : rViewArr)
     {
-        SfxViewShell* pViewShell = rViewArr[i];
         if (pViewShell->GetViewShellId() == nViewShellId)
         {
             SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
@@ -54,9 +53,8 @@ void SfxLokHelper::setView(int nId)
     unsigned nViewShellId = nId;
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
 
-    for (std::size_t i = 0; i < rViewArr.size(); ++i)
+    for (SfxViewShell* pViewShell : rViewArr)
     {
-        SfxViewShell* pViewShell = rViewArr[i];
         if (pViewShell->GetViewShellId() == nViewShellId)
         {
             if (pViewShell == SfxViewShell::Current())


More information about the Libreoffice-commits mailing list