2014-06-12 05:11:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef mozilla_CounterStyleManager_h_
|
|
|
|
#define mozilla_CounterStyleManager_h_
|
|
|
|
|
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2014-09-25 04:19:00 +04:00
|
|
|
#include "nsCSSValue.h"
|
|
|
|
|
2014-06-12 05:11:00 +04:00
|
|
|
class nsPresContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-06-13 19:34:00 +04:00
|
|
|
class WritingMode;
|
|
|
|
|
2014-06-12 05:11:00 +04:00
|
|
|
typedef int32_t CounterValue;
|
|
|
|
|
|
|
|
class CounterStyleManager;
|
2014-09-25 04:19:00 +04:00
|
|
|
class AnonymousCounterStyle;
|
2014-06-12 05:11:00 +04:00
|
|
|
|
|
|
|
struct NegativeType;
|
|
|
|
struct PadType;
|
|
|
|
|
|
|
|
class CounterStyle
|
|
|
|
{
|
|
|
|
protected:
|
2016-07-09 00:39:53 +03:00
|
|
|
explicit constexpr CounterStyle(int32_t aStyle)
|
2014-06-12 05:11:00 +04:00
|
|
|
: mStyle(aStyle)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
CounterStyle(const CounterStyle& aOther) = delete;
|
|
|
|
void operator=(const CounterStyle& other) = delete;
|
2014-06-12 05:11:00 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
int32_t GetStyle() const { return mStyle; }
|
|
|
|
bool IsNone() const { return mStyle == NS_STYLE_LIST_STYLE_NONE; }
|
|
|
|
bool IsCustomStyle() const { return mStyle == NS_STYLE_LIST_STYLE_CUSTOM; }
|
|
|
|
// A style is dependent if it depends on the counter style manager.
|
|
|
|
// Custom styles are certainly dependent. In addition, some builtin
|
|
|
|
// styles are dependent for fallback.
|
|
|
|
bool IsDependentStyle() const;
|
|
|
|
|
2016-05-04 21:42:08 +03:00
|
|
|
virtual void GetStyleName(nsSubstring& aResult) = 0;
|
2014-06-12 05:11:00 +04:00
|
|
|
virtual void GetPrefix(nsSubstring& aResult) = 0;
|
|
|
|
virtual void GetSuffix(nsSubstring& aResult) = 0;
|
|
|
|
void GetCounterText(CounterValue aOrdinal,
|
2014-06-13 19:34:00 +04:00
|
|
|
WritingMode aWritingMode,
|
2014-06-12 05:11:00 +04:00
|
|
|
nsSubstring& aResult,
|
|
|
|
bool& aIsRTL);
|
|
|
|
virtual void GetSpokenCounterText(CounterValue aOrdinal,
|
2014-06-13 19:34:00 +04:00
|
|
|
WritingMode aWritingMode,
|
2014-06-12 05:11:00 +04:00
|
|
|
nsSubstring& aResult,
|
|
|
|
bool& aIsBullet);
|
|
|
|
|
|
|
|
// XXX This method could be removed once ::-moz-list-bullet and
|
|
|
|
// ::-moz-list-number are completely merged into ::marker.
|
|
|
|
virtual bool IsBullet() = 0;
|
|
|
|
|
|
|
|
virtual void GetNegative(NegativeType& aResult) = 0;
|
|
|
|
/**
|
|
|
|
* This method returns whether an ordinal is in the range of this
|
|
|
|
* counter style. Note that, it is possible that an ordinal in range
|
|
|
|
* is rejected by the generating algorithm.
|
|
|
|
*/
|
|
|
|
virtual bool IsOrdinalInRange(CounterValue aOrdinal) = 0;
|
|
|
|
/**
|
|
|
|
* This method returns whether an ordinal is in the default range of
|
|
|
|
* this counter style. This is the effective range when no 'range'
|
|
|
|
* descriptor is specified.
|
|
|
|
*/
|
|
|
|
virtual bool IsOrdinalInAutoRange(CounterValue aOrdinal) = 0;
|
|
|
|
virtual void GetPad(PadType& aResult) = 0;
|
|
|
|
virtual CounterStyle* GetFallback() = 0;
|
|
|
|
virtual uint8_t GetSpeakAs() = 0;
|
|
|
|
virtual bool UseNegativeSign() = 0;
|
|
|
|
|
|
|
|
virtual void CallFallbackStyle(CounterValue aOrdinal,
|
2014-06-13 19:34:00 +04:00
|
|
|
WritingMode aWritingMode,
|
2014-06-12 05:11:00 +04:00
|
|
|
nsSubstring& aResult,
|
2014-09-25 04:19:00 +04:00
|
|
|
bool& aIsRTL);
|
2014-06-12 05:11:00 +04:00
|
|
|
virtual bool GetInitialCounterText(CounterValue aOrdinal,
|
2014-06-13 19:34:00 +04:00
|
|
|
WritingMode aWritingMode,
|
2014-06-12 05:11:00 +04:00
|
|
|
nsSubstring& aResult,
|
|
|
|
bool& aIsRTL) = 0;
|
|
|
|
|
2014-09-25 04:19:00 +04:00
|
|
|
virtual AnonymousCounterStyle* AsAnonymous() { return nullptr; }
|
|
|
|
|
2014-06-12 05:11:00 +04:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int32_t mStyle;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class AnonymousCounterStyle final : public CounterStyle
|
2014-09-25 04:19:00 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-03-27 01:48:10 +03:00
|
|
|
explicit AnonymousCounterStyle(const nsSubstring& aContent);
|
2014-09-24 17:16:53 +04:00
|
|
|
explicit AnonymousCounterStyle(const nsCSSValue::Array* aValue);
|
2014-09-25 04:19:00 +04:00
|
|
|
|
2016-05-04 21:42:08 +03:00
|
|
|
virtual void GetStyleName(nsAString& aResult) override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void GetPrefix(nsAString& aResult) override;
|
|
|
|
virtual void GetSuffix(nsAString& aResult) override;
|
|
|
|
virtual bool IsBullet() override;
|
2014-09-25 04:19:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void GetNegative(NegativeType& aResult) override;
|
|
|
|
virtual bool IsOrdinalInRange(CounterValue aOrdinal) override;
|
|
|
|
virtual bool IsOrdinalInAutoRange(CounterValue aOrdinal) override;
|
|
|
|
virtual void GetPad(PadType& aResult) override;
|
|
|
|
virtual CounterStyle* GetFallback() override;
|
|
|
|
virtual uint8_t GetSpeakAs() override;
|
|
|
|
virtual bool UseNegativeSign() override;
|
2014-09-25 04:19:00 +04:00
|
|
|
|
|
|
|
virtual bool GetInitialCounterText(CounterValue aOrdinal,
|
|
|
|
WritingMode aWritingMode,
|
|
|
|
nsSubstring& aResult,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool& aIsRTL) override;
|
2014-09-25 04:19:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual AnonymousCounterStyle* AsAnonymous() override { return this; }
|
2014-09-25 04:19:00 +04:00
|
|
|
|
2015-03-27 01:48:10 +03:00
|
|
|
bool IsSingleString() const { return mSingleString; }
|
2014-09-25 04:19:00 +04:00
|
|
|
uint8_t GetSystem() const { return mSystem; }
|
|
|
|
const nsTArray<nsString>& GetSymbols() const { return mSymbols; }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(AnonymousCounterStyle, override)
|
2014-09-25 04:19:00 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
~AnonymousCounterStyle() {}
|
|
|
|
|
2015-03-27 01:48:10 +03:00
|
|
|
bool mSingleString;
|
2014-09-25 04:19:00 +04:00
|
|
|
uint8_t mSystem;
|
|
|
|
nsTArray<nsString> mSymbols;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CounterStyleManager final
|
2014-06-12 05:11:00 +04:00
|
|
|
{
|
2014-06-19 06:28:59 +04:00
|
|
|
private:
|
|
|
|
~CounterStyleManager();
|
2014-06-12 05:11:00 +04:00
|
|
|
public:
|
2014-08-08 03:48:38 +04:00
|
|
|
explicit CounterStyleManager(nsPresContext* aPresContext);
|
2014-06-12 05:11:00 +04:00
|
|
|
|
|
|
|
static void InitializeBuiltinCounterStyles();
|
|
|
|
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
bool IsInitial() const
|
|
|
|
{
|
|
|
|
// only 'none' and 'decimal'
|
|
|
|
return mCacheTable.Count() == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
CounterStyle* BuildCounterStyle(const nsSubstring& aName);
|
|
|
|
|
|
|
|
static CounterStyle* GetBuiltinStyle(int32_t aStyle);
|
|
|
|
static CounterStyle* GetNoneStyle()
|
|
|
|
{
|
|
|
|
return GetBuiltinStyle(NS_STYLE_LIST_STYLE_NONE);
|
|
|
|
}
|
|
|
|
static CounterStyle* GetDecimalStyle()
|
|
|
|
{
|
|
|
|
return GetBuiltinStyle(NS_STYLE_LIST_STYLE_DECIMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method will scan all existing counter styles generated by this
|
|
|
|
// manager, and remove or mark data dirty accordingly. It returns true
|
|
|
|
// if any counter style is changed, false elsewise. This method should
|
|
|
|
// be called when any counter style may be affected.
|
|
|
|
bool NotifyRuleChanged();
|
|
|
|
|
2014-10-17 00:10:00 +04:00
|
|
|
nsPresContext* PresContext() const { return mPresContext; }
|
|
|
|
|
2014-06-12 05:11:00 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(CounterStyleManager)
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, CounterStyle> mCacheTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* !defined(mozilla_CounterStyleManager_h_) */
|