diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-06-04 20:57:19 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-06-05 13:06:57 +0200 |
commit | e86a0236e69d76769b91f96d71fe852b91c5db6e (patch) | |
tree | 88e8ca1a9f89556cdf5004daecaa772e59be3a7f /desktop | |
parent | 6c4c040d2ebc4371a706c762e7e6707875c43535 (diff) |
lok: callback to send the updated theme palette when theme changes
The callback sends the updated theme color palette when the theme
changes or initially when the view is registered, so the client
should always have the up-to-date theme color palette stored, so
it can just show the color picker with the theme at any time without
the need to call the server.
Change-Id: I7cceccc46c2fad23ba89e6d3f3643e37f8dab292
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152589
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/qa/data/ThemeDocument.docx | bin | 0 -> 13121 bytes | |||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 40 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 2 |
3 files changed, 42 insertions, 0 deletions
diff --git a/desktop/qa/data/ThemeDocument.docx b/desktop/qa/data/ThemeDocument.docx Binary files differnew file mode 100644 index 000000000000..4dbba883d9b6 --- /dev/null +++ b/desktop/qa/data/ThemeDocument.docx diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 74db478c09a3..b698cc5976b7 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -219,6 +219,7 @@ public: void testRenderSearchResult_CommonNode(); void testNoDuplicateTableSelection(); void testMultiViewTableSelection(); + void testColorPaletteCallback(); void testABI(); CPPUNIT_TEST_SUITE(DesktopLOKTest); @@ -291,6 +292,7 @@ public: CPPUNIT_TEST(testRenderSearchResult_CommonNode); CPPUNIT_TEST(testNoDuplicateTableSelection); CPPUNIT_TEST(testMultiViewTableSelection); + CPPUNIT_TEST(testColorPaletteCallback); CPPUNIT_TEST(testABI); CPPUNIT_TEST_SUITE_END(); @@ -2160,12 +2162,14 @@ class ViewCallback public: OString m_aCellFormula; int m_nTableSelectionCount; + int m_nColorPaletteCallbackCount = 0; bool m_bEmptyTableSelection; bool m_bTilesInvalidated; bool m_bZeroCursor; tools::Rectangle m_aOwnCursor; boost::property_tree::ptree m_aCommentCallbackResult; boost::property_tree::ptree m_aCallbackWindowResult; + boost::property_tree::ptree m_aColorPaletteCallbackResult; bool m_bWindowHidden; ViewCallback(LibLODocument_Impl* pDocument) @@ -2245,6 +2249,14 @@ public: ++m_nTableSelectionCount; } break; + case LOK_CALLBACK_COLOR_PALETTES: + { + m_aColorPaletteCallbackResult.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_aColorPaletteCallbackResult); + ++m_nColorPaletteCallbackCount; + } + break; } } }; @@ -3525,6 +3537,34 @@ void DesktopLOKTest::testMultiViewTableSelection() CPPUNIT_ASSERT(!aView1.m_bEmptyTableSelection); } +void DesktopLOKTest::testColorPaletteCallback() +{ + LibLODocument_Impl* pDocument = loadDoc("ThemeDocument.docx"); + + // Create view 1. + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + ViewCallback aView1(pDocument); + Scheduler::ProcessEventsToIdle(); + { + CPPUNIT_ASSERT_EQUAL(1, aView1.m_nColorPaletteCallbackCount); + boost::property_tree::ptree aValues = aView1.m_aColorPaletteCallbackResult.get_child("ThemeColors"); + CPPUNIT_ASSERT(!aValues.empty()); + CPPUNIT_ASSERT_EQUAL(size_t(6), aValues.size()); + } + + // Create view 2. + pDocument->m_pDocumentClass->createView(pDocument); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + ViewCallback aView2(pDocument); + Scheduler::ProcessEventsToIdle(); + { + CPPUNIT_ASSERT_EQUAL(1, aView2.m_nColorPaletteCallbackCount); + boost::property_tree::ptree aValues = aView1.m_aColorPaletteCallbackResult.get_child("ThemeColors"); + CPPUNIT_ASSERT(!aValues.empty()); + CPPUNIT_ASSERT_EQUAL(size_t(6), aValues.size()); + } +} + namespace { constexpr size_t classOffset(int i) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 13922571d9ce..52cd5411a7e5 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1816,6 +1816,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData) case LOK_CALLBACK_A11Y_FOCUS_CHANGED: case LOK_CALLBACK_A11Y_CARET_CHANGED: case LOK_CALLBACK_A11Y_TEXT_SELECTION_CHANGED: + case LOK_CALLBACK_COLOR_PALETTES: { const auto& pos = std::find(m_queue1.rbegin(), m_queue1.rend(), type); auto pos2 = toQueue2(pos); @@ -1877,6 +1878,7 @@ void CallbackFlushHandler::queue(const int type, CallbackData& aCallbackData) case LOK_CALLBACK_A11Y_FOCUS_CHANGED: case LOK_CALLBACK_A11Y_CARET_CHANGED: case LOK_CALLBACK_A11Y_TEXT_SELECTION_CHANGED: + case LOK_CALLBACK_COLOR_PALETTES: { if (removeAll(type)) SAL_INFO("lok", "Removed dups of [" << type << "]: [" << aCallbackData.getPayload() << "]."); |