aboutsummaryrefslogtreecommitdiffstats
path: root/components/util
diff options
context:
space:
mode:
Diffstat (limited to 'components/util')
-rw-r--r--components/util/cursor.rs2
-rw-r--r--components/util/linked_list.rs73
-rw-r--r--components/util/opts.rs6
-rw-r--r--components/util/range.rs2
4 files changed, 81 insertions, 2 deletions
diff --git a/components/util/cursor.rs b/components/util/cursor.rs
index 622845deaa7..8e4ca9e3c1c 100644
--- a/components/util/cursor.rs
+++ b/components/util/cursor.rs
@@ -9,7 +9,7 @@ use std::ascii::AsciiExt;
macro_rules! define_cursor {
($( $css: expr => $variant: ident = $value: expr, )+) => {
- #[derive(Clone, Copy, PartialEq, Eq, Debug)]
+ #[derive(Clone, Copy, PartialEq, Eq, Debug, Deserialize, Serialize)]
#[repr(u8)]
pub enum Cursor {
$( $variant = $value ),+
diff --git a/components/util/linked_list.rs b/components/util/linked_list.rs
index 5114f02c0e4..bf20f434d54 100644
--- a/components/util/linked_list.rs
+++ b/components/util/linked_list.rs
@@ -4,8 +4,81 @@
//! Utility functions for doubly-linked lists.
+use mem::HeapSizeOf;
+
+use serde::de::{Error, SeqVisitor, Visitor};
+use serde::ser::impls::SeqIteratorVisitor;
+use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::collections::LinkedList;
+use std::marker::PhantomData;
use std::mem;
+use std::ops::{Deref, DerefMut};
+
+pub struct SerializableLinkedList<T>(LinkedList<T>);
+
+impl<T> SerializableLinkedList<T> {
+ pub fn new(linked_list: LinkedList<T>) -> SerializableLinkedList<T> {
+ SerializableLinkedList(linked_list)
+ }
+}
+
+impl<T> Deref for SerializableLinkedList<T> {
+ type Target = LinkedList<T>;
+
+ fn deref(&self) -> &LinkedList<T> {
+ &self.0
+ }
+}
+
+impl<T> DerefMut for SerializableLinkedList<T> {
+ fn deref_mut(&mut self) -> &mut LinkedList<T> {
+ &mut self.0
+ }
+}
+
+impl<T: HeapSizeOf> HeapSizeOf for SerializableLinkedList<T> {
+ fn heap_size_of_children(&self) -> usize {
+ self.0.heap_size_of_children()
+ }
+}
+
+impl<T> Serialize for SerializableLinkedList<T> where T: Serialize {
+ fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
+ serializer.visit_seq(SeqIteratorVisitor::new(self.0.iter(), Some(self.0.len())))
+ }
+}
+
+impl<T> Deserialize for SerializableLinkedList<T> where T: Deserialize {
+ fn deserialize<D>(deserializer: &mut D) -> Result<SerializableLinkedList<T>, D::Error>
+ where D: Deserializer {
+ struct SerializableLinkedListVisitor<T> {
+ marker: PhantomData<T>,
+ }
+
+ impl<T> Visitor for SerializableLinkedListVisitor<T> where T: Deserialize {
+ type Value = SerializableLinkedList<T>;
+
+ #[inline]
+ fn visit_seq<V>(&mut self, mut visitor: V)
+ -> Result<SerializableLinkedList<T>, V::Error>
+ where V: SeqVisitor {
+ let mut list = LinkedList::new();
+ for _ in 0..visitor.size_hint().0 {
+ match try!(visitor.visit()) {
+ Some(element) => list.push_back(element),
+ None => return Err(Error::end_of_stream_error()),
+ }
+ }
+ try!(visitor.end());
+ Ok(SerializableLinkedList(list))
+ }
+ }
+
+ deserializer.visit_seq(SerializableLinkedListVisitor {
+ marker: PhantomData,
+ })
+ }
+}
/// Splits the head off a list in O(1) time, and returns the head.
pub fn split_off_head<T>(list: &mut LinkedList<T>) -> LinkedList<T> {
diff --git a/components/util/opts.rs b/components/util/opts.rs
index 9ba7f86a6d2..550dd2a408e 100644
--- a/components/util/opts.rs
+++ b/components/util/opts.rs
@@ -140,6 +140,9 @@ pub struct Opts {
/// Dumps the display list after a layout.
pub dump_display_list: bool,
+ /// Dumps the display list in JSON form after a layout.
+ pub dump_display_list_json: bool,
+
/// Dumps the display list after optimization (post layout, at painting time).
pub dump_display_list_optimized: bool,
@@ -178,6 +181,7 @@ pub fn print_debug_usage(app: &str) -> ! {
print_option("disable-text-aa", "Disable antialiasing of rendered text.");
print_option("dump-flow-tree", "Print the flow tree after each layout.");
print_option("dump-display-list", "Print the display list after each layout.");
+ print_option("dump-display-list-json", "Print the display list in JSON form.");
print_option("dump-display-list-optimized", "Print optimized display list (at paint time).");
print_option("relayout-event", "Print notifications when there is a relayout.");
print_option("profile-tasks", "Instrument each task, writing the output to a file.");
@@ -248,6 +252,7 @@ pub fn default_opts() -> Opts {
user_agent: None,
dump_flow_tree: false,
dump_display_list: false,
+ dump_display_list_json: false,
dump_display_list_optimized: false,
relayout_event: false,
validate_display_list_geometry: false,
@@ -424,6 +429,7 @@ pub fn from_cmdline_args(args: &[String]) {
enable_canvas_antialiasing: !debug_options.contains(&"disable-canvas-aa"),
dump_flow_tree: debug_options.contains(&"dump-flow-tree"),
dump_display_list: debug_options.contains(&"dump-display-list"),
+ dump_display_list_json: debug_options.contains(&"dump-display-list-json"),
dump_display_list_optimized: debug_options.contains(&"dump-display-list-optimized"),
relayout_event: debug_options.contains(&"relayout-event"),
validate_display_list_geometry: debug_options.contains(&"validate-display-list-geometry"),
diff --git a/components/util/range.rs b/components/util/range.rs
index 2c66c24dcd1..d0143a30340 100644
--- a/components/util/range.rs
+++ b/components/util/range.rs
@@ -124,7 +124,7 @@ macro_rules! int_range_index {
}
/// A range of indices
-#[derive(Clone, RustcEncodable, Copy)]
+#[derive(Clone, RustcEncodable, Copy, Deserialize, Serialize)]
pub struct Range<I> {
begin: I,
length: I,