1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 static_assert(false, "This should not be compiled in !DEBUG");
11 #include "nsAutoLayoutPhase.h"
12 #include "nsPresContext.h"
13 #include "nsContentUtils.h"
15 nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext
* aPresContext
,
17 : mPresContext(aPresContext
), mPhase(aPhase
), mCount(0) {
21 nsAutoLayoutPhase::~nsAutoLayoutPhase() {
23 MOZ_ASSERT(mCount
== 0, "imbalanced");
26 void nsAutoLayoutPhase::Enter() {
28 case nsLayoutPhase::Paint
:
29 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Paint
] == 0,
30 "recurring into paint");
32 mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::DisplayListBuilding
] ==
34 "recurring into paint from display list building");
35 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Reflow
] == 0,
36 "painting in the middle of reflow");
37 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::FrameC
] == 0,
38 "painting in the middle of frame construction");
40 case nsLayoutPhase::DisplayListBuilding
:
41 // It's fine and expected to be in a paint here.
43 mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::DisplayListBuilding
] ==
45 "recurring into display list building");
46 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Reflow
] == 0,
47 "display list building in the middle of reflow");
48 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::FrameC
] == 0,
49 "display list building in the middle of frame construction");
51 case nsLayoutPhase::Reflow
:
52 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Paint
] == 0,
53 "reflowing in the middle of a paint");
55 mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::DisplayListBuilding
] ==
57 "reflowing in the middle of a display list building");
58 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Reflow
] == 0,
59 "recurring into reflow");
60 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::FrameC
] == 0,
61 "reflowing in the middle of frame construction");
63 case nsLayoutPhase::FrameC
:
64 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Paint
] == 0,
65 "constructing frames in the middle of a paint");
67 mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::DisplayListBuilding
] ==
69 "constructing frames in the middle of a display list building");
70 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::Reflow
] == 0,
71 "constructing frames in the middle of reflow");
72 MOZ_ASSERT(mPresContext
->mLayoutPhaseCount
[nsLayoutPhase::FrameC
] == 0,
73 "recurring into frame construction");
74 MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
75 "constructing frames and scripts are not blocked");
77 case nsLayoutPhase::COUNT
:
81 ++(mPresContext
->mLayoutPhaseCount
[mPhase
]);
85 void nsAutoLayoutPhase::Exit() {
86 MOZ_ASSERT(mCount
> 0 && mPresContext
->mLayoutPhaseCount
[mPhase
] > 0,
88 --(mPresContext
->mLayoutPhaseCount
[mPhase
]);