servo: Merge #3686 - Use the Deref traits for FlowRefs (from cgaebel:deref-flows); r=pcwalton

This patch switches FlowRefs to using the Deref and DerefMut traits, instead of
the custom `get` and `get_mut` functions.

Source-Repo: https://github.com/servo/servo
Source-Revision: 6a11ee89de82abae9d6607a6c2890692df5259eb
This commit is contained in:
Clark Gaebel 2014-10-15 16:18:23 -06:00
Родитель 538f3a571c
Коммит 39c7ff714e
10 изменённых файлов: 76 добавлений и 74 удалений

Просмотреть файл

@ -329,7 +329,7 @@ impl<'a> FlowConstructor<'a> {
} }
{ {
let inline_flow = inline_flow_ref.get_mut().as_inline(); let inline_flow = inline_flow_ref.as_inline();
// We must scan for runs before computing minimum ascent and descent because scanning // We must scan for runs before computing minimum ascent and descent because scanning
// for runs might collapse so much whitespace away that only hypothetical fragments // for runs might collapse so much whitespace away that only hypothetical fragments
@ -345,7 +345,7 @@ impl<'a> FlowConstructor<'a> {
inline_flow_ref.finish(self.layout_context); inline_flow_ref.finish(self.layout_context);
if flow.get().need_anonymous_flow(inline_flow_ref.get()) { if flow.need_anonymous_flow(&*inline_flow_ref) {
flow_list.push(inline_flow_ref) flow_list.push(inline_flow_ref)
} else { } else {
flow.add_new_child(inline_flow_ref) flow.add_new_child(inline_flow_ref)
@ -366,10 +366,10 @@ impl<'a> FlowConstructor<'a> {
FlowConstructionResult(kid_flow, kid_abs_descendants) => { FlowConstructionResult(kid_flow, kid_abs_descendants) => {
// If kid_flow is TableCaptionFlow, kid_flow should be added under // If kid_flow is TableCaptionFlow, kid_flow should be added under
// TableWrapperFlow. // TableWrapperFlow.
if flow.get().is_table() && kid_flow.get().is_table_caption() { if flow.is_table() && kid_flow.deref().is_table_caption() {
kid.set_flow_construction_result(FlowConstructionResult(kid_flow, kid.set_flow_construction_result(FlowConstructionResult(kid_flow,
Descendants::new())) Descendants::new()))
} else if flow.get().need_anonymous_flow(kid_flow.get()) { } else if flow.need_anonymous_flow(&*kid_flow) {
consecutive_siblings.push(kid_flow) consecutive_siblings.push(kid_flow)
} else { } else {
// Flush any inline fragments that we were gathering up. This allows us to // Flush any inline fragments that we were gathering up. This allows us to
@ -429,7 +429,7 @@ impl<'a> FlowConstructor<'a> {
// Push the flow generated by the {ib} split onto our list of // Push the flow generated by the {ib} split onto our list of
// flows. // flows.
if flow.get().need_anonymous_flow(kid_flow.get()) { if flow.need_anonymous_flow(&*kid_flow) {
consecutive_siblings.push(kid_flow) consecutive_siblings.push(kid_flow)
} else { } else {
flow.add_new_child(kid_flow) flow.add_new_child(kid_flow)
@ -514,8 +514,8 @@ impl<'a> FlowConstructor<'a> {
flow.finish(self.layout_context); flow.finish(self.layout_context);
// Set up the absolute descendants. // Set up the absolute descendants.
let is_positioned = flow.get_mut().as_block().is_positioned(); let is_positioned = flow.as_block().is_positioned();
let is_absolutely_positioned = flow.get_mut().as_block().is_absolutely_positioned(); let is_absolutely_positioned = flow.as_block().is_absolutely_positioned();
if is_positioned { if is_positioned {
// This is the containing block for all the absolute descendants. // This is the containing block for all the absolute descendants.
flow.set_absolute_descendants(abs_descendants); flow.set_absolute_descendants(abs_descendants);
@ -747,7 +747,7 @@ impl<'a> FlowConstructor<'a> {
NoConstructionResult | ConstructionItemConstructionResult(_) => {} NoConstructionResult | ConstructionItemConstructionResult(_) => {}
FlowConstructionResult(kid_flow, _) => { FlowConstructionResult(kid_flow, _) => {
// Only kid flows with table-caption are matched here. // Only kid flows with table-caption are matched here.
if kid_flow.get().is_table_caption() { if kid_flow.deref().is_table_caption() {
table_wrapper_flow.add_new_child(kid_flow); table_wrapper_flow.add_new_child(kid_flow);
} }
} }
@ -761,10 +761,10 @@ impl<'a> FlowConstructor<'a> {
child_flows: Vec<FlowRef>, child_flows: Vec<FlowRef>,
flow: &mut FlowRef, flow: &mut FlowRef,
node: &ThreadSafeLayoutNode) { node: &ThreadSafeLayoutNode) {
let mut anonymous_flow = flow.get().generate_missing_child_flow(node); let mut anonymous_flow = flow.generate_missing_child_flow(node);
let mut consecutive_siblings = vec!(); let mut consecutive_siblings = vec!();
for kid_flow in child_flows.into_iter() { for kid_flow in child_flows.into_iter() {
if anonymous_flow.get().need_anonymous_flow(kid_flow.get()) { if anonymous_flow.need_anonymous_flow(&*kid_flow) {
consecutive_siblings.push(kid_flow); consecutive_siblings.push(kid_flow);
continue; continue;
} }
@ -823,11 +823,9 @@ impl<'a> FlowConstructor<'a> {
// The flow is done. // The flow is done.
wrapper_flow.finish(self.layout_context); wrapper_flow.finish(self.layout_context);
let is_positioned = wrapper_flow.get_mut().as_block().is_positioned(); let is_positioned = wrapper_flow.as_block().is_positioned();
let is_fixed_positioned = wrapper_flow.get_mut().as_block().is_fixed(); let is_fixed_positioned = wrapper_flow.as_block().is_fixed();
let is_absolutely_positioned = wrapper_flow.get_mut() let is_absolutely_positioned = wrapper_flow.as_block().is_absolutely_positioned();
.as_block()
.is_absolutely_positioned();
if is_positioned { if is_positioned {
// This is the containing block for all the absolute descendants. // This is the containing block for all the absolute descendants.
wrapper_flow.set_absolute_descendants(abs_descendants); wrapper_flow.set_absolute_descendants(abs_descendants);
@ -1185,10 +1183,10 @@ impl FlowConstructionUtils for FlowRef {
/// ///
/// This must not be public because only the layout constructor can do this. /// This must not be public because only the layout constructor can do this.
fn add_new_child(&mut self, mut new_child: FlowRef) { fn add_new_child(&mut self, mut new_child: FlowRef) {
let base = flow::mut_base(self.get_mut()); let base = flow::mut_base(self.deref_mut());
{ {
let kid_base = flow::mut_base(new_child.get_mut()); let kid_base = flow::mut_base(new_child.deref_mut());
kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self); kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self);
} }
@ -1206,7 +1204,7 @@ impl FlowConstructionUtils for FlowRef {
/// This must not be public because only the layout constructor can do this. /// This must not be public because only the layout constructor can do this.
fn finish(&mut self, context: &LayoutContext) { fn finish(&mut self, context: &LayoutContext) {
if !context.shared.opts.bubble_inline_sizes_separately { if !context.shared.opts.bubble_inline_sizes_separately {
self.get_mut().bubble_inline_sizes() self.bubble_inline_sizes()
} }
} }
} }

Просмотреть файл

@ -644,7 +644,7 @@ impl<'a> Iterator<&'a mut Flow + 'a> for DescendantIter<'a> {
None => None, None => None,
Some(ref mut flow) => { Some(ref mut flow) => {
unsafe { unsafe {
let result: &'a mut Flow = mem::transmute(flow.get_mut()); let result: &'a mut Flow = mem::transmute(flow.deref_mut());
Some(result) Some(result)
} }
} }
@ -1258,7 +1258,7 @@ impl MutableOwnedFlowUtils for FlowRef {
fn set_absolute_descendants(&mut self, abs_descendants: AbsDescendants) { fn set_absolute_descendants(&mut self, abs_descendants: AbsDescendants) {
let this = self.clone(); let this = self.clone();
let block = self.get_mut().as_block(); let block = self.as_block();
block.base.abs_descendants = abs_descendants; block.base.abs_descendants = abs_descendants;
for descendant_link in block.base.abs_descendants.iter() { for descendant_link in block.base.abs_descendants.iter() {
@ -1300,7 +1300,7 @@ impl ContainingBlockLink {
pub fn generated_containing_block_rect(&mut self) -> LogicalRect<Au> { pub fn generated_containing_block_rect(&mut self) -> LogicalRect<Au> {
match self.link { match self.link {
None => fail!("haven't done it"), None => fail!("haven't done it"),
Some(ref mut link) => link.get_mut().generated_containing_block_rect(), Some(ref mut link) => link.generated_containing_block_rect(),
} }
} }
} }

Просмотреть файл

@ -39,25 +39,25 @@ impl FlowList {
/// Provide a reference to the front element, or None if the list is empty /// Provide a reference to the front element, or None if the list is empty
#[inline] #[inline]
pub fn front<'a>(&'a self) -> Option<&'a Flow> { pub fn front<'a>(&'a self) -> Option<&'a Flow> {
self.flows.front().map(|head| head.get()) self.flows.front().map(|head| head.deref())
} }
/// Provide a mutable reference to the front element, or None if the list is empty /// Provide a mutable reference to the front element, or None if the list is empty
#[inline] #[inline]
pub unsafe fn front_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { pub unsafe fn front_mut<'a>(&'a mut self) -> Option<&'a mut Flow> {
self.flows.front_mut().map(|head| head.get_mut()) self.flows.front_mut().map(|head| head.deref_mut())
} }
/// Provide a reference to the back element, or None if the list is empty /// Provide a reference to the back element, or None if the list is empty
#[inline] #[inline]
pub fn back<'a>(&'a self) -> Option<&'a Flow> { pub fn back<'a>(&'a self) -> Option<&'a Flow> {
self.flows.back().map(|tail| tail.get()) self.flows.back().map(|tail| tail.deref())
} }
/// Provide a mutable reference to the back element, or None if the list is empty /// Provide a mutable reference to the back element, or None if the list is empty
#[inline] #[inline]
pub unsafe fn back_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { pub unsafe fn back_mut<'a>(&'a mut self) -> Option<&'a mut Flow> {
self.flows.back_mut().map(|tail| tail.get_mut()) self.flows.back_mut().map(|tail| tail.deref_mut())
} }
/// Add an element first in the list /// Add an element first in the list
@ -109,7 +109,7 @@ impl FlowList {
impl<'a> Iterator<&'a Flow + 'a> for FlowListIterator<'a> { impl<'a> Iterator<&'a Flow + 'a> for FlowListIterator<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a Flow + 'a> { fn next(&mut self) -> Option<&'a Flow + 'a> {
self.it.next().map(|x| x.get()) self.it.next().map(|x| x.deref())
} }
#[inline] #[inline]
@ -121,7 +121,7 @@ impl<'a> Iterator<&'a Flow + 'a> for FlowListIterator<'a> {
impl<'a> Iterator<&'a mut Flow + 'a> for MutFlowListIterator<'a> { impl<'a> Iterator<&'a mut Flow + 'a> for MutFlowListIterator<'a> {
#[inline] #[inline]
fn next(&mut self) -> Option<&'a mut Flow + 'a> { fn next(&mut self) -> Option<&'a mut Flow + 'a> {
self.it.next().map(|x| x.get_mut()) self.it.next().map(|x| x.deref_mut())
} }
#[inline] #[inline]

Просмотреть файл

@ -31,16 +31,20 @@ impl FlowRef {
result result
} }
} }
}
pub fn get<'a>(&'a self) -> &'a Flow { impl Deref<Flow + 'static> for FlowRef {
fn deref<'a>(&'a self) -> &'a Flow + 'static {
unsafe { unsafe {
mem::transmute_copy::<raw::TraitObject, &'a Flow>(&self.object) mem::transmute_copy::<raw::TraitObject, &'a Flow + 'static>(&self.object)
} }
} }
}
pub fn get_mut<'a>(&'a mut self) -> &'a mut Flow { impl DerefMut<Flow + 'static> for FlowRef {
fn deref_mut<'a>(&'a mut self) -> &'a mut Flow + 'static {
unsafe { unsafe {
mem::transmute_copy::<raw::TraitObject, &'a mut Flow>(&self.object) mem::transmute_copy::<raw::TraitObject, &'a mut Flow + 'static>(&self.object)
} }
} }
} }
@ -51,7 +55,7 @@ impl Drop for FlowRef {
if self.object.vtable.is_null() { if self.object.vtable.is_null() {
return return
} }
if flow::base(self.get()).ref_count().fetch_sub(1, SeqCst) > 1 { if flow::base(self.deref()).ref_count().fetch_sub(1, SeqCst) > 1 {
return return
} }
let flow_ref: FlowRef = mem::replace(self, FlowRef { let flow_ref: FlowRef = mem::replace(self, FlowRef {
@ -71,7 +75,7 @@ impl Drop for FlowRef {
impl Clone for FlowRef { impl Clone for FlowRef {
fn clone(&self) -> FlowRef { fn clone(&self) -> FlowRef {
unsafe { unsafe {
drop(flow::base(self.get()).ref_count().fetch_add(1, SeqCst)); drop(flow::base(self.deref()).ref_count().fetch_add(1, SeqCst));
FlowRef { FlowRef {
object: raw::TraitObject { object: raw::TraitObject {
vtable: self.object.vtable, vtable: self.object.vtable,
@ -81,4 +85,3 @@ impl Clone for FlowRef {
} }
} }
} }

Просмотреть файл

@ -1321,7 +1321,7 @@ impl Fragment {
TableColumnFragment(_) | TableRowFragment | TableWrapperFragment | TableColumnFragment(_) | TableRowFragment | TableWrapperFragment |
InlineAbsoluteHypotheticalFragment(_) | InputFragment => {} InlineAbsoluteHypotheticalFragment(_) | InputFragment => {}
InlineBlockFragment(ref mut info) => { InlineBlockFragment(ref mut info) => {
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
result.union_block(&block_flow.base.intrinsic_inline_sizes) result.union_block(&block_flow.base.intrinsic_inline_sizes)
} }
ImageFragment(ref mut image_fragment_info) => { ImageFragment(ref mut image_fragment_info) => {
@ -1591,7 +1591,7 @@ impl Fragment {
match self.specific { match self.specific {
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
block_flow.base.position.size.inline = block_flow.base.position.size.inline =
block_flow.base.intrinsic_inline_sizes.preferred_inline_size; block_flow.base.intrinsic_inline_sizes.preferred_inline_size;
@ -1599,7 +1599,7 @@ impl Fragment {
self.border_box.size.inline = Au(0); self.border_box.size.inline = Au(0);
} }
InlineBlockFragment(ref mut info) => { InlineBlockFragment(ref mut info) => {
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
self.border_box.size.inline = self.border_box.size.inline =
block_flow.base.intrinsic_inline_sizes.preferred_inline_size; block_flow.base.intrinsic_inline_sizes.preferred_inline_size;
block_flow.base.block_container_inline_size = self.border_box.size.inline; block_flow.base.block_container_inline_size = self.border_box.size.inline;
@ -1714,13 +1714,13 @@ impl Fragment {
} }
InlineBlockFragment(ref mut info) => { InlineBlockFragment(ref mut info) => {
// Not the primary fragment, so we do not take the noncontent size into account. // Not the primary fragment, so we do not take the noncontent size into account.
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
self.border_box.size.block = block_flow.base.position.size.block + self.border_box.size.block = block_flow.base.position.size.block +
block_flow.fragment.margin.block_start_end() block_flow.fragment.margin.block_start_end()
} }
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
// Not the primary fragment, so we do not take the noncontent size into account. // Not the primary fragment, so we do not take the noncontent size into account.
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
self.border_box.size.block = block_flow.base.position.size.block; self.border_box.size.block = block_flow.base.position.size.block;
} }
_ => fail!("should have been handled above"), _ => fail!("should have been handled above"),
@ -1746,7 +1746,7 @@ impl Fragment {
} }
InlineBlockFragment(ref info) => { InlineBlockFragment(ref info) => {
// See CSS 2.1 § 10.8.1. // See CSS 2.1 § 10.8.1.
let block_flow = info.flow_ref.get().as_immutable_block(); let block_flow = info.flow_ref.deref().as_immutable_block();
let font_style = text::computed_style_to_font_style(&*self.style); let font_style = text::computed_style_to_font_style(&*self.style);
let font_metrics = text::font_metrics_for_style(layout_context.font_context(), let font_metrics = text::font_metrics_for_style(layout_context.font_context(),
&font_style); &font_style);
@ -1839,7 +1839,7 @@ impl Fragment {
match self.specific { match self.specific {
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
let position = self.border_box.start.i; let position = self.border_box.start.i;
info.flow_ref.get_mut().update_late_computed_inline_position_if_necessary(position) info.flow_ref.update_late_computed_inline_position_if_necessary(position)
} }
_ => {} _ => {}
} }
@ -1849,7 +1849,7 @@ impl Fragment {
match self.specific { match self.specific {
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
let position = self.border_box.start.b; let position = self.border_box.start.b;
info.flow_ref.get_mut().update_late_computed_block_position_if_necessary(position) info.flow_ref.update_late_computed_block_position_if_necessary(position)
} }
_ => {} _ => {}
} }
@ -1912,4 +1912,3 @@ bitflags! {
static IntrinsicInlineSizeIncludesSpecified = 0x08, static IntrinsicInlineSizeIncludesSpecified = 0x08,
} }
} }

Просмотреть файл

@ -710,7 +710,7 @@ impl InlineFlow {
&self.base.clip_rect); &self.base.clip_rect);
match fragment.specific { match fragment.specific {
InlineBlockFragment(ref mut block_flow) => { InlineBlockFragment(ref mut block_flow) => {
let block_flow = block_flow.flow_ref.get_mut(); let block_flow = block_flow.flow_ref.deref_mut();
self.base.display_list.push_all_move( self.base.display_list.push_all_move(
mem::replace(&mut flow::mut_base(block_flow).display_list, mem::replace(&mut flow::mut_base(block_flow).display_list,
DisplayList::new())); DisplayList::new()));
@ -1117,7 +1117,7 @@ impl Flow for InlineFlow {
for fragment in self.fragments.fragments.iter_mut() { for fragment in self.fragments.fragments.iter_mut() {
let absolute_position = match fragment.specific { let absolute_position = match fragment.specific {
InlineBlockFragment(ref mut info) => { InlineBlockFragment(ref mut info) => {
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
// FIXME(#2795): Get the real container size // FIXME(#2795): Get the real container size
let container_size = Size2D::zero(); let container_size = Size2D::zero();
@ -1128,7 +1128,7 @@ impl Flow for InlineFlow {
block_flow.base.abs_position block_flow.base.abs_position
} }
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
let block_flow = info.flow_ref.get_mut().as_block(); let block_flow = info.flow_ref.as_block();
// FIXME(#2795): Get the real container size // FIXME(#2795): Get the real container size
let container_size = Size2D::zero(); let container_size = Size2D::zero();
block_flow.base.abs_position = block_flow.base.abs_position =
@ -1146,10 +1146,10 @@ impl Flow for InlineFlow {
match fragment.specific { match fragment.specific {
InlineBlockFragment(ref mut info) => { InlineBlockFragment(ref mut info) => {
flow::mut_base(info.flow_ref.get_mut()).clip_rect = clip_rect flow::mut_base(info.flow_ref.deref_mut()).clip_rect = clip_rect
} }
InlineAbsoluteHypotheticalFragment(ref mut info) => { InlineAbsoluteHypotheticalFragment(ref mut info) => {
flow::mut_base(info.flow_ref.get_mut()).clip_rect = clip_rect flow::mut_base(info.flow_ref.deref_mut()).clip_rect = clip_rect
} }
_ => {} _ => {}
} }

Просмотреть файл

@ -62,7 +62,7 @@ impl Scope {
match maybe_refcell { match maybe_refcell {
Some(refcell) => { Some(refcell) => {
let mut state = refcell.borrow_mut(); let mut state = refcell.borrow_mut();
let flow_trace = json::encode(&state.flow_root.get()); let flow_trace = json::encode(&state.flow_root.deref());
let data = box ScopeData::new(name, flow_trace); let data = box ScopeData::new(name, flow_trace);
state.scope_stack.push(data); state.scope_stack.push(data);
} }
@ -80,7 +80,7 @@ impl Drop for Scope {
Some(refcell) => { Some(refcell) => {
let mut state = refcell.borrow_mut(); let mut state = refcell.borrow_mut();
let mut current_scope = state.scope_stack.pop().unwrap(); let mut current_scope = state.scope_stack.pop().unwrap();
current_scope.post = json::encode(&state.flow_root.get()); current_scope.post = json::encode(&state.flow_root.deref());
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);
} }
@ -101,7 +101,7 @@ pub fn generate_unique_debug_id() -> uint {
pub fn begin_trace(flow_root: FlowRef) { pub fn begin_trace(flow_root: FlowRef) {
assert!(state_key.get().is_none()); assert!(state_key.get().is_none());
let flow_trace = json::encode(&flow_root.get()); let flow_trace = json::encode(&flow_root.deref());
let state = State { let state = State {
scope_stack: vec![box ScopeData::new("root".to_string(), flow_trace)], scope_stack: vec![box ScopeData::new("root".to_string(), flow_trace)],
flow_root: flow_root, flow_root: flow_root,
@ -117,7 +117,7 @@ pub fn end_trace() {
let mut task_state = task_state_cell.borrow_mut(); let mut task_state = task_state_cell.borrow_mut();
assert!(task_state.scope_stack.len() == 1); assert!(task_state.scope_stack.len() == 1);
let mut root_scope = task_state.scope_stack.pop().unwrap(); let mut root_scope = task_state.scope_stack.pop().unwrap();
root_scope.post = json::encode(&task_state.flow_root.get()); root_scope.post = json::encode(&task_state.flow_root.deref());
let result = json::encode(&root_scope); let result = json::encode(&root_scope);
let path = Path::new("layout_trace.json"); let path = Path::new("layout_trace.json");

Просмотреть файл

@ -502,7 +502,7 @@ impl LayoutTask {
_ => fail!("Flow construction didn't result in a flow at the root of the tree!"), _ => fail!("Flow construction didn't result in a flow at the root of the tree!"),
}; };
flow.get_mut().mark_as_root(); flow.mark_as_root();
flow flow
} }
@ -634,7 +634,7 @@ impl LayoutTask {
Some((&data.url, data.iframe, self.first_reflow.get())), Some((&data.url, data.iframe, self.first_reflow.get())),
self.time_profiler_chan.clone(), self.time_profiler_chan.clone(),
|| { || {
layout_root.get_mut().propagate_restyle_damage(); layout_root.propagate_restyle_damage();
}); });
profile(time::LayoutNonIncrementalReset, profile(time::LayoutNonIncrementalReset,
@ -642,7 +642,7 @@ impl LayoutTask {
self.time_profiler_chan.clone(), self.time_profiler_chan.clone(),
|| { || {
if shared_layout_ctx.opts.incremental_layout { if shared_layout_ctx.opts.incremental_layout {
layout_root.get_mut().nonincremental_reset(); layout_root.nonincremental_reset();
} }
}); });
@ -655,7 +655,7 @@ impl LayoutTask {
layout_debug::begin_trace(layout_root.clone()); layout_debug::begin_trace(layout_root.clone());
} }
if self.opts.dump_flow_tree { if self.opts.dump_flow_tree {
layout_root.get_mut().dump(); layout_root.dump();
} }
// Perform the primary layout passes over the flow tree to compute the locations of all // Perform the primary layout passes over the flow tree to compute the locations of all
@ -677,11 +677,11 @@ impl LayoutTask {
// Build the display list if necessary, and send it to the renderer. // Build the display list if necessary, and send it to the renderer.
if data.goal == ReflowForDisplay { if data.goal == ReflowForDisplay {
let writing_mode = flow::base(layout_root.get()).writing_mode; let writing_mode = flow::base(layout_root.deref()).writing_mode;
profile(time::LayoutDispListBuildCategory, Some((&data.url, data.iframe, self.first_reflow.get())), self.time_profiler_chan.clone(), || { profile(time::LayoutDispListBuildCategory, Some((&data.url, data.iframe, self.first_reflow.get())), self.time_profiler_chan.clone(), || {
shared_layout_ctx.dirty = flow::base(layout_root.get()).position.to_physical( shared_layout_ctx.dirty = flow::base(layout_root.deref()).position.to_physical(
writing_mode, rw_data.screen_size); writing_mode, rw_data.screen_size);
flow::mut_base(layout_root.get_mut()).abs_position = flow::mut_base(layout_root.deref_mut()).abs_position =
LogicalPoint::zero(writing_mode).to_physical(writing_mode, rw_data.screen_size); LogicalPoint::zero(writing_mode).to_physical(writing_mode, rw_data.screen_size);
let rw_data = rw_data.deref_mut(); let rw_data = rw_data.deref_mut();
@ -704,10 +704,10 @@ impl LayoutTask {
} }
debug!("Done building display list. Display List = {}", debug!("Done building display list. Display List = {}",
flow::base(layout_root.get()).display_list); flow::base(layout_root.deref()).display_list);
let root_display_list = let root_display_list =
mem::replace(&mut flow::mut_base(layout_root.get_mut()).display_list, mem::replace(&mut flow::mut_base(layout_root.deref_mut()).display_list,
DisplayList::new()); DisplayList::new());
root_display_list.debug(); root_display_list.debug();
let display_list = Arc::new(root_display_list.flatten(ContentStackingLevel)); let display_list = Arc::new(root_display_list.flatten(ContentStackingLevel));
@ -737,13 +737,13 @@ impl LayoutTask {
} }
let root_size = { let root_size = {
let root_flow = flow::base(layout_root.get()); let root_flow = flow::base(layout_root.deref());
root_flow.position.size.to_physical(root_flow.writing_mode) root_flow.position.size.to_physical(root_flow.writing_mode)
}; };
let root_size = Size2D(root_size.width.to_nearest_px() as uint, let root_size = Size2D(root_size.width.to_nearest_px() as uint,
root_size.height.to_nearest_px() as uint); root_size.height.to_nearest_px() as uint);
let render_layer = RenderLayer { let render_layer = RenderLayer {
id: layout_root.get().layer_id(0), id: layout_root.layer_id(0),
display_list: display_list.clone(), display_list: display_list.clone(),
position: Rect(Point2D(0u, 0u), root_size), position: Rect(Point2D(0u, 0u), root_size),
background_color: color, background_color: color,
@ -757,7 +757,7 @@ impl LayoutTask {
// reflow. // reflow.
let mut layers = SmallVec1::new(); let mut layers = SmallVec1::new();
layers.push(render_layer); layers.push(render_layer);
for layer in mem::replace(&mut flow::mut_base(layout_root.get_mut()).layers, for layer in mem::replace(&mut flow::mut_base(layout_root.deref_mut()).layers,
DList::new()).into_iter() { DList::new()).into_iter() {
layers.push(layer) layers.push(layer)
} }

Просмотреть файл

@ -224,12 +224,12 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
let flow: &mut FlowRef = mem::transmute(&unsafe_flow); let flow: &mut FlowRef = mem::transmute(&unsafe_flow);
// Perform the appropriate traversal. // Perform the appropriate traversal.
if self.should_process(flow.get_mut()) { if self.should_process(flow.deref_mut()) {
self.process(flow.get_mut()); self.process(flow.deref_mut());
} }
let base = flow::mut_base(flow.get_mut()); let base = flow::mut_base(flow.deref_mut());
// Reset the count of children for the next layout traversal. // Reset the count of children for the next layout traversal.
base.parallel.children_count.store(base.children.len() as int, Relaxed); base.parallel.children_count.store(base.children.len() as int, Relaxed);
@ -245,7 +245,7 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
// of our parent to finish processing? If so, we can continue // of our parent to finish processing? If so, we can continue
// on with our parent; otherwise, we've gotta wait. // on with our parent; otherwise, we've gotta wait.
let parent: &mut FlowRef = mem::transmute(&unsafe_parent); let parent: &mut FlowRef = mem::transmute(&unsafe_parent);
let parent_base = flow::mut_base(parent.get_mut()); let parent_base = flow::mut_base(parent.deref_mut());
if parent_base.parallel.children_count.fetch_sub(1, SeqCst) == 1 { if parent_base.parallel.children_count.fetch_sub(1, SeqCst) == 1 {
// We were the last child of our parent. Reflow our parent. // We were the last child of our parent. Reflow our parent.
unsafe_flow = unsafe_parent unsafe_flow = unsafe_parent
@ -279,13 +279,13 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
// Get a real flow. // Get a real flow.
let flow: &mut FlowRef = mem::transmute(&unsafe_flow); let flow: &mut FlowRef = mem::transmute(&unsafe_flow);
if self.should_process(flow.get_mut()) { if self.should_process(flow.deref_mut()) {
// Perform the appropriate traversal. // Perform the appropriate traversal.
self.process(flow.get_mut()); self.process(flow.deref_mut());
} }
// Possibly enqueue the children. // Possibly enqueue the children.
for kid in flow::child_iter(flow.get_mut()) { for kid in flow::child_iter(flow.deref_mut()) {
had_children = true; had_children = true;
proxy.push(WorkUnit { proxy.push(WorkUnit {
fun: top_down_func, fun: top_down_func,
@ -397,9 +397,11 @@ fn build_display_list(unsafe_flow: UnsafeFlow,
proxy: &mut WorkerProxy<*const SharedLayoutContext, UnsafeFlow>) { proxy: &mut WorkerProxy<*const SharedLayoutContext, UnsafeFlow>) {
let shared_layout_context = unsafe { &**proxy.user_data() }; let shared_layout_context = unsafe { &**proxy.user_data() };
let layout_context = LayoutContext::new(shared_layout_context); let layout_context = LayoutContext::new(shared_layout_context);
let build_display_list_traversal = BuildDisplayList { let build_display_list_traversal = BuildDisplayList {
layout_context: &layout_context, layout_context: &layout_context,
}; };
build_display_list_traversal.run_parallel(unsafe_flow, proxy); build_display_list_traversal.run_parallel(unsafe_flow, proxy);
} }
@ -428,7 +430,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
if shared_layout_context.opts.bubble_inline_sizes_separately { if shared_layout_context.opts.bubble_inline_sizes_separately {
let layout_context = LayoutContext::new(shared_layout_context); let layout_context = LayoutContext::new(shared_layout_context);
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context }; let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
root.get_mut().traverse_postorder(&bubble_inline_sizes); root.traverse_postorder(&bubble_inline_sizes);
} }
queue.data = shared_layout_context as *const _; queue.data = shared_layout_context as *const _;

Просмотреть файл

@ -52,7 +52,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef,
let layout_context = LayoutContext::new(shared_layout_context); let layout_context = LayoutContext::new(shared_layout_context);
let root = root.get_mut(); let root = root.deref_mut();
if layout_context.shared.opts.bubble_inline_sizes_separately { if layout_context.shared.opts.bubble_inline_sizes_separately {
let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context }; let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context };
@ -85,5 +85,5 @@ pub fn build_display_list_for_subtree(root: &mut FlowRef,
let compute_absolute_positions = ComputeAbsolutePositions { layout_context: &layout_context }; let compute_absolute_positions = ComputeAbsolutePositions { layout_context: &layout_context };
let build_display_list = BuildDisplayList { layout_context: &layout_context }; let build_display_list = BuildDisplayList { layout_context: &layout_context };
doit(root.get_mut(), compute_absolute_positions, build_display_list); doit(root.deref_mut(), compute_absolute_positions, build_display_list);
} }