auto merge of #563 : metajack/servo/glfw, r=metajack

This code replaces glut with glfw. The motivation here is address the GPU driver bugs on Linux when using multiple `Display *` pointers with shared GL contexts instead of a single common one. GLFW has native access methods which provide access to its `Display *`, which appears to be unique among all the similar toolkits.

Details:
- Adds glfw and glfw-rs to the build
- Removes GLUT code and replaces it with GLFW versions
- Fixes hard coded initial window values
- Fixes clean targets
- Event loop doesn't block on windowing events anymore
This commit is contained in:
bors-servo 2013-07-10 06:57:36 -07:00
commit 34a35054e9
85 changed files with 671 additions and 732 deletions

6
.gitmodules vendored
View file

@ -94,3 +94,9 @@
[submodule "src/support/nss/nspr"]
path = src/support/nss/nspr
url = git://github.com/mozilla-servo/nspr.git
[submodule "src/support/glfw/glfw"]
path = src/support/glfw/glfw
url = https://github.com/mozilla-servo/glfw.git
[submodule "src/support/glfw/glfw-rs"]
path = src/support/glfw/glfw-rs
url = https://github.com/mozilla-servo/glfw-rs.git

View file

@ -83,6 +83,7 @@ $(CFG_RUSTC):
clean-rust:
$(MAKE) -C "$(CFG_BUILD_DIR)src/compiler/rust" CFG_RUSTC_FLAGS="" RUSTFLAGS="" clean
else
$(CFG_RUSTC):
@ -90,6 +91,10 @@ clean-rust:
endif
src/compiler/rust-auto-clean-stamp: $(S)src/compiler/rust-auto-clean-trigger
$(Q)$(MAKE) clean-rust
touch $@
rust: $(CFG_RUSTC)
# Strip off submodule paths to determine "raw" submodule names.
@ -222,7 +227,7 @@ include $(S)mk/clean.mk
.DEFAULT_GOAL := all
.PHONY: all
all: servo package
all: src/compiler/rust-auto-clean-stamp servo package
# Servo helper libraries

2
configure vendored
View file

@ -403,6 +403,8 @@ CFG_SUBMODULES="\
support/css/rust-css \
support/geom/rust-geom \
support/glut/rust-glut \
support/glfw/glfw \
support/glfw/glfw-rs \
support/harfbuzz/rust-harfbuzz \
support/http-client/rust-http-client \
support/hubbub/libhubbub \

View file

@ -26,19 +26,19 @@ clean-fast: $(DEPS_CLEAN_TARGETS_FAST) clean-servo
$(Q)echo "$(filter-out $(SLOW_BUILDS),$(DEPS_CLEAN_ALL))"
clean-util:
cd $(B)/src/components/util/ && rm -rf libutil*.dylib $(DONE_util)
cd $(B)/src/components/util/ && rm -rf libutil*.{dylib,so} $(DONE_util)
clean-msg:
cd $(B)/src/components/msg/ && rm -rf libmsg*.dylib $(DONE_msg)
cd $(B)/src/components/msg/ && rm -rf libmsg*.{dylib,so} $(DONE_msg)
clean-net:
cd $(B)/src/components/net/ && rm -rf libnet*.dylib $(DONE_net)
cd $(B)/src/components/net/ && rm -rf libnet*.{dylib,so} $(DONE_net)
clean-gfx:
cd $(B)/src/components/gfx/ && rm -rf libgfx*.dylib $(DONE_gfx)
cd $(B)/src/components/gfx/ && rm -rf libgfx*.{dylib,so} $(DONE_gfx)
clean-script:
cd $(B)/src/components/script/ && rm -rf libscript*.dylib $(DONE_script)
cd $(B)/src/components/script/ && rm -rf libscript*.{dylib,so} $(DONE_script)
clean-servo: clean-gfx clean-util clean-net clean-script
clean-servo: clean-gfx clean-util clean-net clean-script clean-msg
rm -f servo servo-test

View file

@ -29,6 +29,7 @@ NATIVE_BUILDS += \
skia \
nss \
nspr \
glfw \
$(NULL)
# NOTE: the make magic can only compute transitive build dependencies,
@ -40,18 +41,22 @@ NATIVE_BUILDS += \
DEPS_rust-azure += \
rust-opengles \
rust-layers \
rust-glut \
rust-geom \
glfw-rs \
glfw \
skia \
$(NULL)
DEPS_glfw-rs += \
glfw \
$(NULL)
DEPS_rust-glut += \
rust-opengles \
$(NULL)
DEPS_rust-layers += \
rust-geom \
rust-glut \
rust-opengles \
$(NULL)

@ -1 +1 @@
Subproject commit f348465283d6cd85b69bcdc1711d14985d154c39
Subproject commit 5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46

View file

@ -0,0 +1,4 @@
# If this file is modified, then rust will be forcibly cleaned and then rebuilt.
# The actual contents of this file do not matter, but to trigger a change on the
# build bots then the contents should be changed so git updates the mtime.
2013-07-09

View file

@ -48,7 +48,7 @@ impl<E> DisplayList<E> {
/// Draws the display list into the given render context.
pub fn draw_into_context(&self, render_context: &RenderContext) {
debug!("Beginning display list.");
for self.list.each |item| {
for self.list.iter().advance |item| {
// FIXME(Issue #150): crashes
//debug!("drawing %?", *item);
item.draw_into_context(render_context)

View file

@ -389,7 +389,7 @@ impl Font {
let mut origin = copy baseline_origin;
let mut azglyphs = ~[];
vec::reserve(&mut azglyphs, range.length());
azglyphs.reserve(range.length());
for run.iter_slices_for_range(range) |glyphs, _offset, slice_range| {
for glyphs.iter_glyphs_for_char_range(slice_range) |_i, glyph| {
@ -433,7 +433,7 @@ impl Font {
let mut advance = Au(0);
for run.iter_slices_for_range(range) |glyphs, _offset, slice_range| {
for glyphs.iter_glyphs_for_char_range(slice_range) |_i, glyph| {
advance += glyph.advance_();
advance = advance + glyph.advance_();
}
}
RunMetrics::new(advance, self.metrics.ascent, self.metrics.descent)
@ -445,7 +445,7 @@ impl Font {
-> RunMetrics {
let mut advance = Au(0);
for glyphs.iter_glyphs_for_char_range(slice_range) |_i, glyph| {
advance += glyph.advance_();
advance = advance + glyph.advance_();
}
RunMetrics::new(advance, self.metrics.ascent, self.metrics.descent)
}

View file

@ -126,7 +126,7 @@ impl FontFamily {
// TODO(Issue #190): if not in the fast path above, do
// expensive matching of weights, etc.
let this: &mut FontFamily = self; // FIXME: borrow checker workaround
for this.entries.each |entry| {
for this.entries.iter().advance |entry| {
if (style.weight.is_bold() == entry.is_bold()) &&
(style.italic == entry.is_italic()) {

View file

@ -28,7 +28,6 @@ use freetype::tt_os2::TT_OS2;
use std::cast;
use std::ptr;
use std::str;
use std::vec;
fn float_to_fixed_ft(f: float) -> i32 {
float_to_fixed(6, f)
@ -63,7 +62,7 @@ pub struct FontHandle {
#[unsafe_destructor]
impl Drop for FontHandle {
fn finalize(&self) {
fn drop(&self) {
assert!(self.face.is_not_null());
unsafe {
if !FT_Done_Face(self.face).succeeded() {
@ -81,7 +80,7 @@ impl FontHandleMethods for FontHandle {
let ft_ctx: FT_Library = fctx.ctx.ctx;
if ft_ctx.is_null() { return Err(()); }
let face_result = do vec::as_imm_buf(buf) |bytes: *u8, len: uint| {
let face_result = do buf.as_imm_buf |bytes: *u8, len: uint| {
create_face_from_buffer(ft_ctx, bytes, len, style.pt_size)
};

View file

@ -17,7 +17,7 @@ struct FreeTypeLibraryHandle {
}
impl Drop for FreeTypeLibraryHandle {
fn finalize(&self) {
fn drop(&self) {
assert!(self.ctx.is_not_null());
unsafe {
FT_Done_FreeType(self.ctx);

View file

@ -139,7 +139,7 @@ struct AutoPattern {
}
impl Drop for AutoPattern {
fn finalize(&self) {
fn drop(&self) {
unsafe {
FcPatternDestroy(self.pattern);
}

View file

@ -29,7 +29,6 @@ use core_text::font_descriptor::{kCTFontDefaultOrientation};
use core_text;
use std::ptr;
use std::vec;
pub struct FontTable {
data: CFData,
@ -37,7 +36,7 @@ pub struct FontTable {
// Noncopyable.
impl Drop for FontTable {
fn finalize(&self) {}
fn drop(&self) {}
}
impl FontTable {
@ -80,9 +79,9 @@ impl FontHandle {
impl FontHandleMethods for FontHandle {
fn new_from_buffer(_: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle)
-> Result<FontHandle, ()> {
let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| {
let fontprov : CGDataProvider = do buf.as_imm_buf |cbuf, len| {
core_graphics::data_provider::new_from_buffer(cbuf, len)
});
};
let cgfont = core_graphics::font::create_with_data_provider(&fontprov);
let ctfont = core_text::font::new_from_CGFont(&cgfont, style.pt_size);

View file

@ -75,7 +75,7 @@ priv struct RenderTask<C> {
last_paint_msg: Option<(arc::ARC<LayerBufferSet>, Size2D<uint>)>,
}
impl<C: RenderListener + Owned> RenderTask<C> {
impl<C: RenderListener + Send> RenderTask<C> {
pub fn create(id: uint,
port: Port<Msg>,
compositor: C,

View file

@ -347,7 +347,7 @@ impl<'self> DetailedGlyphStore {
// FIXME: Is this right? --pcwalton
// TODO: should fix this somewhere else
if count == 0 {
return vec::slice(self.detail_buffer, 0, 0);
return self.detail_buffer.slice(0, 0);
}
assert!((count as uint) <= self.detail_buffer.len());
@ -365,7 +365,7 @@ impl<'self> DetailedGlyphStore {
Some(i) => {
assert!(i + (count as uint) <= self.detail_buffer.len());
// return a slice into the buffer
vec::slice(self.detail_buffer, i, i + count as uint)
self.detail_buffer.slice(i, i + count as uint)
}
}
}
@ -635,7 +635,8 @@ impl<'self> GlyphStore {
}
for range.eachi |i| {
if !self.iter_glyphs_for_char_index(i, callback) {
// FIXME: Work around rust#2202. We should be able to pass the callback directly.
if !self.iter_glyphs_for_char_index(i, |a, b| callback(a, b)) {
break
}
}
@ -643,9 +644,10 @@ impl<'self> GlyphStore {
true
}
pub fn iter_all_glyphs(&'self self, cb: &fn(uint, &GlyphInfo<'self>) -> bool) -> bool {
pub fn iter_all_glyphs(&'self self, callback: &fn(uint, &GlyphInfo<'self>) -> bool) -> bool {
for uint::range(0, self.entry_buffer.len()) |i| {
if !self.iter_glyphs_for_char_index(i, cb) {
// FIXME: Work around rust#2202. We should be able to pass the callback directly.
if !self.iter_glyphs_for_char_index(i, |a, b| callback(a, b)) {
break;
}
}

View file

@ -118,7 +118,7 @@ impl ShapedGlyphData {
} else {
// adjust the pen..
if y_advance > Au(0) {
*y_pos -= y_advance;
*y_pos = *y_pos - y_advance;
}
Some(Point2D(x_offset, *y_pos - y_offset))
@ -143,7 +143,7 @@ pub struct Shaper {
#[unsafe_destructor]
impl Drop for Shaper {
fn finalize(&self) {
fn drop(&self) {
unsafe {
assert!(self.hb_face.is_not_null());
hb_face_destroy(self.hb_face);

View file

@ -123,7 +123,7 @@ impl<'self> TextRun {
}
pub fn char_len(&self) -> uint {
do self.glyphs.foldl(0u) |len, slice_glyphs| {
do self.glyphs.iter().fold(0u) |len, slice_glyphs| {
len + slice_glyphs.get().char_len()
}
}
@ -161,7 +161,7 @@ impl<'self> TextRun {
f: &fn(&GlyphStore, uint, &Range) -> bool)
-> bool {
let mut offset = 0;
for self.glyphs.each |slice_glyphs| {
for self.glyphs.iter().advance |slice_glyphs| {
// Determine the range of this slice that we need.
let slice_range = Range::new(offset, slice_glyphs.get().char_len());
let mut char_range = range.intersect(&slice_range);

View file

@ -23,6 +23,8 @@ use std::comm;
use std::comm::{Chan, SharedChan, Port};
use std::num::Orderable;
use std::task;
use extra::uv_global_loop;
use extra::timer;
use geom::matrix::identity;
use geom::point::Point2D;
use geom::size::Size2D;
@ -80,15 +82,24 @@ impl CompositorChan {
chan: SharedChan::new(chan),
}
}
pub fn send(&self, msg: Msg) {
self.chan.send(msg);
}
pub fn get_size(&self) -> Size2D<int> {
let (port, chan) = comm::stream();
self.chan.send(GetSize(chan));
port.recv()
}
}
/// Messages to the compositor.
pub enum Msg {
/// Requests that the compositor shut down.
Exit,
/// Requests the window size
GetSize(Chan<Size2D<int>>),
/// Requests the compositors GL context.
GetGLContext(Chan<AzGLContext>),
/// Requests that the compositor paint the given layer buffer set for the given page size.
@ -169,15 +180,18 @@ impl CompositorTask {
// list. This is only here because we don't have that logic in the renderer yet.
let context = rendergl::init_render_context();
let root_layer = @mut ContainerLayer();
let scene = @mut Scene(ContainerLayerKind(root_layer), Size2D(800.0f32, 600.0), identity());
let window_size = window.size();
let scene = @mut Scene(ContainerLayerKind(root_layer), window_size, identity());
let done = @mut false;
let recomposite = @mut false;
// FIXME: This should not be a separate offset applied after the fact but rather should be
// applied to the layers themselves on a per-layer basis. However, this won't work until scroll
// positions are sent to content.
let world_offset = @mut Point2D(0f32, 0f32);
let page_size = @mut Size2D(0f32, 0f32);
let window_size = @mut Size2D(800, 600);
let window_size = @mut Size2D(window_size.width as int,
window_size.height as int);
// Keeps track of the current zoom factor
let world_zoom = @mut 1f32;
@ -271,6 +285,11 @@ impl CompositorTask {
response_chan.send(CompositorAck(new_pipeline_id));
}
GetSize(chan) => {
let size = window.size();
chan.send(Size2D(size.width as int, size.height as int));
}
GetGLContext(chan) => chan.send(current_gl_context()),
Paint(id, new_layer_buffer_set, new_size) => {
@ -343,14 +362,14 @@ impl CompositorTask {
// TODO: Recycle the old buffers; send them back to the renderer to reuse if
// it wishes.
window.set_needs_display();
*recomposite = true;
}
}
}
};
let profiler_chan = self.profiler_chan.clone();
do window.set_composite_callback {
let composite = || {
do profile(time::CompositingCategory, profiler_chan.clone()) {
debug!("compositor: compositing");
// Adjust the layer dimensions as necessary to correspond to the size of the window.
@ -361,7 +380,7 @@ impl CompositorTask {
}
window.present();
}
};
// When the user scrolls, move the layer around.
do window.set_scroll_callback |delta| {
@ -390,7 +409,7 @@ impl CompositorTask {
root_layer.common.set_transform(scroll_transform);
window.set_needs_display()
*recomposite = true;
}
@ -429,8 +448,7 @@ impl CompositorTask {
0.0);
root_layer.common.set_transform(zoom_transform);
window.set_needs_display()
*recomposite = true;
}
// Enter the main event loop.
@ -440,6 +458,13 @@ impl CompositorTask {
// Check for messages coming from the windowing system.
window.check_loop();
if *recomposite {
*recomposite = false;
composite();
}
timer::sleep(&uv_global_loop::get(), 100);
}
self.shutdown_chan.send(())

View file

@ -205,7 +205,7 @@ impl Constellation {
}
ExitMsg(sender) => {
for self.pipelines.each |_, pipeline| {
for self.pipelines.iter().advance |(_, pipeline)| {
pipeline.exit();
}
self.image_cache_task.exit();
@ -240,7 +240,7 @@ impl Constellation {
// Don't navigate on Navigate type, because that is handled by forward/back
match pipeline.navigation_type.get() {
constellation_msg::Load => {
let evicted = self.navigation_context.navigate(id);
let _evicted = self.navigation_context.navigate(id);
/* FIXME(tkuehn): the following code causes a segfault
for evicted.iter().advance |id| {
self.pipelines.get(id).exit();

View file

@ -254,9 +254,9 @@ impl BlockFlowData {
for self.box.iter().advance |&box| {
do box.with_model |model| {
top_offset = model.margin.top + model.border.top + model.padding.top;
cur_y += top_offset;
cur_y = cur_y + top_offset;
left_offset = model.offset();
}
};
}
// TODO(eatkinson): the translation here is probably
@ -284,8 +284,8 @@ impl BlockFlowData {
for BlockFlow(self).each_child |kid| {
do kid.with_mut_base |child_node| {
child_node.position.origin.y = cur_y;
cur_y += child_node.position.size.height;
}
cur_y = cur_y + child_node.position.size.height;
};
}
let height = if self.is_root {
@ -304,7 +304,7 @@ impl BlockFlowData {
base.model.border.top + base.model.border.bottom;
base.position.size.height = height + noncontent_height;
noncontent_height += base.model.margin.top + base.model.margin.bottom;
noncontent_height = noncontent_height + base.model.margin.top + base.model.margin.bottom;
}
});

View file

@ -57,6 +57,7 @@ use extra::net::url::Url;
/// A box's type influences how its styles are interpreted during layout. For example, replaced
/// content such as images are resized differently from tables, text, or other content. Different
/// types of boxes may also contain custom data; for example, text boxes contain text.
#[deriving(Clone)]
pub enum RenderBox {
GenericRenderBoxClass(@mut RenderBoxBase),
ImageRenderBoxClass(@mut ImageRenderBox),
@ -308,7 +309,7 @@ impl RenderBox {
left_range.shift_by(slice_range.length() as int);
} else {
debug!("split_to_width: case=enlarging span");
remaining_width -= advance;
remaining_width = remaining_width - advance;
left_range.extend_by(slice_range.length() as int);
}
} else { // The advance is more than the remaining width.
@ -840,10 +841,10 @@ impl RenderBox {
pub fn dump_indent(&self, indent: uint) {
let mut string = ~"";
for uint::range(0u, indent) |_i| {
string += " ";
string.push_str(" ");
}
string += self.debug_str();
string.push_str(self.debug_str());
debug!("%s", string);
}
@ -863,4 +864,61 @@ impl RenderBox {
fmt!("box b%?: %s", self.id(), representation)
}
//
// Painting
//
/// Adds the display items necessary to paint the borders of this render box to a display list
/// if necessary.
pub fn paint_borders_if_applicable<E:ExtraDisplayListData>(&self,
list: &Cell<DisplayList<E>>,
abs_bounds: &Rect<Au>) {
// Fast path.
let border = do self.with_base |base| {
base.model.border
};
if border.is_zero() {
return
}
// Are all the widths equal?
//
// FIXME(pcwalton): Obviously this is wrong.
let borders = [ border.top, border.right, border.bottom ];
if borders.iter().all(|a| *a == border.left) {
let border_width = border.top;
let bounds = Rect {
origin: Point2D {
x: abs_bounds.origin.x + border_width.scale_by(0.5),
y: abs_bounds.origin.y + border_width.scale_by(0.5),
},
size: Size2D {
width: abs_bounds.size.width - border_width,
height: abs_bounds.size.height - border_width
}
};
let top_color = self.style().border_top_color();
let color = top_color.to_gfx_color(); // FIXME
// Append the border to the display list.
do list.with_mut_ref |list| {
let border_display_item = ~BorderDisplayItem {
base: BaseDisplayItem {
bounds: bounds,
extra: ExtraDisplayListData::new(*self),
},
width: border_width,
color: color,
};
list.append_item(BorderDisplayItemClass(border_display_item))
}
} else {
warn!("ignoring unimplemented border widths");
}
}
}

View file

@ -164,15 +164,15 @@ impl FloatFlowData {
for self.box.iter().advance |&box| {
do box.with_model |model| {
top_offset = model.margin.top + model.border.top + model.padding.top;
cur_y += top_offset;
cur_y = cur_y + top_offset;
}
}
for FloatFlow(self).each_child |kid| {
do kid.with_mut_base |child_node| {
child_node.position.origin.y = cur_y;
cur_y += child_node.position.size.height;
}
cur_y = cur_y + child_node.position.size.height;
};
}
let mut height = cur_y - top_offset;
@ -187,7 +187,7 @@ impl FloatFlowData {
base.model.border.top + base.model.border.bottom;
base.position.size.height = height + noncontent_height;
noncontent_height += base.model.margin.top + base.model.margin.bottom;
noncontent_height = noncontent_height + base.model.margin.top + base.model.margin.bottom;
}
});

View file

@ -115,7 +115,7 @@ impl FloatContextBase{
}
fn translate(&mut self, trans: Point2D<Au>) {
self.offset += trans;
self.offset = self.offset + trans;
}
fn last_float_pos(&self) -> Point2D<Au> {
@ -144,12 +144,16 @@ impl FloatContextBase{
let top = top - self.offset.y;
// Relevant dimensions for the right-most left float
let mut (max_left, l_top, l_bottom) = (Au(0) - self.offset.x, None, None);
let mut max_left = Au(0) - self.offset.x;
let mut l_top = None;
let mut l_bottom = None;
// Relevant dimensions for the left-most right float
let mut (min_right, r_top, r_bottom) = (max_x - self.offset.x, None, None);
let mut min_right = max_x - self.offset.x;
let mut r_top = None;
let mut r_bottom = None;
// Find the float collisions for the given vertical range.
for self.float_data.each |float| {
for self.float_data.iter().advance |float| {
match *float{
None => (),
Some(data) => {

View file

@ -314,25 +314,25 @@ impl<'self> FlowContext {
}
// Actual methods that do not require much flow-specific logic
pub fn foldl_all_boxes<B:Copy>(&self, seed: B, cb: &fn(a: B, b: RenderBox) -> B) -> B {
pub fn foldl_all_boxes<B:Clone>(&self, seed: B, cb: &fn(a: B, b: RenderBox) -> B) -> B {
match *self {
BlockFlow(block) => {
let block = &mut *block;
do block.box.map_default(copy seed) |box| {
cb(copy seed, *box)
do block.box.map_default(seed.clone()) |box| {
cb(seed.clone(), *box)
}
}
InlineFlow(inline) => {
let inline = &mut *inline;
do inline.boxes.foldl(seed) |acc, box| {
cb(copy *acc, *box)
do inline.boxes.iter().fold(seed) |acc, box| {
cb(acc.clone(), *box)
}
}
_ => fail!(fmt!("Don't know how to iterate node's RenderBoxes for %?", self)),
}
}
pub fn foldl_boxes_for_node<B:Copy>(&self,
pub fn foldl_boxes_for_node<B:Clone>(&self,
node: AbstractNode<LayoutView>,
seed: B,
callback: &fn(a: B, RenderBox) -> B)
@ -394,10 +394,10 @@ impl<'self> FlowContext {
pub fn dump_indent(&self, indent: uint) {
let mut s = ~"|";
for uint::range(0, indent) |_i| {
s += "---- ";
s.push_str("---- ");
}
s += self.debug_str();
s.push_str(self.debug_str());
debug!("%s", s);
// FIXME: this should have a pure/const version?
@ -409,10 +409,10 @@ impl<'self> FlowContext {
pub fn debug_str(&self) -> ~str {
let repr = match *self {
InlineFlow(inline) => {
let mut s = inline.boxes.foldl(~"InlineFlow(children=", |s, box| {
fmt!("%s b%d", *s, box.id())
let mut s = inline.boxes.iter().fold(~"InlineFlow(children=", |s, box| {
fmt!("%s b%d", s, box.id())
});
s += ")";
s.push_str(")");
s
},
BlockFlow(block) => {

View file

@ -169,8 +169,8 @@ impl LineboxScanner {
for line_range.eachi |i| {
do self.new_boxes[i].with_mut_base |base| {
base.position.origin.x = offset_x;
offset_x += base.position.size.width;
}
offset_x = offset_x + base.position.size.width;
};
}
},
CSSTextAlignCenter => {
@ -178,8 +178,8 @@ impl LineboxScanner {
for line_range.eachi |i| {
do self.new_boxes[i].with_mut_base |base| {
base.position.origin.x = offset_x;
offset_x += base.position.size.width;
}
offset_x = offset_x + base.position.size.width;
};
}
},
CSSTextAlignRight => {
@ -187,8 +187,8 @@ impl LineboxScanner {
for line_range.eachi |i| {
do self.new_boxes[i].with_mut_base |base| {
base.position.origin.x = offset_x;
offset_x += base.position.size.width;
}
offset_x = offset_x + base.position.size.width;
};
}
},
}
@ -292,7 +292,7 @@ impl LineboxScanner {
self.pending_line.range.reset(self.new_boxes.len(), 0);
}
self.pending_line.range.extend_by(1);
self.pending_line.bounds.size.width += box.position().size.width;
self.pending_line.bounds.size.width = self.pending_line.bounds.size.width + box.position().size.width;
self.new_boxes.push(box);
}
}
@ -325,7 +325,7 @@ impl InlineFlowData {
pub fn teardown(&mut self) {
self.common.teardown();
for self.boxes.each |box| {
for self.boxes.iter().advance |box| {
box.teardown();
}
self.boxes = ~[];
@ -362,7 +362,7 @@ impl InlineFlowData {
let mut min_width = Au(0);
let mut pref_width = Au(0);
for this.boxes.each |box| {
for this.boxes.iter().advance |box| {
debug!("FlowContext[%d]: measuring %s", self.common.id, box.debug_str());
min_width = Au::max(min_width, box.get_min_width(ctx));
pref_width = Au::max(pref_width, box.get_pref_width(ctx));
@ -383,7 +383,7 @@ impl InlineFlowData {
// `RenderBox`.
{
let this = &mut *self;
for this.boxes.each |&box| {
for this.boxes.iter().advance |&box| {
match box {
ImageRenderBoxClass(image_box) => {
let size = image_box.image.get_size();
@ -439,7 +439,7 @@ impl InlineFlowData {
let mut cur_y = Au(0);
for self.lines.eachi |i, line_span| {
for self.lines.iter().enumerate().advance |(i, line_span)| {
debug!("assign_height_inline: processing line %u with box span: %?", i, line_span);
// These coordinates are relative to the left baseline.
@ -537,7 +537,7 @@ impl InlineFlowData {
}
}
cur_y += linebox_height;
cur_y = cur_y + linebox_height;
} // End of `lines.each` loop.
self.common.position.size.height = cur_y;
@ -554,7 +554,7 @@ impl InlineFlowData {
self.common.id,
self.boxes.len());
for self.boxes.each |box| {
for self.boxes.iter().advance |box| {
box.build_display_list(builder, dirty, offset, list)
}

View file

@ -4,16 +4,8 @@
//! Borders, padding, and margins.
use layout::display_list_builder::{ExtraDisplayListData, ToGfxColor};
use layout::box::RenderBox;
use std::cell::Cell;
use std::num::Zero;
use geom::point::Point2D;
use geom::rect::Rect;
use geom::size::Size2D;
use geom::side_offsets::SideOffsets2D;
use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass, DisplayList};
use gfx::geometry::Au;
use newcss::complete::CompleteStyle;
use newcss::units::{Em, Pt, Px};
@ -150,62 +142,3 @@ impl BoxModel {
}
}
}
//
// Painting
//
impl RenderBox {
/// Adds the display items necessary to paint the borders of this render box to a display list
/// if necessary.
pub fn paint_borders_if_applicable<E:ExtraDisplayListData>(&self,
list: &Cell<DisplayList<E>>,
abs_bounds: &Rect<Au>) {
// Fast path.
let border = do self.with_base |base| {
base.model.border
};
if border.is_zero() {
return
}
// Are all the widths equal?
//
// FIXME(pcwalton): Obviously this is wrong.
let borders = [ border.top, border.right, border.bottom ];
if borders.iter().all(|a| *a == border.left) {
let border_width = border.top;
let bounds = Rect {
origin: Point2D {
x: abs_bounds.origin.x + border_width.scale_by(0.5),
y: abs_bounds.origin.y + border_width.scale_by(0.5),
},
size: Size2D {
width: abs_bounds.size.width - border_width,
height: abs_bounds.size.height - border_width
}
};
let top_color = self.style().border_top_color();
let color = top_color.to_gfx_color(); // FIXME
// Append the border to the display list.
do list.with_mut_ref |list| {
let border_display_item = ~BorderDisplayItem {
base: BaseDisplayItem {
bounds: bounds,
extra: ExtraDisplayListData::new(*self),
},
width: border_width,
color: color,
};
list.append_item(BorderDisplayItemClass(border_display_item))
}
} else {
warn!("ignoring unimplemented border widths");
}
}
}

View file

@ -249,13 +249,13 @@ impl TextRunScanner {
} // End of match.
debug!("--- In boxes: ---");
for in_boxes.eachi |i, box| {
for in_boxes.iter().enumerate().advance |(i, box)| {
debug!("%u --> %s", i, box.debug_str());
}
debug!("------------------");
debug!("--- Out boxes: ---");
for out_boxes.eachi |i, box| {
for out_boxes.iter().enumerate().advance |(i, box)| {
debug!("%u --> %s", i, box.debug_str());
}
debug!("------------------");

View file

@ -31,7 +31,7 @@ impl ElementMapping {
}
pub fn each(&self, callback: &fn(nr: &NodeRange) -> bool) -> bool {
for self.entries.each |nr| {
for self.entries.iter().advance |nr| {
if !callback(nr) {
break
}
@ -40,7 +40,7 @@ impl ElementMapping {
}
pub fn eachi(&self, callback: &fn(i: uint, nr: &NodeRange) -> bool) -> bool {
for self.entries.eachi |i, nr| {
for self.entries.iter().enumerate().advance |(i, nr)| {
if !callback(i, nr) {
break
}
@ -49,7 +49,7 @@ impl ElementMapping {
}
pub fn eachi_mut(&self, callback: &fn(i: uint, nr: &NodeRange) -> bool) -> bool {
for self.entries.eachi |i, nr| {
for self.entries.iter().enumerate().advance |(i, nr)| {
if !callback(i, nr) {
break
}
@ -61,19 +61,19 @@ impl ElementMapping {
let entries = &mut self.entries;
debug!("--- Old boxes: ---");
for old_boxes.eachi |i, box| {
for old_boxes.iter().enumerate().advance |(i, box)| {
debug!("%u --> %s", i, box.debug_str());
}
debug!("------------------");
debug!("--- New boxes: ---");
for new_boxes.eachi |i, box| {
for new_boxes.iter().enumerate().advance |(i, box)| {
debug!("%u --> %s", i, box.debug_str());
}
debug!("------------------");
debug!("--- Elem ranges before repair: ---");
for entries.eachi |i: uint, nr: &NodeRange| {
for entries.iter().enumerate().advance |(i, nr)| {
debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str());
}
debug!("----------------------------------");
@ -126,7 +126,7 @@ impl ElementMapping {
}
}
debug!("--- Elem ranges after repair: ---");
for entries.eachi |i: uint, nr: &NodeRange| {
for entries.iter().enumerate().advance |(i, nr)| {
debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str());
}
debug!("----------------------------------");

View file

@ -57,13 +57,14 @@ impl Pipeline {
profiler_chan);
ScriptTask::create(id,
compositor_chan,
compositor_chan.clone(),
layout_chan.clone(),
script_port,
script_chan.clone(),
constellation_chan,
resource_task,
image_cache_task);
image_cache_task,
compositor_chan.get_size());
Pipeline::new(id,
script_chan,
@ -92,8 +93,8 @@ impl Pipeline {
}
pub fn reload(&self) {
for self.url.iter().advance |&url| {
self.script_chan.send(LoadMsg(url));
for self.url.iter().advance |url| {
self.script_chan.send(LoadMsg(url.clone()));
}
}

View file

@ -2,12 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! A windowing implementation using GLUT.
///
/// GLUT is a very old and bare-bones toolkit. However, it has good cross-platform support, at
/// least on desktops. It is designed for testing Servo without the need of a UI.
//! A windowing implementation using GLFW.
use windowing::{ApplicationMethods, CompositeCallback, LoadUrlCallback, MouseCallback};
use windowing::{ApplicationMethods, LoadUrlCallback, MouseCallback};
use windowing::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent, WindowClickEvent};
use windowing::{WindowMouseDownEvent, WindowMouseUpEvent, ZoomCallback, Forward, Back, NavigationCallback};
@ -17,10 +14,8 @@ use geom::point::Point2D;
use geom::size::Size2D;
use servo_msg::compositor_msg::{IdleRenderState, RenderState, RenderingRenderState};
use servo_msg::compositor_msg::{FinishedLoading, Loading, PerformingLayout, ReadyState};
use glut::glut::{ACTIVE_CTRL, ACTIVE_SHIFT, DOUBLE, HAVE_PRECISE_MOUSE_WHEEL, WindowHeight};
use glut::glut::WindowWidth;
use glut::glut;
use glut::machack;
use glfw;
static THROBBER: [char, ..8] = [ '⣾', '⣽', '⣻', '⢿', '⡿', '⣟', '⣯', '⣷' ];
@ -29,17 +24,21 @@ pub struct Application;
impl ApplicationMethods for Application {
pub fn new() -> Application {
glut::init();
glut::init_display_mode(DOUBLE);
glfw::init();
Application
}
}
impl Drop for Application {
fn drop(&self) {
glfw::terminate();
}
}
/// The type of a window.
pub struct Window {
glut_window: glut::Window,
glfw_window: glfw::Window,
composite_callback: Option<CompositeCallback>,
resize_callback: Option<ResizeCallback>,
load_url_callback: Option<LoadUrlCallback>,
mouse_callback: Option<MouseCallback>,
@ -60,15 +59,14 @@ pub struct Window {
impl WindowMethods<Application> for Window {
/// Creates a new window.
pub fn new(_: &Application) -> @mut Window {
// Create the GLUT window.
unsafe { glut::glutInitWindowSize(800, 600); }
let glut_window = glut::create_window(~"Servo");
// Create the GLFW window.
let glfw_window = glfw::Window::create(800, 600, "Servo", glfw::Windowed).unwrap();
glfw_window.make_context_current();
// Create our window object.
let window = @mut Window {
glut_window: glut_window,
glfw_window: glfw_window,
composite_callback: None,
resize_callback: None,
load_url_callback: None,
mouse_callback: None,
@ -86,73 +84,43 @@ impl WindowMethods<Application> for Window {
throbber_frame: 0,
};
// Spin the event loop every 50 ms to allow the Rust channels to be polled.
//
// This requirement is pretty much the nail in the coffin for GLUT's usefulness.
//
// FIXME(pcwalton): What a mess.
let register_timer_callback: @mut @fn() = @mut ||{};
*register_timer_callback = || {
glut::timer_func(50, *register_timer_callback);
window.throbber_frame = (window.throbber_frame + 1) % (THROBBER.len() as u8);
window.update_window_title()
};
// Register event handlers.
do glut::reshape_func(window.glut_window) |width, height| {
do window.glfw_window.set_framebuffer_size_callback |_win, width, height| {
match window.resize_callback {
None => {}
Some(callback) => callback(width as uint, height as uint),
}
}
do glut::display_func {
// FIXME(pcwalton): This will not work with multiple windows.
match window.composite_callback {
None => {}
Some(callback) => callback(),
do window.glfw_window.set_key_callback |_win, key, _scancode, action, mods| {
if action == glfw::PRESS {
window.handle_key(key, mods)
}
}
do glut::keyboard_func |key, _, _| {
window.handle_key(key)
}
do glut::mouse_func |button, state, x, y| {
do window.glfw_window.set_mouse_button_callback |win, button, action, _mods| {
let (x, y) = win.get_cursor_pos();
if button < 3 {
window.handle_mouse(button, state, x, y);
window.handle_mouse(button, action, x as i32, y as i32);
}
}
do glut::mouse_wheel_func |wheel, direction, _x, _y| {
let delta = if HAVE_PRECISE_MOUSE_WHEEL {
(direction as f32) / 10000.0
} else {
(direction as f32) * 30.0
};
do window.glfw_window.set_scroll_callback |_win, x_offset, y_offset| {
let dx = (x_offset as f32) * 30.0;
let dy = (y_offset as f32) * 30.0;
match wheel {
1 => window.handle_scroll(Point2D(delta, 0.0)),
2 => window.handle_zoom(delta),
_ => window.handle_scroll(Point2D(0.0, delta)),
}
window.handle_scroll(Point2D(dx, dy));
}
(*register_timer_callback)();
machack::perform_scroll_wheel_hack();
window
}
/// Returns the size of the window.
pub fn size(&self) -> Size2D<f32> {
Size2D(glut::get(WindowWidth) as f32, glut::get(WindowHeight) as f32)
let (width, height) = self.glfw_window.get_framebuffer_size();
Size2D(width as f32, height as f32)
}
/// Presents the window to the screen (perhaps by page flipping).
pub fn present(&mut self) {
glut::swap_buffers();
}
/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, new_composite_callback: CompositeCallback) {
self.composite_callback = Some(new_composite_callback)
self.glfw_window.swap_buffers();
}
/// Registers a callback to run when a resize event occurs.
@ -187,12 +155,9 @@ impl WindowMethods<Application> for Window {
/// Spins the event loop.
pub fn check_loop(@mut self) {
glut::check_loop()
}
/// Schedules a redisplay.
pub fn set_needs_display(@mut self) {
glut::post_redisplay()
glfw::poll_events();
self.throbber_frame = (self.throbber_frame + 1) % (THROBBER.len() as u8);
self.update_window_title();
}
/// Sets the ready state.
@ -214,71 +179,65 @@ impl Window {
let throbber = THROBBER[self.throbber_frame];
match self.ready_state {
Loading => {
glut::set_window_title(self.glut_window, fmt!("%c Loading — Servo", throbber))
self.glfw_window.set_title(fmt!("%c Loading — Servo", throbber))
}
PerformingLayout => {
glut::set_window_title(self.glut_window,
fmt!("%c Performing Layout — Servo", throbber))
self.glfw_window.set_title(fmt!("%c Performing Layout — Servo", throbber))
}
FinishedLoading => {
match self.render_state {
RenderingRenderState => {
glut::set_window_title(self.glut_window,
fmt!("%c Rendering — Servo", throbber))
self.glfw_window.set_title(fmt!("%c Rendering — Servo", throbber))
}
IdleRenderState => glut::set_window_title(self.glut_window, "Servo"),
IdleRenderState => self.glfw_window.set_title("Servo"),
}
}
}
}
/// Helper function to handle keyboard events.
fn handle_key(&self, key: u8) {
debug!("got key: %?", key);
let modifiers = glut::get_modifiers();
fn handle_key(&self, key: c_int, mods: c_int) {
match key {
12 => self.load_url(), // Ctrl+L
31 if (modifiers & ACTIVE_CTRL) != 0 => { // Ctrl+-
glfw::KEY_L if mods & glfw::MOD_CONTROL != 0 => self.load_url(), // Ctrl+L
glfw::KEY_EQUAL if mods & glfw::MOD_CONTROL != 0 => { // Ctrl-+
for self.zoom_callback.iter().advance |&callback| {
callback(-0.1);
callback(1.1);
}
}
127 => {
glfw::KEY_MINUS if mods & glfw::MOD_CONTROL != 0 => { // Ctrl--
for self.zoom_callback.iter().advance |&callback| {
callback(0.90909090909);
}
}
glfw::KEY_BACKSPACE if mods & glfw::MOD_SHIFT != 0 => { // Shift-Backspace
for self.navigation_callback.iter().advance |&callback| {
if (modifiers & ACTIVE_SHIFT) != 0 { // Shift+Backspace
callback(Forward);
}
else {
callback(Back);
}
callback(Forward);
}
}
c => match c as char {
'=' if (modifiers & ACTIVE_CTRL) != 0 => { // Ctrl++
for self.zoom_callback.iter().advance |&callback| {
callback(0.1);
}
glfw::KEY_BACKSPACE => { // Backspace
for self.navigation_callback.iter().advance |&callback| {
callback(Back);
}
_ => {}
}
_ => {}
}
}
/// Helper function to handle a click
fn handle_mouse(&self, button: c_int, state: c_int, x: c_int, y: c_int) {
fn handle_mouse(&self, button: c_int, action: c_int, x: c_int, y: c_int) {
// FIXME(tkuehn): max pixel dist should be based on pixel density
let max_pixel_dist = 10f;
match self.mouse_callback {
None => {}
Some(callback) => {
let event: WindowMouseEvent;
match state {
glut::MOUSE_DOWN => {
match action {
glfw::PRESS => {
event = WindowMouseDownEvent(button as uint, Point2D(x as f32, y as f32));
*self.mouse_down_point = Point2D(x, y);
*self.mouse_down_button = button;
}
glut::MOUSE_UP => {
glfw::RELEASE => {
event = WindowMouseUpEvent(button as uint, Point2D(x as f32, y as f32));
if *self.mouse_down_button == button {
let pixel_dist = *self.mouse_down_point - Point2D(x, y);

View file

@ -47,9 +47,6 @@ impl WindowingMethods<Application> for Window {
(*self).flush();
}
/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, _: CompositeCallback) {}
/// Registers a callback to run when a resize event occurs.
pub fn set_resize_callback(&mut self, _: ResizeCallback) {}

View file

@ -5,13 +5,13 @@
//! Platform-specific functionality for Servo.
#[cfg(not(shared_gl_windowing))]
pub use platform::common::glut_windowing::{Application, Window};
pub use platform::common::glfw_windowing::{Application, Window};
#[cfg(shared_gl_windowing)]
pub use platform::common::shared_gl_windowing::{Application, Window};
pub mod common {
#[cfg(not(shared_gl_windowing))]
pub mod glut_windowing;
pub mod glfw_windowing;
#[cfg(shared_gl_windowing)]
pub mod shared_gl_windowing;
}

View file

@ -15,7 +15,7 @@ extern mod alert;
extern mod azure;
extern mod geom;
extern mod gfx (name = "gfx");
extern mod glut;
extern mod glfw;
extern mod http_client;
extern mod js;
extern mod layers;
@ -131,7 +131,7 @@ fn run(opts: &Opts) {
profiler_chan.clone());
// Send the URL command to the constellation.
for opts.urls.each |filename| {
for opts.urls.iter().advance |filename| {
constellation_chan.send(LoadUrlMsg(make_url(copy *filename, None)))
}

View file

@ -7,7 +7,7 @@ use std::comm;
use std::comm::{Chan, Port};
use std::task;
pub fn spawn_listener<A: Owned>(f: ~fn(Port<A>)) -> Chan<A> {
pub fn spawn_listener<A: Send>(f: ~fn(Port<A>)) -> Chan<A> {
let (setup_po, setup_ch) = comm::stream();
do task::spawn {
let (po, ch) = comm::stream();
@ -17,7 +17,7 @@ pub fn spawn_listener<A: Owned>(f: ~fn(Port<A>)) -> Chan<A> {
setup_po.recv()
}
pub fn spawn_conversation<A: Owned, B: Owned>(f: ~fn(Port<A>, Chan<B>)) -> (Port<B>, Chan<A>) {
pub fn spawn_conversation<A: Send, B: Send>(f: ~fn(Port<A>, Chan<B>)) -> (Port<B>, Chan<A>) {
let (from_child, to_parent) = comm::stream();
let to_parent = Cell::new(to_parent);
let to_child = do spawn_listener |from_parent| {

View file

@ -19,9 +19,6 @@ pub enum WindowNavigateMsg {
Back,
}
/// Type of the function that is called when the screen is to be redisplayed.
pub type CompositeCallback = @fn();
/// Type of the function that is called when the window is resized.
pub type ResizeCallback = @fn(uint, uint);
@ -53,8 +50,6 @@ pub trait WindowMethods<A> {
/// Presents the window to the screen (perhaps by page flipping).
pub fn present(&mut self);
/// Registers a callback to run when a composite event occurs.
pub fn set_composite_callback(&mut self, new_composite_callback: CompositeCallback);
/// Registers a callback to run when a resize event occurs.
pub fn set_resize_callback(&mut self, new_resize_callback: ResizeCallback);
/// Registers a callback to run when a new URL is to be loaded.
@ -70,8 +65,6 @@ pub trait WindowMethods<A> {
/// Spins the event loop.
pub fn check_loop(@mut self);
/// Schedules a redisplay at the next turn of the event loop.
pub fn set_needs_display(@mut self);
/// Sets the ready state of the current page.
pub fn set_ready_state(@mut self, ready_state: ReadyState);
/// Sets the render state of the current page.

View file

@ -179,7 +179,7 @@ impl ImageCache {
loop {
let msg = self.port.recv();
for msg_handlers.each |handler| {
for msg_handlers.iter().advance |handler| {
(*handler)(&msg)
}
@ -375,7 +375,7 @@ impl ImageCache {
priv fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) {
match self.wait_map.pop(&url) {
Some(waiters) => {
for waiters.each |response| {
for waiters.iter().advance |response| {
response.send(f());
}
}
@ -444,7 +444,7 @@ fn load_image_data(url: Url, resource_task: ResourceTask) -> Result<~[u8], ()> {
loop {
match response_port.recv() {
resource_task::Payload(data) => {
image_data += data;
image_data.push_all(data);
}
resource_task::Done(result::Ok(*)) => {
return Ok(image_data);

View file

@ -105,7 +105,7 @@ impl ResourceManager {
}
fn get_loader_factory(&self, url: &Url) -> Option<LoaderTask> {
for self.loaders.each |scheme_loader| {
for self.loaders.iter().advance |scheme_loader| {
match *scheme_loader {
(ref scheme, ref loader_factory) => {
if (*scheme) == url.scheme {

View file

@ -6,7 +6,7 @@ use std::comm;
use std::comm::{Chan, Port};
use std::task;
pub fn spawn_listener<A: Owned>(f: ~fn(Port<A>)) -> Chan<A> {
pub fn spawn_listener<A: Send>(f: ~fn(Port<A>)) -> Chan<A> {
let (setup_port, setup_chan) = comm::stream();
do task::spawn {
let (port, chan) = comm::stream();

View file

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::bindings::codegen::ClientRectBinding;
use dom::clientrect::ClientRect;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext, JSVal};
use js::glue::RUST_OBJECT_TO_JSVAL;
use std::cast;
impl ClientRect {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for ClientRect {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for ClientRect {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for ClientRect {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -1,45 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::ClientRectListBinding;
use dom::bindings::utils::{WrapperCache, CacheableWrapper, BindingObject};
use dom::clientrectlist::ClientRectList;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
use std::cast;
impl ClientRectList {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for ClientRectList {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectListBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for ClientRectList {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}

View file

@ -2153,7 +2153,7 @@ class CGImports(CGWrapper):
# TODO imports to cover descriptors, etc.
def _useString(imports):
return '#[allow(unused_imports,unused_variable,unused_unsafe,unused_mut)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n'
return '#[allow(non_uppercase_statics,unused_imports,unused_variable,unused_unsafe,unused_mut)];' + ''.join(['use %s;\n' % i for i in imports]) + '\n'
CGWrapper.__init__(self, child,
declarePre=_useString(sorted(declareImports)))

View file

@ -6,7 +6,6 @@ use std::cast;
use std::libc;
use std::ptr;
use std::result;
use std::vec;
use dom::bindings::utils::{DOMString, rust_box, squirrel_away, str};
use dom::bindings::utils::{WrapperCache, DerivedWrapper};
use dom::bindings::utils::{jsval_to_str, WrapNewBindingObject, CacheableWrapper};
@ -102,11 +101,11 @@ pub fn init(compartment: @mut Compartment) {
getter: JSPropertyOpWrapper {op: null(), info: null()},
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
compartment.global_props.push(attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
do attrs.as_imm_buf |specs, _len| {
unsafe {
assert!(JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs) == 1);
}
});
}
let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getElementsByTagName"),
call: JSNativeWrapper {op: getElementsByTagName, info: null()},
@ -118,11 +117,11 @@ pub fn init(compartment: @mut Compartment) {
nargs: 0,
flags: 0,
selfHostedName: null()}];
vec::as_imm_buf(*methods, |fns, _len| {
do methods.as_imm_buf |fns, _len| {
unsafe {
JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
}
});
}
compartment.register_class(utils::instance_jsclass(~"DocumentInstance",
finalize,

View file

@ -21,7 +21,6 @@ use std::ptr;
use std::ptr::null;
use std::result;
use std::str;
use std::vec;
use js::glue::*;
use js::jsapi::*;
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec};
@ -84,12 +83,12 @@ pub fn init(compartment: @mut Compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: JSPropertyOpWrapper {op: null(), info: null()},
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
compartment.global_props.push(attrs);
do attrs.as_imm_buf |specs, _len| {
unsafe {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
}
});
}
let methods = @~[JSFunctionSpec {name: compartment.add_name(~"getClientRects"),
call: JSNativeWrapper {op: getClientRects, info: null()},
@ -111,11 +110,11 @@ pub fn init(compartment: @mut Compartment) {
nargs: 0,
flags: 0,
selfHostedName: null()}];
vec::as_imm_buf(*methods, |fns, _len| {
do methods.as_imm_buf |fns, _len| {
unsafe {
JS_DefineFunctions(compartment.cx.ptr, obj.ptr, fns);
}
});
}
compartment.register_class(utils::instance_jsclass(~"GenericElementInstance",
finalize, trace));
@ -137,12 +136,12 @@ pub fn init(compartment: @mut Compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: JSPropertyOpWrapper {op: null(), info: null()},
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
compartment.global_props.push(attrs);
do attrs.as_imm_buf |specs, _len| {
unsafe {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
}
});
}
}
extern fn getClientRects(cx: *JSContext, _argc: c_uint, vp: *JSVal) -> JSBool {

View file

@ -1,59 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::cast;
use dom::bindings::codegen::EventBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::event::Event_;
use script_task::{task_from_context, global_script_context};
use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
impl Event_ {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for Event_ {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
EventBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for Event_ {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for Event_ {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -1,61 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::cast;
use dom::bindings::codegen::EventTargetBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::eventtarget::EventTarget;
use script_task::{task_from_context, global_script_context};
use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
impl EventTarget {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for EventTarget {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
EventTargetBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for EventTarget {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for EventTarget {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe {
*vp = RUST_OBJECT_TO_JSVAL(obj)
};
return 1;
}
}
}

View file

@ -1,62 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::bindings::codegen::FormDataBinding;
use dom::formdata::FormData;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext, JSVal};
use js::glue::RUST_OBJECT_TO_JSVAL;
use std::cast;
impl FormData {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for FormData {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
FormDataBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for FormData {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for FormData {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -1,45 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::HTMLCollectionBinding;
use dom::bindings::utils::{CacheableWrapper, BindingObject, WrapperCache};
use dom::htmlcollection::HTMLCollection;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
use std::cast;
impl HTMLCollection {
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl BindingObject for HTMLCollection {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl CacheableWrapper for HTMLCollection {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
HTMLCollectionBinding::Wrap(cx, scope, self, &mut unused)
}
}

View file

@ -13,7 +13,6 @@ use std::cast;
use std::libc::c_uint;
use std::ptr;
use std::ptr::null;
use std::vec;
use js::jsapi::*;
use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSPropertySpec};
use js::jsapi::{JSPropertyOpWrapper, JSStrictPropertyOpWrapper};
@ -54,12 +53,12 @@ pub fn init(compartment: @mut Compartment) {
flags: (JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS) as u8,
getter: JSPropertyOpWrapper {op: null(), info: null()},
setter: JSStrictPropertyOpWrapper {op: null(), info: null()}}];
vec::push(&mut compartment.global_props, attrs);
vec::as_imm_buf(*attrs, |specs, _len| {
compartment.global_props.push(attrs);
do attrs.as_imm_buf |specs, _len| {
unsafe {
JS_DefineProperties(compartment.cx.ptr, obj.ptr, specs);
}
});
}
}
#[allow(non_implicitly_copyable_typarams)]
@ -121,35 +120,6 @@ extern fn getNextSibling(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBoo
return 1;
}
impl Node<ScriptView> {
fn getNodeType(&self) -> i32 {
match self.type_id {
ElementNodeTypeId(_) => 1,
TextNodeTypeId => 3,
CommentNodeTypeId => 8,
DoctypeNodeTypeId => 10
}
}
fn getNextSibling(&mut self) -> Option<&mut AbstractNode<ScriptView>> {
match self.next_sibling {
// transmute because the compiler can't deduce that the reference
// is safe outside of with_mut_base blocks.
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
None => None
}
}
fn getFirstChild(&mut self) -> Option<&mut AbstractNode<ScriptView>> {
match self.first_child {
// transmute because the compiler can't deduce that the reference
// is safe outside of with_mut_base blocks.
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
None => None
}
}
}
extern fn getNodeType(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool {
unsafe {
let obj = JS_THIS_OBJECT(cx, cast::transmute(vp));

View file

@ -13,8 +13,8 @@ use std::ptr;
use std::ptr::{null, to_unsafe_ptr};
use std::result;
use std::str;
use std::sys;
use std::uint;
use std::unstable::intrinsics;
use js::glue::*;
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
use js::glue::{PROPERTY_STUB, STRICT_PROPERTY_STUB, ENUMERATE_STUB, CONVERT_STUB, RESOLVE_STUB};
@ -105,7 +105,7 @@ impl DOMString {
pub struct rust_box<T> {
rc: uint,
td: *sys::TypeDesc,
td: *intrinsics::TyDesc,
next: *(),
prev: *(),
payload: T
@ -179,12 +179,12 @@ pub fn get_compartment(cx: *JSContext) -> @mut Compartment {
extern fn has_instance(_cx: *JSContext, obj: **JSObject, v: *JSVal, bp: *mut JSBool) -> JSBool {
//XXXjdm this is totally broken for non-object values
unsafe {
let mut o = RUST_JSVAL_TO_OBJECT(unsafe {*v});
let obj = unsafe {*obj};
unsafe { *bp = 0; }
let mut o = RUST_JSVAL_TO_OBJECT(*v);
let obj = *obj;
*bp = 0;
while o.is_not_null() {
if o == obj {
unsafe { *bp = 1; }
*bp = 1;
break;
}
o = JS_GetPrototype(o);
@ -718,7 +718,7 @@ pub fn XrayResolveProperty(cx: *JSContext,
unsafe {
match attributes {
Some(attrs) => {
for attrs.each |&elem| {
for attrs.iter().advance |&elem| {
let (attr, attr_id) = elem;
if attr_id == JSID_VOID || attr_id != id {
loop;
@ -769,7 +769,7 @@ fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
pub fn InitIds(cx: *JSContext, specs: &[JSPropertySpec], ids: &mut [jsid]) -> bool {
let mut rval = true;
for specs.eachi |i, spec| {
for specs.iter().enumerate().advance |(i, spec)| {
if spec.name.is_null() == true {
break;
}
@ -830,7 +830,7 @@ pub fn FindEnumStringIndex(cx: *JSContext,
if chars.is_null() {
return Err(());
}
for values.eachi |i, value| {
for values.iter().enumerate().advance |(i, value)| {
if value.length != length as uint {
loop;
}

View file

@ -2,8 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::WrapperCache;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use dom::bindings::codegen::ClientRectBinding;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext, JSVal};
use js::glue::RUST_OBJECT_TO_JSVAL;
use std::cast;
use std::f32;
pub struct ClientRect {
@ -27,6 +33,15 @@ impl ClientRect {
rect
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
pub fn Top(&self) -> f32 {
self.top
}
@ -52,3 +67,40 @@ impl ClientRect {
}
}
impl CacheableWrapper for ClientRect {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for ClientRect {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for ClientRect {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -2,8 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::ClientRectListBinding;
use dom::bindings::utils::{WrapperCache, CacheableWrapper, BindingObject};
use dom::clientrect::ClientRect;
use dom::bindings::utils::WrapperCache;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
use std::cast;
pub struct ClientRectList {
wrapper: WrapperCache,
@ -20,6 +26,15 @@ impl ClientRectList {
list
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
pub fn Length(&self) -> u32 {
self.rects.len() as u32
}
@ -37,3 +52,25 @@ impl ClientRectList {
self.Item(index)
}
}
impl CacheableWrapper for ClientRectList {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
ClientRectListBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for ClientRectList {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}

View file

@ -5,9 +5,16 @@
use dom::eventtarget::EventTarget;
use dom::window::Window;
use dom::bindings::codegen::EventBinding;
use dom::bindings::utils::{CacheableWrapper, BindingObject, DerivedWrapper};
use dom::bindings::utils::{DOMString, ErrorResult, WrapperCache};
use script_task::{task_from_context, global_script_context};
use geom::point::Point2D;
use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
use std::cast;
pub enum Event {
ResizeEvent(uint, uint),
@ -38,6 +45,15 @@ impl Event_ {
}
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
pub fn EventPhase(&self) -> u16 {
0
}
@ -101,3 +117,39 @@ impl Event_ {
@mut Event_::new(type_)
}
}
impl CacheableWrapper for Event_ {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
EventBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for Event_ {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for Event_ {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -2,7 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::WrapperCache;
use dom::bindings::codegen::EventTargetBinding;
use dom::bindings::utils::{CacheableWrapper, WrapperCache, BindingObject, DerivedWrapper};
use script_task::{task_from_context, global_script_context};
use js::glue::RUST_OBJECT_TO_JSVAL;
use js::jsapi::{JSObject, JSContext, JSVal};
use std::cast;
pub struct EventTarget {
wrapper: WrapperCache
@ -14,4 +21,51 @@ impl EventTarget {
wrapper: WrapperCache::new()
}
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
}
impl CacheableWrapper for EventTarget {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe { cast::transmute(&self.wrapper) }
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
EventTargetBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for EventTarget {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for EventTarget {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe {
*vp = RUST_OBJECT_TO_JSVAL(obj)
};
return 1;
}
}
}

View file

@ -2,8 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::{CacheableWrapper, BindingObject, DerivedWrapper};
use dom::bindings::utils::{WrapperCache, DOMString, str};
use dom::bindings::codegen::FormDataBinding;
use dom::blob::Blob;
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext, JSVal};
use js::glue::RUST_OBJECT_TO_JSVAL;
use std::cast;
use std::hashmap::HashMap;
enum FormDatum {
@ -24,6 +32,15 @@ impl FormData {
}
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
pub fn Append(&mut self, name: DOMString, value: @mut Blob, filename: Option<DOMString>) {
let blob = BlobData {
blob: value,
@ -36,3 +53,41 @@ impl FormData {
self.data.insert(name.to_str(), StringData(value));
}
}
impl CacheableWrapper for FormData {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
FormDataBinding::Wrap(cx, scope, self, &mut unused)
}
}
impl BindingObject for FormData {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl DerivedWrapper for FormData {
fn wrap(&mut self, _cx: *JSContext, _scope: *JSObject, _vp: *mut JSVal) -> i32 {
fail!(~"nyi")
}
fn wrap_shared(@mut self, cx: *JSContext, scope: *JSObject, vp: *mut JSVal) -> i32 {
let obj = self.wrap_object_shared(cx, scope);
if obj.is_null() {
return 0;
} else {
unsafe { *vp = RUST_OBJECT_TO_JSVAL(obj) };
return 1;
}
}
}

View file

@ -2,12 +2,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::utils::WrapperCache;
use dom::bindings::codegen::HTMLCollectionBinding;
use dom::bindings::utils::{CacheableWrapper, BindingObject, WrapperCache};
use dom::bindings::utils::{DOMString, ErrorResult};
use dom::node::{AbstractNode, ScriptView};
use script_task::{task_from_context, global_script_context};
use js::jsapi::{JSObject, JSContext};
use std::cast;
use std::ptr;
pub struct HTMLCollection {
@ -25,6 +28,15 @@ impl HTMLCollection {
collection
}
pub fn init_wrapper(@mut self) {
let script_context = global_script_context();
let cx = script_context.js_compartment.cx.ptr;
let owner = script_context.root_frame.get_ref().window;
let cache = owner.get_wrappercache();
let scope = cache.get_wrapper();
self.wrap_object_shared(cx, scope);
}
pub fn Length(&self) -> u32 {
self.elements.len() as u32
}
@ -47,3 +59,25 @@ impl HTMLCollection {
self.Item(index)
}
}
impl BindingObject for HTMLCollection {
fn GetParentObject(&self, cx: *JSContext) -> @mut CacheableWrapper {
let script_context = task_from_context(cx);
unsafe {
(*script_context).root_frame.get_ref().window as @mut CacheableWrapper
}
}
}
impl CacheableWrapper for HTMLCollection {
fn get_wrappercache(&mut self) -> &mut WrapperCache {
unsafe {
cast::transmute(&self.wrapper)
}
}
fn wrap_object_shared(@mut self, cx: *JSContext, scope: *JSObject) -> *JSObject {
let mut unused = false;
HTMLCollectionBinding::Wrap(cx, scope, self, &mut unused)
}
}

View file

@ -363,10 +363,10 @@ impl<View> AbstractNode<View> {
pub fn dump_indent(&self, indent: uint) {
let mut s = ~"";
for uint::range(0u, indent) |_i| {
s += " ";
s.push_str(" ");
}
s += self.debug_str();
s.push_str(self.debug_str());
debug!("%s", s);
// FIXME: this should have a pure version?
@ -423,7 +423,35 @@ impl Node<ScriptView> {
layout_data: None,
}
}
}
pub fn getNodeType(&self) -> i32 {
match self.type_id {
ElementNodeTypeId(_) => 1,
TextNodeTypeId => 3,
CommentNodeTypeId => 8,
DoctypeNodeTypeId => 10
}
}
pub fn getNextSibling(&mut self) -> Option<&mut AbstractNode<ScriptView>> {
match self.next_sibling {
// transmute because the compiler can't deduce that the reference
// is safe outside of with_mut_base blocks.
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
None => None
}
}
pub fn getFirstChild(&mut self) -> Option<&mut AbstractNode<ScriptView>> {
match self.first_child {
// transmute because the compiler can't deduce that the reference
// is safe outside of with_mut_base blocks.
Some(ref mut n) => Some(unsafe { cast::transmute(n) }),
None => None
}
}
}
/// The CSS library requires that DOM nodes be convertible to `*c_void` via the `VoidPtrLike`
/// trait.

View file

@ -34,7 +34,7 @@ pub struct Window {
}
impl Drop for Window {
fn finalize(&self) {
fn drop(&self) {
self.timer_chan.send(TimerMessage_Close);
}
}

View file

@ -105,7 +105,7 @@ fn css_link_listener(to_parent: Chan<Option<Stylesheet>>,
// Send the sheets back in order
// FIXME: Shouldn't wait until after we've recieved CSSTaskExit to start sending these
do result_vec.consume |_i, port| {
for result_vec.iter().advance |port| {
to_parent.send(Some(port.recv()));
}
to_parent.send(None);
@ -130,7 +130,7 @@ fn js_script_listener(to_parent: Chan<~[~[u8]]>,
loop {
match input_port.recv() {
Payload(data) => {
buf += data;
buf.push_all(data);
}
Done(Ok(*)) => {
result_chan.send(Some(buf));
@ -292,9 +292,8 @@ pub fn parse_html(url: Url,
debug!("-- attach attrs");
do node.as_mut_element |element| {
for tag.attributes.each |attr| {
let &hubbub::Attribute {name: name, value: value, _} = attr;
element.attrs.push(Attr::new(name, value));
for tag.attributes.iter().advance |attr| {
element.attrs.push(Attr::new(attr.name.clone(), attr.value.clone()));
}
}

View file

@ -26,19 +26,13 @@ pub mod dom {
pub mod bindings {
pub mod document;
pub mod element;
pub mod event;
pub mod eventtarget;
pub mod node;
pub mod text;
pub mod utils;
pub mod conversions;
pub mod window;
pub mod proxyhandler;
pub mod clientrect;
pub mod clientrectlist;
pub mod domparser;
pub mod htmlcollection;
pub mod formdata;
pub mod codegen {
pub mod ClientRectBinding;
pub mod ClientRectListBinding;

View file

@ -167,7 +167,7 @@ pub fn task_from_context(js_context: *JSContext) -> *mut ScriptTask {
#[unsafe_destructor]
impl Drop for ScriptTask {
fn finalize(&self) {
fn drop(&self) {
unsafe {
let _ = local_data::local_data_pop(global_script_context_key);
}
@ -183,7 +183,8 @@ impl ScriptTask {
script_chan: ScriptChan,
constellation_chan: ConstellationChan,
resource_task: ResourceTask,
img_cache_task: ImageCacheTask)
img_cache_task: ImageCacheTask,
initial_size: Size2D<int>)
-> @mut ScriptTask {
let js_runtime = js::rust::rt();
let js_context = js_runtime.cx();
@ -219,7 +220,7 @@ impl ScriptTask {
root_frame: None,
window_size: Size2D(800u, 600),
window_size: Size2D(initial_size.width as uint, initial_size.height as uint),
damage: None,
last_loaded_url: None,
@ -246,14 +247,15 @@ impl ScriptTask {
}
}
pub fn create<C: ScriptListener + Owned>(id: uint,
pub fn create<C: ScriptListener + Send>(id: uint,
compositor: C,
layout_chan: LayoutChan,
script_port: Port<ScriptMsg>,
script_chan: ScriptChan,
constellation_chan: ConstellationChan,
resource_task: ResourceTask,
image_cache_task: ImageCacheTask) {
image_cache_task: ImageCacheTask,
initial_size: Size2D<int>) {
let compositor = Cell::new(compositor);
let script_port = Cell::new(script_port);
// FIXME: rust#6399
@ -267,7 +269,8 @@ impl ScriptTask {
script_chan.clone(),
constellation_chan.clone(),
resource_task.clone(),
image_cache_task.clone());
image_cache_task.clone(),
initial_size);
script_task.start();
}
}
@ -353,8 +356,8 @@ impl ScriptTask {
/// The entry point to document loading. Defines bindings, sets up the window and document
/// objects, parses HTML and CSS, and kicks off initial layout.
fn load(&mut self, url: Url) {
for self.last_loaded_url.iter().advance |&last_loaded_url| {
if url == last_loaded_url { return; }
for self.last_loaded_url.iter().advance |last_loaded_url| {
if url == *last_loaded_url { return; }
}
// Define the script DOM bindings.
//
@ -416,9 +419,9 @@ impl ScriptTask {
self.js_compartment.define_functions(debug_fns);
// Evaluate every script in the document.
do js_scripts.consume |_, bytes| {
for js_scripts.iter().advance |bytes| {
let _ = self.js_context.evaluate_script(self.js_compartment.global_obj,
bytes,
bytes.clone(),
~"???",
1);
}
@ -498,7 +501,7 @@ impl ScriptTask {
}
/// Sends the given query to layout.
pub fn query_layout<T: Owned>(&mut self, query: LayoutQuery, response_port: Port<Result<T, ()>>) -> Result<T,()> {
pub fn query_layout<T: Send>(&mut self, query: LayoutQuery, response_port: Port<Result<T, ()>>) -> Result<T,()> {
self.join_layout();
self.layout_chan.send(QueryMsg(query));
response_port.recv()

View file

@ -143,14 +143,14 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for LRUCache<K,V> {
}
fn find(&mut self, key: &K) -> Option<V> {
match self.entries.position(|&(k, _)| k == *key) {
match self.entries.iter().position(|&(ref k, _)| *k == *key) {
Some(pos) => Some(self.touch(pos)),
None => None,
}
}
fn find_or_create(&mut self, key: &K, blk: &fn(&K) -> V) -> V {
match self.entries.position(|&(k, _)| k == *key) {
match self.entries.iter().position(|&(ref k, _)| *k == *key) {
Some(pos) => self.touch(pos),
None => {
let val = blk(key);

View file

@ -90,7 +90,7 @@ impl ProfilerCategory {
}
priv fn check_order(vec: &[(ProfilerCategory, ~[f64])]) {
for vec.each |&(category, _)| {
for vec.iter().advance |&(category, _)| {
if category != vec[category as uint].first() {
fail!("Enum category does not match bucket index. This is a bug.");
}
@ -161,7 +161,7 @@ impl Profiler {
let data_len = data.len();
if data_len > 0 {
let (mean, median, min, max) =
(data.foldl(0f64, |a, b| a + *b) / (data_len as f64),
(data.iter().fold(0f64, |a, b| a + *b) / (data_len as f64),
data[data_len / 2],
data.iter().min(),
data.iter().max());

View file

@ -152,7 +152,8 @@ impl<NR:TreeNodeRef<N>,N:TreeNode<NR>> TreeUtils for NR {
}
for self.each_child |kid| {
if !kid.traverse_preorder(callback) {
// FIXME: Work around rust#2202. We should be able to pass the callback directly.
if !kid.traverse_preorder(|a| callback(a)) {
return false;
}
}
@ -162,7 +163,8 @@ impl<NR:TreeNodeRef<N>,N:TreeNode<NR>> TreeUtils for NR {
fn traverse_postorder(&self, callback: &fn(NR) -> bool) -> bool {
for self.each_child |kid| {
if !kid.traverse_postorder(callback) {
// FIXME: Work around rust#2202. We should be able to pass the callback directly.
if !kid.traverse_postorder(|a| callback(a)) {
return false;
}
}

View file

@ -44,9 +44,10 @@ pub fn make_url(str_url: ~str, current_url: Option<Url>) -> Url {
for current_url.path.split_iter('/').advance |p| {
path.push(p.to_str());
}
let path = path; // FIXME: borrow checker workaround
let path = path.init();
let path = (path.map(|x| copy *x) + [str_url]).connect("/");
let mut path = path.iter().transform(|x| copy *x).collect::<~[~str]>();
path.push(str_url);
let path = path.connect("/");
current_url.scheme + "://" + current_url.host + path
}

@ -1 +1 @@
Subproject commit faca1281aaf112e96ee03041744fe85ac4273192
Subproject commit 78f84af79eb653fde2d50621fc3631043fa6fa9e

@ -1 +1 @@
Subproject commit 5247c3e97f7eafa336c8a028a3175c3bc3a2d95a
Subproject commit 980254dd840772c8ee5f37056e7bd9f4d93d5377

@ -1 +1 @@
Subproject commit 788f41a6e924e5c3f9d254d3e5dabf2b3e622f00
Subproject commit 641af36389a7592ef0faea2488ec08bd144e9bfe

@ -1 +1 @@
Subproject commit 3ef4cf7fdaaaa51026ec546a71426ff03a0899fd
Subproject commit 23bb17289846dd9486f633c0b5187c7ba333d943

@ -1 +1 @@
Subproject commit ea8d2bd026cd91d3fb5fd753677da3fd7d21dbab
Subproject commit 77e9ed24ca7bb0f9a0b33d7fd888de2905dddcd4

@ -1 +1 @@
Subproject commit 72c7673ac50cc1ffb518de65022fb034df334ed9
Subproject commit 313e26f9202b44d09043485671bc903786c328e7

@ -1 +1 @@
Subproject commit 6daaffe3b6cf226c6da4979d0fb907a8258b0288
Subproject commit ba24db51b38c9875e1356f7bc08c13a683071710

@ -1 +1 @@
Subproject commit 5e8c30cc69286e68ba9bf843f146a580381bff83
Subproject commit 7a584804a98b5731fb53d216c3f059e5a0c7ea5c

1
src/support/glfw/glfw Submodule

@ -0,0 +1 @@
Subproject commit 738b78899bb271258f55ae842e180de2c5ec87db

@ -0,0 +1 @@
Subproject commit 8999e447127c8674cdf130a2bd1759d9f94cd6ad

@ -1 +1 @@
Subproject commit 42931c8e0894c0d3d70d29abdf16639b30e6bf92
Subproject commit 8f253edf62cfadfa18edb773aebd74bd62647ce4

@ -1 +1 @@
Subproject commit d88f23d1541019baaedb350ce275349ad2ca304e
Subproject commit 17afe7a4b5d40dd3da792cd5e22e1e6b48225f21

@ -1 +1 @@
Subproject commit c549e77a677a6f76f8c9a42682d719d4ac20c3fc
Subproject commit 09a6c29e0a9432d67eeb583324c17766aa1155e3

@ -1 +1 @@
Subproject commit a1454f07d3df11b16dc88bedf79d20693bfc3bb7
Subproject commit a8843ea084262773c31916e3a52c6dacea135153

@ -1 +1 @@
Subproject commit afdd72f326f720afcfa7cea6005b20924a441570
Subproject commit aecdedca9ebef5ce6cf4d2dd38e2c312c0907f1d

@ -1 +1 @@
Subproject commit d7c05e81acb66717f1a86ad67f391c9bc0961bbf
Subproject commit 17bd4bbc04942e7de9eae76c0f8a76dfcb3dc9fc

@ -1 +1 @@
Subproject commit 3f41e98925b9d4c0d4074046388e73f0e0032ab9
Subproject commit f889ab32a6fc249b2a8667a7c7c1e5c24d5daf7c

@ -1 +1 @@
Subproject commit af080e2ab3ca871a6e77339eb752e59b3903b068
Subproject commit 26dc2e896a57a28f03be43df46868e1a41a15807

@ -1 +1 @@
Subproject commit 577bebc7c14f391cf5faddc16bda194da6a3e7b6
Subproject commit 86c9525ec4aa886c5afe4ec5202ca3a0d400d155

@ -1 +1 @@
Subproject commit c726370b54f573f7f5d67619f40b0b92d55919c7
Subproject commit 5ed1ff9da4301dd3efd7102f3607fd353a099804