diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2020-07-23 18:27:10 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2020-07-24 09:31:24 +0200 |
commit | b91e2938194e49dc54cf44de3fa6df661fcb18fd (patch) | |
tree | 50d33a6d4933f8bc4264ce4ea39bd1b542c0bf2c /components/layout_2020/lists.rs | |
parent | 4a4199c1d64705e8efbe092879ffd914cd8f33fc (diff) | |
download | servo-b91e2938194e49dc54cf44de3fa6df661fcb18fd.tar.gz servo-b91e2938194e49dc54cf44de3fa6df661fcb18fd.zip |
Add layout support for list markers
Diffstat (limited to 'components/layout_2020/lists.rs')
-rw-r--r-- | components/layout_2020/lists.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/components/layout_2020/lists.rs b/components/layout_2020/lists.rs new file mode 100644 index 00000000000..c8fa7eabee3 --- /dev/null +++ b/components/layout_2020/lists.rs @@ -0,0 +1,50 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::context::LayoutContext; +use crate::dom_traversal::{NodeAndStyleInfo, NodeExt, PseudoElementContentItem}; +use crate::replaced::ReplacedContent; +use style::properties::longhands::list_style_type::computed_value::T as ListStyleType; +use style::properties::style_structs; +use style::values::computed::url::UrlOrNone; + +/// https://drafts.csswg.org/css-lists/#content-property +pub(crate) fn make_marker<'dom, Node>( + context: &LayoutContext, + info: &NodeAndStyleInfo<Node>, +) -> Option<Vec<PseudoElementContentItem>> +where + Node: NodeExt<'dom>, +{ + let style = info.style.get_list(); + + // https://drafts.csswg.org/css-lists/#marker-image + let marker_image = || match &style.list_style_image { + UrlOrNone::Url(url) => Some(vec![ + PseudoElementContentItem::Replaced(ReplacedContent::from_image_url( + info.node, context, url, + )?), + PseudoElementContentItem::Text(" ".into()), + ]), + UrlOrNone::None => None, + }; + marker_image().or_else(|| { + Some(vec![PseudoElementContentItem::Text( + marker_string(style)?.into(), + )]) + }) +} + +/// https://drafts.csswg.org/css-lists/#marker-string +fn marker_string(style: &style_structs::List) -> Option<&'static str> { + // FIXME: add support for counters and other style types + match style.list_style_type { + ListStyleType::None => None, + ListStyleType::Disc => Some("• "), + ListStyleType::Circle => Some("◦ "), + ListStyleType::Square => Some("▪ "), + ListStyleType::DisclosureOpen => Some("▾ "), + ListStyleType::DisclosureClosed => Some("‣ "), + } +} |