Backed out changeset 337531b04603 (bug 1846853) for causing reftests failures. CLOSED...
[gecko.git] / layout / style / nsStyleStruct.h
blob48a7e6c9839155c8ef8f48e54be63dcc0d20bba1
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 /**
86 * Return a contained size from an uncontained size.
88 nsSize ContainSize(const nsSize& aUncontainedSize,
89 const nsIFrame& aFrame) const;
90 IntrinsicSize ContainIntrinsicSize(const IntrinsicSize& aUncontainedSize,
91 const nsIFrame& aFrame) const;
93 Maybe<nscoord> ContainIntrinsicBSize(const nsIFrame& aFrame,
94 nscoord aNoneValue = 0) const;
95 Maybe<nscoord> ContainIntrinsicISize(const nsIFrame& aFrame,
96 nscoord aNoneValue = 0) const;
98 const bool mIContained;
99 const bool mBContained;
102 } // namespace mozilla
104 #define STYLE_STRUCT(name_) \
105 name_(const name_&); \
106 MOZ_COUNTED_DTOR(name_); \
107 void MarkLeaked() const { MOZ_COUNT_DTOR(name_); } \
108 nsChangeHint CalcDifference(const name_&) const;
110 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleFont {
111 STYLE_STRUCT(nsStyleFont)
112 explicit nsStyleFont(const mozilla::dom::Document&);
115 * Return a given size multiplied by the current text zoom factor (in
116 * aPresContext).
118 * The size is allowed to be negative, but the caller is expected to deal with
119 * negative results.
121 static mozilla::Length ZoomText(const mozilla::dom::Document&,
122 mozilla::Length);
124 nsAtom* GetFontPaletteAtom() const { return mFontPalette._0.AsAtom(); }
126 nsFont mFont;
128 // Our "computed size". Can be different from mFont.size which is our "actual
129 // size" and is enforced to be >= the user's preferred min-size. mFont.size
130 // should be used for display purposes while mSize is the value to return in
131 // getComputedStyle() for example.
132 mozilla::NonNegativeLength mSize;
134 // In stylo these three track whether the size is keyword-derived
135 // and if so if it has been modified by a factor/offset
136 float mFontSizeFactor;
137 mozilla::Length mFontSizeOffset;
138 mozilla::StyleFontSizeKeyword mFontSizeKeyword;
139 mozilla::StyleFontPalette mFontPalette;
141 // math-depth support (used for MathML scriptlevel)
142 int8_t mMathDepth;
143 // MathML mathvariant support
144 mozilla::StyleMathVariant mMathVariant;
145 // math-style support (used for MathML displaystyle)
146 mozilla::StyleMathStyle mMathStyle;
148 // allow different min font-size for certain cases
149 uint8_t mMinFontSizeRatio = 100; // percent * 100
151 // Was mLanguage set based on a lang attribute in the document?
152 bool mExplicitLanguage = false;
154 mozilla::StyleXTextScale mXTextScale;
156 bool MinFontSizeEnabled() const {
157 return mXTextScale == mozilla::StyleXTextScale::All;
160 // The value mSize would have had if scriptminsize had never been applied
161 mozilla::NonNegativeLength mScriptUnconstrainedSize;
162 mozilla::Length mScriptMinSize;
163 RefPtr<nsAtom> mLanguage;
166 struct nsStyleImageLayers {
167 enum class LayerType : uint8_t { Background = 0, Mask };
169 explicit nsStyleImageLayers(LayerType aType);
170 nsStyleImageLayers(const nsStyleImageLayers& aSource);
172 struct Repeat {
173 mozilla::StyleImageLayerRepeat mXRepeat, mYRepeat;
175 // Initialize nothing
176 Repeat() = default;
178 bool IsInitialValue() const {
179 return mXRepeat == mozilla::StyleImageLayerRepeat::Repeat &&
180 mYRepeat == mozilla::StyleImageLayerRepeat::Repeat;
183 bool DependsOnPositioningAreaSize() const {
184 return mXRepeat == mozilla::StyleImageLayerRepeat::Space ||
185 mYRepeat == mozilla::StyleImageLayerRepeat::Space;
188 // Initialize to initial values
189 void SetInitialValues() {
190 mXRepeat = mozilla::StyleImageLayerRepeat::Repeat;
191 mYRepeat = mozilla::StyleImageLayerRepeat::Repeat;
194 bool operator==(const Repeat& aOther) const {
195 return mXRepeat == aOther.mXRepeat && mYRepeat == aOther.mYRepeat;
197 bool operator!=(const Repeat& aOther) const { return !(*this == aOther); }
200 struct Layer {
201 using StyleGeometryBox = mozilla::StyleGeometryBox;
202 using StyleImageLayerAttachment = mozilla::StyleImageLayerAttachment;
203 using StyleBackgroundSize = mozilla::StyleBackgroundSize;
205 mozilla::StyleImage mImage;
206 mozilla::Position mPosition;
207 StyleBackgroundSize mSize;
208 StyleGeometryBox mClip;
209 MOZ_INIT_OUTSIDE_CTOR StyleGeometryBox mOrigin;
211 // This property is used for background layer only.
212 // For a mask layer, it should always be the initial value, which is
213 // StyleImageLayerAttachment::Scroll.
214 StyleImageLayerAttachment mAttachment;
216 // This property is used for background layer only.
217 // For a mask layer, it should always be the initial value, which is
218 // StyleBlend::Normal.
219 mozilla::StyleBlend mBlendMode;
221 // This property is used for mask layer only.
222 // For a background layer, it should always be the initial value, which is
223 // StyleMaskComposite::Add.
224 mozilla::StyleMaskComposite mComposite;
226 // mask-only property. This property is used for mask layer only. For a
227 // background layer, it should always be the initial value, which is
228 // StyleMaskMode::MatchSource.
229 mozilla::StyleMaskMode mMaskMode;
231 Repeat mRepeat;
233 // This constructor does not initialize mRepeat or mOrigin and Initialize()
234 // must be called to do that.
235 Layer();
236 ~Layer();
238 // Initialize mRepeat and mOrigin by specified layer type
239 void Initialize(LayerType aType);
241 void ResolveImage(mozilla::dom::Document& aDocument,
242 const Layer* aOldLayer) {
243 mImage.ResolveImage(aDocument, aOldLayer ? &aOldLayer->mImage : nullptr);
246 // True if the rendering of this layer might change when the size
247 // of the background positioning area changes. This is true for any
248 // non-solid-color background whose position or size depends on
249 // the size of the positioning area. It's also true for SVG images
250 // whose root <svg> node has a viewBox.
251 bool RenderingMightDependOnPositioningAreaSizeChange() const;
253 // Compute the change hint required by changes in just this layer.
254 nsChangeHint CalcDifference(const Layer& aNewLayer) const;
256 // An equality operator that compares the images using URL-equality
257 // rather than pointer-equality.
258 bool operator==(const Layer& aOther) const;
259 bool operator!=(const Layer& aOther) const { return !(*this == aOther); }
262 // The (positive) number of computed values of each property, since
263 // the lengths of the lists are independent.
264 uint32_t mAttachmentCount;
265 uint32_t mClipCount;
266 uint32_t mOriginCount;
267 uint32_t mRepeatCount;
268 uint32_t mPositionXCount;
269 uint32_t mPositionYCount;
270 uint32_t mImageCount;
271 uint32_t mSizeCount;
272 uint32_t mMaskModeCount;
273 uint32_t mBlendModeCount;
274 uint32_t mCompositeCount;
276 // Layers are stored in an array, matching the top-to-bottom order in
277 // which they are specified in CSS. The number of layers to be used
278 // should come from the background-image property. We create
279 // additional |Layer| objects for *any* property, not just
280 // background-image. This means that the bottommost layer that
281 // callers in layout care about (which is also the one whose
282 // background-clip applies to the background-color) may not be last
283 // layer. In layers below the bottom layer, properties will be
284 // uninitialized unless their count, above, indicates that they are
285 // present.
286 nsStyleAutoArray<Layer> mLayers;
288 const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; }
290 void ResolveImages(mozilla::dom::Document& aDocument,
291 const nsStyleImageLayers* aOldLayers) {
292 for (uint32_t i = 0; i < mImageCount; ++i) {
293 const Layer* oldLayer = (aOldLayers && aOldLayers->mLayers.Length() > i)
294 ? &aOldLayers->mLayers[i]
295 : nullptr;
296 mLayers[i].ResolveImage(aDocument, oldLayer);
300 // Fill unspecified layers by cycling through their values
301 // till they all are of length aMaxItemCount
302 void FillAllLayers(uint32_t aMaxItemCount);
304 nsChangeHint CalcDifference(const nsStyleImageLayers& aNewLayers,
305 nsStyleImageLayers::LayerType aType) const;
307 nsStyleImageLayers& operator=(const nsStyleImageLayers& aOther);
308 nsStyleImageLayers& operator=(nsStyleImageLayers&& aOther) = default;
309 bool operator==(const nsStyleImageLayers& aOther) const;
311 static const nsCSSPropertyID kBackgroundLayerTable[];
312 static const nsCSSPropertyID kMaskLayerTable[];
314 #define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(var_, layers_) \
315 for (uint32_t var_ = (layers_).mImageCount; (var_)-- != 0;)
316 #define NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT_WITH_RANGE(var_, layers_, \
317 start_, count_) \
318 NS_ASSERTION( \
319 (int32_t)(start_) >= 0 && (uint32_t)(start_) < (layers_).mImageCount, \
320 "Invalid layer start!"); \
321 NS_ASSERTION((count_) > 0 && (count_) <= (start_) + 1, \
322 "Invalid layer range!"); \
323 for (uint32_t var_ = (start_) + 1; \
324 (var_)-- != (uint32_t)((start_) + 1 - (count_));)
327 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBackground {
328 STYLE_STRUCT(nsStyleBackground)
329 nsStyleBackground();
330 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBackground*);
332 // Return the background color as nscolor.
333 nscolor BackgroundColor(const nsIFrame* aFrame) const;
334 nscolor BackgroundColor(const mozilla::ComputedStyle* aStyle) const;
336 // True if this background is completely transparent.
337 bool IsTransparent(const nsIFrame* aFrame) const;
338 bool IsTransparent(const mozilla::ComputedStyle* aStyle) const;
340 // We have to take slower codepaths for fixed background attachment,
341 // but we don't want to do that when there's no image.
342 // Not inline because it uses an nsCOMPtr<imgIRequest>
343 // FIXME: Should be in nsStyleStructInlines.h.
344 bool HasFixedBackground(nsIFrame* aFrame) const;
346 // Checks to see if this has a non-empty image with "local" attachment.
347 // This is defined in nsStyleStructInlines.h.
348 inline bool HasLocalBackground() const;
350 const nsStyleImageLayers::Layer& BottomLayer() const {
351 return mImage.BottomLayer();
354 nsStyleImageLayers mImage;
355 mozilla::StyleColor mBackgroundColor;
358 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleMargin {
359 STYLE_STRUCT(nsStyleMargin)
360 nsStyleMargin();
362 bool GetMargin(nsMargin& aMargin) const {
363 bool convertsToLength = mMargin.All(
364 [](const auto& aLength) { return aLength.ConvertsToLength(); });
366 if (!convertsToLength) {
367 return false;
370 for (const auto side : mozilla::AllPhysicalSides()) {
371 aMargin.Side(side) = mMargin.Get(side).AsLengthPercentage().ToLength();
373 return true;
376 nsMargin GetScrollMargin() const {
377 return nsMargin(mScrollMargin.Get(mozilla::eSideTop).ToAppUnits(),
378 mScrollMargin.Get(mozilla::eSideRight).ToAppUnits(),
379 mScrollMargin.Get(mozilla::eSideBottom).ToAppUnits(),
380 mScrollMargin.Get(mozilla::eSideLeft).ToAppUnits());
383 // Return true if either the start or end side in the axis is 'auto'.
384 // (defined in WritingModes.h since we need the full WritingMode type)
385 inline bool HasBlockAxisAuto(mozilla::WritingMode aWM) const;
386 inline bool HasInlineAxisAuto(mozilla::WritingMode aWM) const;
387 inline bool HasAuto(mozilla::LogicalAxis, mozilla::WritingMode) const;
389 mozilla::StyleRect<mozilla::LengthPercentageOrAuto> mMargin;
390 mozilla::StyleRect<mozilla::StyleLength> mScrollMargin;
391 // TODO: Add support for overflow-clip-margin: <visual-box> and maybe
392 // per-axis/side clipping, see https://github.com/w3c/csswg-drafts/issues/7245
393 mozilla::StyleLength mOverflowClipMargin;
396 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePadding {
397 STYLE_STRUCT(nsStylePadding)
398 nsStylePadding();
400 mozilla::StyleRect<mozilla::NonNegativeLengthPercentage> mPadding;
401 mozilla::StyleRect<mozilla::NonNegativeLengthPercentageOrAuto> mScrollPadding;
403 inline bool IsWidthDependent() const {
404 return !mPadding.All(
405 [](const auto& aLength) { return aLength.ConvertsToLength(); });
408 bool GetPadding(nsMargin& aPadding) const {
409 if (IsWidthDependent()) {
410 return false;
413 for (const auto side : mozilla::AllPhysicalSides()) {
414 // Clamp negative calc() to 0.
415 aPadding.Side(side) = std::max(mPadding.Get(side).ToLength(), 0);
417 return true;
421 // Border widths are rounded to the nearest-below integer number of pixels,
422 // but values between zero and one device pixels are always rounded up to
423 // one device pixel.
424 #define NS_ROUND_BORDER_TO_PIXELS(l, tpp) \
425 ((l) == 0) ? 0 : std::max((tpp), (l) / (tpp) * (tpp))
427 // Returns if the given border style type is visible or not
428 static bool IsVisibleBorderStyle(mozilla::StyleBorderStyle aStyle) {
429 return (aStyle != mozilla::StyleBorderStyle::None &&
430 aStyle != mozilla::StyleBorderStyle::Hidden);
433 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleBorder {
434 STYLE_STRUCT(nsStyleBorder)
435 nsStyleBorder();
436 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleBorder*);
438 // Return whether aStyle is a visible style. Invisible styles cause
439 // the relevant computed border width to be 0.
440 // Note that this does *not* consider the effects of 'border-image':
441 // if border-style is none, but there is a loaded border image,
442 // HasVisibleStyle will be false even though there *is* a border.
443 bool HasVisibleStyle(mozilla::Side aSide) const {
444 return IsVisibleBorderStyle(mBorderStyle[aSide]);
447 // aBorderWidth is in twips
448 void SetBorderWidth(mozilla::Side aSide, nscoord aBorderWidth,
449 nscoord aAppUnitsPerDevPixel) {
450 nscoord roundedWidth =
451 NS_ROUND_BORDER_TO_PIXELS(aBorderWidth, aAppUnitsPerDevPixel);
452 mBorder.Side(aSide) = roundedWidth;
453 if (HasVisibleStyle(aSide)) {
454 mComputedBorder.Side(aSide) = roundedWidth;
458 // Get the computed border (plus rounding). This does consider the
459 // effects of 'border-style: none', but does not consider
460 // 'border-image'.
461 const nsMargin& GetComputedBorder() const { return mComputedBorder; }
463 bool HasBorder() const {
464 return mComputedBorder != nsMargin(0, 0, 0, 0) ||
465 !mBorderImageSource.IsNone();
468 // Get the actual border width for a particular side, in appunits. Note that
469 // this is zero if and only if there is no border to be painted for this
470 // side. That is, this value takes into account the border style and the
471 // value is rounded to the nearest device pixel by NS_ROUND_BORDER_TO_PIXELS.
472 nscoord GetComputedBorderWidth(mozilla::Side aSide) const {
473 return GetComputedBorder().Side(aSide);
476 mozilla::StyleBorderStyle GetBorderStyle(mozilla::Side aSide) const {
477 NS_ASSERTION(aSide <= mozilla::eSideLeft, "bad side");
478 return mBorderStyle[aSide];
481 void SetBorderStyle(mozilla::Side aSide, mozilla::StyleBorderStyle aStyle) {
482 NS_ASSERTION(aSide <= mozilla::eSideLeft, "bad side");
483 mBorderStyle[aSide] = aStyle;
484 mComputedBorder.Side(aSide) =
485 (HasVisibleStyle(aSide) ? mBorder.Side(aSide) : 0);
488 inline bool IsBorderImageSizeAvailable() const {
489 return mBorderImageSource.IsSizeAvailable();
492 nsMargin GetImageOutset() const;
494 imgIRequest* GetBorderImageRequest() const {
495 return mBorderImageSource.GetImageRequest();
498 public:
499 mozilla::StyleBorderRadius mBorderRadius; // coord, percent
500 mozilla::StyleImage mBorderImageSource;
501 mozilla::StyleBorderImageWidth mBorderImageWidth;
502 mozilla::StyleNonNegativeLengthOrNumberRect mBorderImageOutset;
503 mozilla::StyleBorderImageSlice mBorderImageSlice; // factor, percent
504 mozilla::StyleBorderImageRepeat mBorderImageRepeatH;
505 mozilla::StyleBorderImageRepeat mBorderImageRepeatV;
506 mozilla::StyleFloatEdge mFloatEdge;
507 mozilla::StyleBoxDecorationBreak mBoxDecorationBreak;
509 protected:
510 mozilla::StyleBorderStyle mBorderStyle[4]; // StyleBorderStyle::*
512 public:
513 // the colors to use for a simple border.
514 // not used for -moz-border-colors
515 mozilla::StyleColor mBorderTopColor;
516 mozilla::StyleColor mBorderRightColor;
517 mozilla::StyleColor mBorderBottomColor;
518 mozilla::StyleColor mBorderLeftColor;
520 mozilla::StyleColor& BorderColorFor(mozilla::Side aSide) {
521 switch (aSide) {
522 case mozilla::eSideTop:
523 return mBorderTopColor;
524 case mozilla::eSideRight:
525 return mBorderRightColor;
526 case mozilla::eSideBottom:
527 return mBorderBottomColor;
528 case mozilla::eSideLeft:
529 return mBorderLeftColor;
531 MOZ_ASSERT_UNREACHABLE("Unknown side");
532 return mBorderTopColor;
535 const mozilla::StyleColor& BorderColorFor(mozilla::Side aSide) const {
536 switch (aSide) {
537 case mozilla::eSideTop:
538 return mBorderTopColor;
539 case mozilla::eSideRight:
540 return mBorderRightColor;
541 case mozilla::eSideBottom:
542 return mBorderBottomColor;
543 case mozilla::eSideLeft:
544 return mBorderLeftColor;
546 MOZ_ASSERT_UNREACHABLE("Unknown side");
547 return mBorderTopColor;
550 static mozilla::StyleColor nsStyleBorder::*BorderColorFieldFor(
551 mozilla::Side aSide) {
552 switch (aSide) {
553 case mozilla::eSideTop:
554 return &nsStyleBorder::mBorderTopColor;
555 case mozilla::eSideRight:
556 return &nsStyleBorder::mBorderRightColor;
557 case mozilla::eSideBottom:
558 return &nsStyleBorder::mBorderBottomColor;
559 case mozilla::eSideLeft:
560 return &nsStyleBorder::mBorderLeftColor;
562 MOZ_ASSERT_UNREACHABLE("Unknown side");
563 return nullptr;
566 nsStyleBorder& operator=(const nsStyleBorder&) = delete;
568 protected:
569 // mComputedBorder holds the CSS2.1 computed border-width values.
570 // In particular, these widths take into account the border-style
571 // for the relevant side, and the values are rounded to the nearest
572 // device pixel (which is not part of the definition of computed
573 // values). The presence or absence of a border-image does not
574 // affect border-width values.
575 nsMargin mComputedBorder;
577 // mBorder holds the nscoord values for the border widths as they
578 // would be if all the border-style values were visible (not hidden
579 // or none). This member exists so that when we create structs
580 // using the copy constructor during style resolution the new
581 // structs will know what the specified values of the border were in
582 // case they have more specific rules setting the border style.
584 // Note that this isn't quite the CSS specified value, since this
585 // has had the enumerated border widths converted to lengths, and
586 // all lengths converted to twips. But it's not quite the computed
587 // value either. The values are rounded to the nearest device pixel.
588 nsMargin mBorder;
591 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleOutline {
592 STYLE_STRUCT(nsStyleOutline)
593 nsStyleOutline();
595 // This is the specified value of outline-width, but with length values
596 // computed to absolute. mActualOutlineWidth stores the outline-width
597 // value used by layout. (We must store mOutlineWidth for the same
598 // style struct resolution reasons that we do nsStyleBorder::mBorder;
599 // see that field's comment.)
600 nscoord mOutlineWidth;
601 mozilla::Length mOutlineOffset;
602 mozilla::StyleColor mOutlineColor;
603 mozilla::StyleOutlineStyle mOutlineStyle;
605 nscoord GetOutlineWidth() const { return mActualOutlineWidth; }
607 bool ShouldPaintOutline() const {
608 if (mOutlineStyle.IsAuto()) {
609 return true;
611 if (GetOutlineWidth() > 0) {
612 MOZ_ASSERT(
613 mOutlineStyle.AsBorderStyle() != mozilla::StyleBorderStyle::None,
614 "outline-style: none implies outline-width of zero");
615 return true;
617 return false;
620 protected:
621 // The actual value of outline-width is the computed value (an absolute
622 // length, forced to zero when outline-style is none) rounded to device
623 // pixels. This is the value used by layout.
624 nscoord mActualOutlineWidth;
627 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
628 STYLE_STRUCT(nsStyleList)
629 nsStyleList();
631 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleList*);
633 nsStyleList& operator=(const nsStyleList& aOther) = delete;
634 nsChangeHint CalcDifference(const nsStyleList& aNewData,
635 const nsStyleDisplay& aOldDisplay) const;
637 already_AddRefed<nsIURI> GetListStyleImageURI() const;
639 mozilla::StyleListStylePosition mListStylePosition;
641 mozilla::CounterStylePtr mCounterStyle;
642 mozilla::StyleQuotes mQuotes;
643 mozilla::StyleImage mListStyleImage;
646 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePage {
647 STYLE_STRUCT(nsStylePage)
648 MOZ_COUNTED_DEFAULT_CTOR(nsStylePage)
650 using StylePageOrientation = mozilla::StylePageOrientation;
651 using StylePageSize = mozilla::StylePageSize;
652 using StylePageName = mozilla::StylePageName;
654 // page-size property.
655 StylePageSize mSize = StylePageSize::Auto();
656 // page-name property.
657 StylePageName mPage = StylePageName::Auto();
658 // page-orientation property.
659 StylePageOrientation mPageOrientation = StylePageOrientation::Upright;
662 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
663 STYLE_STRUCT(nsStylePosition)
664 nsStylePosition();
666 using LengthPercentageOrAuto = mozilla::LengthPercentageOrAuto;
667 using Position = mozilla::Position;
668 template <typename T>
669 using StyleRect = mozilla::StyleRect<T>;
670 using StyleSize = mozilla::StyleSize;
671 using StyleMaxSize = mozilla::StyleMaxSize;
672 using WritingMode = mozilla::WritingMode;
673 using LogicalAxis = mozilla::LogicalAxis;
674 using StyleImplicitGridTracks = mozilla::StyleImplicitGridTracks;
675 using ComputedStyle = mozilla::ComputedStyle;
676 using StyleAlignSelf = mozilla::StyleAlignSelf;
677 using StyleJustifySelf = mozilla::StyleJustifySelf;
679 nsChangeHint CalcDifference(
680 const nsStylePosition& aNewData,
681 const nsStyleVisibility& aOldStyleVisibility) const;
683 // Returns whether we need to compute an hypothetical position if we were
684 // absolutely positioned.
685 bool NeedsHypotheticalPositionIfAbsPos() const {
686 return (mOffset.Get(mozilla::eSideRight).IsAuto() &&
687 mOffset.Get(mozilla::eSideLeft).IsAuto()) ||
688 (mOffset.Get(mozilla::eSideTop).IsAuto() &&
689 mOffset.Get(mozilla::eSideBottom).IsAuto());
692 const mozilla::StyleContainIntrinsicSize& ContainIntrinsicBSize(
693 const WritingMode& aWM) const;
694 const mozilla::StyleContainIntrinsicSize& ContainIntrinsicISize(
695 const WritingMode& aWM) const;
698 * Return the used value for 'align-self' given our parent ComputedStyle
699 * (or null for the root).
701 StyleAlignSelf UsedAlignSelf(const ComputedStyle*) const;
704 * Return the used value for 'justify-self' given our parent ComputedStyle
705 * aParent (or null for the root).
707 StyleJustifySelf UsedJustifySelf(const ComputedStyle*) const;
710 * Return the used value for 'justify/align-self' in aAxis given our parent
711 * ComputedStyle aParent (or null for the root).
712 * (defined in WritingModes.h since we need the full WritingMode type)
714 inline mozilla::StyleAlignFlags UsedSelfAlignment(
715 LogicalAxis aAxis, const mozilla::ComputedStyle* aParent) const;
718 * Return the used value for 'justify/align-content' in aAxis.
719 * (defined in WritingModes.h since we need the full WritingMode type)
721 inline mozilla::StyleContentDistribution UsedContentAlignment(
722 LogicalAxis aAxis) const;
725 * Return the used value for 'align-tracks'/'justify-tracks' for a track
726 * in the given axis.
727 * (defined in WritingModes.h since we need the full LogicalAxis type)
729 inline mozilla::StyleContentDistribution UsedTracksAlignment(
730 LogicalAxis aAxis, uint32_t aIndex) const;
732 // Each entry has the same encoding as *-content, see below.
733 mozilla::StyleAlignTracks mAlignTracks;
734 mozilla::StyleJustifyTracks mJustifyTracks;
736 Position mObjectPosition;
737 StyleRect<LengthPercentageOrAuto> mOffset;
738 StyleSize mWidth;
739 StyleSize mMinWidth;
740 StyleMaxSize mMaxWidth;
741 StyleSize mHeight;
742 StyleSize mMinHeight;
743 StyleMaxSize mMaxHeight;
744 mozilla::StyleFlexBasis mFlexBasis;
745 StyleImplicitGridTracks mGridAutoColumns;
746 StyleImplicitGridTracks mGridAutoRows;
747 mozilla::StyleAspectRatio mAspectRatio;
748 mozilla::StyleGridAutoFlow mGridAutoFlow;
749 mozilla::StyleMasonryAutoFlow mMasonryAutoFlow;
751 mozilla::StyleAlignContent mAlignContent;
752 mozilla::StyleAlignItems mAlignItems;
753 mozilla::StyleAlignSelf mAlignSelf;
754 mozilla::StyleJustifyContent mJustifyContent;
755 mozilla::StyleComputedJustifyItems mJustifyItems;
756 mozilla::StyleJustifySelf mJustifySelf;
757 mozilla::StyleFlexDirection mFlexDirection;
758 mozilla::StyleFlexWrap mFlexWrap;
759 mozilla::StyleObjectFit mObjectFit;
760 mozilla::StyleBoxSizing mBoxSizing;
761 int32_t mOrder;
762 float mFlexGrow;
763 float mFlexShrink;
764 mozilla::StyleZIndex mZIndex;
766 mozilla::StyleGridTemplateComponent mGridTemplateColumns;
767 mozilla::StyleGridTemplateComponent mGridTemplateRows;
768 mozilla::StyleGridTemplateAreas mGridTemplateAreas;
770 mozilla::StyleGridLine mGridColumnStart;
771 mozilla::StyleGridLine mGridColumnEnd;
772 mozilla::StyleGridLine mGridRowStart;
773 mozilla::StyleGridLine mGridRowEnd;
774 mozilla::NonNegativeLengthPercentageOrNormal mColumnGap;
775 mozilla::NonNegativeLengthPercentageOrNormal mRowGap;
777 mozilla::StyleContainIntrinsicSize mContainIntrinsicWidth;
778 mozilla::StyleContainIntrinsicSize mContainIntrinsicHeight;
780 // Logical-coordinate accessors for width and height properties,
781 // given a WritingMode value. The definitions of these methods are
782 // found in WritingModes.h (after the WritingMode class is fully
783 // declared).
784 inline const StyleSize& ISize(WritingMode) const;
785 inline const StyleSize& MinISize(WritingMode) const;
786 inline const StyleMaxSize& MaxISize(WritingMode) const;
787 inline const StyleSize& BSize(WritingMode) const;
788 inline const StyleSize& MinBSize(WritingMode) const;
789 inline const StyleMaxSize& MaxBSize(WritingMode) const;
790 inline const StyleSize& Size(LogicalAxis, WritingMode) const;
791 inline const StyleSize& MinSize(LogicalAxis, WritingMode) const;
792 inline const StyleMaxSize& MaxSize(LogicalAxis, WritingMode) const;
793 inline bool ISizeDependsOnContainer(WritingMode) const;
794 inline bool MinISizeDependsOnContainer(WritingMode) const;
795 inline bool MaxISizeDependsOnContainer(WritingMode) const;
796 inline bool BSizeDependsOnContainer(WritingMode) const;
797 inline bool MinBSizeDependsOnContainer(WritingMode) const;
798 inline bool MaxBSizeDependsOnContainer(WritingMode) const;
800 private:
801 template <typename SizeOrMaxSize>
802 static bool ISizeCoordDependsOnContainer(const SizeOrMaxSize& aCoord) {
803 if (aCoord.IsLengthPercentage()) {
804 return aCoord.AsLengthPercentage().HasPercent();
806 return aCoord.IsFitContent() || aCoord.IsMozAvailable();
809 template <typename SizeOrMaxSize>
810 static bool BSizeCoordDependsOnContainer(const SizeOrMaxSize& aCoord) {
811 return aCoord.IsLengthPercentage() &&
812 aCoord.AsLengthPercentage().HasPercent();
816 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTextReset {
817 STYLE_STRUCT(nsStyleTextReset)
818 nsStyleTextReset();
820 // Note the difference between this and
821 // ComputedStyle::HasTextDecorationLines.
822 bool HasTextDecorationLines() const {
823 return mTextDecorationLine != mozilla::StyleTextDecorationLine::NONE &&
824 mTextDecorationLine !=
825 mozilla::StyleTextDecorationLine::COLOR_OVERRIDE;
828 mozilla::StyleTextOverflow mTextOverflow;
830 mozilla::StyleTextDecorationLine mTextDecorationLine;
831 mozilla::StyleTextDecorationStyle mTextDecorationStyle;
832 mozilla::StyleUnicodeBidi mUnicodeBidi;
833 nscoord mInitialLetterSink; // 0 means normal
834 float mInitialLetterSize; // 0.0f means normal
835 mozilla::StyleColor mTextDecorationColor;
836 mozilla::StyleTextDecorationLength mTextDecorationThickness;
839 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleText {
840 STYLE_STRUCT(nsStyleText)
841 explicit nsStyleText(const mozilla::dom::Document&);
843 mozilla::StyleAbsoluteColor mColor;
844 mozilla::StyleForcedColorAdjust mForcedColorAdjust;
845 mozilla::StyleTextTransform mTextTransform;
846 mozilla::StyleTextAlign mTextAlign;
847 mozilla::StyleTextAlignLast mTextAlignLast;
848 mozilla::StyleTextJustify mTextJustify;
849 mozilla::StyleWhiteSpace mWhiteSpace;
850 mozilla::StyleLineBreak mLineBreak = mozilla::StyleLineBreak::Auto;
852 private:
853 mozilla::StyleWordBreak mWordBreak = mozilla::StyleWordBreak::Normal;
854 mozilla::StyleOverflowWrap mOverflowWrap = mozilla::StyleOverflowWrap::Normal;
856 public:
857 mozilla::StyleHyphens mHyphens;
858 mozilla::StyleRubyAlign mRubyAlign;
859 mozilla::StyleRubyPosition mRubyPosition;
860 mozilla::StyleTextSizeAdjust mTextSizeAdjust;
861 mozilla::StyleTextCombineUpright mTextCombineUpright;
862 mozilla::StyleMozControlCharacterVisibility mMozControlCharacterVisibility;
863 mozilla::StyleTextEmphasisPosition mTextEmphasisPosition;
864 mozilla::StyleTextRendering mTextRendering;
865 mozilla::StyleColor mTextEmphasisColor;
866 mozilla::StyleColor mWebkitTextFillColor;
867 mozilla::StyleColor mWebkitTextStrokeColor;
869 mozilla::StyleNonNegativeLengthOrNumber mTabSize;
870 mozilla::LengthPercentage mWordSpacing;
871 mozilla::StyleLetterSpacing mLetterSpacing;
872 mozilla::StyleLineHeight mLineHeight;
873 mozilla::LengthPercentage mTextIndent;
875 mozilla::LengthPercentageOrAuto mTextUnderlineOffset;
876 mozilla::StyleTextDecorationSkipInk mTextDecorationSkipInk;
877 mozilla::StyleTextUnderlinePosition mTextUnderlinePosition;
879 mozilla::StyleAu mWebkitTextStrokeWidth;
881 mozilla::StyleArcSlice<mozilla::StyleSimpleShadow> mTextShadow;
882 mozilla::StyleTextEmphasisStyle mTextEmphasisStyle;
884 mozilla::StyleHyphenateCharacter mHyphenateCharacter =
885 mozilla::StyleHyphenateCharacter::Auto();
887 mozilla::StyleTextSecurity mWebkitTextSecurity =
888 mozilla::StyleTextSecurity::None;
890 char16_t TextSecurityMaskChar() const {
891 switch (mWebkitTextSecurity) {
892 case mozilla::StyleTextSecurity::None:
893 return 0;
894 case mozilla::StyleTextSecurity::Circle:
895 return 0x25E6;
896 case mozilla::StyleTextSecurity::Disc:
897 return 0x2022;
898 case mozilla::StyleTextSecurity::Square:
899 return 0x25A0;
900 default:
901 MOZ_ASSERT_UNREACHABLE("unknown StyleTextSecurity value!");
902 return 0;
906 mozilla::StyleWordBreak EffectiveWordBreak() const {
907 if (mWordBreak == mozilla::StyleWordBreak::BreakWord) {
908 return mozilla::StyleWordBreak::Normal;
910 return mWordBreak;
913 mozilla::StyleOverflowWrap EffectiveOverflowWrap() const {
914 if (mWordBreak == mozilla::StyleWordBreak::BreakWord) {
915 return mozilla::StyleOverflowWrap::Anywhere;
917 return mOverflowWrap;
920 bool WhiteSpaceIsSignificant() const {
921 return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
922 mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
923 mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
924 mWhiteSpace == mozilla::StyleWhiteSpace::PreSpace;
927 bool WhiteSpaceCanHangOrVisuallyCollapse() const {
928 // This was originally expressed in nsTextFrame in terms of:
929 // mWhiteSpace != StyleWhiteSpace::BreakSpaces &&
930 // WhiteSpaceCanWrapStyle() &&
931 // WhiteSpaceIsSignificant()
932 // which simplifies to:
933 return mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap;
936 bool NewlineIsSignificantStyle() const {
937 return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
938 mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
939 mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
940 mWhiteSpace == mozilla::StyleWhiteSpace::PreLine;
943 bool WhiteSpaceOrNewlineIsSignificant() const {
944 return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
945 mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
946 mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
947 mWhiteSpace == mozilla::StyleWhiteSpace::PreLine ||
948 mWhiteSpace == mozilla::StyleWhiteSpace::PreSpace;
951 bool TabIsSignificant() const {
952 return mWhiteSpace == mozilla::StyleWhiteSpace::Pre ||
953 mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
954 mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces;
957 bool WhiteSpaceCanWrapStyle() const {
958 return mWhiteSpace == mozilla::StyleWhiteSpace::Normal ||
959 mWhiteSpace == mozilla::StyleWhiteSpace::PreWrap ||
960 mWhiteSpace == mozilla::StyleWhiteSpace::BreakSpaces ||
961 mWhiteSpace == mozilla::StyleWhiteSpace::PreLine;
964 bool WordCanWrapStyle() const {
965 if (!WhiteSpaceCanWrapStyle()) {
966 return false;
968 auto owrap = EffectiveOverflowWrap();
969 return owrap == mozilla::StyleOverflowWrap::BreakWord ||
970 owrap == mozilla::StyleOverflowWrap::Anywhere;
973 bool HasEffectiveTextEmphasis() const {
974 if (mTextEmphasisStyle.IsNone()) {
975 return false;
977 if (mTextEmphasisStyle.IsString() &&
978 mTextEmphasisStyle.AsString().AsString().IsEmpty()) {
979 return false;
981 return true;
984 mozilla::StyleTextAlign TextAlignForLastLine() const {
985 switch (mTextAlignLast) {
986 case mozilla::StyleTextAlignLast::Auto:
987 // 'text-align-last: auto' is equivalent to the value of the
988 // 'text-align' property except when 'text-align' is set to 'justify',
989 // in which case it is 'justify' when 'text-justify' is 'distribute' and
990 // 'start' otherwise.
992 // XXX: the code below will have to change when we implement
993 // text-justify
994 if (mTextAlign == mozilla::StyleTextAlign::Justify) {
995 return mozilla::StyleTextAlign::Start;
997 return mTextAlign;
998 case mozilla::StyleTextAlignLast::Center:
999 return mozilla::StyleTextAlign::Center;
1000 case mozilla::StyleTextAlignLast::Start:
1001 return mozilla::StyleTextAlign::Start;
1002 case mozilla::StyleTextAlignLast::End:
1003 return mozilla::StyleTextAlign::End;
1004 case mozilla::StyleTextAlignLast::Left:
1005 return mozilla::StyleTextAlign::Left;
1006 case mozilla::StyleTextAlignLast::Right:
1007 return mozilla::StyleTextAlign::Right;
1008 case mozilla::StyleTextAlignLast::Justify:
1009 return mozilla::StyleTextAlign::Justify;
1011 return mozilla::StyleTextAlign::Start;
1014 bool HasWebkitTextStroke() const { return mWebkitTextStrokeWidth > 0; }
1016 bool HasTextShadow() const { return !mTextShadow.IsEmpty(); }
1018 // The aContextFrame argument on each of these is the frame this
1019 // style struct is for. If the frame is for SVG text or inside ruby,
1020 // the return value will be massaged to be something that makes sense
1021 // for those cases.
1022 inline bool NewlineIsSignificant(const nsTextFrame* aContextFrame) const;
1023 inline bool WhiteSpaceCanWrap(const nsIFrame* aContextFrame) const;
1024 inline bool WordCanWrap(const nsIFrame* aContextFrame) const;
1026 mozilla::LogicalSide TextEmphasisSide(mozilla::WritingMode aWM) const;
1029 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleVisibility {
1030 STYLE_STRUCT(nsStyleVisibility)
1031 explicit nsStyleVisibility(const mozilla::dom::Document&);
1033 bool IsVisible() const {
1034 return mVisible == mozilla::StyleVisibility::Visible;
1037 bool IsCollapse() const {
1038 return mVisible == mozilla::StyleVisibility::Collapse;
1041 bool IsVisibleOrCollapsed() const {
1042 return mVisible == mozilla::StyleVisibility::Visible ||
1043 mVisible == mozilla::StyleVisibility::Collapse;
1046 bool UseLegacyCollapseBehavior() const {
1047 return mMozBoxCollapse == mozilla::StyleMozBoxCollapse::Legacy;
1051 * Given an image request, returns the orientation that should be used
1052 * on the image. The returned orientation may differ from the style
1053 * struct's orientation member value, if the image request is not of the
1054 * same origin.
1056 * @param aRequest The image request used to determine if same origin.
1058 mozilla::StyleImageOrientation UsedImageOrientation(
1059 imgIRequest* aRequest) const {
1060 return UsedImageOrientation(aRequest, mImageOrientation);
1064 * Given an image request and an orientation, returns the orientation
1065 * that should be used on the image. The returned orientation may differ
1066 * from the input orientation if the image request is not of the same
1067 * origin.
1069 * @param aRequest The image request used to determine if same origin.
1070 * @param aOrientation The input orientation.
1072 static mozilla::StyleImageOrientation UsedImageOrientation(
1073 imgIRequest* aRequest, mozilla::StyleImageOrientation aOrientation);
1075 mozilla::StyleDirection mDirection;
1076 mozilla::StyleVisibility mVisible;
1077 mozilla::StyleImageRendering mImageRendering;
1078 mozilla::StyleWritingModeProperty mWritingMode;
1079 mozilla::StyleTextOrientation mTextOrientation;
1080 mozilla::StyleMozBoxCollapse mMozBoxCollapse;
1081 mozilla::StylePrintColorAdjust mPrintColorAdjust;
1083 private:
1084 mozilla::StyleImageOrientation mImageOrientation;
1087 namespace mozilla {
1089 inline StyleTextTransform StyleTextTransform::None() {
1090 return StyleTextTransform{StyleTextTransformCase::None,
1091 StyleTextTransformOther()};
1094 inline bool StyleTextTransform::IsNone() const { return *this == None(); }
1096 // Note that IsAuto() does not exclude the possibility that `left` or `right`
1097 // is set; it refers only to behavior in horizontal typographic mode.
1098 inline bool StyleTextUnderlinePosition::IsAuto() const {
1099 return !(*this & (StyleTextUnderlinePosition::FROM_FONT |
1100 StyleTextUnderlinePosition::UNDER));
1102 inline bool StyleTextUnderlinePosition::IsFromFont() const {
1103 return bool(*this & StyleTextUnderlinePosition::FROM_FONT);
1105 inline bool StyleTextUnderlinePosition::IsUnder() const {
1106 return bool(*this & StyleTextUnderlinePosition::UNDER);
1108 inline bool StyleTextUnderlinePosition::IsLeft() const {
1109 return bool(*this & StyleTextUnderlinePosition::LEFT);
1111 inline bool StyleTextUnderlinePosition::IsRight() const {
1112 return bool(*this & StyleTextUnderlinePosition::RIGHT);
1115 struct StyleTransition {
1116 StyleTransition() = default;
1117 explicit StyleTransition(const StyleTransition& aCopy);
1119 void SetInitialValues();
1121 // Delay and Duration are in milliseconds
1123 const StyleComputedTimingFunction& GetTimingFunction() const {
1124 return mTimingFunction;
1126 const mozilla::StyleTime& GetDelay() const { return mDelay; }
1127 const mozilla::StyleTime& GetDuration() const { return mDuration; }
1128 nsCSSPropertyID GetProperty() const { return mProperty; }
1129 nsAtom* GetUnknownProperty() const { return mUnknownProperty; }
1131 bool operator==(const StyleTransition& aOther) const;
1132 bool operator!=(const StyleTransition& aOther) const {
1133 return !(*this == aOther);
1136 private:
1137 StyleComputedTimingFunction mTimingFunction{
1138 StyleComputedTimingFunction::LinearKeyword()};
1139 mozilla::StyleTime mDuration{0.0};
1140 mozilla::StyleTime mDelay{0.0};
1141 nsCSSPropertyID mProperty;
1142 RefPtr<nsAtom> mUnknownProperty; // used when mProperty is
1143 // eCSSProperty_UNKNOWN or
1144 // eCSSPropertyExtra_variable
1147 struct StyleAnimation {
1148 StyleAnimation() = default;
1149 explicit StyleAnimation(const StyleAnimation& aCopy);
1151 void SetInitialValues();
1153 // Delay and Duration are in milliseconds
1155 const StyleComputedTimingFunction& GetTimingFunction() const {
1156 return mTimingFunction;
1158 const mozilla::StyleTime& GetDelay() const { return mDelay; }
1159 const mozilla::StyleTime& GetDuration() const { return mDuration; }
1160 nsAtom* GetName() const { return mName; }
1161 dom::PlaybackDirection GetDirection() const { return mDirection; }
1162 dom::FillMode GetFillMode() const { return mFillMode; }
1163 StyleAnimationPlayState GetPlayState() const { return mPlayState; }
1164 float GetIterationCount() const { return mIterationCount._0; }
1165 dom::CompositeOperation GetComposition() const { return mComposition; }
1166 const StyleAnimationTimeline& GetTimeline() const { return mTimeline; }
1168 void SetName(already_AddRefed<nsAtom> aName) { mName = aName; }
1169 void SetName(nsAtom* aName) { mName = aName; }
1171 bool operator==(const StyleAnimation& aOther) const;
1172 bool operator!=(const StyleAnimation& aOther) const {
1173 return !(*this == aOther);
1176 private:
1177 StyleComputedTimingFunction mTimingFunction{
1178 StyleComputedTimingFunction::LinearKeyword()};
1179 StyleTime mDuration{0.0f};
1180 StyleTime mDelay{0.0f};
1181 RefPtr<nsAtom> mName; // nsGkAtoms::_empty for 'none'
1182 dom::PlaybackDirection mDirection;
1183 dom::FillMode mFillMode;
1184 StyleAnimationPlayState mPlayState;
1185 StyleAnimationIterationCount mIterationCount;
1186 dom::CompositeOperation mComposition;
1187 StyleAnimationTimeline mTimeline{StyleAnimationTimeline::Auto()};
1190 struct StyleScrollTimeline {
1191 StyleScrollTimeline() = default;
1192 explicit StyleScrollTimeline(const StyleScrollTimeline& aCopy) = default;
1194 // SetInitialValues() are called when ensuring the array length. So basically
1195 // we can rely on the default constructor to handle the new constructed
1196 // elements.
1197 void SetInitialValues() {}
1199 nsAtom* GetName() const { return mName._0.AsAtom(); }
1200 StyleScrollAxis GetAxis() const { return mAxis; }
1202 bool operator==(const StyleScrollTimeline& aOther) const {
1203 return mName == aOther.mName && mAxis == aOther.mAxis;
1205 bool operator!=(const StyleScrollTimeline& aOther) const {
1206 return !(*this == aOther);
1209 private:
1210 StyleScrollTimelineName mName;
1211 StyleScrollAxis mAxis = StyleScrollAxis::Block;
1214 struct StyleViewTimeline {
1215 StyleViewTimeline() = default;
1216 explicit StyleViewTimeline(const StyleViewTimeline& aCopy) = default;
1218 // SetInitialValues() are called when ensuring the array length. So basically
1219 // we can rely on the default constructor to handle the new constructed
1220 // elements.
1221 void SetInitialValues() {}
1223 nsAtom* GetName() const { return mName._0.AsAtom(); }
1224 StyleScrollAxis GetAxis() const { return mAxis; }
1225 const StyleViewTimelineInset& GetInset() const { return mInset; }
1227 bool operator==(const StyleViewTimeline& aOther) const {
1228 return mName == aOther.mName && mAxis == aOther.mAxis &&
1229 mInset == aOther.mInset;
1231 bool operator!=(const StyleViewTimeline& aOther) const {
1232 return !(*this == aOther);
1235 private:
1236 StyleScrollTimelineName mName;
1237 StyleScrollAxis mAxis = StyleScrollAxis::Block;
1238 StyleViewTimelineInset mInset;
1241 } // namespace mozilla
1243 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleDisplay {
1244 STYLE_STRUCT(nsStyleDisplay)
1245 nsStyleDisplay();
1246 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleDisplay*);
1248 using StyleContain = mozilla::StyleContain;
1249 using StyleContentVisibility = mozilla::StyleContentVisibility;
1251 nsChangeHint CalcDifference(const nsStyleDisplay& aNewData,
1252 const nsStylePosition& aOldPosition) const;
1254 nsChangeHint CalcTransformPropertyDifference(
1255 const nsStyleDisplay& aNewData) const;
1257 mozilla::StyleDisplay mDisplay;
1258 // Saved mDisplay for position:absolute/fixed and float:left/right; otherwise
1259 // equal to mDisplay.
1260 mozilla::StyleDisplay mOriginalDisplay;
1261 // Equal to mContain plus any implicit containment from mContentVisibility and
1262 // mContainerType.
1263 mozilla::StyleContentVisibility mContentVisibility;
1264 mozilla::StyleContainerType mContainerType;
1266 private:
1267 mozilla::StyleAppearance mAppearance;
1268 mozilla::StyleContain mContain;
1269 // Equal to mContain plus any implicit containment from mContentVisibility and
1270 // mContainerType.
1271 mozilla::StyleContain mEffectiveContainment;
1273 public:
1274 mozilla::StyleAppearance mDefaultAppearance;
1275 mozilla::StylePositionProperty mPosition;
1277 mozilla::StyleFloat mFloat;
1278 mozilla::StyleClear mClear;
1279 mozilla::StyleBreakWithin mBreakInside;
1280 mozilla::StyleBreakBetween mBreakBefore;
1281 mozilla::StyleBreakBetween mBreakAfter;
1282 mozilla::StyleOverflow mOverflowX;
1283 mozilla::StyleOverflow mOverflowY;
1284 mozilla::StyleOverflowClipBox mOverflowClipBoxBlock;
1285 mozilla::StyleOverflowClipBox mOverflowClipBoxInline;
1286 mozilla::StyleScrollbarGutter mScrollbarGutter;
1287 mozilla::StyleResize mResize;
1288 mozilla::StyleOrient mOrient;
1289 mozilla::StyleIsolation mIsolation;
1290 mozilla::StyleTopLayer mTopLayer;
1292 mozilla::StyleTouchAction mTouchAction;
1293 mozilla::StyleScrollBehavior mScrollBehavior;
1294 mozilla::StyleOverscrollBehavior mOverscrollBehaviorX;
1295 mozilla::StyleOverscrollBehavior mOverscrollBehaviorY;
1296 mozilla::StyleOverflowAnchor mOverflowAnchor;
1297 mozilla::StyleScrollSnapAlign mScrollSnapAlign;
1298 mozilla::StyleScrollSnapStop mScrollSnapStop;
1299 mozilla::StyleScrollSnapType mScrollSnapType;
1301 mozilla::StyleBackfaceVisibility mBackfaceVisibility;
1302 mozilla::StyleTransformStyle mTransformStyle;
1303 mozilla::StyleTransformBox mTransformBox;
1305 mozilla::StyleTransform mTransform;
1306 mozilla::StyleRotate mRotate;
1308 mozilla::StyleTranslate mTranslate;
1309 mozilla::StyleScale mScale;
1311 mozilla::StyleContainerName mContainerName;
1312 mozilla::StyleWillChange mWillChange;
1314 mozilla::StyleOffsetPath mOffsetPath;
1315 mozilla::LengthPercentage mOffsetDistance;
1316 mozilla::StyleOffsetRotate mOffsetRotate;
1317 mozilla::StylePositionOrAuto mOffsetAnchor;
1318 mozilla::StyleOffsetPosition mOffsetPosition;
1320 mozilla::StyleTransformOrigin mTransformOrigin;
1321 mozilla::StylePerspective mChildPerspective;
1322 mozilla::Position mPerspectiveOrigin;
1324 mozilla::StyleVerticalAlign mVerticalAlign;
1325 mozilla::StyleBaselineSource mBaselineSource;
1327 mozilla::StyleLineClamp mWebkitLineClamp;
1329 // The threshold used for extracting a shape from shape-outside: <image>.
1330 float mShapeImageThreshold = 0.0f;
1332 // The margin around a shape-outside: <image>.
1333 mozilla::NonNegativeLengthPercentage mShapeMargin;
1335 mozilla::StyleShapeOutside mShapeOutside;
1337 mozilla::Maybe<mozilla::WindowButtonType> GetWindowButtonType() const {
1338 if (MOZ_LIKELY(mDefaultAppearance == mozilla::StyleAppearance::None)) {
1339 return mozilla::Nothing();
1341 switch (mDefaultAppearance) {
1342 case mozilla::StyleAppearance::MozWindowButtonMaximize:
1343 case mozilla::StyleAppearance::MozWindowButtonRestore:
1344 return Some(mozilla::WindowButtonType::Maximize);
1345 case mozilla::StyleAppearance::MozWindowButtonMinimize:
1346 return Some(mozilla::WindowButtonType::Minimize);
1347 case mozilla::StyleAppearance::MozWindowButtonClose:
1348 return Some(mozilla::WindowButtonType::Close);
1349 default:
1350 return mozilla::Nothing();
1354 bool HasAppearance() const {
1355 return EffectiveAppearance() != mozilla::StyleAppearance::None;
1358 mozilla::StyleAppearance EffectiveAppearance() const {
1359 if (MOZ_LIKELY(mAppearance == mozilla::StyleAppearance::None)) {
1360 return mAppearance;
1362 switch (mAppearance) {
1363 case mozilla::StyleAppearance::Auto:
1364 case mozilla::StyleAppearance::Button:
1365 case mozilla::StyleAppearance::Searchfield:
1366 case mozilla::StyleAppearance::Textarea:
1367 case mozilla::StyleAppearance::Checkbox:
1368 case mozilla::StyleAppearance::Radio:
1369 case mozilla::StyleAppearance::Menulist:
1370 case mozilla::StyleAppearance::Listbox:
1371 case mozilla::StyleAppearance::Meter:
1372 case mozilla::StyleAppearance::ProgressBar:
1373 // These are all the values that behave like `auto`.
1374 return mDefaultAppearance;
1375 case mozilla::StyleAppearance::Textfield:
1376 // `appearance: textfield` should behave like `auto` on all elements
1377 // except <input type=search> elements, which we identify using the
1378 // internal -moz-default-appearance property. (In the browser chrome
1379 // we have some other elements that set `-moz-default-appearance:
1380 // searchfield`, but not in content documents.)
1381 if (mDefaultAppearance == mozilla::StyleAppearance::Searchfield) {
1382 return mAppearance;
1384 // We also need to support `appearance: textfield` on <input
1385 // type=number>, since that is the only way in Gecko to disable the
1386 // spinners.
1387 if (mDefaultAppearance == mozilla::StyleAppearance::NumberInput) {
1388 return mAppearance;
1390 return mDefaultAppearance;
1391 case mozilla::StyleAppearance::MenulistButton:
1392 // `appearance: menulist-button` should behave like `auto` on all
1393 // elements except for drop down selects, but since we have very little
1394 // difference between menulist and menulist-button handling, we don't
1395 // bother.
1396 return mDefaultAppearance;
1397 default:
1398 return mAppearance;
1402 mozilla::StyleDisplayOutside DisplayOutside() const {
1403 return mDisplay.Outside();
1405 mozilla::StyleDisplayInside DisplayInside() const {
1406 return mDisplay.Inside();
1408 bool IsListItem() const { return mDisplay.IsListItem(); }
1409 bool IsInlineFlow() const { return mDisplay.IsInlineFlow(); }
1411 bool IsInlineInsideStyle() const { return mDisplay.IsInlineInside(); }
1413 bool IsBlockOutsideStyle() const {
1414 return DisplayOutside() == mozilla::StyleDisplayOutside::Block;
1417 bool IsInlineOutsideStyle() const { return mDisplay.IsInlineOutside(); }
1419 bool IsOriginalDisplayInlineOutside() const {
1420 return mOriginalDisplay.IsInlineOutside();
1423 bool IsInnerTableStyle() const { return mDisplay.IsInternalTable(); }
1425 bool IsInternalTableStyleExceptCell() const {
1426 return mDisplay.IsInternalTableExceptCell();
1429 bool IsFloatingStyle() const { return mozilla::StyleFloat::None != mFloat; }
1431 bool IsPositionedStyle() const {
1432 return mPosition != mozilla::StylePositionProperty::Static ||
1433 (mWillChange.bits & mozilla::StyleWillChangeBits::POSITION);
1436 bool IsAbsolutelyPositionedStyle() const {
1437 return mozilla::StylePositionProperty::Absolute == mPosition ||
1438 mozilla::StylePositionProperty::Fixed == mPosition;
1441 bool IsRelativelyOrStickyPositionedStyle() const {
1442 return mozilla::StylePositionProperty::Relative == mPosition ||
1443 mozilla::StylePositionProperty::Sticky == mPosition;
1445 bool IsRelativelyPositionedStyle() const {
1446 return mozilla::StylePositionProperty::Relative == mPosition;
1448 bool IsStickyPositionedStyle() const {
1449 return mozilla::StylePositionProperty::Sticky == mPosition;
1451 bool IsPositionForcingStackingContext() const {
1452 return mozilla::StylePositionProperty::Sticky == mPosition ||
1453 mozilla::StylePositionProperty::Fixed == mPosition;
1456 bool IsRubyDisplayType() const { return mDisplay.IsRuby(); }
1458 bool IsInternalRubyDisplayType() const { return mDisplay.IsInternalRuby(); }
1460 bool IsOutOfFlowStyle() const {
1461 return (IsAbsolutelyPositionedStyle() || IsFloatingStyle());
1464 bool IsScrollableOverflow() const {
1465 // Visible and Clip can be combined but not with other values,
1466 // so checking mOverflowX is enough.
1467 return mOverflowX != mozilla::StyleOverflow::Visible &&
1468 mOverflowX != mozilla::StyleOverflow::Clip;
1471 bool OverflowIsVisibleInBothAxis() const {
1472 return mOverflowX == mozilla::StyleOverflow::Visible &&
1473 mOverflowY == mozilla::StyleOverflow::Visible;
1476 bool IsContainPaint() const {
1477 // Short circuit for no containment whatsoever
1478 if (!mEffectiveContainment) {
1479 return false;
1481 return (mEffectiveContainment & StyleContain::PAINT) &&
1482 !IsInternalRubyDisplayType() && !IsInternalTableStyleExceptCell();
1485 bool IsContainLayout() const {
1486 // Short circuit for no containment whatsoever
1487 if (!mEffectiveContainment) {
1488 return false;
1490 // Note: The spec for layout containment says it should
1491 // have no effect on non-atomic, inline-level boxes. We
1492 // don't check for these here because we don't know
1493 // what type of element is involved. Callers are
1494 // responsible for checking if the box in question is
1495 // non-atomic and inline-level, and creating an
1496 // exemption as necessary.
1497 return (mEffectiveContainment & StyleContain::LAYOUT) &&
1498 !IsInternalRubyDisplayType() && !IsInternalTableStyleExceptCell();
1501 bool IsContainStyle() const {
1502 return !!(mEffectiveContainment & StyleContain::STYLE);
1505 bool IsContainAny() const { return !!mEffectiveContainment; }
1507 // This is similar to PrecludesSizeContainmentOrContentVisibility, but also
1508 // takes into account whether or not the given frame is a non-atomic,
1509 // inline-level box.
1510 bool PrecludesSizeContainmentOrContentVisibilityWithFrame(
1511 const nsIFrame&) const;
1513 StyleContentVisibility ContentVisibility(const nsIFrame&) const;
1515 /* Returns whether the element has the transform property or a related
1516 * property. */
1517 bool HasTransformStyle() const {
1518 return HasTransformProperty() || HasIndividualTransform() ||
1519 mTransformStyle == mozilla::StyleTransformStyle::Preserve3d ||
1520 (mWillChange.bits & mozilla::StyleWillChangeBits::TRANSFORM) ||
1521 !mOffsetPath.IsNone();
1524 bool HasTransformProperty() const { return !mTransform._0.IsEmpty(); }
1526 bool HasIndividualTransform() const {
1527 return !mRotate.IsNone() || !mTranslate.IsNone() || !mScale.IsNone();
1530 bool HasPerspectiveStyle() const { return !mChildPerspective.IsNone(); }
1532 bool BackfaceIsHidden() const {
1533 return mBackfaceVisibility == mozilla::StyleBackfaceVisibility::Hidden;
1536 // FIXME(emilio): This should be more fine-grained on each caller to
1537 // BreakBefore() / BreakAfter().
1538 static bool ShouldBreak(mozilla::StyleBreakBetween aBreak) {
1539 switch (aBreak) {
1540 case mozilla::StyleBreakBetween::Left:
1541 case mozilla::StyleBreakBetween::Right:
1542 case mozilla::StyleBreakBetween::Page:
1543 case mozilla::StyleBreakBetween::Always:
1544 return true;
1545 case mozilla::StyleBreakBetween::Auto:
1546 case mozilla::StyleBreakBetween::Avoid:
1547 return false;
1548 default:
1549 MOZ_ASSERT_UNREACHABLE("Unknown break kind");
1550 return false;
1554 bool BreakBefore() const { return ShouldBreak(mBreakBefore); }
1556 bool BreakAfter() const { return ShouldBreak(mBreakAfter); }
1558 // These are defined in nsStyleStructInlines.h.
1560 // The aContextFrame argument on each of these is the frame this
1561 // style struct is for. If the frame is for SVG text, the return
1562 // value will be massaged to be something that makes sense for
1563 // SVG text.
1564 inline bool IsBlockOutside(const nsIFrame* aContextFrame) const;
1565 inline bool IsInlineOutside(const nsIFrame* aContextFrame) const;
1566 inline mozilla::StyleDisplay GetDisplay(const nsIFrame* aContextFrame) const;
1567 inline bool IsFloating(const nsIFrame* aContextFrame) const;
1568 inline bool IsRelativelyOrStickyPositioned(
1569 const nsIFrame* aContextFrame) const;
1571 // Note: In general, you'd want to call IsRelativelyOrStickyPositioned()
1572 // unless you want to deal with "position:relative" and "position:sticky"
1573 // differently.
1574 inline bool IsRelativelyPositioned(const nsIFrame* aContextFrame) const;
1575 inline bool IsStickyPositioned(const nsIFrame* aContextFrame) const;
1577 inline bool IsAbsolutelyPositioned(const nsIFrame* aContextFrame) const;
1579 // These methods are defined in nsStyleStructInlines.h.
1582 * Returns true when the element has the transform property
1583 * or a related property, and supports CSS transforms.
1584 * aContextFrame is the frame for which this is the nsStyleDisplay.
1586 inline bool HasTransform(const nsIFrame* aContextFrame) const;
1589 * Returns true when the element has the perspective property,
1590 * and supports CSS transforms. aContextFrame is the frame for
1591 * which this is the nsStyleDisplay.
1593 inline bool HasPerspective(const nsIFrame* aContextFrame) const;
1595 inline bool
1596 IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() const;
1597 inline bool IsFixedPosContainingBlockForTransformSupportingFrames() const;
1599 mozilla::ContainSizeAxes GetContainSizeAxes(const nsIFrame& aFrame) const;
1602 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTable {
1603 STYLE_STRUCT(nsStyleTable)
1604 nsStyleTable();
1606 mozilla::StyleTableLayout mLayoutStrategy;
1607 int32_t mXSpan; // The number of columns spanned by a colgroup or col
1610 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleTableBorder {
1611 STYLE_STRUCT(nsStyleTableBorder)
1612 nsStyleTableBorder();
1614 nscoord mBorderSpacingCol;
1615 nscoord mBorderSpacingRow;
1616 mozilla::StyleBorderCollapse mBorderCollapse;
1617 mozilla::StyleCaptionSide mCaptionSide;
1618 mozilla::StyleEmptyCells mEmptyCells;
1621 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleContent {
1622 STYLE_STRUCT(nsStyleContent)
1623 nsStyleContent();
1624 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleContent*);
1626 using CounterPair = mozilla::StyleGenericCounterPair<int32_t>;
1628 size_t ContentCount() const {
1629 return mContent.IsItems() ? mContent.AsItems().Length() : 0;
1632 const mozilla::StyleContentItem& ContentAt(size_t aIndex) const {
1633 return mContent.AsItems().AsSpan()[aIndex];
1636 mozilla::StyleContent mContent;
1637 mozilla::StyleCounterIncrement mCounterIncrement;
1638 mozilla::StyleCounterReset mCounterReset;
1639 mozilla::StyleCounterSet mCounterSet;
1642 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset {
1643 STYLE_STRUCT(nsStyleUIReset)
1644 nsStyleUIReset();
1646 private:
1647 mozilla::StyleUserSelect mUserSelect; // Use ComputedStyle::UserSelect()
1648 mozilla::StyleScrollbarWidth mScrollbarWidth; // Use ScrollbarWidth()
1650 public:
1651 mozilla::StyleUserSelect ComputedUserSelect() const { return mUserSelect; }
1653 mozilla::StyleScrollbarWidth ScrollbarWidth() const;
1655 nsCSSPropertyID GetTransitionProperty(uint32_t aIndex) const {
1656 return mTransitions[aIndex % mTransitionPropertyCount].GetProperty();
1658 const mozilla::StyleTime& GetTransitionDelay(uint32_t aIndex) const {
1659 return mTransitions[aIndex % mTransitionDelayCount].GetDelay();
1661 const mozilla::StyleTime& GetTransitionDuration(uint32_t aIndex) const {
1662 return mTransitions[aIndex % mTransitionDurationCount].GetDuration();
1664 const mozilla::StyleComputedTimingFunction& GetTransitionTimingFunction(
1665 uint32_t aIndex) const {
1666 return mTransitions[aIndex % mTransitionTimingFunctionCount]
1667 .GetTimingFunction();
1669 mozilla::StyleTime GetTransitionCombinedDuration(uint32_t aIndex) const {
1670 // https://drafts.csswg.org/css-transitions/#transition-combined-duration
1671 return {std::max(GetTransitionDuration(aIndex).seconds, 0.0f) +
1672 GetTransitionDelay(aIndex).seconds};
1675 nsAtom* GetAnimationName(uint32_t aIndex) const {
1676 return mAnimations[aIndex % mAnimationNameCount].GetName();
1678 const mozilla::StyleTime& GetAnimationDelay(uint32_t aIndex) const {
1679 return mAnimations[aIndex % mAnimationDelayCount].GetDelay();
1681 const mozilla::StyleTime& GetAnimationDuration(uint32_t aIndex) const {
1682 return mAnimations[aIndex % mAnimationDurationCount].GetDuration();
1684 mozilla::dom::PlaybackDirection GetAnimationDirection(uint32_t aIndex) const {
1685 return mAnimations[aIndex % mAnimationDirectionCount].GetDirection();
1687 mozilla::dom::FillMode GetAnimationFillMode(uint32_t aIndex) const {
1688 return mAnimations[aIndex % mAnimationFillModeCount].GetFillMode();
1690 mozilla::StyleAnimationPlayState GetAnimationPlayState(
1691 uint32_t aIndex) const {
1692 return mAnimations[aIndex % mAnimationPlayStateCount].GetPlayState();
1694 float GetAnimationIterationCount(uint32_t aIndex) const {
1695 return mAnimations[aIndex % mAnimationIterationCountCount]
1696 .GetIterationCount();
1698 const mozilla::StyleComputedTimingFunction& GetAnimationTimingFunction(
1699 uint32_t aIndex) const {
1700 return mAnimations[aIndex % mAnimationTimingFunctionCount]
1701 .GetTimingFunction();
1703 mozilla::dom::CompositeOperation GetAnimationComposition(
1704 uint32_t aIndex) const {
1705 return mAnimations[aIndex % mAnimationCompositionCount].GetComposition();
1707 const mozilla::StyleAnimationTimeline& GetTimeline(uint32_t aIndex) const {
1708 return mAnimations[aIndex % mAnimationTimelineCount].GetTimeline();
1711 mozilla::StyleBoolInteger mMozForceBrokenImageIcon;
1712 mozilla::StyleBoolInteger mMozSubtreeHiddenOnlyVisually;
1713 mozilla::StyleImeMode mIMEMode;
1714 mozilla::StyleWindowDragging mWindowDragging;
1715 mozilla::StyleWindowShadow mWindowShadow;
1716 float mWindowOpacity;
1717 // The margin of the window region that should be transparent to events.
1718 mozilla::StyleLength mMozWindowInputRegionMargin;
1719 mozilla::StyleTransform mMozWindowTransform;
1720 mozilla::StyleTransformOrigin mWindowTransformOrigin;
1722 nsStyleAutoArray<mozilla::StyleTransition> mTransitions;
1723 // The number of elements in mTransitions that are not from repeating
1724 // a list due to another property being longer.
1725 uint32_t mTransitionTimingFunctionCount;
1726 uint32_t mTransitionDurationCount;
1727 uint32_t mTransitionDelayCount;
1728 uint32_t mTransitionPropertyCount;
1729 nsStyleAutoArray<mozilla::StyleAnimation> mAnimations;
1730 // The number of elements in mAnimations that are not from repeating
1731 // a list due to another property being longer.
1732 uint32_t mAnimationTimingFunctionCount;
1733 uint32_t mAnimationDurationCount;
1734 uint32_t mAnimationDelayCount;
1735 uint32_t mAnimationNameCount;
1736 uint32_t mAnimationDirectionCount;
1737 uint32_t mAnimationFillModeCount;
1738 uint32_t mAnimationPlayStateCount;
1739 uint32_t mAnimationIterationCountCount;
1740 uint32_t mAnimationCompositionCount;
1741 uint32_t mAnimationTimelineCount;
1743 nsStyleAutoArray<mozilla::StyleScrollTimeline> mScrollTimelines;
1744 uint32_t mScrollTimelineNameCount;
1745 uint32_t mScrollTimelineAxisCount;
1747 nsStyleAutoArray<mozilla::StyleViewTimeline> mViewTimelines;
1748 uint32_t mViewTimelineNameCount;
1749 uint32_t mViewTimelineAxisCount;
1750 uint32_t mViewTimelineInsetCount;
1753 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI {
1754 STYLE_STRUCT(nsStyleUI)
1755 nsStyleUI();
1756 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleUI*);
1758 mozilla::StyleInert mInert;
1759 mozilla::StyleMozTheme mMozTheme;
1761 private:
1762 mozilla::StyleUserInput mUserInput;
1763 mozilla::StyleUserModify mUserModify;
1764 mozilla::StyleUserFocus mUserFocus;
1765 mozilla::StylePointerEvents mPointerEvents;
1766 mozilla::StyleCursor mCursor;
1768 public:
1769 bool IsInert() const { return mInert == mozilla::StyleInert::Inert; }
1771 mozilla::StyleUserInput UserInput() const {
1772 return IsInert() ? mozilla::StyleUserInput::None : mUserInput;
1775 mozilla::StyleUserModify UserModify() const {
1776 return IsInert() ? mozilla::StyleUserModify::ReadOnly : mUserModify;
1779 mozilla::StyleUserFocus UserFocus() const {
1780 return IsInert() ? mozilla::StyleUserFocus::None : mUserFocus;
1783 // This is likely not the getter you want (you probably want
1784 // ComputedStyle::PointerEvents().
1785 mozilla::StylePointerEvents ComputedPointerEvents() const {
1786 return mPointerEvents;
1789 const mozilla::StyleCursor& Cursor() const {
1790 static mozilla::StyleCursor sAuto{{}, mozilla::StyleCursorKind::Auto};
1791 return IsInert() ? sAuto : mCursor;
1794 mozilla::StyleColorOrAuto mAccentColor;
1795 mozilla::StyleCaretColor mCaretColor;
1796 mozilla::StyleScrollbarColor mScrollbarColor;
1797 mozilla::StyleColorScheme mColorScheme;
1799 bool HasCustomScrollbars() const { return !mScrollbarColor.IsAuto(); }
1802 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleXUL {
1803 STYLE_STRUCT(nsStyleXUL)
1804 nsStyleXUL();
1806 float mBoxFlex;
1807 int32_t mBoxOrdinal;
1808 mozilla::StyleBoxAlign mBoxAlign;
1809 mozilla::StyleBoxDirection mBoxDirection;
1810 mozilla::StyleBoxOrient mBoxOrient;
1811 mozilla::StyleBoxPack mBoxPack;
1814 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColumn {
1815 STYLE_STRUCT(nsStyleColumn)
1816 nsStyleColumn();
1818 // This is the maximum number of columns we can process. It's used in
1819 // nsColumnSetFrame.
1820 static const uint32_t kMaxColumnCount = 1000;
1822 // This represents the value of column-count: auto.
1823 static const uint32_t kColumnCountAuto = 0;
1825 uint32_t mColumnCount = kColumnCountAuto;
1826 mozilla::NonNegativeLengthOrAuto mColumnWidth;
1828 mozilla::StyleColor mColumnRuleColor;
1829 mozilla::StyleBorderStyle mColumnRuleStyle; // StyleborderStyle::*
1830 mozilla::StyleColumnFill mColumnFill = mozilla::StyleColumnFill::Balance;
1831 mozilla::StyleColumnSpan mColumnSpan = mozilla::StyleColumnSpan::None;
1833 nscoord GetColumnRuleWidth() const { return mActualColumnRuleWidth; }
1835 bool IsColumnContainerStyle() const {
1836 return mColumnCount != kColumnCountAuto || !mColumnWidth.IsAuto();
1839 bool IsColumnSpanStyle() const {
1840 return mColumnSpan == mozilla::StyleColumnSpan::All;
1843 protected:
1844 // This is the specified value of column-rule-width, but with length values
1845 // computed to absolute. mActualColumnRuleWidth stores the column-rule-width
1846 // value used by layout. (We must store mColumnRuleWidth for the same
1847 // style struct resolution reasons that we do nsStyleBorder::mBorder;
1848 // see that field's comment.)
1849 nscoord mColumnRuleWidth;
1850 // The actual value of column-rule-width is the computed value (an absolute
1851 // length, forced to zero when column-rule-style is none) rounded to device
1852 // pixels. This is the value used by layout.
1853 nscoord mActualColumnRuleWidth;
1856 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVG {
1857 STYLE_STRUCT(nsStyleSVG)
1858 nsStyleSVG();
1860 mozilla::StyleSVGPaint mFill;
1861 mozilla::StyleSVGPaint mStroke;
1862 mozilla::StyleUrlOrNone mMarkerEnd;
1863 mozilla::StyleUrlOrNone mMarkerMid;
1864 mozilla::StyleUrlOrNone mMarkerStart;
1865 mozilla::StyleMozContextProperties mMozContextProperties;
1867 mozilla::StyleSVGStrokeDashArray mStrokeDasharray;
1868 mozilla::StyleSVGLength mStrokeDashoffset;
1869 mozilla::StyleSVGWidth mStrokeWidth;
1871 mozilla::StyleSVGOpacity mFillOpacity;
1872 float mStrokeMiterlimit;
1873 mozilla::StyleSVGOpacity mStrokeOpacity;
1875 mozilla::StyleFillRule mClipRule;
1876 mozilla::StyleColorInterpolation mColorInterpolation;
1877 mozilla::StyleColorInterpolation mColorInterpolationFilters;
1878 mozilla::StyleFillRule mFillRule;
1879 mozilla::StyleSVGPaintOrder mPaintOrder;
1880 mozilla::StyleShapeRendering mShapeRendering;
1881 mozilla::StyleStrokeLinecap mStrokeLinecap;
1882 mozilla::StyleStrokeLinejoin mStrokeLinejoin;
1883 mozilla::StyleDominantBaseline mDominantBaseline;
1884 mozilla::StyleTextAnchor mTextAnchor;
1886 /// Returns true if style has been set to expose the computed values of
1887 /// certain properties (such as 'fill') to the contents of any linked images.
1888 bool ExposesContextProperties() const {
1889 return bool(mMozContextProperties.bits);
1892 bool HasMarker() const {
1893 return mMarkerStart.IsUrl() || mMarkerMid.IsUrl() || mMarkerEnd.IsUrl();
1897 * Returns true if the stroke is not "none" and the stroke-opacity is greater
1898 * than zero (or a context-dependent value).
1900 * This ignores stroke-widths as that depends on the context.
1902 bool HasStroke() const {
1903 if (mStroke.kind.IsNone()) {
1904 return false;
1906 return !mStrokeOpacity.IsOpacity() || mStrokeOpacity.AsOpacity() > 0;
1910 * Returns true if the fill is not "none" and the fill-opacity is greater
1911 * than zero (or a context-dependent value).
1913 bool HasFill() const {
1914 if (mFill.kind.IsNone()) {
1915 return false;
1917 return !mFillOpacity.IsOpacity() || mFillOpacity.AsOpacity() > 0;
1921 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleSVGReset {
1922 STYLE_STRUCT(nsStyleSVGReset)
1923 nsStyleSVGReset();
1924 void TriggerImageLoads(mozilla::dom::Document&, const nsStyleSVGReset*);
1926 bool HasClipPath() const { return !mClipPath.IsNone(); }
1928 bool HasMask() const;
1930 bool HasNonScalingStroke() const {
1931 return mVectorEffect == mozilla::StyleVectorEffect::NonScalingStroke;
1934 // geometry properties
1935 mozilla::LengthPercentage mX;
1936 mozilla::LengthPercentage mY;
1937 mozilla::LengthPercentage mCx;
1938 mozilla::LengthPercentage mCy;
1939 mozilla::NonNegativeLengthPercentageOrAuto mRx;
1940 mozilla::NonNegativeLengthPercentageOrAuto mRy;
1941 mozilla::NonNegativeLengthPercentage mR;
1943 nsStyleImageLayers mMask;
1944 mozilla::StyleClipPath mClipPath;
1945 mozilla::StyleColor mStopColor;
1946 mozilla::StyleColor mFloodColor;
1947 mozilla::StyleColor mLightingColor;
1949 float mStopOpacity;
1950 float mFloodOpacity;
1952 mozilla::StyleVectorEffect mVectorEffect;
1953 mozilla::StyleMaskType mMaskType;
1955 mozilla::StyleDProperty mD;
1958 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleEffects {
1959 STYLE_STRUCT(nsStyleEffects)
1960 nsStyleEffects();
1962 bool HasFilters() const { return !mFilters.IsEmpty(); }
1964 bool HasBackdropFilters() const { return !mBackdropFilters.IsEmpty(); }
1966 bool HasBoxShadowWithInset(bool aInset) const {
1967 for (const auto& shadow : mBoxShadow.AsSpan()) {
1968 if (shadow.inset == aInset) {
1969 return true;
1972 return false;
1975 bool HasMixBlendMode() const {
1976 return mMixBlendMode != mozilla::StyleBlend::Normal;
1979 bool IsOpaque() const { return mOpacity >= 1.0f; }
1981 bool IsTransparent() const { return mOpacity == 0.0f; }
1983 mozilla::StyleOwnedSlice<mozilla::StyleFilter> mFilters;
1984 mozilla::StyleOwnedSlice<mozilla::StyleBoxShadow> mBoxShadow;
1985 mozilla::StyleOwnedSlice<mozilla::StyleFilter> mBackdropFilters;
1986 mozilla::StyleClipRectOrAuto mClip; // offsets from UL border edge
1987 float mOpacity;
1988 mozilla::StyleBlend mMixBlendMode;
1991 #undef STYLE_STRUCT
1993 #define STATIC_ASSERT_TYPE_LAYOUTS_MATCH(T1, T2) \
1994 static_assert(sizeof(T1) == sizeof(T2), \
1995 "Size mismatch between " #T1 " and " #T2); \
1996 static_assert(alignof(T1) == alignof(T2), \
1997 "Align mismatch between " #T1 " and " #T2);
1999 #define STATIC_ASSERT_FIELD_OFFSET_MATCHES(T1, T2, field) \
2000 static_assert(offsetof(T1, field) == offsetof(T2, field), \
2001 "Field offset mismatch of " #field " between " #T1 \
2002 " and " #T2);
2005 * These *_Simple types are used to map Gecko types to layout-equivalent but
2006 * simpler Rust types, to aid Rust binding generation.
2008 * If something in this types or the assertions below needs to change, ask
2009 * bholley, heycam or emilio before!
2011 * <div rustbindgen="true" replaces="nsPoint">
2013 struct nsPoint_Simple {
2014 nscoord x, y;
2017 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsPoint, nsPoint_Simple);
2018 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsPoint, nsPoint_Simple, x);
2019 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsPoint, nsPoint_Simple, y);
2022 * <div rustbindgen="true" replaces="nsMargin">
2024 struct nsMargin_Simple {
2025 nscoord top, right, bottom, left;
2028 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsMargin, nsMargin_Simple);
2029 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, top);
2030 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, right);
2031 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, bottom);
2032 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsMargin, nsMargin_Simple, left);
2035 * <div rustbindgen="true" replaces="nsRect">
2037 struct nsRect_Simple {
2038 nscoord x, y, width, height;
2041 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsRect, nsRect_Simple);
2042 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, x);
2043 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, y);
2044 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, width);
2045 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsRect, nsRect_Simple, height);
2048 * <div rustbindgen="true" replaces="nsSize">
2050 struct nsSize_Simple {
2051 nscoord width, height;
2054 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsSize, nsSize_Simple);
2055 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsSize, nsSize_Simple, width);
2056 STATIC_ASSERT_FIELD_OFFSET_MATCHES(nsSize, nsSize_Simple, height);
2059 * <div rustbindgen="true" replaces="mozilla::UniquePtr">
2061 * TODO(Emilio): This is a workaround and we should be able to get rid of this
2062 * one.
2064 template <typename T>
2065 struct UniquePtr_Simple {
2066 T* mPtr;
2069 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(mozilla::UniquePtr<int>,
2070 UniquePtr_Simple<int>);
2073 * <div rustbindgen replaces="nsTArray"></div>
2075 template <typename T>
2076 class nsTArray_Simple {
2077 protected:
2078 T* mBuffer;
2080 public:
2081 ~nsTArray_Simple() {
2082 // The existence of a user-provided, and therefore non-trivial, destructor
2083 // here prevents bindgen from deriving the Clone trait via a simple memory
2084 // copy.
2089 * <div rustbindgen replaces="CopyableTArray"></div>
2091 template <typename T>
2092 class CopyableTArray_Simple : public nsTArray_Simple<T> {};
2094 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<nsStyleImageLayers::Layer>,
2095 nsTArray_Simple<nsStyleImageLayers::Layer>);
2096 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleTransition>,
2097 nsTArray_Simple<mozilla::StyleTransition>);
2098 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleAnimation>,
2099 nsTArray_Simple<mozilla::StyleAnimation>);
2100 STATIC_ASSERT_TYPE_LAYOUTS_MATCH(nsTArray<mozilla::StyleViewTimeline>,
2101 nsTArray_Simple<mozilla::StyleViewTimeline>);
2103 #endif /* nsStyleStruct_h___ */