From 1230282cece2552aaeaaf482133054c257221ec3 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 4 Jul 2013 12:51:02 -0600 Subject: [PATCH 1/5] Add glfw and glfw-rs to servo build. --- .gitmodules | 6 ++++++ configure | 2 ++ src/support/glfw/glfw | 1 + src/support/glfw/glfw-rs | 1 + 4 files changed, 10 insertions(+) create mode 160000 src/support/glfw/glfw create mode 160000 src/support/glfw/glfw-rs diff --git a/.gitmodules b/.gitmodules index c08e1f13a16..a6ab58d9897 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/configure b/configure index cb7d9e135bf..6e037746f75 100755 --- a/configure +++ b/configure @@ -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 \ diff --git a/src/support/glfw/glfw b/src/support/glfw/glfw new file mode 160000 index 00000000000..738b78899bb --- /dev/null +++ b/src/support/glfw/glfw @@ -0,0 +1 @@ +Subproject commit 738b78899bb271258f55ae842e180de2c5ec87db diff --git a/src/support/glfw/glfw-rs b/src/support/glfw/glfw-rs new file mode 160000 index 00000000000..dc6b77d2df8 --- /dev/null +++ b/src/support/glfw/glfw-rs @@ -0,0 +1 @@ +Subproject commit dc6b77d2df8cb425a55c5ef48f77320de092fa19 From 39e759fb20582f257f04bf3f99429cfb8adcb2e0 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 4 Jul 2013 12:51:23 -0600 Subject: [PATCH 2/5] Fix clean targets. --- mk/clean.mk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mk/clean.mk b/mk/clean.mk index db92a5df392..a47b69c694f 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -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 From e0e5e1a2a7c33d265e1995a02211a8926980ce82 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 4 Jul 2013 12:53:48 -0600 Subject: [PATCH 3/5] Replace glut with glfw. Also fixes initial window size to get based on the windowing code instead of being hardcoded everywhere. This code works on HiDPI displays, but does not appropriately scale the output up yet. --- mk/sub.mk | 9 +- src/components/main/compositing/mod.rs | 41 ++++- src/components/main/pipeline.rs | 5 +- .../{glut_windowing.rs => glfw_windowing.rs} | 145 ++++++++---------- src/components/main/platform/mod.rs | 4 +- src/components/main/servo.rc | 2 +- src/components/main/windowing.rs | 2 - src/components/script/script_task.rs | 11 +- src/support/azure/rust-azure | 2 +- src/support/layers/rust-layers | 2 +- src/support/skia/skia | 2 +- 11 files changed, 116 insertions(+), 109 deletions(-) rename src/components/main/platform/common/{glut_windowing.rs => glfw_windowing.rs} (69%) diff --git a/mk/sub.mk b/mk/sub.mk index f0a66c2825a..79f67e72954 100644 --- a/mk/sub.mk +++ b/mk/sub.mk @@ -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) diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index ebd1a81636f..2dc4794a420 100644 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -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 { + 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>), /// Requests the compositors GL context. GetGLContext(Chan), /// 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(()) diff --git a/src/components/main/pipeline.rs b/src/components/main/pipeline.rs index ab9ccc6cade..42f76d1b537 100644 --- a/src/components/main/pipeline.rs +++ b/src/components/main/pipeline.rs @@ -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, diff --git a/src/components/main/platform/common/glut_windowing.rs b/src/components/main/platform/common/glfw_windowing.rs similarity index 69% rename from src/components/main/platform/common/glut_windowing.rs rename to src/components/main/platform/common/glfw_windowing.rs index 95fd22d9ef4..4aadfea486b 100644 --- a/src/components/main/platform/common/glut_windowing.rs +++ b/src/components/main/platform/common/glfw_windowing.rs @@ -2,10 +2,7 @@ * 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::{ResizeCallback, ScrollCallback, WindowMethods, WindowMouseEvent, WindowClickEvent}; @@ -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,15 +24,21 @@ pub struct Application; impl ApplicationMethods for Application { pub fn new() -> Application { - glut::init(); - glut::init_display_mode(DOUBLE); + glfw::private::WindowDataMap::init(); + unsafe { glfw::ll::glfwInit(); } Application } } +impl Drop for Application { + fn finalize(&self) { + unsafe { glfw::ll::glfwTerminate(); } + } +} + /// The type of a window. pub struct Window { - glut_window: glut::Window, + glfw_window: glfw::Window, composite_callback: Option, resize_callback: Option, @@ -60,13 +61,13 @@ pub struct Window { impl WindowMethods 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, @@ -86,68 +87,51 @@ impl WindowMethods 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 { + do window.glfw_window.set_refresh_callback |_win| { // FIXME(pcwalton): This will not work with multiple windows. match window.composite_callback { None => {} Some(callback) => callback(), } + window.present(); } - do glut::keyboard_func |key, _, _| { - window.handle_key(key) + do window.glfw_window.set_key_callback |_win, key, _scancode, action, mods| { + if action == glfw::PRESS { + window.handle_key(key, mods) + } } - 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 - }; - - match wheel { - 1 => window.handle_scroll(Point2D(delta, 0.0)), - 2 => window.handle_zoom(delta), - _ => window.handle_scroll(Point2D(0.0, delta)), - } + 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; + + 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 { - 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(); + self.glfw_window.swap_buffers(); } /// Registers a callback to run when a composite event occurs. @@ -187,12 +171,9 @@ impl WindowMethods 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 +195,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); diff --git a/src/components/main/platform/mod.rs b/src/components/main/platform/mod.rs index fdbd3bf42d9..3467234d0e6 100644 --- a/src/components/main/platform/mod.rs +++ b/src/components/main/platform/mod.rs @@ -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; } diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 3ee37198619..424e90b33f3 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -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; diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs index 8a102c055c4..edf4bd3800f 100644 --- a/src/components/main/windowing.rs +++ b/src/components/main/windowing.rs @@ -70,8 +70,6 @@ pub trait WindowMethods { /// 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. diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 4d46b241b3c..e6d2ef28436 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -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) -> @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, @@ -253,7 +254,8 @@ impl ScriptTask { script_chan: ScriptChan, constellation_chan: ConstellationChan, resource_task: ResourceTask, - image_cache_task: ImageCacheTask) { + image_cache_task: ImageCacheTask, + initial_size: Size2D) { 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(); } } diff --git a/src/support/azure/rust-azure b/src/support/azure/rust-azure index 6daaffe3b6c..d265202c324 160000 --- a/src/support/azure/rust-azure +++ b/src/support/azure/rust-azure @@ -1 +1 @@ -Subproject commit 6daaffe3b6cf226c6da4979d0fb907a8258b0288 +Subproject commit d265202c324d566a52d5946e08ad148dcf068252 diff --git a/src/support/layers/rust-layers b/src/support/layers/rust-layers index a1454f07d3d..41b967cf1a1 160000 --- a/src/support/layers/rust-layers +++ b/src/support/layers/rust-layers @@ -1 +1 @@ -Subproject commit a1454f07d3df11b16dc88bedf79d20693bfc3bb7 +Subproject commit 41b967cf1a1bf91227a4e8ee52c82a228eeb7e94 diff --git a/src/support/skia/skia b/src/support/skia/skia index 3f41e98925b..f889ab32a6f 160000 --- a/src/support/skia/skia +++ b/src/support/skia/skia @@ -1 +1 @@ -Subproject commit 3f41e98925b9d4c0d4074046388e73f0e0032ab9 +Subproject commit f889ab32a6fc249b2a8667a7c7c1e5c24d5daf7c From 870db398366bb5f2a19fdc301d8d7641c27cae0b Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 8 Jul 2013 18:41:33 -0600 Subject: [PATCH 4/5] Update to latest Rust. --- src/compiler/rust | 2 +- src/components/gfx/display_list.rs | 2 +- src/components/gfx/font.rs | 6 +- src/components/gfx/font_list.rs | 2 +- src/components/gfx/platform/linux/font.rs | 5 +- .../gfx/platform/linux/font_context.rs | 2 +- .../gfx/platform/linux/font_list.rs | 2 +- src/components/gfx/platform/macos/font.rs | 7 +- src/components/gfx/render_task.rs | 2 +- src/components/gfx/text/glyph.rs | 12 ++-- src/components/gfx/text/shaping/harfbuzz.rs | 4 +- src/components/gfx/text/text_run.rs | 4 +- src/components/main/constellation.rs | 4 +- src/components/main/layout/block.rs | 10 +-- src/components/main/layout/box.rs | 64 +++++++++++++++++- src/components/main/layout/float.rs | 8 +-- src/components/main/layout/float_context.rs | 12 ++-- src/components/main/layout/flow.rs | 22 +++--- src/components/main/layout/inline.rs | 26 +++---- src/components/main/layout/model.rs | 67 ------------------- src/components/main/layout/text.rs | 4 +- src/components/main/layout/util.rs | 14 ++-- src/components/main/pipeline.rs | 4 +- .../main/platform/common/glfw_windowing.rs | 24 ++----- .../platform/common/shared_gl_windowing.rs | 3 - src/components/main/servo.rc | 2 +- src/components/main/util/task.rs | 4 +- src/components/main/windowing.rs | 5 -- src/components/net/image_cache_task.rs | 6 +- src/components/net/resource_task.rs | 2 +- src/components/net/util.rs | 2 +- .../script/dom/bindings/clientrect.rs | 62 ----------------- .../script/dom/bindings/clientrectlist.rs | 45 ------------- .../dom/bindings/codegen/CodegenRust.py | 2 +- .../script/dom/bindings/document.rs | 9 ++- src/components/script/dom/bindings/element.rs | 17 +++-- src/components/script/dom/bindings/event.rs | 59 ---------------- .../script/dom/bindings/eventtarget.rs | 61 ----------------- .../script/dom/bindings/formdata.rs | 62 ----------------- .../script/dom/bindings/htmlcollection.rs | 45 ------------- src/components/script/dom/bindings/node.rs | 36 +--------- src/components/script/dom/bindings/utils.rs | 18 ++--- src/components/script/dom/clientrect.rs | 54 ++++++++++++++- src/components/script/dom/clientrectlist.rs | 39 ++++++++++- src/components/script/dom/event.rs | 52 ++++++++++++++ src/components/script/dom/eventtarget.rs | 58 +++++++++++++++- src/components/script/dom/formdata.rs | 57 +++++++++++++++- src/components/script/dom/htmlcollection.rs | 36 +++++++++- src/components/script/dom/node.rs | 34 +++++++++- src/components/script/dom/window.rs | 2 +- .../script/html/hubbub_html_parser.rs | 9 ++- src/components/script/script.rc | 6 -- src/components/script/script_task.rs | 14 ++-- src/components/util/cache.rs | 4 +- src/components/util/time.rs | 4 +- src/components/util/tree.rs | 6 +- src/components/util/url.rs | 5 +- src/platform/linux/rust-fontconfig | 2 +- src/platform/linux/rust-freetype | 2 +- src/platform/linux/rust-xlib | 2 +- src/platform/macos/rust-cocoa | 2 +- src/platform/macos/rust-core-foundation | 2 +- src/platform/macos/rust-core-text | 2 +- src/support/azure/rust-azure | 2 +- src/support/css/rust-css | 2 +- src/support/glfw/glfw-rs | 2 +- src/support/glut/rust-glut | 2 +- src/support/http-client/rust-http-client | 2 +- src/support/hubbub/rust-hubbub | 2 +- src/support/layers/rust-layers | 2 +- src/support/netsurfcss/rust-netsurfcss | 2 +- src/support/opengles/rust-opengles | 2 +- src/support/spidermonkey/rust-mozjs | 2 +- src/support/stb-image/rust-stb-image | 2 +- src/support/wapcaplet/rust-wapcaplet | 2 +- 75 files changed, 539 insertions(+), 626 deletions(-) delete mode 100644 src/components/script/dom/bindings/clientrect.rs delete mode 100644 src/components/script/dom/bindings/clientrectlist.rs delete mode 100644 src/components/script/dom/bindings/event.rs delete mode 100644 src/components/script/dom/bindings/eventtarget.rs delete mode 100644 src/components/script/dom/bindings/formdata.rs delete mode 100644 src/components/script/dom/bindings/htmlcollection.rs diff --git a/src/compiler/rust b/src/compiler/rust index f348465283d..5aa0ca9b2eb 160000 --- a/src/compiler/rust +++ b/src/compiler/rust @@ -1 +1 @@ -Subproject commit f348465283d6cd85b69bcdc1711d14985d154c39 +Subproject commit 5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46 diff --git a/src/components/gfx/display_list.rs b/src/components/gfx/display_list.rs index b284ebde1de..5d6f5188faa 100644 --- a/src/components/gfx/display_list.rs +++ b/src/components/gfx/display_list.rs @@ -48,7 +48,7 @@ impl DisplayList { /// 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) diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index 8e31f138c1e..7f4bddd7805 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -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) } diff --git a/src/components/gfx/font_list.rs b/src/components/gfx/font_list.rs index 77a18a60b5c..835a6916eac 100644 --- a/src/components/gfx/font_list.rs +++ b/src/components/gfx/font_list.rs @@ -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()) { diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index 95975c8be14..dc2eb8bdd3b 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -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) }; diff --git a/src/components/gfx/platform/linux/font_context.rs b/src/components/gfx/platform/linux/font_context.rs index 625ea0f490a..5a828ee7438 100644 --- a/src/components/gfx/platform/linux/font_context.rs +++ b/src/components/gfx/platform/linux/font_context.rs @@ -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); diff --git a/src/components/gfx/platform/linux/font_list.rs b/src/components/gfx/platform/linux/font_list.rs index 919eaa5c907..ae53929855c 100644 --- a/src/components/gfx/platform/linux/font_list.rs +++ b/src/components/gfx/platform/linux/font_list.rs @@ -139,7 +139,7 @@ struct AutoPattern { } impl Drop for AutoPattern { - fn finalize(&self) { + fn drop(&self) { unsafe { FcPatternDestroy(self.pattern); } diff --git a/src/components/gfx/platform/macos/font.rs b/src/components/gfx/platform/macos/font.rs index f4d0beddb31..793fa9a7589 100644 --- a/src/components/gfx/platform/macos/font.rs +++ b/src/components/gfx/platform/macos/font.rs @@ -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 { - 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); diff --git a/src/components/gfx/render_task.rs b/src/components/gfx/render_task.rs index e81337ef0ef..d704c2e8160 100644 --- a/src/components/gfx/render_task.rs +++ b/src/components/gfx/render_task.rs @@ -75,7 +75,7 @@ priv struct RenderTask { last_paint_msg: Option<(arc::ARC, Size2D)>, } -impl RenderTask { +impl RenderTask { pub fn create(id: uint, port: Port, compositor: C, diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs index a873b3b841a..f6569cc959b 100644 --- a/src/components/gfx/text/glyph.rs +++ b/src/components/gfx/text/glyph.rs @@ -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; } } diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index 560f25d72b4..851beb87c8c 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -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); diff --git a/src/components/gfx/text/text_run.rs b/src/components/gfx/text/text_run.rs index cfcbab54680..c436181977c 100644 --- a/src/components/gfx/text/text_run.rs +++ b/src/components/gfx/text/text_run.rs @@ -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); diff --git a/src/components/main/constellation.rs b/src/components/main/constellation.rs index 9439c0d7674..b35b24c9403 100644 --- a/src/components/main/constellation.rs +++ b/src/components/main/constellation.rs @@ -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(); diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index 91510190c04..d1827561f5c 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -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; } }); diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index c1008673402..fe4cd77aa89 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -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(&self, + list: &Cell>, + abs_bounds: &Rect) { + // 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"); + } + } + } + diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index 50d14307898..426ae8d6281 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -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; } }); diff --git a/src/components/main/layout/float_context.rs b/src/components/main/layout/float_context.rs index 1b1f192aece..f384c718d60 100644 --- a/src/components/main/layout/float_context.rs +++ b/src/components/main/layout/float_context.rs @@ -115,7 +115,7 @@ impl FloatContextBase{ } fn translate(&mut self, trans: Point2D) { - self.offset += trans; + self.offset = self.offset + trans; } fn last_float_pos(&self) -> Point2D { @@ -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) => { diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index 9ddd9b0e7e8..ccfe21b9250 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -314,25 +314,25 @@ impl<'self> FlowContext { } // Actual methods that do not require much flow-specific logic - pub fn foldl_all_boxes(&self, seed: B, cb: &fn(a: B, b: RenderBox) -> B) -> B { + pub fn foldl_all_boxes(&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(&self, + pub fn foldl_boxes_for_node(&self, node: AbstractNode, 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) => { diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index cd15e3e8ee5..616f142c76f 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -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) } diff --git a/src/components/main/layout/model.rs b/src/components/main/layout/model.rs index 104d4b0037e..4bd45dabe17 100644 --- a/src/components/main/layout/model.rs +++ b/src/components/main/layout/model.rs @@ -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(&self, - list: &Cell>, - abs_bounds: &Rect) { - // 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"); - } - } - -} - diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index 59093ed70ff..cf9d8f49bcc 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -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!("------------------"); diff --git a/src/components/main/layout/util.rs b/src/components/main/layout/util.rs index cc3d0267b7d..00d4dae218c 100644 --- a/src/components/main/layout/util.rs +++ b/src/components/main/layout/util.rs @@ -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!("----------------------------------"); diff --git a/src/components/main/pipeline.rs b/src/components/main/pipeline.rs index 42f76d1b537..45852132bbf 100644 --- a/src/components/main/pipeline.rs +++ b/src/components/main/pipeline.rs @@ -93,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())); } } diff --git a/src/components/main/platform/common/glfw_windowing.rs b/src/components/main/platform/common/glfw_windowing.rs index 4aadfea486b..6f9c509f245 100644 --- a/src/components/main/platform/common/glfw_windowing.rs +++ b/src/components/main/platform/common/glfw_windowing.rs @@ -4,7 +4,7 @@ //! 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}; @@ -24,15 +24,14 @@ pub struct Application; impl ApplicationMethods for Application { pub fn new() -> Application { - glfw::private::WindowDataMap::init(); - unsafe { glfw::ll::glfwInit(); } + glfw::init(); Application } } impl Drop for Application { - fn finalize(&self) { - unsafe { glfw::ll::glfwTerminate(); } + fn drop(&self) { + glfw::terminate(); } } @@ -40,7 +39,6 @@ impl Drop for Application { pub struct Window { glfw_window: glfw::Window, - composite_callback: Option, resize_callback: Option, load_url_callback: Option, mouse_callback: Option, @@ -69,7 +67,6 @@ impl WindowMethods for Window { let window = @mut Window { glfw_window: glfw_window, - composite_callback: None, resize_callback: None, load_url_callback: None, mouse_callback: None, @@ -94,14 +91,6 @@ impl WindowMethods for Window { Some(callback) => callback(width as uint, height as uint), } } - do window.glfw_window.set_refresh_callback |_win| { - // FIXME(pcwalton): This will not work with multiple windows. - match window.composite_callback { - None => {} - Some(callback) => callback(), - } - window.present(); - } do window.glfw_window.set_key_callback |_win, key, _scancode, action, mods| { if action == glfw::PRESS { window.handle_key(key, mods) @@ -134,11 +123,6 @@ impl WindowMethods for Window { self.glfw_window.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) - } - /// Registers a callback to run when a resize event occurs. pub fn set_resize_callback(&mut self, new_resize_callback: ResizeCallback) { self.resize_callback = Some(new_resize_callback) diff --git a/src/components/main/platform/common/shared_gl_windowing.rs b/src/components/main/platform/common/shared_gl_windowing.rs index aa4a84b12cd..268bb6386d0 100644 --- a/src/components/main/platform/common/shared_gl_windowing.rs +++ b/src/components/main/platform/common/shared_gl_windowing.rs @@ -47,9 +47,6 @@ impl WindowingMethods 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) {} diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 424e90b33f3..10986322516 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -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))) } diff --git a/src/components/main/util/task.rs b/src/components/main/util/task.rs index d45b10c7465..0300fa59200 100644 --- a/src/components/main/util/task.rs +++ b/src/components/main/util/task.rs @@ -7,7 +7,7 @@ use std::comm; use std::comm::{Chan, Port}; use std::task; -pub fn spawn_listener(f: ~fn(Port)) -> Chan { +pub fn spawn_listener(f: ~fn(Port)) -> Chan { let (setup_po, setup_ch) = comm::stream(); do task::spawn { let (po, ch) = comm::stream(); @@ -17,7 +17,7 @@ pub fn spawn_listener(f: ~fn(Port)) -> Chan { setup_po.recv() } -pub fn spawn_conversation(f: ~fn(Port, Chan)) -> (Port, Chan) { +pub fn spawn_conversation(f: ~fn(Port, Chan)) -> (Port, Chan) { let (from_child, to_parent) = comm::stream(); let to_parent = Cell::new(to_parent); let to_child = do spawn_listener |from_parent| { diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs index edf4bd3800f..1edd0114de1 100644 --- a/src/components/main/windowing.rs +++ b/src/components/main/windowing.rs @@ -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 { /// 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. diff --git a/src/components/net/image_cache_task.rs b/src/components/net/image_cache_task.rs index e4bef56758c..aa0440ff701 100644 --- a/src/components/net/image_cache_task.rs +++ b/src/components/net/image_cache_task.rs @@ -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); diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 958705c8885..457cd6dfd35 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -105,7 +105,7 @@ impl ResourceManager { } fn get_loader_factory(&self, url: &Url) -> Option { - 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 { diff --git a/src/components/net/util.rs b/src/components/net/util.rs index 92f142f2db7..342f7df5d4e 100644 --- a/src/components/net/util.rs +++ b/src/components/net/util.rs @@ -6,7 +6,7 @@ use std::comm; use std::comm::{Chan, Port}; use std::task; -pub fn spawn_listener(f: ~fn(Port)) -> Chan { +pub fn spawn_listener(f: ~fn(Port)) -> Chan { let (setup_port, setup_chan) = comm::stream(); do task::spawn { let (port, chan) = comm::stream(); diff --git a/src/components/script/dom/bindings/clientrect.rs b/src/components/script/dom/bindings/clientrect.rs deleted file mode 100644 index b910ff1f41c..00000000000 --- a/src/components/script/dom/bindings/clientrect.rs +++ /dev/null @@ -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; - } - } -} diff --git a/src/components/script/dom/bindings/clientrectlist.rs b/src/components/script/dom/bindings/clientrectlist.rs deleted file mode 100644 index a6d19a73a10..00000000000 --- a/src/components/script/dom/bindings/clientrectlist.rs +++ /dev/null @@ -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 - } - } -} diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 66984d6c885..055cb0ce488 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -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))) diff --git a/src/components/script/dom/bindings/document.rs b/src/components/script/dom/bindings/document.rs index 731e6619bd9..685b7d2599f 100644 --- a/src/components/script/dom/bindings/document.rs +++ b/src/components/script/dom/bindings/document.rs @@ -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, diff --git a/src/components/script/dom/bindings/element.rs b/src/components/script/dom/bindings/element.rs index b79daf75db7..b37c3f1a43b 100644 --- a/src/components/script/dom/bindings/element.rs +++ b/src/components/script/dom/bindings/element.rs @@ -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 { diff --git a/src/components/script/dom/bindings/event.rs b/src/components/script/dom/bindings/event.rs deleted file mode 100644 index 2197646e188..00000000000 --- a/src/components/script/dom/bindings/event.rs +++ /dev/null @@ -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; - } - } -} diff --git a/src/components/script/dom/bindings/eventtarget.rs b/src/components/script/dom/bindings/eventtarget.rs deleted file mode 100644 index ffb804d905c..00000000000 --- a/src/components/script/dom/bindings/eventtarget.rs +++ /dev/null @@ -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; - } - } -} diff --git a/src/components/script/dom/bindings/formdata.rs b/src/components/script/dom/bindings/formdata.rs deleted file mode 100644 index eaf25a3ebe2..00000000000 --- a/src/components/script/dom/bindings/formdata.rs +++ /dev/null @@ -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; - } - } -} diff --git a/src/components/script/dom/bindings/htmlcollection.rs b/src/components/script/dom/bindings/htmlcollection.rs deleted file mode 100644 index fe7ddf3dfe0..00000000000 --- a/src/components/script/dom/bindings/htmlcollection.rs +++ /dev/null @@ -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) - } -} diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs index 49a857405a9..b5da86320bb 100644 --- a/src/components/script/dom/bindings/node.rs +++ b/src/components/script/dom/bindings/node.rs @@ -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 { - fn getNodeType(&self) -> i32 { - match self.type_id { - ElementNodeTypeId(_) => 1, - TextNodeTypeId => 3, - CommentNodeTypeId => 8, - DoctypeNodeTypeId => 10 - } - } - - fn getNextSibling(&mut self) -> Option<&mut AbstractNode> { - 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> { - 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)); diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index f72aad15ed9..5fc2fcfc647 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -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 { 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 { 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; } diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index ccddcff788f..cd3f9f344e6 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -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; + } + } +} diff --git a/src/components/script/dom/clientrectlist.rs b/src/components/script/dom/clientrectlist.rs index 6165f13e6e3..2fdbc108f36 100644 --- a/src/components/script/dom/clientrectlist.rs +++ b/src/components/script/dom/clientrectlist.rs @@ -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 + } + } +} diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index 6b4be15b701..952a8a227cd 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -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; + } + } +} diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index e4066ccb8d4..d5f3ff309e8 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -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() } } -} \ No newline at end of file + + 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; + } + } +} diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index cda6b7ae272..5c3d49e1371 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -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) { let blob = BlobData { blob: value, @@ -35,4 +52,42 @@ impl FormData { pub fn Append_(&mut self, name: DOMString, value: DOMString) { self.data.insert(name.to_str(), StringData(value)); } -} \ No newline at end of file +} + +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; + } + } +} diff --git a/src/components/script/dom/htmlcollection.rs b/src/components/script/dom/htmlcollection.rs index 403469061b8..da0b29e4e40 100644 --- a/src/components/script/dom/htmlcollection.rs +++ b/src/components/script/dom/htmlcollection.rs @@ -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 { @@ -24,6 +27,15 @@ impl HTMLCollection { collection.init_wrapper(); 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) + } +} diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index c573f9912fb..1dd916b52b1 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -367,10 +367,10 @@ impl AbstractNode { 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? @@ -427,7 +427,35 @@ impl Node { 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> { + 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> { + 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. diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 41f99eaa9e9..7c69ea5aee5 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -34,7 +34,7 @@ pub struct Window { } impl Drop for Window { - fn finalize(&self) { + fn drop(&self) { self.timer_chan.send(TimerMessage_Close); } } diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 9540fcc87d4..da3a2c32e75 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -105,7 +105,7 @@ fn css_link_listener(to_parent: Chan>, // 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())); } } diff --git a/src/components/script/script.rc b/src/components/script/script.rc index 344ff74ca57..a9f6a5c8a00 100644 --- a/src/components/script/script.rc +++ b/src/components/script/script.rc @@ -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; diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index e6d2ef28436..8111ccda72d 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -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); } @@ -247,7 +247,7 @@ impl ScriptTask { } } - pub fn create(id: uint, + pub fn create(id: uint, compositor: C, layout_chan: LayoutChan, script_port: Port, @@ -356,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. // @@ -419,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); } @@ -501,7 +501,7 @@ impl ScriptTask { } /// Sends the given query to layout. - pub fn query_layout(&mut self, query: LayoutQuery, response_port: Port>) -> Result { + pub fn query_layout(&mut self, query: LayoutQuery, response_port: Port>) -> Result { self.join_layout(); self.layout_chan.send(QueryMsg(query)); response_port.recv() diff --git a/src/components/util/cache.rs b/src/components/util/cache.rs index 5e35a440088..b5169211172 100644 --- a/src/components/util/cache.rs +++ b/src/components/util/cache.rs @@ -143,14 +143,14 @@ impl Cache for LRUCache { } fn find(&mut self, key: &K) -> Option { - 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); diff --git a/src/components/util/time.rs b/src/components/util/time.rs index ac94abcfb7a..b8c88753974 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -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()); diff --git a/src/components/util/tree.rs b/src/components/util/tree.rs index 23b8ca80d77..94ceb5e1b36 100644 --- a/src/components/util/tree.rs +++ b/src/components/util/tree.rs @@ -152,7 +152,8 @@ impl,N:TreeNode> 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,N:TreeNode> 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; } } diff --git a/src/components/util/url.rs b/src/components/util/url.rs index 01a8f9b13d1..0cb8a32c3ce 100644 --- a/src/components/util/url.rs +++ b/src/components/util/url.rs @@ -44,9 +44,10 @@ pub fn make_url(str_url: ~str, current_url: Option) -> 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 } diff --git a/src/platform/linux/rust-fontconfig b/src/platform/linux/rust-fontconfig index faca1281aaf..78f84af79eb 160000 --- a/src/platform/linux/rust-fontconfig +++ b/src/platform/linux/rust-fontconfig @@ -1 +1 @@ -Subproject commit faca1281aaf112e96ee03041744fe85ac4273192 +Subproject commit 78f84af79eb653fde2d50621fc3631043fa6fa9e diff --git a/src/platform/linux/rust-freetype b/src/platform/linux/rust-freetype index 5247c3e97f7..980254dd840 160000 --- a/src/platform/linux/rust-freetype +++ b/src/platform/linux/rust-freetype @@ -1 +1 @@ -Subproject commit 5247c3e97f7eafa336c8a028a3175c3bc3a2d95a +Subproject commit 980254dd840772c8ee5f37056e7bd9f4d93d5377 diff --git a/src/platform/linux/rust-xlib b/src/platform/linux/rust-xlib index 788f41a6e92..641af36389a 160000 --- a/src/platform/linux/rust-xlib +++ b/src/platform/linux/rust-xlib @@ -1 +1 @@ -Subproject commit 788f41a6e924e5c3f9d254d3e5dabf2b3e622f00 +Subproject commit 641af36389a7592ef0faea2488ec08bd144e9bfe diff --git a/src/platform/macos/rust-cocoa b/src/platform/macos/rust-cocoa index 3ef4cf7fdaa..23bb1728984 160000 --- a/src/platform/macos/rust-cocoa +++ b/src/platform/macos/rust-cocoa @@ -1 +1 @@ -Subproject commit 3ef4cf7fdaaaa51026ec546a71426ff03a0899fd +Subproject commit 23bb17289846dd9486f633c0b5187c7ba333d943 diff --git a/src/platform/macos/rust-core-foundation b/src/platform/macos/rust-core-foundation index ea8d2bd026c..77e9ed24ca7 160000 --- a/src/platform/macos/rust-core-foundation +++ b/src/platform/macos/rust-core-foundation @@ -1 +1 @@ -Subproject commit ea8d2bd026cd91d3fb5fd753677da3fd7d21dbab +Subproject commit 77e9ed24ca7bb0f9a0b33d7fd888de2905dddcd4 diff --git a/src/platform/macos/rust-core-text b/src/platform/macos/rust-core-text index 72c7673ac50..313e26f9202 160000 --- a/src/platform/macos/rust-core-text +++ b/src/platform/macos/rust-core-text @@ -1 +1 @@ -Subproject commit 72c7673ac50cc1ffb518de65022fb034df334ed9 +Subproject commit 313e26f9202b44d09043485671bc903786c328e7 diff --git a/src/support/azure/rust-azure b/src/support/azure/rust-azure index d265202c324..ba24db51b38 160000 --- a/src/support/azure/rust-azure +++ b/src/support/azure/rust-azure @@ -1 +1 @@ -Subproject commit d265202c324d566a52d5946e08ad148dcf068252 +Subproject commit ba24db51b38c9875e1356f7bc08c13a683071710 diff --git a/src/support/css/rust-css b/src/support/css/rust-css index 5e8c30cc692..7a584804a98 160000 --- a/src/support/css/rust-css +++ b/src/support/css/rust-css @@ -1 +1 @@ -Subproject commit 5e8c30cc69286e68ba9bf843f146a580381bff83 +Subproject commit 7a584804a98b5731fb53d216c3f059e5a0c7ea5c diff --git a/src/support/glfw/glfw-rs b/src/support/glfw/glfw-rs index dc6b77d2df8..8999e447127 160000 --- a/src/support/glfw/glfw-rs +++ b/src/support/glfw/glfw-rs @@ -1 +1 @@ -Subproject commit dc6b77d2df8cb425a55c5ef48f77320de092fa19 +Subproject commit 8999e447127c8674cdf130a2bd1759d9f94cd6ad diff --git a/src/support/glut/rust-glut b/src/support/glut/rust-glut index 42931c8e089..8f253edf62c 160000 --- a/src/support/glut/rust-glut +++ b/src/support/glut/rust-glut @@ -1 +1 @@ -Subproject commit 42931c8e0894c0d3d70d29abdf16639b30e6bf92 +Subproject commit 8f253edf62cfadfa18edb773aebd74bd62647ce4 diff --git a/src/support/http-client/rust-http-client b/src/support/http-client/rust-http-client index d88f23d1541..17afe7a4b5d 160000 --- a/src/support/http-client/rust-http-client +++ b/src/support/http-client/rust-http-client @@ -1 +1 @@ -Subproject commit d88f23d1541019baaedb350ce275349ad2ca304e +Subproject commit 17afe7a4b5d40dd3da792cd5e22e1e6b48225f21 diff --git a/src/support/hubbub/rust-hubbub b/src/support/hubbub/rust-hubbub index c549e77a677..09a6c29e0a9 160000 --- a/src/support/hubbub/rust-hubbub +++ b/src/support/hubbub/rust-hubbub @@ -1 +1 @@ -Subproject commit c549e77a677a6f76f8c9a42682d719d4ac20c3fc +Subproject commit 09a6c29e0a9432d67eeb583324c17766aa1155e3 diff --git a/src/support/layers/rust-layers b/src/support/layers/rust-layers index 41b967cf1a1..a8843ea0842 160000 --- a/src/support/layers/rust-layers +++ b/src/support/layers/rust-layers @@ -1 +1 @@ -Subproject commit 41b967cf1a1bf91227a4e8ee52c82a228eeb7e94 +Subproject commit a8843ea084262773c31916e3a52c6dacea135153 diff --git a/src/support/netsurfcss/rust-netsurfcss b/src/support/netsurfcss/rust-netsurfcss index afdd72f326f..aecdedca9eb 160000 --- a/src/support/netsurfcss/rust-netsurfcss +++ b/src/support/netsurfcss/rust-netsurfcss @@ -1 +1 @@ -Subproject commit afdd72f326f720afcfa7cea6005b20924a441570 +Subproject commit aecdedca9ebef5ce6cf4d2dd38e2c312c0907f1d diff --git a/src/support/opengles/rust-opengles b/src/support/opengles/rust-opengles index d7c05e81acb..17bd4bbc049 160000 --- a/src/support/opengles/rust-opengles +++ b/src/support/opengles/rust-opengles @@ -1 +1 @@ -Subproject commit d7c05e81acb66717f1a86ad67f391c9bc0961bbf +Subproject commit 17bd4bbc04942e7de9eae76c0f8a76dfcb3dc9fc diff --git a/src/support/spidermonkey/rust-mozjs b/src/support/spidermonkey/rust-mozjs index af080e2ab3c..26dc2e896a5 160000 --- a/src/support/spidermonkey/rust-mozjs +++ b/src/support/spidermonkey/rust-mozjs @@ -1 +1 @@ -Subproject commit af080e2ab3ca871a6e77339eb752e59b3903b068 +Subproject commit 26dc2e896a57a28f03be43df46868e1a41a15807 diff --git a/src/support/stb-image/rust-stb-image b/src/support/stb-image/rust-stb-image index 577bebc7c14..86c9525ec4a 160000 --- a/src/support/stb-image/rust-stb-image +++ b/src/support/stb-image/rust-stb-image @@ -1 +1 @@ -Subproject commit 577bebc7c14f391cf5faddc16bda194da6a3e7b6 +Subproject commit 86c9525ec4aa886c5afe4ec5202ca3a0d400d155 diff --git a/src/support/wapcaplet/rust-wapcaplet b/src/support/wapcaplet/rust-wapcaplet index c726370b54f..5ed1ff9da43 160000 --- a/src/support/wapcaplet/rust-wapcaplet +++ b/src/support/wapcaplet/rust-wapcaplet @@ -1 +1 @@ -Subproject commit c726370b54f573f7f5d67619f40b0b92d55919c7 +Subproject commit 5ed1ff9da4301dd3efd7102f3607fd353a099804 From cfc7491b1f1c2c49472da07f6f97c7ef9f1f165e Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 9 Jul 2013 16:26:33 -0600 Subject: [PATCH 5/5] Add Makefile trigger for forcing clean-rust to happen. --- Makefile.in | 7 ++++++- src/compiler/rust-auto-clean-trigger | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/compiler/rust-auto-clean-trigger diff --git a/Makefile.in b/Makefile.in index b2ad90cb475..242e15aa7d7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/src/compiler/rust-auto-clean-trigger b/src/compiler/rust-auto-clean-trigger new file mode 100644 index 00000000000..0ca4dcbb9d6 --- /dev/null +++ b/src/compiler/rust-auto-clean-trigger @@ -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