michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef DEBUG michael@0: static_assert(false, "This should not be compiled in !DEBUG"); michael@0: #endif // DEBUG michael@0: michael@0: #include "nsAutoLayoutPhase.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsContentUtils.h" michael@0: michael@0: nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext, michael@0: nsLayoutPhase aPhase) michael@0: : mPresContext(aPresContext) michael@0: , mPhase(aPhase) michael@0: , mCount(0) michael@0: { michael@0: Enter(); michael@0: } michael@0: michael@0: nsAutoLayoutPhase::~nsAutoLayoutPhase() michael@0: { michael@0: Exit(); michael@0: MOZ_ASSERT(mCount == 0, "imbalanced"); michael@0: } michael@0: michael@0: void michael@0: nsAutoLayoutPhase::Enter() michael@0: { michael@0: switch (mPhase) { michael@0: case eLayoutPhase_Paint: michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0, michael@0: "recurring into paint"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0, michael@0: "painting in the middle of reflow"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0, michael@0: "painting in the middle of frame construction"); michael@0: break; michael@0: case eLayoutPhase_Reflow: michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0, michael@0: "reflowing in the middle of a paint"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0, michael@0: "recurring into reflow"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0, michael@0: "reflowing in the middle of frame construction"); michael@0: break; michael@0: case eLayoutPhase_FrameC: michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0, michael@0: "constructing frames in the middle of a paint"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0, michael@0: "constructing frames in the middle of reflow"); michael@0: MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0, michael@0: "recurring into frame construction"); michael@0: MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), michael@0: "constructing frames and scripts are not blocked"); michael@0: break; michael@0: case eLayoutPhase_COUNT: michael@0: break; michael@0: } michael@0: michael@0: ++(mPresContext->mLayoutPhaseCount[mPhase]); michael@0: ++mCount; michael@0: } michael@0: michael@0: void michael@0: nsAutoLayoutPhase::Exit() michael@0: { michael@0: MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0, michael@0: "imbalanced"); michael@0: --(mPresContext->mLayoutPhaseCount[mPhase]); michael@0: --mCount; michael@0: }