StylePropertyMapReadOnly.h (3165B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef LAYOUT_STYLE_TYPEDOM_STYLEPROPERTYMAPREADONLY_H_ 8 #define LAYOUT_STYLE_TYPEDOM_STYLEPROPERTYMAPREADONLY_H_ 9 10 #include <stdint.h> 11 12 #include "js/TypeDecls.h" 13 #include "mozilla/MemoryReporting.h" 14 #include "mozilla/dom/CSSStyleValueBindingFwd.h" 15 #include "nsCOMPtr.h" 16 #include "nsISupports.h" 17 #include "nsISupportsImpl.h" 18 #include "nsStringFwd.h" 19 #include "nsTArrayForwardDeclare.h" 20 #include "nsWrapperCache.h" 21 22 template <class T> 23 class RefPtr; 24 25 namespace mozilla { 26 27 class ErrorResult; 28 struct StylePropertyTypedValueResult; 29 30 namespace dom { 31 32 class CSSStyleRule; 33 class Element; 34 class OwningUndefinedOrCSSStyleValue; 35 36 class StylePropertyMapReadOnly : public nsISupports, public nsWrapperCache { 37 public: 38 StylePropertyMapReadOnly(Element* aElement, bool aComputed); 39 explicit StylePropertyMapReadOnly(CSSStyleRule* aRule); 40 41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 42 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(StylePropertyMapReadOnly) 43 44 nsISupports* GetParentObject() const; 45 46 JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 47 48 // start of StylePropertyMapReadOnly Web IDL declarations 49 50 // https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get 51 void Get(const nsACString& aProperty, OwningUndefinedOrCSSStyleValue& aRetVal, 52 ErrorResult& aRv) const; 53 54 // https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-getall 55 void GetAll(const nsACString& aProperty, 56 nsTArray<RefPtr<CSSStyleValue>>& aRetVal, ErrorResult& aRv) const; 57 58 bool Has(const nsACString& aProperty, ErrorResult& aRv) const; 59 60 uint32_t Size() const; 61 62 uint32_t GetIterableLength() const; 63 64 const nsACString& GetKeyAtIndex(uint32_t aIndex) const; 65 66 nsTArray<RefPtr<CSSStyleValue>> GetValueAtIndex(uint32_t aIndex) const; 67 68 // end of StylePropertyMapReadOnly Web IDL declarations 69 70 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const; 71 72 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; 73 74 protected: 75 virtual ~StylePropertyMapReadOnly() = default; 76 77 class Declarations { 78 public: 79 enum class Kind : uint8_t { 80 Inline, 81 Computed, 82 Rule, 83 }; 84 Declarations(Element* aElement, bool aComputed) 85 : mElement(aElement), 86 mKind(aComputed ? Kind::Computed : Kind::Inline) {} 87 88 explicit Declarations(CSSStyleRule* aRule) 89 : mRule(aRule), mKind(Kind::Rule) {} 90 91 StylePropertyTypedValueResult Get(const nsACString& aProperty, 92 ErrorResult& aRv) const; 93 94 void Unlink(); 95 96 private: 97 union { 98 Element* mElement; 99 CSSStyleRule* mRule; 100 }; 101 const Kind mKind; 102 }; 103 104 nsCOMPtr<nsISupports> mParent; 105 Declarations mDeclarations; 106 }; 107 108 } // namespace dom 109 } // namespace mozilla 110 111 #endif // LAYOUT_STYLE_TYPEDOM_STYLEPROPERTYMAPREADONLY_H_