ServoDeclarationBlock.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- Mode: C++; tab-width: 2; 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_ServoDeclarationBlock_h
  6. #define mozilla_ServoDeclarationBlock_h
  7. #include "mozilla/ServoBindings.h"
  8. #include "mozilla/DeclarationBlock.h"
  9. namespace mozilla {
  10. class ServoDeclarationBlock final : public DeclarationBlock
  11. {
  12. public:
  13. ServoDeclarationBlock()
  14. : ServoDeclarationBlock(Servo_DeclarationBlock_CreateEmpty().Consume()) {}
  15. ServoDeclarationBlock(const ServoDeclarationBlock& aCopy)
  16. : DeclarationBlock(aCopy)
  17. , mRaw(Servo_DeclarationBlock_Clone(aCopy.mRaw).Consume()) {}
  18. NS_INLINE_DECL_REFCOUNTING(ServoDeclarationBlock)
  19. static already_AddRefed<ServoDeclarationBlock>
  20. FromCssText(const nsAString& aCssText);
  21. RawServoDeclarationBlock* Raw() const { return mRaw; }
  22. RawServoDeclarationBlock* const* RefRaw() const {
  23. static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
  24. sizeof(RawServoDeclarationBlock*),
  25. "RefPtr should just be a pointer");
  26. return reinterpret_cast<RawServoDeclarationBlock* const*>(&mRaw);
  27. }
  28. void ToString(nsAString& aResult) const {
  29. Servo_DeclarationBlock_GetCssText(mRaw, &aResult);
  30. }
  31. uint32_t Count() const {
  32. return Servo_DeclarationBlock_Count(mRaw);
  33. }
  34. bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const {
  35. aReturn.Truncate();
  36. return Servo_DeclarationBlock_GetNthProperty(mRaw, aIndex, &aReturn);
  37. }
  38. void GetPropertyValue(const nsAString& aProperty, nsAString& aValue) const;
  39. void GetPropertyValueByID(nsCSSPropertyID aPropID, nsAString& aValue) const;
  40. void GetAuthoredPropertyValue(const nsAString& aProperty,
  41. nsAString& aValue) const {
  42. GetPropertyValue(aProperty, aValue);
  43. }
  44. bool GetPropertyIsImportant(const nsAString& aProperty) const;
  45. void RemoveProperty(const nsAString& aProperty);
  46. void RemovePropertyByID(nsCSSPropertyID aPropID);
  47. protected:
  48. explicit ServoDeclarationBlock(
  49. already_AddRefed<RawServoDeclarationBlock> aRaw)
  50. : DeclarationBlock(StyleBackendType::Servo), mRaw(aRaw) {}
  51. private:
  52. ~ServoDeclarationBlock() {}
  53. RefPtr<RawServoDeclarationBlock> mRaw;
  54. };
  55. } // namespace mozilla
  56. #endif // mozilla_ServoDeclarationBlock_h