[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Mon Jan 6 18:17:01 UTC 2020


 include/sfx2/sidebar/Panel.hxx            |    5 +
 sfx2/source/sidebar/Deck.cxx              |   12 ++-
 sfx2/source/sidebar/DeckLayouter.cxx      |  112 +++++++++++++++---------------
 sfx2/source/sidebar/Panel.cxx             |   18 ++++
 sfx2/source/sidebar/SidebarController.cxx |    1 
 5 files changed, 89 insertions(+), 59 deletions(-)

New commits:
commit 5b77d17c4f1ca734babf962b45c1aa07bdca14e9
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Sat Jan 4 18:09:20 2020 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Jan 6 19:16:28 2020 +0100

    sidebar: allow panels to lurk around instead of being disposed.
    
    Creating and destroying sidebar panels is done remarkably often - on
    changes of context eg. The process is remarkably expensive - loading
    UI XML files, processing them etc. and is un-necessary.
    
    Instead let panels lurk around for future use - particularly in the
    Properties deck which gets the most thrash. This gives a big speedup
    particularly noticable on mobile where it could take several seconds
    to load switch between panels for eg. shape vs. slide properties when
    tapping to edit text.
    
    Change-Id: I497e77432c11bbd1e35a8a8716519cabc3730e61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86233
    Tested-by: Michael Meeks <michael.meeks at collabora.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86287
    Tested-by: Jenkins

diff --git a/include/sfx2/sidebar/Panel.hxx b/include/sfx2/sidebar/Panel.hxx
index 823ed6e90a3a..2c0e9bd764c2 100644
--- a/include/sfx2/sidebar/Panel.hxx
+++ b/include/sfx2/sidebar/Panel.hxx
@@ -58,6 +58,10 @@ public:
     const OUString& GetId() const { return msPanelId;}
     void TriggerDeckLayouting() { maDeckLayoutTrigger(); }
 
+    /// Set whether a panel should be present but invisible / inactive
+    void SetLurkMode(bool bLurk);
+    bool IsLurking() const { return mbLurking; }
+
     virtual void Resize() override;
     virtual void DataChanged (const DataChangedEvent& rEvent) override;
     virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
@@ -70,6 +74,7 @@ private:
     css::uno::Reference<css::ui::XUIElement> mxElement;
     css::uno::Reference<css::ui::XSidebarPanel> mxPanelComponent;
     bool mbIsExpanded;
+    bool mbLurking;
     const std::function<void()> maDeckLayoutTrigger;
     const std::function<Context()> maContextAccess;
 
diff --git a/sfx2/source/sidebar/Deck.cxx b/sfx2/source/sidebar/Deck.cxx
index aeaf6274e6f9..26723738b7ee 100644
--- a/sfx2/source/sidebar/Deck.cxx
+++ b/sfx2/source/sidebar/Deck.cxx
@@ -218,17 +218,25 @@ bool Deck::ProcessWheelEvent(CommandEvent const * pCommandEvent)
  */
 void Deck::ResetPanels(const SharedPanelContainer& rPanelContainer)
 {
-    // First dispose old panels we no longer need.
+    SharedPanelContainer aHiddens;
+
+    // First hide old panels we don't need just now.
     for (VclPtr<Panel> & rpPanel : maPanels)
     {
         bool bFound = false;
         for (const auto & i : rPanelContainer)
             bFound = bFound || (rpPanel.get() == i.get());
         if (!bFound) // this one didn't survive.
-            rpPanel.disposeAndClear();
+        {
+            rpPanel->SetLurkMode(true);
+            aHiddens.push_back(rpPanel);
+        }
     }
     maPanels = rPanelContainer;
 
+    // Hidden ones always at the end
+    maPanels.insert(std::end(maPanels), std::begin(aHiddens), std::end(aHiddens));
+
     RequestLayoutInternal();
 }
 
diff --git a/sfx2/source/sidebar/DeckLayouter.cxx b/sfx2/source/sidebar/DeckLayouter.cxx
index 5a6e61353696..c83ced15b334 100644
--- a/sfx2/source/sidebar/DeckLayouter.cxx
+++ b/sfx2/source/sidebar/DeckLayouter.cxx
@@ -297,7 +297,7 @@ sal_Int32 PlacePanels (
             }
         }
 
-        if (rPanel.IsExpanded())
+        if (rPanel.IsExpanded() && !rPanel.IsLurking())
         {
             rPanel.Show();
 
@@ -361,69 +361,73 @@ void GetRequestedSizes (
 
     for (auto& rItem : rLayoutItems)
     {
-        ui::LayoutSize aLayoutSize (ui::LayoutSize(0,0,0));
-        if (rItem.mpPanel != nullptr)
+        rItem.maLayoutSize = ui::LayoutSize(0,0,0);
+
+        if (rItem.mpPanel == nullptr)
+            continue;
+
+        if (rItem.mpPanel->IsLurking())
+        {
+            rItem.mbShowTitleBar = false;
+            continue;
+        }
+
+        if (rLayoutItems.size() == 1
+            && rItem.mpPanel->IsTitleBarOptional())
+        {
+            // There is only one panel and its title bar is
+            // optional => hide it.
+            rAvailableHeight -= nDeckSeparatorHeight;
+            rItem.mbShowTitleBar = false;
+        }
+        else
         {
-            if (rLayoutItems.size() == 1
-                && rItem.mpPanel->IsTitleBarOptional())
+            // Show the title bar and a separator above and below
+            // the title bar.
+            const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * rItem.mpPanel->GetDPIScaleFactor());
+
+            rAvailableHeight -= nPanelTitleBarHeight;
+            rAvailableHeight -= nDeckSeparatorHeight;
+        }
+
+        if (rItem.mpPanel->IsExpanded() && rItem.mpPanel->GetPanelComponent().is())
+        {
+            Reference<ui::XSidebarPanel> xPanel (rItem.mpPanel->GetPanelComponent());
+
+            rItem.maLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth());
+            if (!(0 <= rItem.maLayoutSize.Minimum && rItem.maLayoutSize.Minimum <= rItem.maLayoutSize.Preferred
+                  && rItem.maLayoutSize.Preferred <= rItem.maLayoutSize.Maximum))
             {
-                // There is only one panel and its title bar is
-                // optional => hide it.
-                rAvailableHeight -= nDeckSeparatorHeight;
-                rItem.mbShowTitleBar = false;
+                SAL_WARN("sfx.sidebar", "Please follow LayoutSize constraints: 0 ≤ "
+                         "Minimum ≤ Preferred ≤ Maximum."
+                         " Currently: Minimum: "
+                         << rItem.maLayoutSize.Minimum
+                         << " Preferred: " << rItem.maLayoutSize.Preferred
+                         << " Maximum: " << rItem.maLayoutSize.Maximum);
             }
-            else
-            {
-                // Show the title bar and a separator above and below
-                // the title bar.
-                const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight) * rItem.mpPanel->GetDPIScaleFactor());
 
-                rAvailableHeight -= nPanelTitleBarHeight;
-                rAvailableHeight -= nDeckSeparatorHeight;
-            }
+            sal_Int32 nWidth = xPanel->getMinimalWidth();
 
-            if (rItem.mpPanel->IsExpanded())
+            uno::Reference<frame::XDesktop2> xDesktop
+                = frame::Desktop::create(comphelper::getProcessComponentContext());
+            uno::Reference<frame::XFrame> xFrame = xDesktop->getActiveFrame();
+            if (xFrame.is())
             {
-                Reference<ui::XSidebarPanel> xPanel (rItem.mpPanel->GetPanelComponent());
-                if (xPanel.is())
+                SidebarController* pController
+                    = SidebarController::GetSidebarControllerForFrame(xFrame);
+                if (pController && pController->getMaximumWidth() < nWidth)
                 {
-                    aLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth());
-                    if (!(0 <= aLayoutSize.Minimum && aLayoutSize.Minimum <= aLayoutSize.Preferred
-                          && aLayoutSize.Preferred <= aLayoutSize.Maximum))
-                    {
-                        SAL_WARN("sfx.sidebar", "Please follow LayoutSize constraints: 0 ≤ "
-                                                "Minimum ≤ Preferred ≤ Maximum."
-                                                " Currently: Minimum: "
-                                                    << aLayoutSize.Minimum
-                                                    << " Preferred: " << aLayoutSize.Preferred
-                                                    << " Maximum: " << aLayoutSize.Maximum);
-                    }
-
-                    sal_Int32 nWidth = xPanel->getMinimalWidth();
-
-                    uno::Reference<frame::XDesktop2> xDesktop
-                        = frame::Desktop::create(comphelper::getProcessComponentContext());
-                    uno::Reference<frame::XFrame> xFrame = xDesktop->getActiveFrame();
-                    if (xFrame.is())
-                    {
-                        SidebarController* pController
-                            = SidebarController::GetSidebarControllerForFrame(xFrame);
-                        if (pController && pController->getMaximumWidth() < nWidth)
-                        {
-                            // Add 100 extra pixels to still have the sidebar resizable
-                            // (See also documentation of XSidebarPanel::getMinimalWidth)
-                            pController->setMaximumWidth(nWidth + 100);
-                        }
-                    }
-
-                    if (nWidth > rMinimalWidth)
-                        rMinimalWidth = nWidth;
+                    // Add 100 extra pixels to still have the sidebar resizable
+                    // (See also documentation of XSidebarPanel::getMinimalWidth)
+                    pController->setMaximumWidth(nWidth + 100);
                 }
-                else
-                    aLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0);
             }
+
+            if (nWidth > rMinimalWidth)
+                rMinimalWidth = nWidth;
         }
-        rItem.maLayoutSize = aLayoutSize;
+        else
+            rItem.maLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0);
     }
 }
 
diff --git a/sfx2/source/sidebar/Panel.cxx b/sfx2/source/sidebar/Panel.cxx
index e4b9ef6668ec..12caa0807c1d 100644
--- a/sfx2/source/sidebar/Panel.cxx
+++ b/sfx2/source/sidebar/Panel.cxx
@@ -61,6 +61,7 @@ Panel::Panel(const PanelDescriptor& rPanelDescriptor,
     , mxElement()
     , mxPanelComponent()
     , mbIsExpanded(bIsInitiallyExpanded)
+    , mbLurking(false)
     , maDeckLayoutTrigger(rDeckLayoutTrigger)
     , maContextAccess(rContextAccess)
     , mxFrame(rxFrame)
@@ -74,6 +75,12 @@ Panel::~Panel()
     assert(!mpTitleBar);
 }
 
+void Panel::SetLurkMode(bool bLurk)
+{
+    // cf. DeckLayouter
+    mbLurking = bLurk;
+}
+
 void Panel::ApplySettings(vcl::RenderContext& rRenderContext)
 {
     rRenderContext.SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
@@ -81,9 +88,14 @@ void Panel::ApplySettings(vcl::RenderContext& rRenderContext)
 
 boost::property_tree::ptree Panel::DumpAsPropertyTree()
 {
-    boost::property_tree::ptree aTree(vcl::Window::DumpAsPropertyTree());
-    aTree.put("type", "panel");
-    return aTree;
+    if (!IsLurking())
+    {
+        boost::property_tree::ptree aTree(vcl::Window::DumpAsPropertyTree());
+        aTree.put("type", "panel");
+        return aTree;
+    }
+    else
+        return boost::property_tree::ptree();
 }
 
 void Panel::dispose()
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index b34f3b7452b6..284290653e8f 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -719,6 +719,7 @@ void SidebarController::CreatePanels(const OUString& rDeckId, const Context& rCo
         Panel *const pPanel(pDeck->GetPanel(rPanelContexDescriptor.msId));
         if (pPanel != nullptr)
         {
+            pPanel->SetLurkMode(false);
             aNewPanels[nWriteIndex] = pPanel;
             pPanel->SetExpanded( rPanelContexDescriptor.mbIsInitiallyVisible );
             ++nWriteIndex;


More information about the Libreoffice-commits mailing list