summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-10-15 08:43:23 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-10-24 01:40:45 +0200
commit273a25c796fca9afa0dfadac57dc3f336831221c (patch)
tree3efb1e505e27164bcdb2c164c59a48c814221ffe /include
parent667c2499d861cfcd26935fc0512cb5aaf602c4c5 (diff)
change some LOK internal updates to be pull model instead of push
Some LOK messages may get called very often, such as updates about cursor position. And since only the last one matters, they get generated every time, which costs some time, and then later except for one they get all discard again from CallbackFlushHandler queue, which again costs time. Change the model to instead only set an 'updated' flag, and CallbackFlushHandler will request the actual message payload only before flushing. This commit changes LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR and LOK_CALLBACK_INVALIDATE_VIEW_CURSOR to work this way. Change-Id: I376be63176c0b4b5cb492fbf529c21ed01b35481 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124083 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include')
-rw-r--r--include/editeng/outliner.hxx2
-rw-r--r--include/sfx2/lokcallback.hxx11
-rw-r--r--include/sfx2/lokhelper.hxx18
-rw-r--r--include/sfx2/viewsh.hxx5
-rw-r--r--include/test/lokcallback.hxx24
5 files changed, 56 insertions, 4 deletions
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index c269bf49046f..5003a671d35e 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -366,6 +366,8 @@ public:
virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) const = 0;
virtual void libreOfficeKitViewCallbackWithViewId(int nType, const char* pPayload, int nViewId) const = 0;
virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart) const = 0;
+ virtual void libreOfficeKitViewUpdatedCallback(int nType) const = 0;
+ virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, int nSourceViewId) const = 0;
virtual ViewShellId GetViewShellId() const = 0;
virtual ViewShellDocId GetDocId() const = 0;
/// Wrapper around SfxLokHelper::notifyOtherViews().
diff --git a/include/sfx2/lokcallback.hxx b/include/sfx2/lokcallback.hxx
index d01e7203205e..6f59402d0cec 100644
--- a/include/sfx2/lokcallback.hxx
+++ b/include/sfx2/lokcallback.hxx
@@ -11,6 +11,8 @@
#include <sal/types.h>
+#include <vector>
+
namespace tools
{
class Rectangle;
@@ -37,6 +39,15 @@ public:
// comphelper::LibreOfficeKit::isPartInInvalidation() is not set
virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart)
= 0;
+ // A message of the given type should be sent, for performance purpose only a notification
+ // is given here, details about the message should be queried from SfxViewShell when necessary.
+ // This is used for messages that are generated often but only the last one is needed.
+ virtual void libreOfficeKitViewUpdatedCallback(int nType) = 0;
+ // Like libreOfficeKitViewUpdatedCallback(), but a last message is needed for each nViewId value.
+ // SfxViewShell:getLOKPayload() will be called on nSourceViewId view.
+ virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId,
+ int nSourceViewId)
+ = 0;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index cf2c1c9c72bb..4ac50a19cc69 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -110,14 +110,28 @@ public:
static void notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc, bool bInvalidateAll = true);
/// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed.
static void notifyInvalidation(SfxViewShell const* pThisView, tools::Rectangle const *);
- /// Emits a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, but tweaks it according to setOptionalFeatures() if needed.
- static void notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle, bool bMispelledWord = false, const OString& rHyperlink = "");
/// Notifies all views with the given type and payload.
static void notifyAllViews(int nType, const OString& rPayload);
/// Notify about the editing context change.
static void notifyContextChange(SfxViewShell const* pViewShell, const OUString& aApplication, const OUString& aContext);
+ // Notify about the given type needing an update.
+ static void notifyUpdate(SfxViewShell const* pViewShell, int nType);
+ // Notify about the given type needing a per-viewid update.
+ static void notifyUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
+ /// Same as notifyUpdatePerViewId(), pTargetShell will be notified, relevant viewId in pViewShell,
+ /// pSourceView->getLOKPayload() will be called to get the data.
+ static void notifyUpdatePerViewId(SfxViewShell const* pTargetShell, SfxViewShell const* pViewShell,
+ SfxViewShell const* pSourceShell, int nType);
+ // Notify other views about the given type needing a per-viewid update.
+ static void notifyOtherViewsUpdatePerViewId(SfxViewShell const* pViewShell, int nType);
+
+ static OString makePayloadJSON(const SfxViewShell* pThisView, int nViewId, std::string_view rKey, const OString& rPayload);
+ /// Makes a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR payload, but tweaks it according to setOptionalFeatures() if needed.
+ static OString makeVisCursorInvalidation(int nViewId, const OString& rRectangle,
+ bool bMispelledWord = false, const OString& rHyperlink = "");
+
/// Helper for posting async key event
static void postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
int nType, int nCharCode, int nKeyCode, int nRepeat = 0);
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 89c9cd6c0c7c..e35c6848c9e1 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -343,6 +343,11 @@ public:
virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, int nPart) const override;
// Performs any pending calls to libreOfficeKitViewInvalidateTilesCallback() as necessary.
virtual void flushPendingLOKInvalidateTiles();
+ virtual void libreOfficeKitViewUpdatedCallback(int nType) const override;
+ virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, int nSourceViewId) const override;
+ // Returns current payload for nType, after libreOfficeKitViewUpdatedCallback() or
+ // libreOfficeKitViewUpdatedCallbackPerViewId() were called.
+ virtual OString getLOKPayload(int nType, int nViewId) const;
/// Set if we are doing tiled searching.
void setTiledSearching(bool bTiledSearching);
diff --git a/include/test/lokcallback.hxx b/include/test/lokcallback.hxx
index f7372bc7ec80..a3f383bcec5e 100644
--- a/include/test/lokcallback.hxx
+++ b/include/test/lokcallback.hxx
@@ -15,28 +15,48 @@
#include <sfx2/lokcallback.hxx>
#include <vcl/idle.hxx>
+#include <vector>
+
/**
A helper to convert SfxLokCallbackInterface to a LIbreOfficeKitCallback for tests.
It reimplements the specialized callbacks and converts them to the generic type/payload
callback.
*/
-
class OOO_DLLPUBLIC_TEST TestLokCallbackWrapper final : public SfxLokCallbackInterface, public Idle
{
public:
TestLokCallbackWrapper(LibreOfficeKitCallback callback, void* data);
+ /// Discard all possibly still held events.
+ void clear();
+ /// Set the view id of the associated SfxViewShell.
+ void setLOKViewId(int viewId) { m_viewId = viewId; }
virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override;
virtual void libreOfficeKitViewCallbackWithViewId(int nType, const char* pPayload,
int nViewId) override;
virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect,
int nPart) override;
+ virtual void libreOfficeKitViewUpdatedCallback(int nType) override;
+ virtual void libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId,
+ int nSourceViewId) override;
virtual void Invoke() override;
private:
- void callCallback(int nType, const char* pPayload);
+ void callCallback(int nType, const char* pPayload, int nViewId);
+ void startTimer();
+ void flushLOKData();
+ void discardUpdatedTypes(int nType, int nViewId);
LibreOfficeKitCallback m_callback;
void* m_data;
+ int m_viewId = -1; // the associated SfxViewShell
+ std::vector<int> m_updatedTypes; // value is type
+ struct PerViewIdData
+ {
+ int type;
+ int viewId;
+ int sourceViewId;
+ };
+ std::vector<PerViewIdData> m_updatedTypesPerViewId;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */