[escher] ScrollView: fix Decorators contructor/destructors

This commit is contained in:
Émilie Feral
2019-02-14 15:40:03 +01:00
committed by EmilieNumworks
parent f18a55defe
commit 3487547f16
2 changed files with 18 additions and 4 deletions

View File

@@ -33,6 +33,9 @@ public:
Bars,
Arrows
};
/* We want (Decorator *)->~Decorator() to call ~BarDecorator() or ~ArrowDecorator()
* when required. */
virtual ~Decorator() = default;
virtual int numberOfIndicators() const { return 0; }
virtual View * indicatorAtIndex(int index) { assert(false); return nullptr; }
virtual KDRect layoutIndicators(KDSize content, KDPoint offset, KDRect frame) { return frame; }
@@ -132,9 +135,8 @@ private:
Decorator::Type m_decoratorType;
union Decorators {
public:
/* Enforce trivial constructor and destructor that just leaves the memory unmodified. */
Decorators() {}
~Decorators() {}
Decorators();
~Decorators();
Decorator * activeDecorator() { return &m_none; }
void setActiveDecorator(Decorator::Type t);
private:

View File

@@ -198,8 +198,20 @@ void ScrollView::ArrowDecorator::setBackgroundColor(KDColor c) {
}
}
ScrollView::Decorators::Decorators() {
/* We need to initiate the Union at construction to avoid destructing an
* uninitialized object when changing the decorator type. */
new (this) Decorator();
}
ScrollView::Decorators::~Decorators() {
activeDecorator()->~Decorator();
}
void ScrollView::Decorators::setActiveDecorator(Decorator::Type t) {
/* We do NOT need to destroy the previous decorator because they don't have a destructor */
/* Decorator destructor is virtual so calling ~Decorator() on a Decorator
* pointer will call the appropriate destructor. */
activeDecorator()->~Decorator();
switch (t) {
case Decorator::Type::Bars:
new (&m_bars) BarDecorator();