Bug 966166 - Part 2: Computation of counter style. r=dbaron

This commit is contained in:
Xidorn Quan 2014-06-11 21:11:00 -04:00
parent 96a68ed4e1
commit 4831f428cc
8 changed files with 1797 additions and 5 deletions

View File

@ -43,6 +43,7 @@
#include "nsObjectFrame.h"
#include "nsTransitionManager.h"
#include "nsAnimationManager.h"
#include "CounterStyleManager.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Element.h"
#include "nsIMessageManager.h"
@ -964,9 +965,12 @@ nsPresContext::Init(nsDeviceContext* aDeviceContext)
mAnimationManager = new nsAnimationManager(this);
// FIXME: Why is mozilla:: needed?
// Since there are methods in nsPresContext have the same name as the
// classes, it is necessary to prefix them with the namespace here.
mRestyleManager = new mozilla::RestyleManager(this);
mCounterStyleManager = new mozilla::CounterStyleManager(this);
if (mDocument->GetDisplayDocument()) {
NS_ASSERTION(mDocument->GetDisplayDocument()->GetShell() &&
mDocument->GetDisplayDocument()->GetShell()->GetPresContext(),
@ -1142,6 +1146,10 @@ nsPresContext::SetShell(nsIPresShell* aShell)
mRestyleManager->Disconnect();
mRestyleManager = nullptr;
}
if (mCounterStyleManager) {
mCounterStyleManager->Disconnect();
mCounterStyleManager = nullptr;
}
if (IsRoot()) {
// Have to cancel our plugin geometry timer, because the

View File

@ -69,6 +69,7 @@ class nsDeviceContext;
namespace mozilla {
class EventStateManager;
class RestyleManager;
class CounterStyleManager;
namespace dom {
class MediaQueryList;
}
@ -242,6 +243,10 @@ public:
nsRefreshDriver* RefreshDriver() { return mRefreshDriver; }
mozilla::RestyleManager* RestyleManager() { return mRestyleManager; }
mozilla::CounterStyleManager* CounterStyleManager() {
return mCounterStyleManager;
}
#endif
/**
@ -1182,6 +1187,7 @@ protected:
nsRefPtr<nsTransitionManager> mTransitionManager;
nsRefPtr<nsAnimationManager> mAnimationManager;
nsRefPtr<mozilla::RestyleManager> mRestyleManager;
nsRefPtr<mozilla::CounterStyleManager> mCounterStyleManager;
nsIAtom* mMedium; // initialized by subclass ctors;
// weak pointer to static atom
nsCOMPtr<nsIAtom> mMediaEmulated;

View File

@ -63,6 +63,7 @@
#include "CacheObserver.h"
#include "DisplayItemClip.h"
#include "ActiveLayerTracker.h"
#include "CounterStyleManager.h"
#include "AudioChannelService.h"
#include "mozilla/dom/DataStoreService.h"
@ -293,6 +294,8 @@ nsLayoutStatics::Initialize()
CacheObserver::Init();
CounterStyleManager::InitializeBuiltinCounterStyles();
return NS_OK;
}

View File

@ -799,7 +799,7 @@ struct CJKIdeographicData {
uint8_t lang;
bool informal;
};
static const char16_t gJapaneseNegative[] = {
extern const char16_t gJapaneseNegative[] = {
0x30de, 0x30a4, 0x30ca, 0x30b9, 0x0000
};
static const CJKIdeographicData gDataJapaneseInformal = {
@ -824,7 +824,7 @@ static const CJKIdeographicData gDataJapaneseFormal = {
JAPANESE, // lang
false // informal
};
static const char16_t gKoreanNegative[] = {
extern const char16_t gKoreanNegative[] = {
0xb9c8, 0xc774, 0xb108, 0xc2a4, 0x0020, 0x0000
};
static const CJKIdeographicData gDataKoreanHangulFormal = {
@ -860,7 +860,7 @@ static const CJKIdeographicData gDataKoreanHanjaFormal = {
KOREAN, // lang
false // informal
};
static const char16_t gSimpChineseNegative[] = {
extern const char16_t gSimpChineseNegative[] = {
0x8d1f, 0x0000
};
static const CJKIdeographicData gDataSimpChineseInformal = {
@ -885,7 +885,7 @@ static const CJKIdeographicData gDataSimpChineseFormal = {
CHINESE, // lang
false // informal
};
static const char16_t gTradChineseNegative[] = {
extern const char16_t gTradChineseNegative[] = {
0x8ca0, 0x0000
};
static const CJKIdeographicData gDataTradChineseInformal = {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,139 @@
/* -*- 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/NullPtr.h"
#include "mozilla/Attributes.h"
class nsPresContext;
class nsCSSCounterStyleRule;
namespace mozilla {
typedef int32_t CounterValue;
class CounterStyleManager;
struct NegativeType;
struct PadType;
class CounterStyle
{
protected:
explicit MOZ_CONSTEXPR CounterStyle(int32_t aStyle)
: mStyle(aStyle)
{
}
private:
CounterStyle(const CounterStyle& aOther) MOZ_DELETE;
void operator=(const CounterStyle& other) MOZ_DELETE;
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;
virtual void GetPrefix(nsSubstring& aResult) = 0;
virtual void GetSuffix(nsSubstring& aResult) = 0;
void GetCounterText(CounterValue aOrdinal,
nsSubstring& aResult,
bool& aIsRTL);
virtual void GetSpokenCounterText(CounterValue aOrdinal,
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,
nsSubstring& aResult,
bool& aIsRTL) = 0;
virtual bool GetInitialCounterText(CounterValue aOrdinal,
nsSubstring& aResult,
bool& aIsRTL) = 0;
NS_IMETHOD_(MozExternalRefCountType) AddRef() = 0;
NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
protected:
int32_t mStyle;
};
class CounterStyleManager MOZ_FINAL
{
public:
CounterStyleManager(nsPresContext* aPresContext);
~CounterStyleManager();
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();
NS_INLINE_DECL_REFCOUNTING(CounterStyleManager)
private:
nsPresContext* mPresContext;
nsRefPtrHashtable<nsStringHashKey, CounterStyle> mCacheTable;
};
} // namespace mozilla
#endif /* !defined(mozilla_CounterStyleManager_h_) */

View File

@ -84,6 +84,7 @@ EXPORTS.mozilla.css += [
UNIFIED_SOURCES += [
'AnimationCommon.cpp',
'CounterStyleManager.cpp',
'CSS.cpp',
'CSSRuleList.cpp',
'CSSVariableDeclarations.cpp',

View File

@ -634,6 +634,7 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_OVERFLOW_CLIP_BOX_CONTENT_BOX 1
// See nsStyleList
#define NS_STYLE_LIST_STYLE_CUSTOM -1 // for @counter-style
#define NS_STYLE_LIST_STYLE_NONE 0
#define NS_STYLE_LIST_STYLE_DISC 1
#define NS_STYLE_LIST_STYLE_CIRCLE 2
@ -696,6 +697,7 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_AM 152
#define NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ER 153
#define NS_STYLE_LIST_STYLE_MOZ_ETHIOPIC_HALEHAME_TI_ET 154
#define NS_STYLE_LIST_STYLE__MAX 155
// See nsStyleList
#define NS_STYLE_LIST_STYLE_POSITION_INSIDE 0
@ -1072,6 +1074,7 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_COUNTER_SPEAKAS_NUMBERS 1
#define NS_STYLE_COUNTER_SPEAKAS_WORDS 2
#define NS_STYLE_COUNTER_SPEAKAS_SPELL_OUT 3
#define NS_STYLE_COUNTER_SPEAKAS_OTHER 255 // refer to another style
/*****************************************************************************
* Constants for media features. *