Add a directionality flag on MathML frames (bug 534963). r=karlt

This commit is contained in:
Frédéric Wang 2010-01-03 18:52:33 +01:00
parent d38f10bc2f
commit c7129c18d6
6 changed files with 68 additions and 0 deletions

View File

@ -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 <msup> 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))

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* Frederic Wang <fred.wang@free.fr>
*
* 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;
}

View File

@ -21,6 +21,7 @@
*
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* Frederic Wang <fred.wang@free.fr>
*
* 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

View File

@ -22,6 +22,7 @@
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
* Frederic Wang <fred.wang@free.fr>
*
* 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;

View File

@ -22,6 +22,7 @@
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
* Frederic Wang <fred.wang@free.fr>
*
* 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;
}

View File

@ -22,6 +22,7 @@
* Contributor(s):
* Roger B. Sidje <rbs@maths.uq.edu.au>
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
* Frederic Wang <fred.wang@free.fr>
*
* 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;
}