Bumping manifests a=b2g-bump
[gecko.git] / layout / base / nsAutoLayoutPhase.cpp
bloba20d541f8ce39ed9a486545bd8e87fb706f7eb20
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 #ifndef DEBUG
7 static_assert(false, "This should not be compiled in !DEBUG");
8 #endif // DEBUG
10 #include "nsAutoLayoutPhase.h"
11 #include "nsPresContext.h"
12 #include "nsContentUtils.h"
14 nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext,
15 nsLayoutPhase aPhase)
16 : mPresContext(aPresContext)
17 , mPhase(aPhase)
18 , mCount(0)
20 Enter();
23 nsAutoLayoutPhase::~nsAutoLayoutPhase()
25 Exit();
26 MOZ_ASSERT(mCount == 0, "imbalanced");
29 void
30 nsAutoLayoutPhase::Enter()
32 switch (mPhase) {
33 case eLayoutPhase_Paint:
34 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
35 "recurring into paint");
36 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
37 "painting in the middle of reflow");
38 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
39 "painting in the middle of frame construction");
40 break;
41 case eLayoutPhase_Reflow:
42 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
43 "reflowing in the middle of a paint");
44 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
45 "recurring into reflow");
46 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
47 "reflowing in the middle of frame construction");
48 break;
49 case eLayoutPhase_FrameC:
50 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
51 "constructing frames in the middle of a paint");
52 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
53 "constructing frames in the middle of reflow");
54 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
55 "recurring into frame construction");
56 MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
57 "constructing frames and scripts are not blocked");
58 break;
59 case eLayoutPhase_COUNT:
60 break;
63 ++(mPresContext->mLayoutPhaseCount[mPhase]);
64 ++mCount;
67 void
68 nsAutoLayoutPhase::Exit()
70 MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
71 "imbalanced");
72 --(mPresContext->mLayoutPhaseCount[mPhase]);
73 --mCount;