nsAutoLayoutPhase.cpp (3769B)
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/. */ 6 7 #ifndef DEBUG 8 static_assert(false, "This should not be compiled in !DEBUG"); 9 #endif // DEBUG 10 11 #include "nsAutoLayoutPhase.h" 12 13 #include "nsContentUtils.h" 14 #include "nsPresContext.h" 15 16 nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext, 17 nsLayoutPhase aPhase) 18 : mPresContext(aPresContext), mPhase(aPhase), mCount(0) { 19 Enter(); 20 } 21 22 nsAutoLayoutPhase::~nsAutoLayoutPhase() { 23 Exit(); 24 MOZ_ASSERT(mCount == 0, "imbalanced"); 25 } 26 27 void nsAutoLayoutPhase::Enter() { 28 switch (mPhase) { 29 case nsLayoutPhase::Paint: 30 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Paint] == 0, 31 "recurring into paint"); 32 MOZ_ASSERT( 33 mPresContext->mLayoutPhaseCount[nsLayoutPhase::DisplayListBuilding] == 34 0, 35 "recurring into paint from display list building"); 36 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Reflow] == 0, 37 "painting in the middle of reflow"); 38 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::FrameC] == 0, 39 "painting in the middle of frame construction"); 40 break; 41 case nsLayoutPhase::DisplayListBuilding: 42 // It's fine and expected to be in a paint here. 43 MOZ_ASSERT( 44 mPresContext->mLayoutPhaseCount[nsLayoutPhase::DisplayListBuilding] == 45 0, 46 "recurring into display list building"); 47 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Reflow] == 0, 48 "display list building in the middle of reflow"); 49 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::FrameC] == 0, 50 "display list building in the middle of frame construction"); 51 break; 52 case nsLayoutPhase::Reflow: 53 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Paint] == 0, 54 "reflowing in the middle of a paint"); 55 MOZ_ASSERT( 56 mPresContext->mLayoutPhaseCount[nsLayoutPhase::DisplayListBuilding] == 57 0, 58 "reflowing in the middle of a display list building"); 59 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Reflow] == 0, 60 "recurring into reflow"); 61 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::FrameC] == 0, 62 "reflowing in the middle of frame construction"); 63 break; 64 case nsLayoutPhase::FrameC: 65 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Paint] == 0, 66 "constructing frames in the middle of a paint"); 67 MOZ_ASSERT( 68 mPresContext->mLayoutPhaseCount[nsLayoutPhase::DisplayListBuilding] == 69 0, 70 "constructing frames in the middle of a display list building"); 71 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::Reflow] == 0, 72 "constructing frames in the middle of reflow"); 73 MOZ_ASSERT(mPresContext->mLayoutPhaseCount[nsLayoutPhase::FrameC] == 0, 74 "recurring into frame construction"); 75 MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(), 76 "constructing frames and scripts are not blocked"); 77 break; 78 case nsLayoutPhase::COUNT: 79 break; 80 } 81 82 ++(mPresContext->mLayoutPhaseCount[mPhase]); 83 ++mCount; 84 } 85 86 void nsAutoLayoutPhase::Exit() { 87 MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0, 88 "imbalanced"); 89 --(mPresContext->mLayoutPhaseCount[mPhase]); 90 --mCount; 91 }