Changeset 183404 in webkit


Ignore:
Timestamp:
Apr 27, 2015 11:42:29 AM (9 years ago)
Author:
yoav@yoav.ws
Message:

Fix viewport units in Media Queries
https://bugs.webkit.org/show_bug.cgi?id=144260

Reviewed by Darin Adler.

Source/WebCore:

This patch makes sure that viewport units are considered "length units"
in the context of Media Queries, by having MediaQueryExp use the unit logic
that is in CSSPrimitiveValue.
It does that by turning the relevant methods in CSSPrimitiveValue into static.

It also makes sure that the logic for "resolution units" is not maintained separately
in MediaQueryExp, to avoid similiar issues in the future with resolution units.

Test: fast/media/mq-viewport-units.html

  • css/CSSPrimitiveValue.h:

(WebCore::CSSPrimitiveValue::isViewportPercentageLength): Added a static variant.
(WebCore::CSSPrimitiveValue::isLength): Added a static variant.
(WebCore::CSSPrimitiveValue::isResolution): Added a static variant.

  • css/MediaQueryExp.cpp:

(WebCore::featureWithValidPositiveLenghtOrNumber): Call CSSPrimitiveValue's length unit logic.
(WebCore::featureWithValidDensity): Call CSSPrimitiveValue's resolution unit logic.

LayoutTests:

These tests make sure that viewport units are working as expected inside of Media Queries.

  • fast/media/mq-viewport-units-expected.txt: Added.
  • fast/media/mq-viewport-units.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r183399 r183404  
     12015-04-27  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Fix viewport units in Media Queries
     4        https://bugs.webkit.org/show_bug.cgi?id=144260
     5
     6        Reviewed by Darin Adler.
     7
     8        These tests make sure that viewport units are working as expected inside of Media Queries.
     9
     10        * fast/media/mq-viewport-units-expected.txt: Added.
     11        * fast/media/mq-viewport-units.html: Added.
     12
    1132015-04-27  Javier Fernandez  <jfernandez@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r183399 r183404  
     12015-04-27  Yoav Weiss  <yoav@yoav.ws>
     2
     3        Fix viewport units in Media Queries
     4        https://bugs.webkit.org/show_bug.cgi?id=144260
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch makes sure that viewport units are considered "length units"
     9        in the context of Media Queries, by having MediaQueryExp use the unit logic
     10        that is in CSSPrimitiveValue.
     11        It does that by turning the relevant methods in CSSPrimitiveValue into static.
     12
     13        It also makes sure that the logic for "resolution units" is not maintained separately
     14        in MediaQueryExp, to avoid similiar issues in the future with resolution units.
     15
     16        Test: fast/media/mq-viewport-units.html
     17
     18        * css/CSSPrimitiveValue.h:
     19        (WebCore::CSSPrimitiveValue::isViewportPercentageLength): Added a static variant.
     20        (WebCore::CSSPrimitiveValue::isLength): Added a static variant.
     21        (WebCore::CSSPrimitiveValue::isResolution): Added a static variant.
     22        * css/MediaQueryExp.cpp:
     23        (WebCore::featureWithValidPositiveLenghtOrNumber): Call CSSPrimitiveValue's length unit logic.
     24        (WebCore::featureWithValidDensity): Call CSSPrimitiveValue's resolution unit logic.
     25
    1262015-04-27  Javier Fernandez  <jfernandez@igalia.com>
    227
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r182364 r183404  
    189189            || m_primitiveUnitType == CSS_CHS;
    190190    }
    191     bool isLength() const
    192     {
    193         unsigned short type = primitiveType();
    194         return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS || isViewportPercentageLength();
    195     }
     191
     192    static bool isViewportPercentageLength(unsigned short type) { return type >= CSS_VW && type <= CSS_VMAX; }
     193    bool isViewportPercentageLength() const { return isViewportPercentageLength(m_primitiveUnitType); }
     194
     195    static bool isLength(unsigned short type)
     196    {
     197        return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type == CSS_CHS || isViewportPercentageLength(type);
     198    }
     199
     200    bool isLength() const { return isLength(primitiveType()); }
    196201    bool isNumber() const { return primitiveType() == CSS_NUMBER; }
    197202    bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; }
     
    213218    bool isDotsPerPixel() const { return primitiveType() == CSS_DPPX; }
    214219    bool isDotsPerCentimeter() const { return primitiveType() == CSS_DPCM; }
    215     bool isResolution() const
    216     {
    217         unsigned short type = primitiveType();
     220
     221    static bool isResolution(unsigned short type)
     222    {
    218223        return type >= CSS_DPPX && type <= CSS_DPCM;
    219224    }
    220225
    221     bool isViewportPercentageLength() const { return m_primitiveUnitType >= CSS_VW && m_primitiveUnitType <= CSS_VMAX; }
     226    bool isResolution() const { return isResolution(primitiveType()); }
    222227    bool isViewportPercentageWidth() const { return m_primitiveUnitType == CSS_VW; }
    223228    bool isViewportPercentageHeight() const { return m_primitiveUnitType == CSS_VH; }
  • trunk/Source/WebCore/css/MediaQueryExp.cpp

    r179476 r183404  
    5555static inline bool featureWithValidPositiveLenghtOrNumber(const AtomicString& mediaFeature, const CSSParserValue* value)
    5656{
    57     if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimitiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || value->unit == CSSPrimitiveValue::CSS_NUMBER) || value->fValue < 0)
     57    if (!(CSSPrimitiveValue::isLength(value->unit) || value->unit == CSSPrimitiveValue::CSS_NUMBER) || value->fValue < 0)
    5858        return false;
    5959
     
    7474static inline bool featureWithValidDensity(const AtomicString& mediaFeature, const CSSParserValue* value)
    7575{
    76     if ((value->unit != CSSPrimitiveValue::CSS_DPPX && value->unit != CSSPrimitiveValue::CSS_DPI && value->unit != CSSPrimitiveValue::CSS_DPCM) || value->fValue <= 0)
     76    if (!CSSPrimitiveValue::isResolution(value->unit) || value->fValue <= 0)
    7777        return false;
    7878
Note: See TracChangeset for help on using the changeset viewer.