| 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, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 #include "config.h" | 20 #include "config.h" |
| 21 #include "core/css/MediaList.h" | 21 #include "core/css/MediaList.h" |
| 22 | 22 |
| 23 #include "bindings/core/v8/ExceptionState.h" | 23 #include "bindings/core/v8/ExceptionState.h" |
| 24 #include "core/MediaFeatureNames.h" | |
| 25 #include "core/css/CSSStyleSheet.h" | 24 #include "core/css/CSSStyleSheet.h" |
| 26 #include "core/css/MediaQuery.h" | 25 #include "core/css/MediaQuery.h" |
| 27 #include "core/css/MediaQueryExp.h" | 26 #include "core/css/MediaQueryExp.h" |
| 28 #include "core/css/parser/MediaQueryParser.h" | 27 #include "core/css/parser/MediaQueryParser.h" |
| 29 #include "core/dom/Document.h" | |
| 30 #include "core/frame/LocalDOMWindow.h" | |
| 31 #include "core/inspector/ConsoleMessage.h" | |
| 32 #include "wtf/text/StringBuilder.h" | 28 #include "wtf/text/StringBuilder.h" |
| 33 | 29 |
| 34 namespace blink { | 30 namespace blink { |
| 35 | 31 |
| 36 /* MediaList is used to store 3 types of media related entities which mean the s
ame: | 32 /* MediaList is used to store 3 types of media related entities which mean the s
ame: |
| 37 * | 33 * |
| 38 * Media Queries, Media Types and Media Descriptors. | 34 * Media Queries, Media Types and Media Descriptors. |
| 39 * | 35 * |
| 40 * Media queries, as described in the Media Queries Level 3 specification, build
on | 36 * Media queries, as described in the Media Queries Level 3 specification, build
on |
| 41 * the mechanism outlined in HTML4. The syntax of media queries fit into the med
ia | 37 * the mechanism outlined in HTML4. The syntax of media queries fit into the med
ia |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 m_mediaQueries = mediaQueries; | 236 m_mediaQueries = mediaQueries; |
| 241 } | 237 } |
| 242 | 238 |
| 243 void MediaList::trace(Visitor* visitor) | 239 void MediaList::trace(Visitor* visitor) |
| 244 { | 240 { |
| 245 visitor->trace(m_mediaQueries); | 241 visitor->trace(m_mediaQueries); |
| 246 visitor->trace(m_parentStyleSheet); | 242 visitor->trace(m_parentStyleSheet); |
| 247 visitor->trace(m_parentRule); | 243 visitor->trace(m_parentRule); |
| 248 } | 244 } |
| 249 | 245 |
| 250 static void addResolutionWarningMessageToConsole(Document* document, const Strin
g& serializedExpression, CSSPrimitiveValue::UnitType type) | |
| 251 { | |
| 252 ASSERT(document); | |
| 253 | |
| 254 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: ")); | |
| 255 DEFINE_STATIC_LOCAL(String, mediaValueDPI, ("dpi")); | |
| 256 DEFINE_STATIC_LOCAL(String, mediaValueDPCM, ("dpcm")); | |
| 257 DEFINE_STATIC_LOCAL(String, lengthUnitInch, ("inch")); | |
| 258 DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, ("centimeter")); | |
| 259 | |
| 260 StringBuilder message; | |
| 261 if (CSSPrimitiveValue::isDotsPerInch(type)) | |
| 262 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPI).replace("%lengthUnit%", lengthUnitInch)); | |
| 263 else if (CSSPrimitiveValue::isDotsPerCentimeter(type)) | |
| 264 message.append(String(mediaQueryMessage).replace("%replacementUnits%", m
ediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter)); | |
| 265 else | |
| 266 ASSERT_NOT_REACHED(); | |
| 267 | |
| 268 message.append(serializedExpression); | |
| 269 | |
| 270 document->addConsoleMessage(ConsoleMessage::create(CSSMessageSource, DebugMe
ssageLevel, message.toString())); | |
| 271 } | 246 } |
| 272 | |
| 273 static inline bool isResolutionMediaFeature(const String& mediaFeature) | |
| 274 { | |
| 275 return mediaFeature == MediaFeatureNames::resolutionMediaFeature | |
| 276 || mediaFeature == MediaFeatureNames::maxResolutionMediaFeature | |
| 277 || mediaFeature == MediaFeatureNames::minResolutionMediaFeature; | |
| 278 } | |
| 279 | |
| 280 void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me
diaQuerySet) | |
| 281 { | |
| 282 if (!mediaQuerySet || !document) | |
| 283 return; | |
| 284 | |
| 285 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& mediaQueries = medi
aQuerySet->queryVector(); | |
| 286 const size_t queryCount = mediaQueries.size(); | |
| 287 | |
| 288 if (!queryCount) | |
| 289 return; | |
| 290 | |
| 291 CSSPrimitiveValue::UnitType suspiciousType = CSSPrimitiveValue::CSS_UNKNOWN; | |
| 292 bool dotsPerPixelUsed = false; | |
| 293 for (size_t i = 0; i < queryCount; ++i) { | |
| 294 const MediaQuery* query = mediaQueries[i].get(); | |
| 295 if (equalIgnoringCase(query->mediaType(), "print")) | |
| 296 continue; | |
| 297 | |
| 298 const ExpressionHeapVector& expressions = query->expressions(); | |
| 299 for (size_t j = 0; j < expressions.size(); ++j) { | |
| 300 const MediaQueryExp* expression = expressions.at(j).get(); | |
| 301 if (isResolutionMediaFeature(expression->mediaFeature())) { | |
| 302 MediaQueryExpValue expValue = expression->expValue(); | |
| 303 if (expValue.isValue) { | |
| 304 if (CSSPrimitiveValue::isDotsPerPixel(expValue.unit)) | |
| 305 dotsPerPixelUsed = true; | |
| 306 else if (CSSPrimitiveValue::isDotsPerInch(expValue.unit) ||
CSSPrimitiveValue::isDotsPerCentimeter(expValue.unit)) | |
| 307 suspiciousType = expValue.unit; | |
| 308 } | |
| 309 } | |
| 310 } | |
| 311 } | |
| 312 | |
| 313 if (suspiciousType && !dotsPerPixelUsed) | |
| 314 addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(
), suspiciousType); | |
| 315 } | |
| 316 | |
| 317 } | |
| OLD | NEW |