mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Support logical properties
This commit is contained in:
parent
f1c3e97fb4
commit
e34eb13d65
6 changed files with 146 additions and 40 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 %>
|
||||
|
||||
<%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,53 @@
|
|||
}
|
||||
</%self:shorthand>
|
||||
</%def>
|
||||
|
||||
<%def name="logical_setter_helper(name)">
|
||||
<%
|
||||
side = None
|
||||
maybe_side = [side for side in LOGICAL_SIDES if side in name]
|
||||
if len(maybe_side) == 1:
|
||||
side = maybe_side[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)))}
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
% 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(side_ident)">
|
||||
self.set_${side_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>
|
||||
</%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(side_ident)">
|
||||
self.clone_${side_ident}()
|
||||
</%def>
|
||||
</%self:logical_setter_helper>
|
||||
}
|
||||
% endif
|
||||
</%def>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue