This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathparser.rs
69 lines (61 loc) · 2.13 KB
/
parser.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
Constructs a list of css style rules from a token stream
*/
// TODO: fail according to the css spec instead of failing when things
// are not as expected
use util::DataStream;
use netsurfcss::stylesheet::{CssStylesheet, CssStylesheetParams, CssStylesheetParamsVersion1, css_stylesheet_create};
use netsurfcss::types::CssLevel21;
use netsurfcss::CssResult;
use wapcaplet::LwcString;
use extra::url::Url;
use netsurfcss::stylesheet::CssUrlResolutionFn;
fn default_params(url: Url) -> CssStylesheetParams {
let resolve: CssUrlResolutionFn = resolve_url;
CssStylesheetParams {
params_version: CssStylesheetParamsVersion1,
level: CssLevel21,
charset: ~"UTF-8",
url: url.to_str(),
title: ~"FIXME-css-title",
allow_quirks: false,
inline_style: false,
resolve: Some(resolve),
import: None,
color: None,
font: None,
}
}
// This takes a DataStreamFactory instead of a DataStream because
// servo's DataStream contains a comm::Port, which is not sendable,
// so DataStream is an @fn which can't be sent to the lexer task.
// So the DataStreamFactory gives the caller an opportunity to create
// the data stream from inside the lexer task.
pub fn parse_stylesheet(url: Url, input: @mut DataStream) -> CssStylesheet {
let params = default_params(url);
let mut sheet = css_stylesheet_create(¶ms);
loop {
match input.read() {
Some(data) => {
sheet.append_data(data);
}
None => break
}
}
sheet.data_done();
sheet
}
pub fn parse_style_attribute(url: Url, data: &str) -> CssStylesheet {
let mut params = default_params(url);
params.inline_style = true;
let mut sheet = css_stylesheet_create(¶ms);
sheet.append_data(data.as_bytes());
sheet.data_done();
sheet
}
fn resolve_url(_base: &str, _rel: &LwcString) -> CssResult<LwcString> {
fail!(~"resolving url");
}