Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / layout / style / nsCSSRules.cpp
blob7ae1b47f1fff2a17263b68a5930290ad0ffca64e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
8 #include "mozilla/Attributes.h"
10 #include "nsCSSRules.h"
11 #include "nsCSSValue.h"
12 #include "mozilla/CSSStyleSheet.h"
13 #include "mozilla/MemoryReporting.h"
14 #include "mozilla/css/ImportRule.h"
15 #include "mozilla/css/NameSpaceRule.h"
17 #include "nsString.h"
18 #include "nsIAtom.h"
20 #include "nsCSSProps.h"
22 #include "nsCOMPtr.h"
23 #include "nsIDOMCSSStyleSheet.h"
24 #include "nsIMediaList.h"
25 #include "mozilla/dom/CSSRuleList.h"
26 #include "nsIDocument.h"
27 #include "nsPresContext.h"
29 #include "nsContentUtils.h"
30 #include "nsError.h"
31 #include "nsStyleUtil.h"
32 #include "mozilla/css/Declaration.h"
33 #include "nsCSSParser.h"
34 #include "nsDOMClassInfoID.h"
35 #include "mozilla/dom/CSSStyleDeclarationBinding.h"
36 #include "StyleRule.h"
37 #include "nsFont.h"
38 #include "nsIURI.h"
39 #include "mozAutoDocUpdate.h"
41 using namespace mozilla;
42 using namespace mozilla::dom;
44 #define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \
45 /* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \
46 { return this; } \
47 /* virtual */ nsIDOMCSSRule* class_::GetExistingDOMRule() \
48 { return this; }
49 #define IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(class_, super_) \
50 /* virtual */ void class_::MapRuleInfoInto(nsRuleData* aRuleData) \
51 { NS_ABORT_IF_FALSE(false, "should not be called"); }
53 #define IMPL_STYLE_RULE_INHERIT(class_, super_) \
54 IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \
55 IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(class_, super_)
57 // base class for all rule types in a CSS style sheet
59 namespace mozilla {
60 namespace css {
62 CSSStyleSheet*
63 Rule::GetStyleSheet() const
65 if (!(mSheet & 0x1)) {
66 return reinterpret_cast<CSSStyleSheet*>(mSheet);
69 return nullptr;
72 nsHTMLCSSStyleSheet*
73 Rule::GetHTMLCSSStyleSheet() const
75 if (mSheet & 0x1) {
76 return reinterpret_cast<nsHTMLCSSStyleSheet*>(mSheet & ~uintptr_t(0x1));
79 return nullptr;
82 /* virtual */ void
83 Rule::SetStyleSheet(CSSStyleSheet* aSheet)
85 // We don't reference count this up reference. The style sheet
86 // will tell us when it's going away or when we're detached from
87 // it.
88 mSheet = reinterpret_cast<uintptr_t>(aSheet);
91 void
92 Rule::SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet)
94 // We don't reference count this up reference. The style sheet
95 // will tell us when it's going away or when we're detached from
96 // it.
97 mSheet = reinterpret_cast<uintptr_t>(aSheet);
98 mSheet |= 0x1;
101 nsresult
102 Rule::GetParentRule(nsIDOMCSSRule** aParentRule)
104 if (mParentRule) {
105 NS_IF_ADDREF(*aParentRule = mParentRule->GetDOMRule());
106 } else {
107 *aParentRule = nullptr;
109 return NS_OK;
112 nsresult
113 Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
115 NS_ENSURE_ARG_POINTER(aSheet);
117 NS_IF_ADDREF(*aSheet = GetStyleSheet());
118 return NS_OK;
121 css::Rule*
122 Rule::GetCSSRule()
124 return this;
127 size_t
128 Rule::SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
129 MallocSizeOf aMallocSizeOf,
130 void* aData)
132 return aElement->SizeOfIncludingThis(aMallocSizeOf);
135 // -------------------------------
136 // Style Rule List for group rules
139 class GroupRuleRuleList MOZ_FINAL : public dom::CSSRuleList
141 public:
142 explicit GroupRuleRuleList(GroupRule *aGroupRule);
144 virtual CSSStyleSheet* GetParentObject() MOZ_OVERRIDE;
146 virtual nsIDOMCSSRule*
147 IndexedGetter(uint32_t aIndex, bool& aFound) MOZ_OVERRIDE;
148 virtual uint32_t
149 Length() MOZ_OVERRIDE;
151 void DropReference() { mGroupRule = nullptr; }
153 private:
154 ~GroupRuleRuleList();
156 private:
157 GroupRule* mGroupRule;
160 GroupRuleRuleList::GroupRuleRuleList(GroupRule *aGroupRule)
162 // Not reference counted to avoid circular references.
163 // The rule will tell us when its going away.
164 mGroupRule = aGroupRule;
167 GroupRuleRuleList::~GroupRuleRuleList()
171 CSSStyleSheet*
172 GroupRuleRuleList::GetParentObject()
174 if (!mGroupRule) {
175 return nullptr;
178 return mGroupRule->GetStyleSheet();
181 uint32_t
182 GroupRuleRuleList::Length()
184 if (!mGroupRule) {
185 return 0;
188 return AssertedCast<uint32_t>(mGroupRule->StyleRuleCount());
191 nsIDOMCSSRule*
192 GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound)
194 aFound = false;
196 if (mGroupRule) {
197 nsRefPtr<Rule> rule = mGroupRule->GetStyleRuleAt(aIndex);
198 if (rule) {
199 aFound = true;
200 return rule->GetDOMRule();
204 return nullptr;
207 // -------------------------------------------
208 // CharsetRule
211 CharsetRule::CharsetRule(const nsAString& aEncoding,
212 uint32_t aLineNumber, uint32_t aColumnNumber)
213 : Rule(aLineNumber, aColumnNumber),
214 mEncoding(aEncoding)
218 CharsetRule::CharsetRule(const CharsetRule& aCopy)
219 : Rule(aCopy),
220 mEncoding(aCopy.mEncoding)
224 NS_IMPL_ADDREF(CharsetRule)
225 NS_IMPL_RELEASE(CharsetRule)
227 // QueryInterface implementation for CharsetRule
228 NS_INTERFACE_MAP_BEGIN(CharsetRule)
229 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
230 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
231 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCharsetRule)
232 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
233 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCharsetRule)
234 NS_INTERFACE_MAP_END
236 IMPL_STYLE_RULE_INHERIT(CharsetRule, Rule)
238 #ifdef DEBUG
239 /* virtual */ void
240 CharsetRule::List(FILE* out, int32_t aIndent) const
242 nsAutoCString str;
243 // Indent
244 for (int32_t indent = aIndent; --indent >= 0; ) {
245 str.AppendLiteral(" ");
248 str.AppendLiteral("@charset \"");
249 AppendUTF16toUTF8(mEncoding, str);
250 str.AppendLiteral("\"\n");
251 fprintf_stderr(out, "%s", str.get());
253 #endif
255 /* virtual */ int32_t
256 CharsetRule::GetType() const
258 return Rule::CHARSET_RULE;
261 /* virtual */ already_AddRefed<Rule>
262 CharsetRule::Clone() const
264 nsRefPtr<Rule> clone = new CharsetRule(*this);
265 return clone.forget();
268 NS_IMETHODIMP
269 CharsetRule::GetEncoding(nsAString& aEncoding)
271 aEncoding = mEncoding;
272 return NS_OK;
275 NS_IMETHODIMP
276 CharsetRule::SetEncoding(const nsAString& aEncoding)
278 mEncoding = aEncoding;
279 return NS_OK;
282 NS_IMETHODIMP
283 CharsetRule::GetType(uint16_t* aType)
285 *aType = nsIDOMCSSRule::CHARSET_RULE;
286 return NS_OK;
289 NS_IMETHODIMP
290 CharsetRule::GetCssText(nsAString& aCssText)
292 aCssText.AssignLiteral("@charset \"");
293 aCssText.Append(mEncoding);
294 aCssText.AppendLiteral("\";");
295 return NS_OK;
298 NS_IMETHODIMP
299 CharsetRule::SetCssText(const nsAString& aCssText)
301 return NS_ERROR_NOT_IMPLEMENTED;
304 NS_IMETHODIMP
305 CharsetRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
307 return Rule::GetParentStyleSheet(aSheet);
310 NS_IMETHODIMP
311 CharsetRule::GetParentRule(nsIDOMCSSRule** aParentRule)
313 return Rule::GetParentRule(aParentRule);
316 css::Rule*
317 CharsetRule::GetCSSRule()
319 return Rule::GetCSSRule();
322 /* virtual */ size_t
323 CharsetRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
325 return aMallocSizeOf(this);
327 // Measurement of the following members may be added later if DMD finds it is
328 // worthwhile:
329 // - mEncoding
332 // -------------------------------------------
333 // ImportRule
336 ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec,
337 uint32_t aLineNumber, uint32_t aColumnNumber)
338 : Rule(aLineNumber, aColumnNumber)
339 , mURLSpec(aURLSpec)
340 , mMedia(aMedia)
342 // XXXbz This is really silly.... the mMedia here will be replaced
343 // with itself if we manage to load a sheet. Which should really
344 // never fail nowadays, in sane cases.
347 ImportRule::ImportRule(const ImportRule& aCopy)
348 : Rule(aCopy),
349 mURLSpec(aCopy.mURLSpec)
351 // Whether or not an @import rule has a null sheet is a permanent
352 // property of that @import rule, since it is null only if the target
353 // sheet failed security checks.
354 if (aCopy.mChildSheet) {
355 nsRefPtr<CSSStyleSheet> sheet =
356 aCopy.mChildSheet->Clone(nullptr, this, nullptr, nullptr);
357 SetSheet(sheet);
358 // SetSheet sets mMedia appropriately
362 ImportRule::~ImportRule()
364 if (mChildSheet) {
365 mChildSheet->SetOwnerRule(nullptr);
369 NS_IMPL_CYCLE_COLLECTING_ADDREF(ImportRule)
370 NS_IMPL_CYCLE_COLLECTING_RELEASE(ImportRule)
372 NS_IMPL_CYCLE_COLLECTION(ImportRule, mMedia, mChildSheet)
374 // QueryInterface implementation for ImportRule
375 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImportRule)
376 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
377 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
378 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
379 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
380 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule)
381 NS_INTERFACE_MAP_END
383 IMPL_STYLE_RULE_INHERIT(ImportRule, Rule)
385 #ifdef DEBUG
386 /* virtual */ void
387 ImportRule::List(FILE* out, int32_t aIndent) const
389 nsAutoCString str;
390 // Indent
391 for (int32_t indent = aIndent; --indent >= 0; ) {
392 str.AppendLiteral(" ");
395 str.AppendLiteral("@import \"");
396 AppendUTF16toUTF8(mURLSpec, str);
397 str.AppendLiteral("\" ");
399 nsAutoString mediaText;
400 mMedia->GetText(mediaText);
401 AppendUTF16toUTF8(mediaText, str);
402 str.AppendLiteral("\n");
403 fprintf_stderr(out, "%s", str.get());
405 #endif
407 /* virtual */ int32_t
408 ImportRule::GetType() const
410 return Rule::IMPORT_RULE;
413 /* virtual */ already_AddRefed<Rule>
414 ImportRule::Clone() const
416 nsRefPtr<Rule> clone = new ImportRule(*this);
417 return clone.forget();
420 void
421 ImportRule::SetSheet(CSSStyleSheet* aSheet)
423 NS_PRECONDITION(aSheet, "null arg");
425 // set the new sheet
426 mChildSheet = aSheet;
427 aSheet->SetOwnerRule(this);
429 // set our medialist to be the same as the sheet's medialist
430 mMedia = mChildSheet->Media();
433 NS_IMETHODIMP
434 ImportRule::GetType(uint16_t* aType)
436 NS_ENSURE_ARG_POINTER(aType);
437 *aType = nsIDOMCSSRule::IMPORT_RULE;
438 return NS_OK;
441 NS_IMETHODIMP
442 ImportRule::GetCssText(nsAString& aCssText)
444 aCssText.AssignLiteral("@import url(");
445 nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
446 aCssText.Append(')');
447 if (mMedia) {
448 nsAutoString mediaText;
449 mMedia->GetText(mediaText);
450 if (!mediaText.IsEmpty()) {
451 aCssText.Append(' ');
452 aCssText.Append(mediaText);
455 aCssText.Append(';');
456 return NS_OK;
459 NS_IMETHODIMP
460 ImportRule::SetCssText(const nsAString& aCssText)
462 return NS_ERROR_NOT_IMPLEMENTED;
465 NS_IMETHODIMP
466 ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
468 return Rule::GetParentStyleSheet(aSheet);
471 NS_IMETHODIMP
472 ImportRule::GetParentRule(nsIDOMCSSRule** aParentRule)
474 return Rule::GetParentRule(aParentRule);
477 css::Rule*
478 ImportRule::GetCSSRule()
480 return Rule::GetCSSRule();
483 NS_IMETHODIMP
484 ImportRule::GetHref(nsAString & aHref)
486 aHref = mURLSpec;
487 return NS_OK;
490 NS_IMETHODIMP
491 ImportRule::GetMedia(nsIDOMMediaList * *aMedia)
493 NS_ENSURE_ARG_POINTER(aMedia);
495 NS_IF_ADDREF(*aMedia = mMedia);
496 return NS_OK;
499 NS_IMETHODIMP
500 ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
502 NS_ENSURE_ARG_POINTER(aStyleSheet);
504 NS_IF_ADDREF(*aStyleSheet = mChildSheet);
505 return NS_OK;
508 /* virtual */ size_t
509 ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
511 return aMallocSizeOf(this);
513 // Measurement of the following members may be added later if DMD finds it is
514 // worthwhile:
515 // - mURLSpec
517 // The following members are not measured:
518 // - mMedia, because it is measured via CSSStyleSheet::mMedia
519 // - mChildSheet, because it is measured via CSSStyleSheetInner::mSheets
522 GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber)
523 : Rule(aLineNumber, aColumnNumber)
527 static bool
528 SetParentRuleReference(Rule* aRule, void* aParentRule)
530 GroupRule* parentRule = static_cast<GroupRule*>(aParentRule);
531 aRule->SetParentRule(parentRule);
532 return true;
535 GroupRule::GroupRule(const GroupRule& aCopy)
536 : Rule(aCopy)
538 const_cast<GroupRule&>(aCopy).mRules.EnumerateForwards(GroupRule::CloneRuleInto, &mRules);
539 mRules.EnumerateForwards(SetParentRuleReference, this);
542 GroupRule::~GroupRule()
544 NS_ABORT_IF_FALSE(!mSheet, "SetStyleSheet should have been called");
545 mRules.EnumerateForwards(SetParentRuleReference, nullptr);
546 if (mRuleCollection) {
547 mRuleCollection->DropReference();
551 NS_IMPL_CYCLE_COLLECTING_ADDREF(GroupRule)
552 NS_IMPL_CYCLE_COLLECTING_RELEASE(GroupRule)
554 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule)
555 NS_INTERFACE_MAP_END
557 IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(GroupRule, Rule)
559 static bool
560 SetStyleSheetReference(Rule* aRule, void* aSheet)
562 CSSStyleSheet* sheet = (CSSStyleSheet*)aSheet;
563 aRule->SetStyleSheet(sheet);
564 return true;
567 NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule)
569 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule)
570 tmp->mRules.EnumerateForwards(SetParentRuleReference, nullptr);
571 // If tmp does not have a stylesheet, neither do its descendants. In that
572 // case, don't try to null out their stylesheet, to avoid O(N^2) behavior in
573 // depth of group rule nesting. But if tmp _does_ have a stylesheet (which
574 // can happen if it gets unlinked earlier than its owning stylesheet), then we
575 // need to null out the stylesheet pointer on descendants now, before we clear
576 // tmp->mRules.
577 if (tmp->GetStyleSheet()) {
578 tmp->mRules.EnumerateForwards(SetStyleSheetReference, nullptr);
580 tmp->mRules.Clear();
581 if (tmp->mRuleCollection) {
582 tmp->mRuleCollection->DropReference();
583 tmp->mRuleCollection = nullptr;
585 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
587 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(GroupRule)
588 const nsCOMArray<Rule>& rules = tmp->mRules;
589 for (int32_t i = 0, count = rules.Count(); i < count; ++i) {
590 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]");
591 cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule());
593 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection)
594 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
596 /* virtual */ void
597 GroupRule::SetStyleSheet(CSSStyleSheet* aSheet)
599 // Don't set the sheet on the kids if it's already the same as the sheet we
600 // already have. This is needed to avoid O(N^2) behavior in group nesting
601 // depth when seting the sheet to null during unlink, if we happen to unlin in
602 // order from most nested rule up to least nested rule.
603 if (aSheet != GetStyleSheet()) {
604 mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
605 Rule::SetStyleSheet(aSheet);
609 #ifdef DEBUG
610 /* virtual */ void
611 GroupRule::List(FILE* out, int32_t aIndent) const
613 for (int32_t index = 0, count = mRules.Count(); index < count; ++index) {
614 mRules.ObjectAt(index)->List(out, aIndent + 1);
617 #endif
619 void
620 GroupRule::AppendStyleRule(Rule* aRule)
622 mRules.AppendObject(aRule);
623 CSSStyleSheet* sheet = GetStyleSheet();
624 aRule->SetStyleSheet(sheet);
625 aRule->SetParentRule(this);
626 if (sheet) {
627 sheet->SetModifiedByChildRule();
631 Rule*
632 GroupRule::GetStyleRuleAt(int32_t aIndex) const
634 return mRules.SafeObjectAt(aIndex);
637 bool
638 GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
640 return
641 const_cast<GroupRule*>(this)->mRules.EnumerateForwards(aFunc, aData);
645 * The next two methods (DeleteStyleRuleAt and InsertStyleRuleAt)
646 * should never be called unless you have first called WillDirty() on
647 * the parents stylesheet. After they are called, DidDirty() needs to
648 * be called on the sheet
650 nsresult
651 GroupRule::DeleteStyleRuleAt(uint32_t aIndex)
653 Rule* rule = mRules.SafeObjectAt(aIndex);
654 if (rule) {
655 rule->SetStyleSheet(nullptr);
656 rule->SetParentRule(nullptr);
658 return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
661 nsresult
662 GroupRule::InsertStyleRuleAt(uint32_t aIndex, Rule* aRule)
664 aRule->SetStyleSheet(GetStyleSheet());
665 aRule->SetParentRule(this);
666 if (! mRules.InsertObjectAt(aRule, aIndex)) {
667 return NS_ERROR_FAILURE;
669 return NS_OK;
672 nsresult
673 GroupRule::ReplaceStyleRule(Rule* aOld, Rule* aNew)
675 int32_t index = mRules.IndexOf(aOld);
676 NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
677 mRules.ReplaceObjectAt(aNew, index);
678 aNew->SetStyleSheet(GetStyleSheet());
679 aNew->SetParentRule(this);
680 aOld->SetStyleSheet(nullptr);
681 aOld->SetParentRule(nullptr);
682 return NS_OK;
685 void
686 GroupRule::AppendRulesToCssText(nsAString& aCssText)
688 aCssText.AppendLiteral(" {\n");
690 // get all the rules
691 for (int32_t index = 0, count = mRules.Count(); index < count; ++index) {
692 Rule* rule = mRules.ObjectAt(index);
693 nsIDOMCSSRule* domRule = rule->GetDOMRule();
694 if (domRule) {
695 nsAutoString cssText;
696 domRule->GetCssText(cssText);
697 aCssText.AppendLiteral(" ");
698 aCssText.Append(cssText);
699 aCssText.Append('\n');
703 aCssText.Append('}');
706 // nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods
707 nsresult
708 GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
710 if (!mRuleCollection) {
711 mRuleCollection = new css::GroupRuleRuleList(this);
714 NS_ADDREF(*aRuleList = mRuleCollection);
715 return NS_OK;
718 nsresult
719 GroupRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
721 CSSStyleSheet* sheet = GetStyleSheet();
722 NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
724 if (aIndex > uint32_t(mRules.Count()))
725 return NS_ERROR_DOM_INDEX_SIZE_ERR;
727 NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX,
728 "Too many style rules!");
730 return sheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval);
733 nsresult
734 GroupRule::DeleteRule(uint32_t aIndex)
736 CSSStyleSheet* sheet = GetStyleSheet();
737 NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
739 if (aIndex >= uint32_t(mRules.Count()))
740 return NS_ERROR_DOM_INDEX_SIZE_ERR;
742 NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX,
743 "Too many style rules!");
745 return sheet->DeleteRuleFromGroup(this, aIndex);
748 /* virtual */ size_t
749 GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
751 return mRules.SizeOfExcludingThis(Rule::SizeOfCOMArrayElementIncludingThis,
752 aMallocSizeOf);
754 // Measurement of the following members may be added later if DMD finds it is
755 // worthwhile:
756 // - mRuleCollection
760 // -------------------------------------------
761 // nsICSSMediaRule
763 MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber)
764 : GroupRule(aLineNumber, aColumnNumber)
768 MediaRule::MediaRule(const MediaRule& aCopy)
769 : GroupRule(aCopy)
771 if (aCopy.mMedia) {
772 mMedia = aCopy.mMedia->Clone();
773 // XXXldb This doesn't really make sense.
774 mMedia->SetStyleSheet(aCopy.GetStyleSheet());
778 MediaRule::~MediaRule()
780 if (mMedia) {
781 mMedia->SetStyleSheet(nullptr);
785 NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule)
786 NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule)
788 // QueryInterface implementation for MediaRule
789 NS_INTERFACE_MAP_BEGIN(MediaRule)
790 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
791 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
792 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
793 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
794 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
795 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
796 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
797 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
799 /* virtual */ void
800 MediaRule::SetStyleSheet(CSSStyleSheet* aSheet)
802 if (mMedia) {
803 // Set to null so it knows it's leaving one sheet and joining another.
804 mMedia->SetStyleSheet(nullptr);
805 mMedia->SetStyleSheet(aSheet);
808 GroupRule::SetStyleSheet(aSheet);
811 #ifdef DEBUG
812 /* virtual */ void
813 MediaRule::List(FILE* out, int32_t aIndent) const
815 nsAutoCString indentStr;
816 for (int32_t indent = aIndent; --indent >= 0; ) {
817 indentStr.AppendLiteral(" ");
820 nsAutoCString str(indentStr);
821 str.AppendLiteral("@media ");
823 if (mMedia) {
824 nsAutoString mediaText;
825 mMedia->GetText(mediaText);
826 AppendUTF16toUTF8(mediaText, str);
829 str.AppendLiteral(" {\n");
830 fprintf_stderr(out, "%s", str.get());
832 GroupRule::List(out, aIndent);
834 fprintf_stderr(out, "%s}\n", indentStr.get());
836 #endif
838 /* virtual */ int32_t
839 MediaRule::GetType() const
841 return Rule::MEDIA_RULE;
844 /* virtual */ already_AddRefed<Rule>
845 MediaRule::Clone() const
847 nsRefPtr<Rule> clone = new MediaRule(*this);
848 return clone.forget();
851 nsresult
852 MediaRule::SetMedia(nsMediaList* aMedia)
854 mMedia = aMedia;
855 if (aMedia)
856 mMedia->SetStyleSheet(GetStyleSheet());
857 return NS_OK;
860 // nsIDOMCSSRule methods
861 NS_IMETHODIMP
862 MediaRule::GetType(uint16_t* aType)
864 *aType = nsIDOMCSSRule::MEDIA_RULE;
865 return NS_OK;
868 NS_IMETHODIMP
869 MediaRule::GetCssText(nsAString& aCssText)
871 aCssText.AssignLiteral("@media ");
872 AppendConditionText(aCssText);
873 GroupRule::AppendRulesToCssText(aCssText);
874 return NS_OK;
877 NS_IMETHODIMP
878 MediaRule::SetCssText(const nsAString& aCssText)
880 return NS_ERROR_NOT_IMPLEMENTED;
883 NS_IMETHODIMP
884 MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
886 return GroupRule::GetParentStyleSheet(aSheet);
889 NS_IMETHODIMP
890 MediaRule::GetParentRule(nsIDOMCSSRule** aParentRule)
892 return GroupRule::GetParentRule(aParentRule);
895 css::Rule*
896 MediaRule::GetCSSRule()
898 return Rule::GetCSSRule();
901 // nsIDOMCSSGroupingRule methods
902 NS_IMETHODIMP
903 MediaRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
905 return GroupRule::GetCssRules(aRuleList);
908 NS_IMETHODIMP
909 MediaRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
911 return GroupRule::InsertRule(aRule, aIndex, _retval);
914 NS_IMETHODIMP
915 MediaRule::DeleteRule(uint32_t aIndex)
917 return GroupRule::DeleteRule(aIndex);
920 // nsIDOMCSSConditionRule methods
921 NS_IMETHODIMP
922 MediaRule::GetConditionText(nsAString& aConditionText)
924 aConditionText.Truncate(0);
925 AppendConditionText(aConditionText);
926 return NS_OK;
929 NS_IMETHODIMP
930 MediaRule::SetConditionText(const nsAString& aConditionText)
932 if (!mMedia) {
933 nsRefPtr<nsMediaList> media = new nsMediaList();
934 media->SetStyleSheet(GetStyleSheet());
935 nsresult rv = media->SetMediaText(aConditionText);
936 if (NS_SUCCEEDED(rv)) {
937 mMedia = media;
939 return rv;
942 return mMedia->SetMediaText(aConditionText);
945 // nsIDOMCSSMediaRule methods
946 NS_IMETHODIMP
947 MediaRule::GetMedia(nsIDOMMediaList* *aMedia)
949 NS_ENSURE_ARG_POINTER(aMedia);
950 NS_IF_ADDREF(*aMedia = mMedia);
951 return NS_OK;
954 // GroupRule interface
955 /* virtual */ bool
956 MediaRule::UseForPresentation(nsPresContext* aPresContext,
957 nsMediaQueryResultCacheKey& aKey)
959 if (mMedia) {
960 return mMedia->Matches(aPresContext, &aKey);
962 return true;
965 /* virtual */ size_t
966 MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
968 size_t n = aMallocSizeOf(this);
969 n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
971 // Measurement of the following members may be added later if DMD finds it is
972 // worthwhile:
973 // - mMedia
975 return n;
978 void
979 MediaRule::AppendConditionText(nsAString& aOutput)
981 if (mMedia) {
982 nsAutoString mediaText;
983 mMedia->GetText(mediaText);
984 aOutput.Append(mediaText);
988 DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber)
989 : GroupRule(aLineNumber, aColumnNumber)
993 DocumentRule::DocumentRule(const DocumentRule& aCopy)
994 : GroupRule(aCopy)
995 , mURLs(new URL(*aCopy.mURLs))
999 DocumentRule::~DocumentRule()
1003 NS_IMPL_ADDREF_INHERITED(DocumentRule, GroupRule)
1004 NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule)
1006 // QueryInterface implementation for DocumentRule
1007 NS_INTERFACE_MAP_BEGIN(DocumentRule)
1008 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
1009 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
1010 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
1011 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
1012 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
1013 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
1014 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
1015 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
1017 #ifdef DEBUG
1018 /* virtual */ void
1019 DocumentRule::List(FILE* out, int32_t aIndent) const
1021 nsAutoCString indentStr;
1022 for (int32_t indent = aIndent; --indent >= 0; ) {
1023 indentStr.AppendLiteral(" ");
1026 nsAutoCString str;
1027 str.AppendLiteral("@-moz-document ");
1028 for (URL *url = mURLs; url; url = url->next) {
1029 switch (url->func) {
1030 case eURL:
1031 str.AppendLiteral("url(\"");
1032 break;
1033 case eURLPrefix:
1034 str.AppendLiteral("url-prefix(\"");
1035 break;
1036 case eDomain:
1037 str.AppendLiteral("domain(\"");
1038 break;
1039 case eRegExp:
1040 str.AppendLiteral("regexp(\"");
1041 break;
1043 nsAutoCString escapedURL(url->url);
1044 escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
1045 str.Append(escapedURL);
1046 str.AppendLiteral("\"), ");
1048 str.Cut(str.Length() - 2, 1); // remove last ,
1049 fprintf_stderr(out, "%s%s {\n", indentStr.get(), str.get());
1051 GroupRule::List(out, aIndent);
1053 fprintf_stderr(out, "%s}\n", indentStr.get());
1055 #endif
1057 /* virtual */ int32_t
1058 DocumentRule::GetType() const
1060 return Rule::DOCUMENT_RULE;
1063 /* virtual */ already_AddRefed<Rule>
1064 DocumentRule::Clone() const
1066 nsRefPtr<Rule> clone = new DocumentRule(*this);
1067 return clone.forget();
1070 // nsIDOMCSSRule methods
1071 NS_IMETHODIMP
1072 DocumentRule::GetType(uint16_t* aType)
1074 // XXX What should really happen here?
1075 *aType = nsIDOMCSSRule::UNKNOWN_RULE;
1076 return NS_OK;
1079 NS_IMETHODIMP
1080 DocumentRule::GetCssText(nsAString& aCssText)
1082 aCssText.AssignLiteral("@-moz-document ");
1083 AppendConditionText(aCssText);
1084 GroupRule::AppendRulesToCssText(aCssText);
1085 return NS_OK;
1088 NS_IMETHODIMP
1089 DocumentRule::SetCssText(const nsAString& aCssText)
1091 return NS_ERROR_NOT_IMPLEMENTED;
1094 NS_IMETHODIMP
1095 DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
1097 return GroupRule::GetParentStyleSheet(aSheet);
1100 NS_IMETHODIMP
1101 DocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule)
1103 return GroupRule::GetParentRule(aParentRule);
1106 css::Rule*
1107 DocumentRule::GetCSSRule()
1109 return Rule::GetCSSRule();
1112 // nsIDOMCSSGroupingRule methods
1113 NS_IMETHODIMP
1114 DocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
1116 return GroupRule::GetCssRules(aRuleList);
1119 NS_IMETHODIMP
1120 DocumentRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
1122 return GroupRule::InsertRule(aRule, aIndex, _retval);
1125 NS_IMETHODIMP
1126 DocumentRule::DeleteRule(uint32_t aIndex)
1128 return GroupRule::DeleteRule(aIndex);
1131 // nsIDOMCSSConditionRule methods
1132 NS_IMETHODIMP
1133 DocumentRule::GetConditionText(nsAString& aConditionText)
1135 aConditionText.Truncate(0);
1136 AppendConditionText(aConditionText);
1137 return NS_OK;
1140 NS_IMETHODIMP
1141 DocumentRule::SetConditionText(const nsAString& aConditionText)
1143 return NS_ERROR_NOT_IMPLEMENTED;
1146 // GroupRule interface
1147 /* virtual */ bool
1148 DocumentRule::UseForPresentation(nsPresContext* aPresContext,
1149 nsMediaQueryResultCacheKey& aKey)
1151 nsIDocument *doc = aPresContext->Document();
1152 nsIURI *docURI = doc->GetDocumentURI();
1153 nsAutoCString docURISpec;
1154 if (docURI)
1155 docURI->GetSpec(docURISpec);
1157 for (URL *url = mURLs; url; url = url->next) {
1158 switch (url->func) {
1159 case eURL: {
1160 if (docURISpec == url->url)
1161 return true;
1162 } break;
1163 case eURLPrefix: {
1164 if (StringBeginsWith(docURISpec, url->url))
1165 return true;
1166 } break;
1167 case eDomain: {
1168 nsAutoCString host;
1169 if (docURI)
1170 docURI->GetHost(host);
1171 int32_t lenDiff = host.Length() - url->url.Length();
1172 if (lenDiff == 0) {
1173 if (host == url->url)
1174 return true;
1175 } else {
1176 if (StringEndsWith(host, url->url) &&
1177 host.CharAt(lenDiff - 1) == '.')
1178 return true;
1180 } break;
1181 case eRegExp: {
1182 NS_ConvertUTF8toUTF16 spec(docURISpec);
1183 NS_ConvertUTF8toUTF16 regex(url->url);
1184 if (nsContentUtils::IsPatternMatching(spec, regex, doc)) {
1185 return true;
1187 } break;
1191 return false;
1194 DocumentRule::URL::~URL()
1196 NS_CSS_DELETE_LIST_MEMBER(DocumentRule::URL, this, next);
1199 /* virtual */ size_t
1200 DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
1202 size_t n = aMallocSizeOf(this);
1203 n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
1205 // Measurement of the following members may be added later if DMD finds it is
1206 // worthwhile:
1207 // - mURLs
1209 return n;
1212 void
1213 DocumentRule::AppendConditionText(nsAString& aCssText)
1215 for (URL *url = mURLs; url; url = url->next) {
1216 switch (url->func) {
1217 case eURL:
1218 aCssText.AppendLiteral("url(");
1219 break;
1220 case eURLPrefix:
1221 aCssText.AppendLiteral("url-prefix(");
1222 break;
1223 case eDomain:
1224 aCssText.AppendLiteral("domain(");
1225 break;
1226 case eRegExp:
1227 aCssText.AppendLiteral("regexp(");
1228 break;
1230 nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(url->url),
1231 aCssText);
1232 aCssText.AppendLiteral("), ");
1234 aCssText.Truncate(aCssText.Length() - 2); // remove last ", "
1237 // -------------------------------------------
1238 // NameSpaceRule
1241 NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec,
1242 uint32_t aLineNumber, uint32_t aColumnNumber)
1243 : Rule(aLineNumber, aColumnNumber),
1244 mPrefix(aPrefix),
1245 mURLSpec(aURLSpec)
1249 NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy)
1250 : Rule(aCopy),
1251 mPrefix(aCopy.mPrefix),
1252 mURLSpec(aCopy.mURLSpec)
1256 NameSpaceRule::~NameSpaceRule()
1260 NS_IMPL_ADDREF(NameSpaceRule)
1261 NS_IMPL_RELEASE(NameSpaceRule)
1263 // QueryInterface implementation for NameSpaceRule
1264 NS_INTERFACE_MAP_BEGIN(NameSpaceRule)
1265 if (aIID.Equals(NS_GET_IID(css::NameSpaceRule))) {
1266 *aInstancePtr = this;
1267 NS_ADDREF_THIS();
1268 return NS_OK;
1270 else
1271 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
1272 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
1273 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
1274 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule)
1275 NS_INTERFACE_MAP_END
1277 IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule)
1279 #ifdef DEBUG
1280 /* virtual */ void
1281 NameSpaceRule::List(FILE* out, int32_t aIndent) const
1283 nsAutoCString str;
1284 for (int32_t indent = aIndent; --indent >= 0; ) {
1285 str.AppendLiteral(" ");
1288 nsAutoString buffer;
1290 str.AppendLiteral("@namespace ");
1292 if (mPrefix) {
1293 mPrefix->ToString(buffer);
1294 AppendUTF16toUTF8(buffer, str);
1295 str.Append(' ');
1298 str.AppendLiteral("url(\"");
1299 AppendUTF16toUTF8(mURLSpec, str);
1300 str.AppendLiteral("\")\n");
1301 fprintf_stderr(out, "%s", str.get());
1303 #endif
1305 /* virtual */ int32_t
1306 NameSpaceRule::GetType() const
1308 return Rule::NAMESPACE_RULE;
1311 /* virtual */ already_AddRefed<Rule>
1312 NameSpaceRule::Clone() const
1314 nsRefPtr<Rule> clone = new NameSpaceRule(*this);
1315 return clone.forget();
1318 NS_IMETHODIMP
1319 NameSpaceRule::GetType(uint16_t* aType)
1321 *aType = nsIDOMCSSRule::NAMESPACE_RULE;
1322 return NS_OK;
1325 NS_IMETHODIMP
1326 NameSpaceRule::GetCssText(nsAString& aCssText)
1328 aCssText.AssignLiteral("@namespace ");
1329 if (mPrefix) {
1330 aCssText.Append(nsDependentAtomString(mPrefix) + NS_LITERAL_STRING(" "));
1332 aCssText.AppendLiteral("url(");
1333 nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
1334 aCssText.AppendLiteral(");");
1335 return NS_OK;
1338 NS_IMETHODIMP
1339 NameSpaceRule::SetCssText(const nsAString& aCssText)
1341 return NS_ERROR_NOT_IMPLEMENTED;
1344 NS_IMETHODIMP
1345 NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
1347 return Rule::GetParentStyleSheet(aSheet);
1350 NS_IMETHODIMP
1351 NameSpaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
1353 return Rule::GetParentRule(aParentRule);
1356 css::Rule*
1357 NameSpaceRule::GetCSSRule()
1359 return Rule::GetCSSRule();
1362 /* virtual */ size_t
1363 NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
1365 return aMallocSizeOf(this);
1367 // Measurement of the following members may be added later if DMD finds it is
1368 // worthwhile:
1369 // - mPrefix
1370 // - mURLSpec
1374 } // namespace css
1375 } // namespace mozilla
1377 // -------------------------------------------
1378 // nsCSSFontFaceStyleDecl and related routines
1381 // Mapping from nsCSSFontDesc codes to CSSFontFaceDescriptors fields.
1382 nsCSSValue CSSFontFaceDescriptors::* const
1383 CSSFontFaceDescriptors::Fields[] = {
1384 #define CSS_FONT_DESC(name_, method_) &CSSFontFaceDescriptors::m##method_,
1385 #include "nsCSSFontDescList.h"
1386 #undef CSS_FONT_DESC
1389 const nsCSSValue&
1390 CSSFontFaceDescriptors::Get(nsCSSFontDesc aFontDescID) const
1392 MOZ_ASSERT(aFontDescID > eCSSFontDesc_UNKNOWN &&
1393 aFontDescID < eCSSFontDesc_COUNT);
1394 return this->*CSSFontFaceDescriptors::Fields[aFontDescID];
1397 nsCSSValue&
1398 CSSFontFaceDescriptors::Get(nsCSSFontDesc aFontDescID)
1400 MOZ_ASSERT(aFontDescID > eCSSFontDesc_UNKNOWN &&
1401 aFontDescID < eCSSFontDesc_COUNT);
1402 return this->*CSSFontFaceDescriptors::Fields[aFontDescID];
1405 // QueryInterface implementation for nsCSSFontFaceStyleDecl
1406 NS_INTERFACE_MAP_BEGIN(nsCSSFontFaceStyleDecl)
1407 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
1408 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration)
1409 NS_INTERFACE_MAP_ENTRY(nsICSSDeclaration)
1410 NS_INTERFACE_MAP_ENTRY(nsISupports)
1411 // We forward the cycle collection interfaces to ContainingRule(), which is
1412 // never null (in fact, we're part of that object!)
1413 if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
1414 aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
1415 return ContainingRule()->QueryInterface(aIID, aInstancePtr);
1417 else
1418 NS_INTERFACE_MAP_END
1420 NS_IMPL_ADDREF_USING_AGGREGATOR(nsCSSFontFaceStyleDecl, ContainingRule())
1421 NS_IMPL_RELEASE_USING_AGGREGATOR(nsCSSFontFaceStyleDecl, ContainingRule())
1423 // helper for string GetPropertyValue and RemovePropertyValue
1424 nsresult
1425 nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID,
1426 nsAString & aResult) const
1428 NS_ENSURE_ARG_RANGE(aFontDescID, eCSSFontDesc_UNKNOWN,
1429 eCSSFontDesc_COUNT - 1);
1431 aResult.Truncate();
1432 if (aFontDescID == eCSSFontDesc_UNKNOWN)
1433 return NS_OK;
1435 const nsCSSValue& val = mDescriptors.Get(aFontDescID);
1437 if (val.GetUnit() == eCSSUnit_Null) {
1438 // Avoid having to check no-value in the Family and Src cases below.
1439 return NS_OK;
1442 switch (aFontDescID) {
1443 case eCSSFontDesc_Family: {
1444 // we don't use nsCSSValue::AppendToString here because it doesn't
1445 // canonicalize the way we want, and anyway it's overkill when
1446 // we know we have eCSSUnit_String
1447 NS_ASSERTION(val.GetUnit() == eCSSUnit_String, "unexpected unit");
1448 nsDependentString family(val.GetStringBufferValue());
1449 nsStyleUtil::AppendEscapedCSSString(family, aResult);
1450 return NS_OK;
1453 case eCSSFontDesc_Style:
1454 val.AppendToString(eCSSProperty_font_style, aResult,
1455 nsCSSValue::eNormalized);
1456 return NS_OK;
1458 case eCSSFontDesc_Weight:
1459 val.AppendToString(eCSSProperty_font_weight, aResult,
1460 nsCSSValue::eNormalized);
1461 return NS_OK;
1463 case eCSSFontDesc_Stretch:
1464 val.AppendToString(eCSSProperty_font_stretch, aResult,
1465 nsCSSValue::eNormalized);
1466 return NS_OK;
1468 case eCSSFontDesc_FontFeatureSettings:
1469 nsStyleUtil::AppendFontFeatureSettings(val, aResult);
1470 return NS_OK;
1472 case eCSSFontDesc_FontLanguageOverride:
1473 val.AppendToString(eCSSProperty_font_language_override, aResult,
1474 nsCSSValue::eNormalized);
1475 return NS_OK;
1477 case eCSSFontDesc_Src:
1478 nsStyleUtil::AppendSerializedFontSrc(val, aResult);
1479 return NS_OK;
1481 case eCSSFontDesc_UnicodeRange:
1482 nsStyleUtil::AppendUnicodeRange(val, aResult);
1483 return NS_OK;
1485 case eCSSFontDesc_UNKNOWN:
1486 case eCSSFontDesc_COUNT:
1489 NS_NOTREACHED("nsCSSFontFaceStyleDecl::GetPropertyValue: "
1490 "out-of-range value got to the switch");
1491 return NS_ERROR_INVALID_ARG;
1495 // attribute DOMString cssText;
1496 NS_IMETHODIMP
1497 nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText)
1499 nsAutoString descStr;
1501 aCssText.Truncate();
1502 for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
1503 id < eCSSFontDesc_COUNT;
1504 id = nsCSSFontDesc(id + 1)) {
1505 if (mDescriptors.Get(id).GetUnit() != eCSSUnit_Null &&
1506 NS_SUCCEEDED(GetPropertyValue(id, descStr))) {
1507 NS_ASSERTION(descStr.Length() > 0,
1508 "GetCssText: non-null unit, empty property value");
1509 aCssText.AppendLiteral(" ");
1510 aCssText.AppendASCII(nsCSSProps::GetStringValue(id).get());
1511 aCssText.AppendLiteral(": ");
1512 aCssText.Append(descStr);
1513 aCssText.AppendLiteral(";\n");
1516 return NS_OK;
1519 NS_IMETHODIMP
1520 nsCSSFontFaceStyleDecl::SetCssText(const nsAString & aCssText)
1522 return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
1525 // DOMString getPropertyValue (in DOMString propertyName);
1526 NS_IMETHODIMP
1527 nsCSSFontFaceStyleDecl::GetPropertyValue(const nsAString & propertyName,
1528 nsAString & aResult)
1530 return GetPropertyValue(nsCSSProps::LookupFontDesc(propertyName), aResult);
1533 NS_IMETHODIMP
1534 nsCSSFontFaceStyleDecl::GetAuthoredPropertyValue(const nsAString& propertyName,
1535 nsAString& aResult)
1537 // We don't return any authored property values different from
1538 // GetPropertyValue, currently.
1539 return GetPropertyValue(nsCSSProps::LookupFontDesc(propertyName), aResult);
1542 // nsIDOMCSSValue getPropertyCSSValue (in DOMString propertyName);
1543 already_AddRefed<dom::CSSValue>
1544 nsCSSFontFaceStyleDecl::GetPropertyCSSValue(const nsAString & propertyName,
1545 ErrorResult& aRv)
1547 // ??? nsDOMCSSDeclaration returns null/NS_OK, but that seems wrong.
1548 aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
1549 return nullptr;
1552 // DOMString removeProperty (in DOMString propertyName) raises (DOMException);
1553 NS_IMETHODIMP
1554 nsCSSFontFaceStyleDecl::RemoveProperty(const nsAString & propertyName,
1555 nsAString & aResult)
1557 nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(propertyName);
1558 NS_ASSERTION(descID >= eCSSFontDesc_UNKNOWN &&
1559 descID < eCSSFontDesc_COUNT,
1560 "LookupFontDesc returned value out of range");
1562 if (descID == eCSSFontDesc_UNKNOWN) {
1563 aResult.Truncate();
1564 } else {
1565 nsresult rv = GetPropertyValue(descID, aResult);
1566 NS_ENSURE_SUCCESS(rv, rv);
1567 mDescriptors.Get(descID).Reset();
1569 return NS_OK;
1572 // DOMString getPropertyPriority (in DOMString propertyName);
1573 NS_IMETHODIMP
1574 nsCSSFontFaceStyleDecl::GetPropertyPriority(const nsAString & propertyName,
1575 nsAString & aResult)
1577 // font descriptors do not have priorities at present
1578 aResult.Truncate();
1579 return NS_OK;
1582 // void setProperty (in DOMString propertyName, in DOMString value,
1583 // in DOMString priority) raises (DOMException);
1584 NS_IMETHODIMP
1585 nsCSSFontFaceStyleDecl::SetProperty(const nsAString & propertyName,
1586 const nsAString & value,
1587 const nsAString & priority)
1589 return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
1592 // readonly attribute unsigned long length;
1593 NS_IMETHODIMP
1594 nsCSSFontFaceStyleDecl::GetLength(uint32_t *aLength)
1596 uint32_t len = 0;
1597 for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
1598 id < eCSSFontDesc_COUNT;
1599 id = nsCSSFontDesc(id + 1))
1600 if (mDescriptors.Get(id).GetUnit() != eCSSUnit_Null)
1601 len++;
1603 *aLength = len;
1604 return NS_OK;
1607 // DOMString item (in unsigned long index);
1608 NS_IMETHODIMP
1609 nsCSSFontFaceStyleDecl::Item(uint32_t aIndex, nsAString& aReturn)
1611 bool found;
1612 IndexedGetter(aIndex, found, aReturn);
1613 if (!found) {
1614 aReturn.Truncate();
1616 return NS_OK;
1619 void
1620 nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index, bool& aFound, nsAString & aResult)
1622 int32_t nset = -1;
1623 for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
1624 id < eCSSFontDesc_COUNT;
1625 id = nsCSSFontDesc(id + 1)) {
1626 if (mDescriptors.Get(id).GetUnit() != eCSSUnit_Null) {
1627 nset++;
1628 if (nset == int32_t(index)) {
1629 aFound = true;
1630 aResult.AssignASCII(nsCSSProps::GetStringValue(id).get());
1631 return;
1635 aFound = false;
1638 // readonly attribute nsIDOMCSSRule parentRule;
1639 NS_IMETHODIMP
1640 nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule)
1642 NS_IF_ADDREF(*aParentRule = ContainingRule()->GetDOMRule());
1643 return NS_OK;
1646 NS_IMETHODIMP
1647 nsCSSFontFaceStyleDecl::GetPropertyValue(const nsCSSProperty aPropID,
1648 nsAString& aValue)
1650 return
1651 GetPropertyValue(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID)),
1652 aValue);
1655 NS_IMETHODIMP
1656 nsCSSFontFaceStyleDecl::SetPropertyValue(const nsCSSProperty aPropID,
1657 const nsAString& aValue)
1659 return SetProperty(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID)),
1660 aValue, EmptyString());
1663 nsINode*
1664 nsCSSFontFaceStyleDecl::GetParentObject()
1666 return ContainingRule()->GetDocument();
1669 JSObject*
1670 nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx)
1672 return mozilla::dom::CSSStyleDeclarationBinding::Wrap(cx, this);
1675 // -------------------------------------------
1676 // nsCSSFontFaceRule
1679 /* virtual */ already_AddRefed<css::Rule>
1680 nsCSSFontFaceRule::Clone() const
1682 nsRefPtr<css::Rule> clone = new nsCSSFontFaceRule(*this);
1683 return clone.forget();
1686 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSFontFaceRule)
1687 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSFontFaceRule)
1689 NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSFontFaceRule)
1691 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsCSSFontFaceRule)
1692 // Trace the wrapper for our declaration. This just expands out
1693 // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
1694 // directly because the wrapper is on the declaration, not on us.
1695 tmp->mDecl.TraceWrapper(aCallbacks, aClosure);
1696 NS_IMPL_CYCLE_COLLECTION_TRACE_END
1698 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSFontFaceRule)
1699 // Unlink the wrapper for our declaraton. This just expands out
1700 // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
1701 // directly because the wrapper is on the declaration, not on us.
1702 tmp->mDecl.ReleaseWrapper(static_cast<nsISupports*>(p));
1703 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
1705 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSFontFaceRule)
1706 // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS will call into our
1707 // Trace hook, where we do the right thing with declarations already.
1708 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
1709 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
1711 // QueryInterface implementation for nsCSSFontFaceRule
1712 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSFontFaceRule)
1713 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
1714 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule)
1715 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
1716 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
1717 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule)
1718 NS_INTERFACE_MAP_END
1720 IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule)
1722 #ifdef DEBUG
1723 void
1724 nsCSSFontFaceRule::List(FILE* out, int32_t aIndent) const
1726 nsCString baseInd, descInd;
1727 for (int32_t indent = aIndent; --indent >= 0; ) {
1728 baseInd.AppendLiteral(" ");
1729 descInd.AppendLiteral(" ");
1731 descInd.AppendLiteral(" ");
1733 nsString descStr;
1735 fprintf_stderr(out, "%s@font-face {\n", baseInd.get());
1736 for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
1737 id < eCSSFontDesc_COUNT;
1738 id = nsCSSFontDesc(id + 1))
1739 if (mDecl.mDescriptors.Get(id).GetUnit() != eCSSUnit_Null) {
1740 if (NS_FAILED(mDecl.GetPropertyValue(id, descStr)))
1741 descStr.AssignLiteral("#<serialization error>");
1742 else if (descStr.Length() == 0)
1743 descStr.AssignLiteral("#<serialization missing>");
1744 fprintf_stderr(out, "%s%s: %s\n",
1745 descInd.get(), nsCSSProps::GetStringValue(id).get(),
1746 NS_ConvertUTF16toUTF8(descStr).get());
1748 fprintf_stderr(out, "%s}\n", baseInd.get());
1750 #endif
1752 /* virtual */ int32_t
1753 nsCSSFontFaceRule::GetType() const
1755 return Rule::FONT_FACE_RULE;
1758 NS_IMETHODIMP
1759 nsCSSFontFaceRule::GetType(uint16_t* aType)
1761 *aType = nsIDOMCSSRule::FONT_FACE_RULE;
1762 return NS_OK;
1765 NS_IMETHODIMP
1766 nsCSSFontFaceRule::GetCssText(nsAString& aCssText)
1768 nsAutoString propText;
1769 mDecl.GetCssText(propText);
1771 aCssText.AssignLiteral("@font-face {\n");
1772 aCssText.Append(propText);
1773 aCssText.Append('}');
1774 return NS_OK;
1777 NS_IMETHODIMP
1778 nsCSSFontFaceRule::SetCssText(const nsAString& aCssText)
1780 return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
1783 NS_IMETHODIMP
1784 nsCSSFontFaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
1786 return Rule::GetParentStyleSheet(aSheet);
1789 NS_IMETHODIMP
1790 nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
1792 return Rule::GetParentRule(aParentRule);
1795 css::Rule*
1796 nsCSSFontFaceRule::GetCSSRule()
1798 return Rule::GetCSSRule();
1801 NS_IMETHODIMP
1802 nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
1804 NS_IF_ADDREF(*aStyle = &mDecl);
1805 return NS_OK;
1808 // Arguably these should forward to nsCSSFontFaceStyleDecl methods.
1809 void
1810 nsCSSFontFaceRule::SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue)
1812 NS_PRECONDITION(aDescID > eCSSFontDesc_UNKNOWN &&
1813 aDescID < eCSSFontDesc_COUNT,
1814 "aDescID out of range in nsCSSFontFaceRule::SetDesc");
1816 // FIXME: handle dynamic changes
1818 mDecl.mDescriptors.Get(aDescID) = aValue;
1821 void
1822 nsCSSFontFaceRule::GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue)
1824 NS_PRECONDITION(aDescID > eCSSFontDesc_UNKNOWN &&
1825 aDescID < eCSSFontDesc_COUNT,
1826 "aDescID out of range in nsCSSFontFaceRule::GetDesc");
1828 aValue = mDecl.mDescriptors.Get(aDescID);
1831 /* virtual */ size_t
1832 nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
1834 return aMallocSizeOf(this);
1836 // Measurement of the following members may be added later if DMD finds it is
1837 // worthwhile:
1838 // - mDecl
1842 // -----------------------------------
1843 // nsCSSFontFeatureValuesRule
1846 /* virtual */ already_AddRefed<css::Rule>
1847 nsCSSFontFeatureValuesRule::Clone() const
1849 nsRefPtr<css::Rule> clone = new nsCSSFontFeatureValuesRule(*this);
1850 return clone.forget();
1853 NS_IMPL_ADDREF(nsCSSFontFeatureValuesRule)
1854 NS_IMPL_RELEASE(nsCSSFontFeatureValuesRule)
1856 // QueryInterface implementation for nsCSSFontFeatureValuesRule
1857 NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule)
1858 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
1859 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule)
1860 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
1861 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
1862 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule)
1863 NS_INTERFACE_MAP_END
1865 IMPL_STYLE_RULE_INHERIT(nsCSSFontFeatureValuesRule, Rule)
1867 static void
1868 FeatureValuesToString(
1869 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aFeatureValues,
1870 nsAString& aOutStr)
1872 uint32_t i, n;
1874 // append values
1875 n = aFeatureValues.Length();
1876 for (i = 0; i < n; i++) {
1877 const gfxFontFeatureValueSet::FeatureValues& fv = aFeatureValues[i];
1879 // @alternate
1880 aOutStr.AppendLiteral(" @");
1881 nsAutoString functAlt;
1882 nsStyleUtil::GetFunctionalAlternatesName(fv.alternate, functAlt);
1883 aOutStr.Append(functAlt);
1884 aOutStr.AppendLiteral(" {");
1886 // for each ident-values tuple
1887 uint32_t j, numValues = fv.valuelist.Length();
1888 for (j = 0; j < numValues; j++) {
1889 aOutStr.Append(' ');
1890 const gfxFontFeatureValueSet::ValueList& vlist = fv.valuelist[j];
1891 nsStyleUtil::AppendEscapedCSSIdent(vlist.name, aOutStr);
1892 aOutStr.Append(':');
1894 uint32_t k, numSelectors = vlist.featureSelectors.Length();
1895 for (k = 0; k < numSelectors; k++) {
1896 aOutStr.Append(' ');
1897 aOutStr.AppendInt(vlist.featureSelectors[k]);
1900 aOutStr.Append(';');
1902 aOutStr.AppendLiteral(" }\n");
1906 static void
1907 FontFeatureValuesRuleToString(
1908 const mozilla::FontFamilyList& aFamilyList,
1909 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aFeatureValues,
1910 nsAString& aOutStr)
1912 aOutStr.AssignLiteral("@font-feature-values ");
1913 nsAutoString familyListStr, valueTextStr;
1914 nsStyleUtil::AppendEscapedCSSFontFamilyList(aFamilyList, familyListStr);
1915 aOutStr.Append(familyListStr);
1916 aOutStr.AppendLiteral(" {\n");
1917 FeatureValuesToString(aFeatureValues, valueTextStr);
1918 aOutStr.Append(valueTextStr);
1919 aOutStr.Append('}');
1922 #ifdef DEBUG
1923 void
1924 nsCSSFontFeatureValuesRule::List(FILE* out, int32_t aIndent) const
1926 nsAutoString text;
1927 FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, text);
1928 NS_ConvertUTF16toUTF8 utf8(text);
1930 // replace newlines with newlines plus indent spaces
1931 char* indent = new char[(aIndent + 1) * 2];
1932 int32_t i;
1933 for (i = 1; i < (aIndent + 1) * 2 - 1; i++) {
1934 indent[i] = 0x20;
1936 indent[0] = 0xa;
1937 indent[aIndent * 2 + 1] = 0;
1938 utf8.ReplaceSubstring("\n", indent);
1939 delete [] indent;
1941 nsAutoCString indentStr;
1942 for (i = aIndent; --i >= 0; ) {
1943 indentStr.AppendLiteral(" ");
1945 fprintf_stderr(out, "%s%s\n", indentStr.get(), utf8.get());
1947 #endif
1949 /* virtual */ int32_t
1950 nsCSSFontFeatureValuesRule::GetType() const
1952 return Rule::FONT_FEATURE_VALUES_RULE;
1955 NS_IMETHODIMP
1956 nsCSSFontFeatureValuesRule::GetType(uint16_t* aType)
1958 *aType = nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE;
1959 return NS_OK;
1962 NS_IMETHODIMP
1963 nsCSSFontFeatureValuesRule::GetCssText(nsAString& aCssText)
1965 FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, aCssText);
1966 return NS_OK;
1969 NS_IMETHODIMP
1970 nsCSSFontFeatureValuesRule::SetCssText(const nsAString& aCssText)
1972 // FIXME: implement???
1973 return NS_ERROR_NOT_IMPLEMENTED;
1976 NS_IMETHODIMP
1977 nsCSSFontFeatureValuesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
1979 return Rule::GetParentStyleSheet(aSheet);
1982 NS_IMETHODIMP
1983 nsCSSFontFeatureValuesRule::GetParentRule(nsIDOMCSSRule** aParentRule)
1985 return Rule::GetParentRule(aParentRule);
1988 css::Rule*
1989 nsCSSFontFeatureValuesRule::GetCSSRule()
1991 return Rule::GetCSSRule();
1994 NS_IMETHODIMP
1995 nsCSSFontFeatureValuesRule::GetFontFamily(nsAString& aFamilyListStr)
1997 nsStyleUtil::AppendEscapedCSSFontFamilyList(mFamilyList, aFamilyListStr);
1998 return NS_OK;
2001 NS_IMETHODIMP
2002 nsCSSFontFeatureValuesRule::SetFontFamily(const nsAString& aFontFamily)
2004 return NS_ERROR_NOT_IMPLEMENTED;
2007 NS_IMETHODIMP
2008 nsCSSFontFeatureValuesRule::GetValueText(nsAString& aValueText)
2010 FeatureValuesToString(mFeatureValues, aValueText);
2011 return NS_OK;
2014 NS_IMETHODIMP
2015 nsCSSFontFeatureValuesRule::SetValueText(const nsAString& aValueText)
2017 return NS_ERROR_NOT_IMPLEMENTED;
2020 struct MakeFamilyArray {
2021 explicit MakeFamilyArray(nsTArray<nsString>& aFamilyArray)
2022 : familyArray(aFamilyArray), hasGeneric(false)
2025 static bool
2026 AddFamily(const nsString& aFamily, bool aGeneric, void* aData)
2028 MakeFamilyArray *familyArr = reinterpret_cast<MakeFamilyArray*> (aData);
2029 if (!aGeneric && !aFamily.IsEmpty()) {
2030 familyArr->familyArray.AppendElement(aFamily);
2032 if (aGeneric) {
2033 familyArr->hasGeneric = true;
2035 return true;
2038 nsTArray<nsString>& familyArray;
2039 bool hasGeneric;
2042 void
2043 nsCSSFontFeatureValuesRule::SetFamilyList(
2044 const mozilla::FontFamilyList& aFamilyList)
2046 mFamilyList = aFamilyList;
2049 void
2050 nsCSSFontFeatureValuesRule::AddValueList(int32_t aVariantAlternate,
2051 nsTArray<gfxFontFeatureValueSet::ValueList>& aValueList)
2053 uint32_t i, len = mFeatureValues.Length();
2054 bool foundAlternate = false;
2056 // add to an existing list for a given property value
2057 for (i = 0; i < len; i++) {
2058 gfxFontFeatureValueSet::FeatureValues& f = mFeatureValues.ElementAt(i);
2060 if (f.alternate == uint32_t(aVariantAlternate)) {
2061 f.valuelist.AppendElements(aValueList);
2062 foundAlternate = true;
2063 break;
2067 // create a new list for a given property value
2068 if (!foundAlternate) {
2069 gfxFontFeatureValueSet::FeatureValues &f = *mFeatureValues.AppendElement();
2070 f.alternate = aVariantAlternate;
2071 f.valuelist.AppendElements(aValueList);
2075 size_t
2076 nsCSSFontFeatureValuesRule::SizeOfIncludingThis(
2077 MallocSizeOf aMallocSizeOf) const
2079 return aMallocSizeOf(this);
2082 // -------------------------------------------
2083 // nsCSSKeyframeStyleDeclaration
2086 nsCSSKeyframeStyleDeclaration::nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule)
2087 : mRule(aRule)
2091 nsCSSKeyframeStyleDeclaration::~nsCSSKeyframeStyleDeclaration()
2093 NS_ASSERTION(!mRule, "DropReference not called.");
2096 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeStyleDeclaration)
2097 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeStyleDeclaration)
2099 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsCSSKeyframeStyleDeclaration)
2101 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeStyleDeclaration)
2102 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
2103 NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
2105 css::Declaration*
2106 nsCSSKeyframeStyleDeclaration::GetCSSDeclaration(bool aAllocate)
2108 if (mRule) {
2109 return mRule->Declaration();
2110 } else {
2111 return nullptr;
2115 void
2116 nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
2118 GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
2121 NS_IMETHODIMP
2122 nsCSSKeyframeStyleDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
2124 NS_ENSURE_ARG_POINTER(aParent);
2126 NS_IF_ADDREF(*aParent = mRule);
2127 return NS_OK;
2130 nsresult
2131 nsCSSKeyframeStyleDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
2133 NS_ABORT_IF_FALSE(aDecl, "must be non-null");
2134 mRule->ChangeDeclaration(aDecl);
2135 return NS_OK;
2138 nsIDocument*
2139 nsCSSKeyframeStyleDeclaration::DocToUpdate()
2141 return nullptr;
2144 nsINode*
2145 nsCSSKeyframeStyleDeclaration::GetParentObject()
2147 return mRule ? mRule->GetDocument() : nullptr;
2150 // -------------------------------------------
2151 // nsCSSKeyframeRule
2154 nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy)
2155 // copy everything except our reference count and mDOMDeclaration
2156 : Rule(aCopy)
2157 , mKeys(aCopy.mKeys)
2158 , mDeclaration(new css::Declaration(*aCopy.mDeclaration))
2162 nsCSSKeyframeRule::~nsCSSKeyframeRule()
2164 if (mDOMDeclaration) {
2165 mDOMDeclaration->DropReference();
2169 /* virtual */ already_AddRefed<css::Rule>
2170 nsCSSKeyframeRule::Clone() const
2172 nsRefPtr<css::Rule> clone = new nsCSSKeyframeRule(*this);
2173 return clone.forget();
2176 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeRule)
2177 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeRule)
2179 NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSKeyframeRule)
2181 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSKeyframeRule)
2182 if (tmp->mDOMDeclaration) {
2183 tmp->mDOMDeclaration->DropReference();
2184 tmp->mDOMDeclaration = nullptr;
2186 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
2187 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSKeyframeRule)
2188 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration)
2189 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
2191 // QueryInterface implementation for nsCSSKeyframeRule
2192 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeRule)
2193 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
2194 NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
2195 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
2196 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
2197 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframeRule)
2198 NS_INTERFACE_MAP_END
2200 IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule)
2202 /* virtual */ void
2203 nsCSSKeyframeRule::MapRuleInfoInto(nsRuleData* aRuleData)
2205 // We need to implement MapRuleInfoInto because the animation manager
2206 // constructs a rule node pointing to us in order to compute the
2207 // styles it needs to animate.
2209 // The spec says that !important declarations should just be ignored
2210 NS_ASSERTION(!mDeclaration->HasImportantData(),
2211 "Keyframe rules has !important data");
2213 mDeclaration->MapNormalRuleInfoInto(aRuleData);
2216 #ifdef DEBUG
2217 void
2218 nsCSSKeyframeRule::List(FILE* out, int32_t aIndent) const
2220 nsAutoCString str;
2221 for (int32_t index = aIndent; --index >= 0; ) {
2222 str.AppendLiteral(" ");
2225 nsAutoString tmp;
2226 DoGetKeyText(tmp);
2227 AppendUTF16toUTF8(tmp, str);
2228 str.AppendLiteral(" { ");
2229 mDeclaration->ToString(tmp);
2230 AppendUTF16toUTF8(tmp, str);
2231 str.AppendLiteral("}\n");
2232 fprintf_stderr(out, "%s", str.get());
2234 #endif
2236 /* virtual */ int32_t
2237 nsCSSKeyframeRule::GetType() const
2239 return Rule::KEYFRAME_RULE;
2242 NS_IMETHODIMP
2243 nsCSSKeyframeRule::GetType(uint16_t* aType)
2245 *aType = nsIDOMCSSRule::KEYFRAME_RULE;
2246 return NS_OK;
2249 NS_IMETHODIMP
2250 nsCSSKeyframeRule::GetCssText(nsAString& aCssText)
2252 DoGetKeyText(aCssText);
2253 aCssText.AppendLiteral(" { ");
2254 nsAutoString tmp;
2255 mDeclaration->ToString(tmp);
2256 aCssText.Append(tmp);
2257 aCssText.AppendLiteral(" }");
2258 return NS_OK;
2261 NS_IMETHODIMP
2262 nsCSSKeyframeRule::SetCssText(const nsAString& aCssText)
2264 // FIXME: implement???
2265 return NS_ERROR_NOT_IMPLEMENTED;
2268 NS_IMETHODIMP
2269 nsCSSKeyframeRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
2271 return Rule::GetParentStyleSheet(aSheet);
2274 NS_IMETHODIMP
2275 nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule** aParentRule)
2277 return Rule::GetParentRule(aParentRule);
2280 css::Rule*
2281 nsCSSKeyframeRule::GetCSSRule()
2283 return Rule::GetCSSRule();
2286 NS_IMETHODIMP
2287 nsCSSKeyframeRule::GetKeyText(nsAString& aKeyText)
2289 DoGetKeyText(aKeyText);
2290 return NS_OK;
2293 void
2294 nsCSSKeyframeRule::DoGetKeyText(nsAString& aKeyText) const
2296 aKeyText.Truncate();
2297 uint32_t i = 0, i_end = mKeys.Length();
2298 NS_ABORT_IF_FALSE(i_end != 0, "must have some keys");
2299 for (;;) {
2300 aKeyText.AppendFloat(mKeys[i] * 100.0f);
2301 aKeyText.Append(char16_t('%'));
2302 if (++i == i_end) {
2303 break;
2305 aKeyText.AppendLiteral(", ");
2309 NS_IMETHODIMP
2310 nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText)
2312 nsCSSParser parser;
2314 InfallibleTArray<float> newSelectors;
2315 // FIXME: pass filename and line number
2316 if (!parser.ParseKeyframeSelectorString(aKeyText, nullptr, 0, newSelectors)) {
2317 // for now, we don't do anything if the parse fails
2318 return NS_OK;
2321 nsIDocument* doc = GetDocument();
2322 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
2324 newSelectors.SwapElements(mKeys);
2326 CSSStyleSheet* sheet = GetStyleSheet();
2327 if (sheet) {
2328 sheet->SetModifiedByChildRule();
2330 if (doc) {
2331 doc->StyleRuleChanged(sheet, this, this);
2335 return NS_OK;
2338 NS_IMETHODIMP
2339 nsCSSKeyframeRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
2341 if (!mDOMDeclaration) {
2342 mDOMDeclaration = new nsCSSKeyframeStyleDeclaration(this);
2344 NS_ADDREF(*aStyle = mDOMDeclaration);
2345 return NS_OK;
2348 void
2349 nsCSSKeyframeRule::ChangeDeclaration(css::Declaration* aDeclaration)
2351 // Our caller already did a BeginUpdate/EndUpdate, but with
2352 // UPDATE_CONTENT, and we need UPDATE_STYLE to trigger work in
2353 // PresShell::EndUpdate.
2354 nsIDocument* doc = GetDocument();
2355 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
2357 // Be careful to not assign to an nsAutoPtr if we would be assigning
2358 // the thing it already holds.
2359 if (aDeclaration != mDeclaration) {
2360 mDeclaration = aDeclaration;
2363 CSSStyleSheet* sheet = GetStyleSheet();
2364 if (sheet) {
2365 sheet->SetModifiedByChildRule();
2367 if (doc) {
2368 doc->StyleRuleChanged(sheet, this, this);
2373 /* virtual */ size_t
2374 nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
2376 return aMallocSizeOf(this);
2378 // Measurement of the following members may be added later if DMD finds it is
2379 // worthwhile:
2380 // - mKeys
2381 // - mDeclaration
2382 // - mDOMDeclaration
2386 // -------------------------------------------
2387 // nsCSSKeyframesRule
2390 nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy)
2391 // copy everything except our reference count. GroupRule's copy
2392 // constructor also doesn't copy the lazily-constructed
2393 // mRuleCollection.
2394 : GroupRule(aCopy),
2395 mName(aCopy.mName)
2399 nsCSSKeyframesRule::~nsCSSKeyframesRule()
2403 /* virtual */ already_AddRefed<css::Rule>
2404 nsCSSKeyframesRule::Clone() const
2406 nsRefPtr<css::Rule> clone = new nsCSSKeyframesRule(*this);
2407 return clone.forget();
2410 NS_IMPL_ADDREF_INHERITED(nsCSSKeyframesRule, css::GroupRule)
2411 NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule)
2413 // QueryInterface implementation for nsCSSKeyframesRule
2414 NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule)
2415 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
2416 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
2417 NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframesRule)
2418 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
2419 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframesRule)
2420 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
2422 #ifdef DEBUG
2423 void
2424 nsCSSKeyframesRule::List(FILE* out, int32_t aIndent) const
2426 nsAutoCString indentStr;
2427 for (int32_t indent = aIndent; --indent >= 0; ) {
2428 indentStr.AppendLiteral(" ");
2431 fprintf_stderr(out, "%s@keyframes %s {\n",
2432 indentStr.get(), NS_ConvertUTF16toUTF8(mName).get());
2434 GroupRule::List(out, aIndent);
2436 fprintf_stderr(out, "%s}\n", indentStr.get());
2438 #endif
2440 /* virtual */ int32_t
2441 nsCSSKeyframesRule::GetType() const
2443 return Rule::KEYFRAMES_RULE;
2446 NS_IMETHODIMP
2447 nsCSSKeyframesRule::GetType(uint16_t* aType)
2449 *aType = nsIDOMCSSRule::KEYFRAMES_RULE;
2450 return NS_OK;
2453 NS_IMETHODIMP
2454 nsCSSKeyframesRule::GetCssText(nsAString& aCssText)
2456 aCssText.AssignLiteral("@keyframes ");
2457 aCssText.Append(mName);
2458 aCssText.AppendLiteral(" {\n");
2459 nsAutoString tmp;
2460 for (uint32_t i = 0, i_end = mRules.Count(); i != i_end; ++i) {
2461 static_cast<nsCSSKeyframeRule*>(mRules[i])->GetCssText(tmp);
2462 aCssText.Append(tmp);
2463 aCssText.Append('\n');
2465 aCssText.Append('}');
2466 return NS_OK;
2469 NS_IMETHODIMP
2470 nsCSSKeyframesRule::SetCssText(const nsAString& aCssText)
2472 // FIXME: implement???
2473 return NS_ERROR_NOT_IMPLEMENTED;
2476 NS_IMETHODIMP
2477 nsCSSKeyframesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
2479 return GroupRule::GetParentStyleSheet(aSheet);
2482 NS_IMETHODIMP
2483 nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule** aParentRule)
2485 return GroupRule::GetParentRule(aParentRule);
2488 css::Rule*
2489 nsCSSKeyframesRule::GetCSSRule()
2491 return GroupRule::GetCSSRule();
2494 NS_IMETHODIMP
2495 nsCSSKeyframesRule::GetName(nsAString& aName)
2497 aName = mName;
2498 return NS_OK;
2501 NS_IMETHODIMP
2502 nsCSSKeyframesRule::SetName(const nsAString& aName)
2504 if (mName == aName) {
2505 return NS_OK;
2508 nsIDocument* doc = GetDocument();
2509 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
2511 mName = aName;
2513 CSSStyleSheet* sheet = GetStyleSheet();
2514 if (sheet) {
2515 sheet->SetModifiedByChildRule();
2517 if (doc) {
2518 doc->StyleRuleChanged(sheet, this, this);
2522 return NS_OK;
2525 NS_IMETHODIMP
2526 nsCSSKeyframesRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
2528 return GroupRule::GetCssRules(aRuleList);
2531 NS_IMETHODIMP
2532 nsCSSKeyframesRule::AppendRule(const nsAString& aRule)
2534 // The spec is confusing, and I think we should just append the rule,
2535 // which also turns out to match WebKit:
2536 // http://lists.w3.org/Archives/Public/www-style/2011Apr/0034.html
2537 nsCSSParser parser;
2539 // FIXME: pass filename and line number
2540 nsRefPtr<nsCSSKeyframeRule> rule =
2541 parser.ParseKeyframeRule(aRule, nullptr, 0);
2542 if (rule) {
2543 nsIDocument* doc = GetDocument();
2544 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
2546 AppendStyleRule(rule);
2548 CSSStyleSheet* sheet = GetStyleSheet();
2549 if (sheet) {
2550 sheet->SetModifiedByChildRule();
2552 if (doc) {
2553 doc->StyleRuleChanged(sheet, this, this);
2558 return NS_OK;
2561 static const uint32_t RULE_NOT_FOUND = uint32_t(-1);
2563 uint32_t
2564 nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString& aKey)
2566 nsCSSParser parser;
2568 InfallibleTArray<float> keys;
2569 // FIXME: pass filename and line number
2570 if (parser.ParseKeyframeSelectorString(aKey, nullptr, 0, keys)) {
2571 // The spec isn't clear, but we'll match on the key list, which
2572 // mostly matches what WebKit does, except we'll do last-match
2573 // instead of first-match, and handling parsing differences better.
2574 // http://lists.w3.org/Archives/Public/www-style/2011Apr/0036.html
2575 // http://lists.w3.org/Archives/Public/www-style/2011Apr/0037.html
2576 for (uint32_t i = mRules.Count(); i-- != 0; ) {
2577 if (static_cast<nsCSSKeyframeRule*>(mRules[i])->GetKeys() == keys) {
2578 return i;
2583 return RULE_NOT_FOUND;
2586 NS_IMETHODIMP
2587 nsCSSKeyframesRule::DeleteRule(const nsAString& aKey)
2589 uint32_t index = FindRuleIndexForKey(aKey);
2590 if (index != RULE_NOT_FOUND) {
2591 nsIDocument* doc = GetDocument();
2592 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
2594 mRules.RemoveObjectAt(index);
2596 CSSStyleSheet* sheet = GetStyleSheet();
2597 if (sheet) {
2598 sheet->SetModifiedByChildRule();
2600 if (doc) {
2601 doc->StyleRuleChanged(sheet, this, this);
2605 return NS_OK;
2608 NS_IMETHODIMP
2609 nsCSSKeyframesRule::FindRule(const nsAString& aKey,
2610 nsIDOMMozCSSKeyframeRule** aResult)
2612 uint32_t index = FindRuleIndexForKey(aKey);
2613 if (index == RULE_NOT_FOUND) {
2614 *aResult = nullptr;
2615 } else {
2616 NS_ADDREF(*aResult = static_cast<nsCSSKeyframeRule*>(mRules[index]));
2618 return NS_OK;
2621 // GroupRule interface
2622 /* virtual */ bool
2623 nsCSSKeyframesRule::UseForPresentation(nsPresContext* aPresContext,
2624 nsMediaQueryResultCacheKey& aKey)
2626 NS_ABORT_IF_FALSE(false, "should not be called");
2627 return false;
2630 /* virtual */ size_t
2631 nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
2633 size_t n = aMallocSizeOf(this);
2634 n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
2636 // Measurement of the following members may be added later if DMD finds it is
2637 // worthwhile:
2638 // - mName
2640 return n;
2643 // -------------------------------------------
2644 // nsCSSPageStyleDeclaration
2647 nsCSSPageStyleDeclaration::nsCSSPageStyleDeclaration(nsCSSPageRule* aRule)
2648 : mRule(aRule)
2652 nsCSSPageStyleDeclaration::~nsCSSPageStyleDeclaration()
2654 NS_ASSERTION(!mRule, "DropReference not called.");
2657 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSPageStyleDeclaration)
2658 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSPageStyleDeclaration)
2660 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsCSSPageStyleDeclaration)
2662 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSPageStyleDeclaration)
2663 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
2664 NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
2666 css::Declaration*
2667 nsCSSPageStyleDeclaration::GetCSSDeclaration(bool aAllocate)
2669 if (mRule) {
2670 return mRule->Declaration();
2671 } else {
2672 return nullptr;
2676 void
2677 nsCSSPageStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
2679 GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
2682 NS_IMETHODIMP
2683 nsCSSPageStyleDeclaration::GetParentRule(nsIDOMCSSRule** aParent)
2685 NS_ENSURE_ARG_POINTER(aParent);
2687 NS_IF_ADDREF(*aParent = mRule);
2688 return NS_OK;
2691 nsresult
2692 nsCSSPageStyleDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
2694 NS_ABORT_IF_FALSE(aDecl, "must be non-null");
2695 mRule->ChangeDeclaration(aDecl);
2696 return NS_OK;
2699 nsIDocument*
2700 nsCSSPageStyleDeclaration::DocToUpdate()
2702 return nullptr;
2705 nsINode*
2706 nsCSSPageStyleDeclaration::GetParentObject()
2708 return mRule ? mRule->GetDocument() : nullptr;
2711 // -------------------------------------------
2712 // nsCSSPageRule
2715 nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy)
2716 // copy everything except our reference count and mDOMDeclaration
2717 : Rule(aCopy)
2718 , mDeclaration(new css::Declaration(*aCopy.mDeclaration))
2722 nsCSSPageRule::~nsCSSPageRule()
2724 if (mDOMDeclaration) {
2725 mDOMDeclaration->DropReference();
2729 /* virtual */ already_AddRefed<css::Rule>
2730 nsCSSPageRule::Clone() const
2732 nsRefPtr<css::Rule> clone = new nsCSSPageRule(*this);
2733 return clone.forget();
2736 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSPageRule)
2737 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSPageRule)
2739 NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSPageRule)
2741 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSPageRule)
2742 if (tmp->mDOMDeclaration) {
2743 tmp->mDOMDeclaration->DropReference();
2744 tmp->mDOMDeclaration = nullptr;
2746 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
2747 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSPageRule)
2748 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration)
2749 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
2751 // QueryInterface implementation for nsCSSPageRule
2752 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSPageRule)
2753 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
2754 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule)
2755 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
2756 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
2757 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule)
2758 NS_INTERFACE_MAP_END
2760 IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule)
2762 #ifdef DEBUG
2763 void
2764 nsCSSPageRule::List(FILE* out, int32_t aIndent) const
2766 nsAutoCString str;
2767 for (int32_t indent = aIndent; --indent >= 0; ) {
2768 str.AppendLiteral(" ");
2771 str.AppendLiteral("@page { ");
2772 nsAutoString tmp;
2773 mDeclaration->ToString(tmp);
2774 AppendUTF16toUTF8(tmp, str);
2775 str.AppendLiteral("}\n");
2776 fprintf_stderr(out, "%s", str.get());
2778 #endif
2780 /* virtual */ int32_t
2781 nsCSSPageRule::GetType() const
2783 return Rule::PAGE_RULE;
2786 NS_IMETHODIMP
2787 nsCSSPageRule::GetType(uint16_t* aType)
2789 *aType = nsIDOMCSSRule::PAGE_RULE;
2790 return NS_OK;
2793 NS_IMETHODIMP
2794 nsCSSPageRule::GetCssText(nsAString& aCssText)
2796 aCssText.AppendLiteral("@page { ");
2797 nsAutoString tmp;
2798 mDeclaration->ToString(tmp);
2799 aCssText.Append(tmp);
2800 aCssText.AppendLiteral(" }");
2801 return NS_OK;
2804 NS_IMETHODIMP
2805 nsCSSPageRule::SetCssText(const nsAString& aCssText)
2807 // FIXME: implement???
2808 return NS_ERROR_NOT_IMPLEMENTED;
2811 NS_IMETHODIMP
2812 nsCSSPageRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
2814 return Rule::GetParentStyleSheet(aSheet);
2817 NS_IMETHODIMP
2818 nsCSSPageRule::GetParentRule(nsIDOMCSSRule** aParentRule)
2820 return Rule::GetParentRule(aParentRule);
2823 css::Rule*
2824 nsCSSPageRule::GetCSSRule()
2826 return Rule::GetCSSRule();
2829 css::ImportantRule*
2830 nsCSSPageRule::GetImportantRule()
2832 if (!mDeclaration->HasImportantData()) {
2833 return nullptr;
2835 if (!mImportantRule) {
2836 mImportantRule = new css::ImportantRule(mDeclaration);
2838 return mImportantRule;
2841 /* virtual */ void
2842 nsCSSPageRule::MapRuleInfoInto(nsRuleData* aRuleData)
2844 mDeclaration->MapNormalRuleInfoInto(aRuleData);
2847 NS_IMETHODIMP
2848 nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
2850 if (!mDOMDeclaration) {
2851 mDOMDeclaration = new nsCSSPageStyleDeclaration(this);
2853 NS_ADDREF(*aStyle = mDOMDeclaration);
2854 return NS_OK;
2857 void
2858 nsCSSPageRule::ChangeDeclaration(css::Declaration* aDeclaration)
2860 mImportantRule = nullptr;
2861 // Be careful to not assign to an nsAutoPtr if we would be assigning
2862 // the thing it already holds.
2863 if (aDeclaration != mDeclaration) {
2864 mDeclaration = aDeclaration;
2867 CSSStyleSheet* sheet = GetStyleSheet();
2868 if (sheet) {
2869 sheet->SetModifiedByChildRule();
2873 /* virtual */ size_t
2874 nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
2876 return aMallocSizeOf(this);
2879 namespace mozilla {
2881 CSSSupportsRule::CSSSupportsRule(bool aConditionMet,
2882 const nsString& aCondition,
2883 uint32_t aLineNumber, uint32_t aColumnNumber)
2884 : css::GroupRule(aLineNumber, aColumnNumber)
2885 , mUseGroup(aConditionMet)
2886 , mCondition(aCondition)
2890 CSSSupportsRule::~CSSSupportsRule()
2894 CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy)
2895 : css::GroupRule(aCopy),
2896 mUseGroup(aCopy.mUseGroup),
2897 mCondition(aCopy.mCondition)
2901 #ifdef DEBUG
2902 /* virtual */ void
2903 CSSSupportsRule::List(FILE* out, int32_t aIndent) const
2905 nsAutoCString indentStr;
2906 for (int32_t indent = aIndent; --indent >= 0; ) {
2907 indentStr.AppendLiteral(" ");
2910 fprintf_stderr(out, "%s@supports %s {\n",
2911 indentStr.get(), NS_ConvertUTF16toUTF8(mCondition).get());
2913 css::GroupRule::List(out, aIndent);
2915 fprintf_stderr(out, "%s}\n", indentStr.get());
2917 #endif
2919 /* virtual */ int32_t
2920 CSSSupportsRule::GetType() const
2922 return Rule::SUPPORTS_RULE;
2925 /* virtual */ already_AddRefed<mozilla::css::Rule>
2926 CSSSupportsRule::Clone() const
2928 nsRefPtr<css::Rule> clone = new CSSSupportsRule(*this);
2929 return clone.forget();
2932 /* virtual */ bool
2933 CSSSupportsRule::UseForPresentation(nsPresContext* aPresContext,
2934 nsMediaQueryResultCacheKey& aKey)
2936 return mUseGroup;
2939 NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::GroupRule)
2940 NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule)
2942 // QueryInterface implementation for CSSSupportsRule
2943 NS_INTERFACE_MAP_BEGIN(CSSSupportsRule)
2944 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
2945 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
2946 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
2947 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
2948 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule)
2949 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
2950 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule)
2951 NS_INTERFACE_MAP_END_INHERITING(GroupRule)
2953 // nsIDOMCSSRule methods
2954 NS_IMETHODIMP
2955 CSSSupportsRule::GetType(uint16_t* aType)
2957 *aType = nsIDOMCSSRule::SUPPORTS_RULE;
2958 return NS_OK;
2961 NS_IMETHODIMP
2962 CSSSupportsRule::GetCssText(nsAString& aCssText)
2964 aCssText.AssignLiteral("@supports ");
2965 aCssText.Append(mCondition);
2966 css::GroupRule::AppendRulesToCssText(aCssText);
2967 return NS_OK;
2970 NS_IMETHODIMP
2971 CSSSupportsRule::SetCssText(const nsAString& aCssText)
2973 return NS_ERROR_NOT_IMPLEMENTED;
2976 NS_IMETHODIMP
2977 CSSSupportsRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
2979 return css::GroupRule::GetParentStyleSheet(aSheet);
2982 NS_IMETHODIMP
2983 CSSSupportsRule::GetParentRule(nsIDOMCSSRule** aParentRule)
2985 return css::GroupRule::GetParentRule(aParentRule);
2988 css::Rule*
2989 CSSSupportsRule::GetCSSRule()
2991 return css::GroupRule::GetCSSRule();
2994 // nsIDOMCSSGroupingRule methods
2995 NS_IMETHODIMP
2996 CSSSupportsRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
2998 return css::GroupRule::GetCssRules(aRuleList);
3001 NS_IMETHODIMP
3002 CSSSupportsRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
3004 return css::GroupRule::InsertRule(aRule, aIndex, _retval);
3007 NS_IMETHODIMP
3008 CSSSupportsRule::DeleteRule(uint32_t aIndex)
3010 return css::GroupRule::DeleteRule(aIndex);
3013 // nsIDOMCSSConditionRule methods
3014 NS_IMETHODIMP
3015 CSSSupportsRule::GetConditionText(nsAString& aConditionText)
3017 aConditionText.Assign(mCondition);
3018 return NS_OK;
3021 NS_IMETHODIMP
3022 CSSSupportsRule::SetConditionText(const nsAString& aConditionText)
3024 return NS_ERROR_NOT_IMPLEMENTED;
3027 /* virtual */ size_t
3028 CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
3030 size_t n = aMallocSizeOf(this);
3031 n += css::GroupRule::SizeOfExcludingThis(aMallocSizeOf);
3032 n += mCondition.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
3033 return n;
3036 } // namespace mozilla
3038 // -------------------------------------------
3039 // nsCSSCounterStyleRule
3042 nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy)
3043 : Rule(aCopy)
3044 , mName(aCopy.mName)
3045 , mGeneration(aCopy.mGeneration)
3047 for (size_t i = 0; i < ArrayLength(mValues); ++i) {
3048 mValues[i] = aCopy.mValues[i];
3052 nsCSSCounterStyleRule::~nsCSSCounterStyleRule()
3056 /* virtual */ already_AddRefed<css::Rule>
3057 nsCSSCounterStyleRule::Clone() const
3059 nsRefPtr<css::Rule> clone = new nsCSSCounterStyleRule(*this);
3060 return clone.forget();
3063 nsCSSCounterStyleRule::Getter const
3064 nsCSSCounterStyleRule::kGetters[] = {
3065 #define CSS_COUNTER_DESC(name_, method_) &nsCSSCounterStyleRule::Get##method_,
3066 #include "nsCSSCounterDescList.h"
3067 #undef CSS_COUNTER_DESC
3070 NS_IMPL_ADDREF(nsCSSCounterStyleRule)
3071 NS_IMPL_RELEASE(nsCSSCounterStyleRule)
3073 // QueryInterface implementation for nsCSSCounterStyleRule
3074 NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule)
3075 NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
3076 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
3077 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule)
3078 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
3079 NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule)
3080 NS_INTERFACE_MAP_END
3082 IMPL_STYLE_RULE_INHERIT(nsCSSCounterStyleRule, css::Rule)
3084 #ifdef DEBUG
3085 void
3086 nsCSSCounterStyleRule::List(FILE* out, int32_t aIndent) const
3088 nsCString baseInd, descInd;
3089 for (int32_t indent = aIndent; --indent >= 0; ) {
3090 baseInd.AppendLiteral(" ");
3092 descInd = baseInd;
3093 descInd.AppendLiteral(" ");
3095 fprintf_stderr(out, "%s@counter-style %s (rev.%u) {\n",
3096 baseInd.get(), NS_ConvertUTF16toUTF8(mName).get(),
3097 mGeneration);
3098 // TODO
3099 fprintf_stderr(out, "%s}\n", baseInd.get());
3101 #endif
3103 /* virtual */ int32_t
3104 nsCSSCounterStyleRule::GetType() const
3106 return Rule::COUNTER_STYLE_RULE;
3109 // nsIDOMCSSRule methods
3110 NS_IMETHODIMP
3111 nsCSSCounterStyleRule::GetType(uint16_t* aType)
3113 *aType = nsIDOMCSSRule::COUNTER_STYLE_RULE;
3114 return NS_OK;
3117 NS_IMETHODIMP
3118 nsCSSCounterStyleRule::GetCssText(nsAString& aCssText)
3120 aCssText.AssignLiteral(MOZ_UTF16("@counter-style "));
3121 nsStyleUtil::AppendEscapedCSSIdent(mName, aCssText);
3122 aCssText.AppendLiteral(MOZ_UTF16(" {\n"));
3123 for (nsCSSCounterDesc id = nsCSSCounterDesc(0);
3124 id < eCSSCounterDesc_COUNT;
3125 id = nsCSSCounterDesc(id + 1)) {
3126 if (mValues[id].GetUnit() != eCSSUnit_Null) {
3127 nsAutoString tmp;
3128 (this->*kGetters[id])(tmp);
3129 aCssText.AppendLiteral(MOZ_UTF16(" "));
3130 AppendASCIItoUTF16(nsCSSProps::GetStringValue(id), aCssText);
3131 aCssText.AppendLiteral(MOZ_UTF16(": "));
3132 aCssText.Append(tmp);
3133 aCssText.AppendLiteral(MOZ_UTF16(";\n"));
3136 aCssText.AppendLiteral(MOZ_UTF16("}"));
3137 return NS_OK;
3140 NS_IMETHODIMP
3141 nsCSSCounterStyleRule::SetCssText(const nsAString& aCssText)
3143 // FIXME: implement???
3144 return NS_ERROR_NOT_IMPLEMENTED;
3147 NS_IMETHODIMP
3148 nsCSSCounterStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
3150 return Rule::GetParentStyleSheet(aSheet);
3153 NS_IMETHODIMP
3154 nsCSSCounterStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule)
3156 return Rule::GetParentRule(aParentRule);
3159 css::Rule*
3160 nsCSSCounterStyleRule::GetCSSRule()
3162 return Rule::GetCSSRule();
3165 // nsIDOMCSSCounterStyleRule methods
3166 NS_IMETHODIMP
3167 nsCSSCounterStyleRule::GetName(nsAString& aName)
3169 aName.Truncate();
3170 nsStyleUtil::AppendEscapedCSSIdent(mName, aName);
3171 return NS_OK;
3174 NS_IMETHODIMP
3175 nsCSSCounterStyleRule::SetName(const nsAString& aName)
3177 nsCSSParser parser;
3178 nsAutoString name;
3179 if (parser.ParseCounterStyleName(aName, nullptr, name)) {
3180 nsIDocument* doc = GetDocument();
3181 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
3183 mName = name;
3185 CSSStyleSheet* sheet = GetStyleSheet();
3186 if (sheet) {
3187 sheet->SetModifiedByChildRule();
3188 if (doc) {
3189 doc->StyleRuleChanged(sheet, this, this);
3193 return NS_OK;
3196 int32_t
3197 nsCSSCounterStyleRule::GetSystem() const
3199 const nsCSSValue& system = GetDesc(eCSSCounterDesc_System);
3200 switch (system.GetUnit()) {
3201 case eCSSUnit_Enumerated:
3202 return system.GetIntValue();
3203 case eCSSUnit_Pair:
3204 return system.GetPairValue().mXValue.GetIntValue();
3205 default:
3206 return NS_STYLE_COUNTER_SYSTEM_SYMBOLIC;
3210 const nsCSSValue&
3211 nsCSSCounterStyleRule::GetSystemArgument() const
3213 const nsCSSValue& system = GetDesc(eCSSCounterDesc_System);
3214 NS_ABORT_IF_FALSE(system.GetUnit() == eCSSUnit_Pair,
3215 "Invalid system value");
3216 return system.GetPairValue().mYValue;
3219 void
3220 nsCSSCounterStyleRule::SetDesc(nsCSSCounterDesc aDescID, const nsCSSValue& aValue)
3222 NS_ABORT_IF_FALSE(aDescID >= 0 && aDescID < eCSSCounterDesc_COUNT,
3223 "descriptor ID out of range");
3225 nsIDocument* doc = GetDocument();
3226 MOZ_AUTO_DOC_UPDATE(doc, UPDATE_STYLE, true);
3228 mValues[aDescID] = aValue;
3229 mGeneration++;
3231 CSSStyleSheet* sheet = GetStyleSheet();
3232 if (sheet) {
3233 sheet->SetModifiedByChildRule();
3234 if (doc) {
3235 doc->StyleRuleChanged(sheet, this, this);
3240 NS_IMETHODIMP
3241 nsCSSCounterStyleRule::GetSystem(nsAString& aSystem)
3243 const nsCSSValue& value = GetDesc(eCSSCounterDesc_System);
3244 if (value.GetUnit() == eCSSUnit_Null) {
3245 aSystem.Truncate();
3246 return NS_OK;
3249 aSystem = NS_ConvertASCIItoUTF16(nsCSSProps::ValueToKeyword(
3250 GetSystem(), nsCSSProps::kCounterSystemKTable));
3251 if (value.GetUnit() == eCSSUnit_Pair) {
3252 aSystem.Append(' ');
3253 GetSystemArgument().AppendToString(
3254 eCSSProperty_UNKNOWN, aSystem, nsCSSValue::eNormalized);
3256 return NS_OK;
3259 NS_IMETHODIMP
3260 nsCSSCounterStyleRule::GetSymbols(nsAString& aSymbols)
3262 const nsCSSValue& value = GetDesc(eCSSCounterDesc_Symbols);
3264 aSymbols.Truncate();
3265 if (value.GetUnit() == eCSSUnit_List) {
3266 for (const nsCSSValueList* item = value.GetListValue();
3267 item; item = item->mNext) {
3268 item->mValue.AppendToString(eCSSProperty_UNKNOWN,
3269 aSymbols,
3270 nsCSSValue::eNormalized);
3271 if (item->mNext) {
3272 aSymbols.Append(' ');
3276 return NS_OK;
3279 NS_IMETHODIMP
3280 nsCSSCounterStyleRule::GetAdditiveSymbols(nsAString& aSymbols)
3282 const nsCSSValue& value = GetDesc(eCSSCounterDesc_AdditiveSymbols);
3284 aSymbols.Truncate();
3285 if (value.GetUnit() == eCSSUnit_PairList) {
3286 for (const nsCSSValuePairList* item = value.GetPairListValue();
3287 item; item = item->mNext) {
3288 item->mXValue.AppendToString(eCSSProperty_UNKNOWN,
3289 aSymbols, nsCSSValue::eNormalized);
3290 aSymbols.Append(' ');
3291 item->mYValue.AppendToString(eCSSProperty_UNKNOWN,
3292 aSymbols, nsCSSValue::eNormalized);
3293 if (item->mNext) {
3294 aSymbols.AppendLiteral(", ");
3298 return NS_OK;
3301 NS_IMETHODIMP
3302 nsCSSCounterStyleRule::GetRange(nsAString& aRange)
3304 const nsCSSValue& value = GetDesc(eCSSCounterDesc_Range);
3306 switch (value.GetUnit()) {
3307 case eCSSUnit_Auto:
3308 aRange.AssignLiteral(MOZ_UTF16("auto"));
3309 break;
3311 case eCSSUnit_PairList:
3312 aRange.Truncate();
3313 for (const nsCSSValuePairList* item = value.GetPairListValue();
3314 item; item = item->mNext) {
3315 const nsCSSValue& lower = item->mXValue;
3316 const nsCSSValue& upper = item->mYValue;
3317 if (lower.GetUnit() == eCSSUnit_Enumerated) {
3318 NS_ASSERTION(lower.GetIntValue() ==
3319 NS_STYLE_COUNTER_RANGE_INFINITE,
3320 "Unrecognized keyword");
3321 aRange.AppendLiteral("infinite");
3322 } else {
3323 aRange.AppendInt(lower.GetIntValue());
3325 aRange.Append(' ');
3326 if (upper.GetUnit() == eCSSUnit_Enumerated) {
3327 NS_ASSERTION(upper.GetIntValue() ==
3328 NS_STYLE_COUNTER_RANGE_INFINITE,
3329 "Unrecognized keyword");
3330 aRange.AppendLiteral("infinite");
3331 } else {
3332 aRange.AppendInt(upper.GetIntValue());
3334 if (item->mNext) {
3335 aRange.AppendLiteral(", ");
3338 break;
3340 default:
3341 aRange.Truncate();
3343 return NS_OK;
3346 NS_IMETHODIMP
3347 nsCSSCounterStyleRule::GetSpeakAs(nsAString& aSpeakAs)
3349 const nsCSSValue& value = GetDesc(eCSSCounterDesc_SpeakAs);
3351 switch (value.GetUnit()) {
3352 case eCSSUnit_Enumerated:
3353 switch (value.GetIntValue()) {
3354 case NS_STYLE_COUNTER_SPEAKAS_BULLETS:
3355 aSpeakAs.AssignLiteral(MOZ_UTF16("bullets"));
3356 break;
3357 case NS_STYLE_COUNTER_SPEAKAS_NUMBERS:
3358 aSpeakAs.AssignLiteral(MOZ_UTF16("numbers"));
3359 break;
3360 case NS_STYLE_COUNTER_SPEAKAS_WORDS:
3361 aSpeakAs.AssignLiteral(MOZ_UTF16("words"));
3362 break;
3363 case NS_STYLE_COUNTER_SPEAKAS_SPELL_OUT:
3364 aSpeakAs.AssignLiteral(MOZ_UTF16("spell-out"));
3365 break;
3366 default:
3367 NS_NOTREACHED("Unknown speech synthesis");
3369 break;
3371 case eCSSUnit_Auto:
3372 case eCSSUnit_Ident:
3373 aSpeakAs.Truncate();
3374 value.AppendToString(eCSSProperty_UNKNOWN,
3375 aSpeakAs, nsCSSValue::eNormalized);
3376 break;
3378 default:
3379 aSpeakAs.Truncate();
3381 return NS_OK;
3384 nsresult
3385 nsCSSCounterStyleRule::GetDescriptor(nsCSSCounterDesc aDescID,
3386 nsAString& aValue)
3388 NS_ASSERTION(aDescID == eCSSCounterDesc_Negative ||
3389 aDescID == eCSSCounterDesc_Prefix ||
3390 aDescID == eCSSCounterDesc_Suffix ||
3391 aDescID == eCSSCounterDesc_Pad ||
3392 aDescID == eCSSCounterDesc_Fallback,
3393 "Unexpected descriptor");
3394 const nsCSSValue& value = GetDesc(aDescID);
3395 aValue.Truncate();
3396 if (value.GetUnit() != eCSSUnit_Null) {
3397 value.AppendToString(
3398 eCSSProperty_UNKNOWN, aValue, nsCSSValue::eNormalized);
3400 return NS_OK;
3403 #define CSS_COUNTER_DESC_GETTER(name_) \
3404 NS_IMETHODIMP \
3405 nsCSSCounterStyleRule::Get##name_(nsAString& a##name_) \
3407 return GetDescriptor(eCSSCounterDesc_##name_, a##name_);\
3409 CSS_COUNTER_DESC_GETTER(Negative)
3410 CSS_COUNTER_DESC_GETTER(Prefix)
3411 CSS_COUNTER_DESC_GETTER(Suffix)
3412 CSS_COUNTER_DESC_GETTER(Pad)
3413 CSS_COUNTER_DESC_GETTER(Fallback)
3414 #undef CSS_COUNTER_DESC_GETTER
3416 /* static */ bool
3417 nsCSSCounterStyleRule::CheckDescValue(int32_t aSystem,
3418 nsCSSCounterDesc aDescID,
3419 const nsCSSValue& aValue)
3421 switch (aDescID) {
3422 case eCSSCounterDesc_System:
3423 if (aValue.GetUnit() != eCSSUnit_Pair) {
3424 return aValue.GetIntValue() == aSystem;
3425 } else {
3426 return aValue.GetPairValue().mXValue.GetIntValue() == aSystem;
3429 case eCSSCounterDesc_Symbols:
3430 switch (aSystem) {
3431 case NS_STYLE_COUNTER_SYSTEM_NUMERIC:
3432 case NS_STYLE_COUNTER_SYSTEM_ALPHABETIC:
3433 // for these two system, the list must contain at least 2 elements
3434 return aValue.GetListValue()->mNext;
3435 case NS_STYLE_COUNTER_SYSTEM_EXTENDS:
3436 // for extends system, no symbols should be set
3437 return false;
3438 default:
3439 return true;
3442 case eCSSCounterDesc_AdditiveSymbols:
3443 switch (aSystem) {
3444 case NS_STYLE_COUNTER_SYSTEM_EXTENDS:
3445 return false;
3446 default:
3447 return true;
3450 default:
3451 return true;
3455 nsresult
3456 nsCSSCounterStyleRule::SetDescriptor(nsCSSCounterDesc aDescID,
3457 const nsAString& aValue)
3459 nsCSSParser parser;
3460 nsCSSValue value;
3461 CSSStyleSheet* sheet = GetStyleSheet();
3462 nsIURI* baseURL = nullptr;
3463 nsIPrincipal* principal = nullptr;
3464 if (sheet) {
3465 baseURL = sheet->GetBaseURI();
3466 principal = sheet->Principal();
3468 if (parser.ParseCounterDescriptor(aDescID, aValue, nullptr,
3469 baseURL, principal, value)) {
3470 if (CheckDescValue(GetSystem(), aDescID, value)) {
3471 SetDesc(aDescID, value);
3474 return NS_OK;
3477 #define CSS_COUNTER_DESC_SETTER(name_) \
3478 NS_IMETHODIMP \
3479 nsCSSCounterStyleRule::Set##name_(const nsAString& a##name_) \
3481 return SetDescriptor(eCSSCounterDesc_##name_, a##name_); \
3483 CSS_COUNTER_DESC_SETTER(System)
3484 CSS_COUNTER_DESC_SETTER(Symbols)
3485 CSS_COUNTER_DESC_SETTER(AdditiveSymbols)
3486 CSS_COUNTER_DESC_SETTER(Negative)
3487 CSS_COUNTER_DESC_SETTER(Prefix)
3488 CSS_COUNTER_DESC_SETTER(Suffix)
3489 CSS_COUNTER_DESC_SETTER(Range)
3490 CSS_COUNTER_DESC_SETTER(Pad)
3491 CSS_COUNTER_DESC_SETTER(Fallback)
3492 CSS_COUNTER_DESC_SETTER(SpeakAs)
3493 #undef CSS_COUNTER_DESC_SETTER
3495 /* virtual */ size_t
3496 nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
3498 return aMallocSizeOf(this);