diff --git a/accessible/src/base/Makefile.in b/accessible/src/base/Makefile.in
index 9dc49eb30915..7fd861756c47 100644
--- a/accessible/src/base/Makefile.in
+++ b/accessible/src/base/Makefile.in
@@ -75,8 +75,8 @@ CPPSRCS = \
nsCaretAccessible.cpp \
nsTextAccessible.cpp \
nsTextEquivUtils.cpp \
- nsTextAttrs.cpp \
StyleInfo.cpp \
+ TextAttrs.cpp \
TextUpdater.cpp \
$(NULL)
diff --git a/accessible/src/base/StyleInfo.cpp b/accessible/src/base/StyleInfo.cpp
index 4bd503ddcfe1..c3f4c1cf8d4c 100644
--- a/accessible/src/base/StyleInfo.cpp
+++ b/accessible/src/base/StyleInfo.cpp
@@ -131,3 +131,12 @@ StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
}
+
+void
+StyleInfo::FormatTextDecorationStyle(PRUint8 aValue, nsAString& aFormattedValue)
+{
+ nsCSSKeyword keyword =
+ nsCSSProps::ValueToKeywordEnum(aValue,
+ nsCSSProps::kTextDecorationStyleKTable);
+ AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
+}
diff --git a/accessible/src/base/StyleInfo.h b/accessible/src/base/StyleInfo.h
index b77cd0485573..3e44d5754d47 100644
--- a/accessible/src/base/StyleInfo.h
+++ b/accessible/src/base/StyleInfo.h
@@ -62,6 +62,7 @@ public:
static void FormatColor(const nscolor& aValue, nsString& aFormattedValue);
static void FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue);
+ static void FormatTextDecorationStyle(PRUint8 aValue, nsAString& aFormattedValue);
private:
StyleInfo() MOZ_DELETE;
diff --git a/accessible/src/base/nsTextAttrs.cpp b/accessible/src/base/TextAttrs.cpp
similarity index 59%
rename from accessible/src/base/nsTextAttrs.cpp
rename to accessible/src/base/TextAttrs.cpp
index 9dd2085791c6..bf22eca74a75 100644
--- a/accessible/src/base/nsTextAttrs.cpp
+++ b/accessible/src/base/TextAttrs.cpp
@@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
-#include "nsTextAttrs.h"
+#include "TextAttrs.h"
#include "nsAccUtils.h"
#include "nsCoreUtils.h"
@@ -73,28 +73,18 @@ const char* const kCopyValue = nsnull;
static nsCSSTextAttrMapItem gCSSTextAttrsMap[] =
{
- // CSS name CSS value Attribute name Attribute value
- { "text-decoration", "line-through", &nsGkAtoms::textLineThroughStyle, "solid" },
- { "text-decoration", "underline", &nsGkAtoms::textUnderlineStyle, "solid" },
+ // CSS name CSS value Attribute name Attribute value
{ "vertical-align", kAnyValue, &nsGkAtoms::textPosition, kCopyValue }
};
////////////////////////////////////////////////////////////////////////////////
-// nsTextAttrs
+// TextAttrsMgr
+////////////////////////////////////////////////////////////////////////////////
-nsTextAttrsMgr::nsTextAttrsMgr(nsHyperTextAccessible *aHyperTextAcc,
- bool aIncludeDefAttrs,
- nsAccessible *aOffsetAcc,
- PRInt32 aOffsetAccIdx) :
- mHyperTextAcc(aHyperTextAcc), mIncludeDefAttrs(aIncludeDefAttrs),
- mOffsetAcc(aOffsetAcc), mOffsetAccIdx(aOffsetAccIdx)
-{
-}
-
-nsresult
-nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
- PRInt32 *aStartHTOffset,
- PRInt32 *aEndHTOffset)
+void
+TextAttrsMgr::GetAttributes(nsIPersistentProperties* aAttributes,
+ PRInt32* aStartHTOffset,
+ PRInt32* aEndHTOffset)
{
// 1. Hyper text accessible must be specified always.
// 2. Offset accessible and result hyper text offsets must be specified in
@@ -108,7 +98,7 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
(!mOffsetAcc && mOffsetAccIdx == -1 &&
!aStartHTOffset && !aEndHTOffset &&
mIncludeDefAttrs && aAttributes)),
- "Wrong usage of nsTextAttrsMgr!");
+ "Wrong usage of TextAttrsMgr!");
// Embedded objects are combined into own range with empty attributes set.
if (mOffsetAcc && nsAccUtils::IsEmbeddedObject(mOffsetAcc)) {
@@ -130,7 +120,7 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
(*aEndHTOffset)++;
}
- return NS_OK;
+ return;
}
// Get the content and frame of the accessible. In the case of document
@@ -139,7 +129,7 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
nsIFrame *rootFrame = mHyperTextAcc->GetFrame();
NS_ASSERTION(rootFrame, "No frame for accessible!");
if (!rootFrame)
- return NS_OK;
+ return;
nsIContent *offsetNode = nsnull, *offsetElm = nsnull;
nsIFrame *frame = nsnull;
@@ -149,26 +139,18 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
frame = offsetElm->GetPrimaryFrame();
}
- nsTArray textAttrArray(10);
+ nsTArray textAttrArray(9);
// "language" text attribute
- nsLangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
+ LangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
textAttrArray.AppendElement(&langTextAttr);
- // "text-line-through-style" text attribute
- nsCSSTextAttr lineThroughTextAttr(0, hyperTextElm, offsetElm);
- textAttrArray.AppendElement(&lineThroughTextAttr);
-
- // "text-underline-style" text attribute
- nsCSSTextAttr underlineTextAttr(1, hyperTextElm, offsetElm);
- textAttrArray.AppendElement(&underlineTextAttr);
-
// "text-position" text attribute
- nsCSSTextAttr posTextAttr(2, hyperTextElm, offsetElm);
+ CSSTextAttr posTextAttr(0, hyperTextElm, offsetElm);
textAttrArray.AppendElement(&posTextAttr);
// "background-color" text attribute
- nsBGColorTextAttr bgColorTextAttr(rootFrame, frame);
+ BGColorTextAttr bgColorTextAttr(rootFrame, frame);
textAttrArray.AppendElement(&bgColorTextAttr);
// "color" text attribute
@@ -180,7 +162,7 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
textAttrArray.AppendElement(&fontFamilyTextAttr);
// "font-size" text attribute
- nsFontSizeTextAttr fontSizeTextAttr(rootFrame, frame);
+ FontSizeTextAttr fontSizeTextAttr(rootFrame, frame);
textAttrArray.AppendElement(&fontSizeTextAttr);
// "font-style" text attribute
@@ -188,34 +170,28 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
textAttrArray.AppendElement(&fontStyleTextAttr);
// "font-weight" text attribute
- nsFontWeightTextAttr fontWeightTextAttr(rootFrame, frame);
+ FontWeightTextAttr fontWeightTextAttr(rootFrame, frame);
textAttrArray.AppendElement(&fontWeightTextAttr);
+ // "text-underline(line-through)-style(color)" text attributes
+ TextDecorTextAttr textDecorTextAttr(rootFrame, frame);
+ textAttrArray.AppendElement(&textDecorTextAttr);
+
// Expose text attributes if applicable.
if (aAttributes) {
PRUint32 len = textAttrArray.Length();
- for (PRUint32 idx = 0; idx < len; idx++) {
- nsITextAttr *textAttr = textAttrArray[idx];
-
- nsAutoString value;
- if (textAttr->GetValue(value, mIncludeDefAttrs))
- nsAccUtils::SetAccAttr(aAttributes, textAttr->GetName(), value);
- }
+ for (PRUint32 idx = 0; idx < len; idx++)
+ textAttrArray[idx]->Expose(aAttributes, mIncludeDefAttrs);
}
- nsresult rv = NS_OK;
-
// Expose text attributes range where they are applied if applicable.
if (mOffsetAcc)
- rv = GetRange(textAttrArray, aStartHTOffset, aEndHTOffset);
-
- textAttrArray.Clear();
- return rv;
+ GetRange(textAttrArray, aStartHTOffset, aEndHTOffset);
}
-nsresult
-nsTextAttrsMgr::GetRange(const nsTArray& aTextAttrArray,
- PRInt32 *aStartHTOffset, PRInt32 *aEndHTOffset)
+void
+TextAttrsMgr::GetRange(const nsTArray& aTextAttrArray,
+ PRInt32* aStartHTOffset, PRInt32* aEndHTOffset)
{
PRUint32 attrLen = aTextAttrArray.Length();
@@ -228,12 +204,13 @@ nsTextAttrsMgr::GetRange(const nsTArray& aTextAttrArray,
if (nsAccUtils::IsEmbeddedObject(currAcc))
break;
- nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
- NS_ENSURE_STATE(currElm);
+ nsIContent* currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
+ if (!currElm)
+ return;
bool offsetFound = false;
for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
- nsITextAttr *textAttr = aTextAttrArray[attrIdx];
+ TextAttr* textAttr = aTextAttrArray[attrIdx];
if (!textAttr->Equal(currElm)) {
offsetFound = true;
break;
@@ -253,12 +230,13 @@ nsTextAttrsMgr::GetRange(const nsTArray& aTextAttrArray,
if (nsAccUtils::IsEmbeddedObject(currAcc))
break;
- nsIContent *currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
- NS_ENSURE_STATE(currElm);
+ nsIContent* currElm = nsCoreUtils::GetDOMElementFor(currAcc->GetContent());
+ if (!currElm)
+ return;
bool offsetFound = false;
for (PRUint32 attrIdx = 0; attrIdx < attrLen; attrIdx++) {
- nsITextAttr *textAttr = aTextAttrArray[attrIdx];
+ TextAttr* textAttr = aTextAttrArray[attrIdx];
// Alter the end offset when text attribute changes its value and stop
// the search.
@@ -273,69 +251,68 @@ nsTextAttrsMgr::GetRange(const nsTArray& aTextAttrArray,
(*aEndHTOffset) += nsAccUtils::TextLength(currAcc);
}
-
- return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// nsLangTextAttr
-nsLangTextAttr::nsLangTextAttr(nsHyperTextAccessible *aRootAcc,
- nsIContent *aRootContent, nsIContent *aContent) :
- nsTextAttr(aContent == nsnull), mRootContent(aRootContent)
+////////////////////////////////////////////////////////////////////////////////
+// LangTextAttr
+////////////////////////////////////////////////////////////////////////////////
+
+TextAttrsMgr::LangTextAttr::
+ LangTextAttr(nsHyperTextAccessible* aRoot,
+ nsIContent* aRootElm, nsIContent* aElm) :
+ TTextAttr(!aElm), mRootContent(aRootElm)
{
- aRootAcc->Language(mRootNativeValue);
+ aRoot->Language(mRootNativeValue);
mIsRootDefined = !mRootNativeValue.IsEmpty();
- if (aContent)
- mIsDefined = GetLang(aContent, mNativeValue);
+ if (aElm)
+ mIsDefined = GetLang(aElm, mNativeValue);
}
bool
-nsLangTextAttr::GetValueFor(nsIContent *aElm, nsAutoString *aValue)
+TextAttrsMgr::LangTextAttr::
+ GetValueFor(nsIContent* aElm, nsString* aValue)
{
return GetLang(aElm, *aValue);
}
void
-nsLangTextAttr::Format(const nsAutoString& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::LangTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
{
- aFormattedValue = aValue;
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::language, aValue);
}
bool
-nsLangTextAttr::GetLang(nsIContent *aContent, nsAString& aLang)
+TextAttrsMgr::LangTextAttr::
+ GetLang(nsIContent* aElm, nsAString& aLang)
{
- nsCoreUtils::GetLanguageFor(aContent, mRootContent, aLang);
+ nsCoreUtils::GetLanguageFor(aElm, mRootContent, aLang);
return !aLang.IsEmpty();
}
////////////////////////////////////////////////////////////////////////////////
-// nsCSSTextAttr
+// CSSTextAttr
////////////////////////////////////////////////////////////////////////////////
-nsCSSTextAttr::nsCSSTextAttr(PRUint32 aIndex, nsIContent *aRootContent,
- nsIContent *aContent) :
- nsTextAttr(aContent == nsnull), mIndex(aIndex)
+TextAttrsMgr::CSSTextAttr::
+ CSSTextAttr(PRUint32 aIndex, nsIContent* aRootElm, nsIContent* aElm) :
+ TTextAttr(!aElm), mIndex(aIndex)
{
- mIsRootDefined = GetValueFor(aRootContent, &mRootNativeValue);
+ mIsRootDefined = GetValueFor(aRootElm, &mRootNativeValue);
- if (aContent)
- mIsDefined = GetValueFor(aContent, &mNativeValue);
-}
-
-nsIAtom*
-nsCSSTextAttr::GetName() const
-{
- return *gCSSTextAttrsMap[mIndex].mAttrName;
+ if (aElm)
+ mIsDefined = GetValueFor(aElm, &mNativeValue);
}
bool
-nsCSSTextAttr::GetValueFor(nsIContent *aContent, nsAutoString *aValue)
+TextAttrsMgr::CSSTextAttr::
+ GetValueFor(nsIContent* aElm, nsString* aValue)
{
nsCOMPtr currStyleDecl =
- nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aContent);
+ nsCoreUtils::GetComputedStyleDeclaration(EmptyString(), aElm);
if (!currStyleDecl)
return false;
@@ -353,22 +330,30 @@ nsCSSTextAttr::GetValueFor(nsIContent *aContent, nsAutoString *aValue)
}
void
-nsCSSTextAttr::Format(const nsAutoString& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::CSSTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
{
- const char *attrValue = gCSSTextAttrsMap[mIndex].mAttrValue;
- if (attrValue != kCopyValue)
- AppendASCIItoUTF16(attrValue, aFormattedValue);
- else
- aFormattedValue = 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);
}
////////////////////////////////////////////////////////////////////////////////
-// nsBGColorTextAttr
+// BGColorTextAttr
////////////////////////////////////////////////////////////////////////////////
-nsBGColorTextAttr::nsBGColorTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame) :
- nsTextAttr(aFrame == nsnull), mRootFrame(aRootFrame)
+TextAttrsMgr::BGColorTextAttr::
+ BGColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame), mRootFrame(aRootFrame)
{
mIsRootDefined = GetColor(mRootFrame, &mRootNativeValue);
if (aFrame)
@@ -376,27 +361,28 @@ nsBGColorTextAttr::nsBGColorTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame) :
}
bool
-nsBGColorTextAttr::GetValueFor(nsIContent *aContent, nscolor *aValue)
+TextAttrsMgr::BGColorTextAttr::
+ GetValueFor(nsIContent* aElm, nscolor* aValue)
{
- nsIFrame *frame = aContent->GetPrimaryFrame();
- if (!frame)
- return false;
-
- return GetColor(frame, aValue);
+ nsIFrame* frame = aElm->GetPrimaryFrame();
+ return frame ? GetColor(frame, aValue) : false;
}
void
-nsBGColorTextAttr::Format(const nscolor& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::BGColorTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nscolor& aValue)
{
- nsAutoString value;
- StyleInfo::FormatColor(aValue, value);
- aFormattedValue = value;
+ nsAutoString formattedValue;
+ StyleInfo::FormatColor(aValue, formattedValue);
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::backgroundColor,
+ formattedValue);
}
bool
-nsBGColorTextAttr::GetColor(nsIFrame *aFrame, nscolor *aColor)
+TextAttrsMgr::BGColorTextAttr::
+ GetColor(nsIFrame* aFrame, nscolor* aColor)
{
- const nsStyleBackground *styleBackground = aFrame->GetStyleBackground();
+ const nsStyleBackground* styleBackground = aFrame->GetStyleBackground();
if (NS_GET_A(styleBackground->mBackgroundColor) > 0) {
*aColor = styleBackground->mBackgroundColor;
@@ -423,8 +409,9 @@ nsBGColorTextAttr::GetColor(nsIFrame *aFrame, nscolor *aColor)
// ColorTextAttr
////////////////////////////////////////////////////////////////////////////////
-ColorTextAttr::ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
- nsTextAttr(!aFrame)
+TextAttrsMgr::ColorTextAttr::
+ ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
{
mRootNativeValue = aRootFrame->GetStyleColor()->mColor;
mIsRootDefined = true;
@@ -436,9 +423,10 @@ ColorTextAttr::ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
}
bool
-ColorTextAttr::GetValueFor(nsIContent* aContent, nscolor* aValue)
+TextAttrsMgr::ColorTextAttr::
+ GetValueFor(nsIContent* aElm, nscolor* aValue)
{
- nsIFrame* frame = aContent->GetPrimaryFrame();
+ nsIFrame* frame = aElm->GetPrimaryFrame();
if (frame) {
*aValue = frame->GetStyleColor()->mColor;
return true;
@@ -448,11 +436,12 @@ ColorTextAttr::GetValueFor(nsIContent* aContent, nscolor* aValue)
}
void
-ColorTextAttr::Format(const nscolor& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::ColorTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nscolor& aValue)
{
- nsAutoString value;
- StyleInfo::FormatColor(aValue, value);
- aFormattedValue = value;
+ nsAutoString formattedValue;
+ StyleInfo::FormatColor(aValue, formattedValue);
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::color, formattedValue);
}
@@ -460,8 +449,9 @@ ColorTextAttr::Format(const nscolor& aValue, nsAString& aFormattedValue)
// FontFamilyTextAttr
////////////////////////////////////////////////////////////////////////////////
-FontFamilyTextAttr::FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
- nsTextAttr(aFrame == nsnull)
+TextAttrsMgr::FontFamilyTextAttr::
+ FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
{
mIsRootDefined = GetFontFamily(aRootFrame, mRootNativeValue);
@@ -470,24 +460,23 @@ FontFamilyTextAttr::FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
}
bool
-FontFamilyTextAttr::GetValueFor(nsIContent* aElm, nsAutoString* aValue)
+TextAttrsMgr::FontFamilyTextAttr::
+ GetValueFor(nsIContent* aElm, nsString* aValue)
{
nsIFrame* frame = aElm->GetPrimaryFrame();
- if (!frame)
- return false;
-
- return GetFontFamily(frame, *aValue);
+ return frame ? GetFontFamily(frame, *aValue) : false;
}
void
-FontFamilyTextAttr::Format(const nsAutoString& aValue,
- nsAString& aFormattedValue)
+TextAttrsMgr::FontFamilyTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nsString& aValue)
{
- aFormattedValue = aValue;
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::font_family, aValue);
}
bool
-FontFamilyTextAttr::GetFontFamily(nsIFrame* aFrame, nsAutoString& aFamily)
+TextAttrsMgr::FontFamilyTextAttr::
+ GetFontFamily(nsIFrame* aFrame, nsString& aFamily)
{
nsRefPtr fm;
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));
@@ -501,36 +490,40 @@ FontFamilyTextAttr::GetFontFamily(nsIFrame* aFrame, nsAutoString& aFamily)
////////////////////////////////////////////////////////////////////////////////
-// nsFontSizeTextAttr
+// FontSizeTextAttr
////////////////////////////////////////////////////////////////////////////////
-nsFontSizeTextAttr::nsFontSizeTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame) :
- nsTextAttr(aFrame == nsnull)
+TextAttrsMgr::FontSizeTextAttr::
+ FontSizeTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
{
mDC = aRootFrame->PresContext()->DeviceContext();
- mRootNativeValue = GetFontSize(aRootFrame);
+ mRootNativeValue = aRootFrame->GetStyleFont()->mSize;
mIsRootDefined = true;
if (aFrame) {
- mNativeValue = GetFontSize(aFrame);
+ mNativeValue = aFrame->GetStyleFont()->mSize;
mIsDefined = true;
}
}
bool
-nsFontSizeTextAttr::GetValueFor(nsIContent *aContent, nscoord *aValue)
+TextAttrsMgr::FontSizeTextAttr::
+ GetValueFor(nsIContent* aElm, nscoord* aValue)
{
- nsIFrame *frame = aContent->GetPrimaryFrame();
- if (!frame)
- return false;
+ nsIFrame* frame = aElm->GetPrimaryFrame();
+ if (frame) {
+ *aValue = frame->GetStyleFont()->mSize;
+ return true;
+ }
- *aValue = GetFontSize(frame);
- return true;
+ return false;
}
void
-nsFontSizeTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::FontSizeTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nscoord& aValue)
{
// Convert from nscoord to pt.
//
@@ -548,13 +541,8 @@ nsFontSizeTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue)
nsAutoString value;
value.AppendInt(pts);
value.Append(NS_LITERAL_STRING("pt"));
- aFormattedValue = value;
-}
-nscoord
-nsFontSizeTextAttr::GetFontSize(nsIFrame *aFrame)
-{
- return aFrame->GetStyleFont()->mSize;
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::font_size, value);
}
@@ -562,8 +550,9 @@ nsFontSizeTextAttr::GetFontSize(nsIFrame *aFrame)
// FontStyleTextAttr
////////////////////////////////////////////////////////////////////////////////
-FontStyleTextAttr::FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
- nsTextAttr(!aFrame)
+TextAttrsMgr::FontStyleTextAttr::
+ FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
{
mRootNativeValue = aRootFrame->GetStyleFont()->mFont.style;
mIsRootDefined = true;
@@ -575,7 +564,8 @@ FontStyleTextAttr::FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
}
bool
-FontStyleTextAttr::GetValueFor(nsIContent* aContent, nscoord* aValue)
+TextAttrsMgr::FontStyleTextAttr::
+ GetValueFor(nsIContent* aContent, nscoord* aValue)
{
nsIFrame* frame = aContent->GetPrimaryFrame();
if (frame) {
@@ -587,19 +577,23 @@ FontStyleTextAttr::GetValueFor(nsIContent* aContent, nscoord* aValue)
}
void
-FontStyleTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::FontStyleTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const nscoord& aValue)
{
- StyleInfo::FormatFontStyle(aValue, aFormattedValue);
+ nsAutoString formattedValue;
+ StyleInfo::FormatFontStyle(aValue, formattedValue);
+
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::font_style, formattedValue);
}
////////////////////////////////////////////////////////////////////////////////
-// nsFontWeightTextAttr
+// FontWeightTextAttr
////////////////////////////////////////////////////////////////////////////////
-nsFontWeightTextAttr::nsFontWeightTextAttr(nsIFrame *aRootFrame,
- nsIFrame *aFrame) :
- nsTextAttr(aFrame == nsnull)
+TextAttrsMgr::FontWeightTextAttr::
+ FontWeightTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
{
mRootNativeValue = GetFontWeight(aRootFrame);
mIsRootDefined = true;
@@ -611,26 +605,31 @@ nsFontWeightTextAttr::nsFontWeightTextAttr(nsIFrame *aRootFrame,
}
bool
-nsFontWeightTextAttr::GetValueFor(nsIContent *aContent, PRInt32 *aValue)
+TextAttrsMgr::FontWeightTextAttr::
+ GetValueFor(nsIContent* aElm, PRInt32* aValue)
{
- nsIFrame *frame = aContent->GetPrimaryFrame();
- if (!frame)
- return false;
+ nsIFrame* frame = aElm->GetPrimaryFrame();
+ if (frame) {
+ *aValue = GetFontWeight(frame);
+ return true;
+ }
- *aValue = GetFontWeight(frame);
- return true;
+ return false;
}
void
-nsFontWeightTextAttr::Format(const PRInt32& aValue, nsAString& aFormattedValue)
+TextAttrsMgr::FontWeightTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const PRInt32& aValue)
{
- nsAutoString value;
- value.AppendInt(aValue);
- aFormattedValue = value;
+ nsAutoString formattedValue;
+ formattedValue.AppendInt(aValue);
+
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::fontWeight, formattedValue);
}
PRInt32
-nsFontWeightTextAttr::GetFontWeight(nsIFrame *aFrame)
+TextAttrsMgr::FontWeightTextAttr::
+ GetFontWeight(nsIFrame* aFrame)
{
// nsFont::width isn't suitable here because it's necessary to expose real
// value of font weight (used font might not have some font weight values).
@@ -664,3 +663,82 @@ nsFontWeightTextAttr::GetFontWeight(nsIFrame *aFrame)
return fontEntry->Weight();
#endif
}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// TextDecorTextAttr
+////////////////////////////////////////////////////////////////////////////////
+
+TextAttrsMgr::TextDecorValue::
+ TextDecorValue(nsIFrame* aFrame)
+{
+ const nsStyleTextReset* textReset = aFrame->GetStyleTextReset();
+ mStyle = textReset->GetDecorationStyle();
+
+ bool isForegroundColor = false;
+ textReset->GetDecorationColor(mColor, isForegroundColor);
+ if (isForegroundColor)
+ mColor = aFrame->GetStyleColor()->mColor;
+
+ mLine = textReset->mTextDecorationLine &
+ (NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE |
+ NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH);
+}
+
+TextAttrsMgr::TextDecorTextAttr::
+ TextDecorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
+ TTextAttr(!aFrame)
+{
+ mRootNativeValue = TextDecorValue(aRootFrame);
+ mIsRootDefined = mRootNativeValue.IsDefined();
+
+ if (aFrame) {
+ mNativeValue = TextDecorValue(aFrame);
+ mIsDefined = mNativeValue.IsDefined();
+ }
+}
+
+bool
+TextAttrsMgr::TextDecorTextAttr::
+ GetValueFor(nsIContent* aContent, TextDecorValue* aValue)
+{
+ nsIFrame* frame = aContent->GetPrimaryFrame();
+ if (frame) {
+ *aValue = TextDecorValue(frame);
+ return aValue->IsDefined();
+ }
+
+ return false;
+}
+
+void
+TextAttrsMgr::TextDecorTextAttr::
+ ExposeValue(nsIPersistentProperties* aAttributes, const TextDecorValue& aValue)
+{
+ if (aValue.IsUnderline()) {
+ nsAutoString formattedStyle;
+ StyleInfo::FormatTextDecorationStyle(aValue.Style(), formattedStyle);
+ nsAccUtils::SetAccAttr(aAttributes,
+ nsGkAtoms::textUnderlineStyle,
+ formattedStyle);
+
+ nsAutoString formattedColor;
+ StyleInfo::FormatColor(aValue.Color(), formattedColor);
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textUnderlineColor,
+ formattedColor);
+ return;
+ }
+
+ if (aValue.IsLineThrough()) {
+ nsAutoString formattedStyle;
+ StyleInfo::FormatTextDecorationStyle(aValue.Style(), formattedStyle);
+ nsAccUtils::SetAccAttr(aAttributes,
+ nsGkAtoms::textLineThroughStyle,
+ formattedStyle);
+
+ nsAutoString formattedColor;
+ StyleInfo::FormatColor(aValue.Color(), formattedColor);
+ nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::textLineThroughColor,
+ formattedColor);
+ }
+}
diff --git a/accessible/src/base/TextAttrs.h b/accessible/src/base/TextAttrs.h
new file mode 100644
index 000000000000..2374b8dc7aee
--- /dev/null
+++ b/accessible/src/base/TextAttrs.h
@@ -0,0 +1,443 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Alexander Surkov (original author)
+ *
+ * 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"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsTextAttrs_h_
+#define nsTextAttrs_h_
+
+#include "nsIContent.h"
+#include "nsIFrame.h"
+#include "nsIPersistentProperties2.h"
+#include "nsStyleConsts.h"
+
+class nsHyperTextAccessible;
+
+namespace mozilla {
+namespace a11y {
+
+/**
+ * Used to expose text attributes for the hyper text accessible (see
+ * nsHyperTextAccessible class).
+ *
+ * @note "invalid: spelling" text attribute is implemented entirely in
+ * nsHyperTextAccessible class.
+ */
+class TextAttrsMgr
+{
+public:
+ /**
+ * Constructor. Used to expose default text attributes.
+ */
+ TextAttrsMgr(nsHyperTextAccessible* aHyperTextAcc) :
+ mHyperTextAcc(aHyperTextAcc), mIncludeDefAttrs(true),
+ mOffsetAcc(nsnull), mOffsetAccIdx(-1) { }
+
+ /**
+ * Constructor. Used to expose text attributes at the given offset.
+ *
+ * @param aHyperTextAcc [in] hyper text accessible text attributes are
+ * calculated for
+ * @param aIncludeDefAttrs [optional] indicates whether default text
+ * attributes should be included into list of exposed
+ * text attributes
+ * @param oOffsetAcc [optional] offset an accessible the text attributes
+ * should be calculated for
+ * @param oOffsetAccIdx [optional] index in parent of offset accessible
+ */
+ TextAttrsMgr(nsHyperTextAccessible* aHyperTextAcc,
+ bool aIncludeDefAttrs,
+ nsAccessible* aOffsetAcc,
+ PRInt32 aOffsetAccIdx) :
+ mHyperTextAcc(aHyperTextAcc), mIncludeDefAttrs(aIncludeDefAttrs),
+ mOffsetAcc(aOffsetAcc), mOffsetAccIdx(aOffsetAccIdx) { }
+
+ /*
+ * Return text attributes and hyper text offsets where these attributes are
+ * applied. Offsets are calculated in the case of non default attributes.
+ *
+ * @note In the case of default attributes pointers on hyper text offsets
+ * must be skipped.
+ *
+ * @param aAttributes [in, out] text attributes list
+ * @param aStartHTOffset [out, optional] start hyper text offset
+ * @param aEndHTOffset [out, optional] end hyper text offset
+ */
+ void GetAttributes(nsIPersistentProperties* aAttributes,
+ PRInt32* aStartHTOffset = nsnull,
+ PRInt32* aEndHTOffset = nsnull);
+
+protected:
+ /**
+ * Calculates range (start and end offsets) of text where the text attributes
+ * are stretched. New offsets may be smaller if one of text attributes changes
+ * its value before or after the given offsets.
+ *
+ * @param aTextAttrArray [in] text attributes array
+ * @param aStartHTOffset [in, out] the start offset
+ * @param aEndHTOffset [in, out] the end offset
+ */
+ class TextAttr;
+ void GetRange(const nsTArray& aTextAttrArray,
+ PRInt32* aStartHTOffset, PRInt32* aEndHTOffset);
+
+private:
+ nsHyperTextAccessible* mHyperTextAcc;
+
+ bool mIncludeDefAttrs;
+
+ nsAccessible* mOffsetAcc;
+ PRInt32 mOffsetAccIdx;
+
+protected:
+
+ /**
+ * Interface class of text attribute class implementations.
+ */
+ class TextAttr
+ {
+ public:
+ /**
+ * Expose the text attribute to the given attribute set.
+ *
+ * @param aAttributes [in] the given attribute set
+ * @param aIncludeDefAttrValue [in] if true then attribute is exposed even
+ * if its value is the same as default one
+ */
+ virtual void Expose(nsIPersistentProperties* aAttributes,
+ bool aIncludeDefAttrValue) = 0;
+
+ /**
+ * Return true if the text attribute value on the given element equals with
+ * predefined attribute value.
+ */
+ virtual bool Equal(nsIContent* aElm) = 0;
+ };
+
+
+ /**
+ * Base class to work with text attributes. See derived classes below.
+ */
+ template
+ class TTextAttr : public TextAttr
+ {
+ public:
+ TTextAttr(bool aGetRootValue) : mGetRootValue(aGetRootValue) {}
+
+ // ITextAttr
+ virtual void Expose(nsIPersistentProperties* aAttributes,
+ bool aIncludeDefAttrValue)
+ {
+ if (mGetRootValue) {
+ if (mIsRootDefined)
+ ExposeValue(aAttributes, mRootNativeValue);
+ return;
+ }
+
+ if (mIsDefined) {
+ if (aIncludeDefAttrValue || mRootNativeValue != mNativeValue)
+ ExposeValue(aAttributes, mNativeValue);
+ return;
+ }
+
+ if (aIncludeDefAttrValue && mIsRootDefined)
+ ExposeValue(aAttributes, mRootNativeValue);
+ }
+
+ virtual bool Equal(nsIContent* aElm)
+ {
+ T nativeValue;
+ bool isDefined = GetValueFor(aElm, &nativeValue);
+
+ if (!mIsDefined && !isDefined)
+ return true;
+
+ if (mIsDefined && isDefined)
+ return nativeValue == mNativeValue;
+
+ if (mIsDefined)
+ return mNativeValue == mRootNativeValue;
+
+ return nativeValue == mRootNativeValue;
+ }
+
+ protected:
+
+ // Expose the text attribute with the given value to attribute set.
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const T& aValue) = 0;
+
+ // Return native value for the given DOM element.
+ virtual bool GetValueFor(nsIContent* aElm, T* aValue) = 0;
+
+ // Indicates if root value should be exposed.
+ bool mGetRootValue;
+
+ // Native value and flag indicating if the value is defined (initialized in
+ // derived classes). Note, undefined native value means it is inherited
+ // from root.
+ T mNativeValue;
+ bool mIsDefined;
+
+ // Native root value and flag indicating if the value is defined (initialized
+ // in derived classes).
+ T mRootNativeValue;
+ bool mIsRootDefined;
+ };
+
+
+ /**
+ * Class is used for the work with 'language' text attribute.
+ */
+ class LangTextAttr : public TTextAttr
+ {
+ public:
+ LangTextAttr(nsHyperTextAccessible* aRoot, nsIContent* aRootElm,
+ nsIContent* aElm);
+ virtual ~LangTextAttr() { }
+
+ protected:
+
+ // TextAttr
+ virtual bool GetValueFor(nsIContent* aElm, nsString* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nsString& aValue);
+
+ private:
+ bool GetLang(nsIContent* aElm, nsAString& aLang);
+ nsCOMPtr mRootContent;
+ };
+
+
+ /**
+ * 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.
+ */
+ class BGColorTextAttr : public TTextAttr
+ {
+ public:
+ BGColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~BGColorTextAttr() { }
+
+ protected:
+
+ // TextAttr
+ virtual bool GetValueFor(nsIContent* aElm, nscolor* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nscolor& aValue);
+
+ private:
+ bool GetColor(nsIFrame* aFrame, nscolor* aColor);
+ nsIFrame* mRootFrame;
+ };
+
+
+ /**
+ * Class is used for the work with 'color' text attribute.
+ */
+ class ColorTextAttr : public TTextAttr
+ {
+ public:
+ ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~ColorTextAttr() { }
+
+ protected:
+
+ // TTextAttr
+ virtual bool GetValueFor(nsIContent* aElm, nscolor* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nscolor& aValue);
+ };
+
+
+ /**
+ * Class is used for the work with "font-family" text attribute.
+ */
+ class FontFamilyTextAttr : public TTextAttr
+ {
+ public:
+ FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~FontFamilyTextAttr() { }
+
+ protected:
+
+ // TTextAttr
+ virtual bool GetValueFor(nsIContent* aElm, nsString* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nsString& aValue);
+
+ private:
+
+ bool GetFontFamily(nsIFrame* aFrame, nsString& aFamily);
+ };
+
+
+ /**
+ * Class is used for the work with "font-size" text attribute.
+ */
+ class FontSizeTextAttr : public TTextAttr
+ {
+ public:
+ FontSizeTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~FontSizeTextAttr() { }
+
+ protected:
+
+ // TTextAttr
+ virtual bool GetValueFor(nsIContent* aElm, nscoord* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nscoord& aValue);
+
+ private:
+ nsDeviceContext* mDC;
+ };
+
+
+ /**
+ * Class is used for the work with "font-style" text attribute.
+ */
+ class FontStyleTextAttr : public TTextAttr
+ {
+ public:
+ FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~FontStyleTextAttr() { }
+
+ protected:
+
+ // TTextAttr
+ virtual bool GetValueFor(nsIContent* aContent, nscoord* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const nscoord& aValue);
+ };
+
+
+ /**
+ * Class is used for the work with "font-weight" text attribute.
+ */
+ class FontWeightTextAttr : public TTextAttr
+ {
+ public:
+ FontWeightTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~FontWeightTextAttr() { }
+
+ protected:
+
+ // TTextAttr
+ virtual bool GetValueFor(nsIContent* aElm, PRInt32* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const PRInt32& aValue);
+
+ private:
+ PRInt32 GetFontWeight(nsIFrame* aFrame);
+ };
+
+
+ /**
+ * TextDecorTextAttr class is used for the work with
+ * "text-line-through-style", "text-line-through-color",
+ * "text-underline-style" and "text-underline-color" text attributes.
+ */
+
+ class TextDecorValue
+ {
+ public:
+ TextDecorValue() { }
+ TextDecorValue(nsIFrame* aFrame);
+
+ nscolor Color() const { return mColor; }
+ PRUint8 Style() const { return mStyle; }
+
+ bool IsDefined() const
+ { return IsUnderline() || IsLineThrough(); }
+ bool IsUnderline() const
+ { return mLine & NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; }
+ bool IsLineThrough() const
+ { return mLine & NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH; }
+
+ bool operator ==(const TextDecorValue& aValue)
+ {
+ return mColor == aValue.mColor && mLine == aValue.mLine &&
+ mStyle == aValue.mStyle;
+ }
+ bool operator !=(const TextDecorValue& aValue)
+ { return !(*this == aValue); }
+
+ private:
+ nscolor mColor;
+ PRUint8 mLine;
+ PRUint8 mStyle;
+ };
+
+ class TextDecorTextAttr : public TTextAttr
+ {
+ public:
+ TextDecorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
+ virtual ~TextDecorTextAttr() { }
+
+ protected:
+
+ // TextAttr
+ virtual bool GetValueFor(nsIContent* aElm, TextDecorValue* aValue);
+ virtual void ExposeValue(nsIPersistentProperties* aAttributes,
+ const TextDecorValue& aValue);
+ };
+
+}; // TextAttrMgr
+
+} // namespace a11y
+} // namespace mozilla
+
+#endif
diff --git a/accessible/src/base/nsTextAttrs.h b/accessible/src/base/nsTextAttrs.h
deleted file mode 100644
index aadcde7a8e6b..000000000000
--- a/accessible/src/base/nsTextAttrs.h
+++ /dev/null
@@ -1,426 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Mozilla Foundation.
- * Portions created by the Initial Developer are Copyright (C) 2007
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Alexander Surkov (original author)
- *
- * 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"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef nsTextAttrs_h_
-#define nsTextAttrs_h_
-
-class nsHyperTextAccessible;
-
-#include "nsIContent.h"
-#include "nsIFrame.h"
-#include "nsIPersistentProperties2.h"
-
-class nsITextAttr;
-
-/**
- * Used to expose text attributes for the hyper text accessible (see
- * nsHyperTextAccessible class). It is indended for the work with 'language' and
- * CSS based text attributes.
- *
- * @note "invalid: spelling" text attrbiute is implemented entirerly in
- * nsHyperTextAccessible class.
- */
-class nsTextAttrsMgr
-{
-public:
- /**
- * Constructor. If instance of the class is intended to expose default text
- * attributes then 'aIncludeDefAttrs' and 'aOffsetNode' argument must be
- * skiped.
- *
- * @param aHyperTextAcc hyper text accessible text attributes are
- * calculated for
- * @param aHyperTextNode DOM node of the given hyper text accessbile
- * @param aIncludeDefAttrs [optional] indicates whether default text
- * attributes should be included into list of exposed
- * text attributes.
- * @param oOffsetNode [optional] DOM node represents hyper text offset
- * inside hyper text accessible
- */
- nsTextAttrsMgr(nsHyperTextAccessible *aHyperTextAcc,
- bool aIncludeDefAttrs = true,
- nsAccessible *aOffsetAcc = nsnull,
- PRInt32 aOffsetAccIdx = -1);
-
- /*
- * Return text attributes and hyper text offsets where these attributes are
- * applied. Offsets are calculated in the case of non default attributes.
- *
- * @note In the case of default attributes pointers on hyper text offsets
- * must be skiped.
- *
- * @param aAttributes [in, out] text attributes list
- * @param aStartHTOffset [out, optional] start hyper text offset
- * @param aEndHTOffset [out, optional] end hyper text offset
- */
- nsresult GetAttributes(nsIPersistentProperties *aAttributes,
- PRInt32 *aStartHTOffset = nsnull,
- PRInt32 *aEndHTOffset = nsnull);
-
-protected:
- /**
- * Calculates range (start and end offsets) of text where the text attributes
- * are stretched. New offsets may be smaller if one of text attributes changes
- * its value before or after the given offsets.
- *
- * @param aTextAttrArray [in] text attributes array
- * @param aStartHTOffset [in, out] the start offset
- * @param aEndHTOffset [in, out] the end offset
- */
- nsresult GetRange(const nsTArray& aTextAttrArray,
- PRInt32 *aStartHTOffset, PRInt32 *aEndHTOffset);
-
-private:
- nsRefPtr mHyperTextAcc;
-
- bool mIncludeDefAttrs;
-
- nsRefPtr mOffsetAcc;
- PRInt32 mOffsetAccIdx;
-};
-
-
-////////////////////////////////////////////////////////////////////////////////
-// Private implementation details
-
-/**
- * Interface class of text attribute class implementations.
- */
-class nsITextAttr
-{
-public:
- /**
- * Return the name of text attribute.
- */
- virtual nsIAtom* GetName() const = 0;
-
- /**
- * Retrieve the value of text attribute in out param, return true if differs
- * from the default value of text attribute or if include default attribute
- * value flag is setted.
- *
- * @param aValue [in, out] the value of text attribute
- * @param aIncludeDefAttrValue [in] include default attribute value flag
- * @return true if text attribute value differs from
- * default or include default attribute value
- * flag is applied
- */
- virtual bool GetValue(nsAString& aValue, bool aIncludeDefAttrValue) = 0;
-
- /**
- * Return true if the text attribute value on the given element equals with
- * predefined attribute value.
- */
- virtual bool Equal(nsIContent *aContent) = 0;
-};
-
-
-/**
- * Base class to work with text attributes. See derived classes below.
- */
-template
-class nsTextAttr : public nsITextAttr
-{
-public:
- nsTextAttr(bool aGetRootValue) : mGetRootValue(aGetRootValue) {}
-
- // nsITextAttr
- virtual bool GetValue(nsAString& aValue, bool aIncludeDefAttrValue)
- {
- if (mGetRootValue) {
- Format(mRootNativeValue, aValue);
- return mIsRootDefined;
- }
-
- bool isDefined = mIsDefined;
- T* nativeValue = &mNativeValue;
-
- if (!isDefined) {
- if (aIncludeDefAttrValue) {
- isDefined = mIsRootDefined;
- nativeValue = &mRootNativeValue;
- }
- } else if (!aIncludeDefAttrValue) {
- isDefined = mRootNativeValue != mNativeValue;
- }
-
- if (!isDefined)
- return false;
-
- Format(*nativeValue, aValue);
- return true;
- }
-
- virtual bool Equal(nsIContent *aContent)
- {
- T nativeValue;
- bool isDefined = GetValueFor(aContent, &nativeValue);
-
- if (!mIsDefined && !isDefined)
- return true;
-
- if (mIsDefined && isDefined)
- return nativeValue == mNativeValue;
-
- if (mIsDefined)
- return mNativeValue == mRootNativeValue;
-
- return nativeValue == mRootNativeValue;
- }
-
-protected:
-
- // Return native value for the given DOM element.
- virtual bool GetValueFor(nsIContent *aContent, T *aValue) = 0;
-
- // Format native value to text attribute value.
- virtual void Format(const T& aValue, nsAString& aFormattedValue) = 0;
-
- // Indicates if root value should be exposed.
- bool mGetRootValue;
-
- // Native value and flag indicating if the value is defined (initialized in
- // derived classes). Note, undefined native value means it is inherited
- // from root.
- T mNativeValue;
- bool mIsDefined;
-
- // Native root value and flag indicating if the value is defined (initialized
- // in derived classes).
- T mRootNativeValue;
- bool mIsRootDefined;
-};
-
-
-/**
- * Class is used for the work with 'language' text attribute in nsTextAttrsMgr
- * class.
- */
-class nsLangTextAttr : public nsTextAttr
-{
-public:
- nsLangTextAttr(nsHyperTextAccessible *aRootAcc, nsIContent *aRootContent,
- nsIContent *aContent);
-
- // nsITextAttr
- virtual nsIAtom *GetName() const { return nsGkAtoms::language; }
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent *aElm, nsAutoString *aValue);
- virtual void Format(const nsAutoString& aValue, nsAString& aFormattedValue);
-
-private:
- bool GetLang(nsIContent *aContent, nsAString& aLang);
- nsCOMPtr mRootContent;
-};
-
-
-/**
- * Class is used for the work with CSS based text attributes in nsTextAttrsMgr
- * class.
- */
-class nsCSSTextAttr : public nsTextAttr
-{
-public:
- nsCSSTextAttr(PRUint32 aIndex, nsIContent *aRootContent,
- nsIContent *aContent);
-
- // nsITextAttr
- virtual nsIAtom *GetName() const;
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent *aContent, nsAutoString *aValue);
- virtual void Format(const nsAutoString& aValue, nsAString& aFormattedValue);
-
-private:
- PRInt32 mIndex;
-};
-
-
-/**
- * Class is used for the work with 'background-color' text attribute in
- * nsTextAttrsMgr class.
- */
-class nsBGColorTextAttr : public nsTextAttr
-{
-public:
- nsBGColorTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame);
-
- // nsITextAttr
- virtual nsIAtom *GetName() const { return nsGkAtoms::backgroundColor; }
-
-protected:
- // nsTextAttr
- virtual bool GetValueFor(nsIContent *aContent, nscolor *aValue);
- virtual void Format(const nscolor& aValue, nsAString& aFormattedValue);
-
-private:
- bool GetColor(nsIFrame *aFrame, nscolor *aColor);
- nsIFrame *mRootFrame;
-};
-
-
-/**
- * Class is used for the work with 'color' text attribute in nsTextAttrsMgr
- * class.
- */
-class ColorTextAttr : public nsTextAttr
-{
-public:
- ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
-
- // nsITextAttr
- virtual nsIAtom* GetName() const { return nsGkAtoms::color; }
-
-protected:
- // nsTextAttr
- virtual bool GetValueFor(nsIContent* aContent, nscolor* aValue);
- virtual void Format(const nscolor& aValue, nsAString& aFormattedValue);
-};
-
-
-/**
- * Class is used for the work with "font-family" text attribute in
- * nsTextAttrsMgr class.
- */
-class FontFamilyTextAttr : public nsTextAttr
-{
-public:
- FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
-
- // nsITextAttr
- virtual nsIAtom* GetName() const { return nsGkAtoms::font_family; }
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent* aContent, nsAutoString* aValue);
- virtual void Format(const nsAutoString& aValue, nsAString& aFormattedValue);
-
-private:
-
- bool GetFontFamily(nsIFrame* aFrame, nsAutoString& aFamily);
-};
-
-
-/**
- * Class is used for the work with "font-size" text attribute in nsTextAttrsMgr
- * class.
- */
-class nsFontSizeTextAttr : public nsTextAttr
-{
-public:
- nsFontSizeTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame);
-
- // nsITextAttr
- virtual nsIAtom *GetName() const { return nsGkAtoms::font_size; }
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent *aContent, nscoord *aValue);
- virtual void Format(const nscoord& aValue, nsAString& aFormattedValue);
-
-private:
-
- /**
- * Return font size for the given frame.
- *
- * @param aFrame [in] the given frame to query font-size
- * @return font size
- */
- nscoord GetFontSize(nsIFrame *aFrame);
-
- nsDeviceContext *mDC;
-};
-
-
-/**
- * Class is used for the work with "font-style" text attribute in nsTextAttrsMgr
- * class.
- */
-class FontStyleTextAttr : public nsTextAttr
-{
-public:
- FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame);
-
- // nsITextAttr
- virtual nsIAtom* GetName() const { return nsGkAtoms::font_style; }
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent* aContent, nscoord* aValue);
- virtual void Format(const nscoord &aValue, nsAString &aFormattedValue);
-};
-
-
-/**
- * Class is used for the work with "font-weight" text attribute in
- * nsTextAttrsMgr class.
- */
-class nsFontWeightTextAttr : public nsTextAttr
-{
-public:
- nsFontWeightTextAttr(nsIFrame *aRootFrame, nsIFrame *aFrame);
-
- // nsITextAttr
- virtual nsIAtom *GetName() const { return nsGkAtoms::fontWeight; }
-
-protected:
-
- // nsTextAttr
- virtual bool GetValueFor(nsIContent *aElm, PRInt32 *aValue);
- virtual void Format(const PRInt32& aValue, nsAString& aFormattedValue);
-
-private:
-
- /**
- * Return font weight for the given frame.
- *
- * @param aFrame [in] the given frame to query font weight
- * @return font weight
- */
- PRInt32 GetFontWeight(nsIFrame *aFrame);
-};
-
-#endif
diff --git a/accessible/src/html/nsHyperTextAccessible.cpp b/accessible/src/html/nsHyperTextAccessible.cpp
index b51741676bab..77903b195af1 100644
--- a/accessible/src/html/nsHyperTextAccessible.cpp
+++ b/accessible/src/html/nsHyperTextAccessible.cpp
@@ -42,9 +42,9 @@
#include "nsAccessibilityService.h"
#include "nsAccUtils.h"
#include "nsDocAccessible.h"
-#include "nsTextAttrs.h"
#include "Role.h"
#include "States.h"
+#include "TextAttrs.h"
#include "nsIClipboard.h"
#include "nsContentUtils.h"
@@ -1130,8 +1130,8 @@ nsHyperTextAccessible::GetTextAttributes(bool aIncludeDefAttrs,
// default attributes if they were requested, otherwise return empty set.
if (aOffset == 0) {
if (aIncludeDefAttrs) {
- nsTextAttrsMgr textAttrsMgr(this, true, nsnull, -1);
- return textAttrsMgr.GetAttributes(*aAttributes);
+ TextAttrsMgr textAttrsMgr(this);
+ textAttrsMgr.GetAttributes(*aAttributes);
}
return NS_OK;
}
@@ -1143,11 +1143,9 @@ nsHyperTextAccessible::GetTextAttributes(bool aIncludeDefAttrs,
PRInt32 endOffset = GetChildOffset(accAtOffsetIdx + 1);
PRInt32 offsetInAcc = aOffset - startOffset;
- nsTextAttrsMgr textAttrsMgr(this, aIncludeDefAttrs, accAtOffset,
- accAtOffsetIdx);
- nsresult rv = textAttrsMgr.GetAttributes(*aAttributes, &startOffset,
- &endOffset);
- NS_ENSURE_SUCCESS(rv, rv);
+ TextAttrsMgr textAttrsMgr(this, aIncludeDefAttrs, accAtOffset,
+ accAtOffsetIdx);
+ textAttrsMgr.GetAttributes(*aAttributes, &startOffset, &endOffset);
// Compute spelling attributes on text accessible only.
nsIFrame *offsetFrame = accAtOffset->GetFrame();
@@ -1186,8 +1184,9 @@ nsHyperTextAccessible::GetDefaultTextAttributes(nsIPersistentProperties **aAttri
NS_ADDREF(*aAttributes = attributes);
- nsTextAttrsMgr textAttrsMgr(this, true);
- return textAttrsMgr.GetAttributes(*aAttributes);
+ TextAttrsMgr textAttrsMgr(this);
+ textAttrsMgr.GetAttributes(*aAttributes);
+ return NS_OK;
}
PRInt32
diff --git a/accessible/tests/mochitest/attributes/test_text.html b/accessible/tests/mochitest/attributes/test_text.html
index fc4c92f7a594..f695301696dc 100644
--- a/accessible/tests/mochitest/attributes/test_text.html
+++ b/accessible/tests/mochitest/attributes/test_text.html
@@ -269,13 +269,19 @@
attrs = {};
testTextAttrs(ID, 84, attrs, defAttrs, 83, 91);
- attrs = { "text-underline-style": "solid" };
+ attrs = {
+ "text-underline-style": "solid",
+ "text-underline-color": gComputedStyle.color
+ };
testTextAttrs(ID, 92, attrs, defAttrs, 91, 101);
attrs = {};
testTextAttrs(ID, 102, attrs, defAttrs, 101, 109);
- attrs = { "text-line-through-style": "solid" };
+ attrs = {
+ "text-line-through-style": "solid",
+ "text-line-through-color": gComputedStyle.color
+ };
testTextAttrs(ID, 110, attrs, defAttrs, 109, 122);
attrs = {};
@@ -323,13 +329,19 @@
attrs = {};
testTextAttrs(ID, 85, attrs, defAttrs, 84, 92);
- attrs = { "text-underline-style": "solid" };
+ attrs = {
+ "text-underline-style": "solid",
+ "text-underline-color": gComputedStyle.color
+ };
testTextAttrs(ID, 93, attrs, defAttrs, 92, 102);
attrs = {};
testTextAttrs(ID, 103, attrs, defAttrs, 102, 110);
- attrs = { "text-line-through-style": "solid" };
+ attrs = {
+ "text-line-through-style": "solid",
+ "text-line-through-color": gComputedStyle.color
+ };
testTextAttrs(ID, 111, attrs, defAttrs, 110, 123);
attrs = {};
@@ -437,6 +449,48 @@
attrs = { };
testTextAttrs(ID, 31, attrs, defAttrs, 31, 45);
+ //////////////////////////////////////////////////////////////////////////
+ // area17, "text-decoration" tests
+ ID = "area17";
+ defAttrs = buildDefaultTextAttrs(ID, "12pt");
+ testDefaultTextAttrs(ID, defAttrs);
+
+ attrs = {
+ "text-underline-style": "solid",
+ "text-underline-color": "rgb(0, 0, 0)",
+ };
+ testTextAttrs(ID, 0, attrs, defAttrs, 0, 10);
+
+ attrs = {
+ "text-underline-style": "solid",
+ "text-underline-color": "rgb(0, 0, 255)",
+ };
+ testTextAttrs(ID, 10, attrs, defAttrs, 10, 15);
+
+ attrs = {
+ "text-underline-style": "dotted",
+ "text-underline-color": "rgb(0, 0, 0)",
+ };
+ testTextAttrs(ID, 15, attrs, defAttrs, 15, 22);
+
+ attrs = {
+ "text-line-through-style": "solid",
+ "text-line-through-color": "rgb(0, 0, 0)",
+ };
+ testTextAttrs(ID, 22, attrs, defAttrs, 22, 34);
+
+ attrs = {
+ "text-line-through-style": "solid",
+ "text-line-through-color": "rgb(0, 0, 255)",
+ };
+ testTextAttrs(ID, 34, attrs, defAttrs, 34, 39);
+
+ attrs = {
+ "text-line-through-style": "wavy",
+ "text-line-through-color": "rgb(0, 0, 0)",
+ };
+ testTextAttrs(ID, 39, attrs, defAttrs, 39, 44);
+
SimpleTest.finish();
}
@@ -450,12 +504,17 @@
href="https://bugzilla.mozilla.org/show_bug.cgi?id=345759"
title="Implement text attributes">
Mozilla Bug 345759
-
+
Mozilla Bug 473576
+
+ Mozilla Bug 523304
+
@@ -546,5 +605,15 @@
texttext
texttext
+
+
+ underline
+ blue
+ dotted
+ linethrough
+ blue
+ wavy
+
+