From 106cd072747a48ba064d8522cc15f581abffab51 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 14 Sep 2016 19:47:47 +0200 Subject: 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) --- desktop/qa/data/2slides.odp | Bin 0 -> 10888 bytes desktop/qa/desktop_lib/test_desktop_lib.cxx | 74 ++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 desktop/qa/data/2slides.odp (limited to 'desktop/qa') diff --git a/desktop/qa/data/2slides.odp b/desktop/qa/data/2slides.odp new file mode 100644 index 000000000000..8be376f5b548 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 5485da30cb67..a6c256ddde09 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 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(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(); -- cgit v1.2.3