Skip to content

Commit

Permalink
Filter abs-pos children and sort by 'order' field
Browse files Browse the repository at this point in the history
As the flexbox spec change in May 2016, the absolutely positioned
children painting order no longer follow the `order` property, thus we
can simply filter them out.

Also sort items by the order field of 'FlexItem', no longer do two
vtable lookups in each compare.
  • Loading branch information
stshine committed Jul 22, 2016
1 parent 196d19a commit 05cf52c
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions components/layout/flex.rs
Expand Up @@ -712,19 +712,14 @@ impl Flow for FlexFlow {
// Flexbox Section 9.0: Generate anonymous flex items:
// This part was handled in the flow constructor.

// Flexbox Section 9.1: Re-order the flex items (and any absolutely positioned flex
// container children) according to their order.

let mut items = self.block_flow.base.children.iter_flow_ref_mut().map(|flow| {
FlexItem::new(flow.clone())
}).collect::<Vec<FlexItem>>();

items.sort_by(|item1, item2| {
item1.flow.as_block().fragment.style.get_position().order.cmp(
&item2.flow.as_block().fragment.style.get_position().order
)
});

// Flexbox Section 9.1: Re-order flex items according to their order.
// FIXME(stshine): This should be done during flow construction.
let mut items = self.block_flow.base.children.iter_flow_ref_mut()
.filter(|flow| !flow.as_block().base.flags.contains(IS_ABSOLUTELY_POSITIONED))
.map(|flow| FlexItem::new(flow.clone()))
.collect::<Vec<FlexItem>>();

items.sort_by_key(|item| item.order);
self.items = items;

match self.main_mode {
Expand Down

0 comments on commit 05cf52c

Please sign in to comment.