Bug 1328319 part 2 - Add basic integration of @counter-style. r=heycam

MozReview-Commit-ID: 68CcxyWuINu

--HG--
extra : rebase_source : 2772c4ab938daf61e4a14fa952b24ecd4220de6b
This commit is contained in:
Xidorn Quan 2017-05-15 14:18:44 +10:00
parent 6f168c437d
commit 2723728359
5 changed files with 53 additions and 9 deletions

View File

@ -122,6 +122,8 @@ GROUP_RULE_FUNCS(Document)
#undef BASIC_RULE_FUNCS #undef BASIC_RULE_FUNCS
SERVO_BINDING_FUNC(Servo_CssRules_GetFontFaceRuleAt, nsCSSFontFaceRule*, SERVO_BINDING_FUNC(Servo_CssRules_GetFontFaceRuleAt, nsCSSFontFaceRule*,
ServoCssRulesBorrowed rules, uint32_t index) ServoCssRulesBorrowed rules, uint32_t index)
SERVO_BINDING_FUNC(Servo_CssRules_GetCounterStyleRuleAt, nsCSSCounterStyleRule*,
ServoCssRulesBorrowed rules, uint32_t index)
SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong, SERVO_BINDING_FUNC(Servo_StyleRule_GetStyle, RawServoDeclarationBlockStrong,
RawServoStyleRuleBorrowed rule) RawServoStyleRuleBorrowed rule)
SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void, SERVO_BINDING_FUNC(Servo_StyleRule_SetStyle, void,

View File

@ -11,6 +11,7 @@
#include "gfxFontFamilyList.h" #include "gfxFontFamilyList.h"
#include "nsAnimationManager.h" #include "nsAnimationManager.h"
#include "nsAttrValueInlines.h" #include "nsAttrValueInlines.h"
#include "nsCSSCounterStyleRule.h"
#include "nsCSSFrameConstructor.h" #include "nsCSSFrameConstructor.h"
#include "nsCSSProps.h" #include "nsCSSProps.h"
#include "nsCSSParser.h" #include "nsCSSParser.h"
@ -2113,6 +2114,23 @@ Gecko_CSSFontFaceRule_GetCssText(const nsCSSFontFaceRule* aRule,
NS_IMPL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule); NS_IMPL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule);
nsCSSCounterStyleRule*
Gecko_CSSCounterStyle_Create(nsIAtom* aName)
{
RefPtr<nsCSSCounterStyleRule> rule = new nsCSSCounterStyleRule(aName, 0, 0);
return rule.forget().take();
}
void
Gecko_CSSCounterStyle_GetCssText(const nsCSSCounterStyleRule* aRule,
nsAString* aResult)
{
MOZ_ASSERT(NS_IsMainThread());
aRule->GetCssText(*aResult);
}
NS_IMPL_FFI_REFCOUNTING(nsCSSCounterStyleRule, CSSCounterStyleRule);
NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList); NS_IMPL_THREADSAFE_FFI_REFCOUNTING(nsCSSValueSharedList, CSSValueSharedList);
#define STYLE_STRUCT(name, checkdata_cb) \ #define STYLE_STRUCT(name, checkdata_cb) \

View File

@ -51,6 +51,7 @@ namespace mozilla {
using mozilla::FontFamilyList; using mozilla::FontFamilyList;
using mozilla::FontFamilyType; using mozilla::FontFamilyType;
using mozilla::ServoElementSnapshot; using mozilla::ServoElementSnapshot;
class nsCSSCounterStyleRule;
class nsCSSFontFaceRule; class nsCSSFontFaceRule;
struct nsMediaFeature; struct nsMediaFeature;
struct nsStyleList; struct nsStyleList;
@ -520,6 +521,12 @@ nsCSSFontFaceRule* Gecko_CSSFontFaceRule_Create(uint32_t line, uint32_t column);
void Gecko_CSSFontFaceRule_GetCssText(const nsCSSFontFaceRule* rule, nsAString* result); void Gecko_CSSFontFaceRule_GetCssText(const nsCSSFontFaceRule* rule, nsAString* result);
NS_DECL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule); NS_DECL_FFI_REFCOUNTING(nsCSSFontFaceRule, CSSFontFaceRule);
// Counter style rule
// Creates and returns a new (already-addrefed) nsCSSCounterStyleRule object.
nsCSSCounterStyleRule* Gecko_CSSCounterStyle_Create(nsIAtom* name);
void Gecko_CSSCounterStyle_GetCssText(const nsCSSCounterStyleRule* rule, nsAString* result);
NS_DECL_FFI_REFCOUNTING(nsCSSCounterStyleRule, CSSCounterStyleRule);
RawGeckoElementBorrowedOrNull Gecko_GetBody(RawGeckoPresContextBorrowed pres_context); RawGeckoElementBorrowedOrNull Gecko_GetBody(RawGeckoPresContextBorrowed pres_context);
// We use an int32_t here instead of a LookAndFeel::ColorID // We use an int32_t here instead of a LookAndFeel::ColorID

View File

@ -15,6 +15,7 @@
#include "mozilla/ServoPageRule.h" #include "mozilla/ServoPageRule.h"
#include "mozilla/ServoStyleRule.h" #include "mozilla/ServoStyleRule.h"
#include "mozilla/ServoSupportsRule.h" #include "mozilla/ServoSupportsRule.h"
#include "nsCSSCounterStyleRule.h"
#include "nsCSSFontFaceRule.h" #include "nsCSSFontFaceRule.h"
namespace mozilla { namespace mozilla {
@ -46,10 +47,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(ServoCSSRuleList,
if (!aRule->IsCCLeaf()) { if (!aRule->IsCCLeaf()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]");
cb.NoteXPCOMChild(aRule); cb.NoteXPCOMChild(aRule);
// Note about @font-face rule again, since there is an indirect // Note about @font-face and @counter-style rule again, since
// owning edge through Servo's struct that FontFaceRule in Servo // there is an indirect owning edge through Servo's struct that
// owns a Gecko nsCSSFontFaceRule object. // FontFaceRule / CounterStyleRule in Servo owns a Gecko
if (aRule->Type() == nsIDOMCSSRule::FONT_FACE_RULE) { // nsCSSFontFaceRule / nsCSSCounterStyleRule object.
auto type = aRule->Type();
if (type == nsIDOMCSSRule::FONT_FACE_RULE ||
type == nsIDOMCSSRule::COUNTER_STYLE_RULE) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRawRules[i]"); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRawRules[i]");
cb.NoteXPCOMChild(aRule); cb.NoteXPCOMChild(aRule);
} }
@ -99,13 +103,18 @@ ServoCSSRuleList::GetRule(uint32_t aIndex)
CASE_RULE(SUPPORTS, Supports) CASE_RULE(SUPPORTS, Supports)
CASE_RULE(DOCUMENT, Document) CASE_RULE(DOCUMENT, Document)
#undef CASE_RULE #undef CASE_RULE
// For @font-face and @counter-style rules, the function returns
// a borrowed Gecko rule object directly, so we don't need to
// create anything here. But we still need to have the style sheet
// and parent rule set properly.
case nsIDOMCSSRule::FONT_FACE_RULE: { case nsIDOMCSSRule::FONT_FACE_RULE: {
// Returns a borrowed nsCSSFontFaceRule object directly, so we
// don't need to create anything here, but we still need to have
// the style sheet and parent rule set properly.
ruleObj = Servo_CssRules_GetFontFaceRuleAt(mRawRules, aIndex); ruleObj = Servo_CssRules_GetFontFaceRuleAt(mRawRules, aIndex);
break; break;
} }
case nsIDOMCSSRule::COUNTER_STYLE_RULE: {
ruleObj = Servo_CssRules_GetCounterStyleRuleAt(mRawRules, aIndex);
break;
}
case nsIDOMCSSRule::KEYFRAMES_RULE: case nsIDOMCSSRule::KEYFRAMES_RULE:
// XXX create corresponding rules // XXX create corresponding rules
default: default:

View File

@ -2461,7 +2461,11 @@ nsCSSCounterStyleRule::SetName(const nsAString& aName)
mName = name; mName = name;
if (StyleSheet* sheet = GetStyleSheet()) { if (StyleSheet* sheet = GetStyleSheet()) {
sheet->AsGecko()->SetModifiedByChildRule(); if (sheet->IsGecko()) {
sheet->AsGecko()->SetModifiedByChildRule();
} else {
NS_ERROR("stylo: Dynamic change on @counter-style not yet supported");
}
if (doc) { if (doc) {
doc->StyleRuleChanged(sheet, this); doc->StyleRuleChanged(sheet, this);
} }
@ -2506,7 +2510,11 @@ nsCSSCounterStyleRule::SetDesc(nsCSSCounterDesc aDescID, const nsCSSValue& aValu
mGeneration++; mGeneration++;
if (StyleSheet* sheet = GetStyleSheet()) { if (StyleSheet* sheet = GetStyleSheet()) {
sheet->AsGecko()->SetModifiedByChildRule(); if (sheet->IsGecko()) {
sheet->AsGecko()->SetModifiedByChildRule();
} else {
NS_ERROR("stylo: Dynamic change on @counter-style not yet supported");
}
if (doc) { if (doc) {
doc->StyleRuleChanged(sheet, this); doc->StyleRuleChanged(sheet, this);
} }