Line data Source code
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 :
6 : #ifndef mozilla_ServoDeclarationBlock_h
7 : #define mozilla_ServoDeclarationBlock_h
8 :
9 : #include "mozilla/ServoBindings.h"
10 : #include "mozilla/DeclarationBlock.h"
11 :
12 : namespace mozilla {
13 :
14 : class ServoDeclarationBlock final : public DeclarationBlock
15 : {
16 : public:
17 0 : explicit ServoDeclarationBlock(
18 : already_AddRefed<RawServoDeclarationBlock> aRaw)
19 0 : : DeclarationBlock(StyleBackendType::Servo), mRaw(aRaw) {}
20 :
21 0 : ServoDeclarationBlock()
22 0 : : ServoDeclarationBlock(Servo_DeclarationBlock_CreateEmpty().Consume()) {}
23 :
24 0 : ServoDeclarationBlock(const ServoDeclarationBlock& aCopy)
25 0 : : DeclarationBlock(aCopy)
26 0 : , mRaw(Servo_DeclarationBlock_Clone(aCopy.mRaw).Consume()) {}
27 :
28 0 : NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ServoDeclarationBlock)
29 :
30 : static already_AddRefed<ServoDeclarationBlock>
31 : FromCssText(const nsAString& aCssText, URLExtraData* aExtraData,
32 : nsCompatibility aMode, css::Loader* aLoader);
33 :
34 0 : RawServoDeclarationBlock* Raw() const { return mRaw; }
35 : RawServoDeclarationBlock* const* RefRaw() const {
36 : static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
37 : sizeof(RawServoDeclarationBlock*),
38 : "RefPtr should just be a pointer");
39 : return reinterpret_cast<RawServoDeclarationBlock* const*>(&mRaw);
40 : }
41 :
42 0 : const RawServoDeclarationBlockStrong* RefRawStrong() const
43 : {
44 : static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
45 : sizeof(RawServoDeclarationBlock*),
46 : "RefPtr should just be a pointer");
47 : static_assert(sizeof(RefPtr<RawServoDeclarationBlock>) ==
48 : sizeof(RawServoDeclarationBlockStrong),
49 : "RawServoDeclarationBlockStrong should be the same as RefPtr");
50 0 : return reinterpret_cast<const RawServoDeclarationBlockStrong*>(&mRaw);
51 : }
52 :
53 0 : void ToString(nsAString& aResult) const {
54 0 : Servo_DeclarationBlock_GetCssText(mRaw, &aResult);
55 0 : }
56 :
57 0 : uint32_t Count() const {
58 0 : return Servo_DeclarationBlock_Count(mRaw);
59 : }
60 0 : bool GetNthProperty(uint32_t aIndex, nsAString& aReturn) const {
61 0 : aReturn.Truncate();
62 0 : return Servo_DeclarationBlock_GetNthProperty(mRaw, aIndex, &aReturn);
63 : }
64 :
65 : void GetPropertyValue(const nsAString& aProperty, nsAString& aValue) const;
66 : void GetPropertyValueByID(nsCSSPropertyID aPropID, nsAString& aValue) const;
67 0 : void GetAuthoredPropertyValue(const nsAString& aProperty,
68 : nsAString& aValue) const {
69 0 : GetPropertyValue(aProperty, aValue);
70 0 : }
71 : bool GetPropertyIsImportant(const nsAString& aProperty) const;
72 : void RemoveProperty(const nsAString& aProperty);
73 : void RemovePropertyByID(nsCSSPropertyID aPropID);
74 :
75 : private:
76 0 : ~ServoDeclarationBlock() {}
77 :
78 : RefPtr<RawServoDeclarationBlock> mRaw;
79 : };
80 :
81 : } // namespace mozilla
82 :
83 : #endif // mozilla_ServoDeclarationBlock_h
|