xbintsc 0.6.9 → 0.6.10

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.
Files changed (63) hide show
  1. package/dist/src/cli/help.d.ts +1 -1
  2. package/dist/src/cli/main.js +1 -0
  3. package/dist/src/cli/main.js.map +1 -1
  4. package/dist/src/driver/config.js +1 -0
  5. package/dist/src/driver/config.js.map +1 -1
  6. package/dist/src/driver/version.d.ts +1 -1
  7. package/dist/src/driver/version.js +1 -1
  8. package/dist/src/driver/version.js.map +1 -1
  9. package/dist/tests/driver/config.test.js +15 -2
  10. package/dist/tests/driver/config.test.js.map +1 -1
  11. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  12. package/dist/tests/e2e/gui-helpers.js +1 -0
  13. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  14. package/dist/tests/e2e/gui-layout.test.js +47 -0
  15. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  16. package/dist/tests/e2e/gui-paint.test.js +108 -0
  17. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  18. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  19. package/dist/tests/e2e/gui-unsupported.test.js +123 -0
  20. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  21. package/doc/ai/extensions.md +7 -4
  22. package/doc/ai/zh-CN/extensions.md +6 -3
  23. package/doc/gui/dom.md +69 -1
  24. package/doc/gui/known-issues.md +12 -5
  25. package/doc/gui/layout.md +19 -6
  26. package/doc/gui/rendering.md +16 -9
  27. package/doc/zh-CN/gui/dom.md +61 -1
  28. package/doc/zh-CN/gui/known-issues.md +11 -4
  29. package/doc/zh-CN/gui/layout.md +14 -4
  30. package/doc/zh-CN/gui/rendering.md +13 -10
  31. package/package.json +7 -7
  32. package/runtime/ext_gui/clip_values.cpp +11 -0
  33. package/runtime/ext_gui/css.cpp +27 -2
  34. package/runtime/ext_gui/css_selector.cpp +23 -0
  35. package/runtime/ext_gui/css_sheet.cpp +7 -0
  36. package/runtime/ext_gui/document.cpp +3 -0
  37. package/runtime/ext_gui/document_animation.cpp +4 -1
  38. package/runtime/ext_gui/dom_api.cpp +3 -0
  39. package/runtime/ext_gui/dom_parse.cpp +4 -0
  40. package/runtime/ext_gui/effect_values.cpp +28 -7
  41. package/runtime/ext_gui/gradient_values.cpp +25 -5
  42. package/runtime/ext_gui/inline_svg.cpp +3 -0
  43. package/runtime/ext_gui/layout_flow.cpp +12 -2
  44. package/runtime/ext_gui/layout_inline.cpp +80 -7
  45. package/runtime/ext_gui/media_query.cpp +7 -1
  46. package/runtime/ext_gui/paint.cpp +58 -23
  47. package/runtime/ext_gui/paint.h +7 -4
  48. package/runtime/ext_gui/paint_clip.cpp +74 -19
  49. package/runtime/ext_gui/paint_internal.h +7 -1
  50. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  51. package/runtime/ext_gui/style.cpp +5 -1
  52. package/runtime/ext_gui/style.h +5 -0
  53. package/runtime/ext_gui/style_cascade.cpp +2 -0
  54. package/runtime/ext_gui/style_internal.h +7 -2
  55. package/runtime/ext_gui/style_print.cpp +3 -0
  56. package/runtime/ext_gui/style_text.cpp +11 -0
  57. package/runtime/ext_gui/style_values.cpp +89 -90
  58. package/runtime/ext_gui/transform.cpp +2 -0
  59. package/runtime/ext_gui/warnings.cpp +300 -0
  60. package/runtime/ext_gui/warnings.h +59 -0
  61. package/src/cli/main.ts +1 -0
  62. package/src/driver/config.ts +1 -0
  63. package/src/driver/version.ts +1 -1
@@ -13,6 +13,7 @@
13
13
  #include "css_internal.h"
14
14
  #include "style_internal.h"
15
15
  #include "style_values_internal.h"
16
+ #include "warnings.h"
16
17
 
17
18
  namespace xtgui {
18
19
 
@@ -219,6 +220,10 @@ bool xt_style_apply_clip_path(XtStyle *style, const std::string &property,
219
220
  return true;
220
221
  }
221
222
  if (text.size() < 8 || text.back() != ')') {
223
+ const size_t open = lower.find('(');
224
+ if (open != std::string::npos) {
225
+ xt_warn_unsupported_function("clip-path", xt_css_trim(lower.substr(0, open)));
226
+ }
222
227
  style->clip_path = spec;
223
228
  return true;
224
229
  }
@@ -239,6 +244,12 @@ bool xt_style_apply_clip_path(XtStyle *style, const std::string &property,
239
244
  return true;
240
245
  }
241
246
  /* `url(#…)`, `path()` and other shapes are not part of the subset. */
247
+ {
248
+ const size_t open = lower.find('(');
249
+ if (open != std::string::npos) {
250
+ xt_warn_unsupported_function("clip-path", xt_css_trim(lower.substr(0, open)));
251
+ }
252
+ }
242
253
  style->clip_path = spec;
243
254
  return true;
244
255
  }
@@ -6,10 +6,13 @@
6
6
 
7
7
  #include "css_internal.h"
8
8
 
9
+ #include "warnings.h"
10
+
9
11
  #include <cmath>
10
12
  #include <cstdlib>
11
13
  #include <cstring>
12
14
  #include <unordered_map>
15
+ #include <unordered_set>
13
16
 
14
17
  namespace xtgui {
15
18
 
@@ -131,7 +134,10 @@ static Length makeScalarLength(double number, const std::string &rawUnit) {
131
134
  else if (unit == "cm") { length.value = (float)number * (96.0f / 2.54f); length.unit = Unit::Px; }
132
135
  else if (unit == "mm") { length.value = (float)number * (96.0f / 25.4f); length.unit = Unit::Px; }
133
136
  else if (unit == "q") { length.value = (float)number * (96.0f / 101.6f); length.unit = Unit::Px; }
134
- else length.unit = Unit::Invalid;
137
+ else {
138
+ length.unit = Unit::Invalid;
139
+ if (!unit.empty()) xt_warn_unsupported_unit(unit);
140
+ }
135
141
  return length;
136
142
  }
137
143
 
@@ -404,7 +410,10 @@ bool parseFunctionColor(const std::string &text, Color *color) {
404
410
  for (size_t i = 0; i < parts.size() && i < 4; i++) {
405
411
  const std::string &part = parts[i];
406
412
  if (i < 3) {
407
- if (name == "hsl" || name == "hsla") return false; // hsl not supported yet
413
+ if (name == "hsl" || name == "hsla") {
414
+ xt_warn_unsupported_function("color", name);
415
+ return false;
416
+ }
408
417
  if (!part.empty() && part.back() == '%') {
409
418
  values[i] = strtof(part.c_str(), nullptr) / 100.0f;
410
419
  } else {
@@ -447,6 +456,14 @@ const std::unordered_map<std::string, unsigned int> &namedColors() {
447
456
 
448
457
  } // namespace
449
458
 
459
+ /** CSS Color 4 functions the engine does not implement (beyond hsl). */
460
+ static bool isUnsupportedColorFunction(const std::string &name) {
461
+ static const std::unordered_set<std::string> names = {
462
+ "color", "color-mix", "hwb", "lab", "lch", "light-dark", "oklab", "oklch",
463
+ };
464
+ return names.count(name) != 0;
465
+ }
466
+
450
467
  Color xt_css_parse_color(const std::string &value) {
451
468
  Color color;
452
469
  std::string text = xt_css_lower(xt_css_trim(value));
@@ -460,6 +477,14 @@ Color xt_css_parse_color(const std::string &value) {
460
477
  parseFunctionColor(text, &color);
461
478
  return color;
462
479
  }
480
+ const size_t open = text.find('(');
481
+ if (open != std::string::npos) {
482
+ const std::string name = xt_css_trim(text.substr(0, open));
483
+ if (isUnsupportedColorFunction(name)) {
484
+ xt_warn_unsupported_function("color", name);
485
+ return color;
486
+ }
487
+ }
463
488
  auto it = namedColors().find(text);
464
489
  if (it != namedColors().end()) {
465
490
  unsigned int rgba = it->second;
@@ -4,10 +4,27 @@
4
4
 
5
5
  #include "css_internal.h"
6
6
 
7
+ #include "warnings.h"
8
+
9
+ #include <string>
10
+ #include <unordered_set>
11
+
7
12
  namespace xtgui {
8
13
 
9
14
  namespace {
10
15
 
16
+ /** Pseudo-classes `css_match.cpp` can evaluate. `:not(...)` and
17
+ * `:nth-child(...)` are stored with their argument text, so the base name is
18
+ * what this set holds. */
19
+ const std::unordered_set<std::string> &supportedPseudoClasses() {
20
+ static const std::unordered_set<std::string> names = {
21
+ "active", "checked", "disabled", "empty", "first-child", "focus",
22
+ "focus-visible", "hover", "last-child", "not", "nth-child", "only-child",
23
+ "root",
24
+ };
25
+ return names;
26
+ }
27
+
11
28
  class SelectorParser {
12
29
  public:
13
30
  explicit SelectorParser(const std::string &text) : text_(text) {}
@@ -43,6 +60,9 @@ class SelectorParser {
43
60
  ComplexSelector selector;
44
61
  if (parseComplex(part, &selector) && !selector.compounds.empty()) {
45
62
  selectors.push_back(std::move(selector));
63
+ } else {
64
+ const std::string trimmed = xt_css_trim(part);
65
+ if (!trimmed.empty()) xt_warn_unsupported_selector(trimmed);
46
66
  }
47
67
  start = i + 1;
48
68
  }
@@ -93,10 +113,12 @@ class SelectorParser {
93
113
  /* `::before`/`::after` are generated-content elements, not states. The
94
114
  * single-colon spellings (`:before`) are the legacy equivalent. */
95
115
  if (pseudoElement || name == "before" || name == "after") {
116
+ if (name != "before" && name != "after") xt_warn_unsupported_pseudo_element(name);
96
117
  compound->pseudo_element = name;
97
118
  any = true;
98
119
  continue;
99
120
  }
121
+ const std::string base = name;
100
122
  if (!pseudoElement && *index < text.size() && text[*index] == '(') {
101
123
  int depth = 0;
102
124
  size_t start = *index;
@@ -113,6 +135,7 @@ class SelectorParser {
113
135
  }
114
136
  name += text.substr(start, *index - start);
115
137
  }
138
+ if (supportedPseudoClasses().count(base) == 0) xt_warn_unsupported_pseudo_class(base);
116
139
  compound->pseudoClasses.push_back(name);
117
140
  any = true;
118
141
  } else if (xt_css_is_ident_start(c)) {
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "css_internal.h"
10
10
 
11
+ #include "warnings.h"
12
+
11
13
  #include <algorithm>
12
14
  #include <cctype>
13
15
  #include <cstring>
@@ -287,6 +289,8 @@ void parseFontFaceBlock(const std::string &block, StyleSheet *sheet) {
287
289
  rule.has_italic = true;
288
290
  rule.italic = true;
289
291
  }
292
+ } else {
293
+ xt_warn_unsupported_descriptor(declaration.property);
290
294
  }
291
295
  }
292
296
  if (rule.family.empty() || rule.sources.empty()) return;
@@ -308,6 +312,9 @@ void parseRules(const std::string &text, const std::string &media, int *order,
308
312
  (std::isalnum((unsigned char)text[nameEnd]) || text[nameEnd] == '-'))
309
313
  nameEnd++;
310
314
  std::string name = xt_css_lower(text.substr(nameStart, nameEnd - nameStart));
315
+ const bool supported = name == "media" || name == "font-face" ||
316
+ (name.size() >= 9 && name.compare(name.size() - 9, 9, "keyframes") == 0);
317
+ if (!supported) xt_warn_unsupported_at_rule(name);
311
318
  size_t brace = text.find('{', nameEnd);
312
319
  size_t semi = text.find(';', nameEnd);
313
320
  if (brace != std::string::npos && (semi == std::string::npos || brace < semi)) {
@@ -4,6 +4,8 @@
4
4
 
5
5
  #include "document.h"
6
6
 
7
+ #include "warnings.h"
8
+
7
9
  #include <cmath>
8
10
  #include <string>
9
11
  #include <utility>
@@ -184,6 +186,7 @@ std::string XtDocument::toDebugString() const {
184
186
  /* -- DOM mutation --------------------------------------------------------- */
185
187
 
186
188
  Node *XtDocument::createElement(const std::string &tag) {
189
+ xt_warn_unsupported_element(tag);
187
190
  auto node = std::make_unique<Node>(NodeType::Element);
188
191
  node->tag = tag;
189
192
  Node *raw = node.get();
@@ -15,6 +15,7 @@
15
15
  #include <vector>
16
16
 
17
17
  #include "style_internal.h"
18
+ #include "warnings.h"
18
19
 
19
20
  namespace xtgui {
20
21
 
@@ -171,7 +172,9 @@ void applyKeyframeDeclarations(XtStyle *style, const std::vector<Declaration> &d
171
172
  declaration.property[1] == '-')
172
173
  continue;
173
174
  if (declaration.property.compare(0, 9, "animation") == 0) continue;
174
- xt_style_apply_declaration(style, declaration.property, declaration.value, context);
175
+ if (!xt_style_apply_declaration(style, declaration.property, declaration.value, context)) {
176
+ xt_warn_unsupported_property(declaration.property);
177
+ }
175
178
  }
176
179
  }
177
180
 
@@ -21,6 +21,8 @@
21
21
 
22
22
  #include "dom_api_internal.h"
23
23
 
24
+ #include "warnings.h"
25
+
24
26
  #include <cctype>
25
27
  #include <string>
26
28
  #include <vector>
@@ -132,6 +134,7 @@ void remove_attribute_raw(xtgui::Node *node, const std::string &name) {
132
134
 
133
135
  void set_attribute(XtGuiWindow *win, xtgui::Node *node, const std::string &name,
134
136
  const std::string &value) {
137
+ if (node != nullptr) xtgui::xt_warn_unsupported_attribute(node->tag, name);
135
138
  set_attribute_raw(node, name, value);
136
139
  mark_dirty(win);
137
140
  }
@@ -9,6 +9,8 @@
9
9
 
10
10
  #include "dom_internal.h"
11
11
 
12
+ #include "warnings.h"
13
+
12
14
  #include <cstdlib>
13
15
  #include <cstring>
14
16
  #include <string>
@@ -326,8 +328,10 @@ std::unique_ptr<Node> xt_html_parse(const std::string &html) {
326
328
  while (stack.size() > 1 && closesOpenElement(stack.back()->tag, token.name)) {
327
329
  stack.pop_back();
328
330
  }
331
+ xt_warn_unsupported_element(token.name);
329
332
  Node *element = stack.back()->addElement(token.name);
330
333
  element->attrs = std::move(token.attrs);
334
+ for (const Attr &attr : element->attrs) xt_warn_unsupported_attribute(token.name, attr.name);
331
335
  bool isVoid = voidElements().count(token.name) != 0;
332
336
  if (!isVoid && !token.selfClosing) stack.push_back(element);
333
337
  continue;
@@ -14,6 +14,7 @@
14
14
  #include "css_internal.h"
15
15
  #include "style_internal.h"
16
16
  #include "style_values_internal.h"
17
+ #include "warnings.h"
17
18
 
18
19
  namespace xtgui {
19
20
 
@@ -223,7 +224,8 @@ static bool parseShadowLengths(const std::string &value, Length *dx, Length *dy,
223
224
  return true;
224
225
  }
225
226
 
226
- static bool parseFilterList(const std::string &value, std::vector<FilterOp> *out) {
227
+ static bool parseFilterList(const std::string &value, const char *property,
228
+ std::vector<FilterOp> *out) {
227
229
  std::string text = xt_css_trim(value);
228
230
  std::string lower = xt_css_lower(text);
229
231
  if (lower == "none" || text.empty()) {
@@ -260,6 +262,7 @@ static bool parseFilterList(const std::string &value, std::vector<FilterOp> *out
260
262
  i = close + 1;
261
263
 
262
264
  FilterOp op;
265
+ bool knownName = true;
263
266
  bool known = true;
264
267
  if (name == "blur") {
265
268
  op.kind = FilterKind::Blur;
@@ -281,8 +284,12 @@ static bool parseFilterList(const std::string &value, std::vector<FilterOp> *out
281
284
  else if (name == "invert") op.kind = FilterKind::Invert;
282
285
  else if (name == "saturate") op.kind = FilterKind::Saturate;
283
286
  else if (name == "opacity") op.kind = FilterKind::Opacity;
284
- else known = false;
285
- if (known && !parseFilterAmount(args, &op.amount)) known = false;
287
+ else knownName = false;
288
+ if (knownName && !parseFilterAmount(args, &op.amount)) known = false;
289
+ }
290
+ if (!knownName) {
291
+ xt_warn_unsupported_function(property, name);
292
+ continue;
286
293
  }
287
294
  if (known) out->push_back(op);
288
295
  }
@@ -396,10 +403,24 @@ static bool parseAnimationShorthand(const std::string &value, std::vector<Animat
396
403
 
397
404
  bool xt_style_apply_effect(XtStyle *style, const std::string &property,
398
405
  const std::string &value) {
399
- if (property == "filter") return parseFilterList(value, &style->filters);
400
- if (property == "backdrop-filter") return parseFilterList(value, &style->backdrop_filters);
401
- if (property == "text-shadow") return parseTextShadow(value, &style->text_shadow);
402
- if (property == "box-shadow") return parseBoxShadow(value, &style->box_shadow);
406
+ /* A recognised property is "handled" even when the value fails to parse: the
407
+ * caller reports only unknown property names, never invalid values. */
408
+ if (property == "filter") {
409
+ parseFilterList(value, "filter", &style->filters);
410
+ return true;
411
+ }
412
+ if (property == "backdrop-filter") {
413
+ parseFilterList(value, "backdrop-filter", &style->backdrop_filters);
414
+ return true;
415
+ }
416
+ if (property == "text-shadow") {
417
+ parseTextShadow(value, &style->text_shadow);
418
+ return true;
419
+ }
420
+ if (property == "box-shadow") {
421
+ parseBoxShadow(value, &style->box_shadow);
422
+ return true;
423
+ }
403
424
  if (property == "animation") {
404
425
  parseAnimationShorthand(value, &style->animations);
405
426
  return true;
@@ -14,6 +14,7 @@
14
14
 
15
15
  #include "style_internal.h"
16
16
  #include "style_values_internal.h"
17
+ #include "warnings.h"
17
18
 
18
19
  namespace xtgui {
19
20
 
@@ -384,8 +385,22 @@ bool parseRadialGradient(const std::string &body, BackgroundLayer *layer) {
384
385
  return true;
385
386
  }
386
387
 
388
+ /** Image functions a browser accepts but this engine does not paint. */
389
+ bool isUnsupportedImageFunction(const std::string &name) {
390
+ static const char *const names[] = {
391
+ "-webkit-conic-gradient", "-webkit-cross-fade", "-webkit-image-set",
392
+ "conic-gradient", "cross-fade", "element",
393
+ "image", "image-set", "paint",
394
+ "repeating-conic-gradient",
395
+ };
396
+ for (const char *candidate : names) {
397
+ if (name == candidate) return true;
398
+ }
399
+ return false;
400
+ }
401
+
387
402
  /** Parse one layer, appending it when it is a supported gradient or image. */
388
- bool parseLayer(const std::string &part, BackgroundLayer *layer) {
403
+ bool parseLayer(const std::string &part, BackgroundLayer *layer, const char *property) {
389
404
  std::string body;
390
405
  /* The repeating prefix is checked first: a plain substring search for
391
406
  * `linear-gradient(` would also match inside `repeating-linear-gradient(`. */
@@ -410,19 +425,24 @@ bool parseLayer(const std::string &part, BackgroundLayer *layer) {
410
425
  layer->image_src = source;
411
426
  return true;
412
427
  }
428
+ const size_t open = part.find('(');
429
+ if (open != std::string::npos) {
430
+ const std::string name = xt_css_lower(xt_css_trim(part.substr(0, open)));
431
+ if (isUnsupportedImageFunction(name)) xt_warn_unsupported_function(property, name);
432
+ }
413
433
  return false;
414
434
  }
415
435
 
416
436
  /** Parse the layer list. `allowColor` is true for the `background` shorthand. */
417
437
  bool parseLayers(const std::string &value, std::vector<BackgroundLayer> *layers, Color *color,
418
- bool *hasColor, bool allowColor) {
438
+ bool *hasColor, bool allowColor, const char *property) {
419
439
  layers->clear();
420
440
  std::string text = xt_css_trim(value);
421
441
  std::string lower = xt_css_lower(text);
422
442
  if (lower == "none") return true;
423
443
  for (const std::string &part : splitCommas(text)) {
424
444
  BackgroundLayer layer;
425
- if (parseLayer(part, &layer)) {
445
+ if (parseLayer(part, &layer, property)) {
426
446
  layers->push_back(layer);
427
447
  /* `background: linear-gradient(...) #fff` mixes the final colour with the
428
448
  * image layer; the gradient itself is one token, so a colour scan cannot
@@ -460,7 +480,7 @@ void xt_style_apply_background_image(XtStyle *style, const std::string &value) {
460
480
  Color color;
461
481
  bool hasColor = false;
462
482
  std::vector<BackgroundLayer> layers;
463
- parseLayers(value, &layers, &color, &hasColor, false);
483
+ parseLayers(value, &layers, &color, &hasColor, false, "background-image");
464
484
  style->background_layers = std::move(layers);
465
485
  }
466
486
 
@@ -472,7 +492,7 @@ void xt_style_apply_background(XtStyle *style, const std::string &value) {
472
492
  Color color;
473
493
  bool hasColor = false;
474
494
  std::vector<BackgroundLayer> layers;
475
- parseLayers(value, &layers, &color, &hasColor, true);
495
+ parseLayers(value, &layers, &color, &hasColor, true, "background");
476
496
  style->background_layers = std::move(layers);
477
497
  style->background_sizes.clear();
478
498
  if (hasColor) {
@@ -4,6 +4,8 @@
4
4
 
5
5
  #include "inline_svg.h"
6
6
 
7
+ #include "warnings.h"
8
+
7
9
  #include <cctype>
8
10
  #include <cstdio>
9
11
  #include <string>
@@ -239,6 +241,7 @@ void serializeStyleText(const Node *node, const std::unordered_map<const Node *,
239
241
  void serializeNode(const Node *node, const std::unordered_map<const Node *, XtStyle> *styles,
240
242
  std::string *out) {
241
243
  if (node == nullptr || !node->isElement()) return;
244
+ xt_warn_unsupported_svg_element(node->tag);
242
245
  const XtStyle *computed = nullptr;
243
246
  if (styles != nullptr) {
244
247
  auto found = styles->find(node);
@@ -390,6 +390,16 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
390
390
  if (block->style->display == Display::Grid)
391
391
  return layoutGrid(block, contentWidth, definiteHeight);
392
392
 
393
+ /* A percentage height on a child resolves against this block's *content*
394
+ * height. `definiteHeight` is that height when it is known (an explicit
395
+ * `height`, a clamp()/aspect-ratio result, or a flex/grid stretch); a box
396
+ * whose height came from `clamp()` must hand that value down, because the
397
+ * `availableHeight` it received is only the containing block's height from
398
+ * further up (or -1 when that chain is indefinite). Without this, a
399
+ * `height: 100%` portrait inside a sized frame was treated as `auto` and
400
+ * collapsed to its zero-height absolutely positioned artwork. */
401
+ float childHeight = definiteHeight >= 0 ? definiteHeight : availableHeight;
402
+
393
403
  float y = block->content_y;
394
404
  float startY = y;
395
405
  /* The bottom margin of the last in-flow block, waiting to collapse with the
@@ -458,7 +468,7 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
458
468
  : block->content_x + contentWidth - outerWidth;
459
469
  setContainingBlock(child.get(), containingBlockAncestor(block));
460
470
  float height =
461
- layoutBlock(child.get(), floatX, y, contentWidth, availableHeight, contentW);
471
+ layoutBlock(child.get(), floatX, y, contentWidth, childHeight, contentW);
462
472
  ActiveFloat entry;
463
473
  entry.left = childStyle->float_side == FloatSide::Left;
464
474
  entry.x = child->x;
@@ -489,7 +499,7 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
489
499
  }
490
500
  y = desired;
491
501
  setContainingBlock(child.get(), containingBlockAncestor(block));
492
- y += layoutBlock(child.get(), block->content_x, y, contentWidth, availableHeight);
502
+ y += layoutBlock(child.get(), block->content_x, y, contentWidth, childHeight);
493
503
  pending = child->margin_bottom;
494
504
  hasBlock = true;
495
505
  } else {
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "layout_flow_internal.h"
10
10
 
11
+ #include <utility>
12
+
11
13
  namespace xtgui {
12
14
  namespace layout_flow_detail {
13
15
 
@@ -24,12 +26,23 @@ void Layouter::flattenInline(LayoutBox *box, float contentWidth,
24
26
  const std::string &text = box->text;
25
27
  size_t i = 0;
26
28
  while (i < text.size()) {
27
- if (text[i] == '\n') {
28
- InlineItem br;
29
- br.box = box;
30
- br.style = &style;
31
- br.force_break = true;
32
- out.push_back(std::move(br));
29
+ if (text[i] == '\n' || text[i] == '\r') {
30
+ /* `nowrap` collapses a source newline to a space; the other modes keep
31
+ * the engine's existing forced break (notably `pre`, which must). */
32
+ bool preserveNewline = style.white_space != WhiteSpace::NoWrap;
33
+ InlineItem item;
34
+ item.box = box;
35
+ item.style = &style;
36
+ if (preserveNewline) {
37
+ item.force_break = true;
38
+ } else {
39
+ item.text = " ";
40
+ item.is_space = true;
41
+ item.width = textWidth(" ", style);
42
+ item.height = height;
43
+ item.ascent = ascent;
44
+ }
45
+ out.push_back(std::move(item));
33
46
  i++;
34
47
  continue;
35
48
  }
@@ -143,12 +156,34 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
143
156
  for (LayoutBox *box : run) computeInlineGeometry(box);
144
157
  return height;
145
158
  }
159
+ /* `nowrap`/`pre` keep the run on one line (a preserved newline still breaks
160
+ * it); without that, `text-overflow: ellipsis` would never see an overflowing
161
+ * line on ordinary prose. */
162
+ const bool wrap = containerStyle.white_space == WhiteSpace::Normal ||
163
+ containerStyle.white_space == WhiteSpace::PreWrap ||
164
+ containerStyle.white_space == WhiteSpace::PreLine;
165
+ const bool ellipsis = containerStyle.text_overflow == TextOverflow::Ellipsis &&
166
+ containerStyle.overflow != Overflow::Visible;
146
167
  float cursorY = y;
147
168
  std::vector<InlineItem *> line;
148
169
  float lineWidth = 0;
149
170
  float lineAscent = 0;
150
171
  float lineDescent = 0;
151
172
 
173
+ /* Byte length of the longest UTF-8 prefix of `text` that fits in `budget`
174
+ * when measured with `style`, without splitting a multi-byte code point. */
175
+ auto fittingPrefix = [&](const std::string &text, const XtStyle &style, float budget) {
176
+ size_t best = 0;
177
+ for (size_t i = 0; i < text.size();) {
178
+ size_t next = i + 1;
179
+ while (next < text.size() && ((unsigned char)text[next] & 0xC0) == 0x80) next++;
180
+ if (textWidth(text.substr(0, next), style) > budget + 0.001f) break;
181
+ best = next;
182
+ i = next;
183
+ }
184
+ return best;
185
+ };
186
+
152
187
  /* Horizontal band left free by the floats overlapping [top, top + height). */
153
188
  auto band = [&](float top, float height, float *x0, float *x1) {
154
189
  *x0 = container->content_x;
@@ -171,6 +206,44 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
171
206
  float x1 = 0;
172
207
  band(cursorY, height, &x0, &x1);
173
208
  float available = x1 - x0;
209
+ if (ellipsis && lineWidth > available + 0.001f) {
210
+ /* Replace the part of the line that does not fit with one ellipsis. The
211
+ * ellipsis gets the style of the run it terminates, so a smaller/larger
212
+ * inline span keeps its own metrics. */
213
+ const std::string dots = "\xE2\x80\xA6"; // U+2026 HORIZONTAL ELLIPSIS
214
+ float dotsWidth = textWidth(dots, containerStyle);
215
+ float budget = available - dotsWidth;
216
+ if (budget < 0.0f) budget = 0.0f;
217
+ std::vector<InlineItem *> kept;
218
+ float used = 0.0f;
219
+ for (InlineItem *item : line) {
220
+ if (used + item->width <= budget + 0.001f) {
221
+ kept.push_back(item);
222
+ used += item->width;
223
+ continue;
224
+ }
225
+ if (item->atomic) {
226
+ /* An atomic inline box cannot carry the ellipsis itself; append it to
227
+ * the last text run when one still fits, otherwise drop the box. */
228
+ if (!kept.empty() && !kept.back()->atomic && !kept.back()->is_space) {
229
+ kept.back()->text += dots;
230
+ kept.back()->width += dotsWidth;
231
+ }
232
+ break;
233
+ }
234
+ size_t prefix = fittingPrefix(item->text, *item->style, budget - used);
235
+ std::string text = item->text.substr(0, prefix);
236
+ while (!text.empty() && (text.back() == ' ' || text.back() == '\t')) text.pop_back();
237
+ item->text = text + dots;
238
+ item->width = textWidth(text, *item->style) + dotsWidth;
239
+ kept.push_back(item);
240
+ break;
241
+ }
242
+ line = std::move(kept);
243
+ lineWidth = 0.0f;
244
+ for (InlineItem *item : line) lineWidth += item->width;
245
+ if (line.empty()) return;
246
+ }
174
247
  float x = x0;
175
248
  if (containerStyle.text_align == TextAlign::Center) {
176
249
  x += (available - lineWidth) / 2.0f;
@@ -213,7 +286,7 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
213
286
  float x1 = 0;
214
287
  band(cursorY, pendingHeight, &x0, &x1);
215
288
  float available = x1 - x0;
216
- if (lineWidth + item.width > available && !line.empty()) finalize();
289
+ if (wrap && lineWidth + item.width > available && !line.empty()) finalize();
217
290
  if (item.is_space && line.empty()) continue;
218
291
  line.push_back(&item);
219
292
  lineWidth += item.width;
@@ -9,6 +9,8 @@
9
9
  */
10
10
  #include "css_internal.h"
11
11
 
12
+ #include "warnings.h"
13
+
12
14
  #include <cmath>
13
15
  #include <string>
14
16
  #include <vector>
@@ -113,7 +115,10 @@ bool evaluateRange(const std::string &inner, float vw, float vh, bool *matched)
113
115
  float actual = 0.0f;
114
116
  if (feature == "width") actual = vw;
115
117
  else if (feature == "height") actual = vh;
116
- else return false;
118
+ else {
119
+ xt_warn_unsupported_media_feature(feature);
120
+ return false;
121
+ }
117
122
  float value = 0.0f;
118
123
  if (!mediaLength(valueText, vw, vh, &value)) return false;
119
124
  if (flipped) {
@@ -159,6 +164,7 @@ bool evaluateFeature(const std::string &inner, float vw, float vh) {
159
164
  if (name == "prefers-contrast") return value == "no-preference";
160
165
  if (name == "scripting") return value == "enabled";
161
166
  if (name == "display-mode") return value == "browser";
167
+ xt_warn_unsupported_media_feature(name);
162
168
  return false;
163
169
  }
164
170