aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlfontelement.rs
diff options
context:
space:
mode:
authorJayflux <jase.williams@gmail.com>2016-02-15 16:26:59 +0000
committerJayflux <jase.williams@gmail.com>2016-02-15 22:33:14 +0000
commitd169d7bd9e14cf20d680e1c7f2daec3ef83401f7 (patch)
treeecde30806e5fbc62496709e144ae7977a5c7bfc3 /components/script/dom/htmlfontelement.rs
parentc9b2ef5c7f5b23d815e8c3c78f972f6f880d6dbd (diff)
downloadservo-d169d7bd9e14cf20d680e1c7f2daec3ef83401f7.tar.gz
servo-d169d7bd9e14cf20d680e1c7f2daec3ef83401f7.zip
refactor, moving functions into attr and htmlfontelemend fixes #9639 #9638
Diffstat (limited to 'components/script/dom/htmlfontelement.rs')
-rw-r--r--components/script/dom/htmlfontelement.rs57
1 files changed, 56 insertions, 1 deletions
diff --git a/components/script/dom/htmlfontelement.rs b/components/script/dom/htmlfontelement.rs
index 5d7dbe7ed34..ae274411040 100644
--- a/components/script/dom/htmlfontelement.rs
+++ b/components/script/dom/htmlfontelement.rs
@@ -15,7 +15,7 @@ use dom::node::Node;
use dom::virtualmethods::VirtualMethods;
use string_cache::Atom;
use style::values::specified;
-use util::str::{DOMString, parse_legacy_font_size};
+use util::str::{DOMString, WHITESPACE, read_numbers};
#[dom_struct]
pub struct HTMLFontElement {
@@ -119,6 +119,61 @@ 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> {
+ // Steps 1 & 2 are not relevant
+
+ // Step 3
+ input = input.trim_matches(WHITESPACE);
+
+ enum ParseMode {
+ RelativePlus,
+ RelativeMinus,
+ Absolute,
+ }
+ let mut input_chars = input.chars().peekable();
+ let parse_mode = match input_chars.peek() {
+ // Step 4
+ None => return None,
+
+ // Step 5
+ Some(&'+') => {
+ let _ = input_chars.next(); // consume the '+'
+ ParseMode::RelativePlus
+ }
+ Some(&'-') => {
+ let _ = input_chars.next(); // consume the '-'
+ ParseMode::RelativeMinus
+ }
+ Some(_) => ParseMode::Absolute,
+ };
+
+ // Steps 6, 7, 8
+ let mut value = match read_numbers(input_chars) {
+ Some(v) => v,
+ None => return None,
+ };
+
+ // Step 9
+ match parse_mode {
+ ParseMode::RelativePlus => value = 3 + value,
+ ParseMode::RelativeMinus => value = 3 - value,
+ ParseMode::Absolute => (),
+ }
+
+ // 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))
}