aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-05-31 21:09:01 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-06-02 10:53:27 +0200
commit7da94d08802c20b3a31ca2d792e30c9f57958853 (patch)
tree5edd44944ff07dad7bb50ceb7eb5c66284297ef2 /components
parent2c7fbb4b4c9d0468caf61d9c9b33331987ad8de7 (diff)
downloadservo-7da94d08802c20b3a31ca2d792e30c9f57958853.tar.gz
servo-7da94d08802c20b3a31ca2d792e30c9f57958853.zip
Use BorderSideWidth for outline-width
Diffstat (limited to 'components')
-rw-r--r--components/layout/text.rs2
-rw-r--r--components/script/dom/element.rs2
-rw-r--r--components/style/properties/longhand/border.mako.rs4
-rw-r--r--components/style/properties/longhand/column.mako.rs12
-rw-r--r--components/style/properties/longhand/inherited_text.mako.rs10
-rw-r--r--components/style/properties/longhand/outline.mako.rs51
-rw-r--r--components/style/properties/shorthand/border.mako.rs12
-rw-r--r--components/style/values/specified/border.rs81
-rw-r--r--components/style/values/specified/mod.rs89
9 files changed, 112 insertions, 151 deletions
diff --git a/components/layout/text.rs b/components/layout/text.rs
index 481e2025201..10093f251b8 100644
--- a/components/layout/text.rs
+++ b/components/layout/text.rs
@@ -167,7 +167,7 @@ impl TextRunScanner {
};
text_transform = inherited_text_style.text_transform;
letter_spacing = inherited_text_style.letter_spacing;
- word_spacing = inherited_text_style.word_spacing.value().cloned()
+ word_spacing = inherited_text_style.word_spacing.value()
.map(|lop| lop.to_hash_key())
.unwrap_or((Au(0), NotNaN::new(0.0).unwrap()));
text_rendering = inherited_text_style.text_rendering;
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index d7f3b89ba2f..be708113def 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -646,7 +646,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
};
if let Some(border) = border {
- let width_value = specified::BorderWidth::from_length(specified::Length::from_px(border as f32));
+ let width_value = specified::BorderSideWidth::Length(specified::Length::from_px(border as f32));
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::BorderTopWidth(width_value.clone())));
diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs
index dccbb1edfa2..40aaffdc716 100644
--- a/components/style/properties/longhand/border.mako.rs
+++ b/components/style/properties/longhand/border.mako.rs
@@ -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"),
diff --git a/components/style/properties/longhand/column.mako.rs b/components/style/properties/longhand/column.mako.rs
index dee3bbef627..2c99a7f1dc3 100644
--- a/components/style/properties/longhand/column.mako.rs
+++ b/components/style/properties/longhand/column.mako.rs
@@ -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",
diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs
index 1aac10125e3..8b1dafb5cd4 100644
--- a/components/style/properties/longhand/inherited_text.mako.rs
+++ b/components/style/properties/longhand/inherited_text.mako.rs
@@ -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",
diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs
index 0cccccaf310..1640953e305 100644
--- a/components/style/properties/longhand/outline.mako.rs
+++ b/components/style/properties/longhand/outline.mako.rs
@@ -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?
diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs
index e2576891b06..c84549a544f 100644
--- a/components/style/properties/shorthand/border.mako.rs
+++ b/components/style/properties/shorthand/border.mako.rs
@@ -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(())
}
diff --git a/components/style/values/specified/border.rs b/components/style/values/specified/border.rs
index 26b7974732f..741b6a1d94f 100644
--- a/components/style/values/specified/border.rs
+++ b/components/style/values/specified/border.rs
@@ -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]
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index c0bf1cdb3b7..893cbc4db4e 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -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: