Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 64 |
| 65 typedef bool (*EvalFunc)(const MediaQueryExpValue&, MediaFeaturePrefix, const Me diaValues&); | 65 typedef bool (*EvalFunc)(const MediaQueryExpValue&, MediaFeaturePrefix, const Me diaValues&); |
| 66 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; | 66 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; |
| 67 static FunctionMap* gFunctionMap; | 67 static FunctionMap* gFunctionMap; |
| 68 | 68 |
| 69 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) | 69 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) |
| 70 : m_expectedResult(mediaFeatureResult) | 70 : m_expectedResult(mediaFeatureResult) |
| 71 { | 71 { |
| 72 } | 72 } |
| 73 | 73 |
| 74 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult) | |
| 75 : m_mediaType(acceptedMediaType) | |
| 76 , m_expectedResult(mediaFeatureResult) | |
| 77 { | |
| 78 } | |
| 79 | |
| 80 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) | 74 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) |
| 81 : m_mediaType(acceptedMediaType) | 75 : m_mediaType(acceptedMediaType) |
| 82 , m_expectedResult(mediaFeatureResult) | 76 , m_expectedResult(mediaFeatureResult) |
| 83 { | 77 { |
| 84 } | 78 } |
| 85 | 79 |
| 86 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame) | 80 MediaQueryEvaluator::MediaQueryEvaluator(LocalFrame* frame) |
| 87 : m_mediaType(acceptedMediaType) | 81 : m_expectedResult(false) // Doesn't matter when we have m_frame and m_style . |
| 88 , m_expectedResult(false) // Doesn't matter when we have m_frame and m_style . | |
| 89 , m_mediaValues(MediaValues::createDynamicIfFrameExists(frame)) | 82 , m_mediaValues(MediaValues::createDynamicIfFrameExists(frame)) |
| 90 { | 83 { |
| 91 } | 84 } |
| 92 | 85 |
| 93 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, const MediaValues& mediaValues) | 86 MediaQueryEvaluator::MediaQueryEvaluator(const MediaValues& mediaValues) |
| 94 : m_mediaType(acceptedMediaType) | 87 : m_expectedResult(false) // Doesn't matter when we have mediaValues. |
| 95 , m_expectedResult(false) // Doesn't matter when we have mediaValues. | |
| 96 , m_mediaValues(mediaValues.copy()) | 88 , m_mediaValues(mediaValues.copy()) |
| 97 { | 89 { |
| 98 } | 90 } |
| 99 | 91 |
| 100 MediaQueryEvaluator::~MediaQueryEvaluator() | 92 MediaQueryEvaluator::~MediaQueryEvaluator() |
| 101 { | 93 { |
| 102 } | 94 } |
| 103 | 95 |
| 96 const String MediaQueryEvaluator::mediaType() const | |
| 97 { | |
| 98 if (!m_mediaType.isEmpty()) | |
| 99 return m_mediaType; | |
| 100 if (m_mediaValues.get()) | |
|
esprehn
2014/06/27 08:10:32
You don't need to call .get(), there's an overload
| |
| 101 return m_mediaValues->mediaType(); | |
| 102 return nullAtom; | |
| 103 } | |
| 104 | |
| 104 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const | 105 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const |
| 105 { | 106 { |
| 106 return mediaTypeToMatch.isEmpty() | 107 return mediaTypeToMatch.isEmpty() |
| 107 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) | 108 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) |
| 108 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); | 109 || equalIgnoringCase(mediaTypeToMatch, mediaType()); |
| 109 } | 110 } |
| 110 | 111 |
| 111 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst | 112 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst |
| 112 { | 113 { |
| 113 // Like mediaTypeMatch, but without the special cases for "" and "all". | 114 // Like mediaTypeMatch, but without the special cases for "" and "all". |
| 114 ASSERT(mediaTypeToMatch); | 115 ASSERT(mediaTypeToMatch); |
| 115 ASSERT(mediaTypeToMatch[0] != '\0'); | 116 ASSERT(mediaTypeToMatch[0] != '\0'); |
| 116 ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)); | 117 ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)); |
| 117 return equalIgnoringCase(mediaTypeToMatch, m_mediaType); | 118 return equalIgnoringCase(mediaTypeToMatch, mediaType()); |
| 118 } | 119 } |
| 119 | 120 |
| 120 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) | 121 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) |
| 121 { | 122 { |
| 122 return r == MediaQuery::Not ? !value : value; | 123 return r == MediaQuery::Not ? !value : value; |
| 123 } | 124 } |
| 124 | 125 |
| 125 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const | 126 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const |
| 126 { | 127 { |
| 127 if (!querySet) | 128 if (!querySet) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o p, const MediaValues& mediaValues) | 263 static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o p, const MediaValues& mediaValues) |
| 263 { | 264 { |
| 264 // According to MQ4, only 'screen', 'print' and 'speech' may match. | 265 // According to MQ4, only 'screen', 'print' and 'speech' may match. |
| 265 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 | 266 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348 |
| 266 float actualResolution = 0; | 267 float actualResolution = 0; |
| 267 | 268 |
| 268 // This checks the actual media type applied to the document, and we know | 269 // This checks the actual media type applied to the document, and we know |
| 269 // this method only got called if this media type matches the one defined | 270 // this method only got called if this media type matches the one defined |
| 270 // in the query. Thus, if if the document's media type is "print", the | 271 // in the query. Thus, if if the document's media type is "print", the |
| 271 // media type of the query will either be "print" or "all". | 272 // media type of the query will either be "print" or "all". |
| 272 if (mediaValues.screenMediaType()) { | 273 if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) { |
| 273 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); | 274 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); |
| 274 } else if (mediaValues.printMediaType()) { | 275 } else if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::print) ) { |
| 275 // The resolution of images while printing should not depend on the DPI | 276 // The resolution of images while printing should not depend on the DPI |
| 276 // of the screen. Until we support proper ways of querying this info | 277 // of the screen. Until we support proper ways of querying this info |
| 277 // we use 300px which is considered minimum for current printers. | 278 // we use 300px which is considered minimum for current printers. |
| 278 actualResolution = 300 / cssPixelsPerInch; | 279 actualResolution = 300 / cssPixelsPerInch; |
| 279 } | 280 } |
| 280 | 281 |
| 281 if (!value.isValid()) | 282 if (!value.isValid()) |
| 282 return !!actualResolution; | 283 return !!actualResolution; |
| 283 | 284 |
| 284 if (!value.isValue) | 285 if (!value.isValue) |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 if (!value.isID) | 561 if (!value.isID) |
| 561 return false; | 562 return false; |
| 562 | 563 |
| 563 return (pointer == MediaValues::NoPointer && value.id == CSSValueNone) | 564 return (pointer == MediaValues::NoPointer && value.id == CSSValueNone) |
| 564 || (pointer == MediaValues::TouchPointer && value.id == CSSValueCoarse) | 565 || (pointer == MediaValues::TouchPointer && value.id == CSSValueCoarse) |
| 565 || (pointer == MediaValues::MousePointer && value.id == CSSValueFine); | 566 || (pointer == MediaValues::MousePointer && value.id == CSSValueFine); |
| 566 } | 567 } |
| 567 | 568 |
| 568 static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix, const MediaValues& mediaValues) | 569 static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix, const MediaValues& mediaValues) |
| 569 { | 570 { |
| 570 if (!mediaValues.scanMediaType()) | 571 // Scan only applies to 'tv' media. |
| 572 if (!equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::tv)) | |
| 571 return false; | 573 return false; |
| 572 | 574 |
| 573 if (!value.isValid()) | 575 if (!value.isValid()) |
| 574 return true; | 576 return true; |
| 575 | 577 |
| 576 if (!value.isID) | 578 if (!value.isID) |
| 577 return false; | 579 return false; |
| 578 | 580 |
| 579 // If a platform interface supplies progressive/interlace info for TVs in th e | 581 // If a platform interface supplies progressive/interlace info for TVs in th e |
| 580 // future, it needs to be handled here. For now, assume a modern TV with | 582 // future, it needs to be handled here. For now, assume a modern TV with |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 603 // Call the media feature evaluation function. Assume no prefix and let | 605 // Call the media feature evaluation function. Assume no prefix and let |
| 604 // trampoline functions override the prefix if prefix is used. | 606 // trampoline functions override the prefix if prefix is used. |
| 605 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 607 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
| 606 if (func) | 608 if (func) |
| 607 return func(expr->expValue(), NoPrefix, *m_mediaValues); | 609 return func(expr->expValue(), NoPrefix, *m_mediaValues); |
| 608 | 610 |
| 609 return false; | 611 return false; |
| 610 } | 612 } |
| 611 | 613 |
| 612 } // namespace | 614 } // namespace |
| OLD | NEW |