Skip to content

Commit d7f06a4

Browse files
committed
wip computing dimensions
1 parent 69a746b commit d7f06a4

File tree

3 files changed

+38
-66
lines changed

3 files changed

+38
-66
lines changed

src/vaev-engine/layout/block.cpp

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ Output fragmentEmptyBox(Tree& tree, Input input) {
123123
}
124124
}
125125

126+
void _populateChildSpecifiedSizes(Tree& tree, Box& child, Input& childInput, Au horizontalMargins, Opt<Au> blockInlineSize) {
127+
if (childInput.intrinsic == IntrinsicSize::AUTO or child.style->display != Display::INLINE) {
128+
if (child.style->sizing->width.is<Keywords::Auto>()) {
129+
// https://www.w3.org/TR/css-tables-3/#layout-principles
130+
// Unlike other block-level boxes, tables do not fill their containing block by default.
131+
// When their width computes to auto, they behave as if they had fit-content specified instead.
132+
// This is different from most block-level boxes, which behave as if they had stretch instead.
133+
if (child.style->display == Display::TABLE_BOX) {
134+
// Do nothing. 'fit-content' is kinda intrinsic size, when we don't populate knownSize.
135+
} else if (blockInlineSize) {
136+
// When the inline size is not known, we cannot enforce it to the child. (?)
137+
childInput.knownSize.width = blockInlineSize.unwrap() - horizontalMargins;
138+
}
139+
} else {
140+
childInput.knownSize.width = computeSpecifiedSize(
141+
tree, child, child.style->sizing->width, childInput.containingBlock, true
142+
);
143+
}
144+
145+
childInput.knownSize.height = computeSpecifiedSize(
146+
tree, child, child.style->sizing->height, childInput.containingBlock, false
147+
);
148+
}
149+
}
150+
126151
// https://www.w3.org/TR/CSS22/visuren.html#normal-flow
127152
struct BlockFormatingContext : FormatingContext {
128153
Au _computeCapmin(Tree& tree, Box& box, Input input, Au inlineSize) {
@@ -210,38 +235,7 @@ struct BlockFormatingContext : FormatingContext {
210235
childInput.capmin = _computeCapmin(tree, box, input, inlineSize);
211236
}
212237

213-
if (input.intrinsic == IntrinsicSize::AUTO or c.style->display != Display::INLINE) {
214-
if (c.style->sizing->width.is<Keywords::Auto>()) {
215-
// https://www.w3.org/TR/css-tables-3/#layout-principles
216-
// Unlike other block-level boxes, tables do not fill their containing block by default.
217-
// When their width computes to auto, they behave as if they had fit-content specified instead.
218-
// This is different from most block-level boxes, which behave as if they had stretch instead.
219-
if (c.style->display == Display::TABLE_BOX) {
220-
// Do nothing. 'fit-content' is kinda intrinsic size, when we don't populate knownSize.
221-
} else if (input.knownSize.x) {
222-
// When the inline size is not known, we cannot enforce it to the child. (?)
223-
childInput.knownSize.width = inlineSize - usedSpacings.margin.horizontal();
224-
}
225-
} else {
226-
// FIXME: computing border box size. content box sizing should be supported later.
227-
auto specifiedWidth = computeSpecifiedSize(
228-
tree, c, c.style->sizing->width, childInput.containingBlock, true
229-
);
230-
231-
childInput.knownSize.width = specifiedWidth.unwrap();
232-
}
233-
234-
if (c.style->sizing->height.is<Keywords::Auto>()) {
235-
childInput.knownSize.height = NONE;
236-
} else {
237-
// FIXME: computing border box size. content box sizing should be supported later.
238-
auto specifiedHeight = computeSpecifiedSize(
239-
tree, c, c.style->sizing->height, childInput.containingBlock, false
240-
);
241-
242-
childInput.knownSize.height = specifiedHeight.unwrap();
243-
}
244-
}
238+
_populateChildSpecifiedSizes(tree, c, childInput, usedSpacings.margin.horizontal(), input.knownSize.x);
245239

246240
auto output = input.fragment
247241
? layoutBorderBox(tree, c, childInput, *input.fragment, usedSpacings)

src/vaev-engine/layout/flex.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,17 @@ struct FlexItem {
237237
input
238238
);
239239

240+
// FIXME: whats up with intrinsic sizing here?
240241
if (input.intrinsic == IntrinsicSize::AUTO or box->style->display != Display::INLINE) {
241-
if (not box->style->sizing->width.is<Keywords::Auto>()) {
242-
// FIXME: computing border box size. content box sizing should be supported later.
243-
auto specifiedWidth = computeSpecifiedSize(
242+
if (not input.knownSize.width)
243+
input.knownSize.width = computeSpecifiedSize(
244244
t, *box, box->style->sizing->width, input.containingBlock, true
245245
);
246246

247-
input.knownSize.width = input.knownSize.width.unwrapOr(specifiedWidth.unwrap());
248-
}
249-
250-
if (not box->style->sizing->height.is<Keywords::Auto>()) {
251-
// FIXME: computing border box size. content box sizing should be supported later.
252-
auto specifiedHeight = computeSpecifiedSize(
247+
if (not input.knownSize.height)
248+
input.knownSize.height = computeSpecifiedSize(
253249
t, *box, box->style->sizing->height, input.containingBlock, false
254250
);
255-
256-
input.knownSize.height = input.knownSize.height.unwrapOr(specifiedHeight.unwrap());
257-
}
258251
}
259252

260253
speculativeSize = layoutBorderBox(t, *box, input, UsedSpacings{.padding = padding, .borders = borders}).size;

src/vaev-engine/layout/inline.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct InlineFormatingContext : FormatingContext {
5656

5757
auto& atomicBox = *inlineBox.atomicBoxes[boxStrutCell.id];
5858

59+
// FIXME: intrinsic sizing not being passed around
5960
Input childInput{
6061
.knownSize = {NONE, NONE},
6162
.availableSpace = {inlineSize, input.availableSpace.y},
@@ -65,29 +66,13 @@ struct InlineFormatingContext : FormatingContext {
6566
},
6667
};
6768

68-
if (input.intrinsic == IntrinsicSize::AUTO or atomicBox.style->display != Display::INLINE) {
69-
if (atomicBox.style->sizing->width.is<Keywords::Auto>()) {
70-
childInput.knownSize.width = NONE;
71-
} else {
72-
// FIXME: computing border box size. content box sizing should be supported later.
73-
auto specifiedWidth = computeSpecifiedSize(
74-
tree, atomicBox, atomicBox.style->sizing->width, childInput.containingBlock, true
75-
);
76-
77-
childInput.knownSize.width = specifiedWidth.unwrap();
78-
}
79-
80-
if (atomicBox.style->sizing->height.is<Keywords::Auto>()) {
81-
childInput.knownSize.height = NONE;
82-
} else {
83-
// FIXME: computing border box size. content box sizing should be supported later.
84-
auto specifiedHeight = computeSpecifiedSize(
85-
tree, atomicBox, atomicBox.style->sizing->height, childInput.containingBlock, false
86-
);
69+
childInput.knownSize.width = computeSpecifiedSize(
70+
tree, atomicBox, atomicBox.style->sizing->width, childInput.containingBlock, true
71+
);
8772

88-
childInput.knownSize.height = specifiedHeight.unwrap();
89-
}
90-
}
73+
childInput.knownSize.height = computeSpecifiedSize(
74+
tree, atomicBox, atomicBox.style->sizing->height, childInput.containingBlock, false
75+
);
9176

9277
// NOTE: We set the same availableSpace to child inline boxes since line wrapping is possible i.e. in the
9378
// worst case, they will take up the whole availableSpace, and a line break will be done right before them

0 commit comments

Comments
 (0)