Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(796)

Side by Side Diff: Source/core/css/MediaQueryEvaluator.cpp

Issue 240453010: Avoid use of CSSValue in MediaQueryExp and MediaQueryEvaluator (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * CSS Media Query Evaluator 2 * CSS Media Query Evaluator
3 * 3 *
4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>. 4 * Copyright (C) 2006 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com>.
5 * Copyright (C) 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2013 Intel Corporation. All rights reserved. 6 * Copyright (C) 2013 Intel Corporation. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "platform/PlatformScreen.h" 54 #include "platform/PlatformScreen.h"
55 #include "platform/geometry/FloatRect.h" 55 #include "platform/geometry/FloatRect.h"
56 #include "wtf/HashMap.h" 56 #include "wtf/HashMap.h"
57 57
58 namespace WebCore { 58 namespace WebCore {
59 59
60 using namespace MediaFeatureNames; 60 using namespace MediaFeatureNames;
61 61
62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; 62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix };
63 63
64 typedef bool (*EvalFunc)(CSSValue*, MediaFeaturePrefix, const MediaValues&); 64 typedef bool (*EvalFunc)(const MediaQueryExpValue&, MediaFeaturePrefix, const Me diaValues&);
65 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; 65 typedef HashMap<StringImpl*, EvalFunc> FunctionMap;
66 static FunctionMap* gFunctionMap; 66 static FunctionMap* gFunctionMap;
67 67
68 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) 68 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
69 : m_expectedResult(mediaFeatureResult) 69 : m_expectedResult(mediaFeatureResult)
70 { 70 {
71 } 71 }
72 72
73 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult) 73 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult)
74 : m_mediaType(acceptedMediaType) 74 : m_mediaType(acceptedMediaType)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 case MinPrefix: 164 case MinPrefix:
165 return a >= b; 165 return a >= b;
166 case MaxPrefix: 166 case MaxPrefix:
167 return a <= b; 167 return a <= b;
168 case NoPrefix: 168 case NoPrefix:
169 return a == b; 169 return a == b;
170 } 170 }
171 return false; 171 return false;
172 } 172 }
173 173
174 static bool compareAspectRatioValue(CSSValue* value, int width, int height, Medi aFeaturePrefix op) 174 static bool compareAspectRatioValue(const MediaQueryExpValue& value, int width, int height, MediaFeaturePrefix op)
175 { 175 {
176 if (value->isAspectRatioValue()) { 176 if (value.isRatio)
177 CSSAspectRatioValue* aspectRatio = toCSSAspectRatioValue(value); 177 return compareValue(width * static_cast<int>(value.denominator), height * static_cast<int>(value.numerator), op);
178 return compareValue(width * static_cast<int>(aspectRatio->denominatorVal ue()), height * static_cast<int>(aspectRatio->numeratorValue()), op);
179 }
180 178
181 return false; 179 return false;
182 } 180 }
183 181
184 static bool numberValue(CSSValue* value, float& result) 182 static bool numberValue(const MediaQueryExpValue& value, float& result)
185 { 183 {
186 if (value->isPrimitiveValue() 184 if (value.isValue && value.unit == CSSPrimitiveValue::CSS_NUMBER) {
187 && toCSSPrimitiveValue(value)->isNumber()) { 185 result = value.value;
188 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS S_NUMBER);
189 return true; 186 return true;
190 } 187 }
191 return false; 188 return false;
192 } 189 }
193 190
194 static bool colorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 191 static bool colorMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatureP refix op, const MediaValues& mediaValues)
195 { 192 {
196 float number; 193 float number;
197 int bitsPerComponent = mediaValues.colorBitsPerComponent(); 194 int bitsPerComponent = mediaValues.colorBitsPerComponent();
198 if (value) 195 if (value.isInit())
eseidel 2014/04/23 16:51:04 What does isInit mean?
199 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op); 196 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op);
200 197
201 return bitsPerComponent != 0; 198 return bitsPerComponent != 0;
202 } 199 }
203 200
204 static bool colorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues&) 201 static bool colorIndexMediaFeatureEval(const MediaQueryExpValue& value, MediaFea turePrefix op, const MediaValues&)
205 { 202 {
206 // FIXME: We currently assume that we do not support indexed displays, as it is unknown 203 // FIXME: We currently assume that we do not support indexed displays, as it is unknown
207 // how to retrieve the information if the display mode is indexed. This matc hes Firefox. 204 // how to retrieve the information if the display mode is indexed. This matc hes Firefox.
208 if (!value) 205 if (!value.isInit())
209 return false; 206 return false;
210 207
211 // Acording to spec, if the device does not use a color lookup table, the va lue is zero. 208 // Acording to spec, if the device does not use a color lookup table, the va lue is zero.
212 float number; 209 float number;
213 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op); 210 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op);
214 } 211 }
215 212
216 static bool monochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& mediaValues) 213 static bool monochromeMediaFeatureEval(const MediaQueryExpValue& value, MediaFea turePrefix op, const MediaValues& mediaValues)
217 { 214 {
218 if (!mediaValues.monochromeBitsPerComponent()) { 215 if (!mediaValues.monochromeBitsPerComponent()) {
219 if (value) { 216 if (value.isInit()) {
220 float number; 217 float number;
221 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op); 218 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op);
222 } 219 }
223 return false; 220 return false;
224 } 221 }
225 222
226 return colorMediaFeatureEval(value, op, mediaValues); 223 return colorMediaFeatureEval(value, op, mediaValues);
227 } 224 }
228 225
229 static bool orientationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, con st MediaValues& mediaValues) 226 static bool orientationMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix, const MediaValues& mediaValues)
230 { 227 {
231 int width = mediaValues.viewportWidth(); 228 int width = mediaValues.viewportWidth();
232 int height = mediaValues.viewportHeight(); 229 int height = mediaValues.viewportHeight();
233 230
234 if (value && value->isPrimitiveValue()) { 231 if (value.isID) {
235 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID();
236 if (width > height) // Square viewport is portrait. 232 if (width > height) // Square viewport is portrait.
237 return CSSValueLandscape == id; 233 return CSSValueLandscape == value.id;
238 return CSSValuePortrait == id; 234 return CSSValuePortrait == value.id;
239 } 235 }
240 236
241 // Expression (orientation) evaluates to true if width and height >= 0. 237 // Expression (orientation) evaluates to true if width and height >= 0.
242 return height >= 0 && width >= 0; 238 return height >= 0 && width >= 0;
243 } 239 }
244 240
245 static bool aspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 241 static bool aspectRatioMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues)
246 { 242 {
247 if (value) 243 if (value.isInit())
248 return compareAspectRatioValue(value, mediaValues.viewportWidth(), media Values.viewportHeight(), op); 244 return compareAspectRatioValue(value, mediaValues.viewportWidth(), media Values.viewportHeight(), op);
249 245
250 // ({,min-,max-}aspect-ratio) 246 // ({,min-,max-}aspect-ratio)
251 // assume if we have a device, its aspect ratio is non-zero. 247 // assume if we have a device, its aspect ratio is non-zero.
252 return true; 248 return true;
253 } 249 }
254 250
255 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefi x op, const MediaValues& mediaValues) 251 static bool deviceAspectRatioMediaFeatureEval(const MediaQueryExpValue& value, M ediaFeaturePrefix op, const MediaValues& mediaValues)
256 { 252 {
257 if (value) 253 if (value.isInit())
258 return compareAspectRatioValue(value, mediaValues.deviceWidth(), mediaVa lues.deviceHeight(), op); 254 return compareAspectRatioValue(value, mediaValues.deviceWidth(), mediaVa lues.deviceHeight(), op);
259 255
260 // ({,min-,max-}device-aspect-ratio) 256 // ({,min-,max-}device-aspect-ratio)
261 // assume if we have a device, its aspect ratio is non-zero. 257 // assume if we have a device, its aspect ratio is non-zero.
262 return true; 258 return true;
263 } 259 }
264 260
265 static bool evalResolution(CSSValue* value, MediaFeaturePrefix op, const MediaVa lues& mediaValues) 261 static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o p, const MediaValues& mediaValues)
266 { 262 {
267 // According to MQ4, only 'screen', 'print' and 'speech' may match. 263 // According to MQ4, only 'screen', 'print' and 'speech' may match.
268 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 264 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348
269 float actualResolution = 0; 265 float actualResolution = 0;
270 266
271 // This checks the actual media type applied to the document, and we know 267 // This checks the actual media type applied to the document, and we know
272 // this method only got called if this media type matches the one defined 268 // this method only got called if this media type matches the one defined
273 // in the query. Thus, if if the document's media type is "print", the 269 // in the query. Thus, if if the document's media type is "print", the
274 // media type of the query will either be "print" or "all". 270 // media type of the query will either be "print" or "all".
275 if (mediaValues.screenMediaType()) { 271 if (mediaValues.screenMediaType()) {
276 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); 272 actualResolution = clampTo<float>(mediaValues.devicePixelRatio());
277 } else if (mediaValues.printMediaType()) { 273 } else if (mediaValues.printMediaType()) {
278 // The resolution of images while printing should not depend on the DPI 274 // The resolution of images while printing should not depend on the DPI
279 // of the screen. Until we support proper ways of querying this info 275 // of the screen. Until we support proper ways of querying this info
280 // we use 300px which is considered minimum for current printers. 276 // we use 300px which is considered minimum for current printers.
281 actualResolution = 300 / cssPixelsPerInch; 277 actualResolution = 300 / cssPixelsPerInch;
282 } 278 }
283 279
284 if (!value) 280 if (!value.isInit())
285 return !!actualResolution; 281 return !!actualResolution;
286 282
287 if (!value->isPrimitiveValue()) 283 if (!value.isValue)
288 return false; 284 return false;
289 285
290 CSSPrimitiveValue* resolution = toCSSPrimitiveValue(value); 286 if (value.unit == CSSPrimitiveValue::CSS_NUMBER)
287 return compareValue(actualResolution, clampTo<float>(value.value), op);
291 288
292 if (resolution->isNumber()) 289 if (!CSSPrimitiveValue::isResolution(value.unit))
293 return compareValue(actualResolution, resolution->getFloatValue(), op);
294
295 if (!resolution->isResolution())
296 return false; 290 return false;
297 291
298 if (resolution->isDotsPerCentimeter()) { 292 double canonicalFactor = CSSPrimitiveValue::conversionToCanonicalUnitsScaleF actor(value.unit);
293 double dppxFactor = CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor (CSSPrimitiveValue::CSS_DPPX);
294 float valueInDppx = clampTo<float>(value.value * (canonicalFactor / dppxFact or));
295 if (CSSPrimitiveValue::isDotsPerCentimeter(value.unit)) {
299 // To match DPCM to DPPX values, we limit to 2 decimal points. 296 // To match DPCM to DPPX values, we limit to 2 decimal points.
300 // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends 297 // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends
301 // "that the pixel unit refer to the whole number of device pixels that best 298 // "that the pixel unit refer to the whole number of device pixels that best
302 // approximates the reference pixel". With that in mind, allowing 2 deci mal 299 // approximates the reference pixel". With that in mind, allowing 2 deci mal
303 // point precision seems appropriate. 300 // point precision seems appropriate.
304 return compareValue( 301 return compareValue(
305 floorf(0.5 + 100 * actualResolution) / 100, 302 floorf(0.5 + 100 * actualResolution) / 100,
306 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op); 303 floorf(0.5 + 100 * valueInDppx) / 100, op);
307 } 304 }
308 305
309 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op); 306 return compareValue(actualResolution, valueInDppx, op);
310 } 307 }
311 308
312 static bool devicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 309 static bool devicePixelRatioMediaFeatureEval(const MediaQueryExpValue& value, Me diaFeaturePrefix op, const MediaValues& mediaValues)
313 { 310 {
314 UseCounter::count(mediaValues.document(), UseCounter::PrefixedDevicePixelRat ioMediaFeature); 311 UseCounter::count(mediaValues.document(), UseCounter::PrefixedDevicePixelRat ioMediaFeature);
315 312
316 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, op, mediaValues); 313 return (!value.isInit() || value.unit == CSSPrimitiveValue::CSS_NUMBER) && e valResolution(value, op, mediaValues);
317 } 314 }
318 315
319 static bool resolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& MediaValues) 316 static bool resolutionMediaFeatureEval(const MediaQueryExpValue& value, MediaFea turePrefix op, const MediaValues& MediaValues)
320 { 317 {
321 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, op, MediaValues); 318 return (!value.isInit() || CSSPrimitiveValue::isResolution(value.unit)) && e valResolution(value, op, MediaValues);
322 } 319 }
323 320
324 static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M ediaValues&) 321 static bool gridMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix op, const MediaValues&)
325 { 322 {
326 // if output device is bitmap, grid: 0 == true 323 // if output device is bitmap, grid: 0 == true
327 // assume we have bitmap device 324 // assume we have bitmap device
328 float number; 325 float number;
329 if (value && numberValue(value, number)) 326 if (value.isInit() && numberValue(value, number))
330 return compareValue(static_cast<int>(number), 0, op); 327 return compareValue(static_cast<int>(number), 0, op);
331 return false; 328 return false;
332 } 329 }
333 330
334 static bool computeLength(CSSValue* value, const MediaValues& mediaValues, int& result) 331 static bool computeLength(const MediaQueryExpValue& value, const MediaValues& me diaValues, int& result)
335 { 332 {
336 if (!value->isPrimitiveValue()) 333 if (!value.isValue)
337 return false; 334 return false;
338 335
339 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 336 if (value.unit == CSSPrimitiveValue::CSS_NUMBER) {
340 337 result = clampTo<int>(value.value);
341 if (primitiveValue->isNumber()) {
342 result = primitiveValue->getIntValue();
343 return !mediaValues.strictMode() || !result; 338 return !mediaValues.strictMode() || !result;
344 } 339 }
345 340
346 if (primitiveValue->isLength()) 341 if (CSSPrimitiveValue::isLength(value.unit))
347 return mediaValues.computeLength(primitiveValue->getDoubleValue(), primi tiveValue->primitiveType(), result); 342 return mediaValues.computeLength(value.value, value.unit, result);
348
349 return false; 343 return false;
350 } 344 }
351 345
352 static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 346 static bool deviceHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaF eaturePrefix op, const MediaValues& mediaValues)
353 { 347 {
354 if (value) { 348 if (value.isInit()) {
355 int length; 349 int length;
356 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceHeight()), length, op); 350 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceHeight()), length, op);
357 } 351 }
358 // ({,min-,max-}device-height) 352 // ({,min-,max-}device-height)
359 // assume if we have a device, assume non-zero 353 // assume if we have a device, assume non-zero
360 return true; 354 return true;
361 } 355 }
362 356
363 static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 357 static bool deviceWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues)
364 { 358 {
365 if (value) { 359 if (value.isInit()) {
366 int length; 360 int length;
367 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceWidth()), length, op); 361 return computeLength(value, mediaValues, length) && compareValue(static_ cast<int>(mediaValues.deviceWidth()), length, op);
368 } 362 }
369 // ({,min-,max-}device-width) 363 // ({,min-,max-}device-width)
370 // assume if we have a device, assume non-zero 364 // assume if we have a device, assume non-zero
371 return true; 365 return true;
372 } 366 }
373 367
374 static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 368 static bool heightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeature Prefix op, const MediaValues& mediaValues)
375 { 369 {
376 int height = mediaValues.viewportHeight(); 370 int height = mediaValues.viewportHeight();
377 if (value) { 371 if (value.isInit()) {
378 int length; 372 int length;
379 return computeLength(value, mediaValues, length) && compareValue(height, length, op); 373 return computeLength(value, mediaValues, length) && compareValue(height, length, op);
380 } 374 }
381 375
382 return height; 376 return height;
383 } 377 }
384 378
385 static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 379 static bool widthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatureP refix op, const MediaValues& mediaValues)
386 { 380 {
387 int width = mediaValues.viewportWidth(); 381 int width = mediaValues.viewportWidth();
388 if (value) { 382 if (value.isInit()) {
389 int length; 383 int length;
390 return computeLength(value, mediaValues, length) && compareValue(width, length, op); 384 return computeLength(value, mediaValues, length) && compareValue(width, length, op);
391 } 385 }
392 386
393 return width; 387 return width;
394 } 388 }
395 389
396 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. 390 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used.
397 391
398 static bool minColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 392 static bool minColorMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
399 { 393 {
400 return colorMediaFeatureEval(value, MinPrefix, mediaValues); 394 return colorMediaFeatureEval(value, MinPrefix, mediaValues);
401 } 395 }
402 396
403 static bool maxColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 397 static bool maxColorMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
404 { 398 {
405 return colorMediaFeatureEval(value, MaxPrefix, mediaValues); 399 return colorMediaFeatureEval(value, MaxPrefix, mediaValues);
406 } 400 }
407 401
408 static bool minColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 402 static bool minColorIndexMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
409 { 403 {
410 return colorIndexMediaFeatureEval(value, MinPrefix, mediaValues); 404 return colorIndexMediaFeatureEval(value, MinPrefix, mediaValues);
411 } 405 }
412 406
413 static bool maxColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 407 static bool maxColorIndexMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
414 { 408 {
415 return colorIndexMediaFeatureEval(value, MaxPrefix, mediaValues); 409 return colorIndexMediaFeatureEval(value, MaxPrefix, mediaValues);
416 } 410 }
417 411
418 static bool minMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 412 static bool minMonochromeMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
419 { 413 {
420 return monochromeMediaFeatureEval(value, MinPrefix, mediaValues); 414 return monochromeMediaFeatureEval(value, MinPrefix, mediaValues);
421 } 415 }
422 416
423 static bool maxMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 417 static bool maxMonochromeMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
424 { 418 {
425 return monochromeMediaFeatureEval(value, MaxPrefix, mediaValues); 419 return monochromeMediaFeatureEval(value, MaxPrefix, mediaValues);
426 } 420 }
427 421
428 static bool minAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 422 static bool minAspectRatioMediaFeatureEval(const MediaQueryExpValue& value, Medi aFeaturePrefix, const MediaValues& mediaValues)
429 { 423 {
430 return aspectRatioMediaFeatureEval(value, MinPrefix, mediaValues); 424 return aspectRatioMediaFeatureEval(value, MinPrefix, mediaValues);
431 } 425 }
432 426
433 static bool maxAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 427 static bool maxAspectRatioMediaFeatureEval(const MediaQueryExpValue& value, Medi aFeaturePrefix, const MediaValues& mediaValues)
434 { 428 {
435 return aspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues); 429 return aspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
436 } 430 }
437 431
438 static bool minDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues) 432 static bool minDeviceAspectRatioMediaFeatureEval(const MediaQueryExpValue& value , MediaFeaturePrefix, const MediaValues& mediaValues)
439 { 433 {
440 return deviceAspectRatioMediaFeatureEval(value, MinPrefix, mediaValues); 434 return deviceAspectRatioMediaFeatureEval(value, MinPrefix, mediaValues);
441 } 435 }
442 436
443 static bool maxDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues) 437 static bool maxDeviceAspectRatioMediaFeatureEval(const MediaQueryExpValue& value , MediaFeaturePrefix, const MediaValues& mediaValues)
444 { 438 {
445 return deviceAspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues); 439 return deviceAspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
446 } 440 }
447 441
448 static bool minDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues) 442 static bool minDevicePixelRatioMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix, const MediaValues& mediaValues)
449 { 443 {
450 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMinDevicePixel RatioMediaFeature); 444 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMinDevicePixel RatioMediaFeature);
451 445
452 return devicePixelRatioMediaFeatureEval(value, MinPrefix, mediaValues); 446 return devicePixelRatioMediaFeatureEval(value, MinPrefix, mediaValues);
453 } 447 }
454 448
455 static bool maxDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues) 449 static bool maxDevicePixelRatioMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePrefix, const MediaValues& mediaValues)
456 { 450 {
457 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMaxDevicePixel RatioMediaFeature); 451 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMaxDevicePixel RatioMediaFeature);
458 452
459 return devicePixelRatioMediaFeatureEval(value, MaxPrefix, mediaValues); 453 return devicePixelRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
460 } 454 }
461 455
462 static bool minHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 456 static bool minHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeat urePrefix, const MediaValues& mediaValues)
463 { 457 {
464 return heightMediaFeatureEval(value, MinPrefix, mediaValues); 458 return heightMediaFeatureEval(value, MinPrefix, mediaValues);
465 } 459 }
466 460
467 static bool maxHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 461 static bool maxHeightMediaFeatureEval(const MediaQueryExpValue& value, MediaFeat urePrefix, const MediaValues& mediaValues)
468 { 462 {
469 return heightMediaFeatureEval(value, MaxPrefix, mediaValues); 463 return heightMediaFeatureEval(value, MaxPrefix, mediaValues);
470 } 464 }
471 465
472 static bool minWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 466 static bool minWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
473 { 467 {
474 return widthMediaFeatureEval(value, MinPrefix, mediaValues); 468 return widthMediaFeatureEval(value, MinPrefix, mediaValues);
475 } 469 }
476 470
477 static bool maxWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 471 static bool maxWidthMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
478 { 472 {
479 return widthMediaFeatureEval(value, MaxPrefix, mediaValues); 473 return widthMediaFeatureEval(value, MaxPrefix, mediaValues);
480 } 474 }
481 475
482 static bool minDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 476 static bool minDeviceHeightMediaFeatureEval(const MediaQueryExpValue& value, Med iaFeaturePrefix, const MediaValues& mediaValues)
483 { 477 {
484 return deviceHeightMediaFeatureEval(value, MinPrefix, mediaValues); 478 return deviceHeightMediaFeatureEval(value, MinPrefix, mediaValues);
485 } 479 }
486 480
487 static bool maxDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 481 static bool maxDeviceHeightMediaFeatureEval(const MediaQueryExpValue& value, Med iaFeaturePrefix, const MediaValues& mediaValues)
488 { 482 {
489 return deviceHeightMediaFeatureEval(value, MaxPrefix, mediaValues); 483 return deviceHeightMediaFeatureEval(value, MaxPrefix, mediaValues);
490 } 484 }
491 485
492 static bool minDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 486 static bool minDeviceWidthMediaFeatureEval(const MediaQueryExpValue& value, Medi aFeaturePrefix, const MediaValues& mediaValues)
493 { 487 {
494 return deviceWidthMediaFeatureEval(value, MinPrefix, mediaValues); 488 return deviceWidthMediaFeatureEval(value, MinPrefix, mediaValues);
495 } 489 }
496 490
497 static bool maxDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 491 static bool maxDeviceWidthMediaFeatureEval(const MediaQueryExpValue& value, Medi aFeaturePrefix, const MediaValues& mediaValues)
498 { 492 {
499 return deviceWidthMediaFeatureEval(value, MaxPrefix, mediaValues); 493 return deviceWidthMediaFeatureEval(value, MaxPrefix, mediaValues);
500 } 494 }
501 495
502 static bool minResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 496 static bool minResolutionMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
503 { 497 {
504 return resolutionMediaFeatureEval(value, MinPrefix, mediaValues); 498 return resolutionMediaFeatureEval(value, MinPrefix, mediaValues);
505 } 499 }
506 500
507 static bool maxResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues) 501 static bool maxResolutionMediaFeatureEval(const MediaQueryExpValue& value, Media FeaturePrefix, const MediaValues& mediaValues)
508 { 502 {
509 return resolutionMediaFeatureEval(value, MaxPrefix, mediaValues); 503 return resolutionMediaFeatureEval(value, MaxPrefix, mediaValues);
510 } 504 }
511 505
512 static bool animationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, co nst MediaValues& mediaValues) 506 static bool animationMediaFeatureEval(const MediaQueryExpValue& value, MediaFeat urePrefix op, const MediaValues& mediaValues)
513 { 507 {
514 UseCounter::count(mediaValues.document(), UseCounter::PrefixedAnimationMedia Feature); 508 UseCounter::count(mediaValues.document(), UseCounter::PrefixedAnimationMedia Feature);
515 509
516 if (value) { 510 if (value.isInit()) {
517 float number; 511 float number;
518 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); 512 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op);
519 } 513 }
520 return true; 514 return true;
521 } 515 }
522 516
523 static bool transform2dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 517 static bool transform2dMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues)
524 { 518 {
525 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform2dMed iaFeature); 519 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform2dMed iaFeature);
526 520
527 if (value) { 521 if (value.isInit()) {
528 float number; 522 float number;
529 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); 523 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op);
530 } 524 }
531 return true; 525 return true;
532 } 526 }
533 527
534 static bool transform3dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues) 528 static bool transform3dMediaFeatureEval(const MediaQueryExpValue& value, MediaFe aturePrefix op, const MediaValues& mediaValues)
535 { 529 {
536 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform3dMed iaFeature); 530 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform3dMed iaFeature);
537 531
538 bool returnValueIfNoParameter; 532 bool returnValueIfNoParameter;
539 int have3dRendering; 533 int have3dRendering;
540 534
541 bool threeDEnabled = mediaValues.threeDEnabled(); 535 bool threeDEnabled = mediaValues.threeDEnabled();
542 536
543 returnValueIfNoParameter = threeDEnabled; 537 returnValueIfNoParameter = threeDEnabled;
544 have3dRendering = threeDEnabled ? 1 : 0; 538 have3dRendering = threeDEnabled ? 1 : 0;
545 539
546 if (value) { 540 if (value.isInit()) {
547 float number; 541 float number;
548 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op); 542 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op);
549 } 543 }
550 return returnValueIfNoParameter; 544 return returnValueIfNoParameter;
551 } 545 }
552 546
553 static bool viewModeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues) 547 static bool viewModeMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatu rePrefix, const MediaValues& mediaValues)
554 { 548 {
555 UseCounter::count(mediaValues.document(), UseCounter::PrefixedViewModeMediaF eature); 549 UseCounter::count(mediaValues.document(), UseCounter::PrefixedViewModeMediaF eature);
556 550
557 if (!value) 551 if (!value.isInit())
558 return true; 552 return true;
559 553
560 return toCSSPrimitiveValue(value)->getValueID() == CSSValueWindowed; 554 ASSERT(value.isID);
555
556 return value.id == CSSValueWindowed;
561 } 557 }
562 558
563 static bool hoverMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Med iaValues& mediaValues) 559 static bool hoverMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatureP refix, const MediaValues& mediaValues)
564 { 560 {
565 MediaValues::PointerDeviceType pointer = mediaValues.pointer(); 561 MediaValues::PointerDeviceType pointer = mediaValues.pointer();
566 562
567 // If we're on a port that hasn't explicitly opted into providing pointer de vice information 563 // If we're on a port that hasn't explicitly opted into providing pointer de vice information
568 // (or otherwise can't be confident in the pointer hardware available), then behave exactly 564 // (or otherwise can't be confident in the pointer hardware available), then behave exactly
569 // as if this feature feature isn't supported. 565 // as if this feature feature isn't supported.
570 if (pointer == MediaValues::UnknownPointer) 566 if (pointer == MediaValues::UnknownPointer)
571 return false; 567 return false;
572 568
573 float number = 1; 569 float number = 1;
574 if (value) { 570 if (value.isInit()) {
575 if (!numberValue(value, number)) 571 if (!numberValue(value, number))
576 return false; 572 return false;
577 } 573 }
578 574
579 return (pointer == MediaValues::NoPointer && !number) 575 return (pointer == MediaValues::NoPointer && !number)
580 || (pointer == MediaValues::TouchPointer && !number) 576 || (pointer == MediaValues::TouchPointer && !number)
581 || (pointer == MediaValues::MousePointer && number == 1); 577 || (pointer == MediaValues::MousePointer && number == 1);
582 } 578 }
583 579
584 static bool pointerMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const M ediaValues& mediaValues) 580 static bool pointerMediaFeatureEval(const MediaQueryExpValue& value, MediaFeatur ePrefix, const MediaValues& mediaValues)
585 { 581 {
586 MediaValues::PointerDeviceType pointer = mediaValues.pointer(); 582 MediaValues::PointerDeviceType pointer = mediaValues.pointer();
587 583
588 // If we're on a port that hasn't explicitly opted into providing pointer de vice information 584 // If we're on a port that hasn't explicitly opted into providing pointer de vice information
589 // (or otherwise can't be confident in the pointer hardware available), then behave exactly 585 // (or otherwise can't be confident in the pointer hardware available), then behave exactly
590 // as if this feature feature isn't supported. 586 // as if this feature feature isn't supported.
591 if (pointer == MediaValues::UnknownPointer) 587 if (pointer == MediaValues::UnknownPointer)
592 return false; 588 return false;
593 589
594 if (!value) 590 if (!value.isInit())
595 return pointer != MediaValues::NoPointer; 591 return pointer != MediaValues::NoPointer;
596 592
597 if (!value->isPrimitiveValue()) 593 if (!value.isID)
598 return false; 594 return false;
599 595
600 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); 596 return (pointer == MediaValues::NoPointer && value.id == CSSValueNone)
601 return (pointer == MediaValues::NoPointer && id == CSSValueNone) 597 || (pointer == MediaValues::TouchPointer && value.id == CSSValueCoarse)
602 || (pointer == MediaValues::TouchPointer && id == CSSValueCoarse) 598 || (pointer == MediaValues::MousePointer && value.id == CSSValueFine);
603 || (pointer == MediaValues::MousePointer && id == CSSValueFine);
604 } 599 }
605 600
606 static bool scanMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Medi aValues& mediaValues) 601 static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix, const MediaValues& mediaValues)
607 { 602 {
608 if (!mediaValues.scanMediaType()) 603 if (!mediaValues.scanMediaType())
609 return false; 604 return false;
610 605
611 if (!value) 606 if (!value.isInit())
612 return true; 607 return true;
613 608
614 if (!value->isPrimitiveValue()) 609 if (!value.isID)
615 return false; 610 return false;
616 611
617 // If a platform interface supplies progressive/interlace info for TVs in th e 612 // If a platform interface supplies progressive/interlace info for TVs in th e
618 // future, it needs to be handled here. For now, assume a modern TV with 613 // future, it needs to be handled here. For now, assume a modern TV with
619 // progressive display. 614 // progressive display.
620 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive; 615 return (value.id == CSSValueProgressive);
621 } 616 }
622 617
623 static void createFunctionMap() 618 static void createFunctionMap()
624 { 619 {
625 // Create the table. 620 // Create the table.
626 gFunctionMap = new FunctionMap; 621 gFunctionMap = new FunctionMap;
627 #define ADD_TO_FUNCTIONMAP(name) \ 622 #define ADD_TO_FUNCTIONMAP(name) \
628 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); 623 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
629 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); 624 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
630 #undef ADD_TO_FUNCTIONMAP 625 #undef ADD_TO_FUNCTIONMAP
631 } 626 }
632 627
633 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const 628 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
634 { 629 {
635 if (!m_mediaValues || !m_mediaValues->hasValues()) 630 if (!m_mediaValues || !m_mediaValues->hasValues())
636 return m_expectedResult; 631 return m_expectedResult;
637 632
638 if (!gFunctionMap) 633 if (!gFunctionMap)
639 createFunctionMap(); 634 createFunctionMap();
640 635
641 // Call the media feature evaluation function. Assume no prefix and let 636 // Call the media feature evaluation function. Assume no prefix and let
642 // trampoline functions override the prefix if prefix is used. 637 // trampoline functions override the prefix if prefix is used.
643 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 638 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
644 if (func) 639 if (func)
645 return func(expr->value(), NoPrefix, *m_mediaValues); 640 return func(expr->expValue(), NoPrefix, *m_mediaValues);
646 641
647 return false; 642 return false;
648 } 643 }
649 644
650 } // namespace 645 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698