diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-18 14:33:53 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-05-20 09:15:15 +0200 |
commit | 3a86bbd5e06d0fb7c057c761e924111e6499d20e (patch) | |
tree | 8dbb9e61a8ec40c25a8e29a330da0c1824edfa0f /sw/qa/core/txtnode/txtnode.cxx | |
parent | 5d992d36412cd41e8489e98ee1d251125219073f (diff) |
sw: fix not needed invalidation of title field on each keypressco-6.4-39
Type a character, SwDocShell::DoFlushDocInfo() is called because the
number of characters changed, and that rapaints all title fields.
This happens as SwFormatField::UpdateTextNode() calls
SwTextField::ExpandTextField() with bForceNotify=true, because that was
needed for conditional text in commit
cd94a84b89c476760ad74bf088a5d6f8ba4ce209 (125044: - use field's content
cache on <SwTxtFld> construction only, 2014-06-13).
Fix the problem by not forcing notifications for title fields in
SwFormatField::UpdateTextNode(): SwTextField::ExpandTextField() will
send a notification if the expend result differs without forcing as
well.
(cherry picked from commit 0a32630d11ebdb8b8218faa066c72582ef2f300d)
Conflicts:
sw/qa/core/txtnode/txtnode.cxx
sw/source/core/txtnode/atrfld.cxx
Change-Id: I5e46ab6aef33ff5e348d40b8644bcc9cf353c326
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115783
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/qa/core/txtnode/txtnode.cxx')
-rw-r--r-- | sw/qa/core/txtnode/txtnode.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx index eb675c6e77b8..56040043ed25 100644 --- a/sw/qa/core/txtnode/txtnode.cxx +++ b/sw/qa/core/txtnode/txtnode.cxx @@ -14,8 +14,13 @@ #include <svx/svdpage.hxx> #include <tools/globname.hxx> #include <unotest/bootstrapfixturebase.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <comphelper/lok.hxx> +#include <sfx2/viewsh.hxx> #include <vcl/gdimtf.hxx> +#include <vcl/scheduler.hxx> +#include <IDocumentStatistics.hxx> #include <wrtsh.hxx> #include <fmtanchr.hxx> #include <IDocumentDrawModelAccess.hxx> @@ -89,6 +94,71 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testTextBoxNodeSplit) pWrtShell->SplitNode(); } +namespace +{ +struct ViewCallback +{ + int m_nInvalidations = 0; + + static void callback(int nType, const char* pPayload, void* pData); + void callbackImpl(int nType, const char* pPayload); +}; + +void ViewCallback::callback(int nType, const char* pPayload, void* pData) +{ + static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload); +} + +void ViewCallback::callbackImpl(int nType, const char* /*pPayload*/) +{ + switch (nType) + { + case LOK_CALLBACK_INVALIDATE_TILES: + { + ++m_nInvalidations; + } + break; + } +} +} + +CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testTitleFieldInvalidate) +{ + // Set up LOK to track invalidations. + comphelper::LibreOfficeKit::setActive(true); + + // Given a document with a title field: + load(DATA_DIRECTORY, "title-field-invalidate.fodt"); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + pTextDoc->initializeForTiledRendering({}); + SwDocShell* pShell = pTextDoc->GetDocShell(); + SwDoc* pDoc = pShell->GetDoc(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/false); + ViewCallback aCallback; + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, + &aCallback); + Scheduler::ProcessEventsToIdle(); + aCallback.m_nInvalidations = 0; + + // When typing to the document: + pWrtShell->Insert("x"); + + // Then make sure that only the text frame at the cursor is invalidated: + pDoc->getIDocumentStatistics().GetUpdatedDocStat(/*bCompleteAsync=*/true, /*bFields=*/false); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 2 + // i.e. the footer was also invalidated on each keypress. + CPPUNIT_ASSERT_EQUAL(1, aCallback.m_nInvalidations); + + // Tear down LOK. + pWrtShell->GetSfxViewShell()->registerLibreOfficeKitViewCallback(nullptr, nullptr); + mxComponent->dispose(); + mxComponent.clear(); + comphelper::LibreOfficeKit::setActive(false); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |