Commit 0ea3de03 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

Add AutoClearOverrideLogical{Width,Height}

This is a bit safer than the manual calling of clear and set.

This also adds the test from https://crrev.com/c/1808498 to trunk/wpt.

Bug: 1002899
Change-Id: I2a4963fc08f1b66a0d9cdaf63f1d263715f97178
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1810238
Auto-Submit: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarDavid Grogan <dgrogan@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699563}
parent 5947b309
......@@ -65,6 +65,48 @@ enum class TransformedWritingMode {
typedef Vector<FlexItem, 8> FlexItemVector;
class AutoClearOverrideLogicalHeight {
public:
explicit AutoClearOverrideLogicalHeight(LayoutBox* box)
: box_(box), old_override_height_(-1) {
if (box_ && box_->HasOverrideLogicalHeight()) {
old_override_height_ = box_->OverrideLogicalHeight();
box_->ClearOverrideLogicalHeight();
}
}
~AutoClearOverrideLogicalHeight() {
if (old_override_height_ != LayoutUnit(-1)) {
DCHECK(box_);
box_->SetOverrideLogicalHeight(old_override_height_);
}
}
private:
LayoutBox* box_;
LayoutUnit old_override_height_;
};
class AutoClearOverrideLogicalWidth {
public:
explicit AutoClearOverrideLogicalWidth(LayoutBox* box)
: box_(box), old_override_width_(-1) {
if (box_ && box_->HasOverrideLogicalWidth()) {
old_override_width_ = box_->OverrideLogicalWidth();
box_->ClearOverrideLogicalWidth();
}
}
~AutoClearOverrideLogicalWidth() {
if (old_override_width_ != LayoutUnit(-1)) {
DCHECK(box_);
box_->SetOverrideLogicalWidth(old_override_width_);
}
}
private:
LayoutBox* box_;
LayoutUnit old_override_width_;
};
class FlexItem {
DISALLOW_NEW();
......
......@@ -498,11 +498,7 @@ LayoutUnit LayoutFlexibleBox::ChildUnstretchedLogicalHeight(
// This should only be called if the logical height is the cross size
DCHECK(MainAxisIsInlineAxis(child));
if (NeedToStretchChildLogicalHeight(child)) {
LayoutUnit old_override_height = LayoutUnit(-1);
if (child.HasOverrideLogicalHeight()) {
old_override_height = child.OverrideLogicalHeight();
const_cast<LayoutBox&>(child).ClearOverrideLogicalHeight();
}
AutoClearOverrideLogicalHeight clear(const_cast<LayoutBox*>(&child));
LayoutUnit child_intrinsic_content_logical_height;
if (child.ShouldApplySizeContainment()) {
......@@ -522,10 +518,6 @@ LayoutUnit LayoutFlexibleBox::ChildUnstretchedLogicalHeight(
LogicalExtentComputedValues values;
child.ComputeLogicalHeight(child_intrinsic_logical_height, LayoutUnit(),
values);
if (old_override_height != LayoutUnit(-1)) {
const_cast<LayoutBox&>(child).SetOverrideLogicalHeight(
old_override_height);
}
return values.extent_;
}
return child.LogicalHeight();
......@@ -542,17 +534,10 @@ LayoutUnit LayoutFlexibleBox::ChildUnstretchedLogicalWidth(
// However, if our cross axis length is definite we don't need to recompute
// and can just return the already-set logical width.
if (!CrossAxisLengthIsDefinite(child, child.StyleRef().LogicalWidth())) {
LayoutUnit old_override_width = LayoutUnit(-1);
if (child.HasOverrideLogicalWidth()) {
old_override_width = child.OverrideLogicalWidth();
const_cast<LayoutBox&>(child).ClearOverrideLogicalWidth();
}
AutoClearOverrideLogicalWidth clear(const_cast<LayoutBox*>(&child));
LogicalExtentComputedValues values;
child.ComputeLogicalWidth(values);
if (old_override_width != LayoutUnit(-1))
const_cast<LayoutBox&>(child).SetOverrideLogicalWidth(old_override_width);
return values.extent_;
}
......
<!DOCTYPE html>
<title>CSS Flexbox: min-height: auto with flex items containing percentage-sized children</title>
<link rel="author" title="Google LLC" href="https://www.google.com/" />
<link rel="help" href="https://drafts.csswg.org/css-flexbox/#min-size-auto" />
<link rel="match" href="../reference/ref-filled-green-100px-square.xht" />
<link rel="issue" href="https://bugs.chromium.org/p/chromium/issues/detail?id=1003556" />
<style>
.flex {
display: flex;
}
.column {
flex-direction: column;
}
.bigger-than-parent {
height: 100%;
min-height: 100px;
background-color: red;
}
#reference-overlapped-green {
position: absolute;
background-color: green;
width: 100px;
height: 100px;
z-index: 1;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div id="reference-overlapped-green"></div>
<div id="outer" style="width: 100px; height: 300px;" class="flex">
<div style="height: 100px; width: 100px; background: blue;" class="flex column">
<div style="flex: 0 1 100%"></div>
<div style="flex: 1 0 30px;">
<div class="bigger-than-parent">
</div>
</div>
</div>
</div>
<script>
onload = function() {
var outer = document.getElementById("outer");
outer.offsetWidth;
outer.style.height = "200px";
};
</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