mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 473569 - Restrict text-position to allowed values, r=tbsaunde
This commit is contained in:
parent
a6bb287122
commit
28c5ddc5cf
@ -51,32 +51,6 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::a11y;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Constants and structures
|
||||
|
||||
/**
|
||||
* Item of the gCSSTextAttrsMap map.
|
||||
*/
|
||||
struct nsCSSTextAttrMapItem
|
||||
{
|
||||
const char* mCSSName;
|
||||
const char* mCSSValue;
|
||||
nsIAtom** mAttrName;
|
||||
const char* mAttrValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* The map of CSS properties to text attributes.
|
||||
*/
|
||||
const char* const kAnyValue = nsnull;
|
||||
const char* const kCopyValue = nsnull;
|
||||
|
||||
static nsCSSTextAttrMapItem gCSSTextAttrsMap[] =
|
||||
{
|
||||
// CSS name CSS value Attribute name Attribute value
|
||||
{ "vertical-align", kAnyValue, &nsGkAtoms::textPosition, kCopyValue }
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TextAttrsMgr
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -142,9 +116,6 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes,
|
||||
// "language" text attribute
|
||||
LangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
|
||||
|
||||
// "text-position" text attribute
|
||||
CSSTextAttr posTextAttr(0, hyperTextElm, offsetElm);
|
||||
|
||||
// "background-color" text attribute
|
||||
BGColorTextAttr bgColorTextAttr(rootFrame, frame);
|
||||
|
||||
@ -166,17 +137,20 @@ TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes,
|
||||
// "text-underline(line-through)-style(color)" text attributes
|
||||
TextDecorTextAttr textDecorTextAttr(rootFrame, frame);
|
||||
|
||||
// "text-position" text attribute
|
||||
TextPosTextAttr textPosTextAttr(rootFrame, frame);
|
||||
|
||||
TextAttr* attrArray[] =
|
||||
{
|
||||
&langTextAttr,
|
||||
&posTextAttr,
|
||||
&bgColorTextAttr,
|
||||
&colorTextAttr,
|
||||
&fontFamilyTextAttr,
|
||||
&fontSizeTextAttr,
|
||||
&fontStyleTextAttr,
|
||||
&fontWeightTextAttr,
|
||||
&textDecorTextAttr
|
||||
&textDecorTextAttr,
|
||||
&textPosTextAttr
|
||||
};
|
||||
|
||||
// Expose text attributes if applicable.
|
||||
@ -294,60 +268,6 @@ TextAttrsMgr::LangTextAttr::
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// CSSTextAttr
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TextAttrsMgr::CSSTextAttr::
|
||||
CSSTextAttr(PRUint32 aIndex, nsIContent* aRootElm, nsIContent* aElm) :
|
||||
TTextAttr<nsString>(!aElm), mIndex(aIndex)
|
||||
{
|
||||
mIsRootDefined = GetValueFor(aRootElm, &mRootNativeValue);
|
||||
|
||||
if (aElm)
|
||||
mIsDefined = GetValueFor(aElm, &mNativeValue);
|
||||
}
|
||||
|
||||
bool
|
||||
TextAttrsMgr::CSSTextAttr::
|
||||
GetValueFor(nsIContent* aElm, nsString* aValue)
|
||||
{
|
||||
nsCOMPtr<nsIDOMCSSStyleDeclaration> currStyleDecl =
|
||||
nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aElm);
|
||||
if (!currStyleDecl)
|
||||
return false;
|
||||
|
||||
NS_ConvertASCIItoUTF16 cssName(gCSSTextAttrsMap[mIndex].mCSSName);
|
||||
|
||||
nsresult rv = currStyleDecl->GetPropertyValue(cssName, *aValue);
|
||||
if (NS_FAILED(rv))
|
||||
return true;
|
||||
|
||||
const char *cssValue = gCSSTextAttrsMap[mIndex].mCSSValue;
|
||||
if (cssValue != kAnyValue && !aValue->EqualsASCII(cssValue))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
TextAttrsMgr::CSSTextAttr::
|
||||
ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
|
||||
{
|
||||
const char* attrValue = gCSSTextAttrsMap[mIndex].mAttrValue;
|
||||
if (attrValue != kCopyValue) {
|
||||
nsAutoString formattedValue;
|
||||
AppendASCIItoUTF16(attrValue, formattedValue);
|
||||
nsAccUtils::SetAccAttr(aAttributes, *gCSSTextAttrsMap[mIndex].mAttrName,
|
||||
formattedValue);
|
||||
return;
|
||||
}
|
||||
|
||||
nsAccUtils::SetAccAttr(aAttributes, *gCSSTextAttrsMap[mIndex].mAttrName,
|
||||
aValue);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// BGColorTextAttr
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -743,3 +663,104 @@ TextAttrsMgr::TextDecorTextAttr::
|
||||
formattedColor);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TextPosTextAttr
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TextAttrsMgr::TextPosTextAttr::
|
||||
TextPosTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
|
||||
TTextAttr<TextPosValue>(!aFrame)
|
||||
{
|
||||
mRootNativeValue = GetTextPosValue(aRootFrame);
|
||||
mIsRootDefined = mRootNativeValue != eTextPosNone;
|
||||
|
||||
if (aFrame) {
|
||||
mNativeValue = GetTextPosValue(aFrame);
|
||||
mIsDefined = mNativeValue != eTextPosNone;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TextAttrsMgr::TextPosTextAttr::
|
||||
GetValueFor(nsIContent* aContent, TextPosValue* aValue)
|
||||
{
|
||||
nsIFrame* frame = aContent->GetPrimaryFrame();
|
||||
if (frame) {
|
||||
*aValue = GetTextPosValue(frame);
|
||||
return *aValue != eTextPosNone;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
TextAttrsMgr::TextPosTextAttr::
|
||||
ExposeValue(nsIPersistentProperties* aAttributes, const TextPosValue& aValue)
|
||||
{
|
||||
switch (aValue) {
|
||||
case eTextPosBaseline:
|
||||
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textPosition,
|
||||
NS_LITERAL_STRING("baseline"));
|
||||
break;
|
||||
|
||||
case eTextPosSub:
|
||||
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textPosition,
|
||||
NS_LITERAL_STRING("sub"));
|
||||
break;
|
||||
|
||||
case eTextPosSuper:
|
||||
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textPosition,
|
||||
NS_LITERAL_STRING("super"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TextAttrsMgr::TextPosValue
|
||||
TextAttrsMgr::TextPosTextAttr::
|
||||
GetTextPosValue(nsIFrame* aFrame) const
|
||||
{
|
||||
const nsStyleCoord& styleCoord = aFrame->GetStyleTextReset()->mVerticalAlign;
|
||||
switch (styleCoord.GetUnit()) {
|
||||
case eStyleUnit_Enumerated:
|
||||
switch (styleCoord.GetIntValue()) {
|
||||
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
||||
return eTextPosBaseline;
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUB:
|
||||
return eTextPosSub;
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUPER:
|
||||
return eTextPosSuper;
|
||||
|
||||
// No good guess for these:
|
||||
// NS_STYLE_VERTICAL_ALIGN_TOP
|
||||
// NS_STYLE_VERTICAL_ALIGN_TEXT_TOP
|
||||
// NS_STYLE_VERTICAL_ALIGN_MIDDLE
|
||||
// NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM
|
||||
// NS_STYLE_VERTICAL_ALIGN_BOTTOM
|
||||
// NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE
|
||||
// Do not expose value of text-position attribute.
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return eTextPosNone;
|
||||
|
||||
case eStyleUnit_Percent:
|
||||
{
|
||||
float percentValue = styleCoord.GetPercentValue();
|
||||
return percentValue > 0 ?
|
||||
eTextPosSuper :
|
||||
(percentValue < 0 ? eTextPosSub : eTextPosBaseline);
|
||||
}
|
||||
|
||||
case eStyleUnit_Coord:
|
||||
{
|
||||
nscoord coordValue = styleCoord.GetCoordValue();
|
||||
return coordValue > 0 ?
|
||||
eTextPosSuper :
|
||||
(coordValue < 0 ? eTextPosSub : eTextPosBaseline);
|
||||
}
|
||||
}
|
||||
|
||||
return eTextPosNone;
|
||||
}
|
||||
|
@ -243,27 +243,6 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class is used for the work with CSS based text attributes.
|
||||
*/
|
||||
class CSSTextAttr : public TTextAttr<nsString>
|
||||
{
|
||||
public:
|
||||
CSSTextAttr(PRUint32 aIndex, nsIContent* aRootElm, nsIContent* aElm);
|
||||
virtual ~CSSTextAttr() { }
|
||||
|
||||
protected:
|
||||
|
||||
// TextAttr
|
||||
virtual bool GetValueFor(nsIContent* aElm, nsString* aValue);
|
||||
virtual void ExposeValue(nsIPersistentProperties* aAttributes,
|
||||
const nsString& aValue);
|
||||
|
||||
private:
|
||||
PRInt32 mIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Class is used for the work with 'background-color' text attribute.
|
||||
*/
|
||||
@ -436,6 +415,34 @@ protected:
|
||||
const TextDecorValue& aValue);
|
||||
};
|
||||
|
||||
/**
|
||||
* Class is used for the work with "text-position" text attribute.
|
||||
*/
|
||||
|
||||
enum TextPosValue {
|
||||
eTextPosNone = 0,
|
||||
eTextPosBaseline,
|
||||
eTextPosSub,
|
||||
eTextPosSuper
|
||||
};
|
||||
|
||||
class TextPosTextAttr : public TTextAttr<TextPosValue>
|
||||
{
|
||||
public:
|
||||
TextPosTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
|
||||
virtual ~TextPosTextAttr() { }
|
||||
|
||||
protected:
|
||||
|
||||
// TextAttr
|
||||
virtual bool GetValueFor(nsIContent* aElm, TextPosValue* aValue);
|
||||
virtual void ExposeValue(nsIPersistentProperties* aAttributes,
|
||||
const TextPosValue& aValue);
|
||||
|
||||
private:
|
||||
TextPosValue GetTextPosValue(nsIFrame* aFrame) const;
|
||||
};
|
||||
|
||||
}; // TextAttrMgr
|
||||
|
||||
} // namespace a11y
|
||||
|
@ -181,6 +181,30 @@
|
||||
attrs = {"text-position": gComputedStyle.verticalAlign};
|
||||
testTextAttrs(ID, 55, attrs, defAttrs, 55, 64);
|
||||
|
||||
attrs = {};
|
||||
testTextAttrs(ID, 64, attrs, defAttrs, 64, 69);
|
||||
|
||||
attrs = { "text-position": "super" };
|
||||
testTextAttrs(ID, 69, attrs, defAttrs, 69, 84);
|
||||
|
||||
attrs = {};
|
||||
testTextAttrs(ID, 84, attrs, defAttrs, 84, 89);
|
||||
|
||||
attrs = { "text-position": "sub" };
|
||||
testTextAttrs(ID, 89, attrs, defAttrs, 89, 102);
|
||||
|
||||
attrs = {};
|
||||
testTextAttrs(ID, 102, attrs, defAttrs, 102, 107);
|
||||
|
||||
attrs = { "text-position": "super" };
|
||||
testTextAttrs(ID, 107, attrs, defAttrs, 107, 123);
|
||||
|
||||
attrs = {};
|
||||
testTextAttrs(ID, 123, attrs, defAttrs, 123, 128);
|
||||
|
||||
attrs = { "text-position": "sub" };
|
||||
testTextAttrs(ID, 128, attrs, defAttrs, 128, 142);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// area7
|
||||
ID = "area7";
|
||||
@ -505,6 +529,11 @@
|
||||
title="Implement text attributes">
|
||||
Mozilla Bug 345759
|
||||
</a>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=473569"
|
||||
title="Restrict text-position to allowed values">
|
||||
Mozilla Bug 473569
|
||||
</a>
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=473576"
|
||||
title="font-family text attribute should expose actual font used">
|
||||
@ -549,7 +578,11 @@
|
||||
This <sup>sentence</sup> has the word
|
||||
<span style="vertical-align:super;">sentence</span> in
|
||||
<sub>superscript</sub> and
|
||||
<span style="vertical-align:sub;">subscript</span>
|
||||
<span style="vertical-align:sub;">subscript</span> and
|
||||
<span style="vertical-align:20%;">superscript 20%</span> and
|
||||
<span style="vertical-align:-20%;">subscript 20%</span> and
|
||||
<span style="vertical-align:20px;">superscript 20px</span> and
|
||||
<span style="vertical-align:-20px;">subscript 20px</span>
|
||||
</p>
|
||||
|
||||
<p lang="en" id="area7">
|
||||
|
Loading…
Reference in New Issue
Block a user