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 /* FFI functions for Gecko to call into Servo */
8 
9 #ifndef mozilla_ServoBindings_h
10 #define mozilla_ServoBindings_h
11 
12 #include "mozilla/ServoStyleConsts.h"
13 
14 // These functions are defined via macros in Rust, so cbindgen doesn't see them.
15 
16 namespace mozilla {
17 
18 // The clang we use on windows complains about returning StyleStrong<> and
19 // StyleOwned<>, since the template parameters are incomplete.
20 //
21 // But they only contain pointers so it is ok. Also, this warning hilariously
22 // doesn't exist in GCC.
23 //
24 // A solution for this is to explicitly instantiate the template, but duplicate
25 // instantiations are an error.
26 //
27 // https://github.com/eqrion/cbindgen/issues/402 tracks an improvement to
28 // cbindgen that would allow it to autogenerate the template instantiations on
29 // its own.
30 #pragma GCC diagnostic push
31 #ifdef __clang__
32 #  pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
33 #endif
34 
35 extern "C" {
36 
37 #define BASIC_RULE_FUNCS_WITHOUT_GETTER(type_)                            \
38   void Servo_##type_##_Debug(const RawServo##type_*, nsACString* result); \
39   void Servo_##type_##_GetCssText(const RawServo##type_*, nsACString* result);
40 
41 #define BASIC_RULE_FUNCS(type_)                                         \
42   StyleStrong<RawServo##type_##Rule> Servo_CssRules_Get##type_##RuleAt( \
43       const ServoCssRules* rules, uint32_t index, uint32_t* line,       \
44       uint32_t* column);                                                \
45   void Servo_StyleSet_##type_##RuleChanged(                             \
46       const RawServoStyleSet*, const RawServo##type_##Rule*,            \
47       const StyleDomStyleSheet*, StyleRuleChangeKind);                  \
48   BASIC_RULE_FUNCS_WITHOUT_GETTER(type_##Rule)
49 
50 #define GROUP_RULE_FUNCS(type_)                            \
51   BASIC_RULE_FUNCS(type_)                                  \
52   StyleStrong<ServoCssRules> Servo_##type_##Rule_GetRules( \
53       const RawServo##type_##Rule* rule);
54 
55 BASIC_RULE_FUNCS(Style)
56 BASIC_RULE_FUNCS(Import)
57 BASIC_RULE_FUNCS_WITHOUT_GETTER(Keyframe)
58 BASIC_RULE_FUNCS(Keyframes)
59 GROUP_RULE_FUNCS(Media)
60 GROUP_RULE_FUNCS(MozDocument)
61 BASIC_RULE_FUNCS(Namespace)
62 BASIC_RULE_FUNCS(Page)
63 GROUP_RULE_FUNCS(Supports)
64 GROUP_RULE_FUNCS(LayerBlock)
65 BASIC_RULE_FUNCS(LayerStatement)
66 BASIC_RULE_FUNCS(FontFeatureValues)
67 BASIC_RULE_FUNCS(FontFace)
68 BASIC_RULE_FUNCS(CounterStyle)
69 BASIC_RULE_FUNCS(ScrollTimeline)
70 
71 #undef GROUP_RULE_FUNCS
72 #undef BASIC_RULE_FUNCS
73 #undef BASIC_RULE_FUNCS_WITHOUT_GETTER
74 
75 #define BASIC_SERDE_FUNCS(type_)                                            \
76   bool Servo_##type_##_Deserialize(mozilla::ipc::ByteBuf* input, type_* v); \
77   bool Servo_##type_##_Serialize(const type_* v, mozilla::ipc::ByteBuf* output);
78 
79 using RayFunction = StyleRayFunction<StyleAngle>;
80 BASIC_SERDE_FUNCS(LengthPercentage)
81 BASIC_SERDE_FUNCS(StyleRotate)
82 BASIC_SERDE_FUNCS(StyleScale)
83 BASIC_SERDE_FUNCS(StyleTranslate)
84 BASIC_SERDE_FUNCS(StyleTransform)
85 BASIC_SERDE_FUNCS(StyleOffsetPath)
86 BASIC_SERDE_FUNCS(StyleOffsetRotate)
87 BASIC_SERDE_FUNCS(StylePositionOrAuto)
88 
89 #undef BASIC_SERDE_FUNCS
90 
91 void Servo_CounterStyleRule_GetDescriptorCssText(
92     const RawServoCounterStyleRule* rule, nsCSSCounterDesc desc,
93     nsACString* result);
94 
95 bool Servo_CounterStyleRule_SetDescriptor(const RawServoCounterStyleRule* rule,
96                                           nsCSSCounterDesc desc,
97                                           const nsACString* value);
98 
99 }  // extern "C"
100 
101 #pragma GCC diagnostic pop
102 
103 }  // namespace mozilla
104 
105 #endif  // mozilla_ServoBindings_h
106