From f3df2050fad1d9556f3b1a7e69c9b9184d75c887 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Wed, 29 Feb 2012 16:35:51 +0900 Subject: [PATCH] Bug 728907 - don't use GetComputedStyle for text attributes: font-style, r=tbsaunde --- accessible/src/base/StyleInfo.cpp | 10 +++++- accessible/src/base/StyleInfo.h | 3 +- accessible/src/base/nsTextAttrs.cpp | 54 +++++++++++++++++++++++------ accessible/src/base/nsTextAttrs.h | 20 +++++++++++ 4 files changed, 75 insertions(+), 12 deletions(-) diff --git a/accessible/src/base/StyleInfo.cpp b/accessible/src/base/StyleInfo.cpp index f79d819f84c..4bd503ddcfe 100644 --- a/accessible/src/base/StyleInfo.cpp +++ b/accessible/src/base/StyleInfo.cpp @@ -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); +} diff --git a/accessible/src/base/StyleInfo.h b/accessible/src/base/StyleInfo.h index 9b9d5aedf6d..b77cd048557 100644 --- a/accessible/src/base/StyleInfo.h +++ b/accessible/src/base/StyleInfo.h @@ -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; diff --git a/accessible/src/base/nsTextAttrs.cpp b/accessible/src/base/nsTextAttrs.cpp index c300deca139..a6edf8789a7 100644 --- a/accessible/src/base/nsTextAttrs.cpp +++ b/accessible/src/base/nsTextAttrs.cpp @@ -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(&langTextAttr)); - // "font-style" text attribute - nsCSSTextAttr fontStyleTextAttr(0, hyperTextElm, offsetElm); - textAttrArray.AppendElement(static_cast(&fontStyleTextAttr)); - // "text-line-through-style" text attribute - nsCSSTextAttr lineThroughTextAttr(1, hyperTextElm, offsetElm); + nsCSSTextAttr lineThroughTextAttr(0, hyperTextElm, offsetElm); textAttrArray.AppendElement(static_cast(&lineThroughTextAttr)); // "text-underline-style" text attribute - nsCSSTextAttr underlineTextAttr(2, hyperTextElm, offsetElm); + nsCSSTextAttr underlineTextAttr(1, hyperTextElm, offsetElm); textAttrArray.AppendElement(static_cast(&underlineTextAttr)); // "text-position" text attribute - nsCSSTextAttr posTextAttr(3, hyperTextElm, offsetElm); + nsCSSTextAttr posTextAttr(2, hyperTextElm, offsetElm); textAttrArray.AppendElement(static_cast(&posTextAttr)); // "background-color" text attribute @@ -188,6 +183,10 @@ nsTextAttrsMgr::GetAttributes(nsIPersistentProperties *aAttributes, nsFontSizeTextAttr fontSizeTextAttr(rootFrame, frame); textAttrArray.AppendElement(static_cast(&fontSizeTextAttr)); + // "font-style" text attribute + FontStyleTextAttr fontStyleTextAttr(rootFrame, frame); + textAttrArray.AppendElement(static_cast(&fontStyleTextAttr)); + // "font-weight" text attribute nsFontWeightTextAttr fontWeightTextAttr(rootFrame, frame); textAttrArray.AppendElement(static_cast(&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(!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 //////////////////////////////////////////////////////////////////////////////// diff --git a/accessible/src/base/nsTextAttrs.h b/accessible/src/base/nsTextAttrs.h index 8872574deb6..d79b1e3ceab 100644 --- a/accessible/src/base/nsTextAttrs.h +++ b/accessible/src/base/nsTextAttrs.h @@ -381,6 +381,26 @@ private: }; +/** + * 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.