Commit b77818ea authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

css-deprecated-flexbox: remove visibility checks in LayoutDeprecatedFlexibleBox

visibility:collapse is only supported for tables, so all of the visibility
checks in this class should be removed.

BUG=1015987
TEST=wpt/compat/webkit-box-clamp-visibility-change.html

Change-Id: Ib68b03a7942d6cd78b13e3d0bb11ba1a8742cb5d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898398
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712735}
parent 6e9c8ef7
...@@ -156,8 +156,6 @@ static int GetHeightForLineCount(const LayoutBlockFlow* block_flow, ...@@ -156,8 +156,6 @@ static int GetHeightForLineCount(const LayoutBlockFlow* block_flow,
int line_count, int line_count,
bool include_bottom, bool include_bottom,
int& count) { int& count) {
if (block_flow->StyleRef().Visibility() != EVisibility::kVisible)
return -1;
if (block_flow->ChildrenInline()) { if (block_flow->ChildrenInline()) {
for (RootInlineBox* box = block_flow->FirstRootBox(); box; for (RootInlineBox* box = block_flow->FirstRootBox(); box;
box = box->NextRootBox()) { box = box->NextRootBox()) {
...@@ -198,9 +196,6 @@ static int GetHeightForLineCount(const LayoutBlockFlow* block_flow, ...@@ -198,9 +196,6 @@ static int GetHeightForLineCount(const LayoutBlockFlow* block_flow,
static RootInlineBox* LineAtIndex(const LayoutBlockFlow* block_flow, int i) { static RootInlineBox* LineAtIndex(const LayoutBlockFlow* block_flow, int i) {
DCHECK_GE(i, 0); DCHECK_GE(i, 0);
if (block_flow->StyleRef().Visibility() != EVisibility::kVisible)
return nullptr;
if (block_flow->ChildrenInline()) { if (block_flow->ChildrenInline()) {
for (RootInlineBox* box = block_flow->FirstRootBox(); box; for (RootInlineBox* box = block_flow->FirstRootBox(); box;
box = box->NextRootBox()) { box = box->NextRootBox()) {
...@@ -226,8 +221,6 @@ static RootInlineBox* LineAtIndex(const LayoutBlockFlow* block_flow, int i) { ...@@ -226,8 +221,6 @@ static RootInlineBox* LineAtIndex(const LayoutBlockFlow* block_flow, int i) {
static int LineCount(const LayoutBlockFlow* block_flow, static int LineCount(const LayoutBlockFlow* block_flow,
const RootInlineBox* stop_root_inline_box = nullptr, const RootInlineBox* stop_root_inline_box = nullptr,
bool* found = nullptr) { bool* found = nullptr) {
if (block_flow->StyleRef().Visibility() != EVisibility::kVisible)
return 0;
int count = 0; int count = 0;
if (block_flow->ChildrenInline()) { if (block_flow->ChildrenInline()) {
for (RootInlineBox* box = block_flow->FirstRootBox(); box; for (RootInlineBox* box = block_flow->FirstRootBox(); box;
...@@ -261,8 +254,6 @@ static int LineCount(const LayoutBlockFlow* block_flow, ...@@ -261,8 +254,6 @@ static int LineCount(const LayoutBlockFlow* block_flow,
} }
static void ClearTruncation(LayoutBlockFlow* block_flow) { static void ClearTruncation(LayoutBlockFlow* block_flow) {
if (block_flow->StyleRef().Visibility() != EVisibility::kVisible)
return;
if (block_flow->ChildrenInline() && block_flow->HasMarkupTruncation()) { if (block_flow->ChildrenInline() && block_flow->HasMarkupTruncation()) {
block_flow->SetHasMarkupTruncation(false); block_flow->SetHasMarkupTruncation(false);
for (RootInlineBox* box = block_flow->FirstRootBox(); box; for (RootInlineBox* box = block_flow->FirstRootBox(); box;
...@@ -314,12 +305,6 @@ static LayoutUnit MarginWidthForChild(LayoutBox* child) { ...@@ -314,12 +305,6 @@ static LayoutUnit MarginWidthForChild(LayoutBox* child) {
return margin; return margin;
} }
static bool ChildDoesNotAffectWidthOrFlexing(LayoutObject* child) {
// Positioned children and collapsed children don't affect the min/max width.
return child->IsOutOfFlowPositioned() ||
child->StyleRef().Visibility() == EVisibility::kCollapse;
}
static LayoutUnit WidthForChild(LayoutBox* child) { static LayoutUnit WidthForChild(LayoutBox* child) {
if (child->HasOverrideLogicalWidth()) if (child->HasOverrideLogicalWidth())
return child->OverrideLogicalWidth(); return child->OverrideLogicalWidth();
...@@ -360,7 +345,7 @@ void LayoutDeprecatedFlexibleBox::ComputeIntrinsicLogicalWidths( ...@@ -360,7 +345,7 @@ void LayoutDeprecatedFlexibleBox::ComputeIntrinsicLogicalWidths(
if (IsVertical()) { if (IsVertical()) {
for (LayoutBox* child = FirstChildBox(); child; for (LayoutBox* child = FirstChildBox(); child;
child = child->NextSiblingBox()) { child = child->NextSiblingBox()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
LayoutUnit margin = MarginWidthForChild(child); LayoutUnit margin = MarginWidthForChild(child);
...@@ -373,7 +358,7 @@ void LayoutDeprecatedFlexibleBox::ComputeIntrinsicLogicalWidths( ...@@ -373,7 +358,7 @@ void LayoutDeprecatedFlexibleBox::ComputeIntrinsicLogicalWidths(
} else { } else {
for (LayoutBox* child = FirstChildBox(); child; for (LayoutBox* child = FirstChildBox(); child;
child = child->NextSiblingBox()) { child = child->NextSiblingBox()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
LayoutUnit margin = MarginWidthForChild(child); LayoutUnit margin = MarginWidthForChild(child);
...@@ -483,8 +468,7 @@ static void GatherFlexChildrenInfo(FlexBoxIterator& iterator, ...@@ -483,8 +468,7 @@ static void GatherFlexChildrenInfo(FlexBoxIterator& iterator,
} }
// Check to see if this child flexes. // Check to see if this child flexes.
if (!ChildDoesNotAffectWidthOrFlexing(child) && if (!child->IsOutOfFlowPositioned() && child->StyleRef().BoxFlex() > 0.0f) {
child->StyleRef().BoxFlex() > 0.0f) {
// We always have to lay out flexible objects again, since the flex // We always have to lay out flexible objects again, since the flex
// distribution // distribution
// may have changed, and we need to reallocate space. // may have changed, and we need to reallocate space.
...@@ -608,13 +592,6 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) { ...@@ -608,13 +592,6 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) {
continue; continue;
} }
if (child->StyleRef().Visibility() == EVisibility::kCollapse) {
// visibility: collapsed children do not participate in our positioning.
// But we need to lay them down.
child->LayoutIfNeeded();
continue;
}
SubtreeLayoutScope layout_scope(*child); SubtreeLayoutScope layout_scope(*child);
// We need to see if this child's height will change, since we make block // We need to see if this child's height will change, since we make block
...@@ -720,9 +697,6 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) { ...@@ -720,9 +697,6 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) {
for (LayoutBox* child = iterator.First(); for (LayoutBox* child = iterator.First();
child && space_available_this_pass && total_flex; child && space_available_this_pass && total_flex;
child = iterator.Next()) { child = iterator.Next()) {
if (child->StyleRef().Visibility() == EVisibility::kCollapse)
continue;
if (AllowedChildFlex(child, expanding)) { if (AllowedChildFlex(child, expanding)) {
LayoutUnit space_add = LayoutUnit space_add =
LayoutUnit(space_available_this_pass * LayoutUnit(space_available_this_pass *
...@@ -772,7 +746,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) { ...@@ -772,7 +746,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) {
int total_children = 0; int total_children = 0;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
++total_children; ++total_children;
} }
...@@ -784,7 +758,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) { ...@@ -784,7 +758,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) {
bool first_child = true; bool first_child = true;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
if (first_child) { if (first_child) {
...@@ -807,7 +781,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) { ...@@ -807,7 +781,7 @@ void LayoutDeprecatedFlexibleBox::LayoutHorizontalBox(bool relayout_children) {
offset += remaining_space; offset += remaining_space;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
PlaceChild(child, child->Location() + LayoutSize(offset, LayoutUnit())); PlaceChild(child, child->Location() + LayoutSize(offset, LayoutUnit()));
...@@ -874,13 +848,6 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) { ...@@ -874,13 +848,6 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) {
child->StyleRef().Height().IsPercentOrCalc())))) child->StyleRef().Height().IsPercentOrCalc()))))
layout_scope.SetChildNeedsLayout(child); layout_scope.SetChildNeedsLayout(child);
if (child->StyleRef().Visibility() == EVisibility::kCollapse) {
// visibility: collapsed children do not participate in our positioning.
// But we need to lay them down.
child->LayoutIfNeeded();
continue;
}
// Compute the child's vertical margins. // Compute the child's vertical margins.
child->ComputeAndSetBlockDirectionMargins(this); child->ComputeAndSetBlockDirectionMargins(this);
...@@ -1058,7 +1025,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) { ...@@ -1058,7 +1025,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) {
int total_children = 0; int total_children = 0;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
++total_children; ++total_children;
...@@ -1071,7 +1038,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) { ...@@ -1071,7 +1038,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) {
bool first_child = true; bool first_child = true;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
if (first_child) { if (first_child) {
...@@ -1093,7 +1060,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) { ...@@ -1093,7 +1060,7 @@ void LayoutDeprecatedFlexibleBox::LayoutVerticalBox(bool relayout_children) {
offset += remaining_space; offset += remaining_space;
for (LayoutBox* child = iterator.First(); child; for (LayoutBox* child = iterator.First(); child;
child = iterator.Next()) { child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
PlaceChild(child, child->Location() + LayoutSize(LayoutUnit(), offset)); PlaceChild(child, child->Location() + LayoutSize(LayoutUnit(), offset));
} }
...@@ -1131,7 +1098,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator, ...@@ -1131,7 +1098,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator,
int max_line_count = 0; int max_line_count = 0;
for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) { for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
child->ClearOverrideSize(); child->ClearOverrideSize();
...@@ -1167,7 +1134,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator, ...@@ -1167,7 +1134,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator,
for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) { for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) {
auto* block_child = DynamicTo<LayoutBlockFlow>(child); auto* block_child = DynamicTo<LayoutBlockFlow>(child);
if (ChildDoesNotAffectWidthOrFlexing(child) || if (child->IsOutOfFlowPositioned() ||
!child->StyleRef().Height().IsAuto() || !block_child) !child->StyleRef().Height().IsAuto() || !block_child)
continue; continue;
...@@ -1246,7 +1213,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator, ...@@ -1246,7 +1213,7 @@ void LayoutDeprecatedFlexibleBox::ApplyLineClamp(FlexBoxIterator& iterator,
void LayoutDeprecatedFlexibleBox::ClearLineClamp() { void LayoutDeprecatedFlexibleBox::ClearLineClamp() {
FlexBoxIterator iterator(this); FlexBoxIterator iterator(this);
for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) { for (LayoutBox* child = iterator.First(); child; child = iterator.Next()) {
if (ChildDoesNotAffectWidthOrFlexing(child)) if (child->IsOutOfFlowPositioned())
continue; continue;
child->ClearOverrideSize(); child->ClearOverrideSize();
...@@ -1277,8 +1244,7 @@ void LayoutDeprecatedFlexibleBox::PlaceChild(LayoutBox* child, ...@@ -1277,8 +1244,7 @@ void LayoutDeprecatedFlexibleBox::PlaceChild(LayoutBox* child,
LayoutUnit LayoutDeprecatedFlexibleBox::AllowedChildFlex(LayoutBox* child, LayoutUnit LayoutDeprecatedFlexibleBox::AllowedChildFlex(LayoutBox* child,
bool expanding) { bool expanding) {
if (ChildDoesNotAffectWidthOrFlexing(child) || if (child->IsOutOfFlowPositioned() || child->StyleRef().BoxFlex() == 0.0f)
child->StyleRef().BoxFlex() == 0.0f)
return LayoutUnit(); return LayoutUnit();
if (expanding) { if (expanding) {
......
<!DOCTYPE html>
<link rel="help" href="https://crbug.com/1015987">
<style>
#wb {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
</style>
<p>Line-clamp should be respected after removing and changing visibility.
<div id="root" style="border: solid; width: 200px;">
<div id="container">
<p id="wb">
text text text text
text text text text
text text text text
text text text text
text text text text
text text text text
text text text text
</p>
</div>
</div>
<!DOCTYPE html>
<link rel="help" href="https://crbug.com/1015987">
<link rel="match" href="webkit-box-clamp-visibility-change-ref.html">
<style>
#wb {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
</style>
<p>Line-clamp should be respected after removing and changing visibility.
<div id="root" style="border: solid; width: 200px;">
<div id="container">
<p id="wb">
text text text text
text text text text
text text text text
text text text text
text text text text
text text text text
text text text text
</p>
</div>
</div>
<script>
const container = document.getElementById('container');
const root = document.getElementById('root');
container.remove();
container.style.visibility = 'hidden';
root.appendChild(container);
document.body.offsetTop;
container.style.visibility = '';
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment