prevent double caption frame creation instead of later caption frame removal bug 265181 r/sr=bzabrsky

This commit is contained in:
bmlk%gmx.de 2004-10-25 12:31:02 +00:00
parent 72c748e28b
commit d630cce6b0
2 changed files with 48 additions and 58 deletions

View File

@ -8541,44 +8541,39 @@ nsCSSFrameConstructor::ContentAppended(nsPresContext* aPresContext,
// if the container is a table and a caption was appended, it needs to be put in
// the outer table frame's additional child list.
nsFrameItems captionItems;
nsFrameItems captionItems;
PRBool hasCaption = PR_FALSE;
if (nsLayoutAtoms::tableFrame == frameType) {
nsIFrame* outerTable = parentFrame->GetParent();
if (outerTable) {
if (outerTable->GetFirstChild(nsLayoutAtoms::captionList)) {
hasCaption = PR_TRUE;
}
}
}
PRUint32 i;
count = aContainer->GetChildCount();
for (i = aNewIndexInContainer; i < count; i++) {
nsIContent *childContent = aContainer->GetChildAt(i);
// construct a child of a table frame by putting it on a temporary list and then
// moving it into the appropriate list. This is more efficient than checking the display
// type of childContent. During the construction of a caption frame, the outer
// table frame will be used as its parent.
// lookup the table child frame type as it is much more difficult to remove a frame
// and all it descendants (abs. pos. for instance) than to prevent the frame creation.
if (nsLayoutAtoms::tableFrame == frameType) {
if (hasCaption) {
// Resolve the style context and get its display
nsRefPtr<nsStyleContext> childStyleContext;
childStyleContext = ResolveStyleContext(aPresContext, parentFrame,
childContent);
if (childStyleContext->GetStyleDisplay()->mDisplay == NS_STYLE_DISPLAY_TABLE_CAPTION)
continue; //don't create a table caption frame and its descendants
}
nsFrameItems tempItems;
ConstructFrame(shell, aPresContext, state, childContent, parentFrame, tempItems);
if (tempItems.childList) {
if (nsLayoutAtoms::tableCaptionFrame == tempItems.childList->GetType()) {
PRBool abortCaption = PR_FALSE;
// check if a caption already exists in captionItems, and if so, abort the caption
if (captionItems.childList) {
abortCaption = PR_TRUE;
}
else {
// check for a caption already appended to the outer table
nsIFrame* outerTable = parentFrame->GetParent();
if (outerTable) {
nsIFrame* existingCaption =
outerTable->GetFirstChild(nsLayoutAtoms::captionList);
if (existingCaption) {
abortCaption = PR_TRUE;
}
}
}
if (abortCaption) {
tempItems.childList->Destroy(aPresContext);
}
else {
captionItems.AddChild(tempItems.childList);
}
NS_ASSERTION(!captionItems.childList, "don't append twice a caption");
hasCaption = PR_TRUE; // remember that we have a caption now
captionItems.AddChild(tempItems.childList);
}
else {
frameItems.AddChild(tempItems.childList);

View File

@ -8541,44 +8541,39 @@ nsCSSFrameConstructor::ContentAppended(nsPresContext* aPresContext,
// if the container is a table and a caption was appended, it needs to be put in
// the outer table frame's additional child list.
nsFrameItems captionItems;
nsFrameItems captionItems;
PRBool hasCaption = PR_FALSE;
if (nsLayoutAtoms::tableFrame == frameType) {
nsIFrame* outerTable = parentFrame->GetParent();
if (outerTable) {
if (outerTable->GetFirstChild(nsLayoutAtoms::captionList)) {
hasCaption = PR_TRUE;
}
}
}
PRUint32 i;
count = aContainer->GetChildCount();
for (i = aNewIndexInContainer; i < count; i++) {
nsIContent *childContent = aContainer->GetChildAt(i);
// construct a child of a table frame by putting it on a temporary list and then
// moving it into the appropriate list. This is more efficient than checking the display
// type of childContent. During the construction of a caption frame, the outer
// table frame will be used as its parent.
// lookup the table child frame type as it is much more difficult to remove a frame
// and all it descendants (abs. pos. for instance) than to prevent the frame creation.
if (nsLayoutAtoms::tableFrame == frameType) {
if (hasCaption) {
// Resolve the style context and get its display
nsRefPtr<nsStyleContext> childStyleContext;
childStyleContext = ResolveStyleContext(aPresContext, parentFrame,
childContent);
if (childStyleContext->GetStyleDisplay()->mDisplay == NS_STYLE_DISPLAY_TABLE_CAPTION)
continue; //don't create a table caption frame and its descendants
}
nsFrameItems tempItems;
ConstructFrame(shell, aPresContext, state, childContent, parentFrame, tempItems);
if (tempItems.childList) {
if (nsLayoutAtoms::tableCaptionFrame == tempItems.childList->GetType()) {
PRBool abortCaption = PR_FALSE;
// check if a caption already exists in captionItems, and if so, abort the caption
if (captionItems.childList) {
abortCaption = PR_TRUE;
}
else {
// check for a caption already appended to the outer table
nsIFrame* outerTable = parentFrame->GetParent();
if (outerTable) {
nsIFrame* existingCaption =
outerTable->GetFirstChild(nsLayoutAtoms::captionList);
if (existingCaption) {
abortCaption = PR_TRUE;
}
}
}
if (abortCaption) {
tempItems.childList->Destroy(aPresContext);
}
else {
captionItems.AddChild(tempItems.childList);
}
NS_ASSERTION(!captionItems.childList, "don't append twice a caption");
hasCaption = PR_TRUE; // remember that we have a caption now
captionItems.AddChild(tempItems.childList);
}
else {
frameItems.AddChild(tempItems.childList);