1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "mozilla/widget/nsAutoRollup.h"
11 /*static*/ uint32_t nsAutoRollup::sCount
= 0;
12 /*static*/ StaticRefPtr
<nsIContent
> nsAutoRollup::sLastRollup
;
14 nsAutoRollup::nsAutoRollup()
16 // remember if sLastRollup was null, and only clear it upon destruction
17 // if so. This prevents recursive usage of nsAutoRollup from clearing
18 // sLastRollup when it shouldn't.
19 mWasClear
= !sLastRollup
;
23 nsAutoRollup::nsAutoRollup(nsIContent
* aRollup
)
25 MOZ_ASSERT(!sLastRollup
);
28 SetLastRollup(aRollup
);
31 nsAutoRollup::~nsAutoRollup()
33 if (sLastRollup
&& mWasClear
) {
34 sLastRollup
= nullptr;
40 nsAutoRollup::SetLastRollup(nsIContent
* aLastRollup
)
42 // There must be at least one nsAutoRollup on the stack.
45 sLastRollup
= aLastRollup
;
48 /*static*/ nsIContent
*
49 nsAutoRollup::GetLastRollup()
51 return sLastRollup
.get();
55 } // namespace mozilla