Bug 130010 - [CSS Grid Layout] getComputedStyle() must return the specified value for positioning properties
Summary: [CSS Grid Layout] getComputedStyle() must return the specified value for posi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sergio Villar Senin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-10 02:56 PDT by Sergio Villar Senin
Modified: 2014-03-26 09:45 PDT (History)
13 users (show)

See Also:


Attachments
Patch (94.97 KB, patch)
2014-03-25 05:35 PDT, Sergio Villar Senin
no flags Details | Formatted Diff | Diff
Patch (99.12 KB, patch)
2014-03-26 07:19 PDT, Sergio Villar Senin
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergio Villar Senin 2014-03-10 02:56:02 PDT
A recent discussion in www-style mailing list

http://lists.w3.org/Archives/Public/www-style/2014Mar/0162.html

made clear that we basically cannot adjust the style of grid items because we'd be losing the specified value of the property, which is the one we should return in getComputedStyle(). Instead, we should handle that as any other resolution code in the RenderGrid.
Comment 1 Sergio Villar Senin 2014-03-25 05:35:52 PDT
Created attachment 227742 [details]
Patch
Comment 2 Darin Adler 2014-03-25 09:21:58 PDT
Comment on attachment 227742 [details]
Patch

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

> Source/WebCore/rendering/RenderGrid.cpp:871
> +    size_t namedGridLineFirstDefinition = GridPosition::adjustGridPositionForSide(namedLinesMap.get(gridLineName)[0], side);

Doing a get() here will result in copying what we get from the map. We should find a way to write this where we extract the item without copying it out, using find rather than get. The code will be a bit longer, but likely more efficient.

> Source/WebCore/rendering/RenderGrid.cpp:907
> +    if (gridAreaMap.contains(gridAreaName)) {

What guarantees that gridAreaName is not an empty string?

Double hash table lookups here are unfortunate. Here we are calling contains and the function inside will be calling get.

> Source/WebCore/rendering/RenderGrid.cpp:916
> +        if (namedLinesMap.contains(gridLineName) && gridLineDefinedBeforeGridArea(gridLineName, gridAreaName, gridAreaMap, namedLinesMap, side)) {

What guarantees that gridLineName is not an empty string?

Double hash table lookups here are unfortunate. Here we are calling contains and the function inside will be calling get.Double hash table lookups here are unfortunate. Here we are calling contains and the function inside will be calling get.

> Source/WebCore/rendering/style/GridPosition.h:80
> +    static bool isColumnSide(GridPositionSide side)
> +    {
> +        return side == ColumnStartSide || side == ColumnEndSide;
> +    }

I don’t see any reason for this to be a member function. It should just be a free namespace-level function since GridPositionSide is a namespace-level enum.

> LayoutTests/fast/css-grid-layout/grid-item-area-get-set.html:109
> +    testGridAreaCSSParsing("fourValueMixedGridArea", "firstArea", "span 1", "nonExistent", "1 foobar");

Strange to capitalize the letter “e” here. The word nonexistent doesn’t have a capital letter in it.
Comment 3 Sergio Villar Senin 2014-03-25 09:33:40 PDT
Comment on attachment 227742 [details]
Patch

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

Thanks for the review.

>> Source/WebCore/rendering/RenderGrid.cpp:871
>> +    size_t namedGridLineFirstDefinition = GridPosition::adjustGridPositionForSide(namedLinesMap.get(gridLineName)[0], side);
> 
> Doing a get() here will result in copying what we get from the map. We should find a way to write this where we extract the item without copying it out, using find rather than get. The code will be a bit longer, but likely more efficient.

Good point, will change it.

>> Source/WebCore/rendering/RenderGrid.cpp:907
>> +    if (gridAreaMap.contains(gridAreaName)) {
> 
> What guarantees that gridAreaName is not an empty string?
> 
> Double hash table lookups here are unfortunate. Here we are calling contains and the function inside will be calling get.

This is an interesting comment, I hadn't thought about the possibility of authors using just -start or -end. Will add checks for that, in those cases we don't need to check for the existence of the named area, and we could consider that it's just the name of a grid line.

Regarding the double lookups will replace them with finds.

>> Source/WebCore/rendering/style/GridPosition.h:80
>> +    }
> 
> I don’t see any reason for this to be a member function. It should just be a free namespace-level function since GridPositionSide is a namespace-level enum.

Fair enough.

>> LayoutTests/fast/css-grid-layout/grid-item-area-get-set.html:109
>> +    testGridAreaCSSParsing("fourValueMixedGridArea", "firstArea", "span 1", "nonExistent", "1 foobar");
> 
> Strange to capitalize the letter “e” here. The word nonexistent doesn’t have a capital letter in it.

Well I am not really capitalizing anything, it's just the name of a grid line already present in the test, but I can change it as well.
Comment 4 Sergio Villar Senin 2014-03-26 07:19:25 PDT
Created attachment 227848 [details]
Patch
Comment 5 Darin Adler 2014-03-26 07:57:02 PDT
Comment on attachment 227848 [details]
Patch

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

> Source/WebCore/rendering/RenderGrid.cpp:890
> +    const auto& linesIterator = namedLinesMap.find(lineName);

Should just be auto, rather than const auto&.

> Source/WebCore/rendering/RenderGrid.cpp:910
> +    const auto& areaIterator = gridAreaMap.find(namedGridAreaOrGridLine);

Should just be auto rather than const auto&.

> Source/WebCore/rendering/RenderGrid.cpp:921
> +        String gridAreaName = namedGridAreaOrGridLine.substring(0, namedGridAreaOrGridLine.length() - suffixLength);

I know I asked this last time, but what guarantees this is not an empty string? If namedGridAreaOrGridLine is "-end" then I think this code will call find on an empty string, which does not work.

> Source/WebCore/rendering/RenderGrid.cpp:923
> +        const auto& areaIterator = gridAreaMap.find(gridAreaName);

Should just be auto rather than const auto&.
Comment 6 Sergio Villar Senin 2014-03-26 08:20:57 PDT
(In reply to comment #5)
> (From update of attachment 227848 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=227848&action=review

> > Source/WebCore/rendering/RenderGrid.cpp:921
> > +        String gridAreaName = namedGridAreaOrGridLine.substring(0, namedGridAreaOrGridLine.length() - suffixLength);
> 
> I know I asked this last time, but what guarantees this is not an empty string? If namedGridAreaOrGridLine is "-end" then I think this code will call find on an empty string, which does not work.

Oh true, I was assuming that HashTraits<String> was using isEmpty() for isEmptyValue() implementation but I've just checked that it uses isNull() so you're totally right indeed.

I'll add a check for that case before landing.
Comment 7 Darin Adler 2014-03-26 08:47:23 PDT
(In reply to comment #6)
> I was assuming that HashTraits<String> was using isEmpty() for isEmptyValue() implementation but I've just checked that it uses isNull() so you're totally right indeed.

Actually, I think you were right.

Given that HashTraits for strings use null as the special value, that means it’s OK to call find with a non-null empty value. As long as we are guaranteed it’s empty and non-null.

The empty value is the one that is *unsafe* to use with our hash-table-based collections. Along with the deleted value. Other values, like non-null empty strings, are safe to use.

I think the way to clarify this is to make sure we have a test case that covers that code path.
Comment 8 Sergio Villar Senin 2014-03-26 08:51:59 PDT
(In reply to comment #7)
> (In reply to comment #6)
> > I was assuming that HashTraits<String> was using isEmpty() for isEmptyValue() implementation but I've just checked that it uses isNull() so you're totally right indeed.
> 
> Actually, I think you were right.
> 
> Given that HashTraits for strings use null as the special value, that means it’s OK to call find with a non-null empty value. As long as we are guaranteed it’s empty and non-null.
> 
> The empty value is the one that is *unsafe* to use with our hash-table-based collections. Along with the deleted value. Other values, like non-null empty strings, are safe to use.
> 
> I think the way to clarify this is to make sure we have a test case that covers that code path.

Let's add another test for that then.
Comment 9 Sergio Villar Senin 2014-03-26 09:45:56 PDT
Committed r166299: <http://trac.webkit.org/changeset/166299>