diff --git a/.gitmodules b/.gitmodules index e95e06940ca..cbb9898d82c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,9 +22,6 @@ [submodule "src/support/opengles/rust-opengles"] path = src/support/opengles/rust-opengles url = https://github.com/mozilla-servo/rust-opengles.git -[submodule "src/support/glut/rust-glut"] - path = src/support/glut/rust-glut - url = https://github.com/mozilla-servo/rust-glut.git [submodule "src/support/layers/rust-layers"] path = src/support/layers/rust-layers url = https://github.com/mozilla-servo/rust-layers.git diff --git a/Makefile.in b/Makefile.in index 5d136a17fc7..e64ac6a1f8e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,7 +29,7 @@ B := $(CFG_BUILD_DIR) MKFILE_DEPS := config.stamp $(call rwildcard,$(S)mk/,*) -CFG_RUSTC_FLAGS := $(RUSTFLAGS) -A default_methods +CFG_RUSTC_FLAGS := $(RUSTFLAGS) ifdef CFG_DISABLE_OPTIMIZE $(info cfg: disabling rustc optimization (CFG_DISABLE_OPTIMIZE)) @@ -235,23 +235,23 @@ all: src/compiler/rust/rust-auto-clean-stamp servo package $(DONE_util): $(DEPS_util) @$(call E, compile: $@) - $(Q)$(RUSTC) $(RFLAGS_util) -o $@ $< && touch $@ + $(Q)$(RUSTC) $(RFLAGS_util) --out-dir src/components/util $< && touch $@ $(DONE_net): $(DEPS_net) @$(call E, compile: $@) - $(Q)$(RUSTC) $(RFLAGS_net) -o $@ $< && touch $@ + $(Q)$(RUSTC) $(RFLAGS_net) --out-dir src/components/net $< && touch $@ $(DONE_msg): $(DEPS_msg) @$(call E, compile: $@) - $(Q)$(RUSTC) $(RFLAGS_msg) -o $@ $< && touch $@ + $(Q)$(RUSTC) $(RFLAGS_msg) --out-dir src/components/msg $< && touch $@ $(DONE_gfx): $(DEPS_gfx) @$(call E, compile: $@) - $(Q)$(RUSTC) $(RFLAGS_gfx) -o $@ $< && touch $@ + $(Q)$(RUSTC) $(RFLAGS_gfx) --out-dir src/components/gfx $< && touch $@ $(DONE_script): $(DEPS_script) @$(call E, compile: $@) - $(Q)$(RUSTC) $(RFLAGS_script) -o $@ $< && touch $@ + $(Q)$(RUSTC) $(RFLAGS_script) --out-dir src/components/script $< && touch $@ BINDINGS_SRC = $(S)/src/components/script/dom/bindings/codegen diff --git a/configure b/configure index f0c24ba25e6..88f580db82c 100755 --- a/configure +++ b/configure @@ -403,11 +403,9 @@ CFG_SUBMODULES="\ support/css/rust-css \ support/css/rust-cssparser \ 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 \ support/hubbub/rust-hubbub \ support/layers/rust-layers \ diff --git a/mk/sub.mk b/mk/sub.mk index 79f67e72954..38d748d9597 100644 --- a/mk/sub.mk +++ b/mk/sub.mk @@ -51,10 +51,6 @@ DEPS_glfw-rs += \ glfw \ $(NULL) -DEPS_rust-glut += \ - rust-opengles \ - $(NULL) - DEPS_rust-layers += \ rust-geom \ rust-opengles \ @@ -143,10 +139,6 @@ DEPS_rust-layers += \ rust-cocoa \ $(NULL) -DEPS_rust-glut += \ - rust-cocoa \ - $(NULL) - endif ifeq ($(CFG_OSTYPE),unknown-linux-gnu) diff --git a/src/compiler/rust b/src/compiler/rust index 5aa0ca9b2eb..0a677bcf6e3 160000 --- a/src/compiler/rust +++ b/src/compiler/rust @@ -1 +1 @@ -Subproject commit 5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46 +Subproject commit 0a677bcf6e359f6f013a7e580ef467b5f389e5b7 diff --git a/src/compiler/rust-auto-clean-trigger b/src/compiler/rust-auto-clean-trigger index 0ca4dcbb9d6..97ca03fb5ac 100644 --- a/src/compiler/rust-auto-clean-trigger +++ b/src/compiler/rust-auto-clean-trigger @@ -1,4 +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 +2013-08-15 diff --git a/src/components/gfx/display_list.rs b/src/components/gfx/display_list.rs index 3c220974b9b..8a5bb04d7a4 100644 --- a/src/components/gfx/display_list.rs +++ b/src/components/gfx/display_list.rs @@ -23,7 +23,7 @@ use std::cast::transmute_region; use geom::{Point2D, Rect, Size2D, SideOffsets2D}; use servo_net::image::base::Image; use servo_util::range::Range; -use extra::arc::ARC; +use extra::arc::Arc; /// A list of rendering operations to be performed. pub struct DisplayList { @@ -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.iter().advance |item| { + for item in self.list.iter() { // FIXME(Issue #150): crashes //debug!("drawing %?", *item); item.draw_into_context(render_context) @@ -93,7 +93,7 @@ pub struct TextDisplayItem { /// Renders an image. pub struct ImageDisplayItem { base: BaseDisplayItem, - image: ARC<~Image>, + image: Arc<~Image>, } /// Renders a border. @@ -156,7 +156,7 @@ impl DisplayItem { } } - fn base<'a>(&'a self) -> &'a BaseDisplayItem { + pub fn base<'a>(&'a self) -> &'a BaseDisplayItem { // FIXME(tkuehn): Workaround for Rust region bug. unsafe { match *self { @@ -168,7 +168,7 @@ impl DisplayItem { } } - fn bounds(&self) -> Rect { + pub fn bounds(&self) -> Rect { self.base().bounds } } diff --git a/src/components/gfx/font.rs b/src/components/gfx/font.rs index 7f4bddd7805..c8b2680dbfb 100644 --- a/src/components/gfx/font.rs +++ b/src/components/gfx/font.rs @@ -10,7 +10,6 @@ use platform::font::{FontHandle, FontTable}; use render_context::RenderContext; use servo_util::range::Range; use std::cast; -use std::result; use std::ptr; use std::str; use std::vec; @@ -18,7 +17,7 @@ use servo_util::cache::{Cache, HashCache}; use text::glyph::{GlyphStore, GlyphIndex}; use text::shaping::ShaperMethods; use text::{Shaper, TextRun}; -use extra::arc::ARC; +use extra::arc::Arc; use azure::{AzFloat, AzScaledFontRef}; use azure::scaled_font::ScaledFont; @@ -58,12 +57,12 @@ pub type FractionalPixel = float; pub type FontTableTag = u32; -trait FontTableTagConversions { - pub fn tag_to_str(&self) -> ~str; +pub trait FontTableTagConversions { + fn tag_to_str(&self) -> ~str; } impl FontTableTagConversions for FontTableTag { - pub fn tag_to_str(&self) -> ~str { + fn tag_to_str(&self) -> ~str { unsafe { let reversed = str::raw::from_buf_len(cast::transmute(self), 4); return str::from_chars([reversed.char_at(3), @@ -183,7 +182,7 @@ impl FontGroup { pub fn new(families: @str, style: &UsedFontStyle, fonts: ~[@mut Font]) -> FontGroup { FontGroup { families: families, - style: copy *style, + style: (*style).clone(), fonts: fonts, } } @@ -240,7 +239,7 @@ pub struct Font { metrics: FontMetrics, backend: BackendType, profiler_chan: ProfilerChan, - shape_cache: HashCache<~str, ARC>, + shape_cache: HashCache<~str, Arc>, } impl Font { @@ -252,9 +251,9 @@ impl Font { -> Result<@mut Font, ()> { let handle = FontHandleMethods::new_from_buffer(&ctx.handle, buffer, style); let handle: FontHandle = if handle.is_ok() { - result::unwrap(handle) + handle.unwrap() } else { - return Err(handle.get_err()); + return Err(handle.unwrap_err()); }; let metrics = handle.get_metrics(); @@ -264,7 +263,7 @@ impl Font { handle: handle, azure_font: None, shaper: None, - style: copy *style, + style: (*style).clone(), metrics: metrics, backend: backend, profiler_chan: profiler_chan, @@ -281,7 +280,7 @@ impl Font { handle: handle, azure_font: None, shaper: None, - style: copy *style, + style: (*style).clone(), metrics: metrics, backend: backend, profiler_chan: profiler_chan, @@ -302,7 +301,7 @@ impl Font { return Ok(Font::new_from_adopted_handle(fctx, styled_handle, style, backend, profiler_chan)); } - priv fn get_shaper(@mut self) -> @Shaper { + fn get_shaper(@mut self) -> @Shaper { // fast path: already created a shaper match self.shaper { Some(shaper) => { return shaper; }, @@ -333,7 +332,7 @@ impl Font { // TODO: this should return a borrowed pointer, but I can't figure // out why borrowck doesn't like my implementation. - priv fn get_azure_font(&mut self) -> AzScaledFontRef { + fn get_azure_font(&mut self) -> AzScaledFontRef { // fast path: we've already created the azure font resource match self.azure_font { Some(ref azfont) => return azfont.get_ref(), @@ -347,14 +346,14 @@ impl Font { } #[cfg(target_os="macos")] - priv fn create_azure_font(&mut self) -> ScaledFont { + fn create_azure_font(&mut self) -> ScaledFont { let cg_font = self.handle.get_CGFont(); let size = self.style.pt_size as AzFloat; ScaledFont::new(self.backend, &cg_font, size) } #[cfg(target_os="linux")] - priv fn create_azure_font(&self) -> ScaledFont { + fn create_azure_font(&self) -> ScaledFont { let freetype_font = self.handle.face; let size = self.style.pt_size as AzFloat; ScaledFont::new(self.backend, freetype_font, size) @@ -387,14 +386,14 @@ impl Font { fields: 0x0200 as uint16_t }; - let mut origin = copy baseline_origin; + let mut origin = baseline_origin.clone(); let mut azglyphs = ~[]; 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| { - let glyph_advance = glyph.advance_(); - let glyph_offset = glyph.offset().get_or_default(Au::zero_point()); + for (glyphs, _offset, slice_range) in run.iter_slices_for_range(range) { + for (_i, glyph) in glyphs.iter_glyphs_for_char_range(&slice_range) { + let glyph_advance = glyph.advance(); + let glyph_offset = glyph.offset().unwrap_or_default(Au::zero_point()); let azglyph = struct__AzGlyph { mIndex: glyph.index() as uint32_t, @@ -431,9 +430,9 @@ impl Font { // TODO(Issue #199): alter advance direction for RTL // TODO(Issue #98): using inter-char and inter-word spacing settings when measuring text 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 = advance + glyph.advance_(); + for (glyphs, _offset, slice_range) in run.iter_slices_for_range(range) { + for (_i, glyph) in glyphs.iter_glyphs_for_char_range(&slice_range) { + advance = advance + glyph.advance(); } } RunMetrics::new(advance, self.metrics.ascent, self.metrics.descent) @@ -444,25 +443,25 @@ impl Font { slice_range: &Range) -> RunMetrics { let mut advance = Au(0); - for glyphs.iter_glyphs_for_char_range(slice_range) |_i, glyph| { - advance = advance + glyph.advance_(); + for (_i, glyph) in glyphs.iter_glyphs_for_char_range(slice_range) { + advance = advance + glyph.advance(); } RunMetrics::new(advance, self.metrics.ascent, self.metrics.descent) } - pub fn shape_text(@mut self, text: ~str, is_whitespace: bool) -> ARC { + pub fn shape_text(@mut self, text: ~str, is_whitespace: bool) -> Arc { do profile(time::LayoutShapingCategory, self.profiler_chan.clone()) { let shaper = self.get_shaper(); do self.shape_cache.find_or_create(&text) |txt| { let mut glyphs = GlyphStore::new(text.char_len(), is_whitespace); shaper.shape_text(*txt, &mut glyphs); - ARC(glyphs) + Arc::new(glyphs) } } } pub fn get_descriptor(&self) -> FontDescriptor { - FontDescriptor::new(copy self.style, SelectorPlatformIdentifier(self.handle.face_identifier())) + FontDescriptor::new(self.style.clone(), SelectorPlatformIdentifier(self.handle.face_identifier())) } pub fn glyph_index(&self, codepoint: char) -> Option { diff --git a/src/components/gfx/font_context.rs b/src/components/gfx/font_context.rs index 60f58d9571f..a9d71cf1aa7 100644 --- a/src/components/gfx/font_context.rs +++ b/src/components/gfx/font_context.rs @@ -14,7 +14,6 @@ use platform::font_context::FontContextHandle; use azure::azure_hl::BackendType; use std::hashmap::HashMap; -use std::result; // TODO(Rust #3934): creating lots of new dummy styles is a workaround // for not being able to store symbolic enums in top-level constants. @@ -34,7 +33,6 @@ pub trait FontContextHandleMethods { fn create_font_from_identifier(&self, ~str, UsedFontStyle) -> Result; } -#[allow(non_implicitly_copyable_typarams)] pub struct FontContext { instance_cache: LRUCache, font_list: Option, // only needed by layout @@ -45,7 +43,6 @@ pub struct FontContext { profiler_chan: ProfilerChan, } -#[allow(non_implicitly_copyable_typarams)] impl<'self> FontContext { pub fn new(backend: BackendType, needs_font_list: bool, @@ -75,7 +72,7 @@ impl<'self> FontContext { } } - priv fn get_font_list(&'self self) -> &'self FontList { + fn get_font_list(&'self self) -> &'self FontList { self.font_list.get_ref() } @@ -113,23 +110,23 @@ impl<'self> FontContext { } } - priv fn transform_family(&self, family: &str) -> ~str { + fn transform_family(&self, family: &str) -> ~str { // FIXME: Need a find_like() in HashMap. let family = family.to_str(); debug!("(transform family) searching for `%s`", family); match self.generic_fonts.find(&family) { None => family, - Some(mapped_family) => copy *mapped_family + Some(mapped_family) => (*mapped_family).clone() } } - priv fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> @FontGroup { + fn create_font_group(&mut self, style: &SpecifiedFontStyle) -> @FontGroup { let mut fonts = ~[]; debug!("(create font group) --- starting ---"); // TODO(Issue #193): make iteration over 'font-family' more robust. - for style.families.split_iter(',').advance |family| { + for family in style.families.split_iter(',') { let family_name = family.trim(); let transformed_family_name = self.transform_family(family_name); debug!("(create font group) transformed family is `%s`", transformed_family_name); @@ -139,16 +136,16 @@ impl<'self> FontContext { }; let mut found = false; - for result.iter().advance |font_entry| { + for font_entry in result.iter() { found = true; let font_id = SelectorPlatformIdentifier(font_entry.handle.face_identifier()); - let font_desc = FontDescriptor::new(copy *style, font_id); + let font_desc = FontDescriptor::new((*style).clone(), font_id); let instance = self.get_font_by_descriptor(&font_desc); - do result::iter(&instance) |font: &@mut Font| { fonts.push(*font); } + for font in instance.iter() { fonts.push(*font); } }; if !found { @@ -158,19 +155,19 @@ impl<'self> FontContext { let last_resort = FontList::get_last_resort_font_families(); - for last_resort.iter().advance |family| { + for family in last_resort.iter() { let result = do self.font_list.chain_ref |fl| { fl.find_font_in_family(*family, style) }; - for result.iter().advance |font_entry| { + for font_entry in result.iter() { let font_id = SelectorPlatformIdentifier(font_entry.handle.face_identifier()); - let font_desc = FontDescriptor::new(copy *style, font_id); + let font_desc = FontDescriptor::new((*style).clone(), font_id); let instance = self.get_font_by_descriptor(&font_desc); - do result::iter(&instance) |font: &@mut Font| { + for font in instance.iter() { fonts.push(*font); } } @@ -178,26 +175,26 @@ impl<'self> FontContext { assert!(fonts.len() > 0); // TODO(Issue #179): Split FontStyle into specified and used styles - let used_style = copy *style; + let used_style = (*style).clone(); debug!("(create font group) --- finished ---"); @FontGroup::new(style.families.to_managed(), &used_style, fonts) } - priv fn create_font_instance(&self, desc: &FontDescriptor) -> Result<@mut Font, ()> { + fn create_font_instance(&self, desc: &FontDescriptor) -> Result<@mut Font, ()> { return match &desc.selector { // TODO(Issue #174): implement by-platform-name font selectors. &SelectorPlatformIdentifier(ref identifier) => { - let result_handle = self.handle.create_font_from_identifier(copy *identifier, - copy desc.style); - result::chain(result_handle, |handle| { + let result_handle = self.handle.create_font_from_identifier((*identifier).clone(), + desc.style.clone()); + do result_handle.chain |handle| { Ok(Font::new_from_adopted_handle(self, handle, &desc.style, self.backend, self.profiler_chan.clone())) - }) + } } }; } diff --git a/src/components/gfx/font_list.rs b/src/components/gfx/font_list.rs index 835a6916eac..f3d46bb7cce 100644 --- a/src/components/gfx/font_list.rs +++ b/src/components/gfx/font_list.rs @@ -42,7 +42,7 @@ impl FontList { list } - priv fn refresh(&mut self, _: &FontContextHandle) { + fn refresh(&mut self, _: &FontContextHandle) { // TODO(Issue #186): don't refresh unless something actually // changed. Does OSX have a notification for this event? // @@ -61,7 +61,7 @@ impl FontList { // if such family exists, try to match style to a font let mut result: Option<@FontEntry> = None; - for family.iter().advance |fam| { + for fam in family.iter() { result = fam.find_font_for_style(&self.handle, style); } @@ -76,7 +76,7 @@ impl FontList { result } - priv fn find_family(&self, family_name: &str) -> Option<@mut FontFamily> { + fn find_family(&self, family_name: &str) -> Option<@mut FontFamily> { // look up canonical name let family = self.family_map.find_equiv(&family_name); @@ -125,8 +125,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.iter().advance |entry| { + for entry in self.entries.iter() { if (style.weight.is_bold() == entry.is_bold()) && (style.italic == entry.is_italic()) { diff --git a/src/components/gfx/gfx.rc b/src/components/gfx/gfx.rc index c9b7d2a2e4c..4b86374cd9a 100644 --- a/src/components/gfx/gfx.rc +++ b/src/components/gfx/gfx.rc @@ -10,7 +10,6 @@ extern mod azure; extern mod geom; -extern mod http_client; extern mod stb_image; extern mod extra; extern mod servo_net (name = "net"); @@ -36,7 +35,7 @@ pub use gfx_font_list = font_list; pub use servo_gfx_font = font; pub use servo_gfx_font_list = font_list; -priv mod render_context; +mod render_context; // Rendering pub mod color; diff --git a/src/components/gfx/opts.rs b/src/components/gfx/opts.rs index e1b46027cc1..8e201c7a2a7 100644 --- a/src/components/gfx/opts.rs +++ b/src/components/gfx/opts.rs @@ -23,7 +23,6 @@ pub struct Opts { output_file: Option<~str>, } -#[allow(non_implicitly_copyable_typarams)] pub fn from_cmdline_args(args: &[~str]) -> Opts { use extra::getopts; @@ -40,13 +39,13 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts { let opt_match = match getopts::getopts(args, opts) { result::Ok(m) => m, - result::Err(f) => fail!(getopts::fail_str(copy f)), + result::Err(f) => fail!(getopts::fail_str(f.clone())), }; let urls = if opt_match.free.is_empty() { fail!(~"servo asks that you provide 1 or more URLs") } else { - copy opt_match.free + opt_match.free.clone() }; let render_backend = match getopts::opt_maybe_str(&opt_match, "r") { @@ -69,18 +68,18 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts { }; let tile_size: uint = match getopts::opt_maybe_str(&opt_match, "s") { - Some(tile_size_str) => uint::from_str(tile_size_str).get(), + Some(tile_size_str) => uint::from_str(tile_size_str).unwrap(), None => 512, }; let n_render_threads: uint = match getopts::opt_maybe_str(&opt_match, "t") { - Some(n_render_threads_str) => uint::from_str(n_render_threads_str).get(), + Some(n_render_threads_str) => uint::from_str(n_render_threads_str).unwrap(), None => 1, // FIXME: Number of cores. }; // if only flag is present, default to 5 second period let profiler_period = do getopts::opt_default(&opt_match, "p", "5").map |period| { - float::from_str(*period).get() + float::from_str(*period).unwrap() }; let exit_after_load = getopts::opt_present(&opt_match, "x"); diff --git a/src/components/gfx/platform/linux/font.rs b/src/components/gfx/platform/linux/font.rs index dc2eb8bdd3b..aff744cae2d 100644 --- a/src/components/gfx/platform/linux/font.rs +++ b/src/components/gfx/platform/linux/font.rs @@ -73,7 +73,7 @@ impl Drop for FontHandle { } impl FontHandleMethods for FontHandle { - pub fn new_from_buffer(fctx: &FontContextHandle, + fn new_from_buffer(fctx: &FontContextHandle, buf: ~[u8], style: &SpecifiedFontStyle) -> Result { @@ -173,12 +173,12 @@ impl FontHandleMethods for FontHandle { FontHandleMethods::new_from_buffer(fctx, buf.clone(), style) } FontSourceFile(ref file) => { - FontHandle::new_from_file(fctx, copy *file, style) + FontHandle::new_from_file(fctx, (*file).clone(), style) } } } - pub fn glyph_index(&self, + fn glyph_index(&self, codepoint: char) -> Option { assert!(self.face.is_not_null()); unsafe { @@ -192,7 +192,7 @@ impl FontHandleMethods for FontHandle { } } - pub fn glyph_h_advance(&self, + fn glyph_h_advance(&self, glyph: GlyphIndex) -> Option { assert!(self.face.is_not_null()); unsafe { @@ -213,7 +213,7 @@ impl FontHandleMethods for FontHandle { } } - pub fn get_metrics(&self) -> FontMetrics { + fn get_metrics(&self) -> FontMetrics { /* TODO(Issue #76): complete me */ let face = self.get_face_rec(); @@ -242,7 +242,7 @@ impl FontHandleMethods for FontHandle { } impl<'self> FontHandle { - priv fn set_char_size(face: FT_Face, pt_size: float) -> Result<(), ()>{ + fn set_char_size(face: FT_Face, pt_size: float) -> Result<(), ()>{ let char_width = float_to_fixed_ft(pt_size) as FT_F26Dot6; let char_height = float_to_fixed_ft(pt_size) as FT_F26Dot6; let h_dpi = 72; @@ -262,7 +262,7 @@ impl<'self> FontHandle { let mut face: FT_Face = ptr::null(); let face_index = 0 as FT_Long; - do str::as_c_str(file) |file_str| { + do file.to_c_str().with_ref |file_str| { FT_New_Face(ft_ctx, file_str, face_index, ptr::to_mut_unsafe_ptr(&mut face)); } @@ -289,7 +289,7 @@ impl<'self> FontHandle { let mut face: FT_Face = ptr::null(); let face_index = 0 as FT_Long; - do str::as_c_str(file) |file_str| { + do file.to_c_str().with_ref |file_str| { FT_New_Face(ft_ctx, file_str, face_index, ptr::to_mut_unsafe_ptr(&mut face)); } @@ -305,13 +305,13 @@ impl<'self> FontHandle { } } - priv fn get_face_rec(&'self self) -> &'self FT_FaceRec { + fn get_face_rec(&'self self) -> &'self FT_FaceRec { unsafe { &(*self.face) } } - priv fn font_units_to_au(&self, value: float) -> Au { + fn font_units_to_au(&self, value: float) -> Au { let face = self.get_face_rec(); // face.size is a *c_void in the bindings, presumably to avoid diff --git a/src/components/gfx/platform/linux/font_list.rs b/src/components/gfx/platform/linux/font_list.rs index ae53929855c..5af148d0626 100644 --- a/src/components/gfx/platform/linux/font_list.rs +++ b/src/components/gfx/platform/linux/font_list.rs @@ -26,10 +26,9 @@ use platform::font_context::FontContextHandle; use std::hashmap::HashMap; use std::libc; -use std::libc::c_int; +use std::libc::{c_int, c_char}; use std::ptr; use std::str; -use std::uint; pub struct FontListHandle { fctx: FontContextHandle, @@ -45,13 +44,13 @@ impl FontListHandle { unsafe { let config = FcConfigGetCurrent(); let fontSet = FcConfigGetFonts(config, FcSetSystem); - for uint::range(0, (*fontSet).nfont as uint) |i| { + for i in range(0, (*fontSet).nfont as int) { let font = (*fontSet).fonts.offset(i); let family: *FcChar8 = ptr::null(); let mut v: c_int = 0; - do str::as_c_str("family") |FC_FAMILY| { + do "family".to_c_str().with_ref |FC_FAMILY| { while FcPatternGetString(*font, FC_FAMILY, v, &family) == FcResultMatch { - let family_name = str::raw::from_buf(family as *u8); + let family_name = str::raw::from_c_str(family as *c_char); debug!("Creating new FontFamily for family: %s", family_name); let new_family = @mut FontFamily::new(family_name); family_map.insert(family_name, new_family); @@ -71,8 +70,8 @@ impl FontListHandle { let font_set_array_ptr = ptr::to_unsafe_ptr(&font_set); let pattern = FcPatternCreate(); assert!(pattern.is_not_null()); - do str::as_c_str("family") |FC_FAMILY| { - do str::as_c_str(family.family_name) |family_name| { + do "family".to_c_str().with_ref |FC_FAMILY| { + do family.family_name.to_c_str().with_ref |family_name| { let ok = FcPatternAddString(pattern, FC_FAMILY, family_name as *FcChar8); assert!(ok != 0); } @@ -81,10 +80,10 @@ impl FontListHandle { let object_set = FcObjectSetCreate(); assert!(object_set.is_not_null()); - do str::as_c_str("file") |FC_FILE| { + do "file".to_c_str().with_ref |FC_FILE| { FcObjectSetAdd(object_set, FC_FILE); } - do str::as_c_str("index") |FC_INDEX| { + do "index".to_c_str().with_ref |FC_INDEX| { FcObjectSetAdd(object_set, FC_INDEX); } @@ -92,9 +91,9 @@ impl FontListHandle { debug!("found %? variations", (*matches).nfont); - for uint::range(0, (*matches).nfont as uint) |i| { + for i in range(0, (*matches).nfont as int) { let font = (*matches).fonts.offset(i); - let file = do str::as_c_str("file") |FC_FILE| { + let file = do "file".to_c_str().with_ref |FC_FILE| { let file: *FcChar8 = ptr::null(); if FcPatternGetString(*font, FC_FILE, 0, &file) == FcResultMatch { str::raw::from_c_str(file as *libc::c_char) @@ -102,7 +101,7 @@ impl FontListHandle { fail!(); } }; - let index = do str::as_c_str("index") |FC_INDEX| { + let index = do "index".to_c_str().with_ref |FC_INDEX| { let index: libc::c_int = 0; if FcPatternGetInteger(*font, FC_INDEX, 0, &index) == FcResultMatch { index @@ -151,8 +150,8 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( let config = FcConfigGetCurrent(); let wrapper = AutoPattern { pattern: FcPatternCreate() }; let pattern = wrapper.pattern; - let res = do str::as_c_str("family") |FC_FAMILY| { - do str::as_c_str(name) |family| { + let res = do "family".to_c_str().with_ref |FC_FAMILY| { + do name.to_c_str().with_ref |family| { FcPatternAddString(pattern, FC_FAMILY, family as *FcChar8) } }; @@ -162,7 +161,7 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( } if style.italic { - let res = do str::as_c_str("slant") |FC_SLANT| { + let res = do "slant".to_c_str().with_ref |FC_SLANT| { FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC) }; if res != 1 { @@ -171,7 +170,7 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( } } if style.weight.is_bold() { - let res = do str::as_c_str("weight") |FC_WEIGHT| { + let res = do "weight".to_c_str().with_ref |FC_WEIGHT| { FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD) }; if res != 1 { @@ -194,13 +193,13 @@ pub fn path_from_identifier(name: ~str, style: &UsedFontStyle) -> Result<~str, ( } let file: *FcChar8 = ptr::null(); - let res = do str::as_c_str("file") |FC_FILE| { + let res = do "file".to_c_str().with_ref |FC_FILE| { FcPatternGetString(result_pattern, FC_FILE, 0, &file) }; if res != FcResultMatch { debug!("getting filename for font failed"); return Err(()); } - Ok(str::raw::from_buf(file as *u8)) + Ok(str::raw::from_c_str(file as *c_char)) } } diff --git a/src/components/gfx/platform/macos/font_context.rs b/src/components/gfx/platform/macos/font_context.rs index a96390d3537..79ebf1548c3 100644 --- a/src/components/gfx/platform/macos/font_context.rs +++ b/src/components/gfx/platform/macos/font_context.rs @@ -8,8 +8,6 @@ use platform::macos::font::FontHandle; use core_text; -use std::result; - pub struct FontContextHandle { ctx: () } @@ -33,7 +31,7 @@ impl FontContextHandleMethods for FontContextHandle { style: UsedFontStyle) -> Result { let ctfont_result = core_text::font::new_from_name(name, style.pt_size); - do result::chain(ctfont_result) |ctfont| { + do ctfont_result.chain |ctfont| { FontHandle::new_from_CTFont(self, ctfont) } } diff --git a/src/components/gfx/platform/macos/font_list.rs b/src/components/gfx/platform/macos/font_list.rs index 85e22405745..22016f18fe4 100644 --- a/src/components/gfx/platform/macos/font_list.rs +++ b/src/components/gfx/platform/macos/font_list.rs @@ -12,11 +12,9 @@ use core_foundation::array::CFArray; use core_foundation::base::CFWrapper; use core_foundation::string::{CFString, CFStringRef}; use core_text::font_collection::CTFontCollectionMethods; -use core_text::font_descriptor::CTFontDescriptorRef; use core_text; use std::hashmap::HashMap; -use std::result; pub struct FontListHandle { fctx: FontContextHandle, @@ -32,24 +30,25 @@ impl FontListHandle { pub fn get_available_families(&self) -> FontFamilyMap { let family_names: CFArray = core_text::font_collection::get_family_names(); let mut family_map: FontFamilyMap = HashMap::new(); - for family_names.each |&strref: &CFStringRef| { + for strref in family_names.iter() { let family_name = CFString::wrap_shared(strref).to_str(); debug!("Creating new FontFamily for family: %s", family_name); let new_family = @mut FontFamily::new(family_name); family_map.insert(family_name, new_family); } - return family_map; + family_map } pub fn load_variations_for_family(&self, family: @mut FontFamily) { debug!("Looking for faces of family: %s", family.family_name); let family_collection = core_text::font_collection::create_for_family(family.family_name); - for family_collection.get_descriptors().each |descref: &CTFontDescriptorRef| { - let desc = CFWrapper::wrap_shared(*descref); + let family_descriptors = family_collection.get_descriptors(); + for descref in family_descriptors.iter() { + let desc = CFWrapper::wrap_shared(descref); let font = core_text::font::new_from_descriptor(&desc, 0.0); - let handle = result::unwrap(FontHandle::new_from_CTFont(&self.fctx, font)); + let handle = FontHandle::new_from_CTFont(&self.fctx, font).unwrap(); debug!("Creating new FontEntry for face: %s", handle.face_name()); let entry = @FontEntry::new(handle); diff --git a/src/components/gfx/render_context.rs b/src/components/gfx/render_context.rs index 89567f1fa3b..d7e2242935e 100644 --- a/src/components/gfx/render_context.rs +++ b/src/components/gfx/render_context.rs @@ -16,7 +16,7 @@ use geom::rect::Rect; use geom::size::Size2D; use geom::side_offsets::SideOffsets2D; use servo_net::image::base::Image; -use extra::arc::ARC; +use extra::arc::Arc; pub struct RenderContext<'self> { canvas: &'self LayerBuffer, @@ -77,7 +77,7 @@ impl<'self> RenderContext<'self> { self.canvas.draw_target.stroke_line(start, end, &pattern, &stroke_opts, &draw_opts); } - pub fn draw_image(&self, bounds: Rect, image: ARC<~Image>) { + pub fn draw_image(&self, bounds: Rect, image: Arc<~Image>) { let image = image.get(); let size = Size2D(image.width as i32, image.height as i32); let stride = image.width * 4; diff --git a/src/components/gfx/render_task.rs b/src/components/gfx/render_task.rs index dab31cdc2f4..6ddbb19df64 100644 --- a/src/components/gfx/render_task.rs +++ b/src/components/gfx/render_task.rs @@ -39,6 +39,7 @@ pub enum Msg { } /// A request from the compositor to the renderer for tiles that need to be (re)displayed. +#[deriving(Clone)] pub struct BufferRequest { // The rect in pixels that will be drawn to the screen screen_rect: Rect, @@ -70,7 +71,7 @@ impl RenderChan { } } -priv struct RenderTask { +struct RenderTask { id: PipelineId, port: Port, compositor: C, @@ -87,7 +88,7 @@ priv struct RenderTask { /// Permission to send paint messages to the compositor paint_permission: bool, /// Cached copy of last layers rendered - last_paint_msg: Option<(arc::ARC, Size2D)>, + last_paint_msg: Option<(arc::Arc, Size2D)>, } impl RenderTask { @@ -112,7 +113,7 @@ impl RenderTask { id: id, port: port.take(), compositor: compositor, - font_ctx: @mut FontContext::new(copy opts.render_backend, + font_ctx: @mut FontContext::new(opts.render_backend.clone(), false, profiler_chan.clone()), opts: opts, @@ -179,7 +180,7 @@ impl RenderTask { // Divide up the layer into tiles. do time::profile(time::RenderingPrepBuffCategory, self.profiler_chan.clone()) { - for tiles.iter().advance |tile| { + for tile in tiles.iter() { let width = tile.screen_rect.size.width; let height = tile.screen_rect.size.height; @@ -230,7 +231,7 @@ impl RenderTask { let layer_buffer_set = LayerBufferSet { buffers: new_buffers, }; - let layer_buffer_set = arc::ARC(layer_buffer_set); + let layer_buffer_set = arc::Arc::new(layer_buffer_set); debug!("render_task: returning surface"); if self.paint_permission { diff --git a/src/components/gfx/surface.rs b/src/components/gfx/surface.rs index 4c965db812b..b30c165c08b 100644 --- a/src/components/gfx/surface.rs +++ b/src/components/gfx/surface.rs @@ -28,7 +28,7 @@ pub struct ImageSurface { impl ImageSurface { pub fn new(size: Size2D, format: format) -> ImageSurface { ImageSurface { - size: copy size, + size: size.clone(), format: format, buffer: vec::from_elem((size.area() as uint) * format.bpp(), 0u8) } diff --git a/src/components/gfx/text/glyph.rs b/src/components/gfx/text/glyph.rs index f6569cc959b..d5e7bcd8ebb 100644 --- a/src/components/gfx/text/glyph.rs +++ b/src/components/gfx/text/glyph.rs @@ -12,8 +12,8 @@ use std::cmp::{Ord, Eq}; use std::num::NumCast; use std::u16; use std::vec; -use std::uint; use std::util; +use std::iterator; use geom::point::Point2D; use extra::sort; @@ -25,6 +25,7 @@ use extra::sort; /// In the uncommon case (multiple glyphs per unicode character, large glyph index/advance, or /// glyph offsets), we pack the glyph count into GlyphEntry, and store the other glyph information /// in DetailedGlyphStore. +#[deriving(Clone)] struct GlyphEntry { value: u32 } @@ -256,6 +257,7 @@ impl GlyphEntry { // Stores data for a detailed glyph, in the case that several glyphs // correspond to one character, or the glyph's data couldn't be packed. +#[deriving(Clone)] struct DetailedGlyph { index: GlyphIndex, // glyph's advance, in the text's direction (RTL or RTL) @@ -274,7 +276,7 @@ impl DetailedGlyph { } } -#[deriving(Eq)] +#[deriving(Eq, Clone)] struct DetailedGlyphRecord { // source string offset/GlyphEntry offset in the TextRun entry_offset: uint, @@ -459,7 +461,7 @@ enum GlyphInfo<'self> { } impl<'self> GlyphInfo<'self> { - fn index(self) -> GlyphIndex { + pub fn index(self) -> GlyphIndex { match self { SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].index(), DetailGlyphInfo(store, entry_i, detail_j) => { @@ -470,7 +472,7 @@ impl<'self> GlyphInfo<'self> { #[inline(always)] // FIXME: Resolution conflicts with IteratorUtil trait so adding trailing _ - fn advance_(self) -> Au { + pub fn advance(self) -> Au { match self { SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].advance(), DetailGlyphInfo(store, entry_i, detail_j) => { @@ -479,7 +481,7 @@ impl<'self> GlyphInfo<'self> { } } - fn offset(self) -> Option> { + pub fn offset(self) -> Option> { match self { SimpleGlyphInfo(_, _) => None, DetailGlyphInfo(store, entry_i, detail_j) => { @@ -488,14 +490,14 @@ impl<'self> GlyphInfo<'self> { } } - fn is_ligature_start(self) -> bool { + pub fn is_ligature_start(self) -> bool { match self { SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].is_ligature_start(), DetailGlyphInfo(store, entry_i, _) => store.entry_buffer[entry_i].is_ligature_start() } } - fn is_cluster_start(self) -> bool { + pub fn is_cluster_start(self) -> bool { match self { SimpleGlyphInfo(store, entry_i) => store.entry_buffer[entry_i].is_cluster_start(), DetailGlyphInfo(store, entry_i, _) => store.entry_buffer[entry_i].is_cluster_start() @@ -597,62 +599,24 @@ impl<'self> GlyphStore { self.entry_buffer[i] = entry; } - pub fn iter_glyphs_for_char_index(&'self self, - i: uint, - cb: &fn(uint, &GlyphInfo<'self>) -> bool) - -> bool { - assert!(i < self.entry_buffer.len()); - - let entry = &self.entry_buffer[i]; - match entry.is_simple() { - true => { - let proxy = &SimpleGlyphInfo(self, i); - cb(i, proxy); - }, - false => { - let glyphs = self.detail_store.get_detailed_glyphs_for_entry(i, - entry.glyph_count()); - for uint::range(0, glyphs.len()) |j| { - let proxy = &DetailGlyphInfo(self, i, j as u16); - cb(i, proxy); - } - } - } - true + pub fn iter_glyphs_for_char_index(&'self self, i: uint) -> GlyphIterator<'self> { + self.iter_glyphs_for_char_range(&Range::new(i, 1)) } - pub fn iter_glyphs_for_char_range(&'self self, - range: &Range, - callback: &fn(uint, &GlyphInfo<'self>) -> bool) - -> bool { - if range.begin() >= self.entry_buffer.len() { - error!("iter_glyphs_for_range: range.begin beyond length!"); - return false + pub fn iter_glyphs_for_char_range(&'self self, rang: &Range) -> GlyphIterator<'self> { + if rang.begin() >= self.entry_buffer.len() { + fail!("iter_glyphs_for_range: range.begin beyond length!"); } - if range.end() > self.entry_buffer.len() { - error!("iter_glyphs_for_range: range.end beyond length!"); - return false + if rang.end() > self.entry_buffer.len() { + fail!("iter_glyphs_for_range: range.end beyond length!"); } - for range.eachi |i| { - // 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 - } + GlyphIterator { + store: self, + char_index: rang.begin(), + char_range: rang.eachi(), + glyph_range: None } - - true - } - - pub fn iter_all_glyphs(&'self self, callback: &fn(uint, &GlyphInfo<'self>) -> bool) -> bool { - for uint::range(0, self.entry_buffer.len()) |i| { - // 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; - } - } - - true } // getter methods @@ -711,3 +675,49 @@ impl<'self> GlyphStore { self.entry_buffer[i] = entry.set_can_break_before(t); } } + +pub struct GlyphIterator<'self> { + priv store: &'self GlyphStore, + priv char_index: uint, + priv char_range: iterator::Range, + priv glyph_range: Option>, +} + +impl<'self> Iterator<(uint, GlyphInfo<'self>)> for GlyphIterator<'self> { + // I tried to start with something simpler and apply FlatMap, but the + // inability to store free variables in the FlatMap struct was problematic. + + fn next(&mut self) -> Option<(uint, GlyphInfo<'self>)> { + // Would use 'match' here but it borrows contents in a way that + // interferes with mutation. + if self.glyph_range.is_some() { + match self.glyph_range.unwrap().next() { + Some(j) => Some((self.char_index, + DetailGlyphInfo(self.store, self.char_index, j as u16))), + None => { + // No more glyphs for current character. Try to get another. + self.glyph_range = None; + self.next() + } + } + } else { + // No glyph range. Look at next character. + match self.char_range.next() { + Some(i) => { + self.char_index = i; + assert!(i < self.store.entry_buffer.len()); + let entry = &self.store.entry_buffer[i]; + if entry.is_simple() { + Some((self.char_index, SimpleGlyphInfo(self.store, i))) + } else { + let glyphs = self.store.detail_store + .get_detailed_glyphs_for_entry(i, entry.glyph_count()); + self.glyph_range = Some(range(0, glyphs.len())); + self.next() + } + }, + None => None + } + } + } +} diff --git a/src/components/gfx/text/shaping/harfbuzz.rs b/src/components/gfx/text/shaping/harfbuzz.rs index 851beb87c8c..75358329e1e 100644 --- a/src/components/gfx/text/shaping/harfbuzz.rs +++ b/src/components/gfx/text/shaping/harfbuzz.rs @@ -16,7 +16,6 @@ use std::cast::transmute; use std::libc::{c_uint, c_int, c_void, c_char}; use std::ptr; use std::ptr::null; -use std::str; use std::uint; use std::util::ignore; use std::vec; @@ -86,7 +85,7 @@ impl ShapedGlyphData { fn byte_offset_of_glyph(&self, i: uint) -> uint { assert!(i < self.count); - let glyph_info_i = ptr::offset(self.glyph_infos, i); + let glyph_info_i = ptr::offset(self.glyph_infos, i as int); unsafe { (*glyph_info_i).cluster as uint } @@ -101,8 +100,8 @@ impl ShapedGlyphData { assert!(i < self.count); unsafe { - let glyph_info_i = ptr::offset(self.glyph_infos, i); - let pos_info_i = ptr::offset(self.pos_infos, i); + let glyph_info_i = ptr::offset(self.glyph_infos, i as int); + let pos_info_i = ptr::offset(self.pos_infos, i as int); let x_offset = Shaper::fixed_to_float((*pos_info_i).x_offset); let y_offset = Shaper::fixed_to_float((*pos_info_i).y_offset); let x_advance = Shaper::fixed_to_float((*pos_info_i).x_advance); @@ -216,8 +215,8 @@ impl ShaperMethods for Shaper { let hb_buffer: *hb_buffer_t = hb_buffer_create(); hb_buffer_set_direction(hb_buffer, HB_DIRECTION_LTR); - // Using as_buf because it never does a copy - we don't need the trailing null - do str::as_buf(text) |ctext: *u8, _: uint| { + // Using as_imm_buf because it never does a copy - we don't need the trailing null + do text.as_imm_buf |ctext: *u8, _: uint| { hb_buffer_add_utf8(hb_buffer, ctext as *c_char, text.len() as c_int, @@ -272,7 +271,7 @@ impl Shaper { } debug!("(glyph idx) -> (text byte offset)"); - for uint::range(0, glyph_data.len()) |i| { + for i in range(0, glyph_data.len()) { // loc refers to a *byte* offset within the utf8 string. let loc = glyph_data.byte_offset_of_glyph(i); if loc < byte_max { @@ -335,7 +334,7 @@ impl Shaper { // extend glyph range to max glyph index covered by char_span, // in cases where one char made several glyphs and left some unassociated chars. let mut max_glyph_idx = glyph_span.end(); - for char_byte_span.eachi |i| { + for i in char_byte_span.eachi() { if byteToGlyph[i] > NO_GLYPH { max_glyph_idx = uint::max(byteToGlyph[i] as uint, max_glyph_idx); } @@ -359,7 +358,7 @@ impl Shaper { probably doesn't work."); let mut all_glyphs_are_within_cluster: bool = true; - for glyph_span.eachi |j| { + for j in glyph_span.eachi() { let loc = glyph_data.byte_offset_of_glyph(j); if !char_byte_span.contains(loc) { all_glyphs_are_within_cluster = false; @@ -398,7 +397,7 @@ impl Shaper { // cspan: [-] // covsp: [---------------] - let mut covered_byte_span = copy char_byte_span; + let mut covered_byte_span = char_byte_span.clone(); // extend, clipping at end of text range. while covered_byte_span.end() < byte_max && byteToGlyph[covered_byte_span.end()] == NO_GLYPH { @@ -438,7 +437,7 @@ impl Shaper { // collect all glyphs to be assigned to the first character. let mut datas = ~[]; - for glyph_span.eachi |glyph_i| { + for glyph_i in glyph_span.eachi() { let shape = glyph_data.get_entry_for_glyph(glyph_i, &mut y_pos); datas.push(GlyphData::new(shape.codepoint, shape.advance, diff --git a/src/components/gfx/text/text_run.rs b/src/components/gfx/text/text_run.rs index c436181977c..f22b0d94d28 100644 --- a/src/components/gfx/text/text_run.rs +++ b/src/components/gfx/text/text_run.rs @@ -2,27 +2,29 @@ * 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::vec::VecIterator; + use font_context::FontContext; use geometry::Au; use text::glyph::GlyphStore; use font::{Font, FontDescriptor, RunMetrics}; use servo_util::range::Range; -use extra::arc::ARC; +use extra::arc::Arc; /// A text run. pub struct TextRun { text: ~str, font: @mut Font, underline: bool, - glyphs: ~[ARC], + glyphs: ~[Arc], } -/// This is a hack until TextRuns are normally sendable, or we instead use ARC everywhere. +/// This is a hack until TextRuns are normally sendable, or we instead use Arc everywhere. pub struct SendableTextRun { text: ~str, font: FontDescriptor, underline: bool, - priv glyphs: ~[ARC], + priv glyphs: ~[Arc], } impl SendableTextRun { @@ -33,7 +35,7 @@ impl SendableTextRun { }; TextRun { - text: copy self.text, + text: self.text.clone(), font: font, underline: self.underline, glyphs: self.glyphs.clone(), @@ -41,6 +43,78 @@ impl SendableTextRun { } } +pub struct SliceIterator<'self> { + priv glyph_iter: VecIterator<'self, Arc>, + priv range: Range, + priv offset: uint, +} + +impl<'self> Iterator<(&'self GlyphStore, uint, Range)> for SliceIterator<'self> { + fn next(&mut self) -> Option<(&'self GlyphStore, uint, Range)> { + loop { + let slice_glyphs = self.glyph_iter.next(); + if slice_glyphs.is_none() { + return None; + } + let slice_glyphs = slice_glyphs.unwrap().get(); + + let slice_range = Range::new(self.offset, slice_glyphs.char_len()); + let mut char_range = self.range.intersect(&slice_range); + char_range.shift_by(-(self.offset.to_int())); + + let old_offset = self.offset; + self.offset += slice_glyphs.char_len(); + if !char_range.is_empty() { + return Some((slice_glyphs, old_offset, char_range)) + } + } + } +} + +pub struct LineIterator<'self> { + priv range: Range, + priv clump: Option, + priv slices: SliceIterator<'self>, +} + +impl<'self> Iterator for LineIterator<'self> { + fn next(&mut self) -> Option { + // Loop until we hit whitespace and are in a clump. + loop { + match self.slices.next() { + Some((glyphs, offset, slice_range)) => { + match (glyphs.is_whitespace(), self.clump) { + (false, Some(ref mut c)) => { + c.extend_by(slice_range.length().to_int()); + } + (false, None) => { + let mut c = slice_range; + c.shift_by(offset.to_int()); + self.clump = Some(c); + } + (true, None) => { /* chomp whitespace */ } + (true, Some(c)) => { + self.clump = None; + // The final whitespace clump is not included. + return Some(c); + } + } + }, + None => { + // flush any remaining chars as a line + if self.clump.is_some() { + let mut c = self.clump.take_unwrap(); + c.extend_to(self.range.end()); + return Some(c); + } else { + return None; + } + } + } + } + } +} + impl<'self> TextRun { pub fn new(font: @mut Font, text: ~str, underline: bool) -> TextRun { let glyphs = TextRun::break_and_shape(font, text); @@ -58,7 +132,7 @@ impl<'self> TextRun { self.font.teardown(); } - pub fn break_and_shape(font: @mut Font, text: &str) -> ~[ARC] { + pub fn break_and_shape(font: @mut Font, text: &str) -> ~[Arc] { // TODO(Issue #230): do a better job. See Gecko's LineBreaker. let mut glyphs = ~[]; @@ -115,7 +189,7 @@ impl<'self> TextRun { pub fn serialize(&self) -> SendableTextRun { SendableTextRun { - text: copy self.text, + text: self.text.clone(), font: self.font.get_descriptor(), underline: self.underline, glyphs: self.glyphs.clone(), @@ -128,10 +202,10 @@ impl<'self> TextRun { } } - pub fn glyphs(&'self self) -> &'self ~[ARC] { &self.glyphs } + pub fn glyphs(&'self self) -> &'self ~[Arc] { &self.glyphs } pub fn range_is_trimmable_whitespace(&self, range: &Range) -> bool { - for self.iter_slices_for_range(range) |slice_glyphs, _, _| { + for (slice_glyphs, _, _) in self.iter_slices_for_range(range) { if !slice_glyphs.is_whitespace() { return false; } } true @@ -148,61 +222,27 @@ impl<'self> TextRun { pub fn min_width_for_range(&self, range: &Range) -> Au { let mut max_piece_width = Au(0); debug!("iterating outer range %?", range); - for self.iter_slices_for_range(range) |glyphs, offset, slice_range| { + for (glyphs, offset, slice_range) in self.iter_slices_for_range(range) { debug!("iterated on %?[%?]", offset, slice_range); - let metrics = self.font.measure_text_for_slice(glyphs, slice_range); + let metrics = self.font.measure_text_for_slice(glyphs, &slice_range); max_piece_width = Au::max(max_piece_width, metrics.advance_width); } max_piece_width } - pub fn iter_slices_for_range(&self, - range: &Range, - f: &fn(&GlyphStore, uint, &Range) -> bool) - -> bool { - let mut offset = 0; - 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); - char_range.shift_by(-(offset.to_int())); - - let unwrapped_glyphs = slice_glyphs.get(); - if !char_range.is_empty() { - if !f(unwrapped_glyphs, offset, &char_range) { break } - } - offset += unwrapped_glyphs.char_len(); + pub fn iter_slices_for_range(&'self self, range: &Range) -> SliceIterator<'self> { + SliceIterator { + glyph_iter: self.glyphs.iter(), + range: *range, + offset: 0, } - true } - pub fn iter_natural_lines_for_range(&self, range: &Range, f: &fn(&Range) -> bool) -> bool { - let mut clump = Range::new(range.begin(), 0); - let mut in_clump = false; - - for self.iter_slices_for_range(range) |glyphs, offset, slice_range| { - match (glyphs.is_whitespace(), in_clump) { - (false, true) => { clump.extend_by(slice_range.length().to_int()); } - (false, false) => { - in_clump = true; - clump = *slice_range; - clump.shift_by(offset.to_int()); - } - (true, false) => { /* chomp whitespace */ } - (true, true) => { - in_clump = false; - // The final whitespace clump is not included. - if !f(&clump) { break } - } - } + pub fn iter_natural_lines_for_range(&'self self, range: &Range) -> LineIterator<'self> { + LineIterator { + range: *range, + clump: None, + slices: self.iter_slices_for_range(range), } - - // flush any remaining chars as a line - if in_clump { - clump.extend_to(range.end()); - f(&clump); - } - - true } } diff --git a/src/components/gfx/text/util.rs b/src/components/gfx/text/util.rs index e808d08e339..13e8e369926 100644 --- a/src/components/gfx/text/util.rs +++ b/src/components/gfx/text/util.rs @@ -24,7 +24,7 @@ pub fn transform_text(text: &str, mode: CompressionMode, incoming_whitespace: bo let mut out_str: ~str = ~""; let out_whitespace = match mode { CompressNone | DiscardNewline => { - for text.iter().advance |ch: char| { + for ch in text.iter() { if is_discardable_char(ch, mode) { // TODO: record skipped char } else { @@ -40,7 +40,7 @@ pub fn transform_text(text: &str, mode: CompressionMode, incoming_whitespace: bo CompressWhitespace | CompressWhitespaceNewline => { let mut in_whitespace: bool = incoming_whitespace; - for text.iter().advance |ch: char| { + for ch in text.iter() { // TODO: discard newlines between CJK chars let mut next_in_whitespace: bool = is_in_whitespace(ch, mode); @@ -134,7 +134,7 @@ fn test_transform_compress_none() { ~"foobarbaz\n\n"]; let mode = CompressNone; - for uint::range(0, test_strs.len()) |i| { + for i in range(0, test_strs.len()) { (trimmed_str, _out) = transform_text(test_strs[i], mode, true); assert!(trimmed_str == test_strs[i]) } @@ -162,7 +162,7 @@ fn test_transform_discard_newline() { assert!(test_strs.len() == oracle_strs.len()); let mode = DiscardNewline; - for uint::range(0, test_strs.len()) |i| { + for i in range(0, test_strs.len()) { (trimmed_str, _out) = transform_text(test_strs[i], mode, true); assert!(trimmed_str == oracle_strs[i]) } @@ -189,7 +189,7 @@ fn test_transform_compress_whitespace() { assert!(test_strs.len() == oracle_strs.len()); let mode = CompressWhitespace; - for uint::range(0, test_strs.len()) |i| { + for i in range(0, test_strs.len()) { (trimmed_str, _out) = transform_text(test_strs[i], mode, true); assert!(trimmed_str == oracle_strs[i]) } @@ -216,7 +216,7 @@ fn test_transform_compress_whitespace_newline() { assert!(test_strs.len() == oracle_strs.len()); let mode = CompressWhitespaceNewline; - for uint::range(0, test_strs.len()) |i| { + for i in range(0, test_strs.len()) { (trimmed_str, _out) = transform_text(test_strs[i], mode, true); assert!(trimmed_str == oracle_strs[i]) } @@ -245,7 +245,7 @@ fn test_transform_compress_whitespace_newline() { assert!(test_strs.len() == oracle_strs.len()); let mode = CompressWhitespaceNewline; - for uint::range(0, test_strs.len()) |i| { + for i in range(0, test_strs.len()) { (trimmed_str, _out) = transform_text(test_strs[i], mode, false); assert!(trimmed_str == oracle_strs[i]) } diff --git a/src/components/main/compositing/compositor_layer.rs b/src/components/main/compositing/compositor_layer.rs index 083dc5312c5..c846e58a175 100644 --- a/src/components/main/compositing/compositor_layer.rs +++ b/src/components/main/compositing/compositor_layer.rs @@ -87,7 +87,7 @@ impl CompositorLayer { // true; otherwise returns false, so a parent layer can scroll instead. pub fn scroll(&mut self, delta: Point2D, cursor: Point2D, window_size: Size2D) -> bool { let cursor = cursor - self.scroll_offset; - for self.children.mut_iter().filter(|x| !x.child.hidden).advance |child| { + for child in self.children.mut_iter().filter(|x| !x.child.hidden) { match child.container.scissor { None => { error!("CompositorLayer: unable to perform cursor hit test for layer"); @@ -131,7 +131,7 @@ impl CompositorLayer { // page coordinates. pub fn send_mouse_event(&self, event: MouseWindowEvent, cursor: Point2D) { let cursor = cursor - self.scroll_offset; - for self.children.iter().filter(|&x| !x.child.hidden).advance |child| { + for child in self.children.iter().filter(|&x| !x.child.hidden) { match child.container.scissor { None => { error!("CompositorLayer: unable to perform cursor hit test for layer"); @@ -197,7 +197,7 @@ impl CompositorLayer { } }; self.children.mut_iter().filter(|x| !x.child.hidden) - .transform(transform) + .map(transform) .fold(false, |a, b| a || b) || redisplay } @@ -206,7 +206,7 @@ impl CompositorLayer { // and clip the layer to the specified size in page coordinates. // This method returns false if the specified layer is not found. pub fn set_clipping_rect(&mut self, pipeline_id: PipelineId, new_rect: Rect) -> bool { - for self.children.iter().advance |child_node| { + for child_node in self.children.iter() { if pipeline_id != child_node.child.pipeline.id { loop; } @@ -219,7 +219,7 @@ impl CompositorLayer { } // ID does not match any of our immediate children, so recurse on descendents (including hidden children) - self.children.mut_iter().transform(|x| &mut x.child).any(|x| x.set_clipping_rect(pipeline_id, new_rect)) + self.children.mut_iter().map(|x| &mut x.child).any(|x| x.set_clipping_rect(pipeline_id, new_rect)) } @@ -265,15 +265,15 @@ impl CompositorLayer { // Delete old layer. while current_layer_child.is_some() { - let trash = current_layer_child.get(); - do current_layer_child.get().with_common |common| { + let trash = current_layer_child.unwrap(); + do current_layer_child.unwrap().with_common |common| { current_layer_child = common.next_sibling; } self.root_layer.remove_child(trash); } // Add child layers. - for self.children.mut_iter().filter(|x| !x.child.hidden).advance |child| { + for child in self.children.mut_iter().filter(|x| !x.child.hidden) { current_layer_child = match current_layer_child { None => { child.container.common.parent = None; @@ -295,7 +295,7 @@ impl CompositorLayer { }; let all_tiles = quadtree.get_all_tiles(); - for all_tiles.iter().advance |buffer| { + for buffer in all_tiles.iter() { debug!("osmain: compositing buffer rect %?", &buffer.rect); // Find or create a texture layer. @@ -313,7 +313,7 @@ impl CompositorLayer { texture_layer.manager = @buffer.draw_target.clone() as @TextureManager; // Move on to the next sibling. - do current_layer_child.get().with_common |common| { + do current_layer_child.unwrap().with_common |common| { common.next_sibling } } @@ -339,7 +339,7 @@ impl CompositorLayer { Tree(ref mut quadtree) => quadtree, }; - for new_buffers.buffers.iter().advance |buffer| { + for buffer in new_buffers.buffers.iter() { // TODO: This may return old buffers, which should be sent back to the renderer. quadtree.add_tile_pixel(buffer.screen_pos.origin.x, buffer.screen_pos.origin.y, buffer.resolution, ~buffer.clone()); @@ -349,7 +349,7 @@ impl CompositorLayer { return true; } // ID does not match ours, so recurse on descendents (including hidden children). - self.children.mut_iter().transform(|x| &mut x.child).any(|x| x.add_buffers(pipeline_id, new_buffers)) + self.children.mut_iter().map(|x| &mut x.child).any(|x| x.add_buffers(pipeline_id, new_buffers)) } // Deletes a specified sublayer, including hidden children. Returns false if the layer is not found. @@ -362,7 +362,7 @@ impl CompositorLayer { true } None => { - self.children.mut_iter().transform(|x| &mut x.child).any(|x| x.delete(pipeline_id)) + self.children.mut_iter().map(|x| &mut x.child).any(|x| x.delete(pipeline_id)) } } } diff --git a/src/components/main/compositing/mod.rs b/src/components/main/compositing/mod.rs index b8f4c22ae5d..6417e8128f4 100644 --- a/src/components/main/compositing/mod.rs +++ b/src/components/main/compositing/mod.rs @@ -20,15 +20,12 @@ use gfx::opts::Opts; use azure::azure_hl::{DataSourceSurface, DrawTarget, SourceSurfaceMethods, current_gl_context}; use azure::azure::AzGLContext; -use std::cell::Cell; use std::comm; use std::comm::{Chan, SharedChan, Port}; use std::num::Orderable; -use std::task; -use std::uint; use std::vec; -use extra::uv_global_loop; -use extra::timer; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; use geom::matrix::identity; use geom::point::Point2D; use geom::size::Size2D; @@ -80,7 +77,7 @@ impl RenderListener for CompositorChan { port.recv() } - fn paint(&self, id: PipelineId, layer_buffer_set: arc::ARC) { + fn paint(&self, id: PipelineId, layer_buffer_set: arc::Arc) { self.chan.send(Paint(id, layer_buffer_set)) } @@ -136,7 +133,7 @@ pub enum Msg { DeleteLayer(PipelineId), /// Requests that the compositor paint the given layer buffer set for the given page size. - Paint(PipelineId, arc::ARC), + Paint(PipelineId, arc::Arc), /// Alerts the compositor to the current status of page loading. ChangeReadyState(ReadyState), /// Alerts the compositor to the current status of rendering. @@ -192,24 +189,7 @@ impl CompositorTask { } /// Starts the compositor, which listens for messages on the specified port. - pub fn create(opts: Opts, - port: Port, - profiler_chan: ProfilerChan, - shutdown_chan: Chan<()>) { - let port = Cell::new(port); - let shutdown_chan = Cell::new(shutdown_chan); - let opts = Cell::new(opts); - do on_osmain { - let compositor_task = CompositorTask::new(opts.take(), - port.take(), - profiler_chan.clone(), - shutdown_chan.take()); - debug!("preparing to enter main loop"); - compositor_task.run_main_loop(); - }; - } - - fn run_main_loop(&self) { + pub fn run(&self) { let app: Application = ApplicationMethods::new(); let window: @mut Window = WindowMethods::new(&app); @@ -242,7 +222,7 @@ impl CompositorTask { let ask_for_tiles = || { let window_size_page = Size2D(window_size.width as f32 / world_zoom, window_size.height as f32 / world_zoom); - for compositor_layer.mut_iter().advance |layer| { + for layer in compositor_layer.mut_iter() { recomposite = layer.get_buffer_request(Rect(Point2D(0f32, 0f32), window_size_page), world_zoom) || recomposite; } @@ -368,7 +348,7 @@ impl CompositorTask { MouseWindowMouseDownEvent(_, p) => Point2D(p.x / world_zoom, p.y / world_zoom), MouseWindowMouseUpEvent(_, p) => Point2D(p.x / world_zoom, p.y / world_zoom), }; - for compositor_layer.iter().advance |layer| { + for layer in compositor_layer.iter() { layer.send_mouse_event(mouse_window_event, point); } } @@ -380,7 +360,7 @@ impl CompositorTask { cursor.y as f32 / world_zoom); let page_window = Size2D(window_size.width as f32 / world_zoom, window_size.height as f32 / world_zoom); - for compositor_layer.mut_iter().advance |layer| { + for layer in compositor_layer.mut_iter() { recomposite = layer.scroll(page_delta, page_cursor, page_window) || recomposite; } ask_for_tiles(); @@ -402,7 +382,7 @@ impl CompositorTask { let page_cursor = Point2D(-1f32, -1f32); // Make sure this hits the base layer let page_window = Size2D(window_size.width as f32 / world_zoom, window_size.height as f32 / world_zoom); - for compositor_layer.mut_iter().advance |layer| { + for layer in compositor_layer.mut_iter() { layer.scroll(page_delta, page_cursor, page_window); } @@ -458,7 +438,7 @@ impl CompositorTask { // flip image vertically (texture is upside down) let orig_pixels = pixels.clone(); let stride = width * 3; - for uint::range(0, height) |y| { + for y in range(0, height) { let dst_start = y * stride; let src_start = (height - y - 1) * stride; vec::bytes::copy_memory(pixels.mut_slice(dst_start, dst_start + stride), @@ -483,6 +463,7 @@ impl CompositorTask { }; // Enter the main event loop. + let tm = Timer::new().unwrap(); while !done { // Check for new messages coming from the rendering task. check_for_messages(&self.port); @@ -495,7 +476,7 @@ impl CompositorTask { composite(); } - timer::sleep(&uv_global_loop::get(), 10); + tm.sleep(10); // If a pinch-zoom happened recently, ask for tiles at the new resolution if zoom_action && precise_time_s() - zoom_time > 0.3 { @@ -508,14 +489,3 @@ impl CompositorTask { self.shutdown_chan.send(()) } } - -/// A function for spawning into the platform's main thread. -fn on_osmain(f: ~fn()) { - // FIXME: rust#6399 - let mut main_task = task::task(); - main_task.sched_mode(task::PlatformThread); - do main_task.spawn { - f(); - } -} - diff --git a/src/components/main/compositing/quadtree.rs b/src/components/main/compositing/quadtree.rs index 7fc7a72657f..d58f568694d 100644 --- a/src/components/main/compositing/quadtree.rs +++ b/src/components/main/compositing/quadtree.rs @@ -47,7 +47,7 @@ struct QuadtreeNode { tile_mem: uint, } -priv enum Quadrant { +enum Quadrant { TL = 0, TR = 1, BL = 2, @@ -212,7 +212,7 @@ impl Quadtree { let difference = (new_size as f32 / self.root.size as f32).log2() as int; if difference > 0 { // doubling let difference = difference as uint; - for range(0, difference) |i| { + for i in range(0, difference) { let new_root = ~QuadtreeNode { tile: None, origin: Point2D(0f32, 0f32), @@ -225,7 +225,7 @@ impl Quadtree { } } else if difference < 0 { // halving let difference = difference.abs() as uint; - for difference.times { + for _ in range(0, difference) { let remove = replace(&mut self.root.quadrants[TL as int], None); match remove { Some(child) => self.root = child, @@ -299,7 +299,7 @@ impl QuadtreeNode { fn get_all_tiles<'r>(&'r self) -> ~[&'r T] { let mut ret = ~[]; - for self.quadrants.iter().advance |quad| { + for quad in self.quadrants.iter() { match *quad { Some(ref child) => ret = ret + child.get_all_tiles(), None => {} @@ -332,7 +332,7 @@ impl QuadtreeNode { self.tile = Some(tile); // FIXME: This should be inline, but currently won't compile let quads = [TL, TR, BL, BR]; - for quads.iter().advance |quad| { + for quad in quads.iter() { self.quadrants[*quad as int] = None; } self.render_flag = false; @@ -439,7 +439,7 @@ impl QuadtreeNode { let mut del_quad: Option = None; let mut ret = (None, false, 0); - for queue.iter().advance |quad| { + for quad in queue.iter() { match self.quadrants[*quad as int] { Some(ref mut child) => { let (tile, flag, delta) = child.remove_tile(x, y); @@ -514,7 +514,7 @@ impl QuadtreeNode { let old_mem = self.tile_mem; // FIXME: This should be inline, but currently won't compile let quads = [TL, TR, BL, BR]; - for quads.iter().advance |quad| { + for quad in quads.iter() { self.quadrants[*quad as int] = None; } self.tile_mem = tile.get_mem(); @@ -561,7 +561,7 @@ impl QuadtreeNode { let mut redisplay = false; let mut delta = 0; - for quads_to_check.iter().advance |quad| { + for quad in quads_to_check.iter() { // Recurse into child let new_window = match *quad { TL => Rect(window.origin, @@ -628,7 +628,7 @@ impl QuadtreeNode { ret = fmt!("%s", ret); // FIXME: This should be inline, but currently won't compile let quads = [TL, TR, BL, BR]; - for quads.iter().advance |quad| { + for quad in quads.iter() { match self.quadrants[*quad as int] { Some(ref child) => { ret = fmt!("%s", ret, child.get_html()); diff --git a/src/components/main/constellation.rs b/src/components/main/constellation.rs index d1ae44f7bfe..32da23206b0 100644 --- a/src/components/main/constellation.rs +++ b/src/components/main/constellation.rs @@ -4,8 +4,6 @@ use compositing::{CompositorChan, SetIds}; -use extra::net::url; - use std::cell::Cell; use std::comm; use std::comm::Port; @@ -51,7 +49,7 @@ struct FrameTree { // Need to clone the FrameTrees, but _not_ the Pipelines impl Clone for FrameTree { fn clone(&self) -> FrameTree { - let mut children = do self.children.iter().transform |&frame_tree| { + let mut children = do self.children.iter().map |&frame_tree| { @mut (*frame_tree).clone() }; FrameTree { @@ -95,27 +93,27 @@ impl FrameTree { /// Replaces a node of the frame tree in place. Returns the node that was removed or the original node /// if the node to replace could not be found. - fn replace_child(&mut self, id: PipelineId, new_child: @mut FrameTree) -> Result<@mut FrameTree, @mut FrameTree> { + fn replace_child(&mut self, id: PipelineId, new_child: @mut FrameTree) -> Either<@mut FrameTree, @mut FrameTree> { let new_child_cell = Cell::new(new_child); - for self.children.mut_iter().advance |child| { + for child in self.children.mut_iter() { let new_child = new_child_cell.take(); if child.pipeline.id == id { new_child.parent = child.parent; - return Ok(replace(child, new_child)); + return Left(replace(child, new_child)); } let replaced = child.replace_child(id, new_child); - if replaced.is_ok() { + if replaced.is_left() { return replaced; } - new_child_cell.put_back(replaced.get_err()); + new_child_cell.put_back(replaced.unwrap_right()); } - Err(new_child_cell.take()) + Right(new_child_cell.take()) } fn to_sendable(&self) -> SendableFrameTree { let sendable_frame_tree = SendableFrameTree { pipeline: (*self.pipeline).clone(), - children: self.children.iter().transform(|frame_tree| frame_tree.to_sendable()).collect(), + children: self.children.iter().map(|frame_tree| frame_tree.to_sendable()).collect(), }; sendable_frame_tree } @@ -169,17 +167,17 @@ impl NavigationContext { * when it is known that there exists either a previous page or a next page. */ pub fn back(&mut self) -> @mut FrameTree { - self.next.push(self.current.swap_unwrap()); + self.next.push(self.current.take_unwrap()); self.current = Some(self.previous.pop()); debug!("previous: %? next: %? current: %?", self.previous, self.next, *self.current.get_ref()); - self.current.get() + self.current.unwrap() } pub fn forward(&mut self) -> @mut FrameTree { - self.previous.push(self.current.swap_unwrap()); + self.previous.push(self.current.take_unwrap()); self.current = Some(self.next.pop()); debug!("previous: %? next: %? current: %?", self.previous, self.next, *self.current.get_ref()); - self.current.get() + self.current.unwrap() } /// Loads a new set of page frames, returning all evicted frame trees @@ -187,7 +185,7 @@ impl NavigationContext { debug!("navigating to %?", frame_tree); let evicted = replace(&mut self.next, ~[]); if self.current.is_some() { - self.previous.push(self.current.swap_unwrap()); + self.previous.push(self.current.take_unwrap()); } self.current = Some(frame_tree); evicted @@ -204,7 +202,7 @@ impl NavigationContext { let from_prev = do self.previous.iter().filter_map |frame_tree| { frame_tree.find_mut(pipeline_id) }; - from_prev.chain_(from_current).chain_(from_next).collect() + from_prev.chain(from_current).chain(from_next).collect() } pub fn contains(&mut self, pipeline_id: PipelineId) -> bool { @@ -212,7 +210,7 @@ impl NavigationContext { let from_next = self.next.iter(); let from_prev = self.previous.iter(); - let mut all_contained = from_prev.chain_(from_current).chain_(from_next); + let mut all_contained = from_prev.chain(from_current).chain(from_next); do all_contained.any |frame_tree| { frame_tree.contains(pipeline_id) } @@ -227,7 +225,7 @@ impl Constellation { profiler_chan: ProfilerChan) -> ConstellationChan { - let opts = Cell::new(copy *opts); + let opts = Cell::new((*opts).clone()); let (constellation_port, constellation_chan) = special_stream!(ConstellationChan); let constellation_port = Cell::new(constellation_port); @@ -285,7 +283,7 @@ impl Constellation { match request { ExitMsg(sender) => { - for self.pipelines.iter().advance |(_id, ref pipeline)| { + for (_id, ref pipeline) in self.pipelines.iter() { pipeline.exit(); } self.image_cache_task.exit(); @@ -304,7 +302,7 @@ impl Constellation { self.image_cache_task.clone(), self.resource_task.clone(), self.profiler_chan.clone(), - copy self.opts, + self.opts.clone(), { let size = self.compositor_chan.get_size(); from_value(Size2D(size.width as uint, size.height as uint)) @@ -339,7 +337,7 @@ impl Constellation { let matching_pending_frames = do self.pending_frames.iter().filter_map |frame_change| { frame_change.after.find_mut(source_pipeline_id) }; - matching_navi_frames.consume_iter().chain_(matching_pending_frames).collect() + matching_navi_frames.move_iter().chain(matching_pending_frames).collect() }; if frame_trees.is_empty() { @@ -370,7 +368,7 @@ impl Constellation { self.compositor_chan.clone(), self.image_cache_task.clone(), self.profiler_chan.clone(), - copy self.opts, + self.opts.clone(), source_pipeline, size_future) } else { @@ -382,7 +380,7 @@ impl Constellation { self.image_cache_task.clone(), self.resource_task.clone(), self.profiler_chan.clone(), - copy self.opts, + self.opts.clone(), size_future) }; @@ -391,7 +389,7 @@ impl Constellation { } else { pipeline.load(url, None); } - for frame_trees.iter().advance |frame_tree| { + for frame_tree in frame_trees.iter() { frame_tree.children.push(@mut FrameTree { pipeline: pipeline, parent: Some(source_pipeline), @@ -405,14 +403,14 @@ impl Constellation { // If there is already a pending page (self.pending_frames), it will not be overridden; // However, if the id is not encompassed by another change, it will be. LoadUrlMsg(source_id, url, size_future) => { - debug!("received message to load %s", url::to_str(&url)); + debug!("received message to load %s", url.to_str()); // Make sure no pending page would be overridden. let source_frame = self.current_frame().get_ref().find_mut(source_id).expect( "Constellation: received a LoadUrlMsg from a pipeline_id associated with a pipeline not in the active frame tree. This should be impossible."); - for self.pending_frames.iter().advance |frame_change| { + for frame_change in self.pending_frames.iter() { let old_id = frame_change.before.expect("Constellation: Received load msg from pipeline, but there is no currently active page. This should be impossible."); @@ -438,7 +436,7 @@ impl Constellation { self.image_cache_task.clone(), self.resource_task.clone(), self.profiler_chan.clone(), - copy self.opts, + self.opts.clone(), size_future); if url.path.ends_with(".js") { @@ -473,7 +471,7 @@ impl Constellation { return true } else { let old = self.current_frame().get_ref(); - for old.iter().advance |frame| { + for frame in old.iter() { frame.pipeline.revoke_paint_permission(); } } @@ -485,7 +483,7 @@ impl Constellation { return true } else { let old = self.current_frame().get_ref(); - for old.iter().advance |frame| { + for frame in old.iter() { frame.pipeline.revoke_paint_permission(); } } @@ -493,7 +491,7 @@ impl Constellation { } }; - for destination_frame.iter().advance |frame| { + for frame in destination_frame.iter() { let pipeline = &frame.pipeline; pipeline.reload(Some(constellation_msg::Navigate)); } @@ -507,7 +505,7 @@ impl Constellation { // from a pending frame. The only time that we will grant paint permission is // when the message originates from a pending frame or the current frame. - for self.current_frame().iter().advance |¤t_frame| { + for ¤t_frame in self.current_frame().iter() { // Messages originating in the current frame are not navigations; // TODO(tkuehn): In fact, this kind of message might be provably // impossible to occur. @@ -523,26 +521,26 @@ impl Constellation { let pending_index = do self.pending_frames.rposition |frame_change| { frame_change.after.pipeline.id == pipeline_id }; - for pending_index.iter().advance |&pending_index| { + for &pending_index in pending_index.iter() { let frame_change = self.pending_frames.swap_remove(pending_index); let to_add = frame_change.after; // Create the next frame tree that will be given to the compositor let next_frame_tree = match to_add.parent { None => to_add, // to_add is the root - Some(_parent) => @mut (*self.current_frame().get()).clone(), + Some(_parent) => @mut (*self.current_frame().unwrap()).clone(), }; // If there are frames to revoke permission from, do so now. match frame_change.before { Some(revoke_id) => { - let current_frame = self.current_frame().get(); + let current_frame = self.current_frame().unwrap(); let to_revoke = current_frame.find_mut(revoke_id).expect( "Constellation: pending frame change refers to an old frame not contained in the current frame. This is a bug"); - for to_revoke.iter().advance |frame| { + for frame in to_revoke.iter() { frame.pipeline.revoke_paint_permission(); } @@ -556,7 +554,7 @@ impl Constellation { // Add to_add to parent's children, if it is not the root let parent = &to_add.parent; let to_add = Cell::new(to_add); - for parent.iter().advance |parent| { + for parent in parent.iter() { let parent = next_frame_tree.find_mut(parent.id).expect( "Constellation: pending frame has a parent frame that is not active. This is a bug."); @@ -571,13 +569,13 @@ impl Constellation { ResizedWindowBroadcast(new_size) => match *self.current_frame() { Some(ref current_frame) => { let current_frame_id = current_frame.pipeline.id.clone(); - for self.navigation_context.previous.iter().advance |frame_tree| { + for frame_tree in self.navigation_context.previous.iter() { let pipeline = &frame_tree.pipeline; if current_frame_id != pipeline.id { pipeline.script_chan.send(ResizeInactiveMsg(new_size)); } } - for self.navigation_context.next.iter().advance |frame_tree| { + for frame_tree in self.navigation_context.next.iter() { let pipeline = &frame_tree.pipeline; if current_frame_id != pipeline.id { pipeline.script_chan.send(ResizeInactiveMsg(new_size)); @@ -585,10 +583,10 @@ impl Constellation { } } None => { - for self.navigation_context.previous.iter().advance |frame_tree| { + for frame_tree in self.navigation_context.previous.iter() { frame_tree.pipeline.script_chan.send(ResizeInactiveMsg(new_size)); } - for self.navigation_context.next.iter().advance |frame_tree| { + for frame_tree in self.navigation_context.next.iter() { frame_tree.pipeline.script_chan.send(ResizeInactiveMsg(new_size)); } } @@ -608,9 +606,9 @@ impl Constellation { match frame_tree.pipeline.navigation_type { Some(constellation_msg::Load) => { let evicted = self.navigation_context.load(frame_tree); - for evicted.iter().advance |frame_tree| { + for frame_tree in evicted.iter() { // exit any pipelines that don't exist outside the evicted frame trees - for frame_tree.iter().advance |frame| { + for frame in frame_tree.iter() { if !self.navigation_context.contains(frame.pipeline.id) { frame_tree.pipeline.exit(); self.pipelines.remove(&frame_tree.pipeline.id); @@ -626,7 +624,7 @@ impl Constellation { let (port, chan) = comm::stream(); self.compositor_chan.send(SetIds(frame_tree.to_sendable(), chan)); port.recv(); - for frame_tree.iter().advance |frame| { + for frame in frame_tree.iter() { frame.pipeline.grant_paint_permission(); } } diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs index b1712d286eb..f78f8c51ecd 100644 --- a/src/components/main/css/matching.rs +++ b/src/components/main/css/matching.rs @@ -11,7 +11,7 @@ use layout::incremental; use script::dom::node::{AbstractNode, LayoutView}; use newcss::complete::CompleteSelectResults; use newcss::select::{SelectCtx, SelectResults}; -use servo_util::tree::TreeUtils; +use servo_util::tree::TreeNodeRef; pub trait MatchMethods { fn restyle_subtree(&self, select_ctx: &SelectCtx); @@ -48,7 +48,7 @@ impl MatchMethods for AbstractNode { }; } - for self.each_child |kid| { + for kid in self.children() { kid.restyle_subtree(select_ctx); } } diff --git a/src/components/main/css/node_util.rs b/src/components/main/css/node_util.rs index a63ee695af5..721b8ca9132 100644 --- a/src/components/main/css/node_util.rs +++ b/src/components/main/css/node_util.rs @@ -65,7 +65,7 @@ impl<'self> NodeUtil<'self> for AbstractNode { if !self.has_layout_data() { return default; } - self.layout_data().restyle_damage.get_or_default(default) + self.layout_data().restyle_damage.unwrap_or_default(default) } /// Set the restyle damage field. diff --git a/src/components/main/css/select.rs b/src/components/main/css/select.rs index b776ade5978..d106c7bc6e9 100644 --- a/src/components/main/css/select.rs +++ b/src/components/main/css/select.rs @@ -2,10 +2,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use extra::net::url::Url; -use url_from_str = extra::net::url::from_str; +use extra::url::Url; use std::cell::Cell; -use std::result; +use std::FromStr; use newcss::stylesheet::Stylesheet; use newcss::select::SelectCtx; use newcss::types::OriginUA; @@ -29,7 +28,7 @@ fn servo_default_style() -> Stylesheet { } fn default_url(name: &str) -> Url { - result::unwrap(url_from_str(fmt!("http://%s", name))) + FromStr::from_str(fmt!("http://%s", name)).unwrap() } fn style_stream(style: &str) -> DataStream { diff --git a/src/components/main/css/select_handler.rs b/src/components/main/css/select_handler.rs index 4a294aa2426..e031b153b0f 100644 --- a/src/components/main/css/select_handler.rs +++ b/src/components/main/css/select_handler.rs @@ -101,7 +101,7 @@ impl SelectHandler> for NodeSelectHandler { None => false, Some(existing_classes) => { let mut ret = false; - for existing_classes.split_iter(' ').advance |s| { + for s in existing_classes.split_iter(' ') { if s == class { ret = true; break; diff --git a/src/components/main/layout/aux.rs b/src/components/main/layout/aux.rs index d63df74c53d..f49d73de913 100644 --- a/src/components/main/layout/aux.rs +++ b/src/components/main/layout/aux.rs @@ -9,7 +9,7 @@ use layout::incremental::RestyleDamage; use newcss::complete::CompleteSelectResults; use script::dom::node::{AbstractNode, LayoutView}; -use servo_util::tree::TreeUtils; +use servo_util::tree::TreeNodeRef; /// Data that layout associates with a node. pub struct LayoutData { @@ -37,7 +37,7 @@ impl LayoutData { /// Functionality useful for querying the layout-specific data on DOM nodes. pub trait LayoutAuxMethods { fn layout_data(self) -> @mut LayoutData; - pub fn has_layout_data(self) -> bool; + fn has_layout_data(self) -> bool; fn set_layout_data(self, data: @mut LayoutData); fn initialize_layout_data(self) -> Option<@mut LayoutData>; @@ -45,17 +45,17 @@ pub trait LayoutAuxMethods { } impl LayoutAuxMethods for AbstractNode { - pub fn layout_data(self) -> @mut LayoutData { + fn layout_data(self) -> @mut LayoutData { unsafe { self.unsafe_layout_data() } } - pub fn has_layout_data(self) -> bool { + fn has_layout_data(self) -> bool { unsafe { self.unsafe_has_layout_data() } } - pub fn set_layout_data(self, data: @mut LayoutData) { + fn set_layout_data(self, data: @mut LayoutData) { unsafe { self.unsafe_set_layout_data(data) } @@ -84,7 +84,7 @@ impl LayoutAuxMethods for AbstractNode { /// Initializes layout data and styles for a Node tree, if any nodes do not have /// this data already. Append created layout data to the task's GC roots. fn initialize_style_for_subtree(self, refs: &mut ~[@mut LayoutData]) { - let _ = for self.traverse_preorder |n| { + let _ = for n in self.traverse_preorder() { match n.initialize_layout_data() { Some(r) => refs.push(r), None => {} diff --git a/src/components/main/layout/block.rs b/src/components/main/layout/block.rs index e78bc87f158..b30794a0343 100644 --- a/src/components/main/layout/block.rs +++ b/src/components/main/layout/block.rs @@ -18,7 +18,7 @@ use geom::rect::Rect; use gfx::display_list::DisplayList; use gfx::geometry::Au; use gfx::geometry; -use servo_util::tree::{TreeNodeRef, TreeUtils}; +use servo_util::tree::TreeNodeRef; pub struct BlockFlowData { /// Data common to all flows. @@ -50,7 +50,7 @@ impl BlockFlowData { pub fn teardown(&mut self) { self.common.teardown(); - for self.box.iter().advance |box| { + for box in self.box.iter() { box.teardown(); } self.box = None; @@ -94,7 +94,7 @@ impl BlockFlowData { let mut num_floats = 0; /* find max width from child block contexts */ - for BlockFlow(self).each_child |child_ctx| { + for child_ctx in BlockFlow(self).children() { assert!(child_ctx.starts_block_flow() || child_ctx.starts_inline_flow()); do child_ctx.with_mut_base |child_node| { @@ -124,7 +124,7 @@ impl BlockFlowData { /// Computes left and right margins and width based on CSS 2.1 secion 10.3.3. /// Requires borders and padding to already be computed - priv fn compute_horiz( &self, + fn compute_horiz( &self, width: MaybeAuto, left_margin: MaybeAuto, right_margin: MaybeAuto, @@ -192,7 +192,7 @@ impl BlockFlowData { let mut remaining_width = self.common.position.size.width; let mut x_offset = Au(0); - for self.box.iter().advance |&box| { + for &box in self.box.iter() { let style = box.style(); do box.with_model |model| { // Can compute padding here since we know containing block width. @@ -239,7 +239,7 @@ impl BlockFlowData { } let has_inorder_children = self.common.is_inorder || self.common.num_floats > 0; - for BlockFlow(self).each_child |kid| { + for kid in BlockFlow(self).children() { assert!(kid.starts_block_flow() || kid.starts_inline_flow()); do kid.with_mut_base |child_node| { @@ -278,7 +278,7 @@ impl BlockFlowData { let mut left_offset = Au(0); let mut float_ctx = Invalid; - for self.box.iter().advance |&box| { + for &box in self.box.iter() { clearance = match box.clear() { None => Au(0), Some(clear) => { @@ -303,7 +303,7 @@ impl BlockFlowData { // repeat until all children are visited. // last_child.floats_out -> self.floats_out (done at the end of this method) float_ctx = self.common.floats_in.translate(Point2D(-left_offset, -top_offset)); - for BlockFlow(self).each_child |kid| { + for kid in BlockFlow(self).children() { do kid.with_mut_base |child_node| { child_node.floats_in = float_ctx.clone(); } @@ -311,10 +311,9 @@ impl BlockFlowData { do kid.with_mut_base |child_node| { float_ctx = child_node.floats_out.clone(); } - } } - for BlockFlow(self).each_child |kid| { + for kid in BlockFlow(self).children() { do kid.with_mut_base |child_node| { child_node.position.origin.y = cur_y; cur_y = cur_y + child_node.position.size.height; @@ -327,7 +326,7 @@ impl BlockFlowData { cur_y - top_offset }; - for self.box.iter().advance |&box| { + for &box in self.box.iter() { let style = box.style(); let maybe_height = MaybeAuto::from_height(style.height(), Au(0), style.font_size()); let maybe_height = maybe_height.specified_or_zero(); @@ -380,7 +379,7 @@ impl BlockFlowData { // go deeper into the flow tree let flow = BlockFlow(self); - for flow.each_child |child| { + for child in flow.children() { do child.with_mut_base |base| { base.abs_position = self.common.abs_position + base.position.origin; } diff --git a/src/components/main/layout/box.rs b/src/components/main/layout/box.rs index f9b63ed65ed..ac37c30d9a8 100644 --- a/src/components/main/layout/box.rs +++ b/src/components/main/layout/box.rs @@ -16,7 +16,6 @@ use std::cell::Cell; use std::cmp::ApproxEq; use std::managed; use std::num::Zero; -use std::uint; use geom::{Point2D, Rect, Size2D, SideOffsets2D}; use gfx::display_list::{BaseDisplayItem, BorderDisplayItem, BorderDisplayItemClass}; use gfx::display_list::{DisplayList, ImageDisplayItem, ImageDisplayItemClass}; @@ -38,7 +37,7 @@ use script::dom::node::{AbstractNode, LayoutView}; use servo_net::image::holder::ImageHolder; use servo_net::local_image_cache::LocalImageCache; use servo_util::range::*; -use extra::net::url::Url; +use extra::url::Url; /// Render boxes (`struct RenderBox`) are the leaves of the layout tree. They cannot position /// themselves. In general, render boxes do not have a simple correspondence with CSS boxes as in @@ -292,14 +291,13 @@ impl RenderBox { text_box.range, max_width); - for text_box.run.iter_slices_for_range(&text_box.range) - |glyphs, offset, slice_range| { + for (glyphs, offset, slice_range) in text_box.run.iter_slices_for_range(&text_box.range) { debug!("split_to_width: considering slice (offset=%?, range=%?, remain_width=%?)", offset, slice_range, remaining_width); - let metrics = text_box.run.metrics_for_slice(glyphs, slice_range); + let metrics = text_box.run.metrics_for_slice(glyphs, &slice_range); let advance = metrics.advance_width; let should_continue: bool; @@ -385,7 +383,7 @@ impl RenderBox { // // TODO(eatkinson): integrate with // get_min_width and get_pref_width? - priv fn guess_width (&self) -> Au { + fn guess_width (&self) -> Au { do self.with_base |base| { if(!base.node.is_element()) { Au(0) @@ -433,7 +431,7 @@ impl RenderBox { ImageRenderBoxClass(image_box) => { // TODO: Consult the CSS `width` property as well as margins and borders. // TODO: If the image isn't available, consult `width`. - Au::from_px(image_box.image.get_size().get_or_default(Size2D(0, 0)).width) + Au::from_px(image_box.image.get_size().unwrap_or_default(Size2D(0, 0)).width) } TextRenderBoxClass(text_box) => { @@ -454,7 +452,7 @@ impl RenderBox { GenericRenderBoxClass(*) => Au(0), ImageRenderBoxClass(image_box) => { - Au::from_px(image_box.image.get_size().get_or_default(Size2D(0, 0)).width) + Au::from_px(image_box.image.get_size().unwrap_or_default(Size2D(0, 0)).width) } TextRenderBoxClass(text_box) => { @@ -465,9 +463,8 @@ impl RenderBox { // report nothing and the parent flow can factor in minimum/preferred widths of any // text runs that it owns. let mut max_line_width = Au(0); - for text_box.run.iter_natural_lines_for_range(&text_box.range) - |line_range| { - let line_metrics = text_box.run.metrics_for_range(line_range); + for line_range in text_box.run.iter_natural_lines_for_range(&text_box.range) { + let line_metrics = text_box.run.metrics_for_range(&line_range); max_line_width = Au::max(max_line_width, line_metrics.advance_width); } @@ -782,7 +779,7 @@ impl RenderBox { // FIXME: Too much allocation here. let font_families = do my_style.font_family().map |family| { match *family { - CSSFontFamilyFamilyName(ref family_str) => copy *family_str, + CSSFontFamilyFamilyName(ref family_str) => (*family_str).clone(), CSSFontFamilyGenericFamily(Serif) => ~"serif", CSSFontFamilyGenericFamily(SansSerif) => ~"sans-serif", CSSFontFamilyGenericFamily(Cursive) => ~"cursive", @@ -823,7 +820,7 @@ impl RenderBox { self.nearest_ancestor_element().style().text_align() } - fn line_height(&self) -> CSSLineHeight { + pub fn line_height(&self) -> CSSLineHeight { self.nearest_ancestor_element().style().line_height() } @@ -875,7 +872,7 @@ impl RenderBox { /// Dumps a render box for debugging, with indentation. pub fn dump_indent(&self, indent: uint) { let mut string = ~""; - for uint::range(0u, indent) |_i| { + for _ in range(0u, indent) { string.push_str(" "); } diff --git a/src/components/main/layout/box_builder.rs b/src/components/main/layout/box_builder.rs index 643a7b80b5d..3e7cd563206 100644 --- a/src/components/main/layout/box_builder.rs +++ b/src/components/main/layout/box_builder.rs @@ -30,7 +30,7 @@ use script::dom::element::*; use script::dom::node::{AbstractNode, CommentNodeTypeId, DoctypeNodeTypeId}; use script::dom::node::{ElementNodeTypeId, LayoutView, TextNodeTypeId}; use servo_util::range::Range; -use servo_util::tree::{TreeNodeRef, TreeNode, TreeUtils}; +use servo_util::tree::{TreeNodeRef, TreeNode}; pub struct LayoutTreeBuilder { root_flow: Option, @@ -60,7 +60,7 @@ enum InlineSpacerSide { LogicalAfter, } -priv fn simulate_UA_display_rules(node: AbstractNode) -> CSSDisplay { +fn simulate_UA_display_rules(node: AbstractNode) -> CSSDisplay { // FIXME /*let resolved = do node.aux |nd| { match nd.style.display_type { @@ -145,8 +145,7 @@ impl BoxGenerator { } else if self.inline_spacers_needed_for_node(node) { // else, maybe make a spacer for "left" margin, border, padding let inline_spacer = self.make_inline_spacer_for_node_side(ctx, node, LogicalBefore); - for inline_spacer.iter().advance - |spacer: &RenderBox| { + for spacer in inline_spacer.iter() { inline.boxes.push(*spacer); } } @@ -220,7 +219,7 @@ impl BoxGenerator { // If this non-leaf box generates extra horizontal spacing, add a SpacerBox for // it. let result = self.make_inline_spacer_for_node_side(ctx, node, LogicalAfter); - for result.iter().advance |spacer| { + for spacer in result.iter() { let boxes = &mut self.flow.inline().boxes; boxes.push(*spacer); } @@ -269,7 +268,7 @@ impl BoxGenerator { do node.with_imm_image_element |image_element| { if image_element.image.is_some() { // FIXME(pcwalton): Don't copy URLs. - let url = copy *image_element.image.get_ref(); + let url = (*image_element.image.get_ref()).clone(); ImageRenderBoxClass(@mut ImageRenderBox::new(base, url, layout_ctx.image_cache)) } else { info!("Tried to make image box, but couldn't find image. Made generic box \ @@ -328,7 +327,7 @@ impl LayoutTreeBuilder { // recurse on child nodes. let mut prev_generator: Option<@mut BoxGenerator> = None; - for cur_node.each_child |child_node| { + for child_node in cur_node.children() { prev_generator = self.construct_recursively(layout_ctx, child_node, this_generator, prev_generator); } @@ -340,7 +339,7 @@ impl LayoutTreeBuilder { // eventually be elided or split, but the mapping between // nodes and FlowContexts should not change during layout. let flow: &FlowContext = &this_generator.flow; - for flow.each_child |child_flow| { + for child_flow in flow.children() { do child_flow.with_base |child_node| { let dom_node = child_node.node; assert!(dom_node.has_layout_data()); @@ -403,22 +402,22 @@ impl LayoutTreeBuilder { // Floats (CSSDisplayBlock, BlockFlow(_), _) | (CSSDisplayBlock, FloatFlow(_), _) if !is_float.is_none() => { - self.create_child_generator(node, parent_generator, Flow_Float(is_float.get())) + self.create_child_generator(node, parent_generator, Flow_Float(is_float.unwrap())) } // If we're placing a float after an inline, append the float to the inline flow, // then continue building from the inline flow in case there are more inlines // afterward. (CSSDisplayBlock, _, Some(InlineFlow(_))) if !is_float.is_none() => { let float_generator = self.create_child_generator(node, - sibling_generator.get(), - Flow_Float(is_float.get())); - return Some((float_generator, sibling_generator.get())); + sibling_generator.unwrap(), + Flow_Float(is_float.unwrap())); + return Some((float_generator, sibling_generator.unwrap())); } // This is a catch-all case for when: // a) sibling_flow is None // b) sibling_flow is a BlockFlow (CSSDisplayBlock, InlineFlow(_), _) if !is_float.is_none() => { - self.create_child_generator(node, parent_generator, Flow_Float(is_float.get())) + self.create_child_generator(node, parent_generator, Flow_Float(is_float.unwrap())) } (CSSDisplayBlock, BlockFlow(info), _) => match (info.is_root, node.parent_node()) { @@ -515,7 +514,7 @@ impl LayoutTreeBuilder { let mut found_child_block = false; let flow = *parent_flow; - for flow.each_child |child_ctx: FlowContext| { + for child_ctx in flow.children() { match child_ctx { InlineFlow(*) | InlineBlockFlow(*) => found_child_inline = true, BlockFlow(*) => found_child_block = true, @@ -535,7 +534,7 @@ impl LayoutTreeBuilder { let first_child = do parent_flow.with_base |parent_node| { parent_node.first_child }; - for first_child.iter().advance |&first_flow| { + for &first_flow in first_child.iter() { if first_flow.starts_inline_flow() { // FIXME: workaround for rust#6393 let mut do_remove = false; @@ -558,7 +557,7 @@ impl LayoutTreeBuilder { let last_child = do parent_flow.with_base |parent_node| { parent_node.last_child }; - for last_child.iter().advance |&last_flow| { + for &last_flow in last_child.iter() { if last_flow.starts_inline_flow() { // FIXME: workaround for rust#6393 let mut do_remove = false; @@ -580,7 +579,7 @@ impl LayoutTreeBuilder { // Issue 543: We only need to do this if there are inline child // flows, but there's not a quick way to check at the moment. - for (*parent_flow).each_child |child_flow: FlowContext| { + for child_flow in (*parent_flow).children() { match child_flow { InlineFlow(*) | InlineBlockFlow(*) => { let mut scanner = TextRunScanner::new(); diff --git a/src/components/main/layout/float.rs b/src/components/main/layout/float.rs index 2a2758d4aab..6f8107bb46e 100644 --- a/src/components/main/layout/float.rs +++ b/src/components/main/layout/float.rs @@ -15,7 +15,7 @@ use geom::rect::Rect; use gfx::display_list::DisplayList; use gfx::geometry::Au; use gfx::geometry; -use servo_util::tree::{TreeNodeRef, TreeUtils}; +use servo_util::tree::TreeNodeRef; pub struct FloatFlowData { /// Data common to all flows. @@ -55,7 +55,7 @@ impl FloatFlowData { pub fn teardown(&mut self) { self.common.teardown(); - for self.box.iter().advance |box| { + for box in self.box.iter() { box.teardown(); } self.box = None; @@ -69,7 +69,7 @@ impl FloatFlowData { let mut pref_width = Au(0); let mut num_floats = 0; - for FloatFlow(self).each_child |child_ctx| { + for child_ctx in FloatFlow(self).children() { //assert!(child_ctx.starts_block_flow() || child_ctx.starts_inline_flow()); do child_ctx.with_mut_base |child_node| { @@ -108,7 +108,7 @@ impl FloatFlowData { // Parent usually sets this, but floats are never inorder self.common.is_inorder = false; - for self.box.iter().advance |&box| { + for &box in self.box.iter() { let style = box.style(); do box.with_model |model| { // Can compute padding here since we know containing block width. @@ -162,7 +162,7 @@ impl FloatFlowData { self.common.position.size.width = remaining_width; let has_inorder_children = self.common.num_floats > 0; - for FloatFlow(self).each_child |kid| { + for kid in FloatFlow(self).children() { //assert!(kid.starts_block_flow() || kid.starts_inline_flow()); do kid.with_mut_base |child_node| { @@ -199,15 +199,13 @@ impl FloatFlowData { }; do box.with_base |base| { + let noncontent_width = base.model.padding.left + base.model.padding.right + + base.model.border.left + base.model.border.right; + let noncontent_height = base.model.padding.top + base.model.padding.bottom + + base.model.border.top + base.model.border.bottom; - let noncontent_width = base.model.padding.left + base.model.padding.right + - base.model.border.left + base.model.border.right; - let noncontent_height = base.model.padding.top + base.model.padding.bottom + - base.model.border.top + base.model.border.bottom; - - full_noncontent_width = noncontent_width + base.model.margin.left + base.model.margin.right; - full_noncontent_height = noncontent_height + base.model.margin.top + base.model.margin.bottom; - + full_noncontent_width = noncontent_width + base.model.margin.left + base.model.margin.right; + full_noncontent_height = noncontent_height + base.model.margin.top + base.model.margin.bottom; } }); @@ -231,7 +229,7 @@ impl FloatFlowData { let has_inorder_children = self.common.num_floats > 0; if has_inorder_children { let mut float_ctx = FloatContext::new(self.floated_children); - for FloatFlow(self).each_child |kid| { + for kid in FloatFlow(self).children() { do kid.with_mut_base |child_node| { child_node.floats_in = float_ctx.clone(); } @@ -245,14 +243,14 @@ impl FloatFlowData { let mut cur_y = Au(0); let mut top_offset = Au(0); - for self.box.iter().advance |&box| { + for &box in self.box.iter() { do box.with_model |model| { top_offset = model.margin.top + model.border.top + model.padding.top; cur_y = cur_y + top_offset; } } - for FloatFlow(self).each_child |kid| { + for kid in FloatFlow(self).children() { do kid.with_mut_base |child_node| { child_node.position.origin.y = cur_y; cur_y = cur_y + child_node.position.size.height; @@ -279,7 +277,7 @@ impl FloatFlowData { //TODO(eatkinson): compute heights properly using the 'height' property. - for self.box.iter().advance |&box| { + for &box in self.box.iter() { let height_prop = MaybeAuto::from_height(box.style().height(), Au(0), @@ -316,7 +314,7 @@ impl FloatFlowData { // go deeper into the flow tree let flow = FloatFlow(self); - for flow.each_child |child| { + for child in flow.children() { do child.with_mut_base |base| { base.abs_position = offset + base.position.origin; } diff --git a/src/components/main/layout/float_context.rs b/src/components/main/layout/float_context.rs index 5528d5ae8f7..3c4bf3773ad 100644 --- a/src/components/main/layout/float_context.rs +++ b/src/components/main/layout/float_context.rs @@ -10,6 +10,7 @@ use std::util::replace; use std::vec; use std::i32::max_value; +#[deriving(Clone)] pub enum FloatType{ FloatLeft, FloatRight @@ -28,6 +29,7 @@ struct FloatContextBase{ offset: Point2D } +#[deriving(Clone)] struct FloatData{ bounds: Rect, f_type: FloatType @@ -174,7 +176,7 @@ impl FloatContextBase{ let mut r_bottom = None; // Find the float collisions for the given vertical range. - for self.float_data.iter().advance |float| { + for float in self.float_data.iter() { debug!("available_rect: Checking for collision against float"); match *float{ None => (), @@ -268,7 +270,7 @@ impl FloatContextBase{ /// Returns true if the given rect overlaps with any floats. fn collides_with_float(&self, bounds: &Rect) -> bool { - for self.float_data.iter().advance |float| { + for float in self.float_data.iter() { match *float{ None => (), Some(data) => { @@ -290,7 +292,7 @@ impl FloatContextBase{ let left = left - self.offset.x; let mut max_height = None; - for self.float_data.iter().advance |float| { + for float in self.float_data.iter() { match *float { None => (), Some(f_data) => { @@ -298,7 +300,7 @@ impl FloatContextBase{ f_data.bounds.origin.x + f_data.bounds.size.width > left && f_data.bounds.origin.x < left + width { let new_y = f_data.bounds.origin.y; - max_height = Some(min(max_height.get_or_default(new_y), new_y)); + max_height = Some(min(max_height.unwrap_or_default(new_y), new_y)); } } } @@ -338,7 +340,7 @@ impl FloatContextBase{ let height = self.max_height_for_bounds(rect.origin.x, rect.origin.y, rect.size.width); - let height = height.get_or_default(Au(max_value)); + let height = height.unwrap_or_default(Au(max_value)); return match info.f_type { FloatLeft => Rect(Point2D(rect.origin.x, float_y), Size2D(rect.size.width, height)), @@ -359,7 +361,7 @@ impl FloatContextBase{ fn clearance(&self, clear: ClearType) -> Au { let mut clearance = Au(0); - for self.float_data.iter().advance |float| { + for float in self.float_data.iter() { match *float { None => (), Some(f_data) => { diff --git a/src/components/main/layout/flow.rs b/src/components/main/layout/flow.rs index 2d7db5d4a3c..83edbfa61ba 100644 --- a/src/components/main/layout/flow.rs +++ b/src/components/main/layout/flow.rs @@ -36,14 +36,13 @@ use layout::incremental::RestyleDamage; use css::node_style::StyledNode; use std::cell::Cell; -use std::uint; use std::io::stderr; use geom::point::Point2D; use geom::rect::Rect; use gfx::display_list::DisplayList; use gfx::geometry::Au; use script::dom::node::{AbstractNode, LayoutView}; -use servo_util::tree::{TreeNode, TreeNodeRef, TreeUtils}; +use servo_util::tree::{TreeNode, TreeNodeRef}; /// The type of the formatting context and data specific to each context, such as line box /// structures or float lists. @@ -84,29 +83,25 @@ impl FlowContext { // // FIXME: Unify this with traverse_preorder_prune, which takes a separate // 'prune' function. - fn partially_traverse_preorder(&self, callback: &fn(FlowContext) -> bool) { + pub fn partially_traverse_preorder(&self, callback: &fn(FlowContext) -> bool) { if !callback((*self).clone()) { return; } - for self.each_child |kid| { + for kid in self.children() { // FIXME: Work around rust#2202. We should be able to pass the callback directly. kid.partially_traverse_preorder(|a| callback(a)); } } - fn traverse_bu_sub_inorder (&self, callback: &fn(FlowContext) -> bool) -> bool { - for self.each_child |kid| { + pub fn traverse_bu_sub_inorder (&self, callback: &fn(FlowContext)) { + for kid in self.children() { // FIXME: Work around rust#2202. We should be able to pass the callback directly. - if !kid.traverse_bu_sub_inorder(|a| callback(a)) { - return false; - } + kid.traverse_bu_sub_inorder(|a| callback(a)); } if !self.is_inorder() { callback((*self).clone()) - } else { - true } } } @@ -119,14 +114,14 @@ impl FlowData { // or we risk dynamic borrow failures. self.parent = None; - for self.first_child.iter().advance |flow| { + for flow in self.first_child.iter() { flow.teardown(); } self.first_child = None; self.last_child = None; - for self.next_sibling.iter().advance |flow| { + for flow in self.next_sibling.iter() { flow.teardown(); } self.next_sibling = None; @@ -164,8 +159,50 @@ impl TreeNodeRef for FlowContext { TableFlow(info) => callback(info), } } + + fn parent_node(node: &FlowData) -> Option { + node.parent + } + + fn first_child(node: &FlowData) -> Option { + node.first_child + } + + fn last_child(node: &FlowData) -> Option { + node.last_child + } + + fn prev_sibling(node: &FlowData) -> Option { + node.prev_sibling + } + + fn next_sibling(node: &FlowData) -> Option { + node.next_sibling + } + + fn set_parent_node(node: &mut FlowData, new_parent_node: Option) { + node.parent = new_parent_node + } + + fn set_first_child(node: &mut FlowData, new_first_child: Option) { + node.first_child = new_first_child + } + + fn set_last_child(node: &mut FlowData, new_last_child: Option) { + node.last_child = new_last_child + } + + fn set_prev_sibling(node: &mut FlowData, new_prev_sibling: Option) { + node.prev_sibling = new_prev_sibling + } + + fn set_next_sibling(node: &mut FlowData, new_next_sibling: Option) { + node.next_sibling = new_next_sibling + } } +impl TreeNode for FlowData { } + /// Data common to all flows. /// /// FIXME: We need a naming convention for pseudo-inheritance like this. How about @@ -196,45 +233,20 @@ pub struct FlowData { is_inorder: bool, } -impl TreeNode for FlowData { - fn parent_node(&self) -> Option { - self.parent - } +pub struct BoxIterator { + priv boxes: ~[RenderBox], + priv index: uint, +} - fn first_child(&self) -> Option { - self.first_child - } - - fn last_child(&self) -> Option { - self.last_child - } - - fn prev_sibling(&self) -> Option { - self.prev_sibling - } - - fn next_sibling(&self) -> Option { - self.next_sibling - } - - fn set_parent_node(&mut self, new_parent_node: Option) { - self.parent = new_parent_node - } - - fn set_first_child(&mut self, new_first_child: Option) { - self.first_child = new_first_child - } - - fn set_last_child(&mut self, new_last_child: Option) { - self.last_child = new_last_child - } - - fn set_prev_sibling(&mut self, new_prev_sibling: Option) { - self.prev_sibling = new_prev_sibling - } - - fn set_next_sibling(&mut self, new_next_sibling: Option) { - self.next_sibling = new_next_sibling +impl Iterator for BoxIterator { + fn next(&mut self) -> Option { + if self.index >= self.boxes.len() { + None + } else { + let v = self.boxes[self.index].clone(); + self.index += 1; + Some(v) + } } } @@ -408,43 +420,15 @@ impl<'self> FlowContext { } } - pub fn iter_all_boxes(&self, cb: &fn(RenderBox) -> bool) -> bool { - match *self { - BlockFlow(block) => { - let block = &mut *block; - for block.box.iter().advance |box| { - if !cb(*box) { - break; - } - } - } - InlineFlow(inline) => { - let inline = &mut *inline; - for inline.boxes.iter().advance |box| { - if !cb(*box) { - break; - } - } - } - _ => fail!(fmt!("Don't know how to iterate node's RenderBoxes for %?", self)) + pub fn iter_all_boxes(&self) -> BoxIterator { + BoxIterator { + boxes: match *self { + BlockFlow (block) => block.box.map_default(~[], |&x| ~[x]), + InlineFlow(inline) => inline.boxes.clone(), + _ => fail!(fmt!("Don't know how to iterate node's RenderBoxes for %?", self)) + }, + index: 0, } - - true - } - - pub fn iter_boxes_for_node(&self, - node: AbstractNode, - callback: &fn(RenderBox) -> bool) - -> bool { - for self.iter_all_boxes |box| { - if box.node() == node { - if !callback(box) { - break; - } - } - } - - true } /// Dumps the flow tree for debugging. @@ -455,7 +439,7 @@ impl<'self> FlowContext { /// Dumps the flow tree, for debugging, with indentation. pub fn dump_indent(&self, indent: uint) { let mut s = ~"|"; - for uint::range(0, indent) |_i| { + for _ in range(0, indent) { s.push_str("---- "); } @@ -463,7 +447,7 @@ impl<'self> FlowContext { stderr().write_line(s); // FIXME: this should have a pure/const version? - for self.each_child |child| { + for child in self.children() { child.dump_indent(indent + 1) } } diff --git a/src/components/main/layout/inline.rs b/src/components/main/layout/inline.rs index 3886695c4d3..d1a9c5e9708 100644 --- a/src/components/main/layout/inline.rs +++ b/src/components/main/layout/inline.rs @@ -21,8 +21,9 @@ use newcss::values::{CSSTextAlignLeft, CSSTextAlignCenter, CSSTextAlignRight, CS use newcss::units::{Em, Px, Pt}; use newcss::values::{CSSLineHeightNormal, CSSLineHeightNumber, CSSLineHeightLength, CSSLineHeightPercentage}; use servo_util::range::Range; -use servo_util::tree::{TreeNodeRef, TreeUtils}; -use extra::deque::Deque; +use servo_util::tree::TreeNodeRef; +use extra::container::Deque; +use extra::ringbuf::RingBuf; /* Lineboxes are represented as offsets into the child list, rather than @@ -62,7 +63,7 @@ struct LineboxScanner { flow: FlowContext, floats: FloatContext, new_boxes: ~[RenderBox], - work_list: @mut Deque, + work_list: @mut RingBuf, pending_line: LineBox, lines: ~[LineBox], cur_y: Au, @@ -76,7 +77,7 @@ impl LineboxScanner { flow: inline, floats: float_ctx, new_boxes: ~[], - work_list: @mut Deque::new(), + work_list: @mut RingBuf::new(), pending_line: LineBox { range: Range::empty(), bounds: Rect(Point2D(Au(0), Au(0)), Size2D(Au(0), Au(0))), @@ -122,7 +123,7 @@ impl LineboxScanner { debug!("LineboxScanner: Working with box from box list: b%d", box.id()); box } else { - let box = self.work_list.pop_front(); + let box = self.work_list.pop_front().unwrap(); debug!("LineboxScanner: Working with box from work list: b%d", box.id()); box }; @@ -176,7 +177,7 @@ impl LineboxScanner { match box { ImageRenderBoxClass(image_box) => { let size = image_box.image.get_size(); - let height = Au::from_px(size.get_or_default(Size2D(0, 0)).height); + let height = Au::from_px(size.unwrap_or_default(Size2D(0, 0)).height); image_box.base.position.size.height = height; debug!("box_height: found image height: %?", height); height @@ -360,11 +361,11 @@ impl LineboxScanner { self.pending_line.green_zone = next_green_zone; assert!(!line_is_empty, "Non-terminating line breaking"); - self.work_list.add_front(in_box); + self.work_list.push_front(in_box); return true; } else { debug!("LineboxScanner: case=adding box collides vertically with floats: breaking line"); - self.work_list.add_front(in_box); + self.work_list.push_front(in_box); return false; } } @@ -407,7 +408,7 @@ impl LineboxScanner { match (left, right) { (Some(left_box), Some(right_box)) => { self.push_box_to_line(left_box); - self.work_list.add_front(right_box); + self.work_list.push_front(right_box); } (Some(left_box), None) => self.push_box_to_line(left_box), (None, Some(right_box)) => self.push_box_to_line(right_box), @@ -423,7 +424,7 @@ impl LineboxScanner { match (left, right) { (Some(left_box), Some(right_box)) => { self.push_box_to_line(left_box); - self.work_list.add_front(right_box); + self.work_list.push_front(right_box); } (Some(left_box), None) => { self.push_box_to_line(left_box); @@ -438,7 +439,7 @@ impl LineboxScanner { return true; } else { debug!("LineboxScanner: case=split box didn't fit, not appending and deferring original box."); - self.work_list.add_front(in_box); + self.work_list.push_front(in_box); return false; } } @@ -491,7 +492,7 @@ impl InlineFlowData { pub fn teardown(&mut self) { self.common.teardown(); - for self.boxes.iter().advance |box| { + for box in self.boxes.iter() { box.teardown(); } self.boxes = ~[]; @@ -515,7 +516,7 @@ impl InlineFlowData { pub fn bubble_widths_inline(@mut self, ctx: &mut LayoutContext) { let mut num_floats = 0; - for InlineFlow(self).each_child |kid| { + for kid in InlineFlow(self).children() { do kid.with_mut_base |base| { num_floats += base.num_floats; base.floats_in = FloatContext::new(base.num_floats); @@ -528,7 +529,7 @@ impl InlineFlowData { let mut min_width = Au(0); let mut pref_width = Au(0); - for this.boxes.iter().advance |box| { + for box in this.boxes.iter() { 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)); @@ -549,11 +550,11 @@ impl InlineFlowData { // `RenderBox`. { let this = &mut *self; - for this.boxes.iter().advance |&box| { + for &box in this.boxes.iter() { match box { ImageRenderBoxClass(image_box) => { let size = image_box.image.get_size(); - let width = Au::from_px(size.get_or_default(Size2D(0, 0)).width); + let width = Au::from_px(size.unwrap_or_default(Size2D(0, 0)).width); image_box.base.position.size.width = width; } TextRenderBoxClass(_) => { @@ -571,7 +572,7 @@ impl InlineFlowData { } // End of for loop. } - for InlineFlow(self).each_child |kid| { + for kid in InlineFlow(self).children() { do kid.with_mut_base |base| { base.position.size.width = self.common.position.size.width; base.is_inorder = self.common.is_inorder; @@ -587,7 +588,7 @@ impl InlineFlowData { } pub fn assign_height_inorder_inline(@mut self, ctx: &mut LayoutContext) { - for InlineFlow(self).each_child |kid| { + for kid in InlineFlow(self).children() { kid.assign_height_inorder(ctx); } self.assign_height_inline(ctx); @@ -607,7 +608,7 @@ impl InlineFlowData { scanner.scan_for_lines(); // Now, go through each line and lay out the boxes inside - for self.lines.iter().advance |line| { + for line in self.lines.iter() { // We need to distribute extra width based on text-align. let mut slack_width = line.green_zone.width - line.bounds.size.width; if slack_width < Au(0) { @@ -633,7 +634,7 @@ impl InlineFlowData { // So sorry, but justified text is more complicated than shuffling linebox coordinates. // TODO(Issue #213): implement `text-align: justify` CSSTextAlignLeft | CSSTextAlignJustify => { - for line.range.eachi |i| { + for i in line.range.eachi() { do self.boxes[i].with_mut_base |base| { base.position.origin.x = offset_x; offset_x = offset_x + base.position.size.width; @@ -642,7 +643,7 @@ impl InlineFlowData { } CSSTextAlignCenter => { offset_x = offset_x + slack_width.scale_by(0.5f); - for line.range.eachi |i| { + for i in line.range.eachi() { do self.boxes[i].with_mut_base |base| { base.position.origin.x = offset_x; offset_x = offset_x + base.position.size.width; @@ -651,7 +652,7 @@ impl InlineFlowData { } CSSTextAlignRight => { offset_x = offset_x + slack_width; - for line.range.eachi |i| { + for i in line.range.eachi() { do self.boxes[i].with_mut_base |base| { base.position.origin.x = offset_x; offset_x = offset_x + base.position.size.width; @@ -665,13 +666,13 @@ impl InlineFlowData { // the baseline. let mut baseline_offset = Au(0); let mut max_height = Au(0); - for line.range.eachi |box_i| { + for box_i in line.range.eachi() { let cur_box = self.boxes[box_i]; match cur_box { ImageRenderBoxClass(image_box) => { let size = image_box.image.get_size(); - let height = Au::from_px(size.get_or_default(Size2D(0, 0)).height); + let height = Au::from_px(size.unwrap_or_default(Size2D(0, 0)).height); image_box.base.position.size.height = height; image_box.base.position.translate(&Point2D(Au(0), -height)) @@ -718,7 +719,7 @@ impl InlineFlowData { } // Now go back and adjust the Y coordinates to match the baseline we determined. - for line.range.eachi |box_i| { + for box_i in line.range.eachi() { let cur_box = self.boxes[box_i]; // TODO(#226): This is completely wrong. We need to use the element's `line-height` @@ -765,7 +766,7 @@ impl InlineFlowData { self.common.id, self.boxes.len()); - for self.boxes.iter().advance |box| { + for box in self.boxes.iter() { box.build_display_list(builder, dirty, &self.common.abs_position, list) } diff --git a/src/components/main/layout/layout_task.rs b/src/components/main/layout/layout_task.rs index 5170d6f5f88..a3e7901c3c0 100644 --- a/src/components/main/layout/layout_task.rs +++ b/src/components/main/layout/layout_task.rs @@ -41,10 +41,10 @@ use script::script_task::{ReflowCompleteMsg, ScriptChan, SendEventMsg}; use servo_msg::constellation_msg::{ConstellationChan, PipelineId}; use servo_net::image_cache_task::{ImageCacheTask, ImageResponseMsg}; use servo_net::local_image_cache::LocalImageCache; -use servo_util::tree::{TreeNodeRef, TreeUtils}; +use servo_util::tree::TreeNodeRef; use servo_util::time::{ProfilerChan, profile}; use servo_util::time; -use extra::net::url::Url; +use extra::url::Url; struct LayoutTask { id: PipelineId, @@ -181,7 +181,7 @@ impl LayoutTask { }; // FIXME: Bad copy! - let doc_url = copy data.url; + let doc_url = data.url.clone(); let script_chan = data.script_chan.clone(); debug!("layout: received layout request for: %s", doc_url.to_str()); @@ -232,7 +232,7 @@ impl LayoutTask { // Propagate restyle damage up and down the tree, as appropriate. // FIXME: Merge this with flow tree building and/or the other traversals. - for layout_root.traverse_preorder |flow| { + for flow in layout_root.traverse_preorder() { // Also set any damage implied by resize. if resized { do flow.with_mut_base |base| { @@ -242,7 +242,7 @@ impl LayoutTask { let prop = flow.with_base(|base| base.restyle_damage.propagate_down()); if prop.is_nonempty() { - for flow.each_child |kid_ctx| { + for kid_ctx in flow.children() { do kid_ctx.with_mut_base |kid| { kid.restyle_damage.union_in_place(prop); } @@ -250,8 +250,8 @@ impl LayoutTask { } } - for layout_root.traverse_postorder |flow| { - for flow.each_child |child| { + for flow in layout_root.traverse_postorder() { + for child in flow.children() { do child.with_base |child_base| { do flow.with_mut_base |base| { base.restyle_damage.union_in_place(child_base.restyle_damage); @@ -266,20 +266,20 @@ impl LayoutTask { // Perform the primary layout passes over the flow tree to compute the locations of all // the boxes. do profile(time::LayoutMainCategory, self.profiler_chan.clone()) { - for layout_root.traverse_postorder_prune(|f| f.restyle_damage().lacks(BubbleWidths)) |flow| { + for flow in layout_root.traverse_postorder_prune(|f| f.restyle_damage().lacks(BubbleWidths)) { flow.bubble_widths(&mut layout_ctx); }; // FIXME: We want to do - // for layout_root.traverse_preorder_prune(|f| f.restyle_damage().lacks(Reflow)) |flow| { + // for flow in layout_root.traverse_preorder_prune(|f| f.restyle_damage().lacks(Reflow)) { // but FloatContext values can't be reused, so we need to recompute them every time. - for layout_root.traverse_preorder |flow| { + for flow in layout_root.traverse_preorder() { flow.assign_widths(&mut layout_ctx); }; // For now, this is an inorder traversal // FIXME: prune this traversal as well - for layout_root.traverse_bu_sub_inorder |flow| { + do layout_root.traverse_bu_sub_inorder |flow| { flow.assign_height(&mut layout_ctx); } } @@ -366,8 +366,10 @@ impl LayoutTask { None => Err(()), Some(flow) => { let mut boxes = ~[]; - for flow.iter_boxes_for_node(node) |box| { - boxes.push(box.content_box()); + for box in flow.iter_all_boxes() { + if box.node() == node { + boxes.push(box.content_box()); + } } Ok(ContentBoxesResponse(boxes)) @@ -382,7 +384,7 @@ impl LayoutTask { transmute(node) }; let mut flow_node: AbstractNode = node; - for node.traverse_preorder |node| { + for node in node.traverse_preorder() { if node.layout_data().flow.is_some() { flow_node = node; break; @@ -413,7 +415,7 @@ impl LayoutTask { let mut resp = Err(()); let display_list = &display_list.take().list; // iterate in reverse to ensure we have the most recently painted render box - for display_list.rev_iter().advance |display_item| { + for display_item in display_list.rev_iter() { let bounds = display_item.bounds(); // TODO this check should really be performed by a method of DisplayItem if x <= bounds.origin.x + bounds.size.width && diff --git a/src/components/main/layout/text.rs b/src/components/main/layout/text.rs index cf9d8f49bcc..1e744a4f337 100644 --- a/src/components/main/layout/text.rs +++ b/src/components/main/layout/text.rs @@ -4,7 +4,6 @@ //! Text layout. -use std::uint; use std::vec; use gfx::text::text_run::TextRun; @@ -13,7 +12,6 @@ use layout::box::{RenderBox, RenderBoxBase, TextRenderBox}; use layout::box::{TextRenderBoxClass, UnscannedTextRenderBoxClass}; use layout::context::LayoutContext; use layout::flow::FlowContext; -use layout::util::{NodeRange}; use newcss::values::{CSSTextDecoration, CSSTextDecorationUnderline}; use servo_util::range::Range; @@ -50,7 +48,7 @@ pub trait UnscannedMethods { impl UnscannedMethods for RenderBox { fn raw_text(&self) -> ~str { match *self { - UnscannedTextRenderBoxClass(text_box) => copy text_box.text, + UnscannedTextRenderBoxClass(text_box) => text_box.text.clone(), _ => fail!(~"unsupported operation: box.raw_text() on non-unscanned text box."), } } @@ -75,7 +73,7 @@ impl TextRunScanner { let mut last_whitespace = true; let mut out_boxes = ~[]; - for uint::range(0, flow.inline().boxes.len()) |box_i| { + for box_i in range(0, flow.inline().boxes.len()) { debug!("TextRunScanner: considering box: %?", flow.inline().boxes[box_i].debug_str()); if box_i > 0 && !can_coalesce_text_nodes(flow.inline().boxes, box_i-1, box_i) { last_whitespace = self.flush_clump_to_list(ctx, flow, last_whitespace, &mut out_boxes); @@ -204,7 +202,7 @@ impl TextRunScanner { let mut run_str: ~str = ~""; let mut new_ranges: ~[Range] = ~[]; let mut char_total = 0; - for uint::range(0, transformed_strs.len()) |i| { + for i in range(0, transformed_strs.len()) { let added_chars = transformed_strs[i].char_len(); new_ranges.push(Range::new(char_total, added_chars)); run_str.push_str(transformed_strs[i]); @@ -231,7 +229,7 @@ impl TextRunScanner { // Make new boxes with the run and adjusted text indices. debug!("TextRunScanner: pushing box(es) in range: %?", self.clump); - for clump.eachi |i| { + for i in clump.eachi() { let range = new_ranges[i - self.clump.begin()]; if range.length() == 0 { debug!("Elided an `UnscannedTextbox` because it was zero-length after \ @@ -241,7 +239,7 @@ impl TextRunScanner { } do in_boxes[i].with_base |base| { - let new_box = @mut adapt_textbox_with_range(*base, run.get(), range); + let new_box = @mut adapt_textbox_with_range(*base, run.unwrap(), range); out_boxes.push(TextRenderBoxClass(new_box)); } } @@ -249,19 +247,19 @@ impl TextRunScanner { } // End of match. debug!("--- In boxes: ---"); - for in_boxes.iter().enumerate().advance |(i, box)| { + for (i, box) in in_boxes.iter().enumerate() { debug!("%u --> %s", i, box.debug_str()); } debug!("------------------"); debug!("--- Out boxes: ---"); - for out_boxes.iter().enumerate().advance |(i, box)| { + for (i, box) in out_boxes.iter().enumerate() { debug!("%u --> %s", i, box.debug_str()); } debug!("------------------"); debug!("--- Elem ranges: ---"); - for inline.elems.eachi_mut |i: uint, nr: &NodeRange| { + for (i, nr) in inline.elems.eachi() { debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); () } debug!("--------------------"); diff --git a/src/components/main/layout/util.rs b/src/components/main/layout/util.rs index 00d4dae218c..e976e50c635 100644 --- a/src/components/main/layout/util.rs +++ b/src/components/main/layout/util.rs @@ -6,6 +6,9 @@ use layout::box::{RenderBox}; use script::dom::node::{AbstractNode, LayoutView}; use servo_util::range::Range; +use std::iterator::Enumerate; +use std::vec::VecIterator; + pub struct NodeRange { node: AbstractNode, range: Range, @@ -13,7 +16,7 @@ pub struct NodeRange { impl NodeRange { pub fn new(node: AbstractNode, range: &Range) -> NodeRange { - NodeRange { node: node, range: copy *range } + NodeRange { node: node, range: (*range).clone() } } } @@ -31,7 +34,7 @@ impl ElementMapping { } pub fn each(&self, callback: &fn(nr: &NodeRange) -> bool) -> bool { - for self.entries.iter().advance |nr| { + for nr in self.entries.iter() { if !callback(nr) { break } @@ -39,41 +42,27 @@ impl ElementMapping { true } - pub fn eachi(&self, callback: &fn(i: uint, nr: &NodeRange) -> bool) -> bool { - for self.entries.iter().enumerate().advance |(i, nr)| { - if !callback(i, nr) { - break - } - } - true - } - - pub fn eachi_mut(&self, callback: &fn(i: uint, nr: &NodeRange) -> bool) -> bool { - for self.entries.iter().enumerate().advance |(i, nr)| { - if !callback(i, nr) { - break - } - } - true + pub fn eachi<'a>(&'a self) -> Enumerate> { + self.entries.iter().enumerate() } pub fn repair_for_box_changes(&mut self, old_boxes: &[RenderBox], new_boxes: &[RenderBox]) { let entries = &mut self.entries; debug!("--- Old boxes: ---"); - for old_boxes.iter().enumerate().advance |(i, box)| { + for (i, box) in old_boxes.iter().enumerate() { debug!("%u --> %s", i, box.debug_str()); } debug!("------------------"); debug!("--- New boxes: ---"); - for new_boxes.iter().enumerate().advance |(i, box)| { + for (i, box) in new_boxes.iter().enumerate() { debug!("%u --> %s", i, box.debug_str()); } debug!("------------------"); debug!("--- Elem ranges before repair: ---"); - for entries.iter().enumerate().advance |(i, nr)| { + for (i, nr) in entries.iter().enumerate() { debug!("%u: %? --> %s", i, nr.range, nr.node.debug_str()); } debug!("----------------------------------"); @@ -126,7 +115,7 @@ impl ElementMapping { } } debug!("--- Elem ranges after repair: ---"); - for entries.iter().enumerate().advance |(i, nr)| { + for (i, nr) in entries.iter().enumerate() { 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 1ea7965b02a..ab12a1f73e0 100644 --- a/src/components/main/pipeline.rs +++ b/src/components/main/pipeline.rs @@ -2,7 +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/. */ -use extra::net::url::Url; +use extra::url::Url; use compositing::CompositorChan; use gfx::render_task::{RenderChan, RenderTask}; use gfx::render_task::{PaintPermissionGranted, PaintPermissionRevoked}; @@ -52,7 +52,7 @@ impl Pipeline { RenderTask::create(id, render_port, compositor_chan.clone(), - copy opts, + opts.clone(), profiler_chan.clone()); LayoutTask::create(id, @@ -61,7 +61,7 @@ impl Pipeline { script_pipeline.script_chan.clone(), render_chan.clone(), image_cache_task.clone(), - copy opts, + opts.clone(), profiler_chan); let new_layout_info = NewLayoutInfo { @@ -109,7 +109,7 @@ impl Pipeline { RenderTask::create(id, render_port, compositor_chan.clone(), - copy opts, + opts.clone(), profiler_chan.clone()); LayoutTask::create(id, @@ -118,7 +118,7 @@ impl Pipeline { script_chan.clone(), render_chan.clone(), image_cache_task, - copy opts, + opts.clone(), profiler_chan); Pipeline::new(id, subpage_id, diff --git a/src/components/main/platform/common/glfw_windowing.rs b/src/components/main/platform/common/glfw_windowing.rs index 327d7423540..b589258f88c 100644 --- a/src/components/main/platform/common/glfw_windowing.rs +++ b/src/components/main/platform/common/glfw_windowing.rs @@ -25,7 +25,7 @@ static THROBBER: [char, ..8] = [ '⣾', '⣽', '⣻', '⢿', 'â¡¿', '⣟', '⣯' pub struct Application; impl ApplicationMethods for Application { - pub fn new() -> Application { + fn new() -> Application { glfw::init(); Application } diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index 826b04f6d12..bb16497fe65 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -16,7 +16,7 @@ extern mod azure; extern mod geom; extern mod gfx (name = "gfx"); extern mod glfw; -extern mod http_client; +//extern mod http_client; extern mod js; extern mod layers; extern mod newcss (name = "css"); @@ -39,17 +39,21 @@ use compositing::{CompositorChan, CompositorTask}; use constellation::Constellation; use servo_msg::constellation_msg::{ExitMsg, InitLoadUrlMsg}; +#[cfg(not(test))] use gfx::opts; + use servo_net::image_cache_task::ImageCacheTask; use servo_net::resource_task::ResourceTask; use servo_util::time::{Profiler, ProfilerChan, PrintMsg}; -use extra::uv_global_loop; pub use gfx::opts::Opts; pub use gfx::text; pub use servo_util::url::make_url; use std::comm; +#[cfg(not(test))] use std::os; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; #[path="compositing/mod.rs"] pub mod compositing; @@ -57,8 +61,8 @@ pub mod compositing; pub mod macros; pub mod css { - priv mod select_handler; - priv mod node_util; + mod select_handler; + mod node_util; pub mod select; pub mod matching; @@ -94,56 +98,75 @@ pub mod platform; #[path = "util/mod.rs"] pub mod util; -fn main() { - run(&opts::from_cmdline_args(os::args())) +#[cfg(not(test))] +#[start] +fn start(argc: int, argv: **u8, crate_map: *u8) -> int { + do std::rt::start_on_main_thread(argc, argv, crate_map) { + let opts = opts::from_cmdline_args(os::args()); + run(opts) + } } -fn run(opts: &Opts) { +fn run(opts: Opts) { let (shutdown_port, shutdown_chan) = comm::stream(); - - // Create the profiler channel. let (profiler_port, profiler_chan) = comm::stream(); + let (compositor_port, compositor_chan) = comm::stream(); + let profiler_chan = ProfilerChan::new(profiler_chan); Profiler::create(profiler_port); - do opts.profiler_period.map |period| { + do opts.profiler_period.map |&period| { let profiler_chan = profiler_chan.clone(); - let period = *period; + let period = (period * 1000f) as u64; do spawn { + let tm = Timer::new().unwrap(); loop { - extra::timer::sleep(&uv_global_loop::get(), - (period * 1000f) as uint); + tm.sleep(period); profiler_chan.send(PrintMsg); } } }; - - // Create the compositor. - let (compositor_port, compositor_chan) = comm::stream(); let compositor_chan = CompositorChan::new(compositor_chan); - CompositorTask::create(opts.clone(), compositor_port, profiler_chan.clone(), shutdown_chan); + let profiler_chan_clone = profiler_chan.clone(); - // Create a Servo instance. + let opts_clone = opts.clone(); - let resource_task = ResourceTask(); - let image_cache_task = ImageCacheTask(resource_task.clone()); - let constellation_chan = Constellation::start(compositor_chan.clone(), - opts, - resource_task, - image_cache_task, - profiler_chan.clone()); + do spawn { + let profiler_chan = profiler_chan_clone.clone(); + let compositor_chan = compositor_chan.clone(); - // Send the URL command to the constellation. - for opts.urls.iter().advance |filename| { - constellation_chan.send(InitLoadUrlMsg(make_url(filename.clone(), None))) + let opts = &opts_clone.clone(); + + // Create a Servo instance. + + let resource_task = ResourceTask(); + let image_cache_task = ImageCacheTask(resource_task.clone()); + let constellation_chan = Constellation::start(compositor_chan.clone(), + opts, + resource_task, + image_cache_task, + profiler_chan.clone()); + + // Send the URL command to the constellation. + for filename in opts.urls.iter() { + constellation_chan.send(InitLoadUrlMsg(make_url(filename.clone(), None))) + } + + // Wait for the compositor to shut down. + shutdown_port.recv(); + + // Shut the constellation down. + debug!("master: Shut down"); + let (exit_response_from_constellation, exit_chan) = comm::stream(); + constellation_chan.send(ExitMsg(exit_chan)); + exit_response_from_constellation.recv(); } - // Wait for the compositor to shut down. - shutdown_port.recv(); - // Shut the constellation down. - debug!("master: Shut down"); - let (exit_response_from_constellation, exit_chan) = comm::stream(); - constellation_chan.send(ExitMsg(exit_chan)); - exit_response_from_constellation.recv(); + let compositor_task = CompositorTask::new(opts, + compositor_port, + profiler_chan, + shutdown_chan); + debug!("preparing to enter main loop"); + compositor_task.run(); } diff --git a/src/components/main/windowing.rs b/src/components/main/windowing.rs index f4fbca5d58c..dcf94615831 100644 --- a/src/components/main/windowing.rs +++ b/src/components/main/windowing.rs @@ -51,21 +51,21 @@ pub trait ApplicationMethods { pub trait WindowMethods { /// Creates a new window. - pub fn new(app: &A) -> @mut Self; + fn new(app: &A) -> @mut Self; /// Returns the size of the window. - pub fn size(&self) -> Size2D; + fn size(&self) -> Size2D; /// Presents the window to the screen (perhaps by page flipping). - pub fn present(&mut self); + fn present(&mut self); /// Spins the event loop and returns the next event. - pub fn recv(@mut self) -> WindowEvent; + fn recv(@mut self) -> WindowEvent; /// Sets the ready state of the current page. - pub fn set_ready_state(@mut self, ready_state: ReadyState); + fn set_ready_state(@mut self, ready_state: ReadyState); /// Sets the render state of the current page. - pub fn set_render_state(@mut self, render_state: RenderState); + fn set_render_state(@mut self, render_state: RenderState); /// Returns the hidpi factor of the monitor. - pub fn hidpi_factor(@mut self) -> f32; + fn hidpi_factor(@mut self) -> f32; } diff --git a/src/components/msg/compositor_msg.rs b/src/components/msg/compositor_msg.rs index 80f0c0703d3..410da56f6e0 100644 --- a/src/components/msg/compositor_msg.rs +++ b/src/components/msg/compositor_msg.rs @@ -61,7 +61,7 @@ pub trait RenderListener { fn new_layer(&self, PipelineId, Size2D); fn resize_layer(&self, PipelineId, Size2D); fn delete_layer(&self, PipelineId); - fn paint(&self, id: PipelineId, layer_buffer_set: arc::ARC); + fn paint(&self, id: PipelineId, layer_buffer_set: arc::Arc); fn set_render_state(&self, render_state: RenderState); } diff --git a/src/components/msg/constellation_msg.rs b/src/components/msg/constellation_msg.rs index 419aadf1ae3..af0a01184a3 100644 --- a/src/components/msg/constellation_msg.rs +++ b/src/components/msg/constellation_msg.rs @@ -6,7 +6,7 @@ /// coupling between these two components use std::comm::{Chan, SharedChan}; -use extra::net::url::Url; +use extra::url::Url; use extra::future::Future; use geom::size::Size2D; diff --git a/src/components/net/image/holder.rs b/src/components/net/image/holder.rs index bf56b6413e3..096c07b2f19 100644 --- a/src/components/net/image/holder.rs +++ b/src/components/net/image/holder.rs @@ -8,18 +8,18 @@ use local_image_cache::LocalImageCache; use std::util::replace; use geom::size::Size2D; -use extra::net::url::Url; -use extra::arc::ARC; +use extra::url::Url; +use extra::arc::Arc; // FIXME: Nasty coupling here This will be a problem if we want to factor out image handling from // the network stack. This should probably be factored out into an interface and use dependency // injection. /// A struct to store image data. The image will be loaded once the first time it is requested, -/// and an ARC will be stored. Clones of this ARC are given out on demand. +/// and an Arc will be stored. Clones of this Arc are given out on demand. pub struct ImageHolder { url: Url, - image: Option>, + image: Option>, cached_size: Size2D, local_image_cache: @mut LocalImageCache, } @@ -65,7 +65,7 @@ impl ImageHolder { } } - pub fn get_image(&mut self) -> Option> { + pub fn get_image(&mut self) -> Option> { debug!("get_image() %?", self.url); // If this is the first time we've called this function, load diff --git a/src/components/net/image_cache_task.rs b/src/components/net/image_cache_task.rs index aa0440ff701..a6f3dfb529f 100644 --- a/src/components/net/image_cache_task.rs +++ b/src/components/net/image_cache_task.rs @@ -13,8 +13,8 @@ use std::task::spawn; use std::to_str::ToStr; use std::util::replace; use std::result; -use extra::arc::ARC; -use extra::net::url::Url; +use extra::arc::Arc; +use extra::url::Url; pub enum Msg { /// Tell the cache that we may need a particular image soon. Must be posted @@ -29,7 +29,7 @@ pub enum Msg { Decode(Url), /// Used by the decoder tasks to post decoded images back to the cache - priv StoreImage(Url, Option>), + priv StoreImage(Url, Option>), /// Request an Image object for a URL. If the image is not is not immediately /// available then ImageNotReady is returned. @@ -46,7 +46,7 @@ pub enum Msg { } pub enum ImageResponseMsg { - ImageReady(ARC<~Image>), + ImageReady(Arc<~Image>), ImageNotReady, ImageFailed } @@ -157,21 +157,22 @@ struct ImageCache { need_exit: Option>, } +#[deriving(Clone)] enum ImageState { Init, Prefetching(AfterPrefetch), Prefetched(@Cell<~[u8]>), Decoding, - Decoded(@ARC<~Image>), + Decoded(@Arc<~Image>), Failed } +#[deriving(Clone)] enum AfterPrefetch { DoDecode, DoNotDecode } -#[allow(non_implicitly_copyable_typarams)] impl ImageCache { pub fn run(&mut self) { let mut msg_handlers: ~[~fn(msg: &Msg)] = ~[]; @@ -179,7 +180,7 @@ impl ImageCache { loop { let msg = self.port.recv(); - for msg_handlers.iter().advance |handler| { + for handler in msg_handlers.iter() { (*handler)(&msg) } @@ -210,7 +211,7 @@ impl ImageCache { // Wait until we have no outstanding requests and subtasks // before exiting let mut can_exit = true; - for self.state_map.each_value |state| { + for (_, state) in self.state_map.iter() { match *state { Prefetching(*) => can_exit = false, Decoding => can_exit = false, @@ -231,37 +232,37 @@ impl ImageCache { } } - priv fn get_state(&self, url: Url) -> ImageState { + fn get_state(&self, url: Url) -> ImageState { match self.state_map.find(&url) { Some(state) => *state, None => Init } } - priv fn set_state(&self, url: Url, state: ImageState) { + fn set_state(&self, url: Url, state: ImageState) { self.state_map.insert(url, state); } - priv fn prefetch(&self, url: Url) { - match self.get_state(copy url) { + fn prefetch(&self, url: Url) { + match self.get_state(url.clone()) { Init => { let to_cache = self.chan.clone(); let resource_task = self.resource_task.clone(); - let url_cell = Cell::new(copy url); + let url_cell = Cell::new(url.clone()); do spawn { let url = url_cell.take(); debug!("image_cache_task: started fetch for %s", url.to_str()); - let image = load_image_data(copy url, resource_task.clone()); + let image = load_image_data(url.clone(), resource_task.clone()); let result = if image.is_ok() { - Ok(Cell::new(result::unwrap(image))) + Ok(Cell::new(image.unwrap())) } else { Err(()) }; - to_cache.send(StorePrefetchedImageData(copy url, result)); - debug!("image_cache_task: ended fetch for %s", (copy url).to_str()); + to_cache.send(StorePrefetchedImageData(url.clone(), result)); + debug!("image_cache_task: ended fetch for %s", (url.clone()).to_str()); } self.set_state(url, Prefetching(DoNotDecode)); @@ -273,20 +274,20 @@ impl ImageCache { } } - priv fn store_prefetched_image_data(&self, url: Url, data: Result, ()>) { - match self.get_state(copy url) { + fn store_prefetched_image_data(&self, url: Url, data: Result, ()>) { + match self.get_state(url.clone()) { Prefetching(next_step) => { match data { Ok(data_cell) => { let data = data_cell.take(); - self.set_state(copy url, Prefetched(@Cell::new(data))); + self.set_state(url.clone(), Prefetched(@Cell::new(data))); match next_step { DoDecode => self.decode(url), _ => () } } Err(*) => { - self.set_state(copy url, Failed); + self.set_state(url.clone(), Failed); self.purge_waiters(url, || ImageFailed); } } @@ -302,8 +303,8 @@ impl ImageCache { } } - priv fn decode(&self, url: Url) { - match self.get_state(copy url) { + fn decode(&self, url: Url) { + match self.get_state(url.clone()) { Init => fail!(~"decoding image before prefetch"), Prefetching(DoNotDecode) => { @@ -320,7 +321,7 @@ impl ImageCache { let data = data_cell.take(); let to_cache = self.chan.clone(); - let url_cell = Cell::new(copy url); + let url_cell = Cell::new(url.clone()); let decode = (self.decoder_factory)(); do spawn { @@ -328,11 +329,11 @@ impl ImageCache { debug!("image_cache_task: started image decode for %s", url.to_str()); let image = decode(data); let image = if image.is_some() { - Some(ARC(~image.unwrap())) + Some(Arc::new(~image.unwrap())) } else { None }; - to_cache.send(StoreImage(copy url, image)); + to_cache.send(StoreImage(url.clone(), image)); debug!("image_cache_task: ended image decode for %s", url.to_str()); } @@ -345,17 +346,17 @@ impl ImageCache { } } - priv fn store_image(&self, url: Url, image: Option>) { + fn store_image(&self, url: Url, image: Option>) { - match self.get_state(copy url) { + match self.get_state(url.clone()) { Decoding => { match image { Some(image) => { - self.set_state(copy url, Decoded(@image.clone())); + self.set_state(url.clone(), Decoded(@image.clone())); self.purge_waiters(url, || ImageReady(image.clone()) ); } None => { - self.set_state(copy url, Failed); + self.set_state(url.clone(), Failed); self.purge_waiters(url, || ImageFailed ); } } @@ -372,10 +373,10 @@ impl ImageCache { } - priv fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) { + fn purge_waiters(&self, url: Url, f: &fn() -> ImageResponseMsg) { match self.wait_map.pop(&url) { Some(waiters) => { - for waiters.iter().advance |response| { + for response in waiters.iter() { response.send(f()); } } @@ -383,8 +384,8 @@ impl ImageCache { } } - priv fn get_image(&self, url: Url, response: Chan) { - match self.get_state(copy url) { + fn get_image(&self, url: Url, response: Chan) { + match self.get_state(url.clone()) { Init => fail!(~"request for image before prefetch"), Prefetching(DoDecode) => response.send(ImageNotReady), Prefetching(DoNotDecode) | Prefetched(*) => fail!(~"request for image before decode"), @@ -394,8 +395,8 @@ impl ImageCache { } } - priv fn wait_for_image(&self, url: Url, response: Chan) { - match self.get_state(copy url) { + fn wait_for_image(&self, url: Url, response: Chan) { + match self.get_state(url.clone()) { Init => fail!(~"request for image before prefetch"), Prefetching(DoNotDecode) | Prefetched(*) => fail!(~"request for image before decode"), @@ -541,7 +542,7 @@ fn should_fail_if_requesting_image_before_requesting_decode() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); + image_cache_task.send(Prefetch(url.clone())); // no decode message let (chan, _port) = stream(); @@ -564,7 +565,7 @@ fn should_not_request_url_from_resource_task_on_multiple_prefetches() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); + image_cache_task.send(Prefetch(url.clone())); image_cache_task.send(Prefetch(url)); url_requested.recv(); image_cache_task.exit(); @@ -587,8 +588,8 @@ fn should_return_image_not_ready_if_data_has_not_arrived() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); let (response_chan, response_port) = stream(); image_cache_task.send(GetImage(url, response_chan)); assert!(response_port.recv() == ImageNotReady); @@ -617,8 +618,8 @@ fn should_return_decoded_image_data_if_data_has_arrived() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_image_chan.recv(); @@ -654,15 +655,15 @@ fn should_return_decoded_image_data_for_multiple_requests() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_image.recv(); - for iter::repeat(2) { + for _ in iter::repeat(2) { let (response_chan, response_port) = stream(); - image_cache_task.send(GetImage(copy url, response_chan)); + image_cache_task.send(GetImage(url.clone(), response_chan)); match response_port.recv() { ImageReady(_) => (), _ => fail @@ -700,12 +701,12 @@ fn should_not_request_image_from_resource_task_if_image_is_already_available() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); + image_cache_task.send(Prefetch(url.clone())); // Wait until our mock resource task has sent the image to the image cache image_bin_sent.recv(); - image_cache_task.send(Prefetch(copy url)); + image_cache_task.send(Prefetch(url.clone())); image_cache_task.exit(); mock_resource_task.send(resource_task::Exit); @@ -744,14 +745,14 @@ fn should_not_request_image_from_resource_task_if_image_fetch_already_failed() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache image_bin_sent.recv(); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); image_cache_task.exit(); mock_resource_task.send(resource_task::Exit); @@ -784,8 +785,8 @@ fn should_return_failed_if_image_bin_cannot_be_fetched() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_prefetech.recv(); @@ -822,14 +823,14 @@ fn should_return_failed_for_multiple_get_image_requests_if_image_bin_cannot_be_f } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_prefetech.recv(); let (response_chan, response_port) = stream(); - image_cache_task.send(GetImage(copy url, response_chan)); + image_cache_task.send(GetImage(url.clone(), response_chan)); match response_port.recv() { ImageFailed => (), _ => fail @@ -879,8 +880,8 @@ fn should_return_not_ready_if_image_is_still_decoding() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_prefetech.recv(); @@ -922,8 +923,8 @@ fn should_return_failed_if_image_decode_fails() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_decode.recv(); @@ -961,8 +962,8 @@ fn should_return_image_on_wait_if_image_is_already_loaded() { } })); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); // Wait until our mock resource task has sent the image to the image cache wait_for_decode.recv(); @@ -991,8 +992,8 @@ fn should_return_image_on_wait_if_image_is_not_yet_loaded() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); let (response_chan, response_port) = stream(); image_cache_task.send(WaitForImage(url, response_chan)); @@ -1021,8 +1022,8 @@ fn should_return_image_failed_on_wait_if_image_fails_to_load() { let image_cache_task = ImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); let (response_chan, response_port) = stream(); image_cache_task.send(WaitForImage(url, response_chan)); @@ -1048,8 +1049,8 @@ fn sync_cache_should_wait_for_images() { let image_cache_task = SyncImageCacheTask(mock_resource_task); let url = make_url(~"file", None); - image_cache_task.send(Prefetch(copy url)); - image_cache_task.send(Decode(copy url)); + image_cache_task.send(Prefetch(url.clone())); + image_cache_task.send(Decode(url.clone())); let (response_chan, response_port) = stream(); image_cache_task.send(GetImage(url, response_chan)); diff --git a/src/components/net/local_image_cache.rs b/src/components/net/local_image_cache.rs index 335d2c6dd26..9c6bf12191c 100644 --- a/src/components/net/local_image_cache.rs +++ b/src/components/net/local_image_cache.rs @@ -15,7 +15,7 @@ use std::comm; use std::comm::Port; use std::task; use servo_util::url::{UrlMap, url_map}; -use extra::net::url::Url; +use extra::url::Url; pub fn LocalImageCache(image_cache_task: ImageCacheTask) -> LocalImageCache { LocalImageCache { @@ -33,14 +33,13 @@ pub struct LocalImageCache { priv state_map: UrlMap<@mut ImageState> } -priv struct ImageState { +struct ImageState { prefetched: bool, decoded: bool, last_request_round: uint, last_response: ImageResponseMsg } -#[allow(non_implicitly_copyable_typarams)] // Using maps of Urls impl LocalImageCache { /// The local cache will only do a single remote request for a given /// URL in each 'round'. Layout should call this each time it begins @@ -52,7 +51,7 @@ impl LocalImageCache { pub fn prefetch(&self, url: &Url) { let state = self.get_state(url); if !state.prefetched { - self.image_cache_task.send(Prefetch(copy *url)); + self.image_cache_task.send(Prefetch((*url).clone())); state.prefetched = true; } } @@ -60,7 +59,7 @@ impl LocalImageCache { pub fn decode(&self, url: &Url) { let state = self.get_state(url); if !state.decoded { - self.image_cache_task.send(Decode(copy *url)); + self.image_cache_task.send(Decode((*url).clone())); state.decoded = true; } } @@ -98,7 +97,7 @@ impl LocalImageCache { } let (response_port, response_chan) = comm::stream(); - self.image_cache_task.send(GetImage(copy *url, response_chan)); + self.image_cache_task.send(GetImage((*url).clone(), response_chan)); let response = response_port.recv(); match response { @@ -110,11 +109,11 @@ impl LocalImageCache { // on the image to load and triggering layout let image_cache_task = self.image_cache_task.clone(); assert!(self.on_image_available.is_some()); - let on_image_available = self.on_image_available.get()(); - let url = copy *url; + let on_image_available = self.on_image_available.unwrap()(); + let url = (*url).clone(); do task::spawn { let (response_port, response_chan) = comm::stream(); - image_cache_task.send(WaitForImage(copy url, response_chan)); + image_cache_task.send(WaitForImage(url.clone(), response_chan)); on_image_available(response_port.recv()); } } @@ -134,7 +133,7 @@ impl LocalImageCache { return port; } - priv fn get_state(&self, url: &Url) -> @mut ImageState { + fn get_state(&self, url: &Url) -> @mut ImageState { let state = do self.state_map.find_or_insert_with(url.clone()) |_| { let new_state = @mut ImageState { prefetched: false, diff --git a/src/components/net/net.rc b/src/components/net/net.rc index a646de09315..f53f215c8aa 100644 --- a/src/components/net/net.rc +++ b/src/components/net/net.rc @@ -9,7 +9,7 @@ #[crate_type = "lib"]; extern mod geom; -extern mod http_client; +//extern mod http_client; extern mod servo_util (name = "util"); extern mod stb_image; extern mod extra; @@ -25,7 +25,7 @@ pub mod image { } pub mod file_loader; -pub mod http_loader; +//pub mod http_loader; pub mod image_cache_task; pub mod local_image_cache; pub mod resource_task; diff --git a/src/components/net/resource_task.rs b/src/components/net/resource_task.rs index 457cd6dfd35..e2ce236dc80 100644 --- a/src/components/net/resource_task.rs +++ b/src/components/net/resource_task.rs @@ -5,11 +5,11 @@ //! A task that takes a URL and streams back the binary data. use file_loader; -use http_loader; +//use http_loader; use std::cell::Cell; use std::comm::{Chan, Port, SharedChan}; -use extra::net::url::{Url, to_str}; +use extra::url::Url; use util::spawn_listener; pub enum ControlMsg { @@ -43,10 +43,10 @@ pub type LoaderTask = ~fn(url: Url, Chan); /// Create a ResourceTask with the default loaders pub fn ResourceTask() -> ResourceTask { let file_loader_factory: LoaderTaskFactory = file_loader::factory; - let http_loader_factory: LoaderTaskFactory = http_loader::factory; + //let http_loader_factory: LoaderTaskFactory = http_loader::factory; let loaders = ~[ (~"file", file_loader_factory), - (~"http", http_loader_factory) + //(~"http", http_loader_factory) ]; create_resource_task_with_loaders(loaders) } @@ -94,7 +94,7 @@ impl ResourceManager { match self.get_loader_factory(&url) { Some(loader_factory) => { - debug!("resource_task: loading url: %s", to_str(&url)); + debug!("resource_task: loading url: %s", url.to_str()); loader_factory(url, progress_chan); } None => { @@ -105,7 +105,7 @@ impl ResourceManager { } fn get_loader_factory(&self, url: &Url) -> Option { - for self.loaders.iter().advance |scheme_loader| { + for scheme_loader in self.loaders.iter() { match *scheme_loader { (ref scheme, ref loader_factory) => { if (*scheme) == url.scheme { @@ -142,7 +142,7 @@ fn test_bad_scheme() { fn should_delegate_to_scheme_loader() { let payload = ~[1, 2, 3]; let loader_factory = |_url: Url, progress_chan: Chan| { - progress_chan.send(Payload(copy payload)); + progress_chan.send(Payload(payload.clone())); progress_chan.send(Done(Ok(()))); }; let loader_factories = ~[(~"snicklefritz", loader_factory)]; diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 140a712b950..22bd6ca6db3 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1044,7 +1044,7 @@ for (uint32_t i = 0; i < length; ++i) { # "if (!ConvertJSValueToString(cx, ${val}, ${valPtr}, %s, %s, %s)) {\n" # " return false;\n" # "}" % (nullBehavior, undefinedBehavior, varName)) - strval = "str(strval.get())" + strval = "str(strval.unwrap())" if isOptional: strval = "Some(%s)" % strval conversionCode = ( @@ -1114,7 +1114,7 @@ for (uint32_t i = 0; i < length; ++i) { " if result.is_err() {\n" "%(handleInvalidEnumValueCode)s" " }\n" - " let index = result.get();\n" + " let index = result.unwrap();\n" " ${declName} = cast::transmute(index); //XXXjdm need some range checks up in here\n" "}" % { "enumtype" : enum, "values" : enum + "Values::strings", @@ -1511,7 +1511,7 @@ for (uint32_t i = 0; i < length; ++i) { wrappingCode = ("if %s.is_none() {\n" % (result) + CGIndenter(CGGeneric(setValue("JSVAL_NULL"))).define() + "\n" + "}\n" + - "let mut %s = %s.get();\n" % (result, result)) + "let mut %s = %s.unwrap();\n" % (result, result)) else: wrappingCode = "" if (not descriptor.interface.isExternal() and @@ -2746,10 +2746,10 @@ class CGGetPerInterfaceObject(CGAbstractMethod): }*/ /* Check to see whether the interface objects are already installed */ let protoOrIfaceArray: *mut *JSObject = cast::transmute(GetProtoOrIfaceArray(aGlobal)); - let cachedObject: *JSObject = *protoOrIfaceArray.offset(%s as uint); + let cachedObject: *JSObject = *protoOrIfaceArray.offset(%s as int); if cachedObject.is_null() { let tmp: *JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver); - *protoOrIfaceArray.offset(%s as uint) = tmp; + *protoOrIfaceArray.offset(%s as int) = tmp; tmp } else { cachedObject @@ -3623,7 +3623,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): templateValues = {'jsvalRef': '(*desc).value', 'jsvalPtr': 'ptr::to_mut_unsafe_ptr(&mut (*desc).value)', 'obj': 'proxy', 'successCode': fillDescriptor} get = ("if index.is_some() {\n" + - " let index = index.get();\n" + + " let index = index.unwrap();\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" + "}\n") % (self.descriptor.concreteType) @@ -3632,7 +3632,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): setOrIndexedGet += "if set != 0 {\n" if indexedSetter: setOrIndexedGet += (" if index.is_some() {\n" + - " let index = index.get();\n") + " let index = index.unwrap();\n") if not 'IndexedCreator' in self.descriptor.operations: # FIXME need to check that this is a 'supported property index' assert False @@ -3677,7 +3677,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): " if strval.is_err() {\n" + " return 0;\n" + " }\n" + - " let name = str(strval.get());\n" + + " let name = str(strval.unwrap());\n" + "\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" + @@ -3721,7 +3721,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): raise TypeError("Can't handle creator that's different from the setter") set += ("let index = GetArrayIndexFromId(cx, id);\n" + "if index.is_some() {\n" + - " let index = index.get();\n" + + " let index = index.unwrap();\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() + " return 1;\n" + @@ -3746,7 +3746,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " if strval.is_err() {\n" + " return 0;\n" + " }\n" + - " let name = str(strval.get());\n" + + " let name = str(strval.unwrap());\n" + "\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" + @@ -3762,7 +3762,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod): " if strval.is_err() {\n" + " return 0;\n" + " }\n" + - " let name = str(strval.get());\n" + + " let name = str(strval.unwrap());\n" + " let this: %%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + " if (found) {\n" @@ -3787,7 +3787,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): if indexedGetter: indexed = ("let index = GetArrayIndexFromId(cx, id);\n" + "if index.is_some() {\n" + - " let index = index.get();\n" + + " let index = index.unwrap();\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" + " *bp = found as JSBool;\n" + @@ -3808,7 +3808,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod): " if strval.is_err() {\n" + " return 0;\n" + " }\n" + - " let name = str(strval.get());\n" + + " let name = str(strval.unwrap());\n" + "\n" + " let this: *%s = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" + @@ -3861,7 +3861,7 @@ if expando.is_not_null() { if indexedGetter: getIndexedOrExpando = ("let index = GetArrayIndexFromId(cx, id);\n" + "if index.is_some() {\n" + - " let index = index.get();\n" + + " let index = index.unwrap();\n" + " let this = UnwrapProxy(proxy);\n" + CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define()) getIndexedOrExpando += """ @@ -3935,7 +3935,7 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod): JSString* jsresult; return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;""" - return """ do str::as_c_str("%s") |s| { + return """ do "%s".to_c_str().with_ref |s| { _obj_toString(cx, s) }""" % self.descriptor.name @@ -4461,9 +4461,9 @@ class CGDictionary(CGThing): # NOTE: jsids are per-runtime, so don't use them in workers if True or self.workers: #XXXjdm hack until 'static mut' exists for global jsids propName = member.identifier.name - propCheck = ('str::as_c_str("%s", |s| { JS_HasProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&found)) })' % + propCheck = ('"%s".to_c_str().with_ref(|s| { JS_HasProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&found)) })' % propName) - propGet = ('str::as_c_str("%s", |s| { JS_GetProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&temp)) })' % + propGet = ('"%s".to_c_str().with_ref(|s| { JS_GetProperty(cx, RUST_JSVAL_TO_OBJECT(val), s, ptr::to_unsafe_ptr(&temp)) })' % propName) else: propId = self.makeIdName(member.identifier.name); diff --git a/src/components/script/dom/bindings/element.rs b/src/components/script/dom/bindings/element.rs index a177c10c332..8ca841772de 100644 --- a/src/components/script/dom/bindings/element.rs +++ b/src/components/script/dom/bindings/element.rs @@ -21,8 +21,6 @@ use std::libc::c_uint; use std::comm; use std::ptr; use std::ptr::null; -use std::result; -use std::str; use js::glue::*; use js::jsapi::*; use js::jsapi::{JSContext, JSVal, JSObject, JSBool, JSFreeOp, JSPropertySpec}; @@ -49,14 +47,14 @@ pub extern fn trace(tracer: *mut JSTracer, obj: *JSObject) { return; } error!("tracing %s", name); - let mut node = node.get(); + let mut node = node.unwrap(); let cache = node.get_wrappercache(); let wrapper = cache.get_wrapper(); assert!(wrapper.is_not_null()); unsafe { (*tracer).debugPrinter = ptr::null(); (*tracer).debugPrintIndex = -1; - do str::as_c_str(name) |name| { + do name.to_c_str().with_ref |name| { (*tracer).debugPrintArg = name as *libc::c_void; JS_CallTracer(cast::transmute(tracer), wrapper, JSTRACE_OBJECT as u32); } @@ -194,14 +192,14 @@ extern fn setAttribute(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { if strval.is_err() { return 0; } - arg0 = str(strval.get()); + arg0 = str(strval.unwrap()); let arg1: DOMString; let strval = jsval_to_str(cx, (*argv.offset(1))); if strval.is_err() { return 0; } - arg1 = str(strval.get()); + arg1 = str(strval.unwrap()); do node.as_mut_element |elem| { elem.set_attr(&arg0, &arg1); @@ -211,7 +209,6 @@ extern fn setAttribute(cx: *JSContext, argc: c_uint, vp: *JSVal) -> JSBool { } } -#[allow(non_implicitly_copyable_typarams)] extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool { unsafe { let obj = JS_THIS_OBJECT(cx, cast::transmute(vp)); @@ -241,7 +238,6 @@ extern fn HTMLImageElement_getWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVa } } -#[allow(non_implicitly_copyable_typarams)] extern fn HTMLImageElement_setWidth(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool { unsafe { let obj = JS_THIS_OBJECT(cx, cast::transmute(vp)); @@ -275,7 +271,7 @@ extern fn getTagName(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool { let node = unwrap(obj); do node.with_imm_element |elem| { - let s = str(copy elem.tag_name); + let s = str(elem.tag_name.clone()); *vp = domstring_to_jsval(cx, &s); } } @@ -295,9 +291,9 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj { //XXXjdm the parent should probably be the node parent instead of the global //TODO error checking let compartment = utils::get_compartment(cx); - let obj = result::unwrap(compartment.new_object_with_proto(~"GenericElementInstance", - proto, - compartment.global_obj.ptr)); + let obj = compartment.new_object_with_proto(~"GenericElementInstance", + proto, + compartment.global_obj.ptr).unwrap(); let cache = node.get_wrappercache(); assert!(cache.get_wrapper().is_null()); diff --git a/src/components/script/dom/bindings/node.rs b/src/components/script/dom/bindings/node.rs index b8351ced73c..bfa153ff9c2 100644 --- a/src/components/script/dom/bindings/node.rs +++ b/src/components/script/dom/bindings/node.rs @@ -97,7 +97,6 @@ macro_rules! generate_element( }) ) -#[allow(non_implicitly_copyable_typarams)] pub fn create(cx: *JSContext, node: &mut AbstractNode) -> *JSObject { match node.type_id() { ElementNodeTypeId(HTMLElementTypeId) => generate_element!(HTMLElement), @@ -138,7 +137,6 @@ pub unsafe fn unwrap(obj: *JSObject) -> AbstractNode { AbstractNode::from_raw(raw) } -#[allow(non_implicitly_copyable_typarams)] extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool { unsafe { let obj = JS_THIS_OBJECT(cx, cast::transmute(vp)); @@ -160,7 +158,6 @@ extern fn getFirstChild(cx: *JSContext, _argc: c_uint, vp: *mut JSVal) -> JSBool return 1; } -#[allow(non_implicitly_copyable_typarams)] extern fn getNextSibling(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/proxyhandler.rs b/src/components/script/dom/bindings/proxyhandler.rs index fef04d6fee9..2aac4a14918 100644 --- a/src/components/script/dom/bindings/proxyhandler.rs +++ b/src/components/script/dom/bindings/proxyhandler.rs @@ -68,7 +68,7 @@ pub extern fn defineProperty(cx: *JSContext, proxy: *JSObject, id: jsid, pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString { unsafe { - let name = str::raw::from_buf(className as *u8); + let name = str::raw::from_c_str(className); let nchars = "[object ]".len() + name.len(); let chars: *mut jschar = cast::transmute(JS_malloc(cx, (nchars + 1) as u64 * (size_of::() as u64))); if chars.is_null() { @@ -76,10 +76,10 @@ pub fn _obj_toString(cx: *JSContext, className: *libc::c_char) -> *JSString { } let result = ~"[object " + name + "]"; - for result.iter().enumerate().advance |(i, c)| { - *chars.offset(i) = c as jschar; + for (i, c) in result.iter().enumerate() { + *chars.offset(i as int) = c as jschar; } - *chars.offset(nchars) = 0; + *chars.offset(nchars as int) = 0; let jsstr = JS_NewUCString(cx, cast::transmute(chars), nchars as u64); if jsstr.is_null() { JS_free(cx, cast::transmute(chars)); diff --git a/src/components/script/dom/bindings/text.rs b/src/components/script/dom/bindings/text.rs index 2ec4a6a69df..efa8cc90206 100644 --- a/src/components/script/dom/bindings/text.rs +++ b/src/components/script/dom/bindings/text.rs @@ -16,7 +16,6 @@ use js::rust::{Compartment, jsobj}; use std::cast; use std::libc; -use std::result; extern fn finalize_text(_fop: *JSFreeOp, obj: *JSObject) { debug!("text finalize: %?!", obj as uint); @@ -79,9 +78,9 @@ pub fn create(cx: *JSContext, node: &mut AbstractNode) -> jsobj { //XXXjdm the parent should probably be the node parent instead of the global //TODO error checking let compartment = utils::get_compartment(cx); - let obj = result::unwrap(compartment.new_object_with_proto(instance, - proto, - compartment.global_obj.ptr)); + let obj = compartment.new_object_with_proto(instance, + proto, + compartment.global_obj.ptr).unwrap(); let cache = node.get_wrappercache(); assert!(cache.get_wrapper().is_null()); diff --git a/src/components/script/dom/bindings/utils.rs b/src/components/script/dom/bindings/utils.rs index 728c1eb112e..057f6d6ef97 100644 --- a/src/components/script/dom/bindings/utils.rs +++ b/src/components/script/dom/bindings/utils.rs @@ -13,9 +13,7 @@ use std::hashmap::HashMap; use std::libc; use std::ptr; use std::ptr::{null, to_unsafe_ptr}; -use std::result; use std::str; -use std::uint; use std::unstable::intrinsics; use js::glue::*; use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL}; @@ -85,7 +83,7 @@ extern fn InterfaceObjectToString(cx: *JSContext, _argc: uint, vp: *mut JSVal) - return 0; } - let name = jsval_to_str(cx, *v).get(); + let name = jsval_to_str(cx, *v).unwrap(); let retval = str(~"function " + name + "() {\n [native code]\n}"); *vp = domstring_to_jsval(cx, &retval); return 1; @@ -204,7 +202,7 @@ pub fn jsval_to_str(cx: *JSContext, v: JSVal) -> Result<~str, ()> { } let strbuf = JS_EncodeString(cx, jsstr); - let buf = str::raw::from_buf(strbuf as *u8); + let buf = str::raw::from_c_str(strbuf); JS_free(cx, strbuf as *libc::c_void); Ok(buf) } @@ -216,10 +214,10 @@ pub unsafe fn domstring_to_jsval(cx: *JSContext, string: &DOMString) -> JSVal { JSVAL_NULL } &str(ref s) => { - str::as_buf(*s, |buf, len| { + do s.as_imm_buf |buf, len| { let cbuf = cast::transmute(buf); RUST_STRING_TO_JSVAL(JS_NewStringCopyN(cx, cbuf, len as libc::size_t)) - }) + } } } } @@ -322,13 +320,13 @@ pub fn define_empty_prototype(name: ~str, proto: Option<~str>, compartment: @mut compartment.register_class(prototype_jsclass(name.to_owned())); //TODO error checking - let obj = result::unwrap( + let obj = ( match proto { Some(s) => compartment.new_object_with_proto(name.to_owned(), s, compartment.global_obj.ptr), None => compartment.new_object(name.to_owned(), null(), compartment.global_obj.ptr) - }); + }).unwrap(); unsafe { compartment.define_property(name.to_owned(), RUST_OBJECT_TO_JSVAL(obj.ptr), @@ -392,6 +390,7 @@ pub struct JSNativeHolder { propertyHooks: *NativePropertyHooks } +#[deriving(Clone)] pub enum ConstantVal { IntVal(i32), UintVal(u32), @@ -401,6 +400,7 @@ pub enum ConstantVal { VoidVal } +#[deriving(Clone)] pub struct ConstantSpec { name: *libc::c_char, value: ConstantVal @@ -454,7 +454,7 @@ pub fn CreateInterfaceObjects2(cx: *JSContext, global: *JSObject, receiver: *JSO let mut interface = ptr::null(); if constructorClass.is_not_null() || constructor.is_not_null() { - interface = do str::as_c_str(name) |s| { + interface = do name.to_c_str().with_ref |s| { CreateInterfaceObject(cx, global, receiver, constructorClass, constructor, ctorNargs, proto, staticMethods, constants, s) @@ -506,7 +506,7 @@ fn CreateInterfaceObject(cx: *JSContext, global: *JSObject, receiver: *JSObject, } if constructorClass.is_not_null() { - let toString = do str::as_c_str("toString") |s| { + let toString = do "toString".to_c_str().with_ref |s| { DefineFunctionWithReserved(cx, constructor, s, InterfaceObjectToString, 0, 0) @@ -666,7 +666,7 @@ impl WrapperCache { } pub fn WrapNewBindingObject(cx: *JSContext, scope: *JSObject, - mut value: @mut CacheableWrapper, + value: @mut CacheableWrapper, vp: *mut JSVal) -> bool { unsafe { let cache = value.get_wrappercache(); @@ -765,7 +765,7 @@ pub fn XrayResolveProperty(cx: *JSContext, unsafe { match attributes { Some(attrs) => { - for attrs.iter().advance |&elem| { + for &elem in attrs.iter() { let (attr, attr_id) = elem; if attr_id == JSID_VOID || attr_id != id { loop; @@ -815,20 +815,18 @@ 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.iter().enumerate().advance |(i, spec)| { + for (i, spec) in specs.iter().enumerate() { if spec.name.is_null() == true { - break; + return true; } match InternJSString(cx, spec.name) { Some(id) => ids[i] = id, None => { - rval = false; return false; } } } - rval + true } pub trait DerivedWrapper { @@ -853,6 +851,7 @@ impl DerivedWrapper for AbstractNode { } } +#[deriving(ToStr)] pub enum Error { FailureUnknown } @@ -877,12 +876,12 @@ pub fn FindEnumStringIndex(cx: *JSContext, if chars.is_null() { return Err(()); } - for values.iter().enumerate().advance |(i, value)| { + for (i, value) in values.iter().enumerate() { if value.length != length as uint { loop; } let mut equal = true; - for uint::iterate(0, length as uint) |j| { + for j in range(0, length as int) { if value.value[j] as u16 != *chars.offset(j) { equal = false; break; diff --git a/src/components/script/dom/characterdata.rs b/src/components/script/dom/characterdata.rs index d63fd75ec88..2d921fe07c5 100644 --- a/src/components/script/dom/characterdata.rs +++ b/src/components/script/dom/characterdata.rs @@ -23,7 +23,7 @@ impl CharacterData { } pub fn Data(&self) -> DOMString { - copy self.data + self.data.clone() } pub fn SetData(&mut self, arg: &DOMString, _rv: &mut ErrorResult) { diff --git a/src/components/script/dom/clientrect.rs b/src/components/script/dom/clientrect.rs index 5c1de65851a..a0ad4a96dc1 100644 --- a/src/components/script/dom/clientrect.rs +++ b/src/components/script/dom/clientrect.rs @@ -10,7 +10,6 @@ use js::jsapi::{JSObject, JSContext, JSVal}; use js::glue::RUST_OBJECT_TO_JSVAL; use std::cast; -use std::f32; pub struct ClientRect { wrapper: WrapperCache, @@ -54,11 +53,11 @@ impl ClientRect { } pub fn Width(&self) -> f32 { - f32::abs(self.right - self.left) + (self.right - self.left).abs() } pub fn Height(&self) -> f32 { - f32::abs(self.bottom - self.top) + (self.bottom - self.top).abs() } } diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index 043eec3646a..8547a0e3cc7 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -18,7 +18,7 @@ use dom::htmltitleelement::HTMLTitleElement; use js::jsapi::{JS_AddObjectRoot, JS_RemoveObjectRoot, JSObject, JSContext, JSVal}; use js::glue::RUST_OBJECT_TO_JSVAL; -use servo_util::tree::{TreeNodeRef, TreeUtils}; +use servo_util::tree::TreeNodeRef; use std::cast; use std::ptr; @@ -115,7 +115,7 @@ impl Document { } impl WrappableDocument for Document { - pub fn init_wrapper(@mut self, cx: *JSContext) { + fn init_wrapper(@mut self, cx: *JSContext) { self.wrap_object_shared(cx, ptr::null()); //XXXjdm a proper scope would be nice } } @@ -270,11 +270,11 @@ impl Document { fail!("no SVG document yet") }, _ => { - let _ = for self.root.traverse_preorder |node| { + let _ = for node in self.root.traverse_preorder() { if node.type_id() != ElementNodeTypeId(HTMLTitleElementTypeId) { loop; } - for node.children().advance |child| { + for child in node.children() { if child.is_text() { do child.with_imm_text() |text| { let s = text.parent.Data(); @@ -299,17 +299,17 @@ impl Document { }, _ => { let (_scope, cx) = self.get_scope_and_cx(); - let _ = for self.root.traverse_preorder |node| { + let _ = for node in self.root.traverse_preorder() { if node.type_id() != ElementNodeTypeId(HTMLHeadElementTypeId) { loop; } let mut has_title = false; - for node.children().advance |child| { + for child in node.children() { if child.type_id() != ElementNodeTypeId(HTMLTitleElementTypeId) { loop; } has_title = true; - for child.children().advance |title_child| { + for title_child in child.children() { child.remove_child(title_child); } let new_text = unsafe { @@ -427,7 +427,7 @@ impl Document { pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection { let mut elements = ~[]; - let _ = for self.root.traverse_preorder |child| { + let _ = for child in self.root.traverse_preorder() { if child.is_element() { do child.with_imm_element |elem| { if callback(elem) { @@ -441,7 +441,7 @@ impl Document { } pub fn content_changed(&self) { - for self.window.iter().advance |window| { + for window in self.window.iter() { window.content_changed() } } diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 4d775577367..8e6f620c28b 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -47,7 +47,7 @@ use js::jsapi::{JSContext, JSObject}; use std::cell::Cell; use std::comm; use std::str::eq_slice; -use extra::net::url; +use std::FromStr; pub struct Element { parent: Node, @@ -252,7 +252,7 @@ impl<'self> Element { pub fn get_attr(&'self self, name: &str) -> Option<&'self str> { // FIXME: Need an each() that links lifetimes in Rust. - for self.attrs.iter().advance |attr| { + for attr in self.attrs.iter() { if eq_slice(attr.name, name) { let val: &str = attr.value; return Some(val); @@ -265,7 +265,7 @@ impl<'self> Element { let name = name.to_str(); let value_cell = Cell::new(value.to_str()); let mut found = false; - for self.attrs.mut_iter().advance |attr| { + for attr in self.attrs.mut_iter() { if eq_slice(attr.name, name) { attr.value = value_cell.take().clone(); found = true; @@ -279,7 +279,7 @@ impl<'self> Element { if "style" == name { self.style_attribute = Some( Stylesheet::from_attribute( - url::from_str("http://www.example.com/").unwrap(), + FromStr::from_str("http://www.example.com/").unwrap(), value.get_ref())); } @@ -290,8 +290,8 @@ impl<'self> Element { } fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) { - let doc = self.parent.owner_doc.get(); - let win = doc.with_base(|doc| doc.window.get()); + let doc = self.parent.owner_doc.unwrap(); + let win = doc.with_base(|doc| doc.window.unwrap()); let cx = unsafe {(*win.page).js_info.get_ref().js_compartment.cx.ptr}; let cache = win.get_wrappercache(); let scope = cache.get_wrapper(); @@ -419,7 +419,7 @@ impl Element { debug!("no document"); None } - }.get(); + }.unwrap(); ClientRectList::new(rects, cx, scope) } diff --git a/src/components/script/dom/event.rs b/src/components/script/dom/event.rs index ca97d1bc364..78ccfa7e759 100644 --- a/src/components/script/dom/event.rs +++ b/src/components/script/dom/event.rs @@ -55,7 +55,7 @@ impl Event { } pub fn Type(&self) -> DOMString { - copy self.type_ + self.type_.clone() } pub fn GetTarget(&self) -> Option<@mut EventTarget> { diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index e5e027ed4f1..873b539fdc3 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -39,7 +39,7 @@ impl FormData { pub fn Append(&mut self, name: &DOMString, value: @mut Blob, filename: Option) { let blob = BlobData { blob: value, - name: filename.get_or_default(str(~"default")) + name: filename.unwrap_or_default(str(~"default")) }; self.data.insert(name.to_str(), blob); } diff --git a/src/components/script/dom/htmldocument.rs b/src/components/script/dom/htmldocument.rs index 52c15fc36cf..b8b56b1d850 100644 --- a/src/components/script/dom/htmldocument.rs +++ b/src/components/script/dom/htmldocument.rs @@ -13,7 +13,7 @@ use dom::window::Window; use js::jsapi::{JSObject, JSContext}; -use servo_util::tree::TreeUtils; +use servo_util::tree::TreeNodeRef; use std::libc; use std::ptr; @@ -43,7 +43,7 @@ impl HTMLDocument { } impl WrappableDocument for HTMLDocument { - pub fn init_wrapper(@mut self, cx: *JSContext) { + fn init_wrapper(@mut self, cx: *JSContext) { self.wrap_object_shared(cx, ptr::null()); //XXXjdm a proper scope would be nice } } @@ -69,7 +69,7 @@ impl HTMLDocument { pub fn GetHead(&self) -> Option> { let mut headNode: Option> = None; - let _ = for self.parent.root.traverse_preorder |child| { + let _ = for child in self.parent.root.traverse_preorder() { if child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId) { headNode = Some(child); break; diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index ee71c2786ff..98217737a27 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -11,7 +11,7 @@ use geom::size::Size2D; use servo_msg::constellation_msg::SubpageId; use std::comm::ChanOne; -use extra::net::url::Url; +use extra::url::Url; pub struct HTMLIFrameElement { parent: HTMLElement, diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index b803625ebde..f345d59a8b8 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -4,7 +4,7 @@ use dom::bindings::utils::{DOMString, null_string, ErrorResult}; use dom::htmlelement::HTMLElement; -use extra::net::url::Url; +use extra::url::Url; pub struct HTMLImageElement { parent: HTMLElement, diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index 236df0f3732..e06c77577ed 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -20,11 +20,10 @@ use dom::window::Window; use std::cast; use std::cast::transmute; use std::libc::c_void; -use std::uint; use js::jsapi::{JSObject, JSContext}; use js::rust::Compartment; use netsurfcss::util::VoidPtrLike; -use servo_util::tree::{TreeNode, TreeNodeRef, TreeUtils}; +use servo_util::tree::{TreeNode, TreeNodeRef}; // // The basic Node structure @@ -177,41 +176,39 @@ impl Clone for AbstractNode { } } -impl TreeNode> for Node { - fn parent_node(&self) -> Option> { - self.parent_node - } - fn first_child(&self) -> Option> { - self.first_child - } - fn last_child(&self) -> Option> { - self.last_child - } - fn prev_sibling(&self) -> Option> { - self.prev_sibling - } - fn next_sibling(&self) -> Option> { - self.next_sibling - } - - fn set_parent_node(&mut self, new_parent_node: Option>) { - self.parent_node = new_parent_node - } - fn set_first_child(&mut self, new_first_child: Option>) { - self.first_child = new_first_child - } - fn set_last_child(&mut self, new_last_child: Option>) { - self.last_child = new_last_child - } - fn set_prev_sibling(&mut self, new_prev_sibling: Option>) { - self.prev_sibling = new_prev_sibling - } - fn set_next_sibling(&mut self, new_next_sibling: Option>) { - self.next_sibling = new_next_sibling - } -} - impl TreeNodeRef> for AbstractNode { + fn parent_node(node: &Node) -> Option> { + node.parent_node + } + fn first_child(node: &Node) -> Option> { + node.first_child + } + fn last_child(node: &Node) -> Option> { + node.last_child + } + fn prev_sibling(node: &Node) -> Option> { + node.prev_sibling + } + fn next_sibling(node: &Node) -> Option> { + node.next_sibling + } + + fn set_parent_node(node: &mut Node, new_parent_node: Option>) { + node.parent_node = new_parent_node + } + fn set_first_child(node: &mut Node, new_first_child: Option>) { + node.first_child = new_first_child + } + fn set_last_child(node: &mut Node, new_last_child: Option>) { + node.last_child = new_last_child + } + fn set_prev_sibling(node: &mut Node, new_prev_sibling: Option>) { + node.prev_sibling = new_prev_sibling + } + fn set_next_sibling(node: &mut Node, new_next_sibling: Option>) { + node.next_sibling = new_next_sibling + } + // FIXME: The duplication between `with_base` and `with_mut_base` is ugly. fn with_base(&self, callback: &fn(&Node) -> R) -> R { self.transmute(callback) @@ -222,6 +219,8 @@ impl TreeNodeRef> for AbstractNode { } } +impl TreeNode> for Node { } + impl<'self, View> AbstractNode { // Unsafe accessors @@ -250,7 +249,7 @@ impl<'self, View> AbstractNode { /// allowed to call this. This is wildly unsafe and is therefore marked as such. pub unsafe fn unsafe_layout_data(self) -> @mut T { do self.with_base |base| { - transmute(base.layout_data.get()) + transmute(base.layout_data.unwrap()) } } /// Returns true if this node has layout data and false otherwise. @@ -438,7 +437,7 @@ impl<'self, View> AbstractNode { /// Dumps the node tree, for debugging, with indentation. pub fn dump_indent(&self, indent: uint) { let mut s = ~""; - for uint::range(0u, indent) |_i| { + for _ in range(0, indent) { s.push_str(" "); } @@ -446,7 +445,7 @@ impl<'self, View> AbstractNode { debug!("%s", s); // FIXME: this should have a pure version? - for self.each_child() |kid| { + for kid in self.children() { kid.dump_indent(indent + 1u) } } @@ -464,7 +463,7 @@ impl<'self, View> AbstractNode { } impl Iterator> for AbstractNodeChildrenIterator { - pub fn next(&mut self) -> Option> { + fn next(&mut self) -> Option> { let node = self.current_node; self.current_node = self.current_node.chain(|node| node.next_sibling()); node @@ -483,14 +482,14 @@ impl Node { pub fn add_to_doc(&mut self, doc: AbstractDocument) { self.owner_doc = Some(doc); - let mut node = self.first_child; - while node.is_some() { - for node.get().traverse_preorder |node| { + let mut cur_node = self.first_child; + while cur_node.is_some() { + for node in cur_node.unwrap().traverse_preorder() { do node.with_mut_base |node_base| { node_base.owner_doc = Some(doc); } }; - node = node.get().next_sibling(); + cur_node = cur_node.unwrap().next_sibling(); } } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 3f8339f913d..38f7901eafb 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -18,13 +18,13 @@ use js::{JSVAL_NULL, JSPROP_ENUMERATE}; use std::cast; use std::comm; -use std::comm::Chan; -use std::int; +use std::comm::SharedChan; use std::io; use std::ptr; +use std::int; +use std::rt::rtio::RtioTimer; +use std::rt::io::timer::Timer; use js::jsapi::JSVal; -use extra::timer; -use extra::uv_global_loop; pub enum TimerControlMsg { TimerMessage_Fire(~TimerData), @@ -38,7 +38,7 @@ pub struct Window { script_chan: ScriptChan, compositor: @ScriptListener, wrapper: WrapperCache, - timer_chan: Chan, + timer_chan: SharedChan, } #[unsafe_destructor] @@ -68,7 +68,7 @@ impl Window { pub fn Document(&self) -> AbstractDocument { unsafe { - (*self.page).frame.get().document + (*self.page).frame.unwrap().document } } @@ -142,18 +142,19 @@ impl BindingObject for Window { impl Window { pub fn SetTimeout(&self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { - let timeout = int::max(0, timeout) as uint; + let timeout = int::max(0, timeout) as u64; // Post a delayed message to the per-window timer task; it will dispatch it // to the relevant script handler that will deal with it. - let data = ~TimerData { - funval: callback, - args: ~[] - }; - timer::delayed_send(&uv_global_loop::get(), - timeout, - &self.timer_chan, - TimerMessage_Fire(data)); + let tm = Timer::new().unwrap(); + let chan = self.timer_chan.clone(); + do spawn { + tm.sleep(timeout); + chan.send(TimerMessage_Fire(~TimerData { + funval: callback, + args: ~[] + })); + } return 0; //TODO return handle into list of active timers } @@ -182,7 +183,7 @@ impl Window { } } } - timer_chan + SharedChan::new(timer_chan) }, }; diff --git a/src/components/script/html/cssparse.rs b/src/components/script/html/cssparse.rs index 95a600682ac..6d9d0d18a5a 100644 --- a/src/components/script/html/cssparse.rs +++ b/src/components/script/html/cssparse.rs @@ -11,7 +11,7 @@ use std::task; use newcss::stylesheet::Stylesheet; use newcss::util::DataStream; use servo_net::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done}; -use extra::net::url::Url; +use extra::url::Url; /// Where a style sheet comes from. pub enum StylesheetProvenance { @@ -28,8 +28,8 @@ pub fn spawn_css_parser(provenance: StylesheetProvenance, do task::spawn { let url = do provenance_cell.with_ref |p| { match *p { - UrlProvenance(ref the_url) => copy *the_url, - InlineProvenance(ref the_url, _) => copy *the_url + UrlProvenance(ref the_url) => (*the_url).clone(), + InlineProvenance(ref the_url, _) => (*the_url).clone() } }; diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index fd89d71da96..1aad6dc007c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -54,19 +54,18 @@ use newcss::stylesheet::Stylesheet; use std::cast; use std::cell::Cell; use std::comm; -use std::comm::{Chan, Port, SharedChan}; +use std::comm::{Port, SharedChan}; use std::str::eq_slice; -use std::result; use std::task; +use std::from_str::FromStr; use hubbub::hubbub; use servo_msg::constellation_msg::SubpageId; use servo_net::image_cache_task::ImageCacheTask; use servo_net::image_cache_task; use servo_net::resource_task::{Done, Load, Payload, ResourceTask}; -use servo_util::tree::TreeUtils; +use servo_util::tree::TreeNodeRef; use servo_util::url::make_url; -use extra::net::url::Url; -use extra::net::url; +use extra::url::Url; use extra::future::{Future, from_port}; use geom::size::Size2D; @@ -167,7 +166,7 @@ fn css_link_listener(to_parent: SharedChan, // Send the sheets back in order // FIXME: Shouldn't wait until after we've recieved CSSTaskExit to start sending these - for result_vec.iter().advance |port| { + for port in result_vec.iter() { to_parent.send(HtmlDiscoveredStyle(port.recv())); } } @@ -185,7 +184,7 @@ fn js_script_listener(to_parent: SharedChan, do task::spawn { let (input_port, input_chan) = comm::stream(); // TODO: change copy to move once we can move into closures - resource_task.send(Load(copy url, input_chan)); + resource_task.send(Load(url.clone(), input_chan)); let mut buf = ~[]; loop { @@ -273,7 +272,6 @@ fn build_element_from_tag(cx: *JSContext, tag: &str) -> AbstractNode } } -#[allow(non_implicitly_copyable_typarams)] pub fn parse_html(cx: *JSContext, url: Url, resource_task: ResourceTask, @@ -348,7 +346,7 @@ pub fn parse_html(cx: *JSContext, debug!("-- attach attrs"); do node.as_mut_element |element| { - for tag.attributes.iter().advance |attr| { + for attr in tag.attributes.iter() { element.set_attr(&str(attr.name.clone()), &str(attr.value.clone())); } } @@ -377,7 +375,7 @@ pub fn parse_html(cx: *JSContext, let iframe_chan = iframe_chan.take(); let elem = &mut iframe_element.parent.parent; let src_opt = elem.get_attr("src").map(|x| x.to_str()); - for src_opt.iter().advance |src| { + for src in src_opt.iter() { let iframe_url = make_url(src.clone(), Some(url2.clone())); iframe_element.frame = Some(iframe_url.clone()); @@ -404,7 +402,7 @@ pub fn parse_html(cx: *JSContext, None => {} Some(src) => { let img_url = make_url(src, Some(url2.clone())); - image_element.image = Some(copy img_url); + image_element.image = Some(img_url.clone()); // inform the image cache to load this, but don't store a handle. // TODO (Issue #84): don't prefetch if we are within a
%s