mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add support for inline-size, block-size, and max-*-size/min-*-size
This commit is contained in:
parent
f974719d9f
commit
5fad7b0ff6
4 changed files with 62 additions and 42 deletions
|
@ -333,6 +333,18 @@ partial interface CSSStyleDeclaration {
|
||||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString min-width;
|
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString min-width;
|
||||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString maxWidth;
|
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString maxWidth;
|
||||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString max-width;
|
[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 zIndex;
|
||||||
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString z-index;
|
[SetterThrows, TreatNullAs=EmptyString] attribute DOMString z-index;
|
||||||
|
|
|
@ -6,8 +6,12 @@ import re
|
||||||
|
|
||||||
PHYSICAL_SIDES = ["top", "left", "bottom", "right"]
|
PHYSICAL_SIDES = ["top", "left", "bottom", "right"]
|
||||||
LOGICAL_SIDES = ["block-start", "block-end", "inline-start", "inline-end"]
|
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
|
# bool is True when logical
|
||||||
ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES]
|
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):
|
def to_rust_ident(name):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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)">
|
<%def name="longhand(name, **kwargs)">
|
||||||
<%call expr="raw_longhand(name, **kwargs)">
|
<%call expr="raw_longhand(name, **kwargs)">
|
||||||
|
@ -615,19 +615,35 @@
|
||||||
<%def name="logical_setter_helper(name)">
|
<%def name="logical_setter_helper(name)">
|
||||||
<%
|
<%
|
||||||
side = None
|
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:
|
if len(maybe_side) == 1:
|
||||||
side = maybe_side[0]
|
side = maybe_side[0]
|
||||||
|
elif len(maybe_size) == 1:
|
||||||
|
size = maybe_size[0]
|
||||||
%>
|
%>
|
||||||
% if side is not None:
|
% if side is not None:
|
||||||
use logical_geometry::PhysicalSide;
|
use logical_geometry::PhysicalSide;
|
||||||
match wm.${to_rust_ident(side)}_physical_side() {
|
match wm.${to_rust_ident(side)}_physical_side() {
|
||||||
% for phy_side in PHYSICAL_SIDES:
|
% for phy_side in PHYSICAL_SIDES:
|
||||||
PhysicalSide::${phy_side.title()} => {
|
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
|
% 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:
|
% else:
|
||||||
<% raise Exception("Don't know what to do with logical property %s" % name) %>
|
<% raise Exception("Don't know what to do with logical property %s" % name) %>
|
||||||
% endif
|
% endif
|
||||||
|
@ -638,15 +654,15 @@
|
||||||
v: longhands::${to_rust_ident(name)}::computed_value::T,
|
v: longhands::${to_rust_ident(name)}::computed_value::T,
|
||||||
wm: WritingMode) {
|
wm: WritingMode) {
|
||||||
<%self:logical_setter_helper name="${name}">
|
<%self:logical_setter_helper name="${name}">
|
||||||
<%def name="inner(side_ident)">
|
<%def name="inner(physical_ident)">
|
||||||
self.set_${side_ident}(v)
|
self.set_${physical_ident}(v)
|
||||||
</%def>
|
</%def>
|
||||||
</%self:logical_setter_helper>
|
</%self:logical_setter_helper>
|
||||||
}
|
}
|
||||||
pub fn copy_${to_rust_ident(name)}_from(&mut self, other: &Self, wm: WritingMode) {
|
pub fn copy_${to_rust_ident(name)}_from(&mut self, other: &Self, wm: WritingMode) {
|
||||||
<%self:logical_setter_helper name="${name}">
|
<%self:logical_setter_helper name="${name}">
|
||||||
<%def name="inner(side_ident)">
|
<%def name="inner(physical_ident)">
|
||||||
self.copy_${side_ident}_from(other)
|
self.copy_${physical_ident}_from(other)
|
||||||
</%def>
|
</%def>
|
||||||
</%self:logical_setter_helper>
|
</%self:logical_setter_helper>
|
||||||
}
|
}
|
||||||
|
@ -654,8 +670,8 @@
|
||||||
pub fn clone_${to_rust_ident(name)}(&self, wm: WritingMode)
|
pub fn clone_${to_rust_ident(name)}(&self, wm: WritingMode)
|
||||||
-> longhands::${to_rust_ident(name)}::computed_value::T {
|
-> longhands::${to_rust_ident(name)}::computed_value::T {
|
||||||
<%self:logical_setter_helper name="${name}">
|
<%self:logical_setter_helper name="${name}">
|
||||||
<%def name="inner(side_ident)">
|
<%def name="inner(physical_ident)">
|
||||||
self.clone_${side_ident}()
|
self.clone_${physical_ident}()
|
||||||
</%def>
|
</%def>
|
||||||
</%self:logical_setter_helper>
|
</%self:logical_setter_helper>
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
<%namespace name="helpers" file="/helpers.mako.rs" />
|
<%namespace name="helpers" file="/helpers.mako.rs" />
|
||||||
|
<% from data import ALL_SIZES %>
|
||||||
|
|
||||||
<% data.new_style_struct("Position", inherited=False) %>
|
<% data.new_style_struct("Position", inherited=False) %>
|
||||||
|
|
||||||
|
@ -137,41 +138,28 @@ ${helpers.predefined_type("flex-basis",
|
||||||
"computed::LengthOrPercentageOrAutoOrContent::Auto",
|
"computed::LengthOrPercentageOrAutoOrContent::Auto",
|
||||||
animatable=False)}
|
animatable=False)}
|
||||||
|
|
||||||
${helpers.predefined_type("width",
|
% for (size, logical) in ALL_SIZES:
|
||||||
"LengthOrPercentageOrAuto",
|
// width, height, block-size, inline-size
|
||||||
"computed::LengthOrPercentageOrAuto::Auto",
|
${helpers.predefined_type("%s" % size,
|
||||||
"parse_non_negative",
|
"LengthOrPercentageOrAuto",
|
||||||
animatable=True)}
|
"computed::LengthOrPercentageOrAuto::Auto",
|
||||||
|
"parse_non_negative",
|
||||||
|
animatable=True, logical = logical)}
|
||||||
|
|
||||||
${helpers.predefined_type("height",
|
// min-width, min-height, min-block-size, min-inline-size
|
||||||
"LengthOrPercentageOrAuto",
|
${helpers.predefined_type("min-%s" % size,
|
||||||
"computed::LengthOrPercentageOrAuto::Auto",
|
"LengthOrPercentage",
|
||||||
"parse_non_negative",
|
"computed::LengthOrPercentage::Length(Au(0))",
|
||||||
animatable=True)}
|
"parse_non_negative",
|
||||||
|
animatable=True, logical = logical)}
|
||||||
|
|
||||||
${helpers.predefined_type("min-width",
|
// max-width, max-height, max-block-size, max-inline-size
|
||||||
"LengthOrPercentage",
|
${helpers.predefined_type("max-%s" % size,
|
||||||
"computed::LengthOrPercentage::Length(Au(0))",
|
"LengthOrPercentageOrNone",
|
||||||
"parse_non_negative",
|
"computed::LengthOrPercentageOrNone::None",
|
||||||
animatable=True)}
|
"parse_non_negative",
|
||||||
|
animatable=True, logical = logical)}
|
||||||
${helpers.predefined_type("max-width",
|
% endfor
|
||||||
"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)}
|
|
||||||
|
|
||||||
${helpers.single_keyword("box-sizing",
|
${helpers.single_keyword("box-sizing",
|
||||||
"content-box border-box",
|
"content-box border-box",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue