Bug 1684463 - [devtools] Part 1: Shorten the _createAttribute function by refactoring...
[gecko.git] / layout / style / nsHTMLCSSStyleSheet.cpp
blobbd034a735b860265300f4ebb79f13985df137834
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/. */
7 /*
8 * style sheet and style rule processor representing style attributes
9 */
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);
37 } else {
38 MOZ_ASSERT_UNREACHABLE("unexpected cached nsAttrValue type");
41 value->mValue.mCached = 0;
42 iter.Remove();
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) {
53 #ifdef DEBUG
55 NS_ASSERTION(aValue == mCachedStyleAttrs.Get(aSerialized),
56 "Cached value does not match?!");
58 #endif
59 mCachedStyleAttrs.Remove(aSerialized);
62 MiscContainer* nsHTMLCSSStyleSheet::LookupStyleAttr(
63 const nsAString& aSerialized) {
64 return mCachedStyleAttrs.Get(aSerialized);