diff --git a/accessible/src/base/TextAttrs.cpp b/accessible/src/base/TextAttrs.cpp
index b28bdc485acf..91bfc440e169 100644
--- a/accessible/src/base/TextAttrs.cpp
+++ b/accessible/src/base/TextAttrs.cpp
@@ -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(!aElm), mIndex(aIndex)
-{
- mIsRootDefined = GetValueFor(aRootElm, &mRootNativeValue);
-
- if (aElm)
- mIsDefined = GetValueFor(aElm, &mNativeValue);
-}
-
-bool
-TextAttrsMgr::CSSTextAttr::
- GetValueFor(nsIContent* aElm, nsString* aValue)
-{
- nsCOMPtr 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(!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;
+}
diff --git a/accessible/src/base/TextAttrs.h b/accessible/src/base/TextAttrs.h
index 962cf289e493..d40268534219 100644
--- a/accessible/src/base/TextAttrs.h
+++ b/accessible/src/base/TextAttrs.h
@@ -243,27 +243,6 @@ protected:
};
- /**
- * Class is used for the work with CSS based text attributes.
- */
- class CSSTextAttr : public TTextAttr
- {
- 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
+ {
+ 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
diff --git a/accessible/tests/mochitest/attributes/test_text.html b/accessible/tests/mochitest/attributes/test_text.html
index f695301696dc..2e2b4166de13 100644
--- a/accessible/tests/mochitest/attributes/test_text.html
+++ b/accessible/tests/mochitest/attributes/test_text.html
@@ -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
+
+ Mozilla Bug 473569
+
@@ -549,7 +578,11 @@
This sentence has the word
sentence in
superscript and
- subscript
+ subscript and
+ superscript 20% and
+ subscript 20% and
+ superscript 20px and
+ subscript 20px