mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
servo: Merge #16322 - Implement alignment shorthand properties (from tamamu:place-shorthand); r=upsuper
<!-- Please describe your changes on the following line: --> I implemented the shorthand properties, but it may includes some bugs. Currently, `mach test-unit -p style` caught some errors (see #15954). I already tried `mach build-geckolib`, though there is no improvement. Please check my code. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15954 <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 0912bd06d7c5f5560de43a47b2f15002f334a533 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 2acc78b68349b5a7d931cc6ebbdb88360924ab07
This commit is contained in:
parent
64216c2895
commit
0d1d626e5f
@ -137,3 +137,98 @@
|
||||
}
|
||||
|
||||
</%helpers:shorthand>
|
||||
|
||||
<%helpers:shorthand name="place-content" sub_properties="align-content justify-content"
|
||||
spec="https://drafts.csswg.org/css-align/#propdef-place-content"
|
||||
products="gecko" disable_when_testing="True">
|
||||
use properties::longhands::align_content;
|
||||
use properties::longhands::justify_content;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let align = align_content::parse(context, input)?;
|
||||
let justify = input.try(|input| justify_content::parse(context, input))
|
||||
.unwrap_or(justify_content::SpecifiedValue::from(align));
|
||||
|
||||
Ok(Longhands {
|
||||
align_content: align,
|
||||
justify_content: justify,
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.align_content == self.justify_content {
|
||||
self.align_content.to_css(dest)
|
||||
} else {
|
||||
self.justify_content.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.justify_content.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
||||
<%helpers:shorthand name="place-self" sub_properties="align-self justify-self"
|
||||
spec="https://drafts.csswg.org/css-align/#place-self-property"
|
||||
products="gecko" disable_when_testing="True">
|
||||
use values::specified::align::AlignJustifySelf;
|
||||
use parser::Parse;
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let align = AlignJustifySelf::parse(context, input)?;
|
||||
let justify = input.try(|input| AlignJustifySelf::parse(context, input)).unwrap_or(align.clone());
|
||||
|
||||
Ok(Longhands {
|
||||
align_self: align,
|
||||
justify_self: justify,
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.align_self == self.justify_self {
|
||||
self.align_self.to_css(dest)
|
||||
} else {
|
||||
self.align_self.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.justify_self.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
||||
<%helpers:shorthand name="place-items" sub_properties="align-items justify-items"
|
||||
spec="https://drafts.csswg.org/css-align/#place-items-property"
|
||||
products="gecko" disable_when_testing="True">
|
||||
use values::specified::align::{AlignItems, JustifyItems};
|
||||
use parser::Parse;
|
||||
|
||||
impl From<AlignItems> for JustifyItems {
|
||||
fn from(align: AlignItems) -> JustifyItems {
|
||||
JustifyItems(align.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let align = AlignItems::parse(context, input)?;
|
||||
let justify = input.try(|input| JustifyItems::parse(context, input))
|
||||
.unwrap_or(JustifyItems::from(align));
|
||||
|
||||
Ok(Longhands {
|
||||
align_items: align,
|
||||
justify_items: justify,
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
if self.align_items.0 == self.justify_items.0 {
|
||||
self.align_items.to_css(dest)
|
||||
} else {
|
||||
self.align_items.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
self.justify_items.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
Loading…
Reference in New Issue
Block a user