mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #16322 - tamamu:place-shorthand, r=upsuper
Implement alignment shorthand properties <!-- 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. --> <!-- 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/16322) <!-- Reviewable:end -->
This commit is contained in:
commit
0912bd06d7
1 changed files with 95 additions and 0 deletions
|
@ -137,3 +137,98 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
</%helpers:shorthand>
|
</%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…
Add table
Add a link
Reference in a new issue