about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-15 21:40:37 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-15 22:47:20 +0100
commit0971ad855c59866b29659fa4d9c249c3919b600c (patch)
tree22f8ce2761186e71925cc9c9b27d653fb1dc38d2
parente5afb660476c97c97259a72cf4d6f3bbfdbff9fe (diff)
downloadchawan-0971ad855c59866b29659fa4d9c249c3919b600c.tar.gz
layout: do not allow canpx for scFitContent
The test case attached is undefined in CSS 2.1, but css-sizing-3
wants us to just ignore the width property (I think).
-rw-r--r--src/css/layout.nim4
-rw-r--r--test/layout/float-child-percentage-width-ignored.color.expected2
-rw-r--r--test/layout/float-child-percentage-width-ignored.html4
3 files changed, 8 insertions, 2 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index a833126c..c737f9f8 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -144,7 +144,7 @@ func px(l: CSSLength; lctx: LayoutContext; p: LayoutUnit = 0):
   return px(l, lctx.attrs, p)
 
 func canpx(l: CSSLength; sc: SizeConstraint): bool =
-  return l.u != cuAuto and (l.u != cuPerc or sc.isDefinite())
+  return l.u != cuAuto and (l.u != cuPerc or sc.t == scStretch)
 
 # Note: for margins only
 # For percentages, use 0 for indefinite, and containing box's size for
@@ -909,7 +909,7 @@ func spx(l: CSSLength; lctx: LayoutContext; p: SizeConstraint;
 proc resolveContentWidth(sizes: var ResolvedSizes; widthpx: LayoutUnit;
     parentWidth: SizeConstraint; computed: CSSValues;
     isauto = false) =
-  if not sizes.space.w.isDefinite() or not parentWidth.isDefinite():
+  if not sizes.space.w.isDefinite() or parentWidth.t != scStretch:
     # width is indefinite, so no conflicts can be resolved here.
     return
   let total = widthpx + sizes.margin[dtHorizontal].sum() +
diff --git a/test/layout/float-child-percentage-width-ignored.color.expected b/test/layout/float-child-percentage-width-ignored.color.expected
new file mode 100644
index 00000000..5d875773
--- /dev/null
+++ b/test/layout/float-child-percentage-width-ignored.color.expected
@@ -0,0 +1,2 @@
+test
+
diff --git a/test/layout/float-child-percentage-width-ignored.html b/test/layout/float-child-percentage-width-ignored.html
new file mode 100644
index 00000000..02236838
--- /dev/null
+++ b/test/layout/float-child-percentage-width-ignored.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<div style="float: left; background: purple">
+<div style="width: 4ch; background: red">
+test