Bug 138356 - Converting time, angle and frequency units in CSS calc() function
Summary: Converting time, angle and frequency units in CSS calc() function
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-04 08:13 PST by Tibor Mészáros
Modified: 2015-01-17 09:18 PST (History)
7 users (show)

See Also:


Attachments
Patch (32.04 KB, patch)
2014-11-04 09:59 PST, Tibor Mészáros
no flags Details | Formatted Diff | Diff
Alternative patch (13.73 KB, patch)
2015-01-16 16:34 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tibor Mészáros 2014-11-04 08:13:29 PST
According to the standard, calc() should be able to handle angle, time and frequency values as well: http://www.w3.org/TR/css3-values/#calc
Comment 1 Tibor Mészáros 2014-11-04 09:59:21 PST
Created attachment 240930 [details]
Patch

This patch will merge Blink commit https://codereview.chromium.org/345903005/ (Patch by Renata Hodovan) which is based on http://trac.webkit.org/changeset/168685, http://trac.webkit.org/changeset/170544 (Patch by Martin Hodovan).
Comment 2 Tibor Mészáros 2014-11-18 03:16:07 PST
Could you possibly have a little bit of free time to review this patch?
Comment 3 Tibor Mészáros 2014-12-16 10:30:00 PST
ping?
Comment 4 Tibor Mészáros 2015-01-06 04:05:37 PST
Could you have a little free time to review this patch?
Comment 5 Chris Dumez 2015-01-06 09:54:39 PST
Comment on attachment 240930 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=240930&action=review

> LayoutTests/ChangeLog:11
> +        * css3/calc/calc-errors-expected.txt:

Most of these tests are passing without your change. This only one that doesn't is:
FAIL Tests calc() with time units. assert_equals: calc(4s + 1s) should equal to 5s expected "5s" but got "0.005s"

This does look like a bug. But otherwise, converting time, angle and frequency units in CSS calc() function is already working. Right now, it is not really clear what this patch is doing.
I would focus on fixing what actually doesn't work (e.g. the case above) instead of refactoring.

> LayoutTests/css3/calc/calc-errors-expected.txt:1
> +unclosed calc

Could you explain what changes you did to this test and why? It is not in the Changelog and not obvious to me at least.

> Source/WebCore/css/CSSCalculationValue.h:97
> +    unsigned short primitiveType() const { return m_expression->primitiveType(); }

Do we really need this? CSSPrimitiveValue::primitiveType() already handles calculated values.

> Source/WebCore/css/CSSPrimitiveValue.cpp:540
> +    switch (isCalculated() ? cssCalcValue()->primitiveType() : m_primitiveUnitType) {

Can't you call CSSPrimitiveValue::primitiveType() here?
Comment 6 Chris Dumez 2015-01-06 15:50:34 PST
Comment on attachment 240930 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=240930&action=review

> LayoutTests/css3/calc/calc-with-time-angle-and-frequency-values-expected.txt:2
> +PASS Tests calc() with time units. 

We need more example that are currently failing. As I said before, most of these seem to be passing without fix.

>> Source/WebCore/css/CSSCalculationValue.h:97
>> +    unsigned short primitiveType() const { return m_expression->primitiveType(); }
> 
> Do we really need this? CSSPrimitiveValue::primitiveType() already handles calculated values.

It seems this is needed after call, but it should probably be called from CSSPrimitiveValue::primitiveType().

>> Source/WebCore/css/CSSPrimitiveValue.cpp:540
>> +    switch (isCalculated() ? cssCalcValue()->primitiveType() : m_primitiveUnitType) {
> 
> Can't you call CSSPrimitiveValue::primitiveType() here?

Hmm, ok, so CSSPrimitiveValue::primitiveType()'s handling of calculated values is actually not great. It does not really check the unit inside the calculated expression. Instead, it relies on the category and returns CSS_MS if category is CalcTime. We should fix CSSPrimitiveValue::primitiveType().

> Source/WebCore/css/CSSPrimitiveValue.h:-262
> -        if (timeUnit == Seconds && m_primitiveUnitType == CSS_S)

We could potentially keep the same implementation if we call primitiveType() instead of accessing m_primitiveUnitType directly.
Comment 7 Chris Dumez 2015-01-08 13:25:54 PST
Comment on attachment 240930 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=240930&action=review

> LayoutTests/ChangeLog:3
> +        Converting time, angle and frequency units in CSS calc() function

What part of the change fixes frequency unit?
Comment 8 Chris Dumez 2015-01-16 16:34:51 PST
Created attachment 244818 [details]
Alternative patch

As there was no activity for a while, I am uploading another patch with more failing test cases and that updates CSSPrimitiveValue::primitiveType() instead of updating call sites to use CSSCalcValue::primitiveType() directly (more robust this way).
Comment 9 WebKit Commit Bot 2015-01-17 09:18:22 PST
Comment on attachment 244818 [details]
Alternative patch

Clearing flags on attachment: 244818

Committed r178627: <http://trac.webkit.org/changeset/178627>
Comment 10 WebKit Commit Bot 2015-01-17 09:18:29 PST
All reviewed patches have been landed.  Closing bug.