Filter abs-pos children and sort by 'order' field

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.
This commit is contained in:
Pu Xingyu 2016-07-20 16:55:44 +08:00
parent 196d19a311
commit 05cf52cb0b

View file

@ -712,19 +712,14 @@ impl Flow for FlexFlow {
// Flexbox Section 9.0: Generate anonymous flex items: // Flexbox Section 9.0: Generate anonymous flex items:
// This part was handled in the flow constructor. // This part was handled in the flow constructor.
// Flexbox Section 9.1: Re-order the flex items (and any absolutely positioned flex // Flexbox Section 9.1: Re-order flex items according to their order.
// container children) 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()
let mut items = self.block_flow.base.children.iter_flow_ref_mut().map(|flow| { .filter(|flow| !flow.as_block().base.flags.contains(IS_ABSOLUTELY_POSITIONED))
FlexItem::new(flow.clone()) .map(|flow| FlexItem::new(flow.clone()))
}).collect::<Vec<FlexItem>>(); .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
)
});
items.sort_by_key(|item| item.order);
self.items = items; self.items = items;
match self.main_mode { match self.main_mode {