OLD | NEW |
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if (value->isPrimitiveValue() | 182 if (value->isPrimitiveValue() |
183 && toCSSPrimitiveValue(value)->isNumber()) { | 183 && toCSSPrimitiveValue(value)->isNumber()) { |
184 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS
S_NUMBER); | 184 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS
S_NUMBER); |
185 return true; | 185 return true; |
186 } | 186 } |
187 return false; | 187 return false; |
188 } | 188 } |
189 | 189 |
190 static bool colorMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, M
ediaFeaturePrefix op) | 190 static bool colorMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, M
ediaFeaturePrefix op) |
191 { | 191 { |
192 int bitsPerComponent = screenDepthPerComponent(frame->page()->mainFrame()->v
iew()); | 192 int bitsPerComponent = screenDepthPerComponent(frame->view()); |
193 float number; | 193 float number; |
194 if (value) | 194 if (value) |
195 return numberValue(value, number) && compareValue(bitsPerComponent, stat
ic_cast<int>(number), op); | 195 return numberValue(value, number) && compareValue(bitsPerComponent, stat
ic_cast<int>(number), op); |
196 | 196 |
197 return bitsPerComponent != 0; | 197 return bitsPerComponent != 0; |
198 } | 198 } |
199 | 199 |
200 static bool colorIndexMediaFeatureEval(CSSValue* value, RenderStyle*, Frame*, Me
diaFeaturePrefix op) | 200 static bool colorIndexMediaFeatureEval(CSSValue* value, RenderStyle*, Frame*, Me
diaFeaturePrefix op) |
201 { | 201 { |
202 // FIXME: We currently assume that we do not support indexed displays, as it
is unknown | 202 // FIXME: We currently assume that we do not support indexed displays, as it
is unknown |
203 // how to retrieve the information if the display mode is indexed. This matc
hes Firefox. | 203 // how to retrieve the information if the display mode is indexed. This matc
hes Firefox. |
204 if (!value) | 204 if (!value) |
205 return false; | 205 return false; |
206 | 206 |
207 // Acording to spec, if the device does not use a color lookup table, the va
lue is zero. | 207 // Acording to spec, if the device does not use a color lookup table, the va
lue is zero. |
208 float number; | 208 float number; |
209 return numberValue(value, number) && compareValue(0, static_cast<int>(number
), op); | 209 return numberValue(value, number) && compareValue(0, static_cast<int>(number
), op); |
210 } | 210 } |
211 | 211 |
212 static bool monochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, Fram
e* frame, MediaFeaturePrefix op) | 212 static bool monochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, Fram
e* frame, MediaFeaturePrefix op) |
213 { | 213 { |
214 if (!screenIsMonochrome(frame->page()->mainFrame()->view())) { | 214 if (!screenIsMonochrome(frame->view())) { |
215 if (value) { | 215 if (value) { |
216 float number; | 216 float number; |
217 return numberValue(value, number) && compareValue(0, static_cast<int
>(number), op); | 217 return numberValue(value, number) && compareValue(0, static_cast<int
>(number), op); |
218 } | 218 } |
219 return false; | 219 return false; |
220 } | 220 } |
221 | 221 |
222 return colorMediaFeatureEval(value, style, frame, op); | 222 return colorMediaFeatureEval(value, style, frame, op); |
223 } | 223 } |
224 | 224 |
(...skipping 26 matching lines...) Expand all Loading... |
251 } | 251 } |
252 | 252 |
253 // ({,min-,max-}aspect-ratio) | 253 // ({,min-,max-}aspect-ratio) |
254 // assume if we have a device, its aspect ratio is non-zero. | 254 // assume if we have a device, its aspect ratio is non-zero. |
255 return true; | 255 return true; |
256 } | 256 } |
257 | 257 |
258 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, Fra
me* frame, MediaFeaturePrefix op) | 258 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, Fra
me* frame, MediaFeaturePrefix op) |
259 { | 259 { |
260 if (value) { | 260 if (value) { |
261 FloatRect sg = screenRect(frame->page()->mainFrame()->view()); | 261 FloatRect sg = screenRect(frame->view()); |
262 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat
ic_cast<int>(sg.height()), op); | 262 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat
ic_cast<int>(sg.height()), op); |
263 } | 263 } |
264 | 264 |
265 // ({,min-,max-}device-aspect-ratio) | 265 // ({,min-,max-}device-aspect-ratio) |
266 // assume if we have a device, its aspect ratio is non-zero. | 266 // assume if we have a device, its aspect ratio is non-zero. |
267 return true; | 267 return true; |
268 } | 268 } |
269 | 269 |
270 static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op) | 270 static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op) |
271 { | 271 { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 356 |
357 return false; | 357 return false; |
358 } | 358 } |
359 | 359 |
360 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
ame* frame, MediaFeaturePrefix op) | 360 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Fr
ame* frame, MediaFeaturePrefix op) |
361 { | 361 { |
362 if (value) { | 362 if (value) { |
363 int length; | 363 int length; |
364 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len
gth)) | 364 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len
gth)) |
365 return false; | 365 return false; |
366 int height = static_cast<int>(screenRect(frame->page()->mainFrame()->vie
w()).height()); | 366 int height = static_cast<int>(screenRect(frame->view()).height()); |
367 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | 367 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) |
368 height = lroundf(height * frame->page()->deviceScaleFactor()); | 368 height = lroundf(height * frame->page()->deviceScaleFactor()); |
369 return compareValue(height, length, op); | 369 return compareValue(height, length, op); |
370 } | 370 } |
371 // ({,min-,max-}device-height) | 371 // ({,min-,max-}device-height) |
372 // assume if we have a device, assume non-zero | 372 // assume if we have a device, assume non-zero |
373 return true; | 373 return true; |
374 } | 374 } |
375 | 375 |
376 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra
me* frame, MediaFeaturePrefix op) | 376 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Fra
me* frame, MediaFeaturePrefix op) |
377 { | 377 { |
378 if (value) { | 378 if (value) { |
379 int length; | 379 int length; |
380 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len
gth)) | 380 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len
gth)) |
381 return false; | 381 return false; |
382 int width = static_cast<int>(screenRect(frame->page()->mainFrame()->view
()).width()); | 382 int width = static_cast<int>(screenRect(frame->view()).width()); |
383 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | 383 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) |
384 width = lroundf(width * frame->page()->deviceScaleFactor()); | 384 width = lroundf(width * frame->page()->deviceScaleFactor()); |
385 return compareValue(width, length, op); | 385 return compareValue(width, length, op); |
386 } | 386 } |
387 // ({,min-,max-}device-width) | 387 // ({,min-,max-}device-width) |
388 // assume if we have a device, assume non-zero | 388 // assume if we have a device, assume non-zero |
389 return true; | 389 return true; |
390 } | 390 } |
391 | 391 |
392 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f
rame, MediaFeaturePrefix op) | 392 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, Frame* f
rame, MediaFeaturePrefix op) |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 // Call the media feature evaluation function. Assume no prefix and let | 686 // Call the media feature evaluation function. Assume no prefix and let |
687 // trampoline functions override the prefix if prefix is used. | 687 // trampoline functions override the prefix if prefix is used. |
688 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 688 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
689 if (func) | 689 if (func) |
690 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 690 return func(expr->value(), m_style.get(), m_frame, NoPrefix); |
691 | 691 |
692 return false; | 692 return false; |
693 } | 693 } |
694 | 694 |
695 } // namespace | 695 } // namespace |
OLD | NEW |