layout/base/nsAutoLayoutPhase.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial