-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
table_row.rs
229 lines (192 loc) · 8.69 KB
/
table_row.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
//! CSS table formatting contexts.
use layout::box_::Box;
use layout::block::BlockFlow;
use layout::block::WidthAndMarginsComputer;
use layout::construct::FlowConstructor;
use layout::context::LayoutContext;
use layout::flow::{TableRowFlowClass, FlowClass, Flow, ImmutableFlowUtils};
use layout::flow;
use layout::table::InternalTable;
use layout::model::{MaybeAuto, Specified, Auto};
use layout::wrapper::ThreadSafeLayoutNode;
use servo_util::geometry::Au;
use servo_util::geometry;
/// A table formatting context.
pub struct TableRowFlow {
pub block_flow: BlockFlow,
/// Column widths.
pub col_widths: Vec<Au>,
/// Column min widths.
pub col_min_widths: Vec<Au>,
/// Column pref widths.
pub col_pref_widths: Vec<Au>,
}
impl TableRowFlow {
pub fn from_node_and_box(node: &ThreadSafeLayoutNode,
box_: Box)
-> TableRowFlow {
TableRowFlow {
block_flow: BlockFlow::from_node_and_box(node, box_),
col_widths: Vec::new(),
col_min_widths: Vec::new(),
col_pref_widths: Vec::new(),
}
}
pub fn from_node(constructor: &mut FlowConstructor,
node: &ThreadSafeLayoutNode)
-> TableRowFlow {
TableRowFlow {
block_flow: BlockFlow::from_node(constructor, node),
col_widths: Vec::new(),
col_min_widths: Vec::new(),
col_pref_widths: Vec::new(),
}
}
pub fn teardown(&mut self) {
self.block_flow.teardown();
self.col_widths = Vec::new();
self.col_min_widths = Vec::new();
self.col_pref_widths = Vec::new();
}
pub fn box_<'a>(&'a mut self) -> &'a Box {
&self.block_flow.box_
}
fn initialize_offsets(&mut self) -> (Au, Au, Au) {
// TODO: If border-collapse: collapse, top_offset, bottom_offset, and left_offset
// should be updated. Currently, they are set as Au(0).
(Au(0), Au(0), Au(0))
}
/// Assign height for table-row flow.
///
/// TODO(pcwalton): This doesn't handle floats and positioned elements right.
///
/// inline(always) because this is only ever called by in-order or non-in-order top-level
/// methods
#[inline(always)]
fn assign_height_table_row_base(&mut self, layout_context: &mut LayoutContext) {
let (top_offset, _, _) = self.initialize_offsets();
let /* mut */ cur_y = top_offset;
// Per CSS 2.1 § 17.5.3, find max_y = max( computed `height`, minimum height of all cells )
let mut max_y = Au::new(0);
for kid in self.block_flow.base.child_iter() {
kid.assign_height_for_inorder_child_if_necessary(layout_context);
{
let child_box = kid.as_table_cell().box_();
// TODO: Percentage height
let child_specified_height = MaybeAuto::from_style(child_box.style().Box.get().height,
Au::new(0)).specified_or_zero();
max_y =
geometry::max(max_y,
child_specified_height + child_box.border_padding.vertical());
}
let child_node = flow::mut_base(kid);
child_node.position.origin.y = cur_y;
max_y = geometry::max(max_y, child_node.position.size.height);
}
let mut height = max_y;
// TODO: Percentage height
height = match MaybeAuto::from_style(self.block_flow.box_.style().Box.get().height, Au(0)) {
Auto => height,
Specified(value) => geometry::max(value, height)
};
// cur_y = cur_y + height;
// Assign the height of own box
//
// FIXME(pcwalton): Take `cur_y` into account.
let mut position = self.block_flow.box_.border_box;
position.size.height = height;
self.block_flow.box_.border_box = position;
self.block_flow.base.position.size.height = height;
// Assign the height of kid boxes, which is the same value as own height.
for kid in self.block_flow.base.child_iter() {
{
let kid_box_ = kid.as_table_cell().mut_box();
let mut position = kid_box_.border_box;
position.size.height = height;
kid_box_.border_box = position;
}
let child_node = flow::mut_base(kid);
child_node.position.size.height = height;
}
}
pub fn build_display_list_table_row(&mut self, layout_context: &LayoutContext) {
debug!("build_display_list_table_row: same process as block flow");
self.block_flow.build_display_list_block(layout_context)
}
}
impl Flow for TableRowFlow {
fn class(&self) -> FlowClass {
TableRowFlowClass
}
fn as_table_row<'a>(&'a mut self) -> &'a mut TableRowFlow {
self
}
fn as_block<'a>(&'a mut self) -> &'a mut BlockFlow {
&mut self.block_flow
}
fn col_widths<'a>(&'a mut self) -> &'a mut Vec<Au> {
&mut self.col_widths
}
fn col_min_widths<'a>(&'a self) -> &'a Vec<Au> {
&self.col_min_widths
}
fn col_pref_widths<'a>(&'a self) -> &'a Vec<Au> {
&self.col_pref_widths
}
/// Recursively (bottom-up) determines the context's preferred and minimum widths. When called
/// on this context, all child contexts have had their min/pref widths set. This function must
/// decide min/pref widths based on child context widths and dimensions of any boxes it is
/// responsible for flowing.
/// Min/pref widths set by this function are used in automatic table layout calculation.
/// The specified column widths of children cells are used in fixed table layout calculation.
fn bubble_widths(&mut self, _: &mut LayoutContext) {
let mut min_width = Au(0);
let mut pref_width = Au(0);
/* find the specified widths from child table-cell contexts */
for kid in self.block_flow.base.child_iter() {
assert!(kid.is_table_cell());
// collect the specified column widths of cells. These are used in fixed table layout calculation.
{
let child_box = kid.as_table_cell().box_();
let child_specified_width = MaybeAuto::from_style(child_box.style().Box.get().width,
Au::new(0)).specified_or_zero();
self.col_widths.push(child_specified_width);
}
// collect min_width & pref_width of children cells for automatic table layout calculation.
let child_base = flow::mut_base(kid);
self.col_min_widths.push(child_base.intrinsic_widths.minimum_width);
self.col_pref_widths.push(child_base.intrinsic_widths.preferred_width);
min_width = min_width + child_base.intrinsic_widths.minimum_width;
pref_width = pref_width + child_base.intrinsic_widths.preferred_width;
}
self.block_flow.base.intrinsic_widths.minimum_width = min_width;
self.block_flow.base.intrinsic_widths.preferred_width = geometry::max(min_width,
pref_width);
}
/// Recursively (top-down) determines the actual width of child contexts and boxes. When called
/// on this context, the context has had its width set by the parent context.
fn assign_widths(&mut self, ctx: &mut LayoutContext) {
debug!("assign_widths({}): assigning width for flow", "table_row");
// The position was set to the containing block by the flow's parent.
let containing_block_width = self.block_flow.base.position.size.width;
// FIXME: In case of border-collapse: collapse, left_content_edge should be border-left
let left_content_edge = Au::new(0);
let width_computer = InternalTable;
width_computer.compute_used_width(&mut self.block_flow, ctx, containing_block_width);
self.block_flow.propagate_assigned_width_to_children(left_content_edge, Au(0), Some(self.col_widths.clone()));
}
fn assign_height(&mut self, ctx: &mut LayoutContext) {
debug!("assign_height: assigning height for table_row");
self.assign_height_table_row_base(ctx);
}
fn compute_absolute_position(&mut self) {
self.block_flow.compute_absolute_position()
}
fn debug_str(&self) -> ~str {
let txt = "TableRowFlow: ".to_owned();
txt.append(self.block_flow.box_.debug_str())
}
}