Backed out 2 changesets (bug 903746) for causing non-unified build bustages on nsIPri...
[gecko.git] / layout / style / nsStyleStruct.h
blob8835934eafd8176666b6414eb9330a3a8e46bb1f
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/. */
7 /*
8 * structs that contain the data provided by ComputedStyle, the
9 * internal API for computed style data for an element
12 #ifndef nsStyleStruct_h___
13 #define nsStyleStruct_h___
15 #include "mozilla/Assertions.h"
16 #include "mozilla/Attributes.h"
17 #include "mozilla/Likely.h"
18 #include "mozilla/Maybe.h"
19 #include "mozilla/UniquePtr.h"
20 #include "mozilla/WindowButtonType.h"
21 #include "nsColor.h"
22 #include "nsCoord.h"
23 #include "nsMargin.h"
24 #include "nsFont.h"
25 #include "nsStyleAutoArray.h"
26 #include "nsStyleConsts.h"
27 #include "nsChangeHint.h"
28 #include "nsTArray.h"
29 #include "imgIContainer.h"
30 #include "imgRequestProxy.h"
31 #include "CounterStyleManager.h"
32 #include <cstddef> // offsetof()
33 #include "X11UndefineNone.h"
35 class nsIFrame;
36 class nsIURI;
37 class nsTextFrame;
38 struct nsStyleDisplay;
39 struct nsStyleVisibility;
40 namespace mozilla {
41 class ComputedStyle;
42 struct IntrinsicSize;
44 } // namespace mozilla
46 namespace mozilla::dom {
47 enum class CompositeOperation : uint8_t;
48 } // namespace mozilla::dom
50 namespace mozilla {
52 using Position = StylePosition;
54 template <>
55 inline bool StylePosition::HasPercent() const {
56 return horizontal.HasPercent() || vertical.HasPercent();
59 /**
60 * True if the effective background image position described by this depends on
61 * the size of the corresponding frame.
63 template <>
64 inline bool StylePosition::DependsOnPositioningAreaSize() const {
65 return HasPercent();
68 template <>
69 inline Position Position::FromPercentage(float aPercent) {
70 return {LengthPercentage::FromPercentage(aPercent),
71 LengthPercentage::FromPercentage(aPercent)};
74 /**
75 * Convenience struct for querying if a given box has size-containment in
76 * either axis.
78 struct ContainSizeAxes {
79 ContainSizeAxes(bool aIContained, bool aBContained)
80 : mIContained(aIContained), mBContained(aBContained) {}
82 bool IsBoth() const { return mIContained && mBContained; }
83 bool IsAny() const { return mIContained || mBContained; }
85 bool operator==(const ContainSizeAxes& aOther) const {
86 return mIContained == aOther.mIContained &&
87 mBContained == aOther.mBContained;
90 /**
91 * Return a contained size from an uncontained size.
93 nsSize ContainSize(const nsSize& aUncontainedSize,
94 const nsIFrame& aFrame) const;
95 IntrinsicSize ContainIntrinsicSize(const IntrinsicSize& aUncontainedSize,
96 const nsIFrame& aFrame) const;
97 Maybe<nscoord> ContainIntrinsicBSize(const nsIFrame& aFrame,
98 nscoord aNoneValue = 0) const;
99 Maybe<nscoord> ContainIntrinsicISize(const nsIFrame& aFrame,
100 nscoord aNoneValue = 0) const;
102 const bool mIContained;
103 const bool mBContained;
106 } // namespace mozilla
108 #define STYLE_STRUCT(name_) \
109 name_(const name_&); \
110 MOZ_COUNTED_DTOR(name_); \
111 void MarkLeaked() const { MOZ_COUNT_DTOR(name_); } \
112 nsChangeHint CalcDifference(const name_&) const;
114 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
115 STYLE_STRUCT(nsStyleFont)
116 explicit nsStyleFont(const mozilla::dom::Document&);
119 * Return a given size multiplied by the current text zoom factor (in
120 * aPresContext).
122 * The size is allowed to be negative, but the caller is expected to deal with
123 * negative results.
125 static mozilla::Length ZoomText(const mozilla::dom::Document&,
126 mozilla::Length);
128 nsAtom* GetFontPaletteAtom() const { return mFontPalette._0.AsAtom(); }
130 nsFont mFont;
132 // Our "computed size". Can be different from mFont.size which is our "actual
133 // size" and is enforced to be >= the user's preferred min-size. mFont.size
134 // should be used for display purposes while mSize is the value to return in
135 // getComputedStyle() for example.
136 mozilla::NonNegativeLength mSize;
138 // In stylo these three track whether the size is keyword-derived
139 // and if so if it has been modified by a factor/offset
140 float mFontSizeFactor;
141 mozilla::Length mFontSizeOffset;
142 mozilla::StyleFontSizeKeyword mFontSizeKeyword;
143 mozilla::StyleFontPalette mFontPalette;
145 // math-depth support (used for MathML scriptlevel)
146 int8_t mMathDepth;
147 mozilla::StyleLineHeight mLineHeight;
148 // MathML mathvariant support
149 mozilla::StyleMathVariant mMathVariant;
150 // math-style support (used for MathML displaystyle)
151 mozilla::StyleMathStyle mMathStyle;
153 // allow different min font-size for certain cases
154 uint8_t mMinFontSizeRatio = 100; // percent * 100
156 // Was mLanguage set based on a lang attribute in the document?
157 bool mExplicitLanguage = false;
159 mozilla::StyleXTextScale mXTextScale;
161 bool MinFontSizeEnabled() const {
162 return mXTextScale == mozilla::StyleXTextScale::All;
165 // The value mSize would have had if scriptminsize had never been applied
166 mozilla::NonNegativeLength mScriptUnconstrainedSize;
167 mozilla::Length mScriptMinSize;
168 RefPtr<nsAtom> mLanguage;
171 struct nsStyleImageLayers {
172 enum class LayerType : uint8_t { Background = 0, Mask };
174 explicit nsStyleImageLayers(LayerType aType);
175 nsStyleImageLayers(const nsStyleImageLayers& aSource);
177 struct Repeat {
178 mozilla::StyleImageLayerRepeat mXRepeat =
179 mozilla::StyleImageLayerRepeat::Repeat;
180 mozilla::StyleImageLayerRepeat mYRepeat =
181 mozilla::StyleImageLayerRepeat::Repeat;
183 // Initialize nothing
184 Repeat() = default;
186 bool IsInitialValue() const {
187 return mXRepeat == mozilla::StyleImageLayerRepeat::Repeat &&
188 mYRepeat == mozilla::StyleImageLayerRepeat::Repeat;
191 bool DependsOnPositioningAreaSize() const {
192 return mXRepeat == mozilla::StyleImageLayerRepeat::Space ||
193 mYRepeat == mozilla::StyleImageLayerRepeat::Space;
196 bool operator==(const Repeat& aOther) const {
197 return mXRepeat == aOther.mXRepeat && mYRepeat == aOther.mYRepeat;
199 bool operator!=(const Repeat& aOther) const { return !(*this == aOther); }
202 struct Layer {
203 using StyleGeometryBox = mozilla::StyleGeometryBox;
204 using StyleImageLayerAttachment = mozilla::StyleImageLayerAttachment;
205 using StyleBackgroundSize = mozilla::StyleBackgroundSize;
207 mozilla::StyleImage mImage;
208 mozilla::Position mPosition;
209 StyleBackgroundSize mSize;
210 StyleGeometryBox mClip;
211 MOZ_INIT_OUTSIDE_CTOR StyleGeometryBox mOrigin;
213 // This property is used for background layer only.
214 // For a mask layer, it should always be the initial value, which is
215 // StyleImageLayerAttachment::Scroll.
216 StyleImageLayerAttachment mAttachment;
218 // This property is used for background layer only.
219 // For a mask layer, it should always be the initial value, which is
220 // StyleBlend::Normal.
221 mozilla::StyleBlend mBlendMode;
223 // This property is used for mask layer only.
224 // For a background layer, it should always be the initial value, which is
225 // StyleMaskComposite::Add.
226 mozilla::StyleMaskComposite mComposite;
228 // mask-only property. This property is used for mask layer only. For a
229 // background layer, it should always be the initial value, which is
230 // StyleMaskMode::MatchSource.
231 mozilla::StyleMaskMode mMaskMode;
233 Repeat mRepeat;
235 // This constructor does not initialize mRepeat or mOrigin and Initialize()
236 // must be called to do that.
237 Layer();
238 ~Layer();
240 // Initialize mRepeat and mOrigin by specified layer type
241 void Initialize(LayerType aType);
243 void ResolveImage(mozilla::dom::Document& aDocument,
244 const Layer* aOldLayer) {
245 mImage.ResolveImage(aDocument, aOldLayer ? &aOldLayer->mImage : nullptr);
248 // True if the rendering of this layer might change when the size
249 // of the background positioning area changes. This is true for any
250 // non-solid-color background whose position or size depends on
251 // the size of the positioning area. It's also true for SVG images
252 // whose root <svg> node has a viewBox.
253 bool RenderingMightDependOnPositioningAreaSizeChange() const;
255 // Compute the change hint required by changes in just this layer.
256 nsChangeHint CalcDifference(const Layer& aNewLayer) const;
258 // An equality operator that compares the images using URL-equality
259 // rather than pointer-equality.
260 bool operator==(const Layer& aOther) const;
261 bool operator!=(const Layer& aOther) const { return !(*this == aOther); }
264 // The (positive) number of computed values of each property, since
265 // the lengths of the lists are independent.
266 uint32_t mAttachmentCount;
267 uint32_t mClipCount;
268 uint32_t mOriginCount;
269 uint32_t mRepeatCount;
270 uint32_t mPositionXCount;
271 uint32_t mPositionYCount;
272 uint32_t mImageCount;
273 uint32_t mSizeCount;
274 uint32_t mMaskModeCount;
275 uint32_t mBlendModeCount;
276 uint32_t mCompositeCount;
278 // Layers are stored in an array, matching the top-to-bottom order in
279 // which they are specified in CSS. The number of layers to be used
280 // should come from the background-image property. We create
281 // additional |Layer| objects for *any* property, not just
282 // background-image. This means that the bottommost layer that
283 // callers in layout care about (which is also the one whose
284 // background-clip applies to the background-color) may not be last
285 // layer. In layers below the bottom layer, properties will be
286 // uninitialized unless their count, above, indicates that they are
287 // present.
288 nsStyleAutoArray<Layer> mLayers;
290 const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; }
292 void ResolveImages(mozilla::dom::Document& aDocument,
293 const nsStyleImageLayers* aOldLayers) {
294 for (uint32_t i = 0; i < mImageCount; ++i) {
295 const Layer* oldLayer = (aOldLayers && aOldLayers->mLayers.Length() > i)
296 ? &aOldLayers->mLayers[i]
297 : nullptr;
298 mLayers[i].ResolveImage(aDocument, oldLayer);
302 // Fill unspecified layers by cycling through their values
303 // till they all are of length aMaxItemCount
304 void FillAllLayers(uint32_t aMaxItemCount);
306 nsChangeHint CalcDifference(const nsStyleImageLayers& aNewLayers,
307 nsStyleImageLayers::LayerType aType) const;
309 nsStyleImageLayers& operator=(const nsStyleImageLayers& aOther);
310 nsStyleImageLayers& operator=(nsStyleImageLayers&& aOther) = default;
311 bool operator==(const nsStyleImageLayers& aOther) const;
313 static const nsCSSPropertyID kBackgroundLayerTable[];
314 static const nsCSSPropertyID kMaskLayerTable[];
316 #define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(var_, layers_) \
317 for (uint32_t var_ = (layers_).mImageCount; (var_)-- != 0;)
318 #define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(var_, layers_, \
319 start_, count_) \
320 NS_ASSERTION( \
321 (int32_t)(start_) >= 0 && (uint32_t)(start_) < (layers_).mImageCount, \
322 "Invalid layer start!"); \
323 NS_ASSERTION((count_) > 0 && (count_) <= (start_) + 1, \
324 "Invalid layer range!"); \
325 for (uint32_t var_ = (start_) + 1; \
326 (var_)-- != (uint32_t)((start_) + 1 - (count_));)
329 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBackground {
330 STYLE_STRUCT(nsStyleBackground)
331 nsStyleBackground();
332 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBackground*);
334 // Return the background color as nscolor.
335 nscolor BackgroundColor(const nsIFrame* aFrame) const;
336 nscolor BackgroundColor(const mozilla::ComputedStyle* aStyle) const;
338 // True if this background is completely transparent.
339 bool IsTransparent(const nsIFrame* aFrame) const;
340 bool IsTransparent(const mozilla::ComputedStyle* aStyle) const;
342 // We have to take slower codepaths for fixed background attachment,
343 // but we don't want to do that when there's no image.
344 // Not inline because it uses an nsCOMPtr<imgIRequest>
345 // FIXME: Should be in nsStyleStructInlines.h.
346 bool HasFixedBackground(nsIFrame* aFrame) const;
348 // Checks to see if this has a non-empty image with "local" attachment.
349 // This is defined in nsStyleStructInlines.h.
350 inline bool HasLocalBackground() const;
352 const nsStyleImageLayers::Layer& BottomLayer() const {
353 return mImage.BottomLayer();
356 nsStyleImageLayers mImage;
357 mozilla::StyleColor mBackgroundColor;
360 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin {
361 STYLE_STRUCT(nsStyleMargin)
362 nsStyleMargin();
364 bool GetMargin(nsMargin& aMargin) const {
365 bool convertsToLength = mMargin.All(
366 [](const auto& aLength) { return aLength.ConvertsToLength(); });
368 if (!convertsToLength) {
369 return false;
372 for (const auto side : mozilla::AllPhysicalSides()) {
373 aMargin.Side(side) = mMargin.Get(side).AsLengthPercentage().ToLength();
375 return true;
378 nsMargin GetScrollMargin() const {
379 return nsMargin(mScrollMargin.Get(mozilla::eSideTop).ToAppUnits(),
380 mScrollMargin.Get(mozilla::eSideRight).ToAppUnits(),
381 mScrollMargin.Get(mozilla::eSideBottom).ToAppUnits(),
382 mScrollMargin.Get(mozilla::eSideLeft).ToAppUnits());
385 // Return true if either the start or end side in the axis is 'auto'.
386 // (defined in WritingModes.h since we need the full WritingMode type)
387 inline bool HasBlockAxisAuto(mozilla::WritingMode aWM) const;
388 inline bool HasInlineAxisAuto(mozilla::WritingMode aWM) const;
389 inline bool HasAuto(mozilla::LogicalAxis, mozilla::WritingMode) const;
391 mozilla::StyleRect<mozilla::LengthPercentageOrAuto> mMargin;
392 mozilla::StyleRect<mozilla::StyleLength> mScrollMargin;
393 // TODO: Add support for overflow-clip-margin: <visual-box> and maybe
394 // per-axis/side clipping, see https://github.com/w3c/csswg-drafts/issues/7245
395 mozilla::StyleLength mOverflowClipMargin;
398 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePadding {
399 STYLE_STRUCT(nsStylePadding)
400 nsStylePadding();
402 mozilla::StyleRect<mozilla::NonNegativeLengthPercentage> mPadding;
403 mozilla::StyleRect<mozilla::NonNegativeLengthPercentageOrAuto> mScrollPadding;
405 inline bool IsWidthDependent() const {
406 return !mPadding.All(
407 [](const auto& aLength) { return aLength.ConvertsToLength(); });
410 bool GetPadding(nsMargin& aPadding) const {
411 if (IsWidthDependent()) {
412 return false;
415 for (const auto side : mozilla::AllPhysicalSides()) {
416 // Clamp negative calc() to 0.
417 aPadding.Side(side) = std::max(mPadding.Get(side).ToLength(), 0);
419 return true;
423 // Border widths are rounded to the nearest-below integer number of pixels,
424 // but values between zero and one device pixels are always rounded up to
425 // one device pixel.
426 #define NS_ROUND_BORDER_TO_PIXELS(l, tpp) \
427 ((l) == 0) ? 0 : std::max((tpp), (l) / (tpp) * (tpp))
429 // Returns if the given border style type is visible or not
430 static bool IsVisibleBorderStyle(mozilla::StyleBorderStyle aStyle) {
431 return (aStyle != mozilla::StyleBorderStyle::None &&
432 aStyle != mozilla::StyleBorderStyle::Hidden);
435 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
436 STYLE_STRUCT(nsStyleBorder)
437 nsStyleBorder();
438 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBorder*);
440 // Return whether aStyle is a visible style. Invisible styles cause
441 // the relevant computed border width to be 0.
442 // Note that this does *not* consider the effects of 'border-image':
443 // if border-style is none, but there is a loaded border image,
444 // HasVisibleStyle will be false even though there *is* a border.
445 bool HasVisibleStyle(mozilla::Side aSide) const {
446 return IsVisibleBorderStyle(mBorderStyle[aSide]);
449 // aBorderWidth is in twips
450 void SetBorderWidth(mozilla::Side aSide, nscoord aBorderWidth,
451 nscoord aAppUnitsPerDevPixel) {
452 nscoord roundedWidth =
453 NS_ROUND_BORDER_TO_PIXELS(aBorderWidth, aAppUnitsPerDevPixel);
454 mBorder.Side(aSide) = roundedWidth;
455 if (HasVisibleStyle(aSide)) {
456 mComputedBorder.Side(aSide) = roundedWidth;
460 // Get the computed border (plus rounding). This does consider the
461 // effects of 'border-style: none', but does not consider
462 // 'border-image'.
463 const nsMargin& GetComputedBorder() const { return mComputedBorder; }
465 bool HasBorder() const {
466 return mComputedBorder != nsMargin(0, 0, 0, 0) ||
467 !mBorderImageSource.IsNone();
470 // Get the actual border width for a particular side, in appunits. Note that
471 // this is zero if and only if there is no border to be painted for this
472 // side. That is, this value takes into account the border style and the
473 // value is rounded to the nearest device pixel by NS_ROUND_BORDER_TO_PIXELS.
474 nscoord GetComputedBorderWidth(mozilla::Side aSide) const {
475 return GetComputedBorder().Side(aSide);
478 mozilla::StyleBorderStyle GetBorderStyle(mozilla::Side aSide) const {
479 NS_ASSERTION(aSide <= mozilla::eSideLeft, "bad side");
480 return mBorderStyle[aSide];
483 void SetBorderStyle(mozilla::Side aSide, mozilla::StyleBorderStyle aStyle) {
484 NS_ASSERTION(aSide <= mozilla::eSideLeft, "bad side");
485 mBorderStyle[aSide] = aStyle;
486 mComputedBorder.Side(aSide) =
487 (HasVisibleStyle(aSide) ? mBorder.Side(aSide) : 0);
490 inline bool IsBorderImageSizeAvailable() const {
491 return mBorderImageSource.IsSizeAvailable();
494 nsMargin GetImageOutset() const;
496 imgIRequest* GetBorderImageRequest() const {
497 return mBorderImageSource.GetImageRequest();
500 public:
501 mozilla::StyleBorderRadius mBorderRadius; // coord, percent
502 mozilla::StyleImage mBorderImageSource;
503 mozilla::StyleBorderImageWidth mBorderImageWidth;
504 mozilla::StyleNonNegativeLengthOrNumberRect mBorderImageOutset;
505 mozilla::StyleBorderImageSlice mBorderImageSlice; // factor, percent
506 mozilla::StyleBorderImageRepeat mBorderImageRepeatH;
507 mozilla::StyleBorderImageRepeat mBorderImageRepeatV;
508 mozilla::StyleFloatEdge mFloatEdge;
509 mozilla::StyleBoxDecorationBreak mBoxDecorationBreak;
511 protected:
512 mozilla::StyleBorderStyle mBorderStyle[4]; // StyleBorderStyle::*
514 public:
515 // the colors to use for a simple border.
516 // not used for -moz-border-colors
517 mozilla::StyleColor mBorderTopColor;
518 mozilla::StyleColor mBorderRightColor;
519 mozilla::StyleColor mBorderBottomColor;
520 mozilla::StyleColor mBorderLeftColor;
522 mozilla::StyleColor& BorderColorFor(mozilla::Side aSide) {
523 switch (aSide) {
524 case mozilla::eSideTop:
525 return mBorderTopColor;
526 case mozilla::eSideRight:
527 return mBorderRightColor;
528 case mozilla::eSideBottom:
529 return mBorderBottomColor;
530 case mozilla::eSideLeft:
531 return mBorderLeftColor;
533 MOZ_ASSERT_UNREACHABLE("Unknown side");
534 return mBorderTopColor;
537 const mozilla::StyleColor& BorderColorFor(mozilla::Side aSide) const {
538 switch (aSide) {
539 case mozilla::eSideTop:
540 return mBorderTopColor;
541 case mozilla::eSideRight:
542 return mBorderRightColor;
543 case mozilla::eSideBottom:
544 return mBorderBottomColor;
545 case mozilla::eSideLeft:
546 return mBorderLeftColor;
548 MOZ_ASSERT_UNREACHABLE("Unknown side");
549 return mBorderTopColor;
552 static mozilla::StyleColor nsStyleBorder::*BorderColorFieldFor(
553 mozilla::Side aSide) {
554 switch (aSide) {
555 case mozilla::eSideTop:
556 return &nsStyleBorder::mBorderTopColor;
557 case mozilla::eSideRight:
558 return &nsStyleBorder::mBorderRightColor;
559 case mozilla::eSideBottom:
560 return &nsStyleBorder::mBorderBottomColor;
561 case mozilla::eSideLeft:
562 return &nsStyleBorder::mBorderLeftColor;
564 MOZ_ASSERT_UNREACHABLE("Unknown side");
565 return nullptr;
568 nsStyleBorder& operator=(const nsStyleBorder&) = delete;
570 protected:
571 // mComputedBorder holds the CSS2.1 computed border-width values.
572 // In particular, these widths take into account the border-style
573 // for the relevant side, and the values are rounded to the nearest
574 // device pixel (which is not part of the definition of computed
575 // values). The presence or absence of a border-image does not
576 // affect border-width values.
577 nsMargin mComputedBorder;
579 // mBorder holds the nscoord values for the border widths as they
580 // would be if all the border-style values were visible (not hidden
581 // or none). This member exists so that when we create structs
582 // using the copy constructor during style resolution the new
583 // structs will know what the specified values of the border were in
584 // case they have more specific rules setting the border style.
586 // Note that this isn't quite the CSS specified value, since this
587 // has had the enumerated border widths converted to lengths, and
588 // all lengths converted to twips. But it's not quite the computed
589 // value either. The values are rounded to the nearest device pixel.
590 nsMargin mBorder;
593 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline {
594 STYLE_STRUCT(nsStyleOutline)
595 nsStyleOutline();
597 // This is the specified value of outline-width, but with length values
598 // computed to absolute. mActualOutlineWidth stores the outline-width
599 // value used by layout. (We must store mOutlineWidth for the same
600 // style struct resolution reasons that we do nsStyleBorder::mBorder;
601 // see that field's comment.)
602 nscoord mOutlineWidth;
603 mozilla::Length mOutlineOffset;
604 mozilla::StyleColor mOutlineColor;
605 mozilla::StyleOutlineStyle mOutlineStyle;
607 nscoord GetOutlineWidth() const { return mActualOutlineWidth; }
609 bool ShouldPaintOutline() const {
610 if (mOutlineStyle.IsAuto()) {
611 return true;
613 if (GetOutlineWidth() > 0) {
614 MOZ_ASSERT(
615 mOutlineStyle.AsBorderStyle() != mozilla::StyleBorderStyle::None,
616 "outline-style: none implies outline-width of zero");
617 return true;
619 return false;
622 nsSize EffectiveOffsetFor(const nsRect& aRect) const;
624 protected:
625 // The actual value of outline-width is the computed value (an absolute
626 // length, forced to zero when outline-style is none) rounded to device
627 // pixels. This is the value used by layout.
628 nscoord mActualOutlineWidth;
631 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
632 STYLE_STRUCT(nsStyleList)
633 nsStyleList();
635 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleList*);
637 nsStyleList& operator=(const nsStyleList& aOther) = delete;
638 nsChangeHint CalcDifference(const nsStyleList& aNewData,
639 const mozilla::ComputedStyle& aOldStyle) const;
641 already_AddRefed<nsIURI> GetListStyleImageURI() const;
643 mozilla::StyleListStylePosition mListStylePosition;
645 mozilla::CounterStylePtr mCounterStyle;
646 mozilla::StyleQuotes mQuotes;
647 mozilla::StyleImage mListStyleImage;
650 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePage {
651 STYLE_STRUCT(nsStylePage)
652 MOZ_COUNTED_DEFAULT_CTOR(nsStylePage)
654 using StylePageOrientation = mozilla::StylePageOrientation;
655 using StylePageSize = mozilla::StylePageSize;
656 using StylePageName = mozilla::StylePageName;
658 // page-size property.
659 StylePageSize mSize = StylePageSize::Auto();
660 // page-name property.
661 StylePageName mPage = StylePageName::Auto();
662 // page-orientation property.
663 StylePageOrientation mPageOrientation = StylePageOrientation::Upright;
666 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
667 STYLE_STRUCT(nsStylePosition)
668 nsStylePosition();
670 using LengthPercentageOrAuto = mozilla::LengthPercentageOrAuto;
671 using Position = mozilla::Position;
672 template <typename T>
673 using StyleRect = mozilla::StyleRect<T>;
674 using StyleSize = mozilla::StyleSize;
675 using StyleMaxSize = mozilla::StyleMaxSize;
676 using WritingMode = mozilla::WritingMode;
677 using LogicalAxis = mozilla::LogicalAxis;
678 using StyleImplicitGridTracks = mozilla::StyleImplicitGridTracks;
679 using ComputedStyle = mozilla::ComputedStyle;
680 using StyleAlignSelf = mozilla::StyleAlignSelf;
681 using StyleJustifySelf = mozilla::StyleJustifySelf;
683 nsChangeHint CalcDifference(const nsStylePosition& aNewData,
684 const ComputedStyle& aOldStyle) const;
686 // Returns whether we need to compute an hypothetical position if we were
687 // absolutely positioned.
688 bool NeedsHypotheticalPositionIfAbsPos() const {
689 return (mOffset.Get(mozilla::eSideRight).IsAuto() &&
690 mOffset.Get(mozilla::eSideLeft).IsAuto()) ||
691 (mOffset.Get(mozilla::eSideTop).IsAuto() &&
692 mOffset.Get(mozilla::eSideBottom).IsAuto());
695 const mozilla::StyleContainIntrinsicSize& ContainIntrinsicBSize(
696 const WritingMode& aWM) const;
697 const mozilla::StyleContainIntrinsicSize& ContainIntrinsicISize(
698 const WritingMode& aWM) const;
701 * Return the used value for 'align-self' given our parent ComputedStyle
702 * (or null for the root).
704 StyleAlignSelf UsedAlignSelf(const ComputedStyle*) const;
707 * Return the used value for 'justify-self' given our parent ComputedStyle
708 * aParent (or null for the root).
710 StyleJustifySelf UsedJustifySelf(const ComputedStyle*) const;
713 * Return the used value for 'justify/align-self' in aAxis given our parent
714 * ComputedStyle aParent (or null for the root).
715 * (defined in WritingModes.h since we need the full WritingMode type)
717 inline mozilla::StyleAlignFlags UsedSelfAlignment(
718 LogicalAxis aAxis, const mozilla::ComputedStyle* aParent) const;
721 * Return the used value for 'justify/align-content' in aAxis.
722 * (defined in WritingModes.h since we need the full WritingMode type)
724 inline mozilla::StyleContentDistribution UsedContentAlignment(
725 LogicalAxis aAxis) const;
728 * Return the used value for 'align-tracks'/'justify-tracks' for a track
729 * in the given axis.
730 * (defined in WritingModes.h since we need the full LogicalAxis type)
732 inline mozilla::StyleContentDistribution UsedTracksAlignment(
733 LogicalAxis aAxis, uint32_t aIndex) const;
735 // Each entry has the same encoding as *-content, see below.
736 mozilla::StyleAlignTracks mAlignTracks;
737 mozilla::StyleJustifyTracks mJustifyTracks;
739 Position mObjectPosition;
740 StyleRect<LengthPercentageOrAuto> mOffset;
741 StyleSize mWidth;
742 StyleSize mMinWidth;
743 StyleMaxSize mMaxWidth;
744 StyleSize mHeight;
745 StyleSize mMinHeight;
746 StyleMaxSize mMaxHeight;
747 mozilla::StyleFlexBasis mFlexBasis;
748 StyleImplicitGridTracks mGridAutoColumns;
749 StyleImplicitGridTracks mGridAutoRows;
750 mozilla::StyleAspectRatio mAspectRatio;
751 mozilla::StyleGridAutoFlow mGridAutoFlow;
752 mozilla::StyleMasonryAutoFlow mMasonryAutoFlow;
754 mozilla::StyleAlignContent mAlignContent;
755 mozilla::StyleAlignItems mAlignItems;
756 mozilla::StyleAlignSelf mAlignSelf;
757 mozilla::StyleJustifyContent mJustifyContent;
758 mozilla::StyleComputedJustifyItems mJustifyItems;
759 mozilla::StyleJustifySelf mJustifySelf;
760 mozilla::StyleFlexDirection mFlexDirection;
761 mozilla::StyleFlexWrap mFlexWrap;
762 mozilla::StyleObjectFit mObjectFit;
763 mozilla::StyleBoxSizing mBoxSizing;
764 int32_t mOrder;
765 float mFlexGrow;
766 float mFlexShrink;
767 mozilla::StyleZIndex mZIndex;
769 mozilla::StyleGridTemplateComponent mGridTemplateColumns;
770 mozilla::StyleGridTemplateComponent mGridTemplateRows;
771 mozilla::StyleGridTemplateAreas mGridTemplateAreas;
773 mozilla::StyleGridLine mGridColumnStart;
774 mozilla::StyleGridLine mGridColumnEnd;
775 mozilla::StyleGridLine mGridRowStart;
776 mozilla::StyleGridLine mGridRowEnd;
777 mozilla::NonNegativeLengthPercentageOrNormal mColumnGap;
778 mozilla::NonNegativeLengthPercentageOrNormal mRowGap;
780 mozilla::StyleContainIntrinsicSize mContainIntrinsicWidth;
781 mozilla::StyleContainIntrinsicSize mContainIntrinsicHeight;
783 // Logical-coordinate accessors for width and height properties,
784 // given a WritingMode value. The definitions of these methods are
785 // found in WritingModes.h (after the WritingMode class is fully
786 // declared).
787 inline const StyleSize& ISize(WritingMode) const;
788 inline const StyleSize& MinISize(WritingMode) const;
789 inline const StyleMaxSize& MaxISize(WritingMode) const;
790 inline const StyleSize& BSize(WritingMode) const;
791 inline const StyleSize& MinBSize(WritingMode) const;
792 inline const StyleMaxSize& MaxBSize(WritingMode) const;
793 inline const StyleSize& Size(LogicalAxis, WritingMode) const;
794 inline const StyleSize& MinSize(LogicalAxis, WritingMode) const;
795 inline const StyleMaxSize& MaxSize(LogicalAxis, WritingMode) const;
796 inline bool ISizeDependsOnContainer(WritingMode) const;
797 inline bool MinISizeDependsOnContainer(WritingMode) const;
798 inline bool MaxISizeDependsOnContainer(WritingMode) const;
799 inline bool BSizeDependsOnContainer(WritingMode) const;
800 inline bool MinBSizeDependsOnContainer(WritingMode) const;
801 inline bool MaxBSizeDependsOnContainer(WritingMode) const;
803 private:
804 template <typename SizeOrMaxSize>
805 static bool ISizeCoordDependsOnContainer(const SizeOrMaxSize& aCoord) {
806 if (aCoord.IsLengthPercentage()) {
807 return aCoord.AsLengthPercentage().HasPercent();
809 return aCoord.IsFitContent() || aCoord.IsMozAvailable();
812 template <typename SizeOrMaxSize>
813 static bool BSizeCoordDependsOnContainer(const SizeOrMaxSize& aCoord) {
814 return aCoord.IsLengthPercentage() &&
815 aCoord.AsLengthPercentage().HasPercent();
819 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
820 STYLE_STRUCT(nsStyleTextReset)
821 nsStyleTextReset();
823 // Note the difference between this and
824 // ComputedStyle::HasTextDecorationLines.
825 bool HasTextDecorationLines() const {
826 return mTextDecorationLine != mozilla::StyleTextDecorationLine::NONE &&
827 mTextDecorationLine !=
828 mozilla::StyleTextDecorationLine::COLOR_OVERRIDE;
831 mozilla::StyleTextOverflow mTextOverflow;
833 mozilla::StyleTextDecorationLine mTextDecorationLine;
834 mozilla::StyleTextDecorationStyle mTextDecorationStyle;
835 mozilla::StyleUnicodeBidi mUnicodeBidi;
836 nscoord mInitialLetterSink; // 0 means normal
837 float mInitialLetterSize; // 0.0f means normal
838 mozilla::StyleColor mTextDecorationColor;
839 mozilla::StyleTextDecorationLength mTextDecorationThickness;
842 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
843 STYLE_STRUCT(nsStyleText)
844 explicit nsStyleText(const mozilla::dom::Document&);
846 mozilla::StyleAbsoluteColor mColor;
847 mozilla::StyleForcedColorAdjust mForcedColorAdjust;
848 mozilla::StyleTextTransform mTextTransform;
849 mozilla::StyleTextAlign mTextAlign;
850 mozilla::StyleTextAlignLast mTextAlignLast;
851 mozilla::StyleTextJustify mTextJustify;
852 mozilla::StyleWhiteSpaceCollapse mWhiteSpaceCollapse =
853 mozilla::StyleWhiteSpaceCollapse::Collapse;
854 mozilla::StyleTextWrapMode mTextWrapMode = mozilla::StyleTextWrapMode::Wrap;
855 mozilla::StyleLineBreak mLineBreak = mozilla::StyleLineBreak::Auto;
857 private:
858 mozilla::StyleWordBreak mWordBreak = mozilla::StyleWordBreak::Normal;
859 mozilla::StyleOverflowWrap mOverflowWrap = mozilla::StyleOverflowWrap::Normal;
861 public:
862 mozilla::StyleHyphens mHyphens;
863 mozilla::StyleRubyAlign mRubyAlign;
864 mozilla::StyleRubyPosition mRubyPosition;
865 mozilla::StyleTextSizeAdjust mTextSizeAdjust;
866 mozilla::StyleTextCombineUpright mTextCombineUpright;
867 mozilla::StyleMozControlCharacterVisibility mMozControlCharacterVisibility;
868 mozilla::StyleTextEmphasisPosition mTextEmphasisPosition;
869 mozilla::StyleTextRendering mTextRendering;
870 mozilla::StyleColor mTextEmphasisColor;
871 mozilla::StyleColor mWebkitTextFillColor;
872 mozilla::StyleColor mWebkitTextStrokeColor;
874 mozilla::StyleNonNegativeLengthOrNumber mTabSize;
875 mozilla::LengthPercentage mWordSpacing;
876 mozilla::StyleLetterSpacing mLetterSpacing;
877 mozilla::StyleTextIndent mTextIndent;
879 mozilla::LengthPercentageOrAuto mTextUnderlineOffset;
880 mozilla::StyleTextDecorationSkipInk mTextDecorationSkipInk;
881 mozilla::StyleTextUnderlinePosition mTextUnderlinePosition;
883 mozilla::StyleAu mWebkitTextStrokeWidth;
885 mozilla::StyleArcSlice<mozilla::StyleSimpleShadow> mTextShadow;
886 mozilla::StyleTextEmphasisStyle mTextEmphasisStyle;
888 mozilla::StyleHyphenateCharacter mHyphenateCharacter =
889 mozilla::StyleHyphenateCharacter::Auto();
891 mozilla::StyleTextSecurity mWebkitTextSecurity =
892 mozilla::StyleTextSecurity::None;
894 mozilla::StyleTextWrapStyle mTextWrapStyle =
895 mozilla::StyleTextWrapStyle::Auto;
897 char16_t TextSecurityMaskChar() const {
898 switch (mWebkitTextSecurity) {
899 case mozilla::StyleTextSecurity::None:
900 return 0;
901 case mozilla::StyleTextSecurity::Circle:
902 return 0x25E6;
903 case mozilla::StyleTextSecurity::Disc:
904 return 0x2022;
905 case mozilla::StyleTextSecurity::Square:
906 return 0x25A0;
907 default:
908 MOZ_ASSERT_UNREACHABLE("unknown StyleTextSecurity value!");
909 return 0;
913 mozilla::StyleWordBreak EffectiveWordBreak() const {
914 if (mWordBreak == mozilla::StyleWordBreak::BreakWord) {
915 return mozilla::StyleWordBreak::Normal;
917 return mWordBreak;
920 mozilla::StyleOverflowWrap EffectiveOverflowWrap() const {
921 if (mWordBreak == mozilla::StyleWordBreak::BreakWord) {
922 return mozilla::StyleOverflowWrap::Anywhere;
924 return mOverflowWrap;
927 bool WhiteSpaceIsSignificant() const {
928 return mWhiteSpaceCollapse != mozilla::StyleWhiteSpaceCollapse::Collapse &&
929 mWhiteSpaceCollapse !=
930 mozilla::StyleWhiteSpaceCollapse::PreserveBreaks;
933 bool WhiteSpaceCanHangOrVisuallyCollapse() const {
934 // This was originally expressed in nsTextFrame in terms of:
935 // mWhiteSpace != StyleWhiteSpace::BreakSpaces &&
936 // WhiteSpaceCanWrapStyle() &&
937 // WhiteSpaceIsSignificant()
938 // which simplifies to:
939 return mTextWrapMode == mozilla::StyleTextWrapMode::Wrap &&
940 mWhiteSpaceCollapse != mozilla::StyleWhiteSpaceCollapse::BreakSpaces;
943 bool NewlineIsSignificantStyle() const {
944 return mWhiteSpaceCollapse == mozilla::StyleWhiteSpaceCollapse::Preserve ||
945 mWhiteSpaceCollapse ==
946 mozilla::StyleWhiteSpaceCollapse::PreserveBreaks ||
947 mWhiteSpaceCollapse == mozilla::StyleWhiteSpaceCollapse::BreakSpaces;
950 bool WhiteSpaceOrNewlineIsSignificant() const {
951 return NewlineIsSignificantStyle() || WhiteSpaceIsSignificant();
954 bool TabIsSignificant() const {
955 return mWhiteSpaceCollapse == mozilla::StyleWhiteSpaceCollapse::Preserve ||
956 mWhiteSpaceCollapse == mozilla::StyleWhiteSpaceCollapse::BreakSpaces;
959 bool WhiteSpaceCanWrapStyle() const {
960 return mTextWrapMode == mozilla::StyleTextWrapMode::Wrap;
963 bool WordCanWrapStyle() const {
964 if (!WhiteSpaceCanWrapStyle()) {
965 return false;
967 auto owrap = EffectiveOverflowWrap();
968 return owrap == mozilla::StyleOverflowWrap::BreakWord ||
969 owrap == mozilla::StyleOverflowWrap::Anywhere;
972 bool HasEffectiveTextEmphasis() const {
973 if (mTextEmphasisStyle.IsNone()) {
974 return false;
976 if (mTextEmphasisStyle.IsString() &&
977 mTextEmphasisStyle.AsString().AsString().IsEmpty()) {
978 return false;
980 return true;
983 mozilla::StyleTextAlign TextAlignForLastLine() const {
984 switch (mTextAlignLast) {
985 case mozilla::StyleTextAlignLast::Auto:
986 // 'text-align-last: auto' is equivalent to the value of the
987 // 'text-align' property except when 'text-align' is set to 'justify',
988 // in which case it is 'justify' when 'text-justify' is 'distribute' and
989 // 'start' otherwise.
991 // XXX: the code below will have to change when we implement
992 // text-justify
993 if (mTextAlign == mozilla::StyleTextAlign::Justify) {
994 return mozilla::StyleTextAlign::Start;
996 return mTextAlign;
997 case mozilla::StyleTextAlignLast::Center:
998 return mozilla::StyleTextAlign::Center;
999 case mozilla::StyleTextAlignLast::Start:
1000 return mozilla::StyleTextAlign::Start;
1001 case mozilla::StyleTextAlignLast::End:
1002 return mozilla::StyleTextAlign::End;
1003 case mozilla::StyleTextAlignLast::Left:
1004 return mozilla::StyleTextAlign::Left;
1005 case mozilla::StyleTextAlignLast::Right:
1006 return mozilla::StyleTextAlign::Right;
1007 case mozilla::StyleTextAlignLast::Justify:
1008 return mozilla::StyleTextAlign::Justify;
1010 return mozilla::StyleTextAlign::Start;
1013 bool HasWebkitTextStroke() const { return mWebkitTextStrokeWidth > 0; }
1015 bool HasTextShadow() const { return !mTextShadow.IsEmpty(); }
1017 // The aContextFrame argument on each of these is the frame this
1018 // style struct is for. If the frame is for SVG text or inside ruby,
1019 // the return value will be massaged to be something that makes sense
1020 // for those cases.
1021 inline bool NewlineIsSignificant(const nsTextFrame* aContextFrame) const;
1022 inline bool WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const;
1023 inline bool WordCanWrap(const nsIFrame* aContextFrame) const;
1025 mozilla::LogicalSide TextEmphasisSide(mozilla::WritingMode aWM) const;
1028 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility {
1029 STYLE_STRUCT(nsStyleVisibility)
1030 explicit nsStyleVisibility(const mozilla::dom::Document&);
1032 bool IsVisible() const {
1033 return mVisible == mozilla::StyleVisibility::Visible;
1036 bool IsCollapse() const {
1037 return mVisible == mozilla::StyleVisibility::Collapse;
1040 bool IsVisibleOrCollapsed() const {
1041 return mVisible == mozilla::StyleVisibility::Visible ||
1042 mVisible == mozilla::StyleVisibility::Collapse;
1045 bool UseLegacyCollapseBehavior() const {
1046 return mMozBoxCollapse == mozilla::StyleMozBoxCollapse::Legacy;
1050 * Given an image request, returns the orientation that should be used
1051 * on the image. The returned orientation may differ from the style
1052 * struct's orientation member value, if the image request is not of the
1053 * same origin.
1055 * @param aRequest The image request used to determine if same origin.
1057 mozilla::StyleImageOrientation UsedImageOrientation(
1058 imgIRequest* aRequest) const {
1059 return UsedImageOrientation(aRequest, mImageOrientation);
1063 * Given an image request and an orientation, returns the orientation
1064 * that should be used on the image. The returned orientation may differ
1065 * from the input orientation if the image request is not of the same
1066 * origin.
1068 * @param aRequest The image request used to determine if same origin.
1069 * @param aOrientation The input orientation.
1071 static mozilla::StyleImageOrientation UsedImageOrientation(
1072 imgIRequest* aRequest, mozilla::StyleImageOrientation aOrientation);
1074 mozilla::StyleDirection mDirection;
1075 mozilla::StyleVisibility mVisible;
1076 mozilla::StyleImageRendering mImageRendering;
1077 mozilla::StyleWritingModeProperty mWritingMode;
1078 mozilla::StyleTextOrientation mTextOrientation;
1079 mozilla::StyleMozBoxCollapse mMozBoxCollapse;
1080 mozilla::StylePrintColorAdjust mPrintColorAdjust;
1082 private:
1083 mozilla::StyleImageOrientation mImageOrientation;
1086 namespace mozilla {
1088 inline StyleTextTransform StyleTextTransform::None() {
1089 return StyleTextTransform{StyleTextTransformCase::None,
1090 StyleTextTransformOther()};
1093 inline bool StyleTextTransform::IsNone() const { return *this == None(); }
1095 // Note that IsAuto() does not exclude the possibility that `left` or `right`
1096 // is set; it refers only to behavior in horizontal typographic mode.
1097 inline bool StyleTextUnderlinePosition::IsAuto() const {
1098 return !(*this & (StyleTextUnderlinePosition::FROM_FONT |
1099 StyleTextUnderlinePosition::UNDER));
1101 inline bool StyleTextUnderlinePosition::IsFromFont() const {
1102 return bool(*this & StyleTextUnderlinePosition::FROM_FONT);
1104 inline bool StyleTextUnderlinePosition::IsUnder() const {
1105 return bool(*this & StyleTextUnderlinePosition::UNDER);
1107 inline bool StyleTextUnderlinePosition::IsLeft() const {
1108 return bool(*this & StyleTextUnderlinePosition::LEFT);
1110 inline bool StyleTextUnderlinePosition::IsRight() const {
1111 return bool(*this & StyleTextUnderlinePosition::RIGHT);
1114 struct StyleTransition {
1115 StyleTransition() = default;
1116 explicit StyleTransition(const StyleTransition& aCopy);
1117 const StyleComputedTimingFunction& GetTimingFunction() const {
1118 return mTimingFunction;
1120 const StyleTime& GetDelay() const { return mDelay; }
1121 const StyleTime& GetDuration() const { return mDuration; }
1122 const StyleTransitionProperty& GetProperty() const { return mProperty; }
1123 StyleTransitionBehavior GetBehavior() const { return mBehavior; }
1125 bool operator==(const StyleTransition& aOther) const;
1126 bool operator!=(const StyleTransition& aOther) const {
1127 return !(*this == aOther);
1130 private:
1131 StyleComputedTimingFunction mTimingFunction{
1132 StyleComputedTimingFunction::Keyword(StyleTimingKeyword::Ease)};
1133 StyleTime mDuration{0.0};
1134 StyleTime mDelay{0.0};
1135 StyleTransitionProperty mProperty{StyleTransitionProperty::NonCustom(
1136 StyleNonCustomPropertyId{uint16_t(eCSSProperty_all)})};
1137 StyleTransitionBehavior mBehavior = StyleTransitionBehavior::Normal;
1140 struct StyleAnimation {
1141 StyleAnimation() = default;
1142 explicit StyleAnimation(const StyleAnimation& aCopy);
1144 const StyleComputedTimingFunction& GetTimingFunction() const {
1145 return mTimingFunction;
1147 const StyleTime& GetDelay() const { return mDelay; }
1148 const StyleTime& GetDuration() const { return mDuration; }
1149 nsAtom* GetName() const { return mName._0.AsAtom(); }
1150 StyleAnimationDirection GetDirection() const { return mDirection; }
1151 StyleAnimationFillMode GetFillMode() const { return mFillMode; }
1152 StyleAnimationPlayState GetPlayState() const { return mPlayState; }
1153 float GetIterationCount() const { return mIterationCount._0; }
1154 StyleAnimationComposition GetComposition() const { return mComposition; }
1155 const StyleAnimationTimeline& GetTimeline() const { return mTimeline; }
1157 bool operator==(const StyleAnimation& aOther) const;
1158 bool operator!=(const StyleAnimation& aOther) const {
1159 return !(*this == aOther);
1162 private:
1163 StyleComputedTimingFunction mTimingFunction{
1164 StyleComputedTimingFunction::Keyword(StyleTimingKeyword::Ease)};
1165 StyleTime mDuration{0.0f};
1166 StyleTime mDelay{0.0f};
1167 StyleAnimationName mName;
1168 StyleAnimationDirection mDirection = StyleAnimationDirection::Normal;
1169 StyleAnimationFillMode mFillMode = StyleAnimationFillMode::None;
1170 StyleAnimationPlayState mPlayState = StyleAnimationPlayState::Running;
1171 StyleAnimationIterationCount mIterationCount{1.0f};
1172 StyleAnimationComposition mComposition = StyleAnimationComposition::Replace;
1173 StyleAnimationTimeline mTimeline{StyleAnimationTimeline::Auto()};
1176 struct StyleScrollTimeline {
1177 StyleScrollTimeline() = default;
1178 explicit StyleScrollTimeline(const StyleScrollTimeline& aCopy) = default;
1180 nsAtom* GetName() const { return mName._0.AsAtom(); }
1181 StyleScrollAxis GetAxis() const { return mAxis; }
1183 bool operator==(const StyleScrollTimeline& aOther) const {
1184 return mName == aOther.mName && mAxis == aOther.mAxis;
1186 bool operator!=(const StyleScrollTimeline& aOther) const {
1187 return !(*this == aOther);
1190 private:
1191 StyleScrollTimelineName mName;
1192 StyleScrollAxis mAxis = StyleScrollAxis::Block;
1195 struct StyleViewTimeline {
1196 StyleViewTimeline() = default;
1197 explicit StyleViewTimeline(const StyleViewTimeline& aCopy) = default;
1199 nsAtom* GetName() const { return mName._0.AsAtom(); }
1200 StyleScrollAxis GetAxis() const { return mAxis; }
1201 const StyleViewTimelineInset& GetInset() const { return mInset; }
1203 bool operator==(const StyleViewTimeline& aOther) const {
1204 return mName == aOther.mName && mAxis == aOther.mAxis &&
1205 mInset == aOther.mInset;
1207 bool operator!=(const StyleViewTimeline& aOther) const {
1208 return !(*this == aOther);
1211 private:
1212 StyleScrollTimelineName mName;
1213 StyleScrollAxis mAxis = StyleScrollAxis::Block;
1214 StyleViewTimelineInset mInset;
1217 } // namespace mozilla
1219 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
1220 STYLE_STRUCT(nsStyleDisplay)
1221 nsStyleDisplay();
1222 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleDisplay*);
1224 using StyleContain = mozilla::StyleContain;
1225 using StyleContentVisibility = mozilla::StyleContentVisibility;
1227 nsChangeHint CalcDifference(const nsStyleDisplay& aNewData,
1228 const mozilla::ComputedStyle& aOldStyle) const;
1230 nsChangeHint CalcTransformPropertyDifference(
1231 const nsStyleDisplay& aNewData) const;
1233 mozilla::StyleDisplay mDisplay;
1234 // Saved mDisplay for position:absolute/fixed and float:left/right; otherwise
1235 // equal to mDisplay.
1236 mozilla::StyleDisplay mOriginalDisplay;
1237 // Equal to mContain plus any implicit containment from mContentVisibility and
1238 // mContainerType.
1239 mozilla::StyleContentVisibility mContentVisibility;
1240 mozilla::StyleContainerType mContainerType;
1242 bool IsQueryContainer() const {
1243 return mContainerType != mozilla::StyleContainerType::Normal;
1246 private:
1247 mozilla::StyleAppearance mAppearance;
1248 mozilla::StyleContain mContain;
1249 // Equal to mContain plus any implicit containment from mContentVisibility and
1250 // mContainerType.
1251 mozilla::StyleContain mEffectiveContainment;
1253 public:
1254 mozilla::StyleAppearance mDefaultAppearance;
1255 mozilla::StylePositionProperty mPosition;
1257 mozilla::StyleFloat mFloat;
1258 mozilla::StyleClear mClear;
1259 mozilla::StyleBreakWithin mBreakInside;
1260 mozilla::StyleBreakBetween mBreakBefore;
1261 mozilla::StyleBreakBetween mBreakAfter;
1262 mozilla::StyleOverflow mOverflowX;
1263 mozilla::StyleOverflow mOverflowY;
1264 mozilla::StyleOverflowClipBox mOverflowClipBoxBlock;
1265 mozilla::StyleOverflowClipBox mOverflowClipBoxInline;
1266 mozilla::StyleScrollbarGutter mScrollbarGutter;
1267 mozilla::StyleResize mResize;
1268 mozilla::StyleOrient mOrient;
1269 mozilla::StyleIsolation mIsolation;
1270 mozilla::StyleTopLayer mTopLayer;
1272 mozilla::StyleTouchAction mTouchAction;
1273 mozilla::StyleScrollBehavior mScrollBehavior;
1274 mozilla::StyleOverscrollBehavior mOverscrollBehaviorX;
1275 mozilla::StyleOverscrollBehavior mOverscrollBehaviorY;
1276 mozilla::StyleOverflowAnchor mOverflowAnchor;
1277 mozilla::StyleScrollSnapAlign mScrollSnapAlign;
1278 mozilla::StyleScrollSnapStop mScrollSnapStop;
1279 mozilla::StyleScrollSnapType mScrollSnapType;
1281 mozilla::StyleBackfaceVisibility mBackfaceVisibility;
1282 mozilla::StyleTransformStyle mTransformStyle;
1283 mozilla::StyleTransformBox mTransformBox;
1285 mozilla::StyleTransform mTransform;
1286 mozilla::StyleRotate mRotate;
1288 mozilla::StyleTranslate mTranslate;
1289 mozilla::StyleScale mScale;
1291 mozilla::StyleContainerName mContainerName;
1292 mozilla::StyleWillChange mWillChange;
1294 mozilla::StyleOffsetPath mOffsetPath;
1295 mozilla::LengthPercentage mOffsetDistance;
1296 mozilla::StyleOffsetRotate mOffsetRotate;
1297 mozilla::StylePositionOrAuto mOffsetAnchor;
1298 mozilla::StyleOffsetPosition mOffsetPosition;
1300 mozilla::StyleTransformOrigin mTransformOrigin;
1301 mozilla::StylePerspective mChildPerspective;
1302 mozilla::Position mPerspectiveOrigin;
1304 mozilla::StyleVerticalAlign mVerticalAlign;
1305 mozilla::StyleBaselineSource mBaselineSource;
1307 mozilla::StyleLineClamp mWebkitLineClamp;
1309 // The threshold used for extracting a shape from shape-outside: <image>.
1310 float mShapeImageThreshold = 0.0f;
1312 mozilla::StyleZoom mZoom = mozilla::StyleZoom::ONE;
1314 // The margin around a shape-outside: <image>.
1315 mozilla::NonNegativeLengthPercentage mShapeMargin;
1317 mozilla::StyleShapeOutside mShapeOutside;
1319 mozilla::Maybe<mozilla::WindowButtonType> GetWindowButtonType() const {
1320 if (MOZ_LIKELY(mDefaultAppearance == mozilla::StyleAppearance::None)) {
1321 return mozilla::Nothing();
1323 switch (mDefaultAppearance) {
1324 case mozilla::StyleAppearance::MozWindowButtonMaximize:
1325 case mozilla::StyleAppearance::MozWindowButtonRestore:
1326 return Some(mozilla::WindowButtonType::Maximize);
1327 case mozilla::StyleAppearance::MozWindowButtonMinimize:
1328 return Some(mozilla::WindowButtonType::Minimize);
1329 case mozilla::StyleAppearance::MozWindowButtonClose:
1330 return Some(mozilla::WindowButtonType::Close);
1331 default:
1332 return mozilla::Nothing();
1336 bool HasAppearance() const {
1337 return EffectiveAppearance() != mozilla::StyleAppearance::None;
1340 mozilla::StyleAppearance EffectiveAppearance() const {
1341 if (MOZ_LIKELY(mAppearance == mozilla::StyleAppearance::None)) {
1342 return mAppearance;
1344 switch (mAppearance) {
1345 case mozilla::StyleAppearance::Auto:
1346 case mozilla::StyleAppearance::Button:
1347 case mozilla::StyleAppearance::Searchfield:
1348 case mozilla::StyleAppearance::Textarea:
1349 case mozilla::StyleAppearance::Checkbox:
1350 case mozilla::StyleAppearance::Radio:
1351 case mozilla::StyleAppearance::Menulist:
1352 case mozilla::StyleAppearance::Listbox:
1353 case mozilla::StyleAppearance::Meter:
1354 case mozilla::StyleAppearance::ProgressBar:
1355 // These are all the values that behave like `auto`.
1356 return mDefaultAppearance;
1357 case mozilla::StyleAppearance::Textfield:
1358 // `appearance: textfield` should behave like `auto` on all elements
1359 // except <input type=search> elements, which we identify using the
1360 // internal -moz-default-appearance property. (In the browser chrome
1361 // we have some other elements that set `-moz-default-appearance:
1362 // searchfield`, but not in content documents.)
1363 if (mDefaultAppearance == mozilla::StyleAppearance::Searchfield) {
1364 return mAppearance;
1366 // We also need to support `appearance: textfield` on <input
1367 // type=number>, since that is the only way in Gecko to disable the
1368 // spinners.
1369 if (mDefaultAppearance == mozilla::StyleAppearance::NumberInput) {
1370 return mAppearance;
1372 return mDefaultAppearance;
1373 case mozilla::StyleAppearance::MenulistButton:
1374 // `appearance: menulist-button` should behave like `auto` on all
1375 // elements except for drop down selects, but since we have very little
1376 // difference between menulist and menulist-button handling, we don't
1377 // bother.
1378 return mDefaultAppearance;
1379 default:
1380 return mAppearance;
1384 mozilla::StyleDisplayOutside DisplayOutside() const {
1385 return mDisplay.Outside();
1387 mozilla::StyleDisplayInside DisplayInside() const {
1388 return mDisplay.Inside();
1390 bool IsListItem() const { return mDisplay.IsListItem(); }
1391 bool IsInlineFlow() const { return mDisplay.IsInlineFlow(); }
1393 bool IsInlineInsideStyle() const { return mDisplay.IsInlineInside(); }
1395 bool IsBlockOutsideStyle() const {
1396 return DisplayOutside() == mozilla::StyleDisplayOutside::Block;
1399 bool IsInlineOutsideStyle() const { return mDisplay.IsInlineOutside(); }
1401 bool IsOriginalDisplayInlineOutside() const {
1402 return mOriginalDisplay.IsInlineOutside();
1405 bool IsInnerTableStyle() const { return mDisplay.IsInternalTable(); }
1407 bool IsInternalTableStyleExceptCell() const {
1408 return mDisplay.IsInternalTableExceptCell();
1411 bool IsFloatingStyle() const { return mozilla::StyleFloat::None != mFloat; }
1413 bool IsPositionedStyle() const {
1414 return mPosition != mozilla::StylePositionProperty::Static ||
1415 (mWillChange.bits & mozilla::StyleWillChangeBits::POSITION);
1418 bool IsAbsolutelyPositionedStyle() const {
1419 return mozilla::StylePositionProperty::Absolute == mPosition ||
1420 mozilla::StylePositionProperty::Fixed == mPosition;
1423 bool IsRelativelyOrStickyPositionedStyle() const {
1424 return mozilla::StylePositionProperty::Relative == mPosition ||
1425 mozilla::StylePositionProperty::Sticky == mPosition;
1427 bool IsRelativelyPositionedStyle() const {
1428 return mozilla::StylePositionProperty::Relative == mPosition;
1430 bool IsStickyPositionedStyle() const {
1431 return mozilla::StylePositionProperty::Sticky == mPosition;
1433 bool IsPositionForcingStackingContext() const {
1434 return mozilla::StylePositionProperty::Sticky == mPosition ||
1435 mozilla::StylePositionProperty::Fixed == mPosition;
1438 bool IsRubyDisplayType() const { return mDisplay.IsRuby(); }
1440 bool IsInternalRubyDisplayType() const { return mDisplay.IsInternalRuby(); }
1442 bool IsOutOfFlowStyle() const {
1443 return (IsAbsolutelyPositionedStyle() || IsFloatingStyle());
1446 bool IsScrollableOverflow() const {
1447 // Visible and Clip can be combined but not with other values,
1448 // so checking mOverflowX is enough.
1449 return mOverflowX != mozilla::StyleOverflow::Visible &&
1450 mOverflowX != mozilla::StyleOverflow::Clip;
1453 bool OverflowIsVisibleInBothAxis() const {
1454 return mOverflowX == mozilla::StyleOverflow::Visible &&
1455 mOverflowY == mozilla::StyleOverflow::Visible;
1458 bool IsContainPaint() const {
1459 // Short circuit for no containment whatsoever
1460 if (!mEffectiveContainment) {
1461 return false;
1463 return (mEffectiveContainment & StyleContain::PAINT) &&
1464 !IsInternalRubyDisplayType() && !IsInternalTableStyleExceptCell();
1467 bool IsContainLayout() const {
1468 // Short circuit for no containment whatsoever
1469 if (!mEffectiveContainment) {
1470 return false;
1472 // Note: The spec for layout containment says it should
1473 // have no effect on non-atomic, inline-level boxes. We
1474 // don't check for these here because we don't know
1475 // what type of element is involved. Callers are
1476 // responsible for checking if the box in question is
1477 // non-atomic and inline-level, and creating an
1478 // exemption as necessary.
1479 return (mEffectiveContainment & StyleContain::LAYOUT) &&
1480 !IsInternalRubyDisplayType() && !IsInternalTableStyleExceptCell();
1483 bool IsContainStyle() const {
1484 return !!(mEffectiveContainment & StyleContain::STYLE);
1487 bool IsContainAny() const { return !!mEffectiveContainment; }
1489 // This is similar to PrecludesSizeContainmentOrContentVisibility, but also
1490 // takes into account whether or not the given frame is a non-atomic,
1491 // inline-level box.
1492 bool PrecludesSizeContainmentOrContentVisibilityWithFrame(
1493 const nsIFrame&) const;
1495 StyleContentVisibility ContentVisibility(const nsIFrame&) const;
1497 /* Returns whether the element has the transform property or a related
1498 * property. */
1499 bool HasTransformStyle() const {
1500 return HasTransformProperty() || HasIndividualTransform() ||
1501 mTransformStyle == mozilla::StyleTransformStyle::Preserve3d ||
1502 (mWillChange.bits & mozilla::StyleWillChangeBits::TRANSFORM) ||
1503 !mOffsetPath.IsNone();
1506 bool HasTransformProperty() const { return !mTransform._0.IsEmpty(); }
1508 bool HasIndividualTransform() const {
1509 return !mRotate.IsNone() || !mTranslate.IsNone() || !mScale.IsNone();
1512 bool HasPerspectiveStyle() const { return !mChildPerspective.IsNone(); }
1514 bool BackfaceIsHidden() const {
1515 return mBackfaceVisibility == mozilla::StyleBackfaceVisibility::Hidden;
1518 // FIXME(emilio): This should be more fine-grained on each caller to
1519 // BreakBefore() / BreakAfter().
1520 static bool ShouldBreak(mozilla::StyleBreakBetween aBreak) {
1521 switch (aBreak) {
1522 case mozilla::StyleBreakBetween::Left:
1523 case mozilla::StyleBreakBetween::Right:
1524 case mozilla::StyleBreakBetween::Page:
1525 case mozilla::StyleBreakBetween::Always:
1526 return true;
1527 case mozilla::StyleBreakBetween::Auto:
1528 case mozilla::StyleBreakBetween::Avoid:
1529 return false;
1530 default:
1531 MOZ_ASSERT_UNREACHABLE("Unknown break kind");
1532 return false;
1536 bool BreakBefore() const { return ShouldBreak(mBreakBefore); }
1538 bool BreakAfter() const { return ShouldBreak(mBreakAfter); }
1540 // These are defined in nsStyleStructInlines.h.
1542 // The aContextFrame argument on each of these is the frame this
1543 // style struct is for. If the frame is for SVG text, the return
1544 // value will be massaged to be something that makes sense for
1545 // SVG text.
1546 inline bool IsBlockOutside(const nsIFrame* aContextFrame) const;
1547 inline bool IsInlineOutside(const nsIFrame* aContextFrame) const;
1548 inline mozilla::StyleDisplay GetDisplay(const nsIFrame* aContextFrame) const;
1549 inline bool IsFloating(const nsIFrame* aContextFrame) const;
1550 inline bool IsRelativelyOrStickyPositioned(
1551 const nsIFrame* aContextFrame) const;
1553 // Note: In general, you'd want to call IsRelativelyOrStickyPositioned()
1554 // unless you want to deal with "position:relative" and "position:sticky"
1555 // differently.
1556 inline bool IsRelativelyPositioned(const nsIFrame* aContextFrame) const;
1557 inline bool IsStickyPositioned(const nsIFrame* aContextFrame) const;
1559 inline bool IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const;
1561 // These methods are defined in nsStyleStructInlines.h.
1564 * Returns true when the element has the transform property
1565 * or a related property, and supports CSS transforms.
1566 * aContextFrame is the frame for which this is the nsStyleDisplay.
1568 inline bool HasTransform(const nsIFrame* aContextFrame) const;
1571 * Returns true when the element has the perspective property,
1572 * and supports CSS transforms. aContextFrame is the frame for
1573 * which this is the nsStyleDisplay.
1575 inline bool HasPerspective(const nsIFrame* aContextFrame) const;
1577 inline bool
1578 IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const;
1579 inline bool IsFixedPosContainingBlockForTransformSupportingFrames() const;
1581 mozilla::ContainSizeAxes GetContainSizeAxes(const nsIFrame& aFrame) const;
1584 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTable {
1585 STYLE_STRUCT(nsStyleTable)
1586 nsStyleTable();
1588 mozilla::StyleTableLayout mLayoutStrategy;
1589 int32_t mXSpan; // The number of columns spanned by a colgroup or col
1592 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTableBorder {
1593 STYLE_STRUCT(nsStyleTableBorder)
1594 nsStyleTableBorder();
1596 nscoord mBorderSpacingCol;
1597 nscoord mBorderSpacingRow;
1598 mozilla::StyleBorderCollapse mBorderCollapse;
1599 mozilla::StyleCaptionSide mCaptionSide;
1600 mozilla::StyleEmptyCells mEmptyCells;
1603 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent {
1604 STYLE_STRUCT(nsStyleContent)
1605 nsStyleContent();
1606 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleContent*);
1608 using CounterPair = mozilla::StyleGenericCounterPair<int32_t>;
1610 size_t ContentCount() const {
1611 return mContent.IsItems() ? mContent.AsItems().Length() : 0;
1614 const mozilla::StyleContentItem& ContentAt(size_t aIndex) const {
1615 return mContent.AsItems().AsSpan()[aIndex];
1618 mozilla::StyleContent mContent;
1619 mozilla::StyleCounterIncrement mCounterIncrement;
1620 mozilla::StyleCounterReset mCounterReset;
1621 mozilla::StyleCounterSet mCounterSet;
1624 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset {
1625 STYLE_STRUCT(nsStyleUIReset)
1626 nsStyleUIReset();
1628 private:
1629 mozilla::StyleUserSelect mUserSelect; // Use ComputedStyle::UserSelect()
1630 mozilla::StyleScrollbarWidth mScrollbarWidth; // Use ScrollbarWidth()
1632 public:
1633 mozilla::StyleUserSelect ComputedUserSelect() const { return mUserSelect; }
1635 mozilla::StyleScrollbarWidth ScrollbarWidth() const;
1637 const mozilla::StyleTransitionProperty& GetTransitionProperty(
1638 uint32_t aIndex) const {
1639 return mTransitions[aIndex % mTransitionPropertyCount].GetProperty();
1641 const mozilla::StyleTime& GetTransitionDelay(uint32_t aIndex) const {
1642 return mTransitions[aIndex % mTransitionDelayCount].GetDelay();
1644 const mozilla::StyleTime& GetTransitionDuration(uint32_t aIndex) const {
1645 return mTransitions[aIndex % mTransitionDurationCount].GetDuration();
1647 const mozilla::StyleComputedTimingFunction& GetTransitionTimingFunction(
1648 uint32_t aIndex) const {
1649 return mTransitions[aIndex % mTransitionTimingFunctionCount]
1650 .GetTimingFunction();
1652 mozilla::StyleTransitionBehavior GetTransitionBehavior(
1653 uint32_t aIndex) const {
1654 return mTransitions[aIndex % mTransitionBehaviorCount].GetBehavior();
1656 mozilla::StyleTime GetTransitionCombinedDuration(uint32_t aIndex) const {
1657 // https://drafts.csswg.org/css-transitions/#transition-combined-duration
1658 return {std::max(GetTransitionDuration(aIndex).seconds, 0.0f) +
1659 GetTransitionDelay(aIndex).seconds};
1662 nsAtom* GetAnimationName(uint32_t aIndex) const {
1663 return mAnimations[aIndex % mAnimationNameCount].GetName();
1665 const mozilla::StyleTime& GetAnimationDelay(uint32_t aIndex) const {
1666 return mAnimations[aIndex % mAnimationDelayCount].GetDelay();
1668 const mozilla::StyleTime& GetAnimationDuration(uint32_t aIndex) const {
1669 return mAnimations[aIndex % mAnimationDurationCount].GetDuration();
1671 mozilla::StyleAnimationDirection GetAnimationDirection(
1672 uint32_t aIndex) const {
1673 return mAnimations[aIndex % mAnimationDirectionCount].GetDirection();
1675 mozilla::StyleAnimationFillMode GetAnimationFillMode(uint32_t aIndex) const {
1676 return mAnimations[aIndex % mAnimationFillModeCount].GetFillMode();
1678 mozilla::StyleAnimationPlayState GetAnimationPlayState(
1679 uint32_t aIndex) const {
1680 return mAnimations[aIndex % mAnimationPlayStateCount].GetPlayState();
1682 float GetAnimationIterationCount(uint32_t aIndex) const {
1683 return mAnimations[aIndex % mAnimationIterationCountCount]
1684 .GetIterationCount();
1686 const mozilla::StyleComputedTimingFunction& GetAnimationTimingFunction(
1687 uint32_t aIndex) const {
1688 return mAnimations[aIndex % mAnimationTimingFunctionCount]
1689 .GetTimingFunction();
1691 mozilla::StyleAnimationComposition GetAnimationComposition(
1692 uint32_t aIndex) const {
1693 return mAnimations[aIndex % mAnimationCompositionCount].GetComposition();
1695 const mozilla::StyleAnimationTimeline& GetTimeline(uint32_t aIndex) const {
1696 return mAnimations[aIndex % mAnimationTimelineCount].GetTimeline();
1699 mozilla::StyleBoolInteger mMozForceBrokenImageIcon;
1700 mozilla::StyleBoolInteger mMozSubtreeHiddenOnlyVisually;
1701 mozilla::StyleImeMode mIMEMode;
1702 mozilla::StyleWindowDragging mWindowDragging;
1703 mozilla::StyleWindowShadow mWindowShadow;
1704 float mWindowOpacity;
1705 // The margin of the window region that should be transparent to events.
1706 mozilla::StyleLength mMozWindowInputRegionMargin;
1707 mozilla::StyleTransform mMozWindowTransform;
1708 mozilla::StyleTransformOrigin mWindowTransformOrigin;
1710 nsStyleAutoArray<mozilla::StyleTransition> mTransitions;
1711 // The number of elements in mTransitions that are not from repeating
1712 // a list due to another property being longer.
1713 uint32_t mTransitionTimingFunctionCount;
1714 uint32_t mTransitionDurationCount;
1715 uint32_t mTransitionDelayCount;
1716 uint32_t mTransitionPropertyCount;
1717 uint32_t mTransitionBehaviorCount;
1718 nsStyleAutoArray<mozilla::StyleAnimation> mAnimations;
1719 // The number of elements in mAnimations that are not from repeating
1720 // a list due to another property being longer.
1721 uint32_t mAnimationTimingFunctionCount;
1722 uint32_t mAnimationDurationCount;
1723 uint32_t mAnimationDelayCount;
1724 uint32_t mAnimationNameCount;
1725 uint32_t mAnimationDirectionCount;
1726 uint32_t mAnimationFillModeCount;
1727 uint32_t mAnimationPlayStateCount;
1728 uint32_t mAnimationIterationCountCount;
1729 uint32_t mAnimationCompositionCount;
1730 uint32_t mAnimationTimelineCount;
1732 nsStyleAutoArray<mozilla::StyleScrollTimeline> mScrollTimelines;
1733 uint32_t mScrollTimelineNameCount;
1734 uint32_t mScrollTimelineAxisCount;
1736 nsStyleAutoArray<mozilla::StyleViewTimeline> mViewTimelines;
1737 uint32_t mViewTimelineNameCount;
1738 uint32_t mViewTimelineAxisCount;
1739 uint32_t mViewTimelineInsetCount;
1742 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI {
1743 STYLE_STRUCT(nsStyleUI)
1744 nsStyleUI();
1745 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleUI*);
1747 mozilla::StyleInert mInert;
1748 mozilla::StyleMozTheme mMozTheme;
1750 private:
1751 mozilla::StyleUserInput mUserInput;
1752 mozilla::StyleUserModify mUserModify;
1753 mozilla::StyleUserFocus mUserFocus;
1754 mozilla::StylePointerEvents mPointerEvents;
1755 mozilla::StyleCursor mCursor;
1757 public:
1758 bool IsInert() const { return mInert == mozilla::StyleInert::Inert; }
1760 mozilla::StyleUserInput UserInput() const {
1761 return IsInert() ? mozilla::StyleUserInput::None : mUserInput;
1764 mozilla::StyleUserModify UserModify() const {
1765 return IsInert() ? mozilla::StyleUserModify::ReadOnly : mUserModify;
1768 mozilla::StyleUserFocus UserFocus() const {
1769 return IsInert() ? mozilla::StyleUserFocus::None : mUserFocus;
1772 // This is likely not the getter you want (you probably want
1773 // ComputedStyle::PointerEvents().
1774 mozilla::StylePointerEvents ComputedPointerEvents() const {
1775 return mPointerEvents;
1778 const mozilla::StyleCursor& Cursor() const {
1779 static mozilla::StyleCursor sAuto{{}, mozilla::StyleCursorKind::Auto};
1780 return IsInert() ? sAuto : mCursor;
1783 mozilla::StyleColorOrAuto mAccentColor;
1784 mozilla::StyleCaretColor mCaretColor;
1785 mozilla::StyleScrollbarColor mScrollbarColor;
1786 mozilla::StyleColorScheme mColorScheme;
1788 bool HasCustomScrollbars() const { return !mScrollbarColor.IsAuto(); }
1791 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL {
1792 STYLE_STRUCT(nsStyleXUL)
1793 nsStyleXUL();
1795 float mBoxFlex;
1796 int32_t mBoxOrdinal;
1797 mozilla::StyleBoxAlign mBoxAlign;
1798 mozilla::StyleBoxDirection mBoxDirection;
1799 mozilla::StyleBoxOrient mBoxOrient;
1800 mozilla::StyleBoxPack mBoxPack;
1803 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn {
1804 STYLE_STRUCT(nsStyleColumn)
1805 nsStyleColumn();
1807 // This is the maximum number of columns we can process. It's used in
1808 // nsColumnSetFrame.
1809 static const uint32_t kMaxColumnCount = 1000;
1811 // This represents the value of column-count: auto.
1812 static const uint32_t kColumnCountAuto = 0;
1814 uint32_t mColumnCount = kColumnCountAuto;
1815 mozilla::NonNegativeLengthOrAuto mColumnWidth;
1817 mozilla::StyleColor mColumnRuleColor;
1818 mozilla::StyleBorderStyle mColumnRuleStyle; // StyleborderStyle::*
1819 mozilla::StyleColumnFill mColumnFill = mozilla::StyleColumnFill::Balance;
1820 mozilla::StyleColumnSpan mColumnSpan = mozilla::StyleColumnSpan::None;
1822 nscoord GetColumnRuleWidth() const { return mActualColumnRuleWidth; }
1824 bool IsColumnContainerStyle() const {
1825 return mColumnCount != kColumnCountAuto || !mColumnWidth.IsAuto();
1828 bool IsColumnSpanStyle() const {
1829 return mColumnSpan == mozilla::StyleColumnSpan::All;
1832 protected:
1833 // This is the specified value of column-rule-width, but with length values
1834 // computed to absolute. mActualColumnRuleWidth stores the column-rule-width
1835 // value used by layout. (We must store mColumnRuleWidth for the same
1836 // style struct resolution reasons that we do nsStyleBorder::mBorder;
1837 // see that field's comment.)
1838 nscoord mColumnRuleWidth;
1839 // The actual value of column-rule-width is the computed value (an absolute
1840 // length, forced to zero when column-rule-style is none) rounded to device
1841 // pixels. This is the value used by layout.
1842 nscoord mActualColumnRuleWidth;
1845 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG {
1846 STYLE_STRUCT(nsStyleSVG)
1847 nsStyleSVG();
1849 mozilla::StyleSVGPaint mFill;
1850 mozilla::StyleSVGPaint mStroke;
1851 mozilla::StyleUrlOrNone mMarkerEnd;
1852 mozilla::StyleUrlOrNone mMarkerMid;
1853 mozilla::StyleUrlOrNone mMarkerStart;
1854 mozilla::StyleMozContextProperties mMozContextProperties;
1856 mozilla::StyleSVGStrokeDashArray mStrokeDasharray;
1857 mozilla::StyleSVGLength mStrokeDashoffset;
1858 mozilla::StyleSVGWidth mStrokeWidth;
1860 mozilla::StyleSVGOpacity mFillOpacity;
1861 float mStrokeMiterlimit;
1862 mozilla::StyleSVGOpacity mStrokeOpacity;
1864 mozilla::StyleFillRule mClipRule;
1865 mozilla::StyleColorInterpolation mColorInterpolation;
1866 mozilla::StyleColorInterpolation mColorInterpolationFilters;
1867 mozilla::StyleFillRule mFillRule;
1868 mozilla::StyleSVGPaintOrder mPaintOrder;
1869 mozilla::StyleShapeRendering mShapeRendering;
1870 mozilla::StyleStrokeLinecap mStrokeLinecap;
1871 mozilla::StyleStrokeLinejoin mStrokeLinejoin;
1872 mozilla::StyleDominantBaseline mDominantBaseline;
1873 mozilla::StyleTextAnchor mTextAnchor;
1875 /// Returns true if style has been set to expose the computed values of
1876 /// certain properties (such as 'fill') to the contents of any linked images.
1877 bool ExposesContextProperties() const {
1878 return bool(mMozContextProperties.bits);
1881 bool HasMarker() const {
1882 return mMarkerStart.IsUrl() || mMarkerMid.IsUrl() || mMarkerEnd.IsUrl();
1886 * Returns true if the stroke is not "none" and the stroke-opacity is greater
1887 * than zero (or a context-dependent value).
1889 * This ignores stroke-widths as that depends on the context.
1891 bool HasStroke() const {
1892 if (mStroke.kind.IsNone()) {
1893 return false;
1895 return !mStrokeOpacity.IsOpacity() || mStrokeOpacity.AsOpacity() > 0;
1899 * Returns true if the fill is not "none" and the fill-opacity is greater
1900 * than zero (or a context-dependent value).
1902 bool HasFill() const {
1903 if (mFill.kind.IsNone()) {
1904 return false;
1906 return !mFillOpacity.IsOpacity() || mFillOpacity.AsOpacity() > 0;
1910 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset {
1911 STYLE_STRUCT(nsStyleSVGReset)
1912 nsStyleSVGReset();
1913 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleSVGReset*);
1915 bool HasClipPath() const { return !mClipPath.IsNone(); }
1917 bool HasMask() const;
1919 bool HasNonScalingStroke() const {
1920 return mVectorEffect == mozilla::StyleVectorEffect::NonScalingStroke;
1923 // geometry properties
1924 mozilla::LengthPercentage mX;
1925 mozilla::LengthPercentage mY;
1926 mozilla::LengthPercentage mCx;
1927 mozilla::LengthPercentage mCy;
1928 mozilla::NonNegativeLengthPercentageOrAuto mRx;
1929 mozilla::NonNegativeLengthPercentageOrAuto mRy;
1930 mozilla::NonNegativeLengthPercentage mR;
1932 nsStyleImageLayers mMask;
1933 mozilla::StyleClipPath mClipPath;
1934 mozilla::StyleColor mStopColor;
1935 mozilla::StyleColor mFloodColor;
1936 mozilla::StyleColor mLightingColor;
1938 float mStopOpacity;
1939 float mFloodOpacity;
1941 mozilla::StyleVectorEffect mVectorEffect;
1942 mozilla::StyleMaskType mMaskType;
1944 mozilla::StyleDProperty mD;
1947 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects {
1948 STYLE_STRUCT(nsStyleEffects)
1949 nsStyleEffects();
1951 bool HasFilters() const { return !mFilters.IsEmpty(); }
1953 bool HasBackdropFilters() const { return !mBackdropFilters.IsEmpty(); }
1955 bool HasBoxShadowWithInset(bool aInset) const {
1956 for (const auto& shadow : mBoxShadow.AsSpan()) {
1957 if (shadow.inset == aInset) {
1958 return true;
1961 return false;
1964 bool HasMixBlendMode() const {
1965 return mMixBlendMode != mozilla::StyleBlend::Normal;
1968 bool IsOpaque() const { return mOpacity >= 1.0f; }
1970 bool IsTransparent() const { return mOpacity == 0.0f; }
1972 mozilla::StyleOwnedSlice<mozilla::StyleFilter> mFilters;
1973 mozilla::StyleOwnedSlice<mozilla::StyleBoxShadow> mBoxShadow;
1974 mozilla::StyleOwnedSlice<mozilla::StyleFilter> mBackdropFilters;
1975 mozilla::StyleClipRectOrAuto mClip; // offsets from UL border edge
1976 float mOpacity;
1977 mozilla::StyleBlend mMixBlendMode;
1980 #undef STYLE_STRUCT
1982 #define STATIC_ASSERT_TYPE_LAYOUTS_MATCH(T1, T2) \
1983 static_assert(sizeof(T1) == sizeof(T2), \
1984 "Size mismatch between " #T1 " and " #T2); \
1985 static_assert(alignof(T1) == alignof(T2), \
1986 "Align mismatch between " #T1 " and " #T2);
1988 #define STATIC_ASSERT_FIELD_OFFSET_MATCHES(T1, T2, field) \
1989 static_assert(offsetof(T1, field) == offsetof(T2, field), \
1990 "Field offset mismatch of " #field " between " #T1 \
1991 " and " #T2);
1994 * These *_Simple types are used to map Gecko types to layout-equivalent but
1995 * simpler Rust types, to aid Rust binding generation.
1997 * If something in this types or the assertions below needs to change, ask
1998 * bholley, heycam or emilio before!
2000 * <div rustbindgen="true" replaces="nsPoint">
2002 struct nsPoint_Simple {
2003 nscoord x, y;
2006 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsPoint, nsPoint_Simple);
2007 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsPoint, nsPoint_Simple, x);
2008 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsPoint, nsPoint_Simple, y);
2011 * <div rustbindgen="true" replaces="nsMargin">
2013 struct nsMargin_Simple {
2014 nscoord top, right, bottom, left;
2017 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsMargin, nsMargin_Simple);
2018 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, top);
2019 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, right);
2020 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, bottom);
2021 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, left);
2024 * <div rustbindgen="true" replaces="nsRect">
2026 struct nsRect_Simple {
2027 nscoord x, y, width, height;
2030 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsRect, nsRect_Simple);
2031 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, x);
2032 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, y);
2033 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, width);
2034 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, height);
2037 * <div rustbindgen="true" replaces="nsSize">
2039 struct nsSize_Simple {
2040 nscoord width, height;
2043 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsSize, nsSize_Simple);
2044 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsSize, nsSize_Simple, width);
2045 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsSize, nsSize_Simple, height);
2048 * <div rustbindgen="true" replaces="mozilla::UniquePtr">
2050 * TODO(Emilio): This is a workaround and we should be able to get rid of this
2051 * one.
2053 template <typename T>
2054 struct UniquePtr_Simple {
2055 T* mPtr;
2058 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(mozilla::UniquePtr<int>,
2059 UniquePtr_Simple<int>);
2062 * <div rustbindgen replaces="nsTArray"></div>
2064 template <typename T>
2065 class nsTArray_Simple {
2066 protected:
2067 T* mBuffer;
2069 public:
2070 ~nsTArray_Simple() {
2071 // The existence of a user-provided, and therefore non-trivial, destructor
2072 // here prevents bindgen from deriving the Clone trait via a simple memory
2073 // copy.
2078 * <div rustbindgen replaces="CopyableTArray"></div>
2080 template <typename T>
2081 class CopyableTArray_Simple : public nsTArray_Simple<T> {};
2083 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<nsStyleImageLayers::Layer>,
2084 nsTArray_Simple<nsStyleImageLayers::Layer>);
2085 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleTransition>,
2086 nsTArray_Simple<mozilla::StyleTransition>);
2087 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleAnimation>,
2088 nsTArray_Simple<mozilla::StyleAnimation>);
2089 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleViewTimeline>,
2090 nsTArray_Simple<mozilla::StyleViewTimeline>);
2092 #endif /* nsStyleStruct_h___ */