Commit f3d7ed74 authored by Fredrik Söderquist's avatar Fredrik Söderquist Committed by Commit Bot

Simplify some Length comparisons with 'auto'

Using Length::IsAuto() is more efficient (and generates significantly
less code) than constructing a new Length and comparing with that.

Also replace some open-coded "is auto" checks with said method, and
simplify the surrounding code a bit.

Change-Id: I974a28a0eef969b56557428eb019f7cf1dac18c1
Reviewed-on: https://chromium-review.googlesource.com/806170Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#521456}
parent 5ba7cac1
...@@ -710,10 +710,10 @@ static CSSValue* ValueForLineHeight(const ComputedStyle& style) { ...@@ -710,10 +710,10 @@ static CSSValue* ValueForLineHeight(const ComputedStyle& style) {
static CSSValue* ValueForPosition(const LengthPoint& position, static CSSValue* ValueForPosition(const LengthPoint& position,
const ComputedStyle& style) { const ComputedStyle& style) {
DCHECK((position.X() == kAuto) == (position.Y() == kAuto)); DCHECK_EQ(position.X().IsAuto(), position.Y().IsAuto());
if (position.X() == kAuto) { if (position.X().IsAuto())
return CSSIdentifierValue::Create(CSSValueAuto); return CSSIdentifierValue::Create(CSSValueAuto);
}
CSSValueList* list = CSSValueList::CreateSpaceSeparated(); CSSValueList* list = CSSValueList::CreateSpaceSeparated();
list->Append(*ZoomAdjustedPixelValueForLength(position.X(), style)); list->Append(*ZoomAdjustedPixelValueForLength(position.X(), style));
list->Append(*ZoomAdjustedPixelValueForLength(position.Y(), style)); list->Append(*ZoomAdjustedPixelValueForLength(position.Y(), style));
......
...@@ -1500,11 +1500,12 @@ LayoutObject* InlineMinMaxIterator::Next() { ...@@ -1500,11 +1500,12 @@ LayoutObject* InlineMinMaxIterator::Next() {
return current; return current;
} }
static LayoutUnit GetBPMWidth(LayoutUnit child_value, Length css_unit) { static LayoutUnit GetBPMWidth(LayoutUnit child_value, const Length& css_unit) {
if (css_unit.GetType() != kAuto) if (css_unit.IsFixed())
return (css_unit.IsFixed() ? static_cast<LayoutUnit>(css_unit.Value()) return LayoutUnit(css_unit.Value());
: child_value); if (css_unit.IsAuto())
return LayoutUnit(); return LayoutUnit();
return child_value;
} }
static LayoutUnit GetBorderPaddingMargin(const LayoutBoxModelObject& child, static LayoutUnit GetBorderPaddingMargin(const LayoutBoxModelObject& child,
......
...@@ -1356,17 +1356,18 @@ LayoutUnit LayoutDeprecatedFlexibleBox::AllowedChildFlex(LayoutBox* child, ...@@ -1356,17 +1356,18 @@ LayoutUnit LayoutDeprecatedFlexibleBox::AllowedChildFlex(LayoutBox* child,
if (IsHorizontal()) { if (IsHorizontal()) {
LayoutUnit min_width = child->MinPreferredLogicalWidth(); LayoutUnit min_width = child->MinPreferredLogicalWidth();
LayoutUnit width = ContentWidthForChild(child); LayoutUnit width = ContentWidthForChild(child);
if (child->Style()->MinWidth().IsFixed()) const Length& min_width_length = child->Style()->MinWidth();
min_width = LayoutUnit(child->Style()->MinWidth().Value()); if (min_width_length.IsFixed())
else if (child->Style()->MinWidth().GetType() == kAuto) min_width = LayoutUnit(min_width_length.Value());
else if (min_width_length.IsAuto())
min_width = LayoutUnit(); min_width = LayoutUnit();
LayoutUnit allowed_shrinkage = (min_width - width).ClampPositiveToZero(); LayoutUnit allowed_shrinkage = (min_width - width).ClampPositiveToZero();
return allowed_shrinkage; return allowed_shrinkage;
} }
Length min_height = child->Style()->MinHeight(); const Length& min_height_length = child->Style()->MinHeight();
if (min_height.IsFixed() || min_height.IsAuto()) { if (min_height_length.IsFixed() || min_height_length.IsAuto()) {
LayoutUnit min_height(child->Style()->MinHeight().Value()); LayoutUnit min_height(min_height_length.Value());
LayoutUnit height = ContentHeightForChild(child); LayoutUnit height = ContentHeightForChild(child);
LayoutUnit allowed_shrinkage = (min_height - height).ClampPositiveToZero(); LayoutUnit allowed_shrinkage = (min_height - height).ClampPositiveToZero();
return allowed_shrinkage; return allowed_shrinkage;
......
...@@ -167,7 +167,7 @@ int TableLayoutAlgorithmFixed::CalcWidthArray() { ...@@ -167,7 +167,7 @@ int TableLayoutAlgorithmFixed::CalcWidthArray() {
while (used_span < span && current_column < n_eff_cols) { while (used_span < span && current_column < n_eff_cols) {
float e_span = table_->SpanOfEffectiveColumn(current_column); float e_span = table_->SpanOfEffectiveColumn(current_column);
// Only set if no col element has already set it. // Only set if no col element has already set it.
if (width_[current_column].IsAuto() && logical_width.GetType() != kAuto) { if (width_[current_column].IsAuto() && !logical_width.IsAuto()) {
width_[current_column] = logical_width; width_[current_column] = logical_width;
width_[current_column] *= e_span / span; width_[current_column] *= e_span / span;
used_width += fixed_border_box_logical_width * e_span / span; used_width += fixed_border_box_logical_width * e_span / span;
......
...@@ -1011,9 +1011,9 @@ void ComputedStyle::ApplyMotionPathTransform( ...@@ -1011,9 +1011,9 @@ void ComputedStyle::ApplyMotionPathTransform(
float origin_shift_x = 0; float origin_shift_x = 0;
float origin_shift_y = 0; float origin_shift_y = 0;
// If offset-Position and offset-anchor properties are not yet enabled, // If the offset-position and offset-anchor properties are not yet enabled,
// they will have the default value, auto. // they will have the default value, auto.
if (position.X() != Length(kAuto) || anchor.X() != Length(kAuto)) { if (!position.X().IsAuto() || !anchor.X().IsAuto()) {
// Shift the origin from transform-origin to offset-anchor. // Shift the origin from transform-origin to offset-anchor.
origin_shift_x = origin_shift_x =
FloatValueForLength(anchor.X(), bounding_box.Width()) - FloatValueForLength(anchor.X(), bounding_box.Width()) -
...@@ -1027,7 +1027,7 @@ void ComputedStyle::ApplyMotionPathTransform( ...@@ -1027,7 +1027,7 @@ void ComputedStyle::ApplyMotionPathTransform(
point.Y() - origin_y + origin_shift_y); point.Y() - origin_y + origin_shift_y);
transform.Rotate(angle + rotate.angle); transform.Rotate(angle + rotate.angle);
if (position.X() != Length(kAuto) || anchor.X() != Length(kAuto)) if (!position.X().IsAuto() || !anchor.X().IsAuto())
// Shift the origin back to transform-origin. // Shift the origin back to transform-origin.
transform.Translate(-origin_shift_x, -origin_shift_y); transform.Translate(-origin_shift_x, -origin_shift_y);
} }
......
...@@ -1705,7 +1705,7 @@ class ComputedStyle : public ComputedStyleBase, ...@@ -1705,7 +1705,7 @@ class ComputedStyle : public ComputedStyleBase,
// Motion utility functions. // Motion utility functions.
bool HasOffset() const { bool HasOffset() const {
return (OffsetPosition().X() != Length(kAuto)) || OffsetPath(); return !OffsetPosition().X().IsAuto() || OffsetPath();
} }
// Direction utility functions. // Direction utility functions.
......
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