mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Basic handling framework for presentation attributes in Stylo, with handling for font-size and color
This introduces a basic framework for servo's style system to be able to query the style of presentation attributes which it can then insert into the cascade. It uses that framework to implement the size and color attributes on <font>. There are a number of improvements that can be done on top of this: - Implement all other properties - Abstractify the ruledata parameter of the mappers using templates or virtual dispatch so that it can be a Servo decl block instead - Implement aforementiond abstraction over Servo decl blocks (this obsoletes the code in the first item above, so it might just be better to skip that and directly do this) - Replace uses of nsHTMLStyleSheet with an abstract base class containing common elements between Servo and Gecko I'd prefer for these to be done in separate steps.
This commit is contained in:
parent
cd2dbd720b
commit
34ba00e6d9
6 changed files with 126 additions and 24 deletions
|
@ -123,7 +123,7 @@ impl HTMLFontElementLayoutHelpers for LayoutJS<HTMLFontElement> {
|
|||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-font-size
|
||||
pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
|
||||
fn parse_length(mut input: &str) -> Option<specified::Length> {
|
||||
// Steps 1 & 2 are not relevant
|
||||
|
||||
// Step 3
|
||||
|
@ -153,8 +153,8 @@ pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
|
|||
|
||||
// Steps 6, 7, 8
|
||||
let mut value = match read_numbers(input_chars) {
|
||||
(Some(v), _) => v,
|
||||
(None, _) => return None,
|
||||
(Some(v), _) if v >= 0 => v,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
// Step 9
|
||||
|
@ -165,18 +165,5 @@ pub fn parse_legacy_font_size(mut input: &str) -> Option<&'static str> {
|
|||
}
|
||||
|
||||
// Steps 10, 11, 12
|
||||
Some(match value {
|
||||
n if n >= 7 => "xxx-large",
|
||||
6 => "xx-large",
|
||||
5 => "x-large",
|
||||
4 => "large",
|
||||
3 => "medium",
|
||||
2 => "small",
|
||||
n if n <= 1 => "x-small",
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_length(value: &str) -> Option<specified::Length> {
|
||||
parse_legacy_font_size(&value).and_then(|parsed| specified::Length::from_str(&parsed))
|
||||
Some(specified::Length::from_font_size_int(value as u8))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue