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 uint16_t CSSCounterStyleRule::Type() const {
31   return CSSRule_Binding::COUNTER_STYLE_RULE;
32 }
33 
GetCssText(nsACString & aCssText) const34 void CSSCounterStyleRule::GetCssText(nsACString& aCssText) const {
35   Servo_CounterStyleRule_GetCssText(mRawRule, &aCssText);
36 }
37 
GetName(nsAString & aName)38 void CSSCounterStyleRule::GetName(nsAString& aName) {
39   aName.Truncate();
40   nsAtom* name = Servo_CounterStyleRule_GetName(mRawRule);
41   nsDependentAtomString nameStr(name);
42   nsStyleUtil::AppendEscapedCSSIdent(nameStr, aName);
43 }
44 
SetName(const nsAString & aName)45 void CSSCounterStyleRule::SetName(const nsAString& aName) {
46   if (IsReadOnly()) {
47     return;
48   }
49   NS_ConvertUTF16toUTF8 name(aName);
50   if (Servo_CounterStyleRule_SetName(mRawRule, &name)) {
51     if (StyleSheet* sheet = GetStyleSheet()) {
52       sheet->RuleChanged(this, StyleRuleChangeKind::Generic);
53     }
54   }
55 }
56 
57 #define CSS_COUNTER_DESC(name_, method_)                             \
58   void CSSCounterStyleRule::Get##method_(nsACString& aValue) {       \
59     MOZ_ASSERT(aValue.IsEmpty());                                    \
60     Servo_CounterStyleRule_GetDescriptorCssText(                     \
61         mRawRule, eCSSCounterDesc_##method_, &aValue);               \
62   }                                                                  \
63   void CSSCounterStyleRule::Set##method_(const nsACString& aValue) { \
64     if (IsReadOnly()) {                                              \
65       return;                                                        \
66     }                                                                \
67     if (Servo_CounterStyleRule_SetDescriptor(                        \
68             mRawRule, eCSSCounterDesc_##method_, &aValue)) {         \
69       if (StyleSheet* sheet = GetStyleSheet()) {                     \
70         sheet->RuleChanged(this, StyleRuleChangeKind::Generic);      \
71       }                                                              \
72     }                                                                \
73   }
74 #include "nsCSSCounterDescList.h"
75 #undef CSS_COUNTER_DESC
76 
77 /* virtual */
SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const78 size_t CSSCounterStyleRule::SizeOfIncludingThis(
79     MallocSizeOf aMallocSizeOf) const {
80   return aMallocSizeOf(this);
81 }
82 
83 /* virtual */
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)84 JSObject* CSSCounterStyleRule::WrapObject(JSContext* aCx,
85                                           JS::Handle<JSObject*> aGivenProto) {
86   return CSSCounterStyleRule_Binding::Wrap(aCx, this, aGivenProto);
87 }
88 
89 }  // namespace dom
90 }  // namespace mozilla
91