Bug 728907 - don't use GetComputedStyle for text attributes: font-style, r=tbsaunde

This commit is contained in:
Alexander Surkov 2012-02-29 16:35:51 +09:00
parent 997c3fe22a
commit 832f5e86eb
4 changed files with 75 additions and 12 deletions

View File

@ -112,7 +112,7 @@ StyleInfo::Margin(css::Side aSide, nsAString& aValue)
}
void
StyleInfo::Format(const nscolor& aValue, nsString& aFormattedValue)
StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
{
// Combine the string like rgb(R, G, B) from nscolor.
aFormattedValue.AppendLiteral("rgb(");
@ -123,3 +123,11 @@ StyleInfo::Format(const nscolor& aValue, nsString& aFormattedValue)
aFormattedValue.AppendInt(NS_GET_B(aValue));
aFormattedValue.Append(')');
}
void
StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
{
nsCSSKeyword keyword =
nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
}

View File

@ -60,7 +60,8 @@ public:
void MarginTop(nsAString& aValue) { Margin(css::eSideTop, aValue); }
void MarginBottom(nsAString& aValue) { Margin(css::eSideBottom, aValue); }
static void Format(const nscolor& aValue, nsString& aFormattedValue);
static void FormatColor(const nscolor& aValue, nsString& aFormattedValue);
static void FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue);
private:
StyleInfo() MOZ_DELETE;

View File

@ -74,7 +74,6 @@ const char* const kCopyValue = nsnull;
static nsCSSTextAttrMapItem gCSSTextAttrsMap[] =
{
// CSS name CSS value Attribute name Attribute value
{ "font-style", kAnyValue, &nsGkAtoms::font_style, kCopyValue },
{ "text-decoration", "line-through", &nsGkAtoms::textLineThroughStyle, "solid" },
{ "text-decoration", "underline", &nsGkAtoms::textUnderlineStyle, "solid" },
{ "vertical-align", kAnyValue, &nsGkAtoms::textPosition, kCopyValue }
@ -156,20 +155,16 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
nsLangTextAttr langTextAttr(mHyperTextAcc, hyperTextElm, offsetNode);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&langTextAttr));
// "font-style" text attribute
nsCSSTextAttr fontStyleTextAttr(0, hyperTextElm, offsetElm);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&fontStyleTextAttr));
// "text-line-through-style" text attribute
nsCSSTextAttr lineThroughTextAttr(1, hyperTextElm, offsetElm);
nsCSSTextAttr lineThroughTextAttr(0, hyperTextElm, offsetElm);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&lineThroughTextAttr));
// "text-underline-style" text attribute
nsCSSTextAttr underlineTextAttr(2, hyperTextElm, offsetElm);
nsCSSTextAttr underlineTextAttr(1, hyperTextElm, offsetElm);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&underlineTextAttr));
// "text-position" text attribute
nsCSSTextAttr posTextAttr(3, hyperTextElm, offsetElm);
nsCSSTextAttr posTextAttr(2, hyperTextElm, offsetElm);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&posTextAttr));
// "background-color" text attribute
@ -188,6 +183,10 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes,
nsFontSizeTextAttr fontSizeTextAttr(rootFrame, frame);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&fontSizeTextAttr));
// "font-style" text attribute
FontStyleTextAttr fontStyleTextAttr(rootFrame, frame);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&fontStyleTextAttr));
// "font-weight" text attribute
nsFontWeightTextAttr fontWeightTextAttr(rootFrame, frame);
textAttrArray.AppendElement(static_cast<nsITextAttr*>(&fontWeightTextAttr));
@ -390,7 +389,7 @@ void
nsBGColorTextAttr::Format(const nscolor& aValue, nsAString& aFormattedValue)
{
nsAutoString value;
StyleInfo::Format(aValue, value);
StyleInfo::FormatColor(aValue, value);
aFormattedValue = value;
}
@ -452,7 +451,7 @@ void
ColorTextAttr::Format(const nscolor& aValue, nsAString& aFormattedValue)
{
nsAutoString value;
StyleInfo::Format(aValue, value);
StyleInfo::FormatColor(aValue, value);
aFormattedValue = value;
}
@ -559,6 +558,41 @@ nsFontSizeTextAttr::GetFontSize(nsIFrame *aFrame)
}
////////////////////////////////////////////////////////////////////////////////
// FontStyleTextAttr
////////////////////////////////////////////////////////////////////////////////
FontStyleTextAttr::FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame) :
nsTextAttr<nscoord>(!aFrame)
{
mRootNativeValue = aRootFrame->GetStyleFont()->mFont.style;
mIsRootDefined = true;
if (aFrame) {
mNativeValue = aFrame->GetStyleFont()->mFont.style;
mIsDefined = true;
}
}
bool
FontStyleTextAttr::GetValueFor(nsIContent* aContent, nscoord* aValue)
{
nsIFrame* frame = aContent->GetPrimaryFrame();
if (frame) {
*aValue = frame->GetStyleFont()->mFont.style;
return true;
}
return false;
}
void
FontStyleTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue)
{
StyleInfo::FormatFontStyle(aValue, aFormattedValue);
}
////////////////////////////////////////////////////////////////////////////////
// nsFontWeightTextAttr
////////////////////////////////////////////////////////////////////////////////

View File

@ -381,6 +381,26 @@ private:
};
/**
* Class is used for the work with "font-style" text attribute in nsTextAttrsMgr
* class.
*/
class FontStyleTextAttr : public nsTextAttr<nscoord>
{
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.