@geastack/engine 0.1.7 → 0.1.9
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/canvas.cpp +84 -25
- package/css/engine.h +1 -0
- package/package.json +2 -2
- package/ui/absolute_leaf_refresh.cpp +65 -52
- package/ui/core.cpp +4 -4
- package/ui/css_features.h +87 -0
- package/ui/document.cpp +12 -1
- package/ui/image_node.cpp +24 -24
- package/ui/input.cpp +24 -24
- package/ui/input_render.cpp +27 -27
- package/ui/internal.h +22 -0
- package/ui/layout.cpp +771 -573
- package/ui/layout_snapshot.cpp +1 -1
- package/ui/node_features.h +18 -0
- package/ui/node_lifecycle.cpp +167 -1
- package/ui/node_model.h +216 -56
- package/ui/node_text.h +2 -0
- package/ui/refresh_perf.h +19 -17
- package/ui/render.cpp +217 -191
- package/ui/renderer_features.h +5 -0
- package/ui/root_scroll_refresh.cpp +65 -65
- package/ui/storage_usage.h +45 -0
- package/ui/style.cpp +438 -146
- package/ui/style.h +1 -0
- package/ui/style_values.h +2 -2
- package/ui/text.cpp +151 -153
- package/ui/tree_events.cpp +86 -0
- package/ui/tree_events.h +16 -0
- package/ui/tree_nodes.cpp +21 -17
- package/ui/tree_render.cpp +154 -123
- package/ui/tree_scroll_mirror.cpp +4 -4
- package/ui/tree_state.cpp +78 -6
- package/ui/tree_state.h +49 -4
- package/ui/tree_style.cpp +414 -309
- package/ui/view.cpp +207 -207
- package/ui/virtual_keyboard.cpp +11 -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 = (GEA_CSS_ASPECT_RATIO ? 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 = (GEA_CSS_FLEX_LINE_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;
|
|
@@ -672,16 +741,16 @@ public:
|
|
|
672
741
|
// carries it only when it is the first in-flow formatted child of its
|
|
673
742
|
// parent; following block siblings start after the owner's first line.
|
|
674
743
|
if (!LayoutEngine::isCssInlineLevelBox(nodes[ancestor])) {
|
|
675
|
-
if (isOutOfFlowPosition(nodes[ancestor].
|
|
744
|
+
if (isOutOfFlowPosition(nodes[ancestor].computedStyle().position) || nodes[ancestor].computedStyle().float_side) break;
|
|
676
745
|
const int parent = nodes[ancestor].parent;
|
|
677
746
|
if (parent < 0) break;
|
|
678
|
-
if (nodes[parent].
|
|
747
|
+
if (nodes[parent].computedStyle().display == kDisplayFlex || isDisplayGrid(nodes[parent].computedStyle())) break;
|
|
679
748
|
bool firstInFlow = true;
|
|
680
749
|
for (int sibling = nodes[parent].first_child; sibling >= 0 && sibling != ancestor;
|
|
681
750
|
sibling = nodes[sibling].next_sibling) {
|
|
682
|
-
if (!isDisplayNone(nodes[sibling].
|
|
683
|
-
!isOutOfFlowPosition(nodes[sibling].
|
|
684
|
-
!nodes[sibling].
|
|
751
|
+
if (!isDisplayNone(nodes[sibling].computedStyle()) &&
|
|
752
|
+
!isOutOfFlowPosition(nodes[sibling].computedStyle().position) &&
|
|
753
|
+
!nodes[sibling].computedStyle().float_side &&
|
|
685
754
|
!suppressAnonymousWhitespace(nodes, parent, sibling)) {
|
|
686
755
|
firstInFlow = false;
|
|
687
756
|
break;
|
|
@@ -706,8 +775,8 @@ public:
|
|
|
706
775
|
std::vector<std::pair<int, int>> staticBoundaries;
|
|
707
776
|
int flowIndex = 0;
|
|
708
777
|
for (int child = node_.first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
709
|
-
if (isDisplayNone(nodes[child].
|
|
710
|
-
if (isOutOfFlowPosition(nodes[child].
|
|
778
|
+
if (isDisplayNone(nodes[child].computedStyle()) || suppressAnonymousWhitespace(nodes, parentId, child)) continue;
|
|
779
|
+
if (isOutOfFlowPosition(nodes[child].computedStyle().position)) {
|
|
711
780
|
if (auto *rare = rareDataFor(child)) rare->inlineStaticPosition.valid = false;
|
|
712
781
|
if (LayoutEngine::isCssInlineLevelBox(nodes[child], true))
|
|
713
782
|
staticBoundaries.emplace_back(flowIndex, child);
|
|
@@ -726,13 +795,13 @@ public:
|
|
|
726
795
|
if (child.type == NodeType::Text || wrappedRun >= 0) {
|
|
727
796
|
contentW = std::max(contentW, TextRenderer::minContentWidth(wrappedRun >= 0 ? nodes[wrappedRun] : child, &pendingWord));
|
|
728
797
|
} else {
|
|
729
|
-
contentW = std::max(contentW, child.layout.width + child.
|
|
798
|
+
contentW = std::max(contentW, child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
730
799
|
pendingWord = 0;
|
|
731
800
|
}
|
|
732
801
|
}
|
|
733
802
|
}
|
|
734
|
-
const int contentLeft = boxInset(node_.
|
|
735
|
-
const int contentTop = boxInset(node_.
|
|
803
|
+
const int contentLeft = boxInset(node_.computedStyle(), 3);
|
|
804
|
+
const int contentTop = boxInset(node_.computedStyle(), 0);
|
|
736
805
|
const int gapStyle = mainGap_;
|
|
737
806
|
|
|
738
807
|
const bool blockOpensItsFirstLine = startsFormattingLine(nodes, parentId);
|
|
@@ -782,8 +851,8 @@ public:
|
|
|
782
851
|
captureStaticBoundary(j, pen, lineStaticChildren, lineIsContinuation || i > 0);
|
|
783
852
|
const int child = children_[j];
|
|
784
853
|
Node &cn = nodes[child];
|
|
785
|
-
const int marginL = cn.
|
|
786
|
-
const int marginR = cn.
|
|
854
|
+
const int marginL = cn.computedStyle().margin[3];
|
|
855
|
+
const int marginR = cn.computedStyle().margin[1];
|
|
787
856
|
const int gap = pen > 0 ? gapStyle : 0;
|
|
788
857
|
|
|
789
858
|
if (isLineBreak(cn)) {
|
|
@@ -801,8 +870,8 @@ public:
|
|
|
801
870
|
const int innerRun = isFragmentableRun(cn) ? -1 : transparentInlineRun(cn);
|
|
802
871
|
Node &subject = innerRun >= 0 ? nodes[innerRun] : cn;
|
|
803
872
|
if (isFragmentableRun(subject)) {
|
|
804
|
-
const int padH = boxInset(subject.
|
|
805
|
-
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);
|
|
806
875
|
// Budgets are TEXT widths: the run's own padding is part of its box,
|
|
807
876
|
// not of the line it can fill.
|
|
808
877
|
const int rest = contentW - marginL - marginR - padH;
|
|
@@ -815,7 +884,7 @@ public:
|
|
|
815
884
|
// run keeps flowing whole, exactly as before.
|
|
816
885
|
const bool haveLineMetrics =
|
|
817
886
|
m.lineAdvance > 0 &&
|
|
818
|
-
childBaseline(subject) <= boxInset(subject.
|
|
887
|
+
childBaseline(subject) <= boxInset(subject.computedStyle(), 0) + m.lineAdvance;
|
|
819
888
|
if (m.lineCount > 0 && haveLineMetrics) {
|
|
820
889
|
// Its first WORD does not fit what is left: the run starts the
|
|
821
890
|
// next line box rather than overflowing it or being cut open.
|
|
@@ -845,7 +914,7 @@ public:
|
|
|
845
914
|
cn.layout.inline_indent = clampInt16(indent);
|
|
846
915
|
}
|
|
847
916
|
if (wraps) {
|
|
848
|
-
const int ascent = cn.
|
|
917
|
+
const int ascent = cn.computedStyle().margin[0] + childBaseline(cn);
|
|
849
918
|
const int descent = runLineDescent(subject, m.lineAdvance);
|
|
850
919
|
if (ascent > lineAscent) lineAscent = ascent;
|
|
851
920
|
if (descent > lineDescent) lineDescent = descent;
|
|
@@ -870,7 +939,7 @@ public:
|
|
|
870
939
|
const int itemMain = cn.layout.width + marginL + marginR;
|
|
871
940
|
if (pen > 0 && pen + gap + itemMain > contentW) break;
|
|
872
941
|
if (isFragmentableRun(subject) && captureFirstLine && i == 0) {
|
|
873
|
-
const int padH = boxInset(subject.
|
|
942
|
+
const int padH = boxInset(subject.computedStyle(), 1) + boxInset(subject.computedStyle(), 3);
|
|
874
943
|
const int rest = contentW - marginL - marginR - padH;
|
|
875
944
|
const InlineFlowMeasure m = TextRenderer::measureInlineFlow(
|
|
876
945
|
subject, rest - pen - gap, rest, pen == 0 && (j > 0 || blockOpensItsFirstLine));
|
|
@@ -878,12 +947,12 @@ public:
|
|
|
878
947
|
firstLineCandidates.push_back({innerRun >= 0 ? innerRun : child,
|
|
879
948
|
contentLeft + pen + gap + marginL,
|
|
880
949
|
m.firstLineWidth + padH,
|
|
881
|
-
m.lineAdvance + boxInset(subject.
|
|
950
|
+
m.lineAdvance + boxInset(subject.computedStyle(), 0) + boxInset(subject.computedStyle(), 2),
|
|
882
951
|
j, m.firstLineTrailingSpace});
|
|
883
952
|
}
|
|
884
953
|
}
|
|
885
|
-
const int ascent = cn.
|
|
886
|
-
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);
|
|
887
956
|
if (ascent > lineAscent) lineAscent = ascent;
|
|
888
957
|
if (descent > lineDescent) lineDescent = descent;
|
|
889
958
|
pen += gap + itemMain;
|
|
@@ -964,9 +1033,9 @@ public:
|
|
|
964
1033
|
Node &run = nodes[children_[wrapIdx]];
|
|
965
1034
|
const int runBaseline = run.layout.y + childBaseline(run);
|
|
966
1035
|
continuedBaseline = runBaseline + (wrapSpans - 1) * wrapAdvance;
|
|
967
|
-
inheritedAscent = run.
|
|
1036
|
+
inheritedAscent = run.computedStyle().margin[0] + childBaseline(run);
|
|
968
1037
|
inheritedDescent = runLineDescent(run, wrapAdvance);
|
|
969
|
-
penStart = run.
|
|
1038
|
+
penStart = run.computedStyle().margin[3] + wrapLastWidth + run.computedStyle().margin[1];
|
|
970
1039
|
continuing = true;
|
|
971
1040
|
if (trailingWrappedStaticBoundary) {
|
|
972
1041
|
std::vector<int> trailingStaticChildren;
|
|
@@ -1019,14 +1088,14 @@ public:
|
|
|
1019
1088
|
// Same rules as autosizeParent: a scroll container keeps the size it was
|
|
1020
1089
|
// given on its scrolling axis so its overflow becomes scroll range.
|
|
1021
1090
|
const int flowHeight = flowBottom - contentTop;
|
|
1022
|
-
const bool keepScrollHeight = scrollsOverflowY(node_.
|
|
1023
|
-
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;
|
|
1024
1093
|
if (!hasExplicitHeight(node_) && !keepScrollHeight) {
|
|
1025
|
-
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);
|
|
1026
1095
|
node_.layout.height = clampInt16(clampLayoutSize(node_, height, false));
|
|
1027
1096
|
}
|
|
1028
1097
|
if (!hasExplicitWidth(node_) && !keepScrollWidth) {
|
|
1029
|
-
const int width = maxLineWidth + boxInset(node_.
|
|
1098
|
+
const int width = maxLineWidth + boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
1030
1099
|
node_.layout.width = clampInt16(clampLayoutSize(node_, width, true));
|
|
1031
1100
|
}
|
|
1032
1101
|
return extent;
|
|
@@ -1037,8 +1106,8 @@ public:
|
|
|
1037
1106
|
// or nowrap run keeps its own box.
|
|
1038
1107
|
static bool isFragmentableRun(const Node &n)
|
|
1039
1108
|
{
|
|
1040
|
-
return n.type == NodeType::Text && !n.text.empty() && n.
|
|
1041
|
-
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;
|
|
1042
1111
|
}
|
|
1043
1112
|
|
|
1044
1113
|
// True when nothing about `n`'s BOX is visible — no background, border, shadow,
|
|
@@ -1046,9 +1115,9 @@ public:
|
|
|
1046
1115
|
// convenient, because only its content is ever painted.
|
|
1047
1116
|
static bool paintsNoBox(const Node &n)
|
|
1048
1117
|
{
|
|
1049
|
-
if (n.
|
|
1118
|
+
if (n.computedStyle().has_bg || n.computedStyle().border_width > 0 || hasSideBorder(n.computedStyle())) return false;
|
|
1050
1119
|
#if GEA_EMBEDDED_RARE_STYLE_INLINE
|
|
1051
|
-
const RareStyle &r = rstyle(n.
|
|
1120
|
+
const RareStyle &r = rstyle(n.computedStyle());
|
|
1052
1121
|
if (r.translate_present || r.transform_present || r.rotate_present || r.scale_present || r.filter_present ||
|
|
1053
1122
|
r.transform_rotate || r.transform_rotate_x || r.transform_rotate_y ||
|
|
1054
1123
|
composedTranslateX(r) || composedTranslateY(r) || composedTranslateZ(r) ||
|
|
@@ -1059,7 +1128,7 @@ public:
|
|
|
1059
1128
|
#else
|
|
1060
1129
|
// No rare-style record at all: no transform, shadow, gradient or filter was
|
|
1061
1130
|
// ever set on this node.
|
|
1062
|
-
if (n.
|
|
1131
|
+
if (n.computedStyle().rare_style >= 0) return false;
|
|
1063
1132
|
#endif
|
|
1064
1133
|
return true;
|
|
1065
1134
|
}
|
|
@@ -1073,25 +1142,25 @@ public:
|
|
|
1073
1142
|
{
|
|
1074
1143
|
if (wrapper.type != NodeType::View) return -1;
|
|
1075
1144
|
if (!paintsNoBox(wrapper)) return -1;
|
|
1076
|
-
if (boxInset(wrapper.
|
|
1077
|
-
boxInset(wrapper.
|
|
1145
|
+
if (boxInset(wrapper.computedStyle(), 0) || boxInset(wrapper.computedStyle(), 1) || boxInset(wrapper.computedStyle(), 2) ||
|
|
1146
|
+
boxInset(wrapper.computedStyle(), 3))
|
|
1078
1147
|
return -1;
|
|
1079
1148
|
if (hasExplicitWidth(wrapper) || hasExplicitHeight(wrapper)) return -1;
|
|
1080
|
-
if (wrapper.
|
|
1081
|
-
if (wrapper.
|
|
1082
|
-
if (overflowX(wrapper.
|
|
1083
|
-
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 ||
|
|
1084
1153
|
hasFlexBasis(wrapper))
|
|
1085
1154
|
return -1;
|
|
1086
1155
|
const Node *nodes = Tree::instance().nodes();
|
|
1087
1156
|
int run = -1;
|
|
1088
1157
|
for (int c = wrapper.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1089
1158
|
const Node &child = nodes[c];
|
|
1090
|
-
if (isDisplayNone(child.
|
|
1159
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
|
|
1091
1160
|
if (run >= 0) return -1; // more than one in-flow child
|
|
1092
1161
|
if (child.type != NodeType::Text) return -1;
|
|
1093
|
-
if (child.
|
|
1094
|
-
child.
|
|
1162
|
+
if (child.computedStyle().margin[0] || child.computedStyle().margin[1] || child.computedStyle().margin[2] ||
|
|
1163
|
+
child.computedStyle().margin[3])
|
|
1095
1164
|
return -1;
|
|
1096
1165
|
if (!isFragmentableRun(child)) return -1;
|
|
1097
1166
|
run = c;
|
|
@@ -1104,8 +1173,8 @@ public:
|
|
|
1104
1173
|
// actually carries — the others are flush, so this is the taller, safe value).
|
|
1105
1174
|
int runLineDescent(const Node &n, int lineAdvance) const
|
|
1106
1175
|
{
|
|
1107
|
-
const int ascender = childBaseline(n) - boxInset(n.
|
|
1108
|
-
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];
|
|
1109
1178
|
return descent < 0 ? 0 : descent;
|
|
1110
1179
|
}
|
|
1111
1180
|
|
|
@@ -1122,8 +1191,8 @@ public:
|
|
|
1122
1191
|
for (int k = from; k < to; k++) {
|
|
1123
1192
|
const int child = children_[k];
|
|
1124
1193
|
Node &cn = nodes[child];
|
|
1125
|
-
const int marginL = cn.
|
|
1126
|
-
const int marginR = cn.
|
|
1194
|
+
const int marginL = cn.computedStyle().margin[3];
|
|
1195
|
+
const int marginR = cn.computedStyle().margin[1];
|
|
1127
1196
|
const int gap = pen > 0 ? mainGap_ : 0;
|
|
1128
1197
|
|
|
1129
1198
|
if (cn.layout.inline_indent > 0) {
|
|
@@ -1142,15 +1211,15 @@ public:
|
|
|
1142
1211
|
}
|
|
1143
1212
|
|
|
1144
1213
|
int y = baseline - childBaseline(cn);
|
|
1145
|
-
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]);
|
|
1146
1215
|
if (align != 5) {
|
|
1147
|
-
const int crossBefore = cn.
|
|
1148
|
-
const int crossAfter = cn.
|
|
1216
|
+
const int crossBefore = cn.computedStyle().margin[0];
|
|
1217
|
+
const int crossAfter = cn.computedStyle().margin[2];
|
|
1149
1218
|
const int crossTotal = cn.layout.height + crossBefore + crossAfter;
|
|
1150
1219
|
y = lineTop + crossBefore;
|
|
1151
1220
|
if (align == 1) y += (lineCross - crossTotal) / 2;
|
|
1152
1221
|
else if (align == 2) y += lineCross - crossTotal;
|
|
1153
|
-
else if (align == 0 && !hasExplicitHeight(cn) && !isIntrinsicSizeExpression(cn.
|
|
1222
|
+
else if (align == 0 && !hasExplicitHeight(cn) && !isIntrinsicSizeExpression(cn.computedStyle().height_expression)) {
|
|
1154
1223
|
cn.layout.height = clampInt16(lineCross - crossBefore - crossAfter);
|
|
1155
1224
|
engine_.repositionChildren(child);
|
|
1156
1225
|
}
|
|
@@ -1169,12 +1238,12 @@ public:
|
|
|
1169
1238
|
void expandCrossSizes(int lineCount, bool onlyIfDefinite)
|
|
1170
1239
|
{
|
|
1171
1240
|
const bool hasDefiniteCross = isRow_ ? hasExplicitHeight(node_) : hasExplicitWidth(node_);
|
|
1172
|
-
const bool wrappingFlex = node_.
|
|
1241
|
+
const bool wrappingFlex = node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap;
|
|
1173
1242
|
if (onlyIfDefinite && !hasDefiniteCross) {
|
|
1174
1243
|
// A single flex line's intrinsic cross size still obeys the
|
|
1175
1244
|
// container's min/max cross size (Flexbox 9.4, step 8).
|
|
1176
|
-
if (node_.
|
|
1177
|
-
const int insets = boxInsets(node_.
|
|
1245
|
+
if (node_.computedStyle().display == kDisplayFlex && lineCount == 1 && !wrappingFlex) {
|
|
1246
|
+
const int insets = boxInsets(node_.computedStyle(), !isRow_);
|
|
1178
1247
|
lines_[0].crossSize = std::max(0, clampLayoutSize(node_, lines_[0].crossSize + insets, !isRow_) - insets);
|
|
1179
1248
|
}
|
|
1180
1249
|
return;
|
|
@@ -1183,7 +1252,7 @@ public:
|
|
|
1183
1252
|
const int crossAvail = isRow_ ? padHeight_ : padWidth_;
|
|
1184
1253
|
if (lineCount == 1 && !wrappingFlex) {
|
|
1185
1254
|
lines_[0].crossSize = crossAvail;
|
|
1186
|
-
} else if (lineCount > 0 && (!wrappingFlex || node_.
|
|
1255
|
+
} else if (lineCount > 0 && (!wrappingFlex || node_.computedStyle().align_content == 0)) {
|
|
1187
1256
|
int totalLineCross = 0;
|
|
1188
1257
|
for (int i = 0; i < lineCount; i++) totalLineCross += lines_[i].crossSize;
|
|
1189
1258
|
const int extra = crossAvail - totalLineCross - (lineCount - 1) * crossGap_;
|
|
@@ -1198,7 +1267,7 @@ public:
|
|
|
1198
1267
|
void positionLines(int lineCount)
|
|
1199
1268
|
{
|
|
1200
1269
|
Node *nodes = Tree::instance().nodes();
|
|
1201
|
-
const bool wrappingFlex = node_.
|
|
1270
|
+
const bool wrappingFlex = node_.computedStyle().display == kDisplayFlex && node_.computedStyle().flex_wrap;
|
|
1202
1271
|
const bool definiteCross = isRow_ ? hasExplicitHeight(node_) : hasExplicitWidth(node_);
|
|
1203
1272
|
bool ratioCrossChanged = false;
|
|
1204
1273
|
|
|
@@ -1210,8 +1279,8 @@ public:
|
|
|
1210
1279
|
// box shrinks to fit. Reading layout.{width,height} also gives the correct
|
|
1211
1280
|
// free space when a flex item was GROWN past its content by its parent.
|
|
1212
1281
|
const int mainBox = isRow_
|
|
1213
|
-
? (node_.layout.width - boxInset(node_.
|
|
1214
|
-
: (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));
|
|
1215
1284
|
const int mainContentBox = mainBox < 0 ? 0 : mainBox;
|
|
1216
1285
|
|
|
1217
1286
|
for (int lineIndex = 0; lineIndex < lineCount; lineIndex++) {
|
|
@@ -1233,7 +1302,7 @@ public:
|
|
|
1233
1302
|
// container skips main-axis shrink entirely — the pre-flex-shrink
|
|
1234
1303
|
// behavior for scrollable boxes.)
|
|
1235
1304
|
const bool mainAxisScrolls =
|
|
1236
|
-
isRow_ ? scrollsOverflowX(node_.
|
|
1305
|
+
isRow_ ? scrollsOverflowX(node_.computedStyle()) : scrollsOverflowY(node_.computedStyle());
|
|
1237
1306
|
if (!mainAxisScrolls) {
|
|
1238
1307
|
const int totalShrink = totalFlexShrinkForLine(line, nodes);
|
|
1239
1308
|
if (totalShrink > 0) {
|
|
@@ -1249,7 +1318,7 @@ public:
|
|
|
1249
1318
|
for (int i = 0; i < line.count; i++) {
|
|
1250
1319
|
const int child = children_[line.start + i];
|
|
1251
1320
|
Node &childNode = nodes[child];
|
|
1252
|
-
if (childNode.
|
|
1321
|
+
if (childNode.computedStyle().flex <= 0) continue;
|
|
1253
1322
|
const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
|
|
1254
1323
|
if (mainSize == 0) engine_.repositionChildren(child);
|
|
1255
1324
|
}
|
|
@@ -1259,10 +1328,10 @@ public:
|
|
|
1259
1328
|
for (int i = 0; i < line.count; ++i) {
|
|
1260
1329
|
const Node &child = nodes[children_[line.start + i]];
|
|
1261
1330
|
hasRatio |= preferredRatio(child) > 0;
|
|
1262
|
-
measuredCross = std::max(measuredCross, isRow_ ? child.layout.height + child.
|
|
1263
|
-
: 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]);
|
|
1264
1333
|
}
|
|
1265
|
-
if (node_.
|
|
1334
|
+
if (node_.computedStyle().display == kDisplayFlex && hasRatio && !definiteCross) {
|
|
1266
1335
|
line.crossSize = std::max(line.strutSize, baselineCrossSize(line.start, line.count, measuredCross));
|
|
1267
1336
|
ratioCrossChanged = true;
|
|
1268
1337
|
}
|
|
@@ -1272,31 +1341,31 @@ public:
|
|
|
1272
1341
|
if (ratioCrossChanged) {
|
|
1273
1342
|
expandCrossSizes(lineCount, true);
|
|
1274
1343
|
int16_t &cross = isRow_ ? node_.layout.height : node_.layout.width;
|
|
1275
|
-
cross = clampInt16(clampLayoutSize(node_, totalCrossSize(lineCount) + boxInsets(node_.
|
|
1344
|
+
cross = clampInt16(clampLayoutSize(node_, totalCrossSize(lineCount) + boxInsets(node_.computedStyle(), !isRow_), !isRow_));
|
|
1276
1345
|
}
|
|
1277
|
-
int crossOffset = boxInset(node_.
|
|
1278
|
-
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_);
|
|
1279
1348
|
const int crossFree = crossBox - totalCrossSize(lineCount);
|
|
1280
1349
|
for (int lineIndex = 0; lineIndex < lineCount; ++lineIndex) {
|
|
1281
1350
|
FlexLine &line = lines_[lineIndex];
|
|
1282
1351
|
int occupied = std::max(0, line.count - 1) * mainGap_;
|
|
1283
1352
|
for (int i = 0; i < line.count; ++i) {
|
|
1284
1353
|
const Node &child = nodes[children_[line.start + i]];
|
|
1285
|
-
occupied += isRow_ ? child.layout.width + child.
|
|
1286
|
-
: 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];
|
|
1287
1356
|
}
|
|
1288
1357
|
int remaining = mainContentBox - occupied;
|
|
1289
|
-
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);
|
|
1290
1359
|
if (remaining < 0 && mainAlignment != 1 && mainAlignment != 2) remaining = 0;
|
|
1291
1360
|
|
|
1292
|
-
int mainOffset = isRow_ ? boxInset(node_.
|
|
1361
|
+
int mainOffset = isRow_ ? boxInset(node_.computedStyle(), 3) : boxInset(node_.computedStyle(), 0);
|
|
1293
1362
|
int autoCount = 0;
|
|
1294
1363
|
for (int i = 0; i < line.count; ++i) {
|
|
1295
|
-
const auto mask = nodes[children_[line.start + i]].
|
|
1364
|
+
const auto mask = nodes[children_[line.start + i]].computedStyle().margin_auto;
|
|
1296
1365
|
autoCount += isRow_ ? !!(mask & 2) + !!(mask & 8) : !!(mask & 1) + !!(mask & 4);
|
|
1297
1366
|
}
|
|
1298
1367
|
const int autoSpace = autoCount && remaining > 0 ? remaining : 0;
|
|
1299
|
-
if (!isDistributedAlignment(node_.
|
|
1368
|
+
if (!isDistributedAlignment(node_.computedStyle().justify_content))
|
|
1300
1369
|
applyJustifyContent(autoSpace ? 0 : remaining, &mainOffset);
|
|
1301
1370
|
const int lineOffset = wrappingFlex ? crossAlignmentOffset(lineIndex, lineCount, crossFree) : 0;
|
|
1302
1371
|
positionLineChildren(line, nodes, mainOffset, crossOffset + lineOffset, autoSpace, autoCount, autoSpace ? 0 : remaining);
|
|
@@ -1307,18 +1376,18 @@ public:
|
|
|
1307
1376
|
int crossAlignmentOffset(int index, int count, int free) const
|
|
1308
1377
|
{
|
|
1309
1378
|
#if GEA_CSS_FLEX_WRAP
|
|
1310
|
-
const bool wrapReversed = (node_.
|
|
1379
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1311
1380
|
#else
|
|
1312
1381
|
constexpr bool wrapReversed = false;
|
|
1313
1382
|
#endif
|
|
1314
1383
|
// A wrapping container is multi-line even when only one line is occupied.
|
|
1315
1384
|
// Distributed alignments fall back to start/center for overflowing lines.
|
|
1316
|
-
switch (usedAlignment(node_.
|
|
1385
|
+
switch (usedAlignment(node_.computedStyle().align_content, free, wrapReversed)) {
|
|
1317
1386
|
case 1: return free / 2;
|
|
1318
1387
|
case 2: return free;
|
|
1319
1388
|
case 3:
|
|
1320
1389
|
case 4:
|
|
1321
|
-
case kAlignSpaceEvenly: return distributedAlignmentOffset(node_.
|
|
1390
|
+
case kAlignSpaceEvenly: return distributedAlignmentOffset(node_.computedStyle().align_content, free, index, count);
|
|
1322
1391
|
default: return 0;
|
|
1323
1392
|
}
|
|
1324
1393
|
}
|
|
@@ -1333,16 +1402,16 @@ public:
|
|
|
1333
1402
|
// overflow:scroll/auto clips/scrolls its overflow, it does not expand to
|
|
1334
1403
|
// fit content. Guarded on a positive assigned size so an unsized scroll
|
|
1335
1404
|
// container still autosizes as before.
|
|
1336
|
-
const bool keepScrollHeight = scrollsOverflowY(node_.
|
|
1337
|
-
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;
|
|
1338
1407
|
|
|
1339
1408
|
if (!hasExplicitHeight(node_) && !keepScrollHeight) {
|
|
1340
|
-
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);
|
|
1341
1410
|
node_.layout.height = clampLayoutSize(node_, height, false);
|
|
1342
1411
|
}
|
|
1343
1412
|
|
|
1344
1413
|
if (!hasExplicitWidth(node_) && !keepScrollWidth) {
|
|
1345
|
-
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);
|
|
1346
1415
|
node_.layout.width = clampLayoutSize(node_, width, true);
|
|
1347
1416
|
}
|
|
1348
1417
|
}
|
|
@@ -1354,27 +1423,27 @@ private:
|
|
|
1354
1423
|
if (!blockAxis || assignedSize_ || (isRow_ ? hasExplicitWidth(node_) : hasExplicitHeight(node_))) return mainAvail_;
|
|
1355
1424
|
// An automatic block main size grows to fit its items. min-height is
|
|
1356
1425
|
// a floor, not a wrapping constraint; only a maximum bounds packing.
|
|
1357
|
-
if ((isRow_ ? node_.
|
|
1358
|
-
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_));
|
|
1359
1428
|
}
|
|
1360
1429
|
|
|
1361
1430
|
int buildCollapsedLines(const std::vector<int> &struts)
|
|
1362
1431
|
{
|
|
1363
1432
|
Node *nodes = Tree::instance().nodes();
|
|
1364
1433
|
std::vector<int> balancedEnds;
|
|
1365
|
-
if (node_.
|
|
1434
|
+
if (node_.computedStyle().flex_wrap & 4) {
|
|
1366
1435
|
std::vector<int> sizes;
|
|
1367
1436
|
int total = 0;
|
|
1368
1437
|
for (int i = 0; i < childCount_; ++i) {
|
|
1369
1438
|
if (struts[i] >= 0) continue;
|
|
1370
1439
|
const Node &child = nodes[children_[i]];
|
|
1371
|
-
const int size = isRow_ ? child.layout.width + child.
|
|
1372
|
-
: 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];
|
|
1373
1442
|
total += std::max(0, size) + (sizes.empty() ? 0 : mainGap_);
|
|
1374
1443
|
sizes.push_back(size);
|
|
1375
1444
|
}
|
|
1376
1445
|
const int available = std::min(total, flexWrapLimit());
|
|
1377
|
-
balancedEnds = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.
|
|
1446
|
+
balancedEnds = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.computedStyle()).flex_line_count : 1));
|
|
1378
1447
|
}
|
|
1379
1448
|
int lineCount = 0, start = 0, written = 0, main = 0, cross = 0, strut = 0;
|
|
1380
1449
|
auto finish = [&] {
|
|
@@ -1391,12 +1460,12 @@ private:
|
|
|
1391
1460
|
child.layout.x = child.layout.y = child.layout.width = child.layout.height = 0;
|
|
1392
1461
|
continue;
|
|
1393
1462
|
}
|
|
1394
|
-
const int childMain = isRow_ ? child.layout.width + child.
|
|
1395
|
-
: child.layout.height + child.
|
|
1396
|
-
const int childCross = isRow_ ? child.layout.height + child.
|
|
1397
|
-
: 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];
|
|
1398
1467
|
const bool wrap = !balancedEnds.empty() ? written == balancedEnds[lineCount]
|
|
1399
|
-
: node_.
|
|
1468
|
+
: node_.computedStyle().flex_wrap && main + mainGap_ + childMain > flexWrapLimit();
|
|
1400
1469
|
if (written > start && wrap) finish();
|
|
1401
1470
|
main += childMain + (written > start ? mainGap_ : 0);
|
|
1402
1471
|
cross = std::max(cross, childCross);
|
|
@@ -1414,22 +1483,22 @@ private:
|
|
|
1414
1483
|
int total = 0;
|
|
1415
1484
|
for (int i = 0; i < childCount_; ++i) {
|
|
1416
1485
|
const Node &child = nodes[children_[i]];
|
|
1417
|
-
sizes[i] = isRow_ ? child.layout.width + child.
|
|
1418
|
-
: 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];
|
|
1419
1488
|
total += std::max(0, sizes[i]) + (i ? mainGap_ : 0);
|
|
1420
1489
|
}
|
|
1421
1490
|
// An unconstrained automatic block main size is content-based; the
|
|
1422
1491
|
// viewport height must not manufacture additional columns.
|
|
1423
1492
|
const int available = std::min(total, flexWrapLimit());
|
|
1424
|
-
const auto ends = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.
|
|
1493
|
+
const auto ends = balancedFlexLineEnds(sizes, available, mainGap_, (GEA_CSS_FLEX_LINE_COUNT ? rstyle(node_.computedStyle()).flex_line_count : 1));
|
|
1425
1494
|
int start = 0, count = 0;
|
|
1426
1495
|
for (const int end : ends) {
|
|
1427
1496
|
int main = 0, cross = 0;
|
|
1428
1497
|
for (int i = start; i < end; ++i) {
|
|
1429
1498
|
const Node &child = nodes[children_[i]];
|
|
1430
1499
|
main += sizes[i] + (i > start ? mainGap_ : 0);
|
|
1431
|
-
cross = std::max(cross, isRow_ ? child.layout.height + child.
|
|
1432
|
-
: 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]);
|
|
1433
1502
|
}
|
|
1434
1503
|
appendLine(count, start, end - start, main, cross);
|
|
1435
1504
|
start = end;
|
|
@@ -1442,13 +1511,13 @@ private:
|
|
|
1442
1511
|
if (isRow_ ? hasExplicitWidth(node_) : hasExplicitHeight(node_)) return mainAvail_;
|
|
1443
1512
|
// A normal block's automatic inline size fills its containing block.
|
|
1444
1513
|
// Intrinsic measurements and automatic block sizes remain indefinite.
|
|
1445
|
-
if (isRow_ && !intrinsicWidthConstraint(node_) && !node_.
|
|
1446
|
-
!isIntrinsicSizeExpression(node_.
|
|
1447
|
-
(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_;
|
|
1448
1517
|
if (assignedSize_ && node_.parent >= 0) {
|
|
1449
1518
|
const Node &parent = Tree::instance().nodes()[node_.parent];
|
|
1450
|
-
if (parent.
|
|
1451
|
-
const bool parentRow = flexRowDirection(parent.
|
|
1519
|
+
if (parent.computedStyle().display == kDisplayFlex) {
|
|
1520
|
+
const bool parentRow = flexRowDirection(parent.computedStyle()) != (writingMode(parent) != 0);
|
|
1452
1521
|
if (isRow_ != parentRow ? definiteFlexCrossSize(parent, node_, parentRow)
|
|
1453
1522
|
: (isRow_ ? hasExplicitWidth(parent) : hasExplicitHeight(parent))) return mainAvail_;
|
|
1454
1523
|
}
|
|
@@ -1462,7 +1531,7 @@ private:
|
|
|
1462
1531
|
// Authored bases were measured on the physical main axis above. Preserve
|
|
1463
1532
|
// that result, including content sizing for an indefinite percentage.
|
|
1464
1533
|
if (hasFlexBasis(childNode)) return;
|
|
1465
|
-
if (childNode.
|
|
1534
|
+
if (childNode.computedStyle().flex <= 0) return;
|
|
1466
1535
|
if (isRow_) {
|
|
1467
1536
|
if (hasExplicitWidth(childNode)) return;
|
|
1468
1537
|
if (childNode.layout.width == 0) return;
|
|
@@ -1482,15 +1551,15 @@ private:
|
|
|
1482
1551
|
|
|
1483
1552
|
int baselineCrossSize(int start, int count, int crossSize) const
|
|
1484
1553
|
{
|
|
1485
|
-
if (isRow_ && node_.
|
|
1554
|
+
if (isRow_ && node_.computedStyle().display == kDisplayFlex) {
|
|
1486
1555
|
for (int alignment : {5, kAlignLastBaseline}) {
|
|
1487
1556
|
int ascent = 0, descent = 0;
|
|
1488
1557
|
for (int i = start; i < start + count; ++i) {
|
|
1489
1558
|
const Node &child = Tree::instance().nodes()[children_[i]];
|
|
1490
|
-
if (crossAlignFor(child) != alignment || (child.
|
|
1559
|
+
if (crossAlignFor(child) != alignment || (child.computedStyle().margin_auto & 5)) continue;
|
|
1491
1560
|
const int baseline = childBaseline(child, alignment == kAlignLastBaseline);
|
|
1492
|
-
ascent = std::max(ascent, child.
|
|
1493
|
-
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);
|
|
1494
1563
|
}
|
|
1495
1564
|
crossSize = std::max(crossSize, ascent + descent);
|
|
1496
1565
|
}
|
|
@@ -1512,10 +1581,10 @@ private:
|
|
|
1512
1581
|
|
|
1513
1582
|
int totalFlexGrowForLine(const FlexLine &line, Node *nodes) const
|
|
1514
1583
|
{
|
|
1515
|
-
if (node_.
|
|
1584
|
+
if (node_.computedStyle().display != kDisplayFlex) return 0;
|
|
1516
1585
|
int totalFlex = 0;
|
|
1517
1586
|
for (int i = 0; i < line.count; i++) {
|
|
1518
|
-
totalFlex += nodes[children_[line.start + i]].
|
|
1587
|
+
totalFlex += nodes[children_[line.start + i]].computedStyle().flex;
|
|
1519
1588
|
}
|
|
1520
1589
|
return totalFlex;
|
|
1521
1590
|
}
|
|
@@ -1533,8 +1602,8 @@ private:
|
|
|
1533
1602
|
// deficit redistributes to shrinkable siblings or becomes overflow.
|
|
1534
1603
|
bool childMainSizeIsShrinkable(const Node &childNode) const
|
|
1535
1604
|
{
|
|
1536
|
-
if (node_.
|
|
1537
|
-
if (childNode.
|
|
1605
|
+
if (node_.computedStyle().display != kDisplayFlex) return false;
|
|
1606
|
+
if (childNode.computedStyle().flex_shrink <= 0) return false;
|
|
1538
1607
|
if (!isRow_ && childNode.type == NodeType::Text) return false;
|
|
1539
1608
|
return true;
|
|
1540
1609
|
}
|
|
@@ -1547,7 +1616,7 @@ private:
|
|
|
1547
1616
|
if (!childMainSizeIsShrinkable(childNode)) continue;
|
|
1548
1617
|
const int basis = childMainSize(childNode);
|
|
1549
1618
|
if (basis <= 0) continue;
|
|
1550
|
-
totalShrink += childNode.
|
|
1619
|
+
totalShrink += childNode.computedStyle().flex_shrink * basis;
|
|
1551
1620
|
}
|
|
1552
1621
|
return totalShrink;
|
|
1553
1622
|
}
|
|
@@ -1561,9 +1630,9 @@ private:
|
|
|
1561
1630
|
for (int i = 0; i < line.count; i++) {
|
|
1562
1631
|
const int child = children_[line.start + i];
|
|
1563
1632
|
Node &childNode = nodes[child];
|
|
1564
|
-
if (childNode.
|
|
1633
|
+
if (childNode.computedStyle().flex <= 0) continue;
|
|
1565
1634
|
lastGrowChild = child;
|
|
1566
|
-
const int change = (delta * childNode.
|
|
1635
|
+
const int change = (delta * childNode.computedStyle().flex) / totalGrow;
|
|
1567
1636
|
applied += applyFlexMainSizeDelta(child, childNode, change);
|
|
1568
1637
|
}
|
|
1569
1638
|
|
|
@@ -1588,7 +1657,7 @@ private:
|
|
|
1588
1657
|
const int basis = childMainSize(childNode);
|
|
1589
1658
|
if (basis <= 0) continue;
|
|
1590
1659
|
lastShrinkChild = child;
|
|
1591
|
-
const int change = (magnitude * childNode.
|
|
1660
|
+
const int change = (magnitude * childNode.computedStyle().flex_shrink * basis) / totalShrink;
|
|
1592
1661
|
applied += applyFlexMainSizeDelta(child, childNode, -change);
|
|
1593
1662
|
}
|
|
1594
1663
|
|
|
@@ -1612,33 +1681,33 @@ private:
|
|
|
1612
1681
|
// scroll/hidden box really does have a zero automatic minimum.
|
|
1613
1682
|
int automaticMinimumMainSize(const Node &childNode) const
|
|
1614
1683
|
{
|
|
1615
|
-
const int explicitMin = isRow_ ? childNode.
|
|
1684
|
+
const int explicitMin = isRow_ ? childNode.computedStyle().min_width : childNode.computedStyle().min_height;
|
|
1616
1685
|
if (explicitMin != kUnset) return 0;
|
|
1617
|
-
if (isScrollableOverflow(isRow_ ? overflowX(childNode.
|
|
1686
|
+
if (isScrollableOverflow(isRow_ ? overflowX(childNode.computedStyle()) : overflowY(childNode.computedStyle()))) return 0;
|
|
1618
1687
|
const Node *nodes = Tree::instance().nodes();
|
|
1619
1688
|
int extent = 0;
|
|
1620
1689
|
for (int c = childNode.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1621
1690
|
const Node &grand = nodes[c];
|
|
1622
|
-
if (isDisplayNone(grand.
|
|
1691
|
+
if (isDisplayNone(grand.computedStyle()) || isOutOfFlowPosition(grand.computedStyle().position)) continue;
|
|
1623
1692
|
// layout.{x,y} are still parent-relative here: resolveAbsoluteCoords runs
|
|
1624
1693
|
// after the whole layout pass.
|
|
1625
1694
|
const int end = isRow_
|
|
1626
|
-
? grand.layout.x + grand.layout.width + grand.
|
|
1627
|
-
: 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];
|
|
1628
1697
|
if (end > extent) extent = end;
|
|
1629
1698
|
}
|
|
1630
|
-
if (extent > 0) extent += isRow_ ? boxInset(childNode.
|
|
1699
|
+
if (extent > 0) extent += isRow_ ? boxInset(childNode.computedStyle(), 1) : boxInset(childNode.computedStyle(), 2);
|
|
1631
1700
|
if (preferredRatio(childNode) > 0 &&
|
|
1632
1701
|
((isRow_ ? hasExplicitHeight(childNode) : hasExplicitWidth(childNode)) || definiteFlexCrossSize(node_, childNode, isRow_))) {
|
|
1633
1702
|
const int transferred = ratioTransferredSize(childNode, isRow_ ? childNode.layout.height : childNode.layout.width, isRow_);
|
|
1634
1703
|
extent = childNode.type == NodeType::Image ? std::min(extent, transferred) : std::max(extent, transferred);
|
|
1635
1704
|
}
|
|
1636
1705
|
if (extent <= 0) return 0;
|
|
1637
|
-
const int max = isRow_ ? childNode.
|
|
1638
|
-
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_));
|
|
1639
1708
|
if (isRow_ ? hasExplicitWidth(childNode) : hasExplicitHeight(childNode)) {
|
|
1640
1709
|
const int specified = isRow_ ? resolvedStyleWidth(childNode, mainAvail_) : resolvedStyleHeight(childNode, mainAvail_);
|
|
1641
|
-
extent = std::min(extent, contentSizeToBorderSize(childNode.
|
|
1710
|
+
extent = std::min(extent, contentSizeToBorderSize(childNode.computedStyle(), specified, isRow_));
|
|
1642
1711
|
}
|
|
1643
1712
|
return extent;
|
|
1644
1713
|
}
|
|
@@ -1675,7 +1744,7 @@ private:
|
|
|
1675
1744
|
|
|
1676
1745
|
void applyJustifyContent(int remaining, int *mainOffset) const
|
|
1677
1746
|
{
|
|
1678
|
-
switch (usedAlignment(node_.
|
|
1747
|
+
switch (usedAlignment(node_.computedStyle().justify_content, remaining, node_.computedStyle().flex_direction_explicit && node_.computedStyle().flex_direction >= 2)) {
|
|
1679
1748
|
case 0:
|
|
1680
1749
|
break;
|
|
1681
1750
|
case 1:
|
|
@@ -1690,16 +1759,16 @@ private:
|
|
|
1690
1759
|
void positionLineChildren(const FlexLine &line, Node *nodes, int mainOffset, int crossOffset, int autoSpace = 0, int autoCount = 0, int distributedFree = 0)
|
|
1691
1760
|
{
|
|
1692
1761
|
#if GEA_CSS_FLEX_WRAP
|
|
1693
|
-
const bool wrapReversed = (node_.
|
|
1762
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1694
1763
|
#else
|
|
1695
1764
|
constexpr bool wrapReversed = false;
|
|
1696
1765
|
#endif
|
|
1697
|
-
const bool flex = node_.
|
|
1698
|
-
const bool logicalRow = flexRowDirection(node_.
|
|
1766
|
+
const bool flex = node_.computedStyle().display == kDisplayFlex;
|
|
1767
|
+
const bool logicalRow = flexRowDirection(node_.computedStyle());
|
|
1699
1768
|
const int mode = writingMode(node_);
|
|
1700
1769
|
const bool blockReversed = mode == 2 || mode == 3;
|
|
1701
1770
|
const bool inlineReversed = rightToLeft(node_) != (mode == 4);
|
|
1702
|
-
const bool reverseMain = flex && ((node_.
|
|
1771
|
+
const bool reverseMain = flex && ((node_.computedStyle().flex_direction_explicit && node_.computedStyle().flex_direction >= 2) != (logicalRow ? inlineReversed : blockReversed));
|
|
1703
1772
|
const bool reverseCross = flex && ((wrapReversed) != (logicalRow ? blockReversed : inlineReversed));
|
|
1704
1773
|
const int mainBefore = isRow_ ? (reverseMain ? 1 : 3) : (reverseMain ? 2 : 0);
|
|
1705
1774
|
const int mainAfter = (mainBefore + 2) % 4;
|
|
@@ -1707,7 +1776,7 @@ private:
|
|
|
1707
1776
|
const int crossAfter = (crossBefore + 2) % 4;
|
|
1708
1777
|
int autoUsed = 0;
|
|
1709
1778
|
auto autoMargin = [&](const Node &child, int side) {
|
|
1710
|
-
if (!(child.
|
|
1779
|
+
if (!(child.computedStyle().margin_auto & (1 << side)) || !autoCount) return 0;
|
|
1711
1780
|
const int before = autoSpace * autoUsed / autoCount;
|
|
1712
1781
|
return autoSpace * ++autoUsed / autoCount - before;
|
|
1713
1782
|
};
|
|
@@ -1720,14 +1789,14 @@ private:
|
|
|
1720
1789
|
if (isRow_) {
|
|
1721
1790
|
for (int i = 0; i < line.count; i++) {
|
|
1722
1791
|
Node &probe = nodes[children_[line.start + i]];
|
|
1723
|
-
if (probe.
|
|
1792
|
+
if (probe.computedStyle().margin_auto & 5) continue;
|
|
1724
1793
|
if (crossAlignFor(probe) == kAlignLastBaseline) {
|
|
1725
1794
|
const int baseline = childBaseline(probe, true);
|
|
1726
|
-
lineMaxLastDescent = std::max(lineMaxLastDescent, probe.
|
|
1727
|
-
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);
|
|
1728
1797
|
}
|
|
1729
1798
|
if (crossAlignFor(probe) != 5) continue;
|
|
1730
|
-
const int baseline = probe.
|
|
1799
|
+
const int baseline = probe.computedStyle().margin[0] + childBaseline(probe);
|
|
1731
1800
|
if (baseline > lineMaxBaseline) lineMaxBaseline = baseline;
|
|
1732
1801
|
}
|
|
1733
1802
|
}
|
|
@@ -1736,17 +1805,17 @@ private:
|
|
|
1736
1805
|
const int child = children_[line.start + i];
|
|
1737
1806
|
Node &childNode = nodes[child];
|
|
1738
1807
|
|
|
1739
|
-
const int mainMarginBefore = childNode.
|
|
1740
|
-
const int mainMarginAfter = childNode.
|
|
1741
|
-
const int crossMarginBefore = childNode.
|
|
1742
|
-
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];
|
|
1743
1812
|
const int crossSize = isRow_ ? childNode.layout.height : childNode.layout.width;
|
|
1744
1813
|
const int crossTotal = crossSize + crossMarginBefore + crossMarginAfter;
|
|
1745
1814
|
|
|
1746
1815
|
mainOffset += mainMarginBefore;
|
|
1747
1816
|
int crossPosition = crossOffset + crossMarginBefore;
|
|
1748
|
-
const bool crossAutoBefore = childNode.
|
|
1749
|
-
const bool crossAutoAfter = childNode.
|
|
1817
|
+
const bool crossAutoBefore = childNode.computedStyle().margin_auto & (1 << crossBefore);
|
|
1818
|
+
const bool crossAutoAfter = childNode.computedStyle().margin_auto & (1 << crossAfter);
|
|
1750
1819
|
if (crossAutoBefore || crossAutoAfter) {
|
|
1751
1820
|
const int free = std::max(0, line.crossSize - crossTotal);
|
|
1752
1821
|
if (crossAutoBefore) crossPosition += crossAutoAfter ? free / 2 : free;
|
|
@@ -1760,17 +1829,17 @@ private:
|
|
|
1760
1829
|
}
|
|
1761
1830
|
|
|
1762
1831
|
if (isRow_) {
|
|
1763
|
-
childNode.layout.x = mainOffset + distributedAlignmentOffset(node_.
|
|
1832
|
+
childNode.layout.x = mainOffset + distributedAlignmentOffset(node_.computedStyle().justify_content, distributedFree, i, line.count);
|
|
1764
1833
|
childNode.layout.y = crossPosition;
|
|
1765
1834
|
} else {
|
|
1766
1835
|
childNode.layout.x = crossPosition;
|
|
1767
|
-
childNode.layout.y = mainOffset + distributedAlignmentOffset(node_.
|
|
1836
|
+
childNode.layout.y = mainOffset + distributedAlignmentOffset(node_.computedStyle().justify_content, distributedFree, i, line.count);
|
|
1768
1837
|
}
|
|
1769
1838
|
|
|
1770
1839
|
const bool reverseX = isRow_ ? reverseMain : reverseCross;
|
|
1771
1840
|
const bool reverseY = isRow_ ? reverseCross : reverseMain;
|
|
1772
|
-
if (reverseX) childNode.layout.x = node_.layout.width - childNode.layout.x - childNode.layout.width + boxInset(node_.
|
|
1773
|
-
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);
|
|
1774
1843
|
|
|
1775
1844
|
const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
|
|
1776
1845
|
mainOffset += mainSize + mainMarginAfter + mainGap_;
|
|
@@ -1786,14 +1855,14 @@ private:
|
|
|
1786
1855
|
// flex container keeps reading `align-items`.
|
|
1787
1856
|
int crossAlignFor(const Node &childNode) const
|
|
1788
1857
|
{
|
|
1789
|
-
if (childNode.
|
|
1790
|
-
return inlineRow_ ? 5 : node_.
|
|
1858
|
+
if (childNode.computedStyle().align_self >= 0) return childNode.computedStyle().align_self;
|
|
1859
|
+
return inlineRow_ ? 5 : node_.computedStyle().align_items;
|
|
1791
1860
|
}
|
|
1792
1861
|
|
|
1793
1862
|
void positionCrossAxisChild(int child, Node &childNode, int lineCrossSize, int crossMarginBefore, int crossMarginAfter, int crossTotal, int *crossPosition, int lineMaxBaseline, int lineLastBaseline)
|
|
1794
1863
|
{
|
|
1795
1864
|
#if GEA_CSS_FLEX_WRAP
|
|
1796
|
-
const bool wrapReversed = (node_.
|
|
1865
|
+
const bool wrapReversed = (node_.computedStyle().flex_wrap & 3) == 2;
|
|
1797
1866
|
#else
|
|
1798
1867
|
constexpr bool wrapReversed = false;
|
|
1799
1868
|
#endif
|
|
@@ -1806,11 +1875,11 @@ private:
|
|
|
1806
1875
|
switch (align) {
|
|
1807
1876
|
case 0:
|
|
1808
1877
|
if (isRow_) {
|
|
1809
|
-
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
1878
|
+
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression)) {
|
|
1810
1879
|
childNode.layout.height = lineCrossSize - crossMarginBefore - crossMarginAfter;
|
|
1811
1880
|
engine_.repositionChildren(child);
|
|
1812
1881
|
}
|
|
1813
|
-
} else if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
1882
|
+
} else if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression)) {
|
|
1814
1883
|
childNode.layout.width = lineCrossSize - crossMarginBefore - crossMarginAfter;
|
|
1815
1884
|
engine_.repositionChildren(child);
|
|
1816
1885
|
}
|
|
@@ -1846,7 +1915,7 @@ private:
|
|
|
1846
1915
|
// inline boxes use margin edges.
|
|
1847
1916
|
int childBaseline(const Node &childNode, bool last = false) const
|
|
1848
1917
|
{
|
|
1849
|
-
if ((childNode.type == NodeType::Text || isLineBreak(childNode)) && childNode.
|
|
1918
|
+
if ((childNode.type == NodeType::Text || isLineBreak(childNode)) && childNode.computedStyle().font_id >= 0)
|
|
1850
1919
|
return TextRenderer::baselineOffset(childNode, last);
|
|
1851
1920
|
// An inline wrapper (a <span> around text) carries no text of its own, so
|
|
1852
1921
|
// CSS takes the baseline of its FIRST in-flow line box. Its children were
|
|
@@ -1859,11 +1928,11 @@ private:
|
|
|
1859
1928
|
const Node *nodes = Tree::instance().nodes();
|
|
1860
1929
|
for (int c = last ? childNode.last_child : childNode.first_child; c >= 0; c = last ? nodes[c].prev_sibling : nodes[c].next_sibling) {
|
|
1861
1930
|
const Node &inner = nodes[c];
|
|
1862
|
-
if (isDisplayNone(inner.
|
|
1931
|
+
if (isDisplayNone(inner.computedStyle()) || isOutOfFlowPosition(inner.computedStyle().position)) continue;
|
|
1863
1932
|
return inner.layout.y + childBaseline(inner, last);
|
|
1864
1933
|
}
|
|
1865
1934
|
}
|
|
1866
|
-
return childNode.layout.height + (inlineRow_ ? childNode.
|
|
1935
|
+
return childNode.layout.height + (inlineRow_ ? childNode.computedStyle().margin[2] : 0);
|
|
1867
1936
|
}
|
|
1868
1937
|
|
|
1869
1938
|
int totalCrossSize(int lineCount) const
|
|
@@ -1921,17 +1990,17 @@ static bool isInlineLevelTag(const char *tag)
|
|
|
1921
1990
|
bool splitInlineWrapper(const Node *nodes, int id)
|
|
1922
1991
|
{
|
|
1923
1992
|
const Node &n = nodes[id];
|
|
1924
|
-
if (n.type != NodeType::View || n.
|
|
1925
|
-
!isInlineLevelTag(tagFromId(n.tag_id)) || n.
|
|
1926
|
-
!FlexLayoutPass::paintsNoBox(n) || boxInsets(n.
|
|
1927
|
-
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;
|
|
1928
1997
|
bool containsBlock = false;
|
|
1929
1998
|
for (int c = n.first_child; c >= 0; c = nodes[c].next_sibling) {
|
|
1930
1999
|
const Node &child = nodes[c];
|
|
1931
|
-
if (isDisplayNone(child.
|
|
1932
|
-
if (isOutOfFlowPosition(child.
|
|
1933
|
-
if (child.
|
|
1934
|
-
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;
|
|
1935
2004
|
if (splitInlineWrapper(nodes, c)) containsBlock = true;
|
|
1936
2005
|
}
|
|
1937
2006
|
return containsBlock;
|
|
@@ -1942,8 +2011,8 @@ int formattingEdgeNode(const Node *nodes, int id, bool last)
|
|
|
1942
2011
|
if (!splitInlineWrapper(nodes, id)) return id;
|
|
1943
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) {
|
|
1944
2013
|
const Node &child = nodes[c];
|
|
1945
|
-
if (isDisplayNone(child.
|
|
1946
|
-
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) &&
|
|
1947
2016
|
child.text.find_first_not_of(" \t\r\n\f") == std::string::npos) continue;
|
|
1948
2017
|
return formattingEdgeNode(nodes, c, last);
|
|
1949
2018
|
}
|
|
@@ -1953,7 +2022,7 @@ int formattingEdgeNode(const Node *nodes, int id, bool last)
|
|
|
1953
2022
|
template<class Visit>
|
|
1954
2023
|
void visitFormattingChildren(const Node *nodes, int parent, const Visit &visit, bool reverse = false)
|
|
1955
2024
|
{
|
|
1956
|
-
const bool project = nodes[parent].
|
|
2025
|
+
const bool project = nodes[parent].computedStyle().display == kDisplayBlock && !nodes[parent].computedStyle().flex_direction_explicit;
|
|
1957
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) {
|
|
1958
2027
|
if (project && splitInlineWrapper(nodes, c)) visitFormattingChildren(nodes, c, visit, reverse);
|
|
1959
2028
|
else visit(c);
|
|
@@ -1973,21 +2042,21 @@ public:
|
|
|
1973
2042
|
#if GEA_CSS_FIRST_LINE
|
|
1974
2043
|
if (NodeRareData *rare = rareDataFor(id_)) rare->firstLineBackground.lineValid = false;
|
|
1975
2044
|
#endif
|
|
1976
|
-
if (isDisplayNone(node_.
|
|
2045
|
+
if (isDisplayNone(node_.computedStyle())) return;
|
|
1977
2046
|
prepareOwnSize();
|
|
1978
2047
|
|
|
1979
2048
|
if (isLineBreak(node_) && LayoutEngine::isInlineLevelNode(node_) &&
|
|
1980
|
-
(node_.parent < 0 || (nodes_[node_.parent].
|
|
2049
|
+
(node_.parent < 0 || (nodes_[node_.parent].computedStyle().display != kDisplayFlex && !isDisplayGrid(nodes_[node_.parent].computedStyle())))) {
|
|
1981
2050
|
node_.layout.width = 0;
|
|
1982
|
-
node_.layout.height = clampInt16(TextRenderer::measureHeight(" ", node_.
|
|
1983
|
-
node_.
|
|
2051
|
+
node_.layout.height = clampInt16(TextRenderer::measureHeight(" ", node_.computedStyle().font_id,
|
|
2052
|
+
node_.computedStyle().font_size, 0, node_.computedStyle().line_height));
|
|
1984
2053
|
return;
|
|
1985
2054
|
}
|
|
1986
2055
|
|
|
1987
2056
|
if (node_.type == NodeType::Text) {
|
|
1988
2057
|
const std::int64_t __tmT0 = refreshPerfNowUs();
|
|
1989
2058
|
TextRenderer::layout(id_, availWidth_);
|
|
1990
|
-
refreshPerfStatsMutable().treeLayoutTextUs += refreshPerfNowUs() - __tmT0;
|
|
2059
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutTextUs += refreshPerfNowUs() - __tmT0);
|
|
1991
2060
|
return;
|
|
1992
2061
|
}
|
|
1993
2062
|
|
|
@@ -2011,7 +2080,7 @@ public:
|
|
|
2011
2080
|
if (!scratch.valid()) return;
|
|
2012
2081
|
|
|
2013
2082
|
const int childCount = collectFormattingChildren(scratch.children(), kMaxChildren);
|
|
2014
|
-
if (childCount == 0 && !isDisplayGrid(node_.
|
|
2083
|
+
if (childCount == 0 && !isDisplayGrid(node_.computedStyle())) {
|
|
2015
2084
|
autosizeEmptyNode();
|
|
2016
2085
|
positionAbsoluteChildren();
|
|
2017
2086
|
applyRelativeOffsets();
|
|
@@ -2019,7 +2088,7 @@ public:
|
|
|
2019
2088
|
return;
|
|
2020
2089
|
}
|
|
2021
2090
|
|
|
2022
|
-
if (isDisplayGrid(node_.
|
|
2091
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
2023
2092
|
layoutGridChildren(scratch.children(), childCount, padWidth, padHeight, true);
|
|
2024
2093
|
updateScrollContentSize();
|
|
2025
2094
|
positionAbsoluteChildren();
|
|
@@ -2078,12 +2147,12 @@ public:
|
|
|
2078
2147
|
if (!scratch.valid()) return;
|
|
2079
2148
|
|
|
2080
2149
|
const int childCount = collectFormattingChildren(scratch.children(), kMaxChildren);
|
|
2081
|
-
if (childCount == 0 && !isDisplayGrid(node_.
|
|
2150
|
+
if (childCount == 0 && !isDisplayGrid(node_.computedStyle())) {
|
|
2082
2151
|
positionAbsoluteChildren();
|
|
2083
2152
|
return;
|
|
2084
2153
|
}
|
|
2085
2154
|
|
|
2086
|
-
if (isDisplayGrid(node_.
|
|
2155
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
2087
2156
|
layoutGridChildren(scratch.children(), childCount, padWidth, padHeight, false);
|
|
2088
2157
|
positionAbsoluteChildren();
|
|
2089
2158
|
applyRelativeOffsets();
|
|
@@ -2121,10 +2190,10 @@ public:
|
|
|
2121
2190
|
// handled as well as introducing or resizing one.
|
|
2122
2191
|
const bool horizontal = writingMode(node_) != 0;
|
|
2123
2192
|
return !blockBox(node_) || establishesBlockContext(node_) ||
|
|
2124
|
-
(boxInset(node_.
|
|
2125
|
-
(boxInset(node_.
|
|
2193
|
+
(boxInset(node_.computedStyle(), blockMarginSide(false)) > 0 &&
|
|
2194
|
+
(boxInset(node_.computedStyle(), blockMarginSide(true)) > 0 ||
|
|
2126
2195
|
(horizontal ? hasExplicitWidth(node_) : hasExplicitHeight(node_)) ||
|
|
2127
|
-
(horizontal ? node_.
|
|
2196
|
+
(horizontal ? node_.computedStyle().min_width : node_.computedStyle().min_height) > 0));
|
|
2128
2197
|
}
|
|
2129
2198
|
|
|
2130
2199
|
private:
|
|
@@ -2143,20 +2212,20 @@ private:
|
|
|
2143
2212
|
bool splitInlineChildren_ = false;
|
|
2144
2213
|
int collectFormattingChildren(int *children, int capacity)
|
|
2145
2214
|
{
|
|
2146
|
-
if (node_.
|
|
2215
|
+
if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit)
|
|
2147
2216
|
return engine_.collectChildren(id_, children, capacity, true);
|
|
2148
2217
|
int count = 0;
|
|
2149
2218
|
auto collect = [&](auto &&self, int parent) -> void {
|
|
2150
2219
|
for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
|
|
2151
2220
|
Node &child = nodes_[c];
|
|
2152
|
-
if (isDisplayNone(child.
|
|
2221
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position) || suppressAnonymousWhitespace(nodes_, parent, c)) continue;
|
|
2153
2222
|
if (splitInlineWrapper(nodes_, c)) {
|
|
2154
2223
|
splitInlineChildren_ = true;
|
|
2155
2224
|
child.layout.x = child.layout.y = child.layout.width = child.layout.height = 0;
|
|
2156
2225
|
#if GEA_CSS_SCROLLING
|
|
2157
2226
|
child.layout.scroll_content_width = child.layout.scroll_content_height = 0;
|
|
2158
2227
|
#endif
|
|
2159
|
-
|
|
2228
|
+
engine_.invalidateMemo(c);
|
|
2160
2229
|
self(self, c);
|
|
2161
2230
|
} else if (count < capacity) children[count++] = c;
|
|
2162
2231
|
}
|
|
@@ -2187,28 +2256,28 @@ private:
|
|
|
2187
2256
|
|
|
2188
2257
|
bool blockBox(const Node &n) const
|
|
2189
2258
|
{
|
|
2190
|
-
return n.type == NodeType::View && !isDisplayNone(n.
|
|
2191
|
-
(n.
|
|
2259
|
+
return n.type == NodeType::View && !isDisplayNone(n.computedStyle()) &&
|
|
2260
|
+
(n.computedStyle().display_explicit || !isInlineLevelTag(tagFromId(n.tag_id)));
|
|
2192
2261
|
}
|
|
2193
2262
|
|
|
2194
2263
|
bool flowChild(int parent, int child) const
|
|
2195
2264
|
{
|
|
2196
|
-
return !isDisplayNone(nodes_[child].
|
|
2197
|
-
!nodes_[child].
|
|
2265
|
+
return !isDisplayNone(nodes_[child].computedStyle()) && !isOutOfFlowPosition(nodes_[child].computedStyle().position) &&
|
|
2266
|
+
!nodes_[child].computedStyle().float_side && !suppressAnonymousWhitespace(nodes_, parent, child);
|
|
2198
2267
|
}
|
|
2199
2268
|
|
|
2200
2269
|
bool establishesBlockContext(const Node &n) const
|
|
2201
2270
|
{
|
|
2202
|
-
return n.parent < 0 || isOutOfFlowPosition(n.
|
|
2203
|
-
n.
|
|
2204
|
-
(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()) ||
|
|
2205
2274
|
writingMode(n) != writingMode(nodes_[n.parent])));
|
|
2206
2275
|
}
|
|
2207
2276
|
|
|
2208
2277
|
void encloseFloatDescendants()
|
|
2209
2278
|
{
|
|
2210
|
-
if (node_.
|
|
2211
|
-
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);
|
|
2212
2281
|
// With floats absent, no descendant can extend this bound. Keep the
|
|
2213
2282
|
// final height clamp without walking the same subtree at every ancestor.
|
|
2214
2283
|
#if GEA_CSS_FLOATS
|
|
@@ -2218,20 +2287,20 @@ private:
|
|
|
2218
2287
|
auto visit = [&](auto &&self, int parent, int y) -> void {
|
|
2219
2288
|
for (int id = nodes_[parent].first_child; id >= 0; id = nodes_[id].next_sibling) {
|
|
2220
2289
|
const Node &child = nodes_[id];
|
|
2221
|
-
if (isDisplayNone(child.
|
|
2290
|
+
if (isDisplayNone(child.computedStyle()) || isOutOfFlowPosition(child.computedStyle().position)) continue;
|
|
2222
2291
|
int top = y + child.layout.y;
|
|
2223
|
-
if (parent != id_ && child.
|
|
2292
|
+
if (parent != id_ && child.computedStyle().position == 2) {
|
|
2224
2293
|
LayoutNodePass owner(engine_, parent, 0, 0);
|
|
2225
2294
|
if (hasPositionOffset<0>(child)) top -= owner.resolvedRelativePositionOffset<0>(child);
|
|
2226
2295
|
else if (hasPositionOffset<2>(child)) top += owner.resolvedRelativePositionOffset<2>(child);
|
|
2227
2296
|
}
|
|
2228
|
-
if (child.
|
|
2297
|
+
if (child.computedStyle().float_side) bottom = std::max(bottom, top + child.layout.height + child.computedStyle().margin[2]);
|
|
2229
2298
|
else if (!establishesBlockContext(child)) self(self, id, top);
|
|
2230
2299
|
}
|
|
2231
2300
|
};
|
|
2232
2301
|
visit(visit, id_, 0);
|
|
2233
2302
|
#endif
|
|
2234
|
-
node_.layout.height = clampBorderSize(engine_, node_, bottom + boxInset(node_.
|
|
2303
|
+
node_.layout.height = clampBorderSize(engine_, node_, bottom + boxInset(node_.computedStyle(), 2), false);
|
|
2235
2304
|
}
|
|
2236
2305
|
|
|
2237
2306
|
int blockMarginSide(bool end) const
|
|
@@ -2245,7 +2314,7 @@ private:
|
|
|
2245
2314
|
const Node &n = nodes_[id];
|
|
2246
2315
|
const bool horizontal = writingMode(node_) != 0;
|
|
2247
2316
|
if (!blockBox(n) || establishesBlockContext(n) || (horizontal ? n.layout.width : n.layout.height) != 0 ||
|
|
2248
|
-
(horizontal ? n.
|
|
2317
|
+
(horizontal ? n.computedStyle().min_width : n.computedStyle().min_height) > 0 || boxInsets(n.computedStyle(), horizontal)) return false;
|
|
2249
2318
|
bool through = true;
|
|
2250
2319
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2251
2320
|
if (flowChild(nodes_[c].parent, c) && ((floatContext_ && floatContext_->hasClearance(c)) || !collapsesThrough(c))) through = false;
|
|
@@ -2257,10 +2326,10 @@ private:
|
|
|
2257
2326
|
{
|
|
2258
2327
|
const Node &n = nodes_[id];
|
|
2259
2328
|
const bool horizontal = writingMode(node_) != 0;
|
|
2260
|
-
if (!blockBox(n) || establishesBlockContext(n) || boxInset(n.
|
|
2329
|
+
if (!blockBox(n) || establishesBlockContext(n) || boxInset(n.computedStyle(), blockMarginSide(bottom))) return false;
|
|
2261
2330
|
if (bottom && ((horizontal ? hasExplicitWidth(n) : hasExplicitHeight(n)) ||
|
|
2262
|
-
isIntrinsicSizeExpression(horizontal ? n.
|
|
2263
|
-
(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;
|
|
2264
2333
|
int edge = -1;
|
|
2265
2334
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2266
2335
|
if (!flowChild(nodes_[c].parent, c) || (edge >= 0 && !bottom)) return;
|
|
@@ -2274,10 +2343,10 @@ private:
|
|
|
2274
2343
|
{
|
|
2275
2344
|
const Node &n = nodes_[id];
|
|
2276
2345
|
CollapsedMargin margin;
|
|
2277
|
-
margin.add(n.
|
|
2346
|
+
margin.add(n.computedStyle().margin[blockMarginSide(bottom)]);
|
|
2278
2347
|
CollapsedMargin descendants;
|
|
2279
2348
|
if (!separateBottom && collapsesThrough(id)) {
|
|
2280
|
-
margin.add(n.
|
|
2349
|
+
margin.add(n.computedStyle().margin[blockMarginSide(!bottom)]);
|
|
2281
2350
|
visitFormattingChildren(nodes_, id, [&](int c) {
|
|
2282
2351
|
if (flowChild(nodes_[c].parent, c)) descendants.add(childEdgeMargin(id, c, false));
|
|
2283
2352
|
});
|
|
@@ -2300,8 +2369,8 @@ private:
|
|
|
2300
2369
|
bool trimmedBlockEdge(int owner, int id, bool bottom) const
|
|
2301
2370
|
{
|
|
2302
2371
|
const Node &container = nodes_[owner];
|
|
2303
|
-
const int trim = (GEA_CSS_MARGIN_TRIM ? rstyle(container.
|
|
2304
|
-
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;
|
|
2305
2374
|
for (bool end : {false, true}) {
|
|
2306
2375
|
if (!(trim & (end ? 2 : 1)) || (end != bottom && !collapsesThrough(id))) continue;
|
|
2307
2376
|
bool adjacent = true, found = false;
|
|
@@ -2324,52 +2393,52 @@ private:
|
|
|
2324
2393
|
|
|
2325
2394
|
bool layoutBlockChildren(int *children, int count, int contentWidth, int contentHeight, bool autosize)
|
|
2326
2395
|
{
|
|
2327
|
-
if (node_.
|
|
2396
|
+
if (node_.computedStyle().display != kDisplayBlock || node_.computedStyle().flex_direction_explicit) return false;
|
|
2328
2397
|
const bool vertical = writingMode(node_) != 0;
|
|
2329
2398
|
for (int i = 0; i < count; ++i)
|
|
2330
|
-
if (!blockBox(nodes_[children[i]]) || nodes_[children[i]].
|
|
2399
|
+
if (!blockBox(nodes_[children[i]]) || nodes_[children[i]].computedStyle().float_side) return false;
|
|
2331
2400
|
if (vertical) {
|
|
2332
2401
|
const bool measureInline = autosize && !hasExplicitHeight(node_) && node_.parent >= 0;
|
|
2333
2402
|
int intrinsicHeight = 0;
|
|
2334
2403
|
for (int i = 0; i < count; ++i) {
|
|
2335
2404
|
engine_.layoutNode(children[i], contentWidth, contentHeight);
|
|
2336
2405
|
const Node &child = nodes_[children[i]];
|
|
2337
|
-
intrinsicHeight = std::max(intrinsicHeight, child.layout.height + child.
|
|
2406
|
+
intrinsicHeight = std::max(intrinsicHeight, child.layout.height + child.computedStyle().margin[0] + child.computedStyle().margin[2]);
|
|
2338
2407
|
}
|
|
2339
2408
|
if (measureInline) {
|
|
2340
|
-
node_.layout.height = clampLayoutSize(node_, intrinsicHeight + boxInsets(node_.
|
|
2409
|
+
node_.layout.height = clampLayoutSize(node_, intrinsicHeight + boxInsets(node_.computedStyle(), false), false);
|
|
2341
2410
|
contentHeight = paddedHeight();
|
|
2342
2411
|
}
|
|
2343
2412
|
for (int i = 0; i < count; ++i) {
|
|
2344
2413
|
const int id = children[i]; Node &child = nodes_[id];
|
|
2345
2414
|
if (measureInline) engine_.layoutNode(id, contentWidth, contentHeight);
|
|
2346
|
-
if (!hasExplicitHeight(child) && !isIntrinsicSizeExpression(child.
|
|
2415
|
+
if (!hasExplicitHeight(child) && !isIntrinsicSizeExpression(child.computedStyle().height_expression) && writingMode(child) != 0 &&
|
|
2347
2416
|
!(preferredRatio(child) > 0 && hasExplicitWidth(child))) {
|
|
2348
|
-
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);
|
|
2349
2418
|
if (child.layout.height != height) {
|
|
2350
2419
|
child.layout.height = clampInt16(height); engine_.repositionChildren(id);
|
|
2351
2420
|
}
|
|
2352
2421
|
}
|
|
2353
|
-
const int slack = contentHeight - child.layout.height - child.
|
|
2354
|
-
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;
|
|
2355
2424
|
int offset = slack > 0 && autoTop ? (autoBottom ? slack / 2 : slack) : 0;
|
|
2356
2425
|
if (!autoTop && !autoBottom && gridAxisReversed(node_, false)) offset = slack;
|
|
2357
|
-
child.layout.y = boxInset(node_.
|
|
2426
|
+
child.layout.y = boxInset(node_.computedStyle(), 0) + child.computedStyle().margin[0] + offset;
|
|
2358
2427
|
}
|
|
2359
2428
|
} else {
|
|
2360
2429
|
// Measure content before assigning the normal-flow fill width. A flex
|
|
2361
2430
|
// item, float, or absolute box can use this intrinsic width; its parent
|
|
2362
2431
|
// assigns the final width and calls repositionChildren afterwards.
|
|
2363
|
-
const bool measureIntrinsic = autosize && (node_.parent >= 0 || node_.
|
|
2432
|
+
const bool measureIntrinsic = autosize && (node_.parent >= 0 || node_.computedStyle().float_side || intrinsicWidthConstraint(node_)) && !hasExplicitWidth(node_);
|
|
2364
2433
|
int intrinsicWidth = 0;
|
|
2365
2434
|
for (int i = 0; i < count; ++i) {
|
|
2366
2435
|
const int id = children[i];
|
|
2367
2436
|
engine_.layoutNode(id, contentWidth, contentHeight, measureIntrinsic);
|
|
2368
2437
|
const Node &child = nodes_[id];
|
|
2369
|
-
intrinsicWidth = std::max(intrinsicWidth, child.layout.width + child.
|
|
2438
|
+
intrinsicWidth = std::max(intrinsicWidth, child.layout.width + child.computedStyle().margin[1] + child.computedStyle().margin[3]);
|
|
2370
2439
|
}
|
|
2371
2440
|
if (measureIntrinsic) {
|
|
2372
|
-
node_.layout.width = clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.
|
|
2441
|
+
node_.layout.width = clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.computedStyle(), true), true);
|
|
2373
2442
|
contentWidth = paddedWidth();
|
|
2374
2443
|
}
|
|
2375
2444
|
for (int i = 0; i < count; ++i) {
|
|
@@ -2378,19 +2447,19 @@ private:
|
|
|
2378
2447
|
if (measureIntrinsic) engine_.layoutNode(id, contentWidth, contentHeight);
|
|
2379
2448
|
// This horizontal formatting context fills the inline size of
|
|
2380
2449
|
// parallel children. An orthogonal child's width is its block size.
|
|
2381
|
-
if (!hasExplicitWidth(child) && !isIntrinsicSizeExpression(child.
|
|
2382
|
-
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);
|
|
2383
2452
|
if (child.layout.width != width) {
|
|
2384
2453
|
child.layout.width = clampInt16(width);
|
|
2385
2454
|
engine_.repositionChildren(id);
|
|
2386
2455
|
}
|
|
2387
2456
|
}
|
|
2388
|
-
const int slack = contentWidth - child.layout.width - child.
|
|
2389
|
-
const bool autoLeft = child.
|
|
2390
|
-
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);
|
|
2391
2460
|
int offset = slack > 0 && autoLeft ? (autoRight ? slack / 2 : slack) : 0;
|
|
2392
2461
|
if (!autoLeft && !autoRight && rightToLeft(node_)) offset = slack;
|
|
2393
|
-
child.layout.x = boxInset(node_.
|
|
2462
|
+
child.layout.x = boxInset(node_.computedStyle(), 3) + child.computedStyle().margin[3] + offset;
|
|
2394
2463
|
}
|
|
2395
2464
|
}
|
|
2396
2465
|
const bool mergeTop = collapsesWithChildren(id_, false);
|
|
@@ -2408,40 +2477,40 @@ private:
|
|
|
2408
2477
|
// join the group. Its position does not advance normal flow.
|
|
2409
2478
|
auto before = pending;
|
|
2410
2479
|
before.add(childEdgeMargin(id_, id, false, true));
|
|
2411
|
-
(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());
|
|
2412
2481
|
pending.add(childEdgeMargin(id_, id, false));
|
|
2413
2482
|
continue;
|
|
2414
2483
|
}
|
|
2415
2484
|
pending.add(childEdgeMargin(id_, id, false));
|
|
2416
2485
|
cursor += first && mergeTop ? 0 : pending.value();
|
|
2417
|
-
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.
|
|
2486
|
+
(vertical ? child.layout.x : child.layout.y) = boxInset(node_.computedStyle(), blockMarginSide(false)) + cursor;
|
|
2418
2487
|
cursor += vertical ? child.layout.width : child.layout.height;
|
|
2419
2488
|
pending = childEdgeMargin(id_, id, true);
|
|
2420
2489
|
first = false;
|
|
2421
2490
|
}
|
|
2422
2491
|
cursor += mergeBottom || (first && mergeTop) ? 0 : pending.value();
|
|
2423
2492
|
if (vertical) {
|
|
2424
|
-
if (autosize && !hasExplicitWidth(node_) && !(scrollsOverflowX(node_.
|
|
2425
|
-
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);
|
|
2426
2495
|
if (gridAxisReversed(node_, true)) for (int i = 0; i < count; ++i) {
|
|
2427
2496
|
Node &child = nodes_[children[i]];
|
|
2428
2497
|
child.layout.x = node_.layout.width - child.layout.x - child.layout.width;
|
|
2429
2498
|
}
|
|
2430
|
-
} else if (autosize && !hasExplicitHeight(node_) && !(scrollsOverflowY(node_.
|
|
2431
|
-
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);
|
|
2432
2501
|
}
|
|
2433
2502
|
return true;
|
|
2434
2503
|
}
|
|
2435
2504
|
|
|
2436
2505
|
bool layoutFloatChildren(int *children, int count, int contentWidth, int contentHeight, bool autosize)
|
|
2437
2506
|
{
|
|
2438
|
-
if (node_.
|
|
2507
|
+
if (node_.computedStyle().display != kDisplayBlock) return false;
|
|
2439
2508
|
#if GEA_CSS_FLOATS
|
|
2440
2509
|
auto containsFloat = [&](auto &&self, int parent) -> bool {
|
|
2441
2510
|
for (int c = nodes_[parent].first_child; c >= 0; c = nodes_[c].next_sibling) {
|
|
2442
2511
|
const Node &child = nodes_[c];
|
|
2443
|
-
if (isDisplayNone(child.
|
|
2444
|
-
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;
|
|
2445
2514
|
}
|
|
2446
2515
|
return false;
|
|
2447
2516
|
};
|
|
@@ -2449,7 +2518,7 @@ private:
|
|
|
2449
2518
|
bool blocks = false, inlines = false;
|
|
2450
2519
|
for (int i = 0; i < count; ++i) {
|
|
2451
2520
|
if (blockBox(nodes_[children[i]])) blocks = true;
|
|
2452
|
-
else if (!nodes_[children[i]].
|
|
2521
|
+
else if (!nodes_[children[i]].computedStyle().float_side) inlines = true;
|
|
2453
2522
|
}
|
|
2454
2523
|
if (!splitInlineChildren_ && !(blocks && inlines)
|
|
2455
2524
|
#if GEA_CSS_FLOATS
|
|
@@ -2458,8 +2527,8 @@ private:
|
|
|
2458
2527
|
) return false;
|
|
2459
2528
|
FloatContext context;
|
|
2460
2529
|
const bool measureWidth = autosize && !hasExplicitWidth(node_) &&
|
|
2461
|
-
(node_.parent >= 0 || node_.
|
|
2462
|
-
!(scrollsOverflowX(node_.
|
|
2530
|
+
(node_.parent >= 0 || node_.computedStyle().float_side || intrinsicWidthConstraint(node_)) &&
|
|
2531
|
+
!(scrollsOverflowX(node_.computedStyle()) && node_.layout.width > 0 && !intrinsicWidthConstraint(node_));
|
|
2463
2532
|
layoutFloatChildrenInContext(children, count, contentWidth, contentHeight, autosize, context, 0, 0, measureWidth);
|
|
2464
2533
|
if (measureWidth && paddedWidth() != contentWidth) {
|
|
2465
2534
|
// As in ordinary block layout, measure first, then assign the used
|
|
@@ -2483,12 +2552,12 @@ private:
|
|
|
2483
2552
|
bool first = true, clearedThrough = false;
|
|
2484
2553
|
for (int i = 0; i < count; ++i) {
|
|
2485
2554
|
Node &child = nodes_[children[i]];
|
|
2486
|
-
if (!blockBox(child) && !child.
|
|
2555
|
+
if (!blockBox(child) && !child.computedStyle().float_side) {
|
|
2487
2556
|
int end = i + 1;
|
|
2488
2557
|
// Keep a BR with the line it terminates, then recompute the
|
|
2489
2558
|
// float exclusions for the next line.
|
|
2490
2559
|
while (!isLineBreak(nodes_[children[end - 1]]) &&
|
|
2491
|
-
end < count && !blockBox(nodes_[children[end]]) && !nodes_[children[end]].
|
|
2560
|
+
end < count && !blockBox(nodes_[children[end]]) && !nodes_[children[end]].computedStyle().float_side) ++end;
|
|
2492
2561
|
flowY += pending.value();
|
|
2493
2562
|
pending = {};
|
|
2494
2563
|
ScratchFrame inlineScratch;
|
|
@@ -2514,8 +2583,8 @@ private:
|
|
|
2514
2583
|
minimum = item.type == NodeType::Text || inner >= 0
|
|
2515
2584
|
? TextRenderer::firstUnbreakableWidth(inner >= 0 ? nodes_[inner] : item)
|
|
2516
2585
|
: item.layout.width;
|
|
2517
|
-
minimum += item.
|
|
2518
|
-
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);
|
|
2519
2588
|
}
|
|
2520
2589
|
int left = 0, right = contentWidth;
|
|
2521
2590
|
for (;;) {
|
|
@@ -2557,30 +2626,30 @@ private:
|
|
|
2557
2626
|
intrinsicWidth = std::max(intrinsicWidth, left + extent.width);
|
|
2558
2627
|
const Node &last = nodes_[children[end - 1]];
|
|
2559
2628
|
if (isLineBreak(last)) for (const auto &f : floats)
|
|
2560
|
-
if (last.
|
|
2629
|
+
if (last.computedStyle().clear_side & f.side) flowY = std::max(flowY, f.bottom - originY);
|
|
2561
2630
|
}
|
|
2562
2631
|
first = false; clearedThrough = false;
|
|
2563
2632
|
i = end - 1;
|
|
2564
2633
|
continue;
|
|
2565
2634
|
}
|
|
2566
2635
|
engine_.layoutNode(children[i], contentWidth, contentHeight, measureWidth);
|
|
2567
|
-
const bool block = !child.
|
|
2568
|
-
const int measuredOuterW = child.layout.width + child.
|
|
2569
|
-
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) &&
|
|
2570
2639
|
writingMode(child) == 0 && !(preferredRatio(child) > 0 && hasExplicitHeight(child));
|
|
2571
2640
|
// Ordinary blocks still fill their containing block beside floats;
|
|
2572
2641
|
// only their line boxes are shortened by float exclusions.
|
|
2573
2642
|
if (automaticWidth) {
|
|
2574
|
-
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);
|
|
2575
2644
|
if (child.layout.width != width) {
|
|
2576
2645
|
child.layout.width = clampInt16(width);
|
|
2577
2646
|
engine_.repositionChildren(children[i]);
|
|
2578
2647
|
}
|
|
2579
2648
|
}
|
|
2580
|
-
int outerW = child.layout.width + child.
|
|
2581
|
-
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];
|
|
2582
2651
|
const bool mergeTop = first && collapsesWithChildren(id_, false);
|
|
2583
|
-
if (!block && !child.
|
|
2652
|
+
if (!block && !child.computedStyle().float_side) {
|
|
2584
2653
|
flowY += mergeTop ? 0 : pending.value();
|
|
2585
2654
|
pending = {};
|
|
2586
2655
|
first = false;
|
|
@@ -2590,11 +2659,11 @@ private:
|
|
|
2590
2659
|
// Normal blocks clear their border edge, after adjoining margins
|
|
2591
2660
|
// collapse. Floats instead clear their outer edge (CSS 2.2 9.5.2).
|
|
2592
2661
|
int y = block ? flowY + (mergeTop ? 0 : before.value()) :
|
|
2593
|
-
child.
|
|
2662
|
+
child.computedStyle().float_side ? std::max(flowY + (mergeTop ? 0 : pending.value()), context.lastTop - originY) : flowY;
|
|
2594
2663
|
const int hypotheticalY = y;
|
|
2595
2664
|
int clearBottom = INT_MIN;
|
|
2596
2665
|
for (const auto &f : floats)
|
|
2597
|
-
if (child.
|
|
2666
|
+
if (child.computedStyle().clear_side & f.side) clearBottom = std::max(clearBottom, f.bottom - originY);
|
|
2598
2667
|
const bool clearance = block && clearBottom != INT_MIN && (clearBottom > hypotheticalY || context.hasClearance(children[i]));
|
|
2599
2668
|
// Once clearance separated the margins, rebasing the wrapper must
|
|
2600
2669
|
// not mistake the now non-collapsing margin for a new hypothetical
|
|
@@ -2604,7 +2673,7 @@ private:
|
|
|
2604
2673
|
if (clearance && !context.hasClearance(children[i])) context.cleared.push_back(children[i]);
|
|
2605
2674
|
int left = 0, right = contentWidth, contextX = 0;
|
|
2606
2675
|
const bool independentBlock = block && establishesBlockContext(child);
|
|
2607
|
-
if (child.
|
|
2676
|
+
if (child.computedStyle().float_side || child.computedStyle().display != kDisplayBlock || establishesBlockContext(child)) {
|
|
2608
2677
|
for (;;) {
|
|
2609
2678
|
left = 0; right = contentWidth;
|
|
2610
2679
|
int nextY = 32767;
|
|
@@ -2621,18 +2690,18 @@ private:
|
|
|
2621
2690
|
// A BFC's border box cannot overlap float margin boxes.
|
|
2622
2691
|
// Automatic width uses the remaining interval. Even a
|
|
2623
2692
|
// zero-width float prevents a negative margin crossing it.
|
|
2624
|
-
const int start = hasLeft ? std::max<int>(child.
|
|
2625
|
-
const int end = hasRight ? std::min<int>(contentWidth - child.
|
|
2626
|
-
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];
|
|
2627
2696
|
if (automaticWidth) {
|
|
2628
2697
|
const int width = clampLayoutSize(child, std::max(0, end - start), true);
|
|
2629
2698
|
if (child.layout.width != width) {
|
|
2630
2699
|
const int previousHeight = child.layout.height;
|
|
2631
|
-
engine_.layoutNode(children[i], width + child.
|
|
2700
|
+
engine_.layoutNode(children[i], width + child.computedStyle().margin[1] + child.computedStyle().margin[3], contentHeight);
|
|
2632
2701
|
child.layout.width = clampInt16(width);
|
|
2633
2702
|
engine_.repositionChildren(children[i]);
|
|
2634
|
-
outerW = width + child.
|
|
2635
|
-
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];
|
|
2636
2705
|
if (previousHeight != child.layout.height) continue;
|
|
2637
2706
|
}
|
|
2638
2707
|
}
|
|
@@ -2642,11 +2711,11 @@ private:
|
|
|
2642
2711
|
y = nextY;
|
|
2643
2712
|
}
|
|
2644
2713
|
}
|
|
2645
|
-
const int x = child.
|
|
2646
|
-
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
|
|
2647
2716
|
? left + outerW + contentWidth - right : measuredOuterW);
|
|
2648
|
-
child.layout.x = boxInset(node_.
|
|
2649
|
-
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]);
|
|
2650
2719
|
if (block && !establishesBlockContext(child) && child.first_child >= 0) {
|
|
2651
2720
|
LayoutNodePass nested(engine_, children[i], contentWidth, contentHeight);
|
|
2652
2721
|
if (!nested.resolveInlineFormattingRow()) {
|
|
@@ -2657,7 +2726,7 @@ private:
|
|
|
2657
2726
|
const int precedingTop = context.lastTop;
|
|
2658
2727
|
auto placeDescendants = [&]() {
|
|
2659
2728
|
nested.layoutFloatChildrenInContext(nestedScratch.children(), nestedCount, nested.paddedWidth(), nested.paddedHeight(), true,
|
|
2660
|
-
context, originX + x + child.
|
|
2729
|
+
context, originX + x + child.computedStyle().margin[3] + boxInset(child.computedStyle(), 3), originY + y + boxInset(child.computedStyle(), 0));
|
|
2661
2730
|
};
|
|
2662
2731
|
placeDescendants();
|
|
2663
2732
|
// Actual descendant clearance can separate a margin that was
|
|
@@ -2669,10 +2738,10 @@ private:
|
|
|
2669
2738
|
int finalY = flowY + (first && collapsesWithChildren(id_, false) ? 0 : separated.value());
|
|
2670
2739
|
if (clearance) finalY = clearBottom;
|
|
2671
2740
|
for (std::size_t f = 0; f < precedingFloats; ++f)
|
|
2672
|
-
if (child.
|
|
2741
|
+
if (child.computedStyle().clear_side & floats[f].side) finalY = std::max(finalY, floats[f].bottom - originY);
|
|
2673
2742
|
if (finalY != y) {
|
|
2674
2743
|
y = finalY;
|
|
2675
|
-
child.layout.y = boxInset(node_.
|
|
2744
|
+
child.layout.y = boxInset(node_.computedStyle(), 0) + y;
|
|
2676
2745
|
floats.resize(precedingFloats);
|
|
2677
2746
|
context.lastTop = precedingTop;
|
|
2678
2747
|
placeDescendants();
|
|
@@ -2681,12 +2750,12 @@ private:
|
|
|
2681
2750
|
nested.positionAbsoluteChildren();
|
|
2682
2751
|
nested.applyRelativeOffsets();
|
|
2683
2752
|
// This result depends on preceding floats, beyond the size-only memo key.
|
|
2684
|
-
|
|
2753
|
+
engine_.invalidateMemo(children[i]);
|
|
2685
2754
|
}
|
|
2686
2755
|
}
|
|
2687
2756
|
}
|
|
2688
|
-
if (child.
|
|
2689
|
-
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});
|
|
2690
2759
|
context.lastTop = originY + y;
|
|
2691
2760
|
} else if (block && collapsesThrough(children[i])) {
|
|
2692
2761
|
if (clearance) {
|
|
@@ -2708,10 +2777,10 @@ private:
|
|
|
2708
2777
|
if (clearedThrough || (!collapsesWithChildren(id_, true) && !(first && collapsesWithChildren(id_, false))))
|
|
2709
2778
|
flowY += pending.value();
|
|
2710
2779
|
if (measureWidth)
|
|
2711
|
-
node_.layout.width = clampInt16(clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.
|
|
2780
|
+
node_.layout.width = clampInt16(clampLayoutSize(node_, intrinsicWidth + boxInsets(node_.computedStyle(), true), true));
|
|
2712
2781
|
if (autosize && !hasExplicitHeight(node_)) {
|
|
2713
2782
|
// Float enclosure is finalized with all same-context descendants.
|
|
2714
|
-
node_.layout.height = clampBorderSize(engine_, node_, flowY + boxInsets(node_.
|
|
2783
|
+
node_.layout.height = clampBorderSize(engine_, node_, flowY + boxInsets(node_.computedStyle(), false), false);
|
|
2715
2784
|
}
|
|
2716
2785
|
}
|
|
2717
2786
|
|
|
@@ -2721,8 +2790,8 @@ private:
|
|
|
2721
2790
|
// block-level in-flow child stacks them (column), as a browser would.
|
|
2722
2791
|
bool resolveRowDirection() const
|
|
2723
2792
|
{
|
|
2724
|
-
if (node_.
|
|
2725
|
-
return flexRowDirection(node_.
|
|
2793
|
+
if (node_.computedStyle().display == kDisplayFlex)
|
|
2794
|
+
return flexRowDirection(node_.computedStyle()) != (writingMode(node_) != 0);
|
|
2726
2795
|
return resolveInlineFormattingRow();
|
|
2727
2796
|
}
|
|
2728
2797
|
|
|
@@ -2733,12 +2802,12 @@ private:
|
|
|
2733
2802
|
// FlexLayoutPass's `inlineRow` flag switches on.
|
|
2734
2803
|
bool resolveInlineFormattingRow() const
|
|
2735
2804
|
{
|
|
2736
|
-
if (usesRowLayout(node_.
|
|
2737
|
-
if (node_.
|
|
2805
|
+
if (usesRowLayout(node_.computedStyle())) return false;
|
|
2806
|
+
if (node_.computedStyle().flex_direction_explicit || node_.computedStyle().display != kDisplayBlock) return false;
|
|
2738
2807
|
bool anyInFlow = false, allInline = true;
|
|
2739
2808
|
visitFormattingChildren(nodes_, id_, [&](int c) {
|
|
2740
2809
|
const Node &child = nodes_[c];
|
|
2741
|
-
if (child.
|
|
2810
|
+
if (child.computedStyle().display == kDisplayNone || isOutOfFlowPosition(child.computedStyle().position)) return;
|
|
2742
2811
|
if (suppressAnonymousWhitespace(nodes_, child.parent, c)) return;
|
|
2743
2812
|
if (!LayoutEngine::isInlineLevelNode(child)) allInline = false;
|
|
2744
2813
|
anyInFlow = true;
|
|
@@ -2839,15 +2908,15 @@ private:
|
|
|
2839
2908
|
void stretchGridChild(int child, Node &childNode, int cellWidth, int cellHeight, int alignX, int alignY)
|
|
2840
2909
|
{
|
|
2841
2910
|
bool resized = false;
|
|
2842
|
-
const int availableWidth = cellWidth - childNode.
|
|
2843
|
-
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];
|
|
2844
2913
|
const int width = clampLayoutSize(childNode, availableWidth < 0 ? 0 : availableWidth, true);
|
|
2845
2914
|
const int height = clampLayoutSize(childNode, availableHeight < 0 ? 0 : availableHeight, false);
|
|
2846
|
-
if (alignX == 0 && !(childNode.
|
|
2915
|
+
if (alignX == 0 && !(childNode.computedStyle().margin_auto & 10) && !hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression) && childNode.layout.width != width) {
|
|
2847
2916
|
childNode.layout.width = width;
|
|
2848
2917
|
resized = true;
|
|
2849
2918
|
}
|
|
2850
|
-
if (alignY == 0 && !(childNode.
|
|
2919
|
+
if (alignY == 0 && !(childNode.computedStyle().margin_auto & 5) && !hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression) && childNode.layout.height != height) {
|
|
2851
2920
|
childNode.layout.height = height;
|
|
2852
2921
|
resized = true;
|
|
2853
2922
|
}
|
|
@@ -2857,22 +2926,22 @@ private:
|
|
|
2857
2926
|
void layoutGridChildren(int *children, int childCount, int padWidth, int padHeight, bool allowAutosizeParent)
|
|
2858
2927
|
{
|
|
2859
2928
|
#if GEA_CSS_GRID
|
|
2860
|
-
if (!childCount && !rstyle(node_.
|
|
2929
|
+
if (!childCount && !rstyle(node_.computedStyle()).grid_column_count && !rstyle(node_.computedStyle()).grid_row_count) {
|
|
2861
2930
|
if (auto *rare = rareDataFor(id_)) rare->gridLayout.reset();
|
|
2862
2931
|
if (allowAutosizeParent) autosizeEmptyNode();
|
|
2863
2932
|
return;
|
|
2864
2933
|
}
|
|
2865
2934
|
const bool vertical = writingMode(node_) != 0;
|
|
2866
|
-
int columnCount = std::max(childCount ? 1 : 0, int(rstyle(node_.
|
|
2867
|
-
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));
|
|
2868
2937
|
struct Placement { GridAxisPlacement column, row; };
|
|
2869
2938
|
std::vector<Placement> placements(childCount);
|
|
2870
2939
|
int columnOrigin = 0, rowOrigin = 0;
|
|
2871
2940
|
for (int i = 0; i < childCount; ++i) {
|
|
2872
|
-
const auto &rs = rstyle(nodes_[children[i]].
|
|
2941
|
+
const auto &rs = rstyle(nodes_[children[i]].computedStyle());
|
|
2873
2942
|
auto &p = placements[i];
|
|
2874
|
-
p.column = gridAxisPlacement(rs.grid_line[1], rs.grid_line[3], rstyle(node_.
|
|
2875
|
-
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);
|
|
2876
2945
|
if (p.column.start != kUnset) columnOrigin = std::max(columnOrigin, -p.column.start);
|
|
2877
2946
|
if (p.row.start != kUnset) rowOrigin = std::max(rowOrigin, -p.row.start);
|
|
2878
2947
|
columnCount = std::max(columnCount, p.column.end == kUnset ? p.column.span : p.column.end);
|
|
@@ -2945,13 +3014,13 @@ private:
|
|
|
2945
3014
|
int16_t rowValues[kMaxGridLayoutTracks] = {0};
|
|
2946
3015
|
for (int i = 0; i < columnCount; ++i) {
|
|
2947
3016
|
const int track = i - columnOrigin;
|
|
2948
|
-
columnTypes[i] = track >= 0 && track < rstyle(node_.
|
|
2949
|
-
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;
|
|
2950
3019
|
}
|
|
2951
3020
|
for (int i = 0; i < rowCount; ++i) {
|
|
2952
3021
|
const int track = i - rowOrigin;
|
|
2953
|
-
rowTypes[i] = track >= 0 && track < rstyle(node_.
|
|
2954
|
-
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;
|
|
2955
3024
|
}
|
|
2956
3025
|
|
|
2957
3026
|
int autoColumns[kMaxGridLayoutTracks] = {0};
|
|
@@ -2975,8 +3044,8 @@ private:
|
|
|
2975
3044
|
if (p.span != span) continue;
|
|
2976
3045
|
const Node &child = nodes_[children[i]];
|
|
2977
3046
|
const bool horizontal = columns != vertical;
|
|
2978
|
-
const int size = horizontal ? child.layout.width + child.
|
|
2979
|
-
: 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];
|
|
2980
3049
|
int occupied = (span - 1) * gap, autos = 0;
|
|
2981
3050
|
for (int t = p.start; t < p.end; ++t) {
|
|
2982
3051
|
occupied += types[t] == 1 ? values[t] : sizes[t];
|
|
@@ -2999,16 +3068,16 @@ private:
|
|
|
2999
3068
|
computeTrackSizes(columnCount, columnTypes, columnValues, autoColumns, vertical ? padHeight : padWidth, columnGap, columnSizes);
|
|
3000
3069
|
computeTrackSizes(rowCount, rowTypes, rowValues, autoRows, vertical ? padWidth : padHeight, rowGap, rowSizes);
|
|
3001
3070
|
if (allowAutosizeParent && !hasExplicitWidth(node_) &&
|
|
3002
|
-
rstyle(node_.
|
|
3003
|
-
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;
|
|
3004
3073
|
|
|
3005
3074
|
if (allowAutosizeParent && !hasExplicitWidth(node_)) {
|
|
3006
|
-
int width = boxInset(node_.
|
|
3075
|
+
int width = boxInset(node_.computedStyle(), 1) + boxInset(node_.computedStyle(), 3);
|
|
3007
3076
|
width += vertical ? gridTrackTotalSize(rowCount, rowSizes, rowGap) : gridTrackTotalSize(columnCount, columnSizes, columnGap);
|
|
3008
3077
|
node_.layout.width = clampLayoutSize(node_, width, true);
|
|
3009
3078
|
}
|
|
3010
3079
|
if (allowAutosizeParent && !hasExplicitHeight(node_)) {
|
|
3011
|
-
int height = boxInset(node_.
|
|
3080
|
+
int height = boxInset(node_.computedStyle(), 0) + boxInset(node_.computedStyle(), 2);
|
|
3012
3081
|
height += vertical ? gridTrackTotalSize(columnCount, columnSizes, columnGap) : gridTrackTotalSize(rowCount, rowSizes, rowGap);
|
|
3013
3082
|
node_.layout.height = clampLayoutSize(node_, height, false);
|
|
3014
3083
|
}
|
|
@@ -3017,8 +3086,8 @@ private:
|
|
|
3017
3086
|
// contribute free space without making an auto-sized grid fill its parent.
|
|
3018
3087
|
padWidth = paddedWidth();
|
|
3019
3088
|
padHeight = paddedHeight();
|
|
3020
|
-
stretchAutoGridTracks(columnCount, columnTypes, columnSizes, vertical ? padHeight : padWidth, columnGap, node_.
|
|
3021
|
-
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);
|
|
3022
3091
|
|
|
3023
3092
|
int rowY[kMaxGridLayoutTracks] = {0};
|
|
3024
3093
|
int columnX[kMaxGridLayoutTracks] = {0};
|
|
@@ -3026,11 +3095,11 @@ private:
|
|
|
3026
3095
|
const int rowTotal = gridTrackTotalSize(rowCount, rowSizes, rowGap);
|
|
3027
3096
|
int columnPosition = 0, rowPosition = 0;
|
|
3028
3097
|
for (int i = 0; i < columnCount; ++i) {
|
|
3029
|
-
columnX[i] = columnPosition + gridContentOffset(vertical ? padHeight : padWidth, columnTotal, node_.
|
|
3098
|
+
columnX[i] = columnPosition + gridContentOffset(vertical ? padHeight : padWidth, columnTotal, node_.computedStyle().justify_content, i, columnCount);
|
|
3030
3099
|
columnPosition += columnSizes[i] + columnGap;
|
|
3031
3100
|
}
|
|
3032
3101
|
for (int i = 0; i < rowCount; ++i) {
|
|
3033
|
-
rowY[i] = rowPosition + gridContentOffset(vertical ? padWidth : padHeight, rowTotal, node_.
|
|
3102
|
+
rowY[i] = rowPosition + gridContentOffset(vertical ? padWidth : padHeight, rowTotal, node_.computedStyle().align_content, i, rowCount);
|
|
3034
3103
|
rowPosition += rowSizes[i] + rowGap;
|
|
3035
3104
|
}
|
|
3036
3105
|
|
|
@@ -3051,28 +3120,28 @@ private:
|
|
|
3051
3120
|
gridPhysicalRange(node_, true, columnX[p.column.start], tracks.columnEnd[p.column.end - 1], vertical ? cellY : cellX, vertical ? cellHeight : cellWidth);
|
|
3052
3121
|
gridPhysicalRange(node_, false, rowY[p.row.start], tracks.rowEnd[p.row.end - 1], vertical ? cellX : cellY, vertical ? cellWidth : cellHeight);
|
|
3053
3122
|
engine_.layoutNode(child, cellWidth, cellHeight);
|
|
3054
|
-
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? rstyle(childNode.
|
|
3055
|
-
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;
|
|
3056
3125
|
const int alignX = vertical ? blockAlign : inlineAlign;
|
|
3057
3126
|
const int alignY = vertical ? inlineAlign : blockAlign;
|
|
3058
3127
|
stretchGridChild(child, childNode, cellWidth, cellHeight, alignX, alignY);
|
|
3059
3128
|
|
|
3060
|
-
int x = cellX + childNode.
|
|
3061
|
-
int y = cellY + childNode.
|
|
3062
|
-
const int freeX = cellWidth - childNode.layout.width - childNode.
|
|
3063
|
-
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];
|
|
3064
3133
|
const int usedX = usedGridAlignment(node_, childNode, alignX, freeX, true);
|
|
3065
3134
|
const int usedY = usedGridAlignment(node_, childNode, alignY, freeY, false);
|
|
3066
3135
|
// Auto margins consume positive free space before self-alignment and
|
|
3067
3136
|
// suppress it even when the item overflows the grid area.
|
|
3068
|
-
if (childNode.
|
|
3069
|
-
if (freeX > 0 && (childNode.
|
|
3070
|
-
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;
|
|
3071
3140
|
} else if (usedX == 1) x += freeX / 2;
|
|
3072
3141
|
else if (usedX == 2) x += freeX;
|
|
3073
|
-
if (childNode.
|
|
3074
|
-
if (freeY > 0 && (childNode.
|
|
3075
|
-
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;
|
|
3076
3145
|
} else if (usedY == 1) y += freeY / 2;
|
|
3077
3146
|
else if (usedY == 2) y += freeY;
|
|
3078
3147
|
childNode.layout.x = x;
|
|
@@ -3092,14 +3161,14 @@ private:
|
|
|
3092
3161
|
int contentWidth = resolvedStyleWidth(node_, availWidth_);
|
|
3093
3162
|
int contentHeight = resolvedStyleHeight(node_, availHeight_);
|
|
3094
3163
|
if (!hasExplicitWidth(node_)) {
|
|
3095
|
-
contentWidth -= node_.
|
|
3164
|
+
contentWidth -= node_.computedStyle().margin[1] + node_.computedStyle().margin[3];
|
|
3096
3165
|
}
|
|
3097
3166
|
if (!hasExplicitHeight(node_)) {
|
|
3098
|
-
contentHeight -= node_.
|
|
3167
|
+
contentHeight -= node_.computedStyle().margin[0] + node_.computedStyle().margin[2];
|
|
3099
3168
|
}
|
|
3100
3169
|
|
|
3101
|
-
if (hasExplicitWidth(node_)) contentWidth = contentSizeToBorderSize(node_.
|
|
3102
|
-
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);
|
|
3103
3172
|
node_.layout.width = clampLayoutSize(node_, contentWidth, true);
|
|
3104
3173
|
node_.layout.height = clampLayoutSize(node_, contentHeight, false);
|
|
3105
3174
|
// Resolve a definite ratio-derived axis before measuring percentage
|
|
@@ -3114,20 +3183,20 @@ private:
|
|
|
3114
3183
|
|
|
3115
3184
|
int paddedWidth() const
|
|
3116
3185
|
{
|
|
3117
|
-
int width = node_.layout.width - boxInset(node_.
|
|
3186
|
+
int width = node_.layout.width - boxInset(node_.computedStyle(), 1) - boxInset(node_.computedStyle(), 3);
|
|
3118
3187
|
return width < 0 ? 0 : width;
|
|
3119
3188
|
}
|
|
3120
3189
|
|
|
3121
3190
|
int paddedHeight() const
|
|
3122
3191
|
{
|
|
3123
|
-
int height = node_.layout.height - boxInset(node_.
|
|
3192
|
+
int height = node_.layout.height - boxInset(node_.computedStyle(), 0) - boxInset(node_.computedStyle(), 2);
|
|
3124
3193
|
return height < 0 ? 0 : height;
|
|
3125
3194
|
}
|
|
3126
3195
|
|
|
3127
3196
|
void autosizeEmptyNode()
|
|
3128
3197
|
{
|
|
3129
|
-
if (!hasExplicitWidth(node_)) node_.layout.width = boxInset(node_.
|
|
3130
|
-
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);
|
|
3131
3200
|
node_.layout.width = clampLayoutSize(node_, node_.layout.width, true);
|
|
3132
3201
|
node_.layout.height = clampLayoutSize(node_, node_.layout.height, false);
|
|
3133
3202
|
#if GEA_CSS_SCROLLING
|
|
@@ -3162,14 +3231,14 @@ private:
|
|
|
3162
3231
|
int contentHeight = node_.layout.height;
|
|
3163
3232
|
visitFormattingChildren(nodes_, id_, [&](int child) {
|
|
3164
3233
|
Node &childNode = nodes_[child];
|
|
3165
|
-
if (isCollapsedFlexItem(childNode) || isDisplayNone(childNode.
|
|
3234
|
+
if (isCollapsedFlexItem(childNode) || isDisplayNone(childNode.computedStyle()) || isOutOfFlowPosition(childNode.computedStyle().position)) return;
|
|
3166
3235
|
// A visible axis contributes descendant overflow; a clipping axis
|
|
3167
3236
|
// traps it at this child's border box independently of the other axis.
|
|
3168
|
-
const int width = overflowX(childNode.
|
|
3169
|
-
const int height = overflowY(childNode.
|
|
3170
|
-
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);
|
|
3171
3240
|
if (right > contentWidth) contentWidth = right;
|
|
3172
|
-
const int bottom = childNode.layout.y + height + childNode.
|
|
3241
|
+
const int bottom = childNode.layout.y + height + childNode.computedStyle().margin[2] + boxInset(node_.computedStyle(), 2);
|
|
3173
3242
|
if (bottom > contentHeight) contentHeight = bottom;
|
|
3174
3243
|
});
|
|
3175
3244
|
node_.layout.scroll_content_width = contentWidth;
|
|
@@ -3177,7 +3246,7 @@ private:
|
|
|
3177
3246
|
|
|
3178
3247
|
int maxScrollX = node_.layout.scroll_content_width - node_.layout.width;
|
|
3179
3248
|
if (maxScrollX < 0) maxScrollX = 0;
|
|
3180
|
-
if (!scrollsOverflowX(node_.
|
|
3249
|
+
if (!scrollsOverflowX(node_.computedStyle())) {
|
|
3181
3250
|
node_.layout.scroll_x = 0;
|
|
3182
3251
|
} else {
|
|
3183
3252
|
if (node_.layout.scroll_x < 0) node_.layout.scroll_x = 0;
|
|
@@ -3186,7 +3255,7 @@ private:
|
|
|
3186
3255
|
|
|
3187
3256
|
int maxScroll = node_.layout.scroll_content_height - node_.layout.height;
|
|
3188
3257
|
if (maxScroll < 0) maxScroll = 0;
|
|
3189
|
-
if (!scrollsOverflowY(node_.
|
|
3258
|
+
if (!scrollsOverflowY(node_.computedStyle())) {
|
|
3190
3259
|
node_.layout.scroll_y = 0;
|
|
3191
3260
|
} else {
|
|
3192
3261
|
if (node_.layout.scroll_y < 0) node_.layout.scroll_y = 0;
|
|
@@ -3207,7 +3276,7 @@ private:
|
|
|
3207
3276
|
if (node_.type != NodeType::VirtualList) return;
|
|
3208
3277
|
int rowHeight = 0;
|
|
3209
3278
|
for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3210
|
-
if (isDisplayNone(nodes_[child].
|
|
3279
|
+
if (isDisplayNone(nodes_[child].computedStyle())) continue;
|
|
3211
3280
|
rowHeight = nodes_[child].layout.height;
|
|
3212
3281
|
break;
|
|
3213
3282
|
}
|
|
@@ -3228,25 +3297,26 @@ private:
|
|
|
3228
3297
|
void captureBlockStaticPositions()
|
|
3229
3298
|
{
|
|
3230
3299
|
for (int c = node_.first_child; c >= 0; c = nodes_[c].next_sibling)
|
|
3231
|
-
if (isOutOfFlowPosition(nodes_[c].
|
|
3232
|
-
if (node_.
|
|
3233
|
-
(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;
|
|
3234
3303
|
const bool vertical = writingMode(node_) != 0;
|
|
3235
3304
|
const bool reversed = vertical && gridAxisReversed(node_, true);
|
|
3236
|
-
int cursor = boxInset(node_.
|
|
3305
|
+
int cursor = boxInset(node_.computedStyle(), blockMarginSide(false));
|
|
3237
3306
|
bool first = true;
|
|
3238
3307
|
CollapsedMargin pending;
|
|
3239
3308
|
visitFormattingChildren(nodes_, id_, [&](int id) {
|
|
3240
3309
|
Node &child = nodes_[id];
|
|
3241
|
-
if (isDisplayNone(child.
|
|
3242
|
-
if (isOutOfFlowPosition(child.
|
|
3310
|
+
if (isDisplayNone(child.computedStyle())) return;
|
|
3311
|
+
if (isOutOfFlowPosition(child.computedStyle().position)) {
|
|
3243
3312
|
if (child.parent != id_ || !blockBox(child)) return;
|
|
3244
3313
|
const int edge = cursor + (first && collapsesWithChildren(id_, false) ? 0 : pending.value());
|
|
3245
|
-
|
|
3246
|
-
|
|
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;
|
|
3247
3317
|
return;
|
|
3248
3318
|
}
|
|
3249
|
-
if (child.
|
|
3319
|
+
if (child.computedStyle().float_side || suppressAnonymousWhitespace(nodes_, child.parent, id)) return;
|
|
3250
3320
|
if (blockBox(child) && collapsesThrough(id)) {
|
|
3251
3321
|
pending.add(childEdgeMargin(id_, id, false));
|
|
3252
3322
|
return;
|
|
@@ -3264,7 +3334,7 @@ private:
|
|
|
3264
3334
|
captureBlockStaticPositions();
|
|
3265
3335
|
for (int child = node_.first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3266
3336
|
Node &childNode = nodes_[child];
|
|
3267
|
-
if (isDisplayNone(childNode.
|
|
3337
|
+
if (isDisplayNone(childNode.computedStyle()) || !isOutOfFlowPosition(childNode.computedStyle().position)) continue;
|
|
3268
3338
|
|
|
3269
3339
|
int childAvailWidth, childAvailHeight;
|
|
3270
3340
|
int areaX, areaY;
|
|
@@ -3278,11 +3348,11 @@ private:
|
|
|
3278
3348
|
void stretchAbsoluteChild(int child, Node &childNode, int childAvailWidth, int childAvailHeight)
|
|
3279
3349
|
{
|
|
3280
3350
|
bool resized = false;
|
|
3281
|
-
if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
3351
|
+
if (!hasExplicitWidth(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().width_expression) &&
|
|
3282
3352
|
hasPositionOffset<3>(childNode) &&
|
|
3283
3353
|
hasPositionOffset<1>(childNode)) {
|
|
3284
3354
|
int width = childAvailWidth - resolvedPositionOffsetWithBasis<3>(childNode, childAvailWidth) - resolvedPositionOffsetWithBasis<1>(childNode, childAvailWidth) -
|
|
3285
|
-
childNode.
|
|
3355
|
+
childNode.computedStyle().margin[1] - childNode.computedStyle().margin[3];
|
|
3286
3356
|
if (width < 0) width = 0;
|
|
3287
3357
|
width = clampLayoutSize(childNode, width, true);
|
|
3288
3358
|
if (childNode.layout.width != width) {
|
|
@@ -3291,11 +3361,11 @@ private:
|
|
|
3291
3361
|
}
|
|
3292
3362
|
}
|
|
3293
3363
|
|
|
3294
|
-
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.
|
|
3364
|
+
if (!hasExplicitHeight(childNode) && !isIntrinsicSizeExpression(childNode.computedStyle().height_expression) &&
|
|
3295
3365
|
hasPositionOffset<0>(childNode) &&
|
|
3296
3366
|
hasPositionOffset<2>(childNode)) {
|
|
3297
3367
|
int height = childAvailHeight - resolvedPositionOffsetWithBasis<0>(childNode, childAvailHeight) - resolvedPositionOffsetWithBasis<2>(childNode, childAvailHeight) -
|
|
3298
|
-
childNode.
|
|
3368
|
+
childNode.computedStyle().margin[0] - childNode.computedStyle().margin[2];
|
|
3299
3369
|
if (height < 0) height = 0;
|
|
3300
3370
|
height = clampLayoutSize(childNode, height, false);
|
|
3301
3371
|
if (childNode.layout.height != height) {
|
|
@@ -3311,11 +3381,11 @@ private:
|
|
|
3311
3381
|
{
|
|
3312
3382
|
int x, y, width, height;
|
|
3313
3383
|
LayoutEngine::absoluteContainingArea(node_, childNode, x, y, width, height);
|
|
3314
|
-
if (hasPositionOffset<3>(childNode)) childNode.layout.x = x + resolvedPositionOffsetWithBasis<3>(childNode, width) + childNode.
|
|
3315
|
-
else if (hasPositionOffset<1>(childNode)) childNode.layout.x = x + width - childNode.layout.width - resolvedPositionOffsetWithBasis<1>(childNode, width) - 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];
|
|
3316
3386
|
else childNode.layout.x = alignedAbsoluteChildPosition(childNode, true);
|
|
3317
|
-
if (hasPositionOffset<0>(childNode)) childNode.layout.y = y + resolvedPositionOffsetWithBasis<0>(childNode, height) + childNode.
|
|
3318
|
-
else if (hasPositionOffset<2>(childNode)) childNode.layout.y = y + height - childNode.layout.height - resolvedPositionOffsetWithBasis<2>(childNode, height) - 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];
|
|
3319
3389
|
else childNode.layout.y = alignedAbsoluteChildPosition(childNode, false);
|
|
3320
3390
|
}
|
|
3321
3391
|
|
|
@@ -3330,7 +3400,7 @@ private:
|
|
|
3330
3400
|
for (int child = nodes_[parent].first_child; child >= 0; child = nodes_[child].next_sibling) {
|
|
3331
3401
|
Node &childNode = nodes_[child];
|
|
3332
3402
|
if (splitInlineChildren_ && splitInlineWrapper(nodes_, child)) self(self, child);
|
|
3333
|
-
if (childNode.
|
|
3403
|
+
if (childNode.computedStyle().position != 2) continue;
|
|
3334
3404
|
if (hasPositionOffset<0>(childNode))
|
|
3335
3405
|
childNode.layout.y += resolvedRelativePositionOffset<0>(childNode);
|
|
3336
3406
|
else if (hasPositionOffset<2>(childNode))
|
|
@@ -3347,7 +3417,7 @@ private:
|
|
|
3347
3417
|
template <int side>
|
|
3348
3418
|
bool hasPositionOffset(const Node &node) const
|
|
3349
3419
|
{
|
|
3350
|
-
return GEA_CSS_POSITION_PX(node.
|
|
3420
|
+
return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
|
|
3351
3421
|
}
|
|
3352
3422
|
|
|
3353
3423
|
template <int side>
|
|
@@ -3360,7 +3430,7 @@ private:
|
|
|
3360
3430
|
int resolvedRelativePositionOffset(const Node &node) const
|
|
3361
3431
|
{
|
|
3362
3432
|
int basis = (side == 0 || side == 2) ? node_.layout.height : node_.layout.width;
|
|
3363
|
-
if (isDisplayGrid(node_.
|
|
3433
|
+
if (isDisplayGrid(node_.computedStyle())) {
|
|
3364
3434
|
basis = (side == 0 || side == 2) ? node.layout.height : node.layout.width;
|
|
3365
3435
|
}
|
|
3366
3436
|
return resolvedPositionOffsetWithBasis<side>(node, basis);
|
|
@@ -3369,8 +3439,8 @@ private:
|
|
|
3369
3439
|
template <int side>
|
|
3370
3440
|
int resolvedPositionOffsetWithBasis(const Node &node, int percentBasis) const
|
|
3371
3441
|
{
|
|
3372
|
-
int offset = GEA_CSS_POSITION_PX(node.
|
|
3373
|
-
const int percent = GEA_CSS_POSITION_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);
|
|
3374
3444
|
if (percent != kUnset) {
|
|
3375
3445
|
const int numerator = percentBasis * percent;
|
|
3376
3446
|
offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
|
|
@@ -3389,7 +3459,7 @@ private:
|
|
|
3389
3459
|
bool establishesTransformContainingBlock(const Node &node)
|
|
3390
3460
|
{
|
|
3391
3461
|
if (!ViewRenderer::isTransformableBox(node)) return false;
|
|
3392
|
-
const auto &r = rstyle(node.
|
|
3462
|
+
const auto &r = rstyle(node.computedStyle());
|
|
3393
3463
|
return r.translate_present || r.transform_present || r.rotate_present || r.scale_present || r.filter_present || r.transform_preserve_3d ||
|
|
3394
3464
|
r.transform_rotate || r.transform_rotate_x || r.transform_rotate_y ||
|
|
3395
3465
|
composedTranslateX(r) || composedTranslateY(r) || composedTranslateZ(r) ||
|
|
@@ -3399,12 +3469,12 @@ bool establishesTransformContainingBlock(const Node &node)
|
|
|
3399
3469
|
|
|
3400
3470
|
bool establishesAbsoluteContainingBlock(const Node &node)
|
|
3401
3471
|
{
|
|
3402
|
-
return isOutOfFlowPosition(node.
|
|
3472
|
+
return isOutOfFlowPosition(node.computedStyle().position) || node.computedStyle().position == 2 || establishesTransformContainingBlock(node);
|
|
3403
3473
|
}
|
|
3404
3474
|
|
|
3405
3475
|
int containingBlockForAbsoluteNode(int node, int root, Node *nodes)
|
|
3406
3476
|
{
|
|
3407
|
-
if (nodes[node].
|
|
3477
|
+
if (nodes[node].computedStyle().position == kPositionFixed) {
|
|
3408
3478
|
const int fixed = LayoutEngine::fixedContainingBlock(nodes[node]);
|
|
3409
3479
|
return fixed >= 0 ? fixed : root;
|
|
3410
3480
|
}
|
|
@@ -3417,14 +3487,14 @@ int containingBlockForAbsoluteNode(int node, int root, Node *nodes)
|
|
|
3417
3487
|
template <int side>
|
|
3418
3488
|
bool hasPositionOffsetValue(const Node &node)
|
|
3419
3489
|
{
|
|
3420
|
-
return GEA_CSS_POSITION_PX(node.
|
|
3490
|
+
return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
|
|
3421
3491
|
}
|
|
3422
3492
|
|
|
3423
3493
|
template <int side>
|
|
3424
3494
|
int resolvedPositionOffsetForBasis(const Node &node, int percentBasis)
|
|
3425
3495
|
{
|
|
3426
|
-
int offset = GEA_CSS_POSITION_PX(node.
|
|
3427
|
-
const int percent = GEA_CSS_POSITION_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);
|
|
3428
3498
|
if (percent != kUnset) {
|
|
3429
3499
|
const int numerator = percentBasis * percent;
|
|
3430
3500
|
offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
|
|
@@ -3440,8 +3510,8 @@ void offsetFromAncestorToNode(int ancestor, int node, Node *nodes, int *outX, in
|
|
|
3440
3510
|
const Node ¤t = nodes[cursor];
|
|
3441
3511
|
x += current.layout.x;
|
|
3442
3512
|
y += current.layout.y;
|
|
3443
|
-
if (scrollsOverflowX(current.
|
|
3444
|
-
if (scrollsOverflowY(current.
|
|
3513
|
+
if (scrollsOverflowX(current.computedStyle())) x -= current.layout.scroll_x;
|
|
3514
|
+
if (scrollsOverflowY(current.computedStyle())) y -= current.layout.scroll_y;
|
|
3445
3515
|
}
|
|
3446
3516
|
*outX = x;
|
|
3447
3517
|
*outY = y;
|
|
@@ -3451,13 +3521,13 @@ void stretchAbsoluteNodeToContainingBlock(int node, int containingWidth, int con
|
|
|
3451
3521
|
{
|
|
3452
3522
|
Node &absolute = nodes[node];
|
|
3453
3523
|
bool resized = false;
|
|
3454
|
-
if (!hasExplicitWidth(absolute) && !isIntrinsicSizeExpression(absolute.
|
|
3524
|
+
if (!hasExplicitWidth(absolute) && !isIntrinsicSizeExpression(absolute.computedStyle().width_expression) &&
|
|
3455
3525
|
hasPositionOffsetValue<3>(absolute) &&
|
|
3456
3526
|
hasPositionOffsetValue<1>(absolute)) {
|
|
3457
3527
|
int width = containingWidth -
|
|
3458
3528
|
resolvedPositionOffsetForBasis<3>(absolute, containingWidth) -
|
|
3459
3529
|
resolvedPositionOffsetForBasis<1>(absolute, containingWidth) -
|
|
3460
|
-
absolute.
|
|
3530
|
+
absolute.computedStyle().margin[1] - absolute.computedStyle().margin[3];
|
|
3461
3531
|
if (width < 0) width = 0;
|
|
3462
3532
|
width = clampLayoutSize(absolute, width, true);
|
|
3463
3533
|
if (absolute.layout.width != width) {
|
|
@@ -3466,13 +3536,13 @@ void stretchAbsoluteNodeToContainingBlock(int node, int containingWidth, int con
|
|
|
3466
3536
|
}
|
|
3467
3537
|
}
|
|
3468
3538
|
|
|
3469
|
-
if (!hasExplicitHeight(absolute) && !isIntrinsicSizeExpression(absolute.
|
|
3539
|
+
if (!hasExplicitHeight(absolute) && !isIntrinsicSizeExpression(absolute.computedStyle().height_expression) &&
|
|
3470
3540
|
hasPositionOffsetValue<0>(absolute) &&
|
|
3471
3541
|
hasPositionOffsetValue<2>(absolute)) {
|
|
3472
3542
|
int height = containingHeight -
|
|
3473
3543
|
resolvedPositionOffsetForBasis<0>(absolute, containingHeight) -
|
|
3474
3544
|
resolvedPositionOffsetForBasis<2>(absolute, containingHeight) -
|
|
3475
|
-
absolute.
|
|
3545
|
+
absolute.computedStyle().margin[0] - absolute.computedStyle().margin[2];
|
|
3476
3546
|
if (height < 0) height = 0;
|
|
3477
3547
|
height = clampLayoutSize(absolute, height, false);
|
|
3478
3548
|
if (absolute.layout.height != height) {
|
|
@@ -3490,7 +3560,7 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
|
|
|
3490
3560
|
auto &engine = LayoutEngine::instance();
|
|
3491
3561
|
const bool left = hasPositionOffsetValue<3>(absolute), right = hasPositionOffsetValue<1>(absolute);
|
|
3492
3562
|
if (absolute.type != NodeType::View || writingMode(absolute) != 0 ||
|
|
3493
|
-
hasExplicitWidth(absolute) || isIntrinsicSizeExpression(absolute.
|
|
3563
|
+
hasExplicitWidth(absolute) || isIntrinsicSizeExpression(absolute.computedStyle().width_expression) ||
|
|
3494
3564
|
(left && right) || (preferredRatio(absolute) > 0 && hasExplicitHeight(absolute))) {
|
|
3495
3565
|
engine.layoutNode(node, areaWidth, areaHeight);
|
|
3496
3566
|
return;
|
|
@@ -3500,14 +3570,14 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
|
|
|
3500
3570
|
// containing width for percentages during the final used-width layout.
|
|
3501
3571
|
IntrinsicSizeScope scope(absolute, 1);
|
|
3502
3572
|
engine.layoutNode(node, 1, areaHeight, true);
|
|
3503
|
-
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));
|
|
3504
3574
|
scope.constraint = 2;
|
|
3505
3575
|
engine.layoutNode(node, 32767, areaHeight, true);
|
|
3506
|
-
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));
|
|
3507
3577
|
#if GEA_CSS_BOX_EXPRESSIONS
|
|
3508
3578
|
resolveLayoutBoxLengths(node, areaWidth);
|
|
3509
3579
|
#endif
|
|
3510
|
-
int available = areaWidth - absolute.
|
|
3580
|
+
int available = areaWidth - absolute.computedStyle().margin[3] - absolute.computedStyle().margin[1];
|
|
3511
3581
|
if (left || right) {
|
|
3512
3582
|
available -= (left ? resolvedPositionOffsetForBasis<3>(absolute, areaWidth) : resolvedPositionOffsetForBasis<1>(absolute, areaWidth));
|
|
3513
3583
|
} else {
|
|
@@ -3515,10 +3585,10 @@ void layoutAbsoluteNode(int node, int containing, int areaX, int areaWidth, int
|
|
|
3515
3585
|
offsetFromAncestorToNode(containing, absolute.parent, nodes, &parentX, &parentY);
|
|
3516
3586
|
const int staticX = parentX + engine.alignedAbsoluteOffset(nodes[absolute.parent], absolute, true);
|
|
3517
3587
|
available = rightToLeft(nodes[absolute.parent])
|
|
3518
|
-
? staticX + absolute.layout.width - areaX - absolute.
|
|
3519
|
-
: areaX + areaWidth - staticX - absolute.
|
|
3588
|
+
? staticX + absolute.layout.width - areaX - absolute.computedStyle().margin[3]
|
|
3589
|
+
: areaX + areaWidth - staticX - absolute.computedStyle().margin[1];
|
|
3520
3590
|
}
|
|
3521
|
-
const int edges = boxInsets(absolute.
|
|
3591
|
+
const int edges = boxInsets(absolute.computedStyle(), true);
|
|
3522
3592
|
scope.borderSize = edges + std::min(maximum, std::max(minimum, available - edges));
|
|
3523
3593
|
scope.constraint = 0;
|
|
3524
3594
|
engine.layoutNode(node, areaWidth, areaHeight);
|
|
@@ -3531,8 +3601,9 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3531
3601
|
const int parent = absolute.parent;
|
|
3532
3602
|
if (parent < 0) return;
|
|
3533
3603
|
if (LayoutEngine::isViewportFixed(absolute)) {
|
|
3534
|
-
const
|
|
3535
|
-
const int
|
|
3604
|
+
const auto &persistent = layoutState(containing);
|
|
3605
|
+
const int width = persistent.memo_avail_w;
|
|
3606
|
+
const int height = persistent.memo_avail_h;
|
|
3536
3607
|
LayoutEngine::instance().layoutNode(node, width, height);
|
|
3537
3608
|
stretchAbsoluteNodeToContainingBlock(node, width, height, nodes);
|
|
3538
3609
|
int staticX = LayoutEngine::alignedAbsoluteOffset(nodes[parent], absolute, true);
|
|
@@ -3541,10 +3612,10 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3541
3612
|
staticX += nodes[id].layout.x; staticY += nodes[id].layout.y;
|
|
3542
3613
|
if (LayoutEngine::isViewportFixed(nodes[id])) break;
|
|
3543
3614
|
}
|
|
3544
|
-
absolute.layout.x = hasPositionOffsetValue<3>(absolute) ? resolvedPositionOffsetForBasis<3>(absolute, width) + absolute.
|
|
3545
|
-
: hasPositionOffsetValue<1>(absolute) ? width - absolute.layout.width - resolvedPositionOffsetForBasis<1>(absolute, width) - absolute.
|
|
3546
|
-
absolute.layout.y = hasPositionOffsetValue<0>(absolute) ? resolvedPositionOffsetForBasis<0>(absolute, height) + absolute.
|
|
3547
|
-
: hasPositionOffsetValue<2>(absolute) ? height - absolute.layout.height - resolvedPositionOffsetForBasis<2>(absolute, height) - 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;
|
|
3548
3619
|
return;
|
|
3549
3620
|
}
|
|
3550
3621
|
|
|
@@ -3567,17 +3638,17 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3567
3638
|
|
|
3568
3639
|
int containingX = absolute.layout.x + parentOffsetX;
|
|
3569
3640
|
if (hasPositionOffsetValue<3>(absolute))
|
|
3570
|
-
containingX = areaX + resolvedPositionOffsetForBasis<3>(absolute, areaWidth) + absolute.
|
|
3641
|
+
containingX = areaX + resolvedPositionOffsetForBasis<3>(absolute, areaWidth) + absolute.computedStyle().margin[3];
|
|
3571
3642
|
else if (hasPositionOffsetValue<1>(absolute))
|
|
3572
3643
|
containingX = areaX + areaWidth - absolute.layout.width -
|
|
3573
|
-
resolvedPositionOffsetForBasis<1>(absolute, areaWidth) - absolute.
|
|
3644
|
+
resolvedPositionOffsetForBasis<1>(absolute, areaWidth) - absolute.computedStyle().margin[1];
|
|
3574
3645
|
|
|
3575
3646
|
int containingY = absolute.layout.y + parentOffsetY;
|
|
3576
3647
|
if (hasPositionOffsetValue<0>(absolute))
|
|
3577
|
-
containingY = areaY + resolvedPositionOffsetForBasis<0>(absolute, areaHeight) + absolute.
|
|
3648
|
+
containingY = areaY + resolvedPositionOffsetForBasis<0>(absolute, areaHeight) + absolute.computedStyle().margin[0];
|
|
3578
3649
|
else if (hasPositionOffsetValue<2>(absolute))
|
|
3579
3650
|
containingY = areaY + areaHeight - absolute.layout.height -
|
|
3580
|
-
resolvedPositionOffsetForBasis<2>(absolute, areaHeight) - absolute.
|
|
3651
|
+
resolvedPositionOffsetForBasis<2>(absolute, areaHeight) - absolute.computedStyle().margin[2];
|
|
3581
3652
|
|
|
3582
3653
|
absolute.layout.x = containingX - parentOffsetX;
|
|
3583
3654
|
absolute.layout.y = containingY - parentOffsetY;
|
|
@@ -3586,8 +3657,8 @@ void positionAbsoluteNodeInContainingBlock(int node, int containing, Node *nodes
|
|
|
3586
3657
|
void resolvePositionedDescendants(int node, int root, Node *nodes)
|
|
3587
3658
|
{
|
|
3588
3659
|
for (int child = nodes[node].first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
3589
|
-
if (isDisplayNone(nodes[child].
|
|
3590
|
-
if (isOutOfFlowPosition(nodes[child].
|
|
3660
|
+
if (isDisplayNone(nodes[child].computedStyle())) continue;
|
|
3661
|
+
if (isOutOfFlowPosition(nodes[child].computedStyle().position))
|
|
3591
3662
|
positionAbsoluteNodeInContainingBlock(child, containingBlockForAbsoluteNode(child, root, nodes), nodes);
|
|
3592
3663
|
resolvePositionedDescendants(child, root, nodes);
|
|
3593
3664
|
}
|
|
@@ -3617,7 +3688,7 @@ int LayoutEngine::fixedContainingBlock(const Node &node)
|
|
|
3617
3688
|
|
|
3618
3689
|
bool LayoutEngine::isViewportFixed(const Node &node)
|
|
3619
3690
|
{
|
|
3620
|
-
return node.
|
|
3691
|
+
return node.computedStyle().position == kPositionFixed && fixedContainingBlock(node) < 0;
|
|
3621
3692
|
}
|
|
3622
3693
|
|
|
3623
3694
|
bool LayoutEngine::containsViewportFixed(int node)
|
|
@@ -3638,15 +3709,16 @@ void LayoutEngine::absoluteContainingArea(const Node &parent, const Node &child,
|
|
|
3638
3709
|
// The initial containing block is viewport-sized, even when the HTML
|
|
3639
3710
|
// element has an auto height, margins, or an explicit smaller size.
|
|
3640
3711
|
x = -parent.layout.x; y = -parent.layout.y;
|
|
3641
|
-
|
|
3712
|
+
const auto &persistent = layoutState(static_cast<int>(&parent - Tree::instance().nodes()));
|
|
3713
|
+
width = persistent.memo_avail_w; height = persistent.memo_avail_h;
|
|
3642
3714
|
return;
|
|
3643
3715
|
}
|
|
3644
|
-
if (establishesAbsoluteContainingBlock(parent) || child.
|
|
3716
|
+
if (establishesAbsoluteContainingBlock(parent) || child.computedStyle().position == kPositionFixed) {
|
|
3645
3717
|
// Insets and percentages reference the padding box, excluding borders.
|
|
3646
|
-
x = boxInset(parent.
|
|
3647
|
-
y = boxInset(parent.
|
|
3648
|
-
width = std::max(0, width - x - boxInset(parent.
|
|
3649
|
-
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]);
|
|
3650
3722
|
}
|
|
3651
3723
|
absoluteGridArea(parent, child, x, y, width, height);
|
|
3652
3724
|
}
|
|
@@ -3654,8 +3726,8 @@ void LayoutEngine::absoluteContainingArea(const Node &parent, const Node &child,
|
|
|
3654
3726
|
bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &x, int &y, int &width, int &height)
|
|
3655
3727
|
{
|
|
3656
3728
|
#if GEA_CSS_GRID
|
|
3657
|
-
if (!isDisplayGrid(parent.
|
|
3658
|
-
if (child.
|
|
3729
|
+
if (!isDisplayGrid(parent.computedStyle())) return false;
|
|
3730
|
+
if (child.computedStyle().position == kPositionFixed) {
|
|
3659
3731
|
if (fixedContainingBlock(child) != &parent - Tree::instance().nodes()) return false;
|
|
3660
3732
|
} else if (!establishesAbsoluteContainingBlock(parent)) return false;
|
|
3661
3733
|
const auto *rare = rareDataFor(static_cast<int>(&parent - Tree::instance().nodes()));
|
|
@@ -3663,8 +3735,8 @@ bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &
|
|
|
3663
3735
|
const bool vertical = writingMode(parent) != 0;
|
|
3664
3736
|
for (bool columns : {true, false}) {
|
|
3665
3737
|
const bool horizontal = columns != vertical;
|
|
3666
|
-
const int explicitCount = columns ? rstyle(parent.
|
|
3667
|
-
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;
|
|
3668
3740
|
const std::vector<int> *starts = tracks ? (columns ? &tracks->columnStart : &tracks->rowStart) : nullptr;
|
|
3669
3741
|
const std::vector<int> *ends = tracks ? (columns ? &tracks->columnEnd : &tracks->rowEnd) : nullptr;
|
|
3670
3742
|
const int origin = tracks ? (columns ? tracks->columnOrigin : tracks->rowOrigin) : 0;
|
|
@@ -3679,10 +3751,10 @@ bool LayoutEngine::absoluteGridArea(const Node &parent, const Node &child, int &
|
|
|
3679
3751
|
};
|
|
3680
3752
|
auto placement = gridAxisPlacement(validLine(lines[columns ? 1 : 0]), validLine(lines[columns ? 3 : 2]), explicitCount, true);
|
|
3681
3753
|
const bool hasStart = existing(placement.start), hasEnd = existing(placement.end);
|
|
3682
|
-
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);
|
|
3683
3755
|
int beforeSide = horizontal ? 3 : 0, afterSide = horizontal ? 1 : 2;
|
|
3684
3756
|
if (gridAxisReversed(parent, horizontal)) std::swap(beforeSide, afterSide);
|
|
3685
|
-
int start = -parent.
|
|
3757
|
+
int start = -parent.computedStyle().padding[beforeSide], end = available + parent.computedStyle().padding[afterSide];
|
|
3686
3758
|
if (hasStart) {
|
|
3687
3759
|
const int index = placement.start + origin;
|
|
3688
3760
|
start = count == 0 ? 0 : index == count ? ends->back() : (*starts)[index];
|
|
@@ -3723,37 +3795,38 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3723
3795
|
inlineOffset += treeNodes[cursor].layout.x;
|
|
3724
3796
|
cursor = treeNodes[cursor].parent;
|
|
3725
3797
|
}
|
|
3726
|
-
if (cursor >= 0) continuationOrigin = boxInset(treeNodes[cursor].
|
|
3798
|
+
if (cursor >= 0) continuationOrigin = boxInset(treeNodes[cursor].computedStyle(), 3) - inlineOffset;
|
|
3727
3799
|
}
|
|
3728
|
-
return (horizontal ? rare->inlineStaticPosition.x + continuationOrigin + childNode.
|
|
3729
|
-
: rare->inlineStaticPosition.y + childNode.
|
|
3800
|
+
return (horizontal ? rare->inlineStaticPosition.x + continuationOrigin + childNode.computedStyle().margin[3]
|
|
3801
|
+
: rare->inlineStaticPosition.y + childNode.computedStyle().margin[0]);
|
|
3730
3802
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
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)) {
|
|
3733
3806
|
const bool reversed = horizontal && gridAxisReversed(parent, true);
|
|
3734
|
-
return
|
|
3735
|
-
: childNode.
|
|
3807
|
+
return persistent.static_block_start + (reversed ? -childNode.layout.width - childNode.computedStyle().margin[1]
|
|
3808
|
+
: childNode.computedStyle().margin[horizontal ? 3 : 0]);
|
|
3736
3809
|
}
|
|
3737
3810
|
// In block layout the hypothetical box starts at the parent's inline
|
|
3738
3811
|
// content edge. RTL anchors its inline-end margin edge, even when the absolute
|
|
3739
3812
|
// box is wider than its static-position parent. Its actual containing
|
|
3740
3813
|
// block can be an entirely different ancestor.
|
|
3741
|
-
if (horizontal == (writingMode(parent) == 0) && parent.
|
|
3742
|
-
(!isInlineLevelNode(parent) || isOutOfFlowPosition(parent.
|
|
3743
|
-
!parent.
|
|
3814
|
+
if (horizontal == (writingMode(parent) == 0) && parent.computedStyle().display == kDisplayBlock &&
|
|
3815
|
+
(!isInlineLevelNode(parent) || isOutOfFlowPosition(parent.computedStyle().position)) &&
|
|
3816
|
+
!parent.computedStyle().flex_direction_explicit) {
|
|
3744
3817
|
return rightToLeft(parent)
|
|
3745
|
-
? (horizontal ? parent.layout.width : parent.layout.height) - boxInset(parent.
|
|
3746
|
-
(horizontal ? childNode.layout.width : childNode.layout.height) - childNode.
|
|
3747
|
-
: boxInset(parent.
|
|
3748
|
-
}
|
|
3749
|
-
const bool grid = isDisplayGrid(parent.
|
|
3750
|
-
const bool row = flex ? flexRowDirection(parent.
|
|
3751
|
-
const int crossAlign = childNode.
|
|
3752
|
-
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? 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;
|
|
3753
3826
|
int align = grid
|
|
3754
3827
|
? (horizontal == (writingMode(parent) == 0) ? inlineAlign : crossAlign)
|
|
3755
|
-
: (horizontal ? (row ? parent.
|
|
3756
|
-
: (row ? crossAlign : parent.
|
|
3828
|
+
: (horizontal ? (row ? parent.computedStyle().justify_content : crossAlign)
|
|
3829
|
+
: (row ? crossAlign : parent.computedStyle().justify_content));
|
|
3757
3830
|
if (flex && horizontal == row && isDistributedAlignment(align)) {
|
|
3758
3831
|
// Static position lays out the absolute box as the sole hypothetical
|
|
3759
3832
|
// flex item: between falls back to flex-start, around/evenly to center.
|
|
@@ -3762,17 +3835,17 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3762
3835
|
}
|
|
3763
3836
|
// A grid supplies its content box when the containing block is outside
|
|
3764
3837
|
// it; when it is the containing block, grid placement supplies the area.
|
|
3765
|
-
int inset = grid || flex ? boxInset(parent.
|
|
3838
|
+
int inset = grid || flex ? boxInset(parent.computedStyle(), horizontal ? 3 : 0) : 0;
|
|
3766
3839
|
int parentSize = (horizontal ? parent.layout.width : parent.layout.height) -
|
|
3767
|
-
(grid || flex ? boxInsets(parent.
|
|
3840
|
+
(grid || flex ? boxInsets(parent.computedStyle(), horizontal) : 0);
|
|
3768
3841
|
int areaX, areaY, areaWidth, areaHeight;
|
|
3769
3842
|
if (absoluteGridArea(parent, childNode, areaX, areaY, areaWidth, areaHeight)) {
|
|
3770
3843
|
inset = horizontal ? areaX : areaY;
|
|
3771
3844
|
parentSize = horizontal ? areaWidth : areaHeight;
|
|
3772
3845
|
}
|
|
3773
3846
|
const int childSize = horizontal ? childNode.layout.width : childNode.layout.height;
|
|
3774
|
-
const int beforeMargin = horizontal ? childNode.
|
|
3775
|
-
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];
|
|
3776
3849
|
int available = parentSize;
|
|
3777
3850
|
if (available < 0) available = 0;
|
|
3778
3851
|
const int occupied = childSize + beforeMargin + afterMargin;
|
|
@@ -3788,7 +3861,7 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3788
3861
|
: self >= 0 ? self : baseline ? baselineFallbackAlignment(parent, childNode, pointAlignment, free, horizontal, true)
|
|
3789
3862
|
: usedAlignment(pointAlignment, free);
|
|
3790
3863
|
const int keyword = align & 15;
|
|
3791
|
-
if (flex && horizontal == row && parent.
|
|
3864
|
+
if (flex && horizontal == row && parent.computedStyle().flex_direction_explicit && parent.computedStyle().flex_direction >= 2 &&
|
|
3792
3865
|
(keyword == 0 || keyword == 2 || keyword == 6)) used = used == 2 ? 6 : 2;
|
|
3793
3866
|
int position = inset + beforeMargin;
|
|
3794
3867
|
if (used == 1) position += free / 2;
|
|
@@ -3838,7 +3911,7 @@ int LayoutEngine::alignedAbsoluteOffset(const Node &parent, const Node &childNod
|
|
|
3838
3911
|
|
|
3839
3912
|
bool LayoutEngine::isInlineLevelNode(const Node &n)
|
|
3840
3913
|
{
|
|
3841
|
-
if (n.
|
|
3914
|
+
if (n.computedStyle().display == kDisplayFlex || n.computedStyle().display == kDisplayGrid || n.computedStyle().display == kDisplayNone)
|
|
3842
3915
|
return false;
|
|
3843
3916
|
// An explicit `display:block` makes even an inline-level tag (a <span>) — or a
|
|
3844
3917
|
// Text/Image node — a BLOCK-LEVEL box, so it stacks vertically among siblings
|
|
@@ -3846,23 +3919,23 @@ bool LayoutEngine::isInlineLevelNode(const Node &n)
|
|
|
3846
3919
|
// the weather city list's .city-name/.city-detail spans set display:block to
|
|
3847
3920
|
// stack the name over the region). Without an explicit display, fall back to
|
|
3848
3921
|
// the tag's intrinsic inline-ness.
|
|
3849
|
-
if (n.
|
|
3922
|
+
if (n.computedStyle().display == kDisplayBlock && n.computedStyle().display_explicit) return false;
|
|
3850
3923
|
// In Gea's native layout model, vertical margins on inline-level wrappers are
|
|
3851
3924
|
// used as an authoring signal that the wrapper occupies its own line. Keep
|
|
3852
3925
|
// default spans inline, but do not merge title/score spans with margin-bottom
|
|
3853
3926
|
// into one row.
|
|
3854
|
-
if (n.
|
|
3927
|
+
if (n.computedStyle().margin[0] != 0 || n.computedStyle().margin[2] != 0) return false;
|
|
3855
3928
|
if (n.type == NodeType::Text || n.type == NodeType::Image) return true;
|
|
3856
3929
|
return isInlineLevelTag(tagFromId(n.tag_id));
|
|
3857
3930
|
}
|
|
3858
3931
|
|
|
3859
3932
|
bool LayoutEngine::isCssInlineLevelBox(const Node &n, bool hypothetical)
|
|
3860
3933
|
{
|
|
3861
|
-
if (n.
|
|
3862
|
-
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;
|
|
3863
3936
|
if (!hypothetical && n.parent >= 0) {
|
|
3864
3937
|
const Node &parent = Tree::instance().nodes()[n.parent];
|
|
3865
|
-
if (parent.
|
|
3938
|
+
if (parent.computedStyle().display == kDisplayFlex || isDisplayGrid(parent.computedStyle())) return false;
|
|
3866
3939
|
}
|
|
3867
3940
|
if (n.type == NodeType::Text || n.type == NodeType::Image) return true;
|
|
3868
3941
|
return n.type == NodeType::View && isInlineLevelTag(tagFromId(n.tag_id));
|
|
@@ -3880,17 +3953,17 @@ int LayoutEngine::collectChildren(int parent, int *out, int max, bool skipAbs) c
|
|
|
3880
3953
|
int n = 0;
|
|
3881
3954
|
Node *nodes = Tree::instance().nodes();
|
|
3882
3955
|
for (int child = nodes[parent].first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
3883
|
-
if (isDisplayNone(nodes[child].
|
|
3956
|
+
if (isDisplayNone(nodes[child].computedStyle())) continue;
|
|
3884
3957
|
if (suppressAnonymousWhitespace(nodes, parent, child)) continue;
|
|
3885
|
-
if (skipAbs && isOutOfFlowPosition(nodes[child].
|
|
3958
|
+
if (skipAbs && isOutOfFlowPosition(nodes[child].computedStyle().position)) continue;
|
|
3886
3959
|
if (n < max) out[n++] = child;
|
|
3887
3960
|
}
|
|
3888
3961
|
// All consumers (layout, painting, and hit testing) start from this stable
|
|
3889
3962
|
// order. Subsequent stable z-index/depth sorting preserves it for ties.
|
|
3890
3963
|
// Absolutely positioned children have order 0 for painting and are excluded
|
|
3891
3964
|
// by skipAbs when collecting actual flex/grid items for layout.
|
|
3892
|
-
if (nodes[parent].
|
|
3893
|
-
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; };
|
|
3894
3967
|
for (int i = 1; i < n; ++i) {
|
|
3895
3968
|
const int child = out[i];
|
|
3896
3969
|
int j = i;
|
|
@@ -3905,35 +3978,151 @@ int LayoutEngine::collectChildren(int parent, int *out, int max, bool skipAbs) c
|
|
|
3905
3978
|
}
|
|
3906
3979
|
|
|
3907
3980
|
namespace {
|
|
3908
|
-
//
|
|
3909
|
-
//
|
|
3910
|
-
|
|
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;
|
|
3911
3995
|
} // namespace
|
|
3912
3996
|
|
|
3913
3997
|
void LayoutEngine::beginLayoutPass()
|
|
3914
3998
|
{
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
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);
|
|
3923
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;
|
|
3924
4112
|
}
|
|
3925
4113
|
|
|
3926
4114
|
void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBoxEdges)
|
|
3927
4115
|
{
|
|
3928
4116
|
Node &node = Tree::instance().nodes()[id];
|
|
4117
|
+
auto &persistent = layoutState(id);
|
|
3929
4118
|
const Node *parent = node.parent >= 0 ? &Tree::instance().nodes()[node.parent] : nullptr;
|
|
3930
4119
|
// Horizontal non-replaced floats use the same min/max-content measurement
|
|
3931
4120
|
// and final used-width phase as fit-content. Floats on flex/grid items are
|
|
3932
4121
|
// ignored; orthogonal automatic inline sizing is handled separately.
|
|
3933
|
-
const bool shrinkFloat = node.type == NodeType::View && node.
|
|
3934
|
-
!isOutOfFlowPosition(node.
|
|
3935
|
-
(!parent || (parent->
|
|
3936
|
-
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 &&
|
|
3937
4126
|
writingMode(node) == 0;
|
|
3938
4127
|
// CSS Writing Modes 7.3.2: an orthogonal flow root's automatic inline
|
|
3939
4128
|
// size is fit-content. Measure before fixing the used size so cyclic
|
|
@@ -3942,23 +4131,23 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
3942
4131
|
const bool horizontalInline = writingMode(node) == 0;
|
|
3943
4132
|
const bool orthogonalAuto = node.type == NodeType::View && parent &&
|
|
3944
4133
|
horizontalInline != (writingMode(*parent) == 0) &&
|
|
3945
|
-
parent->
|
|
3946
|
-
!isOutOfFlowPosition(node.
|
|
3947
|
-
(horizontalInline ? node.
|
|
3948
|
-
(horizontalInline ? node.
|
|
3949
|
-
(horizontalInline ? node.
|
|
3950
|
-
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);
|
|
3951
4140
|
const bool horizontal = intrinsicWidth || !orthogonalAuto || horizontalInline;
|
|
3952
4141
|
if ((intrinsicWidth || shrinkFloat || orthogonalAuto) &&
|
|
3953
4142
|
!intrinsicSizeScope(node, horizontal) && !flexBasisScope(node, horizontal)) {
|
|
3954
4143
|
const int inherited = parent ? intrinsicSizeConstraint(*parent, horizontal) : 0;
|
|
3955
|
-
const int keyword = intrinsicWidth ? node.
|
|
4144
|
+
const int keyword = intrinsicWidth ? node.computedStyle().width_expression : kSizeFitContent;
|
|
3956
4145
|
IntrinsicSizeScope scope(node, 1, horizontal);
|
|
3957
4146
|
auto measure = [&](int mode) {
|
|
3958
4147
|
scope.constraint = mode;
|
|
3959
4148
|
const int available = mode == 1 ? 1 : 32767;
|
|
3960
4149
|
layoutNode(id, horizontal ? available : avail_w, horizontal ? avail_h : available, true);
|
|
3961
|
-
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));
|
|
3962
4151
|
};
|
|
3963
4152
|
if (inherited) {
|
|
3964
4153
|
measure(keyword == kSizeMinContent ? 1 : keyword == kSizeMaxContent ? 2 : inherited);
|
|
@@ -3970,47 +4159,53 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
3970
4159
|
const int inlineBasis = node.parent >= 0 && writingMode(Tree::instance().nodes()[node.parent]) != 0 ? avail_h : avail_w;
|
|
3971
4160
|
resolveLayoutBoxLengths(id, intrinsicBoxEdges ? 0 : inlineBasis);
|
|
3972
4161
|
#endif
|
|
3973
|
-
const int edges = boxInsets(node.
|
|
4162
|
+
const int edges = boxInsets(node.computedStyle(), horizontal);
|
|
3974
4163
|
const int stretch = std::max(0, (horizontal ? avail_w : avail_h) -
|
|
3975
|
-
node.
|
|
4164
|
+
node.computedStyle().margin[horizontal ? 1 : 0] - node.computedStyle().margin[horizontal ? 3 : 2] - edges);
|
|
3976
4165
|
scope.borderSize = edges + (keyword == kSizeMinContent ? minimum : keyword == kSizeMaxContent ? maximum : std::min(maximum, std::max(minimum, stretch)));
|
|
3977
4166
|
scope.constraint = 0;
|
|
3978
4167
|
layoutNode(id, avail_w, avail_h, intrinsicBoxEdges);
|
|
3979
4168
|
return;
|
|
3980
4169
|
}
|
|
3981
4170
|
if (node.type == NodeType::Text && intrinsicWidthConstraint(node) == 1)
|
|
3982
|
-
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));
|
|
3983
4172
|
#if GEA_CSS_BOX_EXPRESSIONS
|
|
3984
4173
|
const int inlineBasis = node.parent >= 0 && writingMode(Tree::instance().nodes()[node.parent]) != 0 ? avail_h : avail_w;
|
|
3985
4174
|
if (resolveLayoutBoxLengths(id, intrinsicBoxEdges ? 0 : inlineBasis)) {
|
|
3986
|
-
|
|
4175
|
+
invalidateMemo(id);
|
|
3987
4176
|
}
|
|
3988
4177
|
#endif
|
|
3989
4178
|
const bool memoizable = !gIntrinsicSizeScope && !gFlexBasisScope && avail_w >= INT16_MIN && avail_w <= INT16_MAX &&
|
|
3990
4179
|
avail_h >= INT16_MIN && avail_h <= INT16_MAX;
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
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++);
|
|
3998
4192
|
return;
|
|
3999
4193
|
}
|
|
4000
|
-
if (
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
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) {
|
|
4005
4199
|
// Promote the hit to the MRU slot.
|
|
4006
|
-
std::swap(
|
|
4007
|
-
std::swap(
|
|
4008
|
-
std::swap(
|
|
4009
|
-
|
|
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++);
|
|
4010
4205
|
return;
|
|
4011
4206
|
}
|
|
4012
4207
|
}
|
|
4013
|
-
refreshPerfStatsMutable().treeLayoutNodeCalls
|
|
4208
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutNodeCalls++);
|
|
4014
4209
|
LayoutNodePass(*this, id, avail_w, avail_h).run();
|
|
4015
4210
|
const int beforeRatioWidth = node.layout.width, beforeRatioHeight = node.layout.height;
|
|
4016
4211
|
applyPreferredRatio(node, avail_w, avail_h);
|
|
@@ -4019,29 +4214,31 @@ void LayoutEngine::layoutNode(int id, int avail_w, int avail_h, bool intrinsicBo
|
|
|
4019
4214
|
if (node.parent < 0) {
|
|
4020
4215
|
// The initial containing block places the root; there is no parent
|
|
4021
4216
|
// layout pass to position its margin box or apply float alignment.
|
|
4022
|
-
node.layout.x = node.
|
|
4023
|
-
? avail_w - node.layout.width - node.
|
|
4024
|
-
: node.
|
|
4025
|
-
node.layout.y = node.
|
|
4026
|
-
}
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
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;
|
|
4031
4226
|
if (memoizable) {
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
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;
|
|
4037
4233
|
} else {
|
|
4038
|
-
|
|
4234
|
+
persistent.memo_pass = 0;
|
|
4235
|
+
memo.valid1 = 0;
|
|
4039
4236
|
}
|
|
4040
4237
|
}
|
|
4041
4238
|
|
|
4042
4239
|
void LayoutEngine::repositionChildren(int id)
|
|
4043
4240
|
{
|
|
4044
|
-
refreshPerfStatsMutable().treeLayoutRepositionCalls
|
|
4241
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeLayoutRepositionCalls++);
|
|
4045
4242
|
Node *node = &Tree::instance().nodes()[id];
|
|
4046
4243
|
LayoutNodePass(*this, id, node->layout.width, node->layout.height).repositionChildren();
|
|
4047
4244
|
}
|
|
@@ -4053,14 +4250,15 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4053
4250
|
const int nodeCount = tree.nodeCount();
|
|
4054
4251
|
if (scope < 0 || scope >= nodeCount) return false;
|
|
4055
4252
|
Node &a = nodes[scope];
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
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);
|
|
4059
4257
|
return false;
|
|
4060
4258
|
}
|
|
4061
|
-
if (!LayoutNodePass(*this, scope,
|
|
4062
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 5;
|
|
4063
|
-
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);
|
|
4064
4262
|
return false;
|
|
4065
4263
|
}
|
|
4066
4264
|
|
|
@@ -4076,12 +4274,12 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4076
4274
|
// pre-resolve relative space) — those trees must take the full path.
|
|
4077
4275
|
for (int i = 0; i < nodeCount; ++i) {
|
|
4078
4276
|
const Node &n = nodes[i];
|
|
4079
|
-
if (n.parent < 0 || !isOutOfFlowPosition(n.
|
|
4277
|
+
if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isDisplayNone(n.computedStyle())) continue;
|
|
4080
4278
|
if (!inScope(i)) continue;
|
|
4081
4279
|
const int containing = containingBlockForAbsoluteNode(i, treeRoot, nodes);
|
|
4082
4280
|
if (containing >= 0 && !inScope(containing)) {
|
|
4083
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 3;
|
|
4084
|
-
refreshPerfStatsMutable().treeScopedRejectNode = i;
|
|
4281
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 3);
|
|
4282
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = i);
|
|
4085
4283
|
return false;
|
|
4086
4284
|
}
|
|
4087
4285
|
}
|
|
@@ -4090,8 +4288,8 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4090
4288
|
const int prevY = a.layout.y;
|
|
4091
4289
|
const int prevW = a.layout.width;
|
|
4092
4290
|
const int prevH = a.layout.height;
|
|
4093
|
-
|
|
4094
|
-
layoutNode(scope,
|
|
4291
|
+
Pass layoutPass;
|
|
4292
|
+
layoutNode(scope, persistent.memo_avail_w, persistent.memo_avail_h);
|
|
4095
4293
|
const bool widthChanged = a.layout.width != prevW;
|
|
4096
4294
|
const bool heightChanged = a.layout.height != prevH;
|
|
4097
4295
|
if (widthChanged || heightChanged) {
|
|
@@ -4106,25 +4304,25 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4106
4304
|
bool parentOwnsHeight = hasExplicitHeight(a);
|
|
4107
4305
|
if (a.parent >= 0 && a.parent < nodeCount) {
|
|
4108
4306
|
const Node &parent = nodes[a.parent];
|
|
4109
|
-
if (isDisplayGrid(parent.
|
|
4110
|
-
const int inlineAlign = (GEA_CSS_JUSTIFY_SELF ? rstyle(a.
|
|
4111
|
-
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;
|
|
4112
4310
|
const int alignX = writingMode(parent) == 0 ? inlineAlign : blockAlign;
|
|
4113
4311
|
const int alignY = writingMode(parent) == 0 ? blockAlign : inlineAlign;
|
|
4114
|
-
parentOwnsWidth = parentOwnsWidth || (alignX == 0 && !(a.
|
|
4115
|
-
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));
|
|
4116
4314
|
} else {
|
|
4117
|
-
const bool row = usesRowLayout(parent.
|
|
4118
|
-
const bool parentOwnsMain = a.
|
|
4119
|
-
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;
|
|
4120
4318
|
const bool parentOwnsCross = crossAlign == 0;
|
|
4121
4319
|
parentOwnsWidth = parentOwnsWidth || (row ? parentOwnsMain : parentOwnsCross);
|
|
4122
4320
|
parentOwnsHeight = parentOwnsHeight || (row ? parentOwnsCross : parentOwnsMain);
|
|
4123
4321
|
}
|
|
4124
4322
|
}
|
|
4125
4323
|
if ((widthChanged && !parentOwnsWidth) || (heightChanged && !parentOwnsHeight)) {
|
|
4126
|
-
refreshPerfStatsMutable().treeScopedRejectReason = 4;
|
|
4127
|
-
refreshPerfStatsMutable().treeScopedRejectNode = scope;
|
|
4324
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 4);
|
|
4325
|
+
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = scope);
|
|
4128
4326
|
return false;
|
|
4129
4327
|
}
|
|
4130
4328
|
|
|
@@ -4141,7 +4339,7 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4141
4339
|
// Scoped equivalent of the root containing-block pass (both the node and
|
|
4142
4340
|
// its containing block are inside the scope, in the same relative space).
|
|
4143
4341
|
for (int i = 0; i < nodeCount; ++i) {
|
|
4144
|
-
if (isDisplayNone(nodes[i].
|
|
4342
|
+
if (isDisplayNone(nodes[i].computedStyle()) || !isOutOfFlowPosition(nodes[i].computedStyle().position) || nodes[i].parent < 0) continue;
|
|
4145
4343
|
if (!inScope(i) || i == scope) continue;
|
|
4146
4344
|
const int containing = containingBlockForAbsoluteNode(i, scope, nodes);
|
|
4147
4345
|
if (containing < 0) continue;
|
|
@@ -4150,9 +4348,9 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4150
4348
|
|
|
4151
4349
|
int childParentX = a.layout.x;
|
|
4152
4350
|
int childParentY = a.layout.y;
|
|
4153
|
-
if (a.
|
|
4154
|
-
if (scrollsOverflowX(a.
|
|
4155
|
-
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;
|
|
4156
4354
|
}
|
|
4157
4355
|
for (int child = a.first_child; child >= 0; child = nodes[child].next_sibling) {
|
|
4158
4356
|
resolveAbsoluteCoords(child, childParentX, childParentY);
|
|
@@ -4172,9 +4370,9 @@ void LayoutEngine::resolveAbsoluteCoords(int id, int parent_x, int parent_y)
|
|
|
4172
4370
|
|
|
4173
4371
|
int childParentX = node->layout.x;
|
|
4174
4372
|
int childParentY = node->layout.y;
|
|
4175
|
-
if (node->
|
|
4176
|
-
if (scrollsOverflowX(node->
|
|
4177
|
-
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;
|
|
4178
4376
|
}
|
|
4179
4377
|
|
|
4180
4378
|
for (int child = node->first_child; child >= 0; child = nodes[child].next_sibling) {
|