| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2006, 2010, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2010, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 m_mediaQueries = mediaQueries; | 246 m_mediaQueries = mediaQueries; |
| 247 } | 247 } |
| 248 | 248 |
| 249 void MediaList::trace(Visitor* visitor) | 249 void MediaList::trace(Visitor* visitor) |
| 250 { | 250 { |
| 251 visitor->trace(m_mediaQueries); | 251 visitor->trace(m_mediaQueries); |
| 252 visitor->trace(m_parentStyleSheet); | 252 visitor->trace(m_parentStyleSheet); |
| 253 visitor->trace(m_parentRule); | 253 visitor->trace(m_parentRule); |
| 254 } | 254 } |
| 255 | 255 |
| 256 static void addResolutionWarningMessageToConsole(Document* document, const Strin
g& serializedExpression, const CSSPrimitiveValue* value) | 256 static void addResolutionWarningMessageToConsole(Document* document, const Strin
g& serializedExpression, CSSPrimitiveValue::UnitTypes type) |
| 257 { | 257 { |
| 258 ASSERT(document); | 258 ASSERT(document); |
| 259 ASSERT(value); | |
| 260 | 259 |
| 261 DEFINE_STATIC_LOCAL(String, mediaQueryMessage, ("Consider using 'dppx' units
, as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-p
hysical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%'
of a screen. In media query expression: ")); | 260 DEFINE_STATIC_LOCAL(String, mediaQueryMessage, ("Consider using 'dppx' units
, as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-p
hysical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%'
of a screen. In media query expression: ")); |
| 262 DEFINE_STATIC_LOCAL(String, mediaValueDPI, ("dpi")); | 261 DEFINE_STATIC_LOCAL(String, mediaValueDPI, ("dpi")); |
| 263 DEFINE_STATIC_LOCAL(String, mediaValueDPCM, ("dpcm")); | 262 DEFINE_STATIC_LOCAL(String, mediaValueDPCM, ("dpcm")); |
| 264 DEFINE_STATIC_LOCAL(String, lengthUnitInch, ("inch")); | 263 DEFINE_STATIC_LOCAL(String, lengthUnitInch, ("inch")); |
| 265 DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, ("centimeter")); | 264 DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, ("centimeter")); |
| 266 | 265 |
| 267 StringBuilder message; | 266 StringBuilder message; |
| 268 if (value->isDotsPerInch()) | 267 if (CSSPrimitiveValue::isDotsPerInch(type)) |
| 269 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPI).replace("%lengthUnit%", lengthUnitInch)); | 268 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPI).replace("%lengthUnit%", lengthUnitInch)); |
| 270 else if (value->isDotsPerCentimeter()) | 269 else if (CSSPrimitiveValue::isDotsPerCentimeter(type)) |
| 271 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter)); | 270 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter)); |
| 272 else | 271 else |
| 273 ASSERT_NOT_REACHED(); | 272 ASSERT_NOT_REACHED(); |
| 274 | 273 |
| 275 message.append(serializedExpression); | 274 message.append(serializedExpression); |
| 276 | 275 |
| 277 document->addConsoleMessage(CSSMessageSource, DebugMessageLevel, message.toS
tring()); | 276 document->addConsoleMessage(CSSMessageSource, DebugMessageLevel, message.toS
tring()); |
| 278 } | 277 } |
| 279 | 278 |
| 280 static inline bool isResolutionMediaFeature(const String& mediaFeature) | 279 static inline bool isResolutionMediaFeature(const String& mediaFeature) |
| 281 { | 280 { |
| 282 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | 281 return mediaFeature == MediaFeatureNames::resolutionMediaFeature |
| 283 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | 282 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature |
| 284 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | 283 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; |
| 285 } | 284 } |
| 286 | 285 |
| 287 void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me
diaQuerySet) | 286 void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me
diaQuerySet) |
| 288 { | 287 { |
| 289 if (!mediaQuerySet || !document) | 288 if (!mediaQuerySet || !document) |
| 290 return; | 289 return; |
| 291 | 290 |
| 292 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& mediaQueries = medi
aQuerySet->queryVector(); | 291 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& mediaQueries = medi
aQuerySet->queryVector(); |
| 293 const size_t queryCount = mediaQueries.size(); | 292 const size_t queryCount = mediaQueries.size(); |
| 294 | 293 |
| 295 if (!queryCount) | 294 if (!queryCount) |
| 296 return; | 295 return; |
| 297 | 296 |
| 298 CSSPrimitiveValue* suspiciousValue = 0; | 297 CSSPrimitiveValue::UnitTypes suspiciousType = CSSPrimitiveValue::CSS_UNKNOWN
; |
| 299 bool dotsPerPixelUsed = false; | 298 bool dotsPerPixelUsed = false; |
| 300 for (size_t i = 0; i < queryCount; ++i) { | 299 for (size_t i = 0; i < queryCount; ++i) { |
| 301 const MediaQuery* query = mediaQueries[i].get(); | 300 const MediaQuery* query = mediaQueries[i].get(); |
| 302 if (equalIgnoringCase(query->mediaType(), "print")) | 301 if (equalIgnoringCase(query->mediaType(), "print")) |
| 303 continue; | 302 continue; |
| 304 | 303 |
| 305 const ExpressionHeapVector& expressions = query->expressions(); | 304 const ExpressionHeapVector& expressions = query->expressions(); |
| 306 for (size_t j = 0; j < expressions.size(); ++j) { | 305 for (size_t j = 0; j < expressions.size(); ++j) { |
| 307 const MediaQueryExp* expression = expressions.at(j).get(); | 306 const MediaQueryExp* expression = expressions.at(j).get(); |
| 308 if (isResolutionMediaFeature(expression->mediaFeature())) { | 307 if (isResolutionMediaFeature(expression->mediaFeature())) { |
| 309 CSSValue* cssValue = expression->value(); | 308 MediaQueryExpValue expValue = expression->expValue(); |
| 310 if (cssValue && cssValue->isPrimitiveValue()) { | 309 if (expValue.isValue) { |
| 311 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssV
alue); | 310 if (CSSPrimitiveValue::isDotsPerPixel(expValue.unit)) |
| 312 if (primitiveValue->isDotsPerPixel()) | |
| 313 dotsPerPixelUsed = true; | 311 dotsPerPixelUsed = true; |
| 314 else if (primitiveValue->isDotsPerInch() || primitiveValue->
isDotsPerCentimeter()) | 312 else if (CSSPrimitiveValue::isDotsPerInch(expValue.unit) ||
CSSPrimitiveValue::isDotsPerCentimeter(expValue.unit)) |
| 315 suspiciousValue = primitiveValue; | 313 suspiciousType = expValue.unit; |
| 316 } | 314 } |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 } | 317 } |
| 320 | 318 |
| 321 if (suspiciousValue && !dotsPerPixelUsed) | 319 if (suspiciousType && !dotsPerPixelUsed) |
| 322 addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(
), suspiciousValue); | 320 addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(
), suspiciousType); |
| 323 } | 321 } |
| 324 | 322 |
| 325 } | 323 } |
| OLD | NEW |