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

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

Issue 201813002: Enable Media query evaluation in the preload scanner (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix Debug crash. Values based MediaValues::create Created 6 years, 9 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
« no previous file with comments | « Source/core/css/MediaQueryEvaluator.h ('k') | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 #include "CSSValueKeywords.h" 33 #include "CSSValueKeywords.h"
34 #include "MediaFeatureNames.h" 34 #include "MediaFeatureNames.h"
35 #include "MediaFeatures.h" 35 #include "MediaFeatures.h"
36 #include "MediaTypeNames.h" 36 #include "MediaTypeNames.h"
37 #include "core/css/CSSAspectRatioValue.h" 37 #include "core/css/CSSAspectRatioValue.h"
38 #include "core/css/CSSHelper.h" 38 #include "core/css/CSSHelper.h"
39 #include "core/css/CSSPrimitiveValue.h" 39 #include "core/css/CSSPrimitiveValue.h"
40 #include "core/css/CSSToLengthConversionData.h" 40 #include "core/css/CSSToLengthConversionData.h"
41 #include "core/css/MediaList.h" 41 #include "core/css/MediaList.h"
42 #include "core/css/MediaQuery.h" 42 #include "core/css/MediaQuery.h"
43 #include "core/css/MediaValues.h"
43 #include "core/css/resolver/MediaQueryResult.h" 44 #include "core/css/resolver/MediaQueryResult.h"
44 #include "core/dom/NodeRenderStyle.h" 45 #include "core/dom/NodeRenderStyle.h"
45 #include "core/frame/FrameHost.h" 46 #include "core/frame/FrameHost.h"
46 #include "core/frame/FrameView.h" 47 #include "core/frame/FrameView.h"
47 #include "core/frame/LocalFrame.h" 48 #include "core/frame/LocalFrame.h"
48 #include "core/frame/Settings.h" 49 #include "core/frame/Settings.h"
49 #include "core/inspector/InspectorInstrumentation.h" 50 #include "core/inspector/InspectorInstrumentation.h"
50 #include "core/rendering/RenderView.h" 51 #include "core/rendering/RenderView.h"
51 #include "core/rendering/compositing/RenderLayerCompositor.h" 52 #include "core/rendering/compositing/RenderLayerCompositor.h"
52 #include "core/rendering/style/RenderStyle.h" 53 #include "core/rendering/style/RenderStyle.h"
53 #include "platform/PlatformScreen.h" 54 #include "platform/PlatformScreen.h"
54 #include "platform/geometry/FloatRect.h" 55 #include "platform/geometry/FloatRect.h"
55 #include "wtf/HashMap.h" 56 #include "wtf/HashMap.h"
56 57
57 namespace WebCore { 58 namespace WebCore {
58 59
59 using namespace MediaFeatureNames; 60 using namespace MediaFeatureNames;
60 61
61 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; 62 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix };
62 63
63 typedef bool (*EvalFunc)(CSSValue*, RenderStyle*, LocalFrame*, MediaFeaturePrefi x); 64 typedef bool (*EvalFunc)(CSSValue*, MediaFeaturePrefix, const MediaValues&);
64 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; 65 typedef HashMap<StringImpl*, EvalFunc> FunctionMap;
65 static FunctionMap* gFunctionMap; 66 static FunctionMap* gFunctionMap;
66 67
67 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) 68 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
68 : m_frame(0) 69 : m_expectedResult(mediaFeatureResult)
69 , m_style(nullptr)
70 , m_expResult(mediaFeatureResult)
71 { 70 {
72 } 71 }
73 72
74 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult) 73 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult)
75 : m_mediaType(acceptedMediaType) 74 : m_mediaType(acceptedMediaType)
76 , m_frame(0) 75 , m_expectedResult(mediaFeatureResult)
77 , m_style(nullptr)
78 , m_expResult(mediaFeatureResult)
79 { 76 {
80 } 77 }
81 78
82 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) 79 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult)
83 : m_mediaType(acceptedMediaType) 80 : m_mediaType(acceptedMediaType)
84 , m_frame(0) 81 , m_expectedResult(mediaFeatureResult)
85 , m_style(nullptr)
86 , m_expResult(mediaFeatureResult)
87 { 82 {
88 } 83 }
89 84
90 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame, RenderStyle* style) 85 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame, RenderStyle* style)
91 : m_mediaType(acceptedMediaType) 86 : m_mediaType(acceptedMediaType)
92 , m_frame(frame) 87 , m_expectedResult(false) // Doesn't matter when we have m_frame and m_style .
93 , m_style(style) 88 , m_mediaValues(MediaValues::create(frame, style, MediaValues::DynamicMode))
94 , m_expResult(false) // Doesn't matter when we have m_frame and m_style.
95 { 89 {
96 } 90 }
97 91
92 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues& mediaValues)
93 : m_mediaType(acceptedMediaType)
94 , m_expectedResult(false) // Doesn't matter when we have mediaValues.
95 , m_mediaValues(mediaValues.copy())
96 {
97 }
98
98 MediaQueryEvaluator::~MediaQueryEvaluator() 99 MediaQueryEvaluator::~MediaQueryEvaluator()
99 { 100 {
100 } 101 }
101 102
102 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const 103 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
103 { 104 {
104 return mediaTypeToMatch.isEmpty() 105 return mediaTypeToMatch.isEmpty()
105 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) 106 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)
106 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); 107 || equalIgnoringCase(mediaTypeToMatch, m_mediaType);
107 } 108 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 for (; j < expressions.size(); ++j) { 142 for (; j < expressions.size(); ++j) {
142 bool exprResult = eval(expressions.at(j).get()); 143 bool exprResult = eval(expressions.at(j).get());
143 if (viewportDependentMediaQueryResults && expressions.at(j)->isV iewportDependent()) 144 if (viewportDependentMediaQueryResults && expressions.at(j)->isV iewportDependent())
144 viewportDependentMediaQueryResults->append(adoptRefWillBeNoo p(new MediaQueryResult(*expressions.at(j), exprResult))); 145 viewportDependentMediaQueryResults->append(adoptRefWillBeNoo p(new MediaQueryResult(*expressions.at(j), exprResult)));
145 if (!exprResult) 146 if (!exprResult)
146 break; 147 break;
147 } 148 }
148 149
149 // Assume true if we are at the end of the list, otherwise assume fa lse. 150 // Assume true if we are at the end of the list, otherwise assume fa lse.
150 result = applyRestrictor(query->restrictor(), expressions.size() == j); 151 result = applyRestrictor(query->restrictor(), expressions.size() == j);
151 } else 152 } else {
152 result = applyRestrictor(query->restrictor(), false); 153 result = applyRestrictor(query->restrictor(), false);
154 }
153 } 155 }
154 156
155 return result; 157 return result;
156 } 158 }
157 159
158 template<typename T> 160 template<typename T>
159 bool compareValue(T a, T b, MediaFeaturePrefix op) 161 bool compareValue(T a, T b, MediaFeaturePrefix op)
160 { 162 {
161 switch (op) { 163 switch (op) {
162 case MinPrefix: 164 case MinPrefix:
(...skipping 19 matching lines...) Expand all
182 static bool numberValue(CSSValue* value, float& result) 184 static bool numberValue(CSSValue* value, float& result)
183 { 185 {
184 if (value->isPrimitiveValue() 186 if (value->isPrimitiveValue()
185 && toCSSPrimitiveValue(value)->isNumber()) { 187 && toCSSPrimitiveValue(value)->isNumber()) {
186 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS S_NUMBER); 188 result = toCSSPrimitiveValue(value)->getFloatValue(CSSPrimitiveValue::CS S_NUMBER);
187 return true; 189 return true;
188 } 190 }
189 return false; 191 return false;
190 } 192 }
191 193
192 static bool colorMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fra me, MediaFeaturePrefix op) 194 static bool colorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
193 { 195 {
194 int bitsPerComponent = screenDepthPerComponent(frame->view());
195 float number; 196 float number;
197 int bitsPerComponent = mediaValues.colorBitsPerComponent();
196 if (value) 198 if (value)
197 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op); 199 return numberValue(value, number) && compareValue(bitsPerComponent, stat ic_cast<int>(number), op);
198 200
199 return bitsPerComponent != 0; 201 return bitsPerComponent != 0;
200 } 202 }
201 203
202 static bool colorIndexMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame *, MediaFeaturePrefix op) 204 static bool colorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues&)
203 { 205 {
204 // FIXME: We currently assume that we do not support indexed displays, as it is unknown 206 // FIXME: We currently assume that we do not support indexed displays, as it is unknown
205 // how to retrieve the information if the display mode is indexed. This matc hes Firefox. 207 // how to retrieve the information if the display mode is indexed. This matc hes Firefox.
206 if (!value) 208 if (!value)
207 return false; 209 return false;
208 210
209 // Acording to spec, if the device does not use a color lookup table, the va lue is zero. 211 // Acording to spec, if the device does not use a color lookup table, the va lue is zero.
210 float number; 212 float number;
211 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op); 213 return numberValue(value, number) && compareValue(0, static_cast<int>(number ), op);
212 } 214 }
213 215
214 static bool monochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, Loca lFrame* frame, MediaFeaturePrefix op) 216 static bool monochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& mediaValues)
215 { 217 {
216 if (!screenIsMonochrome(frame->view())) { 218 if (!mediaValues.monochromeBitsPerComponent()) {
217 if (value) { 219 if (value) {
218 float number; 220 float number;
219 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op); 221 return numberValue(value, number) && compareValue(0, static_cast<int >(number), op);
220 } 222 }
221 return false; 223 return false;
222 } 224 }
223 225
224 return colorMediaFeatureEval(value, style, frame, op); 226 return colorMediaFeatureEval(value, op, mediaValues);
225 } 227 }
226 228
227 static IntSize viewportSize(FrameView* view) 229 static bool orientationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, con st MediaValues& mediaValues)
228 { 230 {
229 return view->layoutSize(IncludeScrollbars); 231 int width = mediaValues.viewportWidth();
230 } 232 int height = mediaValues.viewportHeight();
231 233
232 static bool orientationMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix)
233 {
234 FrameView* view = frame->view();
235 int width = viewportSize(view).width();
236 int height = viewportSize(view).height();
237 if (value && value->isPrimitiveValue()) { 234 if (value && value->isPrimitiveValue()) {
238 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); 235 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID();
239 if (width > height) // Square viewport is portrait. 236 if (width > height) // Square viewport is portrait.
240 return CSSValueLandscape == id; 237 return CSSValueLandscape == id;
241 return CSSValuePortrait == id; 238 return CSSValuePortrait == id;
242 } 239 }
243 240
244 // Expression (orientation) evaluates to true if width and height >= 0. 241 // Expression (orientation) evaluates to true if width and height >= 0.
245 return height >= 0 && width >= 0; 242 return height >= 0 && width >= 0;
246 } 243 }
247 244
248 static bool aspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) 245 static bool aspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
249 { 246 {
250 if (value) { 247 if (value)
251 FrameView* view = frame->view(); 248 return compareAspectRatioValue(value, mediaValues.viewportWidth(), media Values.viewportHeight(), op);
252 return compareAspectRatioValue(value, viewportSize(view).width(), viewpo rtSize(view).height(), op);
253 }
254 249
255 // ({,min-,max-}aspect-ratio) 250 // ({,min-,max-}aspect-ratio)
256 // assume if we have a device, its aspect ratio is non-zero. 251 // assume if we have a device, its aspect ratio is non-zero.
257 return true; 252 return true;
258 } 253 }
259 254
260 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle*, Loc alFrame* frame, MediaFeaturePrefix op) 255 static bool deviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefi x op, const MediaValues& mediaValues)
261 { 256 {
262 if (value) { 257 if (value)
263 FloatRect sg = screenRect(frame->view()); 258 return compareAspectRatioValue(value, mediaValues.deviceWidth(), mediaVa lues.deviceHeight(), op);
264 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat ic_cast<int>(sg.height()), op);
265 }
266 259
267 // ({,min-,max-}device-aspect-ratio) 260 // ({,min-,max-}device-aspect-ratio)
268 // assume if we have a device, its aspect ratio is non-zero. 261 // assume if we have a device, its aspect ratio is non-zero.
269 return true; 262 return true;
270 } 263 }
271 264
272 static bool evalResolution(CSSValue* value, LocalFrame* frame, MediaFeaturePrefi x op) 265 static bool evalResolution(CSSValue* value, MediaFeaturePrefix op, const MediaVa lues& mediaValues)
273 { 266 {
274 // According to MQ4, only 'screen', 'print' and 'speech' may match. 267 // According to MQ4, only 'screen', 'print' and 'speech' may match.
275 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 268 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348
276 float actualResolution = 0; 269 float actualResolution = 0;
277 270
278 // This checks the actual media type applied to the document, and we know 271 // This checks the actual media type applied to the document, and we know
279 // this method only got called if this media type matches the one defined 272 // this method only got called if this media type matches the one defined
280 // in the query. Thus, if if the document's media type is "print", the 273 // in the query. Thus, if if the document's media type is "print", the
281 // media type of the query will either be "print" or "all". 274 // media type of the query will either be "print" or "all".
282 String mediaType = frame->view()->mediaType(); 275 if (mediaValues.screenMediaType()) {
283 if (equalIgnoringCase(mediaType, "screen")) 276 actualResolution = clampTo<float>(mediaValues.devicePixelRatio());
284 actualResolution = clampTo<float>(frame->devicePixelRatio()); 277 } else if (mediaValues.printMediaType()) {
285 else if (equalIgnoringCase(mediaType, "print")) {
286 // The resolution of images while printing should not depend on the DPI 278 // The resolution of images while printing should not depend on the DPI
287 // of the screen. Until we support proper ways of querying this info 279 // of the screen. Until we support proper ways of querying this info
288 // we use 300px which is considered minimum for current printers. 280 // we use 300px which is considered minimum for current printers.
289 actualResolution = 300 / cssPixelsPerInch; 281 actualResolution = 300 / cssPixelsPerInch;
290 } 282 }
291 283
292 if (!value) 284 if (!value)
293 return !!actualResolution; 285 return !!actualResolution;
294 286
295 if (!value->isPrimitiveValue()) 287 if (!value->isPrimitiveValue())
(...skipping 14 matching lines...) Expand all
310 // approximates the reference pixel". With that in mind, allowing 2 deci mal 302 // approximates the reference pixel". With that in mind, allowing 2 deci mal
311 // point precision seems appropriate. 303 // point precision seems appropriate.
312 return compareValue( 304 return compareValue(
313 floorf(0.5 + 100 * actualResolution) / 100, 305 floorf(0.5 + 100 * actualResolution) / 100,
314 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op); 306 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op);
315 } 307 }
316 308
317 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op); 309 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op);
318 } 310 }
319 311
320 static bool devicePixelRatioMediaFeatureEval(CSSValue *value, RenderStyle*, Loca lFrame* frame, MediaFeaturePrefix op) 312 static bool devicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
321 { 313 {
322 UseCounter::count(frame->document(), UseCounter::PrefixedDevicePixelRatioMed iaFeature); 314 UseCounter::count(mediaValues.document(), UseCounter::PrefixedDevicePixelRat ioMediaFeature);
323 315
324 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, frame, op); 316 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, op, mediaValues);
325 } 317 }
326 318
327 static bool resolutionMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame * frame, MediaFeaturePrefix op) 319 static bool resolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, c onst MediaValues& MediaValues)
328 { 320 {
329 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, frame, op); 321 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, op, MediaValues);
330 } 322 }
331 323
332 static bool gridMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame*, Med iaFeaturePrefix op) 324 static bool gridMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const M ediaValues&)
333 { 325 {
334 // if output device is bitmap, grid: 0 == true 326 // if output device is bitmap, grid: 0 == true
335 // assume we have bitmap device 327 // assume we have bitmap device
336 float number; 328 float number;
337 if (value && numberValue(value, number)) 329 if (value && numberValue(value, number))
338 return compareValue(static_cast<int>(number), 0, op); 330 return compareValue(static_cast<int>(number), 0, op);
339 return false; 331 return false;
340 } 332 }
341 333
342 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl e, int& result) 334 static bool computeLengthWithoutStyle(CSSPrimitiveValue* primitiveValue, int def aultFontSize, int& result)
335 {
336 // We're running in a background thread, so RenderStyle is not available.
337 // Nevertheless, we can evaluate length MQs with em, rem or px units.
338 // FIXME: Learn to support more units here, or teach CSSPrimitiveValue about MediaValues.
339 unsigned short type = primitiveValue->primitiveType();
340 int factor = 0;
341 if (type == CSSPrimitiveValue::CSS_EMS || type == CSSPrimitiveValue::CSS_REM S) {
342 if (defaultFontSize > 0)
343 factor = defaultFontSize;
344 else
345 return false;
346 } else if (type == CSSPrimitiveValue::CSS_PX) {
347 factor = 1;
348 } else {
349 return false;
350 }
351 result = roundForImpreciseConversion<int>(primitiveValue->getDoubleValue()*f actor);
352 return true;
353 }
354
355 static bool computeLength(CSSValue* value, bool strict, RenderStyle* initialStyl e, int defaultFontSize, int& result)
343 { 356 {
344 if (!value->isPrimitiveValue()) 357 if (!value->isPrimitiveValue())
345 return false; 358 return false;
346 359
347 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 360 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
348 361
349 if (primitiveValue->isNumber()) { 362 if (primitiveValue->isNumber()) {
350 result = primitiveValue->getIntValue(); 363 result = primitiveValue->getIntValue();
351 return !strict || !result; 364 return !strict || !result;
352 } 365 }
353 366
354 if (primitiveValue->isLength()) { 367 if (primitiveValue->isLength()) {
355 // Relative (like EM) and root relative (like REM) units are always reso lved against 368 if (initialStyle) {
356 // the initial values for media queries, hence the two initialStyle para meters. 369 // Relative (like EM) and root relative (like REM) units are always resolved against
357 // FIXME: We need to plumb viewport unit support down to here. 370 // the initial values for media queries, hence the two initialStyle parameters.
358 result = primitiveValue->computeLength<int>(CSSToLengthConversionData(in itialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */)); 371 // FIXME: We need to plumb viewport unit support down to here.
372 result = primitiveValue->computeLength<int>(CSSToLengthConversionDat a(initialStyle, initialStyle, 0, 1.0 /* zoom */, true /* computingFontSize */));
373 } else {
374 return computeLengthWithoutStyle(primitiveValue, defaultFontSize, re sult);
375 }
359 return true; 376 return true;
360 } 377 }
361 378
362 return false; 379 return false;
363 } 380 }
364 381
365 static bool deviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Lo calFrame* frame, MediaFeaturePrefix op) 382 static bool deviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
366 { 383 {
367 if (value) { 384 if (value) {
368 int length; 385 int length;
369 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len gth)) 386 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length)
370 return false; 387 && compareValue(static_cast<int>(mediaValues.deviceHeight()), length , op);
371 int height = static_cast<int>(screenRect(frame->view()).height());
372 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk())
373 height = lroundf(height * frame->host()->deviceScaleFactor());
374 return compareValue(height, length, op);
375 } 388 }
376 // ({,min-,max-}device-height) 389 // ({,min-,max-}device-height)
377 // assume if we have a device, assume non-zero 390 // assume if we have a device, assume non-zero
378 return true; 391 return true;
379 } 392 }
380 393
381 static bool deviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, Loc alFrame* frame, MediaFeaturePrefix op) 394 static bool deviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
382 { 395 {
383 if (value) { 396 if (value) {
384 int length; 397 int length;
385 if (!computeLength(value, !frame->document()->inQuirksMode(), style, len gth)) 398 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length)
386 return false; 399 && compareValue(static_cast<int>(mediaValues.deviceWidth()), length, op);
387 int width = static_cast<int>(screenRect(frame->view()).width());
388 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk())
389 width = lroundf(width * frame->host()->deviceScaleFactor());
390 return compareValue(width, length, op);
391 } 400 }
392 // ({,min-,max-}device-width) 401 // ({,min-,max-}device-width)
393 // assume if we have a device, assume non-zero 402 // assume if we have a device, assume non-zero
394 return true; 403 return true;
395 } 404 }
396 405
397 static bool heightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFra me* frame, MediaFeaturePrefix op) 406 static bool heightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
398 { 407 {
399 FrameView* view = frame->view(); 408 int height = mediaValues.viewportHeight();
400
401 int height = viewportSize(view).height();
402 if (value) { 409 if (value) {
403 if (RenderView* renderView = frame->document()->renderView())
404 height = adjustForAbsoluteZoom(height, renderView);
405 int length; 410 int length;
406 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(height, length, op); 411 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length)
412 && compareValue(height, length, op);
407 } 413 }
408 414
409 return height; 415 return height;
410 } 416 }
411 417
412 static bool widthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFram e* frame, MediaFeaturePrefix op) 418 static bool widthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
413 { 419 {
414 FrameView* view = frame->view(); 420 int width = mediaValues.viewportWidth();
415
416 int width = viewportSize(view).width();
417 if (value) { 421 if (value) {
418 if (RenderView* renderView = frame->document()->renderView())
419 width = adjustForAbsoluteZoom(width, renderView);
420 int length; 422 int length;
421 return computeLength(value, !frame->document()->inQuirksMode(), style, l ength) && compareValue(width, length, op); 423 return computeLength(value, mediaValues.strictMode(), mediaValues.style( ), mediaValues.defaultFontSize(), length)
424 && compareValue(width, length, op);
422 } 425 }
423 426
424 return width; 427 return width;
425 } 428 }
426 429
427 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used. 430 // Rest of the functions are trampolines which set the prefix according to the m edia feature expression used.
428 431
429 static bool minColorMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) 432 static bool minColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
430 { 433 {
431 return colorMediaFeatureEval(value, style, frame, MinPrefix); 434 return colorMediaFeatureEval(value, MinPrefix, mediaValues);
432 } 435 }
433 436
434 static bool maxColorMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) 437 static bool maxColorMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
435 { 438 {
436 return colorMediaFeatureEval(value, style, frame, MaxPrefix); 439 return colorMediaFeatureEval(value, MaxPrefix, mediaValues);
437 } 440 }
438 441
439 static bool minColorIndexMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 442 static bool minColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
440 { 443 {
441 return colorIndexMediaFeatureEval(value, style, frame, MinPrefix); 444 return colorIndexMediaFeatureEval(value, MinPrefix, mediaValues);
442 } 445 }
443 446
444 static bool maxColorIndexMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 447 static bool maxColorIndexMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
445 { 448 {
446 return colorIndexMediaFeatureEval(value, style, frame, MaxPrefix); 449 return colorIndexMediaFeatureEval(value, MaxPrefix, mediaValues);
447 } 450 }
448 451
449 static bool minMonochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 452 static bool minMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
450 { 453 {
451 return monochromeMediaFeatureEval(value, style, frame, MinPrefix); 454 return monochromeMediaFeatureEval(value, MinPrefix, mediaValues);
452 } 455 }
453 456
454 static bool maxMonochromeMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 457 static bool maxMonochromeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
455 { 458 {
456 return monochromeMediaFeatureEval(value, style, frame, MaxPrefix); 459 return monochromeMediaFeatureEval(value, MaxPrefix, mediaValues);
457 } 460 }
458 461
459 static bool minAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 462 static bool minAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
460 { 463 {
461 return aspectRatioMediaFeatureEval(value, style, frame, MinPrefix); 464 return aspectRatioMediaFeatureEval(value, MinPrefix, mediaValues);
462 } 465 }
463 466
464 static bool maxAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 467 static bool maxAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
465 { 468 {
466 return aspectRatioMediaFeatureEval(value, style, frame, MaxPrefix); 469 return aspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
467 } 470 }
468 471
469 static bool minDeviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* s tyle, LocalFrame* frame, MediaFeaturePrefix) 472 static bool minDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues)
470 { 473 {
471 return deviceAspectRatioMediaFeatureEval(value, style, frame, MinPrefix); 474 return deviceAspectRatioMediaFeatureEval(value, MinPrefix, mediaValues);
472 } 475 }
473 476
474 static bool maxDeviceAspectRatioMediaFeatureEval(CSSValue* value, RenderStyle* s tyle, LocalFrame* frame, MediaFeaturePrefix) 477 static bool maxDeviceAspectRatioMediaFeatureEval(CSSValue* value, MediaFeaturePr efix, const MediaValues& mediaValues)
475 { 478 {
476 return deviceAspectRatioMediaFeatureEval(value, style, frame, MaxPrefix); 479 return deviceAspectRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
477 } 480 }
478 481
479 static bool minDevicePixelRatioMediaFeatureEval(CSSValue* value, RenderStyle* st yle, LocalFrame* frame, MediaFeaturePrefix) 482 static bool minDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues)
480 { 483 {
481 UseCounter::count(frame->document(), UseCounter::PrefixedMinDevicePixelRatio MediaFeature); 484 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMinDevicePixel RatioMediaFeature);
482 485
483 return devicePixelRatioMediaFeatureEval(value, style, frame, MinPrefix); 486 return devicePixelRatioMediaFeatureEval(value, MinPrefix, mediaValues);
484 } 487 }
485 488
486 static bool maxDevicePixelRatioMediaFeatureEval(CSSValue* value, RenderStyle* st yle, LocalFrame* frame, MediaFeaturePrefix) 489 static bool maxDevicePixelRatioMediaFeatureEval(CSSValue* value, MediaFeaturePre fix, const MediaValues& mediaValues)
487 { 490 {
488 UseCounter::count(frame->document(), UseCounter::PrefixedMaxDevicePixelRatio MediaFeature); 491 UseCounter::count(mediaValues.document(), UseCounter::PrefixedMaxDevicePixel RatioMediaFeature);
489 492
490 return devicePixelRatioMediaFeatureEval(value, style, frame, MaxPrefix); 493 return devicePixelRatioMediaFeatureEval(value, MaxPrefix, mediaValues);
491 } 494 }
492 495
493 static bool minHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Local Frame* frame, MediaFeaturePrefix) 496 static bool minHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
494 { 497 {
495 return heightMediaFeatureEval(value, style, frame, MinPrefix); 498 return heightMediaFeatureEval(value, MinPrefix, mediaValues);
496 } 499 }
497 500
498 static bool maxHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, Local Frame* frame, MediaFeaturePrefix) 501 static bool maxHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
499 { 502 {
500 return heightMediaFeatureEval(value, style, frame, MaxPrefix); 503 return heightMediaFeatureEval(value, MaxPrefix, mediaValues);
501 } 504 }
502 505
503 static bool minWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) 506 static bool minWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
504 { 507 {
505 return widthMediaFeatureEval(value, style, frame, MinPrefix); 508 return widthMediaFeatureEval(value, MinPrefix, mediaValues);
506 } 509 }
507 510
508 static bool maxWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalF rame* frame, MediaFeaturePrefix) 511 static bool maxWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
509 { 512 {
510 return widthMediaFeatureEval(value, style, frame, MaxPrefix); 513 return widthMediaFeatureEval(value, MaxPrefix, mediaValues);
511 } 514 }
512 515
513 static bool minDeviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 516 static bool minDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
514 { 517 {
515 return deviceHeightMediaFeatureEval(value, style, frame, MinPrefix); 518 return deviceHeightMediaFeatureEval(value, MinPrefix, mediaValues);
516 } 519 }
517 520
518 static bool maxDeviceHeightMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 521 static bool maxDeviceHeightMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
519 { 522 {
520 return deviceHeightMediaFeatureEval(value, style, frame, MaxPrefix); 523 return deviceHeightMediaFeatureEval(value, MaxPrefix, mediaValues);
521 } 524 }
522 525
523 static bool minDeviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 526 static bool minDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
524 { 527 {
525 return deviceWidthMediaFeatureEval(value, style, frame, MinPrefix); 528 return deviceWidthMediaFeatureEval(value, MinPrefix, mediaValues);
526 } 529 }
527 530
528 static bool maxDeviceWidthMediaFeatureEval(CSSValue* value, RenderStyle* style, LocalFrame* frame, MediaFeaturePrefix) 531 static bool maxDeviceWidthMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
529 { 532 {
530 return deviceWidthMediaFeatureEval(value, style, frame, MaxPrefix); 533 return deviceWidthMediaFeatureEval(value, MaxPrefix, mediaValues);
531 } 534 }
532 535
533 static bool minResolutionMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 536 static bool minResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
534 { 537 {
535 return resolutionMediaFeatureEval(value, style, frame, MinPrefix); 538 return resolutionMediaFeatureEval(value, MinPrefix, mediaValues);
536 } 539 }
537 540
538 static bool maxResolutionMediaFeatureEval(CSSValue* value, RenderStyle* style, L ocalFrame* frame, MediaFeaturePrefix) 541 static bool maxResolutionMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, c onst MediaValues& mediaValues)
539 { 542 {
540 return resolutionMediaFeatureEval(value, style, frame, MaxPrefix); 543 return resolutionMediaFeatureEval(value, MaxPrefix, mediaValues);
541 } 544 }
542 545
543 static bool animationMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* frame, MediaFeaturePrefix op) 546 static bool animationMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, co nst MediaValues& mediaValues)
544 { 547 {
545 UseCounter::count(frame->document(), UseCounter::PrefixedAnimationMediaFeatu re); 548 UseCounter::count(mediaValues.document(), UseCounter::PrefixedAnimationMedia Feature);
546 549
547 if (value) { 550 if (value) {
548 float number; 551 float number;
549 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); 552 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op);
550 } 553 }
551 return true; 554 return true;
552 } 555 }
553 556
554 static bool transform2dMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) 557 static bool transform2dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
555 { 558 {
556 UseCounter::count(frame->document(), UseCounter::PrefixedTransform2dMediaFea ture); 559 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform2dMed iaFeature);
557 560
558 if (value) { 561 if (value) {
559 float number; 562 float number;
560 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op); 563 return numberValue(value, number) && compareValue(1, static_cast<int>(nu mber), op);
561 } 564 }
562 return true; 565 return true;
563 } 566 }
564 567
565 static bool transform3dMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFram e* frame, MediaFeaturePrefix op) 568 static bool transform3dMediaFeatureEval(CSSValue* value, MediaFeaturePrefix op, const MediaValues& mediaValues)
566 { 569 {
567 UseCounter::count(frame->document(), UseCounter::PrefixedTransform3dMediaFea ture); 570 UseCounter::count(mediaValues.document(), UseCounter::PrefixedTransform3dMed iaFeature);
568 571
569 bool returnValueIfNoParameter; 572 bool returnValueIfNoParameter;
570 int have3dRendering; 573 int have3dRendering;
571 574
572 bool threeDEnabled = false; 575 bool threeDEnabled = mediaValues.threeDEnabled();
573 if (RenderView* view = frame->contentRenderer())
574 threeDEnabled = view->compositor()->canRender3DTransforms();
575 576
576 returnValueIfNoParameter = threeDEnabled; 577 returnValueIfNoParameter = threeDEnabled;
577 have3dRendering = threeDEnabled ? 1 : 0; 578 have3dRendering = threeDEnabled ? 1 : 0;
578 579
579 if (value) { 580 if (value) {
580 float number; 581 float number;
581 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op); 582 return numberValue(value, number) && compareValue(have3dRendering, stati c_cast<int>(number), op);
582 } 583 }
583 return returnValueIfNoParameter; 584 return returnValueIfNoParameter;
584 } 585 }
585 586
586 static bool viewModeMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* frame, MediaFeaturePrefix) 587 static bool viewModeMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const MediaValues& mediaValues)
587 { 588 {
588 UseCounter::count(frame->document(), UseCounter::PrefixedViewModeMediaFeatur e); 589 UseCounter::count(mediaValues.document(), UseCounter::PrefixedViewModeMediaF eature);
589 590
590 if (!value) 591 if (!value)
591 return true; 592 return true;
592 593
593 return toCSSPrimitiveValue(value)->getValueID() == CSSValueWindowed; 594 return toCSSPrimitiveValue(value)->getValueID() == CSSValueWindowed;
594 } 595 }
595 596
596 enum PointerDeviceType { TouchPointer, MousePointer, NoPointer, UnknownPointer } ; 597 static bool hoverMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Med iaValues& mediaValues)
597
598 static PointerDeviceType leastCapablePrimaryPointerDeviceType(LocalFrame* frame)
599 { 598 {
600 if (frame->settings()->deviceSupportsTouch()) 599 MediaValues::PointerDeviceType pointer = mediaValues.pointer();
601 return TouchPointer;
602
603 // FIXME: We should also try to determine if we know we have a mouse.
604 // When we do this, we'll also need to differentiate between known not to
605 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer).
606 // We could also take into account other preferences like accessibility
607 // settings to decide which of the available pointers should be considered
608 // "primary".
609
610 return UnknownPointer;
611 }
612
613 static bool hoverMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fra me, MediaFeaturePrefix)
614 {
615 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame);
616 600
617 // If we're on a port that hasn't explicitly opted into providing pointer de vice information 601 // If we're on a port that hasn't explicitly opted into providing pointer de vice information
618 // (or otherwise can't be confident in the pointer hardware available), then behave exactly 602 // (or otherwise can't be confident in the pointer hardware available), then behave exactly
619 // as if this feature feature isn't supported. 603 // as if this feature feature isn't supported.
620 if (pointer == UnknownPointer) 604 if (pointer == MediaValues::UnknownPointer)
621 return false; 605 return false;
622 606
623 float number = 1; 607 float number = 1;
624 if (value) { 608 if (value) {
625 if (!numberValue(value, number)) 609 if (!numberValue(value, number))
626 return false; 610 return false;
627 } 611 }
628 612
629 return (pointer == NoPointer && !number) 613 return (pointer == MediaValues::NoPointer && !number)
630 || (pointer == TouchPointer && !number) 614 || (pointer == MediaValues::TouchPointer && !number)
631 || (pointer == MousePointer && number == 1); 615 || (pointer == MediaValues::MousePointer && number == 1);
632 } 616 }
633 617
634 static bool pointerMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* f rame, MediaFeaturePrefix) 618 static bool pointerMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const M ediaValues& mediaValues)
635 { 619 {
636 PointerDeviceType pointer = leastCapablePrimaryPointerDeviceType(frame); 620 MediaValues::PointerDeviceType pointer = mediaValues.pointer();
637 621
638 // If we're on a port that hasn't explicitly opted into providing pointer de vice information 622 // If we're on a port that hasn't explicitly opted into providing pointer de vice information
639 // (or otherwise can't be confident in the pointer hardware available), then behave exactly 623 // (or otherwise can't be confident in the pointer hardware available), then behave exactly
640 // as if this feature feature isn't supported. 624 // as if this feature feature isn't supported.
641 if (pointer == UnknownPointer) 625 if (pointer == MediaValues::UnknownPointer)
642 return false; 626 return false;
643 627
644 if (!value) 628 if (!value)
645 return pointer != NoPointer; 629 return pointer != MediaValues::NoPointer;
646 630
647 if (!value->isPrimitiveValue()) 631 if (!value->isPrimitiveValue())
648 return false; 632 return false;
649 633
650 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID(); 634 const CSSValueID id = toCSSPrimitiveValue(value)->getValueID();
651 return (pointer == NoPointer && id == CSSValueNone) 635 return (pointer == MediaValues::NoPointer && id == CSSValueNone)
652 || (pointer == TouchPointer && id == CSSValueCoarse) 636 || (pointer == MediaValues::TouchPointer && id == CSSValueCoarse)
653 || (pointer == MousePointer && id == CSSValueFine); 637 || (pointer == MediaValues::MousePointer && id == CSSValueFine);
654 } 638 }
655 639
656 static bool scanMediaFeatureEval(CSSValue* value, RenderStyle*, LocalFrame* fram e, MediaFeaturePrefix) 640 static bool scanMediaFeatureEval(CSSValue* value, MediaFeaturePrefix, const Medi aValues& mediaValues)
657 { 641 {
658 // Scan only applies to 'tv' media. 642 if (!mediaValues.scanMediaType())
659 if (!equalIgnoringCase(frame->view()->mediaType(), "tv"))
660 return false; 643 return false;
661 644
662 if (!value) 645 if (!value)
663 return true; 646 return true;
664 647
665 if (!value->isPrimitiveValue()) 648 if (!value->isPrimitiveValue())
666 return false; 649 return false;
667 650
668 // If a platform interface supplies progressive/interlace info for TVs in th e 651 // If a platform interface supplies progressive/interlace info for TVs in th e
669 // future, it needs to be handled here. For now, assume a modern TV with 652 // future, it needs to be handled here. For now, assume a modern TV with
670 // progressive display. 653 // progressive display.
671 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive; 654 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive;
672 } 655 }
673 656
674 static void createFunctionMap() 657 static void createFunctionMap()
675 { 658 {
676 // Create the table. 659 // Create the table.
677 gFunctionMap = new FunctionMap; 660 gFunctionMap = new FunctionMap;
678 #define ADD_TO_FUNCTIONMAP(name) \ 661 #define ADD_TO_FUNCTIONMAP(name) \
679 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); 662 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
680 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); 663 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
681 #undef ADD_TO_FUNCTIONMAP 664 #undef ADD_TO_FUNCTIONMAP
682 } 665 }
683 666
684 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const 667 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
685 { 668 {
686 if (!m_frame || !m_style) 669 if (!m_mediaValues)
687 return m_expResult; 670 return m_expectedResult;
688 671
689 if (!gFunctionMap) 672 if (!gFunctionMap)
690 createFunctionMap(); 673 createFunctionMap();
691 674
692 // Call the media feature evaluation function. Assume no prefix and let 675 // Call the media feature evaluation function. Assume no prefix and let
693 // trampoline functions override the prefix if prefix is used. 676 // trampoline functions override the prefix if prefix is used.
694 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 677 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
695 if (func) 678 if (func)
696 return func(expr->value(), m_style.get(), m_frame, NoPrefix); 679 return func(expr->value(), NoPrefix, *m_mediaValues);
697 680
698 return false; 681 return false;
699 } 682 }
700 683
701 } // namespace 684 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/MediaQueryEvaluator.h ('k') | Source/core/css/MediaQueryEvaluatorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698