Update for language changes; remove pipe protocols.

This commit is contained in:
Patrick Walton 2012-10-04 11:02:53 -07:00
parent e105f3b557
commit 994c47d22b
67 changed files with 437 additions and 731 deletions

View file

@ -145,7 +145,7 @@ all: servo package
# Servo binaries
servo: $(DEPS_servo)
$(CFG_RUSTC) $(RFLAGS_servo) -o $@ $< --bin
$(RUSTC) $(RFLAGS_servo) -o $@ $< --bin
# Darwin app packaging

View file

@ -18,13 +18,13 @@ $(eval $(call DEF_SUBMODULE_TEST_RULES,$(submodule))))
# Testing targets
servo-test: $(DEPS_servo)
$(CFG_RUSTC) $(RFLAGS_servo) --test -o $@ $<
$(RUSTC) $(RFLAGS_servo) --test -o $@ $<
reftest: $(S)src/reftest/reftest.rs servo
$(CFG_RUSTC) $(RFLAGS_servo) -o $@ $< -L .
$(RUSTC) $(RFLAGS_servo) -o $@ $< -L .
contenttest: $(S)src/contenttest/contenttest.rs servo
$(CFG_RUSTC) $(RFLAGS_servo) -o $@ $< -L .
$(RUSTC) $(RFLAGS_servo) -o $@ $< -L .
.PHONY: check $(DEPS_CHECK)

@ -1 +1 @@
Subproject commit 0b520a6caf17b05d25db0026431873ae3f86a456
Subproject commit c201bc1f2c6cb38d7a81647516f3f55892c8d89d

@ -1 +1 @@
Subproject commit 5019635e3f44851c08716bd44b70229b2d625aa7
Subproject commit 7dff0d5d6dc40e53989f0db94df74be79bda91c9

@ -1 +1 @@
Subproject commit 22a7aa74798117d9dcfb4640290b35b0950f063b
Subproject commit 9733c605bd11dbd2ebbcd45e4629c157bb8cc01d

@ -1 +1 @@
Subproject commit 5dea272fc5f6a9b3812a845d003724d1bcdaf0bb
Subproject commit e56e41dc94e8f8083d484866fcc22d44b7eb2efe

@ -1 +1 @@
Subproject commit a038f14ebb1219fb7ff9808dde98597ed8645482
Subproject commit 2886e54d6230050ee7a25e590faad969f95a7d16

@ -1 +1 @@
Subproject commit fa1de008eb31d9401dbc3d6232d6fa4e87d54da3
Subproject commit f1670147011cee03a94c751d6d77a30c2330ee4d

@ -1 +1 @@
Subproject commit 28857cda6e86d4da58cb0e25206b7def6bd87534
Subproject commit 8cab62f8095e7c99b858da256f4f7042d57d9712

@ -1 +1 @@
Subproject commit b1184364a73b2269b29897466d984aeb5d6e464f
Subproject commit 546e797384821679fe45f8fe549fc8735ba24617

@ -1 +1 @@
Subproject commit 9223fe2a99ec5c76dc98a98ca99a10ff3513a845
Subproject commit 4d916307330d5b7e5818c87d3aebda175477b9ae

@ -1 +1 @@
Subproject commit a4ef0a56c990d979fa34fed93293c305a03f67cb
Subproject commit 21de9b86992e4a1d60ef82a8611c1fe08aa81641

@ -1 +1 @@
Subproject commit 5a32c07acfc06c24bef948a1ddc60eed09a37929
Subproject commit 74a86cbf8616b34b4fce4891fad21a181a253545

@ -1 +1 @@
Subproject commit 60b6a4ec1d2bd63b24383fe31865552d7eedada4
Subproject commit 5907c48bf0e77562735b8a2fab286a6e5c33a20c

View file

@ -18,12 +18,11 @@ use dom::node::{Node, NodeScope, define_bindings};
use dom::event::{Event, ResizeEvent, ReflowEvent};
use dom::window::Window;
use gfx::compositor::Compositor;
use html::lexer::spawn_html_lexer_task;
use layout::layout_task;
use layout_task::{LayoutTask, BuildMsg};
use resource::image_cache_task::ImageCacheTask;
use css::styles::Stylesheet;
use css::values::Stylesheet;
use jsrt = js::rust::rt;
use js::rust::{cx, methods};
@ -48,18 +47,18 @@ use js::jsapi::{JSContext, jsval};
use js::jsapi::bindgen::{JS_CallFunctionValue, JS_GetContextPrivate};
use ptr::null;
enum ControlMsg {
pub enum ControlMsg {
ParseMsg(Url),
ExecuteMsg(Url),
Timer(~dom::window::TimerData),
ExitMsg
}
enum PingMsg {
pub enum PingMsg {
PongMsg
}
type ContentTask = Chan<ControlMsg>;
pub type ContentTask = Chan<ControlMsg>;
fn ContentTask<S: Compositor Send Copy>(layout_task: LayoutTask,
+compositor: S,
@ -179,11 +178,11 @@ impl Content {
self.window = Some(@window);
self.doc_url = Some(copy url);
let compartment = option::expect(self.compartment, ~"TODO error checking");
let compartment = option::expect(&self.compartment, ~"TODO error checking");
compartment.define_functions(debug_fns);
define_bindings(*compartment,
option::get(self.document),
option::get(self.window));
option::get(&self.document),
option::get(&self.window));
for vec::each(js_scripts) |bytes| {
self.cx.evaluate_script(compartment.global_obj, *bytes, ~"???", 1u);
@ -193,17 +192,17 @@ impl Content {
}
Timer(timerData) => {
let compartment = option::expect(self.compartment, ~"TODO error checking");
let compartment = option::expect(&self.compartment, ~"TODO error checking");
let thisValue = if timerData.args.len() > 0 {
RUST_JSVAL_TO_OBJECT(unsafe { timerData.args.shift() })
} else {
compartment.global_obj.ptr
};
let _rval = JSVAL_NULL;
let rval = JSVAL_NULL;
//TODO: support extra args. requires passing a *jsval argv
JS_CallFunctionValue(self.cx.ptr, thisValue, timerData.funval,
0, null(), ptr::addr_of(_rval));
self.relayout(*option::get(self.document), &option::get(self.doc_url));
0, null(), ptr::to_unsafe_ptr(&rval));
self.relayout(*option::get(&self.document), &option::get(&self.doc_url));
return true;
}
@ -216,7 +215,7 @@ impl Content {
println(fmt!("Error opening %s: %s", url_to_str(copy url), msg));
}
Ok(bytes) => {
let compartment = option::expect(self.compartment, ~"TODO error checking");
let compartment = option::expect(&self.compartment, ~"TODO error checking");
compartment.define_functions(debug_fns);
self.cx.evaluate_script(compartment.global_obj, bytes, url.path, 1u);
}

View file

@ -23,7 +23,7 @@ type CssLexer = {
mut parser_state: ParserState
};
enum Token {
pub enum Token {
StartDescription,
EndDescription,
Descendant,
@ -80,7 +80,7 @@ impl CssLexer : CssLexerMethods {
}
fn parse_css_element(c : u8) -> Token {
assert is_none(self.input_state.lookahead);
assert is_none(&self.input_state.lookahead);
/* Check for special attributes with an implied element,
or a wildcard which is not a alphabet character.*/
@ -182,7 +182,7 @@ impl CssLexer : CssLexerMethods {
break;
}
} else {
push(desc_name, ch);
push(&mut desc_name, ch);
}
match self.input_state.get() {
@ -217,7 +217,7 @@ impl CssLexer : CssLexerMethods {
break;
}
} else {
push(desc_val, ch);
push(&mut desc_val, ch);
}
}
@ -267,7 +267,7 @@ fn spawn_css_lexer_from_string(-content : ~str) -> pipes::Port<Token> {
}
#[allow(non_implicitly_copyable_typarams)]
fn spawn_css_lexer_task(-url: Url, resource_task: ResourceTask) -> pipes::Port<Token> {
pub fn spawn_css_lexer_task(-url: Url, resource_task: ResourceTask) -> pipes::Port<Token> {
let (result_chan, result_port) = pipes::stream();
do task::spawn || {

View file

@ -8,7 +8,7 @@ Constructs a list of css style rules from a token stream
use css::values::*;
// Disambiguate parsed Selector, Rule values from tokens
use css = css::values;
use tok = lexer;
use mod tok = lexer;
use lexer::Token;
use comm::recv;
use option::{map, is_none};
@ -33,7 +33,7 @@ impl TokenReader : TokenReaderMethods {
}
fn unget(-tok : Token) {
assert is_none(self.lookahead);
assert is_none(&self.lookahead);
self.lookahead = Some(tok);
}
}
@ -60,7 +60,7 @@ impl TokenReader : ParserMethods {
loop {
let token = self.get();
match token {
tok::Attr(attr) => { push(attr_list, copy attr); }
tok::Attr(attr) => { push(&mut attr_list, copy attr); }
tok::StartDescription | tok::Descendant | tok::Child | tok::Sibling | tok::Comma => {
self.unget(token);
break;
@ -119,12 +119,12 @@ impl TokenReader : ParserMethods {
}
}
tok::StartDescription => {
push(sel_list, built_sel);
push(&mut sel_list, built_sel);
self.unget(tok::StartDescription);
break;
}
tok::Comma => {
push(sel_list, built_sel);
push(&mut sel_list, built_sel);
self.unget(tok::Comma);
break;
}
@ -159,8 +159,8 @@ impl TokenReader : ParserMethods {
tok::Description(prop, val) => {
let desc : Option<StyleDeclaration> = match prop {
// TODO: have color parsing return a ParseResult instead of a real value
~"background-color" => parse_color(val).map(|res| BackgroundColor(Specified(BgColor(res)))),
~"color" => parse_color(val).map(|res| Color(Specified(TextColor(res)))),
~"background-color" => parse_color(val).map(|res| BackgroundColor(Specified(BgColor(*res)))),
~"color" => parse_color(val).map(|res| Color(Specified(TextColor(*res)))),
~"display" => parse_display_type(val).extract(|res| Display(res)),
~"font-size" => parse_font_size(val).extract(|res| FontSize(res)),
~"height" => parse_box_sizing(val).extract(|res| Height(res)),
@ -168,7 +168,7 @@ impl TokenReader : ParserMethods {
_ => { #debug["Recieved unknown style property '%s'", val]; None }
};
match desc {
Some(d) => push(desc_list, d),
Some(d) => push(&mut desc_list, d),
None => { #debug["Couldn't parse value '%s' for property '%s'", val, prop] }
}
}
@ -204,13 +204,13 @@ impl TokenReader : ParserMethods {
}
}
fn build_stylesheet(+stream : pipes::Port<Token>) -> ~[~css::Rule] {
pub fn build_stylesheet(+stream : pipes::Port<Token>) -> ~[~css::Rule] {
let mut rule_list = ~[];
let reader = {stream : stream, mut lookahead : None};
loop {
match reader.parse_rule() {
Some(rule) => { push(rule_list, copy rule); }
Some(rule) => { push(&mut rule_list, copy rule); }
None => { break; }
}
}

View file

@ -18,14 +18,14 @@ fn parse_length(str : ~str) -> Option<Length> {
const PX_PER_PT: float = 1.0 / 0.75;
match str {
s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 72.0 * f)),
s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(f / 2.54 * 72.0 * 1.0/0.75)),
s if s.ends_with(~"mm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(f * 0.1 / 2.54 * 72.0 * 1.0/0.75)),
s if s.ends_with(~"pt") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * f)),
s if s.ends_with(~"pc") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 12.0 * f)),
s if s.ends_with(~"px") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(f)),
s if s.ends_with(~"em") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(f)),
s if s.ends_with(~"ex") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(0.5*f)),
s if s.ends_with(~"in") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 72.0 * *f)),
s if s.ends_with(~"cm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f / 2.54 * 72.0 * 1.0/0.75)),
s if s.ends_with(~"mm") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f * 0.1 / 2.54 * 72.0 * 1.0/0.75)),
s if s.ends_with(~"pt") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * *f)),
s if s.ends_with(~"pc") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(1.0/0.75 * 12.0 * *f)),
s if s.ends_with(~"px") => from_str(str.substr(0, str.len() - 2)).map(|f| Px(*f)),
s if s.ends_with(~"em") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(*f)),
s if s.ends_with(~"ex") => from_str(str.substr(0, str.len() - 2)).map(|f| Em(0.5 * *f)),
_ => None,
}
}

View file

@ -3,9 +3,10 @@
*/
use au = gfx::geometry;
use css::styles::SpecifiedStyle;
use dom::node::{Node, NodeTree};
use dom::element::*;
use layout::box::{RenderBox, SpecifiedStyle, RenderBoxTree};
use layout::box::{RenderBox, RenderBoxTree};
use layout::context::LayoutContext;
use layout::traverse_parallel::top_down_traversal;
use image::ImageHolder;

View file

@ -31,7 +31,7 @@ fn attrs_match(attr: Attr, elmt: ElementData) -> bool {
if val == ~"" { return false; }
match elmt.get_attr(name) {
Some(value) => value.split_char(' ').contains(val),
Some(value) => value.split_char(' ').contains(&val),
None => false
}
}

View file

@ -168,21 +168,21 @@ enum StyleDeclaration {
Width(CSSValue<BoxSizing>)
}
enum Attr{
pub enum Attr {
Exists(~str),
Exact(~str, ~str),
Includes(~str, ~str),
StartsWith(~str, ~str)
}
enum Selector{
pub enum Selector {
Element(~str, ~[Attr]),
Child(~Selector, ~Selector),
Descendant(~Selector, ~Selector),
Sibling(~Selector, ~Selector)
}
type Rule = (~[~Selector], ~[StyleDeclaration]);
pub type Rule = (~[~Selector], ~[StyleDeclaration]);
type Stylesheet = ~[~Rule];

View file

@ -88,7 +88,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
fn init(compartment: bare_compartment, doc: @Document) {
pub fn init(compartment: bare_compartment, doc: @Document) {
let obj = utils::define_empty_prototype(~"Document", None, compartment);
let attrs = @~[
@ -97,7 +97,7 @@ fn init(compartment: bare_compartment, doc: @Document) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: {op: getDocumentElement, info: null()},
setter: {op: null(), info: null()}}];
vec::push(compartment.global_props, attrs);
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
assert JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1;
});

View file

@ -30,7 +30,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
fn init(compartment: bare_compartment) {
pub fn init(compartment: bare_compartment) {
let obj = utils::define_empty_prototype(~"Element", Some(~"Node"), compartment);
let attrs = @~[
{name: compartment.add_name(~"tagName"),
@ -38,7 +38,7 @@ fn init(compartment: bare_compartment) {
flags: (JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS) as u8,
getter: {op: getTagName, info: null()},
setter: {op: null(), info: null()}}];
vec::push(compartment.global_props, attrs);
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
});
@ -58,7 +58,7 @@ fn init(compartment: bare_compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: {op: HTMLImageElement_getWidth, info: null()},
setter: {op: HTMLImageElement_setWidth, info: null()}}];
vec::push(compartment.global_props, attrs);
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
});
@ -147,7 +147,7 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut jsval)
return 1;
}
fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
let proto = scope.write(node, |nd| {
match nd.kind {
~Element(ed) => {

View file

@ -14,7 +14,7 @@ use utils::{rust_box, squirrel_away_unique, get_compartment, domstring_to_jsval,
use libc::c_uint;
use ptr::null;
fn init(compartment: bare_compartment) {
pub fn init(compartment: bare_compartment) {
let obj = utils::define_empty_prototype(~"Node", None, compartment);
let attrs = @~[
@ -35,13 +35,13 @@ fn init(compartment: bare_compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: {op: getNodeType, info: null()},
setter: {op: null(), info: null()}}];
vec::push(compartment.global_props, attrs);
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
});
}
fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
pub fn create(cx: *JSContext, node: Node, scope: NodeScope) -> jsobj unsafe {
do scope.write(node) |nd| {
match nd.kind {
~Element(*) => {

View file

@ -45,7 +45,7 @@ fn jsval_to_str(cx: *JSContext, v: jsval) -> Result<~str, ()> {
}
let len = 0;
let chars = JS_GetStringCharsZAndLength(cx, jsstr, ptr::addr_of(len));
let chars = JS_GetStringCharsZAndLength(cx, jsstr, ptr::to_unsafe_ptr(&len));
return if chars.is_null() {
Err(())
} else {
@ -70,7 +70,7 @@ unsafe fn domstring_to_jsval(cx: *JSContext, str: DOMString) -> jsval {
}
}
fn get_compartment(cx: *JSContext) -> *bare_compartment {
pub fn get_compartment(cx: *JSContext) -> *bare_compartment {
unsafe {
let privptr: *libc::c_void = JS_GetContextPrivate(cx);
let compartment: *bare_compartment = cast::reinterpret_cast(&privptr);
@ -94,7 +94,7 @@ extern fn has_instance(_cx: *JSContext, obj: **JSObject, v: *jsval, bp: *mut JSB
return 1;
}
fn prototype_jsclass(name: ~str) -> fn(+bare_compartment) -> JSClass {
pub fn prototype_jsclass(name: ~str) -> fn(+compartment: bare_compartment) -> JSClass {
|+compartment: bare_compartment, copy name| {
{name: compartment.add_name(name),
flags: 0,
@ -122,8 +122,8 @@ fn prototype_jsclass(name: ~str) -> fn(+bare_compartment) -> JSClass {
}
}
fn instance_jsclass(name: ~str, finalize: *u8)
-> fn(+bare_compartment) -> JSClass {
pub fn instance_jsclass(name: ~str, finalize: *u8)
-> fn(+compartment: bare_compartment) -> JSClass {
|+compartment: bare_compartment, copy name| {
{name: compartment.add_name(name),
flags: JSCLASS_HAS_RESERVED_SLOTS(1),
@ -151,7 +151,7 @@ fn instance_jsclass(name: ~str, finalize: *u8)
}
}
fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: bare_compartment)
pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: bare_compartment)
-> js::rust::jsobj {
compartment.register_class(utils::prototype_jsclass(name));

View file

@ -64,7 +64,7 @@ extern fn finalize(_fop: *JSFreeOp, obj: *JSObject) {
}
}
fn init(compartment: bare_compartment, win: @Window) {
pub fn init(compartment: bare_compartment, win: @Window) {
let proto = utils::define_empty_prototype(~"Window", None, compartment);
compartment.register_class(utils::instance_jsclass(~"WindowInstance", finalize));

View file

@ -87,7 +87,7 @@ impl Node : DebugMethods {
}
}
enum NodeKind {
pub enum NodeKind {
Doctype(DoctypeData),
Comment(~str),
Element(ElementData),

View file

@ -53,11 +53,6 @@ use core::libc::types::os::arch::c95::size_t;
use ptr::Ptr;
use vec::push;
export Handle;
export ReaderMethods;
export WriterMethods;
export Scope;
type ScopeData<T:Send,A> = {
mut layout_active: bool,
mut free_list: ~[Handle<T,A>],
@ -76,13 +71,13 @@ fn ScopeResource<T:Send,A>(d : ScopeData<T,A>) -> ScopeResource<T,A> {
ScopeResource { d: d }
}
type Scope<T:Send,A> = @ScopeResource<T,A>;
pub type Scope<T:Send,A> = @ScopeResource<T,A>;
type HandleData<T:Send,A> = {mut read_ptr: *T,
mut write_ptr: *mut T,
mut read_aux: *A,
mut next_dirty: Handle<T,A>};
enum Handle<T:Send,A> {
pub enum Handle<T:Send,A> {
_Handle(*HandleData<T,A>)
}
@ -118,7 +113,7 @@ impl<T:Send,A> Handle<T,A> {
**Warning:** the reader is responsible for keeping this data live!
")]
fn set_aux(p: @A) unsafe {
(**self).read_aux = ptr::addr_of(*p);
(**self).read_aux = ptr::to_unsafe_ptr(&*p);
}
#[doc(str = "access the auxiliary data associated with this handle.")]
@ -159,7 +154,7 @@ fn null_handle<T:Send,A>() -> Handle<T,A> {
_Handle(ptr::null())
}
fn Scope<T:Send,A>() -> Scope<T,A> {
pub fn Scope<T:Send,A>() -> Scope<T,A> {
@ScopeResource({mut layout_active: false,
mut free_list: ~[],
mut first_dirty: null_handle()})
@ -219,12 +214,12 @@ impl<T:Copy Send,A> Scope<T,A> {
let d: *HandleData<T,A> =
cast::reinterpret_cast(
&libc::malloc(sys::size_of::<HandleData<T,A>>() as size_t));
(*d).read_ptr = self.clone(ptr::addr_of(v));
(*d).read_ptr = self.clone(ptr::to_unsafe_ptr(&v));
(*d).write_ptr = cast::reinterpret_cast(&(*d).read_ptr);
(*d).read_aux = ptr::null();
(*d).next_dirty = null_handle();
let h = _Handle(d);
push(self.d.free_list, h);
push(&mut self.d.free_list, h);
return h;
}
}

View file

@ -20,12 +20,12 @@ struct Window {
// Holder for the various JS values associated with setTimeout
// (ie. function value to invoke and all arguments to pass
// to the function when calling it)
struct TimerData {
pub struct TimerData {
funval: jsval,
args: DVec<jsval>,
}
fn TimerData(argc: libc::c_uint, argv: *jsval) -> TimerData unsafe {
pub fn TimerData(argc: libc::c_uint, argv: *jsval) -> TimerData unsafe {
let data = TimerData {
funval : *argv,
args : DVec(),

View file

@ -1,112 +1,87 @@
export EngineTask, EngineTask_, EngineProto;
use gfx::compositor::Compositor;
use gfx::render_task;
use render_task::RenderTask;
use pipes::{spawn_service, select};
use mod gfx::render_task;
use gfx::render_task::{Renderer, RenderTask};
use task::spawn_listener;
use layout::layout_task;
use layout_task::LayoutTask;
use content::content_task;
use content_task::{ContentTask};
use mod content::content_task;
use content::content_task::{ContentTask, ExecuteMsg, ParseMsg, ExitMsg};
use resource::resource_task;
use resource::resource_task::{ResourceTask};
use resource::resource_task::ResourceTask;
use std::net::url::Url;
use resource::image_cache_task;
use image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use image_cache_task::{ImageCacheTask, image_cache_task, ImageCacheTaskClient};
use pipes::{Port, Chan};
fn macros() {
include!("macros.rs");
}
type EngineTask = EngineProto::client::Running;
fn EngineTask<C: Compositor Send Copy>(+compositor: C) -> EngineTask {
let resource_task = ResourceTask();
let image_cache_task = ImageCacheTask(resource_task);
EngineTask_(compositor, resource_task, image_cache_task)
}
fn EngineTask_<C: Compositor Send Copy>(
+compositor: C,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask
) -> EngineTask {
do spawn_service(EngineProto::init) |request, move compositor| {
let render_task = RenderTask(compositor);
let layout_task = LayoutTask(render_task, image_cache_task);
let content_task = ContentTask(layout_task, compositor, resource_task, image_cache_task);
Engine {
compositor: compositor,
render_task: render_task,
resource_task: resource_task,
image_cache_task: image_cache_task,
layout_task: layout_task,
content_task: content_task,
}.run(request);
}
}
struct Engine<C:Compositor> {
pub struct Engine<C:Compositor Send Copy> {
compositor: C,
render_task: RenderTask,
render_task: Renderer,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask,
layout_task: LayoutTask,
content_task: ContentTask,
content_task: ContentTask
}
impl<C: Compositor> Engine<C> {
fn run(+request: EngineProto::server::Running) {
use EngineProto::*;
let mut request = request;
pub fn Engine<C:Compositor Send Copy>(compositor: C,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask) -> Engine<C> {
let render_task = RenderTask(compositor);
let layout_task = LayoutTask(render_task, image_cache_task);
let content_task = ContentTask(layout_task, compositor, resource_task, image_cache_task);
loop {
select!(
request => {
LoadURL(url) -> next {
// TODO: change copy to move once we have match move
let url = move_ref!(url);
if url.path.ends_with(".js") {
self.content_task.send(content_task::ExecuteMsg(url))
} else {
self.content_task.send(content_task::ParseMsg(url))
}
request = next;
},
Engine {
compositor: compositor,
render_task: render_task,
resource_task: resource_task,
image_cache_task: image_cache_task,
layout_task: layout_task,
content_task: content_task
}
}
Exit -> channel {
self.content_task.send(content_task::ExitMsg);
self.layout_task.send(layout_task::ExitMsg);
impl<C: Compositor Copy Send> Engine<C> {
fn start() -> comm::Chan<Msg> {
do spawn_listener::<Msg> |request| {
while self.handle_request(request.recv()) {
// Go on...
}
}
}
let (response_chan, response_port) = pipes::stream();
self.render_task.send(render_task::ExitMsg(response_chan));
response_port.recv();
fn handle_request(request: Msg) -> bool {
match request {
LoadURLMsg(url) => {
// TODO: change copy to move once we have match move
let url = copy url;
if url.path.ends_with(".js") {
self.content_task.send(ExecuteMsg(url))
} else {
self.content_task.send(ParseMsg(url))
}
return true;
}
self.image_cache_task.exit();
self.resource_task.send(resource_task::Exit);
ExitMsg(sender) => {
self.content_task.send(content_task::ExitMsg);
self.layout_task.send(layout_task::ExitMsg);
server::Exited(channel);
break
}
}
)
let (response_chan, response_port) = pipes::stream();
self.render_task.send(render_task::ExitMsg(response_chan));
response_port.recv();
self.image_cache_task.exit();
self.resource_task.send(resource_task::Exit);
sender.send(());
return false;
}
}
}
}
proto! EngineProto(
Running:send {
LoadURL(Url) -> Running,
Exit -> Exiting
}
Exiting:recv {
Exited -> !
}
)
pub enum Msg {
LoadURLMsg(Url),
ExitMsg(Chan<()>)
}

View file

@ -29,7 +29,7 @@ A run of glyphs in a single font. This is distinguished from any similar
structure used by layout in that this must be sendable, whereas the text
shaping data structures may end up unsendable.
*/
struct GlyphRun {
pub struct GlyphRun {
glyphs: ~[Glyph]
}
@ -54,7 +54,7 @@ fn draw_Image(self: &DisplayItem, ctx: &RenderContext) {
}
}
fn SolidColor(bounds: Rect<au>, r: u8, g: u8, b: u8) -> DisplayItem {
pub fn SolidColor(bounds: Rect<au>, r: u8, g: u8, b: u8) -> DisplayItem {
DisplayItem {
// TODO: this seems wrong.
draw: |self, ctx| draw_SolidColor(self, ctx),
@ -63,7 +63,7 @@ fn SolidColor(bounds: Rect<au>, r: u8, g: u8, b: u8) -> DisplayItem {
}
}
fn Glyphs(bounds: Rect<au>, run: GlyphRun) -> DisplayItem {
pub fn Glyphs(bounds: Rect<au>, run: GlyphRun) -> DisplayItem {
DisplayItem {
draw: |self, ctx| draw_Glyphs(self, ctx),
bounds: bounds,
@ -72,7 +72,7 @@ fn Glyphs(bounds: Rect<au>, run: GlyphRun) -> DisplayItem {
}
// ARC should be cloned into ImageData, but Images are not sendable
fn Image(bounds: Rect<au>, image: ARC<~image::base::Image>) -> DisplayItem {
pub fn Image(bounds: Rect<au>, image: ARC<~image::base::Image>) -> DisplayItem {
DisplayItem {
// TODO: this seems wrong.
draw: |self, ctx| draw_Image(self, ctx),
@ -81,7 +81,7 @@ fn Image(bounds: Rect<au>, image: ARC<~image::base::Image>) -> DisplayItem {
}
}
type DisplayList = DVec<~DisplayItem>;
pub type DisplayList = DVec<~DisplayItem>;
trait DisplayListMethods {
fn draw(ctx: &RenderContext);

View file

@ -3,19 +3,19 @@ use geom::rect::Rect;
use geom::size::Size2D;
use num::{Num, from_int};
enum au = i32;
pub enum au = i32;
impl au : Num {
pure fn add(&&other: au) -> au { au(*self + *other) }
pure fn sub(&&other: au) -> au { au(*self - *other) }
pure fn mul(&&other: au) -> au { au(*self * *other) }
pure fn div(&&other: au) -> au { au(*self / *other) }
pure fn modulo(&&other: au) -> au { au(*self % *other) }
pure fn add(other: &au) -> au { au(*self + **other) }
pure fn sub(other: &au) -> au { au(*self - **other) }
pure fn mul(other: &au) -> au { au(*self * **other) }
pure fn div(other: &au) -> au { au(*self / **other) }
pure fn modulo(other: &au) -> au { au(*self % **other) }
pure fn neg() -> au { au(-*self) }
pure fn to_int() -> int { *self as int }
static pure fn from_int(n: int) -> au {
static pure fn from_int(+n: int) -> au {
au((n & (i32::max_value as int)) as i32)
}
}
@ -32,31 +32,31 @@ impl au : cmp::Eq {
pure fn ne(other: &au) -> bool { *self != **other }
}
pure fn min(x: au, y: au) -> au { if x < y { x } else { y } }
pure fn max(x: au, y: au) -> au { if x > y { x } else { y } }
pub pure fn min(x: au, y: au) -> au { if x < y { x } else { y } }
pub pure fn max(x: au, y: au) -> au { if x > y { x } else { y } }
fn box<A:Copy Num>(x: A, y: A, w: A, h: A) -> Rect<A> {
pub fn box<A:Copy Num>(x: A, y: A, w: A, h: A) -> Rect<A> {
Rect(Point2D(x, y), Size2D(w, h))
}
fn zero_rect() -> Rect<au> {
pub fn zero_rect() -> Rect<au> {
let z = au(0);
Rect(Point2D(z, z), Size2D(z, z))
}
fn zero_point() -> Point2D<au> {
pub fn zero_point() -> Point2D<au> {
Point2D(au(0), au(0))
}
fn zero_size() -> Size2D<au> {
pub fn zero_size() -> Size2D<au> {
Size2D(au(0), au(0))
}
pure fn from_px(i: int) -> au {
pub pure fn from_px(i: int) -> au {
from_int(i * 60)
}
pure fn to_px(au: au) -> int {
pub pure fn to_px(au: au) -> int {
(*au / 60) as int
}

View file

@ -1,20 +1,21 @@
use mod azure::azure_hl;
use au = geometry;
use au::au;
use platform::osmain;
use comm::*;
use image::base::Image;
use dl = display_list;
use azure::*;
use azure::bindgen::*;
use libc::size_t;
use text::font::Font;
use display_list::GlyphRun;
use geom::size::Size2D;
use geom::rect::Rect;
use geom::point::Point2D;
use azure::{AzDrawOptions, AzFloat, AzGlyph, AzGlyphBuffer};
use azure::bindgen::AzDrawTargetFillGlyphs;
use azure_hl::{AsAzureRect, B8G8R8A8, Color, ColorPattern, DrawOptions, DrawSurfaceOptions};
use azure_hl::{DrawTarget, Linear};
use ptr::addr_of;
use ptr::to_unsafe_ptr;
use std::arc::ARC;
use azure::cairo::{cairo_font_face_t, cairo_scaled_font_t};
use std::cell::Cell;
@ -23,7 +24,7 @@ use servo_text::font_cache::FontCache;
use pipes::{Port, Chan};
type Renderer = comm::Chan<Msg>;
pub type Renderer = comm::Chan<Msg>;
pub enum Msg {
RenderMsg(dl::DisplayList),
@ -35,9 +36,9 @@ struct RenderContext {
font_cache: @FontCache,
}
type RenderTask = comm::Chan<Msg>;
pub type RenderTask = comm::Chan<Msg>;
fn RenderTask<C: Compositor Send>(+compositor: C) -> RenderTask {
pub fn RenderTask<C: Compositor Send>(+compositor: C) -> RenderTask {
do task::spawn_listener |po: comm::Port<Msg>| {
let (draw_target_ch, draw_target_po) = pipes::stream();
let mut draw_target_ch = draw_target_ch;
@ -133,7 +134,7 @@ pub fn draw_image(ctx: &RenderContext, bounds: Rect<au>, image: ARC<~Image>) {
}
pub fn draw_glyphs(ctx: &RenderContext, bounds: Rect<au>, text_run: &GlyphRun) {
use ptr::{addr_of, null};
use ptr::{null};
use vec::raw::to_ptr;
use libc::types::common::c99::{uint16_t, uint32_t};
use geom::point::Point2D;
@ -155,7 +156,7 @@ pub fn draw_glyphs(ctx: &RenderContext, bounds: Rect<au>, text_run: &GlyphRun) {
};
let cfont = get_cairo_font(font);
let azfont = AzCreateScaledFontWithCairo(addr_of(nfont), 1f as AzFloat, cfont);
let azfont = AzCreateScaledFontWithCairo(to_unsafe_ptr(&nfont), 1f as AzFloat, cfont);
assert azfont.is_not_null();
cairo_scaled_font_destroy(cfont);
@ -165,7 +166,7 @@ pub fn draw_glyphs(ctx: &RenderContext, bounds: Rect<au>, text_run: &GlyphRun) {
b: 0f as AzFloat,
a: 1f as AzFloat
};
let pattern = AzCreateColorPattern(addr_of(color));
let pattern = AzCreateColorPattern(to_unsafe_ptr(&color));
assert pattern.is_not_null();
let options: AzDrawOptions = {
@ -173,17 +174,17 @@ pub fn draw_glyphs(ctx: &RenderContext, bounds: Rect<au>, text_run: &GlyphRun) {
fields: 0 as uint16_t
};
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(bounds.size.height));
let mut origin = Point2D(bounds.origin.x, bounds.origin.y.add(&bounds.size.height));
let azglyphs = text_run.glyphs.map(|glyph| {
let azglyph: AzGlyph = {
mIndex: glyph.index as uint32_t,
mPosition: {
x: au::to_px(origin.x.add(glyph.pos.offset.x)) as AzFloat,
y: au::to_px(origin.y.add(glyph.pos.offset.y)) as AzFloat
x: au::to_px(origin.x.add(&glyph.pos.offset.x)) as AzFloat,
y: au::to_px(origin.y.add(&glyph.pos.offset.y)) as AzFloat
}
};
origin = Point2D(origin.x.add(glyph.pos.advance.x),
origin.y.add(glyph.pos.advance.y));
origin = Point2D(origin.x.add(&glyph.pos.advance.x),
origin.y.add(&glyph.pos.advance.y));
azglyph
});
@ -193,8 +194,8 @@ pub fn draw_glyphs(ctx: &RenderContext, bounds: Rect<au>, text_run: &GlyphRun) {
}};
// TODO: this call needs to move into azure_hl.rs
AzDrawTargetFillGlyphs(ctx.canvas.azure_draw_target, azfont, addr_of(glyphbuf),
pattern, addr_of(options), null());
AzDrawTargetFillGlyphs(ctx.canvas.azure_draw_target, azfont, to_unsafe_ptr(&glyphbuf),
pattern, to_unsafe_ptr(&options), null());
AzReleaseColorPattern(pattern);
AzReleaseScaledFont(azfont);
@ -246,14 +247,13 @@ fn get_cairo_font(font: &Font) -> *cairo_scaled_font_t {
x0: 0 as c_double,
y0: 0 as c_double
};
cairo_matrix_init_identity(addr_of(idmatrix));
cairo_matrix_init_identity(to_unsafe_ptr(&idmatrix));
let fontmatrix = idmatrix;
cairo_matrix_scale(addr_of(fontmatrix),
20f as c_double, 20f as c_double);
cairo_matrix_scale(to_unsafe_ptr(&fontmatrix), 20f as c_double, 20f as c_double);
let options = cairo_font_options_create();
let cfont = cairo_scaled_font_create(face, addr_of(fontmatrix),
addr_of(idmatrix), options);
let cfont = cairo_scaled_font_create(face, to_unsafe_ptr(&fontmatrix),
to_unsafe_ptr(&idmatrix), options);
cairo_font_options_destroy(options);
cairo_font_face_destroy(face);

View file

@ -1,6 +1,6 @@
use geom::size::Size2D;
enum format {
pub enum format {
fo_rgba_8888
// TODO: RGB 565, others?
}
@ -16,7 +16,7 @@ impl format: cmp::Eq {
}
}
type image_surface = {
pub type image_surface = {
size: Size2D<int>,
format: format,
buffer: ~[u8]
@ -30,7 +30,7 @@ impl format {
}
}
fn image_surface(size: Size2D<int>, format: format) -> image_surface {
pub fn image_surface(size: Size2D<int>, format: format) -> image_surface {
{
size: copy size,
format: format,

View file

@ -65,7 +65,7 @@ fn css_link_listener(to_parent : comm::Chan<Stylesheet>, from_parent : comm::Por
result_chan.send(css_rules);
});
vec::push(result_vec, result_port);
vec::push(&mut result_vec, result_port);
}
CSSTaskExit => {
break;
@ -110,7 +110,7 @@ fn js_script_listener(to_parent : comm::Chan<~[~[u8]]>, from_parent : comm::Port
}
}
}
vec::push(result_vec, result_port);
vec::push(&mut result_vec, result_port);
}
JSTaskExit => {
break;
@ -165,10 +165,10 @@ fn build_element_kind(tag: &str) -> ~ElementKind {
else { ~UnknownElement }
}
fn parse_html(scope: NodeScope,
url: Url,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask) -> HtmlParserResult unsafe {
pub fn parse_html(scope: NodeScope,
url: Url,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask) -> HtmlParserResult unsafe {
// Spawn a CSS parser to receive links to CSS style sheets.
let (css_port, css_chan): (comm::Port<Stylesheet>, comm::Chan<CSSMessage>) =
do task::spawn_conversation |css_port: comm::Port<CSSMessage>,
@ -237,7 +237,7 @@ fn parse_html(scope: NodeScope,
},
~HTMLImageElement(d) => {
do elem.get_attr(~"src").iter |img_url_str| {
let img_url = make_url(copy img_url_str, Some(copy *url));
let img_url = make_url(copy *img_url_str, Some(copy *url));
d.image = Some(copy img_url);
// inform the image cache to load this, but don't store a handle.
// TODO (Issue #84): don't prefetch if we are within a <noscript> tag.

View file

@ -1,246 +0,0 @@
use comm::{Port, Chan};
use option::is_none;
use str::from_bytes;
use vec::push;
use lexer_util::*;
use resource::resource_task;
use resource_task::{ResourceTask, ProgressMsg, Load};
use std::net::url::Url;
enum Token {
StartOpeningTag(~str),
EndOpeningTag,
EndTag(~str),
SelfCloseTag,
Text(~str),
Attr(~str, ~str),
Doctype,
Eof
}
enum ParseState {
NormalHtml,
TagHtml,
}
type HtmlLexer = {
input_state: InputState,
mut parser_state: ParseState
};
trait HtmlLexerMethods {
fn parse_html() -> Token;
fn parse_in_normal_state(c: u8) -> Token;
fn parse_in_tag_state(c: u8) -> Token;
fn eat_until_end_of_comment();
}
impl HtmlLexer : HtmlLexerMethods {
fn parse_html() -> Token {
let mut ch: u8;
match self.input_state.get() {
CoeChar(c) => { ch = c; }
CoeEof => { return Eof; }
}
let token = match self.parser_state {
NormalHtml => { self.parse_in_normal_state(ch) }
TagHtml => { self.parse_in_tag_state(ch) }
};
#debug["token=%?", token];
return token;
}
fn parse_in_normal_state(c: u8) -> Token {
let mut ch = c;
if ch == ('<' as u8) {
match self.input_state.get() {
CoeChar(c) => { ch = c; }
CoeEof => { self.input_state.parse_err(~"eof after '<'") }
}
if ch == ('!' as u8) {
let ch = self.input_state.get();
// FIXME: This comment parsing is very hacky
if ch == CoeChar('-' as u8) {
self.eat_until_end_of_comment();
return match self.input_state.get() {
CoeChar(c) => self.parse_in_normal_state(c),
CoeEof => self.input_state.parse_err(~"FIXME")
}
} else if ch == CoeChar('D' as u8) {
self.input_state.expect_ident(~"OCTYPE");
self.input_state.eat_whitespace();
self.input_state.expect_ident(~"html");
self.input_state.eat_whitespace();
self.input_state.expect('>' as u8);
return Doctype;
} else {
self.input_state.eat_whitespace();
self.input_state.expect_ident(~"DOCTYPE");
self.input_state.eat_whitespace();
self.input_state.expect_ident(~"html");
self.input_state.eat_whitespace();
self.input_state.expect('>' as u8);
return Doctype;
}
}
if ch == ('/' as u8) {
let ident = self.input_state.parse_ident();
self.input_state.expect('>' as u8);
return EndTag(ident);
}
self.input_state.unget(ch);
self.input_state.eat_whitespace();
let ident = self.input_state.parse_ident();
self.input_state.eat_whitespace();
self.parser_state = TagHtml;
return StartOpeningTag(ident);
}
// Make a text node.
let mut s: ~[u8] = ~[ch];
loop {
match self.input_state.get() {
CoeChar(c) => {
if c == ('<' as u8) {
self.input_state.unget(c);
return Text(from_bytes(s));
}
push(s, c);
}
CoeEof => { return Text(from_bytes(s)); }
}
}
}
fn eat_until_end_of_comment() {
let mut state = None;
loop {
match self.input_state.get() {
CoeChar(c) => {
match c {
'-' as u8 if state == None => {
state = Some(~"-")
}
'-' as u8 if state == Some(~"-") => {
state = Some(~"--")
}
'>' as u8 if state == Some(~"--") => {
return
}
_ => {
state = None
}
}
}
CoeEof => return
}
}
}
fn parse_in_tag_state(c: u8) -> Token {
let mut ch = c;
if ch == ('>' as u8) {
self.parser_state = NormalHtml;
return EndOpeningTag;
}
if ch == ('/' as u8) {
match self.input_state.get() {
CoeChar(c) => {
if c == ('>' as u8) {
self.parser_state = NormalHtml;
return SelfCloseTag;
} else {
#warn["/ not followed by > in a tag"];
}
}
CoeEof => {
#warn["/ not followed by > at end of file"];
}
}
}
if !ch.is_alpha() {
fail #fmt("expected alphabetical in tag but found %c", ch as char);
}
// Parse an attribute.
let mut attribute_name = ~[ch];
loop {
match self.input_state.get() {
CoeChar(c) => {
if c == ('=' as u8) { break; }
push(attribute_name, c);
}
CoeEof => {
let name = from_bytes(attribute_name);
return Attr(copy name, name);
}
}
}
// Parse the attribute value.
self.input_state.expect('"' as u8);
let mut attribute_value = ~[];
loop {
match self.input_state.get() {
CoeChar(c) => {
if c == ('"' as u8) { break; }
push(attribute_value, c);
}
CoeEof => {
return Attr(from_bytes(attribute_name), from_bytes(attribute_value));
}
}
}
// Eat whitespacpe.
self.input_state.eat_whitespace();
return Attr(from_bytes(attribute_name), from_bytes(attribute_value));
}
}
fn lexer(+input_port: Port<resource_task::ProgressMsg>, state : ParseState) -> HtmlLexer {
return {
input_state: {
mut lookahead: None,
mut buffer: ~[],
input_port: input_port,
mut eof: false
},
mut parser_state: state
};
}
#[allow(non_implicitly_copyable_typarams)]
fn spawn_html_lexer_task(-url: Url, resource_task: ResourceTask) -> Port<Token> {
let html_port = Port();
let html_chan = Chan(html_port);
task::spawn(|| {
let input_port = Port();
// TODO: change copy to move once we can move into closures
resource_task.send(Load(copy url, input_port.chan()));
let lexer = lexer(input_port, NormalHtml);
loop {
let token = lexer.parse_html();
let should_break = match token { Eof => true, _ => false };
html_chan.send(token);
if should_break { break; }
}
});
return html_port;
}

View file

@ -73,7 +73,7 @@ impl InputState : InputStateUtil {
// FIXME: Lots of copies here
if self.buffer.len() > 0 {
return CoeChar(vec::shift(self.buffer));
return CoeChar(vec::shift(&mut self.buffer));
}
if self.eof {
@ -84,7 +84,7 @@ impl InputState : InputStateUtil {
Payload(data) => {
// TODO: change copy to move once we have match move
self.buffer = copy data;
return CoeChar(vec::shift(self.buffer));
return CoeChar(vec::shift(&mut self.buffer));
}
Done(*) => {
self.eof = true;
@ -94,7 +94,7 @@ impl InputState : InputStateUtil {
}
fn unget(ch: u8) {
assert is_none(self.lookahead);
assert is_none(&self.lookahead);
self.lookahead = Some(CoeChar(ch));
}
@ -114,7 +114,7 @@ impl InputState : InputStateUtil {
loop {
match self.get() {
CoeChar(c) => {
if (c.is_alpha()) { push(result, c); }
if (c.is_alpha()) { push(&mut result, c); }
else if result.len() == 0u { self.parse_err(~"expected ident"); }
else {
self.unget(c);

View file

@ -9,9 +9,9 @@ use stb_image = stb_image::image;
// FIXME: Images must not be copied every frame. Instead we should atomically
// reference count them.
type Image = stb_image::Image;
pub type Image = stb_image::Image;
fn Image(width: uint, height: uint, depth: uint, +data: ~[u8]) -> Image {
pub fn Image(width: uint, height: uint, depth: uint, +data: ~[u8]) -> Image {
stb_image::new_image(width, height, depth, data)
}
@ -21,7 +21,7 @@ fn test_image_bin() -> ~[u8] {
return vec::from_fn(4962, |i| TEST_IMAGE[i]);
}
fn load_from_memory(buffer: &[u8]) -> Option<Image> {
pub fn load_from_memory(buffer: &[u8]) -> Option<Image> {
do stb_image::load_from_memory(buffer).map |image| {
assert image.depth == 4;

View file

@ -1,7 +1,7 @@
use std::net::url::Url;
use std::arc::{ARC, clone, get};
use resource::image_cache_task::ImageCacheTask;
use resource::image_cache_task;
use mod resource::image_cache_task;
use geom::size::Size2D;
/** A struct to store image data. The image will be loaded once, the

View file

@ -22,7 +22,7 @@ fn BlockFlowData() -> BlockFlowData {
trait BlockLayout {
pure fn starts_block_flow() -> bool;
pure fn with_block_box(fn(&&@RenderBox) -> ()) -> ();
pure fn with_block_box(fn(box: &@RenderBox) -> ()) -> ();
fn bubble_widths_block(ctx: &LayoutContext);
fn assign_widths_block(ctx: &LayoutContext);
@ -43,7 +43,7 @@ impl FlowContext : BlockLayout {
/* Get the current flow's corresponding block box, if it exists, and do something with it.
This works on both BlockFlow and RootFlow, since they are mostly the same. */
pure fn with_block_box(cb:fn(&&@RenderBox) -> ()) -> () {
pure fn with_block_box(cb: fn(box: &@RenderBox) -> ()) -> () {
match self {
BlockFlow(*) => {
let mut box = self.block().box;
@ -83,8 +83,8 @@ impl FlowContext : BlockLayout {
/* if not an anonymous block context, add in block box's widths.
these widths will not include child elements, just padding etc. */
do self.with_block_box |box| {
min_width = min_width.add(box.get_min_width());
pref_width = pref_width.add(box.get_pref_width());
min_width = min_width.add(&box.get_min_width());
pref_width = pref_width.add(&box.get_pref_width());
}
self.d().min_width = min_width;
@ -110,7 +110,7 @@ impl FlowContext : BlockLayout {
do self.with_block_box |box| {
box.d().position.size.width = remaining_width;
let (left_used, right_used) = box.get_used_width();
remaining_width = remaining_width.sub(left_used.add(right_used));
remaining_width = remaining_width.sub(&left_used.add(&right_used));
}
for FlowTree.each_child(@self) |child_ctx| {
@ -127,7 +127,7 @@ impl FlowContext : BlockLayout {
for FlowTree.each_child(@self) |child_ctx| {
child_ctx.d().position.origin.y = cur_y;
cur_y = cur_y.add(child_ctx.d().position.size.height);
cur_y = cur_y.add(&child_ctx.d().position.size.height);
}
self.d().position.size.height = cur_y;

View file

@ -90,7 +90,7 @@ enum RenderBoxType {
RenderBox_Text
}
enum RenderBox {
pub enum RenderBox {
GenericBox(RenderBoxData),
ImageBox(RenderBoxData, ImageHolder),
TextBox(RenderBoxData, TextBoxData)
@ -142,7 +142,7 @@ impl RenderBox {
// TODO: If image isn't available, consult 'width'.
ImageBox(_,i) => au::from_px(i.get_size().get_default(Size2D(0,0)).width),
TextBox(_,d) => d.runs.foldl(au(0), |sum, run| {
au::max(sum, run.min_break_width())
au::max(*sum, run.min_break_width())
})
}
}
@ -160,7 +160,7 @@ impl RenderBox {
// how to compute its own min and pref widths, and should
// probably cache them.
TextBox(_,d) => d.runs.foldl(au(0), |sum, run| {
au::max(sum, run.size().width)
au::max(*sum, run.size().width)
})
}
}
@ -261,7 +261,7 @@ impl RenderBox {
bounds.size.height = runs[i].size().height;
let glyph_run = make_glyph_run(&runs[i]);
list.push(~dl::Glyphs(bounds, glyph_run));
bounds.origin.y = bounds.origin.y.add(bounds.size.height);
bounds.origin.y = bounds.origin.y.add(&bounds.size.height);
}
return;
@ -301,10 +301,10 @@ trait ImageBoxMethods {
* nested CSS boxes that are nested in an otherwise inline flow
* context.
*/
enum RenderBoxTree { RenderBoxTree }
pub enum RenderBoxTree { RenderBoxTree }
impl RenderBoxTree : tree::ReadMethods<@RenderBox> {
fn each_child(node: @RenderBox, f: fn(&&@RenderBox) -> bool) {
fn each_child(node: @RenderBox, f: fn(&&box: @RenderBox) -> bool) {
tree::each_child(self, node, f)
}
@ -350,7 +350,7 @@ impl RenderBox : BoxedDebugMethods {
@ImageBox(*) => ~"ImageBox",
@TextBox(_,d) => {
let mut s = d.runs.foldl(~"TextBox(runs=", |s, run| {
fmt!("%s \"%s\"", s, run.text)
fmt!("%s \"%s\"", *s, run.text)
});
s += ~")"; s
}
@ -385,10 +385,10 @@ mod test {
fn flat_bounds(root: @RenderBox) -> ~[Rect<au>] {
let mut r = ~[];
for tree::each_child(RenderBoxTree, root) |c| {
push_all(r, flat_bounds(c));
push_all(&mut r, flat_bounds(c));
}
push(r, copy root.d().position);
push(&mut r, copy root.d().position);
return r;
}

View file

@ -26,7 +26,7 @@ use vec::push;
Right now, the builder isn't used for much, but it establishes the
pattern we'll need once we support DL-based hit testing &c. */
struct DisplayListBuilder {
pub struct DisplayListBuilder {
ctx: &LayoutContext,
}

View file

@ -181,8 +181,8 @@ impl FlowContext {
_ => seed
},
InlineFlow(*) => do self.inline().boxes.foldl(seed) |acc, box| {
if box.d().node == node { blk(acc, box) }
else { acc }
if box.d().node == node { blk(*acc, *box) }
else { *acc }
},
_ => fail fmt!("Don't know how to iterate node's RenderBoxes for %?", self)
}
@ -213,12 +213,12 @@ impl FlowContext {
enum FlowTree { FlowTree }
impl FlowTree : tree::ReadMethods<@FlowContext> {
fn each_child(ctx: @FlowContext, f: fn(&&@FlowContext) -> bool) {
fn each_child(ctx: @FlowContext, f: fn(&&box: @FlowContext) -> bool) {
tree::each_child(self, ctx, f)
}
fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
f(b.d().tree)
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
f(box.d().tree)
}
}
@ -228,8 +228,8 @@ impl FlowTree : tree::WriteMethods<@FlowContext> {
tree::add_child(self, parent, child)
}
fn with_tree_fields<R>(&&b: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
f(b.d().tree)
fn with_tree_fields<R>(&&box: @FlowContext, f: fn(tree::Tree<@FlowContext>) -> R) -> R {
f(box.d().tree)
}
}
@ -259,7 +259,7 @@ impl FlowContext : BoxedDebugMethods {
let repr = match *self {
InlineFlow(*) => {
let mut s = self.inline().boxes.foldl(~"InlineFlow(children=", |s, box| {
fmt!("%s %?", s, box.d().id)
fmt!("%s %?", *s, box.d().id)
});
s += ~")"; s
},

View file

@ -133,7 +133,7 @@ impl FlowContext : InlineLayout {
};
box.d().position.origin = Point2D(au(0), cur_y);
cur_y = cur_y.add(au::max(line_height, box.d().position.size.height));
cur_y = cur_y.add(&au::max(line_height, box.d().position.size.height));
} // for boxes.each |box|
self.d().position.size.height = cur_y;

View file

@ -30,28 +30,28 @@ use layout::traverse::*;
use comm::*;
use task::*;
type LayoutTask = Chan<Msg>;
pub type LayoutTask = comm::Chan<Msg>;
enum LayoutQuery {
pub enum LayoutQuery {
ContentBox(Node)
}
type LayoutQueryResponse = Result<LayoutQueryResponse_, ()>;
pub type LayoutQueryResponse = Result<LayoutQueryResponse_, ()>;
enum LayoutQueryResponse_ {
ContentSize(Size2D<int>)
}
enum Msg {
BuildMsg(Node, ARC<Stylesheet>, Url, Chan<Event>),
PingMsg(Chan<content_task::PingMsg>),
QueryMsg(LayoutQuery, Chan<LayoutQueryResponse>),
pub enum Msg {
BuildMsg(Node, ARC<Stylesheet>, Url, comm::Chan<Event>),
PingMsg(comm::Chan<content_task::PingMsg>),
QueryMsg(LayoutQuery, comm::Chan<LayoutQueryResponse>),
ExitMsg
}
fn LayoutTask(render_task: RenderTask,
img_cache_task: ImageCacheTask) -> LayoutTask {
do spawn_listener::<Msg>|from_content| {
do spawn_listener::<Msg> |from_content| {
Layout(render_task, img_cache_task, from_content).start();
}
}

View file

@ -56,7 +56,8 @@ finish, and then applies the second function to the current box.
applied to that node's children
*/
fn traverse_helper<T : Copy Send>(-root : @RenderBox, returned : T, -top_down : fn~(+T, @RenderBox) -> T,
fn traverse_helper<T : Copy Send>(-root : @RenderBox, returned : T,
-top_down : fn~(+val: T, @RenderBox) -> T,
-bottom_up : fn~(@RenderBox)) {
let returned = top_down(returned, root);
@ -110,7 +111,7 @@ fn nop(_box : @RenderBox) {
A wrapper to change a function that only acts on a box to one that
threasds a unit through to match travserse_helper
*/
fn unit_wrapper(-fun : fn~(@RenderBox)) -> fn~(+(), @RenderBox) {
fn unit_wrapper(-fun : fn~(@RenderBox)) -> fn~(+val: (), @RenderBox) {
fn~(+_u : (), box : @RenderBox) { fun(box); }
}
@ -146,7 +147,7 @@ fn bottom_up_traversal(+root : @RenderBox, -bottom_up : fn~(@RenderBox)) {
children in parallel, and then the parent.
*/
fn extended_full_traversal<T : Copy Send>(+root : @RenderBox, first_val : T,
-top_down : fn~(+T, @RenderBox) -> T,
-top_down : fn~(+val: T, @RenderBox) -> T,
-bottom_up : fn~(@RenderBox)) {
traverse_helper(root, first_val, top_down, bottom_up);
}
@ -157,6 +158,6 @@ fn extended_full_traversal<T : Copy Send>(+root : @RenderBox, first_val : T,
function is passed to each child when they are recursed upon.
*/
fn extended_top_down_traversal<T : Copy Send>(+root : @RenderBox, first_val : T,
-top_down : fn~(+T, @RenderBox) -> T) {
-top_down : fn~(+val: T, @RenderBox) -> T) {
traverse_helper(root, first_val, top_down, nop);
}

View file

@ -64,5 +64,4 @@
])+)
}
)
}

View file

@ -1,18 +1,18 @@
//! Configuration options for a single run of the servo application. Created
//! from command line arguments.
type Opts = {
pub type Opts = {
urls: ~[~str],
render_mode: RenderMode
};
enum RenderMode {
pub enum RenderMode {
Screen,
Png(~str)
}
#[allow(non_implicitly_copyable_typarams)]
fn from_cmdline_args(args: ~[~str]) -> Opts {
pub fn from_cmdline_args(args: ~[~str]) -> Opts {
use std::getopts;
let args = args.tail();

View file

@ -1,13 +1,10 @@
export OSMain;
export Msg, BeginDrawing, Draw, AddKeyHandler, Exit;
use azure::*;
use mod azure::azure_hl;
use azure::azure_hl::DrawTarget;
use azure::bindgen::*;
use azure::cairo;
use azure::cairo::bindgen::*;
use azure::cairo_hl::ImageSurface;
use comm::*;
use dvec::DVec;
use azure::cairo::cairo_surface_t;
use gfx::compositor::Compositor;
@ -23,6 +20,7 @@ use pipes::Chan;
type OSMain = comm::Chan<Msg>;
// FIXME: Move me over to opts.rs.
enum Mode {
GlutMode,
ShareMode
@ -33,7 +31,7 @@ enum Window {
ShareWindow(ShareGlContext)
}
enum Msg {
pub enum Msg {
BeginDrawing(pipes::Chan<DrawTarget>),
Draw(pipes::Chan<DrawTarget>, DrawTarget),
AddKeyHandler(pipes::Chan<()>),
@ -57,7 +55,7 @@ fn OSMain() -> OSMain {
}
}
fn mainloop(+mode: Mode, po: Port<Msg>) {
fn mainloop(+mode: Mode, po: comm::Port<Msg>) {
let key_handlers: @DVec<pipes::Chan<()>> = @DVec();
let event_listeners: @DVec<comm::Chan<Event>> = @DVec();
@ -101,7 +99,7 @@ fn mainloop(+mode: Mode, po: Port<Msg>) {
#debug("osmain: peeking");
while po.peek() {
match po.recv() {
AddKeyHandler(key_ch) => key_handlers.push(#moov(key_ch)),
AddKeyHandler(move key_ch) => key_handlers.push(move key_ch),
AddEventListener(event_listener) => event_listeners.push(event_listener),
BeginDrawing(sender) => lend_surface(*surfaces, sender),
Draw(sender, dt) => {
@ -229,13 +227,13 @@ fn Surface() -> Surface {
}
#[doc = "A function for spawning into the platform's main thread"]
fn on_osmain<T: Send>(+f: fn~(comm::Port<T>)) -> comm::Chan<T> {
fn on_osmain<T: Send>(+f: fn~(+po: comm::Port<T>)) -> comm::Chan<T> {
task::task().sched_mode(task::PlatformThread).spawn_listener(f)
}
// #[cfg(target_os = "linux")]
mod platform {
fn runmain(f: fn()) {
pub fn runmain(f: fn()) {
f()
}
}

View file

@ -8,7 +8,7 @@ use io::{file_reader, ReaderUtil};
const READ_SIZE: uint = 1024;
fn factory(+url: Url, progress_chan: Chan<ProgressMsg>) {
pub fn factory(+url: Url, progress_chan: Chan<ProgressMsg>) {
assert url.scheme == ~"file";
do spawn {

View file

@ -6,7 +6,7 @@ use resource_task::{ProgressMsg, Payload, Done};
use std::net::url::Url;
use http_client::{uv_http_request};
fn factory(+url: Url, progress_chan: Chan<ProgressMsg>) {
pub fn factory(+url: Url, progress_chan: Chan<ProgressMsg>) {
assert url.scheme == ~"http";
do spawn {

View file

@ -1,9 +1,3 @@
export Msg, Prefetch, Decode, GetImage, WaitForImage, Exit;
export ImageResponseMsg, ImageReady, ImageNotReady, ImageFailed;
export ImageCacheTask;
export ImageCacheTaskClient;
export SyncImageCacheTask;
use image::base::{Image, load_from_memory, test_image_bin};
use std::net::url::Url;
use util::url::{make_url, UrlMap, url_map};
@ -78,15 +72,15 @@ impl ImageResponseMsg: cmp::Eq {
}
}
type ImageCacheTask = Chan<Msg>;
pub type ImageCacheTask = Chan<Msg>;
type DecoderFactory = ~fn() -> ~fn(~[u8]) -> Option<Image>;
fn ImageCacheTask(resource_task: ResourceTask) -> ImageCacheTask {
pub fn ImageCacheTask(resource_task: ResourceTask) -> ImageCacheTask {
ImageCacheTask_(resource_task, default_decoder_factory)
}
fn ImageCacheTask_(resource_task: ResourceTask, +decoder_factory: DecoderFactory) -> ImageCacheTask {
pub fn ImageCacheTask_(resource_task: ResourceTask, +decoder_factory: DecoderFactory) -> ImageCacheTask {
// FIXME: Doing some dancing to avoid copying decoder_factory, our test
// version of which contains an uncopyable type which rust will currently
// copy unsoundly
@ -406,7 +400,7 @@ impl ImageCache {
// We don't have this image yet
match self.wait_map.find(copy url) {
Some(waiters) => {
vec::push(*waiters, response);
vec::push(&mut *waiters, response);
}
None => {
self.wait_map.insert(url, @mut ~[response]);

View file

@ -4,23 +4,19 @@ A task that takes a URL and streams back the binary data
*/
export ControlMsg, Load, Exit;
export ProgressMsg, Payload, Done;
export ResourceTask, ResourceManager, LoaderTaskFactory;
use comm::{Chan, Port};
use task::{spawn, spawn_listener};
use std::net::url;
use std::net::url::{Url, to_str};
enum ControlMsg {
pub enum ControlMsg {
/// Request the data associated with a particular URL
Load(Url, Chan<ProgressMsg>),
Exit
}
/// Messages sent in response to a `Load` message
enum ProgressMsg {
pub enum ProgressMsg {
/// Binary data - there may be multiple of these
Payload(~[u8]),
/// Indicates loading is complete, either successfully or not
@ -69,15 +65,15 @@ fn create_resource_task_with_loaders(+loaders: ~[(~str, LoaderTaskFactory)]) ->
}
}
struct ResourceManager {
pub struct ResourceManager {
from_client: Port<ControlMsg>,
/// Per-scheme resource loaders
loaders: ~[(~str, LoaderTaskFactory)],
}
fn ResourceManager(from_client: Port<ControlMsg>,
loaders: ~[(~str, LoaderTaskFactory)]) -> ResourceManager {
pub fn ResourceManager(from_client: Port<ControlMsg>,
loaders: ~[(~str, LoaderTaskFactory)]) -> ResourceManager {
ResourceManager {
from_client : from_client,
loaders : loaders,

View file

@ -21,123 +21,116 @@ extern mod http_client;
extern mod hubbub;
extern mod sharegl;
mod engine;
pub mod engine;
mod dom {
mod bindings {
mod document;
mod element;
mod utils;
mod node;
mod window;
pub mod dom {
pub mod bindings {
pub mod document;
pub mod element;
pub mod utils;
pub mod node;
pub mod window;
}
mod document;
mod element;
mod event;
mod node;
mod rcu;
mod window;
pub mod document;
pub mod element;
pub mod event;
pub mod node;
pub mod rcu;
pub mod window;
}
#[allow(non_implicitly_copyable_typarams)]
mod content {
mod content_task;
pub mod content {
pub mod content_task;
}
mod css {
mod lexer;
mod parser;
mod parser_util;
pub mod css {
pub mod lexer;
pub mod parser;
pub mod parser_util;
mod values;
mod styles;
mod resolve {
mod apply;
mod matching;
pub mod values;
pub mod styles;
pub mod resolve {
pub mod apply;
pub mod matching;
}
}
mod layout {
mod block;
mod box;
mod box_builder;
mod context;
mod debug;
mod display_list_builder;
mod flow;
mod layout_task;
mod inline;
mod root;
mod text;
mod traverse;
mod traverse_parallel;
pub mod layout {
pub mod block;
pub mod box;
pub mod box_builder;
pub mod context;
pub mod debug;
pub mod display_list_builder;
pub mod flow;
pub mod layout_task;
pub mod inline;
pub mod root;
pub mod text;
pub mod traverse;
pub mod traverse_parallel;
}
mod gfx {
mod geometry;
mod surface;
mod render_task;
mod compositor;
mod png_compositor;
mod display_list;
pub mod gfx {
pub mod geometry;
pub mod surface;
pub mod render_task;
pub mod compositor;
pub mod png_compositor;
pub mod display_list;
}
mod image {
mod base;
mod holder;
mod encode {
mod tga;
pub mod image {
pub mod base;
pub mod holder;
pub mod encode {
pub mod tga;
}
}
mod html {
mod lexer;
mod lexer_util;
mod hubbub_html_parser;
pub mod html {
pub mod lexer_util;
pub mod hubbub_html_parser;
}
mod platform {
mod base;
mod osmain;
pub mod platform {
pub mod base;
pub mod osmain;
}
mod text {
export glyph;
export text_run;
export font;
export font_cache;
export shaper;
mod font;
mod font_cache;
mod glyph;
mod native_font {
pub mod text {
pub mod font;
pub mod font_cache;
pub mod glyph;
pub mod native_font {
#[cfg(target_os = "macos")]
mod quartz_native_font;
pub mod quartz_native_font;
#[cfg(target_os = "linux")]
mod ft_native_font;
pub mod ft_native_font;
}
mod shaper;
mod text_run;
mod util;
pub mod shaper;
pub mod text_run;
pub mod util;
}
mod resource {
mod resource_task;
mod file_loader;
mod http_loader;
mod image_cache_task;
pub mod resource {
pub mod resource_task;
pub mod file_loader;
pub mod http_loader;
pub mod image_cache_task;
}
mod util {
mod color;
mod time;
mod tree;
mod url;
mod vec;
pub mod util {
pub mod tree;
pub mod color;
pub mod time;
pub mod url;
pub mod vec;
}
mod opts;
pub mod opts;
use servo_util = util;
use servo_text = text;

View file

@ -3,7 +3,9 @@ use option::swap_unwrap;
use platform::osmain;
use osmain::{OSMain, AddKeyHandler};
use opts::{Opts, Screen, Png};
use engine::{EngineTask, EngineProto};
use engine::{Engine, ExitMsg, LoadURLMsg};
use resource::image_cache_task::ImageCacheTask;
use resource::resource_task::ResourceTask;
use url_to_str = std::net::url::to_str;
use util::url::make_url;
@ -37,15 +39,16 @@ fn run_pipeline_screen(urls: ~[~str]) {
let (keypress_to_engine, keypress_from_osmain) = pipes::stream();
osmain.send(AddKeyHandler(keypress_to_engine));
// Create a serve instance
let mut engine_task = Some(EngineTask(osmain));
// Create a servo instance
let resource_task = ResourceTask();
let image_cache_task = ImageCacheTask(resource_task);
let engine = Engine(osmain, resource_task, image_cache_task);
let engine_chan = engine.start();
for urls.each |filename| {
let url = make_url(*filename, None);
#debug["master: Sending url `%s`", url_to_str(copy url)];
engine_task =
Some(EngineProto::client::LoadURL(swap_unwrap(&mut engine_task),
url));
#debug["master: Sending url `%s`", url_to_str(url)];
engine_chan.send(LoadURLMsg(url));
#debug["master: Waiting for keypress"];
match keypress_from_osmain.try_recv() {
@ -56,39 +59,39 @@ fn run_pipeline_screen(urls: ~[~str]) {
// Shut everything down
#debug["master: Shut down"];
let engine_task = EngineProto::client::Exit(option::unwrap(engine_task));
pipes::recv(engine_task);
let (exit_chan, exit_response_from_engine) = pipes::stream();
engine_chan.send(engine::ExitMsg(exit_chan));
exit_response_from_engine.recv();
osmain.send(osmain::Exit);
}
fn run_pipeline_png(-url: ~str, outfile: ~str) {
// Use a PNG encoder as the graphics compositor
use gfx::png_compositor;
use png_compositor::PngCompositor;
use io::{Writer, buffered_file_writer};
use resource::resource_task::ResourceTask;
use resource::image_cache_task::SyncImageCacheTask;
use engine::EngineTask_;
listen(|pngdata_from_compositor| {
let compositor = PngCompositor(pngdata_from_compositor);
let resource_task = ResourceTask();
// For the PNG pipeline we are using a synchronous image cache
// so that all requests will be fullfilled before the first
// render
// For the PNG pipeline we are using a synchronous image task so that all images will be
// fulfilled before the first paint.
let image_cache_task = SyncImageCacheTask(resource_task);
let engine_task = EngineTask_(compositor, resource_task, image_cache_task);
let engine_task = EngineProto::client::LoadURL(engine_task, make_url(url, None));
let engine_task = Engine(compositor, resource_task, image_cache_task);
let engine_chan = engine_task.start();
engine_chan.send(LoadURLMsg(make_url(url, None)));
match buffered_file_writer(&Path(outfile)) {
Ok(writer) => writer.write(pngdata_from_compositor.recv()),
Err(e) => fail e
}
let engine_task = EngineProto::client::Exit(engine_task);
pipes::recv(engine_task);
let (exit_chan, exit_response_from_engine) = pipes::stream();
engine_chan.send(engine::ExitMsg(exit_chan));
exit_response_from_engine.recv();
compositor.send(png_compositor::Exit);
})
}

View file

@ -50,15 +50,15 @@ fn create_font(lib: @FontCache, native_lib: &native::NativeFontCache) -> Result<
}
#[cfg(target_os = "linux")]
mod native {
pub mod native {
use ptr::{null, addr_of};
use azure::freetype;
use freetype::{FT_Library, FT_Error};
use freetype::bindgen::{FT_Init_FreeType, FT_Done_FreeType};
type NativeFontCache = FT_Library;
pub type NativeFontCache = FT_Library;
fn create_native_lib() -> NativeFontCache {
pub fn create_native_lib() -> NativeFontCache {
let lib: FT_Library = null();
let res = FT_Init_FreeType(addr_of(lib));
// FIXME: error handling
@ -66,22 +66,22 @@ mod native {
return lib;
}
fn destroy_native_lib(native_lib: &NativeFontCache) {
pub fn destroy_native_lib(native_lib: &NativeFontCache) {
assert native_lib.is_not_null();
FT_Done_FreeType(*native_lib);
}
}
#[cfg(target_os = "macos")]
mod native {
type NativeFontCache = ();
pub mod native {
pub type NativeFontCache = ();
fn create_native_lib() -> NativeFontCache { () }
fn destroy_native_lib(_native_lib: &NativeFontCache) { }
pub fn create_native_lib() -> NativeFontCache { () }
pub fn destroy_native_lib(_native_lib: &NativeFontCache) { }
}
#[test]
fn should_get_fonts() {
pub fn should_get_fonts() {
let lib = FontCache();
lib.get_font();
}

View file

@ -107,7 +107,7 @@ fn MissingGlyphs(glyphCount: u16) -> CompressedGlyph {
impl CompressedGlyph {
pure fn advance() -> GlyphStoreResult<au> {
match self.is_simple() {
true => Simple(au::from_int(((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) as int)),
true => Simple(num::from_int(((self.value & GLYPH_ADVANCE_MASK) >> GLYPH_ADVANCE_SHIFT) as int)),
false => Detailed(self.glyph_count())
}
}

View file

@ -5,34 +5,32 @@ needed by the text shaper as well as access to the underlying
font resources needed by the graphics layer to draw glyphs.
*/
export NativeFont, create;
use glyph::GlyphIndex;
use font_cache::native::NativeFontCache;
#[cfg(target_os = "macos")]
type NativeFont/& = quartz_native_font::QuartzNativeFont;
pub type NativeFont/& = quartz_native_font::QuartzNativeFont;
#[cfg(target_os = "linux")]
type NativeFont/& = ft_native_font::FreeTypeNativeFont;
pub type NativeFont/& = ft_native_font::FreeTypeNativeFont;
#[cfg(target_os = "macos")]
fn create(_native_lib: &NativeFontCache, buf: @~[u8]) -> Result<NativeFont, ()> {
pub fn create(_native_lib: &NativeFontCache, buf: @~[u8]) -> Result<NativeFont, ()> {
quartz_native_font::create(buf)
}
#[cfg(target_os = "linux")]
fn create(native_lib: &NativeFontCache, buf: @~[u8]) -> Result<NativeFont, ()> {
pub fn create(native_lib: &NativeFontCache, buf: @~[u8]) -> Result<NativeFont, ()> {
ft_native_font::create(native_lib, buf)
}
#[cfg(target_os = "macos")]
fn with_test_native_font(f: fn@(nf: &NativeFont)) {
pub fn with_test_native_font(f: fn@(nf: &NativeFont)) {
quartz_native_font::with_test_native_font(f);
}
#[cfg(target_os = "linux")]
fn with_test_native_font(f: fn@(nf: &NativeFont)) {
pub fn with_test_native_font(f: fn@(nf: &NativeFont)) {
ft_native_font::with_test_native_font(f);
}

View file

@ -84,7 +84,7 @@ impl FreeTypeNativeFont {
}
}
fn create(lib: &FT_Library, buf: @~[u8]) -> Result<FreeTypeNativeFont, ()> {
pub fn create(lib: &FT_Library, buf: @~[u8]) -> Result<FreeTypeNativeFont, ()> {
assert lib.is_not_null();
let face: FT_Face = null();
return vec_as_buf(*buf, |cbuf, _len| {

View file

@ -23,58 +23,58 @@ use coretext::coretext::CFRelease;
mod coretext {
type CTFontRef = *u8;
type UniChar = libc::c_ushort;
type CGGlyph = libc::c_ushort;
type CFIndex = libc::c_long;
pub type CTFontRef = *u8;
pub type UniChar = libc::c_ushort;
pub type CGGlyph = libc::c_ushort;
pub type CFIndex = libc::c_long;
type CTFontOrientation = u32;
const kCTFontDefaultOrientation: CTFontOrientation = 0;
const kCTFontHorizontalOrientation: CTFontOrientation = 1;
const kCTFontVerticalOrientation: CTFontOrientation = 2;
pub type CTFontOrientation = u32;
pub const kCTFontDefaultOrientation: CTFontOrientation = 0;
pub const kCTFontHorizontalOrientation: CTFontOrientation = 1;
pub const kCTFontVerticalOrientation: CTFontOrientation = 2;
type CGFloat = libc::c_double;
pub type CGFloat = libc::c_double;
struct CGSize {
pub struct CGSize {
width: CGFloat,
height: CGFloat,
}
struct CGPoint {
pub struct CGPoint {
x: CGFloat,
y: CGFloat,
}
struct CGRect {
pub struct CGRect {
origin: CGPoint,
size: CGSize
}
type CGAffineTransform = ();
type CTFontDescriptorRef = *u8;
pub type CGAffineTransform = ();
pub type CTFontDescriptorRef = *u8;
#[nolink]
#[link_args = "-framework ApplicationServices"]
extern mod coretext {
fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef;
fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool;
fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double;
pub extern mod coretext {
pub fn CTFontCreateWithGraphicsFont(graphicsFont: CGFontRef, size: CGFloat, matrix: *CGAffineTransform, attributes: CTFontDescriptorRef) -> CTFontRef;
pub fn CTFontGetGlyphsForCharacters(font: CTFontRef, characters: *UniChar, glyphs: *CGGlyph, count: CFIndex) -> bool;
pub fn CTFontGetAdvancesForGlyphs(font: CTFontRef, orientation: CTFontOrientation, glyphs: *CGGlyph, advances: *CGSize, count: CFIndex) -> libc::c_double;
/* metrics API */
fn CTFontGetAscent(font: CTFontRef) -> libc::c_float;
fn CTFontGetDescent(font: CTFontRef) -> libc::c_float;
fn CTFontGetLeading(font: CTFontRef) -> libc::c_float;
fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint;
fn CTFontGetUnderlinePosition(font: CTFontRef) -> libc::c_float;
fn CTFontGetUnderlineThickness(font: CTFontRef) -> libc::c_float;
fn CTFontGetXHeight(font: CTFontRef) -> libc::c_float;
fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect;
pub fn CTFontGetAscent(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetDescent(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetLeading(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetUnitsPerEm(font: CTFontRef) -> libc::c_uint;
pub fn CTFontGetUnderlinePosition(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetUnderlineThickness(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetXHeight(font: CTFontRef) -> libc::c_float;
pub fn CTFontGetBoundingBox(font: CTFontRef) -> CGRect;
fn CFRelease(font: CTFontRef);
pub fn CFRelease(font: CTFontRef);
}
}
struct QuartzNativeFont {
pub struct QuartzNativeFont {
fontprov: CGDataProviderRef,
cgfont: CGFontRef,
ctfont: CTFontRef,
@ -177,7 +177,7 @@ fn ctfont_from_cgfont(cgfont: CGFontRef) -> coretext::CTFontRef {
CTFontCreateWithGraphicsFont(cgfont, 21f as CGFloat, null(), null())
}
fn create(buf: @~[u8]) -> Result<QuartzNativeFont, ()> {
pub fn create(buf: @~[u8]) -> Result<QuartzNativeFont, ()> {
let fontprov = vec::as_imm_buf(*buf, |cbuf, len| {
CGDataProviderCreateWithData(
null(),
@ -196,7 +196,7 @@ fn create(buf: @~[u8]) -> Result<QuartzNativeFont, ()> {
}
fn with_test_native_font(f: fn@(nf: &NativeFont)) {
pub fn with_test_native_font(f: fn@(nf: &NativeFont)) {
use font::test_font_bin;
use unwrap_result = result::unwrap;

View file

@ -7,7 +7,7 @@ use libc::types::common::c99::int32_t;
use libc::{c_uint, c_int, c_void, c_char};
use font::Font;
use glyph::{Glyph, GlyphPos, GlyphIndex};
use ptr::{null, addr_of, offset};
use ptr::{null, to_unsafe_ptr, offset};
use gfx::geometry::au;
use geom::point::Point2D;
use font_cache::FontCache;
@ -57,7 +57,7 @@ fn shape_text(font: &Font, text: &str) -> ~[Glyph] unsafe {
let funcs = hb_font_funcs_create();
hb_font_funcs_set_glyph_func(funcs, glyph_func, null(), null());
hb_font_funcs_set_glyph_h_advance_func(funcs, glyph_h_advance_func, null(), null());
hb_font_set_funcs(hbfont, funcs, reinterpret_cast(&addr_of(*font)), null());
hb_font_set_funcs(hbfont, funcs, reinterpret_cast(&to_unsafe_ptr(font)), null());
let buffer = hb_buffer_create();
@ -74,10 +74,10 @@ fn shape_text(font: &Font, text: &str) -> ~[Glyph] unsafe {
hb_shape(hbfont, buffer, null(), 0 as c_uint);
let info_len = 0 as c_uint;
let info_ = hb_buffer_get_glyph_infos(buffer, addr_of(info_len));
let info_ = hb_buffer_get_glyph_infos(buffer, to_unsafe_ptr(&info_len));
assert info_.is_not_null();
let pos_len = 0 as c_uint;
let pos = hb_buffer_get_glyph_positions(buffer, addr_of(pos_len));
let pos = hb_buffer_get_glyph_positions(buffer, to_unsafe_ptr(&pos_len));
assert pos.is_not_null();
assert info_len == pos_len;
@ -163,6 +163,6 @@ fn should_get_glyph_h_advance() {
let font = lib.get_test_font();
let glyphs = shape_text(font, ~"firecracker");
let actual = glyphs.map(|g| g.pos.advance.x);
let expected = (~[6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7]).map(|a| au::from_px(a));
let expected = (~[6, 4, 7, 9, 8, 7, 10, 8, 9, 9, 7]).map(|a| au::from_px(*a));
assert expected == actual;
}

View file

@ -34,10 +34,10 @@ impl TextRun {
let mut candidate = copy curr_run;
if candidate.is_not_empty() {
str::push_str(candidate, " "); // FIXME: just inserting spaces between words can't be right
str::push_str(&mut candidate, " "); // FIXME: just inserting spaces between words can't be right
}
str::push_str(candidate, slice);
str::push_str(&mut candidate, slice);
let glyphs = shape_text(font, candidate);
let size = glyph_run_size(glyphs);
@ -82,8 +82,8 @@ fn glyph_run_size(glyphs: &[Glyph]) -> Size2D<au> {
let pen_start_y = height;
let pen_start = Point2D(pen_start_x, pen_start_y);
let pen_end = glyphs.foldl(pen_start, |cur, glyph| {
Point2D(cur.x.add(glyph.pos.offset.x).add(glyph.pos.advance.x),
cur.y.add(glyph.pos.offset.y).add(glyph.pos.advance.y))
Point2D(cur.x.add(&glyph.pos.offset.x).add(&glyph.pos.advance.x),
cur.y.add(&glyph.pos.offset.y).add(&glyph.pos.advance.y))
});
return Size2D(pen_end.x, pen_end.y);
}

View file

@ -9,7 +9,7 @@ use libc::types::os::arch::c95::c_double;
use css_colors::*;
use cmp::Eq;
enum Color = {red : u8, green : u8, blue : u8, alpha : float};
pub enum Color = {red : u8, green : u8, blue : u8, alpha : float};
impl Color : Eq {
pure fn eq(other: &Color) -> bool {
@ -21,15 +21,15 @@ impl Color : Eq {
}
}
fn rgba(r : u8, g : u8, b : u8, a : float) -> Color {
pub fn rgba(r : u8, g : u8, b : u8, a : float) -> Color {
Color({red : r, green : g, blue : b, alpha : a})
}
fn rgb(r : u8, g : u8, b : u8) -> Color {
pub fn rgb(r : u8, g : u8, b : u8) -> Color {
return rgba(r, g, b, 1.0);
}
fn hsla(h : float, s : float, l : float, a : float) -> Color {
pub fn hsla(h : float, s : float, l : float, a : float) -> Color {
// Algorithm for converting hsl to rbg taken from
// http://www.w3.org/TR/2003/CR-css3-color-20030514/#hsl-color
let m2 = if l <= 0.5 { l*(s + 1.0) } else { l + s - l*s };
@ -55,7 +55,7 @@ fn hsla(h : float, s : float, l : float, a : float) -> Color {
return rgba(r as u8, g as u8, b as u8, a);
}
fn hsl(h : float, s : float, l : float) -> Color {
pub fn hsl(h : float, s : float, l : float) -> Color {
return hsla(h, s, l, 1.0);
}

View file

@ -1,7 +1,7 @@
// Timing functions.
use std::time::precise_time_ns;
fn time(msg: ~str, callback: fn()) {
pub fn time(msg: ~str, callback: fn()) {
let start_time = precise_time_ns();
callback();
let end_time = precise_time_ns();

View file

@ -4,7 +4,7 @@ use core::vec;
//
// TODO: Use traits.
type Tree<T> = {
pub type Tree<T> = {
mut parent: Option<T>,
mut first_child: Option<T>,
mut last_child: Option<T>,
@ -12,15 +12,15 @@ type Tree<T> = {
mut next_sibling: Option<T>
};
trait ReadMethods<T> {
pub trait ReadMethods<T> {
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R;
}
trait WriteMethods<T> {
pub trait WriteMethods<T> {
fn with_tree_fields<R>(T, f: fn(Tree<T>) -> R) -> R;
}
fn each_child<T:Copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
pub fn each_child<T:Copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
let mut p = ops.with_tree_fields(node, |f| f.first_child);
loop {
match copy p {
@ -33,7 +33,7 @@ fn each_child<T:Copy,O:ReadMethods<T>>(ops: O, node: T, f: fn(T) -> bool) {
}
}
fn empty<T>() -> Tree<T> {
pub fn empty<T>() -> Tree<T> {
{mut parent: None,
mut first_child: None,
mut last_child: None,
@ -41,7 +41,7 @@ fn empty<T>() -> Tree<T> {
mut next_sibling: None}
}
fn add_child<T:Copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
pub fn add_child<T:Copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
ops.with_tree_fields(child, |child_tf| {
match child_tf.parent {
@ -72,7 +72,7 @@ fn add_child<T:Copy,O:WriteMethods<T>>(ops: O, parent: T, child: T) {
});
}
fn get_parent<T:Copy,O:ReadMethods<T>>(ops: O, node: T) -> Option<T> {
pub fn get_parent<T:Copy,O:ReadMethods<T>>(ops: O, node: T) -> Option<T> {
ops.with_tree_fields(node, |tf| tf.parent)
}

View file

@ -17,7 +17,7 @@ Create a URL object from a string. Does various helpful browsery things like
#[allow(non_implicitly_copyable_typarams)]
fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
let mut schm = url::get_scheme(str_url);
let str_url = if result::is_err(schm) {
let str_url = if result::is_err(&schm) {
if current_url.is_none() {
// If all we have is a filename, assume it's a local relative file
// and build an absolute path with the cwd

@ -1 +1 @@
Subproject commit 809ba9338f4ab67655786f6f05a60485c9cf56ef
Subproject commit 3914125fc669da3441590a7d5ab76a1b8ff0e218