Skip to content

Commit

Permalink
layout: Add support for box-shadow to Layout 2020
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed Mar 6, 2024
1 parent 096bd29 commit 3af18db
Show file tree
Hide file tree
Showing 30 changed files with 61 additions and 904 deletions.
27 changes: 14 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/layout_2020/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
servo_arc = { workspace = true }
servo_config = { path = "../config" }
servo_geometry = { path = "../geometry" }
servo_url = { path = "../url" }
style = { workspace = true }
style_traits = { workspace = true }
Expand Down
40 changes: 40 additions & 0 deletions components/layout_2020/display_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use gfx_traits::WebRenderEpochToU16;
use msg::constellation_msg::BrowsingContextId;
use net_traits::image_cache::UsePlaceholder;
use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId};
use servo_geometry::MaxRect;
use style::color::{AbsoluteColor, ColorSpace};
use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle;
use style::dom::OpaqueNode;
Expand All @@ -23,6 +24,8 @@ use style::values::specified::text::TextDecorationLine;
use style::values::specified::ui::CursorKind;
use style_traits::CSSPixel;
use webrender_api::{self as wr, units, ClipChainId, ClipId, CommonItemProperties};
use wr::units::LayoutVector2D;
use wr::BoxShadowClipMode;

use crate::context::LayoutContext;
use crate::display_list::conversions::ToWebRender;
Expand Down Expand Up @@ -552,6 +555,7 @@ impl<'a> BuilderForBoxFragment<'a> {
} else {
self.build_hit_test(builder);
self.build_background(builder);
self.build_box_shadow(builder);
self.build_border(builder);
}
}
Expand Down Expand Up @@ -808,6 +812,42 @@ impl<'a> BuilderForBoxFragment<'a> {
.wr()
.push_border(&common, outline_rect, widths, details)
}

fn build_box_shadow(&self, builder: &mut DisplayListBuilder<'_>) {
let box_shadows = &self.fragment.style.get_effects().box_shadow.0;
if box_shadows.is_empty() {
return;
}

// NB: According to CSS-BACKGROUNDS, box shadows render in *reverse* order (front to back).
let border_rect = self.border_rect;
let common = builder.common_properties(MaxRect::max_rect(), &self.fragment.style);
for box_shadow in box_shadows.iter().rev() {
let clip_mode = if box_shadow.inset {
BoxShadowClipMode::Inset
} else {
BoxShadowClipMode::Outset
};

builder.wr().push_box_shadow(
&common,
border_rect,
LayoutVector2D::new(
box_shadow.base.horizontal.px(),
box_shadow.base.vertical.px(),
),
rgba(
self.fragment
.style
.resolve_color(box_shadow.base.color.clone()),
),
box_shadow.base.blur.px(),
box_shadow.spread.px(),
self.border_radius,
clip_mode,
);
}
}
}

fn rgba(color: AbsoluteColor) -> wr::ColorF {
Expand Down

0 comments on commit 3af18db

Please sign in to comment.