Ignore:
Timestamp:
Jan 27, 2020, 11:54:48 PM (5 years ago)
Author:
Noam Rosenthal
Message:

-webkit-image-set should support resolution units other than 'x'
https://bugs.webkit.org/show_bug.cgi?id=100120

Reviewed by Darin Adler.

Source/WebCore:

Leveraged previous work on image-resolution to enable dpi/dppx/dpcm in CSS image-set.
Now the second value of every entry in the image-set is parsed like any resolution,
allowing "x" as a synonim for "dppx.

This changes computed style behavior for image-set - "x" resolution values will be converted
to "dppx". This is in line with the spirit of computed values, though it's not spec'ed particularly.

Tests: fast/hidpi/image-set-units.html

  • css/CSSImageSetValue.cpp:

(WebCore::CSSImageSetValue::fillImageSet):
(WebCore::CSSImageSetValue::updateDeviceScaleFactor):
(WebCore::CSSImageSetValue::customCSSText const):

Convert values to dppx before sorting them the image set.
Use given CSS units in computed styles instead of hardcoding "x"

  • css/CSSPrimitiveValue.cpp:

(WebCore::isValidCSSUnitTypeForDoubleConversion):
(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor):

Allow conversion of dpi/dppx/dpcm to canonical (dppx).

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeResolution):
(WebCore::CSSPropertyParserHelpers::consumeImageSet):

  • css/parser/CSSPropertyParserHelpers.h:

Consume any resolution when parsing image-set.

LayoutTests:

Had to modify several image-set parsing tests because of the behavior change in
computed style (x => dppx).

Also added a couple of parsing/rendering tests specifically to test the new behavior
of dpi/dpcm/dppx.

  • fast/css/cursor-parsing-image-set-expected.txt:
  • fast/css/cursor-parsing-image-set.html:
  • fast/css/image-set-parsing-expected.txt:
  • fast/css/image-set-parsing-invalid-expected.txt:
  • fast/css/image-set-parsing.html:
  • fast/css/image-set-setting-expected.txt:
  • fast/css/image-set-setting.html:
  • fast/css/image-set-unprefixed.html:
  • fast/hidpi/image-set-units-expected.html: Added.
  • fast/hidpi/image-set-units.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSImageSetValue.cpp

    r254861 r255228  
    5151{
    5252    size_t length = this->length();
    53     size_t i = 0;
    54     while (i < length) {
     53    for (size_t i = 0; i + 1 < length; i += 2) {
    5554        CSSValue* imageValue = item(i);
     55        CSSValue* scaleFactorValue = item(i + 1);
     56
    5657        ASSERT(is<CSSImageValue>(imageValue) || is<CSSImageGeneratorValue>(imageValue));
    57         ++i;
    58         ASSERT_WITH_SECURITY_IMPLICATION(i < length);
    59         CSSValue* scaleFactorValue = item(i);
    60         float scaleFactor = downcast<CSSPrimitiveValue>(*scaleFactorValue).floatValue();
     58        ASSERT(is<CSSPrimitiveValue>(scaleFactorValue));
    6159
    62         ImageWithScale image;
    63         image.value = imageValue;
    64         image.scaleFactor = scaleFactor;
    65         m_imagesInSet.append(image);
    66         ++i;
     60        float scaleFactor = downcast<CSSPrimitiveValue>(scaleFactorValue)->floatValue(CSSUnitType::CSS_DPPX);
     61        m_imagesInSet.append({ imageValue, scaleFactor });
    6762    }
    6863
     
    107102void CSSImageSetValue::updateDeviceScaleFactor(const Document& document)
    108103{
    109 
    110104    // FIXME: In the future, we want to take much more than deviceScaleFactor into acount here.
    111105    // All forms of scale should be included: Page::pageScaleFactor(), Frame::pageZoomFactor(),
     
    137131
    138132    size_t length = this->length();
    139     size_t i = 0;
    140     while (i < length) {
     133    for (size_t i = 0; i + 1 < length; i += 2) {
    141134        if (i > 0)
    142135            result.appendLiteral(", ");
    143136
    144         const CSSValue* imageValue = item(i);
    145         result.append(imageValue->cssText());
    146         result.append(' ');
    147 
    148         ++i;
    149         ASSERT_WITH_SECURITY_IMPLICATION(i < length);
    150         const CSSValue* scaleFactorValue = item(i);
    151         result.append(scaleFactorValue->cssText());
    152         // FIXME: Eventually the scale factor should contain it's own unit http://wkb.ug/100120.
    153         // For now 'x' is hard-coded in the parser, so we hard-code it here too.
    154         result.append('x');
    155 
    156         ++i;
     137        result.append(item(i)->cssText(), ' ', item(i + 1)->cssText());
    157138    }
    158139
Note: See TracChangeset for help on using the changeset viewer.