mirror of
https://github.com/servo/servo.git
synced 2025-09-12 16:08:20 +01:00
Refactor Position
A specified position is now a struct made of two values of different types, the first one being PositionComponent<X>, and the second one PositionComponent<Y>. A position component is represented by the new enum PositionComponent<Side>, with the three values Center, Length(LengthOrPercentage), and Side(Side, Option<LengthOrPercentage>). Side keywords are represented by the X and Y enums, which don't include a value for the center keyword anymore. They are accompanied by the Side trait, which allows us to determine whether a side keyword is "left" or "top". This refactor simplified the parsing and serialisation code and exposed bugs in it, where it would reject valid <position> values followed by arbitrary tokens, and where it would fail to prefer "left" to "right" when serialising positions in basic shapes.
This commit is contained in:
parent
0040160b38
commit
70ec61cf01
22 changed files with 484 additions and 887 deletions
|
@ -25,7 +25,7 @@ use style::stylearc::Arc;
|
|||
use style::stylesheets::{Origin, Namespaces};
|
||||
use style::stylesheets::{Stylesheet, NamespaceRule, CssRule, CssRules, StyleRule, KeyframesRule};
|
||||
use style::values::{KeyframesName, CustomIdent};
|
||||
use style::values::specified::{LengthOrPercentageOrAuto, Percentage};
|
||||
use style::values::specified::{LengthOrPercentageOrAuto, Percentage, PositionComponent};
|
||||
|
||||
pub fn block_from<I>(iterable: I) -> PropertyDeclarationBlock
|
||||
where I: IntoIterator<Item=(PropertyDeclaration, Importance)> {
|
||||
|
@ -183,13 +183,11 @@ fn test_parse_stylesheet() {
|
|||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundPositionX(
|
||||
longhands::background_position_x::SpecifiedValue(
|
||||
vec![longhands::background_position_x::single_value
|
||||
::get_initial_position_value()])),
|
||||
Importance::Normal),
|
||||
vec![PositionComponent::zero()])),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundPositionY(
|
||||
longhands::background_position_y::SpecifiedValue(
|
||||
vec![longhands::background_position_y::single_value
|
||||
::get_initial_position_value()])),
|
||||
vec![PositionComponent::zero()])),
|
||||
Importance::Normal),
|
||||
(PropertyDeclaration::BackgroundRepeat(
|
||||
longhands::background_repeat::SpecifiedValue(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue