about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-05-30 17:33:45 +0200
committerbptato <nincsnevem662@gmail.com>2024-05-30 17:36:47 +0200
commitb4cbdb8e1eb8af2a55d6a5b22316d59c87612578 (patch)
treed61a132b0ea64cde82608a96b23ed4739533ab50
parentefbbe82f2387368ec771ab1b58ba735b63f9c7e3 (diff)
downloadchawan-b4cbdb8e1eb8af2a55d6a5b22316d59c87612578.tar.gz
layout: fix clear on blocks establishing new BFCs
As per standard:

> Adjoining vertical margins collapse, except:
> [...]
> If the top and bottom margins of an element with clearance are
> adjoining, its margins collapse with the adjoining margins of
> following siblings but that resulting margin does not collapse with
> the bottom margin of the parent block.
-rw-r--r--src/layout/engine.nim5
-rw-r--r--test/layout/new-bfc-clears-floats.expected4
-rw-r--r--test/layout/new-bfc-clears-floats.html6
3 files changed, 14 insertions, 1 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 5cc32dd1..e91fd0d8 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -1230,7 +1230,8 @@ func canFlushMargins(box: BlockBox; sizes: ResolvedSizes): bool =
   if box.computed{"position"} == PositionAbsolute:
     return false
   return sizes.padding.top != 0 or sizes.padding.bottom != 0 or
-    box.inline != nil or box.computed{"display"} notin DisplayBlockLike
+    box.inline != nil or box.computed{"display"} notin DisplayBlockLike or
+    box.computed{"clear"} != ClearNone
 
 proc flushMargins(bctx: var BlockContext; box: BlockBox) =
   # Apply uncommitted margins.
@@ -2321,6 +2322,8 @@ proc layoutBlockChildBFC(state: var BlockState; bctx: var BlockContext;
     bctx.flushMargins(child)
     bctx.positionFloats()
     bctx.marginTodo.append(child.state.margin.bottom)
+    if child.computed{"clear"} != ClearNone:
+      state.offset.clearFloats(bctx, child.computed{"clear"})
     if bctx.exclusions.len > 0:
       # Consulting the standard for an important edge case... (abridged)
       #
diff --git a/test/layout/new-bfc-clears-floats.expected b/test/layout/new-bfc-clears-floats.expected
new file mode 100644
index 00000000..876d665a
--- /dev/null
+++ b/test/layout/new-bfc-clears-floats.expected
@@ -0,0 +1,4 @@
+left                                                                       right
+testing
+left                                                                       right
+testing
diff --git a/test/layout/new-bfc-clears-floats.html b/test/layout/new-bfc-clears-floats.html
new file mode 100644
index 00000000..ce81c7e1
--- /dev/null
+++ b/test/layout/new-bfc-clears-floats.html
@@ -0,0 +1,6 @@
+<div style="float: left">left</div>
+<div style="float: right">right</div>
+<div style="clear: both"><div style="display: flow-root">testing</div></div>
+<div style="float: left">left</div>
+<div style="float: right">right</div>
+<div style="clear: both; display: flow-root">testing</div>
dddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */