Line data Source code
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_ServoBindingTypes_h
8 : #define mozilla_ServoBindingTypes_h
9 :
10 : #include "mozilla/RefPtr.h"
11 : #include "mozilla/ServoTypes.h"
12 : #include "mozilla/UniquePtr.h"
13 : #include "mozilla/gfx/Types.h"
14 : #include "nsCSSPropertyID.h"
15 : #include "nsStyleAutoArray.h"
16 : #include "nsTArray.h"
17 :
18 : struct RawServoStyleSet;
19 : struct RawServoAnimationValueMap;
20 :
21 : #define SERVO_ARC_TYPE(name_, type_) struct type_;
22 : #include "mozilla/ServoArcTypeList.h"
23 : #undef SERVO_ARC_TYPE
24 :
25 : namespace mozilla {
26 : class ServoElementSnapshot;
27 : struct StyleAnimation;
28 : struct URLExtraData;
29 : namespace dom {
30 : class Element;
31 : class StyleChildrenIterator;
32 : } // namespace dom
33 : struct AnimationPropertySegment;
34 : struct ComputedTiming;
35 : struct Keyframe;
36 : struct PropertyStyleAnimationValuePair;
37 : using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
38 : } // namespace mozilla
39 : namespace nsStyleTransformMatrix {
40 : enum class MatrixTransformOperator: uint8_t;
41 : }
42 :
43 : class nsCSSPropertyIDSet;
44 : class nsCSSValue;
45 : struct nsFontFaceRuleContainer;
46 : class nsIDocument;
47 : class nsINode;
48 : class nsPresContext;
49 : struct nsTimingFunction;
50 : class nsXBLBinding;
51 :
52 : using mozilla::dom::StyleChildrenIterator;
53 : using mozilla::ServoElementSnapshot;
54 :
55 : typedef nsINode RawGeckoNode;
56 : typedef mozilla::dom::Element RawGeckoElement;
57 : typedef nsIDocument RawGeckoDocument;
58 : typedef nsPresContext RawGeckoPresContext;
59 : typedef nsXBLBinding RawGeckoXBLBinding;
60 : typedef mozilla::URLExtraData RawGeckoURLExtraData;
61 : typedef nsTArray<RefPtr<RawServoAnimationValue>> RawGeckoServoAnimationValueList;
62 : typedef nsTArray<mozilla::Keyframe> RawGeckoKeyframeList;
63 : typedef nsTArray<mozilla::ComputedKeyframeValues> RawGeckoComputedKeyframeValuesList;
64 : typedef nsStyleAutoArray<mozilla::StyleAnimation> RawGeckoStyleAnimationList;
65 : typedef nsTArray<nsFontFaceRuleContainer> RawGeckoFontFaceRuleList;
66 : typedef mozilla::AnimationPropertySegment RawGeckoAnimationPropertySegment;
67 : typedef mozilla::ComputedTiming RawGeckoComputedTiming;
68 : typedef nsTArray<const RawServoStyleRule*> RawGeckoServoStyleRuleList;
69 : typedef nsTArray<nsCSSPropertyID> RawGeckoCSSPropertyIDList;
70 : typedef mozilla::gfx::Float RawGeckoGfxMatrix4x4[16];
71 : typedef mozilla::dom::StyleChildrenIterator RawGeckoStyleChildrenIterator;
72 :
73 : // We have these helper types so that we can directly generate
74 : // things like &T or Borrowed<T> on the Rust side in the function, providing
75 : // additional safety benefits.
76 : //
77 : // FFI has a problem with templated types, so we just use raw pointers here.
78 : //
79 : // The "Borrowed" types generate &T or Borrowed<T> in the nullable case.
80 : //
81 : // The "Owned" types generate Owned<T> or OwnedOrNull<T>. Some of these
82 : // are Servo-managed and can be converted to Box<ServoType> on the
83 : // Servo side.
84 : //
85 : // The "Arc" types are Servo-managed Arc<ServoType>s, which are passed
86 : // over FFI as Strong<T> (which is nullable).
87 : // Note that T != ServoType, rather T is ArcInner<ServoType>
88 : #define DECL_BORROWED_REF_TYPE_FOR(type_) typedef type_ const* type_##Borrowed;
89 : #define DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_) typedef type_ const* type_##BorrowedOrNull;
90 : #define DECL_BORROWED_MUT_REF_TYPE_FOR(type_) typedef type_* type_##BorrowedMut;
91 : #define DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_) typedef type_* type_##BorrowedMutOrNull;
92 :
93 : #define SERVO_ARC_TYPE(name_, type_) \
94 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_) \
95 : DECL_BORROWED_REF_TYPE_FOR(type_) \
96 : DECL_BORROWED_MUT_REF_TYPE_FOR(type_) \
97 : struct MOZ_MUST_USE_TYPE type_##Strong \
98 : { \
99 : type_* mPtr; \
100 : already_AddRefed<type_> Consume(); \
101 : };
102 : #include "mozilla/ServoArcTypeList.h"
103 : #undef SERVO_ARC_TYPE
104 :
105 : #define DECL_OWNED_REF_TYPE_FOR(type_) \
106 : typedef type_* type_##Owned; \
107 : DECL_BORROWED_REF_TYPE_FOR(type_) \
108 : DECL_BORROWED_MUT_REF_TYPE_FOR(type_)
109 :
110 : #define DECL_NULLABLE_OWNED_REF_TYPE_FOR(type_) \
111 : typedef type_* type_##OwnedOrNull; \
112 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_) \
113 : DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_)
114 :
115 : // This is a reference to a reference of RawServoDeclarationBlock, which
116 : // corresponds to Option<&Arc<RawServoDeclarationBlock>> in Servo side.
117 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoDeclarationBlockStrong)
118 :
119 : DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
120 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoStyleSet)
121 : DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
122 : DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
123 : DECL_OWNED_REF_TYPE_FOR(ServoElementSnapshot)
124 : DECL_OWNED_REF_TYPE_FOR(RawServoAnimationValueMap)
125 :
126 : // We don't use BorrowedMut because the nodes may alias
127 : // Servo itself doesn't directly read or mutate these;
128 : // it only asks Gecko to do so. In case we wish to in
129 : // the future, we should ensure that things being mutated
130 : // are protected from noalias violations by a cell type
131 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoNode)
132 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoNode)
133 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoElement)
134 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoElement)
135 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoDocument)
136 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoDocument)
137 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoXBLBinding)
138 : DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoXBLBinding)
139 : DECL_BORROWED_MUT_REF_TYPE_FOR(StyleChildrenIterator)
140 : DECL_BORROWED_MUT_REF_TYPE_FOR(ServoElementSnapshot)
141 : DECL_BORROWED_REF_TYPE_FOR(nsCSSValue)
142 : DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSValue)
143 : DECL_OWNED_REF_TYPE_FOR(RawGeckoPresContext)
144 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresContext)
145 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoServoAnimationValueList)
146 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoServoAnimationValueList)
147 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoKeyframeList)
148 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoKeyframeList)
149 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoComputedKeyframeValuesList)
150 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoStyleAnimationList)
151 : DECL_BORROWED_MUT_REF_TYPE_FOR(nsTimingFunction)
152 : DECL_BORROWED_REF_TYPE_FOR(nsTimingFunction)
153 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoFontFaceRuleList)
154 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoAnimationPropertySegment)
155 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoComputedTiming)
156 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoServoStyleRuleList)
157 : DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSPropertyIDSet)
158 : DECL_BORROWED_REF_TYPE_FOR(RawGeckoCSSPropertyIDList)
159 : DECL_BORROWED_REF_TYPE_FOR(nsXBLBinding)
160 : DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoStyleChildrenIterator)
161 :
162 : #undef DECL_ARC_REF_TYPE_FOR
163 : #undef DECL_OWNED_REF_TYPE_FOR
164 : #undef DECL_NULLABLE_OWNED_REF_TYPE_FOR
165 : #undef DECL_BORROWED_REF_TYPE_FOR
166 : #undef DECL_NULLABLE_BORROWED_REF_TYPE_FOR
167 : #undef DECL_BORROWED_MUT_REF_TYPE_FOR
168 : #undef DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR
169 :
170 : #define SERVO_ARC_TYPE(name_, type_) \
171 : extern "C" { \
172 : void Servo_##name_##_AddRef(type_##Borrowed ptr); \
173 : void Servo_##name_##_Release(type_##Borrowed ptr); \
174 : } \
175 : namespace mozilla { \
176 : template<> struct RefPtrTraits<type_> { \
177 : static void AddRef(type_* aPtr) { \
178 : Servo_##name_##_AddRef(aPtr); \
179 : } \
180 : static void Release(type_* aPtr) { \
181 : Servo_##name_##_Release(aPtr); \
182 : } \
183 : }; \
184 : }
185 : #include "mozilla/ServoArcTypeList.h"
186 : #undef SERVO_ARC_TYPE
187 :
188 : #define DEFINE_BOXED_TYPE(name_, type_) \
189 : extern "C" void Servo_##name_##_Drop(type_##Owned ptr); \
190 : namespace mozilla { \
191 : template<> \
192 : class DefaultDelete<type_> \
193 : { \
194 : public: \
195 : void operator()(type_* aPtr) const \
196 : { \
197 : Servo_##name_##_Drop(aPtr); \
198 : } \
199 : }; \
200 : }
201 :
202 0 : DEFINE_BOXED_TYPE(StyleSet, RawServoStyleSet);
203 :
204 : #undef DEFINE_BOXED_TYPE
205 :
206 : #endif // mozilla_ServoBindingTypes_h
|