Commit 63c8fae6 authored by Joonghun Park's avatar Joonghun Park Committed by Commit Bot

Make calc() function can be used in any place that only accepts integer.

https://www.w3.org/TR/css-values-4/#calc-type-checking spec
says that calc() function that resolve to <number> can be used
in any place that only accepts <integer>.
This change makes calc() function's behavior to comply with the spec.

Bug: 931216
Change-Id: Iac9ad21d664bb60538d40ab42cbb8153de6db89f
Reviewed-on: https://chromium-review.googlesource.com/c/1478852Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634955}
parent 75099b9c
...@@ -440,6 +440,7 @@ Jongheon Kim <sapzape@gmail.com> ...@@ -440,6 +440,7 @@ Jongheon Kim <sapzape@gmail.com>
JongKwon Lee <jongkwon.lee@navercorp.com> JongKwon Lee <jongkwon.lee@navercorp.com>
Jongsoo Lee <leejongsoo@gmail.com> Jongsoo Lee <leejongsoo@gmail.com>
Joone Hur <joone.hur@intel.com> Joone Hur <joone.hur@intel.com>
Joonghun Park <pjh0718@gmail.com>
Jorge Villatoro <jorge@tomatocannon.com> Jorge Villatoro <jorge@tomatocannon.com>
Joseph Gentle <josephg@gmail.com> Joseph Gentle <josephg@gmail.com>
Joseph Lolak <joseph.lolak@samsung.com> Joseph Lolak <joseph.lolak@samsung.com>
......
...@@ -200,6 +200,17 @@ class CalcParser { ...@@ -200,6 +200,17 @@ class CalcParser {
source_range_ = range_; source_range_ = range_;
return CSSPrimitiveValue::Create(calc_value_.Release()); return CSSPrimitiveValue::Create(calc_value_.Release());
} }
CSSPrimitiveValue* ConsumeRoundedInt() {
if (!calc_value_)
return nullptr;
source_range_ = range_;
CSSPrimitiveValue::UnitType unit_type =
CSSPrimitiveValue::UnitType::kInteger;
double rounded_value = floor(calc_value_->DoubleValue() + 0.5);
return CSSPrimitiveValue::Create(rounded_value, unit_type);
}
CSSPrimitiveValue* ConsumeNumber() { CSSPrimitiveValue* ConsumeNumber() {
if (!calc_value_) if (!calc_value_)
return nullptr; return nullptr;
...@@ -237,12 +248,18 @@ CSSPrimitiveValue* ConsumeInteger(CSSParserTokenRange& range, ...@@ -237,12 +248,18 @@ CSSPrimitiveValue* ConsumeInteger(CSSParserTokenRange& range,
} }
CalcParser calc_parser(range); CalcParser calc_parser(range);
if (const CSSCalcValue* calculation = calc_parser.Value()) { if (const CSSCalcValue* calculation = calc_parser.Value()) {
if (calculation->Category() != kCalcNumber || !calculation->IsInt()) if (!RuntimeEnabledFeatures::CSSCalcAsIntEnabled() && !calculation->IsInt())
return nullptr;
if (calculation->Category() != kCalcNumber)
return nullptr; return nullptr;
double value = calculation->DoubleValue(); double value = calculation->DoubleValue();
if (value < minimum_value) if (value < minimum_value)
return nullptr; return nullptr;
return calc_parser.ConsumeNumber(); if (!RuntimeEnabledFeatures::CSSCalcAsIntEnabled())
return calc_parser.ConsumeNumber();
if (calculation->IsInt())
return calc_parser.ConsumeNumber();
return calc_parser.ConsumeRoundedInt();
} }
return nullptr; return nullptr;
} }
......
...@@ -275,6 +275,10 @@ ...@@ -275,6 +275,10 @@
name: "CSSBackdropFilter", name: "CSSBackdropFilter",
status: "experimental", status: "experimental",
}, },
{
name: "CSSCalcAsInt",
status: "test",
},
{ {
name: "CSSFocusVisible", name: "CSSFocusVisible",
status: "experimental", status: "experimental",
......
...@@ -3085,7 +3085,6 @@ crbug.com/626703 crbug.com/930297 [ Linux ] external/wpt/html/infrastructure/url ...@@ -3085,7 +3085,6 @@ crbug.com/626703 crbug.com/930297 [ Linux ] external/wpt/html/infrastructure/url
crbug.com/626703 [ Win10 ] external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252.html [ Failure Timeout ] crbug.com/626703 [ Win10 ] external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252.html [ Failure Timeout ]
crbug.com/626703 [ Win7 ] external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252.html [ Failure Timeout ] crbug.com/626703 [ Win7 ] external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/windows-1252.html [ Failure Timeout ]
crbug.com/626703 external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/navigation.sub.html?encoding=windows-1252 [ Timeout ] crbug.com/626703 external/wpt/html/infrastructure/urls/resolving-urls/query-encoding/navigation.sub.html?encoding=windows-1252 [ Timeout ]
crbug.com/626703 external/wpt/css/css-values/calc-positive-fraction-001.html [ Failure ]
crbug.com/626703 external/wpt/css/css-values/ch-unit-011.html [ Failure ] crbug.com/626703 external/wpt/css/css-values/ch-unit-011.html [ Failure ]
crbug.com/626703 external/wpt/css/css-values/attr-invalid-type-008.html [ Failure ] crbug.com/626703 external/wpt/css/css-values/attr-invalid-type-008.html [ Failure ]
crbug.com/626703 external/wpt/css/css-grid/abspos/descendant-static-position-003.html [ Failure ] crbug.com/626703 external/wpt/css/css-grid/abspos/descendant-static-position-003.html [ Failure ]
......
PASS getComputedValue(".int", "tabSize") is "8" PASS getComputedValue(".int", "tabSize") is "8"
PASS getComputedValue(".int-non-neg-invalid", "tabSize") is "12345" PASS getComputedValue(".int-non-neg-invalid", "tabSize") is "12345"
PASS Number(getComputedValue(".float", "opacity")) is within 0.0001 of 0.5 PASS Number(getComputedValue(".float", "opacity")) is within 0.0001 of 0.5
PASS getComputedValue(".float-invalid", "tabSize") is "12345" PASS getComputedValue(".float-to-rounded-int", "tabSize") is "1"
PASS Number(getComputedValue(".px-invalid", "opacity")) is within 0.0001 of 0.9 PASS Number(getComputedValue(".px-invalid", "opacity")) is within 0.0001 of 0.9
PASS getComputedValue(".num-length-invalid", "tabSize") is "12345" PASS getComputedValue(".num-length-invalid", "tabSize") is "12345"
PASS getComputedValue(".px-valid", "tabSize") is "10px" PASS getComputedValue(".px-valid", "tabSize") is "10px"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
.float { .float {
opacity: calc(2 / 4); opacity: calc(2 / 4);
} }
.float-invalid { .float-to-rounded-int {
tab-size: 12345; tab-size: 12345;
tab-size: calc(2 / 4); tab-size: calc(2 / 4);
} }
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<div class="default int"></div> <div class="default int"></div>
<div class="default int-non-neg-invalid"></div> <div class="default int-non-neg-invalid"></div>
<div class="default float"></div> <div class="default float"></div>
<div class="default float-invalid"></div> <div class="default float-to-rounded-int"></div>
<div class="default px-invalid"></div> <div class="default px-invalid"></div>
<div class="default num-length-invalid"></div> <div class="default num-length-invalid"></div>
<div class="default px-valid"></div> <div class="default px-valid"></div>
...@@ -49,7 +49,7 @@ function getComputedValue(selector, property) { ...@@ -49,7 +49,7 @@ function getComputedValue(selector, property) {
shouldBe('getComputedValue(".int", "tabSize")', '"8"'); shouldBe('getComputedValue(".int", "tabSize")', '"8"');
shouldBe('getComputedValue(".int-non-neg-invalid", "tabSize")', '"12345"'); shouldBe('getComputedValue(".int-non-neg-invalid", "tabSize")', '"12345"');
shouldBeCloseTo('Number(getComputedValue(".float", "opacity"))', 0.5, .0001); shouldBeCloseTo('Number(getComputedValue(".float", "opacity"))', 0.5, .0001);
shouldBe('getComputedValue(".float-invalid", "tabSize")', '"12345"'); shouldBe('getComputedValue(".float-to-rounded-int", "tabSize")', '"1"');
shouldBeCloseTo('Number(getComputedValue(".px-invalid", "opacity"))', 0.9, .0001); shouldBeCloseTo('Number(getComputedValue(".px-invalid", "opacity"))', 0.9, .0001);
shouldBe('getComputedValue(".num-length-invalid", "tabSize")', '"12345"'); shouldBe('getComputedValue(".num-length-invalid", "tabSize")', '"12345"');
shouldBe('getComputedValue(".px-valid", "tabSize")', '"10px"'); shouldBe('getComputedValue(".px-valid", "tabSize")', '"10px"');
......
...@@ -18,7 +18,7 @@ test(function() { ...@@ -18,7 +18,7 @@ test(function() {
assertParsedValue('transition-timing-function', 'cubic-bezier(calc(1 / 2), calc(1 - 1), calc(2 - 1), calc(2 * 3))', 'cubic-bezier(0.5, 0, 1, 6)'); assertParsedValue('transition-timing-function', 'cubic-bezier(calc(1 / 2), calc(1 - 1), calc(2 - 1), calc(2 * 3))', 'cubic-bezier(0.5, 0, 1, 6)');
assertParsedValue('transition-timing-function', 'steps(calc(1 + 2), start)', 'steps(3, start)'); assertParsedValue('transition-timing-function', 'steps(calc(1 + 2), start)', 'steps(3, start)');
assertParsedValue('grid-row-start', 'calc(1 + 2) test', '3 test'); assertParsedValue('grid-row-start', 'calc(1 + 2) test', '3 test');
assertParsedValue('grid-row-start', 'calc(1 / 2) test', ''); assertParsedValue('grid-row-start', 'calc(1 / 2) test', '1 test');
assertParsedValue('font-weight', 'calc(100 + 200)', '300'); assertParsedValue('font-weight', 'calc(100 + 200)', '300');
assertParsedValue('flex', 'calc(1 + 2) calc(3 + 4)', '3 7 0%'); assertParsedValue('flex', 'calc(1 + 2) calc(3 + 4)', '3 7 0%');
assertParsedValue('-webkit-filter', 'saturate(calc(4 / 2))', 'saturate(2)'); assertParsedValue('-webkit-filter', 'saturate(calc(4 / 2))', 'saturate(2)');
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
test_invalid_value("z-index", "none"); test_invalid_value("z-index", "none");
test_invalid_value("z-index", "10px"); test_invalid_value("z-index", "10px");
test_invalid_value("z-index", "0.5"); test_invalid_value("z-index", "0.5");
test_invalid_value("z-index", "calc(0.5)");
test_invalid_value("z-index", "auto 123"); test_invalid_value("z-index", "auto 123");
</script> </script>
</body> </body>
......
...@@ -2,7 +2,7 @@ This is a testharness.js-based test. ...@@ -2,7 +2,7 @@ This is a testharness.js-based test.
PASS testing tab-size: calc(2 * 3) PASS testing tab-size: calc(2 * 3)
FAIL testing tab-size: calc(2 * -4) assert_equals: calc(2 * -4) should compute to 0 expected "0" but got "12345" FAIL testing tab-size: calc(2 * -4) assert_equals: calc(2 * -4) should compute to 0 expected "0" but got "12345"
PASS testing opacity: calc(2 / 4) PASS testing opacity: calc(2 / 4)
FAIL testing tab-size: calc(2 / 4) assert_equals: calc(2 / 4) should compute to 0.5 expected "0.5" but got "12345" PASS testing tab-size: calc(2 / 4)
PASS testing opacity: calc(2 / 4) * 1px PASS testing opacity: calc(2 / 4) * 1px
PASS testing tab-size: calc(1 + 1px) PASS testing tab-size: calc(1 + 1px)
PASS testing tab-size: calc(1 + 100%) PASS testing tab-size: calc(1 + 100%)
......
...@@ -71,7 +71,7 @@ https://chromium.googlesource.com/chromium/src/+/c825d655f6aaf73484f9d56e9012793 ...@@ -71,7 +71,7 @@ https://chromium.googlesource.com/chromium/src/+/c825d655f6aaf73484f9d56e9012793
verifyComputedStyle("opacity", "initial", "calc(2 / 4)", "0.5", "testing opacity: calc(2 / 4)"); verifyComputedStyle("opacity", "initial", "calc(2 / 4)", "0.5", "testing opacity: calc(2 / 4)");
verifyComputedStyle("tab-size", "12345", "calc(2 / 4)", "0.5", "testing tab-size: calc(2 / 4)"); verifyComputedStyle("tab-size", "12345", "calc(2 / 4)", "1", "testing tab-size: calc(2 / 4)");
/* /*
'tab-size' accepts <number> values. 'tab-size' accepts <number> values.
*/ */
......
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