Line data Source code
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/. */
5 :
6 : #ifndef DEBUG
7 : static_assert(false, "This should not be compiled in !DEBUG");
8 : #endif // DEBUG
9 :
10 : #include "nsAutoLayoutPhase.h"
11 : #include "nsPresContext.h"
12 : #include "nsContentUtils.h"
13 :
14 298 : nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext,
15 298 : nsLayoutPhase aPhase)
16 : : mPresContext(aPresContext)
17 : , mPhase(aPhase)
18 298 : , mCount(0)
19 : {
20 298 : Enter();
21 298 : }
22 :
23 596 : nsAutoLayoutPhase::~nsAutoLayoutPhase()
24 : {
25 298 : Exit();
26 298 : MOZ_ASSERT(mCount == 0, "imbalanced");
27 298 : }
28 :
29 : void
30 478 : nsAutoLayoutPhase::Enter()
31 : {
32 478 : switch (mPhase) {
33 : case eLayoutPhase_Paint:
34 29 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
35 : "recurring into paint");
36 29 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
37 : "painting in the middle of reflow");
38 29 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
39 : "painting in the middle of frame construction");
40 29 : break;
41 : case eLayoutPhase_Reflow:
42 68 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
43 : "reflowing in the middle of a paint");
44 68 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
45 : "recurring into reflow");
46 68 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
47 : "reflowing in the middle of frame construction");
48 68 : break;
49 : case eLayoutPhase_FrameC:
50 381 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
51 : "constructing frames in the middle of a paint");
52 381 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
53 : "constructing frames in the middle of reflow");
54 381 : MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
55 : "recurring into frame construction");
56 381 : MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
57 : "constructing frames and scripts are not blocked");
58 381 : break;
59 : case eLayoutPhase_COUNT:
60 0 : break;
61 : }
62 :
63 478 : ++(mPresContext->mLayoutPhaseCount[mPhase]);
64 478 : ++mCount;
65 478 : }
66 :
67 : void
68 478 : nsAutoLayoutPhase::Exit()
69 : {
70 478 : MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
71 : "imbalanced");
72 478 : --(mPresContext->mLayoutPhaseCount[mPhase]);
73 478 : --mCount;
74 478 : }
|