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 14:27:28 +0100 |
commit | aacc5ed083b53a99719034ff3b87105741982609 (patch) | |
tree | eed874f3c4020ab52a00b042ccea1f3a928cc43d /sfx2 | |
parent | 1e01adf9d46524569c0c4461b78e5c06143db761 (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>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/sidebar/Deck.cxx | 12 | ||||
-rw-r--r-- | sfx2/source/sidebar/DeckLayouter.cxx | 77 | ||||
-rw-r--r-- | sfx2/source/sidebar/Panel.cxx | 18 | ||||
-rw-r--r-- | sfx2/source/sidebar/SidebarController.cxx | 1 |
4 files changed, 67 insertions, 41 deletions
diff --git a/sfx2/source/sidebar/Deck.cxx b/sfx2/source/sidebar/Deck.cxx index fba9f1330833..074334c2e415 100644 --- a/sfx2/source/sidebar/Deck.cxx +++ b/sfx2/source/sidebar/Deck.cxx @@ -209,17 +209,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 0337c7cc46d6..33d6dc62f4b9 100644 --- a/sfx2/source/sidebar/DeckLayouter.cxx +++ b/sfx2/source/sidebar/DeckLayouter.cxx @@ -289,7 +289,7 @@ sal_Int32 PlacePanels ( } } - if (rPanel.IsExpanded()) + if (rPanel.IsExpanded() && !rPanel.IsLurking()) { rPanel.Show(); @@ -353,46 +353,51 @@ void GetRequestedSizes ( for (LayoutItem& item : rLayoutItems) { - ui::LayoutSize aLayoutSize (ui::LayoutSize(0,0,0)); - if (item.mpPanel != nullptr) + item.maLayoutSize = ui::LayoutSize(0,0,0); + + if (item.mpPanel == nullptr) + continue; + + if (item.mpPanel->IsLurking()) { - if (rLayoutItems.size() == 1 - && item.mpPanel->IsTitleBarOptional()) - { - // There is only one panel and its title bar is - // optional => hide it. - rAvailableHeight -= nDeckSeparatorHeight; - item.mbShowTitleBar = false; - } - else - { - // Show the title bar and a separator above and below - // the title bar. - const sal_Int32 nPanelTitleBarHeight( - Theme::GetInteger(Theme::Int_PanelTitleBarHeight) - * item.mpPanel->GetDPIScaleFactor()); - - rAvailableHeight -= nPanelTitleBarHeight; - rAvailableHeight -= nDeckSeparatorHeight; - } + item.mbShowTitleBar = false; + continue; + } - if (item.mpPanel->IsExpanded()) + if (rLayoutItems.size() == 1 + && item.mpPanel->IsTitleBarOptional()) + { + // There is only one panel and its title bar is + // optional => hide it. + rAvailableHeight -= nDeckSeparatorHeight; + item.mbShowTitleBar = false; + } + else + { + // Show the title bar and a separator above and below + // the title bar. + const sal_Int32 nPanelTitleBarHeight( + Theme::GetInteger(Theme::Int_PanelTitleBarHeight) + * item.mpPanel->GetDPIScaleFactor()); + + rAvailableHeight -= nPanelTitleBarHeight; + rAvailableHeight -= nDeckSeparatorHeight; + } + + if (item.mpPanel->IsExpanded()) + { + Reference<ui::XSidebarPanel> xPanel(item.mpPanel->GetPanelComponent()); + if (xPanel.is()) { - Reference<ui::XSidebarPanel> xPanel(item.mpPanel->GetPanelComponent()); - if (xPanel.is()) - { - aLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth()); - - const sal_Int32 nWidth = xPanel->getMinimalWidth(); - if (nWidth > rMinimalWidth) - rMinimalWidth = nWidth; - } - else - aLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0); + item.maLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth()); + + const sal_Int32 nWidth = xPanel->getMinimalWidth(); + if (nWidth > rMinimalWidth) + rMinimalWidth = nWidth; } + else + item.maLayoutSize = ui::LayoutSize(MinimalPanelHeight, -1, 0); } - - item.maLayoutSize = aLayoutSize; } } diff --git a/sfx2/source/sidebar/Panel.cxx b/sfx2/source/sidebar/Panel.cxx index 7968f667b92d..dc4ea895d26d 100644 --- a/sfx2/source/sidebar/Panel.cxx +++ b/sfx2/source/sidebar/Panel.cxx @@ -57,6 +57,7 @@ Panel::Panel(const PanelDescriptor& rPanelDescriptor, , mxElement() , mxPanelComponent() , mbIsExpanded(bIsInitiallyExpanded) + , mbLurking(false) , maDeckLayoutTrigger(rDeckLayoutTrigger) , maContextAccess(rContextAccess) , mxFrame(rxFrame) @@ -70,6 +71,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()); @@ -77,9 +84,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 91405791c727..f11ce95e7213 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -716,6 +716,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; |