2017-03-13 14:44:56 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/widget/nsAutoRollup.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2019-02-25 22:13:48 +00:00
|
|
|
/*static*/
|
|
|
|
uint32_t nsAutoRollup::sCount = 0;
|
|
|
|
/*static*/
|
|
|
|
StaticRefPtr<nsIContent> nsAutoRollup::sLastRollup;
|
2017-03-13 14:44:56 +00:00
|
|
|
|
|
|
|
nsAutoRollup::nsAutoRollup() {
|
|
|
|
// remember if sLastRollup was null, and only clear it upon destruction
|
|
|
|
// if so. This prevents recursive usage of nsAutoRollup from clearing
|
|
|
|
// sLastRollup when it shouldn't.
|
|
|
|
mWasClear = !sLastRollup;
|
|
|
|
sCount++;
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:44:59 +00:00
|
|
|
nsAutoRollup::nsAutoRollup(nsIContent* aRollup) {
|
|
|
|
MOZ_ASSERT(!sLastRollup);
|
|
|
|
mWasClear = true;
|
|
|
|
sCount++;
|
|
|
|
SetLastRollup(aRollup);
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:44:56 +00:00
|
|
|
nsAutoRollup::~nsAutoRollup() {
|
|
|
|
if (sLastRollup && mWasClear) {
|
|
|
|
sLastRollup = nullptr;
|
|
|
|
}
|
|
|
|
sCount--;
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:13:48 +00:00
|
|
|
/*static*/
|
|
|
|
void nsAutoRollup::SetLastRollup(nsIContent* aLastRollup) {
|
2017-03-13 14:44:56 +00:00
|
|
|
// There must be at least one nsAutoRollup on the stack.
|
|
|
|
MOZ_ASSERT(sCount);
|
|
|
|
|
|
|
|
sLastRollup = aLastRollup;
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:13:48 +00:00
|
|
|
/*static*/
|
|
|
|
nsIContent* nsAutoRollup::GetLastRollup() { return sLastRollup.get(); }
|
2017-03-13 14:44:56 +00:00
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|