michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsTextAttrs_h_ michael@0: #define nsTextAttrs_h_ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsColor.h" michael@0: #include "nsStyleConsts.h" michael@0: michael@0: class nsIFrame; michael@0: class nsIPersistentProperties; michael@0: class nsIContent; michael@0: class nsDeviceContext; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: class Accessible; michael@0: class HyperTextAccessible; michael@0: michael@0: /** michael@0: * Used to expose text attributes for the hyper text accessible (see michael@0: * HyperTextAccessible class). michael@0: * michael@0: * @note "invalid: spelling" text attribute is implemented entirely in michael@0: * HyperTextAccessible class. michael@0: */ michael@0: class TextAttrsMgr michael@0: { michael@0: public: michael@0: /** michael@0: * Constructor. Used to expose default text attributes. michael@0: */ michael@0: TextAttrsMgr(HyperTextAccessible* aHyperTextAcc) : michael@0: mOffsetAcc(nullptr), mHyperTextAcc(aHyperTextAcc), michael@0: mOffsetAccIdx(-1), mIncludeDefAttrs(true) { } michael@0: michael@0: /** michael@0: * Constructor. Used to expose text attributes at the given offset. michael@0: * michael@0: * @param aHyperTextAcc [in] hyper text accessible text attributes are michael@0: * calculated for michael@0: * @param aIncludeDefAttrs [optional] indicates whether default text michael@0: * attributes should be included into list of exposed michael@0: * text attributes michael@0: * @param oOffsetAcc [optional] offset an accessible the text attributes michael@0: * should be calculated for michael@0: * @param oOffsetAccIdx [optional] index in parent of offset accessible michael@0: */ michael@0: TextAttrsMgr(HyperTextAccessible* aHyperTextAcc, michael@0: bool aIncludeDefAttrs, michael@0: Accessible* aOffsetAcc, michael@0: int32_t aOffsetAccIdx) : michael@0: mOffsetAcc(aOffsetAcc), mHyperTextAcc(aHyperTextAcc), michael@0: mOffsetAccIdx(aOffsetAccIdx), mIncludeDefAttrs(aIncludeDefAttrs) { } michael@0: michael@0: /* michael@0: * Return text attributes and hyper text offsets where these attributes are michael@0: * applied. Offsets are calculated in the case of non default attributes. michael@0: * michael@0: * @note In the case of default attributes pointers on hyper text offsets michael@0: * must be skipped. michael@0: * michael@0: * @param aAttributes [in, out] text attributes list michael@0: * @param aStartHTOffset [out, optional] start hyper text offset michael@0: * @param aEndHTOffset [out, optional] end hyper text offset michael@0: */ michael@0: void GetAttributes(nsIPersistentProperties* aAttributes, michael@0: int32_t* aStartHTOffset = nullptr, michael@0: int32_t* aEndHTOffset = nullptr); michael@0: michael@0: protected: michael@0: /** michael@0: * Calculates range (start and end offsets) of text where the text attributes michael@0: * are stretched. New offsets may be smaller if one of text attributes changes michael@0: * its value before or after the given offsets. michael@0: * michael@0: * @param aTextAttrArray [in] text attributes array michael@0: * @param aAttrArrayLen [in] text attributes array length michael@0: * @param aStartHTOffset [in, out] the start offset michael@0: * @param aEndHTOffset [in, out] the end offset michael@0: */ michael@0: class TextAttr; michael@0: void GetRange(TextAttr* aAttrArray[], uint32_t aAttrArrayLen, michael@0: int32_t* aStartHTOffset, int32_t* aEndHTOffset); michael@0: michael@0: private: michael@0: Accessible* mOffsetAcc; michael@0: HyperTextAccessible* mHyperTextAcc; michael@0: int32_t mOffsetAccIdx; michael@0: bool mIncludeDefAttrs; michael@0: michael@0: protected: michael@0: michael@0: /** michael@0: * Interface class of text attribute class implementations. michael@0: */ michael@0: class TextAttr michael@0: { michael@0: public: michael@0: /** michael@0: * Expose the text attribute to the given attribute set. michael@0: * michael@0: * @param aAttributes [in] the given attribute set michael@0: * @param aIncludeDefAttrValue [in] if true then attribute is exposed even michael@0: * if its value is the same as default one michael@0: */ michael@0: virtual void Expose(nsIPersistentProperties* aAttributes, michael@0: bool aIncludeDefAttrValue) = 0; michael@0: michael@0: /** michael@0: * Return true if the text attribute value on the given element equals with michael@0: * predefined attribute value. michael@0: */ michael@0: virtual bool Equal(Accessible* aAccessible) = 0; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Base class to work with text attributes. See derived classes below. michael@0: */ michael@0: template michael@0: class TTextAttr : public TextAttr michael@0: { michael@0: public: michael@0: TTextAttr(bool aGetRootValue) : mGetRootValue(aGetRootValue) {} michael@0: michael@0: // TextAttr michael@0: virtual void Expose(nsIPersistentProperties* aAttributes, michael@0: bool aIncludeDefAttrValue) michael@0: { michael@0: if (mGetRootValue) { michael@0: if (mIsRootDefined) michael@0: ExposeValue(aAttributes, mRootNativeValue); michael@0: return; michael@0: } michael@0: michael@0: if (mIsDefined) { michael@0: if (aIncludeDefAttrValue || mRootNativeValue != mNativeValue) michael@0: ExposeValue(aAttributes, mNativeValue); michael@0: return; michael@0: } michael@0: michael@0: if (aIncludeDefAttrValue && mIsRootDefined) michael@0: ExposeValue(aAttributes, mRootNativeValue); michael@0: } michael@0: michael@0: virtual bool Equal(Accessible* aAccessible) michael@0: { michael@0: T nativeValue; michael@0: bool isDefined = GetValueFor(aAccessible, &nativeValue); michael@0: michael@0: if (!mIsDefined && !isDefined) michael@0: return true; michael@0: michael@0: if (mIsDefined && isDefined) michael@0: return nativeValue == mNativeValue; michael@0: michael@0: if (mIsDefined) michael@0: return mNativeValue == mRootNativeValue; michael@0: michael@0: return nativeValue == mRootNativeValue; michael@0: } michael@0: michael@0: protected: michael@0: michael@0: // Expose the text attribute with the given value to attribute set. michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const T& aValue) = 0; michael@0: michael@0: // Return native value for the given DOM element. michael@0: virtual bool GetValueFor(Accessible* aAccessible, T* aValue) = 0; michael@0: michael@0: // Indicates if root value should be exposed. michael@0: bool mGetRootValue; michael@0: michael@0: // Native value and flag indicating if the value is defined (initialized in michael@0: // derived classes). Note, undefined native value means it is inherited michael@0: // from root. michael@0: T mNativeValue; michael@0: bool mIsDefined; michael@0: michael@0: // Native root value and flag indicating if the value is defined (initialized michael@0: // in derived classes). michael@0: T mRootNativeValue; michael@0: bool mIsRootDefined; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with 'language' text attribute. michael@0: */ michael@0: class LangTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: LangTextAttr(HyperTextAccessible* aRoot, nsIContent* aRootElm, michael@0: nsIContent* aElm); michael@0: virtual ~LangTextAttr(); michael@0: michael@0: protected: michael@0: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, nsString* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nsString& aValue); michael@0: michael@0: private: michael@0: nsCOMPtr mRootContent; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the 'invalid' text attribute. Note, it calculated michael@0: * the attribute from aria-invalid attribute only; invalid:spelling attribute michael@0: * calculated from misspelled text in the editor is managed by michael@0: * HyperTextAccessible and applied on top of the value from aria-invalid. michael@0: */ michael@0: class InvalidTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: InvalidTextAttr(nsIContent* aRootElm, nsIContent* aElm); michael@0: virtual ~InvalidTextAttr() { }; michael@0: michael@0: protected: michael@0: michael@0: enum { michael@0: eFalse, michael@0: eGrammar, michael@0: eSpelling, michael@0: eTrue michael@0: }; michael@0: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, uint32_t* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const uint32_t& aValue); michael@0: michael@0: private: michael@0: bool GetValue(nsIContent* aElm, uint32_t* aValue); michael@0: nsIContent* mRootElm; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with 'background-color' text attribute. michael@0: */ michael@0: class BGColorTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: BGColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~BGColorTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, nscolor* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nscolor& aValue); michael@0: michael@0: private: michael@0: bool GetColor(nsIFrame* aFrame, nscolor* aColor); michael@0: nsIFrame* mRootFrame; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with 'color' text attribute. michael@0: */ michael@0: class ColorTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: ColorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~ColorTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TTextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, nscolor* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nscolor& aValue); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with "font-family" text attribute. michael@0: */ michael@0: class FontFamilyTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: FontFamilyTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~FontFamilyTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TTextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, nsString* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nsString& aValue); michael@0: michael@0: private: michael@0: michael@0: bool GetFontFamily(nsIFrame* aFrame, nsString& aFamily); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with "font-size" text attribute. michael@0: */ michael@0: class FontSizeTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: FontSizeTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~FontSizeTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TTextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, nscoord* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nscoord& aValue); michael@0: michael@0: private: michael@0: nsDeviceContext* mDC; michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with "font-style" text attribute. michael@0: */ michael@0: class FontStyleTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: FontStyleTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~FontStyleTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TTextAttr michael@0: virtual bool GetValueFor(Accessible* aContent, nscoord* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const nscoord& aValue); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * Class is used for the work with "font-weight" text attribute. michael@0: */ michael@0: class FontWeightTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: FontWeightTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~FontWeightTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TTextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, int32_t* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const int32_t& aValue); michael@0: michael@0: private: michael@0: int32_t GetFontWeight(nsIFrame* aFrame); michael@0: }; michael@0: michael@0: /** michael@0: * Class is used for the work with 'auto-generated' text attribute. michael@0: */ michael@0: class AutoGeneratedTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: AutoGeneratedTextAttr(HyperTextAccessible* aHyperTextAcc, michael@0: Accessible* aAccessible); michael@0: virtual ~AutoGeneratedTextAttr() { } michael@0: michael@0: protected: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, bool* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const bool& aValue); michael@0: }; michael@0: michael@0: michael@0: /** michael@0: * TextDecorTextAttr class is used for the work with michael@0: * "text-line-through-style", "text-line-through-color", michael@0: * "text-underline-style" and "text-underline-color" text attributes. michael@0: */ michael@0: michael@0: class TextDecorValue michael@0: { michael@0: public: michael@0: TextDecorValue() { } michael@0: TextDecorValue(nsIFrame* aFrame); michael@0: michael@0: nscolor Color() const { return mColor; } michael@0: uint8_t Style() const { return mStyle; } michael@0: michael@0: bool IsDefined() const michael@0: { return IsUnderline() || IsLineThrough(); } michael@0: bool IsUnderline() const michael@0: { return mLine & NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; } michael@0: bool IsLineThrough() const michael@0: { return mLine & NS_STYLE_TEXT_DECORATION_LINE_LINE_THROUGH; } michael@0: michael@0: bool operator ==(const TextDecorValue& aValue) michael@0: { michael@0: return mColor == aValue.mColor && mLine == aValue.mLine && michael@0: mStyle == aValue.mStyle; michael@0: } michael@0: bool operator !=(const TextDecorValue& aValue) michael@0: { return !(*this == aValue); } michael@0: michael@0: private: michael@0: nscolor mColor; michael@0: uint8_t mLine; michael@0: uint8_t mStyle; michael@0: }; michael@0: michael@0: class TextDecorTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: TextDecorTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~TextDecorTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, TextDecorValue* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const TextDecorValue& aValue); michael@0: }; michael@0: michael@0: /** michael@0: * Class is used for the work with "text-position" text attribute. michael@0: */ michael@0: michael@0: enum TextPosValue { michael@0: eTextPosNone = 0, michael@0: eTextPosBaseline, michael@0: eTextPosSub, michael@0: eTextPosSuper michael@0: }; michael@0: michael@0: class TextPosTextAttr : public TTextAttr michael@0: { michael@0: public: michael@0: TextPosTextAttr(nsIFrame* aRootFrame, nsIFrame* aFrame); michael@0: virtual ~TextPosTextAttr() { } michael@0: michael@0: protected: michael@0: michael@0: // TextAttr michael@0: virtual bool GetValueFor(Accessible* aAccessible, TextPosValue* aValue); michael@0: virtual void ExposeValue(nsIPersistentProperties* aAttributes, michael@0: const TextPosValue& aValue); michael@0: michael@0: private: michael@0: TextPosValue GetTextPosValue(nsIFrame* aFrame) const; michael@0: }; michael@0: michael@0: }; // TextAttrMgr michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif