mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Bug 1349885: stylo: Simplify computation of float and position. r=heycam,xidorn
MozReview-Commit-ID: Hh6391DXV5o Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
d4d8293f22
commit
c8e0542059
2 changed files with 34 additions and 59 deletions
|
@ -103,48 +103,13 @@ ${helpers.single_keyword("-moz-top-layer", "none top",
|
||||||
products="gecko", animatable=False, internal=True,
|
products="gecko", animatable=False, internal=True,
|
||||||
spec="Internal (not web-exposed)")}
|
spec="Internal (not web-exposed)")}
|
||||||
|
|
||||||
<%helpers:single_keyword_computed name="position"
|
${helpers.single_keyword("position", "static absolute relative fixed",
|
||||||
values="static absolute relative fixed"
|
need_clone="True",
|
||||||
need_clone="True"
|
extra_gecko_values="sticky",
|
||||||
extra_gecko_values="sticky"
|
animatable="False",
|
||||||
animatable="False"
|
creates_stacking_context="True",
|
||||||
creates_stacking_context="True"
|
abspos_cb="True",
|
||||||
abspos_cb="True"
|
spec="https://drafts.csswg.org/css-position/#position-property")}
|
||||||
spec="https://drafts.csswg.org/css-position/#position-property">
|
|
||||||
impl SpecifiedValue {
|
|
||||||
pub fn is_absolutely_positioned_style(&self) -> bool {
|
|
||||||
matches!(*self, SpecifiedValue::absolute | SpecifiedValue::fixed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use values::HasViewportPercentage;
|
|
||||||
no_viewport_percentage!(SpecifiedValue);
|
|
||||||
impl ToComputedValue for SpecifiedValue {
|
|
||||||
type ComputedValue = computed_value::T;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn to_computed_value(&self, _context: &Context) -> computed_value::T {
|
|
||||||
% if product == "gecko":
|
|
||||||
// https://fullscreen.spec.whatwg.org/#new-stacking-layer
|
|
||||||
// Any position value other than 'absolute' and 'fixed' are
|
|
||||||
// computed to 'absolute' if the element is in a top layer.
|
|
||||||
if !self.is_absolutely_positioned_style() &&
|
|
||||||
matches!(_context.style().get_box().clone__moz_top_layer(),
|
|
||||||
longhands::_moz_top_layer::SpecifiedValue::top) {
|
|
||||||
SpecifiedValue::absolute
|
|
||||||
} else {
|
|
||||||
*self
|
|
||||||
}
|
|
||||||
% else:
|
|
||||||
*self
|
|
||||||
% endif
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue {
|
|
||||||
*computed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</%helpers:single_keyword_computed>
|
|
||||||
|
|
||||||
<%helpers:single_keyword_computed name="float"
|
<%helpers:single_keyword_computed name="float"
|
||||||
values="none left right"
|
values="none left right"
|
||||||
|
@ -164,20 +129,16 @@ ${helpers.single_keyword("-moz-top-layer", "none top",
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||||
if context.style().get_box().clone_position().is_absolutely_positioned_style() {
|
let ltr = context.style().writing_mode.is_bidi_ltr();
|
||||||
computed_value::T::none
|
// https://drafts.csswg.org/css-logical-props/#float-clear
|
||||||
} else {
|
match *self {
|
||||||
let ltr = context.style().writing_mode.is_bidi_ltr();
|
SpecifiedValue::inline_start if ltr => computed_value::T::left,
|
||||||
// https://drafts.csswg.org/css-logical-props/#float-clear
|
SpecifiedValue::inline_start => computed_value::T::right,
|
||||||
match *self {
|
SpecifiedValue::inline_end if ltr => computed_value::T::right,
|
||||||
SpecifiedValue::inline_start if ltr => computed_value::T::left,
|
SpecifiedValue::inline_end => computed_value::T::left,
|
||||||
SpecifiedValue::inline_start => computed_value::T::right,
|
% for value in "none left right".split():
|
||||||
SpecifiedValue::inline_end if ltr => computed_value::T::right,
|
SpecifiedValue::${value} => computed_value::T::${value},
|
||||||
SpecifiedValue::inline_end => computed_value::T::left,
|
% endfor
|
||||||
% for value in "none left right".split():
|
|
||||||
SpecifiedValue::${value} => computed_value::T::${value},
|
|
||||||
% endfor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -1950,6 +1950,7 @@ pub fn cascade(device: &Device,
|
||||||
|
|
||||||
/// NOTE: This function expects the declaration with more priority to appear
|
/// NOTE: This function expects the declaration with more priority to appear
|
||||||
/// first.
|
/// first.
|
||||||
|
#[allow(unused_mut)] // conditionally compiled code for "position"
|
||||||
pub fn apply_declarations<'a, F, I>(device: &Device,
|
pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
is_root_element: bool,
|
is_root_element: bool,
|
||||||
iter_declarations: F,
|
iter_declarations: F,
|
||||||
|
@ -2050,8 +2051,6 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
LonghandId::FontSize |
|
LonghandId::FontSize |
|
||||||
LonghandId::FontFamily |
|
LonghandId::FontFamily |
|
||||||
LonghandId::Color |
|
LonghandId::Color |
|
||||||
LonghandId::Position |
|
|
||||||
LonghandId::Float |
|
|
||||||
LonghandId::TextDecorationLine |
|
LonghandId::TextDecorationLine |
|
||||||
LonghandId::WritingMode |
|
LonghandId::WritingMode |
|
||||||
LonghandId::Direction
|
LonghandId::Direction
|
||||||
|
@ -2094,9 +2093,24 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||||
|
|
||||||
let mut style = context.style;
|
let mut style = context.style;
|
||||||
|
|
||||||
let positioned = matches!(style.get_box().clone_position(),
|
let mut positioned = matches!(style.get_box().clone_position(),
|
||||||
longhands::position::SpecifiedValue::absolute |
|
longhands::position::SpecifiedValue::absolute |
|
||||||
longhands::position::SpecifiedValue::fixed);
|
longhands::position::SpecifiedValue::fixed);
|
||||||
|
|
||||||
|
// https://fullscreen.spec.whatwg.org/#new-stacking-layer
|
||||||
|
// Any position value other than 'absolute' and 'fixed' are
|
||||||
|
// computed to 'absolute' if the element is in a top layer.
|
||||||
|
% if product == "gecko":
|
||||||
|
if !positioned &&
|
||||||
|
matches!(style.get_box().clone__moz_top_layer(),
|
||||||
|
longhands::_moz_top_layer::SpecifiedValue::top) {
|
||||||
|
positioned = true;
|
||||||
|
style.mutate_box().set_position(longhands::position::computed_value::T::absolute);
|
||||||
|
}
|
||||||
|
% endif
|
||||||
|
|
||||||
|
let positioned = positioned; // To ensure it's not mutated further.
|
||||||
|
|
||||||
let floated = style.get_box().clone_float() != longhands::float::computed_value::T::none;
|
let floated = style.get_box().clone_float() != longhands::float::computed_value::T::none;
|
||||||
let is_item = matches!(context.layout_parent_style.get_box().clone_display(),
|
let is_item = matches!(context.layout_parent_style.get_box().clone_display(),
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue