Flagging of blocks as fixed displays

This commit is contained in:
Isabelle Carter 2013-12-11 12:03:32 -06:00
parent ecaaf4c145
commit f58fd54875
3 changed files with 31 additions and 17 deletions

View file

@ -58,6 +58,8 @@ pub struct BlockFlow {
/// Whether this block flow is the root flow. /// Whether this block flow is the root flow.
is_root: bool, is_root: bool,
is_fixed: bool,
/// Additional floating flow members. /// Additional floating flow members.
float: Option<~FloatedBlockInfo> float: Option<~FloatedBlockInfo>
} }
@ -68,15 +70,17 @@ impl BlockFlow {
base: base, base: base,
box_: None, box_: None,
is_root: false, is_root: false,
is_fixed: false,
float: None float: None
} }
} }
pub fn from_box(base: BaseFlow, box_: Box) -> BlockFlow { pub fn from_box(base: BaseFlow, box_: Box, is_fixed: bool) -> BlockFlow {
BlockFlow { BlockFlow {
base: base, base: base,
box_: Some(box_), box_: Some(box_),
is_root: false, is_root: false,
is_fixed: is_fixed,
float: None float: None
} }
} }
@ -86,6 +90,7 @@ impl BlockFlow {
base: base, base: base,
box_: Some(box_), box_: Some(box_),
is_root: false, is_root: false,
is_fixed: false,
float: Some(~FloatedBlockInfo::new(float_type)) float: Some(~FloatedBlockInfo::new(float_type))
} }
} }
@ -95,6 +100,7 @@ impl BlockFlow {
base: base, base: base,
box_: None, box_: None,
is_root: true, is_root: true,
is_fixed: false,
float: None float: None
} }
} }
@ -104,6 +110,7 @@ impl BlockFlow {
base: base, base: base,
box_: None, box_: None,
is_root: false, is_root: false,
is_fixed: false,
float: Some(~FloatedBlockInfo::new(float_type)) float: Some(~FloatedBlockInfo::new(float_type))
} }
} }
@ -593,7 +600,7 @@ impl Flow for BlockFlow {
}, },
self.base.id); self.base.id);
if self.is_root { if self.is_root || self.is_fixed {
debug!("Setting root position"); debug!("Setting root position");
self.base.position.origin = Au::zero_point(); self.base.position.origin = Au::zero_point();
self.base.position.size.width = ctx.screen_size.size.width; self.base.position.size.width = ctx.screen_size.size.width;

View file

@ -35,7 +35,7 @@ use layout::wrapper::{LayoutNode, PostorderNodeMutTraversal};
use script::dom::element::{HTMLIframeElementTypeId, HTMLImageElementTypeId}; use script::dom::element::{HTMLIframeElementTypeId, HTMLImageElementTypeId};
use script::dom::node::{CommentNodeTypeId, DoctypeNodeTypeId, DocumentFragmentNodeTypeId}; use script::dom::node::{CommentNodeTypeId, DoctypeNodeTypeId, DocumentFragmentNodeTypeId};
use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, TextNodeTypeId}; use script::dom::node::{DocumentNodeTypeId, ElementNodeTypeId, TextNodeTypeId};
use style::computed_values::{display, float}; use style::computed_values::{display, position, float};
use std::cell::RefCell; use std::cell::RefCell;
use std::util; use std::util;
@ -344,10 +344,10 @@ impl<'fc> FlowConstructor<'fc> {
/// Builds a flow for a node with `display: block`. This yields a `BlockFlow` with possibly /// Builds a flow for a node with `display: block`. This yields a `BlockFlow` with possibly
/// other `BlockFlow`s or `InlineFlow`s underneath it, depending on whether {ib} splits needed /// other `BlockFlow`s or `InlineFlow`s underneath it, depending on whether {ib} splits needed
/// to happen. /// to happen.
fn build_flow_for_block(&mut self, node: LayoutNode) -> ~Flow { fn build_flow_for_block(&mut self, node: LayoutNode, is_fixed: bool) -> ~Flow: {
let base = BaseFlow::new(self.next_flow_id(), node); let base = BaseFlow::new(self.next_flow_id(), node);
let box_ = self.build_box_for_node(node); let box_ = self.build_box_for_node(node);
let mut flow = ~BlockFlow::from_box(base, box_) as ~Flow; let mut flow = ~BlockFlow::from_box(base, box_, is_fixed) as ~Flow:;
self.build_children_of_block_flow(&mut flow, node); self.build_children_of_block_flow(&mut flow, node);
flow flow
} }
@ -363,6 +363,7 @@ impl<'fc> FlowConstructor<'fc> {
flow flow
} }
/// Concatenates the boxes of kids, adding in our own borders/padding/margins if necessary. /// Concatenates the boxes of kids, adding in our own borders/padding/margins if necessary.
/// Returns the `InlineBoxesConstructionResult`, if any. There will be no /// Returns the `InlineBoxesConstructionResult`, if any. There will be no
/// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace. /// `InlineBoxesConstructionResult` if this node consisted entirely of ignorable whitespace.
@ -504,47 +505,53 @@ impl<'a> PostorderNodeMutTraversal for FlowConstructor<'a> {
#[inline(always)] #[inline(always)]
fn process(&mut self, node: LayoutNode) -> bool { fn process(&mut self, node: LayoutNode) -> bool {
// Get the `display` property for this node, and determine whether this node is floated. // Get the `display` property for this node, and determine whether this node is floated.
let (display, float) = match node.type_id() { let (display, float, position) = match node.type_id() {
ElementNodeTypeId(_) => { ElementNodeTypeId(_) => {
let style = node.style().get(); let style = node.style().get();
(style.Box.display, style.Box.float) (style.Box.display, style.Box.float, style.Box.position)
} }
TextNodeTypeId => (display::inline, float::none), TextNodeTypeId => (display::inline, float::none, position::static_),
CommentNodeTypeId | CommentNodeTypeId |
DoctypeNodeTypeId | DoctypeNodeTypeId |
DocumentFragmentNodeTypeId | DocumentFragmentNodeTypeId |
DocumentNodeTypeId(_) => (display::none, float::none), DocumentNodeTypeId(_) => (display::none, float::none, position::static_),
}; };
debug!("building flow for node: {:?} {:?}", display, float); debug!("building flow for node: {:?} {:?}", display, float);
// Switch on display and floatedness. // Switch on display and floatedness.
match (display, float) { match (display, float, position) {
// `display: none` contributes no flow construction result. Nuke the flow construction // `display: none` contributes no flow construction result. Nuke the flow construction
// results of children. // results of children.
(display::none, _) => { (display::none, _, _) => {
for child in node.children() { for child in node.children() {
child.set_flow_construction_result(NoConstructionResult) child.set_flow_construction_result(NoConstructionResult)
} }
} }
// Inline items contribute inline box construction results. // Inline items contribute inline box construction results.
(display::inline, float::none) => { (display::inline, float::none, _) => {
let construction_result = self.build_boxes_for_inline(node); let construction_result = self.build_boxes_for_inline(node);
node.set_flow_construction_result(construction_result) node.set_flow_construction_result(construction_result)
} }
// Block flows that are not floated contribute block flow construction results. // Block flows that are not floated contribute block flow construction results.
// //
// TODO(pcwalton): Make this only trigger for blocks and handle the other `display` // TODO(pcwalton): Make this only trigger for blocks and handle the other `display`
// properties separately. // properties separately.
(_, float::none) => {
let flow = self.build_flow_for_block(node); (_, _, position::fixed) => {
let flow = self.build_flow_for_block(node, true);
node.set_flow_construction_result(FlowConstructionResult(flow))
}
(_, float::none, _) => {
let flow = self.build_flow_for_block(node, false);
node.set_flow_construction_result(FlowConstructionResult(flow)) node.set_flow_construction_result(FlowConstructionResult(flow))
} }
// Floated flows contribute float flow construction results. // Floated flows contribute float flow construction results.
(_, float_value) => { (_, float_value, _) => {
let float_type = FloatType::from_property(float_value); let float_type = FloatType::from_property(float_value);
let flow = self.build_flow_for_floated_block(node, float_type); let flow = self.build_flow_for_floated_block(node, float_type);
node.set_flow_construction_result(FlowConstructionResult(flow)) node.set_flow_construction_result(FlowConstructionResult(flow))

View file

@ -378,7 +378,7 @@ impl LayoutTask {
}; };
flow.mark_as_root(); flow.mark_as_root();
flow flow
} }
/// Performs layout constraint solving. /// Performs layout constraint solving.
/// ///
@ -399,7 +399,7 @@ impl LayoutTask {
// For now, this is an inorder traversal // For now, this is an inorder traversal
// FIXME: prune this traversal as well // FIXME: prune this traversal as well
let _ = layout_root.traverse_postorder(&mut let _ = layout_root.traverse_postorder(&mut
AssignHeightsAndStoreOverflowTraversal(layout_context)); AssignHeightsAndStoreOverflowTraversal(layout_context));
} }
/// The high-level routine that performs layout tasks. /// The high-level routine that performs layout tasks.