mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Auto merge of #14120 - Manishearth:logical, r=emilio
Support logical properties in style Adds support for the logical block-end/inline-start/etc properties. These properties (like `border-block-end-color`) map to "physical" properties (e.g. `border-top-color`) depending on the writing mode. Todo: - [x] Handle shorthands - [x] Make geckolib setters work - [x] Handle padding/offset logical properties - [x] Perhaps handle `-block-size`, `-inline-size` type logical properties? - [x] Tests? This will overall add 16 new longhands and 4 new shorthands, taking a big bite out of the [remaining properties work](https://manishearth.github.io/css-properties-list/?stylo=hide&servo=hide&firefox=only&chrome=show&mdn=false&alexa=false) f? @emilio @SimonSapin <!-- 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/14120) <!-- Reviewable:end -->
This commit is contained in:
commit
4b9693cf81
10 changed files with 240 additions and 89 deletions
|
@ -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 %>
|
||||
<%! 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)">
|
||||
|
@ -221,15 +221,19 @@
|
|||
cascade_info.on_cascade_property(&declaration,
|
||||
&value);
|
||||
}
|
||||
% if property.logical:
|
||||
let wm = context.style.writing_mode;
|
||||
% endif
|
||||
<% maybe_wm = ", wm" if property.logical else "" %>
|
||||
match *value {
|
||||
DeclaredValue::Value(ref specified_value) => {
|
||||
let computed = specified_value.to_computed_value(context);
|
||||
% if property.has_uncacheable_values:
|
||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||
.set_${property.ident}(computed, cacheable);
|
||||
.set_${property.ident}(computed, cacheable ${maybe_wm});
|
||||
% else:
|
||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||
.set_${property.ident}(computed);
|
||||
.set_${property.ident}(computed ${maybe_wm});
|
||||
% endif
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
|
@ -239,7 +243,7 @@
|
|||
let initial_struct = ComputedValues::initial_values()
|
||||
.get_${data.current_style_struct.name_lower}();
|
||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||
.copy_${property.ident}_from(initial_struct);
|
||||
.copy_${property.ident}_from(initial_struct ${maybe_wm});
|
||||
},
|
||||
DeclaredValue::Inherit => {
|
||||
// This is a bit slow, but this is rare so it shouldn't
|
||||
|
@ -250,7 +254,7 @@
|
|||
let inherited_struct =
|
||||
inherited_style.get_${data.current_style_struct.name_lower}();
|
||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||
.copy_${property.ident}_from(inherited_struct);
|
||||
.copy_${property.ident}_from(inherited_struct ${maybe_wm});
|
||||
}
|
||||
}
|
||||
}, error_reporter);
|
||||
|
@ -607,3 +611,69 @@
|
|||
}
|
||||
</%self:shorthand>
|
||||
</%def>
|
||||
|
||||
<%def name="logical_setter_helper(name)">
|
||||
<%
|
||||
side = None
|
||||
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(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
|
||||
</%def>
|
||||
|
||||
<%def name="logical_setter(name, need_clone=False)">
|
||||
pub fn set_${to_rust_ident(name)}(&mut self,
|
||||
v: longhands::${to_rust_ident(name)}::computed_value::T,
|
||||
wm: WritingMode) {
|
||||
<%self:logical_setter_helper name="${name}">
|
||||
<%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(physical_ident)">
|
||||
self.copy_${physical_ident}_from(other)
|
||||
</%def>
|
||||
</%self:logical_setter_helper>
|
||||
}
|
||||
% if need_clone:
|
||||
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(physical_ident)">
|
||||
self.clone_${physical_ident}()
|
||||
</%def>
|
||||
</%self:logical_setter_helper>
|
||||
}
|
||||
% endif
|
||||
</%def>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue