diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index c8275c24cc32..a676c3253fce 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -375,7 +375,7 @@ nsDisplayCanvasBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize()); const nsStyleImageLayers::Layer &layer = mBackgroundStyle->StyleBackground()->mImage.mLayers[mLayer]; - if (layer.mAttachment != NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED) + if (layer.mAttachment != StyleImageLayerAttachment::Fixed) return false; nsBackgroundLayerState state = diff --git a/layout/painting/nsCSSRendering.cpp b/layout/painting/nsCSSRendering.cpp index 048ab2c5d740..8ed0d73a2a02 100644 --- a/layout/painting/nsCSSRendering.cpp +++ b/layout/painting/nsCSSRendering.cpp @@ -2334,7 +2334,7 @@ nsCSSRendering::GetImageLayerClip(const nsStyleImageLayers::Layer& aLayer, aClipState->mBGClipArea = clipBorderArea; if (aForFrame->IsScrollFrame() && - NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL == aLayer.mAttachment) { + StyleImageLayerAttachment::Local == aLayer.mAttachment) { // As of this writing, this is still in discussion in the CSS Working Group // http://lists.w3.org/Archives/Public/www-style/2013Jul/0250.html @@ -2947,7 +2947,7 @@ nsCSSRendering::ComputeImageLayerPositioningArea(nsPresContext* aPresContext, LayoutFrameType frameType = aForFrame->Type(); nsIFrame* geometryFrame = aForFrame; if (MOZ_UNLIKELY(frameType == LayoutFrameType::Scroll && - NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL == aLayer.mAttachment)) { + StyleImageLayerAttachment::Local == aLayer.mAttachment)) { nsIScrollableFrame* scrollableFrame = do_QueryFrame(aForFrame); positionArea = nsRect( scrollableFrame->GetScrolledFrame()->GetPosition() @@ -3008,7 +3008,7 @@ nsCSSRendering::ComputeImageLayerPositioningArea(nsPresContext* aPresContext, } nsIFrame* attachedToFrame = aForFrame; - if (NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED == aLayer.mAttachment) { + if (StyleImageLayerAttachment::Fixed == aLayer.mAttachment) { // If it's a fixed background attachment, then the image is placed // relative to the viewport, which is the area of the root frame // in a screen context or the page content frame in a print context. @@ -3283,7 +3283,7 @@ nsCSSRendering::PrepareImageLayer(nsPresContext* aPresContext, // where the background can be drawn to the viewport. nsRect bgClipRect = aBGClipRect; - if (NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED == aLayer.mAttachment && + if (StyleImageLayerAttachment::Fixed == aLayer.mAttachment && !transformedFixed && (aFlags & nsCSSRendering::PAINTBG_TO_WINDOW)) { bgClipRect = positionArea + aBorderArea.TopLeft(); diff --git a/layout/painting/nsDisplayList.cpp b/layout/painting/nsDisplayList.cpp index e7636ac13ec6..f0b83af97157 100644 --- a/layout/painting/nsDisplayList.cpp +++ b/layout/painting/nsDisplayList.cpp @@ -3501,7 +3501,7 @@ nsDisplayBackgroundImage::GetInitData(nsDisplayListBuilder* aBuilder, // if it's affected by a transform. // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17521. bool shouldTreatAsFixed = - layer.mAttachment == NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED && !isTransformedFixed; + layer.mAttachment == StyleImageLayerAttachment::Fixed && !isTransformedFixed; bool shouldFixToViewport = shouldTreatAsFixed && !layer.mImage.IsEmpty(); bool isRasterImage = state.mImageRenderer.IsRasterImage(); diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 1c2a4dd1326f..9185b78359db 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -173,6 +173,7 @@ rusty-enums = [ "mozilla::StyleUserFocus", "mozilla::StyleUserSelect", "mozilla::StyleImageLayerRepeat", + "mozilla::StyleImageLayerAttachment", "mozilla::StyleBoxDecorationBreak", "mozilla::StyleRuleInclusion", "mozilla::StyleGridTrackBreadth", @@ -243,6 +244,7 @@ whitelist-types = [ "mozilla::LookAndFeel", "mozilla::gfx::Float", "mozilla::gfx::FontVariation", + "mozilla::StyleImageLayerAttachment", ".*ThreadSafe.*Holder", "AnonymousContent", "AudioContext", diff --git a/layout/style/nsCSSProps.cpp b/layout/style/nsCSSProps.cpp index dc3cb650ab4e..f39e0cf6b9e4 100644 --- a/layout/style/nsCSSProps.cpp +++ b/layout/style/nsCSSProps.cpp @@ -447,9 +447,9 @@ const KTableEntry nsCSSProps::kTransformStyleKTable[] = { }; const KTableEntry nsCSSProps::kImageLayerAttachmentKTable[] = { - { eCSSKeyword_fixed, NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED }, - { eCSSKeyword_scroll, NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL }, - { eCSSKeyword_local, NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL }, + { eCSSKeyword_fixed, StyleImageLayerAttachment::Fixed }, + { eCSSKeyword_scroll, StyleImageLayerAttachment::Scroll }, + { eCSSKeyword_local, StyleImageLayerAttachment::Local }, { eCSSKeyword_UNKNOWN, -1 } }; diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index 83f338530a24..61d16ea2dc8d 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -254,9 +254,11 @@ enum class FillMode : uint8_t; #define NS_STYLE_ANIMATION_PLAY_STATE_PAUSED 1 // See nsStyleImageLayers -#define NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL 0 -#define NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED 1 -#define NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL 2 +enum class StyleImageLayerAttachment : uint8_t { + Scroll, + Fixed, + Local +}; // A magic value that we use for our "pretend that background-clip is // 'padding' when we have a solid border" optimization. This isn't diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 1f4ab553b169..0e87b27cdb88 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -3111,7 +3111,7 @@ nsStyleImageLayers::Size::operator==(const Size& aOther) const nsStyleImageLayers::Layer::Layer() : mClip(StyleGeometryBox::BorderBox) - , mAttachment(NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL) + , mAttachment(StyleImageLayerAttachment::Scroll) , mBlendMode(NS_STYLE_BLEND_NORMAL) , mComposite(NS_STYLE_MASK_COMPOSITE_ADD) , mMaskMode(NS_STYLE_MASK_MODE_MATCH_SOURCE) @@ -3350,7 +3350,7 @@ nsStyleBackground::HasFixedBackground(nsIFrame* aFrame) const { NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mImage) { const nsStyleImageLayers::Layer &layer = mImage.mLayers[i]; - if (layer.mAttachment == NS_STYLE_IMAGELAYER_ATTACHMENT_FIXED && + if (layer.mAttachment == StyleImageLayerAttachment::Fixed && !layer.mImage.IsEmpty() && !nsLayoutUtils::IsTransformed(aFrame)) { return true; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index ca6475a77aed..ce8b08aa3d16 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -653,6 +653,7 @@ struct nsStyleImageLayers { struct Layer { typedef mozilla::StyleGeometryBox StyleGeometryBox; + typedef mozilla::StyleImageLayerAttachment StyleImageLayerAttachment; nsStyleImage mImage; // [reset] mozilla::Position mPosition; // [reset] @@ -660,12 +661,13 @@ struct nsStyleImageLayers { StyleGeometryBox mClip; // [reset] See nsStyleConsts.h MOZ_INIT_OUTSIDE_CTOR StyleGeometryBox mOrigin; // [reset] See nsStyleConsts.h - uint8_t mAttachment; // [reset] See nsStyleConsts.h + StyleImageLayerAttachment mAttachment; + // [reset] See nsStyleConsts.h // background-only property // This property is used for background layer // only. For a mask layer, it should always // be the initial value, which is - // NS_STYLE_IMAGELAYER_ATTACHMENT_SCROLL. + // StyleImageLayerAttachment::Scroll. uint8_t mBlendMode; // [reset] See nsStyleConsts.h // background-only property // This property is used for background layer diff --git a/layout/style/nsStyleStructInlines.h b/layout/style/nsStyleStructInlines.h index 5e0fd1accf04..48fd263e6c15 100644 --- a/layout/style/nsStyleStructInlines.h +++ b/layout/style/nsStyleStructInlines.h @@ -266,7 +266,7 @@ nsStyleBackground::HasLocalBackground() const NS_FOR_VISIBLE_IMAGE_LAYERS_BACK_TO_FRONT(i, mImage) { const nsStyleImageLayers::Layer& layer = mImage.mLayers[i]; if (!layer.mImage.IsEmpty() && - layer.mAttachment == NS_STYLE_IMAGELAYER_ATTACHMENT_LOCAL) { + layer.mAttachment == mozilla::StyleImageLayerAttachment::Local) { return true; } } diff --git a/servo/components/style/properties/longhand/background.mako.rs b/servo/components/style/properties/longhand/background.mako.rs index d6b9e6e69ba8..a1f1b0394340 100644 --- a/servo/components/style/properties/longhand/background.mako.rs +++ b/servo/components/style/properties/longhand/background.mako.rs @@ -54,7 +54,7 @@ ${helpers.predefined_type( ${helpers.single_keyword("background-attachment", "scroll fixed" + (" local" if product == "gecko" else ""), vector=True, - gecko_constant_prefix="NS_STYLE_IMAGELAYER_ATTACHMENT", + gecko_enum_prefix="StyleImageLayerAttachment", spec="https://drafts.csswg.org/css-backgrounds/#the-background-attachment", animation_value_type="discrete", flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER")}