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 mozilla_ServoStyleSheet_h 8 #define mozilla_ServoStyleSheet_h 9 10 #include "mozilla/dom/SRIMetadata.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/ServoBindingTypes.h" 13 #include "mozilla/StyleSheet.h" 14 #include "mozilla/StyleSheetInfo.h" 15 #include "nsStringFwd.h" 16 17 namespace mozilla { 18 19 /** 20 * CSS style sheet object that is a wrapper for a Servo Stylesheet. 21 */ 22 class ServoStyleSheet : public StyleSheet 23 { 24 public: 25 ServoStyleSheet(css::SheetParsingMode aParsingMode, 26 CORSMode aCORSMode, 27 net::ReferrerPolicy aReferrerPolicy, 28 const dom::SRIMetadata& aIntegrity); 29 30 bool HasRules() const; 31 32 void SetOwningDocument(nsIDocument* aDocument); 33 34 ServoStyleSheet* GetParentSheet() const; 35 void AppendStyleSheet(ServoStyleSheet* aSheet); 36 37 MOZ_MUST_USE nsresult ParseSheet(const nsAString& aInput, 38 nsIURI* aSheetURI, 39 nsIURI* aBaseURI, 40 nsIPrincipal* aSheetPrincipal, 41 uint32_t aLineNumber); 42 43 /** 44 * Called instead of ParseSheet to initialize the Servo stylesheet object 45 * for a failed load. Either ParseSheet or LoadFailed must be called before 46 * adding a ServoStyleSheet to a ServoStyleSet. 47 */ 48 void LoadFailed(); 49 50 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; 51 52 #ifdef DEBUG 53 void List(FILE* aOut = stdout, int32_t aIndex = 0) const; 54 #endif 55 RawSheet()56 RawServoStyleSheet* RawSheet() const { return mSheet; } 57 58 // WebIDL StyleSheet API 59 nsMediaList* Media() final; 60 61 // WebIDL CSSStyleSheet API 62 // Can't be inline because we can't include ImportRule here. And can't be 63 // called GetOwnerRule because that would be ambiguous with the ImportRule 64 // version. 65 nsIDOMCSSRule* GetDOMOwnerRule() const final; 66 WillDirty()67 void WillDirty() {} DidDirty()68 void DidDirty() {} 69 70 protected: 71 virtual ~ServoStyleSheet(); 72 73 // Internal methods which do not have security check and completeness check. 74 dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv); 75 uint32_t InsertRuleInternal(const nsAString& aRule, 76 uint32_t aIndex, ErrorResult& aRv); 77 void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv); 78 79 private: 80 void DropSheet(); 81 82 RefPtr<RawServoStyleSheet> mSheet; 83 StyleSheetInfo mSheetInfo; 84 85 friend class StyleSheet; 86 }; 87 88 } // namespace mozilla 89 90 #endif // mozilla_ServoStyleSheet_h 91