Add support for inline-size, block-size, and max-*-size/min-*-size

This commit is contained in:
Manish Goregaokar 2016-11-08 14:40:18 -08:00
parent f974719d9f
commit 5fad7b0ff6
4 changed files with 62 additions and 42 deletions

View file

@ -333,6 +333,18 @@ partial interface CSSStyleDeclaration {
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString min-width;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString maxWidth;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString max-width;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString block-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString blockSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString inline-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString inlineSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString max-block-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString maxBlockSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString max-inline-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString maxInlineSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString min-block-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString minBlockSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString min-inline-size;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString minInlineSize;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString zIndex;
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString z-index;

View file

@ -6,8 +6,12 @@ import re
PHYSICAL_SIDES = ["top", "left", "bottom", "right"]
LOGICAL_SIDES = ["block-start", "block-end", "inline-start", "inline-end"]
PHYSICAL_SIZES = ["width", "height"]
LOGICAL_SIZES = ["block-size", "inline-size"]
# bool is True when logical
ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES]
ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size in LOGICAL_SIZES]
def to_rust_ident(name):

View file

@ -2,7 +2,7 @@
* 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/. */
<%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES %>
<%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES %>
<%def name="longhand(name, **kwargs)">
<%call expr="raw_longhand(name, **kwargs)">
@ -615,19 +615,35 @@
<%def name="logical_setter_helper(name)">
<%
side = None
maybe_side = [side for side in LOGICAL_SIDES if side in name]
size = None
maybe_side = [s for s in LOGICAL_SIDES if s in name]
maybe_size = [s for s in LOGICAL_SIZES if s in name]
if len(maybe_side) == 1:
side = maybe_side[0]
elif len(maybe_size) == 1:
size = maybe_size[0]
%>
% if side is not None:
use logical_geometry::PhysicalSide;
match wm.${to_rust_ident(side)}_physical_side() {
% for phy_side in PHYSICAL_SIDES:
PhysicalSide::${phy_side.title()} => {
${caller.inner(side_ident=to_rust_ident(name.replace(side, phy_side)))}
${caller.inner(physical_ident=to_rust_ident(name.replace(side, phy_side)))}
}
% endfor
}
% elif size is not None:
<%
# (horizontal, vertical)
physical_size = ("height", "width")
if size == "inline-size":
physical_size = ("width", "height")
%>
if wm.is_vertical() {
${caller.inner(physical_ident=to_rust_ident(name.replace(size, physical_size[1])))}
} else {
${caller.inner(physical_ident=to_rust_ident(name.replace(size, physical_size[0])))}
}
% else:
<% raise Exception("Don't know what to do with logical property %s" % name) %>
% endif
@ -638,15 +654,15 @@
v: longhands::${to_rust_ident(name)}::computed_value::T,
wm: WritingMode) {
<%self:logical_setter_helper name="${name}">
<%def name="inner(side_ident)">
self.set_${side_ident}(v)
<%def name="inner(physical_ident)">
self.set_${physical_ident}(v)
</%def>
</%self:logical_setter_helper>
}
pub fn copy_${to_rust_ident(name)}_from(&mut self, other: &Self, wm: WritingMode) {
<%self:logical_setter_helper name="${name}">
<%def name="inner(side_ident)">
self.copy_${side_ident}_from(other)
<%def name="inner(physical_ident)">
self.copy_${physical_ident}_from(other)
</%def>
</%self:logical_setter_helper>
}
@ -654,8 +670,8 @@
pub fn clone_${to_rust_ident(name)}(&self, wm: WritingMode)
-> longhands::${to_rust_ident(name)}::computed_value::T {
<%self:logical_setter_helper name="${name}">
<%def name="inner(side_ident)">
self.clone_${side_ident}()
<%def name="inner(physical_ident)">
self.clone_${physical_ident}()
</%def>
</%self:logical_setter_helper>
}

View file

@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<% from data import ALL_SIZES %>
<% data.new_style_struct("Position", inherited=False) %>
@ -137,41 +138,28 @@ ${helpers.predefined_type("flex-basis",
"computed::LengthOrPercentageOrAutoOrContent::Auto",
animatable=False)}
${helpers.predefined_type("width",
"LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Auto",
"parse_non_negative",
animatable=True)}
% for (size, logical) in ALL_SIZES:
// width, height, block-size, inline-size
${helpers.predefined_type("%s" % size,
"LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Auto",
"parse_non_negative",
animatable=True, logical = logical)}
${helpers.predefined_type("height",
"LengthOrPercentageOrAuto",
"computed::LengthOrPercentageOrAuto::Auto",
"parse_non_negative",
animatable=True)}
// min-width, min-height, min-block-size, min-inline-size
${helpers.predefined_type("min-%s" % size,
"LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
animatable=True, logical = logical)}
${helpers.predefined_type("min-width",
"LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
animatable=True)}
${helpers.predefined_type("max-width",
"LengthOrPercentageOrNone",
"computed::LengthOrPercentageOrNone::None",
"parse_non_negative",
animatable=True)}
${helpers.predefined_type("min-height",
"LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
animatable=True)}
${helpers.predefined_type("max-height",
"LengthOrPercentageOrNone",
"computed::LengthOrPercentageOrNone::None",
"parse_non_negative",
animatable=True)}
// max-width, max-height, max-block-size, max-inline-size
${helpers.predefined_type("max-%s" % size,
"LengthOrPercentageOrNone",
"computed::LengthOrPercentageOrNone::None",
"parse_non_negative",
animatable=True, logical = logical)}
% endfor
${helpers.single_keyword("box-sizing",
"content-box border-box",