Compact code - use a helper function for a re-usable chunk of code

git-svn-id: svn://10.0.0.236/trunk@112011 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
rbs%maths.uq.edu.au
2002-01-12 03:04:14 +00:00
parent de696ad435
commit 486cb07a88
4 changed files with 53 additions and 123 deletions

View File

@@ -775,6 +775,41 @@ CompressWhitespace(nsIContent* aContent)
}
}
/* static */ void
nsMathMLContainerFrame::GetPresentationDataFrom(nsIFrame* aFrame,
nsPresentationData& aPresentationData)
{
nsIFrame* frame = aFrame;
while (frame) {
nsIMathMLFrame* mathMLFrame;
frame->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
if (mathMLFrame) {
nsPresentationData presentationData;
mathMLFrame->GetPresentationData(presentationData);
aPresentationData.mstyle = presentationData.mstyle;
aPresentationData.scriptLevel = presentationData.scriptLevel;
if (NS_MATHML_IS_DISPLAYSTYLE(presentationData.flags)) {
aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
// stop if we reach the root <math> tag
nsCOMPtr<nsIAtom> tag;
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
content->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsMathMLAtoms::math) {
const nsStyleDisplay* display;
frame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
frame->GetParent(&frame);
}
}
// This method is called in a top-down manner, as we descend the frame tree
// during its construction
NS_IMETHODIMP
@@ -793,39 +828,8 @@ nsMathMLContainerFrame::Init(nsIPresContext* aPresContext,
nsresult rv;
rv = nsHTMLContainerFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// now, find our parent that implements the nsIMathMLFrame interface and inherit
// its scriptlevel and displaystyle. If the parent later wishes to increment
// with other values, it will do so in its SetInitialChildList() method.
nsIFrame* parent = aParent;
while (parent) {
nsIMathMLFrame* mathMLFrame;
parent->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
if (mathMLFrame) {
nsPresentationData parentData;
mathMLFrame->GetPresentationData(parentData);
mPresentationData.mstyle = parentData.mstyle;
mPresentationData.scriptLevel = parentData.scriptLevel;
if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
// stop if we reach the root <math> tag
nsCOMPtr<nsIAtom> parentTag;
nsCOMPtr<nsIContent> parentContent;
parent->GetContent(getter_AddRefs(parentContent));
parentContent->GetTag(*getter_AddRefs(parentTag));
if (parentTag.get() == nsMathMLAtoms::math) {
const nsStyleDisplay* display;
parent->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
parent->GetParent(&parent);
}
// now, inherit the scriptlevel and displaystyle from our parent
GetPresentationDataFrom(aParent, mPresentationData);
return rv;
}

View File

@@ -170,6 +170,14 @@ public:
// --------------------------------------------------------------------------
// Additional methods
// helper to get the presentation data of a frame. If we happen to
// be surrounded by non-MathML helper frames needed for our support,
// we walk up the frame hierarchy until we reach a MathML frame
// or the <root> math element.
static void
GetPresentationDataFrom(nsIFrame* aFrame,
nsPresentationData& aPresentationData);
// helper to get the preferred size that a container frame should use to fire
// the stretch on its stretchy child frames.
virtual void

View File

@@ -272,32 +272,11 @@ nsMathMLmstyleFrame::AttributeChanged(nsIPresContext* aPresContext,
// use the base method here because we really want to reflect any updates
nsMathMLContainerFrame::UpdatePresentationDataFromChildAt(aPresContext, 0, -1,
mPresentationData.scriptLevel - oldData.scriptLevel, newValues, whichFlags);
// now walk up to our immediate ancestor that implements the
// nsIMathMLFrame interface and grab its scriptlevel
PRInt32 parentScriptLevel = 0;
nsIFrame* parent = mParent;
while (parent) {
// if this frame is MathML frame, we are done
nsIMathMLFrame* mathMLFrame;
parent->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
if (mathMLFrame) {
nsPresentationData parentData;
mathMLFrame->GetPresentationData(parentData);
parentScriptLevel = parentData.scriptLevel;
break;
}
// stop if we reach the root <math> tag
nsCOMPtr<nsIAtom> parentTag;
nsCOMPtr<nsIContent> parentContent;
parent->GetContent(getter_AddRefs(parentContent));
parentContent->GetTag(*getter_AddRefs(parentTag));
if (parentTag.get() == nsMathMLAtoms::math) {
break;
}
parent->GetParent(&parent);
}
// now grab the scriptlevel of our parent
nsPresentationData parentData;
GetPresentationDataFrom(mParent, parentData);
// re-resolve style data in our subtree to sync any change of script sizes
PropagateScriptStyleFor(aPresContext, this, parentScriptLevel);
PropagateScriptStyleFor(aPresContext, this, parentData.scriptLevel);
}
}

View File

@@ -283,41 +283,10 @@ nsMathMLmtableOuterFrame::Init(nsIPresContext* aPresContext,
{
nsresult rv = nsTableOuterFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// now, if our parent implements the nsIMathMLFrame interface, we inherit
// its scriptlevel and displaystyle. If the parent later wishes to increment
// with other values, it will do so in its SetInitialChildList() method.
// XXX the REC says that by default, displaystyle=false in <mtable>
nsIFrame* parent = aParent;
while (parent) {
nsIMathMLFrame* mathMLFrame;
parent->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
if (mathMLFrame) {
nsPresentationData parentData;
mathMLFrame->GetPresentationData(parentData);
mPresentationData.mstyle = parentData.mstyle;
mPresentationData.scriptLevel = parentData.scriptLevel;
if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
// stop if we reach the root <math> tag
nsCOMPtr<nsIAtom> parentTag;
nsCOMPtr<nsIContent> parentContent;
parent->GetContent(getter_AddRefs(parentContent));
parentContent->GetTag(*getter_AddRefs(parentTag));
if (parentTag.get() == nsMathMLAtoms::math) {
const nsStyleDisplay* display;
parent->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
parent->GetParent(&parent);
}
// now, inherit the scriptlevel and displaystyle from our parent
nsMathMLContainerFrame::GetPresentationDataFrom(aParent, mPresentationData);
// see if the displaystyle attribute is there and let it override what we inherited
nsAutoString value;
@@ -474,38 +443,8 @@ nsMathMLmtdInnerFrame::Init(nsIPresContext* aPresContext,
// record that children that are ignorable whitespace should be excluded
mState |= NS_FRAME_EXCLUDE_IGNORABLE_WHITESPACE;
// now, get our outermost parent that implements the nsIMathMLFrame interface,
// we will inherit its scriptlevel and displaystyle. If that parent later wishes
// to increment with other values, it will do so in its SetInitialChildList() method.
nsIFrame* parent = aParent;
while (parent) {
nsIMathMLFrame* mathMLFrame;
parent->QueryInterface(NS_GET_IID(nsIMathMLFrame), (void**)&mathMLFrame);
if (mathMLFrame) {
nsPresentationData parentData;
mathMLFrame->GetPresentationData(parentData);
mPresentationData.mstyle = parentData.mstyle;
mPresentationData.scriptLevel = parentData.scriptLevel;
if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
// stop if we reach the root <math> tag
nsCOMPtr<nsIAtom> parentTag;
nsCOMPtr<nsIContent> parentContent;
parent->GetContent(getter_AddRefs(parentContent));
parentContent->GetTag(*getter_AddRefs(parentTag));
if (parentTag.get() == nsMathMLAtoms::math) {
const nsStyleDisplay* display;
parent->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
if (display->mDisplay == NS_STYLE_DISPLAY_BLOCK) {
mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE;
}
break;
}
parent->GetParent(&parent);
}
// now, inherit the scriptlevel and displaystyle from our parent
nsMathMLContainerFrame::GetPresentationDataFrom(aParent, mPresentationData);
return rv;
}