mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
Auto merge of #16597 - Manishearth:stylo-overflow, r=emilio
stylo: support all overflow values overflow:clip doesn't exist, it's just called clip internally. Renamed, and added the other missing values. I also removed the overflow newtype -- no need for extra code bloat, and it's not protecting us from much. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16597) <!-- Reviewable:end -->
This commit is contained in:
commit
cd8af86244
10 changed files with 63 additions and 81 deletions
|
@ -1832,13 +1832,11 @@ fn static_assert() {
|
|||
|
||||
<%call expr="impl_keyword_clone('display', 'mDisplay', display_keyword)"></%call>
|
||||
|
||||
// overflow-y is implemented as a newtype of overflow-x, so we need special handling.
|
||||
// We could generalize this if we run into other newtype keywords.
|
||||
<% overflow_x = data.longhands_by_name["overflow-x"] %>
|
||||
pub fn set_overflow_y(&mut self, v: longhands::overflow_y::computed_value::T) {
|
||||
use properties::longhands::overflow_x::computed_value::T as BaseType;
|
||||
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
|
||||
self.gecko.mOverflowY = match v.0 {
|
||||
self.gecko.mOverflowY = match v {
|
||||
% for value in overflow_x.keyword.values_for('gecko'):
|
||||
BaseType::${to_rust_ident(value)} => structs::${overflow_x.keyword.gecko_constant(value)} as u8,
|
||||
% endfor
|
||||
|
@ -1847,11 +1845,10 @@ fn static_assert() {
|
|||
${impl_simple_copy('overflow_y', 'mOverflowY')}
|
||||
pub fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T {
|
||||
use properties::longhands::overflow_x::computed_value::T as BaseType;
|
||||
use properties::longhands::overflow_y::computed_value::T as NewType;
|
||||
// FIXME(bholley): Align binary representations and ditch |match| for cast + static_asserts
|
||||
match self.gecko.mOverflowY as u32 {
|
||||
% for value in overflow_x.keyword.values_for('gecko'):
|
||||
structs::${overflow_x.keyword.gecko_constant(value)} => NewType(BaseType::${to_rust_ident(value)}),
|
||||
structs::${overflow_x.keyword.gecko_constant(value)} => BaseType::${to_rust_ident(value)},
|
||||
% endfor
|
||||
x => panic!("Found unexpected value in style struct for overflow_y property: {}", x),
|
||||
}
|
||||
|
|
|
@ -351,57 +351,23 @@ ${helpers.single_keyword("overflow-clip-box", "padding-box content-box",
|
|||
spec="Internal, not web-exposed, \
|
||||
may be standardized in the future (https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-clip-box)")}
|
||||
|
||||
<%
|
||||
overflow_custom_consts = { "-moz-hidden-unscrollable": "CLIP" }
|
||||
%>
|
||||
|
||||
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
|
||||
${helpers.single_keyword("overflow-x", "visible hidden scroll auto",
|
||||
extra_gecko_values="clip",
|
||||
need_clone=True, animation_value_type="none",
|
||||
extra_gecko_aliases="-moz-scrollbars-none=hidden",
|
||||
extra_gecko_values="-moz-hidden-unscrollable",
|
||||
custom_consts=overflow_custom_consts,
|
||||
gecko_constant_prefix="NS_STYLE_OVERFLOW",
|
||||
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x")}
|
||||
|
||||
// FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`.
|
||||
<%helpers:longhand name="overflow-y" need_clone="True" animation_value_type="none"
|
||||
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y">
|
||||
use super::overflow_x;
|
||||
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::computed::ComputedValueAsSpecified;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
/// The specified and computed value for overflow-y is a wrapper on top of
|
||||
/// `overflow-x`, so we re-use the logic, but prevent errors from mistakenly
|
||||
/// assign one to other.
|
||||
///
|
||||
/// TODO(Manishearth, emilio): We may want to just use the same value.
|
||||
pub mod computed_value {
|
||||
pub use super::SpecifiedValue as T;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct SpecifiedValue(pub super::overflow_x::SpecifiedValue);
|
||||
|
||||
impl ComputedValueAsSpecified for SpecifiedValue {}
|
||||
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T(overflow_x::get_initial_value())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(missing_docs)]
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
|
||||
overflow_x::parse(context, input).map(SpecifiedValue)
|
||||
}
|
||||
pub use super::overflow_x::{SpecifiedValue, parse, get_initial_value, computed_value};
|
||||
</%helpers:longhand>
|
||||
|
||||
<%helpers:vector_longhand name="transition-duration"
|
||||
|
|
|
@ -2434,10 +2434,9 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
|
||||
{
|
||||
use computed_values::overflow_x::T as overflow;
|
||||
use computed_values::overflow_y;
|
||||
|
||||
let original_overflow_x = style.get_box().clone_overflow_x();
|
||||
let original_overflow_y = style.get_box().clone_overflow_y().0;
|
||||
let original_overflow_y = style.get_box().clone_overflow_y();
|
||||
let mut overflow_x = original_overflow_x;
|
||||
let mut overflow_y = original_overflow_y;
|
||||
|
||||
|
@ -2457,10 +2456,10 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
% if product == "gecko":
|
||||
// overflow: clip is deprecated, so convert to hidden if it's
|
||||
// specified in only one dimension.
|
||||
if overflow_x == overflow::clip {
|
||||
if overflow_x == overflow::_moz_hidden_unscrollable {
|
||||
overflow_x = overflow::hidden;
|
||||
}
|
||||
if overflow_y == overflow::clip {
|
||||
if overflow_y == overflow::_moz_hidden_unscrollable {
|
||||
overflow_y = overflow::hidden;
|
||||
}
|
||||
% endif
|
||||
|
@ -2471,10 +2470,10 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
// When 'contain: paint', update overflow from 'visible' to 'clip'.
|
||||
if style.get_box().clone_contain().contains(contain::PAINT) {
|
||||
if overflow_x == overflow::visible {
|
||||
overflow_x = overflow::clip;
|
||||
overflow_x = overflow::_moz_hidden_unscrollable;
|
||||
}
|
||||
if overflow_y == overflow::visible {
|
||||
overflow_y = overflow::clip;
|
||||
overflow_y = overflow::_moz_hidden_unscrollable;
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
@ -2483,7 +2482,7 @@ pub fn apply_declarations<'a, F, I>(device: &Device,
|
|||
overflow_y != original_overflow_y {
|
||||
let mut box_style = style.mutate_box();
|
||||
box_style.set_overflow_x(overflow_x);
|
||||
box_style.set_overflow_y(overflow_y::T(overflow_y));
|
||||
box_style.set_overflow_y(overflow_y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,19 +6,43 @@
|
|||
|
||||
<%helpers:shorthand name="overflow" sub_properties="overflow-x overflow-y"
|
||||
spec="https://drafts.csswg.org/css-overflow/#propdef-overflow">
|
||||
use properties::longhands::{overflow_x, overflow_y};
|
||||
use properties::longhands::overflow_x::parse as parse_overflow;
|
||||
% if product == "gecko":
|
||||
use properties::longhands::overflow_x::SpecifiedValue;
|
||||
% endif
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let overflow = try!(overflow_x::parse(context, input));
|
||||
% if product == "gecko":
|
||||
let moz_kw_found = input.try(|i| match_ignore_ascii_case! {
|
||||
&i.expect_ident()?,
|
||||
"-moz-scrollbars-horizontal" => {
|
||||
Ok(Longhands {
|
||||
overflow_x: SpecifiedValue::scroll,
|
||||
overflow_y: SpecifiedValue::hidden,
|
||||
})
|
||||
}
|
||||
"-moz-scrollbars-vertical" => {
|
||||
Ok(Longhands {
|
||||
overflow_x: SpecifiedValue::hidden,
|
||||
overflow_y: SpecifiedValue::scroll,
|
||||
})
|
||||
}
|
||||
_ => Err(())
|
||||
});
|
||||
if moz_kw_found.is_ok() {
|
||||
return moz_kw_found
|
||||
}
|
||||
% endif
|
||||
let overflow = try!(parse_overflow(context, input));
|
||||
Ok(Longhands {
|
||||
overflow_x: overflow,
|
||||
overflow_y: overflow_y::SpecifiedValue(overflow),
|
||||
overflow_y: overflow,
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if *self.overflow_x == self.overflow_y.0 {
|
||||
if self.overflow_x == self.overflow_y {
|
||||
self.overflow_x.to_css(dest)
|
||||
} else {
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue