mirror of
https://github.com/servo/servo.git
synced 2025-07-21 14:23:41 +01:00
Use BorderSideWidth for outline-width
This commit is contained in:
parent
2c7fbb4b4c
commit
7da94d0880
13 changed files with 137 additions and 186 deletions
|
@ -32,7 +32,9 @@
|
|||
spec=maybe_logical_spec(side, "style"),
|
||||
animation_value_type="none", logical=side[1])}
|
||||
|
||||
${helpers.predefined_type("border-%s-width" % side[0], "BorderWidth", "Au::from_px(3)",
|
||||
${helpers.predefined_type("border-%s-width" % side[0],
|
||||
"BorderSideWidth",
|
||||
"Au::from_px(3)",
|
||||
computed_type="::app_units::Au",
|
||||
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-width"),
|
||||
spec=maybe_logical_spec(side, "width"),
|
||||
|
|
|
@ -40,11 +40,15 @@ ${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz",
|
|||
products="gecko", animation_value_type="discrete",
|
||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")}
|
||||
|
||||
${helpers.predefined_type("column-rule-width", "BorderWidth", "Au::from_px(3)",
|
||||
initial_specified_value="specified::BorderWidth::Medium",
|
||||
products="gecko", computed_type="::app_units::Au",
|
||||
${helpers.predefined_type("column-rule-width",
|
||||
"BorderSideWidth",
|
||||
"Au::from_px(3)",
|
||||
initial_specified_value="specified::BorderSideWidth::Medium",
|
||||
computed_type="::app_units::Au",
|
||||
products="gecko",
|
||||
spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule-width",
|
||||
animation_value_type="ComputedValue", extra_prefixes="moz")}
|
||||
animation_value_type="ComputedValue",
|
||||
extra_prefixes="moz")}
|
||||
|
||||
// https://drafts.csswg.org/css-multicol-1/#crc
|
||||
${helpers.predefined_type("column-rule-color", "CSSColor",
|
||||
|
|
|
@ -872,13 +872,15 @@ ${helpers.predefined_type(
|
|||
ignored_when_colors_disabled=True,
|
||||
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-color")}
|
||||
|
||||
${helpers.predefined_type("-webkit-text-stroke-width", "BorderWidth", "Au::from_px(0)",
|
||||
initial_specified_value="specified::BorderWidth::from_length(specified::Length::zero())",
|
||||
computed_type="::app_units::Au", products="gecko",
|
||||
${helpers.predefined_type("-webkit-text-stroke-width",
|
||||
"BorderSideWidth",
|
||||
"Au::from_px(0)",
|
||||
initial_specified_value="specified::BorderSideWidth::Length(specified::Length::zero())",
|
||||
computed_type="::app_units::Au",
|
||||
products="gecko",
|
||||
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke-width",
|
||||
animation_value_type="none")}
|
||||
|
||||
|
||||
// CSS Ruby Layout Module Level 1
|
||||
// https://drafts.csswg.org/css-ruby/
|
||||
${helpers.single_keyword("ruby-align", "space-around start center space-between",
|
||||
|
|
|
@ -61,50 +61,13 @@ ${helpers.predefined_type("outline-color", "CSSColor", "computed::CSSColor::Curr
|
|||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="outline-width" animation_value_type="ComputedValue"
|
||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-width">
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
specified::parse_border_width(context, input).map(SpecifiedValue)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub specified::Length);
|
||||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
pub type T = Au;
|
||||
}
|
||||
|
||||
pub use super::border_top_width::get_initial_value;
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue(specified::Length::NoCalc(specified::NoCalcLength::medium()))
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
self.0.to_computed_value(context)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> Self {
|
||||
SpecifiedValue(ToComputedValue::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("outline-width",
|
||||
"BorderSideWidth",
|
||||
"Au::from_px(3)",
|
||||
initial_specified_value="specified::BorderSideWidth::Medium",
|
||||
computed_type="::app_units::Au",
|
||||
animation_value_type="ComputedValue",
|
||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-width")}
|
||||
|
||||
// The -moz-outline-radius-* properties are non-standard and not on a standards track.
|
||||
// TODO: Should they animate?
|
||||
|
|
|
@ -18,11 +18,11 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
for side in PHYSICAL_SIDES)}"
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#border-width">
|
||||
use values::generics::rect::Rect;
|
||||
use values::specified::{AllowQuirks, BorderWidth};
|
||||
use values::specified::{AllowQuirks, BorderSideWidth};
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let rect = Rect::parse_with(context, input, |_, i| {
|
||||
BorderWidth::parse_quirky(context, i, AllowQuirks::Yes)
|
||||
BorderSideWidth::parse_quirky(context, i, AllowQuirks::Yes)
|
||||
})?;
|
||||
Ok(expanded! {
|
||||
border_top_width: rect.0,
|
||||
|
@ -46,8 +46,8 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
||||
-> Result<(specified::CSSColor,
|
||||
specified::BorderStyle,
|
||||
specified::BorderWidth), ()> {
|
||||
use values::specified::{CSSColor, BorderStyle, BorderWidth};
|
||||
specified::BorderSideWidth), ()> {
|
||||
use values::specified::{CSSColor, BorderStyle, BorderSideWidth};
|
||||
let _unused = context;
|
||||
let mut color = None;
|
||||
let mut style = None;
|
||||
|
@ -69,7 +69,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
}
|
||||
if width.is_none() {
|
||||
if let Ok(value) = input.try(|i| BorderWidth::parse(context, i)) {
|
||||
if let Ok(value) = input.try(|i| BorderSideWidth::parse(context, i)) {
|
||||
width = Some(value);
|
||||
any = true;
|
||||
continue
|
||||
|
@ -80,7 +80,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
if any {
|
||||
Ok((color.unwrap_or_else(|| CSSColor::currentcolor()),
|
||||
style.unwrap_or(BorderStyle::none),
|
||||
width.unwrap_or(BorderWidth::Medium)))
|
||||
width.unwrap_or(BorderSideWidth::Medium)))
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
|
|
|
@ -4,15 +4,33 @@
|
|||
|
||||
//! Specified types for CSS values related to borders.
|
||||
|
||||
use app_units::Au;
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
|
||||
use values::generics::border::BorderImageSlice as GenericBorderImageSlice;
|
||||
use values::generics::border::BorderImageWidthSide as GenericBorderImageWidthSide;
|
||||
use values::generics::border::BorderRadius as GenericBorderRadius;
|
||||
use values::generics::rect::Rect;
|
||||
use values::specified::{Number, NumberOrPercentage};
|
||||
use values::specified::length::LengthOrPercentage;
|
||||
use values::specified::{AllowQuirks, Number, NumberOrPercentage};
|
||||
use values::specified::length::{Length, LengthOrPercentage};
|
||||
|
||||
/// A specified value for a single side of the `border-width` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
pub enum BorderSideWidth {
|
||||
/// `thin`
|
||||
Thin,
|
||||
/// `medium`
|
||||
Medium,
|
||||
/// `thick`
|
||||
Thick,
|
||||
/// `<length>`
|
||||
Length(Length),
|
||||
}
|
||||
|
||||
/// A specified value for the `border-image-width` property.
|
||||
pub type BorderImageWidth = Rect<BorderImageWidthSide>;
|
||||
|
@ -29,6 +47,65 @@ pub type BorderRadius = GenericBorderRadius<LengthOrPercentage>;
|
|||
/// A specified value for the `border-*-radius` longhand properties.
|
||||
pub type BorderCornerRadius = GenericBorderCornerRadius<LengthOrPercentage>;
|
||||
|
||||
impl BorderSideWidth {
|
||||
/// Parses, with quirks.
|
||||
pub fn parse_quirky(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<Self, ()>
|
||||
{
|
||||
if let Ok(length) = input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
|
||||
return Ok(BorderSideWidth::Length(length));
|
||||
}
|
||||
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||
"thin" => Ok(BorderSideWidth::Thin),
|
||||
"medium" => Ok(BorderSideWidth::Medium),
|
||||
"thick" => Ok(BorderSideWidth::Thick),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for BorderSideWidth {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
Self::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for BorderSideWidth {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
BorderSideWidth::Thin => dest.write_str("thin"),
|
||||
BorderSideWidth::Medium => dest.write_str("medium"),
|
||||
BorderSideWidth::Thick => dest.write_str("thick"),
|
||||
BorderSideWidth::Length(ref length) => length.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for BorderSideWidth {
|
||||
type ComputedValue = Au;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
// We choose the pixel length of the keyword values the same as both spec and gecko.
|
||||
// Spec: https://drafts.csswg.org/css-backgrounds-3/#line-width
|
||||
// Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1312155#c0
|
||||
match *self {
|
||||
BorderSideWidth::Thin => Length::from_px(1.).to_computed_value(context),
|
||||
BorderSideWidth::Medium => Length::from_px(3.).to_computed_value(context),
|
||||
BorderSideWidth::Thick => Length::from_px(5.).to_computed_value(context),
|
||||
BorderSideWidth::Length(ref length) => length.to_computed_value(context)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
BorderSideWidth::Length(ToComputedValue::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
|
||||
impl BorderImageWidthSide {
|
||||
/// Returns `1`.
|
||||
#[inline]
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
//! TODO(emilio): Enhance docs.
|
||||
|
||||
use Namespace;
|
||||
use app_units::Au;
|
||||
use context::QuirksMode;
|
||||
use cssparser::{self, Parser, Token, serialize_identifier};
|
||||
use itoa;
|
||||
|
@ -32,7 +31,7 @@ use values::specified::calc::CalcNode;
|
|||
pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
pub use self::background::BackgroundSize;
|
||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||
pub use self::border::{BorderImageWidthSide, BorderRadius};
|
||||
pub use self::border::{BorderImageWidthSide, BorderRadius, BorderSideWidth};
|
||||
pub use self::color::Color;
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use super::generics::grid::GridLine;
|
||||
|
@ -434,92 +433,6 @@ impl Angle {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse_border_width(context: &ParserContext, input: &mut Parser) -> Result<Length, ()> {
|
||||
input.try(|i| Length::parse_non_negative(context, i)).or_else(|()| {
|
||||
match_ignore_ascii_case! { &try!(input.expect_ident()),
|
||||
"thin" => Ok(Length::from_px(1.)),
|
||||
"medium" => Ok(Length::from_px(3.)),
|
||||
"thick" => Ok(Length::from_px(5.)),
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum BorderWidth {
|
||||
Thin,
|
||||
Medium,
|
||||
Thick,
|
||||
Width(Length),
|
||||
}
|
||||
|
||||
impl Parse for BorderWidth {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<BorderWidth, ()> {
|
||||
Self::parse_quirky(context, input, AllowQuirks::No)
|
||||
}
|
||||
}
|
||||
|
||||
impl BorderWidth {
|
||||
/// Parses a border width, allowing quirks.
|
||||
pub fn parse_quirky(context: &ParserContext,
|
||||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks)
|
||||
-> Result<BorderWidth, ()> {
|
||||
match input.try(|i| Length::parse_non_negative_quirky(context, i, allow_quirks)) {
|
||||
Ok(length) => Ok(BorderWidth::Width(length)),
|
||||
Err(_) => match_ignore_ascii_case! { &try!(input.expect_ident()),
|
||||
"thin" => Ok(BorderWidth::Thin),
|
||||
"medium" => Ok(BorderWidth::Medium),
|
||||
"thick" => Ok(BorderWidth::Thick),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BorderWidth {
|
||||
#[allow(missing_docs)]
|
||||
pub fn from_length(length: Length) -> Self {
|
||||
BorderWidth::Width(length)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for BorderWidth {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
BorderWidth::Thin => dest.write_str("thin"),
|
||||
BorderWidth::Medium => dest.write_str("medium"),
|
||||
BorderWidth::Thick => dest.write_str("thick"),
|
||||
BorderWidth::Width(ref length) => length.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for BorderWidth {
|
||||
type ComputedValue = Au;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
// We choose the pixel length of the keyword values the same as both spec and gecko.
|
||||
// Spec: https://drafts.csswg.org/css-backgrounds-3/#line-width
|
||||
// Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1312155#c0
|
||||
match *self {
|
||||
BorderWidth::Thin => Length::from_px(1.).to_computed_value(context),
|
||||
BorderWidth::Medium => Length::from_px(3.).to_computed_value(context),
|
||||
BorderWidth::Thick => Length::from_px(5.).to_computed_value(context),
|
||||
BorderWidth::Width(ref length) => length.to_computed_value(context)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
BorderWidth::Width(ToComputedValue::from_computed_value(computed))
|
||||
}
|
||||
}
|
||||
|
||||
// The integer values here correspond to the border conflict resolution rules in CSS 2.1 §
|
||||
// 17.6.2.1. Higher values override lower values.
|
||||
define_numbered_css_keyword_enum! { BorderStyle:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue