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
7 #include "mozilla/dom/CSSCounterStyleRule.h"
8
9 #include "mozAutoDocUpdate.h"
10 #include "mozilla/dom/CSSCounterStyleRuleBinding.h"
11 #include "mozilla/ServoBindings.h"
12 #include "nsStyleUtil.h"
13
14 namespace mozilla {
15 namespace dom {
16
IsCCLeaf() const17 bool CSSCounterStyleRule::IsCCLeaf() const { return Rule::IsCCLeaf(); }
18
19 #ifdef DEBUG
List(FILE * out,int32_t aIndent) const20 void CSSCounterStyleRule::List(FILE* out, int32_t aIndent) const {
21 nsAutoCString str;
22 for (int32_t i = 0; i < aIndent; i++) {
23 str.AppendLiteral(" ");
24 }
25 Servo_CounterStyleRule_Debug(mRawRule, &str);
26 fprintf_stderr(out, "%s\n", str.get());
27 }
28 #endif
29
Type() const30 StyleCssRuleType CSSCounterStyleRule::Type() const {
31 return StyleCssRuleType::CounterStyle;
32 }
33
SetRawAfterClone(RefPtr<RawServoCounterStyleRule> aRaw)34 void CSSCounterStyleRule::SetRawAfterClone(
35 RefPtr<RawServoCounterStyleRule> aRaw) {
36 mRawRule = std::move(aRaw);
37 }
38
GetCssText(nsACString & aCssText) const39 void CSSCounterStyleRule::GetCssText(nsACString& aCssText) const {
40 Servo_CounterStyleRule_GetCssText(mRawRule, &aCssText);
41 }
42
GetName(nsAString & aName)43 void CSSCounterStyleRule::GetName(nsAString& aName) {
44 aName.Truncate();
45 nsAtom* name = Servo_CounterStyleRule_GetName(mRawRule);
46 nsDependentAtomString nameStr(name);
47 nsStyleUtil::AppendEscapedCSSIdent(nameStr, aName);
48 }
49
50 template <typename Func>
ModifyRule(Func aCallback)51 void CSSCounterStyleRule::ModifyRule(Func aCallback) {
52 if (IsReadOnly()) {
53 return;
54 }
55
56 StyleSheet* sheet = GetStyleSheet();
57 if (sheet) {
58 sheet->WillDirty();
59 }
60
61 if (aCallback() && sheet) {
62 sheet->RuleChanged(this, StyleRuleChangeKind::Generic);
63 }
64 }
65
SetName(const nsAString & aName)66 void CSSCounterStyleRule::SetName(const nsAString& aName) {
67 ModifyRule([&] {
68 NS_ConvertUTF16toUTF8 name(aName);
69 return Servo_CounterStyleRule_SetName(mRawRule, &name);
70 });
71 }
72
73 #define CSS_COUNTER_DESC(name_, method_) \
74 void CSSCounterStyleRule::Get##method_(nsACString& aValue) { \
75 MOZ_ASSERT(aValue.IsEmpty()); \
76 Servo_CounterStyleRule_GetDescriptorCssText( \
77 mRawRule, eCSSCounterDesc_##method_, &aValue); \
78 } \
79 void CSSCounterStyleRule::Set##method_(const nsACString& aValue) { \
80 ModifyRule([&] { \
81 return Servo_CounterStyleRule_SetDescriptor( \
82 mRawRule, eCSSCounterDesc_##method_, &aValue); \
83 }); \
84 }
85 #include "nsCSSCounterDescList.h"
86 #undef CSS_COUNTER_DESC
87
88 /* virtual */
SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const89 size_t CSSCounterStyleRule::SizeOfIncludingThis(
90 MallocSizeOf aMallocSizeOf) const {
91 return aMallocSizeOf(this);
92 }
93
94 /* virtual */
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)95 JSObject* CSSCounterStyleRule::WrapObject(JSContext* aCx,
96 JS::Handle<JSObject*> aGivenProto) {
97 return CSSCounterStyleRule_Binding::Wrap(aCx, this, aGivenProto);
98 }
99
100 } // namespace dom
101 } // namespace mozilla
102