1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * style sheet and style rule processor representing style attributes
11 #include "nsHTMLCSSStyleSheet.h"
12 #include "mozilla/MemoryReporting.h"
13 #include "mozilla/DeclarationBlock.h"
14 #include "nsPresContext.h"
15 #include "mozilla/dom/Element.h"
16 #include "nsAttrValue.h"
17 #include "nsAttrValueInlines.h"
18 #include "nsCSSPseudoElements.h"
19 #include "mozilla/RestyleManager.h"
21 using namespace mozilla
;
22 using namespace mozilla::dom
;
24 nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet() = default;
26 nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet() {
27 // We may go away before all of our cached style attributes do,
28 // so clean up any that are left.
29 for (auto iter
= mCachedStyleAttrs
.Iter(); !iter
.Done(); iter
.Next()) {
30 MiscContainer
*& value
= iter
.Data();
32 // Ideally we'd just call MiscContainer::Evict, but we can't do that since
33 // we're iterating the hashtable.
34 if (value
->mType
== nsAttrValue::eCSSDeclaration
) {
35 DeclarationBlock
* declaration
= value
->mValue
.mCSSDeclaration
;
36 declaration
->SetHTMLCSSStyleSheet(nullptr);
38 MOZ_ASSERT_UNREACHABLE("unexpected cached nsAttrValue type");
41 value
->mValue
.mCached
= 0;
46 void nsHTMLCSSStyleSheet::CacheStyleAttr(const nsAString
& aSerialized
,
47 MiscContainer
* aValue
) {
48 mCachedStyleAttrs
.Put(aSerialized
, aValue
);
51 void nsHTMLCSSStyleSheet::EvictStyleAttr(const nsAString
& aSerialized
,
52 MiscContainer
* aValue
) {
55 NS_ASSERTION(aValue
== mCachedStyleAttrs
.Get(aSerialized
),
56 "Cached value does not match?!");
59 mCachedStyleAttrs
.Remove(aSerialized
);
62 MiscContainer
* nsHTMLCSSStyleSheet::LookupStyleAttr(
63 const nsAString
& aSerialized
) {
64 return mCachedStyleAttrs
.Get(aSerialized
);