Skip to content

Commit

Permalink
Bug 654989 part 1. Allow handing out both an nsIContent and an nsStyl…
Browse files Browse the repository at this point in the history
…eContext from CreateAnonymousContent. r=roc
  • Loading branch information
bzbarsky committed May 6, 2011
1 parent 6906061 commit af9e9e2
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 32 deletions.
18 changes: 10 additions & 8 deletions layout/base/nsCSSFrameConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3851,7 +3851,7 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState& aState,
PendingBinding* aPendingBinding,
nsFrameItems& aChildItems)
{
nsAutoTArray<nsIContent*, 4> newAnonymousItems;
nsAutoTArray<nsIAnonymousContentCreator::ContentInfo, 4> newAnonymousItems;
nsresult rv = GetAnonymousContent(aParent, aParentFrame, newAnonymousItems);
NS_ENSURE_SUCCESS(rv, rv);

Expand All @@ -3868,8 +3868,9 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState& aState,
"How can that happen if we have nodes to construct frames for?");

for (PRUint32 i=0; i < count; i++) {
nsIContent* content = newAnonymousItems[i];
nsIContent* content = newAnonymousItems[i].mContent;
NS_ASSERTION(content, "null anonymous content?");
NS_ASSERTION(!newAnonymousItems[i].mStyleContext, "Unexpected style context");

nsIFrame* newFrame = creator->CreateFrameFor(content);
if (newFrame) {
Expand All @@ -3889,7 +3890,7 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsFrameConstructorState& aState,
nsresult
nsCSSFrameConstructor::GetAnonymousContent(nsIContent* aParent,
nsIFrame* aParentFrame,
nsTArray<nsIContent*>& aContent)
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aContent)
{
nsIAnonymousContentCreator* creator = do_QueryFrame(aParentFrame);
if (!creator)
Expand All @@ -3901,7 +3902,7 @@ nsCSSFrameConstructor::GetAnonymousContent(nsIContent* aParent,
PRUint32 count = aContent.Length();
for (PRUint32 i=0; i < count; i++) {
// get our child's content and set its parent to our content
nsIContent* content = aContent[i];
nsIContent* content = aContent[i].mContent;
NS_ASSERTION(content, "null anonymous content?");

// least-surprise CSS binding until we do the SVG specified
Expand Down Expand Up @@ -9534,18 +9535,19 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState,
// Create any anonymous frames we need here. This must happen before the
// non-anonymous children are processed to ensure that popups are never
// constructed before the popupset.
nsAutoTArray<nsIContent*, 4> anonymousItems;
nsAutoTArray<nsIAnonymousContentCreator::ContentInfo, 4> anonymousItems;
GetAnonymousContent(aContent, aFrame, anonymousItems);
for (PRUint32 i = 0; i < anonymousItems.Length(); ++i) {
#ifdef DEBUG
nsIAnonymousContentCreator* creator = do_QueryFrame(aFrame);
NS_ASSERTION(!creator || !creator->CreateFrameFor(anonymousItems[i]),
NS_ASSERTION(!creator ||
!creator->CreateFrameFor(anonymousItems[i].mContent),
"If you need to use CreateFrameFor, you need to call "
"CreateAnonymousFrames manually and not follow the standard "
"ProcessChildren() codepath for this frame");
#endif
AddFrameConstructionItems(aState, anonymousItems[i], PR_TRUE, aFrame,
itemsToConstruct);
AddFrameConstructionItems(aState, anonymousItems[i].mContent, PR_TRUE,
aFrame, itemsToConstruct);
}

if (!aFrame->IsLeaf()) {
Expand Down
3 changes: 2 additions & 1 deletion layout/base/nsCSSFrameConstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "nsPageContentFrame.h"
#include "nsCSSPseudoElements.h"
#include "RestyleTracker.h"
#include "nsIAnonymousContentCreator.h"

class nsIDocument;
struct nsFrameItems;
Expand Down Expand Up @@ -1267,7 +1268,7 @@ class nsCSSFrameConstructor

nsresult GetAnonymousContent(nsIContent* aParent,
nsIFrame* aParentFrame,
nsTArray<nsIContent*>& aAnonContent);
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aAnonContent);

//MathML Mod - RBS
#ifdef MOZ_MATHML
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsComboboxControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ nsComboboxControlFrame::GetContentInsertionFrame() {
}

nsresult
nsComboboxControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsComboboxControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
// The frames used to display the combo box and the button used to popup the dropdown list
// are created through anonymous content. The dropdown list is not created through anonymous
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsComboboxControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class nsComboboxControlFrame : public nsBlockFrame,
NS_DECL_FRAMEARENA_HELPERS

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);
virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsFileControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ PRBool CapturePickerAcceptCallback(const nsAString& aAccept, void* aClosure)
}

nsresult
nsFileControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsFileControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
// Get the NodeInfoManager and tag necessary to create input elements
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsFileControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class nsFileControlFrame : public nsBlockFrame,


// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsGfxButtonControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ nsGfxButtonControlFrame::GetFrameName(nsAString& aResult) const
// Create the text content used as label for the button.
// The frame will be generated by the frame constructor.
nsresult
nsGfxButtonControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsGfxButtonControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
nsXPIDLString label;
GetLabel(label);
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsGfxButtonControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class nsGfxButtonControlFrame : public nsHTMLButtonControlFrame,
NS_DECL_QUERYFRAME

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);
virtual nsIFrame* CreateFrameFor(nsIContent* aContent);
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsIsIndexFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ nsIsIndexFrame::SetFocus(PRBool aOn, PRBool aRepaint)
}

nsresult
nsIsIndexFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsIsIndexFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
// Get the node info manager (used to create hr's and input's)
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsIsIndexFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class nsIsIndexFrame : public nsBlockFrame,
void SetFocus(PRBool aOn, PRBool aRepaint);

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsTextControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ nsTextControlFrame::EnsureEditorInitialized()
}

nsresult
nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
NS_ASSERTION(mContent, "We should have a content!");

Expand Down
2 changes: 1 addition & 1 deletion layout/forms/nsTextControlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class nsTextControlFrame : public nsStackFrame,
}

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down
7 changes: 4 additions & 3 deletions layout/generic/nsGfxScrollFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ nsHTMLScrollFrame::nsHTMLScrollFrame(nsIPresShell* aShell, nsStyleContext* aCont
}

nsresult
nsHTMLScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsHTMLScrollFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
return mInner.CreateAnonymousContent(aElements);
}
Expand Down Expand Up @@ -1024,7 +1024,7 @@ nsMargin nsGfxScrollFrameInner::GetDesiredScrollbarSizes(nsBoxLayoutState* aStat
}

nsresult
nsXULScrollFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsXULScrollFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
return mInner.CreateAnonymousContent(aElements);
}
Expand Down Expand Up @@ -2386,7 +2386,8 @@ nsGfxScrollFrameInner::ReloadChildFrames()
}

nsresult
nsGfxScrollFrameInner::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsGfxScrollFrameInner::CreateAnonymousContent(
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements)
{
nsPresContext* presContext = mOuter->PresContext();
nsIFrame* parent = mOuter->GetParent();
Expand Down
7 changes: 4 additions & 3 deletions layout/generic/nsGfxScrollFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class nsGfxScrollFrameInner : public nsIReflowCallback {
// We need this if a scrollbar frame is recreated.
void ReloadChildFrames();

nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
nsresult CreateAnonymousContent(
nsTArray<nsIAnonymousContentCreator::ContentInfo>& aElements);
void AppendAnonymousContentTo(nsBaseContentList& aElements, PRUint32 aFilter);
nsresult FireScrollPortEvent();
void PostOverflowEvent();
Expand Down Expand Up @@ -424,7 +425,7 @@ class nsHTMLScrollFrame : public nsHTMLContainerFrame,
}

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down Expand Up @@ -624,7 +625,7 @@ class nsXULScrollFrame : public nsBoxFrame,
}

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down
16 changes: 15 additions & 1 deletion layout/generic/nsIAnonymousContentCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include "nsQueryFrame.h"
#include "nsIContent.h"
#include "nsStyleContext.h"

class nsIFrame;
template <class T, class A> class nsTArray;
Expand All @@ -60,6 +61,19 @@ class nsIAnonymousContentCreator
public:
NS_DECL_QUERYFRAME_TARGET(nsIAnonymousContentCreator)

struct ContentInfo {
ContentInfo(nsIContent* aContent) :
mContent(aContent)
{}

ContentInfo(nsIContent* aContent, nsStyleContext* aStyleContext) :
mContent(aContent), mStyleContext(aStyleContext)
{}

nsIContent* mContent;
nsRefPtr<nsStyleContext> mStyleContext;
};

/**
* Creates "native" anonymous content and adds the created content to
* the aElements array. None of the returned elements can be nsnull.
Expand All @@ -69,7 +83,7 @@ class nsIAnonymousContentCreator
* from CreateAnonymousContent when appropriate (i.e. before releasing
* them).
*/
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements)=0;
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements)=0;

/**
* Appends "native" anonymous children created by CreateAnonymousContent()
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsVideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ NS_QUERYFRAME_HEAD(nsVideoFrame)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)

nsresult
nsVideoFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsVideoFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
nsNodeInfoManager *nodeInfoManager = GetContent()->GetCurrentDoc()->NodeInfoManager();
nsCOMPtr<nsINodeInfo> nodeInfo;
Expand Down
2 changes: 1 addition & 1 deletion layout/generic/nsVideoFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class nsVideoFrame : public nsContainerFrame, public nsIAnonymousContentCreator
return nsSplittableFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
}

virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilters);

Expand Down
4 changes: 2 additions & 2 deletions layout/svg/base/src/nsSVGUseFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class nsSVGUseFrame : public nsSVGUseFrameBase,
#endif

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);
};
Expand Down Expand Up @@ -171,7 +171,7 @@ nsSVGUseFrame::IsLeaf() const
// nsIAnonymousContentCreator methods:

nsresult
nsSVGUseFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsSVGUseFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
nsSVGUseElement *use = static_cast<nsSVGUseElement*>(mContent);

Expand Down
4 changes: 2 additions & 2 deletions layout/xul/base/src/nsDocElementBoxFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class nsDocElementBoxFrame : public nsBoxFrame,
NS_DECL_FRAMEARENA_HELPERS

// nsIAnonymousContentCreator
virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements);
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
PRUint32 aFilter);

Expand Down Expand Up @@ -110,7 +110,7 @@ nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
}

nsresult
nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
nsIDocument* doc = mContent->GetDocument();
if (!doc) {
Expand Down

0 comments on commit af9e9e2

Please sign in to comment.