servo/ports/geckolib/cbindgen.toml
author Emilio Cobos Álvarez <emilio@crisal.io>
Mon, 16 Dec 2019 13:31:24 +0000
changeset 507119 aa02e93402e01025296051964250b2dcc0486312
parent 506081 92a31b8aefee42605902a6842b1bda8aca984145
child 508850 fc3002cb85dc4d2c44d8aec1246f0356097411e3
permissions -rw-r--r--
Bug 1604160 - Update cbindgen to do proper copy assignment on tagged enums. r=boris This is needed to support min() / max() / clamp(), as LengthPercentage will have a potential heap allocation and the current copy-assignment operators just do bitwise copies. Differential Revision: https://phabricator.services.mozilla.com/D57300

header = """/* 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 https://mozilla.org/MPL/2.0/. */

// See the comment in ServoBindings.h about the same.
#pragma GCC diagnostic push
#ifdef __clang__
#  pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
#endif
// Work-around silly windows.h define.
#pragma push_macro("STRICT")
#undef STRICT
"""
trailer = """
#pragma pop_macro("STRICT")
#pragma GCC diagnostic pop
#include "mozilla/ServoStyleConstsInlines.h"
"""
autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
 * To generate this file:
 *   1. Get the latest cbindgen using `cargo install --force cbindgen`
 *      a. Alternatively, you can clone `https://github.com/eqrion/cbindgen` and use a tagged release
 *   2. Run `rustup run nightly cbindgen toolkit/library/rust/ --lockfile Cargo.lock --crate style -o layout/style/ServoStyleConsts.h`
 */
"""
include_guard = "mozilla_ServoStyleConsts_h"
include_version = true
braces = "SameLine"
line_length = 80
tab_width = 2
language = "C++"
namespaces = ["mozilla"]
includes = ["mozilla/ServoStyleConstsForwards.h"]

[parse]
parse_deps = true
extra_bindings = ["style"]
include = ["style", "cssparser", "style_traits", "servo_arc"]

[struct]
associated_constants_in_body = true
derive_eq = true
derive_neq = true

[defines]
# This will actually never be defined, but is handy to avoid cbindgen
# generating Servo-only types.
"feature = servo" = "CBINDGEN_IS_SERVO"

[macro_expansion]
bitflags = true

[enum]
derive_helper_methods = true
derive_const_casts = true
derive_tagged_enum_destructor = true
derive_tagged_enum_copy_constructor = true
derive_tagged_enum_copy_assignment = true
private_default_tagged_enum_constructor = true
cast_assert_name = "MOZ_ASSERT"

[export]
prefix = "Style"
exclude = [
  "NS_LogCtor",
  "NS_LogDtor",
]
include = [
  "Appearance",
  "BreakBetween",
  "BreakWithin",
  "BorderStyle",
  "OutlineStyle",
  "ComputedFontStretchRange",
  "ComputedFontStyleDescriptor",
  "ComputedFontWeightRange",
  "ComputedTimingFunction",
  "CursorKind",
  "DisplayOutside",
  "DisplayInside",
  "DisplayMode",
  "PrefersColorScheme",
  "ExtremumLength",
  "FillRule",
  "FontDisplay",
  "FontFaceSourceListComponent",
  "FontLanguageOverride",
  "GenericFontFamily",
  "FontFamilyNameSyntax",
  "OverflowWrap",
  "TimingFunction",
  "OffsetPath",
  "OffsetRotate",
  "UnicodeRange",
  "UserSelect",
  "Float",
  "OverscrollBehavior",
  "ScrollSnapAlign",
  "ScrollSnapAxis",
  "ScrollSnapStrictness",
  "ScrollSnapType",
  "OverflowAnchor",
  "OverflowClipBox",
  "Resize",
  "Overflow",
  "LengthPercentage",
  "LetterSpacing",
  "NonNegativeLengthPercentage",
  "LengthPercentageOrAuto",
  "LineHeight",
  "NonNegativeLengthPercentageOrAuto",
  "NonNegativeLengthPercentageOrNormal",
  "LengthOrAuto",
  "NonNegativeLengthOrAuto",
  "TextDecorationSkipInk",
  "TextDecorationLength",
  "Rect",
  "IntersectionObserverRootMargin",
  "Size",
  "MaxSize",
  "FlexBasis",
  "Position",
  "PositionOrAuto",
  "BackgroundSize",
  "BorderImageSlice",
  "BorderSpacing",
  "BorderRadius",
  "NonNegativeLengthOrNumberRect",
  "Perspective",
  "ZIndex",
  "TransformOrigin",
  "LineBreak",
  "WordBreak",
  "Contain",
  "Origin",
  "RestyleHint",
  "TouchAction",
  "WillChange",
  "TextDecorationLine",
  "TextUnderlinePosition",
  "TextTransform",
  "TextOverflow",
  "MozListReversed",
  "Owned",
  "OwnedOrNull",
  "Strong",
  "ScrollbarColor",
  "Color",
  "ColorOrAuto",
  "SystemColor",
  "GradientItem",
  "VerticalAlign",
  "BasicShape",
  "ShapeRadius",
  "ArcSlice",
  "ForgottenArcSlicePtr",
  "HeaderWithLength",
  "MozContextProperties",
  "Quotes",
  "BoxShadow",
  "SimpleShadow",
  "Transform",
  "Rotate",
  "Scale",
  "Translate",
  "BorderImageWidth",
  "ComputedUrl",
  "ComputedImageUrl",
  "UrlOrNone",
  "Filter",
  "Gradient",
  "GridTemplateAreas",
  "GridLine",
  "TrackSize",
  "TrackBreadth",
  "ImplicitGridTracks",
  "SVGPaint",
  "SVGPaintKind",
  "GridTemplateComponent",
  "TextEmphasisStyle",
  "VariantAlternatesList",
  "PaintOrder",
  "SVGPaintOrder",
  "ClipRectOrAuto",
  "CounterSetOrReset",
  "CounterIncrement",
  "WritingMode",
  "VecU8",
]
item_types = ["enums", "structs", "typedefs", "functions", "constants"]
renaming_overrides_prefixing = true

# Prevent some renaming for Gecko types that cbindgen doesn't otherwise understand.
[export.rename]
"nscolor" = "nscolor"
"nsAtom" = "nsAtom"
"nsIURI" = "nsIURI"
"nsCompatibility" = "nsCompatibility"
"SharedFontList" = "SharedFontList"
"nsSimpleContentList" = "nsSimpleContentList"
"nsACString" = "nsACString"
"nsAString" = "nsAString"
"nsString" = "nsString"
"nsTArray" = "nsTArray"
"nsPresContext" = "nsPresContext"
"ComputedTiming" = "ComputedTiming"
"CountedUnknownProperty" = "CountedUnknownProperty"
"RefPtr" = "RefPtr"
"nsCSSPropertyID" = "nsCSSPropertyID"
"nsCSSPropertyIDSet" = "nsCSSPropertyIDSet"
"nsCSSValueSharedList" = "nsCSSValueSharedList"
"AnimationPropertySegment" = "AnimationPropertySegment"
"RawServoAnimationValueMap" = "RawServoAnimationValueMap"
"RawServoAnimationValueTable" = "RawServoAnimationValueTable"
"nsCSSUnit" = "nsCSSUnit"
"ParsingMode" = "ParsingMode"
"InheritTarget" = "InheritTarget"
"PseudoStyleType" = "PseudoStyleType"
"DeclarationBlockMutationClosure" = "DeclarationBlockMutationClosure"
"AtomArray" = "AtomArray"
"UpdateAnimationsTasks" = "UpdateAnimationsTasks"
"StyleRuleInclusion" = "StyleRuleInclusion"
"nsFontFaceRuleContainer" = "nsFontFaceRuleContainer"
"MediumFeaturesChangedResult" = "MediumFeaturesChangedResult"
"FontSizePrefs" = "FontSizePrefs"
"nsCSSFontDesc" = "nsCSSFontDesc"
"nsresult" = "nsresult"
"gfxFontFeature" = "gfxFontFeature"
"gfxFontFeatureValueSet" = "gfxFontFeatureValueSet"
"SeenPtrs" = "SeenPtrs"
"gfxFontVariation" = "gfxFontVariation"
"URLExtraData" = "URLExtraData"
"Keyframe" = "Keyframe"
"nsChangeHint" = "nsChangeHint"
"ServoElementSnapshotTable" = "ServoElementSnapshotTable"
"nsTimingFunction" = "nsTimingFunction"
"Keyframe" = "Keyframe"
"ComputedKeyframeValues" = "ComputedKeyframeValues"
"OriginFlags" = "OriginFlags"
"ServoTraversalFlags" = "ServoTraversalFlags"
"ServoStyleSetSizes" = "ServoStyleSetSizes"

[export.body]
"CSSPixelLength" = """
  inline nscoord ToAppUnits() const;
  inline bool IsZero() const;
  float ToCSSPixels() const { return _0; }
"""

"LengthPercentage" = """
  static constexpr inline StyleLengthPercentage Zero();
  static inline StyleLengthPercentage FromAppUnits(nscoord);
  static inline StyleLengthPercentage FromPixels(CSSCoord);
  static inline StyleLengthPercentage FromPercentage(float);
  inline CSSCoord LengthInCSSPixels() const;
  inline float Percentage() const;
  inline bool HasPercent() const;
  inline bool ConvertsToLength() const;
  inline nscoord ToLength() const;
  inline bool ConvertsToPercentage() const;
  inline bool HasLengthAndPercentage() const;
  inline float ToPercentage() const;
  inline bool IsDefinitelyZero() const;
  inline CSSCoord ResolveToCSSPixels(CSSCoord aPercentageBasisInCSSPixels) const;
  template<typename T> inline CSSCoord ResolveToCSSPixelsWith(T aPercentageGetter) const;
  template<typename T, typename U>
  inline nscoord Resolve(T aPercentageGetter, U aPercentRoundingFunction) const;
  template<typename T>
  inline nscoord Resolve(nscoord aPercentageBasis, T aPercentRoundingFunction) const;
  template<typename T> inline nscoord Resolve(T aPercentageGetter) const;
  inline nscoord Resolve(nscoord aPercentageBasis) const;
"""

"GenericLengthPercentageOrAuto" = """
  inline bool ConvertsToLength() const;
  inline nscoord ToLength() const;
  inline bool ConvertsToPercentage() const;
  inline float ToPercentage() const;
  inline bool HasPercent() const;
  inline bool HasLengthAndPercentage() const;

  // Just some convenient aliases for LengthOrAuto, to avoid confusing naming.
  inline bool IsLength() const;
  inline const StyleLength& AsLength() const;
"""

"GenericSize" = """
  inline bool ConvertsToLength() const;
  inline nscoord ToLength() const;
  inline bool ConvertsToPercentage() const;
  inline float ToPercentage() const;
  inline bool HasPercent() const;
  inline bool HasLengthAndPercentage() const;
  inline bool BehavesLikeInitialValueOnBlockAxis() const;
"""

"GenericFlexBasis" = """
  inline bool IsAuto() const;
"""

"GenericMaxSize" = """
  inline bool ConvertsToLength() const;
  inline nscoord ToLength() const;
  inline bool ConvertsToPercentage() const;
  inline float ToPercentage() const;
  inline bool HasPercent() const;
  inline bool HasLengthAndPercentage() const;
  inline bool BehavesLikeInitialValueOnBlockAxis() const;
"""

"GenericPosition" = """
  inline bool HasPercent() const;
  inline bool DependsOnPositioningAreaSize() const;
  static inline StyleGenericPosition FromPercentage(float);
"""

"GenericBackgroundSize" = """
  bool IsInitialValue() const;
"""

"Rect" = """
  template<typename Predicate> inline bool All(Predicate) const;
  template<typename Predicate> inline bool Any(Predicate) const;

  // Defined in WritingModes.h
  inline const T& Get(mozilla::Side) const;
  inline const T& Get(mozilla::WritingMode, mozilla::LogicalSide) const;
  inline const T& GetIStart(mozilla::WritingMode) const;
  inline const T& GetBStart(mozilla::WritingMode) const;
  inline const T& GetIEnd(mozilla::WritingMode) const;
  inline const T& GetBEnd(mozilla::WritingMode) const;
"""

"GenericBorderRadius" = """
  inline const StyleLengthPercentage& Get(mozilla::HalfCorner) const;
"""

"RestyleHint" = """
  static inline StyleRestyleHint RestyleSubtree();
  static inline StyleRestyleHint RecascadeSubtree();
  static inline StyleRestyleHint ForAnimations();
"""

"TextTransform" = """
  static inline StyleTextTransform None();
  inline bool IsNone() const;
"""

"TextUnderlinePosition" = """
  inline bool IsAuto() const;
  inline bool IsUnder() const;
  inline bool IsLeft() const;
  inline bool IsRight() const;
"""

# TODO(emilio): Add hooks to cbindgen to be able to generate MOZ_MUST_USE_TYPE
# or MOZ_MUST_USE on the functions.
"Owned" = """
  UniquePtr<GeckoType> Consume() {
    UniquePtr<GeckoType> ret(ptr);
    ptr = nullptr;
    return ret;
  }
"""

"OwnedOrNull" = """
  UniquePtr<GeckoType> Consume() {
    UniquePtr<GeckoType> ret(ptr);
    ptr = nullptr;
    return ret;
  }
"""

"Strong" = """
  already_AddRefed<GeckoType> Consume() {
    already_AddRefed<GeckoType> ret(const_cast<GeckoType*>(ptr));
    ptr = nullptr;
    return ret;
  }
"""

"GenericColor" = """
  static inline StyleGenericColor FromColor(nscolor);
  static inline StyleGenericColor Black();
  static inline StyleGenericColor White();
  static inline StyleGenericColor Transparent();
  bool MaybeTransparent() const;
  /**
   * Compute the final color, taking into account the foreground color from the
   * frame's ComputedStyle.
   */
  nscolor CalcColor(const nsIFrame*) const;
  /**
   * Compute the final color, taking into account the foreground color from the
   * style.
   */
  nscolor CalcColor(const ComputedStyle&) const;
  /**
   * Compute the final color, making the argument the foreground color.
   */
  nscolor CalcColor(nscolor) const;
  nscolor CalcColor(const StyleRGBA&) const;
"""

"RGBA" = """
  static inline StyleRGBA Transparent();
  static inline StyleRGBA FromColor(nscolor);

  inline nscolor ToColor() const;
"""

"OwnedSlice" = """
  StyleOwnedSlice() :
    ptr((T*)alignof(T)),
    len(0) {}

  inline void Clear();
  inline void CopyFrom(const StyleOwnedSlice&);
  inline void SwapElements(StyleOwnedSlice&);

  StyleOwnedSlice& operator=(const StyleOwnedSlice&);
  StyleOwnedSlice& operator=(StyleOwnedSlice&&);

  inline StyleOwnedSlice(const StyleOwnedSlice&);
  inline StyleOwnedSlice(StyleOwnedSlice&&);

  inline ~StyleOwnedSlice();

  Span<const T> AsSpan() const {
    return MakeSpan(ptr, len);
  }

  size_t Length() const {
    return AsSpan().Length();
  }

  bool IsEmpty() const { return Length() == 0; }

  bool operator==(const StyleOwnedSlice& other) const {
    return AsSpan() == other.AsSpan();
  }

  bool operator!=(const StyleOwnedSlice& other) const {
    return !(*this == other);
  }
"""

"ArcInner" = """
  // Increase the reference count.
  inline void IncrementRef();
  // Release the reference count, and return whether the result must be freed or not.
  MOZ_MUST_USE inline bool DecrementRef();
"""

"ArcSlice" = """
  inline StyleArcSlice();
  inline StyleArcSlice(const StyleArcSlice& aOther);

  // Should be easily implementable if wanted, but the default implementation would leak.
  StyleArcSlice& operator=(const StyleArcSlice&) = delete;
  StyleArcSlice& operator=(StyleArcSlice&&) = delete;

  inline explicit StyleArcSlice(const StyleForgottenArcSlicePtr<T>& aPtr);
  inline ~StyleArcSlice();
  inline Span<const T> AsSpan() const;
  inline size_t Length() const;
  inline bool IsEmpty() const;
  inline bool operator==(const StyleArcSlice& other) const;
  inline bool operator!=(const StyleArcSlice& other) const;
"""

"Arc" = """
  StyleArc() = delete;
  inline StyleArc(const StyleArc& Other);
 private:
  inline void Release();
 public:
  inline ~StyleArc();

  inline StyleArc& operator=(const StyleArc&);
  inline StyleArc& operator=(StyleArc&&);

  const T* operator->() const {
    MOZ_DIAGNOSTIC_ASSERT(p, "Arc shouldn't be null");
    return &p->data;
  }
  const T& operator*() const {
    MOZ_DIAGNOSTIC_ASSERT(p, "Arc shouldn't be null");
    return p->data;
  }
  bool operator==(const StyleArc& other) const {
    return p == other.p || *(*this) == *other;
  }
  bool operator!=(const StyleArc& other) const {
    return !(*this == other);
  }
"""

"CustomIdent" = """
  inline nsAtom* AsAtom() const;
"""

"Atom" = """
  StyleAtom(size_t) = delete;
  StyleAtom() = delete;

  inline bool IsStatic() const;
  inline nsAtom* AsAtom() const;

 private:
  inline void AddRef();
  inline void Release();

 public:
  inline explicit StyleAtom(already_AddRefed<nsAtom> aAtom);
  inline StyleAtom(const StyleAtom& aOther);
  inline StyleAtom& operator=(const StyleAtom&);
  inline ~StyleAtom();
"""

"OwnedStr" = """
  inline nsDependentCSubstring AsString() const;
"""

"GenericTransformOrigin" = """
  inline bool HasPercent() const;
"""

"GenericTransform" = """
  inline Span<const T> Operations() const;
  inline bool IsNone() const;
  bool HasPercent() const;
"""

"Angle" = """
  inline static StyleAngle Zero();
  inline float ToDegrees() const;
  inline double ToRadians() const;
  StyleAngle operator+(const StyleAngle& aAngle) const {
    return StyleAngle{_0 + aAngle._0};
  }
  StyleAngle operator-(const StyleAngle& aAngle) const {
    return StyleAngle{_0 - aAngle._0};
  }
"""

"CoordPair" = """
  explicit StyleCoordPair(const gfx::Point& aPoint): _0(aPoint.x), _1(aPoint.y) {}
"""

"TextOverflow" = """
  StyleTextOverflow()
    : first(StyleTextOverflowSide::Clip()),
      second(StyleTextOverflowSide::Clip()),
      sides_are_logical(true) {}
"""

"UrlExtraData" = """
  StyleUrlExtraData() = delete;

  // Could be implemented if wanted.
  StyleUrlExtraData(const StyleUrlExtraData&) = delete;
  StyleUrlExtraData& operator=(const StyleUrlExtraData&) = delete;

  inline bool IsShared() const;

  inline ~StyleUrlExtraData();
  inline const URLExtraData& get() const;
"""

"CssUrlData" = """
  // Implemented in nsStyleStruct.cpp
  bool operator==(const StyleCssUrlData& other) const;
  bool operator!=(const StyleCssUrlData& other) const {
    return !(*this == other);
  }
"""

"LoadData" = """
  ~StyleLoadData();
"""

"CssUrl" = """
  inline nsDependentCSubstring SpecifiedSerialization() const;
  inline const URLExtraData& ExtraData() const;
  inline StyleLoadData& LoadData() const;
  inline nsIURI* GetURI() const;
"""

"ComputedUrl" = """
  // Forwarded from CssUrl.
  inline nsDependentCSubstring SpecifiedSerialization() const;
  inline const URLExtraData& ExtraData() const;
  inline nsIURI* GetURI() const;
  inline StyleLoadData& LoadData() const;

  inline bool IsLocalRef() const;
  inline bool HasRef() const;
  inline StyleCorsMode CorsMode() const;
  already_AddRefed<nsIURI> ResolveLocalRef(nsIURI* aBase) const;
  already_AddRefed<nsIURI> ResolveLocalRef(const nsIContent* aContent) const;
  imgRequestProxy* LoadImage(mozilla::dom::Document&);
"""

"GenericGradient" = """
  bool IsOpaque() const;
"""

"GenericGridLine" = """
  // Returns the `auto` value.
  inline StyleGenericGridLine();
  inline bool IsAuto() const;
  // The line name, or nsGkAtoms::_empty if not present.
  inline nsAtom* LineName() const;
"""

"GenericTrackBreadth" = """
  inline bool HasPercent() const;
"""

"GenericTrackSize" = """
  // Implemented in nsGridContainerFrame.cpp
  inline const StyleGenericTrackBreadth<L>& GetMin() const;
  inline const StyleGenericTrackBreadth<L>& GetMax() const;
"""

"GenericGridTemplateComponent" = """
  inline Maybe<size_t> RepeatAutoIndex() const;
  inline const StyleGenericTrackRepeat<L, I>* GetRepeatAutoValue() const;
  inline bool HasRepeatAuto() const;
  inline Span<const StyleOwnedSlice<StyleCustomIdent>> LineNameLists(bool aIsSubgrid) const;
  inline Span<const StyleGenericTrackListValue<L, I>> TrackListValues() const;
"""

"GenericClipRect" = """
  // Get the layout rect, replacing auto right / bottom values for aAutoSize.
  inline nsRect ToLayoutRect(nscoord aAutoSize = NS_MAXSIZE) const;
"""

"VecU8" = """
  StyleVecU8(): data(nullptr), length(0), capacity(0) {}
  StyleVecU8(const StyleVecU8& aOther) = delete;
  StyleVecU8(StyleVecU8&& aOther)
    : data(aOther.data), length(aOther.length), capacity(aOther.capacity) {
    aOther.data = nullptr;
    aOther.length = 0;
    aOther.capacity = 0;
  }
  StyleVecU8& operator=(StyleVecU8&& aOther) = delete;
  StyleVecU8& operator=(const StyleVecU8& aOther) = delete;

  // This type is not safe to return by value. Should be careful.
  inline ~StyleVecU8();
"""