Bug 833009 - Remove "nsContentUtils.h" inclusions from headers in layout/. r=bz

This commit is contained in:
Mounir Lamouri 2013-01-23 19:37:17 +00:00
parent 0541536fd8
commit 294b57c3ed
6 changed files with 119 additions and 82 deletions

View File

@ -118,6 +118,12 @@ CPPSRCS += \
$(NULL)
endif
ifdef MOZ_DEBUG
CPPSRCS += \
nsAutoLayoutPhase.cpp \
$(NULL)
endif
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef DEBUG
MOZ_STATIC_ASSERT(false, "This should not be compiled in !DEBUG");
#endif // DEBUG
#include "nsAutoLayoutPhase.h"
#include "nsPresContext.h"
#include "nsContentUtils.h"
nsAutoLayoutPhase::nsAutoLayoutPhase(nsPresContext* aPresContext,
nsLayoutPhase aPhase)
: mPresContext(aPresContext)
, mPhase(aPhase)
, mCount(0)
{
Enter();
}
nsAutoLayoutPhase::~nsAutoLayoutPhase()
{
Exit();
MOZ_ASSERT(mCount == 0, "imbalanced");
}
void
nsAutoLayoutPhase::Enter()
{
switch (mPhase) {
case eLayoutPhase_Paint:
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"recurring into paint");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"painting in the middle of reflow");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"painting in the middle of frame construction");
break;
case eLayoutPhase_Reflow:
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"reflowing in the middle of a paint");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"recurring into reflow");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"reflowing in the middle of frame construction");
break;
case eLayoutPhase_FrameC:
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"constructing frames in the middle of a paint");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"constructing frames in the middle of reflow");
MOZ_ASSERT(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"recurring into frame construction");
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
"constructing frames and scripts are not blocked");
break;
case eLayoutPhase_COUNT:
break;
}
++(mPresContext->mLayoutPhaseCount[mPhase]);
++mCount;
}
void
nsAutoLayoutPhase::Exit()
{
MOZ_ASSERT(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
"imbalanced");
--(mPresContext->mLayoutPhaseCount[mPhase]);
--mCount;
}

View File

@ -7,65 +7,16 @@
#ifdef DEBUG
// We can't forward declare an enum before C++11 which means we have to include
// nsPresContext.h just because nsLayoutPhase is passed to the ctor.
#include "nsPresContext.h"
#include "nsContentUtils.h"
struct nsAutoLayoutPhase {
nsAutoLayoutPhase(nsPresContext* aPresContext, nsLayoutPhase aPhase)
: mPresContext(aPresContext), mPhase(aPhase), mCount(0)
{
Enter();
}
nsAutoLayoutPhase(nsPresContext* aPresContext, nsLayoutPhase aPhase);
~nsAutoLayoutPhase();
~nsAutoLayoutPhase()
{
Exit();
NS_ASSERTION(mCount == 0, "imbalanced");
}
void Enter()
{
switch (mPhase) {
case eLayoutPhase_Paint:
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"recurring into paint");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"painting in the middle of reflow");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"painting in the middle of frame construction");
break;
case eLayoutPhase_Reflow:
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"reflowing in the middle of a paint");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"recurring into reflow");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"reflowing in the middle of frame construction");
break;
case eLayoutPhase_FrameC:
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Paint] == 0,
"constructing frames in the middle of a paint");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_Reflow] == 0,
"constructing frames in the middle of reflow");
NS_ASSERTION(mPresContext->mLayoutPhaseCount[eLayoutPhase_FrameC] == 0,
"recurring into frame construction");
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
"constructing frames and scripts are not blocked");
break;
default:
break;
}
++(mPresContext->mLayoutPhaseCount[mPhase]);
++mCount;
}
void Exit()
{
NS_ASSERTION(mCount > 0 && mPresContext->mLayoutPhaseCount[mPhase] > 0,
"imbalanced");
--(mPresContext->mLayoutPhaseCount[mPhase]);
--mCount;
}
void Enter();
void Exit();
private:
nsPresContext* mPresContext;
@ -84,7 +35,7 @@ private:
autoLayoutPhase.Enter(); \
PR_END_MACRO
#else
#else // DEBUG
#define AUTO_LAYOUT_PHASE_ENTRY_POINT(pc_, phase_) \
PR_BEGIN_MACRO PR_END_MACRO
@ -93,6 +44,6 @@ private:
#define LAYOUT_PHASE_TEMP_REENTER() \
PR_BEGIN_MACRO PR_END_MACRO
#endif
#endif // DEBUG
#endif // nsAutoLayoutPhase_h

View File

@ -33,7 +33,7 @@
#include "nsPresArena.h"
#include "nsFrameSelection.h"
#include "nsGUIEvent.h"
#include "nsContentUtils.h"
#include "nsContentUtils.h" // For AddScriptBlocker().
#include "nsRefreshDriver.h"
#include "mozilla/Attributes.h"

View File

@ -72,8 +72,8 @@
#include "nsPresState.h"
#include "nsContentList.h"
#include "nsAttrValueInlines.h"
#include "mozilla/Selection.h"
#include "nsContentUtils.h"
#define DEFAULT_COLUMN_WIDTH 20
@ -1494,3 +1494,31 @@ nsTextControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
return NS_OK;
}
NS_IMETHODIMP
nsTextControlFrame::EditorInitializer::Run()
{
if (!mFrame) {
return NS_OK;
}
// Need to block script to avoid bug 669767.
nsAutoScriptBlocker scriptBlocker;
nsCOMPtr<nsIPresShell> shell =
mFrame->PresContext()->GetPresShell();
bool observes = shell->ObservesNativeAnonMutationsForPrint();
shell->ObserveNativeAnonMutationsForPrint(true);
// This can cause the frame to be destroyed (and call Revoke()).
mFrame->EnsureEditorInitialized();
shell->ObserveNativeAnonMutationsForPrint(observes);
// The frame can *still* be destroyed even though we have a scriptblocker,
// bug 682684.
if (!mFrame) {
return NS_ERROR_FAILURE;
}
mFrame->FinishedInitializer();
return NS_OK;
}

View File

@ -17,7 +17,6 @@
#include "nsStubMutationObserver.h"
#include "nsITextControlElement.h"
#include "nsIStatefulFrame.h"
#include "nsContentUtils.h" // nsAutoScriptBlocker
#include "nsIEditor.h"
class nsISelectionController;
@ -246,28 +245,7 @@ protected:
EditorInitializer(nsTextControlFrame* aFrame) :
mFrame(aFrame) {}
NS_IMETHOD Run() {
if (mFrame) {
// need to block script to avoid bug 669767
nsAutoScriptBlocker scriptBlocker;
nsCOMPtr<nsIPresShell> shell =
mFrame->PresContext()->GetPresShell();
bool observes = shell->ObservesNativeAnonMutationsForPrint();
shell->ObserveNativeAnonMutationsForPrint(true);
// This can cause the frame to be destroyed (and call Revoke())
mFrame->EnsureEditorInitialized();
shell->ObserveNativeAnonMutationsForPrint(observes);
// The frame can *still* be destroyed even though we have a scriptblocker
// Bug 682684
if (!mFrame)
return NS_ERROR_FAILURE;
mFrame->FinishedInitializer();
}
return NS_OK;
}
NS_IMETHOD Run();
// avoids use of nsWeakFrame
void Revoke() {