mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Refactor outline-style to accept "auto" value in addition to border-style values.
Fixes https://github.com/servo/servo/issues/15207
This commit is contained in:
parent
8b9dc9392b
commit
09d4751054
11 changed files with 164 additions and 26 deletions
|
@ -1072,15 +1072,18 @@ impl FragmentDisplayListBuilding for Fragment {
|
|||
style: &ServoComputedValues,
|
||||
bounds: &Rect<Au>,
|
||||
clip: &ClippingRegion) {
|
||||
use style::values::Either;
|
||||
|
||||
let width = style.get_outline().outline_width;
|
||||
if width == Au(0) {
|
||||
return
|
||||
}
|
||||
|
||||
let outline_style = style.get_outline().outline_style;
|
||||
if outline_style == border_style::T::none {
|
||||
return
|
||||
}
|
||||
let outline_style = match style.get_outline().outline_style {
|
||||
Either::First(_auto) => border_style::T::solid,
|
||||
Either::Second(border_style::T::none) => return,
|
||||
Either::Second(border_style) => border_style
|
||||
};
|
||||
|
||||
// Outlines are not accounted for in the dimensions of the border box, so adjust the
|
||||
// absolute bounds.
|
||||
|
|
|
@ -59,6 +59,8 @@ use std::ptr;
|
|||
use std::sync::Arc;
|
||||
use std::cmp;
|
||||
use values::computed::ToComputedValue;
|
||||
use values::{Either, Auto};
|
||||
use computed_values::border_style;
|
||||
|
||||
pub mod style_structs {
|
||||
% for style_struct in data.style_structs:
|
||||
|
@ -913,7 +915,38 @@ fn static_assert() {
|
|||
skip_longhands="${skip_outline_longhands}"
|
||||
skip_additionals="*">
|
||||
|
||||
<% impl_keyword("outline_style", "mOutlineStyle", border_style_keyword, need_clone=True) %>
|
||||
#[allow(non_snake_case)]
|
||||
pub fn set_outline_style(&mut self, v: longhands::outline_style::computed_value::T) {
|
||||
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
|
||||
let result = match v {
|
||||
% for value in border_style_keyword.values_for('gecko'):
|
||||
Either::Second(border_style::T::${to_rust_ident(value)}) =>
|
||||
structs::${border_style_keyword.gecko_constant(value)} ${border_style_keyword.maybe_cast("u8")},
|
||||
% endfor
|
||||
Either::First(Auto) =>
|
||||
structs::${border_style_keyword.gecko_constant('auto')} ${border_style_keyword.maybe_cast("u8")},
|
||||
};
|
||||
${set_gecko_property("mOutlineStyle", "result")}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn copy_outline_style_from(&mut self, other: &Self) {
|
||||
self.gecko.mOutlineStyle = other.gecko.mOutlineStyle;
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn clone_outline_style(&self) -> longhands::outline_style::computed_value::T {
|
||||
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
|
||||
match ${get_gecko_property("mOutlineStyle")} ${border_style_keyword.maybe_cast("u32")} {
|
||||
% for value in border_style_keyword.values_for('gecko'):
|
||||
structs::${border_style_keyword.gecko_constant(value)} => Either::Second(border_style::T::${value}),
|
||||
% endfor
|
||||
structs::${border_style_keyword.gecko_constant('auto')} => Either::First(Auto),
|
||||
% if border_style_keyword.gecko_inexhaustive:
|
||||
x => panic!("Found unexpected value in style struct for outline_style property: {:?}", x),
|
||||
% endif
|
||||
}
|
||||
}
|
||||
|
||||
<% impl_app_units("outline_width", "mActualOutlineWidth", need_clone=True,
|
||||
round_to_pixels=True) %>
|
||||
|
@ -2821,4 +2854,3 @@ pub unsafe extern "C" fn Servo_GetStyleVariables(_cv: ServoComputedValuesBorrowe
|
|||
-> *const nsStyleVariables {
|
||||
&*EMPTY_VARIABLES_STRUCT
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
% for side in ALL_SIDES:
|
||||
${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle",
|
||||
"specified::BorderStyle::none",
|
||||
needs_context=False, need_clone=True,
|
||||
need_clone=True,
|
||||
alias=maybe_moz_logical_alias(product, side, "-moz-border-%s-style"),
|
||||
spec=maybe_logical_spec(side, "style"),
|
||||
animatable=False, logical = side[1])}
|
||||
|
|
|
@ -16,17 +16,46 @@ ${helpers.predefined_type("outline-color", "CSSColor", "::cssparser::Color::Curr
|
|||
|
||||
<%helpers:longhand name="outline-style" need_clone="True" animatable="False"
|
||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline-style">
|
||||
pub use values::specified::BorderStyle as SpecifiedValue;
|
||||
pub fn get_initial_value() -> SpecifiedValue { SpecifiedValue::none }
|
||||
pub mod computed_value {
|
||||
pub use values::specified::BorderStyle as T;
|
||||
}
|
||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
match SpecifiedValue::parse(input) {
|
||||
Ok(SpecifiedValue::hidden) => Err(()),
|
||||
result => result
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::specified::BorderStyle;
|
||||
use values::NoViewportPercentage;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
|
||||
pub type SpecifiedValue = Either<Auto, BorderStyle>;
|
||||
|
||||
impl SpecifiedValue {
|
||||
#[inline]
|
||||
pub fn none_or_hidden(&self) -> bool {
|
||||
match *self {
|
||||
Either::First(ref _auto) => false,
|
||||
Either::Second(ref border_style) => border_style.none_or_hidden()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
Either::Second(BorderStyle::none)
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
pub type T = super::SpecifiedValue;
|
||||
}
|
||||
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
SpecifiedValue::parse(context, input)
|
||||
.and_then(|result| {
|
||||
if let Either::Second(BorderStyle::hidden) = result {
|
||||
// The outline-style property accepts the same values as border-style,
|
||||
// except that 'hidden' is not a legal outline style.
|
||||
Err(())
|
||||
} else {
|
||||
Ok(result)
|
||||
}
|
||||
})
|
||||
}
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:longhand name="outline-width" animatable="True"
|
||||
|
|
|
@ -10,7 +10,6 @@ ${helpers.four_sides_shorthand("border-color", "border-%s-color", "specified::CS
|
|||
|
||||
${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
||||
"specified::BorderStyle::parse",
|
||||
needs_context=False,
|
||||
spec="https://drafts.csswg.org/css-backgrounds/#border-style")}
|
||||
|
||||
<%helpers:shorthand name="border-width" sub_properties="${
|
||||
|
@ -61,7 +60,7 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
}
|
||||
}
|
||||
if style.is_none() {
|
||||
if let Ok(value) = input.try(specified::BorderStyle::parse) {
|
||||
if let Ok(value) = input.try(|i| specified::BorderStyle::parse(context, i)) {
|
||||
style = Some(value);
|
||||
any = true;
|
||||
continue
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<%helpers:shorthand name="outline" sub_properties="outline-color outline-style outline-width"
|
||||
spec="https://drafts.csswg.org/css-ui/#propdef-outline">
|
||||
use properties::longhands::outline_width;
|
||||
use properties::longhands::{outline_width, outline_style};
|
||||
use values::specified;
|
||||
use parser::Parse;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
}
|
||||
}
|
||||
if style.is_none() {
|
||||
if let Ok(value) = input.try(specified::BorderStyle::parse) {
|
||||
if let Ok(value) = input.try(|input| outline_style::parse(context, input)) {
|
||||
style = Some(value);
|
||||
any = true;
|
||||
continue
|
||||
|
|
|
@ -25,9 +25,9 @@ macro_rules! define_numbered_css_keyword_enum {
|
|||
$( $variant = $value ),+
|
||||
}
|
||||
|
||||
impl $name {
|
||||
impl Parse for $name {
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
||||
fn parse(_context: &ParserContext, input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
$( $css => Ok($name::$variant), )+
|
||||
_ => Err(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue