1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is mozilla.org code.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * the Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2006
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (original author)
23 : * Timothy Nikkel <tnikkel@gmail.com>
24 : * Boris Zbarsky <bzbarsky@mit.edu>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsAutoLayoutPhase_h
41 : #define nsAutoLayoutPhase_h
42 :
43 : #ifdef DEBUG
44 :
45 : #include "nsPresContext.h"
46 : #include "nsContentUtils.h"
47 :
48 : struct nsAutoLayoutPhase {
49 0 : nsAutoLayoutPhase(nsPresContext* aPresContext, nsLayoutPhase aPhase)
50 0 : : mPresContext(aPresContext), mPhase(aPhase), mCount(0)
51 : {
52 0 : Enter();
53 0 : }
54 :
55 0 : ~nsAutoLayoutPhase()
56 : {
57 0 : Exit();
58 0 : NS_ASSERTION(mCount == 0, "imbalanced");
59 0 : }
60 :
61 0 : void Enter()
62 : {
63 0 : switch (mPhase) {
64 : case eLayoutPhase_Paint:
65 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
66 : "recurring into paint");
67 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
68 : "painting in the middle of reflow");
69 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
70 : "painting in the middle of frame construction");
71 0 : break;
72 : case eLayoutPhase_Reflow:
73 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
74 : "reflowing in the middle of a paint");
75 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
76 : "recurring into reflow");
77 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
78 : "reflowing in the middle of frame construction");
79 0 : break;
80 : case eLayoutPhase_FrameC:
81 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
82 : "constructing frames in the middle of a paint");
83 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
84 : "constructing frames in the middle of reflow");
85 0 : NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
86 : "recurring into frame construction");
87 0 : NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
88 : "constructing frames and scripts are not blocked");
89 0 : break;
90 : default:
91 0 : break;
92 : }
93 0 : ++(mPresContext->mLayoutPhaseCount[mPhase]);
94 0 : ++mCount;
95 0 : }
96 :
97 0 : void Exit()
98 : {
99 0 : NS_ASSERTION(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
100 : "imbalanced");
101 0 : --(mPresContext->mLayoutPhaseCount[mPhase]);
102 0 : --mCount;
103 0 : }
104 :
105 : private:
106 : nsPresContext* mPresContext;
107 : nsLayoutPhase mPhase;
108 : PRUint32 mCount;
109 : };
110 :
111 : #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
112 : nsAutoLayoutPhase autoLayoutPhase((pc_), (eLayoutPhase_##phase_))
113 : #define LAYOUT_PHASE_TEMP_EXIT() \
114 : PR_BEGIN_MACRO \
115 : autoLayoutPhase.Exit(); \
116 : PR_END_MACRO
117 : #define LAYOUT_PHASE_TEMP_REENTER() \
118 : PR_BEGIN_MACRO \
119 : autoLayoutPhase.Enter(); \
120 : PR_END_MACRO
121 :
122 : #else
123 :
124 : #define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
125 : PR_BEGIN_MACRO PR_END_MACRO
126 : #define LAYOUT_PHASE_TEMP_EXIT() \
127 : PR_BEGIN_MACRO PR_END_MACRO
128 : #define LAYOUT_PHASE_TEMP_REENTER() \
129 : PR_BEGIN_MACRO PR_END_MACRO
130 :
131 : #endif
132 :
133 : #endif // nsAutoLayoutPhase_h
|