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"
20 #include "nsCSSProps.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"
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"
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() \
47 /* virtual */ nsIDOMCSSRule* class_::GetExistingDOMRule() \
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
63 Rule::GetStyleSheet() const
65 if (!(mSheet
& 0x1)) {
66 return reinterpret_cast<CSSStyleSheet
*>(mSheet
);
73 Rule::GetHTMLCSSStyleSheet() const
76 return reinterpret_cast<nsHTMLCSSStyleSheet
*>(mSheet
& ~uintptr_t(0x1));
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
88 mSheet
= reinterpret_cast<uintptr_t>(aSheet
);
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
97 mSheet
= reinterpret_cast<uintptr_t>(aSheet
);
102 Rule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
105 NS_IF_ADDREF(*aParentRule
= mParentRule
->GetDOMRule());
107 *aParentRule
= nullptr;
113 Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
115 NS_ENSURE_ARG_POINTER(aSheet
);
117 NS_IF_ADDREF(*aSheet
= GetStyleSheet());
128 Rule::SizeOfCOMArrayElementIncludingThis(css::Rule
* aElement
,
129 MallocSizeOf aMallocSizeOf
,
132 return aElement
->SizeOfIncludingThis(aMallocSizeOf
);
135 // -------------------------------
136 // Style Rule List for group rules
139 class GroupRuleRuleList MOZ_FINAL
: public dom::CSSRuleList
142 explicit GroupRuleRuleList(GroupRule
*aGroupRule
);
144 virtual CSSStyleSheet
* GetParentObject() MOZ_OVERRIDE
;
146 virtual nsIDOMCSSRule
*
147 IndexedGetter(uint32_t aIndex
, bool& aFound
) MOZ_OVERRIDE
;
149 Length() MOZ_OVERRIDE
;
151 void DropReference() { mGroupRule
= nullptr; }
154 ~GroupRuleRuleList();
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()
172 GroupRuleRuleList::GetParentObject()
178 return mGroupRule
->GetStyleSheet();
182 GroupRuleRuleList::Length()
188 return AssertedCast
<uint32_t>(mGroupRule
->StyleRuleCount());
192 GroupRuleRuleList::IndexedGetter(uint32_t aIndex
, bool& aFound
)
197 nsRefPtr
<Rule
> rule
= mGroupRule
->GetStyleRuleAt(aIndex
);
200 return rule
->GetDOMRule();
207 // -------------------------------------------
211 CharsetRule::CharsetRule(const nsAString
& aEncoding
,
212 uint32_t aLineNumber
, uint32_t aColumnNumber
)
213 : Rule(aLineNumber
, aColumnNumber
),
218 CharsetRule::CharsetRule(const CharsetRule
& 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
)
236 IMPL_STYLE_RULE_INHERIT(CharsetRule
, Rule
)
240 CharsetRule::List(FILE* out
, int32_t aIndent
) const
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());
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();
269 CharsetRule::GetEncoding(nsAString
& aEncoding
)
271 aEncoding
= mEncoding
;
276 CharsetRule::SetEncoding(const nsAString
& aEncoding
)
278 mEncoding
= aEncoding
;
283 CharsetRule::GetType(uint16_t* aType
)
285 *aType
= nsIDOMCSSRule::CHARSET_RULE
;
290 CharsetRule::GetCssText(nsAString
& aCssText
)
292 aCssText
.AssignLiteral("@charset \"");
293 aCssText
.Append(mEncoding
);
294 aCssText
.AppendLiteral("\";");
299 CharsetRule::SetCssText(const nsAString
& aCssText
)
301 return NS_ERROR_NOT_IMPLEMENTED
;
305 CharsetRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
307 return Rule::GetParentStyleSheet(aSheet
);
311 CharsetRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
313 return Rule::GetParentRule(aParentRule
);
317 CharsetRule::GetCSSRule()
319 return Rule::GetCSSRule();
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
332 // -------------------------------------------
336 ImportRule::ImportRule(nsMediaList
* aMedia
, const nsString
& aURLSpec
,
337 uint32_t aLineNumber
, uint32_t aColumnNumber
)
338 : Rule(aLineNumber
, aColumnNumber
)
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
)
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);
358 // SetSheet sets mMedia appropriately
362 ImportRule::~ImportRule()
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
)
383 IMPL_STYLE_RULE_INHERIT(ImportRule
, Rule
)
387 ImportRule::List(FILE* out
, int32_t aIndent
) const
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());
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();
421 ImportRule::SetSheet(CSSStyleSheet
* aSheet
)
423 NS_PRECONDITION(aSheet
, "null arg");
426 mChildSheet
= aSheet
;
427 aSheet
->SetOwnerRule(this);
429 // set our medialist to be the same as the sheet's medialist
430 mMedia
= mChildSheet
->Media();
434 ImportRule::GetType(uint16_t* aType
)
436 NS_ENSURE_ARG_POINTER(aType
);
437 *aType
= nsIDOMCSSRule::IMPORT_RULE
;
442 ImportRule::GetCssText(nsAString
& aCssText
)
444 aCssText
.AssignLiteral("@import url(");
445 nsStyleUtil::AppendEscapedCSSString(mURLSpec
, aCssText
);
446 aCssText
.Append(')');
448 nsAutoString mediaText
;
449 mMedia
->GetText(mediaText
);
450 if (!mediaText
.IsEmpty()) {
451 aCssText
.Append(' ');
452 aCssText
.Append(mediaText
);
455 aCssText
.Append(';');
460 ImportRule::SetCssText(const nsAString
& aCssText
)
462 return NS_ERROR_NOT_IMPLEMENTED
;
466 ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
468 return Rule::GetParentStyleSheet(aSheet
);
472 ImportRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
474 return Rule::GetParentRule(aParentRule
);
478 ImportRule::GetCSSRule()
480 return Rule::GetCSSRule();
484 ImportRule::GetHref(nsAString
& aHref
)
491 ImportRule::GetMedia(nsIDOMMediaList
* *aMedia
)
493 NS_ENSURE_ARG_POINTER(aMedia
);
495 NS_IF_ADDREF(*aMedia
= mMedia
);
500 ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet
* *aStyleSheet
)
502 NS_ENSURE_ARG_POINTER(aStyleSheet
);
504 NS_IF_ADDREF(*aStyleSheet
= mChildSheet
);
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
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
)
528 SetParentRuleReference(Rule
* aRule
, void* aParentRule
)
530 GroupRule
* parentRule
= static_cast<GroupRule
*>(aParentRule
);
531 aRule
->SetParentRule(parentRule
);
535 GroupRule::GroupRule(const GroupRule
& 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
)
557 IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(GroupRule
, Rule
)
560 SetStyleSheetReference(Rule
* aRule
, void* aSheet
)
562 CSSStyleSheet
* sheet
= (CSSStyleSheet
*)aSheet
;
563 aRule
->SetStyleSheet(sheet
);
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
577 if (tmp
->GetStyleSheet()) {
578 tmp
->mRules
.EnumerateForwards(SetStyleSheetReference
, nullptr);
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
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
);
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);
620 GroupRule::AppendStyleRule(Rule
* aRule
)
622 mRules
.AppendObject(aRule
);
623 CSSStyleSheet
* sheet
= GetStyleSheet();
624 aRule
->SetStyleSheet(sheet
);
625 aRule
->SetParentRule(this);
627 sheet
->SetModifiedByChildRule();
632 GroupRule::GetStyleRuleAt(int32_t aIndex
) const
634 return mRules
.SafeObjectAt(aIndex
);
638 GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc
, void * aData
) const
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
651 GroupRule::DeleteStyleRuleAt(uint32_t aIndex
)
653 Rule
* rule
= mRules
.SafeObjectAt(aIndex
);
655 rule
->SetStyleSheet(nullptr);
656 rule
->SetParentRule(nullptr);
658 return mRules
.RemoveObjectAt(aIndex
) ? NS_OK
: NS_ERROR_ILLEGAL_VALUE
;
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
;
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);
686 GroupRule::AppendRulesToCssText(nsAString
& aCssText
)
688 aCssText
.AppendLiteral(" {\n");
691 for (int32_t index
= 0, count
= mRules
.Count(); index
< count
; ++index
) {
692 Rule
* rule
= mRules
.ObjectAt(index
);
693 nsIDOMCSSRule
* domRule
= rule
->GetDOMRule();
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
708 GroupRule::GetCssRules(nsIDOMCSSRuleList
* *aRuleList
)
710 if (!mRuleCollection
) {
711 mRuleCollection
= new css::GroupRuleRuleList(this);
714 NS_ADDREF(*aRuleList
= mRuleCollection
);
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
);
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
);
749 GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
) const
751 return mRules
.SizeOfExcludingThis(Rule::SizeOfCOMArrayElementIncludingThis
,
754 // Measurement of the following members may be added later if DMD finds it is
760 // -------------------------------------------
763 MediaRule::MediaRule(uint32_t aLineNumber
, uint32_t aColumnNumber
)
764 : GroupRule(aLineNumber
, aColumnNumber
)
768 MediaRule::MediaRule(const MediaRule
& aCopy
)
772 mMedia
= aCopy
.mMedia
->Clone();
773 // XXXldb This doesn't really make sense.
774 mMedia
->SetStyleSheet(aCopy
.GetStyleSheet());
778 MediaRule::~MediaRule()
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
)
800 MediaRule::SetStyleSheet(CSSStyleSheet
* aSheet
)
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
);
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 ");
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());
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();
852 MediaRule::SetMedia(nsMediaList
* aMedia
)
856 mMedia
->SetStyleSheet(GetStyleSheet());
860 // nsIDOMCSSRule methods
862 MediaRule::GetType(uint16_t* aType
)
864 *aType
= nsIDOMCSSRule::MEDIA_RULE
;
869 MediaRule::GetCssText(nsAString
& aCssText
)
871 aCssText
.AssignLiteral("@media ");
872 AppendConditionText(aCssText
);
873 GroupRule::AppendRulesToCssText(aCssText
);
878 MediaRule::SetCssText(const nsAString
& aCssText
)
880 return NS_ERROR_NOT_IMPLEMENTED
;
884 MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
886 return GroupRule::GetParentStyleSheet(aSheet
);
890 MediaRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
892 return GroupRule::GetParentRule(aParentRule
);
896 MediaRule::GetCSSRule()
898 return Rule::GetCSSRule();
901 // nsIDOMCSSGroupingRule methods
903 MediaRule::GetCssRules(nsIDOMCSSRuleList
* *aRuleList
)
905 return GroupRule::GetCssRules(aRuleList
);
909 MediaRule::InsertRule(const nsAString
& aRule
, uint32_t aIndex
, uint32_t* _retval
)
911 return GroupRule::InsertRule(aRule
, aIndex
, _retval
);
915 MediaRule::DeleteRule(uint32_t aIndex
)
917 return GroupRule::DeleteRule(aIndex
);
920 // nsIDOMCSSConditionRule methods
922 MediaRule::GetConditionText(nsAString
& aConditionText
)
924 aConditionText
.Truncate(0);
925 AppendConditionText(aConditionText
);
930 MediaRule::SetConditionText(const nsAString
& aConditionText
)
933 nsRefPtr
<nsMediaList
> media
= new nsMediaList();
934 media
->SetStyleSheet(GetStyleSheet());
935 nsresult rv
= media
->SetMediaText(aConditionText
);
936 if (NS_SUCCEEDED(rv
)) {
942 return mMedia
->SetMediaText(aConditionText
);
945 // nsIDOMCSSMediaRule methods
947 MediaRule::GetMedia(nsIDOMMediaList
* *aMedia
)
949 NS_ENSURE_ARG_POINTER(aMedia
);
950 NS_IF_ADDREF(*aMedia
= mMedia
);
954 // GroupRule interface
956 MediaRule::UseForPresentation(nsPresContext
* aPresContext
,
957 nsMediaQueryResultCacheKey
& aKey
)
960 return mMedia
->Matches(aPresContext
, &aKey
);
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
979 MediaRule::AppendConditionText(nsAString
& aOutput
)
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
)
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
)
1019 DocumentRule::List(FILE* out
, int32_t aIndent
) const
1021 nsAutoCString indentStr
;
1022 for (int32_t indent
= aIndent
; --indent
>= 0; ) {
1023 indentStr
.AppendLiteral(" ");
1027 str
.AppendLiteral("@-moz-document ");
1028 for (URL
*url
= mURLs
; url
; url
= url
->next
) {
1029 switch (url
->func
) {
1031 str
.AppendLiteral("url(\"");
1034 str
.AppendLiteral("url-prefix(\"");
1037 str
.AppendLiteral("domain(\"");
1040 str
.AppendLiteral("regexp(\"");
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());
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
1072 DocumentRule::GetType(uint16_t* aType
)
1074 // XXX What should really happen here?
1075 *aType
= nsIDOMCSSRule::UNKNOWN_RULE
;
1080 DocumentRule::GetCssText(nsAString
& aCssText
)
1082 aCssText
.AssignLiteral("@-moz-document ");
1083 AppendConditionText(aCssText
);
1084 GroupRule::AppendRulesToCssText(aCssText
);
1089 DocumentRule::SetCssText(const nsAString
& aCssText
)
1091 return NS_ERROR_NOT_IMPLEMENTED
;
1095 DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
1097 return GroupRule::GetParentStyleSheet(aSheet
);
1101 DocumentRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
1103 return GroupRule::GetParentRule(aParentRule
);
1107 DocumentRule::GetCSSRule()
1109 return Rule::GetCSSRule();
1112 // nsIDOMCSSGroupingRule methods
1114 DocumentRule::GetCssRules(nsIDOMCSSRuleList
* *aRuleList
)
1116 return GroupRule::GetCssRules(aRuleList
);
1120 DocumentRule::InsertRule(const nsAString
& aRule
, uint32_t aIndex
, uint32_t* _retval
)
1122 return GroupRule::InsertRule(aRule
, aIndex
, _retval
);
1126 DocumentRule::DeleteRule(uint32_t aIndex
)
1128 return GroupRule::DeleteRule(aIndex
);
1131 // nsIDOMCSSConditionRule methods
1133 DocumentRule::GetConditionText(nsAString
& aConditionText
)
1135 aConditionText
.Truncate(0);
1136 AppendConditionText(aConditionText
);
1141 DocumentRule::SetConditionText(const nsAString
& aConditionText
)
1143 return NS_ERROR_NOT_IMPLEMENTED
;
1146 // GroupRule interface
1148 DocumentRule::UseForPresentation(nsPresContext
* aPresContext
,
1149 nsMediaQueryResultCacheKey
& aKey
)
1151 nsIDocument
*doc
= aPresContext
->Document();
1152 nsIURI
*docURI
= doc
->GetDocumentURI();
1153 nsAutoCString docURISpec
;
1155 docURI
->GetSpec(docURISpec
);
1157 for (URL
*url
= mURLs
; url
; url
= url
->next
) {
1158 switch (url
->func
) {
1160 if (docURISpec
== url
->url
)
1164 if (StringBeginsWith(docURISpec
, url
->url
))
1170 docURI
->GetHost(host
);
1171 int32_t lenDiff
= host
.Length() - url
->url
.Length();
1173 if (host
== url
->url
)
1176 if (StringEndsWith(host
, url
->url
) &&
1177 host
.CharAt(lenDiff
- 1) == '.')
1182 NS_ConvertUTF8toUTF16
spec(docURISpec
);
1183 NS_ConvertUTF8toUTF16
regex(url
->url
);
1184 if (nsContentUtils::IsPatternMatching(spec
, regex
, doc
)) {
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
1213 DocumentRule::AppendConditionText(nsAString
& aCssText
)
1215 for (URL
*url
= mURLs
; url
; url
= url
->next
) {
1216 switch (url
->func
) {
1218 aCssText
.AppendLiteral("url(");
1221 aCssText
.AppendLiteral("url-prefix(");
1224 aCssText
.AppendLiteral("domain(");
1227 aCssText
.AppendLiteral("regexp(");
1230 nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(url
->url
),
1232 aCssText
.AppendLiteral("), ");
1234 aCssText
.Truncate(aCssText
.Length() - 2); // remove last ", "
1237 // -------------------------------------------
1241 NameSpaceRule::NameSpaceRule(nsIAtom
* aPrefix
, const nsString
& aURLSpec
,
1242 uint32_t aLineNumber
, uint32_t aColumnNumber
)
1243 : Rule(aLineNumber
, aColumnNumber
),
1249 NameSpaceRule::NameSpaceRule(const NameSpaceRule
& 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;
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
)
1281 NameSpaceRule::List(FILE* out
, int32_t aIndent
) const
1284 for (int32_t indent
= aIndent
; --indent
>= 0; ) {
1285 str
.AppendLiteral(" ");
1288 nsAutoString buffer
;
1290 str
.AppendLiteral("@namespace ");
1293 mPrefix
->ToString(buffer
);
1294 AppendUTF16toUTF8(buffer
, str
);
1298 str
.AppendLiteral("url(\"");
1299 AppendUTF16toUTF8(mURLSpec
, str
);
1300 str
.AppendLiteral("\")\n");
1301 fprintf_stderr(out
, "%s", str
.get());
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();
1319 NameSpaceRule::GetType(uint16_t* aType
)
1321 *aType
= nsIDOMCSSRule::NAMESPACE_RULE
;
1326 NameSpaceRule::GetCssText(nsAString
& aCssText
)
1328 aCssText
.AssignLiteral("@namespace ");
1330 aCssText
.Append(nsDependentAtomString(mPrefix
) + NS_LITERAL_STRING(" "));
1332 aCssText
.AppendLiteral("url(");
1333 nsStyleUtil::AppendEscapedCSSString(mURLSpec
, aCssText
);
1334 aCssText
.AppendLiteral(");");
1339 NameSpaceRule::SetCssText(const nsAString
& aCssText
)
1341 return NS_ERROR_NOT_IMPLEMENTED
;
1345 NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
1347 return Rule::GetParentStyleSheet(aSheet
);
1351 NameSpaceRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
1353 return Rule::GetParentRule(aParentRule
);
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
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
1390 CSSFontFaceDescriptors::Get(nsCSSFontDesc aFontDescID
) const
1392 MOZ_ASSERT(aFontDescID
> eCSSFontDesc_UNKNOWN
&&
1393 aFontDescID
< eCSSFontDesc_COUNT
);
1394 return this->*CSSFontFaceDescriptors::Fields
[aFontDescID
];
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
);
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
1425 nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID
,
1426 nsAString
& aResult
) const
1428 NS_ENSURE_ARG_RANGE(aFontDescID
, eCSSFontDesc_UNKNOWN
,
1429 eCSSFontDesc_COUNT
- 1);
1432 if (aFontDescID
== eCSSFontDesc_UNKNOWN
)
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.
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
);
1453 case eCSSFontDesc_Style
:
1454 val
.AppendToString(eCSSProperty_font_style
, aResult
,
1455 nsCSSValue::eNormalized
);
1458 case eCSSFontDesc_Weight
:
1459 val
.AppendToString(eCSSProperty_font_weight
, aResult
,
1460 nsCSSValue::eNormalized
);
1463 case eCSSFontDesc_Stretch
:
1464 val
.AppendToString(eCSSProperty_font_stretch
, aResult
,
1465 nsCSSValue::eNormalized
);
1468 case eCSSFontDesc_FontFeatureSettings
:
1469 nsStyleUtil::AppendFontFeatureSettings(val
, aResult
);
1472 case eCSSFontDesc_FontLanguageOverride
:
1473 val
.AppendToString(eCSSProperty_font_language_override
, aResult
,
1474 nsCSSValue::eNormalized
);
1477 case eCSSFontDesc_Src
:
1478 nsStyleUtil::AppendSerializedFontSrc(val
, aResult
);
1481 case eCSSFontDesc_UnicodeRange
:
1482 nsStyleUtil::AppendUnicodeRange(val
, aResult
);
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;
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");
1520 nsCSSFontFaceStyleDecl::SetCssText(const nsAString
& aCssText
)
1522 return NS_ERROR_NOT_IMPLEMENTED
; // bug 443978
1525 // DOMString getPropertyValue (in DOMString propertyName);
1527 nsCSSFontFaceStyleDecl::GetPropertyValue(const nsAString
& propertyName
,
1528 nsAString
& aResult
)
1530 return GetPropertyValue(nsCSSProps::LookupFontDesc(propertyName
), aResult
);
1534 nsCSSFontFaceStyleDecl::GetAuthoredPropertyValue(const nsAString
& propertyName
,
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
,
1547 // ??? nsDOMCSSDeclaration returns null/NS_OK, but that seems wrong.
1548 aRv
.Throw(NS_ERROR_NOT_IMPLEMENTED
);
1552 // DOMString removeProperty (in DOMString propertyName) raises (DOMException);
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
) {
1565 nsresult rv
= GetPropertyValue(descID
, aResult
);
1566 NS_ENSURE_SUCCESS(rv
, rv
);
1567 mDescriptors
.Get(descID
).Reset();
1572 // DOMString getPropertyPriority (in DOMString propertyName);
1574 nsCSSFontFaceStyleDecl::GetPropertyPriority(const nsAString
& propertyName
,
1575 nsAString
& aResult
)
1577 // font descriptors do not have priorities at present
1582 // void setProperty (in DOMString propertyName, in DOMString value,
1583 // in DOMString priority) raises (DOMException);
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;
1594 nsCSSFontFaceStyleDecl::GetLength(uint32_t *aLength
)
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
)
1607 // DOMString item (in unsigned long index);
1609 nsCSSFontFaceStyleDecl::Item(uint32_t aIndex
, nsAString
& aReturn
)
1612 IndexedGetter(aIndex
, found
, aReturn
);
1620 nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index
, bool& aFound
, nsAString
& aResult
)
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
) {
1628 if (nset
== int32_t(index
)) {
1630 aResult
.AssignASCII(nsCSSProps::GetStringValue(id
).get());
1638 // readonly attribute nsIDOMCSSRule parentRule;
1640 nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule
** aParentRule
)
1642 NS_IF_ADDREF(*aParentRule
= ContainingRule()->GetDOMRule());
1647 nsCSSFontFaceStyleDecl::GetPropertyValue(const nsCSSProperty aPropID
,
1651 GetPropertyValue(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID
)),
1656 nsCSSFontFaceStyleDecl::SetPropertyValue(const nsCSSProperty aPropID
,
1657 const nsAString
& aValue
)
1659 return SetProperty(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID
)),
1660 aValue
, EmptyString());
1664 nsCSSFontFaceStyleDecl::GetParentObject()
1666 return ContainingRule()->GetDocument();
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
)
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(" ");
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());
1752 /* virtual */ int32_t
1753 nsCSSFontFaceRule::GetType() const
1755 return Rule::FONT_FACE_RULE
;
1759 nsCSSFontFaceRule::GetType(uint16_t* aType
)
1761 *aType
= nsIDOMCSSRule::FONT_FACE_RULE
;
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('}');
1778 nsCSSFontFaceRule::SetCssText(const nsAString
& aCssText
)
1780 return NS_ERROR_NOT_IMPLEMENTED
; // bug 443978
1784 nsCSSFontFaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
1786 return Rule::GetParentStyleSheet(aSheet
);
1790 nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
1792 return Rule::GetParentRule(aParentRule
);
1796 nsCSSFontFaceRule::GetCSSRule()
1798 return Rule::GetCSSRule();
1802 nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration
** aStyle
)
1804 NS_IF_ADDREF(*aStyle
= &mDecl
);
1808 // Arguably these should forward to nsCSSFontFaceStyleDecl methods.
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
;
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
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
)
1868 FeatureValuesToString(
1869 const nsTArray
<gfxFontFeatureValueSet::FeatureValues
>& aFeatureValues
,
1875 n
= aFeatureValues
.Length();
1876 for (i
= 0; i
< n
; i
++) {
1877 const gfxFontFeatureValueSet::FeatureValues
& fv
= aFeatureValues
[i
];
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");
1907 FontFeatureValuesRuleToString(
1908 const mozilla::FontFamilyList
& aFamilyList
,
1909 const nsTArray
<gfxFontFeatureValueSet::FeatureValues
>& aFeatureValues
,
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('}');
1924 nsCSSFontFeatureValuesRule::List(FILE* out
, int32_t aIndent
) const
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];
1933 for (i
= 1; i
< (aIndent
+ 1) * 2 - 1; i
++) {
1937 indent
[aIndent
* 2 + 1] = 0;
1938 utf8
.ReplaceSubstring("\n", indent
);
1941 nsAutoCString indentStr
;
1942 for (i
= aIndent
; --i
>= 0; ) {
1943 indentStr
.AppendLiteral(" ");
1945 fprintf_stderr(out
, "%s%s\n", indentStr
.get(), utf8
.get());
1949 /* virtual */ int32_t
1950 nsCSSFontFeatureValuesRule::GetType() const
1952 return Rule::FONT_FEATURE_VALUES_RULE
;
1956 nsCSSFontFeatureValuesRule::GetType(uint16_t* aType
)
1958 *aType
= nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE
;
1963 nsCSSFontFeatureValuesRule::GetCssText(nsAString
& aCssText
)
1965 FontFeatureValuesRuleToString(mFamilyList
, mFeatureValues
, aCssText
);
1970 nsCSSFontFeatureValuesRule::SetCssText(const nsAString
& aCssText
)
1972 // FIXME: implement???
1973 return NS_ERROR_NOT_IMPLEMENTED
;
1977 nsCSSFontFeatureValuesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
1979 return Rule::GetParentStyleSheet(aSheet
);
1983 nsCSSFontFeatureValuesRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
1985 return Rule::GetParentRule(aParentRule
);
1989 nsCSSFontFeatureValuesRule::GetCSSRule()
1991 return Rule::GetCSSRule();
1995 nsCSSFontFeatureValuesRule::GetFontFamily(nsAString
& aFamilyListStr
)
1997 nsStyleUtil::AppendEscapedCSSFontFamilyList(mFamilyList
, aFamilyListStr
);
2002 nsCSSFontFeatureValuesRule::SetFontFamily(const nsAString
& aFontFamily
)
2004 return NS_ERROR_NOT_IMPLEMENTED
;
2008 nsCSSFontFeatureValuesRule::GetValueText(nsAString
& aValueText
)
2010 FeatureValuesToString(mFeatureValues
, aValueText
);
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)
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
);
2033 familyArr
->hasGeneric
= true;
2038 nsTArray
<nsString
>& familyArray
;
2043 nsCSSFontFeatureValuesRule::SetFamilyList(
2044 const mozilla::FontFamilyList
& aFamilyList
)
2046 mFamilyList
= aFamilyList
;
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;
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
);
2076 nsCSSFontFeatureValuesRule::SizeOfIncludingThis(
2077 MallocSizeOf aMallocSizeOf
) const
2079 return aMallocSizeOf(this);
2082 // -------------------------------------------
2083 // nsCSSKeyframeStyleDeclaration
2086 nsCSSKeyframeStyleDeclaration::nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule
*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
)
2106 nsCSSKeyframeStyleDeclaration::GetCSSDeclaration(bool aAllocate
)
2109 return mRule
->Declaration();
2116 nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment
& aCSSParseEnv
)
2118 GetCSSParsingEnvironmentForRule(mRule
, aCSSParseEnv
);
2122 nsCSSKeyframeStyleDeclaration::GetParentRule(nsIDOMCSSRule
**aParent
)
2124 NS_ENSURE_ARG_POINTER(aParent
);
2126 NS_IF_ADDREF(*aParent
= mRule
);
2131 nsCSSKeyframeStyleDeclaration::SetCSSDeclaration(css::Declaration
* aDecl
)
2133 NS_ABORT_IF_FALSE(aDecl
, "must be non-null");
2134 mRule
->ChangeDeclaration(aDecl
);
2139 nsCSSKeyframeStyleDeclaration::DocToUpdate()
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
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
)
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
);
2218 nsCSSKeyframeRule::List(FILE* out
, int32_t aIndent
) const
2221 for (int32_t index
= aIndent
; --index
>= 0; ) {
2222 str
.AppendLiteral(" ");
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());
2236 /* virtual */ int32_t
2237 nsCSSKeyframeRule::GetType() const
2239 return Rule::KEYFRAME_RULE
;
2243 nsCSSKeyframeRule::GetType(uint16_t* aType
)
2245 *aType
= nsIDOMCSSRule::KEYFRAME_RULE
;
2250 nsCSSKeyframeRule::GetCssText(nsAString
& aCssText
)
2252 DoGetKeyText(aCssText
);
2253 aCssText
.AppendLiteral(" { ");
2255 mDeclaration
->ToString(tmp
);
2256 aCssText
.Append(tmp
);
2257 aCssText
.AppendLiteral(" }");
2262 nsCSSKeyframeRule::SetCssText(const nsAString
& aCssText
)
2264 // FIXME: implement???
2265 return NS_ERROR_NOT_IMPLEMENTED
;
2269 nsCSSKeyframeRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
2271 return Rule::GetParentStyleSheet(aSheet
);
2275 nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
2277 return Rule::GetParentRule(aParentRule
);
2281 nsCSSKeyframeRule::GetCSSRule()
2283 return Rule::GetCSSRule();
2287 nsCSSKeyframeRule::GetKeyText(nsAString
& aKeyText
)
2289 DoGetKeyText(aKeyText
);
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");
2300 aKeyText
.AppendFloat(mKeys
[i
] * 100.0f
);
2301 aKeyText
.Append(char16_t('%'));
2305 aKeyText
.AppendLiteral(", ");
2310 nsCSSKeyframeRule::SetKeyText(const nsAString
& aKeyText
)
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
2321 nsIDocument
* doc
= GetDocument();
2322 MOZ_AUTO_DOC_UPDATE(doc
, UPDATE_STYLE
, true);
2324 newSelectors
.SwapElements(mKeys
);
2326 CSSStyleSheet
* sheet
= GetStyleSheet();
2328 sheet
->SetModifiedByChildRule();
2331 doc
->StyleRuleChanged(sheet
, this, this);
2339 nsCSSKeyframeRule::GetStyle(nsIDOMCSSStyleDeclaration
** aStyle
)
2341 if (!mDOMDeclaration
) {
2342 mDOMDeclaration
= new nsCSSKeyframeStyleDeclaration(this);
2344 NS_ADDREF(*aStyle
= mDOMDeclaration
);
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();
2365 sheet
->SetModifiedByChildRule();
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
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
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
)
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());
2440 /* virtual */ int32_t
2441 nsCSSKeyframesRule::GetType() const
2443 return Rule::KEYFRAMES_RULE
;
2447 nsCSSKeyframesRule::GetType(uint16_t* aType
)
2449 *aType
= nsIDOMCSSRule::KEYFRAMES_RULE
;
2454 nsCSSKeyframesRule::GetCssText(nsAString
& aCssText
)
2456 aCssText
.AssignLiteral("@keyframes ");
2457 aCssText
.Append(mName
);
2458 aCssText
.AppendLiteral(" {\n");
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('}');
2470 nsCSSKeyframesRule::SetCssText(const nsAString
& aCssText
)
2472 // FIXME: implement???
2473 return NS_ERROR_NOT_IMPLEMENTED
;
2477 nsCSSKeyframesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
2479 return GroupRule::GetParentStyleSheet(aSheet
);
2483 nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
2485 return GroupRule::GetParentRule(aParentRule
);
2489 nsCSSKeyframesRule::GetCSSRule()
2491 return GroupRule::GetCSSRule();
2495 nsCSSKeyframesRule::GetName(nsAString
& aName
)
2502 nsCSSKeyframesRule::SetName(const nsAString
& aName
)
2504 if (mName
== aName
) {
2508 nsIDocument
* doc
= GetDocument();
2509 MOZ_AUTO_DOC_UPDATE(doc
, UPDATE_STYLE
, true);
2513 CSSStyleSheet
* sheet
= GetStyleSheet();
2515 sheet
->SetModifiedByChildRule();
2518 doc
->StyleRuleChanged(sheet
, this, this);
2526 nsCSSKeyframesRule::GetCssRules(nsIDOMCSSRuleList
* *aRuleList
)
2528 return GroupRule::GetCssRules(aRuleList
);
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
2539 // FIXME: pass filename and line number
2540 nsRefPtr
<nsCSSKeyframeRule
> rule
=
2541 parser
.ParseKeyframeRule(aRule
, nullptr, 0);
2543 nsIDocument
* doc
= GetDocument();
2544 MOZ_AUTO_DOC_UPDATE(doc
, UPDATE_STYLE
, true);
2546 AppendStyleRule(rule
);
2548 CSSStyleSheet
* sheet
= GetStyleSheet();
2550 sheet
->SetModifiedByChildRule();
2553 doc
->StyleRuleChanged(sheet
, this, this);
2561 static const uint32_t RULE_NOT_FOUND
= uint32_t(-1);
2564 nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString
& aKey
)
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
) {
2583 return RULE_NOT_FOUND
;
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();
2598 sheet
->SetModifiedByChildRule();
2601 doc
->StyleRuleChanged(sheet
, this, this);
2609 nsCSSKeyframesRule::FindRule(const nsAString
& aKey
,
2610 nsIDOMMozCSSKeyframeRule
** aResult
)
2612 uint32_t index
= FindRuleIndexForKey(aKey
);
2613 if (index
== RULE_NOT_FOUND
) {
2616 NS_ADDREF(*aResult
= static_cast<nsCSSKeyframeRule
*>(mRules
[index
]));
2621 // GroupRule interface
2623 nsCSSKeyframesRule::UseForPresentation(nsPresContext
* aPresContext
,
2624 nsMediaQueryResultCacheKey
& aKey
)
2626 NS_ABORT_IF_FALSE(false, "should not be called");
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
2643 // -------------------------------------------
2644 // nsCSSPageStyleDeclaration
2647 nsCSSPageStyleDeclaration::nsCSSPageStyleDeclaration(nsCSSPageRule
* 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
)
2667 nsCSSPageStyleDeclaration::GetCSSDeclaration(bool aAllocate
)
2670 return mRule
->Declaration();
2677 nsCSSPageStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment
& aCSSParseEnv
)
2679 GetCSSParsingEnvironmentForRule(mRule
, aCSSParseEnv
);
2683 nsCSSPageStyleDeclaration::GetParentRule(nsIDOMCSSRule
** aParent
)
2685 NS_ENSURE_ARG_POINTER(aParent
);
2687 NS_IF_ADDREF(*aParent
= mRule
);
2692 nsCSSPageStyleDeclaration::SetCSSDeclaration(css::Declaration
* aDecl
)
2694 NS_ABORT_IF_FALSE(aDecl
, "must be non-null");
2695 mRule
->ChangeDeclaration(aDecl
);
2700 nsCSSPageStyleDeclaration::DocToUpdate()
2706 nsCSSPageStyleDeclaration::GetParentObject()
2708 return mRule
? mRule
->GetDocument() : nullptr;
2711 // -------------------------------------------
2715 nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule
& aCopy
)
2716 // copy everything except our reference count and mDOMDeclaration
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
)
2764 nsCSSPageRule::List(FILE* out
, int32_t aIndent
) const
2767 for (int32_t indent
= aIndent
; --indent
>= 0; ) {
2768 str
.AppendLiteral(" ");
2771 str
.AppendLiteral("@page { ");
2773 mDeclaration
->ToString(tmp
);
2774 AppendUTF16toUTF8(tmp
, str
);
2775 str
.AppendLiteral("}\n");
2776 fprintf_stderr(out
, "%s", str
.get());
2780 /* virtual */ int32_t
2781 nsCSSPageRule::GetType() const
2783 return Rule::PAGE_RULE
;
2787 nsCSSPageRule::GetType(uint16_t* aType
)
2789 *aType
= nsIDOMCSSRule::PAGE_RULE
;
2794 nsCSSPageRule::GetCssText(nsAString
& aCssText
)
2796 aCssText
.AppendLiteral("@page { ");
2798 mDeclaration
->ToString(tmp
);
2799 aCssText
.Append(tmp
);
2800 aCssText
.AppendLiteral(" }");
2805 nsCSSPageRule::SetCssText(const nsAString
& aCssText
)
2807 // FIXME: implement???
2808 return NS_ERROR_NOT_IMPLEMENTED
;
2812 nsCSSPageRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
2814 return Rule::GetParentStyleSheet(aSheet
);
2818 nsCSSPageRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
2820 return Rule::GetParentRule(aParentRule
);
2824 nsCSSPageRule::GetCSSRule()
2826 return Rule::GetCSSRule();
2830 nsCSSPageRule::GetImportantRule()
2832 if (!mDeclaration
->HasImportantData()) {
2835 if (!mImportantRule
) {
2836 mImportantRule
= new css::ImportantRule(mDeclaration
);
2838 return mImportantRule
;
2842 nsCSSPageRule::MapRuleInfoInto(nsRuleData
* aRuleData
)
2844 mDeclaration
->MapNormalRuleInfoInto(aRuleData
);
2848 nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration
** aStyle
)
2850 if (!mDOMDeclaration
) {
2851 mDOMDeclaration
= new nsCSSPageStyleDeclaration(this);
2853 NS_ADDREF(*aStyle
= mDOMDeclaration
);
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();
2869 sheet
->SetModifiedByChildRule();
2873 /* virtual */ size_t
2874 nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const
2876 return aMallocSizeOf(this);
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
)
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());
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();
2933 CSSSupportsRule::UseForPresentation(nsPresContext
* aPresContext
,
2934 nsMediaQueryResultCacheKey
& aKey
)
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
2955 CSSSupportsRule::GetType(uint16_t* aType
)
2957 *aType
= nsIDOMCSSRule::SUPPORTS_RULE
;
2962 CSSSupportsRule::GetCssText(nsAString
& aCssText
)
2964 aCssText
.AssignLiteral("@supports ");
2965 aCssText
.Append(mCondition
);
2966 css::GroupRule::AppendRulesToCssText(aCssText
);
2971 CSSSupportsRule::SetCssText(const nsAString
& aCssText
)
2973 return NS_ERROR_NOT_IMPLEMENTED
;
2977 CSSSupportsRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
2979 return css::GroupRule::GetParentStyleSheet(aSheet
);
2983 CSSSupportsRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
2985 return css::GroupRule::GetParentRule(aParentRule
);
2989 CSSSupportsRule::GetCSSRule()
2991 return css::GroupRule::GetCSSRule();
2994 // nsIDOMCSSGroupingRule methods
2996 CSSSupportsRule::GetCssRules(nsIDOMCSSRuleList
* *aRuleList
)
2998 return css::GroupRule::GetCssRules(aRuleList
);
3002 CSSSupportsRule::InsertRule(const nsAString
& aRule
, uint32_t aIndex
, uint32_t* _retval
)
3004 return css::GroupRule::InsertRule(aRule
, aIndex
, _retval
);
3008 CSSSupportsRule::DeleteRule(uint32_t aIndex
)
3010 return css::GroupRule::DeleteRule(aIndex
);
3013 // nsIDOMCSSConditionRule methods
3015 CSSSupportsRule::GetConditionText(nsAString
& aConditionText
)
3017 aConditionText
.Assign(mCondition
);
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
);
3036 } // namespace mozilla
3038 // -------------------------------------------
3039 // nsCSSCounterStyleRule
3042 nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule
& 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
)
3086 nsCSSCounterStyleRule::List(FILE* out
, int32_t aIndent
) const
3088 nsCString baseInd
, descInd
;
3089 for (int32_t indent
= aIndent
; --indent
>= 0; ) {
3090 baseInd
.AppendLiteral(" ");
3093 descInd
.AppendLiteral(" ");
3095 fprintf_stderr(out
, "%s@counter-style %s (rev.%u) {\n",
3096 baseInd
.get(), NS_ConvertUTF16toUTF8(mName
).get(),
3099 fprintf_stderr(out
, "%s}\n", baseInd
.get());
3103 /* virtual */ int32_t
3104 nsCSSCounterStyleRule::GetType() const
3106 return Rule::COUNTER_STYLE_RULE
;
3109 // nsIDOMCSSRule methods
3111 nsCSSCounterStyleRule::GetType(uint16_t* aType
)
3113 *aType
= nsIDOMCSSRule::COUNTER_STYLE_RULE
;
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
) {
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("}"));
3141 nsCSSCounterStyleRule::SetCssText(const nsAString
& aCssText
)
3143 // FIXME: implement???
3144 return NS_ERROR_NOT_IMPLEMENTED
;
3148 nsCSSCounterStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
)
3150 return Rule::GetParentStyleSheet(aSheet
);
3154 nsCSSCounterStyleRule::GetParentRule(nsIDOMCSSRule
** aParentRule
)
3156 return Rule::GetParentRule(aParentRule
);
3160 nsCSSCounterStyleRule::GetCSSRule()
3162 return Rule::GetCSSRule();
3165 // nsIDOMCSSCounterStyleRule methods
3167 nsCSSCounterStyleRule::GetName(nsAString
& aName
)
3170 nsStyleUtil::AppendEscapedCSSIdent(mName
, aName
);
3175 nsCSSCounterStyleRule::SetName(const nsAString
& aName
)
3179 if (parser
.ParseCounterStyleName(aName
, nullptr, name
)) {
3180 nsIDocument
* doc
= GetDocument();
3181 MOZ_AUTO_DOC_UPDATE(doc
, UPDATE_STYLE
, true);
3185 CSSStyleSheet
* sheet
= GetStyleSheet();
3187 sheet
->SetModifiedByChildRule();
3189 doc
->StyleRuleChanged(sheet
, this, this);
3197 nsCSSCounterStyleRule::GetSystem() const
3199 const nsCSSValue
& system
= GetDesc(eCSSCounterDesc_System
);
3200 switch (system
.GetUnit()) {
3201 case eCSSUnit_Enumerated
:
3202 return system
.GetIntValue();
3204 return system
.GetPairValue().mXValue
.GetIntValue();
3206 return NS_STYLE_COUNTER_SYSTEM_SYMBOLIC
;
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
;
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
;
3231 CSSStyleSheet
* sheet
= GetStyleSheet();
3233 sheet
->SetModifiedByChildRule();
3235 doc
->StyleRuleChanged(sheet
, this, this);
3241 nsCSSCounterStyleRule::GetSystem(nsAString
& aSystem
)
3243 const nsCSSValue
& value
= GetDesc(eCSSCounterDesc_System
);
3244 if (value
.GetUnit() == eCSSUnit_Null
) {
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
);
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
,
3270 nsCSSValue::eNormalized
);
3272 aSymbols
.Append(' ');
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
);
3294 aSymbols
.AppendLiteral(", ");
3302 nsCSSCounterStyleRule::GetRange(nsAString
& aRange
)
3304 const nsCSSValue
& value
= GetDesc(eCSSCounterDesc_Range
);
3306 switch (value
.GetUnit()) {
3308 aRange
.AssignLiteral(MOZ_UTF16("auto"));
3311 case eCSSUnit_PairList
:
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");
3323 aRange
.AppendInt(lower
.GetIntValue());
3326 if (upper
.GetUnit() == eCSSUnit_Enumerated
) {
3327 NS_ASSERTION(upper
.GetIntValue() ==
3328 NS_STYLE_COUNTER_RANGE_INFINITE
,
3329 "Unrecognized keyword");
3330 aRange
.AppendLiteral("infinite");
3332 aRange
.AppendInt(upper
.GetIntValue());
3335 aRange
.AppendLiteral(", ");
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"));
3357 case NS_STYLE_COUNTER_SPEAKAS_NUMBERS
:
3358 aSpeakAs
.AssignLiteral(MOZ_UTF16("numbers"));
3360 case NS_STYLE_COUNTER_SPEAKAS_WORDS
:
3361 aSpeakAs
.AssignLiteral(MOZ_UTF16("words"));
3363 case NS_STYLE_COUNTER_SPEAKAS_SPELL_OUT
:
3364 aSpeakAs
.AssignLiteral(MOZ_UTF16("spell-out"));
3367 NS_NOTREACHED("Unknown speech synthesis");
3372 case eCSSUnit_Ident
:
3373 aSpeakAs
.Truncate();
3374 value
.AppendToString(eCSSProperty_UNKNOWN
,
3375 aSpeakAs
, nsCSSValue::eNormalized
);
3379 aSpeakAs
.Truncate();
3385 nsCSSCounterStyleRule::GetDescriptor(nsCSSCounterDesc aDescID
,
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
);
3396 if (value
.GetUnit() != eCSSUnit_Null
) {
3397 value
.AppendToString(
3398 eCSSProperty_UNKNOWN
, aValue
, nsCSSValue::eNormalized
);
3403 #define CSS_COUNTER_DESC_GETTER(name_) \
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
3417 nsCSSCounterStyleRule::CheckDescValue(int32_t aSystem
,
3418 nsCSSCounterDesc aDescID
,
3419 const nsCSSValue
& aValue
)
3422 case eCSSCounterDesc_System
:
3423 if (aValue
.GetUnit() != eCSSUnit_Pair
) {
3424 return aValue
.GetIntValue() == aSystem
;
3426 return aValue
.GetPairValue().mXValue
.GetIntValue() == aSystem
;
3429 case eCSSCounterDesc_Symbols
:
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
3442 case eCSSCounterDesc_AdditiveSymbols
:
3444 case NS_STYLE_COUNTER_SYSTEM_EXTENDS
:
3456 nsCSSCounterStyleRule::SetDescriptor(nsCSSCounterDesc aDescID
,
3457 const nsAString
& aValue
)
3461 CSSStyleSheet
* sheet
= GetStyleSheet();
3462 nsIURI
* baseURL
= nullptr;
3463 nsIPrincipal
* principal
= nullptr;
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
);
3477 #define CSS_COUNTER_DESC_SETTER(name_) \
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);