Bug 1492908 [wpt PR 13122] - Check completeness of images with and without srcset...
[gecko.git] / widget / nsAutoRollup.cpp
blob51d47c55d995b45e7777f1f6d6b9b4c261eb5bbf
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*/ 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;
20 sCount++;
23 nsAutoRollup::nsAutoRollup(nsIContent* aRollup)
25 MOZ_ASSERT(!sLastRollup);
26 mWasClear = true;
27 sCount++;
28 SetLastRollup(aRollup);
31 nsAutoRollup::~nsAutoRollup()
33 if (sLastRollup && mWasClear) {
34 sLastRollup = nullptr;
36 sCount--;
39 /*static*/ void
40 nsAutoRollup::SetLastRollup(nsIContent* aLastRollup)
42 // There must be at least one nsAutoRollup on the stack.
43 MOZ_ASSERT(sCount);
45 sLastRollup = aLastRollup;
48 /*static*/ nsIContent*
49 nsAutoRollup::GetLastRollup()
51 return sLastRollup.get();
54 } // namespace widget
55 } // namespace mozilla