include/sal/log-areas.dox  |    1 +
 vcl/inc/qt5/QtInstance.hxx |    2 ++
 vcl/inc/salinst.hxx        |    2 ++
 vcl/qt5/QtInstance.cxx     |   11 +++++++++++
 vcl/qt5/QtTimer.cxx        |    9 +++++++++
 vcl/source/app/svapp.cxx   |   21 +++++++++++++++++++--
 6 files changed, 44 insertions(+), 2 deletions(-)

New commits:
commit 93133585b5b52e38defc3162eeb1e7704dceafcb
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Sat Oct 2 12:50:05 2021 +0200
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Wed Jan 19 17:06:48 2022 +0100

    WASM optionally run any app via system loop
    
    Allows LO to run via system event loop instead of having an
    own one and processing system events as needed. Needed for
    WASM, so the browser isn't blocked, as there is no way to
    run the browser mainloop from WASM. Generally an alternative
    to running LO in a WebWorker and communicating to some
    frontend.
    
    Change-Id: I24955638827f3b8c04240845ffc781cd28f2aa29
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128602
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de>

diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index fca315f7c915..5767a9e5265f 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -640,6 +640,7 @@ certain functionality.
 @li @c unoxml
 @li @c uui
 @li @c vbahelper
+@li @c wasm
 @li @c xmlhelp
 @li @c xmlreader
 
diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx
index 1511996c0ce0..9c3adb25e98b 100644
--- a/vcl/inc/qt5/QtInstance.hxx
+++ b/vcl/inc/qt5/QtInstance.hxx
@@ -174,6 +174,8 @@ public:
     void UpdateStyle(bool bFontsChanged);
 
     void* CreateGStreamerSink(const SystemChildWindow*) override;
+
+    bool DoExecute(int& nExitCode) override;
 };
 
 inline QtInstance* GetQtInstance() { return 
static_cast<QtInstance*>(GetSalInstance()); }
diff --git a/vcl/inc/salinst.hxx b/vcl/inc/salinst.hxx
index 9dcee57bc2e6..90367c06bcc9 100644
--- a/vcl/inc/salinst.hxx
+++ b/vcl/inc/salinst.hxx
@@ -214,6 +214,8 @@ public:
 
     // Note: we cannot make this a global variable, because it might be 
initialised BEFORE the putenv() call in cppunittester.
     static bool IsRunningUnitTest() { return getenv("LO_TESTNAME") != nullptr; 
}
+
+    virtual bool DoExecute(int & /* nExitCode */) { return false; }
 };
 
 // called from SVMain
diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx
index 9629532f824b..a03b71e46bd2 100644
--- a/vcl/qt5/QtInstance.cxx
+++ b/vcl/qt5/QtInstance.cxx
@@ -724,6 +724,17 @@ std::unique_ptr<QApplication> 
QtInstance::CreateQApplication(int& nArgc, char**
     return pQApp;
 }
 
+bool QtInstance::DoExecute(int& nExitCode)
+{
+#ifdef EMSCRIPTEN
+    nExitCode = m_pQApplication->exec();
+    return true;
+#else
+    (void)nExitCode;
+    return false;
+#endif
+}
+
 extern "C" {
 VCLPLUG_QT_PUBLIC SalInstance* create_SalInstance()
 {
diff --git a/vcl/qt5/QtTimer.cxx b/vcl/qt5/QtTimer.cxx
index 751937b44931..6568ca8ac1b8 100644
--- a/vcl/qt5/QtTimer.cxx
+++ b/vcl/qt5/QtTimer.cxx
@@ -20,12 +20,16 @@
 #include <QtTimer.hxx>
 #include <QtTimer.moc>
 
+#include <QtInstance.hxx>
+
 #include <QtWidgets/QApplication>
 #include <QtCore/QThread>
 
 #include <vcl/svapp.hxx>
 #include <sal/log.hxx>
 
+#include <svdata.hxx>
+
 QtTimer::QtTimer()
 {
     m_aTimer.setSingleShot(true);
@@ -38,6 +42,11 @@ QtTimer::QtTimer()
 void QtTimer::timeoutActivated()
 {
     SolarMutexGuard aGuard;
+#ifdef EMSCRIPTEN
+    const ImplSVData* pSVData = ImplGetSVData();
+    assert(pSVData->mpDefInst);
+    static_cast<QtInstance*>(pSVData->mpDefInst)->DispatchUserEvents(true);
+#endif
     CallCallback();
 }
 
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 2e02bffcb7f2..c1f3b4a5bccf 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -440,14 +440,19 @@ void Application::Execute()
         pSVData->maAppData.mpEventTestingIdle->Start();
     }
 
-    while ( !pSVData->maAppData.mbAppQuit )
-        Application::Yield();
+    int nExitCode = 0;
+    if (!pSVData->mpDefInst->DoExecute(nExitCode))
+    {
+        while (!pSVData->maAppData.mbAppQuit)
+            Application::Yield();
+    }
 
     pSVData->maAppData.mbInAppExecute = false;
 
     GetpApp()->Shutdown();
 }
 
+#ifndef EMSCRIPTEN
 static bool ImplYield(bool i_bWait, bool i_bAllEvents)
 {
     ImplSVData* pSVData = ImplGetSVData();
@@ -472,10 +477,17 @@ static bool ImplYield(bool i_bWait, bool i_bAllEvents)
     SAL_INFO("vcl.schedule", "Leave ImplYield with return " << bProcessedEvent 
);
     return bProcessedEvent;
 }
+#endif
 
 bool Application::Reschedule( bool i_bAllEvents )
 {
+#ifdef EMSCRIPTEN
+    SAL_WARN("wasm", "Application::Reschedule(" << i_bAllEvents << ")");
+    (void) i_bAllEvents;
+    std::abort();
+#else
     return ImplYield(false, i_bAllEvents);
+#endif
 }
 
 void Scheduler::ProcessEventsToIdle()
@@ -529,7 +541,12 @@ SAL_DLLPUBLIC_EXPORT void unit_lok_process_events_to_idle()
 
 void Application::Yield()
 {
+#ifdef EMSCRIPTEN
+    SAL_WARN("wasm", "Application::Yield()");
+    std::abort();
+#else
     ImplYield(true, false);
+#endif
 }
 
 IMPL_STATIC_LINK_NOARG( ImplSVAppData, ImplQuitMsg, void*, void )

Reply via email to