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

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

Issue 2837023005: Move MediaQuery classes off BlinkGC heap (Closed)
Patch Set: fix Created 3 years, 8 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 DeprecatedEqualIgnoringCase(media_type_to_match, 105 DeprecatedEqualIgnoringCase(media_type_to_match,
106 MediaTypeNames::all) || 106 MediaTypeNames::all) ||
107 DeprecatedEqualIgnoringCase(media_type_to_match, MediaType()); 107 DeprecatedEqualIgnoringCase(media_type_to_match, MediaType());
108 } 108 }
109 109
110 static bool ApplyRestrictor(MediaQuery::RestrictorType r, bool value) { 110 static bool ApplyRestrictor(MediaQuery::RestrictorType r, bool value) {
111 return r == MediaQuery::kNot ? !value : value; 111 return r == MediaQuery::kNot ? !value : value;
112 } 112 }
113 113
114 bool MediaQueryEvaluator::Eval( 114 bool MediaQueryEvaluator::Eval(
115 const MediaQuery* query, 115 const MediaQuery& query,
116 MediaQueryResultList* viewport_dependent_media_query_results, 116 MediaQueryResultList* viewport_dependent_media_query_results,
117 MediaQueryResultList* device_dependent_media_query_results) const { 117 MediaQueryResultList* device_dependent_media_query_results) const {
118 if (!MediaTypeMatch(query->MediaType())) 118 if (!MediaTypeMatch(query.MediaType()))
119 return ApplyRestrictor(query->Restrictor(), false); 119 return ApplyRestrictor(query.Restrictor(), false);
120 120
121 const ExpressionHeapVector& expressions = query->Expressions(); 121 const ExpressionHeapVector& expressions = query.Expressions();
122 // Iterate through expressions, stop if any of them eval to false (AND 122 // Iterate through expressions, stop if any of them eval to false (AND
123 // semantics). 123 // semantics).
124 size_t i = 0; 124 size_t i = 0;
125 for (; i < expressions.size(); ++i) { 125 for (; i < expressions.size(); ++i) {
126 bool expr_result = Eval(expressions.at(i).Get()); 126 bool expr_result = Eval(expressions.at(i));
127 if (viewport_dependent_media_query_results && 127 if (viewport_dependent_media_query_results &&
128 expressions.at(i)->IsViewportDependent()) 128 expressions.at(i).IsViewportDependent()) {
129 viewport_dependent_media_query_results->push_back( 129 viewport_dependent_media_query_results->push_back(
130 new MediaQueryResult(*expressions.at(i), expr_result)); 130 MediaQueryResult(expressions.at(i), expr_result));
131 }
131 if (device_dependent_media_query_results && 132 if (device_dependent_media_query_results &&
132 expressions.at(i)->IsDeviceDependent()) 133 expressions.at(i).IsDeviceDependent()) {
133 device_dependent_media_query_results->push_back( 134 device_dependent_media_query_results->push_back(
134 new MediaQueryResult(*expressions.at(i), expr_result)); 135 MediaQueryResult(expressions.at(i), expr_result));
136 }
135 if (!expr_result) 137 if (!expr_result)
136 break; 138 break;
137 } 139 }
138 140
139 // Assume true if we are at the end of the list, otherwise assume false. 141 // Assume true if we are at the end of the list, otherwise assume false.
140 return ApplyRestrictor(query->Restrictor(), expressions.size() == i); 142 return ApplyRestrictor(query.Restrictor(), expressions.size() == i);
141 } 143 }
142 144
143 bool MediaQueryEvaluator::Eval( 145 bool MediaQueryEvaluator::Eval(
144 const MediaQuerySet* query_set, 146 const MediaQuerySet& query_set,
145 MediaQueryResultList* viewport_dependent_media_query_results, 147 MediaQueryResultList* viewport_dependent_media_query_results,
146 MediaQueryResultList* device_dependent_media_query_results) const { 148 MediaQueryResultList* device_dependent_media_query_results) const {
147 if (!query_set) 149 const Vector<std::unique_ptr<MediaQuery>>& queries = query_set.QueryVector();
148 return true;
149
150 const HeapVector<Member<MediaQuery>>& queries = query_set->QueryVector();
151 if (!queries.size()) 150 if (!queries.size())
152 return true; // Empty query list evaluates to true. 151 return true; // Empty query list evaluates to true.
153 152
154 // Iterate over queries, stop if any of them eval to true (OR semantics). 153 // Iterate over queries, stop if any of them eval to true (OR semantics).
155 bool result = false; 154 bool result = false;
156 for (size_t i = 0; i < queries.size() && !result; ++i) { 155 for (size_t i = 0; i < queries.size() && !result; ++i) {
157 // TODO(sof): CHECK() added for crbug.com/699269 diagnosis, remove sooner. 156 // TODO(sof): CHECK() added for crbug.com/699269 diagnosis, remove sooner.
158 CHECK_EQ(queries.data(), query_set->QueryVector().data()); 157 CHECK_EQ(queries.data(), query_set.QueryVector().data());
159 result = Eval(queries[i].Get(), viewport_dependent_media_query_results, 158 result = Eval(*queries[i], viewport_dependent_media_query_results,
160 device_dependent_media_query_results); 159 device_dependent_media_query_results);
161 } 160 }
162 161
163 return result; 162 return result;
164 } 163 }
165 164
166 template <typename T> 165 template <typename T>
167 bool CompareValue(T a, T b, MediaFeaturePrefix op) { 166 bool CompareValue(T a, T b, MediaFeaturePrefix op) {
168 switch (op) { 167 switch (op) {
169 case kMinPrefix: 168 case kMinPrefix:
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 void MediaQueryEvaluator::Init() { 801 void MediaQueryEvaluator::Init() {
803 // Create the table. 802 // Create the table.
804 g_function_map = new FunctionMap; 803 g_function_map = new FunctionMap;
805 #define ADD_TO_FUNCTIONMAP(constantPrefix, methodPrefix) \ 804 #define ADD_TO_FUNCTIONMAP(constantPrefix, methodPrefix) \
806 g_function_map->Set(constantPrefix##MediaFeature.Impl(), \ 805 g_function_map->Set(constantPrefix##MediaFeature.Impl(), \
807 methodPrefix##MediaFeatureEval); 806 methodPrefix##MediaFeatureEval);
808 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP); 807 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
809 #undef ADD_TO_FUNCTIONMAP 808 #undef ADD_TO_FUNCTIONMAP
810 } 809 }
811 810
812 bool MediaQueryEvaluator::Eval(const MediaQueryExp* expr) const { 811 bool MediaQueryEvaluator::Eval(const MediaQueryExp& expr) const {
813 if (!media_values_ || !media_values_->HasValues()) 812 if (!media_values_ || !media_values_->HasValues())
814 return true; 813 return true;
815 814
816 DCHECK(g_function_map); 815 DCHECK(g_function_map);
817 816
818 // Call the media feature evaluation function. Assume no prefix and let 817 // Call the media feature evaluation function. Assume no prefix and let
819 // trampoline functions override the prefix if prefix is used. 818 // trampoline functions override the prefix if prefix is used.
820 EvalFunc func = g_function_map->at(expr->MediaFeature().Impl()); 819 EvalFunc func = g_function_map->at(expr.MediaFeature().Impl());
821 if (func) 820 if (func)
822 return func(expr->ExpValue(), kNoPrefix, *media_values_); 821 return func(expr.ExpValue(), kNoPrefix, *media_values_);
823 822
824 return false; 823 return false;
825 } 824 }
826 825
827 } // namespace blink 826 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698