ServoStyleSheet.h 2.7 KB

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