1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/FontPropertyTypes.h"
13 #include "nsStyleConsts.h"
17 class nsDeviceContext
;
23 class LocalAccessible
;
24 class HyperTextAccessible
;
27 * Used to expose text attributes for the hyper text accessible (see
28 * HyperTextAccessible class).
30 * @note "invalid: spelling" text attribute is implemented entirely in
31 * HyperTextAccessible class.
36 * Constructor. Used to expose default text attributes.
38 explicit TextAttrsMgr(HyperTextAccessible
* aHyperTextAcc
)
39 : mOffsetAcc(nullptr),
40 mHyperTextAcc(aHyperTextAcc
),
42 mIncludeDefAttrs(true) {}
45 * Constructor. Used to expose text attributes at the given offset.
47 * @param aHyperTextAcc [in] hyper text accessible text attributes are
49 * @param aIncludeDefAttrs [optional] indicates whether default text
50 * attributes should be included into list of exposed
52 * @param oOffsetAcc [optional] offset an accessible the text attributes
53 * should be calculated for
54 * @param oOffsetAccIdx [optional] index in parent of offset accessible
56 TextAttrsMgr(HyperTextAccessible
* aHyperTextAcc
, bool aIncludeDefAttrs
,
57 LocalAccessible
* aOffsetAcc
, int32_t aOffsetAccIdx
)
58 : mOffsetAcc(aOffsetAcc
),
59 mHyperTextAcc(aHyperTextAcc
),
60 mOffsetAccIdx(aOffsetAccIdx
),
61 mIncludeDefAttrs(aIncludeDefAttrs
) {}
64 * Return text attributes and hyper text offsets where these attributes are
65 * applied. Offsets are calculated in the case of non default attributes.
67 * @note In the case of default attributes pointers on hyper text offsets
70 * @param aAttributes [in, out] text attributes list
71 * @param aStartHTOffset [out, optional] start hyper text offset
72 * @param aEndHTOffset [out, optional] end hyper text offset
74 void GetAttributes(AccAttributes
* aAttributes
,
75 uint32_t* aStartHTOffset
= nullptr,
76 uint32_t* aEndHTOffset
= nullptr);
80 * Calculates range (start and end offsets) of text where the text attributes
81 * are stretched. New offsets may be smaller if one of text attributes changes
82 * its value before or after the given offsets.
84 * @param aTextAttrArray [in] text attributes array
85 * @param aAttrArrayLen [in] text attributes array length
86 * @param aStartHTOffset [in, out] the start offset
87 * @param aEndHTOffset [in, out] the end offset
90 void GetRange(TextAttr
* aAttrArray
[], uint32_t aAttrArrayLen
,
91 uint32_t* aStartOffset
, uint32_t* aEndOffset
);
94 LocalAccessible
* mOffsetAcc
;
95 HyperTextAccessible
* mHyperTextAcc
;
96 int32_t mOffsetAccIdx
;
97 bool mIncludeDefAttrs
;
101 * Interface class of text attribute class implementations.
106 * Expose the text attribute to the given attribute set.
108 * @param aAttributes [in] the given attribute set
109 * @param aIncludeDefAttrValue [in] if true then attribute is exposed even
110 * if its value is the same as default one
112 virtual void Expose(AccAttributes
* aAttributes
,
113 bool aIncludeDefAttrValue
) = 0;
116 * Return true if the text attribute value on the given element equals with
117 * predefined attribute value.
119 virtual bool Equal(LocalAccessible
* aAccessible
) = 0;
123 * Base class to work with text attributes. See derived classes below.
126 class TTextAttr
: public TextAttr
{
128 explicit TTextAttr(bool aGetRootValue
) : mGetRootValue(aGetRootValue
) {}
131 virtual void Expose(AccAttributes
* aAttributes
,
132 bool aIncludeDefAttrValue
) override
{
134 if (mIsRootDefined
) ExposeValue(aAttributes
, mRootNativeValue
);
139 if (aIncludeDefAttrValue
|| mRootNativeValue
!= mNativeValue
) {
140 ExposeValue(aAttributes
, mNativeValue
);
145 if (aIncludeDefAttrValue
&& mIsRootDefined
) {
146 ExposeValue(aAttributes
, mRootNativeValue
);
150 virtual bool Equal(LocalAccessible
* aAccessible
) override
{
152 bool isDefined
= GetValueFor(aAccessible
, &nativeValue
);
154 if (!mIsDefined
&& !isDefined
) return true;
156 if (mIsDefined
&& isDefined
) return nativeValue
== mNativeValue
;
158 if (mIsDefined
) return mNativeValue
== mRootNativeValue
;
160 return nativeValue
== mRootNativeValue
;
164 // Expose the text attribute with the given value to attribute set.
165 virtual void ExposeValue(AccAttributes
* aAttributes
, const T
& aValue
) = 0;
167 // Return native value for the given DOM element.
168 virtual bool GetValueFor(LocalAccessible
* aAccessible
, T
* aValue
) = 0;
170 // Indicates if root value should be exposed.
173 // Native value and flag indicating if the value is defined (initialized in
174 // derived classes). Note, undefined native value means it is inherited
176 MOZ_INIT_OUTSIDE_CTOR T mNativeValue
;
177 MOZ_INIT_OUTSIDE_CTOR
bool mIsDefined
;
179 // Native root value and flag indicating if the value is defined
180 // (initialized in derived classes).
181 MOZ_INIT_OUTSIDE_CTOR T mRootNativeValue
;
182 MOZ_INIT_OUTSIDE_CTOR
bool mIsRootDefined
;
186 * Class is used for the work with 'language' text attribute.
188 class LangTextAttr
: public TTextAttr
<nsString
> {
190 LangTextAttr(HyperTextAccessible
* aRoot
, nsIContent
* aRootElm
,
192 virtual ~LangTextAttr();
196 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
197 nsString
* aValue
) override
;
198 virtual void ExposeValue(AccAttributes
* aAttributes
,
199 const nsString
& aValue
) override
;
202 nsCOMPtr
<nsIContent
> mRootContent
;
206 * Class is used for the 'invalid' text attribute. Note, it calculated
207 * the attribute from aria-invalid attribute only; invalid:spelling attribute
208 * calculated from misspelled text in the editor is managed by
209 * HyperTextAccessible and applied on top of the value from aria-invalid.
211 class InvalidTextAttr
: public TTextAttr
<uint32_t> {
213 InvalidTextAttr(nsIContent
* aRootElm
, nsIContent
* aElm
);
214 virtual ~InvalidTextAttr(){};
217 enum { eFalse
, eGrammar
, eSpelling
, eTrue
};
220 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
221 uint32_t* aValue
) override
;
222 virtual void ExposeValue(AccAttributes
* aAttributes
,
223 const uint32_t& aValue
) override
;
226 bool GetValue(nsIContent
* aElm
, uint32_t* aValue
);
227 nsIContent
* mRootElm
;
231 * Class is used for the work with 'background-color' text attribute.
233 class BGColorTextAttr
: public TTextAttr
<nscolor
> {
235 BGColorTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
236 virtual ~BGColorTextAttr() {}
240 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
241 nscolor
* aValue
) override
;
242 virtual void ExposeValue(AccAttributes
* aAttributes
,
243 const nscolor
& aValue
) override
;
246 bool GetColor(nsIFrame
* aFrame
, nscolor
* aColor
);
247 nsIFrame
* mRootFrame
;
251 * Class is used for the work with 'color' text attribute.
253 class ColorTextAttr
: public TTextAttr
<nscolor
> {
255 ColorTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
256 virtual ~ColorTextAttr() {}
260 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
261 nscolor
* aValue
) override
;
262 virtual void ExposeValue(AccAttributes
* aAttributes
,
263 const nscolor
& aValue
) override
;
267 * Class is used for the work with "font-family" text attribute.
269 class FontFamilyTextAttr
: public TTextAttr
<nsString
> {
271 FontFamilyTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
272 virtual ~FontFamilyTextAttr() {}
276 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
277 nsString
* aValue
) override
;
278 virtual void ExposeValue(AccAttributes
* aAttributes
,
279 const nsString
& aValue
) override
;
282 bool GetFontFamily(nsIFrame
* aFrame
, nsString
& aFamily
);
286 * Class is used for the work with "font-size" text attribute.
288 class FontSizeTextAttr
: public TTextAttr
<nscoord
> {
290 FontSizeTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
291 virtual ~FontSizeTextAttr() {}
295 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
296 nscoord
* aValue
) override
;
297 virtual void ExposeValue(AccAttributes
* aAttributes
,
298 const nscoord
& aValue
) override
;
301 nsDeviceContext
* mDC
;
305 * Class is used for the work with "font-style" text attribute.
307 class FontStyleTextAttr
: public TTextAttr
<mozilla::FontSlantStyle
> {
309 FontStyleTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
310 virtual ~FontStyleTextAttr() {}
314 virtual bool GetValueFor(LocalAccessible
* aContent
,
315 mozilla::FontSlantStyle
* aValue
) override
;
316 virtual void ExposeValue(AccAttributes
* aAttributes
,
317 const mozilla::FontSlantStyle
& aValue
) override
;
321 * Class is used for the work with "font-weight" text attribute.
323 class FontWeightTextAttr
: public TTextAttr
<mozilla::FontWeight
> {
325 FontWeightTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
326 virtual ~FontWeightTextAttr() {}
330 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
331 mozilla::FontWeight
* aValue
) override
;
332 virtual void ExposeValue(AccAttributes
* aAttributes
,
333 const mozilla::FontWeight
& aValue
) override
;
336 mozilla::FontWeight
GetFontWeight(nsIFrame
* aFrame
);
340 * Class is used for the work with 'auto-generated' text attribute.
342 class AutoGeneratedTextAttr
: public TTextAttr
<bool> {
344 AutoGeneratedTextAttr(HyperTextAccessible
* aHyperTextAcc
,
345 LocalAccessible
* aAccessible
);
346 virtual ~AutoGeneratedTextAttr() {}
350 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
351 bool* aValue
) override
;
352 virtual void ExposeValue(AccAttributes
* aAttributes
,
353 const bool& aValue
) override
;
357 * TextDecorTextAttr class is used for the work with
358 * "text-line-through-style", "text-line-through-color",
359 * "text-underline-style" and "text-underline-color" text attributes.
362 class TextDecorValue
{
366 mLine
{StyleTextDecorationLine::NONE
},
367 mStyle
{StyleTextDecorationStyle::None
} {}
368 explicit TextDecorValue(nsIFrame
* aFrame
);
370 nscolor
Color() const { return mColor
; }
371 mozilla::StyleTextDecorationStyle
Style() const { return mStyle
; }
373 bool IsDefined() const { return IsUnderline() || IsLineThrough(); }
374 bool IsUnderline() const {
375 return bool(mLine
& mozilla::StyleTextDecorationLine::UNDERLINE
);
377 bool IsLineThrough() const {
378 return bool(mLine
& mozilla::StyleTextDecorationLine::LINE_THROUGH
);
381 bool operator==(const TextDecorValue
& aValue
) {
382 return mColor
== aValue
.mColor
&& mLine
== aValue
.mLine
&&
383 mStyle
== aValue
.mStyle
;
385 bool operator!=(const TextDecorValue
& aValue
) { return !(*this == aValue
); }
389 mozilla::StyleTextDecorationLine mLine
;
390 mozilla::StyleTextDecorationStyle mStyle
;
393 class TextDecorTextAttr
: public TTextAttr
<TextDecorValue
> {
395 TextDecorTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
);
396 virtual ~TextDecorTextAttr() {}
400 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
401 TextDecorValue
* aValue
) override
;
402 virtual void ExposeValue(AccAttributes
* aAttributes
,
403 const TextDecorValue
& aValue
) override
;
407 * Class is used for the work with "text-position" text attribute.
410 enum TextPosValue
{ eTextPosBaseline
, eTextPosSub
, eTextPosSuper
};
412 class TextPosTextAttr
: public TTextAttr
<Maybe
<TextPosValue
>> {
414 TextPosTextAttr(nsIFrame
* aRootFrame
, nsIFrame
* aFrame
,
415 nsIContent
* aRootElm
, nsIContent
* aElm
);
416 virtual ~TextPosTextAttr() {}
420 virtual bool GetValueFor(LocalAccessible
* aAccessible
,
421 Maybe
<TextPosValue
>* aValue
) override
;
422 virtual void ExposeValue(AccAttributes
* aAttributes
,
423 const Maybe
<TextPosValue
>& aValue
) override
;
426 Maybe
<TextPosValue
> GetAriaTextPosValue(nsIContent
* aElm
) const;
427 Maybe
<TextPosValue
> GetAriaTextPosValue(nsIContent
* aElm
,
428 nsIFrame
*& ariaFrame
) const;
429 Maybe
<TextPosValue
> GetLayoutTextPosValue(nsIFrame
* aFrame
) const;
430 nsIContent
* mRootElm
;
436 } // namespace mozilla