[Libreoffice-commits] core.git: sfx2/source sw/qa sw/source

2020-11-24 Thread Miklos Vajna (via logerrit)
 sfx2/source/view/viewsh.cxx |   14 -
 sw/qa/extras/tiledrendering/data/table-paint-invalidate.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx  |   33 
 sw/source/uibase/docvw/edtwin2.cxx  |   11 
 4 files changed, 56 insertions(+), 2 deletions(-)

New commits:
commit 0f65b4b6f33891a724bee5356aa5549c76fa0ce3
Author: Miklos Vajna 
AuthorDate: Tue Nov 24 17:26:32 2020 +0100
Commit: Miklos Vajna 
CommitDate: Tue Nov 24 23:05:13 2020 +0100

sw tiled rendering: fix paint->invalidation loop when paint is started by 
vcl

SwViewShell::PaintTile() already calls
comphelper::LibreOfficeKit::setTiledPainting(), so by the time it would
rearch SwViewShell::Paint(), callbacks (e.g. invalidations) are ignored
during paint.

Do the same for SwEditWin::Paint(), where we processed invalidations
during paint, potentially leading to paint->invalidation loops.

Change-Id: I8280f5c2571beeae6c0f2986d275dde3c2d33161
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106542
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index d35253d1342a..2da4bc1e81bd 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1463,8 +1463,18 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, 
const char* pPayload) c
 if (!comphelper::LibreOfficeKit::isActive())
 return;
 
-if (comphelper::LibreOfficeKit::isTiledPainting() && nType != 
LOK_CALLBACK_FORM_FIELD_BUTTON)
-return;
+if (comphelper::LibreOfficeKit::isTiledPainting())
+{
+switch (nType)
+{
+case LOK_CALLBACK_FORM_FIELD_BUTTON:
+case LOK_CALLBACK_TEXT_SELECTION:
+break;
+default:
+// Reject e.g. invalidate during paint.
+return;
+}
+}
 
 if (pImpl->m_bTiledSearching)
 {
diff --git a/sw/qa/extras/tiledrendering/data/table-paint-invalidate.odt 
b/sw/qa/extras/tiledrendering/data/table-paint-invalidate.odt
new file mode 100644
index ..b42c5cc51588
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/table-paint-invalidate.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index dc57ef1e451a..afb261b4d4bc 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -144,6 +144,7 @@ public:
 void testDropDownFormFieldButtonEditing();
 void testDropDownFormFieldButtonNoSelection();
 void testDropDownFormFieldButtonNoItem();
+void testTablePaintInvalidate();
 
 CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
 CPPUNIT_TEST(testRegisterCallback);
@@ -215,6 +216,7 @@ public:
 CPPUNIT_TEST(testDropDownFormFieldButtonEditing);
 CPPUNIT_TEST(testDropDownFormFieldButtonNoSelection);
 CPPUNIT_TEST(testDropDownFormFieldButtonNoItem);
+CPPUNIT_TEST(testTablePaintInvalidate);
 CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2836,6 +2838,37 @@ void 
SwTiledRenderingTest::testDropDownFormFieldButtonNoItem()
 }
 }
 
+void SwTiledRenderingTest::testTablePaintInvalidate()
+{
+// Load a document with a table in it.
+SwXTextDocument* pXTextDocument = createDoc("table-paint-invalidate.odt");
+SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+
pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(::callback,
 this);
+// Enter the table.
+pWrtShell->Down(/*bSelect=*/false);
+Scheduler::ProcessEventsToIdle();
+m_nInvalidations = 0;
+
+// Paint a tile.
+size_t nCanvasWidth = 256;
+size_t nCanvasHeight = 256;
+std::vector aPixmap(nCanvasWidth * nCanvasHeight * 4, 0);
+ScopedVclPtrInstance pDevice(DeviceFormat::DEFAULT);
+pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, 
nCanvasHeight),
+Fraction(1.0), Point(), 
aPixmap.data());
+pXTextDocument->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, 
m_aInvalidation.getX(),
+  m_aInvalidation.getY(), /*nTileWidth=*/1000,
+  /*nTileHeight=*/1000);
+Scheduler::ProcessEventsToIdle();
+
+// Without the accompanying fix in place, this test would have failed with
+// - Expected: 0
+// - Actual  : 5
+// i.e. paint generated an invalidation, which caused a loop.
+CPPUNIT_ASSERT_EQUAL(0, m_nInvalidations);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/docvw/edtwin2.cxx 
b/sw/source/uibase/docvw/edtwin2.cxx
index fb7f965838e2..ae168908de6f 100644
--- a/sw/source/uibase/docvw/edtwin2.cxx
+++ b/sw/source/uibase/docvw/edtwin2.cxx
@@ -51,6 +51,7 @@
 

[Libreoffice-commits] core.git: sfx2/source sw/qa sw/source

2020-11-18 Thread Miklos Vajna (via logerrit)
 sfx2/source/view/sfxbasecontroller.cxx|   12 +-
 sw/qa/uibase/uiview/data/update-replacement-nosetting.odt |binary
 sw/qa/uibase/uiview/uiview.cxx|   25 ++
 sw/source/uibase/uiview/view.cxx  |2 -
 4 files changed, 34 insertions(+), 5 deletions(-)

New commits:
commit 693f12ad57912c2356a197d9a794e6108ce79ef2
Author: Miklos Vajna 
AuthorDate: Wed Nov 18 17:55:13 2020 +0100
Commit: Miklos Vajna 
CommitDate: Thu Nov 19 01:37:50 2020 +0100

sw replacement image creation: fix this when an ODT's settings.xml is 
invalid

This builds on top of commit c123bfff501229f398a1b679fc7434b82d53685c
(Bin overly eager early return that stops replacement image creation,
2020-08-20), and handles a similar case, when
SwView::ReadUserDataSequence() is not called at all.

The result is the same: no shell is selected on the command dispatcher
stack, so .uno:UpdateAll is ignored and the replacement images are not
created.

Change-Id: If8b74424b0ad88e63129fd8f7efd09f85e300895
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106068
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/sfx2/source/view/sfxbasecontroller.cxx 
b/sfx2/source/view/sfxbasecontroller.cxx
index cecf046bfbe9..23b1aad5c3d0 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -1334,12 +1334,18 @@ void SfxBaseController::ConnectSfxFrame_Impl( const 
ConnectSfxFrame i_eConnect )
 break;
 }
 }
-if ( nViewDataIndex < nCount )
+if (nViewDataIndex < nCount || !xViewData.is())
 {
 Sequence< PropertyValue > aViewData;
-OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) 
>>= aViewData );
-if ( aViewData.hasElements() )
+if (xViewData.is())
+{
+OSL_VERIFY(xViewData->getByIndex(nViewDataIndex) 
>>= aViewData);
+}
+if (aViewData.hasElements() || !xViewData.is())
+{
+// Tolerate empty xViewData, 
ReadUserDataSequence() has side effects.
 m_pData->m_pViewShell->ReadUserDataSequence( 
aViewData );
+}
 }
 }
 catch (const Exception&)
diff --git a/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt 
b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt
new file mode 100644
index ..055c3d1a2c2a
Binary files /dev/null and 
b/sw/qa/uibase/uiview/data/update-replacement-nosetting.odt differ
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 8827cea10752..4d622aafaa5f 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -87,6 +88,30 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, 
testUpdateAllObjectReplacements)
 CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components_1"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
+{
+// Load a copy of the document in hidden mode.
+OUString aSourceURL
+= m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"update-replacement-nosetting.odt";
+CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, osl::File::copy(aSourceURL, 
maTempFile.GetURL()));
+mxComponent = loadFromDesktop(maTempFile.GetURL(), 
"com.sun.star.text.TextDocument",
+  { comphelper::makePropertyValue("Hidden", 
true) });
+
+// Update "everything" (including object replacements) and save it.
+dispatchCommand(mxComponent, ".uno:UpdateAll", {});
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+xStorable->storeSelf({});
+
+// Check the contents of the updated copy.
+uno::Reference xContext = 
comphelper::getProcessComponentContext();
+uno::Reference xNameAccess
+= packages::zip::ZipFileAccess::createWithURL(xContext, 
maTempFile.GetURL());
+
+// Without the accompanying fix in place, this test would have failed, 
because the embedded
+// object replacement image was not generated.
+CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 2b5670cffc11..0e12a868f88d 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1283,8 +1283,6 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < 
beans::PropertyValue >