Read user-agent.css at run time. Fix #3516

This commit is contained in:
Simon Sapin 2014-10-07 19:07:04 +01:00
parent 543f11b62b
commit cf1785ecb1
6 changed files with 39 additions and 12 deletions

View file

@ -5,10 +5,10 @@
use resource_task::{LoadResponse, Metadata, Done, LoadData, start_sending};
use file_loader;
use std::os;
use std::io::fs::PathExtensions;
use url::Url;
use http::status::Ok as StatusOk;
use servo_util::resource_files::resources_dir_path;
pub fn factory(mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
@ -26,13 +26,8 @@ pub fn factory(mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
}
"crash" => fail!("Loading the about:crash URL."),
"failure" => {
// FIXME: Find a way to load this without relying on the `../src` directory.
let mut path = os::self_exe_path().expect("can't get exe path");
path.pop();
if !path.join(Path::new("./tests/")).is_dir() {
path.pop();
}
path.push_many(["tests", "html", "failure.html"]);
let mut path = resources_dir_path();
path.push("failure.html");
assert!(path.exists());
load_data.url = Url::from_file_path(&path).unwrap();
}

View file

@ -10,6 +10,7 @@ use sync::Arc;
use url::Url;
use servo_util::bloom::BloomFilter;
use servo_util::resource_files::read_resource_file;
use servo_util::smallvec::VecLike;
use servo_util::sort;
use string_cache::Atom;
@ -279,7 +280,7 @@ impl Stylist {
rules_source_order: 0u,
};
let ua_stylesheet = Stylesheet::from_bytes(
include_bin!("user-agent.css"),
read_resource_file(["user-agent.css"]).unwrap().as_slice(),
Url::parse("chrome:///user-agent.css").unwrap(),
None,
None);

View file

@ -1,130 +0,0 @@
html, address,
blockquote,
body, div,
dt, fieldset, form,
frame, frameset,
h1, h2, h3, h4,
h5, h6, noframes,
center, dir,
hr, menu, pre { display: block; unicode-bidi: embed }
head, noscript { display: none }
table { display: table }
tr { display: table-row }
thead { display: table-header-group }
tbody { display: table-row-group }
tfoot { display: table-footer-group }
col { display: table-column }
colgroup { display: table-column-group }
td, th { display: table-cell }
caption { display: table-caption }
th { font-weight: bolder; text-align: center }
caption { text-align: center }
body { margin: 8px }
h1 { font-size: 2em; margin: .67em 0 }
h2 { font-size: 1.5em; margin: .75em 0 }
h3 { font-size: 1.17em; margin: .83em 0 }
h4,
blockquote,
fieldset, dir,
menu { margin: 1.12em 0 }
h5 { font-size: .83em; margin: 1.5em 0 }
h6 { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4,
h5, h6, b,
strong { font-weight: bolder }
blockquote { margin-left: 40px; margin-right: 40px }
i, cite, em,
var, address { font-style: italic }
pre, tt, code,
kbd, samp { font-family: monospace }
pre { white-space: pre }
button, textarea,
input, select { display: inline-block }
big { font-size: 1.17em }
small, sub, sup { font-size: .83em }
sub { vertical-align: sub }
sup { vertical-align: super }
table { border-spacing: 2px; }
thead, tbody,
tfoot { vertical-align: middle }
td, th, tr { vertical-align: inherit }
s, strike, del { text-decoration: line-through }
hr { border: 1px inset }
/* lists */
dd { display: block; margin-left: 40px }
p, dl, multicol { display: block; margin: 1em 0 }
ul { display: block; list-style-type: disc;
margin: 1em 0; padding-left: 40px }
ol { display: block; list-style-type: decimal;
margin: 1em 0; padding-left: 40px }
li { display: list-item }
/* nested lists have no top/bottom margins */
ul ul, ul ol, ul dl,
ol ul, ol ol, ol dl,
dl ul, dl ol, dl dl { margin-top: 0; margin-bottom: 0 }
/* 2 deep unordered lists use a circle */
ol ul, ul ul { list-style-type: circle; }
/* 3 deep (or more) unordered lists use a square */
ol ol ul, ol ul ul,
ul ol ul, ul ul ul { list-style-type: square; }
/* The type attribute on ol and ul elements */
ul[type="disc"] { list-style-type: disc; }
ul[type="circle"] { list-style-type: circle; }
ul[type="square"] { list-style-type: square; }
ol[type="1"] { list-style-type: decimal; }
ol[type="a"] { list-style-type: lower-alpha; }
ol[type="A"] { list-style-type: upper-alpha; }
ol[type="i"] { list-style-type: lower-roman; }
ol[type="I"] { list-style-type: upper-roman; }
u, ins { text-decoration: underline }
br:before { content: "\A"; white-space: pre }
center { text-align: center }
a:link,
a:visited,
area:link,
area:visited,
link:link,
link:visited { text-decoration: underline }
:focus { outline: thin dotted invert }
/* Begin bidirectionality settings (do not change) */
BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override }
*[DIR="ltr"] { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"] { direction: rtl; unicode-bidi: embed }
@media print {
h1 { page-break-before: always }
h1, h2, h3,
h4, h5, h6 { page-break-after: avoid }
ul, ol, dl { page-break-before: avoid }
}
/* Servo additions */
a:link,
area:link,
link:link { color: blue }
script { display: none }
style { display: none }
input { background: white; min-height: 1.0em; padding: 0em; padding-left: 0.25em; padding-right: 0.25em; border: solid lightgrey 1px; color: black; white-space: nowrap; }
input[type="button"],
input[type="submit"],
input[type="reset"] { background: lightgrey; border-top: solid 1px #EEEEEE; border-left: solid 1px #CCCCCC; border-right: solid 1px #999999; border-bottom: solid 1px #999999; text-align: center; vertical-align: middle; color: black; }
input[type="hidden"] { display: none !important }
input[type="checkbox"],
input[type="radio"] { font-family: monospace !important; border: none !important; background: transparent; }
input[type="checkbox"]::before { content: "[ ]"; padding: 0; }
input[type="checkbox"][checked]::before { content: "[✓]"; }
input[type="radio"]::before { content: "( )"; padding: 0; }
input[type="radio"][checked]::before { content: "(●)"; }

View file

@ -42,6 +42,7 @@ pub mod memory;
pub mod namespace;
pub mod opts;
pub mod range;
pub mod resource_files;
pub mod smallvec;
pub mod sort;
pub mod str;

View file

@ -0,0 +1,30 @@
/* 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/. */
use std::io::{File, IoResult};
use std::io::fs::PathExtensions;
use std::os;
use std::path::Path;
pub fn resources_dir_path() -> Path {
// FIXME: Find a way to not rely on the executable being under `<servo source>/target`.
let mut path = os::self_exe_path().expect("can't get exe path");
path.pop();
path.push("resources");
if !path.is_dir() {
path.pop();
path.pop();
path.push("resources");
}
path
}
pub fn read_resource_file(relative_path_components: &[&str]) -> IoResult<Vec<u8>> {
let mut path = resources_dir_path();
path.push_many(relative_path_components);
let mut file = try!(File::open(&path));
file.read_to_end()
}