2016-10-24 12:16:46 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-10-15 02:29:59 +03:00
|
|
|
/* C++ types corresponding to Servo and Gecko types used across bindings,
|
|
|
|
with some annotations to indicate ownership expectations */
|
|
|
|
|
2019-03-21 20:00:27 +03:00
|
|
|
// This file defines a number of C++ types used to represent strong, and owning
|
|
|
|
// references to Servo and Gecko objects that might be used across bindings and
|
|
|
|
// FFI.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// By convention, the types defined here are named "RawServo{Type}" and
|
|
|
|
// "RawGecko{Type}". The {Type} should be something close to the real Rust or
|
|
|
|
// C++ name of the type, but need not be. The "Raw" is really just used to
|
|
|
|
// avoid clashing with other names.
|
|
|
|
//
|
|
|
|
// For Servo types, each "RawServo{ServoTypeName}" is generated as an opaque,
|
|
|
|
// declared but not defined struct.
|
|
|
|
//
|
|
|
|
// For Gecko types, each "RawGecko{GeckoTypeName}" is a typedef that aliases
|
|
|
|
// the actual C++ type.
|
|
|
|
//
|
|
|
|
// Each of these types can have a number of different typedefs generated for
|
|
|
|
// them, representing different notions of ownership when passing or receiving
|
|
|
|
// these values across bindings and FFI:
|
|
|
|
//
|
|
|
|
// RawServo{Type}Strong
|
|
|
|
// strong reference to an Arc-managed value
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// All of these strong, and owned types are generated by adding
|
2018-10-15 02:29:59 +03:00
|
|
|
// entries to one of these files:
|
|
|
|
//
|
|
|
|
// ServoArcTypeList.h
|
2019-03-21 20:00:27 +03:00
|
|
|
// generates the Strong type
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// The strong, and owned reference types should be used in FFI function
|
|
|
|
// signatures where possible, to help indicate the ownership properties that
|
|
|
|
// both sides of the function call must adhere to.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// There are some special cases defined at the bottom of this file that don't
|
|
|
|
// fit neatly into these three categories.
|
|
|
|
//
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// Using these types in C++ ========================
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// The Strong types are a C++ struct that wraps a raw pointer. When receiving a
|
|
|
|
// Strong value from a Servo_* FFI function, you must call Consume() on it to
|
|
|
|
// convert it into an already_AddRefed<RawServo{Type}>, otherwise it will leak.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// We don't currently have any cases where we pass a Strong value to Servo; this
|
|
|
|
// could be done by creating a RawServo{Type}Strong struct value whose mPtr is
|
|
|
|
// initialized to the result of calling `.forget().take()` on a
|
2019-03-21 20:00:27 +03:00
|
|
|
// RefPtr<RawServo{Type}>, but it's probably easier just to pass a raw pointer
|
|
|
|
// and let the Rust code turn it into an Arc.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// TODO(heycam): We should perhaps have a similar struct for Owned types with a
|
|
|
|
// Consume() method to convert them into a UniquePtr. The struct for Strong
|
2018-10-15 02:29:59 +03:00
|
|
|
// types at least have MOZ_MUST_USE_TYPE on them.
|
|
|
|
//
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// Using these types in Rust =========================
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// The FFI type names are available in Rust in the gecko_bindings::bindings mod,
|
|
|
|
// which is generated by servo/components/style/build_gecko.rs.
|
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// Borrowed types in rust are represented by &T, Option<&T>, &mut T, and
|
|
|
|
// Option<&mut T>.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
2019-03-21 20:00:27 +03:00
|
|
|
// In C++ you should write them as const pointers (for &T and Option<&T>) or
|
|
|
|
// non-const pointers (for &mut T and Option<&mut T>).
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// The Strong types are defined as gecko_bindings::sugar::ownership::Strong<T>.
|
|
|
|
//
|
|
|
|
// This is an FFI safe type that represents the value with a strong reference
|
|
|
|
// already added to it. Dropping a Strong<T> will leak the strong reference.
|
|
|
|
//
|
|
|
|
// A RawServoFooStrong received from FFI can be converted into a
|
|
|
|
// `RawOffsetArc<Foo>` by calling `into_arc()` or `into_arc_opt()` on it.
|
|
|
|
// To pass a RawServoFooStrong back to Gecko, call `into_strong()` on the
|
|
|
|
// `Arc<Foo>`.
|
|
|
|
//
|
|
|
|
// The Owned types are defined as gecko_bindings::sugar::ownership::Owned<T>
|
|
|
|
// (or OwnedOrNull<T>).
|
|
|
|
//
|
|
|
|
// This is another FFI safe type that represents the owning reference to the
|
|
|
|
// value. Dropping an Owned<T> will leak the value.
|
|
|
|
//
|
2019-03-26 21:15:59 +03:00
|
|
|
// An Owned<RawServoFoo> received from FFI can be converted into a `Box<Foo>`
|
|
|
|
// by calling `into_box()`. To pass an Owned<RawServoFoo> back to Gecko, call
|
|
|
|
// `HasBoxFFI::into_ffi()` passing in the `Box<Foo>` value.
|
2018-10-15 02:29:59 +03:00
|
|
|
//
|
|
|
|
// Reading through servo/components/style/gecko_bindings/sugar/ownership.rs
|
|
|
|
// is also instructive in understanding all this.
|
|
|
|
|
2016-10-24 12:16:46 +03:00
|
|
|
#ifndef mozilla_ServoBindingTypes_h
|
|
|
|
#define mozilla_ServoBindingTypes_h
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
2016-12-01 04:34:54 +03:00
|
|
|
#include "mozilla/ServoTypes.h"
|
2016-10-24 12:16:46 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2017-06-07 06:25:14 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
2017-05-19 10:58:47 +03:00
|
|
|
#include "nsCSSPropertyID.h"
|
2017-03-10 05:53:17 +03:00
|
|
|
#include "nsStyleAutoArray.h"
|
2016-12-01 04:34:54 +03:00
|
|
|
#include "nsTArray.h"
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2018-10-14 03:06:13 +03:00
|
|
|
// Forward declarations.
|
2018-10-14 03:06:05 +03:00
|
|
|
|
2016-11-23 03:35:55 +03:00
|
|
|
#define SERVO_ARC_TYPE(name_, type_) struct type_;
|
|
|
|
#include "mozilla/ServoArcTypeList.h"
|
|
|
|
#undef SERVO_ARC_TYPE
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2017-05-19 10:58:47 +03:00
|
|
|
class nsCSSPropertyIDSet;
|
2016-11-01 02:30:43 +03:00
|
|
|
class nsCSSValue;
|
2016-10-24 12:16:46 +03:00
|
|
|
class nsINode;
|
2017-01-04 22:52:26 +03:00
|
|
|
class nsPresContext;
|
2018-10-14 03:06:13 +03:00
|
|
|
struct nsFontFaceRuleContainer;
|
|
|
|
struct nsTimingFunction;
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2018-10-14 03:06:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class ComputedStyle;
|
|
|
|
class ServoElementSnapshot;
|
|
|
|
struct AnimationPropertySegment;
|
|
|
|
struct ComputedTiming;
|
|
|
|
struct Keyframe;
|
|
|
|
struct PropertyStyleAnimationValuePair;
|
|
|
|
struct PropertyValuePair;
|
|
|
|
struct StyleAnimation;
|
|
|
|
struct URLExtraData;
|
|
|
|
using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
|
|
|
|
using GfxMatrix4x4 = mozilla::gfx::Float[16];
|
2017-08-02 21:24:35 +03:00
|
|
|
|
2018-10-14 03:06:13 +03:00
|
|
|
namespace dom {
|
|
|
|
class StyleChildrenIterator;
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2018-10-14 03:06:13 +03:00
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
2019-03-26 17:40:20 +03:00
|
|
|
|
2019-03-26 21:15:59 +03:00
|
|
|
} // namespace mozilla
|
2019-03-26 17:40:20 +03:00
|
|
|
|
2016-11-23 03:35:55 +03:00
|
|
|
#define SERVO_ARC_TYPE(name_, type_) \
|
2016-10-24 12:16:46 +03:00
|
|
|
extern "C" { \
|
2019-03-21 20:00:27 +03:00
|
|
|
void Servo_##name_##_AddRef(const type_*); \
|
|
|
|
void Servo_##name_##_Release(const type_*); \
|
2016-10-24 12:16:46 +03:00
|
|
|
} \
|
|
|
|
namespace mozilla { \
|
|
|
|
template <> \
|
|
|
|
struct RefPtrTraits<type_> { \
|
|
|
|
static void AddRef(type_* aPtr) { Servo_##name_##_AddRef(aPtr); } \
|
|
|
|
static void Release(type_* aPtr) { Servo_##name_##_Release(aPtr); } \
|
|
|
|
}; \
|
|
|
|
}
|
2016-11-23 03:35:55 +03:00
|
|
|
#include "mozilla/ServoArcTypeList.h"
|
2019-03-26 21:16:01 +03:00
|
|
|
SERVO_ARC_TYPE(ComputedStyle, mozilla::ComputedStyle)
|
2016-11-23 03:35:55 +03:00
|
|
|
#undef SERVO_ARC_TYPE
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2019-03-30 23:18:33 +03:00
|
|
|
#define SERVO_BOXED_TYPE(name_, type_) \
|
|
|
|
struct type_; \
|
|
|
|
extern "C" void Servo_##name_##_Drop(type_*); \
|
|
|
|
namespace mozilla { \
|
|
|
|
template <> \
|
|
|
|
class DefaultDelete<type_> { \
|
|
|
|
public: \
|
|
|
|
void operator()(type_* aPtr) const { Servo_##name_##_Drop(aPtr); } \
|
|
|
|
}; \
|
2016-10-24 12:16:46 +03:00
|
|
|
}
|
2019-03-30 23:18:33 +03:00
|
|
|
#include "mozilla/ServoBoxedTypeList.h"
|
2018-10-14 03:06:05 +03:00
|
|
|
#undef SERVO_BOXED_TYPE
|
2016-10-24 12:16:46 +03:00
|
|
|
|
2018-10-14 03:06:13 +03:00
|
|
|
// Other special cases.
|
|
|
|
|
2019-03-21 20:00:27 +03:00
|
|
|
struct RawServoAnimationValueTable;
|
2018-10-14 03:06:13 +03:00
|
|
|
|
2016-10-24 12:16:46 +03:00
|
|
|
#endif // mozilla_ServoBindingTypes_h
|