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

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

Issue 171383002: A thread-safe Media Query Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Generate strings with make_names Created 6 years, 9 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 13 matching lines...) Expand all
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "config.h" 30 #include "config.h"
31 #include "core/css/MediaQueryEvaluator.h" 31 #include "core/css/MediaQueryEvaluator.h"
32 32
33 #include "CSSValueKeywords.h" 33 #include "CSSValueKeywords.h"
34 #include "MediaFeatureNames.h"
34 #include "core/css/CSSAspectRatioValue.h" 35 #include "core/css/CSSAspectRatioValue.h"
35 #include "core/css/CSSHelper.h" 36 #include "core/css/CSSHelper.h"
36 #include "core/css/CSSPrimitiveValue.h" 37 #include "core/css/CSSPrimitiveValue.h"
37 #include "core/css/CSSToLengthConversionData.h" 38 #include "core/css/CSSToLengthConversionData.h"
38 #include "core/css/MediaFeatureNames.h" 39 #include "core/css/MediaFeatures.h"
39 #include "core/css/MediaList.h" 40 #include "core/css/MediaList.h"
40 #include "core/css/MediaQuery.h" 41 #include "core/css/MediaQuery.h"
41 #include "core/css/resolver/MediaQueryResult.h" 42 #include "core/css/resolver/MediaQueryResult.h"
42 #include "core/dom/NodeRenderStyle.h" 43 #include "core/dom/NodeRenderStyle.h"
43 #include "core/frame/FrameHost.h" 44 #include "core/frame/FrameHost.h"
44 #include "core/frame/FrameView.h" 45 #include "core/frame/FrameView.h"
45 #include "core/frame/LocalFrame.h" 46 #include "core/frame/LocalFrame.h"
46 #include "core/frame/Settings.h" 47 #include "core/frame/Settings.h"
47 #include "core/inspector/InspectorInstrumentation.h" 48 #include "core/inspector/InspectorInstrumentation.h"
48 #include "core/rendering/RenderView.h" 49 #include "core/rendering/RenderView.h"
(...skipping 13 matching lines...) Expand all
62 typedef HashMap<StringImpl*, EvalFunc> FunctionMap; 63 typedef HashMap<StringImpl*, EvalFunc> FunctionMap;
63 static FunctionMap* gFunctionMap; 64 static FunctionMap* gFunctionMap;
64 65
65 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) 66 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
66 : m_frame(0) 67 : m_frame(0)
67 , m_style(nullptr) 68 , m_style(nullptr)
68 , m_expResult(mediaFeatureResult) 69 , m_expResult(mediaFeatureResult)
69 { 70 {
70 } 71 }
71 72
72 MediaQueryEvaluator::MediaQueryEvaluator(const AtomicString& acceptedMediaType, bool mediaFeatureResult) 73 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool m ediaFeatureResult)
73 : m_mediaType(acceptedMediaType) 74 : m_mediaType(acceptedMediaType)
74 , m_frame(0) 75 , m_frame(0)
75 , m_style(nullptr) 76 , m_style(nullptr)
76 , m_expResult(mediaFeatureResult) 77 , m_expResult(mediaFeatureResult)
77 { 78 {
78 } 79 }
79 80
80 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult) 81 MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool med iaFeatureResult)
81 : m_mediaType(acceptedMediaType) 82 : m_mediaType(acceptedMediaType)
82 , m_frame(0) 83 , m_frame(0)
83 , m_style(nullptr) 84 , m_style(nullptr)
84 , m_expResult(mediaFeatureResult) 85 , m_expResult(mediaFeatureResult)
85 { 86 {
86 } 87 }
87 88
88 MediaQueryEvaluator::MediaQueryEvaluator(const AtomicString& acceptedMediaType, LocalFrame* frame, RenderStyle* style) 89 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, LocalF rame* frame, RenderStyle* style)
89 : m_mediaType(acceptedMediaType) 90 : m_mediaType(acceptedMediaType)
90 , m_frame(frame) 91 , m_frame(frame)
91 , m_style(style) 92 , m_style(style)
92 , m_expResult(false) // Doesn't matter when we have m_frame and m_style. 93 , m_expResult(false) // Doesn't matter when we have m_frame and m_style.
93 { 94 {
94 } 95 }
95 96
96 MediaQueryEvaluator::~MediaQueryEvaluator() 97 MediaQueryEvaluator::~MediaQueryEvaluator()
97 { 98 {
98 } 99 }
99 100
100 bool MediaQueryEvaluator::mediaTypeMatch(const AtomicString& mediaTypeToMatch) c onst 101 bool MediaQueryEvaluator::mediaTypeMatch(const String& mediaTypeToMatch) const
101 { 102 {
102 return mediaTypeToMatch.isEmpty() 103 return mediaTypeToMatch.isEmpty()
103 || equalIgnoringCase(mediaTypeToMatch, "all") 104 || equalIgnoringCase(mediaTypeToMatch, "all")
104 || equalIgnoringCase(mediaTypeToMatch, m_mediaType); 105 || equalIgnoringCase(mediaTypeToMatch, m_mediaType);
105 } 106 }
106 107
107 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst 108 bool MediaQueryEvaluator::mediaTypeMatchSpecific(const char* mediaTypeToMatch) c onst
108 { 109 {
109 // Like mediaTypeMatch, but without the special cases for "" and "all". 110 // Like mediaTypeMatch, but without the special cases for "" and "all".
110 ASSERT(mediaTypeToMatch); 111 ASSERT(mediaTypeToMatch);
111 ASSERT(mediaTypeToMatch[0] != '\0'); 112 ASSERT(mediaTypeToMatch[0] != '\0');
112 ASSERT(!equalIgnoringCase(mediaTypeToMatch, AtomicString("all"))); 113 ASSERT(!equalIgnoringCase(mediaTypeToMatch, String("all")));
113 return equalIgnoringCase(mediaTypeToMatch, m_mediaType); 114 return equalIgnoringCase(mediaTypeToMatch, m_mediaType);
114 } 115 }
115 116
116 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) 117 static bool applyRestrictor(MediaQuery::Restrictor r, bool value)
117 { 118 {
118 return r == MediaQuery::Not ? !value : value; 119 return r == MediaQuery::Not ? !value : value;
119 } 120 }
120 121
121 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const 122 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi st* viewportDependentMediaQueryResults) const
122 { 123 {
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // If a platform interface supplies progressive/interlace info for TVs in th e 667 // If a platform interface supplies progressive/interlace info for TVs in th e
667 // future, it needs to be handled here. For now, assume a modern TV with 668 // future, it needs to be handled here. For now, assume a modern TV with
668 // progressive display. 669 // progressive display.
669 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive; 670 return toCSSPrimitiveValue(value)->getValueID() == CSSValueProgressive;
670 } 671 }
671 672
672 static void createFunctionMap() 673 static void createFunctionMap()
673 { 674 {
674 // Create the table. 675 // Create the table.
675 gFunctionMap = new FunctionMap; 676 gFunctionMap = new FunctionMap;
676 #define ADD_TO_FUNCTIONMAP(name, str) \ 677 #define ADD_TO_FUNCTIONMAP(name) \
677 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval); 678 gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
678 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); 679 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
679 #undef ADD_TO_FUNCTIONMAP 680 #undef ADD_TO_FUNCTIONMAP
680 } 681 }
681 682
682 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const 683 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
683 { 684 {
684 if (!m_frame || !m_style) 685 if (!m_frame || !m_style)
685 return m_expResult; 686 return m_expResult;
686 687
687 if (!gFunctionMap) 688 if (!gFunctionMap)
688 createFunctionMap(); 689 createFunctionMap();
689 690
690 // Call the media feature evaluation function. Assume no prefix and let 691 // Call the media feature evaluation function. Assume no prefix and let
691 // trampoline functions override the prefix if prefix is used. 692 // trampoline functions override the prefix if prefix is used.
692 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); 693 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
693 if (func) 694 if (func)
694 return func(expr->value(), m_style.get(), m_frame, NoPrefix); 695 return func(expr->value(), m_style.get(), m_frame, NoPrefix);
695 696
696 return false; 697 return false;
697 } 698 }
698 699
699 } // namespace 700 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698