diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2020-01-04 18:09:20 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2020-01-06 19:16:28 +0100 |
commit | 5b77d17c4f1ca734babf962b45c1aa07bdca14e9 (patch) | |
tree | 7ea5542a677748273d2c95cbd3ab1514a4b876f1 /sfx2 | |
parent | 0bb6bb7729f159f05100e33797ed667fd9d13ab7 (diff) |
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@collabora.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86287
Tested-by: Jenkins
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/sidebar/Deck.cxx | 12 | ||||
-rw-r--r-- | sfx2/source/sidebar/DeckLayouter.cxx | 112 | ||||
-rw-r--r-- | sfx2/source/sidebar/Panel.cxx | 18 | ||||
-rw-r--r-- | sfx2/source/sidebar/SidebarController.cxx | 1 |
4 files changed, 84 insertions, 59 deletions
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; |