From 8bea421329f584f8394bd9ffe874249d293b8249 Mon Sep 17 00:00:00 2001 From: Shing Lyu Date: Wed, 12 Oct 2016 11:47:04 +0800 Subject: [PATCH] Migrated -Z trace-layout to serde_json --- components/layout/Cargo.toml | 3 +- components/layout/block.rs | 12 +++--- components/layout/floats.rs | 2 +- components/layout/flow.rs | 55 +++++++--------------------- components/layout/flow_list.rs | 32 +++++++++++++++- components/layout/flow_ref.rs | 1 + components/layout/fragment.rs | 31 ++++++++-------- components/layout/inline.rs | 12 +++--- components/layout/layout_debug.rs | 22 +++++------ components/layout/lib.rs | 5 ++- components/layout/model.rs | 2 +- components/layout/table.rs | 6 +-- components/layout/table_cell.rs | 4 +- components/layout/table_row.rs | 16 ++++---- components/layout/table_rowgroup.rs | 8 ++-- components/layout/table_wrapper.rs | 4 +- components/servo/Cargo.lock | 3 +- components/style/logical_geometry.rs | 22 +++++++---- ports/cef/Cargo.lock | 3 +- 19 files changed, 129 insertions(+), 114 deletions(-) diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 49af18e17d4e..b1b0eb176f0c 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -31,11 +31,12 @@ parking_lot = {version = "0.3.3", features = ["nightly"]} plugins = {path = "../plugins"} profile_traits = {path = "../profile_traits"} range = {path = "../range"} -rustc-serialize = "0.3" script_layout_interface = {path = "../script_layout_interface"} script_traits = {path = "../script_traits"} selectors = "0.14" +serde = "0.8" serde_derive = "0.8" +serde_json = "0.8" servo_atoms = {path = "../atoms"} smallvec = "0.1" style = {path = "../style"} diff --git a/components/layout/block.rs b/components/layout/block.rs index c60b103e608b..71db966d69c3 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -48,10 +48,10 @@ use gfx_traits::print_tree::PrintTree; use layout_debug; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto}; use model::{specified, specified_or_none}; -use rustc_serialize::{Encodable, Encoder}; use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW}; use script_layout_interface::restyle_damage::REPOSITION; use sequential; +use serde::{Serialize, Serializer}; use std::cmp::{max, min}; use std::fmt; use std::sync::Arc; @@ -65,7 +65,7 @@ use style::values::computed::LengthOrPercentageOrAuto; use util::clamp; /// Information specific to floated blocks. -#[derive(Clone, RustcEncodable)] +#[derive(Clone, Serialize)] pub struct FloatedBlockInfo { /// The amount of inline size that is available for the float. pub containing_inline_size: Au, @@ -502,7 +502,7 @@ pub enum FormattingContextType { } // A block formatting context. -#[derive(RustcEncodable)] +#[derive(Serialize)] pub struct BlockFlow { /// Data common to all flows. pub base: BaseFlow, @@ -526,9 +526,9 @@ bitflags! { } } -impl Encodable for BlockFlowFlags { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - self.bits().encode(e) +impl Serialize for BlockFlowFlags { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + self.bits().serialize(serializer) } } diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 9fee4db43ca6..d7e419a97404 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -14,7 +14,7 @@ use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode}; use style::values::computed::LengthOrPercentageOrAuto; /// The kind of float: left or right. -#[derive(Clone, RustcEncodable, Debug, Copy)] +#[derive(Clone, Serialize, Debug, Copy)] pub enum FloatKind { Left, Right diff --git a/components/layout/flow.rs b/components/layout/flow.rs index cd6b7d7ae1e4..22f64438f918 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -41,9 +41,9 @@ use inline::InlineFlow; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo}; use multicol::MulticolFlow; use parallel::FlowParallelInfo; -use rustc_serialize::{Encodable, Encoder}; use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW}; use script_layout_interface::restyle_damage::{REPAINT, REPOSITION, RestyleDamage}; +use serde::{Serialize, Serializer}; use std::{fmt, mem, raw}; use std::iter::Zip; use std::slice::IterMut; @@ -551,7 +551,7 @@ pub trait MutableOwnedFlowUtils { absolute_descendants: &mut AbsoluteDescendants); } -#[derive(Copy, Clone, RustcEncodable, PartialEq, Debug)] +#[derive(Copy, Clone, Serialize, PartialEq, Debug)] pub enum FlowClass { Block, Inline, @@ -821,7 +821,7 @@ impl EarlyAbsolutePositionInfo { /// Information needed to compute absolute (i.e. viewport-relative) flow positions (not to be /// confused with absolutely-positioned flows) that is computed during final position assignment. -#[derive(RustcEncodable, Copy, Clone)] +#[derive(Serialize, Copy, Clone)] pub struct LateAbsolutePositionInfo { /// The position of the absolute containing block relative to the nearest ancestor stacking /// context. If the absolute containing block establishes the stacking context for this flow, @@ -978,44 +978,17 @@ impl fmt::Debug for BaseFlow { } } -impl Encodable for BaseFlow { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - e.emit_struct("base", 5, |e| { - try!(e.emit_struct_field("id", 0, |e| self.debug_id().encode(e))); - try!(e.emit_struct_field("stacking_relative_position", - 1, - |e| self.stacking_relative_position.encode(e))); - try!(e.emit_struct_field("intrinsic_inline_sizes", - 2, - |e| self.intrinsic_inline_sizes.encode(e))); - try!(e.emit_struct_field("position", 3, |e| self.position.encode(e))); - e.emit_struct_field("children", 4, |e| { - e.emit_seq(self.children.len(), |e| { - for (i, c) in self.children.iter().enumerate() { - try!(e.emit_seq_elt(i, |e| { - try!(e.emit_struct("flow", 2, |e| { - try!(e.emit_struct_field("class", 0, |e| c.class().encode(e))); - e.emit_struct_field("data", 1, |e| { - match c.class() { - FlowClass::Block => c.as_block().encode(e), - FlowClass::Inline => c.as_inline().encode(e), - FlowClass::Table => c.as_table().encode(e), - FlowClass::TableWrapper => c.as_table_wrapper().encode(e), - FlowClass::TableRowGroup => c.as_table_rowgroup().encode(e), - FlowClass::TableRow => c.as_table_row().encode(e), - FlowClass::TableCell => c.as_table_cell().encode(e), - _ => { Ok(()) } // TODO: Support captions - } - }) - })); - Ok(()) - })); - } - Ok(()) - }) - - }) - }) +impl Serialize for BaseFlow { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + let mut state = try!(serializer.serialize_struct("base", 5)); + try!(serializer.serialize_struct_elt(&mut state, "id", self.debug_id())); + try!(serializer.serialize_struct_elt(&mut state, "stacking_relative_position", + &self.stacking_relative_position)); + try!(serializer.serialize_struct_elt(&mut state, "intrinsic_inline_sizes", + &self.intrinsic_inline_sizes)); + try!(serializer.serialize_struct_elt(&mut state, "position", &self.position)); + try!(serializer.serialize_struct_elt(&mut state, "children", &self.children)); + serializer.serialize_struct_end(state) } } diff --git a/components/layout/flow_list.rs b/components/layout/flow_list.rs index 11fdddc6bdd1..8fd32af60f40 100644 --- a/components/layout/flow_list.rs +++ b/components/layout/flow_list.rs @@ -2,8 +2,11 @@ * 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 flow::Flow; +use flow::{Flow, FlowClass}; use flow_ref::FlowRef; +use serde::{Serialize, Serializer}; +use serde_json::{to_value, Value}; +use serde_json::builder::ObjectBuilder; use std::collections::{LinkedList, linked_list}; use std::sync::Arc; @@ -20,6 +23,33 @@ pub struct FlowList { flows: LinkedList, } +impl Serialize for FlowList { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + let mut state = try!(serializer.serialize_seq(Some(self.len()))); + for f in self.iter() { + let flow_val = ObjectBuilder::new() + .insert("class", f.class()) + .insert("data", match f.class() { + FlowClass::Block => to_value(f.as_block()), + FlowClass::Inline => to_value(f.as_inline()), + FlowClass::Table => to_value(f.as_table()), + FlowClass::TableWrapper => to_value(f.as_table_wrapper()), + FlowClass::TableRowGroup => to_value(f.as_table_rowgroup()), + FlowClass::TableRow => to_value(f.as_table_row()), + FlowClass::TableCell => to_value(f.as_table_cell()), + FlowClass::ListItem | FlowClass::TableColGroup | FlowClass::TableCaption | + FlowClass::Multicol | FlowClass::MulticolColumn | FlowClass::Flex => { + Value::Null // Not implemented yet + } + }) + .build(); + + try!(serializer.serialize_seq_elt(&mut state, flow_val)); + } + serializer.serialize_seq_end(state) + } +} + pub struct MutFlowListIterator<'a> { it: linked_list::IterMut<'a, FlowRef>, } diff --git a/components/layout/flow_ref.rs b/components/layout/flow_ref.rs index 2906d6e3c1f1..ea2c3ebf3315 100644 --- a/components/layout/flow_ref.rs +++ b/components/layout/flow_ref.rs @@ -63,3 +63,4 @@ impl WeakFlowRef { self.0.upgrade().map(FlowRef) } } + diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index e4eb0ea81f45..e624ad6013c2 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -28,11 +28,11 @@ use msg::constellation_msg::PipelineId; use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder}; use range::*; -use rustc_serialize::{Encodable, Encoder}; use script_layout_interface::HTMLCanvasData; use script_layout_interface::SVGSVGData; use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, RestyleDamage}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; +use serde::{Serialize, Serializer}; use std::borrow::ToOwned; use std::cmp::{max, min}; use std::collections::LinkedList; @@ -133,13 +133,13 @@ pub struct Fragment { pub stacking_context_id: StackingContextId, } -impl Encodable for Fragment { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - e.emit_struct("fragment", 3, |e| { - try!(e.emit_struct_field("id", 0, |e| self.debug_id.encode(e))); - try!(e.emit_struct_field("border_box", 1, |e| self.border_box.encode(e))); - e.emit_struct_field("margin", 2, |e| self.margin.encode(e)) - }) +impl Serialize for Fragment { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + let mut state = try!(serializer.serialize_struct("fragment", 3)); + try!(serializer.serialize_struct_elt(&mut state, "id", &self.debug_id)); + try!(serializer.serialize_struct_elt(&mut state, "border_box", &self.border_box)); + try!(serializer.serialize_struct_elt(&mut state, "margin", &self.margin)); + serializer.serialize_struct_end(state) } } @@ -503,7 +503,7 @@ impl ImageFragmentInfo { absolute_anchor_origin, image_size); *tile_spacing = Au(0); - *size = image_size;; + *size = image_size; return; } @@ -3162,16 +3162,15 @@ impl fmt::Display for DebugId { } #[cfg(not(debug_assertions))] -impl Encodable for DebugId { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - e.emit_str(&format!("{:p}", &self)) +impl Serialize for DebugId { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + serializer.serialize_str(&format!("{:p}", &self)) } } #[cfg(debug_assertions)] -impl Encodable for DebugId { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - e.emit_u16(self.0) +impl Serialize for DebugId { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + serializer.serialize_u16(self.0) } } - diff --git a/components/layout/inline.rs b/components/layout/inline.rs index b8e67632d1cc..80b8c29eae60 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -65,7 +65,7 @@ use unicode_bidi; /// with a float or a horizontal wall of the containing block. The block-start /// inline-start corner of the green zone is the same as that of the line, but /// the green zone can be taller and wider than the line itself. -#[derive(RustcEncodable, Debug, Clone)] +#[derive(Serialize, Debug, Clone)] pub struct Line { /// A range of line indices that describe line breaks. /// @@ -207,7 +207,7 @@ impl Line { } int_range_index! { - #[derive(RustcEncodable)] + #[derive(Serialize)] #[doc = "The index of a fragment in a flattened vector of DOM elements."] struct FragmentIndex(isize) } @@ -791,7 +791,7 @@ impl LineBreaker { } /// Represents a list of inline fragments, including element ranges. -#[derive(RustcEncodable, Clone)] +#[derive(Serialize, Clone)] pub struct InlineFragments { /// The fragments themselves. pub fragments: Vec, @@ -828,7 +828,7 @@ impl InlineFragments { } /// Flows for inline layout. -#[derive(RustcEncodable)] +#[derive(Serialize)] pub struct InlineFlow { /// Data common to all flows. pub base: BaseFlow, @@ -1780,7 +1780,7 @@ fn inline_contexts_are_equal(inline_context_a: &Option, /// /// Descent is not included in this structure because it can be computed from the fragment's /// border/content box and the ascent. -#[derive(Clone, Copy, Debug, RustcEncodable)] +#[derive(Clone, Copy, Debug, Serialize)] pub struct InlineMetrics { /// The amount of space above the baseline needed for this fragment. pub space_above_baseline: Au, @@ -1831,7 +1831,7 @@ enum LineFlushMode { Flush, } -#[derive(Copy, Clone, Debug, RustcEncodable)] +#[derive(Copy, Clone, Debug, Serialize)] pub struct LineMetrics { pub space_above_baseline: Au, pub space_below_baseline: Au, diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index 77ed1741adda..f98f253881fe 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -10,7 +10,7 @@ use flow; use flow_ref::FlowRef; -use rustc_serialize::json; +use serde_json::{to_string, to_value, Value}; use std::borrow::ToOwned; use std::cell::RefCell; use std::fs::File; @@ -36,20 +36,20 @@ macro_rules! layout_debug_scope( ) ); -#[derive(RustcEncodable)] +#[derive(Serialize)] struct ScopeData { name: String, - pre: String, - post: String, + pre: Value, + post: Value, children: Vec>, } impl ScopeData { - fn new(name: String, pre: String) -> ScopeData { + fn new(name: String, pre: Value) -> ScopeData { ScopeData { name: name, pre: pre, - post: String::new(), + post: Value::Null, children: vec!(), } } @@ -67,7 +67,7 @@ impl Scope { STATE_KEY.with(|ref r| { match *r.borrow_mut() { Some(ref mut state) => { - let flow_trace = json::encode(&flow::base(&*state.flow_root)).unwrap(); + let flow_trace = to_value(&flow::base(&*state.flow_root)); let data = box ScopeData::new(name.clone(), flow_trace); state.scope_stack.push(data); } @@ -85,7 +85,7 @@ impl Drop for Scope { match *r.borrow_mut() { Some(ref mut state) => { let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = json::encode(&flow::base(&*state.flow_root)).unwrap(); + current_scope.post = to_value(&flow::base(&*state.flow_root)); let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope); } @@ -109,7 +109,7 @@ pub fn begin_trace(flow_root: FlowRef) { assert!(STATE_KEY.with(|ref r| r.borrow().is_none())); STATE_KEY.with(|ref r| { - let flow_trace = json::encode(&flow::base(&*flow_root)).unwrap(); + let flow_trace = to_value(&flow::base(&*flow_root)); let state = State { scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)], flow_root: flow_root.clone(), @@ -125,9 +125,9 @@ pub fn end_trace(generation: u32) { let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap()); assert!(thread_state.scope_stack.len() == 1); let mut root_scope = thread_state.scope_stack.pop().unwrap(); - root_scope.post = json::encode(&flow::base(&*thread_state.flow_root)).unwrap(); + root_scope.post = to_value(&flow::base(&*thread_state.flow_root)); - let result = json::encode(&root_scope).unwrap(); + let result = to_string(&root_scope).unwrap(); let mut file = File::create(format!("layout_trace-{}.json", generation)).unwrap(); file.write_all(result.as_bytes()).unwrap(); } diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 8284f2fc8359..a39e7af2eb23 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -44,9 +44,12 @@ extern crate plugins as servo_plugins; extern crate profile_traits; #[macro_use] extern crate range; -extern crate rustc_serialize; extern crate script_layout_interface; extern crate script_traits; +extern crate serde; +#[macro_use] +extern crate serde_derive; +extern crate serde_json; #[macro_use] extern crate servo_atoms; extern crate smallvec; extern crate style; diff --git a/components/layout/model.rs b/components/layout/model.rs index 823ca6469d3b..4d2ef8e8c875 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -301,7 +301,7 @@ pub enum MarginCollapseState { } /// Intrinsic inline-sizes, which consist of minimum and preferred. -#[derive(RustcEncodable, Copy, Clone)] +#[derive(Serialize, Copy, Clone)] pub struct IntrinsicISizes { /// The *minimum inline-size* of the content. pub minimum_inline_size: Au, diff --git a/components/layout/table.rs b/components/layout/table.rs index 1d904e00b23f..3ffc5231f5ae 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -38,7 +38,7 @@ use table_wrapper::TableLayout; /// A table flow corresponded to the table's internal table fragment under a table wrapper flow. /// The properties `position`, `float`, and `margin-*` are used on the table wrapper fragment, /// not table fragment per CSS 2.1 ยง 10.5. -#[derive(RustcEncodable)] +#[derive(Serialize)] pub struct TableFlow { pub block_flow: BlockFlow, @@ -578,7 +578,7 @@ impl ISizeAndMarginsComputer for InternalTable { /// maximum of 100 pixels and 20% of the table), the preceding constraint means that we must /// potentially store both a specified width *and* a specified percentage, so that the inline-size /// assignment phase of layout will know which one to pick. -#[derive(Clone, RustcEncodable, Debug, Copy)] +#[derive(Clone, Serialize, Debug, Copy)] pub struct ColumnIntrinsicInlineSize { /// The preferred intrinsic inline size. pub preferred: Au, @@ -615,7 +615,7 @@ impl ColumnIntrinsicInlineSize { /// /// TODO(pcwalton): There will probably be some `border-collapse`-related info in here too /// eventually. -#[derive(RustcEncodable, Clone, Copy, Debug)] +#[derive(Serialize, Clone, Copy, Debug)] pub struct ColumnComputedInlineSize { /// The computed size of this inline column. pub size: Au, diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index ca2af6a48978..abdcf03cb2bc 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -30,7 +30,7 @@ use table::InternalTable; use table_row::{CollapsedBorder, CollapsedBorderProvenance}; /// A table formatting context. -#[derive(RustcEncodable)] +#[derive(Serialize)] pub struct TableCellFlow { /// Data common to all block flows. pub block_flow: BlockFlow, @@ -297,7 +297,7 @@ impl fmt::Debug for TableCellFlow { } } -#[derive(Copy, Clone, Debug, RustcEncodable)] +#[derive(Copy, Clone, Debug, Serialize)] pub struct CollapsedBordersForCell { pub inline_start_border: CollapsedBorder, pub inline_end_border: CollapsedBorder, diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 19f423a576c3..1b4df7b7bfc4 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -20,8 +20,8 @@ use gfx_traits::ScrollRootId; use gfx_traits::print_tree::PrintTree; use layout_debug; use model::MaybeAuto; -use rustc_serialize::{Encodable, Encoder}; use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; +use serde::{Serialize, Serializer}; use std::cmp::max; use std::fmt; use std::iter::{Enumerate, IntoIterator, Peekable}; @@ -65,14 +65,14 @@ pub struct TableRowFlow { pub collapsed_border_spacing: CollapsedBorderSpacingForRow, } -impl Encodable for TableRowFlow { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - self.block_flow.encode(e) +impl Serialize for TableRowFlow { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + self.block_flow.serialize(serializer) } } /// Information about the column inline size and span for each cell. -#[derive(RustcEncodable, Copy, Clone)] +#[derive(Serialize, Copy, Clone)] pub struct CellIntrinsicInlineSize { /// Inline sizes that this cell contributes to the column. pub column_size: ColumnIntrinsicInlineSize, @@ -559,8 +559,8 @@ pub struct CollapsedBorder { pub provenance: CollapsedBorderProvenance, } -impl Encodable for CollapsedBorder { - fn encode(&self, _: &mut S) -> Result<(), S::Error> { +impl Serialize for CollapsedBorder { + fn serialize(&self, _: &mut S) -> Result<(), S::Error> { Ok(()) } } @@ -572,7 +572,7 @@ impl Encodable for CollapsedBorder { // FIXME(#8586): FromTableRow, FromTableRowGroup, FromTableColumn, // FromTableColumnGroup are unused #[allow(dead_code)] -#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable)] +#[derive(Copy, Clone, Debug, PartialEq, Serialize)] pub enum CollapsedBorderProvenance { FromPreviousTableCell = 6, FromNextTableCell = 5, diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index d1f3e1754a44..f7e450b09f91 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -17,7 +17,7 @@ use gfx::display_list::StackingContext; use gfx_traits::ScrollRootId; use gfx_traits::print_tree::PrintTree; use layout_debug; -use rustc_serialize::{Encodable, Encoder}; +use serde::{Serialize, Serializer}; use std::fmt; use std::iter::{IntoIterator, Iterator, Peekable}; use std::sync::Arc; @@ -55,9 +55,9 @@ pub struct TableRowGroupFlow { pub collapsed_block_direction_border_widths_for_table: Vec, } -impl Encodable for TableRowGroupFlow { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - self.block_flow.encode(e) +impl Serialize for TableRowGroupFlow { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> { + self.block_flow.serialize(serializer) } } diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 1fcf08b249b3..ede99df7bc11 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -39,14 +39,14 @@ use style::values::computed::LengthOrPercentageOrAuto; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize}; use table_row; -#[derive(Copy, Clone, RustcEncodable, Debug)] +#[derive(Copy, Clone, Serialize, Debug)] pub enum TableLayout { Fixed, Auto } /// A table wrapper flow based on a block formatting context. -#[derive(RustcEncodable)] +#[derive(Serialize)] pub struct TableWrapperFlow { pub block_flow: BlockFlow, diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index df9ff55045bf..587b0cd84ab4 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -1213,11 +1213,12 @@ dependencies = [ "plugins 0.0.1", "profile_traits 0.0.1", "range 0.0.1", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script_layout_interface 0.0.1", "script_traits 0.0.1", "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "servo_atoms 0.0.1", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", diff --git a/components/style/logical_geometry.rs b/components/style/logical_geometry.rs index 0bf47cbc5750..94dcd3881db2 100644 --- a/components/style/logical_geometry.rs +++ b/components/style/logical_geometry.rs @@ -22,9 +22,9 @@ pub enum InlineBaseDirection { RightToLeft } +// TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt() bitflags!( - #[derive(RustcEncodable)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize))] pub flags WritingMode: u8 { const FLAG_RTL = 1 << 0, const FLAG_VERTICAL = 1 << 1, @@ -157,11 +157,13 @@ impl fmt::Display for WritingMode { /// (in addition to taking it as a parameter to methods) and check it. /// In non-debug builds, make this storage zero-size and the checks no-ops. #[cfg(not(debug_assertions))] -#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] struct DebugWritingMode; #[cfg(debug_assertions)] -#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] struct DebugWritingMode { mode: WritingMode } @@ -212,7 +214,8 @@ impl Debug for DebugWritingMode { /// A 2D size in flow-relative dimensions -#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] pub struct LogicalSize { pub inline: T, // inline-size, a.k.a. logical width, a.k.a. measure pub block: T, // block-size, a.k.a. logical height, a.k.a. extent @@ -348,7 +351,8 @@ impl> Sub for LogicalSize { /// A 2D point in flow-relative dimensions -#[derive(PartialEq, RustcEncodable, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] pub struct LogicalPoint { /// inline-axis coordinate pub i: T, @@ -520,7 +524,8 @@ impl> Sub> for LogicalPoint { /// Represents the four sides of the margins, borders, or padding of a CSS box, /// or a combination of those. /// A positive "margin" can be added to a rectangle to obtain a bigger rectangle. -#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] pub struct LogicalMargin { pub block_start: T, pub inline_end: T, @@ -813,7 +818,8 @@ impl> Sub for LogicalMargin { /// A rectangle in flow-relative dimensions -#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "servo", derive(Serialize))] pub struct LogicalRect { pub start: LogicalPoint, pub size: LogicalSize, diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index b5e3f64ca713..4d1760aef700 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -1118,11 +1118,12 @@ dependencies = [ "plugins 0.0.1", "profile_traits 0.0.1", "range 0.0.1", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "script_layout_interface 0.0.1", "script_traits 0.0.1", "selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "servo_atoms 0.0.1", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1",