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

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

Issue 23192002: Let page zoom affect resolution and -webkit-device-pixel-ratio MQs. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat ic_cast<int>(sg.height()), op); 265 return compareAspectRatioValue(value, static_cast<int>(sg.width()), stat ic_cast<int>(sg.height()), op);
266 } 266 }
267 267
268 // ({,min-,max-}device-aspect-ratio) 268 // ({,min-,max-}device-aspect-ratio)
269 // assume if we have a device, its aspect ratio is non-zero 269 // assume if we have a device, its aspect ratio is non-zero
270 return true; 270 return true;
271 } 271 }
272 272
273 static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op) 273 static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op)
274 { 274 {
275 // FIXME: Possible handle other media types than 'screen' and 'print'. 275 // FIXME: Possibly handle other media types than 'screen' and 'print'.
276 float deviceScaleFactor = 0; 276 float actualResolution = 0;
277 277
278 // This checks the actual media type applied to the document, and we know 278 // 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 279 // 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 280 // 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". 281 // media type of the query will either be "print" or "all".
282 String mediaType = frame->view()->mediaType(); 282 String mediaType = frame->view()->mediaType();
283 if (equalIgnoringCase(mediaType, "screen")) 283 if (equalIgnoringCase(mediaType, "screen"))
284 deviceScaleFactor = frame->page()->deviceScaleFactor(); 284 actualResolution = frame->resolutionDPPX();
eae 2013/08/14 15:20:49 Why not use devicePixelRatio directly here?
rune 2013/08/14 15:59:34 Do you mean the one in DOMWindow? It felt more na
285 else if (equalIgnoringCase(mediaType, "print")) { 285 else if (equalIgnoringCase(mediaType, "print")) {
286 // The resolution of images while printing should not depend on the DPI 286 // 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 287 // of the screen. Until we support proper ways of querying this info
288 // we use 300px which is considered minimum for current printers. 288 // we use 300px which is considered minimum for current printers.
289 deviceScaleFactor = 300 / cssPixelsPerInch; 289 actualResolution = 300 / cssPixelsPerInch;
290 } 290 }
291 291
292 if (!value) 292 if (!value)
293 return !!deviceScaleFactor; 293 return !!actualResolution;
294 294
295 if (!value->isPrimitiveValue()) 295 if (!value->isPrimitiveValue())
296 return false; 296 return false;
297 297
298 CSSPrimitiveValue* resolution = toCSSPrimitiveValue(value); 298 CSSPrimitiveValue* resolution = toCSSPrimitiveValue(value);
299 299
300 if (resolution->isNumber()) 300 if (resolution->isNumber())
301 return compareValue(deviceScaleFactor, resolution->getFloatValue(), op); 301 return compareValue(actualResolution, resolution->getFloatValue(), op);
302 302
303 if (!resolution->isResolution()) 303 if (!resolution->isResolution())
304 return false; 304 return false;
305 305
306 if (resolution->isDotsPerCentimeter()) { 306 if (resolution->isDotsPerCentimeter()) {
307 // To match DPCM to DPPX values, we limit to 2 decimal points. 307 // To match DPCM to DPPX values, we limit to 2 decimal points.
308 // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends 308 // The http://dev.w3.org/csswg/css3-values/#absolute-lengths recommends
309 // "that the pixel unit refer to the whole number of device pixels that best 309 // "that the pixel unit refer to the whole number of device pixels that best
310 // approximates the reference pixel". With that in mind, allowing 2 deci mal 310 // approximates the reference pixel". With that in mind, allowing 2 deci mal
311 // point precision seems appropriate. 311 // point precision seems appropriate.
312 return compareValue( 312 return compareValue(
313 floorf(0.5 + 100 * deviceScaleFactor) / 100, 313 floorf(0.5 + 100 * actualResolution) / 100,
314 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op); 314 floorf(0.5 + 100 * resolution->getFloatValue(CSSPrimitiveValue::CSS_ DPPX)) / 100, op);
315 } 315 }
316 316
317 return compareValue(deviceScaleFactor, resolution->getFloatValue(CSSPrimitiv eValue::CSS_DPPX), op); 317 return compareValue(actualResolution, resolution->getFloatValue(CSSPrimitive Value::CSS_DPPX), op);
318 } 318 }
319 319
320 static bool devicePixelRatioMediaFeatureEval(CSSValue *value, RenderStyle*, Fram e* frame, MediaFeaturePrefix op) 320 static bool devicePixelRatioMediaFeatureEval(CSSValue *value, RenderStyle*, Fram e* frame, MediaFeaturePrefix op)
321 { 321 {
322 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, frame, op); 322 return (!value || toCSSPrimitiveValue(value)->isNumber()) && evalResolution( value, frame, op);
323 } 323 }
324 324
325 static bool resolutionMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* fra me, MediaFeaturePrefix op) 325 static bool resolutionMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* fra me, MediaFeaturePrefix op)
326 { 326 {
327 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, frame, op); 327 return (!value || toCSSPrimitiveValue(value)->isResolution()) && evalResolut ion(value, frame, op);
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // and let trampoline functions override the prefix if prefix is 686 // and let trampoline functions override the prefix if prefix is
687 // used 687 // 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698