Bug 1489588 - Disallow nsDisplayList copies and implement moves r=mattwoodrow

Summary:
nsDisplayLists are currently a little bit error prone, since the
empty state of an nsDisplayList requires mTop == &mSentinel.
since &mSentinel will change when copied, while mTop won't,
this naturally creates an invalid state. Additionally, copies
don't quite make sense, since there is a requirement in the
destructor that destructed nsDisplayLists are empty - in which
case we would have to empty both the copied and the original
nsDisplayList - something which is unlikely to happen naturally.
Moves however are a natural operation - we just need to implement
the correct move behavior accounting for this mTop == &mSentinel
requirement.

Reviewers: mattwoodrow

Reviewed By: mattwoodrow

Bug #: 1489588

Differential Revision: https://phabricator.services.mozilla.com/D5293

--HG--
extra : rebase_source : e8889903c6cd03a8ec0ff90f189dbdcc79201eb3
extra : histedit_source : 9e0e18702e6e4b4feb5bea0548dc42250905f897
This commit is contained in:
Doug Thayer 2018-09-11 04:29:38 +03:00
parent 5826bb91b9
commit ebc62f01e4

View File

@ -3254,6 +3254,40 @@ public:
}
}
nsDisplayList(nsDisplayList&& aOther)
{
mIsOpaque = aOther.mIsOpaque;
mForceTransparentSurface = aOther.mForceTransparentSurface;
if (aOther.mSentinel.mAbove) {
AppendToTop(&aOther);
} else {
mTop = &mSentinel;
mLength = 0;
}
}
nsDisplayList& operator=(nsDisplayList&& aOther)
{
if (this != &aOther) {
if (aOther.mSentinel.mAbove) {
nsDisplayList tmp;
tmp.AppendToTop(&aOther);
aOther.AppendToTop(this);
AppendToTop(&tmp);
} else {
mTop = &mSentinel;
mLength = 0;
}
mIsOpaque = aOther.mIsOpaque;
mForceTransparentSurface = aOther.mForceTransparentSurface;
}
return *this;
}
nsDisplayList(const nsDisplayList&) = delete;
nsDisplayList& operator=(const nsDisplayList& aOther) = delete;
/**
* Append an item to the top of the list. The item must not currently
* be in a list and cannot be null.