mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Support logical values for float/clear
This commit is contained in:
parent
0b515c2bc9
commit
6a88723409
3 changed files with 70 additions and 14 deletions
|
@ -338,7 +338,7 @@
|
|||
</%call>
|
||||
</%def>
|
||||
|
||||
<%def name="single_keyword_computed(name, values, vector=False, **kwargs)">
|
||||
<%def name="single_keyword_computed(name, values, vector=False, extra_specified=None, **kwargs)">
|
||||
<%
|
||||
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||
'gecko_constant_prefix', 'gecko_enum_prefix',
|
||||
|
@ -348,7 +348,16 @@
|
|||
%>
|
||||
|
||||
<%def name="inner_body()">
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
% if extra_specified:
|
||||
use style_traits::ToCss;
|
||||
define_css_keyword_enum! { SpecifiedValue:
|
||||
% for value in data.longhands_by_name[name].keyword.values_for(product) + extra_specified.split():
|
||||
"${value}" => ${to_rust_ident(value)},
|
||||
% endfor
|
||||
}
|
||||
% else:
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
% endif
|
||||
pub mod computed_value {
|
||||
use style_traits::ToCss;
|
||||
define_css_keyword_enum! { T:
|
||||
|
@ -363,12 +372,12 @@
|
|||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
get_initial_value()
|
||||
SpecifiedValue::${to_rust_ident(values.split()[0])}
|
||||
}
|
||||
#[inline]
|
||||
pub fn parse(_context: &ParserContext, input: &mut Parser)
|
||||
-> Result<SpecifiedValue, ()> {
|
||||
computed_value::T::parse(input)
|
||||
SpecifiedValue::parse(input)
|
||||
}
|
||||
</%def>
|
||||
% if vector:
|
||||
|
|
|
@ -98,9 +98,10 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
|
|||
need_clone=True, extra_gecko_values="sticky", animatable=False,
|
||||
spec="https://drafts.csswg.org/css-position/#position-property")}
|
||||
|
||||
// TODO add support for logical values inline-start and inline-end (https://drafts.csswg.org/css-logical-props/#float-clear)
|
||||
<%helpers:single_keyword_computed name="float"
|
||||
values="none left right"
|
||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||
extra_specified="inline-start inline-end"
|
||||
animatable="False"
|
||||
need_clone="True"
|
||||
gecko_enum_prefix="StyleFloat"
|
||||
|
@ -118,23 +119,69 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
|
|||
longhands::position::SpecifiedValue::absolute |
|
||||
longhands::position::SpecifiedValue::fixed);
|
||||
if positioned {
|
||||
SpecifiedValue::none
|
||||
computed_value::T::none
|
||||
} else {
|
||||
*self
|
||||
let ltr = context.style().writing_mode.is_bidi_ltr();
|
||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||
match *self {
|
||||
SpecifiedValue::inline_start if ltr => computed_value::T::left,
|
||||
SpecifiedValue::inline_start => computed_value::T::right,
|
||||
SpecifiedValue::inline_end if ltr => computed_value::T::right,
|
||||
SpecifiedValue::inline_end => computed_value::T::left,
|
||||
% for value in "none left right".split():
|
||||
SpecifiedValue::${value} => computed_value::T::${value},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
|
||||
*computed
|
||||
match *computed {
|
||||
% for value in "none left right".split():
|
||||
computed_value::T::${value} => SpecifiedValue::${value},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</%helpers:single_keyword_computed>
|
||||
|
||||
${helpers.single_keyword("clear", "none left right both",
|
||||
animatable=False, gecko_ffi_name="mBreakType",
|
||||
gecko_enum_prefix="StyleClear",
|
||||
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control")}
|
||||
<%helpers:single_keyword_computed name="clear"
|
||||
values="none left right both"
|
||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||
extra_specified="inline-start inline-end"
|
||||
animatable="False"
|
||||
gecko_enum_prefix="StyleClear"
|
||||
gecko_ffi_name="mBreakType"
|
||||
spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control">
|
||||
use values::NoViewportPercentage;
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
let ltr = context.style().writing_mode.is_bidi_ltr();
|
||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||
match *self {
|
||||
SpecifiedValue::inline_start if ltr => computed_value::T::left,
|
||||
SpecifiedValue::inline_start => computed_value::T::right,
|
||||
SpecifiedValue::inline_end if ltr => computed_value::T::right,
|
||||
SpecifiedValue::inline_end => computed_value::T::left,
|
||||
% for value in "none left right both".split():
|
||||
SpecifiedValue::${value} => computed_value::T::${value},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
|
||||
match *computed {
|
||||
% for value in "none left right both".split():
|
||||
computed_value::T::${value} => SpecifiedValue::${value},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:single_keyword_computed>
|
||||
|
||||
<%helpers:longhand name="-servo-display-for-hypothetical-box"
|
||||
animatable="False"
|
||||
|
|
|
@ -1891,7 +1891,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D<Au>,
|
|||
let positioned = matches!(style.get_box().clone_position(),
|
||||
longhands::position::SpecifiedValue::absolute |
|
||||
longhands::position::SpecifiedValue::fixed);
|
||||
let floated = style.get_box().clone_float() != longhands::float::SpecifiedValue::none;
|
||||
let floated = style.get_box().clone_float() != longhands::float::computed_value::T::none;
|
||||
// FIXME(heycam): We should look past any display:contents ancestors to
|
||||
// determine if we are a flex or grid item, but we don't have access to
|
||||
// grandparent or higher style here.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue