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

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

Issue 335313003: MediaQueryEvaluator getting mediaType from MediaValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added a comment Created 6 years, 5 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 a static mediaType was given by the constructor, we use it here.
99 if (!m_mediaType.isEmpty())
100 return m_mediaType;
101 // Otherwise, we get one from mediaValues (which may be dynamic or cached).
102 if (m_mediaValues)
103 return m_mediaValues->mediaType();
104 return nullAtom;
105 }
106
104 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const 107 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
105 { 108 {
106 return mediaTypeToMatch.isEmpty() 109 return mediaTypeToMatch.isEmpty()
107 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all) 110 || equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)
108 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); 111 || equalIgnoringCase(mediaTypeToMatch, mediaType());
109 } 112 }
110 113
111 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst 114 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst
112 { 115 {
113 // Like mediaTypeMatch, but without the special cases for "" and "all". 116 // Like mediaTypeMatch, but without the special cases for "" and "all".
114 ASSERT(mediaTypeToMatch); 117 ASSERT(mediaTypeToMatch);
115 ASSERT(mediaTypeToMatch[0] != '\0'); 118 ASSERT(mediaTypeToMatch[0] != '\0');
116 ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all)); 119 ASSERT(!equalIgnoringCase(mediaTypeToMatch, MediaTypeNames::all));
117 return equalIgnoringCase(mediaTypeToMatch, m_mediaType); 120 return equalIgnoringCase(mediaTypeToMatch, mediaType());
118 } 121 }
119 122
120 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) 123 static bool applyRestrictor(MediaQuery::Restrictor r, bool value)
121 { 124 {
122 return r == MediaQuery::Not ? !value : value; 125 return r == MediaQuery::Not ? !value : value;
123 } 126 }
124 127
125 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const 128 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const
126 { 129 {
127 if (!querySet) 130 if (!querySet)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o p, const MediaValues& mediaValues) 265 static bool evalResolution(const MediaQueryExpValue& value, MediaFeaturePrefix o p, const MediaValues& mediaValues)
263 { 266 {
264 // According to MQ4, only 'screen', 'print' and 'speech' may match. 267 // 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 268 // FIXME: What should speech match? https://www.w3.org/Style/CSS/Tracker/iss ues/348
266 float actualResolution = 0; 269 float actualResolution = 0;
267 270
268 // 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
269 // 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
270 // 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
271 // media type of the query will either be "print" or "all". 274 // media type of the query will either be "print" or "all".
272 if (mediaValues.screenMediaType()) { 275 if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::screen)) {
273 actualResolution = clampTo<float>(mediaValues.devicePixelRatio()); 276 actualResolution = clampTo<float>(mediaValues.devicePixelRatio());
274 } else if (mediaValues.printMediaType()) { 277 } else if (equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::print) ) {
275 // 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
276 // 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
277 // we use 300px which is considered minimum for current printers. 280 // we use 300px which is considered minimum for current printers.
278 actualResolution = 300 / cssPixelsPerInch; 281 actualResolution = 300 / cssPixelsPerInch;
279 } 282 }
280 283
281 if (!value.isValid()) 284 if (!value.isValid())
282 return !!actualResolution; 285 return !!actualResolution;
283 286
284 if (!value.isValue) 287 if (!value.isValue)
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 if (!value.isID) 563 if (!value.isID)
561 return false; 564 return false;
562 565
563 return (pointer == MediaValues::NoPointer && value.id == CSSValueNone) 566 return (pointer == MediaValues::NoPointer && value.id == CSSValueNone)
564 || (pointer == MediaValues::TouchPointer && value.id == CSSValueCoarse) 567 || (pointer == MediaValues::TouchPointer && value.id == CSSValueCoarse)
565 || (pointer == MediaValues::MousePointer && value.id == CSSValueFine); 568 || (pointer == MediaValues::MousePointer && value.id == CSSValueFine);
566 } 569 }
567 570
568 static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix, const MediaValues& mediaValues) 571 static bool scanMediaFeatureEval(const MediaQueryExpValue& value, MediaFeaturePr efix, const MediaValues& mediaValues)
569 { 572 {
570 if (!mediaValues.scanMediaType()) 573 // Scan only applies to 'tv' media.
574 if (!equalIgnoringCase(mediaValues.mediaType(), MediaTypeNames::tv))
571 return false; 575 return false;
572 576
573 if (!value.isValid()) 577 if (!value.isValid())
574 return true; 578 return true;
575 579
576 if (!value.isID) 580 if (!value.isID)
577 return false; 581 return false;
578 582
579 // If a platform interface supplies progressive/interlace info for TVs in th e 583 // 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 584 // future, it needs to be handled here. For now, assume a modern TV with
(...skipping 22 matching lines...) Expand all
603 // Call the media feature evaluation function. Assume no prefix and let 607 // Call the media feature evaluation function. Assume no prefix and let
604 // trampoline functions override the prefix if prefix is used. 608 // trampoline functions override the prefix if prefix is used.
605 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 609 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
606 if (func) 610 if (func)
607 return func(expr->expValue(), NoPrefix, *m_mediaValues); 611 return func(expr->expValue(), NoPrefix, *m_mediaValues);
608 612
609 return false; 613 return false;
610 } 614 }
611 615
612 } // namespace 616 } // 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