Added overloaded ConstructFrame() member function. Prep work for table

changes
This commit is contained in:
troy%netscape.com 1998-09-14 21:16:01 +00:00
Родитель 8c37a3839d
Коммит 805dafbcdf
3 изменённых файлов: 546 добавлений и 432 удалений

Просмотреть файл

@ -266,6 +266,17 @@ protected:
PRInt32 aAttrCount,
nsIHTMLAttributes*& aAttributes);
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree);
nsIFrame* ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext);
nsresult ProcessChildren(nsIPresContext* aPresContext,
nsIFrame* aFrame,
nsIContent* aContent,
@ -946,6 +957,174 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
return rv;
}
nsIFrame*
HTMLStyleSheetImpl::ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext)
{
nsIFrame* rootFrame;
nsIFrame* childList;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, aStyleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
return rootFrame;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree)
{
aFrameSubTree = nsnull;
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
#ifdef NS_DEBUG
nsIDocument* doc;
nsIContent* rootContent;
// Verify it's the root content object
aContent->GetDocument(doc);
rootContent = doc->GetRootContent();
NS_ASSERTION(rootContent == aContent, "unexpected content");
NS_RELEASE(doc);
NS_RELEASE(rootContent);
#endif
// Construct the root frame object
aFrameSubTree = ConstructRootFrame(aPresContext, aContent, aStyleContext);
} else {
nsIFrame* frame = nsnull;
nsIFrame* childList = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == aTag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == aTag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the child content
rv = ProcessChildren(aPresContext, frame, aContent, childList);
}
else if (nsHTMLAtoms::frameset == aTag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == aTag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == aTag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == aTag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == aTag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == aTag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == aTag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == aTag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == aTag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == aTag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == aTag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
aStyleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
default:
// Don't create any frame for content that's not displayed...
break;
}
if (NS_OK != rv) {
return rv;
}
}
if (nsnull != frame) {
// Set the style context
frame->SetStyleContext(aPresContext, aStyleContext);
// Initialize the frame giving it its child list
frame->Init(*aPresContext, childList);
}
aFrameSubTree = frame;
}
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
@ -955,8 +1134,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIAtom* tag;
aContent->GetTag(tag);
aFrameSubTree = nsnull;
// Resolve the style context.
// XXX Cheesy hack for text
nsIStyleContext* styleContext;
@ -966,151 +1143,12 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
styleContext = aPresContext->ResolveStyleContextFor(aContent, aParentFrame);
}
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
// XXX Add assertion...
nsIFrame* rootFrame;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, styleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
// Return the frame sub-tree
aFrameSubTree = rootFrame;
} else {
nsIFrame* frame = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == tag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == tag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
}
else if (nsHTMLAtoms::frameset == tag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == tag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == tag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == tag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == tag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == tag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == tag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == tag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == tag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == tag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == tag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
nsIFrame* childList;
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
styleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
default:
// XXX Don't create a placeholder frame for content that's not
// displayed...
#if 0
// Create an empty frame for holding content that is not being
// reflowed.
rv = nsFrame::NewFrame(&frame, aContent, aParentFrame);
#endif
break;
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
}
if (nsnull != frame) {
frame->SetStyleContext(aPresContext, styleContext);
}
aFrameSubTree = frame;
}
nsresult result = ConstructFrame(aPresContext, aContent, aParentFrame,
tag, styleContext, aFrameSubTree);
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return NS_OK;
return result;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,

Просмотреть файл

@ -266,6 +266,17 @@ protected:
PRInt32 aAttrCount,
nsIHTMLAttributes*& aAttributes);
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree);
nsIFrame* ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext);
nsresult ProcessChildren(nsIPresContext* aPresContext,
nsIFrame* aFrame,
nsIContent* aContent,
@ -946,6 +957,174 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
return rv;
}
nsIFrame*
HTMLStyleSheetImpl::ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext)
{
nsIFrame* rootFrame;
nsIFrame* childList;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, aStyleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
return rootFrame;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree)
{
aFrameSubTree = nsnull;
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
#ifdef NS_DEBUG
nsIDocument* doc;
nsIContent* rootContent;
// Verify it's the root content object
aContent->GetDocument(doc);
rootContent = doc->GetRootContent();
NS_ASSERTION(rootContent == aContent, "unexpected content");
NS_RELEASE(doc);
NS_RELEASE(rootContent);
#endif
// Construct the root frame object
aFrameSubTree = ConstructRootFrame(aPresContext, aContent, aStyleContext);
} else {
nsIFrame* frame = nsnull;
nsIFrame* childList = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == aTag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == aTag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the child content
rv = ProcessChildren(aPresContext, frame, aContent, childList);
}
else if (nsHTMLAtoms::frameset == aTag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == aTag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == aTag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == aTag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == aTag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == aTag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == aTag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == aTag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == aTag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == aTag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == aTag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
aStyleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
default:
// Don't create any frame for content that's not displayed...
break;
}
if (NS_OK != rv) {
return rv;
}
}
if (nsnull != frame) {
// Set the style context
frame->SetStyleContext(aPresContext, aStyleContext);
// Initialize the frame giving it its child list
frame->Init(*aPresContext, childList);
}
aFrameSubTree = frame;
}
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
@ -955,8 +1134,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIAtom* tag;
aContent->GetTag(tag);
aFrameSubTree = nsnull;
// Resolve the style context.
// XXX Cheesy hack for text
nsIStyleContext* styleContext;
@ -966,151 +1143,12 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
styleContext = aPresContext->ResolveStyleContextFor(aContent, aParentFrame);
}
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
// XXX Add assertion...
nsIFrame* rootFrame;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, styleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
// Return the frame sub-tree
aFrameSubTree = rootFrame;
} else {
nsIFrame* frame = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == tag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == tag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
}
else if (nsHTMLAtoms::frameset == tag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == tag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == tag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == tag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == tag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == tag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == tag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == tag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == tag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == tag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == tag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
nsIFrame* childList;
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
styleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
default:
// XXX Don't create a placeholder frame for content that's not
// displayed...
#if 0
// Create an empty frame for holding content that is not being
// reflowed.
rv = nsFrame::NewFrame(&frame, aContent, aParentFrame);
#endif
break;
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
}
if (nsnull != frame) {
frame->SetStyleContext(aPresContext, styleContext);
}
aFrameSubTree = frame;
}
nsresult result = ConstructFrame(aPresContext, aContent, aParentFrame,
tag, styleContext, aFrameSubTree);
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return NS_OK;
return result;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,

Просмотреть файл

@ -266,6 +266,17 @@ protected:
PRInt32 aAttrCount,
nsIHTMLAttributes*& aAttributes);
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree);
nsIFrame* ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext);
nsresult ProcessChildren(nsIPresContext* aPresContext,
nsIFrame* aFrame,
nsIContent* aContent,
@ -946,6 +957,174 @@ HTMLStyleSheetImpl::CreateInputFrame(nsIContent* aContent,
return rv;
}
nsIFrame*
HTMLStyleSheetImpl::ConstructRootFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aStyleContext)
{
nsIFrame* rootFrame;
nsIFrame* childList;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, aStyleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
return rootFrame;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIAtom* aTag,
nsIStyleContext* aStyleContext,
nsIFrame*& aFrameSubTree)
{
aFrameSubTree = nsnull;
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
#ifdef NS_DEBUG
nsIDocument* doc;
nsIContent* rootContent;
// Verify it's the root content object
aContent->GetDocument(doc);
rootContent = doc->GetRootContent();
NS_ASSERTION(rootContent == aContent, "unexpected content");
NS_RELEASE(doc);
NS_RELEASE(rootContent);
#endif
// Construct the root frame object
aFrameSubTree = ConstructRootFrame(aPresContext, aContent, aStyleContext);
} else {
nsIFrame* frame = nsnull;
nsIFrame* childList = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == aTag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == aTag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the child content
rv = ProcessChildren(aPresContext, frame, aContent, childList);
}
else if (nsHTMLAtoms::frameset == aTag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == aTag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == aTag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == aTag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == aTag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == aTag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == aTag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == aTag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == aTag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == aTag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == aTag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == aTag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
aStyleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
// Process the child content
ProcessChildren(aPresContext, frame, aContent, childList);
break;
default:
// Don't create any frame for content that's not displayed...
break;
}
if (NS_OK != rv) {
return rv;
}
}
if (nsnull != frame) {
// Set the style context
frame->SetStyleContext(aPresContext, aStyleContext);
// Initialize the frame giving it its child list
frame->Init(*aPresContext, childList);
}
aFrameSubTree = frame;
}
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
@ -955,8 +1134,6 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
nsIAtom* tag;
aContent->GetTag(tag);
aFrameSubTree = nsnull;
// Resolve the style context.
// XXX Cheesy hack for text
nsIStyleContext* styleContext;
@ -966,151 +1143,12 @@ NS_IMETHODIMP HTMLStyleSheetImpl::ConstructFrame(nsIPresContext* aPresContext,
styleContext = aPresContext->ResolveStyleContextFor(aContent, aParentFrame);
}
// Create a frame.
if (nsnull == aParentFrame) {
// This should only be the case for the root content object.
// XXX Add assertion...
nsIFrame* rootFrame;
// Create the root frame and set its style context
NS_NewHTMLFrame(aContent, nsnull, rootFrame);
rootFrame->SetStyleContext(aPresContext, styleContext);
// Bind root frame to root view (and root window)
nsIPresShell* presShell = aPresContext->GetShell();
nsIViewManager* viewManager = presShell->GetViewManager();
nsIView* rootView;
NS_RELEASE(presShell);
viewManager->GetRootView(rootView);
rootFrame->SetView(rootView);
NS_RELEASE(viewManager);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, rootFrame, aContent, childList);
rootFrame->Init(*aPresContext, childList);
// Return the frame sub-tree
aFrameSubTree = rootFrame;
} else {
nsIFrame* frame = nsnull;
nsresult rv = NS_OK;
// Handle specific frame types
if (nsnull == tag) {
rv = NS_NewTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::applet == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::body == tag) {
rv = NS_NewBodyFrame(aContent, aParentFrame, frame);
// Process the children and initialize the frame
nsIFrame* childList;
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
}
else if (nsHTMLAtoms::frameset == tag) {
rv = NS_NewHTMLFramesetFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::br == tag) {
rv = NS_NewBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::embed == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::hr == tag) {
rv = NS_NewHRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::img == tag) {
rv = NS_NewImageFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::object == tag) {
rv = NS_NewObjectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::spacer == tag) {
rv = NS_NewSpacerFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::wbr == tag) {
rv = NS_NewWBRFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::table == tag) {
rv = nsTableOuterFrame::NewFrame(&frame, aContent, aParentFrame);
}
else if (nsHTMLAtoms::input == tag) {
rv = CreateInputFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::textarea == tag) {
rv = NS_NewInputTextFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::select == tag) {
rv = NS_NewHTMLSelectFrame(aContent, aParentFrame, frame);
}
else if (nsHTMLAtoms::iframe == tag) {
rv = NS_NewHTMLFrameOuterFrame(aContent, aParentFrame, frame);
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
// XXX add code in here to force the odd ones into the empty frame?
// AREA, HEAD, META, MAP, etc...
if (nsnull == frame) {
nsIFrame* childList;
// When there is no explicit frame to create, assume it's a
// container and let style dictate the rest.
const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*)
styleContext->GetStyleData(eStyleStruct_Display);
// Use style to choose what kind of frame to create
nsresult rv;
switch (styleDisplay->mDisplay) {
case NS_STYLE_DISPLAY_BLOCK:
case NS_STYLE_DISPLAY_LIST_ITEM:
rv = NS_NewCSSBlockFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
case NS_STYLE_DISPLAY_INLINE:
rv = NS_NewCSSInlineFrame(&frame, aContent, aParentFrame);
ProcessChildren(aPresContext, frame, aContent, childList);
frame->Init(*aPresContext, childList);
break;
default:
// XXX Don't create a placeholder frame for content that's not
// displayed...
#if 0
// Create an empty frame for holding content that is not being
// reflowed.
rv = nsFrame::NewFrame(&frame, aContent, aParentFrame);
#endif
break;
}
if (NS_OK != rv) {
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return rv;
}
}
if (nsnull != frame) {
frame->SetStyleContext(aPresContext, styleContext);
}
aFrameSubTree = frame;
}
nsresult result = ConstructFrame(aPresContext, aContent, aParentFrame,
tag, styleContext, aFrameSubTree);
NS_RELEASE(styleContext);
NS_IF_RELEASE(tag);
return NS_OK;
return result;
}
NS_IMETHODIMP HTMLStyleSheetImpl::ContentAppended(nsIPresContext* aPresContext,