mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Remove unneeded unsafe blocks.
This commit is contained in:
parent
4aec737c11
commit
868c7407a8
10 changed files with 276 additions and 301 deletions
|
@ -125,7 +125,7 @@ impl FontHandleMethods for FontHandle {
|
|||
if unsafe { (*self.face).style_flags & FT_STYLE_FLAG_BOLD == 0 } {
|
||||
default_weight
|
||||
} else {
|
||||
let os2 = unsafe { FT_Get_Sfnt_Table(self.face, ft_sfnt_os2) as *TT_OS2 };
|
||||
let os2 = FT_Get_Sfnt_Table(self.face, ft_sfnt_os2) as *TT_OS2;
|
||||
let valid = os2.is_not_null() && unsafe { (*os2).version != 0xffff };
|
||||
if valid {
|
||||
let weight = unsafe { (*os2).usWeightClass };
|
||||
|
@ -283,7 +283,7 @@ pub impl<'self> FontHandle {
|
|||
// face.size is a *c_void in the bindings, presumably to avoid
|
||||
// recursive structural types
|
||||
let size: &FT_SizeRec = unsafe { cast::transmute(&(*face.size)) };
|
||||
let metrics: &FT_Size_Metrics = unsafe { &((*size).metrics) };
|
||||
let metrics: &FT_Size_Metrics = &(*size).metrics;
|
||||
|
||||
let em_size = face.units_per_EM as float;
|
||||
let x_scale = (metrics.x_ppem as float) / em_size as float;
|
||||
|
|
|
@ -54,7 +54,7 @@ pub enum ImageResponseMsg {
|
|||
impl ImageResponseMsg {
|
||||
fn clone(&self) -> ImageResponseMsg {
|
||||
match *self {
|
||||
ImageReady(ref img) => ImageReady(unsafe { clone_arc(img) }),
|
||||
ImageReady(ref img) => ImageReady(clone_arc(img)),
|
||||
ImageNotReady => ImageNotReady,
|
||||
ImageFailed => ImageFailed
|
||||
}
|
||||
|
|
|
@ -74,21 +74,19 @@ pub struct ShapedGlyphEntry {
|
|||
|
||||
impl ShapedGlyphData {
|
||||
pub fn new(buffer: *hb_buffer_t) -> ShapedGlyphData {
|
||||
unsafe {
|
||||
let glyph_count = 0;
|
||||
let glyph_infos = hb_buffer_get_glyph_infos(buffer, &glyph_count);
|
||||
let glyph_count = glyph_count as uint;
|
||||
assert!(glyph_infos.is_not_null());
|
||||
let pos_count = 0;
|
||||
let pos_infos = hb_buffer_get_glyph_positions(buffer, &pos_count);
|
||||
assert!(pos_infos.is_not_null());
|
||||
assert!(glyph_count == pos_count as uint);
|
||||
let glyph_count = 0;
|
||||
let glyph_infos = hb_buffer_get_glyph_infos(buffer, &glyph_count);
|
||||
let glyph_count = glyph_count as uint;
|
||||
assert!(glyph_infos.is_not_null());
|
||||
let pos_count = 0;
|
||||
let pos_infos = hb_buffer_get_glyph_positions(buffer, &pos_count);
|
||||
assert!(pos_infos.is_not_null());
|
||||
assert!(glyph_count == pos_count as uint);
|
||||
|
||||
ShapedGlyphData {
|
||||
count: glyph_count,
|
||||
glyph_infos: glyph_infos,
|
||||
pos_infos: pos_infos,
|
||||
}
|
||||
ShapedGlyphData {
|
||||
count: glyph_count,
|
||||
glyph_infos: glyph_infos,
|
||||
pos_infos: pos_infos,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,35 +165,33 @@ impl Drop for Shaper {
|
|||
|
||||
impl Shaper {
|
||||
pub fn new(font: @mut Font) -> Shaper {
|
||||
unsafe {
|
||||
let font_ptr: *mut Font = &mut *font;
|
||||
let hb_face: *hb_face_t = hb_face_create_for_tables(get_font_table_func,
|
||||
font_ptr as *c_void,
|
||||
null());
|
||||
let hb_font: *hb_font_t = hb_font_create(hb_face);
|
||||
let font_ptr: *mut Font = &mut *font;
|
||||
let hb_face: *hb_face_t = hb_face_create_for_tables(get_font_table_func,
|
||||
font_ptr as *c_void,
|
||||
null());
|
||||
let hb_font: *hb_font_t = hb_font_create(hb_face);
|
||||
|
||||
// Set points-per-em. if zero, performs no hinting in that direction.
|
||||
let pt_size = font.style.pt_size;
|
||||
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
||||
// Set points-per-em. if zero, performs no hinting in that direction.
|
||||
let pt_size = font.style.pt_size;
|
||||
hb_font_set_ppem(hb_font, pt_size as c_uint, pt_size as c_uint);
|
||||
|
||||
// Set scaling. Note that this takes 16.16 fixed point.
|
||||
hb_font_set_scale(hb_font,
|
||||
Shaper::float_to_fixed(pt_size) as c_int,
|
||||
Shaper::float_to_fixed(pt_size) as c_int);
|
||||
// Set scaling. Note that this takes 16.16 fixed point.
|
||||
hb_font_set_scale(hb_font,
|
||||
Shaper::float_to_fixed(pt_size) as c_int,
|
||||
Shaper::float_to_fixed(pt_size) as c_int);
|
||||
|
||||
// configure static function callbacks.
|
||||
// NB. This funcs structure could be reused globally, as it never changes.
|
||||
let hb_funcs: *hb_font_funcs_t = hb_font_funcs_create();
|
||||
hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, null(), null());
|
||||
hb_font_funcs_set_glyph_h_advance_func(hb_funcs, glyph_h_advance_func, null(), null());
|
||||
hb_font_set_funcs(hb_font, hb_funcs, font_ptr as *c_void, null());
|
||||
// configure static function callbacks.
|
||||
// NB. This funcs structure could be reused globally, as it never changes.
|
||||
let hb_funcs: *hb_font_funcs_t = hb_font_funcs_create();
|
||||
hb_font_funcs_set_glyph_func(hb_funcs, glyph_func, null(), null());
|
||||
hb_font_funcs_set_glyph_h_advance_func(hb_funcs, glyph_h_advance_func, null(), null());
|
||||
hb_font_set_funcs(hb_font, hb_funcs, font_ptr as *c_void, null());
|
||||
|
||||
Shaper {
|
||||
font: font,
|
||||
hb_face: hb_face,
|
||||
hb_font: hb_font,
|
||||
hb_funcs: hb_funcs,
|
||||
}
|
||||
Shaper {
|
||||
font: font,
|
||||
hb_face: hb_face,
|
||||
hb_font: hb_font,
|
||||
hb_funcs: hb_funcs,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -156,9 +156,7 @@ pub fn Content(layout_task: LayoutTask,
|
|||
}
|
||||
|
||||
pub fn task_from_context(cx: *JSContext) -> *mut Content {
|
||||
unsafe {
|
||||
JS_GetContextPrivate(cx) as *mut Content
|
||||
}
|
||||
JS_GetContextPrivate(cx) as *mut Content
|
||||
}
|
||||
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
|
|
|
@ -202,10 +202,8 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj {
|
|||
|
||||
node.get_wrappercache().set_wrapper(obj.ptr);
|
||||
|
||||
unsafe {
|
||||
let raw_ptr = ptr::addr_of(node) as *libc::c_void;
|
||||
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
|
||||
}
|
||||
let raw_ptr = ptr::addr_of(node) as *libc::c_void;
|
||||
JS_SetReservedSlot(obj.ptr, DOM_OBJECT_SLOT as u32, RUST_PRIVATE_TO_JSVAL(raw_ptr));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -372,38 +372,36 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO
|
|||
constants: *ConstantSpec,
|
||||
staticMethods: *JSFunctionSpec,
|
||||
name: &str) -> *JSObject {
|
||||
unsafe {
|
||||
let mut proto = ptr::null();
|
||||
if protoClass.is_not_null() {
|
||||
proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||
protoClass, methods,
|
||||
properties, constants);
|
||||
if proto.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
||||
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||
RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
|
||||
let mut proto = ptr::null();
|
||||
if protoClass.is_not_null() {
|
||||
proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
||||
protoClass, methods,
|
||||
properties, constants);
|
||||
if proto.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
|
||||
let mut interface = ptr::null();
|
||||
if constructorClass.is_not_null() || constructor.is_not_null() {
|
||||
interface = do str::as_c_str(name) |s| {
|
||||
CreateInterfaceObject(cx, global, receiver, constructorClass,
|
||||
constructor, ctorNargs, proto,
|
||||
staticMethods, constants, s)
|
||||
};
|
||||
if interface.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
}
|
||||
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||
RUST_PRIVATE_TO_JSVAL(domClass as *libc::c_void));
|
||||
}
|
||||
|
||||
if protoClass.is_not_null() {
|
||||
proto
|
||||
} else {
|
||||
interface
|
||||
let mut interface = ptr::null();
|
||||
if constructorClass.is_not_null() || constructor.is_not_null() {
|
||||
interface = do str::as_c_str(name) |s| {
|
||||
CreateInterfaceObject(cx, global, receiver, constructorClass,
|
||||
constructor, ctorNargs, proto,
|
||||
staticMethods, constants, s)
|
||||
};
|
||||
if interface.is_null() {
|
||||
return ptr::null();
|
||||
}
|
||||
}
|
||||
|
||||
if protoClass.is_not_null() {
|
||||
proto
|
||||
} else {
|
||||
interface
|
||||
}
|
||||
}
|
||||
|
||||
fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
||||
|
@ -412,7 +410,6 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
|||
staticMethods: *JSFunctionSpec,
|
||||
constants: *ConstantSpec,
|
||||
name: *libc::c_char) -> *JSObject {
|
||||
unsafe {
|
||||
let constructor = if constructorClass.is_not_null() {
|
||||
let functionProto = JS_GetFunctionPrototype(cx, global);
|
||||
if functionProto.is_null() {
|
||||
|
@ -482,7 +479,6 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject,
|
|||
}
|
||||
|
||||
return constructor;
|
||||
}
|
||||
}
|
||||
|
||||
fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) -> bool {
|
||||
|
@ -506,11 +502,11 @@ fn DefineConstants(cx: *JSContext, obj: *JSObject, constants: *ConstantSpec) ->
|
|||
}
|
||||
|
||||
fn DefineMethods(cx: *JSContext, obj: *JSObject, methods: *JSFunctionSpec) -> bool {
|
||||
unsafe { JS_DefineFunctions(cx, obj, methods) != 0 }
|
||||
JS_DefineFunctions(cx, obj, methods) != 0
|
||||
}
|
||||
|
||||
fn DefineProperties(cx: *JSContext, obj: *JSObject, properties: *JSPropertySpec) -> bool {
|
||||
unsafe { JS_DefineProperties(cx, obj, properties) != 0 }
|
||||
JS_DefineProperties(cx, obj, properties) != 0
|
||||
}
|
||||
|
||||
fn CreateInterfacePrototypeObject(cx: *JSContext, global: *JSObject,
|
||||
|
@ -571,7 +567,7 @@ pub impl WrapperCache {
|
|||
}
|
||||
|
||||
fn set_wrapper(&mut self, wrapper: *JSObject) {
|
||||
unsafe { self.wrapper = wrapper; }
|
||||
self.wrapper = wrapper;
|
||||
}
|
||||
|
||||
fn new() -> WrapperCache {
|
||||
|
|
|
@ -335,18 +335,13 @@ impl DebugMethods for AbstractNode {
|
|||
debug!("%s", s);
|
||||
|
||||
// FIXME: this should have a pure version?
|
||||
unsafe {
|
||||
for self.each_child() |kid| {
|
||||
kid.dump_indent(indent + 1u)
|
||||
}
|
||||
for self.each_child() |kid| {
|
||||
kid.dump_indent(indent + 1u)
|
||||
}
|
||||
}
|
||||
|
||||
fn debug_str(&self) -> ~str {
|
||||
// Unsafe due to the call to type_id().
|
||||
unsafe {
|
||||
fmt!("%?", self.type_id())
|
||||
}
|
||||
fmt!("%?", self.type_id())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,217 +224,211 @@ pub fn parse_html(url: Url,
|
|||
|
||||
let url2 = url.clone(), url3 = url.clone();
|
||||
|
||||
unsafe {
|
||||
// Build the root node.
|
||||
let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
|
||||
let root = unsafe { Node::as_abstract_node(root) };
|
||||
debug!("created new node");
|
||||
let mut parser = hubbub::Parser("UTF-8", false);
|
||||
debug!("created parser");
|
||||
parser.set_document_node(root.to_hubbub_node());
|
||||
parser.enable_scripting(true);
|
||||
// Build the root node.
|
||||
let root = ~HTMLHtmlElement { parent: Element::new(HTMLHtmlElementTypeId, ~"html") };
|
||||
let root = unsafe { Node::as_abstract_node(root) };
|
||||
debug!("created new node");
|
||||
let mut parser = hubbub::Parser("UTF-8", false);
|
||||
debug!("created parser");
|
||||
parser.set_document_node(root.to_hubbub_node());
|
||||
parser.enable_scripting(true);
|
||||
|
||||
// Performs various actions necessary after appending has taken place. Currently, this
|
||||
// consists of processing inline stylesheets, but in the future it might perform
|
||||
// prefetching, etc.
|
||||
let css_chan2 = css_chan.clone();
|
||||
let append_hook: ~fn(AbstractNode, AbstractNode) = |parent_node, child_node| {
|
||||
if parent_node.is_style_element() && child_node.is_text() {
|
||||
debug!("found inline CSS stylesheet");
|
||||
let url = url::from_str("http://example.com/"); // FIXME
|
||||
let url_cell = Cell(url);
|
||||
do child_node.with_imm_text |text_node| {
|
||||
let data = text_node.text.to_str(); // FIXME: Bad copy.
|
||||
let provenance = InlineProvenance(result::unwrap(url_cell.take()), data);
|
||||
css_chan2.send(CSSTaskNewFile(provenance));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let (css_chan2, js_chan2) = (css_chan.clone(), js_chan.clone());
|
||||
parser.set_tree_handler(~hubbub::TreeHandler {
|
||||
create_comment: |data: ~str| {
|
||||
debug!("create comment");
|
||||
unsafe {
|
||||
Node::as_abstract_node(~Comment::new(data)).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_doctype: |doctype: ~hubbub::Doctype| {
|
||||
debug!("create doctype");
|
||||
// TODO: remove copying here by using struct pattern matching to
|
||||
// move all ~strs at once (blocked on Rust #3845, #3846, #3847)
|
||||
let public_id = match &doctype.public_id {
|
||||
&None => None,
|
||||
&Some(ref id) => Some(copy *id)
|
||||
};
|
||||
let system_id = match &doctype.system_id {
|
||||
&None => None,
|
||||
&Some(ref id) => Some(copy *id)
|
||||
};
|
||||
let node = ~Doctype::new(copy doctype.name,
|
||||
public_id,
|
||||
system_id,
|
||||
doctype.force_quirks);
|
||||
unsafe {
|
||||
Node::as_abstract_node(node).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_element: |tag: ~hubbub::Tag| {
|
||||
debug!("create element");
|
||||
// TODO: remove copying here by using struct pattern matching to
|
||||
// move all ~strs at once (blocked on Rust #3845, #3846, #3847)
|
||||
let node = build_element_from_tag(tag.name);
|
||||
|
||||
debug!("-- attach attrs");
|
||||
do node.as_mut_element |element| {
|
||||
for tag.attributes.each |attr| {
|
||||
element.attrs.push(Attr::new(copy attr.name, copy attr.value));
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn additional parsing, network loads, etc. from tag and attrs
|
||||
match node.type_id() {
|
||||
// Handle CSS style sheets from <link> elements
|
||||
ElementNodeTypeId(HTMLLinkElementTypeId) => {
|
||||
do node.with_imm_element |element| {
|
||||
match (element.get_attr(~"rel"), element.get_attr(~"href")) {
|
||||
(Some(rel), Some(href)) => {
|
||||
if rel == ~"stylesheet" {
|
||||
debug!("found CSS stylesheet: %s", href);
|
||||
let url = make_url(href.to_str(), Some(url2.clone()));
|
||||
css_chan2.send(CSSTaskNewFile(UrlProvenance(url)));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
},
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
do node.with_mut_image_element |image_element| {
|
||||
let src_opt = image_element.parent.get_attr(~"src").map(|x| x.to_str());
|
||||
match src_opt {
|
||||
None => {}
|
||||
Some(src) => {
|
||||
let img_url = make_url(src, Some(url2.clone()));
|
||||
image_element.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.
|
||||
image_cache_task.send(image_cache_task::Prefetch(img_url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO (Issue #86): handle inline styles ('style' attr)
|
||||
_ => {}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
node.to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_text: |data: ~str| {
|
||||
debug!("create text");
|
||||
unsafe {
|
||||
Node::as_abstract_node(~Text::new(data)).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
ref_node: |_| {},
|
||||
unref_node: |_| {},
|
||||
append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| {
|
||||
unsafe {
|
||||
debug!("append child %x %x", cast::transmute(parent), cast::transmute(child));
|
||||
let parent: AbstractNode = NodeWrapping::from_hubbub_node(parent);
|
||||
let child: AbstractNode = NodeWrapping::from_hubbub_node(child);
|
||||
parent.append_child(child);
|
||||
append_hook(parent, child);
|
||||
}
|
||||
child
|
||||
},
|
||||
insert_before: |_parent, _child| {
|
||||
debug!("insert before");
|
||||
0u
|
||||
},
|
||||
remove_child: |_parent, _child| {
|
||||
debug!("remove child");
|
||||
0u
|
||||
},
|
||||
clone_node: |_node, deep| {
|
||||
debug!("clone node");
|
||||
unsafe {
|
||||
if deep { error!("-- deep clone unimplemented"); }
|
||||
fail!(~"clone node unimplemented")
|
||||
}
|
||||
},
|
||||
reparent_children: |_node, _new_parent| {
|
||||
debug!("reparent children");
|
||||
0u
|
||||
},
|
||||
get_parent: |_node, _element_only| {
|
||||
debug!("get parent");
|
||||
0u
|
||||
},
|
||||
has_children: |_node| {
|
||||
debug!("has children");
|
||||
false
|
||||
},
|
||||
form_associate: |_form, _node| {
|
||||
debug!("form associate");
|
||||
},
|
||||
add_attributes: |_node, _attributes| {
|
||||
debug!("add attributes");
|
||||
},
|
||||
set_quirks_mode: |_mode| {
|
||||
debug!("set quirks mode");
|
||||
},
|
||||
encoding_change: |_encname| {
|
||||
debug!("encoding change");
|
||||
},
|
||||
complete_script: |script| {
|
||||
// A little function for holding this lint attr
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn complete_script(script: hubbub::NodeDataPtr,
|
||||
url: Url,
|
||||
js_chan: SharedChan<JSMessage>) {
|
||||
unsafe {
|
||||
let script: AbstractNode = NodeWrapping::from_hubbub_node(script);
|
||||
do script.with_imm_element |script| {
|
||||
match script.get_attr(~"src") {
|
||||
Some(src) => {
|
||||
debug!("found script: %s", src);
|
||||
let new_url = make_url(src.to_str(), Some(url.clone()));
|
||||
js_chan.send(JSTaskNewFile(new_url));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
complete_script(script, url3.clone(), js_chan2.clone());
|
||||
debug!("complete script");
|
||||
}
|
||||
});
|
||||
debug!("set tree handler");
|
||||
|
||||
let (input_port, input_chan) = comm::stream();
|
||||
resource_task.send(Load(url.clone(), input_chan));
|
||||
debug!("loaded page");
|
||||
loop {
|
||||
match input_port.recv() {
|
||||
Payload(data) => {
|
||||
debug!("received data");
|
||||
parser.parse_chunk(data);
|
||||
}
|
||||
Done(*) => {
|
||||
break;
|
||||
}
|
||||
// Performs various actions necessary after appending has taken place. Currently, this
|
||||
// consists of processing inline stylesheets, but in the future it might perform
|
||||
// prefetching, etc.
|
||||
let css_chan2 = css_chan.clone();
|
||||
let append_hook: ~fn(AbstractNode, AbstractNode) = |parent_node, child_node| {
|
||||
if parent_node.is_style_element() && child_node.is_text() {
|
||||
debug!("found inline CSS stylesheet");
|
||||
let url = url::from_str("http://example.com/"); // FIXME
|
||||
let url_cell = Cell(url);
|
||||
do child_node.with_imm_text |text_node| {
|
||||
let data = text_node.text.to_str(); // FIXME: Bad copy.
|
||||
let provenance = InlineProvenance(result::unwrap(url_cell.take()), data);
|
||||
css_chan2.send(CSSTaskNewFile(provenance));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
css_chan.send(CSSTaskExit);
|
||||
js_chan.send(JSTaskExit);
|
||||
let (css_chan2, js_chan2) = (css_chan.clone(), js_chan.clone());
|
||||
parser.set_tree_handler(~hubbub::TreeHandler {
|
||||
create_comment: |data: ~str| {
|
||||
debug!("create comment");
|
||||
unsafe {
|
||||
Node::as_abstract_node(~Comment::new(data)).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_doctype: |doctype: ~hubbub::Doctype| {
|
||||
debug!("create doctype");
|
||||
// TODO: remove copying here by using struct pattern matching to
|
||||
// move all ~strs at once (blocked on Rust #3845, #3846, #3847)
|
||||
let public_id = match &doctype.public_id {
|
||||
&None => None,
|
||||
&Some(ref id) => Some(copy *id)
|
||||
};
|
||||
let system_id = match &doctype.system_id {
|
||||
&None => None,
|
||||
&Some(ref id) => Some(copy *id)
|
||||
};
|
||||
let node = ~Doctype::new(copy doctype.name,
|
||||
public_id,
|
||||
system_id,
|
||||
doctype.force_quirks);
|
||||
unsafe {
|
||||
Node::as_abstract_node(node).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_element: |tag: ~hubbub::Tag| {
|
||||
debug!("create element");
|
||||
// TODO: remove copying here by using struct pattern matching to
|
||||
// move all ~strs at once (blocked on Rust #3845, #3846, #3847)
|
||||
let node = build_element_from_tag(tag.name);
|
||||
|
||||
return HtmlParserResult { root: root, style_port: css_port, js_port: js_port };
|
||||
debug!("-- attach attrs");
|
||||
do node.as_mut_element |element| {
|
||||
for tag.attributes.each |attr| {
|
||||
element.attrs.push(Attr::new(copy attr.name, copy attr.value));
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn additional parsing, network loads, etc. from tag and attrs
|
||||
match node.type_id() {
|
||||
// Handle CSS style sheets from <link> elements
|
||||
ElementNodeTypeId(HTMLLinkElementTypeId) => {
|
||||
do node.with_imm_element |element| {
|
||||
match (element.get_attr(~"rel"), element.get_attr(~"href")) {
|
||||
(Some(rel), Some(href)) => {
|
||||
if rel == ~"stylesheet" {
|
||||
debug!("found CSS stylesheet: %s", href);
|
||||
let url = make_url(href.to_str(), Some(url2.clone()));
|
||||
css_chan2.send(CSSTaskNewFile(UrlProvenance(url)));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
},
|
||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||
do node.with_mut_image_element |image_element| {
|
||||
let src_opt = image_element.parent.get_attr(~"src").map(|x| x.to_str());
|
||||
match src_opt {
|
||||
None => {}
|
||||
Some(src) => {
|
||||
let img_url = make_url(src, Some(url2.clone()));
|
||||
image_element.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.
|
||||
image_cache_task.send(image_cache_task::Prefetch(img_url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO (Issue #86): handle inline styles ('style' attr)
|
||||
_ => {}
|
||||
}
|
||||
|
||||
node.to_hubbub_node()
|
||||
},
|
||||
create_text: |data: ~str| {
|
||||
debug!("create text");
|
||||
unsafe {
|
||||
Node::as_abstract_node(~Text::new(data)).to_hubbub_node()
|
||||
}
|
||||
},
|
||||
ref_node: |_| {},
|
||||
unref_node: |_| {},
|
||||
append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| {
|
||||
unsafe {
|
||||
debug!("append child %x %x", cast::transmute(parent), cast::transmute(child));
|
||||
let parent: AbstractNode = NodeWrapping::from_hubbub_node(parent);
|
||||
let child: AbstractNode = NodeWrapping::from_hubbub_node(child);
|
||||
parent.append_child(child);
|
||||
append_hook(parent, child);
|
||||
}
|
||||
child
|
||||
},
|
||||
insert_before: |_parent, _child| {
|
||||
debug!("insert before");
|
||||
0u
|
||||
},
|
||||
remove_child: |_parent, _child| {
|
||||
debug!("remove child");
|
||||
0u
|
||||
},
|
||||
clone_node: |_node, deep| {
|
||||
debug!("clone node");
|
||||
if deep { error!("-- deep clone unimplemented"); }
|
||||
fail!(~"clone node unimplemented")
|
||||
},
|
||||
reparent_children: |_node, _new_parent| {
|
||||
debug!("reparent children");
|
||||
0u
|
||||
},
|
||||
get_parent: |_node, _element_only| {
|
||||
debug!("get parent");
|
||||
0u
|
||||
},
|
||||
has_children: |_node| {
|
||||
debug!("has children");
|
||||
false
|
||||
},
|
||||
form_associate: |_form, _node| {
|
||||
debug!("form associate");
|
||||
},
|
||||
add_attributes: |_node, _attributes| {
|
||||
debug!("add attributes");
|
||||
},
|
||||
set_quirks_mode: |_mode| {
|
||||
debug!("set quirks mode");
|
||||
},
|
||||
encoding_change: |_encname| {
|
||||
debug!("encoding change");
|
||||
},
|
||||
complete_script: |script| {
|
||||
// A little function for holding this lint attr
|
||||
#[allow(non_implicitly_copyable_typarams)]
|
||||
fn complete_script(script: hubbub::NodeDataPtr,
|
||||
url: Url,
|
||||
js_chan: SharedChan<JSMessage>) {
|
||||
unsafe {
|
||||
let script: AbstractNode = NodeWrapping::from_hubbub_node(script);
|
||||
do script.with_imm_element |script| {
|
||||
match script.get_attr(~"src") {
|
||||
Some(src) => {
|
||||
debug!("found script: %s", src);
|
||||
let new_url = make_url(src.to_str(), Some(url.clone()));
|
||||
js_chan.send(JSTaskNewFile(new_url));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
complete_script(script, url3.clone(), js_chan2.clone());
|
||||
debug!("complete script");
|
||||
}
|
||||
});
|
||||
debug!("set tree handler");
|
||||
|
||||
let (input_port, input_chan) = comm::stream();
|
||||
resource_task.send(Load(url.clone(), input_chan));
|
||||
debug!("loaded page");
|
||||
loop {
|
||||
match input_port.recv() {
|
||||
Payload(data) => {
|
||||
debug!("received data");
|
||||
parser.parse_chunk(data);
|
||||
}
|
||||
Done(*) => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
css_chan.send(CSSTaskExit);
|
||||
js_chan.send(JSTaskExit);
|
||||
|
||||
return HtmlParserResult { root: root, style_port: css_port, js_port: js_port };
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ priv fn simulate_UA_display_rules(node: AbstractNode) -> CSSDisplay {
|
|||
|
||||
impl BoxGenerator {
|
||||
fn new(flow: @mut FlowContext) -> BoxGenerator {
|
||||
unsafe { debug!("Creating box generator for flow: %s", flow.debug_str()); }
|
||||
debug!("Creating box generator for flow: %s", flow.debug_str());
|
||||
BoxGenerator {
|
||||
flow: flow,
|
||||
range_stack: ~[]
|
||||
|
@ -208,7 +208,7 @@ struct BuilderContext {
|
|||
|
||||
impl BuilderContext {
|
||||
fn new(collector: @mut BoxGenerator) -> BuilderContext {
|
||||
unsafe { debug!("Creating new BuilderContext for flow: %s", collector.flow.debug_str()); }
|
||||
debug!("Creating new BuilderContext for flow: %s", collector.flow.debug_str());
|
||||
BuilderContext {
|
||||
default_collector: collector,
|
||||
inline_collector: None,
|
||||
|
|
|
@ -279,10 +279,8 @@ impl BoxedMutDebugMethods for FlowContext {
|
|||
debug!("%s", s);
|
||||
|
||||
// FIXME: this should have a pure/const version?
|
||||
unsafe {
|
||||
for FlowTree.each_child(self) |child| {
|
||||
child.dump_indent(indent + 1u)
|
||||
}
|
||||
for FlowTree.each_child(self) |child| {
|
||||
child.dump_indent(indent + 1u)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue