layout/base/nsAutoLayoutPhase.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/base/nsAutoLayoutPhase.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef DEBUG
    1.10 +static_assert(false, "This should not be compiled in !DEBUG");
    1.11 +#endif // DEBUG
    1.12 +
    1.13 +#include "nsAutoLayoutPhase.h"
    1.14 +#include "nsPresContext.h"
    1.15 +#include "nsContentUtils.h"
    1.16 +
    1.17 +nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext,
    1.18 +                                     nsLayoutPhase aPhase)
    1.19 +  : mPresContext(aPresContext)
    1.20 +  , mPhase(aPhase)
    1.21 +  , mCount(0)
    1.22 +{
    1.23 +  Enter();
    1.24 +}
    1.25 +
    1.26 +nsAutoLayoutPhase::~nsAutoLayoutPhase()
    1.27 +{
    1.28 +  Exit();
    1.29 +  MOZ_ASSERT(mCount == 0, "imbalanced");
    1.30 +}
    1.31 +
    1.32 +void
    1.33 +nsAutoLayoutPhase::Enter()
    1.34 +{
    1.35 +  switch (mPhase) {
    1.36 +    case eLayoutPhase_Paint:
    1.37 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
    1.38 +                 "recurring into paint");
    1.39 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
    1.40 +                 "painting in the middle of reflow");
    1.41 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
    1.42 +                 "painting in the middle of frame construction");
    1.43 +      break;
    1.44 +    case eLayoutPhase_Reflow:
    1.45 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
    1.46 +                 "reflowing in the middle of a paint");
    1.47 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
    1.48 +                 "recurring into reflow");
    1.49 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
    1.50 +                 "reflowing in the middle of frame construction");
    1.51 +      break;
    1.52 +    case eLayoutPhase_FrameC:
    1.53 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
    1.54 +                 "constructing frames in the middle of a paint");
    1.55 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
    1.56 +                 "constructing frames in the middle of reflow");
    1.57 +      MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
    1.58 +                 "recurring into frame construction");
    1.59 +      MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
    1.60 +                 "constructing frames and scripts are not blocked");
    1.61 +      break;
    1.62 +    case eLayoutPhase_COUNT:
    1.63 +      break;
    1.64 +  }
    1.65 +
    1.66 +  ++(mPresContext->mLayoutPhaseCount[mPhase]);
    1.67 +  ++mCount;
    1.68 +}
    1.69 +
    1.70 +void
    1.71 +nsAutoLayoutPhase::Exit()
    1.72 +{
    1.73 +  MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
    1.74 +             "imbalanced");
    1.75 +  --(mPresContext->mLayoutPhaseCount[mPhase]);
    1.76 +  --mCount;
    1.77 +}

mercurial