Backed out 3 changesets (bug 1474300) on request by kats for introducing a crasher a=backout
authorAndreea Pavel <apavel@mozilla.com>
Sun, 15 Jul 2018 17:57:36 +0300
changeset 481768 f97ba5c963ffbda5cb0b793047e581ae55d20530
parent 481767 2a8f94a45fd3f898cb63c54b8df662f8ad1f7527
child 481773 6024634afa8c90d56d2025d46f33d8bf661abab1
child 481778 33ecee5699744d6dc2e7017bf4f5521b0e88da40
child 481781 943d3038172ba0a7fe1f231a400cfd7d149935ef
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1474300
milestone63.0a1
backs outf7659b60b7b02ccdcf902f34273f7c386620cafd
a65429a135c7a385c3614d24b6d79cb7a9e3b3d1
376e702ed3ea6ed5b61421adf09b12f5dfe72212
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 3 changesets (bug 1474300) on request by kats for introducing a crasher a=backout Backed out changeset f7659b60b7b0 (bug 1474300) Backed out changeset a65429a135c7 (bug 1474300) Backed out changeset 376e702ed3ea (bug 1474300)
Cargo.lock
gfx/webrender/Cargo.toml
gfx/webrender/src/batch.rs
gfx/webrender/src/clip.rs
gfx/webrender/src/clip_node.rs
gfx/webrender/src/clip_scroll_node.rs
gfx/webrender/src/clip_scroll_tree.rs
gfx/webrender/src/display_list_flattener.rs
gfx/webrender/src/frame_builder.rs
gfx/webrender/src/gpu_types.rs
gfx/webrender/src/hit_test.rs
gfx/webrender/src/lib.rs
gfx/webrender/src/picture.rs
gfx/webrender/src/platform/macos/font.rs
gfx/webrender/src/prim_store.rs
gfx/webrender/src/render_backend.rs
gfx/webrender/src/spatial_node.rs
gfx/webrender/src/tiling.rs
gfx/webrender/tests/angle_shader_validation.rs
gfx/webrender_api/Cargo.toml
gfx/webrender_api/src/display_item.rs
gfx/webrender_api/src/display_list.rs
gfx/webrender_bindings/Cargo.toml
gfx/webrender_bindings/revision.txt
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi_generated.h
gfx/wrench/Cargo.toml
gfx/wrench/src/angle.rs
gfx/wrench/src/egl.rs
gfx/wrench/src/main.rs
third_party/rust/core-foundation-0.5.1/.cargo-checksum.json
third_party/rust/core-foundation-0.5.1/Cargo.toml
third_party/rust/core-foundation-0.5.1/LICENSE-APACHE
third_party/rust/core-foundation-0.5.1/LICENSE-MIT
third_party/rust/core-foundation-0.5.1/src/array.rs
third_party/rust/core-foundation-0.5.1/src/base.rs
third_party/rust/core-foundation-0.5.1/src/boolean.rs
third_party/rust/core-foundation-0.5.1/src/bundle.rs
third_party/rust/core-foundation-0.5.1/src/data.rs
third_party/rust/core-foundation-0.5.1/src/date.rs
third_party/rust/core-foundation-0.5.1/src/dictionary.rs
third_party/rust/core-foundation-0.5.1/src/error.rs
third_party/rust/core-foundation-0.5.1/src/filedescriptor.rs
third_party/rust/core-foundation-0.5.1/src/lib.rs
third_party/rust/core-foundation-0.5.1/src/number.rs
third_party/rust/core-foundation-0.5.1/src/propertylist.rs
third_party/rust/core-foundation-0.5.1/src/runloop.rs
third_party/rust/core-foundation-0.5.1/src/set.rs
third_party/rust/core-foundation-0.5.1/src/string.rs
third_party/rust/core-foundation-0.5.1/src/timezone.rs
third_party/rust/core-foundation-0.5.1/src/url.rs
third_party/rust/core-foundation-0.5.1/src/uuid.rs
third_party/rust/core-foundation-0.5.1/tests/use_macro_outside_crate.rs
third_party/rust/core-foundation-sys-0.5.1/.cargo-checksum.json
third_party/rust/core-foundation-sys-0.5.1/Cargo.toml
third_party/rust/core-foundation-sys-0.5.1/LICENSE-APACHE
third_party/rust/core-foundation-sys-0.5.1/LICENSE-MIT
third_party/rust/core-foundation-sys-0.5.1/build.rs
third_party/rust/core-foundation-sys-0.5.1/src/array.rs
third_party/rust/core-foundation-sys-0.5.1/src/base.rs
third_party/rust/core-foundation-sys-0.5.1/src/bundle.rs
third_party/rust/core-foundation-sys-0.5.1/src/data.rs
third_party/rust/core-foundation-sys-0.5.1/src/date.rs
third_party/rust/core-foundation-sys-0.5.1/src/dictionary.rs
third_party/rust/core-foundation-sys-0.5.1/src/error.rs
third_party/rust/core-foundation-sys-0.5.1/src/filedescriptor.rs
third_party/rust/core-foundation-sys-0.5.1/src/lib.rs
third_party/rust/core-foundation-sys-0.5.1/src/messageport.rs
third_party/rust/core-foundation-sys-0.5.1/src/number.rs
third_party/rust/core-foundation-sys-0.5.1/src/propertylist.rs
third_party/rust/core-foundation-sys-0.5.1/src/runloop.rs
third_party/rust/core-foundation-sys-0.5.1/src/set.rs
third_party/rust/core-foundation-sys-0.5.1/src/string.rs
third_party/rust/core-foundation-sys-0.5.1/src/timezone.rs
third_party/rust/core-foundation-sys-0.5.1/src/url.rs
third_party/rust/core-foundation-sys-0.5.1/src/uuid.rs
third_party/rust/core-graphics/.cargo-checksum.json
third_party/rust/core-graphics/Cargo.toml
third_party/rust/core-graphics/src/display.rs
third_party/rust/core-graphics/src/event.rs
third_party/rust/core-graphics/src/font.rs
third_party/rust/core-text/.cargo-checksum.json
third_party/rust/core-text/Cargo.toml
third_party/rust/core-text/src/font.rs
third_party/rust/core-text/src/font_collection.rs
third_party/rust/core-text/src/font_descriptor.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -330,46 +330,63 @@ name = "cookie"
 version = "0.10.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "core-foundation"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-foundation"
 version = "0.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "core-foundation-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "core-foundation-sys"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "core-foundation-sys"
 version = "0.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "core-graphics"
-version = "0.14.0"
+version = "0.13.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "core-text"
-version = "10.0.0"
+version = "9.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "cose"
 version = "0.1.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2345,19 +2362,19 @@ dependencies = [
 name = "webrender"
 version = "0.57.2"
 dependencies = [
  "app_units 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-text 10.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "dwrote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "freetype 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2374,34 +2391,34 @@ dependencies = [
 [[package]]
 name = "webrender_api"
 version = "0.57.2"
 dependencies = [
  "app_units 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "dwrote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_bytes 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 1.0.66 (git+https://github.com/servo/serde?branch=deserialize_from_enums8)",
  "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender_bindings"
 version = "0.1.0"
 dependencies = [
  "app_units 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "dwrote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "foreign-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "fxhash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "nsstring 0.1.0",
  "rayon 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2558,20 +2575,22 @@ dependencies = [
 "checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc"
 "checksum cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "393a5f0088efbe41f9d1fcd062f24e83c278608420e62109feb2c8abee07de7d"
 "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
 "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00"
 "checksum clang-sys 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7f7c04e52c35222fffcc3a115b5daf5f7e2bfb71c13c4e2321afe1fc71859c2"
 "checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
 "checksum cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb"
 "checksum cookie 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "746858cae4eae40fff37e1998320068df317bc247dc91a67c6cfa053afdc2abb"
+"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
 "checksum core-foundation 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7caa6cb9e76ddddbea09a03266d6b3bc98cd41e9fb9b017c473e7cca593ec25"
+"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
 "checksum core-foundation-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2a53cce0ddcf7e7e1f998738d757d5a3bf08bf799a180e50ebe50d298f52f5a"
-"checksum core-graphics 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e54c4ab33705fa1fc8af375bb7929d68e1c1546c1ecef408966d8c3e49a1d84a"
-"checksum core-text 10.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f59bff773954e5cd058a3f5983406b52bec7cc65202bef340ba64a0c40ac91"
+"checksum core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb0ed45fdc32f9ab426238fba9407dfead7bacd7900c9b4dd3f396f46eafdae3"
+"checksum core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd581c37283d0c23311d179aefbb891f2324ee0405da58a26e8594ab76e5748"
 "checksum cose 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "72fa26cb151d3ae4b70f63d67d0fed57ce04220feafafbae7f503bef7aae590d"
 "checksum cose-c 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "49726015ab0ca765144fcca61e4a7a543a16b795a777fa53f554da2fffff9a94"
 "checksum crc 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5d02c0aac6bd68393ed69e00bbc2457f3e89075c6349db7189618dc4ddc1d7"
 "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3"
 "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150"
 "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
 "checksum cssparser 0.24.0 (registry+https://github.com/rust-lang/crates.io-index)" = "495beddc39b1987b8e9f029354eccbd5ef88eb5f1cd24badb764dce338acf2e0"
 "checksum cssparser-macros 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f3a5383ae18dbfdeb569ed62019f5bddb2a95cd2d3833313c475a0d014777805"
--- a/gfx/webrender/Cargo.toml
+++ b/gfx/webrender/Cargo.toml
@@ -66,11 +66,11 @@ mozangle = "0.1"
 
 [target.'cfg(any(target_os = "android", all(unix, not(target_os = "macos"))))'.dependencies]
 freetype = { version = "0.4", default-features = false }
 
 [target.'cfg(target_os = "windows")'.dependencies]
 dwrote = "0.4.1"
 
 [target.'cfg(target_os = "macos")'.dependencies]
-core-foundation = "0.6"
-core-graphics = "0.14"
-core-text = { version = "10", default-features = false }
+core-foundation = "0.5"
+core-graphics = "0.13"
+core-text = { version = "9.2.0", default-features = false }
--- a/gfx/webrender/src/batch.rs
+++ b/gfx/webrender/src/batch.rs
@@ -470,18 +470,18 @@ impl AlphaBatchBuilder {
         };
 
         // Even though most of the time a splitter isn't used or needed,
         // they are cheap to construct so we will always pass one down.
         let mut splitter = BspSplitter::new();
 
         // Add each run in this picture to the batch.
         for run in &pic.runs {
-            let transform_id =
-                ctx.transforms.get_id(run.clip_and_scroll.scroll_node_id.transform_index());
+            let scroll_node = &ctx.clip_scroll_tree.nodes[run.clip_and_scroll.scroll_node_id.0];
+            let transform_id = ctx.transforms.get_id(scroll_node.transform_index);
             self.add_run_to_batch(
                 run,
                 transform_id,
                 ctx,
                 gpu_cache,
                 render_tasks,
                 task_id,
                 task_address,
@@ -665,17 +665,17 @@ impl AlphaBatchBuilder {
                         // If this picture is participating in a 3D rendering context,
                         // then don't add it to any batches here. Instead, create a polygon
                         // for it and add it to the current plane splitter.
                         if picture.is_in_3d_context {
                             // Push into parent plane splitter.
                             debug_assert!(picture.surface.is_some());
 
                             let real_xf = &ctx.clip_scroll_tree
-                                .spatial_nodes[picture.reference_frame_index.0]
+                                .nodes[picture.reference_frame_index.0]
                                 .world_content_transform
                                 .into();
                             let polygon = make_polygon(
                                 picture.real_local_rect,
                                 real_xf,
                                 prim_index.0,
                             );
 
--- a/gfx/webrender/src/clip.rs
+++ b/gfx/webrender/src/clip.rs
@@ -2,21 +2,21 @@
  * 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 api::{BorderRadius, ClipMode, ComplexClipRegion, DeviceIntRect, DevicePixelScale, ImageMask};
 use api::{ImageRendering, LayoutRect, LayoutSize, LayoutPoint, LayoutVector2D, LocalClip};
 use api::{BoxShadowClipMode, LayoutToWorldScale, LineOrientation, LineStyle};
 use border::{ensure_no_corner_overlap};
 use box_shadow::{BLUR_SAMPLE_SCALE, BoxShadowClipSource, BoxShadowCacheKey};
-use clip_scroll_tree::{ClipChainIndex, CoordinateSystemId};
+use clip_scroll_tree::{ClipChainIndex, CoordinateSystemId, TransformIndex};
 use ellipse::Ellipse;
 use freelist::{FreeList, FreeListHandle, WeakFreeListHandle};
 use gpu_cache::{GpuCache, GpuCacheHandle, ToGpuBlocks};
-use gpu_types::{BoxShadowStretchMode, TransformIndex};
+use gpu_types::{BoxShadowStretchMode};
 use prim_store::{ClipData, ImageMaskData};
 use render_task::to_cache_size;
 use resource_cache::{ImageRequest, ResourceCache};
 use util::{LayoutToWorldFastTransform, MaxRect, calculate_screen_bounding_rect};
 use util::{extract_inner_rect_safe, pack_as_float};
 use std::sync::Arc;
 
 #[derive(Debug)]
@@ -252,60 +252,38 @@ impl ClipSource {
                     ..*info
                 })
             }
             _ => {
                 panic!("bug: other clip sources not expected here yet");
             }
         }
     }
-
-    pub fn is_rect(&self) -> bool {
-        match *self {
-            ClipSource::Rectangle(..) => true,
-            _ => false,
-        }
-    }
-
-    pub fn is_image_or_line_decoration_clip(&self) -> bool {
-        match *self {
-            ClipSource::Image(..) | ClipSource::LineDecoration(..) => true,
-            _ => false,
-        }
-    }
 }
 
 #[derive(Debug)]
 pub struct ClipSources {
     pub clips: Vec<(ClipSource, GpuCacheHandle)>,
     pub local_inner_rect: LayoutRect,
-    pub local_outer_rect: Option<LayoutRect>,
-    pub only_rectangular_clips: bool,
-    pub has_image_or_line_decoration_clip: bool,
+    pub local_outer_rect: Option<LayoutRect>
 }
 
 impl ClipSources {
     pub fn new(clips: Vec<ClipSource>) -> Self {
         let (local_inner_rect, local_outer_rect) = Self::calculate_inner_and_outer_rects(&clips);
 
-        let has_image_or_line_decoration_clip =
-            clips.iter().any(|clip| clip.is_image_or_line_decoration_clip());
-        let only_rectangular_clips =
-            !has_image_or_line_decoration_clip && clips.iter().all(|clip| clip.is_rect());
         let clips = clips
             .into_iter()
             .map(|clip| (clip, GpuCacheHandle::new()))
             .collect();
 
         ClipSources {
             clips,
             local_inner_rect,
             local_outer_rect,
-            only_rectangular_clips,
-            has_image_or_line_decoration_clip,
         }
     }
 
     pub fn clips(&self) -> &[(ClipSource, GpuCacheHandle)] {
         &self.clips
     }
 
     fn calculate_inner_and_outer_rects(clips: &Vec<ClipSource>) -> (LayoutRect, Option<LayoutRect>) {
deleted file mode 100644
--- a/gfx/webrender/src/clip_node.rs
+++ /dev/null
@@ -1,100 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-use api::DevicePixelScale;
-use clip::{ClipChain, ClipChainNode, ClipSourcesHandle, ClipStore, ClipWorkItem};
-use clip_scroll_tree::{ClipChainIndex, SpatialNodeIndex};
-use gpu_cache::GpuCache;
-use resource_cache::ResourceCache;
-use spatial_node::SpatialNode;
-
-#[derive(Debug)]
-pub struct ClipNode {
-    /// The node that determines how this clip node is positioned.
-    pub spatial_node: SpatialNodeIndex,
-
-    /// A handle to this clip nodes clips in the ClipStore.
-    pub handle: Option<ClipSourcesHandle>,
-
-    /// An index to a ClipChain defined by this ClipNode's hiearchy in the display
-    /// list.
-    pub clip_chain_index: ClipChainIndex,
-
-    /// The index of the parent ClipChain of this node's hiearchical ClipChain.
-    pub parent_clip_chain_index: ClipChainIndex,
-
-    /// A copy of the ClipChainNode this node would produce. We need to keep a copy,
-    /// because the ClipChain may not contain our node if is optimized out, but API
-    /// defined ClipChains will still need to access it.
-    pub clip_chain_node: Option<ClipChainNode>,
-}
-
-impl ClipNode {
-    const EMPTY: ClipNode = ClipNode {
-        spatial_node: SpatialNodeIndex(0),
-        handle: None,
-        clip_chain_index: ClipChainIndex(0),
-        parent_clip_chain_index: ClipChainIndex(0),
-        clip_chain_node: None,
-    };
-
-    pub fn empty() -> ClipNode {
-        ClipNode::EMPTY
-    }
-
-    pub fn update(
-        &mut self,
-        spatial_node: &SpatialNode,
-        device_pixel_scale: DevicePixelScale,
-        clip_store: &mut ClipStore,
-        resource_cache: &mut ResourceCache,
-        gpu_cache: &mut GpuCache,
-        clip_chains: &mut [ClipChain],
-    ) {
-        let (clip_sources, weak_handle) = match self.handle {
-            Some(ref handle) => (clip_store.get_mut(handle), handle.weak()),
-            None => {
-                warn!("Tried to process an empty clip node");
-                return;
-            }
-        };
-        clip_sources.update(gpu_cache, resource_cache, device_pixel_scale);
-
-        let (screen_inner_rect, screen_outer_rect) = clip_sources.get_screen_bounds(
-            &spatial_node.world_content_transform,
-            device_pixel_scale,
-            None,
-        );
-
-        // All clipping SpatialNodes should have outer rectangles, because they never
-        // use the BorderCorner clip type and they always have at last one non-ClipOut
-        // Rectangle ClipSource.
-        let screen_outer_rect = screen_outer_rect
-            .expect("Clipping node didn't have outer rect.");
-        let local_outer_rect = clip_sources.local_outer_rect
-            .expect("Clipping node didn't have outer rect.");
-
-        let new_node = ClipChainNode {
-            work_item: ClipWorkItem {
-                transform_index: self.spatial_node.transform_index(),
-                clip_sources: weak_handle,
-                coordinate_system_id: spatial_node.coordinate_system_id,
-            },
-            local_clip_rect: spatial_node
-                .coordinate_system_relative_transform
-                .transform_rect(&local_outer_rect),
-            screen_outer_rect,
-            screen_inner_rect,
-            prev: None,
-        };
-
-        let mut clip_chain =
-            clip_chains[self.parent_clip_chain_index.0]
-            .new_with_added_node(&new_node);
-
-        self.clip_chain_node = Some(new_node);
-        clip_chain.parent_index = Some(self.parent_clip_chain_index);
-        clip_chains[self.clip_chain_index.0] = clip_chain;
-    }
-}
new file mode 100644
--- /dev/null
+++ b/gfx/webrender/src/clip_scroll_node.rs
@@ -0,0 +1,844 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use api::{DevicePixelScale, ExternalScrollId, LayoutPixel, LayoutPoint, LayoutRect, LayoutSize};
+use api::{LayoutVector2D, LayoutTransform, PipelineId, PropertyBinding};
+use api::{ScrollClamping, ScrollLocation, ScrollSensitivity, StickyOffsetBounds};
+use clip::{ClipChain, ClipChainNode, ClipSourcesHandle, ClipStore, ClipWorkItem};
+use clip_scroll_tree::{ClipChainIndex, ClipScrollNodeIndex, CoordinateSystemId};
+use clip_scroll_tree::{TransformUpdateState, TransformIndex};
+use euclid::SideOffsets2D;
+use gpu_cache::GpuCache;
+use gpu_types::{TransformData, TransformPalette};
+use resource_cache::ResourceCache;
+use scene::SceneProperties;
+use util::{LayoutToWorldFastTransform, LayoutFastTransform};
+use util::{TransformedRectKind};
+
+#[derive(Debug)]
+pub struct StickyFrameInfo {
+    pub frame_rect: LayoutRect,
+    pub margins: SideOffsets2D<Option<f32>>,
+    pub vertical_offset_bounds: StickyOffsetBounds,
+    pub horizontal_offset_bounds: StickyOffsetBounds,
+    pub previously_applied_offset: LayoutVector2D,
+    pub current_offset: LayoutVector2D,
+}
+
+impl StickyFrameInfo {
+    pub fn new(
+        frame_rect: LayoutRect,
+        margins: SideOffsets2D<Option<f32>>,
+        vertical_offset_bounds: StickyOffsetBounds,
+        horizontal_offset_bounds: StickyOffsetBounds,
+        previously_applied_offset: LayoutVector2D
+    ) -> StickyFrameInfo {
+        StickyFrameInfo {
+            frame_rect,
+            margins,
+            vertical_offset_bounds,
+            horizontal_offset_bounds,
+            previously_applied_offset,
+            current_offset: LayoutVector2D::zero(),
+        }
+    }
+}
+
+#[derive(Debug)]
+pub enum SpatialNodeKind {
+    /// A special kind of node that adjusts its position based on the position
+    /// of its parent node and a given set of sticky positioning offset bounds.
+    /// Sticky positioned is described in the CSS Positioned Layout Module Level 3 here:
+    /// https://www.w3.org/TR/css-position-3/#sticky-pos
+    StickyFrame(StickyFrameInfo),
+
+    /// Transforms it's content, but doesn't clip it. Can also be adjusted
+    /// by scroll events or setting scroll offsets.
+    ScrollFrame(ScrollFrameInfo),
+
+    /// A reference frame establishes a new coordinate space in the tree.
+    ReferenceFrame(ReferenceFrameInfo),
+}
+
+#[derive(Debug)]
+pub enum NodeType {
+    Spatial {
+        kind: SpatialNodeKind,
+    },
+
+    /// Other nodes just do clipping, but no transformation.
+    Clip {
+        handle: ClipSourcesHandle,
+        clip_chain_index: ClipChainIndex,
+
+        /// A copy of the ClipChainNode this node would produce. We need to keep a copy,
+        /// because the ClipChain may not contain our node if is optimized out, but API
+        /// defined ClipChains will still need to access it.
+        clip_chain_node: Option<ClipChainNode>,
+    },
+
+    /// An empty node, used to pad the ClipScrollTree's array of nodes so that
+    /// we can immediately use each assigned ClipScrollNodeIndex. After display
+    /// list flattening this node type should never be used.
+    Empty,
+}
+
+impl NodeType {
+    fn is_reference_frame(&self) -> bool {
+        match *self {
+            NodeType::Spatial { kind: SpatialNodeKind::ReferenceFrame(_), .. } => true,
+            _ => false,
+        }
+    }
+}
+
+/// Contains information common among all types of ClipScrollTree nodes.
+#[derive(Debug)]
+pub struct ClipScrollNode {
+    /// The transformation for this viewport in world coordinates is the transformation for
+    /// our parent reference frame, plus any accumulated scrolling offsets from nodes
+    /// between our reference frame and this node. For reference frames, we also include
+    /// whatever local transformation this reference frame provides.
+    pub world_viewport_transform: LayoutToWorldFastTransform,
+
+    /// World transform for content transformed by this node.
+    pub world_content_transform: LayoutToWorldFastTransform,
+
+    /// The current transform kind of world_content_transform.
+    pub transform_kind: TransformedRectKind,
+
+    /// Pipeline that this layer belongs to
+    pub pipeline_id: PipelineId,
+
+    /// Parent layer. If this is None, we are the root node.
+    pub parent: Option<ClipScrollNodeIndex>,
+
+    /// Child layers
+    pub children: Vec<ClipScrollNodeIndex>,
+
+    /// The type of this node and any data associated with that node type.
+    pub node_type: NodeType,
+
+    /// True if this node is transformed by an invertible transform.  If not, display items
+    /// transformed by this node will not be displayed and display items not transformed by this
+    /// node will not be clipped by clips that are transformed by this node.
+    pub invertible: bool,
+
+    /// The axis-aligned coordinate system id of this node.
+    pub coordinate_system_id: CoordinateSystemId,
+
+    /// The transformation from the coordinate system which established our compatible coordinate
+    /// system (same coordinate system id) and us. This can change via scroll offsets and via new
+    /// reference frame transforms.
+    pub coordinate_system_relative_transform: LayoutFastTransform,
+
+    /// The index of the spatial node that provides positioning information for this node.
+    /// For reference frames, scroll and sticky frames it is a unique identfier.
+    /// For clip nodes, this is the nearest ancestor spatial node.
+    pub transform_index: TransformIndex,
+}
+
+impl ClipScrollNode {
+    pub fn new(
+        pipeline_id: PipelineId,
+        parent_index: Option<ClipScrollNodeIndex>,
+        node_type: NodeType,
+        transform_index: TransformIndex,
+    ) -> Self {
+        ClipScrollNode {
+            world_viewport_transform: LayoutToWorldFastTransform::identity(),
+            world_content_transform: LayoutToWorldFastTransform::identity(),
+            transform_kind: TransformedRectKind::AxisAligned,
+            parent: parent_index,
+            children: Vec::new(),
+            pipeline_id,
+            node_type,
+            invertible: true,
+            coordinate_system_id: CoordinateSystemId(0),
+            coordinate_system_relative_transform: LayoutFastTransform::identity(),
+            transform_index,
+        }
+    }
+
+    pub fn empty() -> ClipScrollNode {
+        Self::new(
+            PipelineId::dummy(),
+            None,
+            NodeType::Empty,
+            TransformIndex(0),
+        )
+    }
+
+    pub fn new_scroll_frame(
+        pipeline_id: PipelineId,
+        parent_index: ClipScrollNodeIndex,
+        external_id: Option<ExternalScrollId>,
+        frame_rect: &LayoutRect,
+        content_size: &LayoutSize,
+        scroll_sensitivity: ScrollSensitivity,
+        transform_index: TransformIndex,
+    ) -> Self {
+        let node_type = NodeType::Spatial {
+            kind: SpatialNodeKind::ScrollFrame(ScrollFrameInfo::new(
+                *frame_rect,
+                scroll_sensitivity,
+                LayoutSize::new(
+                    (content_size.width - frame_rect.size.width).max(0.0),
+                    (content_size.height - frame_rect.size.height).max(0.0)
+                ),
+                external_id,
+            )),
+        };
+
+        Self::new(
+            pipeline_id,
+            Some(parent_index),
+            node_type,
+            transform_index,
+        )
+    }
+
+    pub fn new_reference_frame(
+        parent_index: Option<ClipScrollNodeIndex>,
+        source_transform: Option<PropertyBinding<LayoutTransform>>,
+        source_perspective: Option<LayoutTransform>,
+        origin_in_parent_reference_frame: LayoutVector2D,
+        pipeline_id: PipelineId,
+        transform_index: TransformIndex,
+    ) -> Self {
+        let identity = LayoutTransform::identity();
+        let source_perspective = source_perspective.map_or_else(
+            LayoutFastTransform::identity, |perspective| perspective.into());
+        let info = ReferenceFrameInfo {
+            resolved_transform: LayoutFastTransform::identity(),
+            source_transform: source_transform.unwrap_or(PropertyBinding::Value(identity)),
+            source_perspective,
+            origin_in_parent_reference_frame,
+            invertible: true,
+        };
+        Self::new(
+            pipeline_id,
+            parent_index,
+            NodeType::Spatial {
+                kind: SpatialNodeKind::ReferenceFrame(info),
+            },
+            transform_index,
+        )
+    }
+
+    pub fn new_sticky_frame(
+        parent_index: ClipScrollNodeIndex,
+        sticky_frame_info: StickyFrameInfo,
+        pipeline_id: PipelineId,
+        transform_index: TransformIndex,
+    ) -> Self {
+        let node_type = NodeType::Spatial {
+            kind: SpatialNodeKind::StickyFrame(sticky_frame_info),
+        };
+        Self::new(
+            pipeline_id,
+            Some(parent_index),
+            node_type,
+            transform_index,
+        )
+    }
+
+
+    pub fn add_child(&mut self, child: ClipScrollNodeIndex) {
+        self.children.push(child);
+    }
+
+    pub fn apply_old_scrolling_state(&mut self, old_scroll_info: &ScrollFrameInfo) {
+        match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(ref mut scrolling), .. } => {
+                *scrolling = scrolling.combine_with_old_scroll_info(old_scroll_info);
+            }
+            _ if old_scroll_info.offset != LayoutVector2D::zero() => {
+                warn!("Tried to scroll a non-scroll node.")
+            }
+            _ => {}
+        }
+    }
+
+    pub fn set_scroll_origin(&mut self, origin: &LayoutPoint, clamp: ScrollClamping) -> bool {
+        let scrollable_size = self.scrollable_size();
+        let scrollable_width = scrollable_size.width;
+        let scrollable_height = scrollable_size.height;
+
+        let scrolling = match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(ref mut scrolling), .. } => scrolling,
+            _ => {
+                warn!("Tried to scroll a non-scroll node.");
+                return false;
+            }
+        };
+
+        let new_offset = match clamp {
+            ScrollClamping::ToContentBounds => {
+                if scrollable_height <= 0. && scrollable_width <= 0. {
+                    return false;
+                }
+
+                let origin = LayoutPoint::new(origin.x.max(0.0), origin.y.max(0.0));
+                LayoutVector2D::new(
+                    (-origin.x).max(-scrollable_width).min(0.0).round(),
+                    (-origin.y).max(-scrollable_height).min(0.0).round(),
+                )
+            }
+            ScrollClamping::NoClamping => LayoutPoint::zero() - *origin,
+        };
+
+        if new_offset == scrolling.offset {
+            return false;
+        }
+
+        scrolling.offset = new_offset;
+        true
+    }
+
+    pub fn mark_uninvertible(&mut self) {
+        self.invertible = false;
+        self.world_content_transform = LayoutToWorldFastTransform::identity();
+        self.world_viewport_transform = LayoutToWorldFastTransform::identity();
+    }
+
+    pub fn push_gpu_data(
+        &mut self,
+        transform_palette: &mut TransformPalette,
+    ) {
+        if let NodeType::Spatial { .. } = self.node_type {
+            if !self.invertible {
+                transform_palette.set(self.transform_index, TransformData::invalid());
+                return;
+            }
+
+            let inv_transform = match self.world_content_transform.inverse() {
+                Some(inverted) => inverted.to_transform(),
+                None => {
+                    transform_palette.set(self.transform_index, TransformData::invalid());
+                    return;
+                }
+            };
+
+            let data = TransformData {
+                transform: self.world_content_transform.into(),
+                inv_transform,
+            };
+
+            // Write the data that will be made available to the GPU for this node.
+            transform_palette.set(self.transform_index, data);
+        }
+    }
+
+    pub fn update(
+        &mut self,
+        state: &mut TransformUpdateState,
+        next_coordinate_system_id: &mut CoordinateSystemId,
+        device_pixel_scale: DevicePixelScale,
+        clip_store: &mut ClipStore,
+        resource_cache: &mut ResourceCache,
+        gpu_cache: &mut GpuCache,
+        scene_properties: &SceneProperties,
+        clip_chains: &mut Vec<ClipChain>,
+    ) {
+        // If any of our parents was not rendered, we are not rendered either and can just
+        // quit here.
+        if !state.invertible {
+            self.mark_uninvertible();
+            return;
+        }
+
+        self.update_transform(state, next_coordinate_system_id, scene_properties);
+
+        self.transform_kind = if self.world_content_transform.preserves_2d_axis_alignment() {
+            TransformedRectKind::AxisAligned
+        } else {
+            TransformedRectKind::Complex
+        };
+
+        // If this node is a reference frame, we check if it has a non-invertible matrix.
+        // For non-reference-frames we assume that they will produce only additional
+        // translations which should be invertible.
+        match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ReferenceFrame(info), .. } if !info.invertible => {
+                self.mark_uninvertible();
+                return;
+            }
+            _ => self.invertible = true,
+        }
+
+        self.update_clip_work_item(
+            state,
+            device_pixel_scale,
+            clip_store,
+            resource_cache,
+            gpu_cache,
+            clip_chains,
+        );
+    }
+
+    pub fn update_clip_work_item(
+        &mut self,
+        state: &mut TransformUpdateState,
+        device_pixel_scale: DevicePixelScale,
+        clip_store: &mut ClipStore,
+        resource_cache: &mut ResourceCache,
+        gpu_cache: &mut GpuCache,
+        clip_chains: &mut [ClipChain],
+    ) {
+        let (clip_sources_handle, clip_chain_index, stored_clip_chain_node) = match self.node_type {
+            NodeType::Clip { ref handle, clip_chain_index, ref mut clip_chain_node, .. } =>
+                (handle, clip_chain_index, clip_chain_node),
+            _ => {
+                self.invertible = true;
+                return;
+            }
+        };
+
+        let clip_sources = clip_store.get_mut(clip_sources_handle);
+        clip_sources.update(
+            gpu_cache,
+            resource_cache,
+            device_pixel_scale,
+        );
+
+        let (screen_inner_rect, screen_outer_rect) = clip_sources.get_screen_bounds(
+            &self.world_viewport_transform,
+            device_pixel_scale,
+            None,
+        );
+
+        // All clipping ClipScrollNodes should have outer rectangles, because they never
+        // use the BorderCorner clip type and they always have at last one non-ClipOut
+        // Rectangle ClipSource.
+        let screen_outer_rect = screen_outer_rect
+            .expect("Clipping node didn't have outer rect.");
+        let local_outer_rect = clip_sources.local_outer_rect
+            .expect("Clipping node didn't have outer rect.");
+
+        let new_node = ClipChainNode {
+            work_item: ClipWorkItem {
+                transform_index: self.transform_index,
+                clip_sources: clip_sources_handle.weak(),
+                coordinate_system_id: state.current_coordinate_system_id,
+            },
+            local_clip_rect:
+                self.coordinate_system_relative_transform.transform_rect(&local_outer_rect),
+            screen_outer_rect,
+            screen_inner_rect,
+            prev: None,
+        };
+
+        let mut clip_chain =
+            clip_chains[state.parent_clip_chain_index.0].new_with_added_node(&new_node);
+
+        *stored_clip_chain_node = Some(new_node);
+        clip_chain.parent_index = Some(state.parent_clip_chain_index);
+        clip_chains[clip_chain_index.0] = clip_chain;
+        state.parent_clip_chain_index = clip_chain_index;
+    }
+
+    pub fn update_transform(
+        &mut self,
+        state: &mut TransformUpdateState,
+        next_coordinate_system_id: &mut CoordinateSystemId,
+        scene_properties: &SceneProperties,
+    ) {
+        if self.node_type.is_reference_frame() {
+            self.update_transform_for_reference_frame(
+                state,
+                next_coordinate_system_id,
+                scene_properties
+            );
+            return;
+        }
+
+        // We calculate this here to avoid a double-borrow later.
+        let sticky_offset = self.calculate_sticky_offset(
+            &state.nearest_scrolling_ancestor_offset,
+            &state.nearest_scrolling_ancestor_viewport,
+        );
+
+        // The transformation for the bounds of our viewport is the parent reference frame
+        // transform, plus any accumulated scroll offset from our parents, plus any offset
+        // provided by our own sticky positioning.
+        let accumulated_offset = state.parent_accumulated_scroll_offset + sticky_offset;
+        self.world_viewport_transform = if accumulated_offset != LayoutVector2D::zero() {
+            state.parent_reference_frame_transform.pre_translate(&accumulated_offset)
+        } else {
+            state.parent_reference_frame_transform
+        };
+
+        // The transformation for any content inside of us is the viewport transformation, plus
+        // whatever scrolling offset we supply as well.
+        let scroll_offset = self.scroll_offset();
+        self.world_content_transform = if scroll_offset != LayoutVector2D::zero() {
+            self.world_viewport_transform.pre_translate(&scroll_offset)
+        } else {
+            self.world_viewport_transform
+        };
+
+        let added_offset = state.parent_accumulated_scroll_offset + sticky_offset + scroll_offset;
+        self.coordinate_system_relative_transform =
+            state.coordinate_system_relative_transform.offset(added_offset);
+
+        if let NodeType::Spatial { kind: SpatialNodeKind::StickyFrame(ref mut info), .. } = self.node_type {
+            info.current_offset = sticky_offset;
+        }
+
+        self.coordinate_system_id = state.current_coordinate_system_id;
+    }
+
+    pub fn update_transform_for_reference_frame(
+        &mut self,
+        state: &mut TransformUpdateState,
+        next_coordinate_system_id: &mut CoordinateSystemId,
+        scene_properties: &SceneProperties,
+    ) {
+        let info = match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ReferenceFrame(ref mut info), .. } => info,
+            _ => unreachable!("Called update_transform_for_reference_frame on non-ReferenceFrame"),
+        };
+
+        // Resolve the transform against any property bindings.
+        let source_transform = scene_properties.resolve_layout_transform(&info.source_transform);
+        info.resolved_transform =
+            LayoutFastTransform::with_vector(info.origin_in_parent_reference_frame)
+            .pre_mul(&source_transform.into())
+            .pre_mul(&info.source_perspective);
+
+        // The transformation for this viewport in world coordinates is the transformation for
+        // our parent reference frame, plus any accumulated scrolling offsets from nodes
+        // between our reference frame and this node. Finally, we also include
+        // whatever local transformation this reference frame provides.
+        let relative_transform = info.resolved_transform
+            .post_translate(state.parent_accumulated_scroll_offset)
+            .to_transform()
+            .with_destination::<LayoutPixel>();
+        self.world_viewport_transform =
+            state.parent_reference_frame_transform.pre_mul(&relative_transform.into());
+        self.world_content_transform = self.world_viewport_transform;
+
+        info.invertible = self.world_viewport_transform.is_invertible();
+        if !info.invertible {
+            return;
+        }
+
+        // Try to update our compatible coordinate system transform. If we cannot, start a new
+        // incompatible coordinate system.
+        match state.coordinate_system_relative_transform.update(relative_transform) {
+            Some(offset) => self.coordinate_system_relative_transform = offset,
+            None => {
+                self.coordinate_system_relative_transform = LayoutFastTransform::identity();
+                state.current_coordinate_system_id = *next_coordinate_system_id;
+                next_coordinate_system_id.advance();
+            }
+        }
+
+        self.coordinate_system_id = state.current_coordinate_system_id;
+    }
+
+    fn calculate_sticky_offset(
+        &self,
+        viewport_scroll_offset: &LayoutVector2D,
+        viewport_rect: &LayoutRect,
+    ) -> LayoutVector2D {
+        let info = match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::StickyFrame(ref info), .. } => info,
+            _ => return LayoutVector2D::zero(),
+        };
+
+        if info.margins.top.is_none() && info.margins.bottom.is_none() &&
+            info.margins.left.is_none() && info.margins.right.is_none() {
+            return LayoutVector2D::zero();
+        }
+
+        // The viewport and margins of the item establishes the maximum amount that it can
+        // be offset in order to keep it on screen. Since we care about the relationship
+        // between the scrolled content and unscrolled viewport we adjust the viewport's
+        // position by the scroll offset in order to work with their relative positions on the
+        // page.
+        let sticky_rect = info.frame_rect.translate(viewport_scroll_offset);
+
+        let mut sticky_offset = LayoutVector2D::zero();
+        if let Some(margin) = info.margins.top {
+            let top_viewport_edge = viewport_rect.min_y() + margin;
+            if sticky_rect.min_y() < top_viewport_edge {
+                // If the sticky rect is positioned above the top edge of the viewport (plus margin)
+                // we move it down so that it is fully inside the viewport.
+                sticky_offset.y = top_viewport_edge - sticky_rect.min_y();
+            } else if info.previously_applied_offset.y > 0.0 &&
+                sticky_rect.min_y() > top_viewport_edge {
+                // However, if the sticky rect is positioned *below* the top edge of the viewport
+                // and there is already some offset applied to the sticky rect's position, then
+                // we need to move it up so that it remains at the correct position. This
+                // makes sticky_offset.y negative and effectively reduces the amount of the
+                // offset that was already applied. We limit the reduction so that it can, at most,
+                // cancel out the already-applied offset, but should never end up adjusting the
+                // position the other way.
+                sticky_offset.y = top_viewport_edge - sticky_rect.min_y();
+                sticky_offset.y = sticky_offset.y.max(-info.previously_applied_offset.y);
+            }
+            debug_assert!(sticky_offset.y + info.previously_applied_offset.y >= 0.0);
+        }
+
+        // If we don't have a sticky-top offset (sticky_offset.y + info.previously_applied_offset.y
+        // == 0), or if we have a previously-applied bottom offset (previously_applied_offset.y < 0)
+        // then we check for handling the bottom margin case.
+        if sticky_offset.y + info.previously_applied_offset.y <= 0.0 {
+            if let Some(margin) = info.margins.bottom {
+                // Same as the above case, but inverted for bottom-sticky items. Here
+                // we adjust items upwards, resulting in a negative sticky_offset.y,
+                // or reduce the already-present upward adjustment, resulting in a positive
+                // sticky_offset.y.
+                let bottom_viewport_edge = viewport_rect.max_y() - margin;
+                if sticky_rect.max_y() > bottom_viewport_edge {
+                    sticky_offset.y = bottom_viewport_edge - sticky_rect.max_y();
+                } else if info.previously_applied_offset.y < 0.0 &&
+                    sticky_rect.max_y() < bottom_viewport_edge {
+                    sticky_offset.y = bottom_viewport_edge - sticky_rect.max_y();
+                    sticky_offset.y = sticky_offset.y.min(-info.previously_applied_offset.y);
+                }
+                debug_assert!(sticky_offset.y + info.previously_applied_offset.y <= 0.0);
+            }
+        }
+
+        // Same as above, but for the x-axis.
+        if let Some(margin) = info.margins.left {
+            let left_viewport_edge = viewport_rect.min_x() + margin;
+            if sticky_rect.min_x() < left_viewport_edge {
+                sticky_offset.x = left_viewport_edge - sticky_rect.min_x();
+            } else if info.previously_applied_offset.x > 0.0 &&
+                sticky_rect.min_x() > left_viewport_edge {
+                sticky_offset.x = left_viewport_edge - sticky_rect.min_x();
+                sticky_offset.x = sticky_offset.x.max(-info.previously_applied_offset.x);
+            }
+            debug_assert!(sticky_offset.x + info.previously_applied_offset.x >= 0.0);
+        }
+
+        if sticky_offset.x + info.previously_applied_offset.x <= 0.0 {
+            if let Some(margin) = info.margins.right {
+                let right_viewport_edge = viewport_rect.max_x() - margin;
+                if sticky_rect.max_x() > right_viewport_edge {
+                    sticky_offset.x = right_viewport_edge - sticky_rect.max_x();
+                } else if info.previously_applied_offset.x < 0.0 &&
+                    sticky_rect.max_x() < right_viewport_edge {
+                    sticky_offset.x = right_viewport_edge - sticky_rect.max_x();
+                    sticky_offset.x = sticky_offset.x.min(-info.previously_applied_offset.x);
+                }
+                debug_assert!(sticky_offset.x + info.previously_applied_offset.x <= 0.0);
+            }
+        }
+
+        // The total "sticky offset" (which is the sum that was already applied by
+        // the calling code, stored in info.previously_applied_offset, and the extra amount we
+        // computed as a result of scrolling, stored in sticky_offset) needs to be
+        // clamped to the provided bounds.
+        let clamp_adjusted = |value: f32, adjust: f32, bounds: &StickyOffsetBounds| {
+            (value + adjust).max(bounds.min).min(bounds.max) - adjust
+        };
+        sticky_offset.y = clamp_adjusted(sticky_offset.y,
+                                         info.previously_applied_offset.y,
+                                         &info.vertical_offset_bounds);
+        sticky_offset.x = clamp_adjusted(sticky_offset.x,
+                                         info.previously_applied_offset.x,
+                                         &info.horizontal_offset_bounds);
+
+        sticky_offset
+    }
+
+    pub fn prepare_state_for_children(&self, state: &mut TransformUpdateState) {
+        if !self.invertible {
+            state.invertible = false;
+            return;
+        }
+
+        // The transformation we are passing is the transformation of the parent
+        // reference frame and the offset is the accumulated offset of all the nodes
+        // between us and the parent reference frame. If we are a reference frame,
+        // we need to reset both these values.
+        match self.node_type {
+            NodeType::Spatial { ref kind, .. } => {
+                match *kind {
+                    SpatialNodeKind::StickyFrame(ref info) => {
+                        // We don't translate the combined rect by the sticky offset, because sticky
+                        // offsets actually adjust the node position itself, whereas scroll offsets
+                        // only apply to contents inside the node.
+                        state.parent_accumulated_scroll_offset =
+                            info.current_offset + state.parent_accumulated_scroll_offset;
+                    }
+                    SpatialNodeKind::ScrollFrame(ref scrolling) => {
+                        state.parent_accumulated_scroll_offset =
+                            scrolling.offset + state.parent_accumulated_scroll_offset;
+                        state.nearest_scrolling_ancestor_offset = scrolling.offset;
+                        state.nearest_scrolling_ancestor_viewport = scrolling.viewport_rect;
+                    }
+                    SpatialNodeKind::ReferenceFrame(ref info) => {
+                        state.parent_reference_frame_transform = self.world_viewport_transform;
+                        state.parent_accumulated_scroll_offset = LayoutVector2D::zero();
+                        state.coordinate_system_relative_transform =
+                            self.coordinate_system_relative_transform.clone();
+                        let translation = -info.origin_in_parent_reference_frame;
+                        state.nearest_scrolling_ancestor_viewport =
+                            state.nearest_scrolling_ancestor_viewport
+                               .translate(&translation);
+                    }
+                }
+            }
+            NodeType::Clip{ .. } => { }
+            NodeType::Empty => unreachable!("Empty node remaining in ClipScrollTree."),
+        }
+    }
+
+    pub fn scrollable_size(&self) -> LayoutSize {
+        match self.node_type {
+           NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(state), .. } => state.scrollable_size,
+            _ => LayoutSize::zero(),
+        }
+    }
+
+    pub fn scroll(&mut self, scroll_location: ScrollLocation) -> bool {
+        let scrolling = match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(ref mut scrolling), .. } => scrolling,
+            _ => return false,
+        };
+
+        let delta = match scroll_location {
+            ScrollLocation::Delta(delta) => delta,
+            ScrollLocation::Start => {
+                if scrolling.offset.y.round() >= 0.0 {
+                    // Nothing to do on this layer.
+                    return false;
+                }
+
+                scrolling.offset.y = 0.0;
+                return true;
+            }
+            ScrollLocation::End => {
+                let end_pos = -scrolling.scrollable_size.height;
+                if scrolling.offset.y.round() <= end_pos {
+                    // Nothing to do on this layer.
+                    return false;
+                }
+
+                scrolling.offset.y = end_pos;
+                return true;
+            }
+        };
+
+        let scrollable_width = scrolling.scrollable_size.width;
+        let scrollable_height = scrolling.scrollable_size.height;
+        let original_layer_scroll_offset = scrolling.offset;
+
+        if scrollable_width > 0. {
+            scrolling.offset.x = (scrolling.offset.x + delta.x)
+                .min(0.0)
+                .max(-scrollable_width)
+                .round();
+        }
+
+        if scrollable_height > 0. {
+            scrolling.offset.y = (scrolling.offset.y + delta.y)
+                .min(0.0)
+                .max(-scrollable_height)
+                .round();
+        }
+
+        scrolling.offset != original_layer_scroll_offset
+    }
+
+    pub fn scroll_offset(&self) -> LayoutVector2D {
+        match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(ref scrolling), .. } => scrolling.offset,
+            _ => LayoutVector2D::zero(),
+        }
+    }
+
+    pub fn matches_external_id(&self, external_id: ExternalScrollId) -> bool {
+        match self.node_type {
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(info), .. } if info.external_id == Some(external_id) => true,
+            _ => false,
+        }
+    }
+}
+
+#[derive(Copy, Clone, Debug)]
+pub struct ScrollFrameInfo {
+    /// The rectangle of the viewport of this scroll frame. This is important for
+    /// positioning of items inside child StickyFrames.
+    pub viewport_rect: LayoutRect,
+
+    pub offset: LayoutVector2D,
+    pub scroll_sensitivity: ScrollSensitivity,
+
+    /// Amount that this ScrollFrame can scroll in both directions.
+    pub scrollable_size: LayoutSize,
+
+    /// An external id to identify this scroll frame to API clients. This
+    /// allows setting scroll positions via the API without relying on ClipsIds
+    /// which may change between frames.
+    pub external_id: Option<ExternalScrollId>,
+
+}
+
+/// Manages scrolling offset.
+impl ScrollFrameInfo {
+    pub fn new(
+        viewport_rect: LayoutRect,
+        scroll_sensitivity: ScrollSensitivity,
+        scrollable_size: LayoutSize,
+        external_id: Option<ExternalScrollId>,
+    ) -> ScrollFrameInfo {
+        ScrollFrameInfo {
+            viewport_rect,
+            offset: LayoutVector2D::zero(),
+            scroll_sensitivity,
+            scrollable_size,
+            external_id,
+        }
+    }
+
+    pub fn sensitive_to_input_events(&self) -> bool {
+        match self.scroll_sensitivity {
+            ScrollSensitivity::ScriptAndInputEvents => true,
+            ScrollSensitivity::Script => false,
+        }
+    }
+
+    pub fn combine_with_old_scroll_info(
+        self,
+        old_scroll_info: &ScrollFrameInfo
+    ) -> ScrollFrameInfo {
+        ScrollFrameInfo {
+            viewport_rect: self.viewport_rect,
+            offset: old_scroll_info.offset,
+            scroll_sensitivity: self.scroll_sensitivity,
+            scrollable_size: self.scrollable_size,
+            external_id: self.external_id,
+        }
+    }
+}
+
+/// Contains information about reference frames.
+#[derive(Copy, Clone, Debug)]
+pub struct ReferenceFrameInfo {
+    /// The transformation that establishes this reference frame, relative to the parent
+    /// reference frame. The origin of the reference frame is included in the transformation.
+    pub resolved_transform: LayoutFastTransform,
+
+    /// The source transform and perspective matrices provided by the stacking context
+    /// that forms this reference frame. We maintain the property binding information
+    /// here so that we can resolve the animated transform and update the tree each
+    /// frame.
+    pub source_transform: PropertyBinding<LayoutTransform>,
+    pub source_perspective: LayoutFastTransform,
+
+    /// The original, not including the transform and relative to the parent reference frame,
+    /// origin of this reference frame. This is already rolled into the `transform' property, but
+    /// we also store it here to properly transform the viewport for sticky positioning.
+    pub origin_in_parent_reference_frame: LayoutVector2D,
+
+    /// True if the resolved transform is invertible.
+    pub invertible: bool,
+}
--- a/gfx/webrender/src/clip_scroll_tree.rs
+++ b/gfx/webrender/src/clip_scroll_tree.rs
@@ -1,51 +1,50 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use api::{DeviceIntRect, DevicePixelScale, ExternalScrollId, LayoutPoint, LayoutRect, LayoutVector2D};
 use api::{PipelineId, ScrollClamping, ScrollLocation, ScrollNodeState};
 use api::{LayoutSize, LayoutTransform, PropertyBinding, ScrollSensitivity, WorldPoint};
 use clip::{ClipChain, ClipSourcesHandle, ClipStore};
-use clip_node::ClipNode;
+use clip_scroll_node::{ClipScrollNode, NodeType, SpatialNodeKind, ScrollFrameInfo, StickyFrameInfo};
 use gpu_cache::GpuCache;
-use gpu_types::{TransformIndex, TransformPalette};
+use gpu_types::TransformPalette;
 use internal_types::{FastHashMap, FastHashSet};
 use print_tree::{PrintTree, PrintTreePrinter};
 use resource_cache::ResourceCache;
 use scene::SceneProperties;
-use spatial_node::{ScrollFrameInfo, SpatialNode, SpatialNodeType, StickyFrameInfo};
 use util::{LayoutFastTransform, LayoutToWorldFastTransform};
 
 pub type ScrollStates = FastHashMap<ExternalScrollId, ScrollFrameInfo>;
 
 /// An id that identifies coordinate systems in the ClipScrollTree. Each
 /// coordinate system has an id and those ids will be shared when the coordinates
 /// system are the same or are in the same axis-aligned space. This allows
 /// for optimizing mask generation.
 #[derive(Debug, Copy, Clone, PartialEq)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
 pub struct CoordinateSystemId(pub u32);
 
 #[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
-pub struct SpatialNodeIndex(pub usize);
-
-#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
-pub struct ClipNodeIndex(pub usize);
+pub struct ClipScrollNodeIndex(pub usize);
 
-impl SpatialNodeIndex {
-    pub fn transform_index(&self) -> TransformIndex {
-        TransformIndex(self.0 as u32)
-    }
-}
+// Used to index the smaller subset of nodes in the CST that define
+// new transform / positioning.
+// TODO(gw): In the future if we split the CST into a positioning and
+//           clipping tree, this can be tidied up a bit.
+#[derive(Copy, Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "capture", derive(Serialize))]
+#[cfg_attr(feature = "replay", derive(Deserialize))]
+pub struct TransformIndex(pub u32);
 
-const ROOT_REFERENCE_FRAME_INDEX: SpatialNodeIndex = SpatialNodeIndex(0);
-const TOPMOST_SCROLL_NODE_INDEX: SpatialNodeIndex = SpatialNodeIndex(1);
+const ROOT_REFERENCE_FRAME_INDEX: ClipScrollNodeIndex = ClipScrollNodeIndex(0);
+const TOPMOST_SCROLL_NODE_INDEX: ClipScrollNodeIndex = ClipScrollNodeIndex(1);
 
 impl CoordinateSystemId {
     pub fn root() -> Self {
         CoordinateSystemId(0)
     }
 
     pub fn next(&self) -> Self {
         let CoordinateSystemId(id) = *self;
@@ -55,53 +54,55 @@ impl CoordinateSystemId {
     pub fn advance(&mut self) {
         self.0 += 1;
     }
 }
 
 pub struct ClipChainDescriptor {
     pub index: ClipChainIndex,
     pub parent: Option<ClipChainIndex>,
-    pub clips: Vec<ClipNodeIndex>,
+    pub clips: Vec<ClipScrollNodeIndex>,
 }
 
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
 pub struct ClipChainIndex(pub usize);
 
 pub struct ClipScrollTree {
-    /// Nodes which determine the positions (offsets and transforms) for primitives
-    /// and clips.
-    pub spatial_nodes: Vec<SpatialNode>,
-
-    /// Nodes which clip primitives.
-    pub clip_nodes: Vec<ClipNode>,
+    pub nodes: Vec<ClipScrollNode>,
 
     /// A Vec of all descriptors that describe ClipChains in the order in which they are
     /// encountered during display list flattening. ClipChains are expected to never be
     /// the children of ClipChains later in the list.
     pub clip_chains_descriptors: Vec<ClipChainDescriptor>,
 
     /// A vector of all ClipChains in this ClipScrollTree including those from
     /// ClipChainDescriptors and also those defined by the clipping node hierarchy.
     pub clip_chains: Vec<ClipChain>,
 
     pub pending_scroll_offsets: FastHashMap<ExternalScrollId, (LayoutPoint, ScrollClamping)>,
 
     /// A set of pipelines which should be discarded the next time this
     /// tree is drained.
     pub pipelines_to_discard: FastHashSet<PipelineId>,
+
+    /// The number of nodes in the CST that are spatial. Currently, this is all
+    /// nodes that are not clip nodes.
+    spatial_node_count: usize,
 }
 
 #[derive(Clone)]
 pub struct TransformUpdateState {
     pub parent_reference_frame_transform: LayoutToWorldFastTransform,
     pub parent_accumulated_scroll_offset: LayoutVector2D,
     pub nearest_scrolling_ancestor_offset: LayoutVector2D,
     pub nearest_scrolling_ancestor_viewport: LayoutRect,
 
+    /// The index of the current parent's clip chain.
+    pub parent_clip_chain_index: ClipChainIndex,
+
     /// An id for keeping track of the axis-aligned space of this node. This is used in
     /// order to to track what kinds of clip optimizations can be done for a particular
     /// display list item, since optimizations can usually only be done among
     /// coordinate systems which are relatively axis aligned.
     pub current_coordinate_system_id: CoordinateSystemId,
 
     /// Transform from the coordinate system that started this compatible coordinate system.
     pub coordinate_system_relative_transform: LayoutFastTransform,
@@ -110,433 +111,461 @@ pub struct TransformUpdateState {
     /// transformed by this node will not be displayed and display items not transformed by this
     /// node will not be clipped by clips that are transformed by this node.
     pub invertible: bool,
 }
 
 impl ClipScrollTree {
     pub fn new() -> Self {
         ClipScrollTree {
-            spatial_nodes: Vec::new(),
-            clip_nodes: Vec::new(),
+            nodes: Vec::new(),
             clip_chains_descriptors: Vec::new(),
             clip_chains: vec![ClipChain::empty(&DeviceIntRect::zero())],
             pending_scroll_offsets: FastHashMap::default(),
             pipelines_to_discard: FastHashSet::default(),
+            spatial_node_count: 0,
         }
     }
 
     /// The root reference frame, which is the true root of the ClipScrollTree. Initially
-    /// this ID is not valid, which is indicated by ```spatial_nodes``` being empty.
-    pub fn root_reference_frame_index(&self) -> SpatialNodeIndex {
+    /// this ID is not valid, which is indicated by ```nodes``` being empty.
+    pub fn root_reference_frame_index(&self) -> ClipScrollNodeIndex {
         // TODO(mrobinson): We should eventually make this impossible to misuse.
-        debug_assert!(!self.spatial_nodes.is_empty());
+        debug_assert!(!self.nodes.is_empty());
         ROOT_REFERENCE_FRAME_INDEX
     }
 
     /// The root scroll node which is the first child of the root reference frame.
-    /// Initially this ID is not valid, which is indicated by ```spatial_nodes``` being empty.
-    pub fn topmost_scroll_node_index(&self) -> SpatialNodeIndex {
+    /// Initially this ID is not valid, which is indicated by ```nodes``` being empty.
+    pub fn topmost_scroll_node_index(&self) -> ClipScrollNodeIndex {
         // TODO(mrobinson): We should eventually make this impossible to misuse.
-        debug_assert!(self.spatial_nodes.len() >= 1);
+        debug_assert!(self.nodes.len() >= 1);
         TOPMOST_SCROLL_NODE_INDEX
     }
 
     pub fn get_scroll_node_state(&self) -> Vec<ScrollNodeState> {
         let mut result = vec![];
-        for node in &self.spatial_nodes {
-            if let SpatialNodeType::ScrollFrame(info) = node.node_type {
+        for node in &self.nodes {
+            if let NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(info), .. } = node.node_type {
                 if let Some(id) = info.external_id {
                     result.push(ScrollNodeState { id, scroll_offset: info.offset })
                 }
             }
         }
         result
     }
 
     pub fn drain(&mut self) -> ScrollStates {
         let mut scroll_states = FastHashMap::default();
-        for old_node in &mut self.spatial_nodes.drain(..) {
+        for old_node in &mut self.nodes.drain(..) {
             if self.pipelines_to_discard.contains(&old_node.pipeline_id) {
                 continue;
             }
 
             match old_node.node_type {
-                SpatialNodeType::ScrollFrame(info) if info.external_id.is_some() => {
+                NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(info), .. } if info.external_id.is_some() => {
                     scroll_states.insert(info.external_id.unwrap(), info);
                 }
                 _ => {}
             }
         }
 
-        self.clip_nodes.clear();
+        self.spatial_node_count = 0;
         self.pipelines_to_discard.clear();
         self.clip_chains = vec![ClipChain::empty(&DeviceIntRect::zero())];
         self.clip_chains_descriptors.clear();
         scroll_states
     }
 
     pub fn scroll_node(
         &mut self,
         origin: LayoutPoint,
         id: ExternalScrollId,
         clamp: ScrollClamping
     ) -> bool {
-        for node in &mut self.spatial_nodes {
+        for node in &mut self.nodes {
             if node.matches_external_id(id) {
                 return node.set_scroll_origin(&origin, clamp);
             }
         }
 
         self.pending_scroll_offsets.insert(id, (origin, clamp));
         false
     }
 
     fn find_nearest_scrolling_ancestor(
         &self,
-        index: Option<SpatialNodeIndex>
-    ) -> SpatialNodeIndex {
+        index: Option<ClipScrollNodeIndex>
+    ) -> ClipScrollNodeIndex {
         let index = match index {
             Some(index) => index,
             None => return self.topmost_scroll_node_index(),
         };
 
-        let node = &self.spatial_nodes[index.0];
+        let node = &self.nodes[index.0];
         match node.node_type {
-            SpatialNodeType::ScrollFrame(state) if state.sensitive_to_input_events() => index,
+            NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(state), .. } if state.sensitive_to_input_events() => index,
             _ => self.find_nearest_scrolling_ancestor(node.parent)
         }
     }
 
     pub fn scroll_nearest_scrolling_ancestor(
         &mut self,
         scroll_location: ScrollLocation,
-        node_index: Option<SpatialNodeIndex>,
+        node_index: Option<ClipScrollNodeIndex>,
     ) -> bool {
-        if self.spatial_nodes.is_empty() {
+        if self.nodes.is_empty() {
             return false;
         }
         let node_index = self.find_nearest_scrolling_ancestor(node_index);
-        self.spatial_nodes[node_index.0].scroll(scroll_location)
+        self.nodes[node_index.0].scroll(scroll_location)
     }
 
     pub fn update_tree(
         &mut self,
         screen_rect: &DeviceIntRect,
         device_pixel_scale: DevicePixelScale,
         clip_store: &mut ClipStore,
         resource_cache: &mut ResourceCache,
         gpu_cache: &mut GpuCache,
         pan: WorldPoint,
         scene_properties: &SceneProperties,
     ) -> TransformPalette {
-        let mut transform_palette = TransformPalette::new(self.spatial_nodes.len());
-        if self.spatial_nodes.is_empty() {
-            return transform_palette;
-        }
+        let mut transform_palette = TransformPalette::new(self.spatial_node_count);
 
-        self.clip_chains[0] = ClipChain::empty(screen_rect);
+        if !self.nodes.is_empty() {
+            self.clip_chains[0] = ClipChain::empty(screen_rect);
 
-        let root_reference_frame_index = self.root_reference_frame_index();
-        let mut state = TransformUpdateState {
-            parent_reference_frame_transform: LayoutVector2D::new(pan.x, pan.y).into(),
-            parent_accumulated_scroll_offset: LayoutVector2D::zero(),
-            nearest_scrolling_ancestor_offset: LayoutVector2D::zero(),
-            nearest_scrolling_ancestor_viewport: LayoutRect::zero(),
-            current_coordinate_system_id: CoordinateSystemId::root(),
-            coordinate_system_relative_transform: LayoutFastTransform::identity(),
-            invertible: true,
-        };
-
-        let mut next_coordinate_system_id = state.current_coordinate_system_id.next();
-        self.update_node(
-            root_reference_frame_index,
-            &mut state,
-            &mut next_coordinate_system_id,
-            &mut transform_palette,
-            scene_properties,
-        );
-
-        for clip_node in &mut self.clip_nodes {
-            let spatial_node = &self.spatial_nodes[clip_node.spatial_node.0];
-            clip_node.update(
-                spatial_node,
+            let root_reference_frame_index = self.root_reference_frame_index();
+            let mut state = TransformUpdateState {
+                parent_reference_frame_transform: LayoutVector2D::new(pan.x, pan.y).into(),
+                parent_accumulated_scroll_offset: LayoutVector2D::zero(),
+                nearest_scrolling_ancestor_offset: LayoutVector2D::zero(),
+                nearest_scrolling_ancestor_viewport: LayoutRect::zero(),
+                parent_clip_chain_index: ClipChainIndex(0),
+                current_coordinate_system_id: CoordinateSystemId::root(),
+                coordinate_system_relative_transform: LayoutFastTransform::identity(),
+                invertible: true,
+            };
+            let mut next_coordinate_system_id = state.current_coordinate_system_id.next();
+            self.update_node(
+                root_reference_frame_index,
+                &mut state,
+                &mut next_coordinate_system_id,
                 device_pixel_scale,
                 clip_store,
                 resource_cache,
                 gpu_cache,
-                &mut self.clip_chains,
+                &mut transform_palette,
+                scene_properties,
             );
+
+            self.build_clip_chains(screen_rect);
         }
-        self.build_clip_chains(screen_rect);
 
         transform_palette
     }
 
     fn update_node(
         &mut self,
-        node_index: SpatialNodeIndex,
+        node_index: ClipScrollNodeIndex,
         state: &mut TransformUpdateState,
         next_coordinate_system_id: &mut CoordinateSystemId,
+        device_pixel_scale: DevicePixelScale,
+        clip_store: &mut ClipStore,
+        resource_cache: &mut ResourceCache,
+        gpu_cache: &mut GpuCache,
         transform_palette: &mut TransformPalette,
         scene_properties: &SceneProperties,
     ) {
         // TODO(gw): This is an ugly borrow check workaround to clone these.
         //           Restructure this to avoid the clones!
         let mut state = state.clone();
         let node_children = {
-            let node = match self.spatial_nodes.get_mut(node_index.0) {
+            let node = match self.nodes.get_mut(node_index.0) {
                 Some(node) => node,
                 None => return,
             };
 
-            node.update(&mut state, next_coordinate_system_id, scene_properties);
-            node.push_gpu_data(transform_palette, node_index);
+            node.update(
+                &mut state,
+                next_coordinate_system_id,
+                device_pixel_scale,
+                clip_store,
+                resource_cache,
+                gpu_cache,
+                scene_properties,
+                &mut self.clip_chains,
+            );
+
+            node.push_gpu_data(transform_palette);
 
             if node.children.is_empty() {
                 return;
             }
 
             node.prepare_state_for_children(&mut state);
             node.children.clone()
         };
 
         for child_node_index in node_children {
             self.update_node(
                 child_node_index,
                 &mut state,
                 next_coordinate_system_id,
+                device_pixel_scale,
+                clip_store,
+                resource_cache,
+                gpu_cache,
                 transform_palette,
                 scene_properties,
             );
         }
     }
 
     pub fn build_clip_chains(&mut self, screen_rect: &DeviceIntRect) {
         for descriptor in &self.clip_chains_descriptors {
             // A ClipChain is an optional parent (which is another ClipChain) and a list of
-            // SpatialNode clipping nodes. Here we start the ClipChain with a clone of the
+            // ClipScrollNode clipping nodes. Here we start the ClipChain with a clone of the
             // parent's node, if necessary.
             let mut chain = match descriptor.parent {
                 Some(index) => self.clip_chains[index.0].clone(),
                 None => ClipChain::empty(screen_rect),
             };
 
-            // Now we walk through each ClipNode in the vector and extract their ClipChain nodes to
-            // construct the final list.
+            // Now we walk through each ClipScrollNode in the vector of clip nodes and
+            // extract their ClipChain nodes to construct the final list.
             for clip_index in &descriptor.clips {
-                match self.clip_nodes[clip_index.0] {
-                    ClipNode { clip_chain_node: Some(ref node), .. } => {
+                match self.nodes[clip_index.0].node_type {
+                    NodeType::Clip { clip_chain_node: Some(ref node), .. } => {
                         chain.add_node(node.clone());
                     }
-                    ClipNode { .. } => warn!("Found uninitialized clipping ClipNode."),
+                    NodeType::Clip { .. } => warn!("Found uninitialized clipping ClipScrollNode."),
+                    _ => warn!("Tried to create a clip chain with non-clipping node."),
                 };
             }
 
             chain.parent_index = descriptor.parent;
             self.clip_chains[descriptor.index.0] = chain;
         }
     }
 
     pub fn finalize_and_apply_pending_scroll_offsets(&mut self, old_states: ScrollStates) {
-        for node in &mut self.spatial_nodes {
+        for node in &mut self.nodes {
             let external_id = match node.node_type {
-                SpatialNodeType::ScrollFrame(ScrollFrameInfo { external_id: Some(id), ..} ) => id,
+                NodeType::Spatial { kind: SpatialNodeKind::ScrollFrame(ScrollFrameInfo { external_id: Some(id), ..} ), .. } => id,
                 _ => continue,
             };
 
             if let Some(scrolling_state) = old_states.get(&external_id) {
                 node.apply_old_scrolling_state(scrolling_state);
             }
 
             if let Some((offset, clamping)) = self.pending_scroll_offsets.remove(&external_id) {
                 node.set_scroll_origin(&offset, clamping);
             }
         }
     }
 
+    // Generate the next valid TransformIndex for the CST.
+    fn next_transform_index(&mut self) -> TransformIndex {
+        let transform_index = TransformIndex(self.spatial_node_count as u32);
+        self.spatial_node_count += 1;
+        transform_index
+    }
+
     pub fn add_clip_node(
         &mut self,
-        index: ClipNodeIndex,
-        parent_clip_chain_index: ClipChainIndex,
-        spatial_node: SpatialNodeIndex,
+        index: ClipScrollNodeIndex,
+        parent_index: ClipScrollNodeIndex,
         handle: ClipSourcesHandle,
+        pipeline_id: PipelineId,
     )  -> ClipChainIndex {
         let clip_chain_index = self.allocate_clip_chain();
-        let node = ClipNode {
-            parent_clip_chain_index,
-            spatial_node,
-            handle: Some(handle),
+        let transform_index = self.nodes[parent_index.0].transform_index;
+
+        let node_type = NodeType::Clip {
+            handle,
             clip_chain_index,
             clip_chain_node: None,
         };
-        self.push_clip_node(node, index);
+        let node = ClipScrollNode::new(
+            pipeline_id,
+            Some(parent_index),
+            node_type,
+            transform_index,
+        );
+        self.add_node(node, index);
         clip_chain_index
     }
 
     pub fn add_scroll_frame(
         &mut self,
-        index: SpatialNodeIndex,
-        parent_index: SpatialNodeIndex,
+        index: ClipScrollNodeIndex,
+        parent_index: ClipScrollNodeIndex,
         external_id: Option<ExternalScrollId>,
         pipeline_id: PipelineId,
         frame_rect: &LayoutRect,
         content_size: &LayoutSize,
         scroll_sensitivity: ScrollSensitivity,
     ) {
-        let node = SpatialNode::new_scroll_frame(
+        let node = ClipScrollNode::new_scroll_frame(
             pipeline_id,
             parent_index,
             external_id,
             frame_rect,
             content_size,
             scroll_sensitivity,
+            self.next_transform_index(),
         );
-        self.add_spatial_node(node, index);
+        self.add_node(node, index);
     }
 
     pub fn add_reference_frame(
         &mut self,
-        index: SpatialNodeIndex,
-        parent_index: Option<SpatialNodeIndex>,
+        index: ClipScrollNodeIndex,
+        parent_index: Option<ClipScrollNodeIndex>,
         source_transform: Option<PropertyBinding<LayoutTransform>>,
         source_perspective: Option<LayoutTransform>,
         origin_in_parent_reference_frame: LayoutVector2D,
         pipeline_id: PipelineId,
     ) {
-        let node = SpatialNode::new_reference_frame(
+        let node = ClipScrollNode::new_reference_frame(
             parent_index,
             source_transform,
             source_perspective,
             origin_in_parent_reference_frame,
             pipeline_id,
+            self.next_transform_index(),
         );
-        self.add_spatial_node(node, index);
+        self.add_node(node, index);
     }
 
     pub fn add_sticky_frame(
         &mut self,
-        index: SpatialNodeIndex,
-        parent_index: SpatialNodeIndex,
+        index: ClipScrollNodeIndex,
+        parent_index: ClipScrollNodeIndex,
         sticky_frame_info: StickyFrameInfo,
         pipeline_id: PipelineId,
     ) {
-        let node = SpatialNode::new_sticky_frame(
+        let node = ClipScrollNode::new_sticky_frame(
             parent_index,
             sticky_frame_info,
             pipeline_id,
+            self.next_transform_index(),
         );
-        self.add_spatial_node(node, index);
+        self.add_node(node, index);
     }
 
     pub fn add_clip_chain_descriptor(
         &mut self,
         parent: Option<ClipChainIndex>,
-        clips: Vec<ClipNodeIndex>
+        clips: Vec<ClipScrollNodeIndex>
     ) -> ClipChainIndex {
         let index = self.allocate_clip_chain();
         self.clip_chains_descriptors.push(ClipChainDescriptor { index, parent, clips });
         index
     }
 
-    pub fn push_clip_node(&mut self, node: ClipNode, index: ClipNodeIndex) {
-        if index.0 == self.clip_nodes.len() {
-            self.clip_nodes.push(node);
+    pub fn add_node(&mut self, node: ClipScrollNode, index: ClipScrollNodeIndex) {
+        // When the parent node is None this means we are adding the root.
+        if let Some(parent_index) = node.parent {
+            self.nodes[parent_index.0].add_child(index);
+        }
+
+        if index.0 == self.nodes.len() {
+            self.nodes.push(node);
             return;
         }
 
-        if let Some(empty_node) = self.clip_nodes.get_mut(index.0) {
+
+        if let Some(empty_node) = self.nodes.get_mut(index.0) {
             *empty_node = node;
             return
         }
 
-        let length_to_reserve = index.0 + 1 - self.clip_nodes.len();
-        self.clip_nodes.reserve_exact(length_to_reserve);
+        let length_to_reserve = index.0 + 1 - self.nodes.len();
+        self.nodes.reserve_exact(length_to_reserve);
 
         // We would like to use `Vec::resize` here, but the Clone trait is not supported
-        // for ClipNodes. We can fix this either when support is added for something like
-        // `Vec::resize_default`.
-        let length_to_extend = self.clip_nodes.len() .. index.0;
-        self.clip_nodes.extend(length_to_extend.map(|_| ClipNode::empty()));
-        self.clip_nodes.push(node);
-    }
-
-    pub fn add_spatial_node(&mut self, node: SpatialNode, index: SpatialNodeIndex) {
-        // When the parent node is None this means we are adding the root.
-        if let Some(parent_index) = node.parent {
-            self.spatial_nodes[parent_index.0].add_child(index);
-        }
+        // for ClipScrollNodes. We can fix this either by splitting the clip nodes out into
+        // their own tree or when support is added for something like `Vec::resize_default`.
+        let length_to_extend = self.nodes.len() .. index.0;
+        self.nodes.extend(length_to_extend.map(|_| ClipScrollNode::empty()));
 
-        if index.0 == self.spatial_nodes.len() {
-            self.spatial_nodes.push(node);
-            return;
-        }
-
-        if let Some(empty_node) = self.spatial_nodes.get_mut(index.0) {
-            *empty_node = node;
-            return
-        }
-
-        debug_assert!(index.0 > self.spatial_nodes.len() - 1);
-        self.spatial_nodes.resize(index.0, SpatialNode::empty());
-        self.spatial_nodes.push(node);
+        self.nodes.push(node);
     }
 
     pub fn discard_frame_state_for_pipeline(&mut self, pipeline_id: PipelineId) {
         self.pipelines_to_discard.insert(pipeline_id);
     }
 
     fn print_node<T: PrintTreePrinter>(
         &self,
-        index: SpatialNodeIndex,
+        index: ClipScrollNodeIndex,
         pt: &mut T,
         clip_store: &ClipStore
     ) {
-        let node = &self.spatial_nodes[index.0];
+        let node = &self.nodes[index.0];
         match node.node_type {
-            SpatialNodeType::StickyFrame(ref sticky_frame_info) => {
-                pt.new_level(format!("StickyFrame"));
-                pt.add_item(format!("index: {:?}", index));
-                pt.add_item(format!("sticky info: {:?}", sticky_frame_info));
+            NodeType::Spatial { ref kind, .. } => {
+                match *kind {
+                    SpatialNodeKind::StickyFrame(ref sticky_frame_info) => {
+                        pt.new_level(format!("StickyFrame"));
+                        pt.add_item(format!("index: {:?}", index));
+                        pt.add_item(format!("sticky info: {:?}", sticky_frame_info));
+                    }
+                    SpatialNodeKind::ScrollFrame(scrolling_info) => {
+                        pt.new_level(format!("ScrollFrame"));
+                        pt.add_item(format!("index: {:?}", index));
+                        pt.add_item(format!("viewport: {:?}", scrolling_info.viewport_rect));
+                        pt.add_item(format!("scrollable_size: {:?}", scrolling_info.scrollable_size));
+                        pt.add_item(format!("scroll offset: {:?}", scrolling_info.offset));
+                    }
+                    SpatialNodeKind::ReferenceFrame(ref info) => {
+                        pt.new_level(format!("ReferenceFrame {:?}", info.resolved_transform));
+                        pt.add_item(format!("index: {:?}", index));
+                    }
+                }
             }
-            SpatialNodeType::ScrollFrame(scrolling_info) => {
-                pt.new_level(format!("ScrollFrame"));
+            NodeType::Clip { ref handle, .. } => {
+                pt.new_level("Clip".to_owned());
+
                 pt.add_item(format!("index: {:?}", index));
-                pt.add_item(format!("viewport: {:?}", scrolling_info.viewport_rect));
-                pt.add_item(format!("scrollable_size: {:?}", scrolling_info.scrollable_size));
-                pt.add_item(format!("scroll offset: {:?}", scrolling_info.offset));
+                let clips = clip_store.get(handle).clips();
+                pt.new_level(format!("Clip Sources [{}]", clips.len()));
+                for source in clips {
+                    pt.add_item(format!("{:?}", source));
+                }
+                pt.end_level();
             }
-            SpatialNodeType::ReferenceFrame(ref info) => {
-                pt.new_level(format!("ReferenceFrame {:?}", info.resolved_transform));
-                pt.add_item(format!("index: {:?}", index));
-            }
-            SpatialNodeType::Empty => unreachable!("Empty node remaining in ClipScrollTree."),
+            NodeType::Empty => unreachable!("Empty node remaining in ClipScrollTree."),
         }
 
         pt.add_item(format!("world_viewport_transform: {:?}", node.world_viewport_transform));
         pt.add_item(format!("world_content_transform: {:?}", node.world_content_transform));
         pt.add_item(format!("coordinate_system_id: {:?}", node.coordinate_system_id));
 
         for child_index in &node.children {
             self.print_node(*child_index, pt, clip_store);
         }
 
         pt.end_level();
     }
 
     #[allow(dead_code)]
     pub fn print(&self, clip_store: &ClipStore) {
-        if !self.spatial_nodes.is_empty() {
+        if !self.nodes.is_empty() {
             let mut pt = PrintTree::new("clip_scroll tree");
             self.print_with(clip_store, &mut pt);
         }
     }
 
     pub fn print_with<T: PrintTreePrinter>(&self, clip_store: &ClipStore, pt: &mut T) {
-        if !self.spatial_nodes.is_empty() {
+        if !self.nodes.is_empty() {
             self.print_node(self.root_reference_frame_index(), pt, clip_store);
         }
     }
 
     pub fn allocate_clip_chain(&mut self) -> ClipChainIndex {
         debug_assert!(!self.clip_chains.is_empty());
         let new_clip_chain =self.clip_chains[0].clone();
         self.clip_chains.push(new_clip_chain);
--- a/gfx/webrender/src/display_list_flattener.rs
+++ b/gfx/webrender/src/display_list_flattener.rs
@@ -9,17 +9,18 @@ use api::{DevicePixelScale, DeviceUintRe
 use api::{FilterOp, FontInstanceKey, GlyphInstance, GlyphOptions, GlyphRasterSpace, GradientStop};
 use api::{IframeDisplayItem, ImageKey, ImageRendering, ItemRange, LayoutPoint};
 use api::{LayoutPrimitiveInfo, LayoutRect, LayoutSize, LayoutTransform, LayoutVector2D};
 use api::{LineOrientation, LineStyle, LocalClip, NinePatchBorderSource, PipelineId};
 use api::{PropertyBinding, ReferenceFrame, RepeatMode, ScrollFrameDisplayItem, ScrollSensitivity};
 use api::{Shadow, SpecificDisplayItem, StackingContext, StickyFrameDisplayItem, TexelRect};
 use api::{TransformStyle, YuvColorSpace, YuvData};
 use clip::{ClipRegion, ClipSource, ClipSources, ClipStore};
-use clip_scroll_tree::{ClipChainIndex, ClipNodeIndex, ClipScrollTree, SpatialNodeIndex};
+use clip_scroll_node::{NodeType, SpatialNodeKind, StickyFrameInfo};
+use clip_scroll_tree::{ClipChainIndex, ClipScrollNodeIndex, ClipScrollTree};
 use euclid::vec2;
 use frame_builder::{ChasePrimitive, FrameBuilder, FrameBuilderConfig};
 use glyph_rasterizer::FontInstance;
 use gpu_cache::GpuCacheHandle;
 use gpu_types::BrushFlags;
 use hit_test::{HitTestingItem, HitTestingRun};
 use image::simplify_repeated_primitive;
 use internal_types::{FastHashMap, FastHashSet};
@@ -27,68 +28,55 @@ use picture::PictureCompositeMode;
 use prim_store::{BrushClipMaskKind, BrushKind, BrushPrimitive, BrushSegmentDescriptor};
 use prim_store::{EdgeAaSegmentMask, ImageSource};
 use prim_store::{BorderSource, BrushSegment, PictureIndex, PrimitiveContainer, PrimitiveIndex, PrimitiveStore};
 use prim_store::{OpacityBinding, ScrollNodeAndClipChain, TextRunPrimitiveCpu};
 use render_backend::{DocumentView};
 use resource_cache::{FontInstanceMap, ImageRequest};
 use scene::{Scene, ScenePipeline, StackingContextHelpers};
 use scene_builder::{BuiltScene, SceneRequest};
-use spatial_node::{SpatialNodeType, StickyFrameInfo};
 use std::{f32, mem, usize};
 use tiling::{CompositeOps, ScrollbarPrimitive};
 use util::{MaxRect, RectHelpers, recycle_vec};
 
 static DEFAULT_SCROLLBAR_COLOR: ColorF = ColorF {
     r: 0.3,
     g: 0.3,
     b: 0.3,
     a: 0.6,
 };
 
-#[derive(Clone, Copy)]
-pub struct PipelineOffset {
-    pipeline: PipelineId,
-    spatial_offset: usize,
-    clip_offset: usize,
-}
-
 /// A data structure that keeps track of mapping between API ClipIds and the indices used
 /// internally in the ClipScrollTree to avoid having to do HashMap lookups. ClipIdToIndexMapper is
-/// responsible for mapping both ClipId to ClipChainIndex and ClipId to SpatialNodeIndex.  We
+/// responsible for mapping both ClipId to ClipChainIndex and ClipId to ClipScrollNodeIndex.  We
 /// also include two small LRU caches. Currently the caches are small (1 entry), but in the future
 /// we could use uluru here to do something more involved.
 #[derive(Default)]
 pub struct ClipIdToIndexMapper {
     /// A map which converts a ClipId for a clipping node or an API-defined ClipChain into
     /// a ClipChainIndex, which is the index used internally in the ClipScrollTree to
     /// identify ClipChains.
     clip_chain_map: FastHashMap<ClipId, ClipChainIndex>,
 
     /// The last mapped ClipChainIndex, used to avoid having to do lots of consecutive
     /// HashMap lookups.
     cached_clip_chain_index: Option<(ClipId, ClipChainIndex)>,
 
-    /// The offset in the ClipScrollTree's array of SpatialNodes and ClipNodes for a particular
-    /// pipeline.  This is used to convert ClipIds into SpatialNodeIndex or ClipNodeIndex.
-    pipeline_offsets: FastHashMap<PipelineId, PipelineOffset>,
+    /// The offset in the ClipScrollTree's array of ClipScrollNodes for a particular pipeline.
+    /// This is used to convert a ClipId into a ClipScrollNodeIndex.
+    pipeline_offsets: FastHashMap<PipelineId, usize>,
 
     /// The last mapped pipeline offset for this mapper. This is used to avoid having to
     /// consult `pipeline_offsets` repeatedly when flattening the display list.
-    cached_pipeline_offset: Option<PipelineOffset>,
+    cached_pipeline_offset: Option<(PipelineId, usize)>,
 
-    /// The next available pipeline offset for ClipNodeIndex. When we encounter a pipeline
-    /// we will use this value and increment it by the total number of clip nodes in the
+    /// The next available pipeline offset for ClipScrollNodeIndex. When we encounter a pipeline
+    /// we will use this value and increment it by the total number of ClipScrollNodes in the
     /// pipeline's display list.
-    next_available_clip_offset: usize,
-
-    /// The next available pipeline offset for SpatialNodeIndex. When we encounter a pipeline
-    /// we will use this value and increment it by the total number of spatial nodes in the
-    /// pipeline's display list.
-    next_available_spatial_offset: usize,
+    next_available_offset: usize,
 }
 
 impl ClipIdToIndexMapper {
     pub fn add_clip_chain(&mut self, id: ClipId, index: ClipChainIndex) {
         debug_assert!(!self.clip_chain_map.contains_key(&id));
         self.clip_chain_map.insert(id, index);
     }
 
@@ -108,56 +96,49 @@ impl ClipIdToIndexMapper {
     }
 
     pub fn get_clip_chain_index_and_cache_result(&mut self, id: &ClipId) -> ClipChainIndex {
         let index = self.get_clip_chain_index(id);
         self.cached_clip_chain_index = Some((*id, index));
         index
     }
 
+    pub fn map_clip_and_scroll(&mut self, info: &ClipAndScrollInfo) -> ScrollNodeAndClipChain {
+        ScrollNodeAndClipChain::new(
+            self.get_node_index(info.scroll_node_id),
+            self.get_clip_chain_index_and_cache_result(&info.clip_node_id())
+        )
+    }
+
+    pub fn simple_scroll_and_clip_chain(&mut self, id: &ClipId) -> ScrollNodeAndClipChain {
+        self.map_clip_and_scroll(&ClipAndScrollInfo::simple(*id))
+    }
+
     pub fn initialize_for_pipeline(&mut self, pipeline: &ScenePipeline) {
         debug_assert!(!self.pipeline_offsets.contains_key(&pipeline.pipeline_id));
-        self.pipeline_offsets.insert(
-            pipeline.pipeline_id,
-            PipelineOffset {
-                pipeline: pipeline.pipeline_id,
-                spatial_offset: self.next_available_spatial_offset,
-                clip_offset: self.next_available_clip_offset,
-            }
-        );
-
-        self.next_available_clip_offset += pipeline.display_list.total_clip_nodes();
-        self.next_available_spatial_offset += pipeline.display_list.total_spatial_nodes();
+        self.pipeline_offsets.insert(pipeline.pipeline_id, self.next_available_offset);
+        self.next_available_offset += pipeline.display_list.total_clip_ids();
     }
 
-    pub fn get_pipeline_offet<'a>(&'a mut self, id: PipelineId) -> &'a PipelineOffset {
-        match self.cached_pipeline_offset {
-            Some(ref offset) if offset.pipeline == id => offset,
+    pub fn get_node_index(&mut self, id: ClipId) -> ClipScrollNodeIndex {
+        let (index, pipeline_id) = match id {
+            ClipId::Clip(index, pipeline_id) => (index, pipeline_id),
+            ClipId::ClipChain(_) => panic!("Tried to use ClipChain as scroll node."),
+        };
+
+        let pipeline_offset = match self.cached_pipeline_offset {
+            Some((last_used_id, offset)) if last_used_id == pipeline_id => offset,
             _ => {
-                let offset = &self.pipeline_offsets[&id];
-                self.cached_pipeline_offset = Some(*offset);
+                let offset = self.pipeline_offsets[&pipeline_id];
+                self.cached_pipeline_offset = Some((pipeline_id, offset));
                 offset
             }
-        }
-    }
+        };
 
-    pub fn get_clip_node_index(&mut self, id: ClipId) -> ClipNodeIndex {
-        match id {
-            ClipId::Clip(index, pipeline_id) => {
-                let pipeline_offset = self.get_pipeline_offet(pipeline_id);
-                ClipNodeIndex(pipeline_offset.clip_offset + index)
-            }
-            ClipId::Spatial(..) => {
-                // We could theoretically map back to the containing clip node with the current
-                // design, but we will eventually fully separate out clipping from spatial nodes
-                // in the display list. We don't ever need to do this anyway.
-                panic!("Tried to use positioning node as clip node.");
-            }
-            ClipId::ClipChain(_) => panic!("Tried to use ClipChain as scroll node."),
-        }
+        ClipScrollNodeIndex(pipeline_offset + index)
     }
 }
 
 /// A structure that converts a serialized display list into a form that WebRender
 /// can use to later build a frame. This structure produces a FrameBuilder. Public
 /// members are typically those that are destructured into the FrameBuilder.
 pub struct DisplayListFlattener<'a> {
     /// The scene that we are currently flattening.
@@ -174,17 +155,17 @@ pub struct DisplayListFlattener<'a> {
     output_pipelines: &'a FastHashSet<PipelineId>,
 
     /// The data structure that converting between ClipId and the various index
     /// types that the ClipScrollTree uses.
     id_to_index_mapper: ClipIdToIndexMapper,
 
     /// A stack of scroll nodes used during display list processing to properly
     /// parent new scroll nodes.
-    reference_frame_stack: Vec<(ClipId, SpatialNodeIndex)>,
+    reference_frame_stack: Vec<(ClipId, ClipScrollNodeIndex)>,
 
     /// A stack of stacking context properties.
     sc_stack: Vec<FlattenedStackingContext>,
 
     /// A stack of the current pictures.
     picture_stack: Vec<PictureIndex>,
 
     /// A stack of the currently active shadows
@@ -287,22 +268,24 @@ impl<'a> DisplayListFlattener<'a> {
         if items.is_empty() {
             return vec![];
         }
         self.scene.get_display_list_for_pipeline(pipeline_id).get(items).collect()
     }
 
     fn flatten_root(&mut self, pipeline: &'a ScenePipeline, frame_size: &LayoutSize) {
         let pipeline_id = pipeline.pipeline_id;
-        let reference_frame_info = self.simple_scroll_and_clip_chain(
-            &ClipId::root_reference_frame(pipeline_id),
+        let reference_frame_info = self.id_to_index_mapper.simple_scroll_and_clip_chain(
+            &ClipId::root_reference_frame(pipeline_id)
         );
 
         let root_scroll_node = ClipId::root_scroll_node(pipeline_id);
-        let scroll_frame_info = self.simple_scroll_and_clip_chain(&root_scroll_node);
+        let scroll_frame_info = self.id_to_index_mapper.simple_scroll_and_clip_chain(
+            &root_scroll_node,
+        );
 
         self.push_stacking_context(
             pipeline_id,
             CompositeOps::default(),
             TransformStyle::Flat,
             true,
             true,
             root_scroll_node,
@@ -392,17 +375,17 @@ impl<'a> DisplayListFlattener<'a> {
         let sticky_frame_info = StickyFrameInfo::new(
             frame_rect,
             info.margins,
             info.vertical_offset_bounds,
             info.horizontal_offset_bounds,
             info.previously_applied_offset,
         );
 
-        let index = self.get_spatial_node_index_for_clip_id(info.id);
+        let index = self.id_to_index_mapper.get_node_index(info.id);
         self.clip_scroll_tree.add_sticky_frame(
             index,
             clip_and_scroll.scroll_node_id, /* parent id */
             sticky_frame_info,
             info.id.pipeline_id(),
         );
         self.id_to_index_mapper.map_to_parent_clip_chain(info.id, parent_id);
     }
@@ -419,17 +402,17 @@ impl<'a> DisplayListFlattener<'a> {
         let clip_region = ClipRegion::create_for_clip_node(
             *item.clip_rect(),
             complex_clips,
             info.image_mask,
             reference_frame_relative_offset,
         );
         // Just use clip rectangle as the frame rect for this scroll frame.
         // This is useful when calculating scroll extents for the
-        // SpatialNode::scroll(..) API as well as for properly setting sticky
+        // ClipScrollNode::scroll(..) API as well as for properly setting sticky
         // positioning offsets.
         let frame_rect = item.clip_rect().translate(reference_frame_relative_offset);
         let content_rect = item.rect().translate(reference_frame_relative_offset);
 
         debug_assert!(info.clip_id != info.scroll_frame_id);
 
         self.add_clip_node(info.clip_id, clip_and_scroll_ids.scroll_node_id, clip_region);
 
@@ -568,17 +551,17 @@ impl<'a> DisplayListFlattener<'a> {
 
     fn flatten_item<'b>(
         &'b mut self,
         item: DisplayItemRef<'a, 'b>,
         pipeline_id: PipelineId,
         reference_frame_relative_offset: LayoutVector2D,
     ) -> Option<BuiltDisplayListIter<'a>> {
         let clip_and_scroll_ids = item.clip_and_scroll();
-        let clip_and_scroll = self.map_clip_and_scroll(&clip_and_scroll_ids);
+        let clip_and_scroll = self.id_to_index_mapper.map_clip_and_scroll(&clip_and_scroll_ids);
 
         let prim_info = item.get_layout_primitive_info(&reference_frame_relative_offset);
         match *item.item() {
             SpecificDisplayItem::Image(ref info) => {
                 self.add_image(
                     clip_and_scroll,
                     &prim_info,
                     info.stretch_size,
@@ -729,17 +712,17 @@ impl<'a> DisplayListFlattener<'a> {
                     info.image_mask,
                     &reference_frame_relative_offset,
                 );
                 self.add_clip_node(info.id, clip_and_scroll_ids.scroll_node_id, clip_region);
             }
             SpecificDisplayItem::ClipChain(ref info) => {
                 let items = self.get_clip_chain_items(pipeline_id, item.clip_chain_items())
                                 .iter()
-                                .map(|id| self.id_to_index_mapper.get_clip_node_index(*id))
+                                .map(|id| self.id_to_index_mapper.get_node_index(*id))
                                 .collect();
                 let parent = info.parent.map(|id|
                      self.id_to_index_mapper.get_clip_chain_index(&ClipId::ClipChain(id))
                 );
                 let clip_chain_index =
                     self.clip_scroll_tree.add_clip_chain_descriptor(parent, items);
                 self.id_to_index_mapper.add_clip_chain(ClipId::ClipChain(info.id), clip_chain_index);
             },
@@ -895,26 +878,26 @@ impl<'a> DisplayListFlattener<'a> {
 
     pub fn push_stacking_context(
         &mut self,
         pipeline_id: PipelineId,
         composite_ops: CompositeOps,
         transform_style: TransformStyle,
         is_backface_visible: bool,
         is_pipeline_root: bool,
-        spatial_node: ClipId,
+        positioning_node: ClipId,
         clipping_node: Option<ClipId>,
         glyph_raster_space: GlyphRasterSpace,
     ) {
         let clip_chain_id = match clipping_node {
             Some(ref clipping_node) => self.id_to_index_mapper.get_clip_chain_index(clipping_node),
             None => ClipChainIndex(0), // This means no clipping.
         };
         let clip_and_scroll = ScrollNodeAndClipChain::new(
-            self.get_spatial_node_index_for_clip_id(spatial_node),
+            self.id_to_index_mapper.get_node_index(positioning_node),
             clip_chain_id
         );
 
         // Construct the necessary set of Picture primitives
         // to draw this stacking context.
         let current_reference_frame_index = self.current_reference_frame_index();
 
         // An arbitrary large clip rect. For now, we don't
@@ -1203,19 +1186,19 @@ impl<'a> DisplayListFlattener<'a> {
     pub fn push_reference_frame(
         &mut self,
         reference_frame_id: ClipId,
         parent_id: Option<ClipId>,
         pipeline_id: PipelineId,
         source_transform: Option<PropertyBinding<LayoutTransform>>,
         source_perspective: Option<LayoutTransform>,
         origin_in_parent_reference_frame: LayoutVector2D,
-    ) -> SpatialNodeIndex {
-        let index = self.get_spatial_node_index_for_clip_id(reference_frame_id);
-        let parent_index = parent_id.map(|id| self.get_spatial_node_index_for_clip_id(id));
+    ) -> ClipScrollNodeIndex {
+        let index = self.id_to_index_mapper.get_node_index(reference_frame_id);
+        let parent_index = parent_id.map(|id| self.id_to_index_mapper.get_node_index(id));
         self.clip_scroll_tree.add_reference_frame(
             index,
             parent_index,
             source_transform,
             source_perspective,
             origin_in_parent_reference_frame,
             pipeline_id,
         );
@@ -1224,29 +1207,29 @@ impl<'a> DisplayListFlattener<'a> {
         match parent_id {
             Some(ref parent_id) =>
                 self.id_to_index_mapper.map_to_parent_clip_chain(reference_frame_id, parent_id),
             _ => self.id_to_index_mapper.add_clip_chain(reference_frame_id, ClipChainIndex(0)),
         }
         index
     }
 
-    pub fn current_reference_frame_index(&self) -> SpatialNodeIndex {
+    pub fn current_reference_frame_index(&self) -> ClipScrollNodeIndex {
         self.reference_frame_stack.last().unwrap().1
     }
 
     pub fn setup_viewport_offset(
         &mut self,
         inner_rect: DeviceUintRect,
         device_pixel_scale: DevicePixelScale,
     ) {
         let viewport_offset = (inner_rect.origin.to_vector().to_f32() / device_pixel_scale).round();
         let root_id = self.clip_scroll_tree.root_reference_frame_index();
-        let root_node = &mut self.clip_scroll_tree.spatial_nodes[root_id.0];
-        if let SpatialNodeType::ReferenceFrame(ref mut info) = root_node.node_type {
+        let root_node = &mut self.clip_scroll_tree.nodes[root_id.0];
+        if let NodeType::Spatial { kind: SpatialNodeKind::ReferenceFrame(ref mut info), .. } = root_node.node_type {
             info.resolved_transform =
                 LayoutVector2D::new(viewport_offset.x, viewport_offset.y).into();
         }
     }
 
     pub fn push_root(
         &mut self,
         pipeline_id: PipelineId,
@@ -1273,48 +1256,45 @@ impl<'a> DisplayListFlattener<'a> {
         );
     }
 
     pub fn add_clip_node(
         &mut self,
         new_node_id: ClipId,
         parent_id: ClipId,
         clip_region: ClipRegion,
-    ) {
+    ) -> ClipScrollNodeIndex {
         let clip_sources = ClipSources::from(clip_region);
         let handle = self.clip_store.insert(clip_sources);
 
-        let node_index = self.id_to_index_mapper.get_clip_node_index(new_node_id);
-        let parent_clip_chain_index =
-            self.id_to_index_mapper.get_clip_chain_index_and_cache_result(&parent_id);
-        let spatial_node = self.get_spatial_node_index_for_clip_id(parent_id);
+        let node_index = self.id_to_index_mapper.get_node_index(new_node_id);
         let clip_chain_index = self.clip_scroll_tree.add_clip_node(
             node_index,
-            parent_clip_chain_index,
-            spatial_node,
+            self.id_to_index_mapper.get_node_index(parent_id),
             handle,
+            new_node_id.pipeline_id(),
         );
         self.id_to_index_mapper.add_clip_chain(new_node_id, clip_chain_index);
+        node_index
     }
 
     pub fn add_scroll_frame(
         &mut self,
         new_node_id: ClipId,
         parent_id: ClipId,
         external_id: Option<ExternalScrollId>,
         pipeline_id: PipelineId,
         frame_rect: &LayoutRect,
         content_size: &LayoutSize,
         scroll_sensitivity: ScrollSensitivity,
-    ) -> SpatialNodeIndex {
-        let node_index = self.get_spatial_node_index_for_clip_id(new_node_id);
-        let parent_node_index = self.get_spatial_node_index_for_clip_id(parent_id);
+    ) -> ClipScrollNodeIndex {
+        let node_index = self.id_to_index_mapper.get_node_index(new_node_id);
         self.clip_scroll_tree.add_scroll_frame(
             node_index,
-            parent_node_index,
+            self.id_to_index_mapper.get_node_index(parent_id),
             external_id,
             pipeline_id,
             frame_rect,
             content_size,
             scroll_sensitivity,
         );
         self.id_to_index_mapper.map_to_parent_clip_chain(new_node_id, &parent_id);
         node_index
@@ -1948,41 +1928,16 @@ impl<'a> DisplayListFlattener<'a> {
 
         self.add_primitive(
             clip_and_scroll,
             info,
             Vec::new(),
             PrimitiveContainer::Brush(prim),
         );
     }
-
-    pub fn map_clip_and_scroll(&mut self, info: &ClipAndScrollInfo) -> ScrollNodeAndClipChain {
-        ScrollNodeAndClipChain::new(
-            self.get_spatial_node_index_for_clip_id(info.scroll_node_id),
-            self.id_to_index_mapper.get_clip_chain_index_and_cache_result(&info.clip_node_id())
-        )
-    }
-
-    pub fn simple_scroll_and_clip_chain(&mut self, id: &ClipId) -> ScrollNodeAndClipChain {
-        self.map_clip_and_scroll(&ClipAndScrollInfo::simple(*id))
-    }
-
-    pub fn get_spatial_node_index_for_clip_id(&mut self, id: ClipId,) -> SpatialNodeIndex {
-        match id {
-            ClipId::Spatial(index, pipeline_id) => {
-                let pipeline_offset = self.id_to_index_mapper.get_pipeline_offet(pipeline_id);
-                SpatialNodeIndex(pipeline_offset.spatial_offset + index)
-            }
-            ClipId::Clip(..) => {
-                let clip_node_index = self.id_to_index_mapper.get_clip_node_index(id);
-                self.clip_scroll_tree.clip_nodes[clip_node_index.0].spatial_node
-            }
-            ClipId::ClipChain(_) => panic!("Tried to use ClipChain as scroll node."),
-        }
-    }
 }
 
 pub fn build_scene(config: &FrameBuilderConfig, request: SceneRequest) -> BuiltScene {
 
     let mut clip_scroll_tree = ClipScrollTree::new();
     let mut new_scene = Scene::new();
 
     let frame_builder = DisplayListFlattener::create_frame_builder(
@@ -2027,9 +1982,9 @@ struct FlattenedStackingContext {
 
     /// If Some(..), this stacking context establishes a new
     /// 3d rendering context, and the value is the picture
     // index of the 3d context container.
     rendering_context_3d_pic_index: Option<PictureIndex>,
 }
 
 #[derive(Debug)]
-pub struct ScrollbarInfo(pub SpatialNodeIndex, pub LayoutRect);
+pub struct ScrollbarInfo(pub ClipScrollNodeIndex, pub LayoutRect);
--- a/gfx/webrender/src/frame_builder.rs
+++ b/gfx/webrender/src/frame_builder.rs
@@ -1,30 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use api::{BuiltDisplayList, ColorF, DeviceIntPoint, DeviceIntRect, DevicePixelScale};
 use api::{DeviceUintPoint, DeviceUintRect, DeviceUintSize, DocumentLayer, FontRenderMode};
 use api::{LayoutPoint, LayoutRect, LayoutSize, PipelineId, WorldPoint};
 use clip::{ClipChain, ClipStore};
-use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
+use clip_scroll_node::{ClipScrollNode};
+use clip_scroll_tree::{ClipScrollNodeIndex, ClipScrollTree};
 use display_list_flattener::{DisplayListFlattener};
 use gpu_cache::GpuCache;
-use gpu_types::{PrimitiveHeaders, TransformData, TransformIndex, UvRectKind};
+use gpu_types::{PrimitiveHeaders, TransformData, UvRectKind};
 use hit_test::{HitTester, HitTestingRun};
 use internal_types::{FastHashMap};
 use picture::PictureSurface;
 use prim_store::{PrimitiveIndex, PrimitiveRun, PrimitiveStore};
 use profiler::{FrameProfileCounters, GpuCacheProfileCounters, TextureCacheProfileCounters};
 use render_backend::FrameId;
 use render_task::{RenderTask, RenderTaskId, RenderTaskLocation, RenderTaskTree};
 use resource_cache::{ResourceCache};
 use scene::{ScenePipeline, SceneProperties};
-use spatial_node::SpatialNode;
 use std::{mem, f32};
 use std::sync::Arc;
 use tiling::{Frame, RenderPass, RenderPassKind, RenderTargetContext};
 use tiling::{ScrollbarPrimitive, SpecialRenderPasses};
 use util::{self, WorldToLayoutFastTransform};
 
 
 #[derive(Clone, Copy, Debug, PartialEq)]
@@ -83,17 +83,17 @@ pub struct FrameBuildingState<'a> {
     pub resource_cache: &'a mut ResourceCache,
     pub gpu_cache: &'a mut GpuCache,
     pub special_render_passes: &'a mut SpecialRenderPasses,
 }
 
 pub struct PictureContext<'a> {
     pub pipeline_id: PipelineId,
     pub prim_runs: Vec<PrimitiveRun>,
-    pub original_reference_frame_index: Option<SpatialNodeIndex>,
+    pub original_reference_frame_index: Option<ClipScrollNodeIndex>,
     pub display_list: &'a BuiltDisplayList,
     pub inv_world_transform: Option<WorldToLayoutFastTransform>,
     pub apply_local_clip_rect: bool,
     pub inflation_factor: f32,
     pub allow_subpixel_aa: bool,
 }
 
 pub struct PictureState {
@@ -109,33 +109,30 @@ impl PictureState {
             has_non_root_coord_system: false,
             local_rect_changed: false,
         }
     }
 }
 
 pub struct PrimitiveRunContext<'a> {
     pub clip_chain: &'a ClipChain,
-    pub scroll_node: &'a SpatialNode,
-    pub transform_index: TransformIndex,
+    pub scroll_node: &'a ClipScrollNode,
     pub local_clip_rect: LayoutRect,
 }
 
 impl<'a> PrimitiveRunContext<'a> {
     pub fn new(
         clip_chain: &'a ClipChain,
-        scroll_node: &'a SpatialNode,
-        transform_index: TransformIndex,
+        scroll_node: &'a ClipScrollNode,
         local_clip_rect: LayoutRect,
     ) -> Self {
         PrimitiveRunContext {
             clip_chain,
             scroll_node,
             local_clip_rect,
-            transform_index,
         }
     }
 }
 
 impl FrameBuilder {
     pub fn empty() -> Self {
         FrameBuilder {
             hit_testing_runs: Vec::new(),
@@ -193,21 +190,21 @@ impl FrameBuilder {
     ) -> Option<RenderTaskId> {
         profile_scope!("cull");
 
         if self.prim_store.pictures.is_empty() {
             return None
         }
 
         // The root picture is always the first one added.
-        let root_spatial_node =
-            &clip_scroll_tree.spatial_nodes[clip_scroll_tree.root_reference_frame_index().0];
+        let root_clip_scroll_node =
+            &clip_scroll_tree.nodes[clip_scroll_tree.root_reference_frame_index().0];
 
         let display_list = &pipelines
-            .get(&root_spatial_node.pipeline_id)
+            .get(&root_clip_scroll_node.pipeline_id)
             .expect("No display list?")
             .display_list;
 
         const MAX_CLIP_COORD: f32 = 1.0e9;
 
         let frame_context = FrameBuildingContext {
             scene_id: self.scene_id,
             device_pixel_scale,
@@ -227,17 +224,17 @@ impl FrameBuilder {
             profile_counters,
             clip_store: &mut self.clip_store,
             resource_cache,
             gpu_cache,
             special_render_passes,
         };
 
         let pic_context = PictureContext {
-            pipeline_id: root_spatial_node.pipeline_id,
+            pipeline_id: root_clip_scroll_node.pipeline_id,
             prim_runs: mem::replace(&mut self.prim_store.pictures[0].runs, Vec::new()),
             original_reference_frame_index: None,
             display_list,
             inv_world_transform: None,
             apply_local_clip_rect: true,
             inflation_factor: 0.0,
             allow_subpixel_aa: true,
         };
@@ -268,17 +265,17 @@ impl FrameBuilder {
         Some(render_task_id)
     }
 
     fn update_scroll_bars(&mut self, clip_scroll_tree: &ClipScrollTree, gpu_cache: &mut GpuCache) {
         static SCROLLBAR_PADDING: f32 = 8.0;
 
         for scrollbar_prim in &self.scrollbar_prims {
             let metadata = &mut self.prim_store.cpu_metadata[scrollbar_prim.prim_index.0];
-            let scroll_frame = &clip_scroll_tree.spatial_nodes[scrollbar_prim.scroll_frame_index.0];
+            let scroll_frame = &clip_scroll_tree.nodes[scrollbar_prim.scroll_frame_index.0];
 
             // Invalidate what's in the cache so it will get rebuilt.
             gpu_cache.invalidate(&metadata.gpu_location);
 
             let scrollable_distance = scroll_frame.scrollable_size().height;
             if scrollable_distance <= 0.0 {
                 metadata.local_clip_rect.size = LayoutSize::zero();
                 continue;
--- a/gfx/webrender/src/gpu_types.rs
+++ b/gfx/webrender/src/gpu_types.rs
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use api::{DevicePoint, DeviceSize, DeviceRect, LayoutRect, LayoutToWorldTransform};
 use api::{PremultipliedColorF, WorldToLayoutTransform};
+use clip_scroll_tree::TransformIndex;
 use gpu_cache::{GpuCacheAddress, GpuDataRequest};
 use prim_store::{EdgeAaSegmentMask};
 use render_task::RenderTaskAddress;
 use util::{MatrixHelpers, TransformedRectKind};
 
 // Contains type that must exactly match the same structures declared in GLSL.
 
 #[derive(Copy, Clone, Debug)]
@@ -394,21 +395,16 @@ pub struct TransformMetadata {
 //           the future, the transform palette will support
 //           specifying a coordinate system that the transform
 //           should be relative to.
 pub struct TransformPalette {
     pub transforms: Vec<TransformData>,
     metadata: Vec<TransformMetadata>,
 }
 
-#[derive(Copy, Debug, Clone, PartialEq)]
-#[cfg_attr(feature = "capture", derive(Serialize))]
-#[cfg_attr(feature = "replay", derive(Deserialize))]
-pub struct TransformIndex(pub u32);
-
 impl TransformPalette {
     pub fn new(spatial_node_count: usize) -> TransformPalette {
         TransformPalette {
             transforms: Vec::with_capacity(spatial_node_count),
             metadata: Vec::with_capacity(spatial_node_count),
         }
     }
 
--- a/gfx/webrender/src/hit_test.rs
+++ b/gfx/webrender/src/hit_test.rs
@@ -1,53 +1,48 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use api::{BorderRadius, ClipMode, HitTestFlags, HitTestItem, HitTestResult, ItemTag, LayoutPoint};
 use api::{LayoutPrimitiveInfo, LayoutRect, PipelineId, WorldPoint};
 use clip::{ClipSource, ClipStore, rounded_rectangle_contains_point};
-use clip_node::ClipNode;
-use clip_scroll_tree::{ClipChainIndex, ClipNodeIndex, SpatialNodeIndex, ClipScrollTree};
+use clip_scroll_node::{ClipScrollNode, NodeType};
+use clip_scroll_tree::{ClipChainIndex, ClipScrollNodeIndex, ClipScrollTree};
 use internal_types::FastHashMap;
 use prim_store::ScrollNodeAndClipChain;
 use util::LayoutToWorldFastTransform;
 
 /// A copy of important clip scroll node data to use during hit testing. This a copy of
 /// data from the ClipScrollTree that will persist as a new frame is under construction,
 /// allowing hit tests consistent with the currently rendered frame.
-pub struct HitTestSpatialNode {
+pub struct HitTestClipScrollNode {
     /// The pipeline id of this node.
     pipeline_id: PipelineId,
 
+    /// A particular point must be inside all of these regions to be considered clipped in
+    /// for the purposes of a hit test.
+    regions: Vec<HitTestRegion>,
+
     /// World transform for content transformed by this node.
     world_content_transform: LayoutToWorldFastTransform,
 
     /// World viewport transform for content transformed by this node.
     world_viewport_transform: LayoutToWorldFastTransform,
 }
 
-pub struct HitTestClipNode {
-    /// The positioning node for this clip node.
-    spatial_node: SpatialNodeIndex,
-
-    /// A particular point must be inside all of these regions to be considered clipped in
-    /// for the purposes of a hit test.
-    regions: Vec<HitTestRegion>,
-}
-
 /// A description of a clip chain in the HitTester. This is used to describe
 /// hierarchical clip scroll nodes as well as ClipChains, so that they can be
 /// handled the same way during hit testing. Once we represent all ClipChains
 /// using ClipChainDescriptors, we can get rid of this and just use the
 /// ClipChainDescriptor here.
 #[derive(Clone)]
 struct HitTestClipChainDescriptor {
     parent: Option<ClipChainIndex>,
-    clips: Vec<ClipNodeIndex>,
+    clips: Vec<ClipScrollNodeIndex>,
 }
 
 impl HitTestClipChainDescriptor {
     fn empty() -> HitTestClipChainDescriptor {
         HitTestClipChainDescriptor {
             parent: None,
             clips: Vec::new(),
         }
@@ -93,79 +88,69 @@ impl HitTestRegion {
             HitTestRegion::RoundedRectangle(rect, radii, ClipMode::ClipOut) =>
                 !rounded_rectangle_contains_point(point, &rect, &radii),
         }
     }
 }
 
 pub struct HitTester {
     runs: Vec<HitTestingRun>,
-    spatial_nodes: Vec<HitTestSpatialNode>,
-    clip_nodes: Vec<HitTestClipNode>,
+    nodes: Vec<HitTestClipScrollNode>,
     clip_chains: Vec<HitTestClipChainDescriptor>,
-    pipeline_root_nodes: FastHashMap<PipelineId, SpatialNodeIndex>,
+    pipeline_root_nodes: FastHashMap<PipelineId, ClipScrollNodeIndex>,
 }
 
 impl HitTester {
     pub fn new(
         runs: &Vec<HitTestingRun>,
         clip_scroll_tree: &ClipScrollTree,
         clip_store: &ClipStore
     ) -> HitTester {
         let mut hit_tester = HitTester {
             runs: runs.clone(),
-            spatial_nodes: Vec::new(),
-            clip_nodes: Vec::new(),
+            nodes: Vec::new(),
             clip_chains: Vec::new(),
             pipeline_root_nodes: FastHashMap::default(),
         };
         hit_tester.read_clip_scroll_tree(clip_scroll_tree, clip_store);
         hit_tester
     }
 
     fn read_clip_scroll_tree(
         &mut self,
         clip_scroll_tree: &ClipScrollTree,
         clip_store: &ClipStore
     ) {
-        self.spatial_nodes.clear();
+        self.nodes.clear();
         self.clip_chains.clear();
         self.clip_chains.resize(
             clip_scroll_tree.clip_chains.len(),
             HitTestClipChainDescriptor::empty()
         );
 
-        for (index, node) in clip_scroll_tree.spatial_nodes.iter().enumerate() {
-            let index = SpatialNodeIndex(index);
+        for (index, node) in clip_scroll_tree.nodes.iter().enumerate() {
+            let index = ClipScrollNodeIndex(index);
 
             // If we haven't already seen a node for this pipeline, record this one as the root
             // node.
             self.pipeline_root_nodes.entry(node.pipeline_id).or_insert(index);
 
-            self.spatial_nodes.push(HitTestSpatialNode {
+            self.nodes.push(HitTestClipScrollNode {
                 pipeline_id: node.pipeline_id,
+                regions: get_regions_for_clip_scroll_node(node, clip_store),
                 world_content_transform: node.world_content_transform,
                 world_viewport_transform: node.world_viewport_transform,
             });
-        }
 
-        for (index, node) in clip_scroll_tree.clip_nodes.iter().enumerate() {
-            let regions = match get_regions_for_clip_node(node, clip_store) {
-                Some(regions) => regions,
-                None => continue,
-            };
-            self.clip_nodes.push(HitTestClipNode {
-                spatial_node: node.spatial_node,
-                regions,
-            });
-
-             let clip_chain = self.clip_chains.get_mut(node.clip_chain_index.0).unwrap();
-             clip_chain.parent =
-                 clip_scroll_tree.get_clip_chain(node.clip_chain_index).parent_index;
-             clip_chain.clips = vec![ClipNodeIndex(index)];
+            if let NodeType::Clip { clip_chain_index, .. } = node.node_type {
+              let clip_chain = self.clip_chains.get_mut(clip_chain_index.0).unwrap();
+              clip_chain.parent =
+                  clip_scroll_tree.get_clip_chain(clip_chain_index).parent_index;
+              clip_chain.clips = vec![index];
+            }
         }
 
         for descriptor in &clip_scroll_tree.clip_chains_descriptors {
             let clip_chain = self.clip_chains.get_mut(descriptor.index.0).unwrap();
             clip_chain.parent = clip_scroll_tree.get_clip_chain(descriptor.index).parent_index;
             clip_chain.clips = descriptor.clips.clone();
         }
     }
@@ -187,38 +172,38 @@ impl HitTester {
         };
 
         if !parent_clipped_in {
             test.set_in_clip_chain_cache(clip_chain_index, ClippedIn::NotClippedIn);
             return false;
         }
 
         for clip_node_index in &descriptor.clips {
-            if !self.is_point_clipped_in_for_clip_node(point, *clip_node_index, test) {
+            if !self.is_point_clipped_in_for_node(point, *clip_node_index, test) {
                 test.set_in_clip_chain_cache(clip_chain_index, ClippedIn::NotClippedIn);
                 return false;
             }
         }
 
         test.set_in_clip_chain_cache(clip_chain_index, ClippedIn::ClippedIn);
         true
     }
 
-    fn is_point_clipped_in_for_clip_node(
+    fn is_point_clipped_in_for_node(
         &self,
         point: WorldPoint,
-        node_index: ClipNodeIndex,
+        node_index: ClipScrollNodeIndex,
         test: &mut HitTest
     ) -> bool {
         if let Some(clipped_in) = test.node_cache.get(&node_index) {
             return *clipped_in == ClippedIn::ClippedIn;
         }
 
-        let node = &self.clip_nodes[node_index.0];
-        let transform = self.spatial_nodes[node.spatial_node.0].world_viewport_transform;
+        let node = &self.nodes[node_index.0];
+        let transform = node.world_viewport_transform;
         let transformed_point = match transform.inverse() {
             Some(inverted) => inverted.transform_point2d(&point),
             None => {
                 test.node_cache.insert(node_index, ClippedIn::NotClippedIn);
                 return false;
             }
         };
 
@@ -228,22 +213,22 @@ impl HitTester {
                 return false;
             }
         }
 
         test.node_cache.insert(node_index, ClippedIn::ClippedIn);
         true
     }
 
-    pub fn find_node_under_point(&self, mut test: HitTest) -> Option<SpatialNodeIndex> {
+    pub fn find_node_under_point(&self, mut test: HitTest) -> Option<ClipScrollNodeIndex> {
         let point = test.get_absolute_point(self);
 
         for &HitTestingRun(ref items, ref clip_and_scroll) in self.runs.iter().rev() {
             let scroll_node_id = clip_and_scroll.scroll_node_id;
-            let scroll_node = &self.spatial_nodes[scroll_node_id.0];
+            let scroll_node = &self.nodes[scroll_node_id.0];
             let transform = scroll_node.world_content_transform;
             let point_in_layer = match transform.inverse() {
                 Some(inverted) => inverted.transform_point2d(&point),
                 None => continue,
             };
 
             let mut clipped_in = false;
             for item in items.iter().rev() {
@@ -267,17 +252,17 @@ impl HitTester {
     }
 
     pub fn hit_test(&self, mut test: HitTest) -> HitTestResult {
         let point = test.get_absolute_point(self);
 
         let mut result = HitTestResult::default();
         for &HitTestingRun(ref items, ref clip_and_scroll) in self.runs.iter().rev() {
             let scroll_node_id = clip_and_scroll.scroll_node_id;
-            let scroll_node = &self.spatial_nodes[scroll_node_id.0];
+            let scroll_node = &self.nodes[scroll_node_id.0];
             let pipeline_id = scroll_node.pipeline_id;
             match (test.pipeline_id, pipeline_id) {
                 (Some(id), node_id) if node_id != id => continue,
                 _ => {},
             }
 
             let transform = scroll_node.world_content_transform;
             let mut facing_backwards: Option<bool> = None;  // will be computed on first use
@@ -306,17 +291,17 @@ impl HitTester {
                         continue;
                     }
                 }
 
                 // We need to calculate the position of the test point relative to the origin of
                 // the pipeline of the hit item. If we cannot get a transformed point, we are
                 // in a situation with an uninvertible transformation so we should just skip this
                 // result.
-                let root_node = &self.spatial_nodes[self.pipeline_root_nodes[&pipeline_id].0];
+                let root_node = &self.nodes[self.pipeline_root_nodes[&pipeline_id].0];
                 let point_in_viewport = match root_node.world_viewport_transform.inverse() {
                     Some(inverted) => inverted.transform_point2d(&point),
                     None => continue,
                 };
 
                 result.items.push(HitTestItem {
                     pipeline: pipeline_id,
                     tag: item.tag,
@@ -328,59 +313,55 @@ impl HitTester {
                 }
             }
         }
 
         result.items.dedup();
         result
     }
 
-    pub fn get_pipeline_root(&self, pipeline_id: PipelineId) -> &HitTestSpatialNode {
-        &self.spatial_nodes[self.pipeline_root_nodes[&pipeline_id].0]
+    pub fn get_pipeline_root(&self, pipeline_id: PipelineId) -> &HitTestClipScrollNode {
+        &self.nodes[self.pipeline_root_nodes[&pipeline_id].0]
     }
 }
 
-fn get_regions_for_clip_node(
-    node: &ClipNode,
+fn get_regions_for_clip_scroll_node(
+    node: &ClipScrollNode,
     clip_store: &ClipStore
-) -> Option<Vec<HitTestRegion>> {
-    let handle = match node.handle.as_ref() {
-        Some(handle) => handle,
-        None => {
-            warn!("Encountered an empty clip node unexpectedly.");
-            return None;
-        }
+) -> Vec<HitTestRegion> {
+    let clips = match node.node_type {
+        NodeType::Clip{ ref handle, .. } => clip_store.get(handle).clips(),
+        _ => return Vec::new(),
     };
 
-    let clips = clip_store.get(handle).clips();
-    Some(clips.iter().map(|source| {
+    clips.iter().map(|source| {
         match source.0 {
             ClipSource::Rectangle(ref rect, mode) => HitTestRegion::Rectangle(*rect, mode),
             ClipSource::RoundedRectangle(ref rect, ref radii, ref mode) =>
                 HitTestRegion::RoundedRectangle(*rect, *radii, *mode),
             ClipSource::Image(ref mask) => HitTestRegion::Rectangle(mask.rect, ClipMode::Clip),
             ClipSource::LineDecoration(_) |
             ClipSource::BoxShadow(_) => {
                 unreachable!("Didn't expect to hit test against BorderCorner / BoxShadow / LineDecoration");
             }
         }
-    }).collect())
+    }).collect()
 }
 
 #[derive(Clone, Copy, PartialEq)]
 enum ClippedIn {
     ClippedIn,
     NotClippedIn,
 }
 
 pub struct HitTest {
     pipeline_id: Option<PipelineId>,
     point: WorldPoint,
     flags: HitTestFlags,
-    node_cache: FastHashMap<ClipNodeIndex, ClippedIn>,
+    node_cache: FastHashMap<ClipScrollNodeIndex, ClippedIn>,
     clip_chain_cache: Vec<Option<ClippedIn>>,
 }
 
 impl HitTest {
     pub fn new(
         pipeline_id: Option<PipelineId>,
         point: WorldPoint,
         flags: HitTestFlags,
--- a/gfx/webrender/src/lib.rs
+++ b/gfx/webrender/src/lib.rs
@@ -55,17 +55,17 @@ extern crate serde;
 extern crate thread_profiler;
 
 mod batch;
 mod border;
 mod box_shadow;
 #[cfg(any(feature = "capture", feature = "replay"))]
 mod capture;
 mod clip;
-mod clip_node;
+mod clip_scroll_node;
 mod clip_scroll_tree;
 mod debug_colors;
 #[cfg(feature = "debug_renderer")]
 mod debug_font_data;
 #[cfg(feature = "debug_renderer")]
 mod debug_render;
 #[cfg(feature = "debugger")]
 mod debug_server;
@@ -93,17 +93,16 @@ mod record;
 mod render_backend;
 mod render_task;
 mod renderer;
 mod resource_cache;
 mod scene;
 mod scene_builder;
 mod segment;
 mod shade;
-mod spatial_node;
 mod texture_allocator;
 mod texture_cache;
 mod tiling;
 mod util;
 
 mod shader_source {
     include!(concat!(env!("OUT_DIR"), "/shaders.rs"));
 }
--- a/gfx/webrender/src/picture.rs
+++ b/gfx/webrender/src/picture.rs
@@ -1,18 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use api::{DeviceRect, FilterOp, MixBlendMode, PipelineId, PremultipliedColorF};
 use api::{DeviceIntRect, DeviceIntSize, DevicePoint, LayoutPoint, LayoutRect};
 use api::{DevicePixelScale, PictureIntPoint, PictureIntRect, PictureIntSize};
 use box_shadow::{BLUR_SAMPLE_SCALE};
-use spatial_node::SpatialNode;
-use clip_scroll_tree::SpatialNodeIndex;
+use clip_scroll_node::ClipScrollNode;
+use clip_scroll_tree::ClipScrollNodeIndex;
 use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureState, PrimitiveRunContext};
 use gpu_cache::{GpuCacheHandle};
 use gpu_types::UvRectKind;
 use prim_store::{PrimitiveIndex, PrimitiveRun, PrimitiveRunLocalRect};
 use prim_store::{PrimitiveMetadata, ScrollNodeAndClipChain};
 use render_task::{ClearMode, RenderTask, RenderTaskCacheEntryHandle};
 use render_task::{RenderTaskCacheKey, RenderTaskCacheKeyKind, RenderTaskId, RenderTaskLocation};
 use scene::{FilterOpHelpers, SceneProperties};
@@ -145,17 +145,17 @@ pub struct PicturePrimitive {
     pub is_in_3d_context: bool,
     // If requested as a frame output (for rendering
     // pages to a texture), this is the pipeline this
     // picture is the root of.
     pub frame_output_pipeline_id: Option<PipelineId>,
     // The original reference frame ID for this picture.
     // It is only different if this is part of a 3D
     // rendering context.
-    pub reference_frame_index: SpatialNodeIndex,
+    pub reference_frame_index: ClipScrollNodeIndex,
     pub real_local_rect: LayoutRect,
     // An optional cache handle for storing extra data
     // in the GPU cache, depending on the type of
     // picture.
     pub extra_gpu_data_handle: GpuCacheHandle,
 
     // Unique identifier for this picture.
     pub id: PictureId,
@@ -178,17 +178,17 @@ impl PicturePrimitive {
         }
     }
 
     pub fn new_image(
         id: PictureId,
         composite_mode: Option<PictureCompositeMode>,
         is_in_3d_context: bool,
         pipeline_id: PipelineId,
-        reference_frame_index: SpatialNodeIndex,
+        reference_frame_index: ClipScrollNodeIndex,
         frame_output_pipeline_id: Option<PipelineId>,
         apply_local_clip_rect: bool,
     ) -> Self {
         PicturePrimitive {
             runs: Vec::new(),
             surface: None,
             secondary_render_task_id: None,
             composite_mode,
@@ -585,72 +585,72 @@ impl PicturePrimitive {
             }
         }
     }
 }
 
 // Calculate a single screen-space UV for a picture.
 fn calculate_screen_uv(
     local_pos: &LayoutPoint,
-    spatial_node: &SpatialNode,
+    clip_scroll_node: &ClipScrollNode,
     rendered_rect: &DeviceRect,
     device_pixel_scale: DevicePixelScale,
 ) -> DevicePoint {
-    let world_pos = spatial_node
+    let world_pos = clip_scroll_node
         .world_content_transform
         .transform_point2d(local_pos);
 
     let mut device_pos = world_pos * device_pixel_scale;
 
     // Apply snapping for axis-aligned scroll nodes, as per prim_shared.glsl.
-    if spatial_node.transform_kind == TransformedRectKind::AxisAligned {
+    if clip_scroll_node.transform_kind == TransformedRectKind::AxisAligned {
         device_pos.x = (device_pos.x + 0.5).floor();
         device_pos.y = (device_pos.y + 0.5).floor();
     }
 
     DevicePoint::new(
         (device_pos.x - rendered_rect.origin.x) / rendered_rect.size.width,
         (device_pos.y - rendered_rect.origin.y) / rendered_rect.size.height,
     )
 }
 
 // Calculate a UV rect within an image based on the screen space
 // vertex positions of a picture.
 fn calculate_uv_rect_kind(
     local_rect: &LayoutRect,
-    spatial_node: &SpatialNode,
+    clip_scroll_node: &ClipScrollNode,
     rendered_rect: &DeviceIntRect,
     device_pixel_scale: DevicePixelScale,
 ) -> UvRectKind {
     let rendered_rect = rendered_rect.to_f32();
 
     let top_left = calculate_screen_uv(
         &local_rect.origin,
-        spatial_node,
+        clip_scroll_node,
         &rendered_rect,
         device_pixel_scale,
     );
 
     let top_right = calculate_screen_uv(
         &local_rect.top_right(),
-        spatial_node,
+        clip_scroll_node,
         &rendered_rect,
         device_pixel_scale,
     );
 
     let bottom_left = calculate_screen_uv(
         &local_rect.bottom_left(),
-        spatial_node,
+        clip_scroll_node,
         &rendered_rect,
         device_pixel_scale,
     );
 
     let bottom_right = calculate_screen_uv(
         &local_rect.bottom_right(),
-        spatial_node,
+        clip_scroll_node,
         &rendered_rect,
         device_pixel_scale,
     );
 
     UvRectKind::Quad {
         top_left,
         top_right,
         bottom_left,
--- a/gfx/webrender/src/platform/macos/font.rs
+++ b/gfx/webrender/src/platform/macos/font.rs
@@ -182,69 +182,69 @@ fn new_ct_font_with_variations(cg_font: 
         let axes: CFArray<CFDictionary> = TCFType::wrap_under_create_rule(axes_ref);
         let mut vals: Vec<(CFString, CFNumber)> = Vec::with_capacity(variations.len() as usize);
         for axis in axes.iter() {
             if !axis.instance_of::<CFDictionary>() {
                 return ct_font;
             }
             let tag_val = match axis.find(kCTFontVariationAxisIdentifierKey as *const _) {
                 Some(tag_ptr) => {
-                    let tag: CFNumber = TCFType::wrap_under_get_rule(*tag_ptr as CFNumberRef);
+                    let tag: CFNumber = TCFType::wrap_under_get_rule(tag_ptr as CFNumberRef);
                     if !tag.instance_of::<CFNumber>() {
                         return ct_font;
                     }
                     match tag.to_i64() {
                         Some(val) => val,
                         None => return ct_font,
                     }
                 }
                 None => return ct_font,
             };
             let mut val = match variations.iter().find(|variation| (variation.tag as i64) == tag_val) {
                 Some(variation) => variation.value as f64,
                 None => continue,
             };
 
             let name: CFString = match axis.find(kCTFontVariationAxisNameKey as *const _) {
-                Some(name_ptr) => TCFType::wrap_under_get_rule(*name_ptr as CFStringRef),
+                Some(name_ptr) => TCFType::wrap_under_get_rule(name_ptr as CFStringRef),
                 None => return ct_font,
             };
             if !name.instance_of::<CFString>() {
                 return ct_font;
             }
 
             let min_val = match axis.find(kCTFontVariationAxisMinimumValueKey as *const _) {
                 Some(min_ptr) => {
-                    let min: CFNumber = TCFType::wrap_under_get_rule(*min_ptr as CFNumberRef);
+                    let min: CFNumber = TCFType::wrap_under_get_rule(min_ptr as CFNumberRef);
                     if !min.instance_of::<CFNumber>() {
                         return ct_font;
                     }
                     match min.to_f64() {
                         Some(val) => val,
                         None => return ct_font,
                     }
                 }
                 None => return ct_font,
             };
             let max_val = match axis.find(kCTFontVariationAxisMaximumValueKey as *const _) {
                 Some(max_ptr) => {
-                    let max: CFNumber = TCFType::wrap_under_get_rule(*max_ptr as CFNumberRef);
+                    let max: CFNumber = TCFType::wrap_under_get_rule(max_ptr as CFNumberRef);
                     if !max.instance_of::<CFNumber>() {
                         return ct_font;
                     }
                     match max.to_f64() {
                         Some(val) => val,
                         None => return ct_font,
                     }
                 }
                 None => return ct_font,
             };
             let def_val = match axis.find(kCTFontVariationAxisDefaultValueKey as *const _) {
                 Some(def_ptr) => {
-                    let def: CFNumber = TCFType::wrap_under_get_rule(*def_ptr as CFNumberRef);
+                    let def: CFNumber = TCFType::wrap_under_get_rule(def_ptr as CFNumberRef);
                     if !def.instance_of::<CFNumber>() {
                         return ct_font;
                     }
                     match def.to_f64() {
                         Some(val) => val,
                         None => return ct_font,
                     }
                 }
--- a/gfx/webrender/src/prim_store.rs
+++ b/gfx/webrender/src/prim_store.rs
@@ -6,17 +6,18 @@ use api::{AlphaType, BorderRadius, BoxSh
 use api::{DeviceIntRect, DeviceIntSize, DevicePixelScale, ExtendMode};
 use api::{FilterOp, GlyphInstance, GradientStop, ImageKey, ImageRendering, ItemRange, ItemTag, TileOffset};
 use api::{GlyphRasterSpace, LayoutPoint, LayoutRect, LayoutSize, LayoutToWorldTransform, LayoutVector2D};
 use api::{PipelineId, PremultipliedColorF, PropertyBinding, Shadow, YuvColorSpace, YuvFormat, DeviceIntSideOffsets};
 use api::{BorderWidths, LayoutToWorldScale, NormalBorder};
 use app_units::Au;
 use border::{BorderCacheKey, BorderRenderTaskInfo};
 use box_shadow::BLUR_SAMPLE_SCALE;
-use clip_scroll_tree::{ClipChainIndex, CoordinateSystemId, SpatialNodeIndex};
+use clip_scroll_tree::{ClipChainIndex, ClipScrollNodeIndex, CoordinateSystemId};
+use clip_scroll_node::ClipScrollNode;
 use clip::{ClipChain, ClipChainNode, ClipChainNodeIter, ClipChainNodeRef, ClipSource};
 use clip::{ClipSourcesHandle, ClipWorkItem};
 use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureContext, PictureState};
 use frame_builder::PrimitiveRunContext;
 use glyph_rasterizer::{FontInstance, FontTransform, GlyphKey, FONT_SIZE_LIMIT};
 use gpu_cache::{GpuBlockData, GpuCache, GpuCacheAddress, GpuCacheHandle, GpuDataRequest,
                 ToGpuBlocks};
 use gpu_types::BrushFlags;
@@ -25,35 +26,34 @@ use picture::{PictureCompositeMode, Pict
 #[cfg(debug_assertions)]
 use render_backend::FrameId;
 use render_task::{BlitSource, RenderTask, RenderTaskCacheKey};
 use render_task::{RenderTaskCacheKeyKind, RenderTaskId, RenderTaskCacheEntryHandle};
 use renderer::{MAX_VERTEX_TEXTURE_WIDTH};
 use resource_cache::{ImageProperties, ImageRequest, ResourceCache};
 use scene::SceneProperties;
 use segment::SegmentBuilder;
-use spatial_node::SpatialNode;
 use std::{mem, usize};
 use std::sync::Arc;
-use util::{MatrixHelpers, calculate_screen_bounding_rect};
+use util::{MatrixHelpers, WorldToLayoutFastTransform, calculate_screen_bounding_rect};
 use util::{pack_as_float, recycle_vec};
 
 
 const MIN_BRUSH_SPLIT_AREA: f32 = 256.0 * 256.0;
 pub const VECS_PER_SEGMENT: usize = 2;
 
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
 pub struct ScrollNodeAndClipChain {
-    pub scroll_node_id: SpatialNodeIndex,
+    pub scroll_node_id: ClipScrollNodeIndex,
     pub clip_chain_index: ClipChainIndex,
 }
 
 impl ScrollNodeAndClipChain {
     pub fn new(
-        scroll_node_id: SpatialNodeIndex,
+        scroll_node_id: ClipScrollNodeIndex,
         clip_chain_index: ClipChainIndex
     ) -> Self {
         ScrollNodeAndClipChain { scroll_node_id, clip_chain_index }
     }
 }
 
 #[derive(Debug)]
 pub struct PrimitiveRun {
@@ -1237,17 +1237,17 @@ impl PrimitiveStore {
         }
     }
 
     pub fn add_image_picture(
         &mut self,
         composite_mode: Option<PictureCompositeMode>,
         is_in_3d_context: bool,
         pipeline_id: PipelineId,
-        reference_frame_index: SpatialNodeIndex,
+        reference_frame_index: ClipScrollNodeIndex,
         frame_output_pipeline_id: Option<PipelineId>,
         apply_local_clip_rect: bool,
     ) -> PictureIndex {
         let picture = PicturePrimitive::new_image(
             PictureId(self.next_picture_id),
             composite_mode,
             is_in_3d_context,
             pipeline_id,
@@ -1989,16 +1989,17 @@ impl PrimitiveStore {
     }
 
     fn write_brush_segment_description(
         brush: &mut BrushPrimitive,
         metadata: &PrimitiveMetadata,
         prim_run_context: &PrimitiveRunContext,
         clips: &Vec<ClipWorkItem>,
         has_clips_from_other_coordinate_systems: bool,
+        frame_context: &FrameBuildingContext,
         frame_state: &mut FrameBuildingState,
     ) {
         match brush.segment_desc {
             Some(ref segment_desc) => {
                 // If we already have a segment descriptor, only run through the
                 // clips list if we haven't already determined the mask kind.
                 if segment_desc.clip_mask_kind != BrushClipMaskKind::Unknown {
                     return;
@@ -2041,49 +2042,29 @@ impl PrimitiveStore {
 
         // Segment the primitive on all the local-space clip sources that we can.
         for clip_item in clips {
             if clip_item.coordinate_system_id != prim_run_context.scroll_node.coordinate_system_id {
                 continue;
             }
 
             let local_clips = frame_state.clip_store.get_opt(&clip_item.clip_sources).expect("bug");
-            rect_clips_only = rect_clips_only && local_clips.only_rectangular_clips;
-
-            // TODO(gw): We can easily extend the segment builder to support these clip sources in
-            // the future, but they are rarely used.
-            // We must do this check here in case we continue early below.
-            if local_clips.has_image_or_line_decoration_clip {
-                clip_mask_kind = BrushClipMaskKind::Global;
-            }
-
-            // If this clip item is positioned by another positioning node, its relative position
-            // could change during scrolling. This means that we would need to resegment. Instead
-            // of doing that, only segment with clips that have the same positioning node.
-            // TODO(mrobinson, #2858): It may make sense to include these nodes, resegmenting only
-            // when necessary while scrolling.
-            if clip_item.transform_index != prim_run_context.transform_index {
-                // We don't need to generate a global clip mask for rectangle clips because we are
-                // in the same coordinate system and rectangular clips are handled by the local
-                // clip chain rectangle.
-                if !local_clips.only_rectangular_clips {
-                    clip_mask_kind = BrushClipMaskKind::Global;
-                }
-                continue;
-            }
-
             for &(ref clip, _) in &local_clips.clips {
                 let (local_clip_rect, radius, mode) = match *clip {
                     ClipSource::RoundedRectangle(rect, radii, clip_mode) => {
+                        rect_clips_only = false;
+
                         (rect, Some(radii), clip_mode)
                     }
                     ClipSource::Rectangle(rect, mode) => {
                         (rect, None, mode)
                     }
                     ClipSource::BoxShadow(ref info) => {
+                        rect_clips_only = false;
+
                         // For inset box shadows, we can clip out any
                         // pixels that are inside the shadow region
                         // and are beyond the inner rect, as they can't
                         // be affected by the blur radius.
                         let inner_clip_mode = match info.clip_mode {
                             BoxShadowClipMode::Outset => None,
                             BoxShadowClipMode::Inset => Some(ClipMode::ClipOut),
                         };
@@ -2098,17 +2079,45 @@ impl PrimitiveStore {
                                 -0.5 * info.shadow_rect_alloc_size.width,
                                 -0.5 * info.shadow_rect_alloc_size.height,
                             ),
                             inner_clip_mode,
                         );
 
                         continue;
                     }
-                    ClipSource::LineDecoration(..) | ClipSource::Image(..) => continue,
+                    ClipSource::LineDecoration(..) |
+                    ClipSource::Image(..) => {
+                        rect_clips_only = false;
+
+                        // TODO(gw): We can easily extend the segment builder
+                        //           to support these clip sources in the
+                        //           future, but they are rarely used.
+                        clip_mask_kind = BrushClipMaskKind::Global;
+                        continue;
+                    }
+                };
+
+                // If the scroll node transforms are different between the clip
+                // node and the primitive, we need to get the clip rect in the
+                // local space of the primitive, in order to generate correct
+                // local segments.
+                let local_clip_rect = if clip_item.transform_index == prim_run_context.scroll_node.transform_index {
+                    local_clip_rect
+                } else {
+                    let clip_transform = frame_context
+                        .transforms[clip_item.transform_index.0 as usize]
+                        .transform;
+                    let prim_transform = &prim_run_context.scroll_node.world_content_transform;
+                    let relative_transform = prim_transform
+                        .inverse()
+                        .unwrap_or(WorldToLayoutFastTransform::identity())
+                        .pre_mul(&clip_transform.into());
+
+                    relative_transform.transform_rect(&local_clip_rect)
                 };
 
                 segment_builder.push_clip_rect(local_clip_rect, radius, mode);
             }
         }
 
         if is_large || rect_clips_only {
             match brush.segment_desc {
@@ -2167,16 +2176,17 @@ impl PrimitiveStore {
         };
 
         PrimitiveStore::write_brush_segment_description(
             brush,
             metadata,
             prim_run_context,
             clips,
             has_clips_from_other_coordinate_systems,
+            frame_context,
             frame_state,
         );
 
         let segment_desc = match brush.segment_desc {
             Some(ref mut description) => description,
             None => return false,
         };
         let clip_mask_kind = segment_desc.clip_mask_kind;
@@ -2288,21 +2298,21 @@ impl PrimitiveStore {
                     combined_outer_rect = combined_outer_rect.and_then(|r| r.intersection(&outer));
                 }
                 if cfg!(debug_assertions) && Some(prim_index) == self.chase_id {
                     println!("\tfound extra clip with screen bounds {:?}", screen_outer_rect);
                 }
 
                 Arc::new(ClipChainNode {
                     work_item: ClipWorkItem {
-                        transform_index: prim_run_context.transform_index,
+                        transform_index: prim_run_context.scroll_node.transform_index,
                         clip_sources: clip_sources.weak(),
                         coordinate_system_id: prim_coordinate_system_id,
                     },
-                    // The local_clip_rect a property of ClipChain nodes that are ClipNodes.
+                    // The local_clip_rect a property of ClipChain nodes that are ClipScrollNodes.
                     // It's used to calculate a local clipping rectangle before we reach this
                     // point, so we can set it to zero here. It should be unused from this point
                     // on.
                     local_clip_rect: LayoutRect::zero(),
                     screen_inner_rect,
                     screen_outer_rect: screen_outer_rect.unwrap_or(prim_screen_rect),
                     prev: None,
                 })
@@ -2634,17 +2644,17 @@ impl PrimitiveStore {
                 println!("\tpreparing a run of length {} in pipeline {:?}",
                     run.count, pic_context.pipeline_id);
             }
             // TODO(gw): Perhaps we can restructure this to not need to create
             //           a new primitive context for every run (if the hash
             //           lookups ever show up in a profile).
             let scroll_node = &frame_context
                 .clip_scroll_tree
-                .spatial_nodes[run.clip_and_scroll.scroll_node_id.0];
+                .nodes[run.clip_and_scroll.scroll_node_id.0];
             let clip_chain = frame_context
                 .clip_scroll_tree
                 .get_clip_chain(run.clip_and_scroll.clip_chain_index);
 
             // Mark whether this picture contains any complex coordinate
             // systems, due to either the scroll node or the clip-chain.
             pic_state.has_non_root_coord_system |=
                 scroll_node.coordinate_system_id != CoordinateSystemId::root();
@@ -2670,17 +2680,17 @@ impl PrimitiveStore {
                     inv_parent.pre_mul(&scroll_node.world_content_transform)
                 });
 
             let original_relative_transform = pic_context
                 .original_reference_frame_index
                 .and_then(|original_reference_frame_index| {
                     frame_context
                         .clip_scroll_tree
-                        .spatial_nodes[original_reference_frame_index.0]
+                        .nodes[original_reference_frame_index.0]
                         .world_content_transform
                         .inverse()
                 })
                 .map(|inv_parent| {
                     inv_parent.pre_mul(&scroll_node.world_content_transform)
                 });
 
             if run.is_chasing(self.chase_id) {
@@ -2707,17 +2717,16 @@ impl PrimitiveStore {
                 Some(rect) if rect.is_empty() => continue,
                 Some(rect) => rect,
                 None => frame_context.max_local_clip,
             };
 
             let child_prim_run_context = PrimitiveRunContext::new(
                 clip_chain,
                 scroll_node,
-                run.clip_and_scroll.scroll_node_id.transform_index(),
                 local_clip_chain_rect,
             );
 
             for i in 0 .. run.count {
                 let prim_index = PrimitiveIndex(run.base_prim_index.0 + i);
 
                 if let Some(prim_local_rect) = self.prepare_prim_for_render(
                     prim_index,
@@ -2900,17 +2909,17 @@ fn convert_clip_chain_to_clip_vector(
             };
 
             Some(node.work_item.clone())
         })
         .collect()
 }
 
 fn get_local_clip_rect_for_nodes(
-    scroll_node: &SpatialNode,
+    scroll_node: &ClipScrollNode,
     clip_chain: &ClipChain,
 ) -> Option<LayoutRect> {
     ClipChainNodeIter { current: clip_chain.nodes.clone() }
         .fold(
             None,
             |combined_local_clip_rect: Option<LayoutRect>, node| {
                 if node.work_item.coordinate_system_id != scroll_node.coordinate_system_id {
                     return combined_local_clip_rect;
--- a/gfx/webrender/src/render_backend.rs
+++ b/gfx/webrender/src/render_backend.rs
@@ -9,17 +9,17 @@ use api::{DeviceIntPoint, DevicePixelSca
 use api::{DocumentId, DocumentLayer, ExternalScrollId, FrameMsg, HitTestFlags, HitTestResult};
 use api::{IdNamespace, LayoutPoint, PipelineId, RenderNotifier, SceneMsg, ScrollClamping};
 use api::{ScrollLocation, ScrollNodeState, TransactionMsg};
 use api::channel::{MsgReceiver, Payload};
 #[cfg(feature = "capture")]
 use api::CaptureBits;
 #[cfg(feature = "replay")]
 use api::CapturedDocument;
-use clip_scroll_tree::{SpatialNodeIndex, ClipScrollTree};
+use clip_scroll_tree::{ClipScrollNodeIndex, ClipScrollTree};
 #[cfg(feature = "debugger")]
 use debug_server;
 use display_list_flattener::DisplayListFlattener;
 use frame_builder::{FrameBuilder, FrameBuilderConfig};
 use gpu_cache::GpuCache;
 use hit_test::{HitTest, HitTester};
 use internal_types::{DebugOutput, FastHashMap, FastHashSet, RenderedDocument, ResultMsg};
 use profiler::{BackendProfileCounters, IpcProfileCounters, ResourceProfileCounters};
@@ -84,19 +84,19 @@ struct Document {
     // received from the scene builder thread.
     current: SceneData,
     // The scene with the latest transactions applied, not necessarily built yet.
     // what we will send to the scene builder.
     pending: SceneData,
 
     view: DocumentView,
 
-    /// The ClipScrollTree for this document which tracks SpatialNodes, ClipNodes, and ClipChains.
-    /// This is stored here so that we are able to preserve scrolling positions between rendered
-    /// frames.
+    /// The ClipScrollTree for this document which tracks both ClipScrollNodes and ClipChains.
+    /// This is stored here so that we are able to preserve scrolling positions between
+    /// rendered frames.
     clip_scroll_tree: ClipScrollTree,
 
     /// The id of the current frame.
     frame_id: FrameId,
 
     /// A configuration object for the FrameBuilder that we produce.
     frame_builder_config: FrameBuilderConfig,
 
@@ -308,17 +308,17 @@ impl Document {
         self.clip_scroll_tree
             .discard_frame_state_for_pipeline(pipeline_id);
     }
 
     /// Returns true if any nodes actually changed position or false otherwise.
     pub fn scroll_nearest_scrolling_ancestor(
         &mut self,
         scroll_location: ScrollLocation,
-        scroll_node_index: Option<SpatialNodeIndex>,
+        scroll_node_index: Option<ClipScrollNodeIndex>,
     ) -> bool {
         self.clip_scroll_tree.scroll_nearest_scrolling_ancestor(scroll_location, scroll_node_index)
     }
 
     /// Returns true if the node actually changed position or false otherwise.
     pub fn scroll_node(
         &mut self,
         origin: LayoutPoint,
deleted file mode 100644
--- a/gfx/webrender/src/spatial_node.rs
+++ /dev/null
@@ -1,706 +0,0 @@
-
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-use api::{ExternalScrollId, LayoutPixel, LayoutPoint, LayoutRect, LayoutSize, LayoutTransform};
-use api::{LayoutVector2D, PipelineId, PropertyBinding, ScrollClamping, ScrollLocation};
-use api::{ScrollSensitivity, StickyOffsetBounds};
-use clip_scroll_tree::{CoordinateSystemId, SpatialNodeIndex, TransformUpdateState};
-use euclid::SideOffsets2D;
-use gpu_types::{TransformData, TransformIndex, TransformPalette};
-use scene::SceneProperties;
-use util::{LayoutFastTransform, LayoutToWorldFastTransform, TransformedRectKind};
-
-#[derive(Clone, Debug)]
-pub enum SpatialNodeType {
-    /// A special kind of node that adjusts its position based on the position
-    /// of its parent node and a given set of sticky positioning offset bounds.
-    /// Sticky positioned is described in the CSS Positioned Layout Module Level 3 here:
-    /// https://www.w3.org/TR/css-position-3/#sticky-pos
-    StickyFrame(StickyFrameInfo),
-
-    /// Transforms it's content, but doesn't clip it. Can also be adjusted
-    /// by scroll events or setting scroll offsets.
-    ScrollFrame(ScrollFrameInfo),
-
-    /// A reference frame establishes a new coordinate space in the tree.
-    ReferenceFrame(ReferenceFrameInfo),
-
-    /// An empty node, used to pad the ClipScrollTree's array of nodes so that
-    /// we can immediately use each assigned SpatialNodeIndex. After display
-    /// list flattening this node type should never be used.
-    Empty,
-}
-
-impl SpatialNodeType {
-    fn is_reference_frame(&self) -> bool {
-        match *self {
-            SpatialNodeType::ReferenceFrame(_) => true,
-            _ => false,
-        }
-    }
-}
-
-/// Contains information common among all types of ClipScrollTree nodes.
-#[derive(Clone, Debug)]
-pub struct SpatialNode {
-    /// The transformation for this viewport in world coordinates is the transformation for
-    /// our parent reference frame, plus any accumulated scrolling offsets from nodes
-    /// between our reference frame and this node. For reference frames, we also include
-    /// whatever local transformation this reference frame provides.
-    pub world_viewport_transform: LayoutToWorldFastTransform,
-
-    /// World transform for content transformed by this node.
-    pub world_content_transform: LayoutToWorldFastTransform,
-
-    /// The current transform kind of world_content_transform.
-    pub transform_kind: TransformedRectKind,
-
-    /// Pipeline that this layer belongs to
-    pub pipeline_id: PipelineId,
-
-    /// Parent layer. If this is None, we are the root node.
-    pub parent: Option<SpatialNodeIndex>,
-
-    /// Child layers
-    pub children: Vec<SpatialNodeIndex>,
-
-    /// The type of this node and any data associated with that node type.
-    pub node_type: SpatialNodeType,
-
-    /// True if this node is transformed by an invertible transform.  If not, display items
-    /// transformed by this node will not be displayed and display items not transformed by this
-    /// node will not be clipped by clips that are transformed by this node.
-    pub invertible: bool,
-
-    /// The axis-aligned coordinate system id of this node.
-    pub coordinate_system_id: CoordinateSystemId,
-
-    /// The transformation from the coordinate system which established our compatible coordinate
-    /// system (same coordinate system id) and us. This can change via scroll offsets and via new
-    /// reference frame transforms.
-    pub coordinate_system_relative_transform: LayoutFastTransform,
-}
-
-impl SpatialNode {
-    pub fn new(
-        pipeline_id: PipelineId,
-        parent_index: Option<SpatialNodeIndex>,
-        node_type: SpatialNodeType,
-    ) -> Self {
-        SpatialNode {
-            world_viewport_transform: LayoutToWorldFastTransform::identity(),
-            world_content_transform: LayoutToWorldFastTransform::identity(),
-            transform_kind: TransformedRectKind::AxisAligned,
-            parent: parent_index,
-            children: Vec::new(),
-            pipeline_id,
-            node_type,
-            invertible: true,
-            coordinate_system_id: CoordinateSystemId(0),
-            coordinate_system_relative_transform: LayoutFastTransform::identity(),
-        }
-    }
-
-    pub fn empty() -> SpatialNode {
-        Self::new(PipelineId::dummy(), None, SpatialNodeType::Empty)
-    }
-
-    pub fn new_scroll_frame(
-        pipeline_id: PipelineId,
-        parent_index: SpatialNodeIndex,
-        external_id: Option<ExternalScrollId>,
-        frame_rect: &LayoutRect,
-        content_size: &LayoutSize,
-        scroll_sensitivity: ScrollSensitivity,
-    ) -> Self {
-        let node_type = SpatialNodeType::ScrollFrame(ScrollFrameInfo::new(
-                *frame_rect,
-                scroll_sensitivity,
-                LayoutSize::new(
-                    (content_size.width - frame_rect.size.width).max(0.0),
-                    (content_size.height - frame_rect.size.height).max(0.0)
-                ),
-                external_id,
-            )
-        );
-
-        Self::new(pipeline_id, Some(parent_index), node_type)
-    }
-
-    pub fn new_reference_frame(
-        parent_index: Option<SpatialNodeIndex>,
-        source_transform: Option<PropertyBinding<LayoutTransform>>,
-        source_perspective: Option<LayoutTransform>,
-        origin_in_parent_reference_frame: LayoutVector2D,
-        pipeline_id: PipelineId,
-    ) -> Self {
-        let identity = LayoutTransform::identity();
-        let source_perspective = source_perspective.map_or_else(
-            LayoutFastTransform::identity, |perspective| perspective.into());
-        let info = ReferenceFrameInfo {
-            resolved_transform: LayoutFastTransform::identity(),
-            source_transform: source_transform.unwrap_or(PropertyBinding::Value(identity)),
-            source_perspective,
-            origin_in_parent_reference_frame,
-            invertible: true,
-        };
-        Self::new(pipeline_id, parent_index, SpatialNodeType:: ReferenceFrame(info))
-    }
-
-    pub fn new_sticky_frame(
-        parent_index: SpatialNodeIndex,
-        sticky_frame_info: StickyFrameInfo,
-        pipeline_id: PipelineId,
-    ) -> Self {
-        Self::new(pipeline_id, Some(parent_index), SpatialNodeType::StickyFrame(sticky_frame_info))
-    }
-
-
-    pub fn add_child(&mut self, child: SpatialNodeIndex) {
-        self.children.push(child);
-    }
-
-    pub fn apply_old_scrolling_state(&mut self, old_scroll_info: &ScrollFrameInfo) {
-        match self.node_type {
-            SpatialNodeType::ScrollFrame(ref mut scrolling) => {
-                *scrolling = scrolling.combine_with_old_scroll_info(old_scroll_info);
-            }
-            _ if old_scroll_info.offset != LayoutVector2D::zero() => {
-                warn!("Tried to scroll a non-scroll node.")
-            }
-            _ => {}
-        }
-    }
-
-    pub fn set_scroll_origin(&mut self, origin: &LayoutPoint, clamp: ScrollClamping) -> bool {
-        let scrollable_size = self.scrollable_size();
-        let scrollable_width = scrollable_size.width;
-        let scrollable_height = scrollable_size.height;
-
-        let scrolling = match self.node_type {
-            SpatialNodeType::ScrollFrame(ref mut scrolling) => scrolling,
-            _ => {
-                warn!("Tried to scroll a non-scroll node.");
-                return false;
-            }
-        };
-
-        let new_offset = match clamp {
-            ScrollClamping::ToContentBounds => {
-                if scrollable_height <= 0. && scrollable_width <= 0. {
-                    return false;
-                }
-
-                let origin = LayoutPoint::new(origin.x.max(0.0), origin.y.max(0.0));
-                LayoutVector2D::new(
-                    (-origin.x).max(-scrollable_width).min(0.0).round(),
-                    (-origin.y).max(-scrollable_height).min(0.0).round(),
-                )
-            }
-            ScrollClamping::NoClamping => LayoutPoint::zero() - *origin,
-        };
-
-        if new_offset == scrolling.offset {
-            return false;
-        }
-
-        scrolling.offset = new_offset;
-        true
-    }
-
-    pub fn mark_uninvertible(&mut self) {
-        self.invertible = false;
-        self.world_content_transform = LayoutToWorldFastTransform::identity();
-        self.world_viewport_transform = LayoutToWorldFastTransform::identity();
-    }
-
-    pub fn push_gpu_data(
-        &mut self,
-        transform_palette: &mut TransformPalette,
-        node_index: SpatialNodeIndex,
-    ) {
-        let transform_index = TransformIndex(node_index.0 as u32);
-        if !self.invertible {
-            transform_palette.set(transform_index, TransformData::invalid());
-            return;
-        }
-
-        let inv_transform = match self.world_content_transform.inverse() {
-            Some(inverted) => inverted.to_transform(),
-            None => {
-                transform_palette.set(transform_index, TransformData::invalid());
-                return;
-            }
-        };
-
-        let data = TransformData {
-            transform: self.world_content_transform.into(),
-            inv_transform,
-        };
-
-        // Write the data that will be made available to the GPU for this node.
-        transform_palette.set(transform_index, data);
-    }
-
-    pub fn update(
-        &mut self,
-        state: &mut TransformUpdateState,
-        next_coordinate_system_id: &mut CoordinateSystemId,
-        scene_properties: &SceneProperties,
-    ) {
-        // If any of our parents was not rendered, we are not rendered either and can just
-        // quit here.
-        if !state.invertible {
-            self.mark_uninvertible();
-            return;
-        }
-
-        self.update_transform(state, next_coordinate_system_id, scene_properties);
-
-        self.transform_kind = if self.world_content_transform.preserves_2d_axis_alignment() {
-            TransformedRectKind::AxisAligned
-        } else {
-            TransformedRectKind::Complex
-        };
-
-        // If this node is a reference frame, we check if it has a non-invertible matrix.
-        // For non-reference-frames we assume that they will produce only additional
-        // translations which should be invertible.
-        match self.node_type {
-            SpatialNodeType::ReferenceFrame(info) if !info.invertible => {
-                self.mark_uninvertible();
-                return;
-            }
-            _ => self.invertible = true,
-        }
-    }
-
-    pub fn update_transform(
-        &mut self,
-        state: &mut TransformUpdateState,
-        next_coordinate_system_id: &mut CoordinateSystemId,
-        scene_properties: &SceneProperties,
-    ) {
-        if self.node_type.is_reference_frame() {
-            self.update_transform_for_reference_frame(
-                state,
-                next_coordinate_system_id,
-                scene_properties
-            );
-            return;
-        }
-
-        // We calculate this here to avoid a double-borrow later.
-        let sticky_offset = self.calculate_sticky_offset(
-            &state.nearest_scrolling_ancestor_offset,
-            &state.nearest_scrolling_ancestor_viewport,
-        );
-
-        // The transformation for the bounds of our viewport is the parent reference frame
-        // transform, plus any accumulated scroll offset from our parents, plus any offset
-        // provided by our own sticky positioning.
-        let accumulated_offset = state.parent_accumulated_scroll_offset + sticky_offset;
-        self.world_viewport_transform = if accumulated_offset != LayoutVector2D::zero() {
-            state.parent_reference_frame_transform.pre_translate(&accumulated_offset)
-        } else {
-            state.parent_reference_frame_transform
-        };
-
-        // The transformation for any content inside of us is the viewport transformation, plus
-        // whatever scrolling offset we supply as well.
-        let scroll_offset = self.scroll_offset();
-        self.world_content_transform = if scroll_offset != LayoutVector2D::zero() {
-            self.world_viewport_transform.pre_translate(&scroll_offset)
-        } else {
-            self.world_viewport_transform
-        };
-
-        let added_offset = state.parent_accumulated_scroll_offset + sticky_offset + scroll_offset;
-        self.coordinate_system_relative_transform =
-            state.coordinate_system_relative_transform.offset(added_offset);
-
-        if let SpatialNodeType::StickyFrame(ref mut info) = self.node_type {
-            info.current_offset = sticky_offset;
-        }
-
-        self.coordinate_system_id = state.current_coordinate_system_id;
-    }
-
-    pub fn update_transform_for_reference_frame(
-        &mut self,
-        state: &mut TransformUpdateState,
-        next_coordinate_system_id: &mut CoordinateSystemId,
-        scene_properties: &SceneProperties,
-    ) {
-        let info = match self.node_type {
-            SpatialNodeType::ReferenceFrame(ref mut info) => info,
-            _ => unreachable!("Called update_transform_for_reference_frame on non-ReferenceFrame"),
-        };
-
-        // Resolve the transform against any property bindings.
-        let source_transform = scene_properties.resolve_layout_transform(&info.source_transform);
-        info.resolved_transform =
-            LayoutFastTransform::with_vector(info.origin_in_parent_reference_frame)
-            .pre_mul(&source_transform.into())
-            .pre_mul(&info.source_perspective);
-
-        // The transformation for this viewport in world coordinates is the transformation for
-        // our parent reference frame, plus any accumulated scrolling offsets from nodes
-        // between our reference frame and this node. Finally, we also include
-        // whatever local transformation this reference frame provides.
-        let relative_transform = info.resolved_transform
-            .post_translate(state.parent_accumulated_scroll_offset)
-            .to_transform()
-            .with_destination::<LayoutPixel>();
-        self.world_viewport_transform =
-            state.parent_reference_frame_transform.pre_mul(&relative_transform.into());
-        self.world_content_transform = self.world_viewport_transform;
-
-        info.invertible = self.world_viewport_transform.is_invertible();
-        if !info.invertible {
-            return;
-        }
-
-        // Try to update our compatible coordinate system transform. If we cannot, start a new
-        // incompatible coordinate system.
-        match state.coordinate_system_relative_transform.update(relative_transform) {
-            Some(offset) => self.coordinate_system_relative_transform = offset,
-            None => {
-                self.coordinate_system_relative_transform = LayoutFastTransform::identity();
-                state.current_coordinate_system_id = *next_coordinate_system_id;
-                next_coordinate_system_id.advance();
-            }
-        }
-
-        self.coordinate_system_id = state.current_coordinate_system_id;
-    }
-
-    fn calculate_sticky_offset(
-        &self,
-        viewport_scroll_offset: &LayoutVector2D,
-        viewport_rect: &LayoutRect,
-    ) -> LayoutVector2D {
-        let info = match self.node_type {
-            SpatialNodeType::StickyFrame(ref info) => info,
-            _ => return LayoutVector2D::zero(),
-        };
-
-        if info.margins.top.is_none() && info.margins.bottom.is_none() &&
-            info.margins.left.is_none() && info.margins.right.is_none() {
-            return LayoutVector2D::zero();
-        }
-
-        // The viewport and margins of the item establishes the maximum amount that it can
-        // be offset in order to keep it on screen. Since we care about the relationship
-        // between the scrolled content and unscrolled viewport we adjust the viewport's
-        // position by the scroll offset in order to work with their relative positions on the
-        // page.
-        let sticky_rect = info.frame_rect.translate(viewport_scroll_offset);
-
-        let mut sticky_offset = LayoutVector2D::zero();
-        if let Some(margin) = info.margins.top {
-            let top_viewport_edge = viewport_rect.min_y() + margin;
-            if sticky_rect.min_y() < top_viewport_edge {
-                // If the sticky rect is positioned above the top edge of the viewport (plus margin)
-                // we move it down so that it is fully inside the viewport.
-                sticky_offset.y = top_viewport_edge - sticky_rect.min_y();
-            } else if info.previously_applied_offset.y > 0.0 &&
-                sticky_rect.min_y() > top_viewport_edge {
-                // However, if the sticky rect is positioned *below* the top edge of the viewport
-                // and there is already some offset applied to the sticky rect's position, then
-                // we need to move it up so that it remains at the correct position. This
-                // makes sticky_offset.y negative and effectively reduces the amount of the
-                // offset that was already applied. We limit the reduction so that it can, at most,
-                // cancel out the already-applied offset, but should never end up adjusting the
-                // position the other way.
-                sticky_offset.y = top_viewport_edge - sticky_rect.min_y();
-                sticky_offset.y = sticky_offset.y.max(-info.previously_applied_offset.y);
-            }
-            debug_assert!(sticky_offset.y + info.previously_applied_offset.y >= 0.0);
-        }
-
-        // If we don't have a sticky-top offset (sticky_offset.y + info.previously_applied_offset.y
-        // == 0), or if we have a previously-applied bottom offset (previously_applied_offset.y < 0)
-        // then we check for handling the bottom margin case.
-        if sticky_offset.y + info.previously_applied_offset.y <= 0.0 {
-            if let Some(margin) = info.margins.bottom {
-                // Same as the above case, but inverted for bottom-sticky items. Here
-                // we adjust items upwards, resulting in a negative sticky_offset.y,
-                // or reduce the already-present upward adjustment, resulting in a positive
-                // sticky_offset.y.
-                let bottom_viewport_edge = viewport_rect.max_y() - margin;
-                if sticky_rect.max_y() > bottom_viewport_edge {
-                    sticky_offset.y = bottom_viewport_edge - sticky_rect.max_y();
-                } else if info.previously_applied_offset.y < 0.0 &&
-                    sticky_rect.max_y() < bottom_viewport_edge {
-                    sticky_offset.y = bottom_viewport_edge - sticky_rect.max_y();
-                    sticky_offset.y = sticky_offset.y.min(-info.previously_applied_offset.y);
-                }
-                debug_assert!(sticky_offset.y + info.previously_applied_offset.y <= 0.0);
-            }
-        }
-
-        // Same as above, but for the x-axis.
-        if let Some(margin) = info.margins.left {
-            let left_viewport_edge = viewport_rect.min_x() + margin;
-            if sticky_rect.min_x() < left_viewport_edge {
-                sticky_offset.x = left_viewport_edge - sticky_rect.min_x();
-            } else if info.previously_applied_offset.x > 0.0 &&
-                sticky_rect.min_x() > left_viewport_edge {
-                sticky_offset.x = left_viewport_edge - sticky_rect.min_x();
-                sticky_offset.x = sticky_offset.x.max(-info.previously_applied_offset.x);
-            }
-            debug_assert!(sticky_offset.x + info.previously_applied_offset.x >= 0.0);
-        }
-
-        if sticky_offset.x + info.previously_applied_offset.x <= 0.0 {
-            if let Some(margin) = info.margins.right {
-                let right_viewport_edge = viewport_rect.max_x() - margin;
-                if sticky_rect.max_x() > right_viewport_edge {
-                    sticky_offset.x = right_viewport_edge - sticky_rect.max_x();
-                } else if info.previously_applied_offset.x < 0.0 &&
-                    sticky_rect.max_x() < right_viewport_edge {
-                    sticky_offset.x = right_viewport_edge - sticky_rect.max_x();
-                    sticky_offset.x = sticky_offset.x.min(-info.previously_applied_offset.x);
-                }
-                debug_assert!(sticky_offset.x + info.previously_applied_offset.x <= 0.0);
-            }
-        }
-
-        // The total "sticky offset" (which is the sum that was already applied by
-        // the calling code, stored in info.previously_applied_offset, and the extra amount we
-        // computed as a result of scrolling, stored in sticky_offset) needs to be
-        // clamped to the provided bounds.
-        let clamp_adjusted = |value: f32, adjust: f32, bounds: &StickyOffsetBounds| {
-            (value + adjust).max(bounds.min).min(bounds.max) - adjust
-        };
-        sticky_offset.y = clamp_adjusted(sticky_offset.y,
-                                         info.previously_applied_offset.y,
-                                         &info.vertical_offset_bounds);
-        sticky_offset.x = clamp_adjusted(sticky_offset.x,
-                                         info.previously_applied_offset.x,
-                                         &info.horizontal_offset_bounds);
-
-        sticky_offset
-    }
-
-    pub fn prepare_state_for_children(&self, state: &mut TransformUpdateState) {
-        if !self.invertible {
-            state.invertible = false;
-            return;
-        }
-
-        // The transformation we are passing is the transformation of the parent
-        // reference frame and the offset is the accumulated offset of all the nodes
-        // between us and the parent reference frame. If we are a reference frame,
-        // we need to reset both these values.
-        match self.node_type {
-            SpatialNodeType::StickyFrame(ref info) => {
-                // We don't translate the combined rect by the sticky offset, because sticky
-                // offsets actually adjust the node position itself, whereas scroll offsets
-                // only apply to contents inside the node.
-                state.parent_accumulated_scroll_offset =
-                    info.current_offset + state.parent_accumulated_scroll_offset;
-            }
-            SpatialNodeType::ScrollFrame(ref scrolling) => {
-                state.parent_accumulated_scroll_offset =
-                    scrolling.offset + state.parent_accumulated_scroll_offset;
-                state.nearest_scrolling_ancestor_offset = scrolling.offset;
-                state.nearest_scrolling_ancestor_viewport = scrolling.viewport_rect;
-            }
-            SpatialNodeType::ReferenceFrame(ref info) => {
-                state.parent_reference_frame_transform = self.world_viewport_transform;
-                state.parent_accumulated_scroll_offset = LayoutVector2D::zero();
-                state.coordinate_system_relative_transform =
-                    self.coordinate_system_relative_transform.clone();
-                let translation = -info.origin_in_parent_reference_frame;
-                state.nearest_scrolling_ancestor_viewport =
-                    state.nearest_scrolling_ancestor_viewport
-                       .translate(&translation);
-            }
-            SpatialNodeType::Empty => unreachable!("Empty node remaining in ClipScrollTree."),
-        }
-    }
-
-    pub fn scrollable_size(&self) -> LayoutSize {
-        match self.node_type {
-           SpatialNodeType::ScrollFrame(state) => state.scrollable_size,
-            _ => LayoutSize::zero(),
-        }
-    }
-
-    pub fn scroll(&mut self, scroll_location: ScrollLocation) -> bool {
-        let scrolling = match self.node_type {
-            SpatialNodeType::ScrollFrame(ref mut scrolling) => scrolling,
-            _ => return false,
-        };
-
-        let delta = match scroll_location {
-            ScrollLocation::Delta(delta) => delta,
-            ScrollLocation::Start => {
-                if scrolling.offset.y.round() >= 0.0 {
-                    // Nothing to do on this layer.
-                    return false;
-                }
-
-                scrolling.offset.y = 0.0;
-                return true;
-            }
-            ScrollLocation::End => {
-                let end_pos = -scrolling.scrollable_size.height;
-                if scrolling.offset.y.round() <= end_pos {
-                    // Nothing to do on this layer.
-                    return false;
-                }
-
-                scrolling.offset.y = end_pos;
-                return true;
-            }
-        };
-
-        let scrollable_width = scrolling.scrollable_size.width;
-        let scrollable_height = scrolling.scrollable_size.height;
-        let original_layer_scroll_offset = scrolling.offset;
-
-        if scrollable_width > 0. {
-            scrolling.offset.x = (scrolling.offset.x + delta.x)
-                .min(0.0)
-                .max(-scrollable_width)
-                .round();
-        }
-
-        if scrollable_height > 0. {
-            scrolling.offset.y = (scrolling.offset.y + delta.y)
-                .min(0.0)
-                .max(-scrollable_height)
-                .round();
-        }
-
-        scrolling.offset != original_layer_scroll_offset
-    }
-
-    pub fn scroll_offset(&self) -> LayoutVector2D {
-        match self.node_type {
-            SpatialNodeType::ScrollFrame(ref scrolling) => scrolling.offset,
-            _ => LayoutVector2D::zero(),
-        }
-    }
-
-    pub fn matches_external_id(&self, external_id: ExternalScrollId) -> bool {
-        match self.node_type {
-            SpatialNodeType::ScrollFrame(info) if info.external_id == Some(external_id) => true,
-            _ => false,
-        }
-    }
-}
-
-#[derive(Copy, Clone, Debug)]
-pub struct ScrollFrameInfo {
-    /// The rectangle of the viewport of this scroll frame. This is important for
-    /// positioning of items inside child StickyFrames.
-    pub viewport_rect: LayoutRect,
-
-    pub offset: LayoutVector2D,
-    pub scroll_sensitivity: ScrollSensitivity,
-
-    /// Amount that this ScrollFrame can scroll in both directions.
-    pub scrollable_size: LayoutSize,
-
-    /// An external id to identify this scroll frame to API clients. This
-    /// allows setting scroll positions via the API without relying on ClipsIds
-    /// which may change between frames.
-    pub external_id: Option<ExternalScrollId>,
-
-}
-
-/// Manages scrolling offset.
-impl ScrollFrameInfo {
-    pub fn new(
-        viewport_rect: LayoutRect,
-        scroll_sensitivity: ScrollSensitivity,
-        scrollable_size: LayoutSize,
-        external_id: Option<ExternalScrollId>,
-    ) -> ScrollFrameInfo {
-        ScrollFrameInfo {
-            viewport_rect,
-            offset: LayoutVector2D::zero(),
-            scroll_sensitivity,
-            scrollable_size,
-            external_id,
-        }
-    }
-
-    pub fn sensitive_to_input_events(&self) -> bool {
-        match self.scroll_sensitivity {
-            ScrollSensitivity::ScriptAndInputEvents => true,
-            ScrollSensitivity::Script => false,
-        }
-    }
-
-    pub fn combine_with_old_scroll_info(
-        self,
-        old_scroll_info: &ScrollFrameInfo
-    ) -> ScrollFrameInfo {
-        ScrollFrameInfo {
-            viewport_rect: self.viewport_rect,
-            offset: old_scroll_info.offset,
-            scroll_sensitivity: self.scroll_sensitivity,
-            scrollable_size: self.scrollable_size,
-            external_id: self.external_id,
-        }
-    }
-}
-
-/// Contains information about reference frames.
-#[derive(Copy, Clone, Debug)]
-pub struct ReferenceFrameInfo {
-    /// The transformation that establishes this reference frame, relative to the parent
-    /// reference frame. The origin of the reference frame is included in the transformation.
-    pub resolved_transform: LayoutFastTransform,
-
-    /// The source transform and perspective matrices provided by the stacking context
-    /// that forms this reference frame. We maintain the property binding information
-    /// here so that we can resolve the animated transform and update the tree each
-    /// frame.
-    pub source_transform: PropertyBinding<LayoutTransform>,
-    pub source_perspective: LayoutFastTransform,
-
-    /// The original, not including the transform and relative to the parent reference frame,
-    /// origin of this reference frame. This is already rolled into the `transform' property, but
-    /// we also store it here to properly transform the viewport for sticky positioning.
-    pub origin_in_parent_reference_frame: LayoutVector2D,
-
-    /// True if the resolved transform is invertible.
-    pub invertible: bool,
-}
-
-#[derive(Clone, Debug)]
-pub struct StickyFrameInfo {
-    pub frame_rect: LayoutRect,
-    pub margins: SideOffsets2D<Option<f32>>,
-    pub vertical_offset_bounds: StickyOffsetBounds,
-    pub horizontal_offset_bounds: StickyOffsetBounds,
-    pub previously_applied_offset: LayoutVector2D,
-    pub current_offset: LayoutVector2D,
-}
-
-impl StickyFrameInfo {
-    pub fn new(
-        frame_rect: LayoutRect,
-        margins: SideOffsets2D<Option<f32>>,
-        vertical_offset_bounds: StickyOffsetBounds,
-        horizontal_offset_bounds: StickyOffsetBounds,
-        previously_applied_offset: LayoutVector2D
-    ) -> StickyFrameInfo {
-        StickyFrameInfo {
-            frame_rect,
-            margins,
-            vertical_offset_bounds,
-            horizontal_offset_bounds,
-            previously_applied_offset,
-            current_offset: LayoutVector2D::zero(),
-        }
-    }
-}
--- a/gfx/webrender/src/tiling.rs
+++ b/gfx/webrender/src/tiling.rs
@@ -2,17 +2,17 @@
  * 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 api::{ColorF, DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixelScale, DeviceUintPoint};
 use api::{DeviceUintRect, DeviceUintSize, DocumentLayer, FilterOp, ImageFormat, LayoutRect};
 use api::{MixBlendMode, PipelineId};
 use batch::{AlphaBatchBuilder, AlphaBatchContainer, ClipBatcher, resolve_image};
 use clip::{ClipStore};
-use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
+use clip_scroll_tree::{ClipScrollTree, ClipScrollNodeIndex};
 use device::{FrameId, Texture};
 #[cfg(feature = "pathfinder")]
 use euclid::{TypedPoint2D, TypedVector2D};
 use gpu_cache::{GpuCache};
 use gpu_types::{BorderInstance, BlurDirection, BlurInstance, PrimitiveHeaders, TransformData, TransformPalette};
 use internal_types::{FastHashMap, SavedTargetIndex, SourceTexture};
 #[cfg(feature = "pathfinder")]
 use pathfinder_partitioner::mesh::Mesh;
@@ -26,17 +26,17 @@ use std::{cmp, usize, f32, i32, mem};
 use texture_allocator::GuillotineAllocator;
 #[cfg(feature = "pathfinder")]
 use webrender_api::{DevicePixel, FontRenderMode};
 
 const MIN_TARGET_SIZE: u32 = 2048;
 
 #[derive(Debug)]
 pub struct ScrollbarPrimitive {
-    pub scroll_frame_index: SpatialNodeIndex,
+    pub scroll_frame_index: ClipScrollNodeIndex,
     pub prim_index: PrimitiveIndex,
     pub frame_rect: LayoutRect,
 }
 
 #[derive(Debug, Copy, Clone)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
 pub struct RenderTargetIndex(pub usize);
--- a/gfx/webrender/tests/angle_shader_validation.rs
+++ b/gfx/webrender/tests/angle_shader_validation.rs
@@ -13,21 +13,19 @@ const VERTEX_SHADER: u32 = 0x8B31;
 
 struct Shader {
     name: &'static str,
     features: &'static [&'static str],
 }
 
 const SHADER_PREFIX: &str = "#define WR_MAX_VERTEX_TEXTURE_WIDTH 1024\n";
 
-const BRUSH_FEATURES: &[&str] = &["", "ALPHA_PASS"];
 const CLIP_FEATURES: &[&str] = &["TRANSFORM"];
 const CACHE_FEATURES: &[&str] = &[""];
-const GRADIENT_FEATURES: &[&str] = &[ "", "DITHERING", "ALPHA_PASS", "DITHERING,ALPHA_PASS" ];
-const PRIM_FEATURES: &[&str] = &[""];
+const PRIM_FEATURES: &[&str] = &["", "TRANSFORM"];
 
 const SHADERS: &[Shader] = &[
     // Clip mask shaders
     Shader {
         name: "cs_clip_rectangle",
         features: CLIP_FEATURES,
     },
     Shader {
@@ -40,66 +38,59 @@ const SHADERS: &[Shader] = &[
     },
     Shader {
         name: "cs_clip_line",
         features: CLIP_FEATURES,
     },
     // Cache shaders
     Shader {
         name: "cs_blur",
-        features: &[ "ALPHA_TARGET", "COLOR_TARGET" ],
+        features: CACHE_FEATURES,
     },
     Shader {
         name: "cs_border_segment",
         features: CACHE_FEATURES,
     },
     // Prim shaders
     Shader {
         name: "ps_split_composite",
         features: PRIM_FEATURES,
     },
     Shader {
         name: "ps_text_run",
-        features: &[ "", "GLYPH_TRANSFORM" ],
+        features: PRIM_FEATURES,
     },
     // Brush shaders
     Shader {
         name: "brush_yuv_image",
-        features: &[
-            "",
-            "YUV_NV12",
-            "YUV_PLANAR",
-            "YUV_INTERLEAVED",
-            "TEXTURE_2D,YUV_NV12",
-            "YUV_NV12,ALPHA_PASS",
-        ],
+        features: &["", "YUV_NV12", "YUV_PLANAR", "YUV_INTERLEAVED", "YUV_NV12,TEXTURE_RECT"],
     },
     Shader {
         name: "brush_solid",
-        features: BRUSH_FEATURES,
+        features: &[],
     },
     Shader {
         name: "brush_image",
-        features: BRUSH_FEATURES,
+        features: &["", "ALPHA_PASS"],
     },
     Shader {
         name: "brush_blend",
-        features: BRUSH_FEATURES,
+        features: &[],
     },
     Shader {
         name: "brush_mix_blend",
-        features: BRUSH_FEATURES,
+        features: &[],
     },
     Shader {
         name: "brush_radial_gradient",
-        features: GRADIENT_FEATURES,
+        features: &[ "DITHERING" ],
     },
     Shader {
         name: "brush_linear_gradient",
-        features: GRADIENT_FEATURES,
+        features: &[],
     },
 ];
 
 const VERSION_STRING: &str = "#version 300 es\n";
 
 #[test]
 fn validate_shaders() {
     mozangle::shaders::initialize().unwrap();
@@ -112,17 +103,17 @@ fn validate_shaders() {
         ShaderValidator::new(FRAGMENT_SHADER, ShaderSpec::Gles3, Output::Essl, &resources).unwrap();
 
     for shader in SHADERS {
         for config in shader.features {
             let mut features = String::new();
             features.push_str(SHADER_PREFIX);
 
             for feature in config.split(",") {
-                features.push_str(&format!("#define WR_FEATURE_{}\n", feature));
+                features.push_str(&format!("#define WR_FEATURE_{}", feature));
             }
 
             let (vs, fs) =
                 webrender::build_shader_strings(VERSION_STRING, &features, shader.name, &None);
 
             validate(&vs_validator, shader.name, vs);
             validate(&fs_validator, shader.name, fs);
         }
--- a/gfx/webrender_api/Cargo.toml
+++ b/gfx/webrender_api/Cargo.toml
@@ -19,13 +19,13 @@ byteorder = "1.2.1"
 ipc-channel = {version = "0.10.0", optional = true}
 euclid = { version = "0.17", features = ["serde"] }
 serde = { version = "=1.0.66", features = ["rc"] }
 serde_derive = { version = "=1.0.66", features = ["deserialize_in_place"] }
 serde_bytes = "0.10"
 time = "0.1"
 
 [target.'cfg(target_os = "macos")'.dependencies]
-core-foundation = "0.6"
-core-graphics = "0.14"
+core-foundation = "0.5"
+core-graphics = "0.13"
 
 [target.'cfg(target_os = "windows")'.dependencies]
 dwrote = "0.4.1"
--- a/gfx/webrender_api/src/display_item.rs
+++ b/gfx/webrender_api/src/display_item.rs
@@ -801,51 +801,49 @@ impl ComplexClipRegion {
 }
 
 
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
 pub struct ClipChainId(pub u64, pub PipelineId);
 
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
 pub enum ClipId {
-    Spatial(usize, PipelineId),
     Clip(usize, PipelineId),
     ClipChain(ClipChainId),
 }
 
 const ROOT_REFERENCE_FRAME_CLIP_ID: usize = 0;
 const ROOT_SCROLL_NODE_CLIP_ID: usize = 1;
 
 impl ClipId {
     pub fn root_scroll_node(pipeline_id: PipelineId) -> ClipId {
-        ClipId::Spatial(ROOT_SCROLL_NODE_CLIP_ID, pipeline_id)
+        ClipId::Clip(ROOT_SCROLL_NODE_CLIP_ID, pipeline_id)
     }
 
     pub fn root_reference_frame(pipeline_id: PipelineId) -> ClipId {
-        ClipId::Spatial(ROOT_REFERENCE_FRAME_CLIP_ID, pipeline_id)
+        ClipId::Clip(ROOT_REFERENCE_FRAME_CLIP_ID, pipeline_id)
     }
 
     pub fn pipeline_id(&self) -> PipelineId {
         match *self {
-            ClipId::Spatial(_, pipeline_id) |
             ClipId::Clip(_, pipeline_id) |
             ClipId::ClipChain(ClipChainId(_, pipeline_id)) => pipeline_id,
         }
     }
 
     pub fn is_root_scroll_node(&self) -> bool {
         match *self {
-            ClipId::Spatial(ROOT_SCROLL_NODE_CLIP_ID, _) => true,
+            ClipId::Clip(1, _) => true,
             _ => false,
         }
     }
 
     pub fn is_root_reference_frame(&self) -> bool {
         match *self {
-            ClipId::Spatial(ROOT_REFERENCE_FRAME_CLIP_ID, _) => true,
+            ClipId::Clip(1, _) => true,
             _ => false,
         }
     }
 }
 
 /// An external identifier that uniquely identifies a scroll frame independent of its ClipId, which
 /// may change from frame to frame. This should be unique within a pipeline. WebRender makes no
 /// attempt to ensure uniqueness. The zero value is reserved for use by the root scroll node of
--- a/gfx/webrender_api/src/display_list.rs
+++ b/gfx/webrender_api/src/display_list.rs
@@ -26,22 +26,17 @@ use {ScrollFrameDisplayItem, ScrollSensi
 use {StickyFrameDisplayItem, StickyOffsetBounds, TextDisplayItem, TransformStyle, YuvColorSpace};
 use {YuvData, YuvImageDisplayItem};
 
 // We don't want to push a long text-run. If a text-run is too long, split it into several parts.
 // This needs to be set to (renderer::MAX_VERTEX_TEXTURE_WIDTH - VECS_PER_TEXT_RUN) * 2
 pub const MAX_TEXT_RUN_LENGTH: usize = 2040;
 
 // We start at 2, because the root reference is always 0 and the root scroll node is always 1.
-// TODO(mrobinson): It would be a good idea to eliminate the root scroll frame which is only
-// used by Servo.
-const FIRST_SPATIAL_NODE_INDEX: usize = 2;
-
-// There are no default clips, so we start at the 0 index for clips.
-const FIRST_CLIP_NODE_INDEX: usize = 0;
+const FIRST_CLIP_ID: usize = 2;
 
 #[repr(C)]
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
 pub struct ItemRange<T> {
     start: usize,
     length: usize,
     _boo: PhantomData<T>,
 }
@@ -79,20 +74,18 @@ pub struct BuiltDisplayList {
 #[derive(Copy, Clone, Default, Deserialize, Serialize)]
 pub struct BuiltDisplayListDescriptor {
     /// The first IPC time stamp: before any work has been done
     builder_start_time: u64,
     /// The second IPC time stamp: after serialization
     builder_finish_time: u64,
     /// The third IPC time stamp: just before sending
     send_start_time: u64,
-    /// The amount of clipping nodes created while building this display list.
-    total_clip_nodes: usize,
-    /// The amount of spatial nodes created while building this display list.
-    total_spatial_nodes: usize,
+    /// The amount of clips ids assigned while building this display list.
+    total_clip_ids: usize,
 }
 
 pub struct BuiltDisplayListIter<'a> {
     list: &'a BuiltDisplayList,
     data: &'a [u8],
     cur_item: DisplayItem,
     cur_stops: ItemRange<GradientStop>,
     cur_glyphs: ItemRange<GlyphInstance>,
@@ -148,22 +141,18 @@ impl BuiltDisplayList {
     pub fn times(&self) -> (u64, u64, u64) {
         (
             self.descriptor.builder_start_time,
             self.descriptor.builder_finish_time,
             self.descriptor.send_start_time,
         )
     }
 
-    pub fn total_clip_nodes(&self) -> usize {
-        self.descriptor.total_clip_nodes
-    }
-
-    pub fn total_spatial_nodes(&self) -> usize {
-        self.descriptor.total_spatial_nodes
+    pub fn total_clip_ids(&self) -> usize {
+        self.descriptor.total_clip_ids
     }
 
     pub fn iter(&self) -> BuiltDisplayListIter {
         BuiltDisplayListIter::new(self)
     }
 
     pub fn get<'de, T: Deserialize<'de>>(&self, range: ItemRange<T>) -> AuxIter<T> {
         AuxIter::new(&self.data[range.start .. range.start + range.length])
@@ -523,38 +512,36 @@ impl<'de> Deserialize<'de> for BuiltDisp
         use display_item::CompletelySpecificDisplayItem::*;
         use display_item::{CompletelySpecificDisplayItem, GenericDisplayItem};
 
         let list = Vec::<GenericDisplayItem<CompletelySpecificDisplayItem>>
             ::deserialize(deserializer)?;
 
         let mut data = Vec::new();
         let mut temp = Vec::new();
-        let mut total_clip_nodes = FIRST_CLIP_NODE_INDEX;
-        let mut total_spatial_nodes = FIRST_SPATIAL_NODE_INDEX;
+        let mut total_clip_ids = FIRST_CLIP_ID;
         for complete in list {
             let item = DisplayItem {
                 item: match complete.item {
                     Clip(specific_item, complex_clips) => {
-                        total_clip_nodes += 1;
+                        total_clip_ids += 1;
                         DisplayListBuilder::push_iter_impl(&mut temp, complex_clips);
                         SpecificDisplayItem::Clip(specific_item)
                     },
                     ClipChain(specific_item, clip_chain_ids) => {
                         DisplayListBuilder::push_iter_impl(&mut temp, clip_chain_ids);
                         SpecificDisplayItem::ClipChain(specific_item)
                     }
                     ScrollFrame(specific_item, complex_clips) => {
-                        total_spatial_nodes += 1;
-                        total_clip_nodes += 1;
+                        total_clip_ids += 2;
                         DisplayListBuilder::push_iter_impl(&mut temp, complex_clips);
                         SpecificDisplayItem::ScrollFrame(specific_item)
                     },
                     StickyFrame(specific_item) => {
-                        total_spatial_nodes += 1;
+                        total_clip_ids += 1;
                         SpecificDisplayItem::StickyFrame(specific_item)
                     }
                     Rectangle(specific_item) => SpecificDisplayItem::Rectangle(specific_item),
                     ClearRectangle => SpecificDisplayItem::ClearRectangle,
                     Line(specific_item) => SpecificDisplayItem::Line(specific_item),
                     Text(specific_item, glyphs) => {
                         DisplayListBuilder::push_iter_impl(&mut temp, glyphs);
                         SpecificDisplayItem::Text(specific_item)
@@ -562,26 +549,26 @@ impl<'de> Deserialize<'de> for BuiltDisp
                     Image(specific_item) => SpecificDisplayItem::Image(specific_item),
                     YuvImage(specific_item) => SpecificDisplayItem::YuvImage(specific_item),
                     Border(specific_item) => SpecificDisplayItem::Border(specific_item),
                     BoxShadow(specific_item) => SpecificDisplayItem::BoxShadow(specific_item),
                     Gradient(specific_item) => SpecificDisplayItem::Gradient(specific_item),
                     RadialGradient(specific_item) =>
                         SpecificDisplayItem::RadialGradient(specific_item),
                     Iframe(specific_item) => {
-                        total_clip_nodes += 1;
+                        total_clip_ids += 1;
                         SpecificDisplayItem::Iframe(specific_item)
                     }
                     PushStackingContext(specific_item, filters) => {
                         DisplayListBuilder::push_iter_impl(&mut temp, filters);
                         SpecificDisplayItem::PushStackingContext(specific_item)
                     },
                     PopStackingContext => SpecificDisplayItem::PopStackingContext,
                     PushReferenceFrame(specific_item) => {
-                        total_spatial_nodes += 1;
+                        total_clip_ids += 1;
                         SpecificDisplayItem::PushReferenceFrame(specific_item)
                     }
                     PopReferenceFrame => SpecificDisplayItem::PopReferenceFrame,
                     SetGradientStops(stops) => {
                         DisplayListBuilder::push_iter_impl(&mut temp, stops);
                         SpecificDisplayItem::SetGradientStops
                     },
                     PushShadow(specific_item) => SpecificDisplayItem::PushShadow(specific_item),
@@ -596,18 +583,17 @@ impl<'de> Deserialize<'de> for BuiltDisp
         }
 
         Ok(BuiltDisplayList {
             data,
             descriptor: BuiltDisplayListDescriptor {
                 builder_start_time: 0,
                 builder_finish_time: 1,
                 send_start_time: 0,
-                total_clip_nodes,
-                total_spatial_nodes,
+                total_clip_ids,
             },
         })
     }
 }
 
 // This is a replacement for bincode::serialize_into(&vec)
 // The default implementation Write for Vec will basically
 // call extend_from_slice(). Serde ends up calling that for every
@@ -822,28 +808,26 @@ impl<'a, 'b> Read for UnsafeReader<'a, '
         Ok(())
     }
 }
 
 #[derive(Clone, Debug)]
 pub struct SaveState {
     dl_len: usize,
     clip_stack_len: usize,
-    next_clip_index: usize,
-    next_spatial_index: usize,
+    next_clip_id: usize,
     next_clip_chain_id: u64,
 }
 
 #[derive(Clone)]
 pub struct DisplayListBuilder {
     pub data: Vec<u8>,
     pub pipeline_id: PipelineId,
     clip_stack: Vec<ClipAndScrollInfo>,
-    next_clip_index: usize,
-    next_spatial_index: usize,
+    next_clip_id: usize,
     next_clip_chain_id: u64,
     builder_start_time: u64,
 
     /// The size of the content of this display list. This is used to allow scrolling
     /// outside the bounds of the display list items themselves.
     content_size: LayoutSize,
     save_state: Option<SaveState>,
 }
@@ -861,18 +845,17 @@ impl DisplayListBuilder {
         let start_time = precise_time_ns();
 
         DisplayListBuilder {
             data: Vec::with_capacity(capacity),
             pipeline_id,
             clip_stack: vec![
                 ClipAndScrollInfo::simple(ClipId::root_scroll_node(pipeline_id)),
             ],
-            next_clip_index: FIRST_CLIP_NODE_INDEX,
-            next_spatial_index: FIRST_SPATIAL_NODE_INDEX,
+            next_clip_id: FIRST_CLIP_ID,
             next_clip_chain_id: 0,
             builder_start_time: start_time,
             content_size,
             save_state: None,
         }
     }
 
     /// Return the content size for this display list
@@ -888,30 +871,28 @@ impl DisplayListBuilder {
     /// * Doesn't support nested saves.
     /// * Must call `clear_save()` if the restore becomes unnecessary.
     pub fn save(&mut self) {
         assert!(self.save_state.is_none(), "DisplayListBuilder doesn't support nested saves");
 
         self.save_state = Some(SaveState {
             clip_stack_len: self.clip_stack.len(),
             dl_len: self.data.len(),
-            next_clip_index: self.next_clip_index,
-            next_spatial_index: self.next_spatial_index,
+            next_clip_id: self.next_clip_id,
             next_clip_chain_id: self.next_clip_chain_id,
         });
     }
 
     /// Restores the state of the builder to when `save()` was last called.
     pub fn restore(&mut self) {
         let state = self.save_state.take().expect("No save to restore DisplayListBuilder from");
 
         self.clip_stack.truncate(state.clip_stack_len);
         self.data.truncate(state.dl_len);
-        self.next_clip_index = state.next_clip_index;
-        self.next_spatial_index = state.next_spatial_index;
+        self.next_clip_id = state.next_clip_id;
         self.next_clip_chain_id = state.next_clip_chain_id;
     }
 
     /// Discards the builder's save (indicating the attempted operation was successful).
     pub fn clear_save(&mut self) {
         self.save_state.take().expect("No save to clear in DisplayListBuilder");
     }
 
@@ -1302,17 +1283,17 @@ impl DisplayListBuilder {
     }
 
     pub fn push_reference_frame(
         &mut self,
         info: &LayoutPrimitiveInfo,
         transform: Option<PropertyBinding<LayoutTransform>>,
         perspective: Option<LayoutTransform>,
     ) -> ClipId {
-        let id = self.generate_spatial_index();
+        let id = self.generate_clip_id();
         let item = SpecificDisplayItem::PushReferenceFrame(PushReferenceFrameDisplayListItem {
             reference_frame: ReferenceFrame {
                 transform,
                 perspective,
                 id,
             },
         });
         self.push_item(item, info);
@@ -1352,24 +1333,19 @@ impl DisplayListBuilder {
     pub fn push_stops(&mut self, stops: &[GradientStop]) {
         if stops.is_empty() {
             return;
         }
         self.push_new_empty_item(SpecificDisplayItem::SetGradientStops);
         self.push_iter(stops);
     }
 
-    fn generate_clip_index(&mut self) -> ClipId {
-        self.next_clip_index += 1;
-        ClipId::Clip(self.next_clip_index - 1, self.pipeline_id)
-    }
-
-    fn generate_spatial_index(&mut self) -> ClipId {
-        self.next_spatial_index += 1;
-        ClipId::Spatial(self.next_spatial_index - 1, self.pipeline_id)
+    fn generate_clip_id(&mut self) -> ClipId {
+        self.next_clip_id += 1;
+        ClipId::Clip(self.next_clip_id - 1, self.pipeline_id)
     }
 
     fn generate_clip_chain_id(&mut self) -> ClipChainId {
         self.next_clip_chain_id += 1;
         ClipChainId(self.next_clip_chain_id - 1, self.pipeline_id)
     }
 
     pub fn define_scroll_frame<I>(
@@ -1405,18 +1381,18 @@ impl DisplayListBuilder {
         complex_clips: I,
         image_mask: Option<ImageMask>,
         scroll_sensitivity: ScrollSensitivity,
     ) -> ClipId
     where
         I: IntoIterator<Item = ComplexClipRegion>,
         I::IntoIter: ExactSizeIterator + Clone,
     {
-        let clip_id = self.generate_clip_index();
-        let scroll_frame_id = self.generate_spatial_index();
+        let clip_id = self.generate_clip_id();
+        let scroll_frame_id = self.generate_clip_id();
         let item = SpecificDisplayItem::ScrollFrame(ScrollFrameDisplayItem {
             clip_id,
             scroll_frame_id,
             external_id,
             image_mask,
             scroll_sensitivity,
         });
 
@@ -1470,17 +1446,17 @@ impl DisplayListBuilder {
         clip_rect: LayoutRect,
         complex_clips: I,
         image_mask: Option<ImageMask>,
     ) -> ClipId
     where
         I: IntoIterator<Item = ComplexClipRegion>,
         I::IntoIter: ExactSizeIterator + Clone,
     {
-        let id = self.generate_clip_index();
+        let id = self.generate_clip_id();
         let item = SpecificDisplayItem::Clip(ClipDisplayItem {
             id,
             image_mask,
         });
 
         let info = LayoutPrimitiveInfo::new(clip_rect);
 
         let scrollinfo = ClipAndScrollInfo::simple(parent);
@@ -1493,17 +1469,17 @@ impl DisplayListBuilder {
         &mut self,
         frame_rect: LayoutRect,
         margins: SideOffsets2D<Option<f32>>,
         vertical_offset_bounds: StickyOffsetBounds,
         horizontal_offset_bounds: StickyOffsetBounds,
         previously_applied_offset: LayoutVector2D,
 
     ) -> ClipId {
-        let id = self.generate_spatial_index();
+        let id = self.generate_clip_id();
         let item = SpecificDisplayItem::StickyFrame(StickyFrameDisplayItem {
             id,
             margins,
             vertical_offset_bounds,
             horizontal_offset_bounds,
             previously_applied_offset,
         });
 
@@ -1531,17 +1507,17 @@ impl DisplayListBuilder {
 
     pub fn push_iframe(
         &mut self,
         info: &LayoutPrimitiveInfo,
         pipeline_id: PipelineId,
         ignore_missing_pipeline: bool
     ) {
         let item = SpecificDisplayItem::Iframe(IframeDisplayItem {
-            clip_id: self.generate_clip_index(),
+            clip_id: self.generate_clip_id(),
             pipeline_id,
             ignore_missing_pipeline,
         });
         self.push_item(item, info);
     }
 
     pub fn push_shadow(&mut self, info: &LayoutPrimitiveInfo, shadow: Shadow) {
         self.push_item(SpecificDisplayItem::PushShadow(shadow), info);
@@ -1560,16 +1536,15 @@ impl DisplayListBuilder {
         (
             self.pipeline_id,
             self.content_size,
             BuiltDisplayList {
                 descriptor: BuiltDisplayListDescriptor {
                     builder_start_time: self.builder_start_time,
                     builder_finish_time: end_time,
                     send_start_time: 0,
-                    total_clip_nodes: self.next_clip_index,
-                    total_spatial_nodes: self.next_spatial_index,
+                    total_clip_ids: self.next_clip_id,
                 },
                 data: self.data,
             },
         )
     }
 }
--- a/gfx/webrender_bindings/Cargo.toml
+++ b/gfx/webrender_bindings/Cargo.toml
@@ -21,12 +21,12 @@ path = "../webrender"
 version = "0.57.2"
 default-features = false
 features = ["capture", "serialize_program"]
 
 [target.'cfg(target_os = "windows")'.dependencies]
 dwrote = "0.4.1"
 
 [target.'cfg(target_os = "macos")'.dependencies]
-core-foundation = "0.6"
-core-graphics = "0.14"
+core-foundation = "0.5"
+core-graphics = "0.13"
 foreign-types = "0.3.0"
 
--- a/gfx/webrender_bindings/revision.txt
+++ b/gfx/webrender_bindings/revision.txt
@@ -1,1 +1,1 @@
-e600bfe68efac6416ce2e8091d7344744771f6db
+0e9563688e575cd662570f54bc9d6f849040dbf8
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -1651,17 +1651,17 @@ pub extern "C" fn wr_dp_push_stacking_co
                                                                c_filter.argument,
                                                                c_filter.color),
             WrFilterOpType::ColorMatrix => FilterOp::ColorMatrix(c_filter.matrix),
         }
     }).collect();
 
     let clip_node_id_ref = unsafe { clip_node_id.as_ref() };
     let clip_node_id = match clip_node_id_ref {
-        Some(clip_node_id) => Some(unpack_clip_id(*clip_node_id, state.pipeline_id)),
+        Some(clip_node_id) => Some(ClipId::Clip(*clip_node_id, state.pipeline_id)),
         None => None,
     };
 
     let transform_ref = unsafe { transform.as_ref() };
     let mut transform_binding = match transform_ref {
         Some(transform) => Some(PropertyBinding::Value(transform.clone())),
         None => None,
     };
@@ -1705,17 +1705,23 @@ pub extern "C" fn wr_dp_push_stacking_co
 
     let mut prim_info = LayoutPrimitiveInfo::new(bounds);
 
     *out_is_reference_frame = transform_binding.is_some() || perspective.is_some();
     if *out_is_reference_frame {
         let ref_frame_id = state.frame_builder
             .dl_builder
             .push_reference_frame(&prim_info, transform_binding, perspective);
-        *out_reference_frame_id = pack_clip_id(ref_frame_id);
+        match ref_frame_id {
+            ClipId::Clip(id, pipeline_id) => {
+                assert!(pipeline_id == state.pipeline_id);
+                *out_reference_frame_id = id;
+            },
+            _ => panic!("Pushing a reference frame must produce a ClipId::Clip"),
+        }
 
         prim_info.rect.origin = LayoutPoint::zero();
         prim_info.clip_rect.origin = LayoutPoint::zero();
         state.frame_builder.dl_builder.push_clip_id(ref_frame_id);
     }
 
     prim_info.is_backface_visible = is_backface_visible;
     prim_info.tag = state.current_tag;
@@ -1744,21 +1750,17 @@ pub extern "C" fn wr_dp_pop_stacking_con
 #[no_mangle]
 pub extern "C" fn wr_dp_define_clipchain(state: &mut WrState,
                                          parent_clipchain_id: *const u64,
                                          clips: *const usize,
                                          clips_count: usize)
                                          -> u64 {
     debug_assert!(unsafe { is_in_main_thread() });
     let parent = unsafe { parent_clipchain_id.as_ref() }.map(|id| ClipChainId(*id, state.pipeline_id));
-    let clips_slice : Vec<ClipId> = make_slice(clips, clips_count)
-        .iter()
-        .map(|id| unpack_clip_id(*id, state.pipeline_id))
-        .collect();
-
+    let clips_slice : Vec<ClipId> = make_slice(clips, clips_count).iter().map(|id| ClipId::Clip(*id, state.pipeline_id)).collect();
     let clipchain_id = state.frame_builder.dl_builder.define_clip_chain(parent, clips_slice);
     assert!(clipchain_id.1 == state.pipeline_id);
     clipchain_id.0
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_define_clip(state: &mut WrState,
                                     parent_id: *const usize,
@@ -1771,29 +1773,36 @@ pub extern "C" fn wr_dp_define_clip(stat
 
     let parent_id = unsafe { parent_id.as_ref() };
     let complex_slice = make_slice(complex, complex_count);
     let complex_iter = complex_slice.iter().cloned();
     let mask : Option<ImageMask> = unsafe { mask.as_ref() }.map(|x| x.into());
 
     let clip_id = if let Some(&pid) = parent_id {
         state.frame_builder.dl_builder.define_clip_with_parent(
-            unpack_clip_id(pid, state.pipeline_id),
+            ClipId::Clip(pid, state.pipeline_id),
             clip_rect, complex_iter, mask)
     } else {
         state.frame_builder.dl_builder.define_clip(clip_rect, complex_iter, mask)
     };
-    pack_clip_id(clip_id)
+    // return the usize id value from inside the ClipId::Clip(..)
+    match clip_id {
+        ClipId::Clip(id, pipeline_id) => {
+            assert!(pipeline_id == state.pipeline_id);
+            id
+        },
+        _ => panic!("Got unexpected clip id type"),
+    }
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_clip(state: &mut WrState,
                                   clip_id: usize) {
     debug_assert!(unsafe { is_in_main_thread() });
-    state.frame_builder.dl_builder.push_clip_id(unpack_clip_id(clip_id, state.pipeline_id));
+    state.frame_builder.dl_builder.push_clip_id(ClipId::Clip(clip_id, state.pipeline_id));
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_clip(state: &mut WrState) {
     debug_assert!(unsafe { !is_in_render_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
 }
 
@@ -1812,33 +1821,39 @@ pub extern "C" fn wr_dp_define_sticky_fr
     let clip_id = state.frame_builder.dl_builder.define_sticky_frame(
         content_rect, SideOffsets2D::new(
             unsafe { top_margin.as_ref() }.cloned(),
             unsafe { right_margin.as_ref() }.cloned(),
             unsafe { bottom_margin.as_ref() }.cloned(),
             unsafe { left_margin.as_ref() }.cloned()
         ),
         vertical_bounds, horizontal_bounds, applied_offset);
-    pack_clip_id(clip_id)
+    match clip_id {
+        ClipId::Clip(id, pipeline_id) => {
+            assert!(pipeline_id == state.pipeline_id);
+            id
+        },
+        _ => panic!("Got unexpected clip id type"),
+    }
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_define_scroll_layer(state: &mut WrState,
                                             scroll_id: u64,
                                             parent_id: *const usize,
                                             content_rect: LayoutRect,
                                             clip_rect: LayoutRect)
                                             -> usize {
     assert!(unsafe { is_in_main_thread() });
 
     let parent_id = unsafe { parent_id.as_ref() };
 
     let new_id = if let Some(&pid) = parent_id {
         state.frame_builder.dl_builder.define_scroll_frame_with_parent(
-            unpack_clip_id(pid, state.pipeline_id),
+            ClipId::Clip(pid, state.pipeline_id),
             Some(ExternalScrollId(scroll_id, state.pipeline_id)),
             content_rect,
             clip_rect,
             vec![],
             None,
             ScrollSensitivity::Script
         )
     } else {
@@ -1847,24 +1862,30 @@ pub extern "C" fn wr_dp_define_scroll_la
             content_rect,
             clip_rect,
             vec![],
             None,
             ScrollSensitivity::Script
         )
     };
 
-    pack_clip_id(new_id)
+    match new_id {
+        ClipId::Clip(id, pipeline_id) => {
+            assert!(pipeline_id == state.pipeline_id);
+            id
+        },
+        _ => panic!("Got unexpected clip id type"),
+    }
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_scroll_layer(state: &mut WrState,
                                           scroll_id: usize) {
     debug_assert!(unsafe { is_in_main_thread() });
-    let clip_id = unpack_clip_id(scroll_id, state.pipeline_id);
+    let clip_id = ClipId::Clip(scroll_id, state.pipeline_id);
     state.frame_builder.dl_builder.push_clip_id(clip_id);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_scroll_layer(state: &mut WrState) {
     debug_assert!(unsafe { is_in_main_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
 }
@@ -1873,20 +1894,21 @@ pub extern "C" fn wr_dp_pop_scroll_layer
 pub extern "C" fn wr_dp_push_clip_and_scroll_info(state: &mut WrState,
                                                   scroll_id: usize,
                                                   clip_chain_id: *const u64) {
     debug_assert!(unsafe { is_in_main_thread() });
 
     let clip_chain_id = unsafe { clip_chain_id.as_ref() };
     let info = if let Some(&ccid) = clip_chain_id {
         ClipAndScrollInfo::new(
-            unpack_clip_id(scroll_id, state.pipeline_id),
+            ClipId::Clip(scroll_id, state.pipeline_id),
             ClipId::ClipChain(ClipChainId(ccid, state.pipeline_id)))
     } else {
-        ClipAndScrollInfo::simple(unpack_clip_id(scroll_id, state.pipeline_id))
+        ClipAndScrollInfo::simple(
+            ClipId::Clip(scroll_id, state.pipeline_id))
     };
     state.frame_builder.dl_builder.push_clip_and_scroll_info(info);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_pop_clip_and_scroll_info(state: &mut WrState) {
     debug_assert!(unsafe { is_in_main_thread() });
     state.frame_builder.dl_builder.pop_clip_id();
@@ -2436,32 +2458,13 @@ extern "C" {
                                output: MutByteSlice)
                                -> bool;
 }
 
 #[no_mangle]
 pub extern "C" fn wr_root_scroll_node_id() -> usize {
     // The PipelineId doesn't matter here, since we just want the numeric part of the id
     // produced for any given root reference frame.
-    pack_clip_id(ClipId::root_scroll_node(PipelineId(0, 0)))
-}
-
-fn pack_clip_id(id: ClipId) -> usize {
-    let (id, type_value) = match id {
-        ClipId::Spatial(id, _) => (id, 0),
-        ClipId::Clip(id, _) => (id, 1),
-        ClipId::ClipChain(..) => unreachable!("Tried to pack a clip chain id"),
-    };
-
-    assert!(id <= usize::max_value() >> 1);
-    return (id << 1) + type_value;
-}
-
-fn unpack_clip_id(id: usize, pipeline_id: PipelineId) -> ClipId {
-    let type_value = id & 0b01;
-    let id = id >> 1;
-
-    match type_value {
-        0 => ClipId::Spatial(id, pipeline_id),
-        1 => ClipId::Clip(id, pipeline_id),
-        _ => unreachable!("Got a bizarre value for the clip type"),
+    match ClipId::root_scroll_node(PipelineId(0, 0)) {
+        ClipId::Clip(id, _) => id,
+        _ => unreachable!("Got a non Clip ClipId for root reference frame."),
     }
 }
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -396,27 +396,24 @@ using LayoutSize = TypedSize2D<float, La
 // items.
 struct BuiltDisplayListDescriptor {
   // The first IPC time stamp: before any work has been done
   uint64_t builder_start_time;
   // The second IPC time stamp: after serialization
   uint64_t builder_finish_time;
   // The third IPC time stamp: just before sending
   uint64_t send_start_time;
-  // The amount of clipping nodes created while building this display list.
-  uintptr_t total_clip_nodes;
-  // The amount of spatial nodes created while building this display list.
-  uintptr_t total_spatial_nodes;
+  // The amount of clips ids assigned while building this display list.
+  uintptr_t total_clip_ids;
 
   bool operator==(const BuiltDisplayListDescriptor& aOther) const {
     return builder_start_time == aOther.builder_start_time &&
            builder_finish_time == aOther.builder_finish_time &&
            send_start_time == aOther.send_start_time &&
-           total_clip_nodes == aOther.total_clip_nodes &&
-           total_spatial_nodes == aOther.total_spatial_nodes;
+           total_clip_ids == aOther.total_clip_ids;
   }
 };
 
 struct WrVecU8 {
   uint8_t *data;
   uintptr_t length;
   uintptr_t capacity;
 
--- a/gfx/wrench/Cargo.toml
+++ b/gfx/wrench/Cargo.toml
@@ -7,40 +7,40 @@ license = "MPL-2.0"
 
 [dependencies]
 base64 = "0.6"
 bincode = "1.0"
 byteorder = "1.0"
 env_logger = { version = "0.5", optional = true }
 euclid = "0.17"
 gleam = "0.5"
-glutin = "0.17"
+glutin = "0.15"
 app_units = "0.6"
 image = "0.19"
 clap = { version = "2", features = ["yaml"] }
 lazy_static = "1"
 log = "0.4"
 yaml-rust = { git = "https://github.com/vvuk/yaml-rust", features = ["preserve_order"] }
 serde_json = "1.0"
 ron = "0.1.5"
 time = "0.1"
 crossbeam = "0.2"
 osmesa-sys = { version = "0.1.2", optional = true }
 osmesa-src = { git = "https://github.com/jrmuizel/osmesa-src", optional = true, branch = "serialize" }
 webrender = {path = "../webrender", features=["capture","replay","debugger","png","profiler"]}
 webrender_api = {path = "../webrender_api", features=["serialize","deserialize"]}
-winit = "0.16"
+winit = "0.13"
 serde = {version = "1.0", features = ["derive"] }
 
 [target.'cfg(target_os = "macos")'.dependencies]
-core-graphics = "0.14"
-core-foundation = "0.6"
+core-graphics = "0.13"
+core-foundation = "0.5"
 
 [features]
 headless = [ "osmesa-sys", "osmesa-src" ]
 pathfinder = [ "webrender/pathfinder" ]
 
 [target.'cfg(target_os = "windows")'.dependencies]
 dwrote = "0.4.1"
 mozangle = {version = "0.1.5", features = ["egl"]}
 
 [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
-font-loader = "0.7"
+font-loader = "0.6"
--- a/gfx/wrench/src/angle.rs
+++ b/gfx/wrench/src/angle.rs
@@ -1,15 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use glutin::{self, ContextBuilder, CreationError};
-#[cfg(not(windows))]
-use glutin::dpi::PhysicalSize;
 use winit::{EventsLoop, Window, WindowBuilder};
 
 #[cfg(not(windows))]
 pub enum Context {}
 
 #[cfg(windows)]
 pub use ::egl::Context;
 
@@ -62,13 +60,13 @@ impl glutin::GlContext for Context {
     fn get_api(&self) -> glutin::Api {
         match *self {}
     }
 
     fn get_pixel_format(&self) -> glutin::PixelFormat {
         match *self {}
     }
 
-    fn resize(&self, _: PhysicalSize) {
+    fn resize(&self, _: u32, _: u32) {
         match *self {}
     }
 }
 
--- a/gfx/wrench/src/egl.rs
+++ b/gfx/wrench/src/egl.rs
@@ -10,17 +10,16 @@ use glutin::CreationError;
 use glutin::GlAttributes;
 use glutin::GlContext;
 use glutin::GlRequest;
 use glutin::PixelFormat;
 use glutin::PixelFormatRequirements;
 use glutin::ReleaseBehavior;
 use glutin::Robustness;
 use glutin::Api;
-use glutin::dpi::PhysicalSize;
 
 use std::ffi::{CStr, CString};
 use std::os::raw::c_int;
 use std::{mem, ptr};
 use std::cell::Cell;
 
 use mozangle::egl::ffi as egl;
 mod ffi {
@@ -202,17 +201,17 @@ impl GlContext for Context {
     }
 
     #[inline]
     fn get_pixel_format(&self) -> PixelFormat {
         self.pixel_format.clone()
     }
 
     #[inline]
-    fn resize(&self, _: PhysicalSize) {}
+    fn resize(&self, _: u32, _: u32) {}
 }
 
 unsafe impl Send for Context {}
 unsafe impl Sync for Context {}
 
 impl Drop for Context {
     fn drop(&mut self) {
         unsafe {
--- a/gfx/wrench/src/main.rs
+++ b/gfx/wrench/src/main.rs
@@ -58,17 +58,16 @@ mod yaml_frame_reader;
 mod yaml_frame_writer;
 mod yaml_helper;
 #[cfg(target_os = "macos")]
 mod cgfont_to_data;
 
 use binary_frame_reader::BinaryFrameReader;
 use gleam::gl;
 use glutin::GlContext;
-use glutin::dpi::{LogicalPosition, LogicalSize};
 use perf::PerfHarness;
 use png::save_flipped;
 use rawtest::RawtestHarness;
 use reftest::{ReftestHarness, ReftestOptions};
 #[cfg(feature = "headless")]
 use std::ffi::CString;
 #[cfg(feature = "headless")]
 use std::mem;
@@ -179,49 +178,45 @@ impl WindowWrapper {
             WindowWrapper::Angle(_, ref context, _) => context.swap_buffers().unwrap(),
             WindowWrapper::Headless(_, _) => {}
         }
     }
 
     fn get_inner_size(&self) -> DeviceUintSize {
         //HACK: `winit` needs to figure out its hidpi story...
         #[cfg(target_os = "macos")]
-        fn inner_size(window: &winit::Window) -> LogicalSize {
-            let LogicalSize { width, height } = window.get_inner_size().unwrap();
-            let factor = window.get_hidpi_factor();
-            LogicalSize::new(width * factor, height * factor)
+        fn inner_size(window: &winit::Window) -> (u32, u32) {
+            let (w, h) = window.get_inner_size().unwrap();
+            let factor = window.hidpi_factor();
+            ((w as f32 * factor) as _, (h as f32 * factor) as _)
         }
         #[cfg(not(target_os = "macos"))]
-        fn inner_size(window: &winit::Window) -> LogicalSize {
+        fn inner_size(window: &winit::Window) -> (u32, u32) {
             window.get_inner_size().unwrap()
         }
-        let LogicalSize { width, height } = match *self {
+        let (w, h) = match *self {
             WindowWrapper::Window(ref window, _) => inner_size(window.window()),
             WindowWrapper::Angle(ref window, ..) => inner_size(window),
-            WindowWrapper::Headless(ref context, _) => LogicalSize::new(context.width as f64, context.height as f64),
+            WindowWrapper::Headless(ref context, _) => (context.width, context.height),
         };
-        DeviceUintSize::new(width as u32, height as u32)
+        DeviceUintSize::new(w, h)
     }
 
     fn hidpi_factor(&self) -> f32 {
         match *self {
-            WindowWrapper::Window(ref window, _) => window.get_hidpi_factor() as f32,
-            WindowWrapper::Angle(ref window, ..) => window.get_hidpi_factor() as f32,
+            WindowWrapper::Window(ref window, _) => window.hidpi_factor(),
+            WindowWrapper::Angle(ref window, ..) => window.hidpi_factor(),
             WindowWrapper::Headless(_, _) => 1.0,
         }
     }
 
     fn resize(&mut self, size: DeviceUintSize) {
         match *self {
-            WindowWrapper::Window(ref mut window, _) => {
-                window.set_inner_size(LogicalSize::new(size.width as f64, size.height as f64))
-            },
-            WindowWrapper::Angle(ref mut window, ..) => {
-                window.set_inner_size(LogicalSize::new(size.width as f64, size.height as f64))
-            },
+            WindowWrapper::Window(ref mut window, _) => window.set_inner_size(size.width, size.height),
+            WindowWrapper::Angle(ref mut window, ..) => window.set_inner_size(size.width, size.height),
             WindowWrapper::Headless(_, _) => unimplemented!(), // requites Glutin update
         }
     }
 
     fn set_title(&mut self, title: &str) {
         match *self {
             WindowWrapper::Window(ref window, _) => window.set_title(title),
             WindowWrapper::Angle(ref window, ..) => window.set_title(title),
@@ -259,17 +254,17 @@ fn make_window(
                 .with_gl(glutin::GlRequest::GlThenGles {
                     opengl_version: (3, 2),
                     opengles_version: (3, 0),
                 })
                 .with_vsync(vsync);
             let window_builder = winit::WindowBuilder::new()
                 .with_title("WRench")
                 .with_multitouch()
-                .with_dimensions(LogicalSize::new(size.width as f64, size.height as f64));
+                .with_dimensions(size.width, size.height);
 
             let init = |context: &glutin::GlContext| {
                 unsafe {
                     context
                         .make_current()
                         .expect("unable to make context current!");
                 }
 
@@ -583,17 +578,17 @@ fn render<'a>(
             winit::Event::WindowEvent { event, .. } => match event {
                 winit::WindowEvent::CloseRequested => {
                     return winit::ControlFlow::Break;
                 }
                 winit::WindowEvent::Refresh |
                 winit::WindowEvent::Focused(..) => {
                     do_render = true;
                 }
-                winit::WindowEvent::CursorMoved { position: LogicalPosition { x, y }, .. } => {
+                winit::WindowEvent::CursorMoved { position: (x, y), .. } => {
                     cursor_position = WorldPoint::new(x as f32, y as f32);
                     do_render = true;
                 }
                 winit::WindowEvent::KeyboardInput {
                     input: winit::KeyboardInput {
                         state: winit::ElementState::Pressed,
                         virtual_keycode: Some(vk),
                         ..
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/.cargo-checksum.json
@@ -0,0 +1,1 @@
+{"files":{"Cargo.toml":"01f34fc5a612332c1a3aca9fcd89cd254afa02a27e6e538b0a2fa4280ef4fa66","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","src/array.rs":"d7af185408d937354f484e3ef97cb1a56e06b39965cbdc89de4bcdafb1d57f06","src/base.rs":"3032ea5253b2d4bd323d0656fc863d1e787642121702ad741c6055d96d0b3d5c","src/boolean.rs":"f5b4d295aaf6cc3681212afebeae2974c5d551125badcc066e6089ac0d2a0873","src/bundle.rs":"de092198bbc3486f617131e9f5f321812c4839da505409abaa70217f05f40450","src/data.rs":"a1d7e6430c745731fc7b2aee49af9f14e79c8a288951c82ea6507689a3356af8","src/date.rs":"a02f6cca7b6e8fbabc7713177429012658dba5146556e14a08e7baaf81958d83","src/dictionary.rs":"429005bc00890b655c8bdf0d7361eb20187ba8725552261aeaf52690c3f2683f","src/error.rs":"22c21087d9c2c103d1bcb2c4af33b684317bbda5d4747902e510d410f8c1a14b","src/filedescriptor.rs":"6ecd8570fad620fc20726539fe11e9f914e3742af9f3208a31727e89a4cd92ba","src/lib.rs":"900179d9ada4b8f000ced4121a9981cdf5ea83277e812177f4126779b818f50c","src/number.rs":"0c2842b8ea973a2c12173a13544b7d49472df11e166540ca5c28f38f54a746f6","src/propertylist.rs":"2ef4b1f44f688fd49ab810a0c8eccc7c40320fa16f93ff1453edcd2fd0d7200f","src/runloop.rs":"bb400ffe84949c4faa4a91f196aeb0a88b31984d206cd236c9daf27005b7744a","src/set.rs":"f23edb8fc009c24600f017131ab734e91129907248713618be89a0719622a9e9","src/string.rs":"50c08f0504c718576e4f2397218a963ab701de0214422dc82e1991d4ab9a00e3","src/timezone.rs":"65859378232ee55f04bc4544b88f5dbc21f5db01bd16f2df3e82136ee3ce26b4","src/url.rs":"ee5370a1ba88823ee0eaa8615c5dafd55cedd7bd50172e9f2caa52ed305e2233","src/uuid.rs":"c532363a1a322a88e195f8606e613a68012708454b0d61ffe7abce432ec68596","tests/use_macro_outside_crate.rs":"452a1329d304bf0301929278aab275cc9b6d57e4ae799b4acd6f2210b1ed0a49"},"package":"286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/Cargo.toml
@@ -0,0 +1,39 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g. crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+name = "core-foundation"
+version = "0.5.1"
+authors = ["The Servo Project Developers"]
+description = "Bindings to Core Foundation for OS X"
+homepage = "https://github.com/servo/core-foundation-rs"
+license = "MIT / Apache-2.0"
+repository = "https://github.com/servo/core-foundation-rs"
+[dependencies.chrono]
+version = "0.4"
+optional = true
+
+[dependencies.core-foundation-sys]
+version = "0.5.1"
+
+[dependencies.libc]
+version = "0.2"
+
+[dependencies.uuid]
+version = "0.5"
+optional = true
+
+[features]
+mac_os_10_7_support = ["core-foundation-sys/mac_os_10_7_support"]
+mac_os_10_8_features = ["core-foundation-sys/mac_os_10_8_features"]
+with-chrono = ["chrono"]
+with-uuid = ["uuid"]
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/LICENSE-APACHE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2012-2013 Mozilla Foundation
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/array.rs
@@ -0,0 +1,289 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Heterogeneous immutable arrays.
+
+pub use core_foundation_sys::array::*;
+pub use core_foundation_sys::base::CFIndex;
+use core_foundation_sys::base::{CFTypeRef, CFRelease, kCFAllocatorDefault};
+use libc::c_void;
+use std::mem;
+use std::mem::ManuallyDrop;
+use std::marker::PhantomData;
+use std;
+use std::ops::Deref;
+use std::fmt::{Debug, Formatter};
+
+use base::{CFIndexConvertible, TCFType, TCFTypeRef, CFRange};
+
+/// A heterogeneous immutable array.
+pub struct CFArray<T = *const c_void>(CFArrayRef, PhantomData<T>);
+
+/// A reference to an element inside the array
+pub struct ItemRef<'a, T: 'a>(ManuallyDrop<T>, PhantomData<&'a T>);
+
+impl<'a, T> Deref for ItemRef<'a, T> {
+    type Target = T;
+
+    fn deref(&self) -> &T {
+        &self.0
+    }
+}
+
+impl<'a, T: Debug> Debug for ItemRef<'a, T> {
+    fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
+        self.0.fmt(f)
+    }
+}
+
+/// A trait describing how to convert from the stored *const c_void to the desired T
+pub unsafe trait FromVoid {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> where Self: std::marker::Sized;
+}
+
+unsafe impl FromVoid for u32 {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
+        // Functions like CGFontCopyTableTags treat the void*'s as u32's
+        // so we convert by casting directly
+        ItemRef(ManuallyDrop::new(x as u32), PhantomData)
+    }
+}
+
+unsafe impl<T: TCFType> FromVoid for T {
+    unsafe fn from_void<'a>(x: *const c_void) -> ItemRef<'a, Self> {
+        ItemRef(ManuallyDrop::new(TCFType::wrap_under_create_rule(T::Ref::from_void_ptr(x))), PhantomData)
+    }
+}
+
+impl<T> Drop for CFArray<T> {
+    fn drop(&mut self) {
+        unsafe { CFRelease(self.as_CFTypeRef()) }
+    }
+}
+
+pub struct CFArrayIterator<'a, T: 'a> {
+    array: &'a CFArray<T>,
+    index: CFIndex,
+    len: CFIndex,
+}
+
+impl<'a, T: FromVoid> Iterator for CFArrayIterator<'a, T> {
+    type Item = ItemRef<'a, T>;
+
+    fn next(&mut self) -> Option<ItemRef<'a, T>> {
+        if self.index >= self.len {
+            None
+        } else {
+            let value = unsafe { self.array.get_unchecked(self.index) };
+            self.index += 1;
+            Some(value)
+        }
+    }
+}
+
+impl<'a, T: FromVoid> ExactSizeIterator for CFArrayIterator<'a, T> {
+    fn len(&self) -> usize {
+        (self.array.len() - self.index) as usize
+    }
+}
+
+impl_TCFTypeGeneric!(CFArray, CFArrayRef, CFArrayGetTypeID);
+impl_CFTypeDescriptionGeneric!(CFArray);
+
+impl<T> CFArray<T> {
+    /// Creates a new `CFArray` with the given elements, which must be `CFType` objects.
+    pub fn from_CFTypes(elems: &[T]) -> CFArray<T> where T: TCFType {
+        unsafe {
+            let elems: Vec<CFTypeRef> = elems.iter().map(|elem| elem.as_CFTypeRef()).collect();
+            let array_ref = CFArrayCreate(kCFAllocatorDefault,
+                                          mem::transmute(elems.as_ptr()),
+                                          elems.len().to_CFIndex(),
+                                          &kCFTypeArrayCallBacks);
+            TCFType::wrap_under_create_rule(array_ref)
+        }
+    }
+
+    #[inline]
+    pub fn to_untyped(&self) -> CFArray {
+        unsafe { CFArray::wrap_under_get_rule(self.0) }
+    }
+
+    /// Returns the same array, but with the type reset to void pointers.
+    /// Equal to `to_untyped`, but is faster since it does not increment the retain count.
+    #[inline]
+    pub fn into_untyped(self) -> CFArray {
+        let reference = self.0;
+        mem::forget(self);
+        unsafe { CFArray::wrap_under_create_rule(reference) }
+    }
+
+    /// Iterates over the elements of this `CFArray`.
+    ///
+    /// Careful; the loop body must wrap the reference properly. Generally, when array elements are
+    /// Core Foundation objects (not always true), they need to be wrapped with
+    /// `TCFType::wrap_under_get_rule()`.
+    #[inline]
+    pub fn iter<'a>(&'a self) -> CFArrayIterator<'a, T> {
+        CFArrayIterator {
+            array: self,
+            index: 0,
+            len: self.len(),
+        }
+    }
+
+    #[inline]
+    pub fn len(&self) -> CFIndex {
+        unsafe {
+            CFArrayGetCount(self.0)
+        }
+    }
+
+    #[inline]
+    pub unsafe fn get_unchecked<'a>(&'a self, index: CFIndex) -> ItemRef<'a, T> where T: FromVoid {
+        T::from_void(CFArrayGetValueAtIndex(self.0, index))
+    }
+
+    #[inline]
+    pub fn get<'a>(&'a self, index: CFIndex) -> Option<ItemRef<'a, T>> where T: FromVoid {
+        if index < self.len() {
+            Some(unsafe { T::from_void(CFArrayGetValueAtIndex(self.0, index)) } )
+        } else {
+            None
+        }
+    }
+
+    pub fn get_values(&self, range: CFRange) -> Vec<*const c_void> {
+        let mut vec = Vec::with_capacity(range.length as usize);
+        unsafe {
+            CFArrayGetValues(self.0, range, vec.as_mut_ptr());
+            vec.set_len(range.length as usize);
+            vec
+        }
+    }
+
+    pub fn get_all_values(&self) -> Vec<*const c_void> {
+        self.get_values(CFRange {
+            location: 0,
+            length: self.len()
+        })
+    }
+}
+
+impl<'a, T: FromVoid> IntoIterator for &'a CFArray<T> {
+    type Item = ItemRef<'a, T>;
+    type IntoIter = CFArrayIterator<'a, T>;
+
+    fn into_iter(self) -> CFArrayIterator<'a, T> {
+        self.iter()
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::mem;
+    use base::CFType;
+
+    #[test]
+    fn to_untyped_correct_retain_count() {
+        let array = CFArray::<CFType>::from_CFTypes(&[]);
+        assert_eq!(array.retain_count(), 1);
+
+        let untyped_array = array.to_untyped();
+        assert_eq!(array.retain_count(), 2);
+        assert_eq!(untyped_array.retain_count(), 2);
+
+        mem::drop(array);
+        assert_eq!(untyped_array.retain_count(), 1);
+    }
+
+    #[test]
+    fn into_untyped() {
+        let array = CFArray::<CFType>::from_CFTypes(&[]);
+        let array2 = array.to_untyped();
+        assert_eq!(array.retain_count(), 2);
+
+        let untyped_array = array.into_untyped();
+        assert_eq!(untyped_array.retain_count(), 2);
+
+        mem::drop(array2);
+        assert_eq!(untyped_array.retain_count(), 1);
+    }
+
+    #[test]
+    fn borrow() {
+        use string::CFString;
+
+        let string = CFString::from_static_string("bar");
+        assert_eq!(string.retain_count(), 1);
+        let x;
+        {
+            let arr: CFArray<CFString> = CFArray::from_CFTypes(&[string]);
+            {
+                let p = arr.get(0).unwrap();
+                assert_eq!(p.retain_count(), 1);
+            }
+            {
+                x = arr.get(0).unwrap().clone();
+                assert_eq!(x.retain_count(), 2);
+                assert_eq!(x.to_string(), "bar");
+            }
+        }
+        assert_eq!(x.retain_count(), 1);
+    }
+
+    #[test]
+    fn should_box_and_unbox() {
+        use number::CFNumber;
+
+        let n0 = CFNumber::from(0);
+        let n1 = CFNumber::from(1);
+        let n2 = CFNumber::from(2);
+        let n3 = CFNumber::from(3);
+        let n4 = CFNumber::from(4);
+        let n5 = CFNumber::from(5);
+
+        let arr = CFArray::from_CFTypes(&[
+            n0.as_CFType(),
+            n1.as_CFType(),
+            n2.as_CFType(),
+            n3.as_CFType(),
+            n4.as_CFType(),
+            n5.as_CFType(),
+        ]);
+
+        assert!(arr.get_all_values() == &[n0.as_CFTypeRef(),
+                                        n1.as_CFTypeRef(),
+                                        n2.as_CFTypeRef(),
+                                        n3.as_CFTypeRef(),
+                                        n4.as_CFTypeRef(),
+                                        n5.as_CFTypeRef()]);
+
+        let mut sum = 0;
+
+        let mut iter = arr.iter();
+        assert_eq!(iter.len(), 6);
+        assert!(iter.next().is_some());
+        assert_eq!(iter.len(), 5);
+
+        for elem in iter {
+            let number: CFNumber = elem.downcast::<CFNumber>().unwrap();
+            sum += number.to_i64().unwrap()
+        }
+
+        assert!(sum == 15);
+
+        for elem in arr.iter() {
+            let number: CFNumber = elem.downcast::<CFNumber>().unwrap();
+            sum += number.to_i64().unwrap()
+        }
+
+        assert!(sum == 30);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/base.rs
@@ -0,0 +1,293 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::fmt;
+use std::mem;
+
+pub use core_foundation_sys::base::*;
+
+use string::CFString;
+
+pub trait CFIndexConvertible {
+    /// Always use this method to construct a `CFIndex` value. It performs bounds checking to
+    /// ensure the value is in range.
+    fn to_CFIndex(self) -> CFIndex;
+}
+
+impl CFIndexConvertible for usize {
+    #[inline]
+    fn to_CFIndex(self) -> CFIndex {
+        let max_CFIndex = CFIndex::max_value();
+        if self > (max_CFIndex as usize) {
+            panic!("value out of range")
+        }
+        self as CFIndex
+    }
+}
+
+declare_TCFType!{
+    /// Superclass of all Core Foundation objects.
+    CFType, CFTypeRef
+}
+
+impl CFType {
+    /// Try to downcast the `CFType` to a subclass. Checking if the instance is the
+    /// correct subclass happens at runtime and `None` is returned if it is not the correct type.
+    /// Works similar to [`Box::downcast`] and [`CFPropertyList::downcast`].
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// # use core_foundation::string::CFString;
+    /// # use core_foundation::boolean::CFBoolean;
+    /// # use core_foundation::base::{CFType, TCFType};
+    /// #
+    /// // Create a string.
+    /// let string: CFString = CFString::from_static_string("FooBar");
+    /// // Cast it up to a CFType.
+    /// let cf_type: CFType = string.as_CFType();
+    /// // Cast it down again.
+    /// assert!(cf_type.downcast::<CFString>().unwrap().to_string() == "FooBar");
+    /// // Casting it to some other type will yield `None`
+    /// assert!(cf_type.downcast::<CFBoolean>().is_none());
+    /// ```
+    ///
+    /// [`Box::downcast`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.downcast
+    /// [`CFPropertyList::downcast`]: ../propertylist/struct.CFPropertyList.html#method.downcast
+    #[inline]
+    pub fn downcast<T: TCFType>(&self) -> Option<T> {
+        if self.instance_of::<T>() {
+            unsafe {
+                let reference = T::Ref::from_void_ptr(self.0);
+                Some(T::wrap_under_get_rule(reference))
+            }
+        } else {
+            None
+        }
+    }
+
+    /// Similar to [`downcast`], but consumes self and can thus avoid touching the retain count.
+    ///
+    /// [`downcast`]: #method.downcast
+    #[inline]
+    pub fn downcast_into<T: TCFType>(self) -> Option<T> {
+        if self.instance_of::<T>() {
+            unsafe {
+                let reference = T::Ref::from_void_ptr(self.0);
+                mem::forget(self);
+                Some(T::wrap_under_create_rule(reference))
+            }
+        } else {
+            None
+        }
+    }
+}
+
+impl fmt::Debug for CFType {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        let desc = unsafe {
+            CFString::wrap_under_create_rule(CFCopyDescription(self.0))
+        };
+        desc.fmt(f)
+    }
+}
+
+impl Clone for CFType {
+    #[inline]
+    fn clone(&self) -> CFType {
+        unsafe {
+            TCFType::wrap_under_get_rule(self.0)
+        }
+    }
+}
+
+impl PartialEq for CFType {
+    #[inline]
+    fn eq(&self, other: &CFType) -> bool {
+        unsafe {
+            CFEqual(self.as_CFTypeRef(), other.as_CFTypeRef()) != 0
+        }
+    }
+}
+
+declare_TCFType!(CFAllocator, CFAllocatorRef);
+impl_TCFType!(CFAllocator, CFAllocatorRef, CFAllocatorGetTypeID);
+
+impl CFAllocator {
+    #[inline]
+    pub fn new(mut context: CFAllocatorContext) -> CFAllocator {
+        unsafe {
+            let allocator_ref = CFAllocatorCreate(kCFAllocatorDefault, &mut context);
+            TCFType::wrap_under_create_rule(allocator_ref)
+        }
+    }
+}
+
+
+/// All Core Foundation types implement this trait. The associated type `Ref` specifies the
+/// associated Core Foundation type: e.g. for `CFType` this is `CFTypeRef`; for `CFArray` this is
+/// `CFArrayRef`.
+pub trait TCFType {
+    /// The reference type wrapped inside this type.
+    type Ref: TCFTypeRef;
+
+    /// Returns the object as its concrete TypeRef.
+    fn as_concrete_TypeRef(&self) -> Self::Ref;
+
+    /// Returns an instance of the object, wrapping the underlying `CFTypeRef` subclass. Use this
+    /// when following Core Foundation's "Create Rule". The reference count is *not* bumped.
+    unsafe fn wrap_under_create_rule(obj: Self::Ref) -> Self;
+
+    /// Returns the type ID for this class.
+    fn type_id() -> CFTypeID;
+
+    /// Returns the object as a wrapped `CFType`. The reference count is incremented by one.
+    #[inline]
+    fn as_CFType(&self) -> CFType {
+        unsafe {
+            TCFType::wrap_under_get_rule(self.as_CFTypeRef())
+        }
+    }
+
+    /// Returns the object as a wrapped `CFType`. Consumes self and avoids changing the reference
+    /// count.
+    #[inline]
+    fn into_CFType(self) -> CFType
+    where
+        Self: Sized,
+    {
+        let reference = self.as_CFTypeRef();
+        mem::forget(self);
+        unsafe { TCFType::wrap_under_create_rule(reference) }
+    }
+
+    /// Returns the object as a raw `CFTypeRef`. The reference count is not adjusted.
+    fn as_CFTypeRef(&self) -> CFTypeRef;
+
+    /// Returns an instance of the object, wrapping the underlying `CFTypeRef` subclass. Use this
+    /// when following Core Foundation's "Get Rule". The reference count *is* bumped.
+    unsafe fn wrap_under_get_rule(reference: Self::Ref) -> Self;
+
+    /// Returns the reference count of the object. It is unwise to do anything other than test
+    /// whether the return value of this method is greater than zero.
+    #[inline]
+    fn retain_count(&self) -> CFIndex {
+        unsafe {
+            CFGetRetainCount(self.as_CFTypeRef())
+        }
+    }
+
+    /// Returns the type ID of this object.
+    #[inline]
+    fn type_of(&self) -> CFTypeID {
+        unsafe {
+            CFGetTypeID(self.as_CFTypeRef())
+        }
+    }
+
+    /// Writes a debugging version of this object on standard error.
+    fn show(&self) {
+        unsafe {
+            CFShow(self.as_CFTypeRef())
+        }
+    }
+
+    /// Returns true if this value is an instance of another type.
+    #[inline]
+    fn instance_of<OtherCFType: TCFType>(&self) -> bool {
+        self.type_of() == OtherCFType::type_id()
+    }
+}
+
+impl TCFType for CFType {
+    type Ref = CFTypeRef;
+
+    #[inline]
+    fn as_concrete_TypeRef(&self) -> CFTypeRef {
+        self.0
+    }
+
+    #[inline]
+    unsafe fn wrap_under_get_rule(reference: CFTypeRef) -> CFType {
+        let reference: CFTypeRef = CFRetain(reference);
+        TCFType::wrap_under_create_rule(reference)
+    }
+
+    #[inline]
+    fn as_CFTypeRef(&self) -> CFTypeRef {
+        self.as_concrete_TypeRef()
+    }
+
+    #[inline]
+    unsafe fn wrap_under_create_rule(obj: CFTypeRef) -> CFType {
+        CFType(obj)
+    }
+
+    #[inline]
+    fn type_id() -> CFTypeID {
+        // FIXME(pcwalton): Is this right?
+        0
+    }
+}
+
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::mem;
+    use boolean::CFBoolean;
+
+    #[test]
+    fn cftype_instance_of() {
+        let string = CFString::from_static_string("foo");
+        let cftype = string.as_CFType();
+
+        assert!(cftype.instance_of::<CFString>());
+        assert!(!cftype.instance_of::<CFBoolean>());
+    }
+
+    #[test]
+    fn as_cftype_retain_count() {
+        let string = CFString::from_static_string("bar");
+        assert_eq!(string.retain_count(), 1);
+        let cftype = string.as_CFType();
+        assert_eq!(cftype.retain_count(), 2);
+        mem::drop(string);
+        assert_eq!(cftype.retain_count(), 1);
+    }
+
+    #[test]
+    fn into_cftype_retain_count() {
+        let string = CFString::from_static_string("bar");
+        assert_eq!(string.retain_count(), 1);
+        let cftype = string.into_CFType();
+        assert_eq!(cftype.retain_count(), 1);
+    }
+
+    #[test]
+    fn as_cftype_and_downcast() {
+        let string = CFString::from_static_string("bar");
+        let cftype = string.as_CFType();
+        let string2 = cftype.downcast::<CFString>().unwrap();
+        assert_eq!(string2.to_string(), "bar");
+
+        assert_eq!(string.retain_count(), 3);
+        assert_eq!(cftype.retain_count(), 3);
+        assert_eq!(string2.retain_count(), 3);
+    }
+
+    #[test]
+    fn into_cftype_and_downcast_into() {
+        let string = CFString::from_static_string("bar");
+        let cftype = string.into_CFType();
+        let string2 = cftype.downcast_into::<CFString>().unwrap();
+        assert_eq!(string2.to_string(), "bar");
+        assert_eq!(string2.retain_count(), 1);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/boolean.rs
@@ -0,0 +1,70 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! A Boolean type.
+
+pub use core_foundation_sys::number::{CFBooleanRef, CFBooleanGetTypeID, kCFBooleanTrue, kCFBooleanFalse};
+
+use base::TCFType;
+
+
+declare_TCFType!{
+    /// A Boolean type.
+    ///
+    /// FIXME(pcwalton): Should be a newtype struct, but that fails due to a Rust compiler bug.
+    CFBoolean, CFBooleanRef
+}
+impl_TCFType!(CFBoolean, CFBooleanRef, CFBooleanGetTypeID);
+impl_CFTypeDescription!(CFBoolean);
+
+impl CFBoolean {
+    pub fn true_value() -> CFBoolean {
+        unsafe {
+            TCFType::wrap_under_get_rule(kCFBooleanTrue)
+        }
+    }
+
+    pub fn false_value() -> CFBoolean {
+        unsafe {
+            TCFType::wrap_under_get_rule(kCFBooleanFalse)
+        }
+    }
+}
+
+impl From<bool> for CFBoolean {
+    fn from(value: bool) -> CFBoolean {
+        if value {
+            CFBoolean::true_value()
+        } else {
+            CFBoolean::false_value()
+        }
+    }
+}
+
+impl From<CFBoolean> for bool {
+    fn from(value: CFBoolean) -> bool {
+        value.0 == unsafe { kCFBooleanTrue }
+    }
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn to_and_from_bool() {
+        let b_false = CFBoolean::from(false);
+        let b_true = CFBoolean::from(true);
+        assert_ne!(b_false, b_true);
+        assert_eq!(b_false, CFBoolean::false_value());
+        assert_eq!(b_true, CFBoolean::true_value());
+        assert!(!bool::from(b_false));
+        assert!(bool::from(b_true));
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/bundle.rs
@@ -0,0 +1,122 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation Bundle Type
+
+pub use core_foundation_sys::bundle::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+use url::CFURL;
+use dictionary::CFDictionary;
+
+
+declare_TCFType!{
+    /// A Bundle type.
+    CFBundle, CFBundleRef
+}
+impl_TCFType!(CFBundle, CFBundleRef, CFBundleGetTypeID);
+
+impl CFBundle {
+    pub fn new(bundleURL: CFURL) -> Option<CFBundle> {
+        unsafe {
+            let bundle_ref = CFBundleCreate(kCFAllocatorDefault, bundleURL.as_concrete_TypeRef());
+            if bundle_ref.is_null() {
+                None
+            } else {
+                Some(TCFType::wrap_under_create_rule(bundle_ref))
+            }
+        }
+    }
+
+    pub fn main_bundle() -> CFBundle {
+        unsafe {
+            let bundle_ref = CFBundleGetMainBundle();
+            TCFType::wrap_under_get_rule(bundle_ref)
+        }
+    }
+
+    pub fn info_dictionary(&self) -> CFDictionary {
+        unsafe {
+            let info_dictionary = CFBundleGetInfoDictionary(self.0);
+            TCFType::wrap_under_get_rule(info_dictionary)
+        }
+    }
+
+    pub fn executable_url(&self) -> Option<CFURL> {
+        unsafe {
+            let exe_url = CFBundleCopyExecutableURL(self.0);
+            if exe_url.is_null() {
+                None
+            } else {
+                Some(TCFType::wrap_under_create_rule(exe_url))
+            }
+        }
+    }
+
+    pub fn private_frameworks_url(&self) -> Option<CFURL> {
+        unsafe {
+            let fw_url = CFBundleCopyPrivateFrameworksURL(self.0);
+            if fw_url.is_null() {
+                None
+            } else {
+                Some(TCFType::wrap_under_create_rule(fw_url))
+            }
+        }
+    }
+}
+
+
+#[test]
+fn safari_executable_url() {
+    use string::CFString;
+    use url::{CFURL, kCFURLPOSIXPathStyle};
+
+    let cfstr_path = CFString::from_static_string("/Applications/Safari.app");
+    let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    let cfurl_executable = CFBundle::new(cfurl_path)
+        .expect("Safari not present")
+        .executable_url();
+    assert!(cfurl_executable.is_some());
+    assert_eq!(cfurl_executable
+                   .unwrap()
+                   .absolute()
+                   .get_file_system_path(kCFURLPOSIXPathStyle)
+                   .to_string(),
+               "/Applications/Safari.app/Contents/MacOS/Safari");
+}
+
+#[test]
+fn safari_private_frameworks_url() {
+    use string::CFString;
+    use url::{CFURL, kCFURLPOSIXPathStyle};
+
+    let cfstr_path = CFString::from_static_string("/Applications/Safari.app");
+    let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    let cfurl_executable = CFBundle::new(cfurl_path)
+        .expect("Safari not present")
+        .private_frameworks_url();
+    assert!(cfurl_executable.is_some());
+    assert_eq!(cfurl_executable
+                   .unwrap()
+                   .absolute()
+                   .get_file_system_path(kCFURLPOSIXPathStyle)
+                   .to_string(),
+               "/Applications/Safari.app/Contents/Frameworks");
+}
+
+#[test]
+fn non_existant_bundle() {
+    use string::CFString;
+    use url::{CFURL, kCFURLPOSIXPathStyle};
+
+    let cfstr_path = CFString::from_static_string("/usr/local/foo");
+    let cfurl_path = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    assert!(CFBundle::new(cfurl_path).is_none());
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/data.rs
@@ -0,0 +1,63 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation byte buffers.
+
+pub use core_foundation_sys::data::*;
+use core_foundation_sys::base::CFIndex;
+use core_foundation_sys::base::{kCFAllocatorDefault};
+use std::ops::Deref;
+use std::slice;
+
+use base::{CFIndexConvertible, TCFType};
+
+
+declare_TCFType!{
+    /// A byte buffer.
+    CFData, CFDataRef
+}
+impl_TCFType!(CFData, CFDataRef, CFDataGetTypeID);
+impl_CFTypeDescription!(CFData);
+
+impl CFData {
+    pub fn from_buffer(buffer: &[u8]) -> CFData {
+        unsafe {
+            let data_ref = CFDataCreate(kCFAllocatorDefault,
+                                        buffer.as_ptr(),
+                                        buffer.len().to_CFIndex());
+            TCFType::wrap_under_create_rule(data_ref)
+        }
+    }
+
+    /// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is
+    /// read-only.
+    #[inline]
+    pub fn bytes<'a>(&'a self) -> &'a [u8] {
+        unsafe {
+            slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize)
+        }
+    }
+
+    /// Returns the length of this byte buffer.
+    #[inline]
+    pub fn len(&self) -> CFIndex {
+        unsafe {
+            CFDataGetLength(self.0)
+        }
+    }
+}
+
+impl Deref for CFData {
+    type Target = [u8];
+
+    #[inline]
+    fn deref(&self) -> &[u8] {
+        self.bytes()
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/date.rs
@@ -0,0 +1,130 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation date objects.
+
+pub use core_foundation_sys::date::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+
+#[cfg(feature = "with-chrono")]
+use chrono::NaiveDateTime;
+
+
+declare_TCFType!{
+    /// A date.
+    CFDate, CFDateRef
+}
+impl_TCFType!(CFDate, CFDateRef, CFDateGetTypeID);
+impl_CFTypeDescription!(CFDate);
+impl_CFComparison!(CFDate, CFDateCompare);
+
+impl CFDate {
+    #[inline]
+    pub fn new(time: CFAbsoluteTime) -> CFDate {
+        unsafe {
+            let date_ref = CFDateCreate(kCFAllocatorDefault, time);
+            TCFType::wrap_under_create_rule(date_ref)
+        }
+    }
+
+    #[inline]
+    pub fn now() -> CFDate {
+        CFDate::new(unsafe { CFAbsoluteTimeGetCurrent() })
+    }
+
+    #[inline]
+    pub fn abs_time(&self) -> CFAbsoluteTime {
+        unsafe {
+            CFDateGetAbsoluteTime(self.0)
+        }
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn naive_utc(&self) -> NaiveDateTime {
+        let ts = unsafe {
+            self.abs_time() + kCFAbsoluteTimeIntervalSince1970
+        };
+        let (secs, nanos) = if ts.is_sign_positive() {
+            (ts.trunc() as i64, ts.fract())
+        } else {
+            // nanoseconds can't be negative in NaiveDateTime
+            (ts.trunc() as i64 - 1, 1.0 - ts.fract().abs())
+        };
+        NaiveDateTime::from_timestamp(secs, (nanos * 1e9).floor() as u32)
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn from_naive_utc(time: NaiveDateTime) -> CFDate {
+        let secs = time.timestamp();
+        let nanos = time.timestamp_subsec_nanos();
+        let ts = unsafe {
+            secs as f64 + (nanos as f64 / 1e9) - kCFAbsoluteTimeIntervalSince1970
+        };
+        CFDate::new(ts)
+    }
+}
+
+#[cfg(test)]
+mod test {
+    use super::CFDate;
+    use std::cmp::Ordering;
+
+    #[cfg(feature = "with-chrono")]
+    use chrono::NaiveDateTime;
+
+    #[cfg(feature = "with-chrono")]
+    fn approx_eq(a: f64, b: f64) -> bool {
+        use std::f64;
+
+        let same_sign = a.is_sign_positive() == b.is_sign_positive();
+        let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON;
+        (same_sign && equal)
+    }
+
+    #[test]
+    fn date_comparison() {
+        let now = CFDate::now();
+        let past = CFDate::new(now.abs_time() - 1.0);
+        assert_eq!(now.cmp(&past), Ordering::Greater);
+        assert_eq!(now.cmp(&now), Ordering::Equal);
+        assert_eq!(past.cmp(&now), Ordering::Less);
+    }
+
+    #[test]
+    fn date_equality() {
+        let now = CFDate::now();
+        let same_time = CFDate::new(now.abs_time());
+        assert_eq!(now, same_time);
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn date_chrono_conversion_positive() {
+        let date = CFDate::now();
+        let datetime = date.naive_utc();
+        let converted = CFDate::from_naive_utc(datetime);
+        assert!(approx_eq(date.abs_time(), converted.abs_time()));
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn date_chrono_conversion_negative() {
+        use super::kCFAbsoluteTimeIntervalSince1970;
+
+        let ts = unsafe {
+            kCFAbsoluteTimeIntervalSince1970 - 420.0
+        };
+        let date = CFDate::new(ts);
+        let datetime: NaiveDateTime = date.naive_utc();
+        let converted = CFDate::from_naive_utc(datetime);
+        assert!(approx_eq(date.abs_time(), converted.abs_time()));
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/dictionary.rs
@@ -0,0 +1,391 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Dictionaries of key-value pairs.
+
+pub use core_foundation_sys::dictionary::*;
+
+use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault};
+use libc::c_void;
+use std::mem;
+use std::ptr;
+
+use base::{CFType, CFIndexConvertible, TCFType, TCFTypeRef};
+
+
+declare_TCFType!{
+    /// An immutable dictionary of key-value pairs.
+    CFDictionary, CFDictionaryRef
+}
+impl_TCFType!(CFDictionary, CFDictionaryRef, CFDictionaryGetTypeID);
+impl_CFTypeDescription!(CFDictionary);
+
+impl CFDictionary {
+    pub fn from_CFType_pairs<K: TCFType, V: TCFType>(pairs: &[(K, V)]) -> CFDictionary {
+        let (keys, values): (Vec<CFTypeRef>, Vec<CFTypeRef>) = pairs
+            .iter()
+            .map(|&(ref key, ref value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
+            .unzip();
+
+        unsafe {
+            let dictionary_ref = CFDictionaryCreate(kCFAllocatorDefault,
+                                                    mem::transmute(keys.as_ptr()),
+                                                    mem::transmute(values.as_ptr()),
+                                                    keys.len().to_CFIndex(),
+                                                    &kCFTypeDictionaryKeyCallBacks,
+                                                    &kCFTypeDictionaryValueCallBacks);
+            TCFType::wrap_under_create_rule(dictionary_ref)
+        }
+    }
+
+    #[inline]
+    pub fn len(&self) -> usize {
+        unsafe {
+            CFDictionaryGetCount(self.0) as usize
+        }
+    }
+
+    #[inline]
+    pub fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
+
+    #[inline]
+    pub fn contains_key(&self, key: *const c_void) -> bool {
+        unsafe { CFDictionaryContainsKey(self.0, key) != 0 }
+    }
+
+    /// Similar to `contains_key` but acts on a higher level, automatically converting from any
+    /// `TCFType` to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn contains_key2<K: TCFType>(&self, key: &K) -> bool {
+        self.contains_key(key.as_concrete_TypeRef().as_void_ptr())
+    }
+
+    #[inline]
+    pub fn find(&self, key: *const c_void) -> Option<*const c_void> {
+        unsafe {
+            let mut value: *const c_void = ptr::null();
+            if CFDictionaryGetValueIfPresent(self.0, key, &mut value) != 0 {
+                Some(value)
+            } else {
+                None
+            }
+        }
+    }
+
+    /// Similar to `find` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn find2<K: TCFType>(&self, key: &K) -> Option<*const c_void> {
+        self.find(key.as_concrete_TypeRef().as_void_ptr())
+    }
+
+    /// # Panics
+    ///
+    /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
+    /// of panicking.
+    #[inline]
+    pub fn get(&self, key: *const c_void) -> *const c_void {
+        self.find(key).expect(&format!("No entry found for key {:p}", key))
+    }
+
+    /// A convenience function to retrieve `CFType` instances.
+    #[inline]
+    pub unsafe fn get_CFType(&self, key: *const c_void) -> CFType {
+        let value: CFTypeRef = mem::transmute(self.get(key));
+        TCFType::wrap_under_get_rule(value)
+    }
+
+    pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) {
+        let length = self.len();
+        let mut keys = Vec::with_capacity(length);
+        let mut values = Vec::with_capacity(length);
+
+        unsafe {
+            CFDictionaryGetKeysAndValues(self.0, keys.as_mut_ptr(), values.as_mut_ptr());
+            keys.set_len(length);
+            values.set_len(length);
+        }
+
+        (keys, values)
+    }
+}
+
+declare_TCFType!{
+    /// An mutable dictionary of key-value pairs.
+    CFMutableDictionary, CFMutableDictionaryRef
+}
+
+impl_TCFType!(CFMutableDictionary, CFMutableDictionaryRef, CFDictionaryGetTypeID);
+impl_CFTypeDescription!(CFMutableDictionary);
+
+impl CFMutableDictionary {
+    pub fn new() -> Self {
+        Self::with_capacity(0)
+    }
+
+    pub fn with_capacity(capacity: isize) -> Self {
+        unsafe {
+            let dictionary_ref = CFDictionaryCreateMutable(kCFAllocatorDefault,
+                                                           capacity as _,
+                                                           &kCFTypeDictionaryKeyCallBacks,
+                                                           &kCFTypeDictionaryValueCallBacks);
+            TCFType::wrap_under_create_rule(dictionary_ref)
+        }
+    }
+
+    pub fn copy_with_capacity(&self, capacity: isize) -> Self {
+        unsafe {
+            let dictionary_ref = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, capacity as _, self.0);
+            TCFType::wrap_under_get_rule(dictionary_ref)
+        }
+    }
+
+    pub fn from_CFType_pairs<K: TCFType, V: TCFType>(pairs: &[(K, V)]) -> CFMutableDictionary {
+        let result = Self::with_capacity(pairs.len() as _);
+        unsafe {
+            for &(ref key, ref value) in pairs {
+                result.add(key.as_CFTypeRef(), value.as_CFTypeRef());
+            }
+        }
+        result
+    }
+
+    // Immutable interface
+
+    #[inline]
+    pub fn len(&self) -> usize {
+        unsafe {
+            CFDictionaryGetCount(self.0) as usize
+        }
+    }
+
+    #[inline]
+    pub fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
+
+    #[inline]
+    pub fn contains_key(&self, key: *const c_void) -> bool {
+        unsafe {
+            CFDictionaryContainsKey(self.0, key) != 0
+        }
+    }
+
+    /// Similar to `contains_key` but acts on a higher level, automatically converting from any
+    /// `TCFType` to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn contains_key2<K: TCFType>(&self, key: &K) -> bool {
+        self.contains_key(key.as_concrete_TypeRef().as_void_ptr())
+    }
+
+    #[inline]
+    pub fn find(&self, key: *const c_void) -> Option<*const c_void> {
+        unsafe {
+            let mut value: *const c_void = ptr::null();
+            if CFDictionaryGetValueIfPresent(self.0, key, &mut value) != 0 {
+                Some(value)
+            } else {
+                None
+            }
+        }
+    }
+
+    /// Similar to `find` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn find2<K: TCFType>(&self, key: &K) -> Option<*const c_void> {
+        self.find(key.as_concrete_TypeRef().as_void_ptr())
+    }
+
+    /// # Panics
+    ///
+    /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
+    /// of panicking.
+    #[inline]
+    pub fn get(&self, key: *const c_void) -> *const c_void {
+        self.find(key).expect(&format!("No entry found for key {:p}", key))
+    }
+
+    /// A convenience function to retrieve `CFType` instances.
+    #[inline]
+    pub unsafe fn get_CFType(&self, key: *const c_void) -> CFType {
+        let value: CFTypeRef = mem::transmute(self.get(key));
+        TCFType::wrap_under_get_rule(value)
+    }
+
+    pub fn get_keys_and_values(&self) -> (Vec<*const c_void>, Vec<*const c_void>) {
+        let length = self.len();
+        let mut keys = Vec::with_capacity(length);
+        let mut values = Vec::with_capacity(length);
+
+        unsafe {
+            CFDictionaryGetKeysAndValues(self.0, keys.as_mut_ptr(), values.as_mut_ptr());
+            keys.set_len(length);
+            values.set_len(length);
+        }
+
+        (keys, values)
+    }
+
+    // Mutable interface
+
+    /// Adds the key-value pair to the dictionary if no such key already exist.
+    #[inline]
+    pub unsafe fn add(&self, key: *const c_void, value: *const c_void) {
+        CFDictionaryAddValue(self.0, key, value)
+    }
+
+    /// Similar to `add` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn add2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
+        unsafe {
+            self.add(
+                key.as_concrete_TypeRef().as_void_ptr(),
+                value.as_concrete_TypeRef().as_void_ptr(),
+            )
+        }
+    }
+
+    /// Sets the value of the key in the dictionary.
+    #[inline]
+    pub unsafe fn set(&self, key: *const c_void, value: *const c_void) {
+        CFDictionarySetValue(self.0, key, value)
+    }
+
+    /// Similar to `set` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn set2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
+        unsafe {
+            self.set(
+                key.as_concrete_TypeRef().as_void_ptr(),
+                value.as_concrete_TypeRef().as_void_ptr(),
+            )
+        }
+    }
+
+    /// Replaces the value of the key in the dictionary.
+    #[inline]
+    pub unsafe fn replace(&self, key: *const c_void, value: *const c_void) {
+        CFDictionaryReplaceValue(self.0, key, value)
+    }
+
+    /// Similar to `replace` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn replace2<K: TCFType, V: TCFType>(&self, key: &K, value: &V) {
+        unsafe {
+            self.replace(
+                key.as_concrete_TypeRef().as_void_ptr(),
+                value.as_concrete_TypeRef().as_void_ptr(),
+            )
+        }
+    }
+
+    /// Removes the value of the key from the dictionary.
+    #[inline]
+    pub unsafe fn remove(&self, key: *const c_void) {
+        CFDictionaryRemoveValue(self.0, key);
+    }
+
+    /// Similar to `remove` but acts on a higher level, automatically converting from any `TCFType`
+    /// to the raw pointer of its concrete TypeRef.
+    #[inline]
+    pub fn remove2<K: TCFType>(&self, key: &K) {
+        unsafe { self.remove(key.as_concrete_TypeRef().as_void_ptr()) }
+    }
+
+    #[inline]
+    pub fn remove_all(&self) {
+        unsafe { CFDictionaryRemoveAllValues(self.0) }
+    }
+}
+
+
+#[cfg(test)]
+pub mod test {
+    use super::*;
+    use base::TCFType;
+    use boolean::{CFBoolean, CFBooleanRef};
+    use number::CFNumber;
+    use string::CFString;
+
+
+    #[test]
+    fn dictionary() {
+        let bar = CFString::from_static_string("Bar");
+        let baz = CFString::from_static_string("Baz");
+        let boo = CFString::from_static_string("Boo");
+        let foo = CFString::from_static_string("Foo");
+        let tru = CFBoolean::true_value();
+        let n42 = CFNumber::from(42);
+
+        let d = CFDictionary::from_CFType_pairs(&[
+            (bar.as_CFType(), boo.as_CFType()),
+            (baz.as_CFType(), tru.as_CFType()),
+            (foo.as_CFType(), n42.as_CFType()),
+        ]);
+
+        let (v1, v2) = d.get_keys_and_values();
+        assert!(v1 == &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()]);
+        assert!(v2 == &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()]);
+    }
+
+    #[test]
+    fn mutable_dictionary() {
+        let bar = CFString::from_static_string("Bar");
+        let baz = CFString::from_static_string("Baz");
+        let boo = CFString::from_static_string("Boo");
+        let foo = CFString::from_static_string("Foo");
+        let tru = CFBoolean::true_value();
+        let n42 = CFNumber::from(42);
+
+        let d = CFMutableDictionary::new();
+        d.add2(&bar, &boo);
+        d.add2(&baz, &tru);
+        d.add2(&foo, &n42);
+        assert_eq!(d.len(), 3);
+
+        let (v1, v2) = d.get_keys_and_values();
+        assert!(v1 == &[bar.as_CFTypeRef(), baz.as_CFTypeRef(), foo.as_CFTypeRef()]);
+        assert!(v2 == &[boo.as_CFTypeRef(), tru.as_CFTypeRef(), n42.as_CFTypeRef()]);
+
+        d.remove2(&baz);
+        assert_eq!(d.len(), 2);
+
+        let (v1, v2) = d.get_keys_and_values();
+        assert!(v1 == &[bar.as_CFTypeRef(), foo.as_CFTypeRef()]);
+        assert!(v2 == &[boo.as_CFTypeRef(), n42.as_CFTypeRef()]);
+
+        d.remove_all();
+        assert_eq!(d.len(), 0)
+    }
+
+    #[test]
+    fn dict_find2_and_contains_key2() {
+        let dict = CFDictionary::from_CFType_pairs(&[
+            (
+                CFString::from_static_string("hello"),
+                CFBoolean::true_value(),
+            ),
+        ]);
+        let key = CFString::from_static_string("hello");
+        let invalid_key = CFString::from_static_string("foobar");
+
+        assert!(dict.contains_key2(&key));
+        assert!(!dict.contains_key2(&invalid_key));
+
+        let value = unsafe { CFBoolean::wrap_under_get_rule(dict.find2(&key).unwrap() as CFBooleanRef) };
+        assert_eq!(value, CFBoolean::true_value());
+        assert_eq!(dict.find2(&invalid_key), None);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/error.rs
@@ -0,0 +1,71 @@
+// Copyright 2016 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation errors.
+
+pub use core_foundation_sys::error::*;
+
+use std::error::Error;
+use std::fmt;
+
+use base::{CFIndex, TCFType};
+use string::CFString;
+
+
+declare_TCFType!{
+    /// An error value.
+    CFError, CFErrorRef
+}
+impl_TCFType!(CFError, CFErrorRef, CFErrorGetTypeID);
+
+impl fmt::Debug for CFError {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        fmt.debug_struct("CFError")
+           .field("domain", &self.domain())
+           .field("code", &self.code())
+           .field("description", &self.description())
+           .finish()
+    }
+}
+
+impl fmt::Display for CFError {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        write!(fmt, "{}", self.description())
+    }
+}
+
+impl Error for CFError {
+    fn description(&self) -> &str {
+        "a Core Foundation error"
+    }
+}
+
+impl CFError {
+    /// Returns a string identifying the domain with which this error is
+    /// associated.
+    pub fn domain(&self) -> CFString {
+        unsafe {
+            let s = CFErrorGetDomain(self.0);
+            CFString::wrap_under_get_rule(s)
+        }
+    }
+
+    /// Returns the code identifying this type of error.
+    pub fn code(&self) -> CFIndex {
+        unsafe { CFErrorGetCode(self.0) }
+    }
+
+    /// Returns a human-presentable description of the error.
+    pub fn description(&self) -> CFString {
+        unsafe {
+            let s = CFErrorCopyDescription(self.0);
+            CFString::wrap_under_create_rule(s)
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/filedescriptor.rs
@@ -0,0 +1,200 @@
+pub use core_foundation_sys::filedescriptor::*;
+
+use core_foundation_sys::base::{Boolean, CFIndex};
+use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags};
+
+use base::TCFType;
+use runloop::CFRunLoopSource;
+
+use std::mem;
+use std::os::unix::io::{AsRawFd, RawFd};
+use std::ptr;
+
+declare_TCFType!{
+    CFFileDescriptor, CFFileDescriptorRef
+}
+impl_TCFType!(CFFileDescriptor, CFFileDescriptorRef, CFFileDescriptorGetTypeID);
+
+impl CFFileDescriptor {
+    pub fn new(fd: RawFd,
+               closeOnInvalidate: bool,
+               callout: CFFileDescriptorCallBack,
+               context: Option<&CFFileDescriptorContext>) -> Option<CFFileDescriptor> {
+        let context = context.map_or(ptr::null(), |c| c as *const _);
+        unsafe {
+            let fd_ref = CFFileDescriptorCreate(kCFAllocatorDefault,
+                                                fd,
+                                                closeOnInvalidate as Boolean,
+                                                callout,
+                                                context);
+            if fd_ref.is_null() {
+                None
+            } else {
+                Some(TCFType::wrap_under_create_rule(fd_ref))
+            }
+        }
+    }
+
+    pub fn context(&self) -> CFFileDescriptorContext {
+        unsafe {
+            let mut context: CFFileDescriptorContext = mem::uninitialized();
+            CFFileDescriptorGetContext(self.0, &mut context);
+            context
+        }
+    }
+
+    pub fn enable_callbacks(&self, callback_types: CFOptionFlags) {
+        unsafe {
+            CFFileDescriptorEnableCallBacks(self.0, callback_types)
+        }
+    }
+
+    pub fn disable_callbacks(&self, callback_types: CFOptionFlags) {
+        unsafe {
+            CFFileDescriptorDisableCallBacks(self.0, callback_types)
+        }
+    }
+
+    pub fn valid(&self) -> bool {
+        unsafe {
+            CFFileDescriptorIsValid(self.0) != 0
+        }
+    }
+
+    pub fn invalidate(&self) {
+        unsafe {
+            CFFileDescriptorInvalidate(self.0)
+        }
+    }
+
+    pub fn to_run_loop_source(&self, order: CFIndex) -> Option<CFRunLoopSource> {
+        unsafe {
+            let source_ref = CFFileDescriptorCreateRunLoopSource(
+                kCFAllocatorDefault,
+                self.0,
+                order
+            );
+            if source_ref.is_null() {
+                None
+            } else {
+                Some(TCFType::wrap_under_create_rule(source_ref))
+            }
+        }
+    }
+}
+
+impl AsRawFd for CFFileDescriptor {
+    fn as_raw_fd(&self) -> RawFd {
+        unsafe {
+            CFFileDescriptorGetNativeDescriptor(self.0)
+        }
+    }
+}
+
+
+#[cfg(test)]
+mod test {
+    extern crate libc;
+
+    use super::*;
+    use std::ffi::CString;
+    use libc::{c_void, O_RDWR};
+    use core_foundation_sys::base::{CFOptionFlags};
+    use core_foundation_sys::runloop::{kCFRunLoopDefaultMode};
+    use runloop::{CFRunLoop};
+
+    #[test]
+    fn test_consumed() {
+        let path = CString::new("/dev/null").unwrap();
+        let raw_fd = unsafe { libc::open(path.as_ptr(), O_RDWR, 0) };
+        let cf_fd = CFFileDescriptor::new(raw_fd, true, never_callback, None);
+        assert!(cf_fd.is_some());
+        let cf_fd = cf_fd.unwrap();
+
+        assert!(cf_fd.valid());
+        cf_fd.invalidate();
+        assert!(!cf_fd.valid());
+
+        // close() should fail
+        assert_eq!(unsafe { libc::close(raw_fd) }, -1);
+    }
+
+    #[test]
+    fn test_unconsumed() {
+        let path = CString::new("/dev/null").unwrap();
+        let raw_fd = unsafe { libc::open(path.as_ptr(), O_RDWR, 0) };
+        let cf_fd = CFFileDescriptor::new(raw_fd, false, never_callback, None);
+        assert!(cf_fd.is_some());
+        let cf_fd = cf_fd.unwrap();
+
+        assert!(cf_fd.valid());
+        cf_fd.invalidate();
+        assert!(!cf_fd.valid());
+
+        // close() should succeed
+        assert_eq!(unsafe { libc::close(raw_fd) }, 0);
+    }
+
+    extern "C" fn never_callback(_f: CFFileDescriptorRef,
+                                 _callback_types: CFOptionFlags,
+                                 _info_ptr: *mut c_void) {
+        unreachable!();
+    }
+
+    struct TestInfo {
+        value: CFOptionFlags
+    }
+
+    #[test]
+    fn test_callback() {
+        let mut info = TestInfo { value: 0 };
+        let context = CFFileDescriptorContext {
+            version: 0,
+            info: &mut info as *mut _ as *mut c_void,
+            retain: None,
+            release: None,
+            copyDescription: None
+        };
+
+        let path = CString::new("/dev/null").unwrap();
+        let raw_fd = unsafe { libc::open(path.as_ptr(), O_RDWR, 0) };
+        let cf_fd = CFFileDescriptor::new(raw_fd, true, callback, Some(&context));
+        assert!(cf_fd.is_some());
+        let cf_fd = cf_fd.unwrap();
+
+        assert!(cf_fd.valid());
+
+        let run_loop = CFRunLoop::get_current();
+        let source = CFRunLoopSource::from_file_descriptor(&cf_fd, 0);
+        assert!(source.is_some());
+        unsafe {
+            run_loop.add_source(&source.unwrap(), kCFRunLoopDefaultMode);
+        }
+
+        info.value = 0;
+        cf_fd.enable_callbacks(kCFFileDescriptorReadCallBack);
+        CFRunLoop::run_current();
+        assert_eq!(info.value, kCFFileDescriptorReadCallBack);
+
+        info.value = 0;
+        cf_fd.enable_callbacks(kCFFileDescriptorWriteCallBack);
+        CFRunLoop::run_current();
+        assert_eq!(info.value, kCFFileDescriptorWriteCallBack);
+
+        info.value = 0;
+        cf_fd.disable_callbacks(kCFFileDescriptorReadCallBack | kCFFileDescriptorWriteCallBack);
+
+        cf_fd.invalidate();
+        assert!(!cf_fd.valid());
+    }
+
+    extern "C" fn callback(_f: CFFileDescriptorRef, callback_types: CFOptionFlags, info_ptr: *mut c_void) {
+        assert!(!info_ptr.is_null());
+
+        let info: *mut TestInfo = info_ptr as *mut TestInfo;
+
+        unsafe { (*info).value = callback_types };
+
+        CFRunLoop::get_current().stop();
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/lib.rs
@@ -0,0 +1,212 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![allow(non_snake_case)]
+
+extern crate core_foundation_sys;
+extern crate libc;
+
+#[cfg(feature = "with-chrono")]
+extern crate chrono;
+
+#[macro_export]
+macro_rules! declare_TCFType {
+    (
+        $(#[$doc:meta])*
+        $ty:ident, $raw:ident
+    ) => {
+        $(#[$doc])*
+        pub struct $ty($raw);
+
+        impl Drop for $ty {
+            fn drop(&mut self) {
+                unsafe { $crate::base::CFRelease(self.as_CFTypeRef()) }
+            }
+        }
+    }
+}
+
+#[macro_export]
+macro_rules! impl_TCFType {
+    ($ty:ident, $ty_ref:ident, $ty_id:ident) => {
+        impl $crate::base::TCFType for $ty {
+            type Ref = $ty_ref;
+
+            #[inline]
+            fn as_concrete_TypeRef(&self) -> $ty_ref {
+                self.0
+            }
+
+            #[inline]
+            unsafe fn wrap_under_get_rule(reference: $ty_ref) -> $ty {
+                use std::mem;
+                let reference = mem::transmute($crate::base::CFRetain(mem::transmute(reference)));
+                $crate::base::TCFType::wrap_under_create_rule(reference)
+            }
+
+            #[inline]
+            fn as_CFTypeRef(&self) -> $crate::base::CFTypeRef {
+                unsafe {
+                    ::std::mem::transmute(self.as_concrete_TypeRef())
+                }
+            }
+
+            #[inline]
+            unsafe fn wrap_under_create_rule(reference: $ty_ref) -> $ty {
+                $ty(reference)
+            }
+
+            #[inline]
+            fn type_id() -> $crate::base::CFTypeID {
+                unsafe {
+                    $ty_id()
+                }
+            }
+        }
+
+        impl Clone for $ty {
+            #[inline]
+            fn clone(&self) -> $ty {
+                unsafe {
+                    $ty::wrap_under_get_rule(self.0)
+                }
+            }
+        }
+
+        impl PartialEq for $ty {
+            #[inline]
+            fn eq(&self, other: &$ty) -> bool {
+                self.as_CFType().eq(&other.as_CFType())
+            }
+        }
+
+        impl Eq for $ty { }
+    }
+}
+
+// This is basically identical to the implementation above. I can't
+// think of a clean way to have them share code
+#[macro_export]
+macro_rules! impl_TCFTypeGeneric {
+    ($ty:ident, $ty_ref:ident, $ty_id:ident) => {
+        impl<T> $crate::base::TCFType for $ty<T> {
+            type Ref = $ty_ref;
+
+            #[inline]
+            fn as_concrete_TypeRef(&self) -> $ty_ref {
+                self.0
+            }
+
+            #[inline]
+            unsafe fn wrap_under_get_rule(reference: $ty_ref) -> $ty<T> {
+                use std::mem;
+                let reference = mem::transmute($crate::base::CFRetain(mem::transmute(reference)));
+                $crate::base::TCFType::wrap_under_create_rule(reference)
+            }
+
+            #[inline]
+            fn as_CFTypeRef(&self) -> ::core_foundation_sys::base::CFTypeRef {
+                unsafe {
+                    ::std::mem::transmute(self.as_concrete_TypeRef())
+                }
+            }
+
+            #[inline]
+            unsafe fn wrap_under_create_rule(obj: $ty_ref) -> $ty<T> {
+                $ty(obj, PhantomData)
+            }
+
+            #[inline]
+            fn type_id() -> ::core_foundation_sys::base::CFTypeID {
+                unsafe {
+                    $ty_id()
+                }
+            }
+        }
+
+        impl<T> Clone for $ty<T> {
+            #[inline]
+            fn clone(&self) -> $ty<T> {
+                unsafe {
+                    $ty::wrap_under_get_rule(self.0)
+                }
+            }
+        }
+
+        impl<T> PartialEq for $ty<T> {
+            #[inline]
+            fn eq(&self, other: &$ty<T>) -> bool {
+                self.as_CFType().eq(&other.as_CFType())
+            }
+        }
+
+        impl<T> Eq for $ty<T> { }
+    }
+}
+
+#[macro_export]
+macro_rules! impl_CFTypeDescription {
+    ($ty:ident) => {
+        impl ::std::fmt::Debug for $ty {
+            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+                self.as_CFType().fmt(f)
+            }
+        }
+    }
+}
+
+// The same as impl_CFTypeDescription but with a type parameter
+#[macro_export]
+macro_rules! impl_CFTypeDescriptionGeneric {
+    ($ty:ident) => {
+        impl<T> ::std::fmt::Debug for $ty<T> {
+            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
+                self.as_CFType().fmt(f)
+            }
+        }
+    }
+}
+
+#[macro_export]
+macro_rules! impl_CFComparison {
+    ($ty:ident, $compare:ident) => {
+        impl PartialOrd for $ty {
+            #[inline]
+            fn partial_cmp(&self, other: &$ty) -> Option<::std::cmp::Ordering> {
+                unsafe {
+                    Some($compare(self.as_concrete_TypeRef(), other.as_concrete_TypeRef(), ::std::ptr::null_mut()).into())
+                }
+            }
+        }
+
+        impl Ord for $ty {
+            #[inline]
+            fn cmp(&self, other: &$ty) -> ::std::cmp::Ordering {
+                self.partial_cmp(other).unwrap()
+            }
+        }
+    }
+}
+
+pub mod array;
+pub mod base;
+pub mod boolean;
+pub mod data;
+pub mod date;
+pub mod dictionary;
+pub mod error;
+pub mod filedescriptor;
+pub mod number;
+pub mod set;
+pub mod string;
+pub mod url;
+pub mod bundle;
+pub mod propertylist;
+pub mod runloop;
+pub mod timezone;
+pub mod uuid;
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/number.rs
@@ -0,0 +1,110 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Immutable numbers.
+
+use core_foundation_sys::base::kCFAllocatorDefault;
+pub use core_foundation_sys::number::*;
+use std::mem;
+
+use base::TCFType;
+
+
+declare_TCFType!{
+    /// An immutable numeric value.
+    CFNumber, CFNumberRef
+}
+impl_TCFType!(CFNumber, CFNumberRef, CFNumberGetTypeID);
+impl_CFTypeDescription!(CFNumber);
+impl_CFComparison!(CFNumber, CFNumberCompare);
+
+impl CFNumber {
+    #[inline]
+    pub fn to_i64(&self) -> Option<i64> {
+        unsafe {
+            let mut value: i64 = 0;
+            let ok = CFNumberGetValue(self.0, kCFNumberSInt64Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+
+    #[inline]
+    pub fn to_f32(&self) -> Option<f32> {
+        unsafe {
+            let mut value: f32 = 0.0;
+            let ok = CFNumberGetValue(self.0, kCFNumberFloat32Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+
+    #[inline]
+    pub fn to_f64(&self) -> Option<f64> {
+        unsafe {
+            let mut value: f64 = 0.0;
+            let ok = CFNumberGetValue(self.0, kCFNumberFloat64Type, mem::transmute(&mut value));
+            if ok { Some(value) } else { None }
+        }
+    }
+}
+
+impl From<i32> for CFNumber {
+    #[inline]
+    fn from(value: i32) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberSInt32Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<i64> for CFNumber {
+    #[inline]
+    fn from(value: i64) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberSInt64Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<f32> for CFNumber {
+    #[inline]
+    fn from(value: f32) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberFloat32Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
+
+impl From<f64> for CFNumber {
+    #[inline]
+    fn from(value: f64) -> Self {
+        unsafe {
+            let number_ref = CFNumberCreate(
+                kCFAllocatorDefault,
+                kCFNumberFloat64Type,
+                mem::transmute(&value),
+            );
+            TCFType::wrap_under_create_rule(number_ref)
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/propertylist.rs
@@ -0,0 +1,326 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation property lists
+
+use std::ptr;
+use std::mem;
+
+use libc::c_void;
+
+use error::CFError;
+use data::CFData;
+use base::{CFType, TCFType, TCFTypeRef};
+
+pub use core_foundation_sys::propertylist::*;
+use core_foundation_sys::error::CFErrorRef;
+use core_foundation_sys::base::{CFGetRetainCount, CFGetTypeID, CFIndex, CFRetain,
+                                CFShow, CFTypeID, kCFAllocatorDefault};
+
+pub fn create_with_data(data: CFData,
+                        options: CFPropertyListMutabilityOptions)
+                        -> Result<(*const c_void, CFPropertyListFormat), CFError> {
+    unsafe {
+        let mut error: CFErrorRef = ptr::null_mut();
+        let mut format: CFPropertyListFormat = 0;
+        let property_list = CFPropertyListCreateWithData(kCFAllocatorDefault,
+                                                         data.as_concrete_TypeRef(),
+                                                         options,
+                                                         &mut format,
+                                                         &mut error);
+        if property_list.is_null() {
+            Err(TCFType::wrap_under_create_rule(error))
+        } else {
+            Ok((property_list, format))
+        }
+    }
+}
+
+pub fn create_data(property_list: *const c_void, format: CFPropertyListFormat) -> Result<CFData, CFError> {
+    unsafe {
+        let mut error: CFErrorRef = ptr::null_mut();
+        let data_ref = CFPropertyListCreateData(kCFAllocatorDefault,
+                                                property_list,
+                                                format,
+                                                0,
+                                                &mut error);
+        if data_ref.is_null() {
+            Err(TCFType::wrap_under_create_rule(error))
+        } else {
+            Ok(TCFType::wrap_under_create_rule(data_ref))
+        }
+    }
+}
+
+
+/// Trait for all subclasses of [`CFPropertyList`].
+///
+/// [`CFPropertyList`]: struct.CFPropertyList.html
+pub trait CFPropertyListSubClass: TCFType {
+    /// Create an instance of the superclass type [`CFPropertyList`] for this instance.
+    ///
+    /// [`CFPropertyList`]: struct.CFPropertyList.html
+    #[inline]
+    fn to_CFPropertyList(&self) -> CFPropertyList {
+        unsafe { CFPropertyList::wrap_under_get_rule(self.as_concrete_TypeRef().as_void_ptr()) }
+    }
+
+    /// Equal to [`to_CFPropertyList`], but consumes self and avoids changing the reference count.
+    ///
+    /// [`to_CFPropertyList`]: #method.to_CFPropertyList
+    #[inline]
+    fn into_CFPropertyList(self) -> CFPropertyList
+    where
+        Self: Sized,
+    {
+        let reference = self.as_concrete_TypeRef().as_void_ptr();
+        mem::forget(self);
+        unsafe { CFPropertyList::wrap_under_create_rule(reference) }
+    }
+}
+
+impl CFPropertyListSubClass for ::data::CFData {}
+impl CFPropertyListSubClass for ::string::CFString {}
+impl CFPropertyListSubClass for ::array::CFArray {}
+impl CFPropertyListSubClass for ::dictionary::CFDictionary {}
+impl CFPropertyListSubClass for ::date::CFDate {}
+impl CFPropertyListSubClass for ::boolean::CFBoolean {}
+impl CFPropertyListSubClass for ::number::CFNumber {}
+
+
+declare_TCFType!{
+    /// A CFPropertyList struct. This is superclass to [`CFData`], [`CFString`], [`CFArray`],
+    /// [`CFDictionary`], [`CFDate`], [`CFBoolean`], and [`CFNumber`].
+    ///
+    /// This superclass type does not have its own `CFTypeID`, instead each instance has the `CFTypeID`
+    /// of the subclass it is an instance of. Thus, this type cannot implement the [`TCFType`] trait,
+    /// since it cannot implement the static [`TCFType::type_id()`] method.
+    ///
+    /// [`CFData`]: ../data/struct.CFData.html
+    /// [`CFString`]: ../string/struct.CFString.html
+    /// [`CFArray`]: ../array/struct.CFArray.html
+    /// [`CFDictionary`]: ../dictionary/struct.CFDictionary.html
+    /// [`CFDate`]: ../date/struct.CFDate.html
+    /// [`CFBoolean`]: ../boolean/struct.CFBoolean.html
+    /// [`CFNumber`]: ../number/struct.CFNumber.html
+    /// [`TCFType`]: ../base/trait.TCFType.html
+    /// [`TCFType::type_id()`]: ../base/trait.TCFType.html#method.type_of
+    CFPropertyList, CFPropertyListRef
+}
+
+impl CFPropertyList {
+    #[inline]
+    pub fn as_concrete_TypeRef(&self) -> CFPropertyListRef {
+        self.0
+    }
+
+    #[inline]
+    pub unsafe fn wrap_under_get_rule(reference: CFPropertyListRef) -> CFPropertyList {
+        let reference = mem::transmute(CFRetain(mem::transmute(reference)));
+        CFPropertyList(reference)
+    }
+
+    #[inline]
+    pub fn as_CFType(&self) -> CFType {
+        unsafe { CFType::wrap_under_get_rule(self.as_CFTypeRef()) }
+    }
+
+    #[inline]
+    pub fn into_CFType(self) -> CFType
+    where
+        Self: Sized,
+    {
+        let reference = self.as_CFTypeRef();
+        mem::forget(self);
+        unsafe { TCFType::wrap_under_create_rule(reference) }
+    }
+
+    #[inline]
+    pub fn as_CFTypeRef(&self) -> ::core_foundation_sys::base::CFTypeRef {
+        unsafe { mem::transmute(self.as_concrete_TypeRef()) }
+    }
+
+    #[inline]
+    pub unsafe fn wrap_under_create_rule(obj: CFPropertyListRef) -> CFPropertyList {
+        CFPropertyList(obj)
+    }
+
+    /// Returns the reference count of the object. It is unwise to do anything other than test
+    /// whether the return value of this method is greater than zero.
+    #[inline]
+    pub fn retain_count(&self) -> CFIndex {
+        unsafe { CFGetRetainCount(self.as_CFTypeRef()) }
+    }
+
+    /// Returns the type ID of this object. Will be one of CFData, CFString, CFArray, CFDictionary,
+    /// CFDate, CFBoolean, or CFNumber.
+    #[inline]
+    pub fn type_of(&self) -> CFTypeID {
+        unsafe { CFGetTypeID(self.as_CFTypeRef()) }
+    }
+
+    /// Writes a debugging version of this object on standard error.
+    pub fn show(&self) {
+        unsafe { CFShow(self.as_CFTypeRef()) }
+    }
+
+    /// Returns true if this value is an instance of another type.
+    #[inline]
+    pub fn instance_of<OtherCFType: TCFType>(&self) -> bool {
+        self.type_of() == OtherCFType::type_id()
+    }
+}
+
+impl Clone for CFPropertyList {
+    #[inline]
+    fn clone(&self) -> CFPropertyList {
+        unsafe { CFPropertyList::wrap_under_get_rule(self.0) }
+    }
+}
+
+impl PartialEq for CFPropertyList {
+    #[inline]
+    fn eq(&self, other: &CFPropertyList) -> bool {
+        self.as_CFType().eq(&other.as_CFType())
+    }
+}
+
+impl Eq for CFPropertyList {}
+
+impl CFPropertyList {
+    /// Try to downcast the [`CFPropertyList`] to a subclass. Checking if the instance is the
+    /// correct subclass happens at runtime and `None` is returned if it is not the correct type.
+    /// Works similar to [`Box::downcast`] and [`CFType::downcast`].
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// # use core_foundation::string::CFString;
+    /// # use core_foundation::propertylist::{CFPropertyList, CFPropertyListSubClass};
+    /// #
+    /// // Create a string.
+    /// let string: CFString = CFString::from_static_string("FooBar");
+    /// // Cast it up to a property list.
+    /// let propertylist: CFPropertyList = string.to_CFPropertyList();
+    /// // Cast it down again.
+    /// assert!(propertylist.downcast::<CFString>().unwrap().to_string() == "FooBar");
+    /// ```
+    ///
+    /// [`CFPropertyList`]: struct.CFPropertyList.html
+    /// [`Box::downcast`]: https://doc.rust-lang.org/std/boxed/struct.Box.html#method.downcast
+    pub fn downcast<T: CFPropertyListSubClass>(&self) -> Option<T> {
+        if self.instance_of::<T>() {
+            unsafe {
+                let subclass_ref = T::Ref::from_void_ptr(self.0);
+                Some(T::wrap_under_get_rule(subclass_ref))
+            }
+        } else {
+            None
+        }
+    }
+
+    /// Similar to [`downcast`], but consumes self and can thus avoid touching the retain count.
+    ///
+    /// [`downcast`]: #method.downcast
+    pub fn downcast_into<T: CFPropertyListSubClass>(self) -> Option<T> {
+        if self.instance_of::<T>() {
+            unsafe {
+                let subclass_ref = T::Ref::from_void_ptr(self.0);
+                mem::forget(self);
+                Some(T::wrap_under_create_rule(subclass_ref))
+            }
+        } else {
+            None
+        }
+    }
+}
+
+
+
+#[cfg(test)]
+pub mod test {
+    use super::*;
+    use string::CFString;
+    use boolean::CFBoolean;
+
+    #[test]
+    fn test_property_list_serialization() {
+        use base::{TCFType, CFEqual};
+        use boolean::CFBoolean;
+        use number::CFNumber;
+        use dictionary::CFDictionary;
+        use string::CFString;
+        use super::*;
+
+        let bar = CFString::from_static_string("Bar");
+        let baz = CFString::from_static_string("Baz");
+        let boo = CFString::from_static_string("Boo");
+        let foo = CFString::from_static_string("Foo");
+        let tru = CFBoolean::true_value();
+        let n42 = CFNumber::from(42);
+
+        let dict1 = CFDictionary::from_CFType_pairs(&[(bar.as_CFType(), boo.as_CFType()),
+                                                      (baz.as_CFType(), tru.as_CFType()),
+                                                      (foo.as_CFType(), n42.as_CFType())]);
+
+        let data = create_data(dict1.as_CFTypeRef(), kCFPropertyListXMLFormat_v1_0).unwrap();
+        let (dict2, _) = create_with_data(data, kCFPropertyListImmutable).unwrap();
+        unsafe {
+            assert!(CFEqual(dict1.as_CFTypeRef(), dict2) == 1);
+        }
+    }
+
+    #[test]
+    fn to_propertylist_retain_count() {
+        let string = CFString::from_static_string("Bar");
+        assert_eq!(string.retain_count(), 1);
+
+        let propertylist = string.to_CFPropertyList();
+        assert_eq!(string.retain_count(), 2);
+        assert_eq!(propertylist.retain_count(), 2);
+
+        mem::drop(string);
+        assert_eq!(propertylist.retain_count(), 1);
+    }
+
+    #[test]
+    fn downcast_string() {
+        let propertylist = CFString::from_static_string("Bar").to_CFPropertyList();
+        assert!(propertylist.downcast::<CFString>().unwrap().to_string() == "Bar");
+        assert!(propertylist.downcast::<CFBoolean>().is_none());
+    }
+
+    #[test]
+    fn downcast_boolean() {
+        let propertylist = CFBoolean::true_value().to_CFPropertyList();
+        assert!(propertylist.downcast::<CFBoolean>().is_some());
+        assert!(propertylist.downcast::<CFString>().is_none());
+    }
+
+    #[test]
+    fn downcast_into_fail() {
+        let string = CFString::from_static_string("Bar");
+        let propertylist = string.to_CFPropertyList();
+        assert_eq!(string.retain_count(), 2);
+
+        assert!(propertylist.downcast_into::<CFBoolean>().is_none());
+        assert_eq!(string.retain_count(), 1);
+    }
+
+    #[test]
+    fn downcast_into() {
+        let string = CFString::from_static_string("Bar");
+        let propertylist = string.to_CFPropertyList();
+        assert_eq!(string.retain_count(), 2);
+
+        let string2 = propertylist.downcast_into::<CFString>().unwrap();
+        assert!(string2.to_string() == "Bar");
+        assert_eq!(string2.retain_count(), 2);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/runloop.rs
@@ -0,0 +1,199 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![allow(non_upper_case_globals)]
+
+pub use core_foundation_sys::runloop::*;
+use core_foundation_sys::base::CFIndex;
+use core_foundation_sys::base::{kCFAllocatorDefault, CFOptionFlags};
+use core_foundation_sys::string::CFStringRef;
+
+use base::{TCFType};
+use date::{CFAbsoluteTime, CFTimeInterval};
+use filedescriptor::CFFileDescriptor;
+use string::{CFString};
+
+pub type CFRunLoopMode = CFStringRef;
+
+
+declare_TCFType!(CFRunLoop, CFRunLoopRef);
+impl_TCFType!(CFRunLoop, CFRunLoopRef, CFRunLoopGetTypeID);
+impl_CFTypeDescription!(CFRunLoop);
+
+impl CFRunLoop {
+    pub fn get_current() -> CFRunLoop {
+        unsafe {
+            let run_loop_ref = CFRunLoopGetCurrent();
+            TCFType::wrap_under_get_rule(run_loop_ref)
+        }
+    }
+
+    pub fn get_main() -> CFRunLoop {
+        unsafe {
+            let run_loop_ref = CFRunLoopGetMain();
+            TCFType::wrap_under_get_rule(run_loop_ref)
+        }
+    }
+
+    pub fn run_current() {
+        unsafe {
+            CFRunLoopRun();
+        }
+    }
+
+    pub fn stop(&self) {
+        unsafe {
+            CFRunLoopStop(self.0);
+        }
+    }
+
+    pub fn current_mode(&self) -> Option<String> {
+        unsafe {
+            let string_ref = CFRunLoopCopyCurrentMode(self.0);
+            if string_ref.is_null() {
+                return None;
+            }
+
+            let cf_string: CFString = TCFType::wrap_under_create_rule(string_ref);
+            Some(cf_string.to_string())
+        }
+    }
+
+    pub fn contains_timer(&self, timer: &CFRunLoopTimer, mode: CFRunLoopMode) -> bool {
+        unsafe {
+            CFRunLoopContainsTimer(self.0, timer.0, mode) != 0
+        }
+    }
+
+    pub fn add_timer(&self, timer: &CFRunLoopTimer, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopAddTimer(self.0, timer.0, mode);
+        }
+    }
+
+    pub fn remove_timer(&self, timer: &CFRunLoopTimer, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopRemoveTimer(self.0, timer.0, mode);
+        }
+    }
+
+    pub fn contains_source(&self, source: &CFRunLoopSource, mode: CFRunLoopMode) -> bool {
+        unsafe {
+            CFRunLoopContainsSource(self.0, source.0, mode) != 0
+        }
+    }
+
+    pub fn add_source(&self, source: &CFRunLoopSource, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopAddSource(self.0, source.0, mode);
+        }
+    }
+
+    pub fn remove_source(&self, source: &CFRunLoopSource, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopRemoveSource(self.0, source.0, mode);
+        }
+    }
+
+    pub fn contains_observer(&self, observer: &CFRunLoopObserver, mode: CFRunLoopMode) -> bool {
+        unsafe {
+            CFRunLoopContainsObserver(self.0, observer.0, mode) != 0
+        }
+    }
+
+    pub fn add_observer(&self, observer: &CFRunLoopObserver, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopAddObserver(self.0, observer.0, mode);
+        }
+    }
+
+    pub fn remove_observer(&self, observer: &CFRunLoopObserver, mode: CFRunLoopMode) {
+        unsafe {
+            CFRunLoopRemoveObserver(self.0, observer.0, mode);
+        }
+    }
+
+}
+
+
+declare_TCFType!(CFRunLoopTimer, CFRunLoopTimerRef);
+impl_TCFType!(CFRunLoopTimer, CFRunLoopTimerRef, CFRunLoopTimerGetTypeID);
+
+impl CFRunLoopTimer {
+    pub fn new(fireDate: CFAbsoluteTime, interval: CFTimeInterval, flags: CFOptionFlags, order: CFIndex, callout: CFRunLoopTimerCallBack, context: *mut CFRunLoopTimerContext) -> CFRunLoopTimer {
+        unsafe {
+            let timer_ref = CFRunLoopTimerCreate(kCFAllocatorDefault, fireDate, interval, flags, order, callout, context);
+            TCFType::wrap_under_create_rule(timer_ref)
+        }
+    }
+}
+
+
+declare_TCFType!(CFRunLoopSource, CFRunLoopSourceRef);
+impl_TCFType!(CFRunLoopSource, CFRunLoopSourceRef, CFRunLoopSourceGetTypeID);
+
+impl CFRunLoopSource {
+    pub fn from_file_descriptor(fd: &CFFileDescriptor, order: CFIndex) -> Option<CFRunLoopSource> {
+        fd.to_run_loop_source(order)
+    }
+}
+
+declare_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef);
+impl_TCFType!(CFRunLoopObserver, CFRunLoopObserverRef, CFRunLoopObserverGetTypeID);
+
+#[cfg(test)]
+mod test {
+    use super::*;
+    use date::{CFDate, CFAbsoluteTime};
+    use std::mem;
+    use libc::c_void;
+    use std::sync::mpsc;
+
+    #[test]
+    fn wait_200_milliseconds() {
+        let run_loop = CFRunLoop::get_current();
+
+        let now = CFDate::now().abs_time();
+        let (elapsed_tx, elapsed_rx) = mpsc::channel();
+        let mut info = Info {
+            start_time: now,
+            elapsed_tx,
+        };
+        let mut context = unsafe { CFRunLoopTimerContext {
+            version: 0,
+            info: &mut info as *mut _ as *mut c_void,
+            retain: mem::zeroed(),
+            release: mem::zeroed(),
+            copyDescription: mem::zeroed(),
+        } };
+
+
+        let run_loop_timer = CFRunLoopTimer::new(now + 0.20f64, 0f64, 0, 0, timer_popped, &mut context);
+        unsafe {
+            run_loop.add_timer(&run_loop_timer, kCFRunLoopDefaultMode);
+        }
+        CFRunLoop::run_current();
+        let elapsed = elapsed_rx.try_recv().unwrap();
+        println!("wait_200_milliseconds, elapsed: {}", elapsed);
+        assert!(elapsed > 0.19 && elapsed < 0.30);
+    }
+
+    struct Info {
+        start_time: CFAbsoluteTime,
+        elapsed_tx: mpsc::Sender<f64>,
+    }
+
+    extern "C" fn timer_popped(_timer: CFRunLoopTimerRef, raw_info: *mut c_void) {
+        let info: *mut Info = unsafe { mem::transmute(raw_info) };
+        let now = CFDate::now().abs_time();
+        let elapsed = now - unsafe { (*info).start_time };
+        let _ = unsafe { (*info).elapsed_tx.send(elapsed) };
+        CFRunLoop::get_current().stop();
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/set.rs
@@ -0,0 +1,39 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! An immutable bag of elements.
+
+pub use core_foundation_sys::set::*;
+use core_foundation_sys::base::{CFTypeRef, kCFAllocatorDefault};
+
+use base::{CFIndexConvertible, TCFType};
+
+use std::mem;
+
+
+declare_TCFType!{
+    /// An immutable bag of elements.
+    CFSet, CFSetRef
+}
+impl_TCFType!(CFSet, CFSetRef, CFSetGetTypeID);
+impl_CFTypeDescription!(CFSet);
+
+impl CFSet {
+    /// Creates a new set from a list of `CFType` instances.
+    pub fn from_slice<T>(elems: &[T]) -> CFSet where T: TCFType {
+        unsafe {
+            let elems: Vec<CFTypeRef> = elems.iter().map(|elem| elem.as_CFTypeRef()).collect();
+            let set_ref = CFSetCreate(kCFAllocatorDefault,
+                                      mem::transmute(elems.as_ptr()),
+                                      elems.len().to_CFIndex(),
+                                      &kCFTypeSetCallBacks);
+            TCFType::wrap_under_create_rule(set_ref)
+        }
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/string.rs
@@ -0,0 +1,143 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Immutable strings.
+
+pub use core_foundation_sys::string::*;
+
+use base::{CFIndexConvertible, TCFType};
+
+use core_foundation_sys::base::{Boolean, CFIndex, CFRange};
+use core_foundation_sys::base::{kCFAllocatorDefault, kCFAllocatorNull};
+use std::fmt;
+use std::str::{self, FromStr};
+use std::ptr;
+use std::ffi::CStr;
+
+
+declare_TCFType!{
+    /// An immutable string in one of a variety of encodings.
+    CFString, CFStringRef
+}
+impl_TCFType!(CFString, CFStringRef, CFStringGetTypeID);
+
+impl FromStr for CFString {
+    type Err = ();
+
+    /// See also CFString::new for a variant of this which does not return a Result
+    #[inline]
+    fn from_str(string: &str) -> Result<CFString, ()> {
+        Ok(CFString::new(string))
+    }
+}
+
+impl<'a> From<&'a str> for CFString {
+    #[inline]
+    fn from(string: &'a str) -> CFString {
+        CFString::new(string)
+    }
+}
+
+impl fmt::Display for CFString {
+    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+        unsafe {
+            // Do this without allocating if we can get away with it
+            let c_string = CFStringGetCStringPtr(self.0, kCFStringEncodingUTF8);
+            if c_string != ptr::null() {
+                let c_str = CStr::from_ptr(c_string);
+                fmt.write_str(str::from_utf8_unchecked(c_str.to_bytes()))
+            } else {
+                let char_len = self.char_len();
+
+                // First, ask how big the buffer ought to be.
+                let mut bytes_required: CFIndex = 0;
+                CFStringGetBytes(self.0,
+                                 CFRange { location: 0, length: char_len },
+                                 kCFStringEncodingUTF8,
+                                 0,
+                                 false as Boolean,
+                                 ptr::null_mut(),
+                                 0,
+                                 &mut bytes_required);
+
+                // Then, allocate the buffer and actually copy.
+                let mut buffer = vec![b'\x00'; bytes_required as usize];
+
+                let mut bytes_used: CFIndex = 0;
+                let chars_written = CFStringGetBytes(self.0,
+                                                     CFRange { location: 0, length: char_len },
+                                                     kCFStringEncodingUTF8,
+                                                     0,
+                                                     false as Boolean,
+                                                     buffer.as_mut_ptr(),
+                                                     buffer.len().to_CFIndex(),
+                                                     &mut bytes_used) as usize;
+                assert!(chars_written.to_CFIndex() == char_len);
+
+                // This is dangerous; we over-allocate and null-terminate the string (during
+                // initialization).
+                assert!(bytes_used == buffer.len().to_CFIndex());
+                fmt.write_str(str::from_utf8_unchecked(&buffer))
+            }
+        }
+    }
+}
+
+impl fmt::Debug for CFString {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "\"{}\"", self)
+    }
+}
+
+
+impl CFString {
+    /// Creates a new `CFString` instance from a Rust string.
+    #[inline]
+    pub fn new(string: &str) -> CFString {
+        unsafe {
+            let string_ref = CFStringCreateWithBytes(kCFAllocatorDefault,
+                                                     string.as_ptr(),
+                                                     string.len().to_CFIndex(),
+                                                     kCFStringEncodingUTF8,
+                                                     false as Boolean);
+            CFString::wrap_under_create_rule(string_ref)
+        }
+    }
+
+    /// Like `CFString::new`, but references a string that can be used as a backing store
+    /// by virtue of being statically allocated.
+    #[inline]
+    pub fn from_static_string(string: &'static str) -> CFString {
+        unsafe {
+            let string_ref = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault,
+                                                           string.as_ptr(),
+                                                           string.len().to_CFIndex(),
+                                                           kCFStringEncodingUTF8,
+                                                           false as Boolean,
+                                                           kCFAllocatorNull);
+            TCFType::wrap_under_create_rule(string_ref)
+        }
+    }
+
+    /// Returns the number of characters in the string.
+    #[inline]
+    pub fn char_len(&self) -> CFIndex {
+        unsafe {
+            CFStringGetLength(self.0)
+        }
+    }
+}
+
+#[test]
+fn string_and_back() {
+    let original = "The quick brown fox jumped over the slow lazy dog.";
+    let cfstr = CFString::from_static_string(original);
+    let converted = cfstr.to_string();
+    assert!(converted == original);
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/timezone.rs
@@ -0,0 +1,95 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation time zone objects.
+
+pub use core_foundation_sys::timezone::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+use date::{CFDate, CFTimeInterval};
+
+#[cfg(feature = "with-chrono")]
+use chrono::{FixedOffset, NaiveDateTime};
+
+
+declare_TCFType!{
+    /// A time zone.
+    CFTimeZone, CFTimeZoneRef
+}
+impl_TCFType!(CFTimeZone, CFTimeZoneRef, CFTimeZoneGetTypeID);
+impl_CFTypeDescription!(CFTimeZone);
+
+impl Default for CFTimeZone {
+    fn default() -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCopyDefault();
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+}
+
+impl CFTimeZone {
+    #[inline]
+    pub fn new(interval: CFTimeInterval) -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, interval);
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+
+    #[inline]
+    pub fn system() -> CFTimeZone {
+        unsafe {
+            let tz_ref = CFTimeZoneCopySystem();
+            TCFType::wrap_under_create_rule(tz_ref)
+        }
+    }
+
+    pub fn seconds_from_gmt(&self, date: CFDate) -> CFTimeInterval {
+        unsafe {
+            CFTimeZoneGetSecondsFromGMT(self.0, date.abs_time())
+        }
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn offset_at_date(&self, date: NaiveDateTime) -> FixedOffset {
+        let date = CFDate::from_naive_utc(date);
+        FixedOffset::east(self.seconds_from_gmt(date) as i32)
+    }
+
+    #[cfg(feature = "with-chrono")]
+    pub fn from_offset(offset: FixedOffset) -> CFTimeZone {
+        CFTimeZone::new(offset.local_minus_utc() as f64)
+    }
+}
+
+#[cfg(test)]
+mod test {
+    use super::CFTimeZone;
+
+    #[cfg(feature = "with-chrono")]
+    use chrono::{NaiveDateTime, FixedOffset};
+
+    #[test]
+    fn timezone_comparison() {
+        let system = CFTimeZone::system();
+        let default = CFTimeZone::default();
+        assert_eq!(system, default);
+    }
+
+    #[test]
+    #[cfg(feature = "with-chrono")]
+    fn timezone_chrono_conversion() {
+        let offset = FixedOffset::west(28800);
+        let tz = CFTimeZone::from_offset(offset);
+        let converted = tz.offset_at_date(NaiveDateTime::from_timestamp(0, 0));
+        assert_eq!(offset, converted);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/url.rs
@@ -0,0 +1,156 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! A URL type for Core Foundation.
+
+pub use core_foundation_sys::url::*;
+
+use base::{TCFType, CFIndex};
+use string::{CFString};
+
+use core_foundation_sys::base::{kCFAllocatorDefault, Boolean};
+use std::fmt;
+use std::ptr;
+use std::path::{Path, PathBuf};
+use std::mem;
+
+use libc::{strlen, PATH_MAX};
+
+#[cfg(unix)]
+use std::os::unix::ffi::OsStrExt;
+#[cfg(unix)]
+use std::ffi::OsStr;
+
+
+declare_TCFType!(CFURL, CFURLRef);
+impl_TCFType!(CFURL, CFURLRef, CFURLGetTypeID);
+
+impl fmt::Debug for CFURL {
+    #[inline]
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        unsafe {
+            let string: CFString = TCFType::wrap_under_get_rule(CFURLGetString(self.0));
+            write!(f, "{}", string.to_string())
+        }
+    }
+}
+
+impl CFURL {
+    pub fn from_path<P: AsRef<Path>>(path: P, isDirectory: bool) -> Option<CFURL> {
+        let path_bytes;
+        #[cfg(unix)]
+        {
+            path_bytes = path.as_ref().as_os_str().as_bytes()
+        }
+        #[cfg(not(unix))]
+        {
+            // XXX: Getting non-valid UTF8 paths into CoreFoundation on Windows is going to be unpleasant
+            // CFURLGetWideFileSystemRepresentation might help
+            path_bytes = match path.as_ref().to_str() {
+                Some(path) => path,
+                None => return None,
+            }
+        }
+
+        unsafe {
+            let url_ref = CFURLCreateFromFileSystemRepresentation(ptr::null_mut(), path_bytes.as_ptr(), path_bytes.len() as CFIndex, isDirectory as u8);
+            if url_ref.is_null() {
+                return None;
+            }
+            Some(TCFType::wrap_under_create_rule(url_ref))
+        }
+    }
+
+    pub fn from_file_system_path(filePath: CFString, pathStyle: CFURLPathStyle, isDirectory: bool) -> CFURL {
+        unsafe {
+            let url_ref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, filePath.as_concrete_TypeRef(), pathStyle, isDirectory as u8);
+            TCFType::wrap_under_create_rule(url_ref)
+        }
+    }
+
+    #[cfg(unix)]
+    pub fn to_path(&self) -> Option<PathBuf> {
+        // implementing this on Windows is more complicated because of the different OsStr representation
+        unsafe {
+            let mut buf: [u8; PATH_MAX as usize] = mem::uninitialized();
+            let result = CFURLGetFileSystemRepresentation(self.0, true as Boolean, buf.as_mut_ptr(), buf.len() as CFIndex);
+            if result == false as Boolean {
+                return None;
+            }
+            let len = strlen(buf.as_ptr() as *const i8);
+            let path = OsStr::from_bytes(&buf[0..len]);
+            Some(PathBuf::from(path))
+        }
+    }
+
+    pub fn get_string(&self) -> CFString {
+        unsafe {
+            TCFType::wrap_under_get_rule(CFURLGetString(self.0))
+        }
+    }
+
+    pub fn get_file_system_path(&self, pathStyle: CFURLPathStyle) -> CFString {
+        unsafe {
+            TCFType::wrap_under_create_rule(CFURLCopyFileSystemPath(self.as_concrete_TypeRef(), pathStyle))
+        }
+    }
+
+    pub fn absolute(&self) -> CFURL {
+        unsafe {
+            TCFType::wrap_under_create_rule(CFURLCopyAbsoluteURL(self.as_concrete_TypeRef()))
+        }
+    }
+}
+
+#[test]
+fn file_url_from_path() {
+    let path = "/usr/local/foo/";
+    let cfstr_path = CFString::from_static_string(path);
+    let cfurl = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    assert_eq!(cfurl.get_string().to_string(), "file:///usr/local/foo/");
+}
+
+#[cfg(unix)]
+#[test]
+fn non_utf8() {
+    use std::ffi::OsStr;
+    let path = Path::new(OsStr::from_bytes(b"/\xC0/blame"));
+    let cfurl = CFURL::from_path(path, false).unwrap();
+    assert_eq!(cfurl.to_path().unwrap(), path);
+    let len = unsafe { CFURLGetBytes(cfurl.as_concrete_TypeRef(), ptr::null_mut(), 0) };
+    assert_eq!(len, 17);
+}
+
+#[test]
+fn absolute_file_url() {
+    use core_foundation_sys::url::CFURLCreateWithFileSystemPathRelativeToBase;
+    use std::path::PathBuf;
+
+    let path = "/usr/local/foo";
+    let file = "bar";
+
+    let cfstr_path = CFString::from_static_string(path);
+    let cfstr_file = CFString::from_static_string(file);
+    let cfurl_base = CFURL::from_file_system_path(cfstr_path, kCFURLPOSIXPathStyle, true);
+    let cfurl_relative: CFURL = unsafe {
+        let url_ref = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault,
+            cfstr_file.as_concrete_TypeRef(),
+            kCFURLPOSIXPathStyle,
+            false as u8,
+            cfurl_base.as_concrete_TypeRef());
+        TCFType::wrap_under_create_rule(url_ref)
+    };
+
+    let mut absolute_path = PathBuf::from(path);
+    absolute_path.push(file);
+
+    assert_eq!(cfurl_relative.get_file_system_path(kCFURLPOSIXPathStyle).to_string(), file);
+    assert_eq!(cfurl_relative.absolute().get_file_system_path(kCFURLPOSIXPathStyle).to_string(),
+        absolute_path.to_str().unwrap());
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/src/uuid.rs
@@ -0,0 +1,112 @@
+// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Core Foundation UUID objects.
+
+#[cfg(feature = "with-uuid")]
+extern crate uuid;
+
+pub use core_foundation_sys::uuid::*;
+use core_foundation_sys::base::kCFAllocatorDefault;
+
+use base::TCFType;
+
+#[cfg(feature = "with-uuid")]
+use self::uuid::Uuid;
+
+
+declare_TCFType! {
+    /// A UUID.
+    CFUUID, CFUUIDRef
+}
+impl_TCFType!(CFUUID, CFUUIDRef, CFUUIDGetTypeID);
+impl_CFTypeDescription!(CFUUID);
+
+impl CFUUID {
+    #[inline]
+    pub fn new() -> CFUUID {
+        unsafe {
+            let uuid_ref = CFUUIDCreate(kCFAllocatorDefault);
+            TCFType::wrap_under_create_rule(uuid_ref)
+        }
+    }
+}
+
+#[cfg(feature = "with-uuid")]
+impl Into<Uuid> for CFUUID {
+    fn into(self) -> Uuid {
+        let b = unsafe {
+            CFUUIDGetUUIDBytes(self.0)
+        };
+        let bytes = [
+            b.byte0,
+            b.byte1,
+            b.byte2,
+            b.byte3,
+            b.byte4,
+            b.byte5,
+            b.byte6,
+            b.byte7,
+            b.byte8,
+            b.byte9,
+            b.byte10,
+            b.byte11,
+            b.byte12,
+            b.byte13,
+            b.byte14,
+            b.byte15,
+        ];
+        Uuid::from_bytes(&bytes).unwrap()
+    }
+}
+
+#[cfg(feature = "with-uuid")]
+impl From<Uuid> for CFUUID {
+    fn from(uuid: Uuid) -> CFUUID {
+        let b = uuid.as_bytes();
+        let bytes = CFUUIDBytes {
+            byte0: b[0],
+            byte1: b[1],
+            byte2: b[2],
+            byte3: b[3],
+            byte4: b[4],
+            byte5: b[5],
+            byte6: b[6],
+            byte7: b[7],
+            byte8: b[8],
+            byte9: b[9],
+            byte10: b[10],
+            byte11: b[11],
+            byte12: b[12],
+            byte13: b[13],
+            byte14: b[14],
+            byte15: b[15],
+        };
+        unsafe {
+            let uuid_ref = CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, bytes);
+            TCFType::wrap_under_create_rule(uuid_ref)
+        }
+    }
+}
+
+
+#[cfg(test)]
+#[cfg(feature = "with-uuid")]
+mod test {
+    use super::CFUUID;
+    use uuid::Uuid;
+
+    #[test]
+    fn uuid_conversion() {
+        let cf_uuid = CFUUID::new();
+        let uuid: Uuid = cf_uuid.clone().into();
+        let converted = CFUUID::from(uuid);
+        assert!(cf_uuid == converted);
+    }
+}
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-0.5.1/tests/use_macro_outside_crate.rs
@@ -0,0 +1,29 @@
+#[macro_use]
+extern crate core_foundation;
+extern crate libc;
+
+use core_foundation::base::{CFComparisonResult, TCFType};
+use libc::c_void;
+
+// sys equivalent stuff that must be declared
+
+#[repr(C)]
+pub struct __CFFooBar(c_void);
+
+pub type CFFooBarRef = *const __CFFooBar;
+
+extern "C" {
+    pub fn CFFooBarGetTypeID() -> core_foundation::base::CFTypeID;
+    pub fn fake_compare(
+        this: CFFooBarRef,
+        other: CFFooBarRef,
+        context: *mut c_void,
+    ) -> CFComparisonResult;
+}
+
+// Try to use the macros outside of the crate
+
+declare_TCFType!(CFFooBar, CFFooBarRef);
+impl_TCFType!(CFFooBar, CFFooBarRef, CFFooBarGetTypeID);
+impl_CFTypeDescription!(CFFooBar);
+impl_CFComparison!(CFFooBar, fake_compare);
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/.cargo-checksum.json
@@ -0,0 +1,1 @@
+{"files":{"Cargo.toml":"08b77adecca4222d97b0fb359b1c9ce97983e0e0914a4418834c032395af76ea","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"62065228e42caebca7e7d7db1204cbb867033de5982ca4009928915e4095f3a3","build.rs":"9433ed3b20cc99e716dda4c6d8507c29bc04882544cbbea8d4e48ba80fd0fa12","src/array.rs":"c70be1c0485612ac327a4fc9ca87098034e13df80dead23167560a38471fb823","src/base.rs":"37ad5b765d9e70f043f70a26da65cc46f0af5f1361e431e6f8591a143a31da31","src/bundle.rs":"b4e0e9b7ca2e35e3dc9bee316690538a5d17a470f8173f6b80c6816c847d12ec","src/data.rs":"21e968951fe56e080d33474f4438de2dfb7e0c8af426a6dfb100efdd6c530eec","src/date.rs":"90f29b07d3bd1549a3ab64adaaf153aff5ba546c1cd449f7248479d26bce9687","src/dictionary.rs":"37d881fbcf3232f90ab8648084b0f26b45ffee882b95e76831ac206f3e35f7de","src/error.rs":"61bc31a401ec6c8495668175eade9284e257da056fc666af74a5555af5daf33f","src/filedescriptor.rs":"14800c805b66f1fd6f995a6e73138d65a724163acb8a3f8f2539c807d333473d","src/lib.rs":"1038a1292f6f6c790ae055242015b8e3b91c2cccce34bfba240403399149f64c","src/messageport.rs":"f22b8552ff8b8e1edf25fe322eeabd9d7e5472b11514b95bc936387e4fa51b2a","src/number.rs":"4e69c688f24a1226fb40faec7d18861b5a617afcedbb352331c45a8e4eff292a","src/propertylist.rs":"cc2b27f8f8ebc80c03871b7b1ad50ee348539b016078ce721c86b8cd5f9d75bd","src/runloop.rs":"1d4aba9425669ef32450396c31655a90daf0e67d579e4617465fb7abe23c047f","src/set.rs":"22055b5ce6a2ce37847ee955f5e6e517348a351770d335373704776bc5412b9f","src/string.rs":"0e9373c6e48c97d7cbdb2ceaa07bc0af4e5d25ab0f91b138b4f8667cff337f4e","src/timezone.rs":"6711924b967d96ba88be4976cf17dfd3f9573033115da8e61ad07e8b0f26cdb7","src/url.rs":"b85110fe203c685719ba92517ff3c09ce0fe358e15380ecc0bd18356ac3573ed","src/uuid.rs":"e591e0bac875832acc15ea7ee0c9bff296543f4f77470101de0602ee69c2e527"},"package":"716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/Cargo.toml
@@ -0,0 +1,27 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g. crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+name = "core-foundation-sys"
+version = "0.5.1"
+authors = ["The Servo Project Developers"]
+build = "build.rs"
+description = "Bindings to Core Foundation for OS X"
+homepage = "https://github.com/servo/core-foundation-rs"
+license = "MIT / Apache-2.0"
+repository = "https://github.com/servo/core-foundation-rs"
+[dependencies.libc]
+version = "0.2"
+
+[features]
+mac_os_10_7_support = []
+mac_os_10_8_features = []
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/LICENSE-APACHE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+	http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2012-2013 Mozilla Foundation
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
new file mode 100644
--- /dev/null
+++ b/third_party/rust/core-foundation-sys-0.5.1/build.rs
@@ -0,0 +1,14 @@
+// Copyright 2013-2015 The Servo Project Dev