Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / widget / nsAutoRollup.cpp
blob9a043576df562a41dd0a1b2b19ac9cc9a2e383cc
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"
8 namespace mozilla {
9 namespace widget {
11 /*static*/
12 uint32_t nsAutoRollup::sCount = 0;
13 /*static*/
14 StaticRefPtr<nsIContent> nsAutoRollup::sLastRollup;
16 nsAutoRollup::nsAutoRollup() {
17 // remember if sLastRollup was null, and only clear it upon destruction
18 // if so. This prevents recursive usage of nsAutoRollup from clearing
19 // sLastRollup when it shouldn't.
20 mWasClear = !sLastRollup;
21 sCount++;
24 nsAutoRollup::nsAutoRollup(nsIContent* aRollup) {
25 MOZ_ASSERT(!sLastRollup);
26 mWasClear = true;
27 sCount++;
28 SetLastRollup(aRollup);
31 nsAutoRollup::~nsAutoRollup() {
32 if (sLastRollup && mWasClear) {
33 sLastRollup = nullptr;
35 sCount--;
38 /*static*/
39 void nsAutoRollup::SetLastRollup(nsIContent* aLastRollup) {
40 // There must be at least one nsAutoRollup on the stack.
41 MOZ_ASSERT(sCount);
43 sLastRollup = aLastRollup;
46 /*static*/
47 nsIContent* nsAutoRollup::GetLastRollup() { return sLastRollup.get(); }
49 } // namespace widget
50 } // namespace mozilla