@geastack/engine 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/canvas.cpp +105 -48
- package/css/declarative.h +6 -0
- package/css/engine.h +20 -0
- package/image_store.cpp +136 -33
- package/package.json +4 -3
- package/ui/CSS_FEATURES.md +261 -0
- package/ui/absolute_leaf_refresh.cpp +77 -62
- package/ui/core.cpp +26 -3
- package/ui/css_atom.cpp +6 -0
- package/ui/css_atom.h +2 -0
- package/ui/css_features.h +369 -0
- package/ui/document.cpp +11 -0
- package/ui/image_node.cpp +25 -24
- package/ui/input.cpp +46 -26
- package/ui/input_render.cpp +31 -27
- package/ui/internal.h +22 -0
- package/ui/layout.cpp +899 -613
- package/ui/layout_snapshot.cpp +29 -2
- package/ui/node_features.h +36 -0
- package/ui/node_lifecycle.cpp +358 -84
- package/ui/node_lifecycle.h +1 -0
- package/ui/node_model.h +816 -96
- package/ui/node_text.h +84 -0
- package/ui/refresh_perf.h +19 -17
- package/ui/render.cpp +341 -259
- package/ui/renderer_features.h +24 -0
- package/ui/root_scroll_refresh.cpp +86 -69
- package/ui/storage_usage.h +45 -0
- package/ui/style.cpp +1398 -349
- package/ui/style_values.h +2 -2
- package/ui/text.cpp +172 -154
- package/ui/tree_events.cpp +218 -92
- package/ui/tree_events.h +44 -20
- package/ui/tree_inspection.h +15 -0
- package/ui/tree_nodes.cpp +51 -19
- package/ui/tree_render.cpp +159 -126
- package/ui/tree_scroll_mirror.cpp +30 -4
- package/ui/tree_state.cpp +334 -115
- package/ui/tree_state.h +118 -22
- package/ui/tree_style.cpp +679 -303
- package/ui/view.cpp +268 -208
- package/ui/virtual_keyboard.cpp +18 -11
package/ui/layout.cpp
CHANGED
|
@@ -13,13 +13,18 @@
|
|
|
13
13
|
#include <algorithm>
|
|
14
14
|
#include <cmath>
|
|
15
15
|
#include <vector>
|
|
16
|
+
#include <memory>
|
|
17
|
+
#include <cstdlib>
|
|
18
|
+
#if defined(ESP_PLATFORM)
|
|
19
|
+
#include "esp_heap_caps.h"
|
|
20
|
+
#endif
|
|
16
21
|
|
|
17
22
|
namespace gea::embedded::ui {
|
|
18
23
|
|
|
19
24
|
bool isCollapsedFlexItem(const Node &node)
|
|
20
25
|
{
|
|
21
|
-
return node.
|
|
22
|
-
!isOutOfFlowPosition(node.
|
|
26
|
+
return node.computedStyle().visibility == 2 && node.parent >= 0 &&
|
|
27
|
+
!isOutOfFlowPosition(node.computedStyle().position) && Tree::instance().nodes()[node.parent].computedStyle().display == kDisplayFlex;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
bool isCollapsedFlexSubtree(const Node &node)
|
|
@@ -34,6 +39,70 @@ namespace {
|
|
|
34
39
|
|
|
35
40
|
constexpr int kScratchDepth = 16;
|
|
36
41
|
|
|
42
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
43
|
+
// Persistent, cold layout state belongs only to allocated node slots. Pages
|
|
44
|
+
// never move: recursive layout may create nodes while holding an entry reference.
|
|
45
|
+
// Current/previous geometry and render flags remain embedded in Node.
|
|
46
|
+
struct PersistentLayoutState {
|
|
47
|
+
int16_t memo_avail_w = 0, memo_avail_h = 0;
|
|
48
|
+
int16_t static_block_start = 0;
|
|
49
|
+
// Retain the legacy field name: this is now available-box validity only.
|
|
50
|
+
uint8_t memo_pass = 0;
|
|
51
|
+
uint8_t static_block_axis = 0;
|
|
52
|
+
};
|
|
53
|
+
static_assert(sizeof(PersistentLayoutState) == 8);
|
|
54
|
+
constexpr int kLayoutStatePageEntries = 16;
|
|
55
|
+
struct LayoutStatePage { PersistentLayoutState entries[kLayoutStatePageEntries]; };
|
|
56
|
+
struct LayoutStatePageDeleter {
|
|
57
|
+
void operator()(LayoutStatePage *page) const {
|
|
58
|
+
page->~LayoutStatePage();
|
|
59
|
+
gea::framework::memory::Allocator::free(page);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
using LayoutStatePageOwner = std::unique_ptr<LayoutStatePage, LayoutStatePageDeleter>;
|
|
63
|
+
std::vector<LayoutStatePageOwner> gLayoutStatePages;
|
|
64
|
+
std::size_t gLayoutStatePeakBytes = 0;
|
|
65
|
+
std::size_t gLayoutStatePeakAllocations = 0;
|
|
66
|
+
|
|
67
|
+
void ensureLayoutState(int id)
|
|
68
|
+
{
|
|
69
|
+
while (gLayoutStatePages.size() <= static_cast<std::size_t>(id / kLayoutStatePageEntries)) {
|
|
70
|
+
const auto oldCapacity = gLayoutStatePages.capacity();
|
|
71
|
+
const auto oldBytes = LayoutEngine::persistentLayoutHeapBytes();
|
|
72
|
+
void *storage = gea::framework::memory::Allocator::allocatePreferSpiram(sizeof(LayoutStatePage));
|
|
73
|
+
if (!storage) std::abort();
|
|
74
|
+
#if defined(ESP_PLATFORM)
|
|
75
|
+
const auto pageBytes = heap_caps_get_allocated_size(storage);
|
|
76
|
+
#else
|
|
77
|
+
const auto pageBytes = sizeof(LayoutStatePage);
|
|
78
|
+
#endif
|
|
79
|
+
LayoutStatePageOwner page(new (storage) LayoutStatePage{});
|
|
80
|
+
gLayoutStatePages.push_back(std::move(page));
|
|
81
|
+
// Include overlapping old/new pointer tables during vector growth.
|
|
82
|
+
std::size_t growingTable = 0;
|
|
83
|
+
if (gLayoutStatePages.capacity() > oldCapacity) {
|
|
84
|
+
#if defined(ESP_PLATFORM)
|
|
85
|
+
growingTable = heap_caps_get_allocated_size(gLayoutStatePages.data());
|
|
86
|
+
#else
|
|
87
|
+
growingTable = gLayoutStatePages.capacity() * sizeof(LayoutStatePageOwner);
|
|
88
|
+
#endif
|
|
89
|
+
}
|
|
90
|
+
const auto peak = oldBytes + pageBytes + growingTable;
|
|
91
|
+
if (peak > gLayoutStatePeakBytes) {
|
|
92
|
+
gLayoutStatePeakBytes = peak;
|
|
93
|
+
gLayoutStatePeakAllocations = gLayoutStatePages.size() + (oldCapacity ? 1 : 0) + (growingTable ? 1 : 0);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
PersistentLayoutState &layoutState(int id)
|
|
98
|
+
{
|
|
99
|
+
return gLayoutStatePages[id / kLayoutStatePageEntries]->entries[id % kLayoutStatePageEntries];
|
|
100
|
+
}
|
|
101
|
+
#else
|
|
102
|
+
void ensureLayoutState(int) {}
|
|
103
|
+
LayoutBox &layoutState(int id) { return Tree::instance().nodes()[id].layout; }
|
|
104
|
+
#endif
|
|
105
|
+
|
|
37
106
|
int formattingEdgeNode(const Node *nodes, int id, bool last);
|
|
38
107
|
|
|
39
108
|
bool isLineBreak(const Node &node)
|
|
@@ -47,13 +116,13 @@ bool suppressAnonymousWhitespace(const Node *nodes, int parent, int child)
|
|
|
47
116
|
const Node &text = nodes[child];
|
|
48
117
|
if (!isAnonymousTextNode(text)) return false;
|
|
49
118
|
if (text.text.empty()) return true;
|
|
50
|
-
if ((text.
|
|
51
|
-
if (nodes[parent].
|
|
119
|
+
if ((text.computedStyle().white_space != 0 && text.computedStyle().white_space != 1) || text.text.find_first_not_of(" \t\r\n\f") != std::string::npos) return false;
|
|
120
|
+
if (nodes[parent].computedStyle().display == kDisplayFlex || isDisplayGrid(nodes[parent].computedStyle())) return true;
|
|
52
121
|
// Whitespace at a line boundary or between block boxes creates no line.
|
|
53
122
|
// Preserve the text node itself and spaces between inline siblings.
|
|
54
123
|
auto adjacentInline = [&](int sibling, bool forward) {
|
|
55
|
-
while (sibling >= 0 && (isDisplayNone(nodes[sibling].
|
|
56
|
-
(isAnonymousTextNode(nodes[sibling]) && (nodes[sibling].
|
|
124
|
+
while (sibling >= 0 && (isDisplayNone(nodes[sibling].computedStyle()) || isOutOfFlowPosition(nodes[sibling].computedStyle().position) ||
|
|
125
|
+
(isAnonymousTextNode(nodes[sibling]) && (nodes[sibling].computedStyle().white_space == 0 || nodes[sibling].computedStyle().white_space == 1) &&
|
|
57
126
|
nodes[sibling].text.find_first_not_of(" \t\r\n\f") == std::string::npos)))
|
|
58
127
|
sibling = forward ? nodes[sibling].next_sibling : nodes[sibling].prev_sibling;
|
|
59
128
|
if (sibling >= 0) sibling = formattingEdgeNode(nodes, sibling, !forward);
|
|
@@ -70,10 +139,10 @@ bool startsFormattingLine(const Node *nodes, int id)
|
|
|
70
139
|
while (LayoutEngine::isCssInlineLevelBox(nodes[id]) && LayoutEngine::isInlineLevelNode(nodes[id])) {
|
|
71
140
|
for (int sibling = nodes[id].prev_sibling; sibling >= 0; sibling = nodes[sibling].prev_sibling) {
|
|
72
141
|
const Node &previous = nodes[sibling];
|
|
73
|
-
if (isDisplayNone(previous.
|
|
142
|
+
if (isDisplayNone(previous.computedStyle()) || isOutOfFlowPosition(previous.computedStyle().position) || previous.computedStyle().float_side)
|
|
74
143
|
continue;
|
|
75
144
|
if (isAnonymousTextNode(previous) &&
|
|
76
|
-
(previous.
|
|
145
|
+
(previous.computedStyle().white_space == 0 || previous.computedStyle().white_space == 1 || previous.computedStyle().white_space == 4) &&
|
|
77
146
|
previous.text.find_first_not_of(" \t\r\n\f") == std::string::npos) continue;
|
|
78
147
|
const int edge = formattingEdgeNode(nodes, sibling, true);
|
|
79
148
|
if (edge < 0) continue;
|
|
@@ -212,8 +281,8 @@ int intrinsicSizeConstraint(const Node &node, bool horizontal)
|
|
|
212
281
|
const Node *current = &node;
|
|
213
282
|
for (;;) {
|
|
214
283
|
if (auto *scope = intrinsicSizeScope(*current, horizontal)) return scope->constraint;
|
|
215
|
-
const int expression = horizontal ? current->
|
|
216
|
-
if (current->parent < 0 || (horizontal ? current->
|
|
284
|
+
const int expression = horizontal ? current->computedStyle().width_expression : current->computedStyle().height_expression;
|
|
285
|
+
if (current->parent < 0 || (horizontal ? current->computedStyle().width : current->computedStyle().height) != kUnset ||
|
|
217
286
|
(expression >= 0 && !layoutSizeExpressionUsesPercentage(
|
|
218
287
|
static_cast<int>(current - Tree::instance().nodes()), expression))) return 0;
|
|
219
288
|
current = &Tree::instance().nodes()[current->parent];
|
|
@@ -241,20 +310,20 @@ const FlexBasisScope *flexBasisScope(const Node &node, bool horizontal)
|
|
|
241
310
|
}
|
|
242
311
|
bool hasFlexBasis(const Node &node)
|
|
243
312
|
{
|
|
244
|
-
return node.
|
|
313
|
+
return node.computedStyle().flex_basis != kUnset || rstyle(node.computedStyle()).flex_basis_expression >= 0;
|
|
245
314
|
}
|
|
246
315
|
|
|
247
316
|
bool hasExplicitWidth(const Node &node)
|
|
248
317
|
{
|
|
249
318
|
if (const auto *basis = flexBasisScope(node, true)) return basis->value != kUnset;
|
|
250
319
|
if (const auto *scope = intrinsicSizeScope(node, true); scope && scope->constraint == 0) return true;
|
|
251
|
-
if (isIntrinsicSizeExpression(node.
|
|
320
|
+
if (isIntrinsicSizeExpression(node.computedStyle().width_expression)) {
|
|
252
321
|
const auto *scope = intrinsicSizeScope(node, true);
|
|
253
322
|
return scope && scope->constraint == 0;
|
|
254
323
|
}
|
|
255
|
-
if (node.
|
|
324
|
+
if (node.computedStyle().width != kUnset) return true;
|
|
256
325
|
if (intrinsicWidthConstraint(node)) return false;
|
|
257
|
-
return node.
|
|
326
|
+
return node.computedStyle().width_expression >= 0 || node.computedStyle().width_percent != kUnset;
|
|
258
327
|
}
|
|
259
328
|
|
|
260
329
|
int clampLayoutSize(const Node &node, int size, bool horizontal)
|
|
@@ -262,8 +331,8 @@ int clampLayoutSize(const Node &node, int size, bool horizontal)
|
|
|
262
331
|
const auto *scope = intrinsicSizeScope(node, horizontal);
|
|
263
332
|
// The property's intrinsic size is measured first; its author's min/max
|
|
264
333
|
// constraints apply to the final used size, after resolving box edges.
|
|
265
|
-
if (scope && scope->constraint) return std::max(boxInsets(node.
|
|
266
|
-
return clampBorderBoxSize(node.
|
|
334
|
+
if (scope && scope->constraint) return std::max(boxInsets(node.computedStyle(), horizontal), size);
|
|
335
|
+
return clampBorderBoxSize(node.computedStyle(), size, horizontal);
|
|
267
336
|
}
|
|
268
337
|
|
|
269
338
|
int16_t clampInt16(int value)
|
|
@@ -275,14 +344,14 @@ int16_t clampInt16(int value)
|
|
|
275
344
|
|
|
276
345
|
bool percentageHeightDependsOnIntrinsicSize(const Node &node)
|
|
277
346
|
{
|
|
278
|
-
if (isOutOfFlowPosition(node.
|
|
347
|
+
if (isOutOfFlowPosition(node.computedStyle().position)) return false;
|
|
279
348
|
const Node *current = &node;
|
|
280
349
|
while (current->parent >= 0) {
|
|
281
350
|
const Node &parent = Tree::instance().nodes()[current->parent];
|
|
282
|
-
if (isIntrinsicSizeExpression(parent.
|
|
283
|
-
if (parent.
|
|
284
|
-
if (parent.
|
|
285
|
-
!layoutSizeExpressionUsesPercentage(current->parent, parent.
|
|
351
|
+
if (isIntrinsicSizeExpression(parent.computedStyle().height_expression)) return true;
|
|
352
|
+
if (parent.computedStyle().height != kUnset || isOutOfFlowPosition(parent.computedStyle().position)) return false;
|
|
353
|
+
if (parent.computedStyle().height_expression >= 0 &&
|
|
354
|
+
!layoutSizeExpressionUsesPercentage(current->parent, parent.computedStyle().height_expression)) return false;
|
|
286
355
|
current = &parent;
|
|
287
356
|
}
|
|
288
357
|
return false;
|
|
@@ -292,23 +361,23 @@ bool hasExplicitHeight(const Node &node)
|
|
|
292
361
|
{
|
|
293
362
|
if (const auto *basis = flexBasisScope(node, false)) return basis->value != kUnset;
|
|
294
363
|
if (const auto *scope = intrinsicSizeScope(node, false); scope && scope->constraint == 0) return true;
|
|
295
|
-
if (node.
|
|
364
|
+
if (node.computedStyle().height != kUnset) return true;
|
|
296
365
|
if (intrinsicSizeConstraint(node, false)) return false;
|
|
297
|
-
if (node.
|
|
366
|
+
if (node.computedStyle().height_expression < 0 && node.computedStyle().height_percent == kUnset) return false;
|
|
298
367
|
if (!percentageHeightDependsOnIntrinsicSize(node)) return true;
|
|
299
|
-
return node.
|
|
300
|
-
!layoutSizeExpressionUsesPercentage(static_cast<int>(&node - Tree::instance().nodes()), node.
|
|
368
|
+
return node.computedStyle().height_percent == kUnset &&
|
|
369
|
+
!layoutSizeExpressionUsesPercentage(static_cast<int>(&node - Tree::instance().nodes()), node.computedStyle().height_expression);
|
|
301
370
|
}
|
|
302
371
|
|
|
303
372
|
int resolvedStyleWidth(const Node &node, int basis)
|
|
304
373
|
{
|
|
305
374
|
if (const auto *scope = flexBasisScope(node, true)) return scope->value == kUnset ? basis : scope->value;
|
|
306
375
|
if (const auto *scope = intrinsicSizeScope(node, true); scope && scope->constraint == 0)
|
|
307
|
-
return std::max(0, scope->borderSize - (node.
|
|
376
|
+
return std::max(0, scope->borderSize - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), true) : 0));
|
|
308
377
|
if (!hasExplicitWidth(node)) return basis;
|
|
309
|
-
if (node.
|
|
310
|
-
if (node.
|
|
311
|
-
if (node.
|
|
378
|
+
if (node.computedStyle().width_expression >= 0) return resolveLayoutSizeExpression(static_cast<int>(&node - Tree::instance().nodes()), node.computedStyle().width_expression, true);
|
|
379
|
+
if (node.computedStyle().width != kUnset) return node.computedStyle().width;
|
|
380
|
+
if (node.computedStyle().width_percent != kUnset) return resolvePercentSize(basis, node.computedStyle().width_percent);
|
|
312
381
|
return basis;
|
|
313
382
|
}
|
|
314
383
|
|
|
@@ -316,29 +385,29 @@ int resolvedStyleHeight(const Node &node, int basis)
|
|
|
316
385
|
{
|
|
317
386
|
if (const auto *scope = flexBasisScope(node, false)) return scope->value == kUnset ? basis : scope->value;
|
|
318
387
|
if (const auto *scope = intrinsicSizeScope(node, false); scope && scope->constraint == 0)
|
|
319
|
-
return std::max(0, scope->borderSize - (node.
|
|
388
|
+
return std::max(0, scope->borderSize - (node.computedStyle().box_sizing == 0 ? boxInsets(node.computedStyle(), false) : 0));
|
|
320
389
|
if (!hasExplicitHeight(node)) return basis;
|
|
321
|
-
if (node.
|
|
322
|
-
if (node.
|
|
323
|
-
if (node.
|
|
324
|
-
return resolvePercentSize(basis, node.
|
|
390
|
+
if (node.computedStyle().height_expression >= 0) return resolveLayoutSizeExpression(static_cast<int>(&node - Tree::instance().nodes()), node.computedStyle().height_expression, false);
|
|
391
|
+
if (node.computedStyle().height != kUnset) return node.computedStyle().height;
|
|
392
|
+
if (node.computedStyle().height_percent != kUnset && !percentageHeightDependsOnIntrinsicSize(node))
|
|
393
|
+
return resolvePercentSize(basis, node.computedStyle().height_percent);
|
|
325
394
|
return basis;
|
|
326
395
|
}
|
|
327
396
|
|
|
328
397
|
int writingMode(const Node &node)
|
|
329
398
|
{
|
|
330
399
|
const Node *current = &node;
|
|
331
|
-
while (current->
|
|
400
|
+
while (current->computedStyle().writing_mode < 0 && current->parent >= 0)
|
|
332
401
|
current = &Tree::instance().nodes()[current->parent];
|
|
333
|
-
return current->
|
|
402
|
+
return current->computedStyle().writing_mode < 0 ? 0 : current->computedStyle().writing_mode;
|
|
334
403
|
}
|
|
335
404
|
|
|
336
405
|
bool rightToLeft(const Node &node)
|
|
337
406
|
{
|
|
338
407
|
const Node *current = &node;
|
|
339
|
-
while (current->
|
|
408
|
+
while (current->computedStyle().direction < 0 && current->parent >= 0)
|
|
340
409
|
current = &Tree::instance().nodes()[current->parent];
|
|
341
|
-
return current->
|
|
410
|
+
return current->computedStyle().direction == 1;
|
|
342
411
|
}
|
|
343
412
|
|
|
344
413
|
struct GridAxisPlacement {
|
|
@@ -375,7 +444,7 @@ bool flexRowDirection(const ComputedStyle &style);
|
|
|
375
444
|
double preferredRatio(const Node &node)
|
|
376
445
|
{
|
|
377
446
|
float ratio = 0;
|
|
378
|
-
const int bits = rstyle(node.
|
|
447
|
+
const int bits = (GEA_CSS_ASPECT_RATIO ? rstyle(node.computedStyle()).aspect_ratio : 0);
|
|
379
448
|
std::memcpy(&ratio, &bits, sizeof(ratio));
|
|
380
449
|
if (!std::isfinite(ratio)) return 0;
|
|
381
450
|
if (ratio < 0 && node.type == NodeType::Image && node.image_id >= 0) return 0;
|
|
@@ -386,17 +455,17 @@ int ratioTransferredSize(const Node &node, int crossBorderSize, bool horizontal)
|
|
|
386
455
|
{
|
|
387
456
|
const double ratio = preferredRatio(node);
|
|
388
457
|
if (ratio <= 0) return 0;
|
|
389
|
-
const int crossEdges = node.
|
|
390
|
-
const int mainEdges = node.
|
|
458
|
+
const int crossEdges = node.computedStyle().box_sizing ? 0 : boxInsets(node.computedStyle(), !horizontal);
|
|
459
|
+
const int mainEdges = node.computedStyle().box_sizing ? 0 : boxInsets(node.computedStyle(), horizontal);
|
|
391
460
|
const double value = std::max(0, crossBorderSize - crossEdges) * (horizontal ? ratio : 1 / ratio) + mainEdges;
|
|
392
461
|
return static_cast<int>(std::min(32767.0, std::round(value)));
|
|
393
462
|
}
|
|
394
463
|
|
|
395
464
|
bool definiteFlexCrossSize(const Node &parent, const Node &child, bool row)
|
|
396
465
|
{
|
|
397
|
-
const int alignment = child.
|
|
466
|
+
const int alignment = child.computedStyle().align_self >= 0 ? child.computedStyle().align_self : parent.computedStyle().align_items;
|
|
398
467
|
const int margins = row ? 5 : 10;
|
|
399
|
-
return parent.
|
|
468
|
+
return parent.computedStyle().flex_wrap == 0 && alignment == 0 && !(child.computedStyle().margin_auto & margins) &&
|
|
400
469
|
(row ? hasExplicitHeight(parent) : hasExplicitWidth(parent));
|
|
401
470
|
}
|
|
402
471
|
|
|
@@ -407,15 +476,15 @@ void applyPreferredRatio(Node &node, int availableWidth, int availableHeight)
|
|
|
407
476
|
bool width = hasExplicitWidth(node), height = hasExplicitHeight(node);
|
|
408
477
|
if (width && height) return;
|
|
409
478
|
const Node *parent = node.parent >= 0 ? &Tree::instance().nodes()[node.parent] : nullptr;
|
|
410
|
-
const bool flexItem = parent && parent->
|
|
479
|
+
const bool flexItem = parent && parent->computedStyle().display == kDisplayFlex;
|
|
411
480
|
if (flexItem && !width && !height) {
|
|
412
|
-
const bool row = flexRowDirection(parent->
|
|
481
|
+
const bool row = flexRowDirection(parent->computedStyle()) != (writingMode(*parent) != 0);
|
|
413
482
|
if (definiteFlexCrossSize(*parent, node, row)) {
|
|
414
483
|
if (row) {
|
|
415
|
-
node.layout.height = clampLayoutSize(node, availableHeight - node.
|
|
484
|
+
node.layout.height = clampLayoutSize(node, availableHeight - node.computedStyle().margin[0] - node.computedStyle().margin[2], false);
|
|
416
485
|
height = true;
|
|
417
486
|
} else {
|
|
418
|
-
node.layout.width = clampLayoutSize(node, availableWidth - node.
|
|
487
|
+
node.layout.width = clampLayoutSize(node, availableWidth - node.computedStyle().margin[1] - node.computedStyle().margin[3], true);
|
|
419
488
|
width = true;
|
|
420
489
|
}
|
|
421
490
|
}
|
|
@@ -423,16 +492,16 @@ void applyPreferredRatio(Node &node, int availableWidth, int availableHeight)
|
|
|
423
492
|
if (!width && !height) {
|
|
424
493
|
// Normal block flow supplies a definite inline size. Shrink-to-fit
|
|
425
494
|
// contexts keep the intrinsic width measured from their contents.
|
|
426
|
-
if (!flexItem && !node.
|
|
427
|
-
node.layout.width = clampLayoutSize(node, availableWidth - node.
|
|
495
|
+
if (!flexItem && !node.computedStyle().float_side && !isOutOfFlowPosition(node.computedStyle().position))
|
|
496
|
+
node.layout.width = clampLayoutSize(node, availableWidth - node.computedStyle().margin[1] - node.computedStyle().margin[3], true);
|
|
428
497
|
width = true;
|
|
429
498
|
}
|
|
430
499
|
const bool horizontal = !width && height;
|
|
431
500
|
int16_t &target = horizontal ? node.layout.width : node.layout.height;
|
|
432
501
|
const int fromRatio = ratioTransferredSize(node, horizontal ? node.layout.height : node.layout.width, horizontal);
|
|
433
502
|
// Non-scrollable boxes retain a content-based minimum on the automatic axis.
|
|
434
|
-
const bool contentMinimum = node.type != NodeType::Image && (horizontal ? node.
|
|
435
|
-
!isScrollableOverflow(horizontal ? overflowX(node.
|
|
503
|
+
const bool contentMinimum = node.type != NodeType::Image && (horizontal ? node.computedStyle().min_width : node.computedStyle().min_height) == kUnset &&
|
|
504
|
+
!isScrollableOverflow(horizontal ? overflowX(node.computedStyle()) : overflowY(node.computedStyle()));
|
|
436
505
|
const int result = contentMinimum ? std::max<int>(target, fromRatio) : fromRatio;
|
|
437
506
|
target = clampInt16(clampLayoutSize(node, result, horizontal));
|
|
438
507
|
}
|
|
@@ -482,8 +551,8 @@ int usedGridAlignment(const Node &parent, const Node &child, int alignment, int
|
|
|
482
551
|
void gridPhysicalRange(const Node &parent, bool columns, int start, int end, int &offset, int &size)
|
|
483
552
|
{
|
|
484
553
|
const bool horizontal = columns == (writingMode(parent) == 0);
|
|
485
|
-
const int available = (horizontal ? parent.layout.width : parent.layout.height) - boxInsets(parent.
|
|
486
|
-
offset = boxInset(parent.
|
|
554
|
+
const int available = (horizontal ? parent.layout.width : parent.layout.height) - boxInsets(parent.computedStyle(), horizontal);
|
|
555
|
+
offset = boxInset(parent.computedStyle(), horizontal ? 3 : 0) + (gridAxisReversed(parent, horizontal) ? available - end : start);
|
|
487
556
|
size = std::max(0, end - start);
|
|
488
557
|
}
|
|
489
558
|
|
|
@@ -494,8 +563,8 @@ bool flexRowDirection(const ComputedStyle &style)
|
|
|
494
563
|
|
|
495
564
|
int resolvedGap(const Node &node, bool rowGap, int width, int height)
|
|
496
565
|
{
|
|
497
|
-
const int length = rowGap ? node.
|
|
498
|
-
const int percent = rowGap ? node.
|
|
566
|
+
const int length = rowGap ? node.computedStyle().row_gap : node.computedStyle().column_gap;
|
|
567
|
+
const int percent = rowGap ? node.computedStyle().row_gap_percent : node.computedStyle().column_gap_percent;
|
|
499
568
|
const bool vertical = writingMode(node) != 0;
|
|
500
569
|
const bool horizontalAxis = rowGap == vertical;
|
|
501
570
|
if (percent != kUnset) {
|
|
@@ -503,7 +572,7 @@ int resolvedGap(const Node &node, bool rowGap, int width, int height)
|
|
|
503
572
|
if (horizontalAxis ? !hasExplicitWidth(node) : !hasExplicitHeight(node)) return 0;
|
|
504
573
|
return std::max(0, resolvePercentSize(horizontalAxis ? width : height, percent));
|
|
505
574
|
}
|
|
506
|
-
return std::max(0, length == kUnset ? node.
|
|
575
|
+
return std::max(0, length == kUnset ? node.computedStyle().gap : length);
|
|
507
576
|
}
|
|
508
577
|
|
|
509
578
|
int clampBorderSize(LayoutEngine &engine, const Node &node, int size, bool horizontal)
|
|
@@ -526,12 +595,12 @@ public:
|
|
|
526
595
|
padHeight_(padHeight),
|
|
527
596
|
lines_(lines)
|
|
528
597
|
{
|
|
529
|
-
const bool logicalRow = node.
|
|
598
|
+
const bool logicalRow = node.computedStyle().display == kDisplayFlex ? flexRowDirection(node.computedStyle()) : isRow;
|
|
530
599
|
mainGap_ = resolvedGap(node, !logicalRow, padWidth, padHeight);
|
|
531
600
|
crossGap_ = resolvedGap(node, logicalRow, padWidth, padHeight);
|
|
532
601
|
// Most containers fit the shared 32-line storage. Allocate extra lines
|
|
533
602
|
// only for a wrapping container that can actually exceed it.
|
|
534
|
-
if (node.
|
|
603
|
+
if (node.computedStyle().display == kDisplayFlex && node.computedStyle().flex_wrap && childCount > kMaxFlexLines) {
|
|
535
604
|
extraLines_.resize(childCount);
|
|
536
605
|
lines_ = extraLines_.data();
|
|
537
606
|
}
|
|
@@ -543,9 +612,9 @@ public:
|
|
|
543
612
|
const int child = children_[i];
|
|
544
613
|
int childAvailWidth = isRow_ ? mainAvail_ : padWidth_;
|
|
545
614
|
int childAvailHeight = isRow_ ? padHeight_ : mainAvail_;
|
|
546
|
-
const int count = rstyle(node_.
|
|
615
|
+
const int count = (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.computedStyle()).flex_line_count : 1);
|
|
547
616
|
const Node &item = Tree::instance().nodes()[child];
|
|
548
|
-
if (node_.
|
|
617
|
+
if (node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap && count > 1) {
|
|
549
618
|
// The specified count limits available cross space even for normal
|
|
550
619
|
// wrapping. Percentage cross sizes retain the container's basis.
|
|
551
620
|
const auto available = [&](int size) {
|
|
@@ -555,14 +624,14 @@ public:
|
|
|
555
624
|
if (isRow_ && hasExplicitHeight(node_) && !hasExplicitHeight(item)) childAvailHeight = available(childAvailHeight);
|
|
556
625
|
if (!isRow_ && !hasExplicitWidth(item)) childAvailWidth = available(childAvailWidth);
|
|
557
626
|
}
|
|
558
|
-
if (node_.
|
|
627
|
+
if (node_.computedStyle().display == kDisplayFlex && hasFlexBasis(item)) {
|
|
559
628
|
const int basis = resolveLayoutFlexBasis(child, flexPercentageBasis(), isRow_);
|
|
560
629
|
FlexBasisScope scope(item, isRow_, basis);
|
|
561
630
|
engine_.layoutNode(child, childAvailWidth, childAvailHeight);
|
|
562
631
|
} else {
|
|
563
632
|
engine_.layoutNode(child, childAvailWidth, childAvailHeight);
|
|
564
633
|
}
|
|
565
|
-
if (node_.
|
|
634
|
+
if (node_.computedStyle().display == kDisplayFlex) {
|
|
566
635
|
applyFlexBasis(child);
|
|
567
636
|
Node &item = Tree::instance().nodes()[child];
|
|
568
637
|
const int floor = automaticMinimumMainSize(item);
|
|
@@ -579,7 +648,7 @@ public:
|
|
|
579
648
|
expandCrossSizes(lineCount, autosize);
|
|
580
649
|
if (autosize) autosizeParent(lineCount);
|
|
581
650
|
positionLines(lineCount);
|
|
582
|
-
if (node_.
|
|
651
|
+
if (node_.computedStyle().display != kDisplayFlex) return;
|
|
583
652
|
Node *nodes = Tree::instance().nodes();
|
|
584
653
|
bool collapsed = false;
|
|
585
654
|
for (int i = 0; i < childCount_; ++i) collapsed |= isCollapsedFlexItem(nodes[children_[i]]);
|
|
@@ -608,7 +677,7 @@ public:
|
|
|
608
677
|
// split across two.
|
|
609
678
|
int buildLines()
|
|
610
679
|
{
|
|
611
|
-
if (node_.
|
|
680
|
+
if (node_.computedStyle().display == kDisplayFlex && (node_.computedStyle().flex_wrap & 4)) return buildBalancedLines();
|
|
612
681
|
int lineStart = 0;
|
|
613
682
|
int lineMain = 0;
|
|
614
683
|
int lineCross = 0;
|
|
@@ -620,14 +689,14 @@ public:
|
|
|
620
689
|
const int child = children_[i];
|
|
621
690
|
Node &childNode = nodes[child];
|
|
622
691
|
const int childMain = isRow_
|
|
623
|
-
? (childNode.layout.width + childNode.
|
|
624
|
-
: (childNode.layout.height + childNode.
|
|
692
|
+
? (childNode.layout.width + childNode.computedStyle().margin[1] + childNode.computedStyle().margin[3])
|
|
693
|
+
: (childNode.layout.height + childNode.computedStyle().margin[0] + childNode.computedStyle().margin[2]);
|
|
625
694
|
const int childCross = isRow_
|
|
626
|
-
? (childNode.layout.height + childNode.
|
|
627
|
-
: (childNode.layout.width + childNode.
|
|
695
|
+
? (childNode.layout.height + childNode.computedStyle().margin[0] + childNode.computedStyle().margin[2])
|
|
696
|
+
: (childNode.layout.width + childNode.computedStyle().margin[1] + childNode.computedStyle().margin[3]);
|
|
628
697
|
|
|
629
698
|
const int withGap = gapCount > 0 ? mainGap_ : 0;
|
|
630
|
-
if (node_.
|
|
699
|
+
if (node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap && lineMain + childMain + withGap > flexWrapLimit() && gapCount > 0) {
|
|
631
700
|
appendLine(lineCount, lineStart, gapCount, lineMain, lineCross);
|
|
632
701
|
lineStart = i;
|
|
633
702
|
lineMain = childMain;
|
|
@@ -661,6 +730,7 @@ public:
|
|
|
661
730
|
Node *nodes = Tree::instance().nodes();
|
|
662
731
|
const int parentId = static_cast<int>(&node_ - nodes);
|
|
663
732
|
int firstLineStyleOwner = -1;
|
|
733
|
+
#if GEA_CSS_FIRST_LINE
|
|
664
734
|
for (int ancestor = parentId; ancestor >= 0; ancestor = nodes[ancestor].parent) {
|
|
665
735
|
const NodeRareData *rare = rareDataFor(ancestor);
|
|
666
736
|
if (rare && rare->firstLineBackground.hasColor) {
|
|
@@ -671,16 +741,16 @@ public:
|
|
|
671
741
|
// carries it only when it is the first in-flow formatted child of its
|
|
672
742
|
// parent; following block siblings start after the owner's first line.
|
|
673
743
|
if (!LayoutEngine::isCssInlineLevelBox(nodes[ancestor])) {
|
|
674
|
-
if (isOutOfFlowPosition(nodes[ancestor].
|
|
744
|
+
if (isOutOfFlowPosition(nodes[ancestor].computedStyle().position) || nodes[ancestor].computedStyle().float_side) break;
|
|
675
745
|
const int parent = nodes[ancestor].parent;
|
|
676
746
|
if (parent < 0) break;
|
|
677
|
-
if (nodes[parent].
|
|
747
|
+
if (nodes[parent].computedStyle().display == kDisplayFlex || isDisplayGrid(nodes[parent].computedStyle())) break;
|
|
678
748
|
bool firstInFlow = true;
|
|
679
749
|
for (int sibling = nodes[parent].first_child; sibling >= 0 && sibling != ancestor;
|
|
680
750
|
sibling = nodes[sibling].next_sibling) {
|
|
681
|
-
if (!isDisplayNone(nodes[sibling].
|
|
682
|
-
!isOutOfFlowPosition(nodes[sibling].
|
|
683
|
-
!nodes[sibling].
|
|
751
|
+
if (!isDisplayNone(nodes[sibling].computedStyle()) &&
|
|
752
|
+
!isOutOfFlowPosition(nodes[sibling].computedStyle().position) &&
|
|
753
|
+
!nodes[sibling].computedStyle().float_side &&
|
|
684
754
|
!suppressAnonymousWhitespace(nodes, parent, sibling)) {
|
|
685
755
|
firstInFlow = false;
|
|
686
756
|
break;
|
|
@@ -689,7 +759,9 @@ public:
|
|
|
689
759
|
if (!firstInFlow) break;
|
|
690
760
|
}
|
|
691
761
|
}
|
|
762
|
+
#endif
|
|
692
763
|
const bool captureFirstLine = firstLineStyleOwner >= 0;
|
|
764
|
+
#if GEA_CSS_FIRST_LINE
|
|
693
765
|
// Runs that leave this formatting context must not keep an old fragment
|
|
694
766
|
// rectangle. A nested inline flow may write its own first-line fragment
|
|
695
767
|
// later in the same layout pass.
|
|
@@ -699,11 +771,12 @@ public:
|
|
|
699
771
|
const int run = transparentInlineRun(nodes[child]);
|
|
700
772
|
if (run >= 0) if (NodeRareData *rare = rareDataFor(run)) rare->firstLineFragment.valid = false;
|
|
701
773
|
}
|
|
774
|
+
#endif
|
|
702
775
|
std::vector<std::pair<int, int>> staticBoundaries;
|
|
703
776
|
int flowIndex = 0;
|
|
704
777
|
for (int child = node_.first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
705
|
-
if (isDisplayNone(nodes[child].
|
|
706
|
-
if (isOutOfFlowPosition(nodes[child].
|
|
778
|
+
if (isDisplayNone(nodes[child].computedStyle()) || suppressAnonymousWhitespace(nodes, parentId, child)) continue;
|
|
779
|
+
if (isOutOfFlowPosition(nodes[child].computedStyle().position)) {
|
|
707
780
|
if (auto *rare = rareDataFor(child)) rare->inlineStaticPosition.valid = false;
|
|
708
781
|
if (LayoutEngine::isCssInlineLevelBox(nodes[child], true))
|
|
709
782
|
staticBoundaries.emplace_back(flowIndex, child);
|
|
@@ -722,13 +795,13 @@ public:
|
|
|
722
795
|
if (child.type == NodeType::Text || wrappedRun >= 0) {
|
|
723
796
|
contentW = std::max(contentW, TextRenderer::minContentWidth(wrappedRun >= 0 ? nodes[wrappedRun] : child, &pendingWord));
|
|
724
797
|
} else {
|
|
725
|
-
contentW = std::max(contentW, child.layout.width + child.
|
|
798
|
+
contentW = std::max(contentW, child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
726
799
|
pendingWord = 0;
|
|
727
800
|
}
|
|
728
801
|
}
|
|
729
802
|
}
|
|
730
|
-
const int contentLeft = boxInset(node_.
|
|
731
|
-
const int contentTop = boxInset(node_.
|
|
803
|
+
const int contentLeft = boxInset(node_.computedStyle(), 3);
|
|
804
|
+
const int contentTop = boxInset(node_.computedStyle(), 0);
|
|
732
805
|
const int gapStyle = mainGap_;
|
|
733
806
|
|
|
734
807
|
const bool blockOpensItsFirstLine = startsFormattingLine(nodes, parentId);
|
|
@@ -778,8 +851,8 @@ public:
|
|
|
778
851
|
captureStaticBoundary(j, pen, lineStaticChildren, lineIsContinuation || i > 0);
|
|
779
852
|
const int child = children_[j];
|
|
780
853
|
Node &cn = nodes[child];
|
|
781
|
-
const int marginL = cn.
|
|
782
|
-
const int marginR = cn.
|
|
854
|
+
const int marginL = cn.computedStyle().margin[3];
|
|
855
|
+
const int marginR = cn.computedStyle().margin[1];
|
|
783
856
|
const int gap = pen > 0 ? gapStyle : 0;
|
|
784
857
|
|
|
785
858
|
if (isLineBreak(cn)) {
|
|
@@ -797,8 +870,8 @@ public:
|
|
|
797
870
|
const int innerRun = isFragmentableRun(cn) ? -1 : transparentInlineRun(cn);
|
|
798
871
|
Node &subject = innerRun >= 0 ? nodes[innerRun] : cn;
|
|
799
872
|
if (isFragmentableRun(subject)) {
|
|
800
|
-
const int padH = boxInset(subject.
|
|
801
|
-
const int padV = boxInset(subject.
|
|
873
|
+
const int padH = boxInset(subject.computedStyle(), 1) + boxInset(subject.computedStyle(), 3);
|
|
874
|
+
const int padV = boxInset(subject.computedStyle(), 0) + boxInset(subject.computedStyle(), 2);
|
|
802
875
|
// Budgets are TEXT widths: the run's own padding is part of its box,
|
|
803
876
|
// not of the line it can fill.
|
|
804
877
|
const int rest = contentW - marginL - marginR - padH;
|
|
@@ -811,7 +884,7 @@ public:
|
|
|
811
884
|
// run keeps flowing whole, exactly as before.
|
|
812
885
|
const bool haveLineMetrics =
|
|
813
886
|
m.lineAdvance > 0 &&
|
|
814
|
-
childBaseline(subject) <= boxInset(subject.
|
|
887
|
+
childBaseline(subject) <= boxInset(subject.computedStyle(), 0) + m.lineAdvance;
|
|
815
888
|
if (m.lineCount > 0 && haveLineMetrics) {
|
|
816
889
|
// Its first WORD does not fit what is left: the run starts the
|
|
817
890
|
// next line box rather than overflowing it or being cut open.
|
|
@@ -841,7 +914,7 @@ public:
|
|
|
841
914
|
cn.layout.inline_indent = clampInt16(indent);
|
|
842
915
|
}
|
|
843
916
|
if (wraps) {
|
|
844
|
-
const int ascent = cn.
|
|
917
|
+
const int ascent = cn.computedStyle().margin[0] + childBaseline(cn);
|
|
845
918
|
const int descent = runLineDescent(subject, m.lineAdvance);
|
|
846
919
|
if (ascent > lineAscent) lineAscent = ascent;
|
|
847
920
|
if (descent > lineDescent) lineDescent = descent;
|
|
@@ -866,7 +939,7 @@ public:
|
|
|
866
939
|
const int itemMain = cn.layout.width + marginL + marginR;
|
|
867
940
|
if (pen > 0 && pen + gap + itemMain > contentW) break;
|
|
868
941
|
if (isFragmentableRun(subject) && captureFirstLine && i == 0) {
|
|
869
|
-
const int padH = boxInset(subject.
|
|
942
|
+
const int padH = boxInset(subject.computedStyle(), 1) + boxInset(subject.computedStyle(), 3);
|
|
870
943
|
const int rest = contentW - marginL - marginR - padH;
|
|
871
944
|
const InlineFlowMeasure m = TextRenderer::measureInlineFlow(
|
|
872
945
|
subject, rest - pen - gap, rest, pen == 0 && (j > 0 || blockOpensItsFirstLine));
|
|
@@ -874,12 +947,12 @@ public:
|
|
|
874
947
|
firstLineCandidates.push_back({innerRun >= 0 ? innerRun : child,
|
|
875
948
|
contentLeft + pen + gap + marginL,
|
|
876
949
|
m.firstLineWidth + padH,
|
|
877
|
-
m.lineAdvance + boxInset(subject.
|
|
950
|
+
m.lineAdvance + boxInset(subject.computedStyle(), 0) + boxInset(subject.computedStyle(), 2),
|
|
878
951
|
j, m.firstLineTrailingSpace});
|
|
879
952
|
}
|
|
880
953
|
}
|
|
881
|
-
const int ascent = cn.
|
|
882
|
-
const int descent = cn.layout.height + cn.
|
|
954
|
+
const int ascent = cn.computedStyle().margin[0] + childBaseline(cn);
|
|
955
|
+
const int descent = cn.layout.height + cn.computedStyle().margin[2] - childBaseline(cn);
|
|
883
956
|
if (ascent > lineAscent) lineAscent = ascent;
|
|
884
957
|
if (descent > lineDescent) lineDescent = descent;
|
|
885
958
|
pen += gap + itemMain;
|
|
@@ -911,6 +984,7 @@ public:
|
|
|
911
984
|
|
|
912
985
|
placeLineItems(nodes, i, j, contentLeft, contentW, lineTop, lineCross, baseline, penStart,
|
|
913
986
|
!lineIsContinuation);
|
|
987
|
+
#if GEA_CSS_FIRST_LINE
|
|
914
988
|
if (i == 0 && captureFirstLine) {
|
|
915
989
|
int firstFormattedLineHeight = actualLineCross;
|
|
916
990
|
if (!firstLineCandidates.empty()) firstFormattedLineHeight = 0;
|
|
@@ -950,6 +1024,7 @@ public:
|
|
|
950
1024
|
fragment.valid = fragment.width > 0 && fragment.height > 0;
|
|
951
1025
|
}
|
|
952
1026
|
}
|
|
1027
|
+
#endif
|
|
953
1028
|
|
|
954
1029
|
if (baseline + lineDescent > flowBottom) flowBottom = baseline + lineDescent;
|
|
955
1030
|
if (lineTop + lineCross > flowBottom) flowBottom = lineTop + lineCross;
|
|
@@ -958,9 +1033,9 @@ public:
|
|
|
958
1033
|
Node &run = nodes[children_[wrapIdx]];
|
|
959
1034
|
const int runBaseline = run.layout.y + childBaseline(run);
|
|
960
1035
|
continuedBaseline = runBaseline + (wrapSpans - 1) * wrapAdvance;
|
|
961
|
-
inheritedAscent = run.
|
|
1036
|
+
inheritedAscent = run.computedStyle().margin[0] + childBaseline(run);
|
|
962
1037
|
inheritedDescent = runLineDescent(run, wrapAdvance);
|
|
963
|
-
penStart = run.
|
|
1038
|
+
penStart = run.computedStyle().margin[3] + wrapLastWidth + run.computedStyle().margin[1];
|
|
964
1039
|
continuing = true;
|
|
965
1040
|
if (trailingWrappedStaticBoundary) {
|
|
966
1041
|
std::vector<int> trailingStaticChildren;
|
|
@@ -1013,14 +1088,14 @@ public:
|
|
|
1013
1088
|
// Same rules as autosizeParent: a scroll container keeps the size it was
|
|
1014
1089
|
// given on its scrolling axis so its overflow becomes scroll range.
|
|
1015
1090
|
const int flowHeight = flowBottom - contentTop;
|
|
1016
|
-
const bool keepScrollHeight = scrollsOverflowY(node_.
|
|
1017
|
-
const bool keepScrollWidth = !intrinsicWidthConstraint(node_) && scrollsOverflowX(node_.
|
|
1091
|
+
const bool keepScrollHeight = scrollsOverflowY(node_.computedStyle()) && node_.layout.height > 0;
|
|
1092
|
+
const bool keepScrollWidth = !intrinsicWidthConstraint(node_) && scrollsOverflowX(node_.computedStyle()) && node_.layout.width > 0;
|
|
1018
1093
|
if (!hasExplicitHeight(node_) && !keepScrollHeight) {
|
|
1019
|
-
const int height = (flowHeight < 0 ? 0 : flowHeight) + boxInset(node_.
|
|
1094
|
+
const int height = (flowHeight < 0 ? 0 : flowHeight) + boxInset(node_.computedStyle(), 0) + boxInset(node_.computedStyle(), 2);
|
|
1020
1095
|
node_.layout.height = clampInt16(clampLayoutSize(node_, height, false));
|
|
1021
1096
|
}
|
|
1022
1097
|
if (!hasExplicitWidth(node_) && !keepScrollWidth) {
|
|
1023
|
-
const int width = maxLineWidth + boxInset(node_.
|
|
1098
|
+
const int width = maxLineWidth + boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
1024
1099
|
node_.layout.width = clampInt16(clampLayoutSize(node_, width, true));
|
|
1025
1100
|
}
|
|
1026
1101
|
return extent;
|
|
@@ -1031,8 +1106,8 @@ public:
|
|
|
1031
1106
|
// or nowrap run keeps its own box.
|
|
1032
1107
|
static bool isFragmentableRun(const Node &n)
|
|
1033
1108
|
{
|
|
1034
|
-
return n.type == NodeType::Text && !n.text.empty() && n.
|
|
1035
|
-
n.
|
|
1109
|
+
return n.type == NodeType::Text && !n.text.empty() && n.computedStyle().white_space != 1 && n.computedStyle().white_space != 2 &&
|
|
1110
|
+
n.computedStyle().width == kUnset && n.computedStyle().width_percent == kUnset;
|
|
1036
1111
|
}
|
|
1037
1112
|
|
|
1038
1113
|
// True when nothing about `n`'s BOX is visible — no background, border, shadow,
|
|
@@ -1040,9 +1115,9 @@ public:
|
|
|
1040
1115
|
// convenient, because only its content is ever painted.
|
|
1041
1116
|
static bool paintsNoBox(const Node &n)
|
|
1042
1117
|
{
|
|
1043
|
-
if (n.
|
|
1118
|
+
if (n.computedStyle().has_bg || n.computedStyle().border_width > 0 || hasSideBorder(n.computedStyle())) return false;
|
|
1044
1119
|
#if GEA_EMBEDDED_RARE_STYLE_INLINE
|
|
1045
|
-
const RareStyle &r = rstyle(n.
|
|
1120
|
+
const RareStyle &r = rstyle(n.computedStyle());
|
|
1046
1121
|
if (r.translate_present || r.transform_present || r.rotate_present || r.scale_present || r.filter_present ||
|
|
1047
1122
|
r.transform_rotate || r.transform_rotate_x || r.transform_rotate_y ||
|
|
1048
1123
|
composedTranslateX(r) || composedTranslateY(r) || composedTranslateZ(r) ||
|
|
@@ -1053,7 +1128,7 @@ public:
|
|
|
1053
1128
|
#else
|
|
1054
1129
|
// No rare-style record at all: no transform, shadow, gradient or filter was
|
|
1055
1130
|
// ever set on this node.
|
|
1056
|
-
if (n.
|
|
1131
|
+
if (n.computedStyle().rare_style >= 0) return false;
|
|
1057
1132
|
#endif
|
|
1058
1133
|
return true;
|
|
1059
1134
|
}
|
|
@@ -1067,25 +1142,25 @@ public:
|
|
|
1067
1142
|
{
|
|
1068
1143
|
if (wrapper.type != NodeType::View) return -1;
|
|
1069
1144
|
if (!paintsNoBox(wrapper)) return -1;
|
|
1070
|
-
if (boxInset(wrapper.
|
|
1071
|
-
boxInset(wrapper.
|
|
1145
|
+
if (boxInset(wrapper.computedStyle(), 0) || boxInset(wrapper.computedStyle(), 1) || boxInset(wrapper.computedStyle(), 2) ||
|
|
1146
|
+
boxInset(wrapper.computedStyle(), 3))
|
|
1072
1147
|
return -1;
|
|
1073
1148
|
if (hasExplicitWidth(wrapper) || hasExplicitHeight(wrapper)) return -1;
|
|
1074
|
-
if (wrapper.
|
|
1075
|
-
if (wrapper.
|
|
1076
|
-
if (wrapper.
|
|
1077
|
-
if (wrapper.
|
|
1149
|
+
if (wrapper.computedStyle().min_width > 0 || wrapper.computedStyle().min_height > 0) return -1;
|
|
1150
|
+
if (wrapper.computedStyle().max_width != kUnset || wrapper.computedStyle().max_height != kUnset) return -1;
|
|
1151
|
+
if (overflowX(wrapper.computedStyle()) || overflowY(wrapper.computedStyle())) return -1;
|
|
1152
|
+
if (wrapper.computedStyle().align_self >= 0 || wrapper.computedStyle().flex > 0 ||
|
|
1078
1153
|
hasFlexBasis(wrapper))
|
|
1079
1154
|
return -1;
|
|
1080
1155
|
const Node *nodes = Tree::instance().nodes();
|
|
1081
1156
|
int run = -1;
|
|
1082
1157
|
for (int c = wrapper.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1083
1158
|
const Node &child = nodes[c];
|
|
1084
|
-
if (isDisplayNone(child.
|
|
1159
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
|
|
1085
1160
|
if (run >= 0) return -1; // more than one in-flow child
|
|
1086
1161
|
if (child.type != NodeType::Text) return -1;
|
|
1087
|
-
if (child.
|
|
1088
|
-
child.
|
|
1162
|
+
if (child.computedStyle().margin[0] || child.computedStyle().margin[1] || child.computedStyle().margin[2] ||
|
|
1163
|
+
child.computedStyle().margin[3])
|
|
1089
1164
|
return -1;
|
|
1090
1165
|
if (!isFragmentableRun(child)) return -1;
|
|
1091
1166
|
run = c;
|
|
@@ -1098,8 +1173,8 @@ public:
|
|
|
1098
1173
|
// actually carries — the others are flush, so this is the taller, safe value).
|
|
1099
1174
|
int runLineDescent(const Node &n, int lineAdvance) const
|
|
1100
1175
|
{
|
|
1101
|
-
const int ascender = childBaseline(n) - boxInset(n.
|
|
1102
|
-
const int descent = lineAdvance - ascender + boxInset(n.
|
|
1176
|
+
const int ascender = childBaseline(n) - boxInset(n.computedStyle(), 0);
|
|
1177
|
+
const int descent = lineAdvance - ascender + boxInset(n.computedStyle(), 2) + n.computedStyle().margin[2];
|
|
1103
1178
|
return descent < 0 ? 0 : descent;
|
|
1104
1179
|
}
|
|
1105
1180
|
|
|
@@ -1116,8 +1191,8 @@ public:
|
|
|
1116
1191
|
for (int k = from; k < to; k++) {
|
|
1117
1192
|
const int child = children_[k];
|
|
1118
1193
|
Node &cn = nodes[child];
|
|
1119
|
-
const int marginL = cn.
|
|
1120
|
-
const int marginR = cn.
|
|
1194
|
+
const int marginL = cn.computedStyle().margin[3];
|
|
1195
|
+
const int marginR = cn.computedStyle().margin[1];
|
|
1121
1196
|
const int gap = pen > 0 ? mainGap_ : 0;
|
|
1122
1197
|
|
|
1123
1198
|
if (cn.layout.inline_indent > 0) {
|
|
@@ -1136,15 +1211,15 @@ public:
|
|
|
1136
1211
|
}
|
|
1137
1212
|
|
|
1138
1213
|
int y = baseline - childBaseline(cn);
|
|
1139
|
-
const int align = usedAlignment(crossAlignFor(cn), lineCross - cn.layout.height - cn.
|
|
1214
|
+
const int align = usedAlignment(crossAlignFor(cn), lineCross - cn.layout.height - cn.computedStyle().margin[0] - cn.computedStyle().margin[2]);
|
|
1140
1215
|
if (align != 5) {
|
|
1141
|
-
const int crossBefore = cn.
|
|
1142
|
-
const int crossAfter = cn.
|
|
1216
|
+
const int crossBefore = cn.computedStyle().margin[0];
|
|
1217
|
+
const int crossAfter = cn.computedStyle().margin[2];
|
|
1143
1218
|
const int crossTotal = cn.layout.height + crossBefore + crossAfter;
|
|
1144
1219
|
y = lineTop + crossBefore;
|
|
1145
1220
|
if (align == 1) y += (lineCross - crossTotal) / 2;
|
|
1146
1221
|
else if (align == 2) y += lineCross - crossTotal;
|
|
1147
|
-
else if (align == 0 && !hasExplicitHeight(cn) && !isIntrinsicSizeExpression(cn.
|
|
1222
|
+
else if (align == 0 && !hasExplicitHeight(cn) && !isIntrinsicSizeExpression(cn.computedStyle().height_expression)) {
|
|
1148
1223
|
cn.layout.height = clampInt16(lineCross - crossBefore - crossAfter);
|
|
1149
1224
|
engine_.repositionChildren(child);
|
|
1150
1225
|
}
|
|
@@ -1163,12 +1238,12 @@ public:
|
|
|
1163
1238
|
void expandCrossSizes(int lineCount, bool onlyIfDefinite)
|
|
1164
1239
|
{
|
|
1165
1240
|
const bool hasDefiniteCross = isRow_ ? hasExplicitHeight(node_) : hasExplicitWidth(node_);
|
|
1166
|
-
const bool wrappingFlex = node_.
|
|
1241
|
+
const bool wrappingFlex = node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap;
|
|
1167
1242
|
if (onlyIfDefinite && !hasDefiniteCross) {
|
|
1168
1243
|
// A single flex line's intrinsic cross size still obeys the
|
|
1169
1244
|
// container's min/max cross size (Flexbox 9.4, step 8).
|
|
1170
|
-
if (node_.
|
|
1171
|
-
const int insets = boxInsets(node_.
|
|
1245
|
+
if (node_.computedStyle().display == kDisplayFlex && lineCount == 1 && !wrappingFlex) {
|
|
1246
|
+
const int insets = boxInsets(node_.computedStyle(), !isRow_);
|
|
1172
1247
|
lines_[0].crossSize = std::max(0, clampLayoutSize(node_, lines_[0].crossSize + insets, !isRow_) - insets);
|
|
1173
1248
|
}
|
|
1174
1249
|
return;
|
|
@@ -1177,7 +1252,7 @@ public:
|
|
|
1177
1252
|
const int crossAvail = isRow_ ? padHeight_ : padWidth_;
|
|
1178
1253
|
if (lineCount == 1 && !wrappingFlex) {
|
|
1179
1254
|
lines_[0].crossSize = crossAvail;
|
|
1180
|
-
} else if (lineCount > 0 && (!wrappingFlex || node_.
|
|
1255
|
+
} else if (lineCount > 0 && (!wrappingFlex || node_.computedStyle().align_content == 0)) {
|
|
1181
1256
|
int totalLineCross = 0;
|
|
1182
1257
|
for (int i = 0; i < lineCount; i++) totalLineCross += lines_[i].crossSize;
|
|
1183
1258
|
const int extra = crossAvail - totalLineCross - (lineCount - 1) * crossGap_;
|
|
@@ -1192,7 +1267,7 @@ public:
|
|
|
1192
1267
|
void positionLines(int lineCount)
|
|
1193
1268
|
{
|
|
1194
1269
|
Node *nodes = Tree::instance().nodes();
|
|
1195
|
-
const bool wrappingFlex = node_.
|
|
1270
|
+
const bool wrappingFlex = node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap;
|
|
1196
1271
|
const bool definiteCross = isRow_ ? hasExplicitHeight(node_) : hasExplicitWidth(node_);
|
|
1197
1272
|
bool ratioCrossChanged = false;
|
|
1198
1273
|
|
|
@@ -1204,8 +1279,8 @@ public:
|
|
|
1204
1279
|
// box shrinks to fit. Reading layout.{width,height} also gives the correct
|
|
1205
1280
|
// free space when a flex item was GROWN past its content by its parent.
|
|
1206
1281
|
const int mainBox = isRow_
|
|
1207
|
-
? (node_.layout.width - boxInset(node_.
|
|
1208
|
-
: (node_.layout.height - boxInset(node_.
|
|
1282
|
+
? (node_.layout.width - boxInset(node_.computedStyle(), 1) - boxInset(node_.computedStyle(), 3))
|
|
1283
|
+
: (node_.layout.height - boxInset(node_.computedStyle(), 0) - boxInset(node_.computedStyle(), 2));
|
|
1209
1284
|
const int mainContentBox = mainBox < 0 ? 0 : mainBox;
|
|
1210
1285
|
|
|
1211
1286
|
for (int lineIndex = 0; lineIndex < lineCount; lineIndex++) {
|
|
@@ -1227,7 +1302,7 @@ public:
|
|
|
1227
1302
|
// container skips main-axis shrink entirely — the pre-flex-shrink
|
|
1228
1303
|
// behavior for scrollable boxes.)
|
|
1229
1304
|
const bool mainAxisScrolls =
|
|
1230
|
-
isRow_ ? scrollsOverflowX(node_.
|
|
1305
|
+
isRow_ ? scrollsOverflowX(node_.computedStyle()) : scrollsOverflowY(node_.computedStyle());
|
|
1231
1306
|
if (!mainAxisScrolls) {
|
|
1232
1307
|
const int totalShrink = totalFlexShrinkForLine(line, nodes);
|
|
1233
1308
|
if (totalShrink > 0) {
|
|
@@ -1243,7 +1318,7 @@ public:
|
|
|
1243
1318
|
for (int i = 0; i < line.count; i++) {
|
|
1244
1319
|
const int child = children_[line.start + i];
|
|
1245
1320
|
Node &childNode = nodes[child];
|
|
1246
|
-
if (childNode.
|
|
1321
|
+
if (childNode.computedStyle().flex <= 0) continue;
|
|
1247
1322
|
const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
|
|
1248
1323
|
if (mainSize == 0) engine_.repositionChildren(child);
|
|
1249
1324
|
}
|
|
@@ -1253,10 +1328,10 @@ public:
|
|
|
1253
1328
|
for (int i = 0; i < line.count; ++i) {
|
|
1254
1329
|
const Node &child = nodes[children_[line.start + i]];
|
|
1255
1330
|
hasRatio |= preferredRatio(child) > 0;
|
|
1256
|
-
measuredCross = std::max(measuredCross, isRow_ ? child.layout.height + child.
|
|
1257
|
-
: child.layout.width + child.
|
|
1331
|
+
measuredCross = std::max(measuredCross, isRow_ ? child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2]
|
|
1332
|
+
: child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
1258
1333
|
}
|
|
1259
|
-
if (node_.
|
|
1334
|
+
if (node_.computedStyle().display == kDisplayFlex && hasRatio && !definiteCross) {
|
|
1260
1335
|
line.crossSize = std::max(line.strutSize, baselineCrossSize(line.start, line.count, measuredCross));
|
|
1261
1336
|
ratioCrossChanged = true;
|
|
1262
1337
|
}
|
|
@@ -1266,31 +1341,31 @@ public:
|
|
|
1266
1341
|
if (ratioCrossChanged) {
|
|
1267
1342
|
expandCrossSizes(lineCount, true);
|
|
1268
1343
|
int16_t &cross = isRow_ ? node_.layout.height : node_.layout.width;
|
|
1269
|
-
cross = clampInt16(clampLayoutSize(node_, totalCrossSize(lineCount) + boxInsets(node_.
|
|
1344
|
+
cross = clampInt16(clampLayoutSize(node_, totalCrossSize(lineCount) + boxInsets(node_.computedStyle(), !isRow_), !isRow_));
|
|
1270
1345
|
}
|
|
1271
|
-
int crossOffset = boxInset(node_.
|
|
1272
|
-
const int crossBox = (isRow_ ? node_.layout.height : node_.layout.width) - boxInsets(node_.
|
|
1346
|
+
int crossOffset = boxInset(node_.computedStyle(), isRow_ ? 0 : 3);
|
|
1347
|
+
const int crossBox = (isRow_ ? node_.layout.height : node_.layout.width) - boxInsets(node_.computedStyle(), !isRow_);
|
|
1273
1348
|
const int crossFree = crossBox - totalCrossSize(lineCount);
|
|
1274
1349
|
for (int lineIndex = 0; lineIndex < lineCount; ++lineIndex) {
|
|
1275
1350
|
FlexLine &line = lines_[lineIndex];
|
|
1276
1351
|
int occupied = std::max(0, line.count - 1) * mainGap_;
|
|
1277
1352
|
for (int i = 0; i < line.count; ++i) {
|
|
1278
1353
|
const Node &child = nodes[children_[line.start + i]];
|
|
1279
|
-
occupied += isRow_ ? child.layout.width + child.
|
|
1280
|
-
: child.layout.height + child.
|
|
1354
|
+
occupied += isRow_ ? child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]
|
|
1355
|
+
: child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
1281
1356
|
}
|
|
1282
1357
|
int remaining = mainContentBox - occupied;
|
|
1283
|
-
const int mainAlignment = usedAlignment(node_.
|
|
1358
|
+
const int mainAlignment = usedAlignment(node_.computedStyle().justify_content, remaining, node_.computedStyle().flex_direction_explicit && node_.computedStyle().flex_direction >= 2);
|
|
1284
1359
|
if (remaining < 0 && mainAlignment != 1 && mainAlignment != 2) remaining = 0;
|
|
1285
1360
|
|
|
1286
|
-
int mainOffset = isRow_ ? boxInset(node_.
|
|
1361
|
+
int mainOffset = isRow_ ? boxInset(node_.computedStyle(), 3) : boxInset(node_.computedStyle(), 0);
|
|
1287
1362
|
int autoCount = 0;
|
|
1288
1363
|
for (int i = 0; i < line.count; ++i) {
|
|
1289
|
-
const auto mask = nodes[children_[line.start + i]].
|
|
1364
|
+
const auto mask = nodes[children_[line.start + i]].computedStyle().margin_auto;
|
|
1290
1365
|
autoCount += isRow_ ? !!(mask & 2) + !!(mask & 8) : !!(mask & 1) + !!(mask & 4);
|
|
1291
1366
|
}
|
|
1292
1367
|
const int autoSpace = autoCount && remaining > 0 ? remaining : 0;
|
|
1293
|
-
if (!isDistributedAlignment(node_.
|
|
1368
|
+
if (!isDistributedAlignment(node_.computedStyle().justify_content))
|
|
1294
1369
|
applyJustifyContent(autoSpace ? 0 : remaining, &mainOffset);
|
|
1295
1370
|
const int lineOffset = wrappingFlex ? crossAlignmentOffset(lineIndex, lineCount, crossFree) : 0;
|
|
1296
1371
|
positionLineChildren(line, nodes, mainOffset, crossOffset + lineOffset, autoSpace, autoCount, autoSpace ? 0 : remaining);
|
|
@@ -1300,14 +1375,19 @@ public:
|
|
|
1300
1375
|
|
|
1301
1376
|
int crossAlignmentOffset(int index, int count, int free) const
|
|
1302
1377
|
{
|
|
1378
|
+
#if GEA_CSS_FLEX_WRAP
|
|
1379
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1380
|
+
#else
|
|
1381
|
+
constexpr bool wrapReversed = false;
|
|
1382
|
+
#endif
|
|
1303
1383
|
// A wrapping container is multi-line even when only one line is occupied.
|
|
1304
1384
|
// Distributed alignments fall back to start/center for overflowing lines.
|
|
1305
|
-
switch (usedAlignment(node_.
|
|
1385
|
+
switch (usedAlignment(node_.computedStyle().align_content, free, wrapReversed)) {
|
|
1306
1386
|
case 1: return free / 2;
|
|
1307
1387
|
case 2: return free;
|
|
1308
1388
|
case 3:
|
|
1309
1389
|
case 4:
|
|
1310
|
-
case kAlignSpaceEvenly: return distributedAlignmentOffset(node_.
|
|
1390
|
+
case kAlignSpaceEvenly: return distributedAlignmentOffset(node_.computedStyle().align_content, free, index, count);
|
|
1311
1391
|
default: return 0;
|
|
1312
1392
|
}
|
|
1313
1393
|
}
|
|
@@ -1322,16 +1402,16 @@ public:
|
|
|
1322
1402
|
// overflow:scroll/auto clips/scrolls its overflow, it does not expand to
|
|
1323
1403
|
// fit content. Guarded on a positive assigned size so an unsized scroll
|
|
1324
1404
|
// container still autosizes as before.
|
|
1325
|
-
const bool keepScrollHeight = scrollsOverflowY(node_.
|
|
1326
|
-
const bool keepScrollWidth = !intrinsicWidthConstraint(node_) && scrollsOverflowX(node_.
|
|
1405
|
+
const bool keepScrollHeight = scrollsOverflowY(node_.computedStyle()) && node_.layout.height > 0;
|
|
1406
|
+
const bool keepScrollWidth = !intrinsicWidthConstraint(node_) && scrollsOverflowX(node_.computedStyle()) && node_.layout.width > 0;
|
|
1327
1407
|
|
|
1328
1408
|
if (!hasExplicitHeight(node_) && !keepScrollHeight) {
|
|
1329
|
-
const int height = (isRow_ ? totalCrossSize(lineCount) : maxMainSize(lineCount)) + boxInset(node_.
|
|
1409
|
+
const int height = (isRow_ ? totalCrossSize(lineCount) : maxMainSize(lineCount)) + boxInset(node_.computedStyle(), 0) + boxInset(node_.computedStyle(), 2);
|
|
1330
1410
|
node_.layout.height = clampLayoutSize(node_, height, false);
|
|
1331
1411
|
}
|
|
1332
1412
|
|
|
1333
1413
|
if (!hasExplicitWidth(node_) && !keepScrollWidth) {
|
|
1334
|
-
const int width = (isRow_ ? maxMainSize(lineCount) : totalCrossSize(lineCount)) + boxInset(node_.
|
|
1414
|
+
const int width = (isRow_ ? maxMainSize(lineCount) : totalCrossSize(lineCount)) + boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
1335
1415
|
node_.layout.width = clampLayoutSize(node_, width, true);
|
|
1336
1416
|
}
|
|
1337
1417
|
}
|
|
@@ -1343,27 +1423,27 @@ private:
|
|
|
1343
1423
|
if (!blockAxis || assignedSize_ || (isRow_ ? hasExplicitWidth(node_) : hasExplicitHeight(node_))) return mainAvail_;
|
|
1344
1424
|
// An automatic block main size grows to fit its items. min-height is
|
|
1345
1425
|
// a floor, not a wrapping constraint; only a maximum bounds packing.
|
|
1346
|
-
if ((isRow_ ? node_.
|
|
1347
|
-
return std::max(0, clampLayoutSize(node_, INT16_MAX, isRow_) - boxInsets(node_.
|
|
1426
|
+
if ((isRow_ ? node_.computedStyle().max_width : node_.computedStyle().max_height) == kUnset) return INT_MAX;
|
|
1427
|
+
return std::max(0, clampLayoutSize(node_, INT16_MAX, isRow_) - boxInsets(node_.computedStyle(), isRow_));
|
|
1348
1428
|
}
|
|
1349
1429
|
|
|
1350
1430
|
int buildCollapsedLines(const std::vector<int> &struts)
|
|
1351
1431
|
{
|
|
1352
1432
|
Node *nodes = Tree::instance().nodes();
|
|
1353
1433
|
std::vector<int> balancedEnds;
|
|
1354
|
-
if (node_.
|
|
1434
|
+
if (node_.computedStyle().flex_wrap & 4) {
|
|
1355
1435
|
std::vector<int> sizes;
|
|
1356
1436
|
int total = 0;
|
|
1357
1437
|
for (int i = 0; i < childCount_; ++i) {
|
|
1358
1438
|
if (struts[i] >= 0) continue;
|
|
1359
1439
|
const Node &child = nodes[children_[i]];
|
|
1360
|
-
const int size = isRow_ ? child.layout.width + child.
|
|
1361
|
-
: child.layout.height + child.
|
|
1440
|
+
const int size = isRow_ ? child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]
|
|
1441
|
+
: child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
1362
1442
|
total += std::max(0, size) + (sizes.empty() ? 0 : mainGap_);
|
|
1363
1443
|
sizes.push_back(size);
|
|
1364
1444
|
}
|
|
1365
1445
|
const int available = std::min(total, flexWrapLimit());
|
|
1366
|
-
balancedEnds = balancedFlexLineEnds(sizes, available, mainGap_, rstyle(node_.
|
|
1446
|
+
balancedEnds = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.computedStyle()).flex_line_count : 1));
|
|
1367
1447
|
}
|
|
1368
1448
|
int lineCount = 0, start = 0, written = 0, main = 0, cross = 0, strut = 0;
|
|
1369
1449
|
auto finish = [&] {
|
|
@@ -1380,12 +1460,12 @@ private:
|
|
|
1380
1460
|
child.layout.x = child.layout.y = child.layout.width = child.layout.height = 0;
|
|
1381
1461
|
continue;
|
|
1382
1462
|
}
|
|
1383
|
-
const int childMain = isRow_ ? child.layout.width + child.
|
|
1384
|
-
: child.layout.height + child.
|
|
1385
|
-
const int childCross = isRow_ ? child.layout.height + child.
|
|
1386
|
-
: child.layout.width + child.
|
|
1463
|
+
const int childMain = isRow_ ? child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]
|
|
1464
|
+
: child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
1465
|
+
const int childCross = isRow_ ? child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2]
|
|
1466
|
+
: child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3];
|
|
1387
1467
|
const bool wrap = !balancedEnds.empty() ? written == balancedEnds[lineCount]
|
|
1388
|
-
: node_.
|
|
1468
|
+
: node_.computedStyle().flex_wrap && main + mainGap_ + childMain > flexWrapLimit();
|
|
1389
1469
|
if (written > start && wrap) finish();
|
|
1390
1470
|
main += childMain + (written > start ? mainGap_ : 0);
|
|
1391
1471
|
cross = std::max(cross, childCross);
|
|
@@ -1403,22 +1483,22 @@ private:
|
|
|
1403
1483
|
int total = 0;
|
|
1404
1484
|
for (int i = 0; i < childCount_; ++i) {
|
|
1405
1485
|
const Node &child = nodes[children_[i]];
|
|
1406
|
-
sizes[i] = isRow_ ? child.layout.width + child.
|
|
1407
|
-
: child.layout.height + child.
|
|
1486
|
+
sizes[i] = isRow_ ? child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]
|
|
1487
|
+
: child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
1408
1488
|
total += std::max(0, sizes[i]) + (i ? mainGap_ : 0);
|
|
1409
1489
|
}
|
|
1410
1490
|
// An unconstrained automatic block main size is content-based; the
|
|
1411
1491
|
// viewport height must not manufacture additional columns.
|
|
1412
1492
|
const int available = std::min(total, flexWrapLimit());
|
|
1413
|
-
const auto ends = balancedFlexLineEnds(sizes, available, mainGap_, rstyle(node_.
|
|
1493
|
+
const auto ends = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.computedStyle()).flex_line_count : 1));
|
|
1414
1494
|
int start = 0, count = 0;
|
|
1415
1495
|
for (const int end : ends) {
|
|
1416
1496
|
int main = 0, cross = 0;
|
|
1417
1497
|
for (int i = start; i < end; ++i) {
|
|
1418
1498
|
const Node &child = nodes[children_[i]];
|
|
1419
1499
|
main += sizes[i] + (i > start ? mainGap_ : 0);
|
|
1420
|
-
cross = std::max(cross, isRow_ ? child.layout.height + child.
|
|
1421
|
-
: child.layout.width + child.
|
|
1500
|
+
cross = std::max(cross, isRow_ ? child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2]
|
|
1501
|
+
: child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
1422
1502
|
}
|
|
1423
1503
|
appendLine(count, start, end - start, main, cross);
|
|
1424
1504
|
start = end;
|
|
@@ -1431,13 +1511,13 @@ private:
|
|
|
1431
1511
|
if (isRow_ ? hasExplicitWidth(node_) : hasExplicitHeight(node_)) return mainAvail_;
|
|
1432
1512
|
// A normal block's automatic inline size fills its containing block.
|
|
1433
1513
|
// Intrinsic measurements and automatic block sizes remain indefinite.
|
|
1434
|
-
if (isRow_ && !intrinsicWidthConstraint(node_) && !node_.
|
|
1435
|
-
!isIntrinsicSizeExpression(node_.
|
|
1436
|
-
(node_.parent < 0 || Tree::instance().nodes()[node_.parent].
|
|
1514
|
+
if (isRow_ && !intrinsicWidthConstraint(node_) && !node_.computedStyle().float_side &&
|
|
1515
|
+
!isIntrinsicSizeExpression(node_.computedStyle().width_expression) &&
|
|
1516
|
+
(node_.parent < 0 || Tree::instance().nodes()[node_.parent].computedStyle().display != kDisplayFlex)) return mainAvail_;
|
|
1437
1517
|
if (assignedSize_ && node_.parent >= 0) {
|
|
1438
1518
|
const Node &parent = Tree::instance().nodes()[node_.parent];
|
|
1439
|
-
if (parent.
|
|
1440
|
-
const bool parentRow = flexRowDirection(parent.
|
|
1519
|
+
if (parent.computedStyle().display == kDisplayFlex) {
|
|
1520
|
+
const bool parentRow = flexRowDirection(parent.computedStyle()) != (writingMode(parent) != 0);
|
|
1441
1521
|
if (isRow_ != parentRow ? definiteFlexCrossSize(parent, node_, parentRow)
|
|
1442
1522
|
: (isRow_ ? hasExplicitWidth(parent) : hasExplicitHeight(parent))) return mainAvail_;
|
|
1443
1523
|
}
|
|
@@ -1451,7 +1531,7 @@ private:
|
|
|
1451
1531
|
// Authored bases were measured on the physical main axis above. Preserve
|
|
1452
1532
|
// that result, including content sizing for an indefinite percentage.
|
|
1453
1533
|
if (hasFlexBasis(childNode)) return;
|
|
1454
|
-
if (childNode.
|
|
1534
|
+
if (childNode.computedStyle().flex <= 0) return;
|
|
1455
1535
|
if (isRow_) {
|
|
1456
1536
|
if (hasExplicitWidth(childNode)) return;
|
|
1457
1537
|
if (childNode.layout.width == 0) return;
|
|
@@ -1471,15 +1551,15 @@ private:
|
|
|
1471
1551
|
|
|
1472
1552
|
int baselineCrossSize(int start, int count, int crossSize) const
|
|
1473
1553
|
{
|
|
1474
|
-
if (isRow_ && node_.
|
|
1554
|
+
if (isRow_ && node_.computedStyle().display == kDisplayFlex) {
|
|
1475
1555
|
for (int alignment : {5, kAlignLastBaseline}) {
|
|
1476
1556
|
int ascent = 0, descent = 0;
|
|
1477
1557
|
for (int i = start; i < start + count; ++i) {
|
|
1478
1558
|
const Node &child = Tree::instance().nodes()[children_[i]];
|
|
1479
|
-
if (crossAlignFor(child) != alignment || (child.
|
|
1559
|
+
if (crossAlignFor(child) != alignment || (child.computedStyle().margin_auto & 5)) continue;
|
|
1480
1560
|
const int baseline = childBaseline(child, alignment == kAlignLastBaseline);
|
|
1481
|
-
ascent = std::max(ascent, child.
|
|
1482
|
-
descent = std::max(descent, child.
|
|
1561
|
+
ascent = std::max(ascent, child.computedStyle().margin[0] + baseline);
|
|
1562
|
+
descent = std::max(descent, child.computedStyle().margin[2] + child.layout.height - baseline);
|
|
1483
1563
|
}
|
|
1484
1564
|
crossSize = std::max(crossSize, ascent + descent);
|
|
1485
1565
|
}
|
|
@@ -1501,10 +1581,10 @@ private:
|
|
|
1501
1581
|
|
|
1502
1582
|
int totalFlexGrowForLine(const FlexLine &line, Node *nodes) const
|
|
1503
1583
|
{
|
|
1504
|
-
if (node_.
|
|
1584
|
+
if (node_.computedStyle().display != kDisplayFlex) return 0;
|
|
1505
1585
|
int totalFlex = 0;
|
|
1506
1586
|
for (int i = 0; i < line.count; i++) {
|
|
1507
|
-
totalFlex += nodes[children_[line.start + i]].
|
|
1587
|
+
totalFlex += nodes[children_[line.start + i]].computedStyle().flex;
|
|
1508
1588
|
}
|
|
1509
1589
|
return totalFlex;
|
|
1510
1590
|
}
|
|
@@ -1522,8 +1602,8 @@ private:
|
|
|
1522
1602
|
// deficit redistributes to shrinkable siblings or becomes overflow.
|
|
1523
1603
|
bool childMainSizeIsShrinkable(const Node &childNode) const
|
|
1524
1604
|
{
|
|
1525
|
-
if (node_.
|
|
1526
|
-
if (childNode.
|
|
1605
|
+
if (node_.computedStyle().display != kDisplayFlex) return false;
|
|
1606
|
+
if (childNode.computedStyle().flex_shrink <= 0) return false;
|
|
1527
1607
|
if (!isRow_ && childNode.type == NodeType::Text) return false;
|
|
1528
1608
|
return true;
|
|
1529
1609
|
}
|
|
@@ -1536,7 +1616,7 @@ private:
|
|
|
1536
1616
|
if (!childMainSizeIsShrinkable(childNode)) continue;
|
|
1537
1617
|
const int basis = childMainSize(childNode);
|
|
1538
1618
|
if (basis <= 0) continue;
|
|
1539
|
-
totalShrink += childNode.
|
|
1619
|
+
totalShrink += childNode.computedStyle().flex_shrink * basis;
|
|
1540
1620
|
}
|
|
1541
1621
|
return totalShrink;
|
|
1542
1622
|
}
|
|
@@ -1550,9 +1630,9 @@ private:
|
|
|
1550
1630
|
for (int i = 0; i < line.count; i++) {
|
|
1551
1631
|
const int child = children_[line.start + i];
|
|
1552
1632
|
Node &childNode = nodes[child];
|
|
1553
|
-
if (childNode.
|
|
1633
|
+
if (childNode.computedStyle().flex <= 0) continue;
|
|
1554
1634
|
lastGrowChild = child;
|
|
1555
|
-
const int change = (delta * childNode.
|
|
1635
|
+
const int change = (delta * childNode.computedStyle().flex) / totalGrow;
|
|
1556
1636
|
applied += applyFlexMainSizeDelta(child, childNode, change);
|
|
1557
1637
|
}
|
|
1558
1638
|
|
|
@@ -1577,7 +1657,7 @@ private:
|
|
|
1577
1657
|
const int basis = childMainSize(childNode);
|
|
1578
1658
|
if (basis <= 0) continue;
|
|
1579
1659
|
lastShrinkChild = child;
|
|
1580
|
-
const int change = (magnitude * childNode.
|
|
1660
|
+
const int change = (magnitude * childNode.computedStyle().flex_shrink * basis) / totalShrink;
|
|
1581
1661
|
applied += applyFlexMainSizeDelta(child, childNode, -change);
|
|
1582
1662
|
}
|
|
1583
1663
|
|
|
@@ -1601,33 +1681,33 @@ private:
|
|
|
1601
1681
|
// scroll/hidden box really does have a zero automatic minimum.
|
|
1602
1682
|
int automaticMinimumMainSize(const Node &childNode) const
|
|
1603
1683
|
{
|
|
1604
|
-
const int explicitMin = isRow_ ? childNode.
|
|
1684
|
+
const int explicitMin = isRow_ ? childNode.computedStyle().min_width : childNode.computedStyle().min_height;
|
|
1605
1685
|
if (explicitMin != kUnset) return 0;
|
|
1606
|
-
if (isScrollableOverflow(isRow_ ? overflowX(childNode.
|
|
1686
|
+
if (isScrollableOverflow(isRow_ ? overflowX(childNode.computedStyle()) : overflowY(childNode.computedStyle()))) return 0;
|
|
1607
1687
|
const Node *nodes = Tree::instance().nodes();
|
|
1608
1688
|
int extent = 0;
|
|
1609
1689
|
for (int c = childNode.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1610
1690
|
const Node &grand = nodes[c];
|
|
1611
|
-
if (isDisplayNone(grand.
|
|
1691
|
+
if (isDisplayNone(grand.computedStyle()) || isOutOfFlowPosition(grand.computedStyle().position)) continue;
|
|
1612
1692
|
// layout.{x,y} are still parent-relative here: resolveAbsoluteCoords runs
|
|
1613
1693
|
// after the whole layout pass.
|
|
1614
1694
|
const int end = isRow_
|
|
1615
|
-
? grand.layout.x + grand.layout.width + grand.
|
|
1616
|
-
: grand.layout.y + grand.layout.height + grand.
|
|
1695
|
+
? grand.layout.x + grand.layout.width + grand.computedStyle().margin[1]
|
|
1696
|
+
: grand.layout.y + grand.layout.height + grand.computedStyle().margin[2];
|
|
1617
1697
|
if (end > extent) extent = end;
|
|
1618
1698
|
}
|
|
1619
|
-
if (extent > 0) extent += isRow_ ? boxInset(childNode.
|
|
1699
|
+
if (extent > 0) extent += isRow_ ? boxInset(childNode.computedStyle(), 1) : boxInset(childNode.computedStyle(), 2);
|
|
1620
1700
|
if (preferredRatio(childNode) > 0 &&
|
|
1621
1701
|
((isRow_ ? hasExplicitHeight(childNode) : hasExplicitWidth(childNode)) || definiteFlexCrossSize(node_, childNode, isRow_))) {
|
|
1622
1702
|
const int transferred = ratioTransferredSize(childNode, isRow_ ? childNode.layout.height : childNode.layout.width, isRow_);
|
|
1623
1703
|
extent = childNode.type == NodeType::Image ? std::min(extent, transferred) : std::max(extent, transferred);
|
|
1624
1704
|
}
|
|
1625
1705
|
if (extent <= 0) return 0;
|
|
1626
|
-
const int max = isRow_ ? childNode.
|
|
1627
|
-
if (max != kUnset) extent = std::min(extent, contentSizeToBorderSize(childNode.
|
|
1706
|
+
const int max = isRow_ ? childNode.computedStyle().max_width : childNode.computedStyle().max_height;
|
|
1707
|
+
if (max != kUnset) extent = std::min(extent, contentSizeToBorderSize(childNode.computedStyle(), max, isRow_));
|
|
1628
1708
|
if (isRow_ ? hasExplicitWidth(childNode) : hasExplicitHeight(childNode)) {
|
|
1629
1709
|
const int specified = isRow_ ? resolvedStyleWidth(childNode, mainAvail_) : resolvedStyleHeight(childNode, mainAvail_);
|
|
1630
|
-
extent = std::min(extent, contentSizeToBorderSize(childNode.
|
|
1710
|
+
extent = std::min(extent, contentSizeToBorderSize(childNode.computedStyle(), specified, isRow_));
|
|
1631
1711
|
}
|
|
1632
1712
|
return extent;
|
|
1633
1713
|
}
|
|
@@ -1664,7 +1744,7 @@ private:
|
|
|
1664
1744
|
|
|
1665
1745
|
void applyJustifyContent(int remaining, int *mainOffset) const
|
|
1666
1746
|
{
|
|
1667
|
-
switch (usedAlignment(node_.
|
|
1747
|
+
switch (usedAlignment(node_.computedStyle().justify_content, remaining, node_.computedStyle().flex_direction_explicit && node_.computedStyle().flex_direction >= 2)) {
|
|
1668
1748
|
case 0:
|
|
1669
1749
|
break;
|
|
1670
1750
|
case 1:
|
|
@@ -1678,20 +1758,25 @@ private:
|
|
|
1678
1758
|
|
|
1679
1759
|
void positionLineChildren(const FlexLine &line, Node *nodes, int mainOffset, int crossOffset, int autoSpace = 0, int autoCount = 0, int distributedFree = 0)
|
|
1680
1760
|
{
|
|
1681
|
-
|
|
1682
|
-
|
|
1761
|
+
#if GEA_CSS_FLEX_WRAP
|
|
1762
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1763
|
+
#else
|
|
1764
|
+
constexpr bool wrapReversed = false;
|
|
1765
|
+
#endif
|
|
1766
|
+
const bool flex = node_.computedStyle().display == kDisplayFlex;
|
|
1767
|
+
const bool logicalRow = flexRowDirection(node_.computedStyle());
|
|
1683
1768
|
const int mode = writingMode(node_);
|
|
1684
1769
|
const bool blockReversed = mode == 2 || mode == 3;
|
|
1685
1770
|
const bool inlineReversed = rightToLeft(node_) != (mode == 4);
|
|
1686
|
-
const bool reverseMain = flex && ((node_.
|
|
1687
|
-
const bool reverseCross = flex && ((
|
|
1771
|
+
const bool reverseMain = flex && ((node_.computedStyle().flex_direction_explicit && node_.computedStyle().flex_direction >= 2) != (logicalRow ? inlineReversed : blockReversed));
|
|
1772
|
+
const bool reverseCross = flex && ((wrapReversed) != (logicalRow ? blockReversed : inlineReversed));
|
|
1688
1773
|
const int mainBefore = isRow_ ? (reverseMain ? 1 : 3) : (reverseMain ? 2 : 0);
|
|
1689
1774
|
const int mainAfter = (mainBefore + 2) % 4;
|
|
1690
1775
|
const int crossBefore = isRow_ ? (reverseCross ? 2 : 0) : (reverseCross ? 1 : 3);
|
|
1691
1776
|
const int crossAfter = (crossBefore + 2) % 4;
|
|
1692
1777
|
int autoUsed = 0;
|
|
1693
1778
|
auto autoMargin = [&](const Node &child, int side) {
|
|
1694
|
-
if (!(child.
|
|
1779
|
+
if (!(child.computedStyle().margin_auto & (1 << side)) || !autoCount) return 0;
|
|
1695
1780
|
const int before = autoSpace * autoUsed / autoCount;
|
|
1696
1781
|
return autoSpace * ++autoUsed / autoCount - before;
|
|
1697
1782
|
};
|
|
@@ -1704,14 +1789,14 @@ private:
|
|
|
1704
1789
|
if (isRow_) {
|
|
1705
1790
|
for (int i = 0; i < line.count; i++) {
|
|
1706
1791
|
Node &probe = nodes[children_[line.start + i]];
|
|
1707
|
-
if (probe.
|
|
1792
|
+
if (probe.computedStyle().margin_auto & 5) continue;
|
|
1708
1793
|
if (crossAlignFor(probe) == kAlignLastBaseline) {
|
|
1709
1794
|
const int baseline = childBaseline(probe, true);
|
|
1710
|
-
lineMaxLastDescent = std::max(lineMaxLastDescent, probe.
|
|
1711
|
-
lineMaxLastAscent = std::max(lineMaxLastAscent, probe.
|
|
1795
|
+
lineMaxLastDescent = std::max(lineMaxLastDescent, probe.computedStyle().margin[2] + probe.layout.height - baseline);
|
|
1796
|
+
lineMaxLastAscent = std::max(lineMaxLastAscent, probe.computedStyle().margin[0] + baseline);
|
|
1712
1797
|
}
|
|
1713
1798
|
if (crossAlignFor(probe) != 5) continue;
|
|
1714
|
-
const int baseline = probe.
|
|
1799
|
+
const int baseline = probe.computedStyle().margin[0] + childBaseline(probe);
|
|
1715
1800
|
if (baseline > lineMaxBaseline) lineMaxBaseline = baseline;
|
|
1716
1801
|
}
|
|
1717
1802
|
}
|
|
@@ -1720,17 +1805,17 @@ private:
|
|
|
1720
1805
|
const int child = children_[line.start + i];
|
|
1721
1806
|
Node &childNode = nodes[child];
|
|
1722
1807
|
|
|
1723
|
-
const int mainMarginBefore = childNode.
|
|
1724
|
-
const int mainMarginAfter = childNode.
|
|
1725
|
-
const int crossMarginBefore = childNode.
|
|
1726
|
-
const int crossMarginAfter = childNode.
|
|
1808
|
+
const int mainMarginBefore = childNode.computedStyle().margin[mainBefore] + autoMargin(childNode, mainBefore);
|
|
1809
|
+
const int mainMarginAfter = childNode.computedStyle().margin[mainAfter] + autoMargin(childNode, mainAfter);
|
|
1810
|
+
const int crossMarginBefore = childNode.computedStyle().margin[crossBefore];
|
|
1811
|
+
const int crossMarginAfter = childNode.computedStyle().margin[crossAfter];
|
|
1727
1812
|
const int crossSize = isRow_ ? childNode.layout.height : childNode.layout.width;
|
|
1728
1813
|
const int crossTotal = crossSize + crossMarginBefore + crossMarginAfter;
|
|
1729
1814
|
|
|
1730
1815
|
mainOffset += mainMarginBefore;
|
|
1731
1816
|
int crossPosition = crossOffset + crossMarginBefore;
|
|
1732
|
-
const bool crossAutoBefore = childNode.
|
|
1733
|
-
const bool crossAutoAfter = childNode.
|
|
1817
|
+
const bool crossAutoBefore = childNode.computedStyle().margin_auto & (1 << crossBefore);
|
|
1818
|
+
const bool crossAutoAfter = childNode.computedStyle().margin_auto & (1 << crossAfter);
|
|
1734
1819
|
if (crossAutoBefore || crossAutoAfter) {
|
|
1735
1820
|
const int free = std::max(0, line.crossSize - crossTotal);
|
|
1736
1821
|
if (crossAutoBefore) crossPosition += crossAutoAfter ? free / 2 : free;
|
|
@@ -1744,17 +1829,17 @@ private:
|
|
|
1744
1829
|
}
|
|
1745
1830
|
|
|
1746
1831
|
if (isRow_) {
|
|
1747
|
-
childNode.layout.x = mainOffset + distributedAlignmentOffset(node_.
|
|
1832
|
+
childNode.layout.x = mainOffset + distributedAlignmentOffset(node_.computedStyle().justify_content, distributedFree, i, line.count);
|
|
1748
1833
|
childNode.layout.y = crossPosition;
|
|
1749
1834
|
} else {
|
|
1750
1835
|
childNode.layout.x = crossPosition;
|
|
1751
|
-
childNode.layout.y = mainOffset + distributedAlignmentOffset(node_.
|
|
1836
|
+
childNode.layout.y = mainOffset + distributedAlignmentOffset(node_.computedStyle().justify_content, distributedFree, i, line.count);
|
|
1752
1837
|
}
|
|
1753
1838
|
|
|
1754
1839
|
const bool reverseX = isRow_ ? reverseMain : reverseCross;
|
|
1755
1840
|
const bool reverseY = isRow_ ? reverseCross : reverseMain;
|
|
1756
|
-
if (reverseX) childNode.layout.x = node_.layout.width - childNode.layout.x - childNode.layout.width + boxInset(node_.
|
|
1757
|
-
if (reverseY) childNode.layout.y = node_.layout.height - childNode.layout.y - childNode.layout.height + boxInset(node_.
|
|
1841
|
+
if (reverseX) childNode.layout.x = node_.layout.width - childNode.layout.x - childNode.layout.width + boxInset(node_.computedStyle(), 3) - boxInset(node_.computedStyle(), 1);
|
|
1842
|
+
if (reverseY) childNode.layout.y = node_.layout.height - childNode.layout.y - childNode.layout.height + boxInset(node_.computedStyle(), 0) - boxInset(node_.computedStyle(), 2);
|
|
1758
1843
|
|
|
1759
1844
|
const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
|
|
1760
1845
|
mainOffset += mainSize + mainMarginAfter + mainGap_;
|
|
@@ -1770,26 +1855,31 @@ private:
|
|
|
1770
1855
|
// flex container keeps reading `align-items`.
|
|
1771
1856
|
int crossAlignFor(const Node &childNode) const
|
|
1772
1857
|
{
|
|
1773
|
-
if (childNode.
|
|
1774
|
-
return inlineRow_ ? 5 : node_.
|
|
1858
|
+
if (childNode.computedStyle().align_self >= 0) return childNode.computedStyle().align_self;
|
|
1859
|
+
return inlineRow_ ? 5 : node_.computedStyle().align_items;
|
|
1775
1860
|
}
|
|
1776
1861
|
|
|
1777
1862
|
void positionCrossAxisChild(int child, Node &childNode, int lineCrossSize, int crossMarginBefore, int crossMarginAfter, int crossTotal, int *crossPosition, int lineMaxBaseline, int lineLastBaseline)
|
|
1778
1863
|
{
|
|
1864
|
+
#if GEA_CSS_FLEX_WRAP
|
|
1865
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1866
|
+
#else
|
|
1867
|
+
constexpr bool wrapReversed = false;
|
|
1868
|
+
#endif
|
|
1779
1869
|
const int alignment = crossAlignFor(childNode);
|
|
1780
1870
|
int align = physicalSelfAlignment(node_, childNode, alignment, lineCrossSize - crossTotal, !isRow_);
|
|
1781
1871
|
if (align >= 0) {
|
|
1782
|
-
const bool reversed = gridAxisReversed(node_, !isRow_) != (
|
|
1872
|
+
const bool reversed = gridAxisReversed(node_, !isRow_) != (wrapReversed);
|
|
1783
1873
|
if (reversed) align = align == 2 ? 6 : 2;
|
|
1784
|
-
} else align = usedAlignment(alignment, lineCrossSize - crossTotal,
|
|
1874
|
+
} else align = usedAlignment(alignment, lineCrossSize - crossTotal, wrapReversed);
|
|
1785
1875
|
switch (align) {
|
|
1786
1876
|
case 0:
|
|
1787
1877
|
if (isRow_) {
|
|
1788
|
-
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
1878
|
+
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression)) {
|
|
1789
1879
|
childNode.layout.height = lineCrossSize - crossMarginBefore - crossMarginAfter;
|
|
1790
1880
|
engine_.repositionChildren(child);
|
|
1791
1881
|
}
|
|
1792
|
-
} else if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
1882
|
+
} else if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression)) {
|
|
1793
1883
|
childNode.layout.width = lineCrossSize - crossMarginBefore - crossMarginAfter;
|
|
1794
1884
|
engine_.repositionChildren(child);
|
|
1795
1885
|
}
|
|
@@ -1825,7 +1915,7 @@ private:
|
|
|
1825
1915
|
// inline boxes use margin edges.
|
|
1826
1916
|
int childBaseline(const Node &childNode, bool last = false) const
|
|
1827
1917
|
{
|
|
1828
|
-
if ((childNode.type == NodeType::Text || isLineBreak(childNode)) && childNode.
|
|
1918
|
+
if ((childNode.type == NodeType::Text || isLineBreak(childNode)) && childNode.computedStyle().font_id >= 0)
|
|
1829
1919
|
return TextRenderer::baselineOffset(childNode, last);
|
|
1830
1920
|
// An inline wrapper (a <span> around text) carries no text of its own, so
|
|
1831
1921
|
// CSS takes the baseline of its FIRST in-flow line box. Its children were
|
|
@@ -1838,11 +1928,11 @@ private:
|
|
|
1838
1928
|
const Node *nodes = Tree::instance().nodes();
|
|
1839
1929
|
for (int c = last ? childNode.last_child : childNode.first_child; c >= 0; c = last ? nodes[c].prev_sibling : nodes[c].next_sibling) {
|
|
1840
1930
|
const Node &inner = nodes[c];
|
|
1841
|
-
if (isDisplayNone(inner.
|
|
1931
|
+
if (isDisplayNone(inner.computedStyle()) || isOutOfFlowPosition(inner.computedStyle().position)) continue;
|
|
1842
1932
|
return inner.layout.y + childBaseline(inner, last);
|
|
1843
1933
|
}
|
|
1844
1934
|
}
|
|
1845
|
-
return childNode.layout.height + (inlineRow_ ? childNode.
|
|
1935
|
+
return childNode.layout.height + (inlineRow_ ? childNode.computedStyle().margin[2] : 0);
|
|
1846
1936
|
}
|
|
1847
1937
|
|
|
1848
1938
|
int totalCrossSize(int lineCount) const
|
|
@@ -1900,17 +1990,17 @@ static bool isInlineLevelTag(const char *tag)
|
|
|
1900
1990
|
bool splitInlineWrapper(const Node *nodes, int id)
|
|
1901
1991
|
{
|
|
1902
1992
|
const Node &n = nodes[id];
|
|
1903
|
-
if (n.type != NodeType::View || n.
|
|
1904
|
-
!isInlineLevelTag(tagFromId(n.tag_id)) || n.
|
|
1905
|
-
!FlexLayoutPass::paintsNoBox(n) || boxInsets(n.
|
|
1906
|
-
n.
|
|
1993
|
+
if (n.type != NodeType::View || n.computedStyle().display_explicit || n.computedStyle().display != kDisplayBlock ||
|
|
1994
|
+
!isInlineLevelTag(tagFromId(n.tag_id)) || n.computedStyle().float_side || isOutOfFlowPosition(n.computedStyle().position) ||
|
|
1995
|
+
!FlexLayoutPass::paintsNoBox(n) || boxInsets(n.computedStyle(), true) || boxInsets(n.computedStyle(), false) ||
|
|
1996
|
+
n.computedStyle().margin[1] || n.computedStyle().margin[3] || n.computedStyle().opacity != 255 || overflowEstablishesContext(n.computedStyle())) return false;
|
|
1907
1997
|
bool containsBlock = false;
|
|
1908
1998
|
for (int c = n.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1909
1999
|
const Node &child = nodes[c];
|
|
1910
|
-
if (isDisplayNone(child.
|
|
1911
|
-
if (isOutOfFlowPosition(child.
|
|
1912
|
-
if (child.
|
|
1913
|
-
if (child.type == NodeType::View && (child.
|
|
2000
|
+
if (isDisplayNone(child.computedStyle())) continue;
|
|
2001
|
+
if (isOutOfFlowPosition(child.computedStyle().position)) return false;
|
|
2002
|
+
if (child.computedStyle().float_side) continue;
|
|
2003
|
+
if (child.type == NodeType::View && (child.computedStyle().display_explicit || !isInlineLevelTag(tagFromId(child.tag_id)))) containsBlock = true;
|
|
1914
2004
|
if (splitInlineWrapper(nodes, c)) containsBlock = true;
|
|
1915
2005
|
}
|
|
1916
2006
|
return containsBlock;
|
|
@@ -1921,8 +2011,8 @@ int formattingEdgeNode(const Node *nodes, int id, bool last)
|
|
|
1921
2011
|
if (!splitInlineWrapper(nodes, id)) return id;
|
|
1922
2012
|
for (int c = last ? nodes[id].last_child : nodes[id].first_child; c >= 0; c = last ? nodes[c].prev_sibling : nodes[c].next_sibling) {
|
|
1923
2013
|
const Node &child = nodes[c];
|
|
1924
|
-
if (isDisplayNone(child.
|
|
1925
|
-
if (isAnonymousTextNode(child) && (child.
|
|
2014
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position) || child.computedStyle().float_side) continue;
|
|
2015
|
+
if (isAnonymousTextNode(child) && (child.computedStyle().white_space == 0 || child.computedStyle().white_space == 1) &&
|
|
1926
2016
|
child.text.find_first_not_of(" \t\r\n\f") == std::string::npos) continue;
|
|
1927
2017
|
return formattingEdgeNode(nodes, c, last);
|
|
1928
2018
|
}
|
|
@@ -1932,7 +2022,7 @@ int formattingEdgeNode(const Node *nodes, int id, bool last)
|
|
|
1932
2022
|
template<class Visit>
|
|
1933
2023
|
void visitFormattingChildren(const Node *nodes, int parent, const Visit &visit, bool reverse = false)
|
|
1934
2024
|
{
|
|
1935
|
-
const bool project = nodes[parent].
|
|
2025
|
+
const bool project = nodes[parent].computedStyle().display == kDisplayBlock && !nodes[parent].computedStyle().flex_direction_explicit;
|
|
1936
2026
|
for (int c = reverse ? nodes[parent].last_child : nodes[parent].first_child; c >= 0; c = reverse ? nodes[c].prev_sibling : nodes[c].next_sibling) {
|
|
1937
2027
|
if (project && splitInlineWrapper(nodes, c)) visitFormattingChildren(nodes, c, visit, reverse);
|
|
1938
2028
|
else visit(c);
|
|
@@ -1949,22 +2039,24 @@ public:
|
|
|
1949
2039
|
void run()
|
|
1950
2040
|
{
|
|
1951
2041
|
invalidateInlineChildMetadata();
|
|
2042
|
+
#if GEA_CSS_FIRST_LINE
|
|
1952
2043
|
if (NodeRareData *rare = rareDataFor(id_)) rare->firstLineBackground.lineValid = false;
|
|
1953
|
-
|
|
2044
|
+
#endif
|
|
2045
|
+
if (isDisplayNone(node_.computedStyle())) return;
|
|
1954
2046
|
prepareOwnSize();
|
|
1955
2047
|
|
|
1956
2048
|
if (isLineBreak(node_) && LayoutEngine::isInlineLevelNode(node_) &&
|
|
1957
|
-
(node_.parent < 0 || (nodes_[node_.parent].
|
|
2049
|
+
(node_.parent < 0 || (nodes_[node_.parent].computedStyle().display != kDisplayFlex && !isDisplayGrid(nodes_[node_.parent].computedStyle())))) {
|
|
1958
2050
|
node_.layout.width = 0;
|
|
1959
|
-
node_.layout.height = clampInt16(TextRenderer::measureHeight(" ", node_.
|
|
1960
|
-
node_.
|
|
2051
|
+
node_.layout.height = clampInt16(TextRenderer::measureHeight(" ", node_.computedStyle().font_id,
|
|
2052
|
+
node_.computedStyle().font_size, 0, node_.computedStyle().line_height));
|
|
1961
2053
|
return;
|
|
1962
2054
|
}
|
|
1963
2055
|
|
|
1964
2056
|
if (node_.type == NodeType::Text) {
|
|
1965
2057
|
const std::int64_t __tmT0 = refreshPerfNowUs();
|
|
1966
2058
|
TextRenderer::layout(id_, availWidth_);
|
|
1967
|
-
refreshPerfStatsMutable().treeLayoutTextUs += refreshPerfNowUs() - __tmT0;
|
|
2059
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutTextUs += refreshPerfNowUs() - __tmT0);
|
|
1968
2060
|
return;
|
|
1969
2061
|
}
|
|
1970
2062
|
|
|
@@ -1988,7 +2080,7 @@ public:
|
|
|
1988
2080
|
if (!scratch.valid()) return;
|
|
1989
2081
|
|
|
1990
2082
|
const int childCount = collectFormattingChildren(scratch.children(), kMaxChildren);
|
|
1991
|
-
if (childCount == 0 && !isDisplayGrid(node_.
|
|
2083
|
+
if (childCount == 0 && !isDisplayGrid(node_.computedStyle())) {
|
|
1992
2084
|
autosizeEmptyNode();
|
|
1993
2085
|
positionAbsoluteChildren();
|
|
1994
2086
|
applyRelativeOffsets();
|
|
@@ -1996,7 +2088,7 @@ public:
|
|
|
1996
2088
|
return;
|
|
1997
2089
|
}
|
|
1998
2090
|
|
|
1999
|
-
if (isDisplayGrid(node_.
|
|
2091
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
2000
2092
|
layoutGridChildren(scratch.children(), childCount, padWidth, padHeight, true);
|
|
2001
2093
|
updateScrollContentSize();
|
|
2002
2094
|
positionAbsoluteChildren();
|
|
@@ -2041,7 +2133,9 @@ public:
|
|
|
2041
2133
|
{
|
|
2042
2134
|
if (node_.type == NodeType::Text || node_.type == NodeType::Image) return;
|
|
2043
2135
|
invalidateInlineChildMetadata();
|
|
2136
|
+
#if GEA_CSS_FIRST_LINE
|
|
2044
2137
|
if (NodeRareData *rare = rareDataFor(id_)) rare->firstLineBackground.lineValid = false;
|
|
2138
|
+
#endif
|
|
2045
2139
|
|
|
2046
2140
|
const int padWidth = paddedWidth();
|
|
2047
2141
|
const int padHeight = paddedHeight();
|
|
@@ -2053,12 +2147,12 @@ public:
|
|
|
2053
2147
|
if (!scratch.valid()) return;
|
|
2054
2148
|
|
|
2055
2149
|
const int childCount = collectFormattingChildren(scratch.children(), kMaxChildren);
|
|
2056
|
-
if (childCount == 0 && !isDisplayGrid(node_.
|
|
2150
|
+
if (childCount == 0 && !isDisplayGrid(node_.computedStyle())) {
|
|
2057
2151
|
positionAbsoluteChildren();
|
|
2058
2152
|
return;
|
|
2059
2153
|
}
|
|
2060
2154
|
|
|
2061
|
-
if (isDisplayGrid(node_.
|
|
2155
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
2062
2156
|
layoutGridChildren(scratch.children(), childCount, padWidth, padHeight, false);
|
|
2063
2157
|
positionAbsoluteChildren();
|
|
2064
2158
|
applyRelativeOffsets();
|
|
@@ -2096,10 +2190,10 @@ public:
|
|
|
2096
2190
|
// handled as well as introducing or resizing one.
|
|
2097
2191
|
const bool horizontal = writingMode(node_) != 0;
|
|
2098
2192
|
return !blockBox(node_) || establishesBlockContext(node_) ||
|
|
2099
|
-
(boxInset(node_.
|
|
2100
|
-
(boxInset(node_.
|
|
2193
|
+
(boxInset(node_.computedStyle(), blockMarginSide(false)) > 0 &&
|
|
2194
|
+
(boxInset(node_.computedStyle(), blockMarginSide(true)) > 0 ||
|
|
2101
2195
|
(horizontal ? hasExplicitWidth(node_) : hasExplicitHeight(node_)) ||
|
|
2102
|
-
(horizontal ? node_.
|
|
2196
|
+
(horizontal ? node_.computedStyle().min_width : node_.computedStyle().min_height) > 0));
|
|
2103
2197
|
}
|
|
2104
2198
|
|
|
2105
2199
|
private:
|
|
@@ -2109,25 +2203,29 @@ private:
|
|
|
2109
2203
|
NodeRareData *rare = rareDataFor(child);
|
|
2110
2204
|
if (!rare) continue;
|
|
2111
2205
|
rare->inlineStaticPosition.valid = false;
|
|
2206
|
+
#if GEA_CSS_FIRST_LINE
|
|
2112
2207
|
rare->firstLineFragment.valid = false;
|
|
2208
|
+
#endif
|
|
2113
2209
|
}
|
|
2114
2210
|
}
|
|
2115
2211
|
|
|
2116
2212
|
bool splitInlineChildren_ = false;
|
|
2117
2213
|
int collectFormattingChildren(int *children, int capacity)
|
|
2118
2214
|
{
|
|
2119
|
-
if (node_.
|
|
2215
|
+
if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit)
|
|
2120
2216
|
return engine_.collectChildren(id_, children, capacity, true);
|
|
2121
2217
|
int count = 0;
|
|
2122
2218
|
auto collect = [&](auto &&self, int parent) -> void {
|
|
2123
2219
|
for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
|
|
2124
2220
|
Node &child = nodes_[c];
|
|
2125
|
-
if (isDisplayNone(child.
|
|
2221
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position) || suppressAnonymousWhitespace(nodes_, parent, c)) continue;
|
|
2126
2222
|
if (splitInlineWrapper(nodes_, c)) {
|
|
2127
2223
|
splitInlineChildren_ = true;
|
|
2128
2224
|
child.layout.x = child.layout.y = child.layout.width = child.layout.height = 0;
|
|
2225
|
+
#if GEA_CSS_SCROLLING
|
|
2129
2226
|
child.layout.scroll_content_width = child.layout.scroll_content_height = 0;
|
|
2130
|
-
|
|
2227
|
+
#endif
|
|
2228
|
+
engine_.invalidateMemo(c);
|
|
2131
2229
|
self(self, c);
|
|
2132
2230
|
} else if (count < capacity) children[count++] = c;
|
|
2133
2231
|
}
|
|
@@ -2158,47 +2256,51 @@ private:
|
|
|
2158
2256
|
|
|
2159
2257
|
bool blockBox(const Node &n) const
|
|
2160
2258
|
{
|
|
2161
|
-
return n.type == NodeType::View && !isDisplayNone(n.
|
|
2162
|
-
(n.
|
|
2259
|
+
return n.type == NodeType::View && !isDisplayNone(n.computedStyle()) &&
|
|
2260
|
+
(n.computedStyle().display_explicit || !isInlineLevelTag(tagFromId(n.tag_id)));
|
|
2163
2261
|
}
|
|
2164
2262
|
|
|
2165
2263
|
bool flowChild(int parent, int child) const
|
|
2166
2264
|
{
|
|
2167
|
-
return !isDisplayNone(nodes_[child].
|
|
2168
|
-
!nodes_[child].
|
|
2265
|
+
return !isDisplayNone(nodes_[child].computedStyle()) && !isOutOfFlowPosition(nodes_[child].computedStyle().position) &&
|
|
2266
|
+
!nodes_[child].computedStyle().float_side && !suppressAnonymousWhitespace(nodes_, parent, child);
|
|
2169
2267
|
}
|
|
2170
2268
|
|
|
2171
2269
|
bool establishesBlockContext(const Node &n) const
|
|
2172
2270
|
{
|
|
2173
|
-
return n.parent < 0 || isOutOfFlowPosition(n.
|
|
2174
|
-
n.
|
|
2175
|
-
(n.parent >= 0 && (nodes_[n.parent].
|
|
2271
|
+
return n.parent < 0 || isOutOfFlowPosition(n.computedStyle().position) || n.computedStyle().float_side ||
|
|
2272
|
+
n.computedStyle().display != kDisplayBlock || overflowEstablishesContext(n.computedStyle()) ||
|
|
2273
|
+
(n.parent >= 0 && (nodes_[n.parent].computedStyle().display == kDisplayFlex || isDisplayGrid(nodes_[n.parent].computedStyle()) ||
|
|
2176
2274
|
writingMode(n) != writingMode(nodes_[n.parent])));
|
|
2177
2275
|
}
|
|
2178
2276
|
|
|
2179
2277
|
void encloseFloatDescendants()
|
|
2180
2278
|
{
|
|
2181
|
-
if (node_.
|
|
2182
|
-
int bottom = node_.layout.height - boxInset(node_.
|
|
2279
|
+
if (node_.computedStyle().display != kDisplayBlock || hasExplicitHeight(node_) || !establishesBlockContext(node_)) return;
|
|
2280
|
+
int bottom = node_.layout.height - boxInset(node_.computedStyle(), 2);
|
|
2281
|
+
// With floats absent, no descendant can extend this bound. Keep the
|
|
2282
|
+
// final height clamp without walking the same subtree at every ancestor.
|
|
2283
|
+
#if GEA_CSS_FLOATS
|
|
2183
2284
|
// CSS 2.2 10.6.7 includes floats through ordinary wrappers, but never
|
|
2184
2285
|
// crosses another formatting context. Child layout is still relative;
|
|
2185
2286
|
// offsets below the first level have already been applied by its parent.
|
|
2186
2287
|
auto visit = [&](auto &&self, int parent, int y) -> void {
|
|
2187
2288
|
for (int id = nodes_[parent].first_child; id >= 0; id = nodes_[id].next_sibling) {
|
|
2188
2289
|
const Node &child = nodes_[id];
|
|
2189
|
-
if (isDisplayNone(child.
|
|
2290
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
|
|
2190
2291
|
int top = y + child.layout.y;
|
|
2191
|
-
if (parent != id_ && child.
|
|
2292
|
+
if (parent != id_ && child.computedStyle().position == 2) {
|
|
2192
2293
|
LayoutNodePass owner(engine_, parent, 0, 0);
|
|
2193
|
-
if (hasPositionOffset(child
|
|
2194
|
-
else if (hasPositionOffset(child
|
|
2294
|
+
if (hasPositionOffset<0>(child)) top -= owner.resolvedRelativePositionOffset<0>(child);
|
|
2295
|
+
else if (hasPositionOffset<2>(child)) top += owner.resolvedRelativePositionOffset<2>(child);
|
|
2195
2296
|
}
|
|
2196
|
-
if (child.
|
|
2297
|
+
if (child.computedStyle().float_side) bottom = std::max(bottom, top + child.layout.height + child.computedStyle().margin[2]);
|
|
2197
2298
|
else if (!establishesBlockContext(child)) self(self, id, top);
|
|
2198
2299
|
}
|
|
2199
2300
|
};
|
|
2200
2301
|
visit(visit, id_, 0);
|
|
2201
|
-
|
|
2302
|
+
#endif
|
|
2303
|
+
node_.layout.height = clampBorderSize(engine_, node_, bottom + boxInset(node_.computedStyle(), 2), false);
|
|
2202
2304
|
}
|
|
2203
2305
|
|
|
2204
2306
|
int blockMarginSide(bool end) const
|
|
@@ -2212,7 +2314,7 @@ private:
|
|
|
2212
2314
|
const Node &n = nodes_[id];
|
|
2213
2315
|
const bool horizontal = writingMode(node_) != 0;
|
|
2214
2316
|
if (!blockBox(n) || establishesBlockContext(n) || (horizontal ? n.layout.width : n.layout.height) != 0 ||
|
|
2215
|
-
(horizontal ? n.
|
|
2317
|
+
(horizontal ? n.computedStyle().min_width : n.computedStyle().min_height) > 0 || boxInsets(n.computedStyle(), horizontal)) return false;
|
|
2216
2318
|
bool through = true;
|
|
2217
2319
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2218
2320
|
if (flowChild(nodes_[c].parent, c) && ((floatContext_ && floatContext_->hasClearance(c)) || !collapsesThrough(c))) through = false;
|
|
@@ -2224,10 +2326,10 @@ private:
|
|
|
2224
2326
|
{
|
|
2225
2327
|
const Node &n = nodes_[id];
|
|
2226
2328
|
const bool horizontal = writingMode(node_) != 0;
|
|
2227
|
-
if (!blockBox(n) || establishesBlockContext(n) || boxInset(n.
|
|
2329
|
+
if (!blockBox(n) || establishesBlockContext(n) || boxInset(n.computedStyle(), blockMarginSide(bottom))) return false;
|
|
2228
2330
|
if (bottom && ((horizontal ? hasExplicitWidth(n) : hasExplicitHeight(n)) ||
|
|
2229
|
-
isIntrinsicSizeExpression(horizontal ? n.
|
|
2230
|
-
(horizontal ? n.
|
|
2331
|
+
isIntrinsicSizeExpression(horizontal ? n.computedStyle().width_expression : n.computedStyle().height_expression) ||
|
|
2332
|
+
(horizontal ? n.computedStyle().min_width : n.computedStyle().min_height) > 0)) return false;
|
|
2231
2333
|
int edge = -1;
|
|
2232
2334
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2233
2335
|
if (!flowChild(nodes_[c].parent, c) || (edge >= 0 && !bottom)) return;
|
|
@@ -2241,10 +2343,10 @@ private:
|
|
|
2241
2343
|
{
|
|
2242
2344
|
const Node &n = nodes_[id];
|
|
2243
2345
|
CollapsedMargin margin;
|
|
2244
|
-
margin.add(n.
|
|
2346
|
+
margin.add(n.computedStyle().margin[blockMarginSide(bottom)]);
|
|
2245
2347
|
CollapsedMargin descendants;
|
|
2246
2348
|
if (!separateBottom && collapsesThrough(id)) {
|
|
2247
|
-
margin.add(n.
|
|
2349
|
+
margin.add(n.computedStyle().margin[blockMarginSide(!bottom)]);
|
|
2248
2350
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2249
2351
|
if (flowChild(nodes_[c].parent, c)) descendants.add(childEdgeMargin(id, c, false));
|
|
2250
2352
|
});
|
|
@@ -2267,8 +2369,8 @@ private:
|
|
|
2267
2369
|
bool trimmedBlockEdge(int owner, int id, bool bottom) const
|
|
2268
2370
|
{
|
|
2269
2371
|
const Node &container = nodes_[owner];
|
|
2270
|
-
const int trim = rstyle(container.
|
|
2271
|
-
if (!(trim & 3) || container.
|
|
2372
|
+
const int trim = (GEA_CSS_MARGIN_TRIM ? rstyle(container.computedStyle()).margin_trim : 0);
|
|
2373
|
+
if (!(trim & 3) || container.computedStyle().display != kDisplayBlock || container.computedStyle().flex_direction_explicit || !blockBox(nodes_[id])) return false;
|
|
2272
2374
|
for (bool end : {false, true}) {
|
|
2273
2375
|
if (!(trim & (end ? 2 : 1)) || (end != bottom && !collapsesThrough(id))) continue;
|
|
2274
2376
|
bool adjacent = true, found = false;
|
|
@@ -2291,52 +2393,52 @@ private:
|
|
|
2291
2393
|
|
|
2292
2394
|
bool layoutBlockChildren(int *children, int count, int contentWidth, int contentHeight, bool autosize)
|
|
2293
2395
|
{
|
|
2294
|
-
if (node_.
|
|
2396
|
+
if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit) return false;
|
|
2295
2397
|
const bool vertical = writingMode(node_) != 0;
|
|
2296
2398
|
for (int i = 0; i < count; ++i)
|
|
2297
|
-
if (!blockBox(nodes_[children[i]]) || nodes_[children[i]].
|
|
2399
|
+
if (!blockBox(nodes_[children[i]]) || nodes_[children[i]].computedStyle().float_side) return false;
|
|
2298
2400
|
if (vertical) {
|
|
2299
2401
|
const bool measureInline = autosize && !hasExplicitHeight(node_) && node_.parent >= 0;
|
|
2300
2402
|
int intrinsicHeight = 0;
|
|
2301
2403
|
for (int i = 0; i < count; ++i) {
|
|
2302
2404
|
engine_.layoutNode(children[i], contentWidth, contentHeight);
|
|
2303
2405
|
const Node &child = nodes_[children[i]];
|
|
2304
|
-
intrinsicHeight = std::max(intrinsicHeight, child.layout.height + child.
|
|
2406
|
+
intrinsicHeight = std::max(intrinsicHeight, child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2]);
|
|
2305
2407
|
}
|
|
2306
2408
|
if (measureInline) {
|
|
2307
|
-
node_.layout.height = clampLayoutSize(node_, intrinsicHeight + boxInsets(node_.
|
|
2409
|
+
node_.layout.height = clampLayoutSize(node_, intrinsicHeight + boxInsets(node_.computedStyle(), false), false);
|
|
2308
2410
|
contentHeight = paddedHeight();
|
|
2309
2411
|
}
|
|
2310
2412
|
for (int i = 0; i < count; ++i) {
|
|
2311
2413
|
const int id = children[i]; Node &child = nodes_[id];
|
|
2312
2414
|
if (measureInline) engine_.layoutNode(id, contentWidth, contentHeight);
|
|
2313
|
-
if (!hasExplicitHeight(child) && !isIntrinsicSizeExpression(child.
|
|
2415
|
+
if (!hasExplicitHeight(child) && !isIntrinsicSizeExpression(child.computedStyle().height_expression) && writingMode(child) != 0 &&
|
|
2314
2416
|
!(preferredRatio(child) > 0 && hasExplicitWidth(child))) {
|
|
2315
|
-
const int height = clampLayoutSize(child, std::max(0, contentHeight - child.
|
|
2417
|
+
const int height = clampLayoutSize(child, std::max(0, contentHeight - child.computedStyle().margin[0] - child.computedStyle().margin[2]), false);
|
|
2316
2418
|
if (child.layout.height != height) {
|
|
2317
2419
|
child.layout.height = clampInt16(height); engine_.repositionChildren(id);
|
|
2318
2420
|
}
|
|
2319
2421
|
}
|
|
2320
|
-
const int slack = contentHeight - child.layout.height - child.
|
|
2321
|
-
const bool autoTop = child.
|
|
2422
|
+
const int slack = contentHeight - child.layout.height - child.computedStyle().margin[0] - child.computedStyle().margin[2];
|
|
2423
|
+
const bool autoTop = child.computedStyle().margin_auto & 1, autoBottom = child.computedStyle().margin_auto & 4;
|
|
2322
2424
|
int offset = slack > 0 && autoTop ? (autoBottom ? slack / 2 : slack) : 0;
|
|
2323
2425
|
if (!autoTop && !autoBottom && gridAxisReversed(node_, false)) offset = slack;
|
|
2324
|
-
child.layout.y = boxInset(node_.
|
|
2426
|
+
child.layout.y = boxInset(node_.computedStyle(), 0) + child.computedStyle().margin[0] + offset;
|
|
2325
2427
|
}
|
|
2326
2428
|
} else {
|
|
2327
2429
|
// Measure content before assigning the normal-flow fill width. A flex
|
|
2328
2430
|
// item, float, or absolute box can use this intrinsic width; its parent
|
|
2329
2431
|
// assigns the final width and calls repositionChildren afterwards.
|
|
2330
|
-
const bool measureIntrinsic = autosize && (node_.parent >= 0 || node_.
|
|
2432
|
+
const bool measureIntrinsic = autosize && (node_.parent >= 0 || node_.computedStyle().float_side || intrinsicWidthConstraint(node_)) && !hasExplicitWidth(node_);
|
|
2331
2433
|
int intrinsicWidth = 0;
|
|
2332
2434
|
for (int i = 0; i < count; ++i) {
|
|
2333
2435
|
const int id = children[i];
|
|
2334
2436
|
engine_.layoutNode(id, contentWidth, contentHeight, measureIntrinsic);
|
|
2335
2437
|
const Node &child = nodes_[id];
|
|
2336
|
-
intrinsicWidth = std::max(intrinsicWidth, child.layout.width + child.
|
|
2438
|
+
intrinsicWidth = std::max(intrinsicWidth, child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
2337
2439
|
}
|
|
2338
2440
|
if (measureIntrinsic) {
|
|
2339
|
-
node_.layout.width = clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.
|
|
2441
|
+
node_.layout.width = clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.computedStyle(), true), true);
|
|
2340
2442
|
contentWidth = paddedWidth();
|
|
2341
2443
|
}
|
|
2342
2444
|
for (int i = 0; i < count; ++i) {
|
|
@@ -2345,19 +2447,19 @@ private:
|
|
|
2345
2447
|
if (measureIntrinsic) engine_.layoutNode(id, contentWidth, contentHeight);
|
|
2346
2448
|
// This horizontal formatting context fills the inline size of
|
|
2347
2449
|
// parallel children. An orthogonal child's width is its block size.
|
|
2348
|
-
if (!hasExplicitWidth(child) && !isIntrinsicSizeExpression(child.
|
|
2349
|
-
const int width = clampLayoutSize(child, std::max(0, contentWidth - child.
|
|
2450
|
+
if (!hasExplicitWidth(child) && !isIntrinsicSizeExpression(child.computedStyle().width_expression) && writingMode(child) == 0 && !(preferredRatio(child) > 0 && hasExplicitHeight(child))) {
|
|
2451
|
+
const int width = clampLayoutSize(child, std::max(0, contentWidth - child.computedStyle().margin[1] - child.computedStyle().margin[3]), true);
|
|
2350
2452
|
if (child.layout.width != width) {
|
|
2351
2453
|
child.layout.width = clampInt16(width);
|
|
2352
2454
|
engine_.repositionChildren(id);
|
|
2353
2455
|
}
|
|
2354
2456
|
}
|
|
2355
|
-
const int slack = contentWidth - child.layout.width - child.
|
|
2356
|
-
const bool autoLeft = child.
|
|
2357
|
-
const bool autoRight = child.
|
|
2457
|
+
const int slack = contentWidth - child.layout.width - child.computedStyle().margin[1] - child.computedStyle().margin[3];
|
|
2458
|
+
const bool autoLeft = child.computedStyle().margin_auto & (1 << 3);
|
|
2459
|
+
const bool autoRight = child.computedStyle().margin_auto & (1 << 1);
|
|
2358
2460
|
int offset = slack > 0 && autoLeft ? (autoRight ? slack / 2 : slack) : 0;
|
|
2359
2461
|
if (!autoLeft && !autoRight && rightToLeft(node_)) offset = slack;
|
|
2360
|
-
child.layout.x = boxInset(node_.
|
|
2462
|
+
child.layout.x = boxInset(node_.computedStyle(), 3) + child.computedStyle().margin[3] + offset;
|
|
2361
2463
|
}
|
|
2362
2464
|
}
|
|
2363
2465
|
const bool mergeTop = collapsesWithChildren(id_, false);
|
|
@@ -2375,52 +2477,58 @@ private:
|
|
|
2375
2477
|
// join the group. Its position does not advance normal flow.
|
|
2376
2478
|
auto before = pending;
|
|
2377
2479
|
before.add(childEdgeMargin(id_, id, false, true));
|
|
2378
|
-
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.
|
|
2480
|
+
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.computedStyle(), blockMarginSide(false)) + cursor + (first && mergeTop ? 0 : before.value());
|
|
2379
2481
|
pending.add(childEdgeMargin(id_, id, false));
|
|
2380
2482
|
continue;
|
|
2381
2483
|
}
|
|
2382
2484
|
pending.add(childEdgeMargin(id_, id, false));
|
|
2383
2485
|
cursor += first && mergeTop ? 0 : pending.value();
|
|
2384
|
-
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.
|
|
2486
|
+
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.computedStyle(), blockMarginSide(false)) + cursor;
|
|
2385
2487
|
cursor += vertical ? child.layout.width : child.layout.height;
|
|
2386
2488
|
pending = childEdgeMargin(id_, id, true);
|
|
2387
2489
|
first = false;
|
|
2388
2490
|
}
|
|
2389
2491
|
cursor += mergeBottom || (first && mergeTop) ? 0 : pending.value();
|
|
2390
2492
|
if (vertical) {
|
|
2391
|
-
if (autosize && !hasExplicitWidth(node_) && !(scrollsOverflowX(node_.
|
|
2392
|
-
node_.layout.width = clampLayoutSize(node_, std::max(0, cursor) + boxInsets(node_.
|
|
2493
|
+
if (autosize && !hasExplicitWidth(node_) && !(scrollsOverflowX(node_.computedStyle()) && node_.layout.width > 0))
|
|
2494
|
+
node_.layout.width = clampLayoutSize(node_, std::max(0, cursor) + boxInsets(node_.computedStyle(), true), true);
|
|
2393
2495
|
if (gridAxisReversed(node_, true)) for (int i = 0; i < count; ++i) {
|
|
2394
2496
|
Node &child = nodes_[children[i]];
|
|
2395
2497
|
child.layout.x = node_.layout.width - child.layout.x - child.layout.width;
|
|
2396
2498
|
}
|
|
2397
|
-
} else if (autosize && !hasExplicitHeight(node_) && !(scrollsOverflowY(node_.
|
|
2398
|
-
node_.layout.height = clampLayoutSize(node_, std::max(0, cursor) + boxInsets(node_.
|
|
2499
|
+
} else if (autosize && !hasExplicitHeight(node_) && !(scrollsOverflowY(node_.computedStyle()) && node_.layout.height > 0)) {
|
|
2500
|
+
node_.layout.height = clampLayoutSize(node_, std::max(0, cursor) + boxInsets(node_.computedStyle(), false), false);
|
|
2399
2501
|
}
|
|
2400
2502
|
return true;
|
|
2401
2503
|
}
|
|
2402
2504
|
|
|
2403
2505
|
bool layoutFloatChildren(int *children, int count, int contentWidth, int contentHeight, bool autosize)
|
|
2404
2506
|
{
|
|
2405
|
-
if (node_.
|
|
2507
|
+
if (node_.computedStyle().display != kDisplayBlock) return false;
|
|
2508
|
+
#if GEA_CSS_FLOATS
|
|
2406
2509
|
auto containsFloat = [&](auto &&self, int parent) -> bool {
|
|
2407
2510
|
for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
|
|
2408
2511
|
const Node &child = nodes_[c];
|
|
2409
|
-
if (isDisplayNone(child.
|
|
2410
|
-
if (child.
|
|
2512
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
|
|
2513
|
+
if (child.computedStyle().float_side || (!establishesBlockContext(child) && self(self, c))) return true;
|
|
2411
2514
|
}
|
|
2412
2515
|
return false;
|
|
2413
2516
|
};
|
|
2517
|
+
#endif
|
|
2414
2518
|
bool blocks = false, inlines = false;
|
|
2415
2519
|
for (int i = 0; i < count; ++i) {
|
|
2416
2520
|
if (blockBox(nodes_[children[i]])) blocks = true;
|
|
2417
|
-
else if (!nodes_[children[i]].
|
|
2521
|
+
else if (!nodes_[children[i]].computedStyle().float_side) inlines = true;
|
|
2418
2522
|
}
|
|
2419
|
-
if (!splitInlineChildren_ && !(blocks && inlines)
|
|
2523
|
+
if (!splitInlineChildren_ && !(blocks && inlines)
|
|
2524
|
+
#if GEA_CSS_FLOATS
|
|
2525
|
+
&& !containsFloat(containsFloat, id_)
|
|
2526
|
+
#endif
|
|
2527
|
+
) return false;
|
|
2420
2528
|
FloatContext context;
|
|
2421
2529
|
const bool measureWidth = autosize && !hasExplicitWidth(node_) &&
|
|
2422
|
-
(node_.parent >= 0 || node_.
|
|
2423
|
-
!(scrollsOverflowX(node_.
|
|
2530
|
+
(node_.parent >= 0 || node_.computedStyle().float_side || intrinsicWidthConstraint(node_)) &&
|
|
2531
|
+
!(scrollsOverflowX(node_.computedStyle()) && node_.layout.width > 0 && !intrinsicWidthConstraint(node_));
|
|
2424
2532
|
layoutFloatChildrenInContext(children, count, contentWidth, contentHeight, autosize, context, 0, 0, measureWidth);
|
|
2425
2533
|
if (measureWidth && paddedWidth() != contentWidth) {
|
|
2426
2534
|
// As in ordinary block layout, measure first, then assign the used
|
|
@@ -2444,12 +2552,12 @@ private:
|
|
|
2444
2552
|
bool first = true, clearedThrough = false;
|
|
2445
2553
|
for (int i = 0; i < count; ++i) {
|
|
2446
2554
|
Node &child = nodes_[children[i]];
|
|
2447
|
-
if (!blockBox(child) && !child.
|
|
2555
|
+
if (!blockBox(child) && !child.computedStyle().float_side) {
|
|
2448
2556
|
int end = i + 1;
|
|
2449
2557
|
// Keep a BR with the line it terminates, then recompute the
|
|
2450
2558
|
// float exclusions for the next line.
|
|
2451
2559
|
while (!isLineBreak(nodes_[children[end - 1]]) &&
|
|
2452
|
-
end < count && !blockBox(nodes_[children[end]]) && !nodes_[children[end]].
|
|
2560
|
+
end < count && !blockBox(nodes_[children[end]]) && !nodes_[children[end]].computedStyle().float_side) ++end;
|
|
2453
2561
|
flowY += pending.value();
|
|
2454
2562
|
pending = {};
|
|
2455
2563
|
ScratchFrame inlineScratch;
|
|
@@ -2459,8 +2567,10 @@ private:
|
|
|
2459
2567
|
line.measureChildren();
|
|
2460
2568
|
return line.layoutInlineFlow(false, true);
|
|
2461
2569
|
};
|
|
2570
|
+
#if GEA_CSS_FIRST_LINE
|
|
2462
2571
|
NodeRareData *ownerRare = rareDataFor(id_);
|
|
2463
2572
|
const bool ownerLineWasValid = ownerRare && ownerRare->firstLineBackground.lineValid;
|
|
2573
|
+
#endif
|
|
2464
2574
|
auto extent = layoutRun(contentWidth);
|
|
2465
2575
|
// If even the first unbreakable unit cannot fit beside a float,
|
|
2466
2576
|
// move this line down to the next float boundary and retry.
|
|
@@ -2473,8 +2583,8 @@ private:
|
|
|
2473
2583
|
minimum = item.type == NodeType::Text || inner >= 0
|
|
2474
2584
|
? TextRenderer::firstUnbreakableWidth(inner >= 0 ? nodes_[inner] : item)
|
|
2475
2585
|
: item.layout.width;
|
|
2476
|
-
minimum += item.
|
|
2477
|
-
if (item.type == NodeType::Text) minimum += boxInsets(item.
|
|
2586
|
+
minimum += item.computedStyle().margin[1] + item.computedStyle().margin[3];
|
|
2587
|
+
if (item.type == NodeType::Text) minimum += boxInsets(item.computedStyle(), true);
|
|
2478
2588
|
}
|
|
2479
2589
|
int left = 0, right = contentWidth;
|
|
2480
2590
|
for (;;) {
|
|
@@ -2490,6 +2600,7 @@ private:
|
|
|
2490
2600
|
flowY = nextBottom;
|
|
2491
2601
|
}
|
|
2492
2602
|
if (right - left != contentWidth) extent = layoutRun(std::max(0, right - left));
|
|
2603
|
+
#if GEA_CSS_FIRST_LINE
|
|
2493
2604
|
if (!ownerLineWasValid && ownerRare && ownerRare->firstLineBackground.lineValid)
|
|
2494
2605
|
ownerRare->firstLineBackground.lineY = clampInt16(ownerRare->firstLineBackground.lineY + flowY);
|
|
2495
2606
|
for (int j = i; j < end; ++j) {
|
|
@@ -2506,6 +2617,7 @@ private:
|
|
|
2506
2617
|
}
|
|
2507
2618
|
}
|
|
2508
2619
|
}
|
|
2620
|
+
#endif
|
|
2509
2621
|
for (int j = i; j < end; ++j) {
|
|
2510
2622
|
nodes_[children[j]].layout.x += left;
|
|
2511
2623
|
nodes_[children[j]].layout.y += flowY;
|
|
@@ -2514,30 +2626,30 @@ private:
|
|
|
2514
2626
|
intrinsicWidth = std::max(intrinsicWidth, left + extent.width);
|
|
2515
2627
|
const Node &last = nodes_[children[end - 1]];
|
|
2516
2628
|
if (isLineBreak(last)) for (const auto &f : floats)
|
|
2517
|
-
if (last.
|
|
2629
|
+
if (last.computedStyle().clear_side & f.side) flowY = std::max(flowY, f.bottom - originY);
|
|
2518
2630
|
}
|
|
2519
2631
|
first = false; clearedThrough = false;
|
|
2520
2632
|
i = end - 1;
|
|
2521
2633
|
continue;
|
|
2522
2634
|
}
|
|
2523
2635
|
engine_.layoutNode(children[i], contentWidth, contentHeight, measureWidth);
|
|
2524
|
-
const bool block = !child.
|
|
2525
|
-
const int measuredOuterW = child.layout.width + child.
|
|
2526
|
-
const bool automaticWidth = block && !hasExplicitWidth(child) && !isIntrinsicSizeExpression(child.
|
|
2636
|
+
const bool block = !child.computedStyle().float_side && blockBox(child);
|
|
2637
|
+
const int measuredOuterW = child.layout.width + child.computedStyle().margin[3] + child.computedStyle().margin[1];
|
|
2638
|
+
const bool automaticWidth = block && !hasExplicitWidth(child) && !isIntrinsicSizeExpression(child.computedStyle().width_expression) &&
|
|
2527
2639
|
writingMode(child) == 0 && !(preferredRatio(child) > 0 && hasExplicitHeight(child));
|
|
2528
2640
|
// Ordinary blocks still fill their containing block beside floats;
|
|
2529
2641
|
// only their line boxes are shortened by float exclusions.
|
|
2530
2642
|
if (automaticWidth) {
|
|
2531
|
-
const int width = clampLayoutSize(child, std::max(0, contentWidth - child.
|
|
2643
|
+
const int width = clampLayoutSize(child, std::max(0, contentWidth - child.computedStyle().margin[1] - child.computedStyle().margin[3]), true);
|
|
2532
2644
|
if (child.layout.width != width) {
|
|
2533
2645
|
child.layout.width = clampInt16(width);
|
|
2534
2646
|
engine_.repositionChildren(children[i]);
|
|
2535
2647
|
}
|
|
2536
2648
|
}
|
|
2537
|
-
int outerW = child.layout.width + child.
|
|
2538
|
-
int outerH = child.layout.height + child.
|
|
2649
|
+
int outerW = child.layout.width + child.computedStyle().margin[3] + child.computedStyle().margin[1];
|
|
2650
|
+
int outerH = child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
2539
2651
|
const bool mergeTop = first && collapsesWithChildren(id_, false);
|
|
2540
|
-
if (!block && !child.
|
|
2652
|
+
if (!block && !child.computedStyle().float_side) {
|
|
2541
2653
|
flowY += mergeTop ? 0 : pending.value();
|
|
2542
2654
|
pending = {};
|
|
2543
2655
|
first = false;
|
|
@@ -2547,11 +2659,11 @@ private:
|
|
|
2547
2659
|
// Normal blocks clear their border edge, after adjoining margins
|
|
2548
2660
|
// collapse. Floats instead clear their outer edge (CSS 2.2 9.5.2).
|
|
2549
2661
|
int y = block ? flowY + (mergeTop ? 0 : before.value()) :
|
|
2550
|
-
child.
|
|
2662
|
+
child.computedStyle().float_side ? std::max(flowY + (mergeTop ? 0 : pending.value()), context.lastTop - originY) : flowY;
|
|
2551
2663
|
const int hypotheticalY = y;
|
|
2552
2664
|
int clearBottom = INT_MIN;
|
|
2553
2665
|
for (const auto &f : floats)
|
|
2554
|
-
if (child.
|
|
2666
|
+
if (child.computedStyle().clear_side & f.side) clearBottom = std::max(clearBottom, f.bottom - originY);
|
|
2555
2667
|
const bool clearance = block && clearBottom != INT_MIN && (clearBottom > hypotheticalY || context.hasClearance(children[i]));
|
|
2556
2668
|
// Once clearance separated the margins, rebasing the wrapper must
|
|
2557
2669
|
// not mistake the now non-collapsing margin for a new hypothetical
|
|
@@ -2561,7 +2673,7 @@ private:
|
|
|
2561
2673
|
if (clearance && !context.hasClearance(children[i])) context.cleared.push_back(children[i]);
|
|
2562
2674
|
int left = 0, right = contentWidth, contextX = 0;
|
|
2563
2675
|
const bool independentBlock = block && establishesBlockContext(child);
|
|
2564
|
-
if (child.
|
|
2676
|
+
if (child.computedStyle().float_side || child.computedStyle().display != kDisplayBlock || establishesBlockContext(child)) {
|
|
2565
2677
|
for (;;) {
|
|
2566
2678
|
left = 0; right = contentWidth;
|
|
2567
2679
|
int nextY = 32767;
|
|
@@ -2578,18 +2690,18 @@ private:
|
|
|
2578
2690
|
// A BFC's border box cannot overlap float margin boxes.
|
|
2579
2691
|
// Automatic width uses the remaining interval. Even a
|
|
2580
2692
|
// zero-width float prevents a negative margin crossing it.
|
|
2581
|
-
const int start = hasLeft ? std::max<int>(child.
|
|
2582
|
-
const int end = hasRight ? std::min<int>(contentWidth - child.
|
|
2583
|
-
contextX = start - child.
|
|
2693
|
+
const int start = hasLeft ? std::max<int>(child.computedStyle().margin[3], left) : child.computedStyle().margin[3];
|
|
2694
|
+
const int end = hasRight ? std::min<int>(contentWidth - child.computedStyle().margin[1], right) : contentWidth - child.computedStyle().margin[1];
|
|
2695
|
+
contextX = start - child.computedStyle().margin[3];
|
|
2584
2696
|
if (automaticWidth) {
|
|
2585
2697
|
const int width = clampLayoutSize(child, std::max(0, end - start), true);
|
|
2586
2698
|
if (child.layout.width != width) {
|
|
2587
2699
|
const int previousHeight = child.layout.height;
|
|
2588
|
-
engine_.layoutNode(children[i], width + child.
|
|
2700
|
+
engine_.layoutNode(children[i], width + child.computedStyle().margin[1] + child.computedStyle().margin[3], contentHeight);
|
|
2589
2701
|
child.layout.width = clampInt16(width);
|
|
2590
2702
|
engine_.repositionChildren(children[i]);
|
|
2591
|
-
outerW = width + child.
|
|
2592
|
-
outerH = child.layout.height + child.
|
|
2703
|
+
outerW = width + child.computedStyle().margin[1] + child.computedStyle().margin[3];
|
|
2704
|
+
outerH = child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
2593
2705
|
if (previousHeight != child.layout.height) continue;
|
|
2594
2706
|
}
|
|
2595
2707
|
}
|
|
@@ -2599,11 +2711,11 @@ private:
|
|
|
2599
2711
|
y = nextY;
|
|
2600
2712
|
}
|
|
2601
2713
|
}
|
|
2602
|
-
const int x = child.
|
|
2603
|
-
intrinsicWidth = std::max(intrinsicWidth, child.
|
|
2714
|
+
const int x = child.computedStyle().float_side == 2 ? right - outerW : independentBlock ? contextX : left;
|
|
2715
|
+
intrinsicWidth = std::max(intrinsicWidth, child.computedStyle().float_side
|
|
2604
2716
|
? left + outerW + contentWidth - right : measuredOuterW);
|
|
2605
|
-
child.layout.x = boxInset(node_.
|
|
2606
|
-
child.layout.y = boxInset(node_.
|
|
2717
|
+
child.layout.x = boxInset(node_.computedStyle(), 3) + x + child.computedStyle().margin[3];
|
|
2718
|
+
child.layout.y = boxInset(node_.computedStyle(), 0) + y + (block ? 0 : child.computedStyle().margin[0]);
|
|
2607
2719
|
if (block && !establishesBlockContext(child) && child.first_child >= 0) {
|
|
2608
2720
|
LayoutNodePass nested(engine_, children[i], contentWidth, contentHeight);
|
|
2609
2721
|
if (!nested.resolveInlineFormattingRow()) {
|
|
@@ -2614,7 +2726,7 @@ private:
|
|
|
2614
2726
|
const int precedingTop = context.lastTop;
|
|
2615
2727
|
auto placeDescendants = [&]() {
|
|
2616
2728
|
nested.layoutFloatChildrenInContext(nestedScratch.children(), nestedCount, nested.paddedWidth(), nested.paddedHeight(), true,
|
|
2617
|
-
context, originX + x + child.
|
|
2729
|
+
context, originX + x + child.computedStyle().margin[3] + boxInset(child.computedStyle(), 3), originY + y + boxInset(child.computedStyle(), 0));
|
|
2618
2730
|
};
|
|
2619
2731
|
placeDescendants();
|
|
2620
2732
|
// Actual descendant clearance can separate a margin that was
|
|
@@ -2626,10 +2738,10 @@ private:
|
|
|
2626
2738
|
int finalY = flowY + (first && collapsesWithChildren(id_, false) ? 0 : separated.value());
|
|
2627
2739
|
if (clearance) finalY = clearBottom;
|
|
2628
2740
|
for (std::size_t f = 0; f < precedingFloats; ++f)
|
|
2629
|
-
if (child.
|
|
2741
|
+
if (child.computedStyle().clear_side & floats[f].side) finalY = std::max(finalY, floats[f].bottom - originY);
|
|
2630
2742
|
if (finalY != y) {
|
|
2631
2743
|
y = finalY;
|
|
2632
|
-
child.layout.y = boxInset(node_.
|
|
2744
|
+
child.layout.y = boxInset(node_.computedStyle(), 0) + y;
|
|
2633
2745
|
floats.resize(precedingFloats);
|
|
2634
2746
|
context.lastTop = precedingTop;
|
|
2635
2747
|
placeDescendants();
|
|
@@ -2638,12 +2750,12 @@ private:
|
|
|
2638
2750
|
nested.positionAbsoluteChildren();
|
|
2639
2751
|
nested.applyRelativeOffsets();
|
|
2640
2752
|
// This result depends on preceding floats, beyond the size-only memo key.
|
|
2641
|
-
|
|
2753
|
+
engine_.invalidateMemo(children[i]);
|
|
2642
2754
|
}
|
|
2643
2755
|
}
|
|
2644
2756
|
}
|
|
2645
|
-
if (child.
|
|
2646
|
-
floats.push_back({originX + x, originY + y, originX + x + outerW, originY + y + outerH, child.
|
|
2757
|
+
if (child.computedStyle().float_side) {
|
|
2758
|
+
floats.push_back({originX + x, originY + y, originX + x + outerW, originY + y + outerH, child.computedStyle().float_side});
|
|
2647
2759
|
context.lastTop = originY + y;
|
|
2648
2760
|
} else if (block && collapsesThrough(children[i])) {
|
|
2649
2761
|
if (clearance) {
|
|
@@ -2665,10 +2777,10 @@ private:
|
|
|
2665
2777
|
if (clearedThrough || (!collapsesWithChildren(id_, true) && !(first && collapsesWithChildren(id_, false))))
|
|
2666
2778
|
flowY += pending.value();
|
|
2667
2779
|
if (measureWidth)
|
|
2668
|
-
node_.layout.width = clampInt16(clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.
|
|
2780
|
+
node_.layout.width = clampInt16(clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.computedStyle(), true), true));
|
|
2669
2781
|
if (autosize && !hasExplicitHeight(node_)) {
|
|
2670
2782
|
// Float enclosure is finalized with all same-context descendants.
|
|
2671
|
-
node_.layout.height = clampBorderSize(engine_, node_, flowY + boxInsets(node_.
|
|
2783
|
+
node_.layout.height = clampBorderSize(engine_, node_, flowY + boxInsets(node_.computedStyle(), false), false);
|
|
2672
2784
|
}
|
|
2673
2785
|
}
|
|
2674
2786
|
|
|
@@ -2678,8 +2790,8 @@ private:
|
|
|
2678
2790
|
// block-level in-flow child stacks them (column), as a browser would.
|
|
2679
2791
|
bool resolveRowDirection() const
|
|
2680
2792
|
{
|
|
2681
|
-
if (node_.
|
|
2682
|
-
return flexRowDirection(node_.
|
|
2793
|
+
if (node_.computedStyle().display == kDisplayFlex)
|
|
2794
|
+
return flexRowDirection(node_.computedStyle()) != (writingMode(node_) != 0);
|
|
2683
2795
|
return resolveInlineFormattingRow();
|
|
2684
2796
|
}
|
|
2685
2797
|
|
|
@@ -2690,12 +2802,12 @@ private:
|
|
|
2690
2802
|
// FlexLayoutPass's `inlineRow` flag switches on.
|
|
2691
2803
|
bool resolveInlineFormattingRow() const
|
|
2692
2804
|
{
|
|
2693
|
-
if (usesRowLayout(node_.
|
|
2694
|
-
if (node_.
|
|
2805
|
+
if (usesRowLayout(node_.computedStyle())) return false;
|
|
2806
|
+
if (node_.computedStyle().flex_direction_explicit || node_.computedStyle().display != kDisplayBlock) return false;
|
|
2695
2807
|
bool anyInFlow = false, allInline = true;
|
|
2696
2808
|
visitFormattingChildren(nodes_, id_, [&](int c) {
|
|
2697
2809
|
const Node &child = nodes_[c];
|
|
2698
|
-
if (child.
|
|
2810
|
+
if (child.computedStyle().display == kDisplayNone || isOutOfFlowPosition(child.computedStyle().position)) return;
|
|
2699
2811
|
if (suppressAnonymousWhitespace(nodes_, child.parent, c)) return;
|
|
2700
2812
|
if (!LayoutEngine::isInlineLevelNode(child)) allInline = false;
|
|
2701
2813
|
anyInFlow = true;
|
|
@@ -2796,15 +2908,15 @@ private:
|
|
|
2796
2908
|
void stretchGridChild(int child, Node &childNode, int cellWidth, int cellHeight, int alignX, int alignY)
|
|
2797
2909
|
{
|
|
2798
2910
|
bool resized = false;
|
|
2799
|
-
const int availableWidth = cellWidth - childNode.
|
|
2800
|
-
const int availableHeight = cellHeight - childNode.
|
|
2911
|
+
const int availableWidth = cellWidth - childNode.computedStyle().margin[1] - childNode.computedStyle().margin[3];
|
|
2912
|
+
const int availableHeight = cellHeight - childNode.computedStyle().margin[0] - childNode.computedStyle().margin[2];
|
|
2801
2913
|
const int width = clampLayoutSize(childNode, availableWidth < 0 ? 0 : availableWidth, true);
|
|
2802
2914
|
const int height = clampLayoutSize(childNode, availableHeight < 0 ? 0 : availableHeight, false);
|
|
2803
|
-
if (alignX == 0 && !(childNode.
|
|
2915
|
+
if (alignX == 0 && !(childNode.computedStyle().margin_auto & 10) && !hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression) && childNode.layout.width != width) {
|
|
2804
2916
|
childNode.layout.width = width;
|
|
2805
2917
|
resized = true;
|
|
2806
2918
|
}
|
|
2807
|
-
if (alignY == 0 && !(childNode.
|
|
2919
|
+
if (alignY == 0 && !(childNode.computedStyle().margin_auto & 5) && !hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression) && childNode.layout.height != height) {
|
|
2808
2920
|
childNode.layout.height = height;
|
|
2809
2921
|
resized = true;
|
|
2810
2922
|
}
|
|
@@ -2813,22 +2925,23 @@ private:
|
|
|
2813
2925
|
|
|
2814
2926
|
void layoutGridChildren(int *children, int childCount, int padWidth, int padHeight, bool allowAutosizeParent)
|
|
2815
2927
|
{
|
|
2816
|
-
|
|
2928
|
+
#if GEA_CSS_GRID
|
|
2929
|
+
if (!childCount && !rstyle(node_.computedStyle()).grid_column_count && !rstyle(node_.computedStyle()).grid_row_count) {
|
|
2817
2930
|
if (auto *rare = rareDataFor(id_)) rare->gridLayout.reset();
|
|
2818
2931
|
if (allowAutosizeParent) autosizeEmptyNode();
|
|
2819
2932
|
return;
|
|
2820
2933
|
}
|
|
2821
2934
|
const bool vertical = writingMode(node_) != 0;
|
|
2822
|
-
int columnCount = std::max(childCount ? 1 : 0, int(rstyle(node_.
|
|
2823
|
-
int rowCount = std::max(childCount ? 1 : 0, int(rstyle(node_.
|
|
2935
|
+
int columnCount = std::max(childCount ? 1 : 0, int(rstyle(node_.computedStyle()).grid_column_count));
|
|
2936
|
+
int rowCount = std::max(childCount ? 1 : 0, int(rstyle(node_.computedStyle()).grid_row_count));
|
|
2824
2937
|
struct Placement { GridAxisPlacement column, row; };
|
|
2825
2938
|
std::vector<Placement> placements(childCount);
|
|
2826
2939
|
int columnOrigin = 0, rowOrigin = 0;
|
|
2827
2940
|
for (int i = 0; i < childCount; ++i) {
|
|
2828
|
-
const auto &rs = rstyle(nodes_[children[i]].
|
|
2941
|
+
const auto &rs = rstyle(nodes_[children[i]].computedStyle());
|
|
2829
2942
|
auto &p = placements[i];
|
|
2830
|
-
p.column = gridAxisPlacement(rs.grid_line[1], rs.grid_line[3], rstyle(node_.
|
|
2831
|
-
p.row = gridAxisPlacement(rs.grid_line[0], rs.grid_line[2], rstyle(node_.
|
|
2943
|
+
p.column = gridAxisPlacement(rs.grid_line[1], rs.grid_line[3], rstyle(node_.computedStyle()).grid_column_count, false);
|
|
2944
|
+
p.row = gridAxisPlacement(rs.grid_line[0], rs.grid_line[2], rstyle(node_.computedStyle()).grid_row_count, false);
|
|
2832
2945
|
if (p.column.start != kUnset) columnOrigin = std::max(columnOrigin, -p.column.start);
|
|
2833
2946
|
if (p.row.start != kUnset) rowOrigin = std::max(rowOrigin, -p.row.start);
|
|
2834
2947
|
columnCount = std::max(columnCount, p.column.end == kUnset ? p.column.span : p.column.end);
|
|
@@ -2901,13 +3014,13 @@ private:
|
|
|
2901
3014
|
int16_t rowValues[kMaxGridLayoutTracks] = {0};
|
|
2902
3015
|
for (int i = 0; i < columnCount; ++i) {
|
|
2903
3016
|
const int track = i - columnOrigin;
|
|
2904
|
-
columnTypes[i] = track >= 0 && track < rstyle(node_.
|
|
2905
|
-
columnValues[i] = track >= 0 && track < rstyle(node_.
|
|
3017
|
+
columnTypes[i] = track >= 0 && track < rstyle(node_.computedStyle()).grid_column_count ? rstyle(node_.computedStyle()).grid_column_type[track] : 0;
|
|
3018
|
+
columnValues[i] = track >= 0 && track < rstyle(node_.computedStyle()).grid_column_count ? rstyle(node_.computedStyle()).grid_column_value[track] : 0;
|
|
2906
3019
|
}
|
|
2907
3020
|
for (int i = 0; i < rowCount; ++i) {
|
|
2908
3021
|
const int track = i - rowOrigin;
|
|
2909
|
-
rowTypes[i] = track >= 0 && track < rstyle(node_.
|
|
2910
|
-
rowValues[i] = track >= 0 && track < rstyle(node_.
|
|
3022
|
+
rowTypes[i] = track >= 0 && track < rstyle(node_.computedStyle()).grid_row_count ? rstyle(node_.computedStyle()).grid_row_type[track] : 0;
|
|
3023
|
+
rowValues[i] = track >= 0 && track < rstyle(node_.computedStyle()).grid_row_count ? rstyle(node_.computedStyle()).grid_row_value[track] : 0;
|
|
2911
3024
|
}
|
|
2912
3025
|
|
|
2913
3026
|
int autoColumns[kMaxGridLayoutTracks] = {0};
|
|
@@ -2931,8 +3044,8 @@ private:
|
|
|
2931
3044
|
if (p.span != span) continue;
|
|
2932
3045
|
const Node &child = nodes_[children[i]];
|
|
2933
3046
|
const bool horizontal = columns != vertical;
|
|
2934
|
-
const int size = horizontal ? child.layout.width + child.
|
|
2935
|
-
: child.layout.height + child.
|
|
3047
|
+
const int size = horizontal ? child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]
|
|
3048
|
+
: child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2];
|
|
2936
3049
|
int occupied = (span - 1) * gap, autos = 0;
|
|
2937
3050
|
for (int t = p.start; t < p.end; ++t) {
|
|
2938
3051
|
occupied += types[t] == 1 ? values[t] : sizes[t];
|
|
@@ -2955,16 +3068,16 @@ private:
|
|
|
2955
3068
|
computeTrackSizes(columnCount, columnTypes, columnValues, autoColumns, vertical ? padHeight : padWidth, columnGap, columnSizes);
|
|
2956
3069
|
computeTrackSizes(rowCount, rowTypes, rowValues, autoRows, vertical ? padWidth : padHeight, rowGap, rowSizes);
|
|
2957
3070
|
if (allowAutosizeParent && !hasExplicitWidth(node_) &&
|
|
2958
|
-
rstyle(node_.
|
|
2959
|
-
writingMode(node_) == 0 && node_.
|
|
3071
|
+
rstyle(node_.computedStyle()).grid_column_count == 0 && columnCount == 1 &&
|
|
3072
|
+
writingMode(node_) == 0 && node_.computedStyle().justify_content == 0) columnSizes[0] = padWidth;
|
|
2960
3073
|
|
|
2961
3074
|
if (allowAutosizeParent && !hasExplicitWidth(node_)) {
|
|
2962
|
-
int width = boxInset(node_.
|
|
3075
|
+
int width = boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
2963
3076
|
width += vertical ? gridTrackTotalSize(rowCount, rowSizes, rowGap) : gridTrackTotalSize(columnCount, columnSizes, columnGap);
|
|
2964
3077
|
node_.layout.width = clampLayoutSize(node_, width, true);
|
|
2965
3078
|
}
|
|
2966
3079
|
if (allowAutosizeParent && !hasExplicitHeight(node_)) {
|
|
2967
|
-
int height = boxInset(node_.
|
|
3080
|
+
int height = boxInset(node_.computedStyle(), 0) + boxInset(node_.computedStyle(), 2);
|
|
2968
3081
|
height += vertical ? gridTrackTotalSize(columnCount, columnSizes, columnGap) : gridTrackTotalSize(rowCount, rowSizes, rowGap);
|
|
2969
3082
|
node_.layout.height = clampLayoutSize(node_, height, false);
|
|
2970
3083
|
}
|
|
@@ -2973,8 +3086,8 @@ private:
|
|
|
2973
3086
|
// contribute free space without making an auto-sized grid fill its parent.
|
|
2974
3087
|
padWidth = paddedWidth();
|
|
2975
3088
|
padHeight = paddedHeight();
|
|
2976
|
-
stretchAutoGridTracks(columnCount, columnTypes, columnSizes, vertical ? padHeight : padWidth, columnGap, node_.
|
|
2977
|
-
stretchAutoGridTracks(rowCount, rowTypes, rowSizes, vertical ? padWidth : padHeight, rowGap, node_.
|
|
3089
|
+
stretchAutoGridTracks(columnCount, columnTypes, columnSizes, vertical ? padHeight : padWidth, columnGap, node_.computedStyle().justify_content);
|
|
3090
|
+
stretchAutoGridTracks(rowCount, rowTypes, rowSizes, vertical ? padWidth : padHeight, rowGap, node_.computedStyle().align_content);
|
|
2978
3091
|
|
|
2979
3092
|
int rowY[kMaxGridLayoutTracks] = {0};
|
|
2980
3093
|
int columnX[kMaxGridLayoutTracks] = {0};
|
|
@@ -2982,11 +3095,11 @@ private:
|
|
|
2982
3095
|
const int rowTotal = gridTrackTotalSize(rowCount, rowSizes, rowGap);
|
|
2983
3096
|
int columnPosition = 0, rowPosition = 0;
|
|
2984
3097
|
for (int i = 0; i < columnCount; ++i) {
|
|
2985
|
-
columnX[i] = columnPosition + gridContentOffset(vertical ? padHeight : padWidth, columnTotal, node_.
|
|
3098
|
+
columnX[i] = columnPosition + gridContentOffset(vertical ? padHeight : padWidth, columnTotal, node_.computedStyle().justify_content, i, columnCount);
|
|
2986
3099
|
columnPosition += columnSizes[i] + columnGap;
|
|
2987
3100
|
}
|
|
2988
3101
|
for (int i = 0; i < rowCount; ++i) {
|
|
2989
|
-
rowY[i] = rowPosition + gridContentOffset(vertical ? padWidth : padHeight, rowTotal, node_.
|
|
3102
|
+
rowY[i] = rowPosition + gridContentOffset(vertical ? padWidth : padHeight, rowTotal, node_.computedStyle().align_content, i, rowCount);
|
|
2990
3103
|
rowPosition += rowSizes[i] + rowGap;
|
|
2991
3104
|
}
|
|
2992
3105
|
|
|
@@ -3007,48 +3120,55 @@ private:
|
|
|
3007
3120
|
gridPhysicalRange(node_, true, columnX[p.column.start], tracks.columnEnd[p.column.end - 1], vertical ? cellY : cellX, vertical ? cellHeight : cellWidth);
|
|
3008
3121
|
gridPhysicalRange(node_, false, rowY[p.row.start], tracks.rowEnd[p.row.end - 1], vertical ? cellX : cellY, vertical ? cellWidth : cellHeight);
|
|
3009
3122
|
engine_.layoutNode(child, cellWidth, cellHeight);
|
|
3010
|
-
const int inlineAlign = rstyle(childNode.
|
|
3011
|
-
const int blockAlign = childNode.
|
|
3123
|
+
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? rstyle(childNode.computedStyle()).justify_self : -1) >= 0 ? (GEA_CSS_JUSTIFY_SELF ? rstyle(childNode.computedStyle()).justify_self : -1) : node_.computedStyle().justify_items;
|
|
3124
|
+
const int blockAlign = childNode.computedStyle().align_self >= 0 ? childNode.computedStyle().align_self : node_.computedStyle().align_items;
|
|
3012
3125
|
const int alignX = vertical ? blockAlign : inlineAlign;
|
|
3013
3126
|
const int alignY = vertical ? inlineAlign : blockAlign;
|
|
3014
3127
|
stretchGridChild(child, childNode, cellWidth, cellHeight, alignX, alignY);
|
|
3015
3128
|
|
|
3016
|
-
int x = cellX + childNode.
|
|
3017
|
-
int y = cellY + childNode.
|
|
3018
|
-
const int freeX = cellWidth - childNode.layout.width - childNode.
|
|
3019
|
-
const int freeY = cellHeight - childNode.layout.height - childNode.
|
|
3129
|
+
int x = cellX + childNode.computedStyle().margin[3];
|
|
3130
|
+
int y = cellY + childNode.computedStyle().margin[0];
|
|
3131
|
+
const int freeX = cellWidth - childNode.layout.width - childNode.computedStyle().margin[1] - childNode.computedStyle().margin[3];
|
|
3132
|
+
const int freeY = cellHeight - childNode.layout.height - childNode.computedStyle().margin[0] - childNode.computedStyle().margin[2];
|
|
3020
3133
|
const int usedX = usedGridAlignment(node_, childNode, alignX, freeX, true);
|
|
3021
3134
|
const int usedY = usedGridAlignment(node_, childNode, alignY, freeY, false);
|
|
3022
3135
|
// Auto margins consume positive free space before self-alignment and
|
|
3023
3136
|
// suppress it even when the item overflows the grid area.
|
|
3024
|
-
if (childNode.
|
|
3025
|
-
if (freeX > 0 && (childNode.
|
|
3026
|
-
x += (childNode.
|
|
3137
|
+
if (childNode.computedStyle().margin_auto & 10) {
|
|
3138
|
+
if (freeX > 0 && (childNode.computedStyle().margin_auto & 8))
|
|
3139
|
+
x += (childNode.computedStyle().margin_auto & 2) ? freeX / 2 : freeX;
|
|
3027
3140
|
} else if (usedX == 1) x += freeX / 2;
|
|
3028
3141
|
else if (usedX == 2) x += freeX;
|
|
3029
|
-
if (childNode.
|
|
3030
|
-
if (freeY > 0 && (childNode.
|
|
3031
|
-
y += (childNode.
|
|
3142
|
+
if (childNode.computedStyle().margin_auto & 5) {
|
|
3143
|
+
if (freeY > 0 && (childNode.computedStyle().margin_auto & 1))
|
|
3144
|
+
y += (childNode.computedStyle().margin_auto & 4) ? freeY / 2 : freeY;
|
|
3032
3145
|
} else if (usedY == 1) y += freeY / 2;
|
|
3033
3146
|
else if (usedY == 2) y += freeY;
|
|
3034
3147
|
childNode.layout.x = x;
|
|
3035
3148
|
childNode.layout.y = y;
|
|
3036
3149
|
}
|
|
3037
|
-
|
|
3150
|
+
#else
|
|
3151
|
+
(void)children;
|
|
3152
|
+
(void)childCount;
|
|
3153
|
+
(void)padWidth;
|
|
3154
|
+
(void)padHeight;
|
|
3155
|
+
(void)allowAutosizeParent;
|
|
3156
|
+
#endif
|
|
3157
|
+
}
|
|
3038
3158
|
|
|
3039
3159
|
void prepareOwnSize()
|
|
3040
3160
|
{
|
|
3041
3161
|
int contentWidth = resolvedStyleWidth(node_, availWidth_);
|
|
3042
3162
|
int contentHeight = resolvedStyleHeight(node_, availHeight_);
|
|
3043
3163
|
if (!hasExplicitWidth(node_)) {
|
|
3044
|
-
contentWidth -= node_.
|
|
3164
|
+
contentWidth -= node_.computedStyle().margin[1] + node_.computedStyle().margin[3];
|
|
3045
3165
|
}
|
|
3046
3166
|
if (!hasExplicitHeight(node_)) {
|
|
3047
|
-
contentHeight -= node_.
|
|
3167
|
+
contentHeight -= node_.computedStyle().margin[0] + node_.computedStyle().margin[2];
|
|
3048
3168
|
}
|
|
3049
3169
|
|
|
3050
|
-
if (hasExplicitWidth(node_)) contentWidth = contentSizeToBorderSize(node_.
|
|
3051
|
-
if (hasExplicitHeight(node_)) contentHeight = contentSizeToBorderSize(node_.
|
|
3170
|
+
if (hasExplicitWidth(node_)) contentWidth = contentSizeToBorderSize(node_.computedStyle(), contentWidth, true);
|
|
3171
|
+
if (hasExplicitHeight(node_)) contentHeight = contentSizeToBorderSize(node_.computedStyle(), contentHeight, false);
|
|
3052
3172
|
node_.layout.width = clampLayoutSize(node_, contentWidth, true);
|
|
3053
3173
|
node_.layout.height = clampLayoutSize(node_, contentHeight, false);
|
|
3054
3174
|
// Resolve a definite ratio-derived axis before measuring percentage
|
|
@@ -3063,22 +3183,23 @@ private:
|
|
|
3063
3183
|
|
|
3064
3184
|
int paddedWidth() const
|
|
3065
3185
|
{
|
|
3066
|
-
int width = node_.layout.width - boxInset(node_.
|
|
3186
|
+
int width = node_.layout.width - boxInset(node_.computedStyle(), 1) - boxInset(node_.computedStyle(), 3);
|
|
3067
3187
|
return width < 0 ? 0 : width;
|
|
3068
3188
|
}
|
|
3069
3189
|
|
|
3070
3190
|
int paddedHeight() const
|
|
3071
3191
|
{
|
|
3072
|
-
int height = node_.layout.height - boxInset(node_.
|
|
3192
|
+
int height = node_.layout.height - boxInset(node_.computedStyle(), 0) - boxInset(node_.computedStyle(), 2);
|
|
3073
3193
|
return height < 0 ? 0 : height;
|
|
3074
3194
|
}
|
|
3075
3195
|
|
|
3076
3196
|
void autosizeEmptyNode()
|
|
3077
3197
|
{
|
|
3078
|
-
if (!hasExplicitWidth(node_)) node_.layout.width = boxInset(node_.
|
|
3079
|
-
if (!hasExplicitHeight(node_)) node_.layout.height = boxInset(node_.
|
|
3198
|
+
if (!hasExplicitWidth(node_)) node_.layout.width = boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
3199
|
+
if (!hasExplicitHeight(node_)) node_.layout.height = boxInset(node_.computedStyle(), 0) + boxInset(node_.computedStyle(), 2);
|
|
3080
3200
|
node_.layout.width = clampLayoutSize(node_, node_.layout.width, true);
|
|
3081
3201
|
node_.layout.height = clampLayoutSize(node_, node_.layout.height, false);
|
|
3202
|
+
#if GEA_CSS_SCROLLING
|
|
3082
3203
|
// A <virtual-list>'s scroll geometry is owned by
|
|
3083
3204
|
// applyVirtualListContentHeight() (invoked right after this in the
|
|
3084
3205
|
// empty-node branch). Its recycled slot pool is entirely
|
|
@@ -3092,10 +3213,12 @@ private:
|
|
|
3092
3213
|
node_.layout.scroll_x = 0;
|
|
3093
3214
|
node_.layout.scroll_y = 0;
|
|
3094
3215
|
}
|
|
3216
|
+
#endif
|
|
3095
3217
|
}
|
|
3096
3218
|
|
|
3097
3219
|
void updateScrollContentSize()
|
|
3098
3220
|
{
|
|
3221
|
+
#if GEA_CSS_SCROLLING
|
|
3099
3222
|
// A <virtual-list>'s scroll geometry is owned by
|
|
3100
3223
|
// applyVirtualListContentHeight() (scroll_content_height = itemCount *
|
|
3101
3224
|
// rowHeight). Its real children are the recycled, position:absolute slot
|
|
@@ -3108,14 +3231,14 @@ private:
|
|
|
3108
3231
|
int contentHeight = node_.layout.height;
|
|
3109
3232
|
visitFormattingChildren(nodes_, id_, [&](int child) {
|
|
3110
3233
|
Node &childNode = nodes_[child];
|
|
3111
|
-
if (isCollapsedFlexItem(childNode) || isDisplayNone(childNode.
|
|
3234
|
+
if (isCollapsedFlexItem(childNode) || isDisplayNone(childNode.computedStyle()) || isOutOfFlowPosition(childNode.computedStyle().position)) return;
|
|
3112
3235
|
// A visible axis contributes descendant overflow; a clipping axis
|
|
3113
3236
|
// traps it at this child's border box independently of the other axis.
|
|
3114
|
-
const int width = overflowX(childNode.
|
|
3115
|
-
const int height = overflowY(childNode.
|
|
3116
|
-
const int right = childNode.layout.x + width + childNode.
|
|
3237
|
+
const int width = overflowX(childNode.computedStyle()) == 0 ? std::max<int>(childNode.layout.width, childNode.layout.scroll_content_width) : childNode.layout.width;
|
|
3238
|
+
const int height = overflowY(childNode.computedStyle()) == 0 ? std::max<int>(childNode.layout.height, childNode.layout.scroll_content_height) : childNode.layout.height;
|
|
3239
|
+
const int right = childNode.layout.x + width + childNode.computedStyle().margin[1] + boxInset(node_.computedStyle(), 1);
|
|
3117
3240
|
if (right > contentWidth) contentWidth = right;
|
|
3118
|
-
const int bottom = childNode.layout.y + height + childNode.
|
|
3241
|
+
const int bottom = childNode.layout.y + height + childNode.computedStyle().margin[2] + boxInset(node_.computedStyle(), 2);
|
|
3119
3242
|
if (bottom > contentHeight) contentHeight = bottom;
|
|
3120
3243
|
});
|
|
3121
3244
|
node_.layout.scroll_content_width = contentWidth;
|
|
@@ -3123,7 +3246,7 @@ private:
|
|
|
3123
3246
|
|
|
3124
3247
|
int maxScrollX = node_.layout.scroll_content_width - node_.layout.width;
|
|
3125
3248
|
if (maxScrollX < 0) maxScrollX = 0;
|
|
3126
|
-
if (!scrollsOverflowX(node_.
|
|
3249
|
+
if (!scrollsOverflowX(node_.computedStyle())) {
|
|
3127
3250
|
node_.layout.scroll_x = 0;
|
|
3128
3251
|
} else {
|
|
3129
3252
|
if (node_.layout.scroll_x < 0) node_.layout.scroll_x = 0;
|
|
@@ -3132,13 +3255,16 @@ private:
|
|
|
3132
3255
|
|
|
3133
3256
|
int maxScroll = node_.layout.scroll_content_height - node_.layout.height;
|
|
3134
3257
|
if (maxScroll < 0) maxScroll = 0;
|
|
3135
|
-
if (!scrollsOverflowY(node_.
|
|
3258
|
+
if (!scrollsOverflowY(node_.computedStyle())) {
|
|
3136
3259
|
node_.layout.scroll_y = 0;
|
|
3137
3260
|
} else {
|
|
3138
3261
|
if (node_.layout.scroll_y < 0) node_.layout.scroll_y = 0;
|
|
3139
3262
|
if (node_.layout.scroll_y > maxScroll) node_.layout.scroll_y = maxScroll;
|
|
3140
3263
|
}
|
|
3141
|
-
|
|
3264
|
+
#else
|
|
3265
|
+
|
|
3266
|
+
#endif
|
|
3267
|
+
}
|
|
3142
3268
|
|
|
3143
3269
|
// A <virtual-list> only materializes a small pool of real child slot nodes
|
|
3144
3270
|
// but scrolls over a virtual content height of itemCount * rowHeight. The
|
|
@@ -3146,10 +3272,11 @@ private:
|
|
|
3146
3272
|
// controls it purely through the template's stylesheet.
|
|
3147
3273
|
void applyVirtualListContentHeight()
|
|
3148
3274
|
{
|
|
3275
|
+
#if GEA_CSS_SCROLLING
|
|
3149
3276
|
if (node_.type != NodeType::VirtualList) return;
|
|
3150
3277
|
int rowHeight = 0;
|
|
3151
3278
|
for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3152
|
-
if (isDisplayNone(nodes_[child].
|
|
3279
|
+
if (isDisplayNone(nodes_[child].computedStyle())) continue;
|
|
3153
3280
|
rowHeight = nodes_[child].layout.height;
|
|
3154
3281
|
break;
|
|
3155
3282
|
}
|
|
@@ -3162,30 +3289,34 @@ private:
|
|
|
3162
3289
|
if (maxScroll < 0) maxScroll = 0;
|
|
3163
3290
|
if (node_.layout.scroll_y < 0) node_.layout.scroll_y = 0;
|
|
3164
3291
|
if (node_.layout.scroll_y > maxScroll) node_.layout.scroll_y = maxScroll;
|
|
3165
|
-
|
|
3292
|
+
#else
|
|
3293
|
+
|
|
3294
|
+
#endif
|
|
3295
|
+
}
|
|
3166
3296
|
|
|
3167
3297
|
void captureBlockStaticPositions()
|
|
3168
3298
|
{
|
|
3169
3299
|
for (int c = node_.first_child; c >= 0; c = nodes_[c].next_sibling)
|
|
3170
|
-
if (isOutOfFlowPosition(nodes_[c].
|
|
3171
|
-
if (node_.
|
|
3172
|
-
(LayoutEngine::isInlineLevelNode(node_) && !isOutOfFlowPosition(node_.
|
|
3300
|
+
if (isOutOfFlowPosition(nodes_[c].computedStyle().position)) layoutState(c).static_block_axis = 0;
|
|
3301
|
+
if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit ||
|
|
3302
|
+
(LayoutEngine::isInlineLevelNode(node_) && !isOutOfFlowPosition(node_.computedStyle().position))) return;
|
|
3173
3303
|
const bool vertical = writingMode(node_) != 0;
|
|
3174
3304
|
const bool reversed = vertical && gridAxisReversed(node_, true);
|
|
3175
|
-
int cursor = boxInset(node_.
|
|
3305
|
+
int cursor = boxInset(node_.computedStyle(), blockMarginSide(false));
|
|
3176
3306
|
bool first = true;
|
|
3177
3307
|
CollapsedMargin pending;
|
|
3178
3308
|
visitFormattingChildren(nodes_, id_, [&](int id) {
|
|
3179
3309
|
Node &child = nodes_[id];
|
|
3180
|
-
if (isDisplayNone(child.
|
|
3181
|
-
if (isOutOfFlowPosition(child.
|
|
3310
|
+
if (isDisplayNone(child.computedStyle())) return;
|
|
3311
|
+
if (isOutOfFlowPosition(child.computedStyle().position)) {
|
|
3182
3312
|
if (child.parent != id_ || !blockBox(child)) return;
|
|
3183
3313
|
const int edge = cursor + (first && collapsesWithChildren(id_, false) ? 0 : pending.value());
|
|
3184
|
-
|
|
3185
|
-
|
|
3314
|
+
auto &persistent = layoutState(id);
|
|
3315
|
+
persistent.static_block_start = clampInt16(reversed ? node_.layout.width - edge : edge);
|
|
3316
|
+
persistent.static_block_axis = vertical ? 2 : 1;
|
|
3186
3317
|
return;
|
|
3187
3318
|
}
|
|
3188
|
-
if (child.
|
|
3319
|
+
if (child.computedStyle().float_side || suppressAnonymousWhitespace(nodes_, child.parent, id)) return;
|
|
3189
3320
|
if (blockBox(child) && collapsesThrough(id)) {
|
|
3190
3321
|
pending.add(childEdgeMargin(id_, id, false));
|
|
3191
3322
|
return;
|
|
@@ -3203,7 +3334,7 @@ private:
|
|
|
3203
3334
|
captureBlockStaticPositions();
|
|
3204
3335
|
for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3205
3336
|
Node &childNode = nodes_[child];
|
|
3206
|
-
if (isDisplayNone(childNode.
|
|
3337
|
+
if (isDisplayNone(childNode.computedStyle()) || !isOutOfFlowPosition(childNode.computedStyle().position)) continue;
|
|
3207
3338
|
|
|
3208
3339
|
int childAvailWidth, childAvailHeight;
|
|
3209
3340
|
int areaX, areaY;
|
|
@@ -3217,11 +3348,11 @@ private:
|
|
|
3217
3348
|
void stretchAbsoluteChild(int child, Node &childNode, int childAvailWidth, int childAvailHeight)
|
|
3218
3349
|
{
|
|
3219
3350
|
bool resized = false;
|
|
3220
|
-
if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
3221
|
-
hasPositionOffset(childNode
|
|
3222
|
-
hasPositionOffset(childNode
|
|
3223
|
-
int width = childAvailWidth - resolvedPositionOffsetWithBasis(childNode,
|
|
3224
|
-
childNode.
|
|
3351
|
+
if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression) &&
|
|
3352
|
+
hasPositionOffset<3>(childNode) &&
|
|
3353
|
+
hasPositionOffset<1>(childNode)) {
|
|
3354
|
+
int width = childAvailWidth - resolvedPositionOffsetWithBasis<3>(childNode, childAvailWidth) - resolvedPositionOffsetWithBasis<1>(childNode, childAvailWidth) -
|
|
3355
|
+
childNode.computedStyle().margin[1] - childNode.computedStyle().margin[3];
|
|
3225
3356
|
if (width < 0) width = 0;
|
|
3226
3357
|
width = clampLayoutSize(childNode, width, true);
|
|
3227
3358
|
if (childNode.layout.width != width) {
|
|
@@ -3230,11 +3361,11 @@ private:
|
|
|
3230
3361
|
}
|
|
3231
3362
|
}
|
|
3232
3363
|
|
|
3233
|
-
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
3234
|
-
hasPositionOffset(childNode
|
|
3235
|
-
hasPositionOffset(childNode
|
|
3236
|
-
int height = childAvailHeight - resolvedPositionOffsetWithBasis(childNode,
|
|
3237
|
-
childNode.
|
|
3364
|
+
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression) &&
|
|
3365
|
+
hasPositionOffset<0>(childNode) &&
|
|
3366
|
+
hasPositionOffset<2>(childNode)) {
|
|
3367
|
+
int height = childAvailHeight - resolvedPositionOffsetWithBasis<0>(childNode, childAvailHeight) - resolvedPositionOffsetWithBasis<2>(childNode, childAvailHeight) -
|
|
3368
|
+
childNode.computedStyle().margin[0] - childNode.computedStyle().margin[2];
|
|
3238
3369
|
if (height < 0) height = 0;
|
|
3239
3370
|
height = clampLayoutSize(childNode, height, false);
|
|
3240
3371
|
if (childNode.layout.height != height) {
|
|
@@ -3250,11 +3381,11 @@ private:
|
|
|
3250
3381
|
{
|
|
3251
3382
|
int x, y, width, height;
|
|
3252
3383
|
LayoutEngine::absoluteContainingArea(node_, childNode, x, y, width, height);
|
|
3253
|
-
if (hasPositionOffset(childNode
|
|
3254
|
-
else if (hasPositionOffset(childNode
|
|
3384
|
+
if (hasPositionOffset<3>(childNode)) childNode.layout.x = x + resolvedPositionOffsetWithBasis<3>(childNode, width) + childNode.computedStyle().margin[3];
|
|
3385
|
+
else if (hasPositionOffset<1>(childNode)) childNode.layout.x = x + width - childNode.layout.width - resolvedPositionOffsetWithBasis<1>(childNode, width) - childNode.computedStyle().margin[1];
|
|
3255
3386
|
else childNode.layout.x = alignedAbsoluteChildPosition(childNode, true);
|
|
3256
|
-
if (hasPositionOffset(childNode
|
|
3257
|
-
else if (hasPositionOffset(childNode
|
|
3387
|
+
if (hasPositionOffset<0>(childNode)) childNode.layout.y = y + resolvedPositionOffsetWithBasis<0>(childNode, height) + childNode.computedStyle().margin[0];
|
|
3388
|
+
else if (hasPositionOffset<2>(childNode)) childNode.layout.y = y + height - childNode.layout.height - resolvedPositionOffsetWithBasis<2>(childNode, height) - childNode.computedStyle().margin[2];
|
|
3258
3389
|
else childNode.layout.y = alignedAbsoluteChildPosition(childNode, false);
|
|
3259
3390
|
}
|
|
3260
3391
|
|
|
@@ -3269,43 +3400,47 @@ private:
|
|
|
3269
3400
|
for (int child = nodes_[parent].first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3270
3401
|
Node &childNode = nodes_[child];
|
|
3271
3402
|
if (splitInlineChildren_ && splitInlineWrapper(nodes_, child)) self(self, child);
|
|
3272
|
-
if (childNode.
|
|
3273
|
-
if (hasPositionOffset(childNode
|
|
3274
|
-
childNode.layout.y += resolvedRelativePositionOffset(childNode
|
|
3275
|
-
else if (hasPositionOffset(childNode
|
|
3276
|
-
childNode.layout.y -= resolvedRelativePositionOffset(childNode
|
|
3277
|
-
if (hasPositionOffset(childNode
|
|
3278
|
-
childNode.layout.x += resolvedRelativePositionOffset(childNode
|
|
3279
|
-
else if (hasPositionOffset(childNode
|
|
3280
|
-
childNode.layout.x -= resolvedRelativePositionOffset(childNode
|
|
3403
|
+
if (childNode.computedStyle().position != 2) continue;
|
|
3404
|
+
if (hasPositionOffset<0>(childNode))
|
|
3405
|
+
childNode.layout.y += resolvedRelativePositionOffset<0>(childNode);
|
|
3406
|
+
else if (hasPositionOffset<2>(childNode))
|
|
3407
|
+
childNode.layout.y -= resolvedRelativePositionOffset<2>(childNode);
|
|
3408
|
+
if (hasPositionOffset<3>(childNode))
|
|
3409
|
+
childNode.layout.x += resolvedRelativePositionOffset<3>(childNode);
|
|
3410
|
+
else if (hasPositionOffset<1>(childNode))
|
|
3411
|
+
childNode.layout.x -= resolvedRelativePositionOffset<1>(childNode);
|
|
3281
3412
|
}
|
|
3282
3413
|
};
|
|
3283
3414
|
apply(apply, id_);
|
|
3284
3415
|
}
|
|
3285
3416
|
|
|
3286
|
-
|
|
3417
|
+
template <int side>
|
|
3418
|
+
bool hasPositionOffset(const Node &node) const
|
|
3287
3419
|
{
|
|
3288
|
-
return node.
|
|
3420
|
+
return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
|
|
3289
3421
|
}
|
|
3290
3422
|
|
|
3291
|
-
|
|
3423
|
+
template <int side>
|
|
3424
|
+
int resolvedPositionOffset(const Node &node) const
|
|
3292
3425
|
{
|
|
3293
|
-
return resolvedPositionOffsetWithBasis(node,
|
|
3426
|
+
return resolvedPositionOffsetWithBasis<side>(node, (side == 0 || side == 2) ? node_.layout.height : node_.layout.width);
|
|
3294
3427
|
}
|
|
3295
3428
|
|
|
3296
|
-
|
|
3429
|
+
template <int side>
|
|
3430
|
+
int resolvedRelativePositionOffset(const Node &node) const
|
|
3297
3431
|
{
|
|
3298
3432
|
int basis = (side == 0 || side == 2) ? node_.layout.height : node_.layout.width;
|
|
3299
|
-
if (isDisplayGrid(node_.
|
|
3433
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
3300
3434
|
basis = (side == 0 || side == 2) ? node.layout.height : node.layout.width;
|
|
3301
3435
|
}
|
|
3302
|
-
return resolvedPositionOffsetWithBasis(node,
|
|
3436
|
+
return resolvedPositionOffsetWithBasis<side>(node, basis);
|
|
3303
3437
|
}
|
|
3304
3438
|
|
|
3305
|
-
|
|
3439
|
+
template <int side>
|
|
3440
|
+
int resolvedPositionOffsetWithBasis(const Node &node, int percentBasis) const
|
|
3306
3441
|
{
|
|
3307
|
-
int offset = node.
|
|
3308
|
-
const int percent = node.
|
|
3442
|
+
int offset = GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset ? GEA_CSS_POSITION_PX(node.computedStyle(), side) : 0;
|
|
3443
|
+
const int percent = GEA_CSS_POSITION_PERCENT(node.computedStyle(), side);
|
|
3309
3444
|
if (percent != kUnset) {
|
|
3310
3445
|
const int numerator = percentBasis * percent;
|
|
3311
3446
|
offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
|
|
@@ -3324,7 +3459,7 @@ private:
|
|
|
3324
3459
|
bool establishesTransformContainingBlock(const Node &node)
|
|
3325
3460
|
{
|
|
3326
3461
|
if (!ViewRenderer::isTransformableBox(node)) return false;
|
|
3327
|
-
const auto &r = rstyle(node.
|
|
3462
|
+
const auto &r = rstyle(node.computedStyle());
|
|
3328
3463
|
return r.translate_present || r.transform_present || r.rotate_present || r.scale_present || r.filter_present || r.transform_preserve_3d ||
|
|
3329
3464
|
r.transform_rotate || r.transform_rotate_x || r.transform_rotate_y ||
|
|
3330
3465
|
composedTranslateX(r) || composedTranslateY(r) || composedTranslateZ(r) ||
|
|
@@ -3334,12 +3469,12 @@ bool establishesTransformContainingBlock(const Node &node)
|
|
|
3334
3469
|
|
|
3335
3470
|
bool establishesAbsoluteContainingBlock(const Node &node)
|
|
3336
3471
|
{
|
|
3337
|
-
return isOutOfFlowPosition(node.
|
|
3472
|
+
return isOutOfFlowPosition(node.computedStyle().position) || node.computedStyle().position == 2 || establishesTransformContainingBlock(node);
|
|
3338
3473
|
}
|
|
3339
3474
|
|
|
3340
3475
|
int containingBlockForAbsoluteNode(int node, int root, Node *nodes)
|
|
3341
3476
|
{
|
|
3342
|
-
if (nodes[node].
|
|
3477
|
+
if (nodes[node].computedStyle().position == kPositionFixed) {
|
|
3343
3478
|
const int fixed = LayoutEngine::fixedContainingBlock(nodes[node]);
|
|
3344
3479
|
return fixed >= 0 ? fixed : root;
|
|
3345
3480
|
}
|
|
@@ -3349,15 +3484,17 @@ int containingBlockForAbsoluteNode(int node, int root, Node *nodes)
|
|
|
3349
3484
|
return root;
|
|
3350
3485
|
}
|
|
3351
3486
|
|
|
3352
|
-
|
|
3487
|
+
template <int side>
|
|
3488
|
+
bool hasPositionOffsetValue(const Node &node)
|
|
3353
3489
|
{
|
|
3354
|
-
return node.
|
|
3490
|
+
return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
|
|
3355
3491
|
}
|
|
3356
3492
|
|
|
3357
|
-
|
|
3493
|
+
template <int side>
|
|
3494
|
+
int resolvedPositionOffsetForBasis(const Node &node, int percentBasis)
|
|
3358
3495
|
{
|
|
3359
|
-
int offset = node.
|
|
3360
|
-
const int percent = node.
|
|
3496
|
+
int offset = GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset ? GEA_CSS_POSITION_PX(node.computedStyle(), side) : 0;
|
|
3497
|
+
const int percent = GEA_CSS_POSITION_PERCENT(node.computedStyle(), side);
|
|
3361
3498
|
if (percent != kUnset) {
|
|
3362
3499
|
const int numerator = percentBasis * percent;
|
|
3363
3500
|
offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
|
|
@@ -3373,8 +3510,8 @@ void offsetFromAncestorToNode(int ancestor, int node, Node *nodes, int *outX, in
|
|
|
3373
3510
|
const Node ¤t = nodes[cursor];
|
|
3374
3511
|
x += current.layout.x;
|
|
3375
3512
|
y += current.layout.y;
|
|
3376
|
-
if (scrollsOverflowX(current.
|
|
3377
|
-
if (scrollsOverflowY(current.
|
|
3513
|
+
if (scrollsOverflowX(current.computedStyle())) x -= current.layout.scroll_x;
|
|
3514
|
+
if (scrollsOverflowY(current.computedStyle())) y -= current.layout.scroll_y;
|
|
3378
3515
|
}
|
|
3379
3516
|
*outX = x;
|
|
3380
3517
|
*outY = y;
|
|
@@ -3384,13 +3521,13 @@ void stretchAbsoluteNodeToContainingBlock(int node, int containingWidth, int con
|
|
|
3384
3521
|
{
|
|
3385
3522
|
Node &absolute = nodes[node];
|
|
3386
3523
|
bool resized = false;
|
|
3387
|
-
if (!hasExplicitWidth(absolute) && !isIntrinsicSizeExpression(absolute.
|
|
3388
|
-
hasPositionOffsetValue(absolute
|
|
3389
|
-
hasPositionOffsetValue(absolute
|
|
3524
|
+
if (!hasExplicitWidth(absolute) && !isIntrinsicSizeExpression(absolute.computedStyle().width_expression) &&
|
|
3525
|
+
hasPositionOffsetValue<3>(absolute) &&
|
|
3526
|
+
hasPositionOffsetValue<1>(absolute)) {
|
|
3390
3527
|
int width = containingWidth -
|
|
3391
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3392
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3393
|
-
absolute.
|
|
3528
|
+
resolvedPositionOffsetForBasis<3>(absolute, containingWidth) -
|
|
3529
|
+
resolvedPositionOffsetForBasis<1>(absolute, containingWidth) -
|
|
3530
|
+
absolute.computedStyle().margin[1] - absolute.computedStyle().margin[3];
|
|
3394
3531
|
if (width < 0) width = 0;
|
|
3395
3532
|
width = clampLayoutSize(absolute, width, true);
|
|
3396
3533
|
if (absolute.layout.width != width) {
|
|
@@ -3399,13 +3536,13 @@ void stretchAbsoluteNodeToContainingBlock(int node, int containingWidth, int con
|
|
|
3399
3536
|
}
|
|
3400
3537
|
}
|
|
3401
3538
|
|
|
3402
|
-
if (!hasExplicitHeight(absolute) && !isIntrinsicSizeExpression(absolute.
|
|
3403
|
-
hasPositionOffsetValue(absolute
|
|
3404
|
-
hasPositionOffsetValue(absolute
|
|
3539
|
+
if (!hasExplicitHeight(absolute) && !isIntrinsicSizeExpression(absolute.computedStyle().height_expression) &&
|
|
3540
|
+
hasPositionOffsetValue<0>(absolute) &&
|
|
3541
|
+
hasPositionOffsetValue<2>(absolute)) {
|
|
3405
3542
|
int height = containingHeight -
|
|
3406
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3407
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3408
|
-
absolute.
|
|
3543
|
+
resolvedPositionOffsetForBasis<0>(absolute, containingHeight) -
|
|
3544
|
+
resolvedPositionOffsetForBasis<2>(absolute, containingHeight) -
|
|
3545
|
+
absolute.computedStyle().margin[0] - absolute.computedStyle().margin[2];
|
|
3409
3546
|
if (height < 0) height = 0;
|
|
3410
3547
|
height = clampLayoutSize(absolute, height, false);
|
|
3411
3548
|
if (absolute.layout.height != height) {
|
|
@@ -3421,9 +3558,9 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
|
|
|
3421
3558
|
{
|
|
3422
3559
|
Node &absolute = nodes[node];
|
|
3423
3560
|
auto &engine = LayoutEngine::instance();
|
|
3424
|
-
const bool left = hasPositionOffsetValue(absolute
|
|
3561
|
+
const bool left = hasPositionOffsetValue<3>(absolute), right = hasPositionOffsetValue<1>(absolute);
|
|
3425
3562
|
if (absolute.type != NodeType::View || writingMode(absolute) != 0 ||
|
|
3426
|
-
hasExplicitWidth(absolute) || isIntrinsicSizeExpression(absolute.
|
|
3563
|
+
hasExplicitWidth(absolute) || isIntrinsicSizeExpression(absolute.computedStyle().width_expression) ||
|
|
3427
3564
|
(left && right) || (preferredRatio(absolute) > 0 && hasExplicitHeight(absolute))) {
|
|
3428
3565
|
engine.layoutNode(node, areaWidth, areaHeight);
|
|
3429
3566
|
return;
|
|
@@ -3433,23 +3570,25 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
|
|
|
3433
3570
|
// containing width for percentages during the final used-width layout.
|
|
3434
3571
|
IntrinsicSizeScope scope(absolute, 1);
|
|
3435
3572
|
engine.layoutNode(node, 1, areaHeight, true);
|
|
3436
|
-
const int minimum = std::max(0, absolute.layout.width - boxInsets(absolute.
|
|
3573
|
+
const int minimum = std::max(0, absolute.layout.width - boxInsets(absolute.computedStyle(), true));
|
|
3437
3574
|
scope.constraint = 2;
|
|
3438
3575
|
engine.layoutNode(node, 32767, areaHeight, true);
|
|
3439
|
-
const int maximum = std::max(minimum, absolute.layout.width - boxInsets(absolute.
|
|
3576
|
+
const int maximum = std::max(minimum, absolute.layout.width - boxInsets(absolute.computedStyle(), true));
|
|
3577
|
+
#if GEA_CSS_BOX_EXPRESSIONS
|
|
3440
3578
|
resolveLayoutBoxLengths(node, areaWidth);
|
|
3441
|
-
|
|
3579
|
+
#endif
|
|
3580
|
+
int available = areaWidth - absolute.computedStyle().margin[3] - absolute.computedStyle().margin[1];
|
|
3442
3581
|
if (left || right) {
|
|
3443
|
-
available -=
|
|
3582
|
+
available -= (left ? resolvedPositionOffsetForBasis<3>(absolute, areaWidth) : resolvedPositionOffsetForBasis<1>(absolute, areaWidth));
|
|
3444
3583
|
} else {
|
|
3445
3584
|
int parentX = 0, parentY = 0;
|
|
3446
3585
|
offsetFromAncestorToNode(containing, absolute.parent, nodes, &parentX, &parentY);
|
|
3447
3586
|
const int staticX = parentX + engine.alignedAbsoluteOffset(nodes[absolute.parent], absolute, true);
|
|
3448
3587
|
available = rightToLeft(nodes[absolute.parent])
|
|
3449
|
-
? staticX + absolute.layout.width - areaX - absolute.
|
|
3450
|
-
: areaX + areaWidth - staticX - absolute.
|
|
3588
|
+
? staticX + absolute.layout.width - areaX - absolute.computedStyle().margin[3]
|
|
3589
|
+
: areaX + areaWidth - staticX - absolute.computedStyle().margin[1];
|
|
3451
3590
|
}
|
|
3452
|
-
const int edges = boxInsets(absolute.
|
|
3591
|
+
const int edges = boxInsets(absolute.computedStyle(), true);
|
|
3453
3592
|
scope.borderSize = edges + std::min(maximum, std::max(minimum, available - edges));
|
|
3454
3593
|
scope.constraint = 0;
|
|
3455
3594
|
engine.layoutNode(node, areaWidth, areaHeight);
|
|
@@ -3462,8 +3601,9 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3462
3601
|
const int parent = absolute.parent;
|
|
3463
3602
|
if (parent < 0) return;
|
|
3464
3603
|
if (LayoutEngine::isViewportFixed(absolute)) {
|
|
3465
|
-
const
|
|
3466
|
-
const int
|
|
3604
|
+
const auto &persistent = layoutState(containing);
|
|
3605
|
+
const int width = persistent.memo_avail_w;
|
|
3606
|
+
const int height = persistent.memo_avail_h;
|
|
3467
3607
|
LayoutEngine::instance().layoutNode(node, width, height);
|
|
3468
3608
|
stretchAbsoluteNodeToContainingBlock(node, width, height, nodes);
|
|
3469
3609
|
int staticX = LayoutEngine::alignedAbsoluteOffset(nodes[parent], absolute, true);
|
|
@@ -3472,10 +3612,10 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3472
3612
|
staticX += nodes[id].layout.x; staticY += nodes[id].layout.y;
|
|
3473
3613
|
if (LayoutEngine::isViewportFixed(nodes[id])) break;
|
|
3474
3614
|
}
|
|
3475
|
-
absolute.layout.x = hasPositionOffsetValue(absolute
|
|
3476
|
-
: hasPositionOffsetValue(absolute
|
|
3477
|
-
absolute.layout.y = hasPositionOffsetValue(absolute
|
|
3478
|
-
: hasPositionOffsetValue(absolute
|
|
3615
|
+
absolute.layout.x = hasPositionOffsetValue<3>(absolute) ? resolvedPositionOffsetForBasis<3>(absolute, width) + absolute.computedStyle().margin[3]
|
|
3616
|
+
: hasPositionOffsetValue<1>(absolute) ? width - absolute.layout.width - resolvedPositionOffsetForBasis<1>(absolute, width) - absolute.computedStyle().margin[1] : staticX;
|
|
3617
|
+
absolute.layout.y = hasPositionOffsetValue<0>(absolute) ? resolvedPositionOffsetForBasis<0>(absolute, height) + absolute.computedStyle().margin[0]
|
|
3618
|
+
: hasPositionOffsetValue<2>(absolute) ? height - absolute.layout.height - resolvedPositionOffsetForBasis<2>(absolute, height) - absolute.computedStyle().margin[2] : staticY;
|
|
3479
3619
|
return;
|
|
3480
3620
|
}
|
|
3481
3621
|
|
|
@@ -3491,24 +3631,24 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3491
3631
|
stretchAbsoluteNodeToContainingBlock(node, areaWidth, areaHeight, nodes);
|
|
3492
3632
|
int parentOffsetX = 0, parentOffsetY = 0;
|
|
3493
3633
|
offsetFromAncestorToNode(containing, parent, nodes, &parentOffsetX, &parentOffsetY);
|
|
3494
|
-
if (!hasPositionOffsetValue(absolute
|
|
3634
|
+
if (!hasPositionOffsetValue<3>(absolute) && !hasPositionOffsetValue<1>(absolute))
|
|
3495
3635
|
absolute.layout.x = LayoutEngine::alignedAbsoluteOffset(nodes[parent], absolute, true, &containingNode, areaX - parentOffsetX, areaWidth);
|
|
3496
|
-
if (!hasPositionOffsetValue(absolute
|
|
3636
|
+
if (!hasPositionOffsetValue<0>(absolute) && !hasPositionOffsetValue<2>(absolute))
|
|
3497
3637
|
absolute.layout.y = LayoutEngine::alignedAbsoluteOffset(nodes[parent], absolute, false, &containingNode, areaY - parentOffsetY, areaHeight);
|
|
3498
3638
|
|
|
3499
3639
|
int containingX = absolute.layout.x + parentOffsetX;
|
|
3500
|
-
if (hasPositionOffsetValue(absolute
|
|
3501
|
-
containingX = areaX + resolvedPositionOffsetForBasis(absolute,
|
|
3502
|
-
else if (hasPositionOffsetValue(absolute
|
|
3640
|
+
if (hasPositionOffsetValue<3>(absolute))
|
|
3641
|
+
containingX = areaX + resolvedPositionOffsetForBasis<3>(absolute, areaWidth) + absolute.computedStyle().margin[3];
|
|
3642
|
+
else if (hasPositionOffsetValue<1>(absolute))
|
|
3503
3643
|
containingX = areaX + areaWidth - absolute.layout.width -
|
|
3504
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3644
|
+
resolvedPositionOffsetForBasis<1>(absolute, areaWidth) - absolute.computedStyle().margin[1];
|
|
3505
3645
|
|
|
3506
3646
|
int containingY = absolute.layout.y + parentOffsetY;
|
|
3507
|
-
if (hasPositionOffsetValue(absolute
|
|
3508
|
-
containingY = areaY + resolvedPositionOffsetForBasis(absolute,
|
|
3509
|
-
else if (hasPositionOffsetValue(absolute
|
|
3647
|
+
if (hasPositionOffsetValue<0>(absolute))
|
|
3648
|
+
containingY = areaY + resolvedPositionOffsetForBasis<0>(absolute, areaHeight) + absolute.computedStyle().margin[0];
|
|
3649
|
+
else if (hasPositionOffsetValue<2>(absolute))
|
|
3510
3650
|
containingY = areaY + areaHeight - absolute.layout.height -
|
|
3511
|
-
resolvedPositionOffsetForBasis(absolute,
|
|
3651
|
+
resolvedPositionOffsetForBasis<2>(absolute, areaHeight) - absolute.computedStyle().margin[2];
|
|
3512
3652
|
|
|
3513
3653
|
absolute.layout.x = containingX - parentOffsetX;
|
|
3514
3654
|
absolute.layout.y = containingY - parentOffsetY;
|
|
@@ -3517,8 +3657,8 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3517
3657
|
void resolvePositionedDescendants(int node, int root, Node *nodes)
|
|
3518
3658
|
{
|
|
3519
3659
|
for (int child = nodes[node].first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
3520
|
-
if (isDisplayNone(nodes[child].
|
|
3521
|
-
if (isOutOfFlowPosition(nodes[child].
|
|
3660
|
+
if (isDisplayNone(nodes[child].computedStyle())) continue;
|
|
3661
|
+
if (isOutOfFlowPosition(nodes[child].computedStyle().position))
|
|
3522
3662
|
positionAbsoluteNodeInContainingBlock(child, containingBlockForAbsoluteNode(child, root, nodes), nodes);
|
|
3523
3663
|
resolvePositionedDescendants(child, root, nodes);
|
|
3524
3664
|
}
|
|
@@ -3548,7 +3688,7 @@ int LayoutEngine::fixedContainingBlock(const Node &node)
|
|
|
3548
3688
|
|
|
3549
3689
|
bool LayoutEngine::isViewportFixed(const Node &node)
|
|
3550
3690
|
{
|
|
3551
|
-
return node.
|
|
3691
|
+
return node.computedStyle().position == kPositionFixed && fixedContainingBlock(node) < 0;
|
|
3552
3692
|
}
|
|
3553
3693
|
|
|
3554
3694
|
bool LayoutEngine::containsViewportFixed(int node)
|
|
@@ -3569,23 +3709,25 @@ void LayoutEngine::absoluteContainingArea(const Node &parent, const Node &child,
|
|
|
3569
3709
|
// The initial containing block is viewport-sized, even when the HTML
|
|
3570
3710
|
// element has an auto height, margins, or an explicit smaller size.
|
|
3571
3711
|
x = -parent.layout.x; y = -parent.layout.y;
|
|
3572
|
-
|
|
3712
|
+
const auto &persistent = layoutState(static_cast<int>(&parent - Tree::instance().nodes()));
|
|
3713
|
+
width = persistent.memo_avail_w; height = persistent.memo_avail_h;
|
|
3573
3714
|
return;
|
|
3574
3715
|
}
|
|
3575
|
-
if (establishesAbsoluteContainingBlock(parent) || child.
|
|
3716
|
+
if (establishesAbsoluteContainingBlock(parent) || child.computedStyle().position == kPositionFixed) {
|
|
3576
3717
|
// Insets and percentages reference the padding box, excluding borders.
|
|
3577
|
-
x = boxInset(parent.
|
|
3578
|
-
y = boxInset(parent.
|
|
3579
|
-
width = std::max(0, width - x - boxInset(parent.
|
|
3580
|
-
height = std::max(0, height - y - boxInset(parent.
|
|
3718
|
+
x = boxInset(parent.computedStyle(), 3) - parent.computedStyle().padding[3];
|
|
3719
|
+
y = boxInset(parent.computedStyle(), 0) - parent.computedStyle().padding[0];
|
|
3720
|
+
width = std::max(0, width - x - boxInset(parent.computedStyle(), 1) + parent.computedStyle().padding[1]);
|
|
3721
|
+
height = std::max(0, height - y - boxInset(parent.computedStyle(), 2) + parent.computedStyle().padding[2]);
|
|
3581
3722
|
}
|
|
3582
3723
|
absoluteGridArea(parent, child, x, y, width, height);
|
|
3583
3724
|
}
|
|
3584
3725
|
|
|
3585
3726
|
bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height)
|
|
3586
3727
|
{
|
|
3587
|
-
|
|
3588
|
-
if (
|
|
3728
|
+
#if GEA_CSS_GRID
|
|
3729
|
+
if (!isDisplayGrid(parent.computedStyle())) return false;
|
|
3730
|
+
if (child.computedStyle().position == kPositionFixed) {
|
|
3589
3731
|
if (fixedContainingBlock(child) != &parent - Tree::instance().nodes()) return false;
|
|
3590
3732
|
} else if (!establishesAbsoluteContainingBlock(parent)) return false;
|
|
3591
3733
|
const auto *rare = rareDataFor(static_cast<int>(&parent - Tree::instance().nodes()));
|
|
@@ -3593,8 +3735,8 @@ bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &
|
|
|
3593
3735
|
const bool vertical = writingMode(parent) != 0;
|
|
3594
3736
|
for (bool columns : {true, false}) {
|
|
3595
3737
|
const bool horizontal = columns != vertical;
|
|
3596
|
-
const int explicitCount = columns ? rstyle(parent.
|
|
3597
|
-
const auto &lines = rstyle(child.
|
|
3738
|
+
const int explicitCount = columns ? rstyle(parent.computedStyle()).grid_column_count : rstyle(parent.computedStyle()).grid_row_count;
|
|
3739
|
+
const auto &lines = rstyle(child.computedStyle()).grid_line;
|
|
3598
3740
|
const std::vector<int> *starts = tracks ? (columns ? &tracks->columnStart : &tracks->rowStart) : nullptr;
|
|
3599
3741
|
const std::vector<int> *ends = tracks ? (columns ? &tracks->columnEnd : &tracks->rowEnd) : nullptr;
|
|
3600
3742
|
const int origin = tracks ? (columns ? tracks->columnOrigin : tracks->rowOrigin) : 0;
|
|
@@ -3609,10 +3751,10 @@ bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &
|
|
|
3609
3751
|
};
|
|
3610
3752
|
auto placement = gridAxisPlacement(validLine(lines[columns ? 1 : 0]), validLine(lines[columns ? 3 : 2]), explicitCount, true);
|
|
3611
3753
|
const bool hasStart = existing(placement.start), hasEnd = existing(placement.end);
|
|
3612
|
-
const int available = (horizontal ? parent.layout.width : parent.layout.height) - boxInsets(parent.
|
|
3754
|
+
const int available = (horizontal ? parent.layout.width : parent.layout.height) - boxInsets(parent.computedStyle(), horizontal);
|
|
3613
3755
|
int beforeSide = horizontal ? 3 : 0, afterSide = horizontal ? 1 : 2;
|
|
3614
3756
|
if (gridAxisReversed(parent, horizontal)) std::swap(beforeSide, afterSide);
|
|
3615
|
-
int start = -parent.
|
|
3757
|
+
int start = -parent.computedStyle().padding[beforeSide], end = available + parent.computedStyle().padding[afterSide];
|
|
3616
3758
|
if (hasStart) {
|
|
3617
3759
|
const int index = placement.start + origin;
|
|
3618
3760
|
start = count == 0 ? 0 : index == count ? ends->back() : (*starts)[index];
|
|
@@ -3624,6 +3766,15 @@ bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &
|
|
|
3624
3766
|
gridPhysicalRange(parent, columns, start, std::max(start, end), horizontal ? x : y, horizontal ? width : height);
|
|
3625
3767
|
}
|
|
3626
3768
|
return true;
|
|
3769
|
+
#else
|
|
3770
|
+
(void)parent;
|
|
3771
|
+
(void)child;
|
|
3772
|
+
(void)x;
|
|
3773
|
+
(void)y;
|
|
3774
|
+
(void)width;
|
|
3775
|
+
(void)height;
|
|
3776
|
+
return false;
|
|
3777
|
+
#endif
|
|
3627
3778
|
}
|
|
3628
3779
|
|
|
3629
3780
|
int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNode, bool horizontal,
|
|
@@ -3644,37 +3795,38 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3644
3795
|
inlineOffset += treeNodes[cursor].layout.x;
|
|
3645
3796
|
cursor = treeNodes[cursor].parent;
|
|
3646
3797
|
}
|
|
3647
|
-
if (cursor >= 0) continuationOrigin = boxInset(treeNodes[cursor].
|
|
3798
|
+
if (cursor >= 0) continuationOrigin = boxInset(treeNodes[cursor].computedStyle(), 3) - inlineOffset;
|
|
3648
3799
|
}
|
|
3649
|
-
return (horizontal ? rare->inlineStaticPosition.x + continuationOrigin + childNode.
|
|
3650
|
-
: rare->inlineStaticPosition.y + childNode.
|
|
3800
|
+
return (horizontal ? rare->inlineStaticPosition.x + continuationOrigin + childNode.computedStyle().margin[3]
|
|
3801
|
+
: rare->inlineStaticPosition.y + childNode.computedStyle().margin[0]);
|
|
3651
3802
|
}
|
|
3652
|
-
|
|
3653
|
-
|
|
3803
|
+
const auto &persistent = layoutState(childId);
|
|
3804
|
+
if (parent.computedStyle().display == kDisplayBlock && !parent.computedStyle().flex_direction_explicit &&
|
|
3805
|
+
persistent.static_block_axis == (horizontal ? 2 : 1)) {
|
|
3654
3806
|
const bool reversed = horizontal && gridAxisReversed(parent, true);
|
|
3655
|
-
return
|
|
3656
|
-
: childNode.
|
|
3807
|
+
return persistent.static_block_start + (reversed ? -childNode.layout.width - childNode.computedStyle().margin[1]
|
|
3808
|
+
: childNode.computedStyle().margin[horizontal ? 3 : 0]);
|
|
3657
3809
|
}
|
|
3658
3810
|
// In block layout the hypothetical box starts at the parent's inline
|
|
3659
3811
|
// content edge. RTL anchors its inline-end margin edge, even when the absolute
|
|
3660
3812
|
// box is wider than its static-position parent. Its actual containing
|
|
3661
3813
|
// block can be an entirely different ancestor.
|
|
3662
|
-
if (horizontal == (writingMode(parent) == 0) && parent.
|
|
3663
|
-
(!isInlineLevelNode(parent) || isOutOfFlowPosition(parent.
|
|
3664
|
-
!parent.
|
|
3814
|
+
if (horizontal == (writingMode(parent) == 0) && parent.computedStyle().display == kDisplayBlock &&
|
|
3815
|
+
(!isInlineLevelNode(parent) || isOutOfFlowPosition(parent.computedStyle().position)) &&
|
|
3816
|
+
!parent.computedStyle().flex_direction_explicit) {
|
|
3665
3817
|
return rightToLeft(parent)
|
|
3666
|
-
? (horizontal ? parent.layout.width : parent.layout.height) - boxInset(parent.
|
|
3667
|
-
(horizontal ? childNode.layout.width : childNode.layout.height) - childNode.
|
|
3668
|
-
: boxInset(parent.
|
|
3669
|
-
}
|
|
3670
|
-
const bool grid = isDisplayGrid(parent.
|
|
3671
|
-
const bool row = flex ? flexRowDirection(parent.
|
|
3672
|
-
const int crossAlign = childNode.
|
|
3673
|
-
const int inlineAlign = rstyle(childNode.
|
|
3818
|
+
? (horizontal ? parent.layout.width : parent.layout.height) - boxInset(parent.computedStyle(), horizontal ? 1 : 2) -
|
|
3819
|
+
(horizontal ? childNode.layout.width : childNode.layout.height) - childNode.computedStyle().margin[horizontal ? 1 : 2]
|
|
3820
|
+
: boxInset(parent.computedStyle(), horizontal ? 3 : 0) + childNode.computedStyle().margin[horizontal ? 3 : 0];
|
|
3821
|
+
}
|
|
3822
|
+
const bool grid = isDisplayGrid(parent.computedStyle()), flex = parent.computedStyle().display == kDisplayFlex;
|
|
3823
|
+
const bool row = flex ? flexRowDirection(parent.computedStyle()) != (writingMode(parent) != 0) : usesRowLayout(parent.computedStyle());
|
|
3824
|
+
const int crossAlign = childNode.computedStyle().align_self >= 0 ? childNode.computedStyle().align_self : parent.computedStyle().align_items;
|
|
3825
|
+
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? rstyle(childNode.computedStyle()).justify_self : -1) >= 0 ? (GEA_CSS_JUSTIFY_SELF ? rstyle(childNode.computedStyle()).justify_self : -1) : parent.computedStyle().justify_items;
|
|
3674
3826
|
int align = grid
|
|
3675
3827
|
? (horizontal == (writingMode(parent) == 0) ? inlineAlign : crossAlign)
|
|
3676
|
-
: (horizontal ? (row ? parent.
|
|
3677
|
-
: (row ? crossAlign : parent.
|
|
3828
|
+
: (horizontal ? (row ? parent.computedStyle().justify_content : crossAlign)
|
|
3829
|
+
: (row ? crossAlign : parent.computedStyle().justify_content));
|
|
3678
3830
|
if (flex && horizontal == row && isDistributedAlignment(align)) {
|
|
3679
3831
|
// Static position lays out the absolute box as the sole hypothetical
|
|
3680
3832
|
// flex item: between falls back to flex-start, around/evenly to center.
|
|
@@ -3683,17 +3835,17 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3683
3835
|
}
|
|
3684
3836
|
// A grid supplies its content box when the containing block is outside
|
|
3685
3837
|
// it; when it is the containing block, grid placement supplies the area.
|
|
3686
|
-
int inset = grid || flex ? boxInset(parent.
|
|
3838
|
+
int inset = grid || flex ? boxInset(parent.computedStyle(), horizontal ? 3 : 0) : 0;
|
|
3687
3839
|
int parentSize = (horizontal ? parent.layout.width : parent.layout.height) -
|
|
3688
|
-
(grid || flex ? boxInsets(parent.
|
|
3840
|
+
(grid || flex ? boxInsets(parent.computedStyle(), horizontal) : 0);
|
|
3689
3841
|
int areaX, areaY, areaWidth, areaHeight;
|
|
3690
3842
|
if (absoluteGridArea(parent, childNode, areaX, areaY, areaWidth, areaHeight)) {
|
|
3691
3843
|
inset = horizontal ? areaX : areaY;
|
|
3692
3844
|
parentSize = horizontal ? areaWidth : areaHeight;
|
|
3693
3845
|
}
|
|
3694
3846
|
const int childSize = horizontal ? childNode.layout.width : childNode.layout.height;
|
|
3695
|
-
const int beforeMargin = horizontal ? childNode.
|
|
3696
|
-
const int afterMargin = horizontal ? childNode.
|
|
3847
|
+
const int beforeMargin = horizontal ? childNode.computedStyle().margin[3] : childNode.computedStyle().margin[0];
|
|
3848
|
+
const int afterMargin = horizontal ? childNode.computedStyle().margin[1] : childNode.computedStyle().margin[2];
|
|
3697
3849
|
int available = parentSize;
|
|
3698
3850
|
if (available < 0) available = 0;
|
|
3699
3851
|
const int occupied = childSize + beforeMargin + afterMargin;
|
|
@@ -3709,7 +3861,7 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3709
3861
|
: self >= 0 ? self : baseline ? baselineFallbackAlignment(parent, childNode, pointAlignment, free, horizontal, true)
|
|
3710
3862
|
: usedAlignment(pointAlignment, free);
|
|
3711
3863
|
const int keyword = align & 15;
|
|
3712
|
-
if (flex && horizontal == row && parent.
|
|
3864
|
+
if (flex && horizontal == row && parent.computedStyle().flex_direction_explicit && parent.computedStyle().flex_direction >= 2 &&
|
|
3713
3865
|
(keyword == 0 || keyword == 2 || keyword == 6)) used = used == 2 ? 6 : 2;
|
|
3714
3866
|
int position = inset + beforeMargin;
|
|
3715
3867
|
if (used == 1) position += free / 2;
|
|
@@ -3759,7 +3911,7 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3759
3911
|
|
|
3760
3912
|
bool LayoutEngine::isInlineLevelNode(const Node &n)
|
|
3761
3913
|
{
|
|
3762
|
-
if (n.
|
|
3914
|
+
if (n.computedStyle().display == kDisplayFlex || n.computedStyle().display == kDisplayGrid || n.computedStyle().display == kDisplayNone)
|
|
3763
3915
|
return false;
|
|
3764
3916
|
// An explicit `display:block` makes even an inline-level tag (a <span>) — or a
|
|
3765
3917
|
// Text/Image node — a BLOCK-LEVEL box, so it stacks vertically among siblings
|
|
@@ -3767,23 +3919,23 @@ bool LayoutEngine::isInlineLevelNode(const Node &n)
|
|
|
3767
3919
|
// the weather city list's .city-name/.city-detail spans set display:block to
|
|
3768
3920
|
// stack the name over the region). Without an explicit display, fall back to
|
|
3769
3921
|
// the tag's intrinsic inline-ness.
|
|
3770
|
-
if (n.
|
|
3922
|
+
if (n.computedStyle().display == kDisplayBlock && n.computedStyle().display_explicit) return false;
|
|
3771
3923
|
// In Gea's native layout model, vertical margins on inline-level wrappers are
|
|
3772
3924
|
// used as an authoring signal that the wrapper occupies its own line. Keep
|
|
3773
3925
|
// default spans inline, but do not merge title/score spans with margin-bottom
|
|
3774
3926
|
// into one row.
|
|
3775
|
-
if (n.
|
|
3927
|
+
if (n.computedStyle().margin[0] != 0 || n.computedStyle().margin[2] != 0) return false;
|
|
3776
3928
|
if (n.type == NodeType::Text || n.type == NodeType::Image) return true;
|
|
3777
3929
|
return isInlineLevelTag(tagFromId(n.tag_id));
|
|
3778
3930
|
}
|
|
3779
3931
|
|
|
3780
3932
|
bool LayoutEngine::isCssInlineLevelBox(const Node &n, bool hypothetical)
|
|
3781
3933
|
{
|
|
3782
|
-
if (n.
|
|
3783
|
-
if (!hypothetical && (n.
|
|
3934
|
+
if (n.computedStyle().display == kDisplayNone || n.computedStyle().display_explicit) return false;
|
|
3935
|
+
if (!hypothetical && (n.computedStyle().float_side || isOutOfFlowPosition(n.computedStyle().position))) return false;
|
|
3784
3936
|
if (!hypothetical && n.parent >= 0) {
|
|
3785
3937
|
const Node &parent = Tree::instance().nodes()[n.parent];
|
|
3786
|
-
if (parent.
|
|
3938
|
+
if (parent.computedStyle().display == kDisplayFlex || isDisplayGrid(parent.computedStyle())) return false;
|
|
3787
3939
|
}
|
|
3788
3940
|
if (n.type == NodeType::Text || n.type == NodeType::Image) return true;
|
|
3789
3941
|
return n.type == NodeType::View && isInlineLevelTag(tagFromId(n.tag_id));
|
|
@@ -3801,17 +3953,17 @@ int LayoutEngine::collectChildren(int parent, int *out, int max, bool skipAbs) c
|
|
|
3801
3953
|
int n = 0;
|
|
3802
3954
|
Node *nodes = Tree::instance().nodes();
|
|
3803
3955
|
for (int child = nodes[parent].first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
3804
|
-
if (isDisplayNone(nodes[child].
|
|
3956
|
+
if (isDisplayNone(nodes[child].computedStyle())) continue;
|
|
3805
3957
|
if (suppressAnonymousWhitespace(nodes, parent, child)) continue;
|
|
3806
|
-
if (skipAbs && isOutOfFlowPosition(nodes[child].
|
|
3958
|
+
if (skipAbs && isOutOfFlowPosition(nodes[child].computedStyle().position)) continue;
|
|
3807
3959
|
if (n < max) out[n++] = child;
|
|
3808
3960
|
}
|
|
3809
3961
|
// All consumers (layout, painting, and hit testing) start from this stable
|
|
3810
3962
|
// order. Subsequent stable z-index/depth sorting preserves it for ties.
|
|
3811
3963
|
// Absolutely positioned children have order 0 for painting and are excluded
|
|
3812
3964
|
// by skipAbs when collecting actual flex/grid items for layout.
|
|
3813
|
-
if (nodes[parent].
|
|
3814
|
-
auto order = [&](int child) { return isOutOfFlowPosition(nodes[child].
|
|
3965
|
+
if (nodes[parent].computedStyle().display == kDisplayFlex || isDisplayGrid(nodes[parent].computedStyle())) {
|
|
3966
|
+
auto order = [&](int child) { return isOutOfFlowPosition(nodes[child].computedStyle().position) ? 0 : nodes[child].computedStyle().order; };
|
|
3815
3967
|
for (int i = 1; i < n; ++i) {
|
|
3816
3968
|
const int child = out[i];
|
|
3817
3969
|
int j = i;
|
|
@@ -3826,27 +3978,151 @@ int LayoutEngine::collectChildren(int parent, int *out, int max, bool skipAbs) c
|
|
|
3826
3978
|
}
|
|
3827
3979
|
|
|
3828
3980
|
namespace {
|
|
3829
|
-
//
|
|
3830
|
-
//
|
|
3831
|
-
|
|
3981
|
+
// Neither result dimensions nor the second available box are used across
|
|
3982
|
+
// passes. Keep this allocation alive through absolute-coordinate resolution,
|
|
3983
|
+
// which can itself re-enter layoutNode(). Retained frames allocate nothing.
|
|
3984
|
+
struct LayoutPassMemo {
|
|
3985
|
+
int16_t result_w, result_h;
|
|
3986
|
+
int16_t avail2_w, avail2_h;
|
|
3987
|
+
// The whole array is zeroed for each pass, so two validity bytes replace
|
|
3988
|
+
// generation tags without a global counter or periodic invalidation scan.
|
|
3989
|
+
uint8_t valid1, valid2;
|
|
3990
|
+
};
|
|
3991
|
+
static_assert(sizeof(LayoutPassMemo) == 10);
|
|
3992
|
+
LayoutPassMemo *gLayoutMemo = nullptr;
|
|
3993
|
+
int gLayoutMemoCapacity = 0;
|
|
3994
|
+
std::size_t gLayoutMemoPeakBytes = 0;
|
|
3832
3995
|
} // namespace
|
|
3833
3996
|
|
|
3834
3997
|
void LayoutEngine::beginLayoutPass()
|
|
3835
3998
|
{
|
|
3836
|
-
|
|
3999
|
+
endLayoutPass();
|
|
4000
|
+
gLayoutMemoCapacity = Tree::instance().nodeCount();
|
|
4001
|
+
const std::size_t bytes = sizeof(LayoutPassMemo) * gLayoutMemoCapacity;
|
|
4002
|
+
gLayoutMemo = bytes ? static_cast<LayoutPassMemo *>(gea::framework::memory::Allocator::allocatePreferSpiram(bytes)) : nullptr;
|
|
4003
|
+
if (gLayoutMemo) {
|
|
4004
|
+
std::memset(gLayoutMemo, 0, bytes);
|
|
4005
|
+
#if defined(ESP_PLATFORM)
|
|
4006
|
+
const auto heapBytes = heap_caps_get_allocated_size(gLayoutMemo);
|
|
4007
|
+
#else
|
|
4008
|
+
const auto heapBytes = bytes;
|
|
4009
|
+
#endif
|
|
4010
|
+
gLayoutMemoPeakBytes = std::max(gLayoutMemoPeakBytes, heapBytes);
|
|
4011
|
+
}
|
|
4012
|
+
// Allocation failure disables memoization for this pass; layout remains
|
|
4013
|
+
// correct and its persistent available box still supports scoped relayout.
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
void LayoutEngine::endLayoutPass()
|
|
4017
|
+
{
|
|
4018
|
+
gea::framework::memory::Allocator::free(gLayoutMemo);
|
|
4019
|
+
gLayoutMemo = nullptr;
|
|
4020
|
+
gLayoutMemoCapacity = 0;
|
|
4021
|
+
}
|
|
4022
|
+
|
|
4023
|
+
void LayoutEngine::resetNodeLayoutState(int id)
|
|
4024
|
+
{
|
|
4025
|
+
ensureLayoutState(id);
|
|
4026
|
+
auto &persistent = layoutState(id);
|
|
4027
|
+
persistent.memo_avail_w = persistent.memo_avail_h = 0;
|
|
4028
|
+
persistent.static_block_start = 0;
|
|
4029
|
+
persistent.static_block_axis = 0;
|
|
4030
|
+
invalidateMemo(id);
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
void LayoutEngine::releasePersistentLayoutStorage()
|
|
4034
|
+
{
|
|
4035
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4036
|
+
std::vector<LayoutStatePageOwner>().swap(gLayoutStatePages);
|
|
4037
|
+
gLayoutStatePeakBytes = 0;
|
|
4038
|
+
gLayoutStatePeakAllocations = 0;
|
|
4039
|
+
#endif
|
|
4040
|
+
}
|
|
4041
|
+
|
|
4042
|
+
std::size_t LayoutEngine::persistentLayoutStorageBytes()
|
|
4043
|
+
{
|
|
4044
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4045
|
+
return gLayoutStatePages.size() * sizeof(LayoutStatePage) + gLayoutStatePages.capacity() * sizeof(LayoutStatePageOwner);
|
|
4046
|
+
#else
|
|
4047
|
+
return 0;
|
|
4048
|
+
#endif
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
std::size_t LayoutEngine::persistentLayoutHeapBytes()
|
|
4052
|
+
{
|
|
4053
|
+
#if GEA_EMBEDDED_SHARED_STYLES && defined(ESP_PLATFORM)
|
|
4054
|
+
std::size_t bytes = gLayoutStatePages.capacity() ? heap_caps_get_allocated_size(gLayoutStatePages.data()) : 0;
|
|
4055
|
+
for (const auto &page : gLayoutStatePages) bytes += heap_caps_get_allocated_size(page.get());
|
|
4056
|
+
return bytes;
|
|
4057
|
+
#else
|
|
4058
|
+
return persistentLayoutStorageBytes();
|
|
4059
|
+
#endif
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
std::size_t LayoutEngine::persistentLayoutAllocationCount()
|
|
4063
|
+
{
|
|
4064
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4065
|
+
return gLayoutStatePages.size() + (gLayoutStatePages.capacity() ? 1 : 0);
|
|
4066
|
+
#else
|
|
4067
|
+
return 0;
|
|
4068
|
+
#endif
|
|
4069
|
+
}
|
|
4070
|
+
|
|
4071
|
+
std::size_t LayoutEngine::persistentLayoutPeakBytes()
|
|
4072
|
+
{
|
|
4073
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4074
|
+
return gLayoutStatePeakBytes;
|
|
4075
|
+
#else
|
|
4076
|
+
return 0;
|
|
4077
|
+
#endif
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
std::size_t LayoutEngine::persistentLayoutPeakAllocations()
|
|
4081
|
+
{
|
|
4082
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4083
|
+
return gLayoutStatePeakAllocations;
|
|
4084
|
+
#else
|
|
4085
|
+
return 0;
|
|
4086
|
+
#endif
|
|
4087
|
+
}
|
|
4088
|
+
|
|
4089
|
+
std::size_t LayoutEngine::persistentLayoutStaticBytes()
|
|
4090
|
+
{
|
|
4091
|
+
#if GEA_EMBEDDED_SHARED_STYLES
|
|
4092
|
+
return sizeof(gLayoutStatePages) + sizeof(gLayoutStatePeakBytes) + sizeof(gLayoutStatePeakAllocations);
|
|
4093
|
+
#else
|
|
4094
|
+
return 0;
|
|
4095
|
+
#endif
|
|
4096
|
+
}
|
|
4097
|
+
|
|
4098
|
+
void LayoutEngine::invalidateMemo(int id)
|
|
4099
|
+
{
|
|
4100
|
+
layoutState(id).memo_pass = 0;
|
|
4101
|
+
if (gLayoutMemo && id < gLayoutMemoCapacity) gLayoutMemo[id] = {};
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
std::size_t LayoutEngine::memoStorageBytes()
|
|
4105
|
+
{
|
|
4106
|
+
return gLayoutMemo ? sizeof(LayoutPassMemo) * gLayoutMemoCapacity : 0;
|
|
4107
|
+
}
|
|
4108
|
+
|
|
4109
|
+
std::size_t LayoutEngine::memoPeakHeapBytes()
|
|
4110
|
+
{
|
|
4111
|
+
return gLayoutMemoPeakBytes;
|
|
3837
4112
|
}
|
|
3838
4113
|
|
|
3839
4114
|
void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBoxEdges)
|
|
3840
4115
|
{
|
|
3841
4116
|
Node &node = Tree::instance().nodes()[id];
|
|
4117
|
+
auto &persistent = layoutState(id);
|
|
3842
4118
|
const Node *parent = node.parent >= 0 ? &Tree::instance().nodes()[node.parent] : nullptr;
|
|
3843
4119
|
// Horizontal non-replaced floats use the same min/max-content measurement
|
|
3844
4120
|
// and final used-width phase as fit-content. Floats on flex/grid items are
|
|
3845
4121
|
// ignored; orthogonal automatic inline sizing is handled separately.
|
|
3846
|
-
const bool shrinkFloat = node.type == NodeType::View && node.
|
|
3847
|
-
!isOutOfFlowPosition(node.
|
|
3848
|
-
(!parent || (parent->
|
|
3849
|
-
node.
|
|
4122
|
+
const bool shrinkFloat = node.type == NodeType::View && node.computedStyle().float_side &&
|
|
4123
|
+
!isOutOfFlowPosition(node.computedStyle().position) &&
|
|
4124
|
+
(!parent || (parent->computedStyle().display != kDisplayFlex && !isDisplayGrid(parent->computedStyle()))) &&
|
|
4125
|
+
node.computedStyle().width == kUnset && node.computedStyle().width_percent == kUnset && node.computedStyle().width_expression == -1 &&
|
|
3850
4126
|
writingMode(node) == 0;
|
|
3851
4127
|
// CSS Writing Modes 7.3.2: an orthogonal flow root's automatic inline
|
|
3852
4128
|
// size is fit-content. Measure before fixing the used size so cyclic
|
|
@@ -3855,23 +4131,23 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
3855
4131
|
const bool horizontalInline = writingMode(node) == 0;
|
|
3856
4132
|
const bool orthogonalAuto = node.type == NodeType::View && parent &&
|
|
3857
4133
|
horizontalInline != (writingMode(*parent) == 0) &&
|
|
3858
|
-
parent->
|
|
3859
|
-
!isOutOfFlowPosition(node.
|
|
3860
|
-
(horizontalInline ? node.
|
|
3861
|
-
(horizontalInline ? node.
|
|
3862
|
-
(horizontalInline ? node.
|
|
3863
|
-
const bool intrinsicWidth = isIntrinsicSizeExpression(node.
|
|
4134
|
+
parent->computedStyle().display != kDisplayFlex && !isDisplayGrid(parent->computedStyle()) &&
|
|
4135
|
+
!isOutOfFlowPosition(node.computedStyle().position) &&
|
|
4136
|
+
(horizontalInline ? node.computedStyle().width : node.computedStyle().height) == kUnset &&
|
|
4137
|
+
(horizontalInline ? node.computedStyle().width_percent : node.computedStyle().height_percent) == kUnset &&
|
|
4138
|
+
(horizontalInline ? node.computedStyle().width_expression : node.computedStyle().height_expression) == -1;
|
|
4139
|
+
const bool intrinsicWidth = isIntrinsicSizeExpression(node.computedStyle().width_expression) && !intrinsicSizeScope(node, true);
|
|
3864
4140
|
const bool horizontal = intrinsicWidth || !orthogonalAuto || horizontalInline;
|
|
3865
4141
|
if ((intrinsicWidth || shrinkFloat || orthogonalAuto) &&
|
|
3866
4142
|
!intrinsicSizeScope(node, horizontal) && !flexBasisScope(node, horizontal)) {
|
|
3867
4143
|
const int inherited = parent ? intrinsicSizeConstraint(*parent, horizontal) : 0;
|
|
3868
|
-
const int keyword = intrinsicWidth ? node.
|
|
4144
|
+
const int keyword = intrinsicWidth ? node.computedStyle().width_expression : kSizeFitContent;
|
|
3869
4145
|
IntrinsicSizeScope scope(node, 1, horizontal);
|
|
3870
4146
|
auto measure = [&](int mode) {
|
|
3871
4147
|
scope.constraint = mode;
|
|
3872
4148
|
const int available = mode == 1 ? 1 : 32767;
|
|
3873
4149
|
layoutNode(id, horizontal ? available : avail_w, horizontal ? avail_h : available, true);
|
|
3874
|
-
return std::max(0, (horizontal ? node.layout.width : node.layout.height) - boxInsets(node.
|
|
4150
|
+
return std::max(0, (horizontal ? node.layout.width : node.layout.height) - boxInsets(node.computedStyle(), horizontal));
|
|
3875
4151
|
};
|
|
3876
4152
|
if (inherited) {
|
|
3877
4153
|
measure(keyword == kSizeMinContent ? 1 : keyword == kSizeMaxContent ? 2 : inherited);
|
|
@@ -3879,49 +4155,57 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
3879
4155
|
}
|
|
3880
4156
|
const int minimum = keyword == kSizeMaxContent ? 0 : measure(1);
|
|
3881
4157
|
const int maximum = keyword == kSizeMinContent ? minimum : std::max(minimum, measure(2));
|
|
4158
|
+
#if GEA_CSS_BOX_EXPRESSIONS
|
|
3882
4159
|
const int inlineBasis = node.parent >= 0 && writingMode(Tree::instance().nodes()[node.parent]) != 0 ? avail_h : avail_w;
|
|
3883
4160
|
resolveLayoutBoxLengths(id, intrinsicBoxEdges ? 0 : inlineBasis);
|
|
3884
|
-
|
|
4161
|
+
#endif
|
|
4162
|
+
const int edges = boxInsets(node.computedStyle(), horizontal);
|
|
3885
4163
|
const int stretch = std::max(0, (horizontal ? avail_w : avail_h) -
|
|
3886
|
-
node.
|
|
4164
|
+
node.computedStyle().margin[horizontal ? 1 : 0] - node.computedStyle().margin[horizontal ? 3 : 2] - edges);
|
|
3887
4165
|
scope.borderSize = edges + (keyword == kSizeMinContent ? minimum : keyword == kSizeMaxContent ? maximum : std::min(maximum, std::max(minimum, stretch)));
|
|
3888
4166
|
scope.constraint = 0;
|
|
3889
4167
|
layoutNode(id, avail_w, avail_h, intrinsicBoxEdges);
|
|
3890
4168
|
return;
|
|
3891
4169
|
}
|
|
3892
4170
|
if (node.type == NodeType::Text && intrinsicWidthConstraint(node) == 1)
|
|
3893
|
-
avail_w = std::max(avail_w, TextRenderer::minContentWidth(node) + boxInsets(node.
|
|
4171
|
+
avail_w = std::max(avail_w, TextRenderer::minContentWidth(node) + boxInsets(node.computedStyle(), true));
|
|
4172
|
+
#if GEA_CSS_BOX_EXPRESSIONS
|
|
3894
4173
|
const int inlineBasis = node.parent >= 0 && writingMode(Tree::instance().nodes()[node.parent]) != 0 ? avail_h : avail_w;
|
|
3895
4174
|
if (resolveLayoutBoxLengths(id, intrinsicBoxEdges ? 0 : inlineBasis)) {
|
|
3896
|
-
|
|
4175
|
+
invalidateMemo(id);
|
|
3897
4176
|
}
|
|
4177
|
+
#endif
|
|
3898
4178
|
const bool memoizable = !gIntrinsicSizeScope && !gFlexBasisScope && avail_w >= INT16_MIN && avail_w <= INT16_MAX &&
|
|
3899
4179
|
avail_h >= INT16_MIN && avail_h <= INT16_MAX;
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
4180
|
+
LayoutPassMemo uncached{};
|
|
4181
|
+
// New nodes created during this pass remain uncached until the next pass.
|
|
4182
|
+
// Never grow the array under recursive callers holding references into it.
|
|
4183
|
+
LayoutPassMemo *entry = gLayoutMemo && id < gLayoutMemoCapacity ? &gLayoutMemo[id] : nullptr;
|
|
4184
|
+
LayoutPassMemo &memo = entry ? *entry : uncached;
|
|
4185
|
+
if (memoizable && entry) {
|
|
4186
|
+
if (memo.valid1 &&
|
|
4187
|
+
persistent.memo_avail_w == avail_w &&
|
|
4188
|
+
persistent.memo_avail_h == avail_h &&
|
|
4189
|
+
memo.result_w == node.layout.width &&
|
|
4190
|
+
memo.result_h == node.layout.height) {
|
|
4191
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutMemoHits++);
|
|
3907
4192
|
return;
|
|
3908
4193
|
}
|
|
3909
|
-
if (
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
4194
|
+
if (memo.valid2 &&
|
|
4195
|
+
memo.avail2_w == avail_w &&
|
|
4196
|
+
memo.avail2_h == avail_h &&
|
|
4197
|
+
memo.result_w == node.layout.width &&
|
|
4198
|
+
memo.result_h == node.layout.height) {
|
|
3914
4199
|
// Promote the hit to the MRU slot.
|
|
3915
|
-
std::swap(
|
|
3916
|
-
std::swap(
|
|
3917
|
-
std::swap(
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
refreshPerfStatsMutable().treeLayoutMemoHits++;
|
|
4200
|
+
std::swap(persistent.memo_avail_w, memo.avail2_w);
|
|
4201
|
+
std::swap(persistent.memo_avail_h, memo.avail2_h);
|
|
4202
|
+
std::swap(memo.valid1, memo.valid2);
|
|
4203
|
+
persistent.memo_pass = 1;
|
|
4204
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutMemoHits++);
|
|
3921
4205
|
return;
|
|
3922
4206
|
}
|
|
3923
4207
|
}
|
|
3924
|
-
refreshPerfStatsMutable().treeLayoutNodeCalls
|
|
4208
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutNodeCalls++);
|
|
3925
4209
|
LayoutNodePass(*this, id, avail_w, avail_h).run();
|
|
3926
4210
|
const int beforeRatioWidth = node.layout.width, beforeRatioHeight = node.layout.height;
|
|
3927
4211
|
applyPreferredRatio(node, avail_w, avail_h);
|
|
@@ -3930,30 +4214,31 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
3930
4214
|
if (node.parent < 0) {
|
|
3931
4215
|
// The initial containing block places the root; there is no parent
|
|
3932
4216
|
// layout pass to position its margin box or apply float alignment.
|
|
3933
|
-
node.layout.x = node.
|
|
3934
|
-
? avail_w - node.layout.width - node.
|
|
3935
|
-
: node.
|
|
3936
|
-
node.layout.y = node.
|
|
3937
|
-
}
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
node.layout.memo2_pass = node.layout.memo_pass;
|
|
4217
|
+
node.layout.x = node.computedStyle().float_side == 2
|
|
4218
|
+
? avail_w - node.layout.width - node.computedStyle().margin[1]
|
|
4219
|
+
: node.computedStyle().margin[3];
|
|
4220
|
+
node.layout.y = node.computedStyle().margin[0];
|
|
4221
|
+
}
|
|
4222
|
+
memo.avail2_w = persistent.memo_avail_w;
|
|
4223
|
+
memo.avail2_h = persistent.memo_avail_h;
|
|
4224
|
+
memo.valid2 = memo.result_w == node.layout.width &&
|
|
4225
|
+
memo.result_h == node.layout.height ? memo.valid1 : 0;
|
|
3943
4226
|
if (memoizable) {
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
4227
|
+
persistent.memo_avail_w = static_cast<std::int16_t>(avail_w);
|
|
4228
|
+
persistent.memo_avail_h = static_cast<std::int16_t>(avail_h);
|
|
4229
|
+
memo.result_w = node.layout.width;
|
|
4230
|
+
memo.result_h = node.layout.height;
|
|
4231
|
+
persistent.memo_pass = 1;
|
|
4232
|
+
memo.valid1 = 1;
|
|
3949
4233
|
} else {
|
|
3950
|
-
|
|
4234
|
+
persistent.memo_pass = 0;
|
|
4235
|
+
memo.valid1 = 0;
|
|
3951
4236
|
}
|
|
3952
4237
|
}
|
|
3953
4238
|
|
|
3954
4239
|
void LayoutEngine::repositionChildren(int id)
|
|
3955
4240
|
{
|
|
3956
|
-
refreshPerfStatsMutable().treeLayoutRepositionCalls
|
|
4241
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutRepositionCalls++);
|
|
3957
4242
|
Node *node = &Tree::instance().nodes()[id];
|
|
3958
4243
|
LayoutNodePass(*this, id, node->layout.width, node->layout.height).repositionChildren();
|
|
3959
4244
|
}
|
|
@@ -3965,14 +4250,15 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
3965
4250
|
const int nodeCount = tree.nodeCount();
|
|
3966
4251
|
if (scope < 0 || scope >= nodeCount) return false;
|
|
3967
4252
|
Node &a = nodes[scope];
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
refreshPerfStatsMutable().
|
|
4253
|
+
auto &persistent = layoutState(scope);
|
|
4254
|
+
if (persistent.memo_pass == 0) {
|
|
4255
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 2);
|
|
4256
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = scope);
|
|
3971
4257
|
return false;
|
|
3972
4258
|
}
|
|
3973
|
-
if (!LayoutNodePass(*this, scope,
|
|
3974
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 5;
|
|
3975
|
-
refreshPerfStatsMutable().treeScopedRejectNode = scope;
|
|
4259
|
+
if (!LayoutNodePass(*this, scope, persistent.memo_avail_w, persistent.memo_avail_h).containsChildMargins()) {
|
|
4260
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 5);
|
|
4261
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = scope);
|
|
3976
4262
|
return false;
|
|
3977
4263
|
}
|
|
3978
4264
|
|
|
@@ -3988,12 +4274,12 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
3988
4274
|
// pre-resolve relative space) — those trees must take the full path.
|
|
3989
4275
|
for (int i = 0; i < nodeCount; ++i) {
|
|
3990
4276
|
const Node &n = nodes[i];
|
|
3991
|
-
if (n.parent < 0 || !isOutOfFlowPosition(n.
|
|
4277
|
+
if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isDisplayNone(n.computedStyle())) continue;
|
|
3992
4278
|
if (!inScope(i)) continue;
|
|
3993
4279
|
const int containing = containingBlockForAbsoluteNode(i, treeRoot, nodes);
|
|
3994
4280
|
if (containing >= 0 && !inScope(containing)) {
|
|
3995
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 3;
|
|
3996
|
-
refreshPerfStatsMutable().treeScopedRejectNode = i;
|
|
4281
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 3);
|
|
4282
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = i);
|
|
3997
4283
|
return false;
|
|
3998
4284
|
}
|
|
3999
4285
|
}
|
|
@@ -4002,8 +4288,8 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4002
4288
|
const int prevY = a.layout.y;
|
|
4003
4289
|
const int prevW = a.layout.width;
|
|
4004
4290
|
const int prevH = a.layout.height;
|
|
4005
|
-
|
|
4006
|
-
layoutNode(scope,
|
|
4291
|
+
Pass layoutPass;
|
|
4292
|
+
layoutNode(scope, persistent.memo_avail_w, persistent.memo_avail_h);
|
|
4007
4293
|
const bool widthChanged = a.layout.width != prevW;
|
|
4008
4294
|
const bool heightChanged = a.layout.height != prevH;
|
|
4009
4295
|
if (widthChanged || heightChanged) {
|
|
@@ -4018,25 +4304,25 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4018
4304
|
bool parentOwnsHeight = hasExplicitHeight(a);
|
|
4019
4305
|
if (a.parent >= 0 && a.parent < nodeCount) {
|
|
4020
4306
|
const Node &parent = nodes[a.parent];
|
|
4021
|
-
if (isDisplayGrid(parent.
|
|
4022
|
-
const int inlineAlign = rstyle(a.
|
|
4023
|
-
const int blockAlign = a.
|
|
4307
|
+
if (isDisplayGrid(parent.computedStyle())) {
|
|
4308
|
+
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? rstyle(a.computedStyle()).justify_self : -1) >= 0 ? (GEA_CSS_JUSTIFY_SELF ? rstyle(a.computedStyle()).justify_self : -1) : parent.computedStyle().justify_items;
|
|
4309
|
+
const int blockAlign = a.computedStyle().align_self >= 0 ? a.computedStyle().align_self : parent.computedStyle().align_items;
|
|
4024
4310
|
const int alignX = writingMode(parent) == 0 ? inlineAlign : blockAlign;
|
|
4025
4311
|
const int alignY = writingMode(parent) == 0 ? blockAlign : inlineAlign;
|
|
4026
|
-
parentOwnsWidth = parentOwnsWidth || (alignX == 0 && !(a.
|
|
4027
|
-
parentOwnsHeight = parentOwnsHeight || (alignY == 0 && !(a.
|
|
4312
|
+
parentOwnsWidth = parentOwnsWidth || (alignX == 0 && !(a.computedStyle().margin_auto & 10));
|
|
4313
|
+
parentOwnsHeight = parentOwnsHeight || (alignY == 0 && !(a.computedStyle().margin_auto & 5));
|
|
4028
4314
|
} else {
|
|
4029
|
-
const bool row = usesRowLayout(parent.
|
|
4030
|
-
const bool parentOwnsMain = a.
|
|
4031
|
-
const int crossAlign = a.
|
|
4315
|
+
const bool row = usesRowLayout(parent.computedStyle());
|
|
4316
|
+
const bool parentOwnsMain = a.computedStyle().flex > 0 || hasFlexBasis(a);
|
|
4317
|
+
const int crossAlign = a.computedStyle().align_self >= 0 ? a.computedStyle().align_self : parent.computedStyle().align_items;
|
|
4032
4318
|
const bool parentOwnsCross = crossAlign == 0;
|
|
4033
4319
|
parentOwnsWidth = parentOwnsWidth || (row ? parentOwnsMain : parentOwnsCross);
|
|
4034
4320
|
parentOwnsHeight = parentOwnsHeight || (row ? parentOwnsCross : parentOwnsMain);
|
|
4035
4321
|
}
|
|
4036
4322
|
}
|
|
4037
4323
|
if ((widthChanged && !parentOwnsWidth) || (heightChanged && !parentOwnsHeight)) {
|
|
4038
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 4;
|
|
4039
|
-
refreshPerfStatsMutable().treeScopedRejectNode = scope;
|
|
4324
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 4);
|
|
4325
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = scope);
|
|
4040
4326
|
return false;
|
|
4041
4327
|
}
|
|
4042
4328
|
|
|
@@ -4053,7 +4339,7 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4053
4339
|
// Scoped equivalent of the root containing-block pass (both the node and
|
|
4054
4340
|
// its containing block are inside the scope, in the same relative space).
|
|
4055
4341
|
for (int i = 0; i < nodeCount; ++i) {
|
|
4056
|
-
if (isDisplayNone(nodes[i].
|
|
4342
|
+
if (isDisplayNone(nodes[i].computedStyle()) || !isOutOfFlowPosition(nodes[i].computedStyle().position) || nodes[i].parent < 0) continue;
|
|
4057
4343
|
if (!inScope(i) || i == scope) continue;
|
|
4058
4344
|
const int containing = containingBlockForAbsoluteNode(i, scope, nodes);
|
|
4059
4345
|
if (containing < 0) continue;
|
|
@@ -4062,9 +4348,9 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4062
4348
|
|
|
4063
4349
|
int childParentX = a.layout.x;
|
|
4064
4350
|
int childParentY = a.layout.y;
|
|
4065
|
-
if (a.
|
|
4066
|
-
if (scrollsOverflowX(a.
|
|
4067
|
-
if (scrollsOverflowY(a.
|
|
4351
|
+
if (a.computedStyle().overflow == 2) {
|
|
4352
|
+
if (scrollsOverflowX(a.computedStyle())) childParentX -= a.layout.scroll_x;
|
|
4353
|
+
if (scrollsOverflowY(a.computedStyle())) childParentY -= a.layout.scroll_y;
|
|
4068
4354
|
}
|
|
4069
4355
|
for (int child = a.first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
4070
4356
|
resolveAbsoluteCoords(child, childParentX, childParentY);
|
|
@@ -4084,9 +4370,9 @@ void LayoutEngine::resolveAbsoluteCoords(int id, int parent_x, int parent_y)
|
|
|
4084
4370
|
|
|
4085
4371
|
int childParentX = node->layout.x;
|
|
4086
4372
|
int childParentY = node->layout.y;
|
|
4087
|
-
if (node->
|
|
4088
|
-
if (scrollsOverflowX(node->
|
|
4089
|
-
if (scrollsOverflowY(node->
|
|
4373
|
+
if (node->computedStyle().overflow == 2) {
|
|
4374
|
+
if (scrollsOverflowX(node->computedStyle())) childParentX -= node->layout.scroll_x;
|
|
4375
|
+
if (scrollsOverflowY(node->computedStyle())) childParentY -= node->layout.scroll_y;
|
|
4090
4376
|
}
|
|
4091
4377
|
|
|
4092
4378
|
for (int child = node->first_child; child >= 0; child = nodes[child].next_sibling) {
|