Skip to content

Commit

Permalink
stylo: support all overflow values
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 1iQdUDsb6u9
  • Loading branch information
Manishearth committed Apr 25, 2017
1 parent e3e10ad commit f8e298b
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 81 deletions.
6 changes: 3 additions & 3 deletions components/layout/block.rs
Expand Up @@ -53,7 +53,7 @@ use servo_geometry::max_rect;
use std::cmp::{max, min};
use std::fmt;
use std::sync::Arc;
use style::computed_values::{border_collapse, box_sizing, display, float, overflow_x, overflow_y};
use style::computed_values::{border_collapse, box_sizing, display, float, overflow_x};
use style::computed_values::{position, text_align};
use style::context::SharedStyleContext;
use style::logical_geometry::{LogicalPoint, LogicalRect, LogicalSize, WritingMode};
Expand Down Expand Up @@ -1440,7 +1440,7 @@ impl BlockFlow {
FormattingContextType::Other
}
_ if style.get_box().overflow_x != overflow_x::T::visible ||
style.get_box().overflow_y != overflow_y::T(overflow_x::T::visible) ||
style.get_box().overflow_y != overflow_x::T::visible ||
style.is_multicol() => {
FormattingContextType::Block
}
Expand Down Expand Up @@ -1677,7 +1677,7 @@ impl BlockFlow {

pub fn overflow_style_may_require_scroll_root(&self) -> bool {
match (self.fragment.style().get_box().overflow_x,
self.fragment.style().get_box().overflow_y.0) {
self.fragment.style().get_box().overflow_y) {
(overflow_x::T::auto, _) | (overflow_x::T::scroll, _) | (overflow_x::T::hidden, _) |
(_, overflow_x::T::auto) | (_, overflow_x::T::scroll) | (_, overflow_x::T::hidden) =>
true,
Expand Down
6 changes: 3 additions & 3 deletions components/layout/display_list_builder.rs
Expand Up @@ -2132,7 +2132,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
self.base.overflow.scroll.size.width > content_box.size.width ||
self.base.overflow.scroll.size.height > content_box.size.height ||
overflow_x::T::hidden == self.fragment.style.get_box().overflow_x ||
overflow_x::T::hidden == self.fragment.style.get_box().overflow_y.0;
overflow_x::T::hidden == self.fragment.style.get_box().overflow_y;

self.mark_scrolling_overflow(has_scrolling_overflow);
if !has_scrolling_overflow {
Expand Down Expand Up @@ -2163,11 +2163,11 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
content_size.width = content_box.size.width;
}

if overflow_x::T::hidden == self.fragment.style.get_box().overflow_y.0 {
if overflow_x::T::hidden == self.fragment.style.get_box().overflow_y {
content_size.height = content_box.size.height;
}

if overflow_x::T::hidden == self.fragment.style.get_box().overflow_y.0 ||
if overflow_x::T::hidden == self.fragment.style.get_box().overflow_y ||
overflow_x::T::hidden == self.fragment.style.get_box().overflow_x {
preserved_state.push_clip(state, &border_box, self.positioning());
}
Expand Down
2 changes: 1 addition & 1 deletion components/layout/flow.rs
Expand Up @@ -276,7 +276,7 @@ pub trait Flow: fmt::Debug + Sync + Send + 'static {
overflow.scroll.origin.x = Au(0);
overflow.scroll.size.width = border_box.size.width;
}
if overflow_x::T::visible != self.as_block().fragment.style.get_box().overflow_y.0 {
if overflow_x::T::visible != self.as_block().fragment.style.get_box().overflow_y {
overflow.paint.origin.y = Au(0);
overflow.paint.size.height = border_box.size.height;
overflow.scroll.origin.y = Au(0);
Expand Down
4 changes: 2 additions & 2 deletions components/layout/fragment.rs
Expand Up @@ -2150,7 +2150,7 @@ impl Fragment {
let block_flow = flow.as_block();
let start_margin = block_flow.fragment.margin.block_start;
let end_margin = block_flow.fragment.margin.block_end;
if style.get_box().overflow_y.0 == overflow_x::T::visible {
if style.get_box().overflow_y == overflow_x::T::visible {
if let Some(baseline_offset) = flow.baseline_offset_of_last_line_box_in_flow() {
let ascent = baseline_offset + start_margin;
let space_below_baseline = block_flow.fragment.border_box.size.block -
Expand Down Expand Up @@ -2491,7 +2491,7 @@ impl Fragment {
match (self.style().get_box().position,
self.style().get_position().z_index,
self.style().get_box().overflow_x,
self.style().get_box().overflow_y.0) {
self.style().get_box().overflow_y) {
(position::T::absolute,
Either::Second(Auto),
overflow_x::T::visible,
Expand Down
2 changes: 1 addition & 1 deletion components/layout/query.rs
Expand Up @@ -885,7 +885,7 @@ pub fn process_node_overflow_request<N: LayoutNode>(requested_node: N) -> NodeOv
let style = &*layout_node.as_element().unwrap().resolved_style();
let style_box = style.get_box();

NodeOverflowResponse(Some((Point2D::new(style_box.overflow_x, style_box.overflow_y.0))))
NodeOverflowResponse(Some((Point2D::new(style_box.overflow_x, style_box.overflow_y))))
}

pub fn process_margin_style_query<N: LayoutNode>(requested_node: N)
Expand Down
7 changes: 2 additions & 5 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -1793,13 +1793,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
Expand All @@ -1808,11 +1806,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),
}
Expand Down
50 changes: 8 additions & 42 deletions components/style/properties/longhand/box.mako.rs
Expand Up @@ -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"
Expand Down
13 changes: 6 additions & 7 deletions components/style/properties/properties.mako.rs
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}

Expand Down
32 changes: 28 additions & 4 deletions components/style/properties/shorthand/box.mako.rs
Expand Up @@ -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(())
Expand Down
22 changes: 9 additions & 13 deletions tests/unit/style/properties/serialization.rs
Expand Up @@ -16,8 +16,7 @@ use stylesheets::block_from;

#[test]
fn property_declaration_block_should_serialize_correctly() {
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowXValue;
use style::properties::longhands::overflow_y::SpecifiedValue as OverflowYContainer;
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowValue;

let declarations = vec![
(PropertyDeclaration::Width(
Expand All @@ -37,11 +36,11 @@ fn property_declaration_block_should_serialize_correctly() {
Importance::Normal),

(PropertyDeclaration::OverflowX(
OverflowXValue::auto),
OverflowValue::auto),
Importance::Normal),

(PropertyDeclaration::OverflowY(
OverflowYContainer(OverflowXValue::auto)),
OverflowValue::auto),
Importance::Normal),
];

Expand All @@ -68,18 +67,15 @@ mod shorthand_serialization {

mod overflow {
pub use super::*;
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowXValue;
use style::properties::longhands::overflow_y::SpecifiedValue as OverflowYContainer;
use style::properties::longhands::overflow_x::SpecifiedValue as OverflowValue;

#[test]
fn equal_overflow_properties_should_serialize_to_single_value() {
let mut properties = Vec::new();

let overflow_x = OverflowXValue::auto;
properties.push(PropertyDeclaration::OverflowX(overflow_x));

let overflow_y = OverflowYContainer(OverflowXValue::auto);
properties.push(PropertyDeclaration::OverflowY(overflow_y));
let overflow = OverflowValue::auto;
properties.push(PropertyDeclaration::OverflowX(overflow));
properties.push(PropertyDeclaration::OverflowY(overflow));

let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "overflow: auto;");
Expand All @@ -89,10 +85,10 @@ mod shorthand_serialization {
fn different_overflow_properties_should_serialize_to_two_values() {
let mut properties = Vec::new();

let overflow_x = OverflowXValue::scroll;
let overflow_x = OverflowValue::scroll;
properties.push(PropertyDeclaration::OverflowX(overflow_x));

let overflow_y = OverflowYContainer(OverflowXValue::auto);
let overflow_y = OverflowValue::auto;
properties.push(PropertyDeclaration::OverflowY(overflow_y));

let serialization = shorthand_properties_to_string(properties);
Expand Down

0 comments on commit f8e298b

Please sign in to comment.