Auto merge of #13740 - shinglyu:layout_serde, r=jdm

Migrated -Z trace-layout to serde_json

<!-- Please describe your changes on the following line: -->

Migrated the trace-layout code from old `rustc-serialize` to `serde_json`. This will help us iterate faster on the layout viewer (#13432), #13436, #12675 and fix #12936.
---

<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #12936 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it's a relatively low risk debug tool

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---

This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13740)

<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-07 02:15:03 -06:00 committed by GitHub
commit 1c26f44cbb
19 changed files with 129 additions and 114 deletions

View file

@ -31,11 +31,12 @@ parking_lot = {version = "0.3.3", features = ["nightly"]}
plugins = {path = "../plugins"} plugins = {path = "../plugins"}
profile_traits = {path = "../profile_traits"} profile_traits = {path = "../profile_traits"}
range = {path = "../range"} range = {path = "../range"}
rustc-serialize = "0.3"
script_layout_interface = {path = "../script_layout_interface"} script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"} script_traits = {path = "../script_traits"}
selectors = "0.14" selectors = "0.14"
serde = "0.8"
serde_derive = "0.8" serde_derive = "0.8"
serde_json = "0.8"
servo_atoms = {path = "../atoms"} servo_atoms = {path = "../atoms"}
smallvec = "0.1" smallvec = "0.1"
style = {path = "../style"} style = {path = "../style"}

View file

@ -48,10 +48,10 @@ use gfx_traits::print_tree::PrintTree;
use layout_debug; use layout_debug;
use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto}; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo, MaybeAuto};
use model::{specified, specified_or_none}; 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::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW};
use script_layout_interface::restyle_damage::REPOSITION; use script_layout_interface::restyle_damage::REPOSITION;
use sequential; use sequential;
use serde::{Serialize, Serializer};
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::fmt; use std::fmt;
use std::sync::Arc; use std::sync::Arc;
@ -65,7 +65,7 @@ use style::values::computed::LengthOrPercentageOrAuto;
use util::clamp; use util::clamp;
/// Information specific to floated blocks. /// Information specific to floated blocks.
#[derive(Clone, RustcEncodable)] #[derive(Clone, Serialize)]
pub struct FloatedBlockInfo { pub struct FloatedBlockInfo {
/// The amount of inline size that is available for the float. /// The amount of inline size that is available for the float.
pub containing_inline_size: Au, pub containing_inline_size: Au,
@ -502,7 +502,7 @@ pub enum FormattingContextType {
} }
// A block formatting context. // A block formatting context.
#[derive(RustcEncodable)] #[derive(Serialize)]
pub struct BlockFlow { pub struct BlockFlow {
/// Data common to all flows. /// Data common to all flows.
pub base: BaseFlow, pub base: BaseFlow,
@ -526,9 +526,9 @@ bitflags! {
} }
} }
impl Encodable for BlockFlowFlags { impl Serialize for BlockFlowFlags {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
self.bits().encode(e) self.bits().serialize(serializer)
} }
} }

View file

@ -14,7 +14,7 @@ use style::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
use style::values::computed::LengthOrPercentageOrAuto; use style::values::computed::LengthOrPercentageOrAuto;
/// The kind of float: left or right. /// The kind of float: left or right.
#[derive(Clone, RustcEncodable, Debug, Copy)] #[derive(Clone, Serialize, Debug, Copy)]
pub enum FloatKind { pub enum FloatKind {
Left, Left,
Right Right

View file

@ -41,9 +41,9 @@ use inline::InlineFlow;
use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo}; use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo};
use multicol::MulticolFlow; use multicol::MulticolFlow;
use parallel::FlowParallelInfo; 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::{RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW};
use script_layout_interface::restyle_damage::{REPAINT, REPOSITION, RestyleDamage}; use script_layout_interface::restyle_damage::{REPAINT, REPOSITION, RestyleDamage};
use serde::{Serialize, Serializer};
use std::{fmt, mem, raw}; use std::{fmt, mem, raw};
use std::iter::Zip; use std::iter::Zip;
use std::slice::IterMut; use std::slice::IterMut;
@ -551,7 +551,7 @@ pub trait MutableOwnedFlowUtils {
absolute_descendants: &mut AbsoluteDescendants); absolute_descendants: &mut AbsoluteDescendants);
} }
#[derive(Copy, Clone, RustcEncodable, PartialEq, Debug)] #[derive(Copy, Clone, Serialize, PartialEq, Debug)]
pub enum FlowClass { pub enum FlowClass {
Block, Block,
Inline, Inline,
@ -821,7 +821,7 @@ impl EarlyAbsolutePositionInfo {
/// Information needed to compute absolute (i.e. viewport-relative) flow positions (not to be /// 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. /// confused with absolutely-positioned flows) that is computed during final position assignment.
#[derive(RustcEncodable, Copy, Clone)] #[derive(Serialize, Copy, Clone)]
pub struct LateAbsolutePositionInfo { pub struct LateAbsolutePositionInfo {
/// The position of the absolute containing block relative to the nearest ancestor stacking /// 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, /// 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 { impl Serialize for BaseFlow {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
e.emit_struct("base", 5, |e| { let mut state = try!(serializer.serialize_struct("base", 5));
try!(e.emit_struct_field("id", 0, |e| self.debug_id().encode(e))); try!(serializer.serialize_struct_elt(&mut state, "id", self.debug_id()));
try!(e.emit_struct_field("stacking_relative_position", try!(serializer.serialize_struct_elt(&mut state, "stacking_relative_position",
1, &self.stacking_relative_position));
|e| self.stacking_relative_position.encode(e))); try!(serializer.serialize_struct_elt(&mut state, "intrinsic_inline_sizes",
try!(e.emit_struct_field("intrinsic_inline_sizes", &self.intrinsic_inline_sizes));
2, try!(serializer.serialize_struct_elt(&mut state, "position", &self.position));
|e| self.intrinsic_inline_sizes.encode(e))); try!(serializer.serialize_struct_elt(&mut state, "children", &self.children));
try!(e.emit_struct_field("position", 3, |e| self.position.encode(e))); serializer.serialize_struct_end(state)
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(())
})
})
})
} }
} }

View file

@ -2,8 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use flow::Flow; use flow::{Flow, FlowClass};
use flow_ref::FlowRef; 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::collections::{LinkedList, linked_list};
use std::sync::Arc; use std::sync::Arc;
@ -20,6 +23,33 @@ pub struct FlowList {
flows: LinkedList<FlowRef>, flows: LinkedList<FlowRef>,
} }
impl Serialize for FlowList {
fn serialize<S: Serializer>(&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> { pub struct MutFlowListIterator<'a> {
it: linked_list::IterMut<'a, FlowRef>, it: linked_list::IterMut<'a, FlowRef>,
} }

View file

@ -63,3 +63,4 @@ impl WeakFlowRef {
self.0.upgrade().map(FlowRef) self.0.upgrade().map(FlowRef)
} }
} }

View file

@ -28,11 +28,11 @@ use msg::constellation_msg::PipelineId;
use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder}; use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
use range::*; use range::*;
use rustc_serialize::{Encodable, Encoder};
use script_layout_interface::HTMLCanvasData; use script_layout_interface::HTMLCanvasData;
use script_layout_interface::SVGSVGData; use script_layout_interface::SVGSVGData;
use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, RestyleDamage}; use script_layout_interface::restyle_damage::{RECONSTRUCT_FLOW, RestyleDamage};
use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use serde::{Serialize, Serializer};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cmp::{max, min}; use std::cmp::{max, min};
use std::collections::LinkedList; use std::collections::LinkedList;
@ -133,13 +133,13 @@ pub struct Fragment {
pub stacking_context_id: StackingContextId, pub stacking_context_id: StackingContextId,
} }
impl Encodable for Fragment { impl Serialize for Fragment {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
e.emit_struct("fragment", 3, |e| { let mut state = try!(serializer.serialize_struct("fragment", 3));
try!(e.emit_struct_field("id", 0, |e| self.debug_id.encode(e))); try!(serializer.serialize_struct_elt(&mut state, "id", &self.debug_id));
try!(e.emit_struct_field("border_box", 1, |e| self.border_box.encode(e))); try!(serializer.serialize_struct_elt(&mut state, "border_box", &self.border_box));
e.emit_struct_field("margin", 2, |e| self.margin.encode(e)) try!(serializer.serialize_struct_elt(&mut state, "margin", &self.margin));
}) serializer.serialize_struct_end(state)
} }
} }
@ -503,7 +503,7 @@ impl ImageFragmentInfo {
absolute_anchor_origin, absolute_anchor_origin,
image_size); image_size);
*tile_spacing = Au(0); *tile_spacing = Au(0);
*size = image_size;; *size = image_size;
return; return;
} }
@ -3162,16 +3162,15 @@ impl fmt::Display for DebugId {
} }
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
impl Encodable for DebugId { impl Serialize for DebugId {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
e.emit_str(&format!("{:p}", &self)) serializer.serialize_str(&format!("{:p}", &self))
} }
} }
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
impl Encodable for DebugId { impl Serialize for DebugId {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
e.emit_u16(self.0) serializer.serialize_u16(self.0)
} }
} }

View file

@ -65,7 +65,7 @@ use unicode_bidi;
/// with a float or a horizontal wall of the containing block. The block-start /// 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 /// 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. /// the green zone can be taller and wider than the line itself.
#[derive(RustcEncodable, Debug, Clone)] #[derive(Serialize, Debug, Clone)]
pub struct Line { pub struct Line {
/// A range of line indices that describe line breaks. /// A range of line indices that describe line breaks.
/// ///
@ -207,7 +207,7 @@ impl Line {
} }
int_range_index! { int_range_index! {
#[derive(RustcEncodable)] #[derive(Serialize)]
#[doc = "The index of a fragment in a flattened vector of DOM elements."] #[doc = "The index of a fragment in a flattened vector of DOM elements."]
struct FragmentIndex(isize) struct FragmentIndex(isize)
} }
@ -791,7 +791,7 @@ impl LineBreaker {
} }
/// Represents a list of inline fragments, including element ranges. /// Represents a list of inline fragments, including element ranges.
#[derive(RustcEncodable, Clone)] #[derive(Serialize, Clone)]
pub struct InlineFragments { pub struct InlineFragments {
/// The fragments themselves. /// The fragments themselves.
pub fragments: Vec<Fragment>, pub fragments: Vec<Fragment>,
@ -828,7 +828,7 @@ impl InlineFragments {
} }
/// Flows for inline layout. /// Flows for inline layout.
#[derive(RustcEncodable)] #[derive(Serialize)]
pub struct InlineFlow { pub struct InlineFlow {
/// Data common to all flows. /// Data common to all flows.
pub base: BaseFlow, pub base: BaseFlow,
@ -1780,7 +1780,7 @@ fn inline_contexts_are_equal(inline_context_a: &Option<InlineFragmentContext>,
/// ///
/// Descent is not included in this structure because it can be computed from the fragment's /// Descent is not included in this structure because it can be computed from the fragment's
/// border/content box and the ascent. /// border/content box and the ascent.
#[derive(Clone, Copy, Debug, RustcEncodable)] #[derive(Clone, Copy, Debug, Serialize)]
pub struct InlineMetrics { pub struct InlineMetrics {
/// The amount of space above the baseline needed for this fragment. /// The amount of space above the baseline needed for this fragment.
pub space_above_baseline: Au, pub space_above_baseline: Au,
@ -1831,7 +1831,7 @@ enum LineFlushMode {
Flush, Flush,
} }
#[derive(Copy, Clone, Debug, RustcEncodable)] #[derive(Copy, Clone, Debug, Serialize)]
pub struct LineMetrics { pub struct LineMetrics {
pub space_above_baseline: Au, pub space_above_baseline: Au,
pub space_below_baseline: Au, pub space_below_baseline: Au,

View file

@ -10,7 +10,7 @@
use flow; use flow;
use flow_ref::FlowRef; use flow_ref::FlowRef;
use rustc_serialize::json; use serde_json::{to_string, to_value, Value};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::RefCell; use std::cell::RefCell;
use std::fs::File; use std::fs::File;
@ -36,20 +36,20 @@ macro_rules! layout_debug_scope(
) )
); );
#[derive(RustcEncodable)] #[derive(Serialize)]
struct ScopeData { struct ScopeData {
name: String, name: String,
pre: String, pre: Value,
post: String, post: Value,
children: Vec<Box<ScopeData>>, children: Vec<Box<ScopeData>>,
} }
impl ScopeData { impl ScopeData {
fn new(name: String, pre: String) -> ScopeData { fn new(name: String, pre: Value) -> ScopeData {
ScopeData { ScopeData {
name: name, name: name,
pre: pre, pre: pre,
post: String::new(), post: Value::Null,
children: vec!(), children: vec!(),
} }
} }
@ -67,7 +67,7 @@ impl Scope {
STATE_KEY.with(|ref r| { STATE_KEY.with(|ref r| {
match *r.borrow_mut() { match *r.borrow_mut() {
Some(ref mut state) => { 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); let data = box ScopeData::new(name.clone(), flow_trace);
state.scope_stack.push(data); state.scope_stack.push(data);
} }
@ -85,7 +85,7 @@ impl Drop for Scope {
match *r.borrow_mut() { match *r.borrow_mut() {
Some(ref mut state) => { Some(ref mut state) => {
let mut current_scope = state.scope_stack.pop().unwrap(); 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(); let previous_scope = state.scope_stack.last_mut().unwrap();
previous_scope.children.push(current_scope); 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())); assert!(STATE_KEY.with(|ref r| r.borrow().is_none()));
STATE_KEY.with(|ref r| { 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 { let state = State {
scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)], scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)],
flow_root: flow_root.clone(), 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()); let mut thread_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap());
assert!(thread_state.scope_stack.len() == 1); assert!(thread_state.scope_stack.len() == 1);
let mut root_scope = thread_state.scope_stack.pop().unwrap(); 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(); let mut file = File::create(format!("layout_trace-{}.json", generation)).unwrap();
file.write_all(result.as_bytes()).unwrap(); file.write_all(result.as_bytes()).unwrap();
} }

View file

@ -44,9 +44,12 @@ extern crate plugins as servo_plugins;
extern crate profile_traits; extern crate profile_traits;
#[macro_use] #[macro_use]
extern crate range; extern crate range;
extern crate rustc_serialize;
extern crate script_layout_interface; extern crate script_layout_interface;
extern crate script_traits; extern crate script_traits;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use] extern crate servo_atoms; #[macro_use] extern crate servo_atoms;
extern crate smallvec; extern crate smallvec;
extern crate style; extern crate style;

View file

@ -301,7 +301,7 @@ pub enum MarginCollapseState {
} }
/// Intrinsic inline-sizes, which consist of minimum and preferred. /// Intrinsic inline-sizes, which consist of minimum and preferred.
#[derive(RustcEncodable, Copy, Clone)] #[derive(Serialize, Copy, Clone)]
pub struct IntrinsicISizes { pub struct IntrinsicISizes {
/// The *minimum inline-size* of the content. /// The *minimum inline-size* of the content.
pub minimum_inline_size: Au, pub minimum_inline_size: Au,

View file

@ -38,7 +38,7 @@ use table_wrapper::TableLayout;
/// A table flow corresponded to the table's internal table fragment under a table wrapper flow. /// 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, /// The properties `position`, `float`, and `margin-*` are used on the table wrapper fragment,
/// not table fragment per CSS 2.1 § 10.5. /// not table fragment per CSS 2.1 § 10.5.
#[derive(RustcEncodable)] #[derive(Serialize)]
pub struct TableFlow { pub struct TableFlow {
pub block_flow: BlockFlow, 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 /// 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 /// 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. /// assignment phase of layout will know which one to pick.
#[derive(Clone, RustcEncodable, Debug, Copy)] #[derive(Clone, Serialize, Debug, Copy)]
pub struct ColumnIntrinsicInlineSize { pub struct ColumnIntrinsicInlineSize {
/// The preferred intrinsic inline size. /// The preferred intrinsic inline size.
pub preferred: Au, pub preferred: Au,
@ -615,7 +615,7 @@ impl ColumnIntrinsicInlineSize {
/// ///
/// TODO(pcwalton): There will probably be some `border-collapse`-related info in here too /// TODO(pcwalton): There will probably be some `border-collapse`-related info in here too
/// eventually. /// eventually.
#[derive(RustcEncodable, Clone, Copy, Debug)] #[derive(Serialize, Clone, Copy, Debug)]
pub struct ColumnComputedInlineSize { pub struct ColumnComputedInlineSize {
/// The computed size of this inline column. /// The computed size of this inline column.
pub size: Au, pub size: Au,

View file

@ -30,7 +30,7 @@ use table::InternalTable;
use table_row::{CollapsedBorder, CollapsedBorderProvenance}; use table_row::{CollapsedBorder, CollapsedBorderProvenance};
/// A table formatting context. /// A table formatting context.
#[derive(RustcEncodable)] #[derive(Serialize)]
pub struct TableCellFlow { pub struct TableCellFlow {
/// Data common to all block flows. /// Data common to all block flows.
pub block_flow: BlockFlow, 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 struct CollapsedBordersForCell {
pub inline_start_border: CollapsedBorder, pub inline_start_border: CollapsedBorder,
pub inline_end_border: CollapsedBorder, pub inline_end_border: CollapsedBorder,

View file

@ -20,8 +20,8 @@ use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree; use gfx_traits::print_tree::PrintTree;
use layout_debug; use layout_debug;
use model::MaybeAuto; use model::MaybeAuto;
use rustc_serialize::{Encodable, Encoder};
use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW}; use script_layout_interface::restyle_damage::{REFLOW, REFLOW_OUT_OF_FLOW};
use serde::{Serialize, Serializer};
use std::cmp::max; use std::cmp::max;
use std::fmt; use std::fmt;
use std::iter::{Enumerate, IntoIterator, Peekable}; use std::iter::{Enumerate, IntoIterator, Peekable};
@ -65,14 +65,14 @@ pub struct TableRowFlow {
pub collapsed_border_spacing: CollapsedBorderSpacingForRow, pub collapsed_border_spacing: CollapsedBorderSpacingForRow,
} }
impl Encodable for TableRowFlow { impl Serialize for TableRowFlow {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
self.block_flow.encode(e) self.block_flow.serialize(serializer)
} }
} }
/// Information about the column inline size and span for each cell. /// Information about the column inline size and span for each cell.
#[derive(RustcEncodable, Copy, Clone)] #[derive(Serialize, Copy, Clone)]
pub struct CellIntrinsicInlineSize { pub struct CellIntrinsicInlineSize {
/// Inline sizes that this cell contributes to the column. /// Inline sizes that this cell contributes to the column.
pub column_size: ColumnIntrinsicInlineSize, pub column_size: ColumnIntrinsicInlineSize,
@ -559,8 +559,8 @@ pub struct CollapsedBorder {
pub provenance: CollapsedBorderProvenance, pub provenance: CollapsedBorderProvenance,
} }
impl Encodable for CollapsedBorder { impl Serialize for CollapsedBorder {
fn encode<S: Encoder>(&self, _: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, _: &mut S) -> Result<(), S::Error> {
Ok(()) Ok(())
} }
} }
@ -572,7 +572,7 @@ impl Encodable for CollapsedBorder {
// FIXME(#8586): FromTableRow, FromTableRowGroup, FromTableColumn, // FIXME(#8586): FromTableRow, FromTableRowGroup, FromTableColumn,
// FromTableColumnGroup are unused // FromTableColumnGroup are unused
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Copy, Clone, Debug, PartialEq, RustcEncodable)] #[derive(Copy, Clone, Debug, PartialEq, Serialize)]
pub enum CollapsedBorderProvenance { pub enum CollapsedBorderProvenance {
FromPreviousTableCell = 6, FromPreviousTableCell = 6,
FromNextTableCell = 5, FromNextTableCell = 5,

View file

@ -17,7 +17,7 @@ use gfx::display_list::StackingContext;
use gfx_traits::ScrollRootId; use gfx_traits::ScrollRootId;
use gfx_traits::print_tree::PrintTree; use gfx_traits::print_tree::PrintTree;
use layout_debug; use layout_debug;
use rustc_serialize::{Encodable, Encoder}; use serde::{Serialize, Serializer};
use std::fmt; use std::fmt;
use std::iter::{IntoIterator, Iterator, Peekable}; use std::iter::{IntoIterator, Iterator, Peekable};
use std::sync::Arc; use std::sync::Arc;
@ -55,9 +55,9 @@ pub struct TableRowGroupFlow {
pub collapsed_block_direction_border_widths_for_table: Vec<Au>, pub collapsed_block_direction_border_widths_for_table: Vec<Au>,
} }
impl Encodable for TableRowGroupFlow { impl Serialize for TableRowGroupFlow {
fn encode<S: Encoder>(&self, e: &mut S) -> Result<(), S::Error> { fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
self.block_flow.encode(e) self.block_flow.serialize(serializer)
} }
} }

View file

@ -39,14 +39,14 @@ use style::values::computed::LengthOrPercentageOrAuto;
use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize}; use table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize};
use table_row; use table_row;
#[derive(Copy, Clone, RustcEncodable, Debug)] #[derive(Copy, Clone, Serialize, Debug)]
pub enum TableLayout { pub enum TableLayout {
Fixed, Fixed,
Auto Auto
} }
/// A table wrapper flow based on a block formatting context. /// A table wrapper flow based on a block formatting context.
#[derive(RustcEncodable)] #[derive(Serialize)]
pub struct TableWrapperFlow { pub struct TableWrapperFlow {
pub block_flow: BlockFlow, pub block_flow: BlockFlow,

View file

@ -1213,11 +1213,12 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 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_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "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_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", "servo_atoms 0.0.1",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",

View file

@ -22,9 +22,9 @@ pub enum InlineBaseDirection {
RightToLeft RightToLeft
} }
// TODO: improve the readability of the WritingMode serialization, refer to the Debug:fmt()
bitflags!( bitflags!(
#[derive(RustcEncodable)] #[cfg_attr(feature = "servo", derive(HeapSizeOf, Serialize))]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub flags WritingMode: u8 { pub flags WritingMode: u8 {
const FLAG_RTL = 1 << 0, const FLAG_RTL = 1 << 0,
const FLAG_VERTICAL = 1 << 1, 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 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. /// In non-debug builds, make this storage zero-size and the checks no-ops.
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "servo", derive(Serialize))]
struct DebugWritingMode; struct DebugWritingMode;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
#[derive(RustcEncodable, PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "servo", derive(Serialize))]
struct DebugWritingMode { struct DebugWritingMode {
mode: WritingMode mode: WritingMode
} }
@ -212,7 +214,8 @@ impl Debug for DebugWritingMode {
/// A 2D size in flow-relative dimensions /// 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<T> { pub struct LogicalSize<T> {
pub inline: T, // inline-size, a.k.a. logical width, a.k.a. measure 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 pub block: T, // block-size, a.k.a. logical height, a.k.a. extent
@ -348,7 +351,8 @@ impl<T: Sub<T, Output=T>> Sub for LogicalSize<T> {
/// A 2D point in flow-relative dimensions /// 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<T> { pub struct LogicalPoint<T> {
/// inline-axis coordinate /// inline-axis coordinate
pub i: T, pub i: T,
@ -520,7 +524,8 @@ impl<T: Copy + Sub<T, Output=T>> Sub<LogicalSize<T>> for LogicalPoint<T> {
/// Represents the four sides of the margins, borders, or padding of a CSS box, /// Represents the four sides of the margins, borders, or padding of a CSS box,
/// or a combination of those. /// or a combination of those.
/// A positive "margin" can be added to a rectangle to obtain a bigger rectangle. /// 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<T> { pub struct LogicalMargin<T> {
pub block_start: T, pub block_start: T,
pub inline_end: T, pub inline_end: T,
@ -813,7 +818,8 @@ impl<T: Sub<T, Output=T>> Sub for LogicalMargin<T> {
/// A rectangle in flow-relative dimensions /// 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<T> { pub struct LogicalRect<T> {
pub start: LogicalPoint<T>, pub start: LogicalPoint<T>,
pub size: LogicalSize<T>, pub size: LogicalSize<T>,

3
ports/cef/Cargo.lock generated
View file

@ -1118,11 +1118,12 @@ dependencies = [
"plugins 0.0.1", "plugins 0.0.1",
"profile_traits 0.0.1", "profile_traits 0.0.1",
"range 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_layout_interface 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "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_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", "servo_atoms 0.0.1",
"smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",