New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor outline-style to accept "auto" value in addition to border-style values. #15357
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")} { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check auto here, which we don't right now. You can add a branch here like: structs::NS_STYLE_BORDER_STYLE_AUTO => Either::First(Auto), There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I assumed that we're setting |
||
% 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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,16 +16,45 @@ ${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 } | ||
|
||
use std::fmt; | ||
use style_traits::ToCss; | ||
use values::specified::BorderStyle; | ||
use values::NoViewportPercentage; | ||
use values::computed::ComputedValueAsSpecified; | ||
|
||
pub type SpecifiedValue = Either<Auto, BorderStyle>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wafflespeanut why using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, thought the exception was the other way around, sorry for the noise. |
||
|
||
impl SpecifiedValue { | ||
#[inline] | ||
pub fn none_or_hidden(&self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wafflespeanut is this fine? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep |
||
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 use values::specified::BorderStyle as T; | ||
pub type T = super::SpecifiedValue; | ||
} | ||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { | ||
match SpecifiedValue::parse(input) { | ||
Ok(SpecifiedValue::hidden) => Err(()), | ||
result => result | ||
} | ||
|
||
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> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
use cssparser::Parser; | ||
use media_queries::CSSErrorReporterTest; | ||
use style::parser::ParserContext; | ||
use style::stylesheets::Origin; | ||
use style_traits::ToCss; | ||
|
||
#[test] | ||
fn test_outline_style() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wafflespeanut there doesn't seem to be similar a test case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool with me. |
||
use style::properties::longhands::outline_style; | ||
|
||
assert_roundtrip_with_context!(outline_style::parse, r#"auto"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"none"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"solid"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"double"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"dotted"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"dashed"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"groove"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"ridge"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"inset"#); | ||
assert_roundtrip_with_context!(outline_style::parse, r#"outset"#); | ||
|
||
{ | ||
// The outline-style property accepts the same values as border-style, | ||
// except that 'hidden' is not a legal outline style. | ||
|
||
let url = ::servo_url::ServoUrl::parse("http://localhost").unwrap(); | ||
let context = ParserContext::new(Origin::Author, &url, Box::new(CSSErrorReporterTest)); | ||
let mut parser = Parser::new(r#"hidden"#); | ||
let parsed = outline_style::parse(&context, &mut parser); | ||
assert!(parsed.is_err()); | ||
}; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wafflespeanut I stopped around here when refactoring towards
Either
. I am unsure if I should continue to refactorgfx::display_list::BorderDisplayItem
.Temporarily, the outline is transformed to
border_style::T::none
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore above comment. It's addressed now.