Bug 111121 - getComputedStyle not working with more than one background image.
Summary: getComputedStyle not working with more than one background image.
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: InRadar
Depends on:
Blocks:
 
Reported: 2013-02-28 15:31 PST by Uday Kiran
Modified: 2021-11-28 14:25 PST (History)
10 users (show)

See Also:


Attachments
testcase (289 bytes, text/html)
2013-02-28 15:32 PST, Uday Kiran
no flags Details
Patch (13.68 KB, patch)
2021-11-25 00:20 PST, Matt Woodrow
no flags Details | Formatted Diff | Diff
Patch (14.00 KB, patch)
2021-11-25 11:21 PST, Matt Woodrow
no flags Details | Formatted Diff | Diff
Patch (13.87 KB, patch)
2021-11-25 11:40 PST, Matt Woodrow
no flags Details | Formatted Diff | Diff
Patch (16.01 KB, patch)
2021-11-25 16:14 PST, Matt Woodrow
no flags Details | Formatted Diff | Diff
Patch (15.99 KB, patch)
2021-11-25 17:56 PST, Matt Woodrow
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Uday Kiran 2013-02-28 15:31:18 PST
getComputedStyle of background: url("dummy://test/1.png"), url("dummy://test/2.png"); is incorrect.
Tested on Chrome 24.
Comment 1 Uday Kiran 2013-02-28 15:32:27 PST
Created attachment 190824 [details]
testcase
Comment 2 Emil A Eklund 2013-03-19 04:57:25 PDT
What do you expect the computed style to return and what are you seeing instead?
Comment 3 Uday Kiran 2013-03-20 22:42:05 PDT
Actual Result:
rgba(0, 0, 0, 0) url(dummy://test/1.png), url(dummy://test/2.png) repeat, repeat scroll, scroll 0% 0%, 0% 0% / auto, auto padding-box, padding-box border-box, border-box

I think expected result should be
rgba(0, 0, 0, 0) url(dummy://test/1.png) repeat scroll 0% 0% / auto padding-box border-box, url(dummy://test/2.png) repeat scroll 0% 0% / auto padding-box border-box
Comment 4 Matt Woodrow 2021-11-25 00:20:09 PST
Created attachment 445122 [details]
Patch
Comment 5 Matt Woodrow 2021-11-25 11:21:15 PST
Created attachment 445148 [details]
Patch
Comment 6 Matt Woodrow 2021-11-25 11:40:41 PST
Created attachment 445149 [details]
Patch
Comment 7 Matt Woodrow 2021-11-25 16:14:09 PST
Created attachment 445160 [details]
Patch
Comment 8 Cameron McCormack (:heycam) 2021-11-25 17:02:39 PST
Comment on attachment 445160 [details]
Patch

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

Patch is good but I'd like to see the next version. Some comments and questions below.

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4451
> +size_t ComputedStyleExtractor::getLayerCount(CSSPropertyID property)
> +{

You have the assertion about `property` in getBackgroundPropertyShorthandValue, but I'd repeat it in here too.

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4452
> +    auto* styledElement = this->styledElement();

Can drop the "this->". (Not sure why some other functions in this file do that.)

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4469
> +Ref<CSSValueList> ComputedStyleExtractor::getBackgroundPropertyShorthandValue(CSSPropertyID property, const StylePropertyShorthand& propertiesBeforeSlashSeperator, const StylePropertyShorthand& propertiesAfterSlashSeperator, CSSPropertyID lastLayerProperty)

Maybe "getFillLayerPropertyShorthandValue" (after the naming of the FillLayer type)? I don't really think of "mask" as a being background-ish.

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4475
> +    auto bgColor = lastLayerProperty != CSSPropertyInvalid ? propertyValue(CSSPropertyBackgroundColor, DoNotUpdateLayout) : nullptr;

Feels a bit weird to pass in a property for lastLayerProperty but use CSSPropertyBackgroundColor here. Maybe call bgColor "lastValue" and pass in lastLayerProperty to propertyValue()?

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4488
> +        // Background color is a singleton, and should only be prepended to the last layer.

WebKit style is to avoid comments that describe what the code is doing, if it's reasonably clear what the code is doing by reading it. (And to make code clear enough that a comment isn't required, if possible.) So I would probably drop this comment.

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4494
> +            beforeList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));

When layerCount == 1, is value a CSSValueList or a single value? If it's a list, we should append item(i).

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4497
> +

Do we need to append the slash in here?

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4506
> +        // If there was only a single layer, then don't bother wrapping in the
> +        // layers list.

And I'd drop this one too.

> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4520
> +    static const CSSPropertyID propertiesBeforeSlashSeperator[4] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition };
>      static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };

Do you know what other browsers do in terms of the ordering of the longhand components? The general rule should be to follow the grammar order in the spec, unless there is some other explicit rules about serialization, and this ordering here doesn't match what's in the spec.

Also we can drop the explicit array lengths.
Comment 9 Matt Woodrow 2021-11-25 17:27:50 PST
Comment on attachment 445160 [details]
Patch

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

>> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4469
>> +Ref<CSSValueList> ComputedStyleExtractor::getBackgroundPropertyShorthandValue(CSSPropertyID property, const StylePropertyShorthand& propertiesBeforeSlashSeperator, const StylePropertyShorthand& propertiesAfterSlashSeperator, CSSPropertyID lastLayerProperty)
> 
> Maybe "getFillLayerPropertyShorthandValue" (after the naming of the FillLayer type)? I don't really think of "mask" as a being background-ish.

Yeah, that's probably a good idea. Some of the other mask code is using 'background' naming (in the parser etc), though that's probably just an artefact of how it was developed, rather than an explicit style choice.

>> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4475
>> +    auto bgColor = lastLayerProperty != CSSPropertyInvalid ? propertyValue(CSSPropertyBackgroundColor, DoNotUpdateLayout) : nullptr;
> 
> Feels a bit weird to pass in a property for lastLayerProperty but use CSSPropertyBackgroundColor here. Maybe call bgColor "lastValue" and pass in lastLayerProperty to propertyValue()?

Whoops, that indeed was the intent, just forgot to change it.

>> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4494
>> +            beforeList->append(layerCount == 1 ? value : *downcast<CSSValueList>(value).item(i));
> 
> When layerCount == 1, is value a CSSValueList or a single value? If it's a list, we should append item(i).

When layerCount == 1 then it's just a single value (which could itself be a list, if the property itself is a list), if layerCount > 1, then it's a list with a value per-layer.

>> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4497
>> +
> 
> Do we need to append the slash in here?

It's a slash-separated list, so just by having the two sublist, we get the '/' into the serialised output.

>> Source/WebCore/css/CSSComputedStyleDeclaration.cpp:4520
>>      static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, CSSPropertyBackgroundClip };
> 
> Do you know what other browsers do in terms of the ordering of the longhand components? The general rule should be to follow the grammar order in the spec, unless there is some other explicit rules about serialization, and this ordering here doesn't match what's in the spec.
> 
> Also we can drop the explicit array lengths.

This matches the order we were outputting previously, and matches what blink does. Gecko doesn't appear to make any attempt to produce a computed style for the background shorthand.

I figured it'd be easier to just change the (obviously broken) behaviour for multi-layer backgrounds to match blink, and worry about the property ordering as a separate issue.
Comment 10 Matt Woodrow 2021-11-25 17:56:09 PST
Created attachment 445165 [details]
Patch
Comment 11 Cameron McCormack (:heycam) 2021-11-25 18:29:25 PST
Comment on attachment 445165 [details]
Patch

r=me though it would be nice if some subtests checked for the correct interleaving of the longhand components when there is more than one layer present.
Comment 12 Matt Woodrow 2021-11-25 18:42:16 PST
(In reply to Cameron McCormack (:heycam) from comment #11)
> Comment on attachment 445165 [details]
> Patch
> 
> r=me though it would be nice if some subtests checked for the correct
> interleaving of the longhand components when there is more than one layer
> present.

The new tests that I added should be checking multiple layers, and that all the components are in the expected order.
Comment 13 EWS 2021-11-28 14:24:12 PST
Committed r286200 (244582@main): <https://commits.webkit.org/244582@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 445165 [details].
Comment 14 Radar WebKit Bug Importer 2021-11-28 14:25:25 PST
<rdar://problem/85790272>