diff --git a/layout/mathml/nsIMathMLFrame.h b/layout/mathml/nsIMathMLFrame.h index d7a13d18bc6..b8c79532e30 100644 --- a/layout/mathml/nsIMathMLFrame.h +++ b/layout/mathml/nsIMathMLFrame.h @@ -330,6 +330,9 @@ struct nsPresentationData { // This bit is set if the frame is "space-like", as defined by the spec. #define NS_MATHML_SPACE_LIKE 0x00000040U +// This bit is set if the directionality of the frame is right-to-left +#define NS_MATHML_RTL 0x00000080U + // This bit is set when the frame cannot be formatted due to an // error (e.g., invalid markup such as a without an overscript). // When set, a visual feedback will be provided to the user. @@ -364,6 +367,9 @@ struct nsPresentationData { #define NS_MATHML_IS_SPACE_LIKE(_flags) \ (NS_MATHML_SPACE_LIKE == ((_flags) & NS_MATHML_SPACE_LIKE)) +#define NS_MATHML_IS_RTL(_flags) \ + (NS_MATHML_RTL == ((_flags) & NS_MATHML_RTL)) + #define NS_MATHML_HAS_ERROR(_flags) \ (NS_MATHML_ERROR == ((_flags) & NS_MATHML_ERROR)) diff --git a/layout/mathml/nsMathMLFrame.cpp b/layout/mathml/nsMathMLFrame.cpp index 6ea32a03632..8e23f823198 100644 --- a/layout/mathml/nsMathMLFrame.cpp +++ b/layout/mathml/nsMathMLFrame.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Roger B. Sidje + * Frederic Wang * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -88,6 +89,37 @@ nsMathMLFrame::FindAttrDisplaystyle(nsIContent* aContent, // no reset if the attr isn't found. so be sure to call it on inherited flags } +// snippet of code used by the tags where the dir attribute is allowed. +/* static */ void +nsMathMLFrame::FindAttrDirectionality(nsIContent* aContent, + nsPresentationData& aPresentationData) +{ + NS_ASSERTION(aContent->Tag() == nsGkAtoms::math || + aContent->Tag() == nsGkAtoms::mrow_ || + aContent->Tag() == nsGkAtoms::mstyle_ || + aContent->Tag() == nsGkAtoms::mi_ || + aContent->Tag() == nsGkAtoms::mn_ || + aContent->Tag() == nsGkAtoms::mo_ || + aContent->Tag() == nsGkAtoms::mtext_ || + aContent->Tag() == nsGkAtoms::ms_, "bad caller"); + + static nsIContent::AttrValuesArray strings[] = + {&nsGkAtoms::ltr, &nsGkAtoms::rtl, nsnull}; + + // see if the explicit dir attribute is there + switch (aContent->FindAttrValueIn(kNameSpaceID_None, + nsGkAtoms::dir, strings, eCaseMatters)) + { + case 0: + aPresentationData.flags &= ~NS_MATHML_RTL; + break; + case 1: + aPresentationData.flags |= NS_MATHML_RTL; + break; + } + // no reset if the attr isn't found. so be sure to call it on inherited flags +} + NS_IMETHODIMP nsMathMLFrame::InheritAutomaticData(nsIFrame* aParent) { @@ -108,6 +140,9 @@ nsMathMLFrame::InheritAutomaticData(nsIFrame* aParent) if (NS_MATHML_IS_DISPLAYSTYLE(parentData.flags)) { mPresentationData.flags |= NS_MATHML_DISPLAYSTYLE; } + if (NS_MATHML_IS_RTL(parentData.flags)) { + mPresentationData.flags |= NS_MATHML_RTL; + } #if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX) mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS; @@ -120,6 +155,10 @@ NS_IMETHODIMP nsMathMLFrame::UpdatePresentationData(PRUint32 aFlagsValues, PRUint32 aWhichFlags) { + NS_ASSERTION(NS_MATHML_IS_DISPLAYSTYLE(aWhichFlags) || + NS_MATHML_IS_COMPRESSED(aWhichFlags), + "aWhichFlags should only be displaystyle or compression flag"); + // update flags that are relevant to this call if (NS_MATHML_IS_DISPLAYSTYLE(aWhichFlags)) { // updating the displaystyle flag is allowed @@ -221,6 +260,7 @@ nsMathMLFrame::GetPresentationDataFrom(nsIFrame* aFrame, aPresentationData.flags |= NS_MATHML_DISPLAYSTYLE; } FindAttrDisplaystyle(content, aPresentationData); + FindAttrDirectionality(content, aPresentationData); aPresentationData.mstyle = frame->GetFirstContinuation(); break; } diff --git a/layout/mathml/nsMathMLFrame.h b/layout/mathml/nsMathMLFrame.h index a807a4760fd..1dbf0442457 100644 --- a/layout/mathml/nsMathMLFrame.h +++ b/layout/mathml/nsMathMLFrame.h @@ -21,6 +21,7 @@ * * Contributor(s): * Roger B. Sidje + * Frederic Wang * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -168,6 +169,11 @@ public: FindAttrDisplaystyle(nsIContent* aContent, nsPresentationData& aPresentationData); + // helper used to see if an element has a dir attribute + static void + FindAttrDirectionality(nsIContent* aContent, + nsPresentationData& aPresentationData); + // helper to check if a content has an attribute. If content is nsnull or if // the attribute is not there, check if the attribute is on the mstyle hierarchy // @return true --if attribute exists diff --git a/layout/mathml/nsMathMLTokenFrame.cpp b/layout/mathml/nsMathMLTokenFrame.cpp index 65616b5b84c..7572654347c 100644 --- a/layout/mathml/nsMathMLTokenFrame.cpp +++ b/layout/mathml/nsMathMLTokenFrame.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Roger B. Sidje * Karl Tomlinson , Mozilla Corporation + * Frederic Wang * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -64,6 +65,11 @@ nsMathMLTokenFrame::InheritAutomaticData(nsIFrame* aParent) // let the base class get the default from our parent nsMathMLContainerFrame::InheritAutomaticData(aParent); + if (mContent->Tag() != nsGkAtoms::mspace_) { + // see if the directionality attribute is there + nsMathMLFrame::FindAttrDirectionality(mContent, mPresentationData); + } + ProcessTextData(); return NS_OK; diff --git a/layout/mathml/nsMathMLmrowFrame.cpp b/layout/mathml/nsMathMLmrowFrame.cpp index af3c3854707..060d36ce1c0 100644 --- a/layout/mathml/nsMathMLmrowFrame.cpp +++ b/layout/mathml/nsMathMLmrowFrame.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Roger B. Sidje * David J. Fiddes + * Frederic Wang * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -69,6 +70,11 @@ nsMathMLmrowFrame::InheritAutomaticData(nsIFrame* aParent) mPresentationData.flags |= NS_MATHML_STRETCH_ALL_CHILDREN_VERTICALLY; + if (mContent->Tag() == nsGkAtoms::mrow_) { + // see if the directionality attribute is there + nsMathMLFrame::FindAttrDirectionality(mContent, mPresentationData); + } + return NS_OK; } diff --git a/layout/mathml/nsMathMLmstyleFrame.cpp b/layout/mathml/nsMathMLmstyleFrame.cpp index bf7340c8d87..b697ae58a62 100644 --- a/layout/mathml/nsMathMLmstyleFrame.cpp +++ b/layout/mathml/nsMathMLmstyleFrame.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Roger B. Sidje * David J. Fiddes + * Frederic Wang * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -76,6 +77,9 @@ nsMathMLmstyleFrame::InheritAutomaticData(nsIFrame* aParent) // see if the displaystyle attribute is there nsMathMLFrame::FindAttrDisplaystyle(mContent, mPresentationData); + // see if the directionality attribute is there + nsMathMLFrame::FindAttrDirectionality(mContent, mPresentationData); + return NS_OK; }