Floating legend should be added to the existing anonymous block. (issue 2550963002 by glebl@chromium.org)

0 views
Skip to first unread message

gl...@chromium.org

unread,
Dec 3, 2016, 5:06:34 PM12/3/16
to e...@chromium.org, cbies...@chromium.org, chromium...@chromium.org, szager+la...@chromium.org, zol...@webkit.org, blink-revi...@chromium.org, pdr+renderi...@chromium.org, eae+bli...@chromium.org, leviw+re...@chromium.org, jchaffraix...@chromium.org, blink-...@chromium.org
Reviewers: eae, cbiesinger
CL: https://codereview.chromium.org/2550963002/

Description:
Floating legend should be added to the existing anonymous block.

If fieldset's legend is floating it should be added to the existing fieldset\'s
anonymous block instead of creating a nested one.

BUG=661230, 670837
TEST=fast/forms/fieldset/fieldset-legend-float.html

Tested with real world websites:
https://jsbin.com/zutekilusi/1/edit?html,css,output
http://www.timico.co.uk/timico-ltd-application-form
http://codepen.io/michaelpumo/pen/VmZqrr

Affected files (+50, -6 lines):
A third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float.html
A third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float-expected.html
M third_party/WebKit/Source/core/layout/LayoutFieldset.cpp


Index: third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float-expected.html
diff --git a/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float-expected.html b/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float-expected.html
new file mode 100644
index 0000000000000000000000000000000000000000..0699fe2bcbd977f77375f3b7f5857db796c50e94
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float-expected.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<style>
+ #legend {
+ float: left;
+ }
+</style>
+
+This should display fieldset with the legend that is styled as a left float.
+
+<div id="fieldset">
+ <div id="legend">Left floating legend</legend>
+</div>
Index: third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float.html
diff --git a/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float.html b/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float.html
new file mode 100644
index 0000000000000000000000000000000000000000..0606f8cf3e55389272ba5993deba01bd2f2f0493
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/forms/fieldset/fieldset-legend-float.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<style>
+ fieldset {
+ border: 0px;
+ padding: 0px;
+ margin: 0px;
+ }
+
+ legend {
+ float: left;
+ padding: 0px;
+ }
+</style>
+
+This should display fieldset with the legend that is styled as a left float.
+
+<fieldset>
+ <legend>Left floating legend</legend>
+</fieldset>
Index: third_party/WebKit/Source/core/layout/LayoutFieldset.cpp
diff --git a/third_party/WebKit/Source/core/layout/LayoutFieldset.cpp b/third_party/WebKit/Source/core/layout/LayoutFieldset.cpp
index 1527da1bdd632aaf0803296b2e45862baf241dfd..f0eb1cb0bb31fa10c48ff27296ab5c51a2b96c4b 100644
--- a/third_party/WebKit/Source/core/layout/LayoutFieldset.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutFieldset.cpp
@@ -262,7 +262,15 @@ void LayoutFieldset::addChild(LayoutObject* newChild,
if (isHTMLLegendElement(newChild->node())) {
// Let legend block to be the 2nd for correct layout positioning.
newChild->mutableStyle()->setOrder(2);
- LayoutFlexibleBox::addChild(newChild, m_innerBlock);
+
+ // LayoutFlexibleBox::addChild will create an anonymous block if legend is
+ // float. Use the existing fieldset's anonymous block here instead.
+ if (newChild->isFloatingOrOutOfFlowPositioned()) {
+ m_innerBlock->addChild(newChild);
+ } else {
+ LayoutFlexibleBox::addChild(newChild, m_innerBlock);
+ }
+
} else {
if (beforeChild && isHTMLLegendElement(beforeChild->node())) {
m_innerBlock->addChild(newChild);
@@ -285,12 +293,17 @@ void LayoutFieldset::createInnerBlock() {

void LayoutFieldset::removeChild(LayoutObject* oldChild) {
if (isHTMLLegendElement(oldChild->node())) {
- LayoutFlexibleBox::removeChild(oldChild);
- if (m_innerBlock) {
- resetInnerBlockPadding(isHorizontalWritingMode(), m_innerBlock);
- m_innerBlock->setNeedsLayout(LayoutInvalidationReason::FieldsetChanged,
- MarkOnlyThis);
+ if (oldChild->isFloatingOrOutOfFlowPositioned()) {
+ m_innerBlock->removeChild(oldChild);
+ } else {
+ LayoutFlexibleBox::removeChild(oldChild);
+ if (m_innerBlock) {
+ resetInnerBlockPadding(isHorizontalWritingMode(), m_innerBlock);
+ m_innerBlock->setNeedsLayout(LayoutInvalidationReason::FieldsetChanged,
+ MarkOnlyThis);
+ }
}
+
setShouldDoFullPaintInvalidation();
} else if (oldChild == m_innerBlock) {
LayoutFlexibleBox::removeChild(oldChild);


cbies...@chromium.org

unread,
Dec 3, 2016, 6:54:12 PM12/3/16
to gl...@chromium.org, e...@chromium.org, chromium...@chromium.org, szager+la...@chromium.org, zol...@webkit.org, blink-revi...@chromium.org, pdr+renderi...@chromium.org, eae+bli...@chromium.org, leviw+re...@chromium.org, jchaffraix...@chromium.org, blink-...@chromium.org
lgtm but please add a comment that this is necessary because flexbox forces the
floating legend to be non-floating and so we need to add it to the child so it
can float. (either that or I misunderstood the purpose of this patch)

https://codereview.chromium.org/2550963002/

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 4, 2016, 12:36:18 AM12/4/16
to gl...@chromium.org, e...@chromium.org, cbies...@chromium.org, commi...@chromium.org, chromium...@chromium.org, szager+la...@chromium.org, zol...@webkit.org, blink-revi...@chromium.org, pdr+renderi...@chromium.org, eae+bli...@chromium.org, leviw+re...@chromium.org, jchaffraix...@chromium.org, blink-...@chromium.org

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 4, 2016, 12:44:51 AM12/4/16
to gl...@chromium.org, e...@chromium.org, cbies...@chromium.org, commi...@chromium.org, chromium...@chromium.org, szager+la...@chromium.org, zol...@webkit.org, blink-revi...@chromium.org, pdr+renderi...@chromium.org, eae+bli...@chromium.org, leviw+re...@chromium.org, jchaffraix...@chromium.org, blink-...@chromium.org
Committed patchset #1 (id:1)

https://codereview.chromium.org/2550963002/

commit-bot@chromium.org via codereview.chromium.org

unread,
Dec 4, 2016, 12:46:43 AM12/4/16
to gl...@chromium.org, e...@chromium.org, cbies...@chromium.org, commi...@chromium.org, chromium...@chromium.org, szager+la...@chromium.org, zol...@webkit.org, blink-revi...@chromium.org, pdr+renderi...@chromium.org, eae+bli...@chromium.org, leviw+re...@chromium.org, jchaffraix...@chromium.org, blink-...@chromium.org
Patchset 1 (id:??) landed as
https://crrev.com/0f77a4ef8c0218492b5b8689a793b34b0f5a34d8
Cr-Commit-Position: refs/heads/master@{#436187}

https://codereview.chromium.org/2550963002/
Reply all
Reply to author
Forward
0 new messages