1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_CounterStyleManager_h_
7 #define mozilla_CounterStyleManager_h_
9 #include "nsStringFwd.h"
10 #include "nsRefPtrHashtable.h"
11 #include "nsHashKeys.h"
13 #include "nsStyleConsts.h"
15 #include "mozilla/NullPtr.h"
16 #include "mozilla/Attributes.h"
19 class nsCSSCounterStyleRule
;
25 typedef int32_t CounterValue
;
27 class CounterStyleManager
;
35 explicit MOZ_CONSTEXPR
CounterStyle(int32_t aStyle
)
41 CounterStyle(const CounterStyle
& aOther
) MOZ_DELETE
;
42 void operator=(const CounterStyle
& other
) MOZ_DELETE
;
45 int32_t GetStyle() const { return mStyle
; }
46 bool IsNone() const { return mStyle
== NS_STYLE_LIST_STYLE_NONE
; }
47 bool IsCustomStyle() const { return mStyle
== NS_STYLE_LIST_STYLE_CUSTOM
; }
48 // A style is dependent if it depends on the counter style manager.
49 // Custom styles are certainly dependent. In addition, some builtin
50 // styles are dependent for fallback.
51 bool IsDependentStyle() const;
53 virtual void GetPrefix(nsSubstring
& aResult
) = 0;
54 virtual void GetSuffix(nsSubstring
& aResult
) = 0;
55 void GetCounterText(CounterValue aOrdinal
,
56 WritingMode aWritingMode
,
59 virtual void GetSpokenCounterText(CounterValue aOrdinal
,
60 WritingMode aWritingMode
,
64 // XXX This method could be removed once ::-moz-list-bullet and
65 // ::-moz-list-number are completely merged into ::marker.
66 virtual bool IsBullet() = 0;
68 virtual void GetNegative(NegativeType
& aResult
) = 0;
70 * This method returns whether an ordinal is in the range of this
71 * counter style. Note that, it is possible that an ordinal in range
72 * is rejected by the generating algorithm.
74 virtual bool IsOrdinalInRange(CounterValue aOrdinal
) = 0;
76 * This method returns whether an ordinal is in the default range of
77 * this counter style. This is the effective range when no 'range'
78 * descriptor is specified.
80 virtual bool IsOrdinalInAutoRange(CounterValue aOrdinal
) = 0;
81 virtual void GetPad(PadType
& aResult
) = 0;
82 virtual CounterStyle
* GetFallback() = 0;
83 virtual uint8_t GetSpeakAs() = 0;
84 virtual bool UseNegativeSign() = 0;
86 virtual void CallFallbackStyle(CounterValue aOrdinal
,
87 WritingMode aWritingMode
,
90 virtual bool GetInitialCounterText(CounterValue aOrdinal
,
91 WritingMode aWritingMode
,
95 NS_IMETHOD_(MozExternalRefCountType
) AddRef() = 0;
96 NS_IMETHOD_(MozExternalRefCountType
) Release() = 0;
102 class CounterStyleManager MOZ_FINAL
105 ~CounterStyleManager();
107 explicit CounterStyleManager(nsPresContext
* aPresContext
);
109 static void InitializeBuiltinCounterStyles();
113 bool IsInitial() const
115 // only 'none' and 'decimal'
116 return mCacheTable
.Count() == 2;
119 CounterStyle
* BuildCounterStyle(const nsSubstring
& aName
);
121 static CounterStyle
* GetBuiltinStyle(int32_t aStyle
);
122 static CounterStyle
* GetNoneStyle()
124 return GetBuiltinStyle(NS_STYLE_LIST_STYLE_NONE
);
126 static CounterStyle
* GetDecimalStyle()
128 return GetBuiltinStyle(NS_STYLE_LIST_STYLE_DECIMAL
);
131 // This method will scan all existing counter styles generated by this
132 // manager, and remove or mark data dirty accordingly. It returns true
133 // if any counter style is changed, false elsewise. This method should
134 // be called when any counter style may be affected.
135 bool NotifyRuleChanged();
137 nsPresContext
* PresContext() const { return mPresContext
; }
139 NS_INLINE_DECL_REFCOUNTING(CounterStyleManager
)
142 nsPresContext
* mPresContext
;
143 nsRefPtrHashtable
<nsStringHashKey
, CounterStyle
> mCacheTable
;
146 } // namespace mozilla
148 #endif /* !defined(mozilla_CounterStyleManager_h_) */