mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
2020: paint borders
This commit is contained in:
parent
59f68525c4
commit
5eb1472a33
5 changed files with 95 additions and 47 deletions
|
@ -6,24 +6,22 @@ use crate::fragments::{BoxFragment, Fragment};
|
|||
use crate::geom::physical::{Rect, Vec2};
|
||||
use crate::style_ext::ComputedValuesExt;
|
||||
use app_units::Au;
|
||||
use style::values::computed::Length;
|
||||
use webrender_api::CommonItemProperties;
|
||||
use euclid::{self, SideOffsets2D};
|
||||
use style::values::computed::{BorderStyle, Length};
|
||||
use webrender_api::{self as wr, units, CommonItemProperties};
|
||||
|
||||
pub struct DisplayListBuilder {
|
||||
pipeline_id: webrender_api::PipelineId,
|
||||
pub wr: webrender_api::DisplayListBuilder,
|
||||
pipeline_id: wr::PipelineId,
|
||||
pub wr: wr::DisplayListBuilder,
|
||||
pub is_contentful: bool,
|
||||
}
|
||||
|
||||
impl DisplayListBuilder {
|
||||
pub fn new(
|
||||
pipeline_id: webrender_api::PipelineId,
|
||||
viewport_size: webrender_api::units::LayoutSize,
|
||||
) -> Self {
|
||||
pub fn new(pipeline_id: wr::PipelineId, viewport_size: wr::units::LayoutSize) -> Self {
|
||||
Self {
|
||||
pipeline_id,
|
||||
is_contentful: false,
|
||||
wr: webrender_api::DisplayListBuilder::new(pipeline_id, viewport_size),
|
||||
wr: wr::DisplayListBuilder::new(pipeline_id, viewport_size),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,25 +65,22 @@ impl BoxFragment {
|
|||
is_contentful: &mut IsContentful,
|
||||
containing_block: &Rect<Length>,
|
||||
) {
|
||||
let background_color = self
|
||||
.style
|
||||
.resolve_color(self.style.clone_background_color());
|
||||
if background_color.alpha > 0 {
|
||||
let clip_rect = self
|
||||
.border_rect()
|
||||
.to_physical(self.style.writing_mode(), containing_block)
|
||||
.translate(&containing_block.top_left)
|
||||
.into();
|
||||
let common = CommonItemProperties {
|
||||
clip_rect,
|
||||
clip_id: webrender_api::ClipId::root(builder.pipeline_id),
|
||||
spatial_id: webrender_api::SpatialId::root_scroll_node(builder.pipeline_id),
|
||||
hit_info: None,
|
||||
// TODO(gw): Make use of the WR backface visibility functionality.
|
||||
is_backface_visible: true,
|
||||
};
|
||||
builder.wr.push_rect(&common, rgba(background_color))
|
||||
}
|
||||
let border_rect = self
|
||||
.border_rect()
|
||||
.to_physical(self.style.writing_mode(), containing_block)
|
||||
.translate(&containing_block.top_left)
|
||||
.into();
|
||||
let common = CommonItemProperties {
|
||||
clip_rect: border_rect,
|
||||
clip_id: wr::ClipId::root(builder.pipeline_id),
|
||||
spatial_id: wr::SpatialId::root_scroll_node(builder.pipeline_id),
|
||||
hit_info: None,
|
||||
// TODO(gw): Make use of the WR backface visibility functionality.
|
||||
is_backface_visible: true,
|
||||
};
|
||||
|
||||
self.background_display_items(builder, &common);
|
||||
self.border_display_items(builder, &common, border_rect);
|
||||
let content_rect = self
|
||||
.content_rect
|
||||
.to_physical(self.style.writing_mode(), containing_block)
|
||||
|
@ -94,10 +89,65 @@ impl BoxFragment {
|
|||
child.build_display_list(builder, is_contentful, &content_rect)
|
||||
}
|
||||
}
|
||||
|
||||
fn background_display_items(
|
||||
&self,
|
||||
builder: &mut DisplayListBuilder,
|
||||
common: &CommonItemProperties,
|
||||
) {
|
||||
let background_color = self
|
||||
.style
|
||||
.resolve_color(self.style.clone_background_color());
|
||||
if background_color.alpha > 0 {
|
||||
builder.wr.push_rect(common, rgba(background_color))
|
||||
}
|
||||
}
|
||||
|
||||
fn border_display_items(
|
||||
&self,
|
||||
builder: &mut DisplayListBuilder,
|
||||
common: &CommonItemProperties,
|
||||
border_rect: units::LayoutRect,
|
||||
) {
|
||||
let b = self.style.get_border();
|
||||
let widths = SideOffsets2D::new(
|
||||
b.border_top_width.px(),
|
||||
b.border_right_width.px(),
|
||||
b.border_bottom_width.px(),
|
||||
b.border_left_width.px(),
|
||||
);
|
||||
if widths == SideOffsets2D::zero() {
|
||||
return;
|
||||
}
|
||||
let side = |style, color| wr::BorderSide {
|
||||
color: rgba(self.style.resolve_color(color)),
|
||||
style: match style {
|
||||
BorderStyle::None => wr::BorderStyle::None,
|
||||
BorderStyle::Solid => wr::BorderStyle::Solid,
|
||||
BorderStyle::Double => wr::BorderStyle::Double,
|
||||
BorderStyle::Dotted => wr::BorderStyle::Dotted,
|
||||
BorderStyle::Dashed => wr::BorderStyle::Dashed,
|
||||
BorderStyle::Hidden => wr::BorderStyle::Hidden,
|
||||
BorderStyle::Groove => wr::BorderStyle::Groove,
|
||||
BorderStyle::Ridge => wr::BorderStyle::Ridge,
|
||||
BorderStyle::Inset => wr::BorderStyle::Inset,
|
||||
BorderStyle::Outset => wr::BorderStyle::Outset,
|
||||
},
|
||||
};
|
||||
let details = wr::BorderDetails::Normal(wr::NormalBorder {
|
||||
top: side(b.border_top_style, b.border_top_color),
|
||||
right: side(b.border_right_style, b.border_right_color),
|
||||
bottom: side(b.border_bottom_style, b.border_bottom_color),
|
||||
left: side(b.border_left_style, b.border_left_color),
|
||||
radius: wr::BorderRadius::zero(),
|
||||
do_aa: true,
|
||||
});
|
||||
builder.wr.push_border(common, border_rect, widths, details)
|
||||
}
|
||||
}
|
||||
|
||||
fn rgba(rgba: cssparser::RGBA) -> webrender_api::ColorF {
|
||||
webrender_api::ColorF::new(
|
||||
fn rgba(rgba: cssparser::RGBA) -> wr::ColorF {
|
||||
wr::ColorF::new(
|
||||
rgba.red_f32(),
|
||||
rgba.green_f32(),
|
||||
rgba.blue_f32(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue