Commit d0822ad0 authored by yoav@yoav.ws's avatar yoav@yoav.ws

Bug fix - rem & ch in MQs/sizes treated as unknown units

'rem' and 'ch' units were unrecognized when used inside MQs/sizes, since they were not in the unit table.
I've added them and fixed another bug related to CH and MQs.

I've also added the 'fr' and 'turn' units to the unit table, even though there aren't valid MQs that can use them,
since some other code may use the unit table in the future, and they should be there for completeness.

BUG=398185

Review URL: https://codereview.chromium.org/427683002

git-svn-id: svn://svn.chromium.org/blink/trunk@179103 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent fa8363b4
......@@ -140,6 +140,10 @@ StringToUnitTable createStringToUnitTable()
table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN);
table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX);
table.set(String("rem"), CSSPrimitiveValue::CSS_REMS);
table.set(String("fr"), CSSPrimitiveValue::CSS_FR);
table.set(String("turn"), CSSPrimitiveValue::CSS_TURN);
table.set(String("ch"), CSSPrimitiveValue::CSS_CHS);
return table;
}
......
......@@ -67,9 +67,27 @@ static inline bool featureWithValidIdent(const String& mediaFeature, CSSValueID
return false;
}
static bool positiveLengthUnit(const int unit)
{
switch (unit) {
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
return true;
}
return false;
}
static inline bool featureWithValidPositiveLength(const String& mediaFeature, const CSSParserValue* value)
{
if (!(((value->unit >= CSSPrimitiveValue::CSS_EMS && value->unit <= CSSPrimitiveValue::CSS_PC) || value->unit == CSSPrimitiveValue::CSS_REMS) || (value->unit == CSSPrimitiveValue::CSS_NUMBER && !(value->fValue))) || value->fValue < 0)
if (!(positiveLengthUnit(value->unit) || (value->unit == CSSPrimitiveValue::CSS_NUMBER && value->fValue == 0)) || value->fValue < 0)
return false;
......
......@@ -67,6 +67,8 @@ TEST(MediaQuerySetTest, Basic)
{"screen and (min-width: 400px) and (max-width: 700px)", "screen and (max-width: 700px) and (min-width: 400px)", true},
{"screen and (device-width: 800px)", 0, true},
{"screen and (device-height: 60em)", 0, true},
{"screen and (device-height: 60rem)", 0, true},
{"screen and (device-height: 60ch)", 0, true},
{"screen and (device-aspect-ratio: 16/9)", 0, true},
{"(device-aspect-ratio: 16.0/9.0)", "not all", true},
{"(device-aspect-ratio: 16/ 9)", "(device-aspect-ratio: 16/9)", true},
......
......@@ -46,6 +46,8 @@ TEST(SizesAttributeParserTest, Basic)
{"(max-width: 3000px) 200w, 400w", 500},
{",, , /**/ ,200px", 200},
{"50vw", 250},
{"5em", 80},
{"5rem", 80},
{"calc(40vw*2)", 400},
{"(min-width:5000px) calc(5000px/10), (min-width:500px) calc(1200px/3)", 400},
{"(min-width:500px) calc(1200/3)", 500},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment