diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2023-12-19 15:30:27 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2023-12-19 18:39:54 +0100 |
commit | e83309d97d0bbad131a7fdfd365fb6122d6f415b (patch) | |
tree | 2190ff7aa6dde787e6902d4b07c8deca7b473d0e /sc | |
parent | 9ca22d44e5293f3335a2b475ccef157d31c60b94 (diff) |
cool#7853 sc lok: fix bad view id on hyperlink click
The document had 2 windows. The first window was typing in column A, the
second window ctrl-clicked on a hyperlink in column B. The LOK callback
was emitted in window 1, not in window 2, which is unexpected.
What happens is that ScGlobal::OpenURL() dispatched an async command
when window 2 was active, and we happened to be in window 1 when
processing that user event from the main loop.
Fix the problem by dispatching the URL open command in a synchronous
way, so the LOK view can't be different.
An alternative would be to track the current LOK view id for posted user
events, and set the view back to the one which was current at post-time
before executing the event. We can consider doing that in a follow-up
change, but this fixes the problem at hand and is a safe fix.
Change-Id: I9a3c9fc1b90ad538d8b2510c7844549c9881ca56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160976
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/global.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/tiledrendering/tiledrendering.cxx | 28 | ||||
-rw-r--r-- | sc/source/core/data/global.cxx | 11 |
3 files changed, 39 insertions, 2 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 089611e5ee6b..e140a7fb6ef0 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -575,7 +575,7 @@ public: * Open the specified URL. * @param bIgnoreSettings - If true, ignore security settings (Ctrl-Click) and just open the URL. */ - static void OpenURL(const OUString& rURL, const OUString& rTarget, bool bIgnoreSettings = false); + SC_DLLPUBLIC static void OpenURL(const OUString& rURL, const OUString& rTarget, bool bIgnoreSettings = false); /// Whether the URL can be opened according to current security options (Click/Ctrl-Click) static bool ShouldOpenURL(); SC_DLLPUBLIC static OUString GetAbsDocName( const OUString& rFileName, diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 27950831a1f3..d72cb6457fb4 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -435,6 +435,7 @@ public: TextSelectionMessage m_aTextSelectionResult; OString m_sInvalidateHeader; OString m_sInvalidateSheetGeometry; + OString m_aHyperlinkClicked; OString m_ShapeSelection; TestLokCallbackWrapper m_callbackWrapper; @@ -571,6 +572,11 @@ public: m_aInvalidateCursorResult.parseMessage(pPayload); } break; + case LOK_CALLBACK_HYPERLINK_CLICKED: + { + m_aHyperlinkClicked = pPayload; + } + break; case LOK_CALLBACK_TEXT_SELECTION: { m_aTextSelectionResult.parseMessage(pPayload); @@ -3113,6 +3119,28 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testGetViewRenderState) CPPUNIT_ASSERT_EQUAL(";Default"_ostr, pModelObj->getViewRenderState()); } +CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testOpenURL) +{ + // Given a document that has 2 views: + createDoc("empty.ods"); + int nView1 = SfxLokHelper::getView(); + ViewCallback aView1; + SfxLokHelper::createView(); + ViewCallback aView2; + + // When clicking on a link in view 2, but switching to view 1 before processing async events: + ScGlobal::OpenURL(/*aUrl=*/u"http://www.example.com/"_ustr, /*aTarget=*/u""_ustr, + /*bIgnoreSettings=*/true); + SfxLokHelper::setView(nView1); + Scheduler::ProcessEventsToIdle(); + + // Then make sure view 2 gets the callback, not view 1: + // Without the accompanying fix in place, this test would have failed, view 1 got the hyperlink + // callback. + CPPUNIT_ASSERT(aView1.m_aHyperlinkClicked.isEmpty()); + CPPUNIT_ASSERT(!aView2.m_aHyperlinkClicked.isEmpty()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 29a616c6b6e8..15fdc7dfb39d 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -879,8 +879,17 @@ void ScGlobal::OpenURL(const OUString& rURL, const OUString& rTarget, bool bIgno SfxBoolItem aBrowsing( SID_BROWSE, true ); // No SID_SILENT anymore + SfxCallMode nCall = SfxCallMode::RECORD; + if (comphelper::LibreOfficeKit::isActive()) + { + nCall |= SfxCallMode::SYNCHRON; + } + else + { + nCall |= SfxCallMode::ASYNCHRON; + } pViewFrm->GetDispatcher()->ExecuteList(SID_OPENDOC, - SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, + nCall, { &aUrl, &aTarget, &aFrm, &aReferer, &aNewView, &aBrowsing }); } |