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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) | 116 static bool applyRestrictor(MediaQuery::Restrictor r, bool value) |
117 { | 117 { |
118 return r == MediaQuery::Not ? !value : value; | 118 return r == MediaQuery::Not ? !value : value; |
119 } | 119 } |
120 | 120 |
121 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi
st* viewportDependentMediaQueryResults) const | 121 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, MediaQueryResultLi
st* viewportDependentMediaQueryResults) const |
122 { | 122 { |
123 if (!querySet) | 123 if (!querySet) |
124 return true; | 124 return true; |
125 | 125 |
126 const Vector<OwnPtr<MediaQuery> >& queries = querySet->queryVector(); | 126 const WillBeHeapVector<OwnPtrWillBeMember<MediaQuery> >& queries = querySet-
>queryVector(); |
127 if (!queries.size()) | 127 if (!queries.size()) |
128 return true; // Empty query list evaluates to true. | 128 return true; // Empty query list evaluates to true. |
129 | 129 |
130 // Iterate over queries, stop if any of them eval to true (OR semantics). | 130 // Iterate over queries, stop if any of them eval to true (OR semantics). |
131 bool result = false; | 131 bool result = false; |
132 for (size_t i = 0; i < queries.size() && !result; ++i) { | 132 for (size_t i = 0; i < queries.size() && !result; ++i) { |
133 MediaQuery* query = queries[i].get(); | 133 MediaQuery* query = queries[i].get(); |
134 | 134 |
135 if (mediaTypeMatch(query->mediaType())) { | 135 if (mediaTypeMatch(query->mediaType())) { |
136 const ExpressionVector& expressions = query->expressions(); | 136 const ExpressionVector& expressions = query->expressions(); |
137 // Iterate through expressions, stop if any of them eval to false (A
ND semantics). | 137 // Iterate through expressions, stop if any of them eval to false (A
ND semantics). |
138 size_t j = 0; | 138 size_t j = 0; |
139 for (; j < expressions.size(); ++j) { | 139 for (; j < expressions.size(); ++j) { |
140 bool exprResult = eval(expressions.at(j).get()); | 140 bool exprResult = eval(expressions.at(j).get()); |
141 if (viewportDependentMediaQueryResults && expressions.at(j)->isV
iewportDependent()) | 141 if (viewportDependentMediaQueryResults && expressions.at(j)->isV
iewportDependent()) |
142 viewportDependentMediaQueryResults->append(adoptRef(new Medi
aQueryResult(*expressions.at(j), exprResult))); | 142 viewportDependentMediaQueryResults->append(adoptRefWillBeNoo
p(new MediaQueryResult(*expressions.at(j), exprResult))); |
143 if (!exprResult) | 143 if (!exprResult) |
144 break; | 144 break; |
145 } | 145 } |
146 | 146 |
147 // Assume true if we are at the end of the list, otherwise assume fa
lse. | 147 // Assume true if we are at the end of the list, otherwise assume fa
lse. |
148 result = applyRestrictor(query->restrictor(), expressions.size() ==
j); | 148 result = applyRestrictor(query->restrictor(), expressions.size() ==
j); |
149 } else | 149 } else |
150 result = applyRestrictor(query->restrictor(), false); | 150 result = applyRestrictor(query->restrictor(), false); |
151 } | 151 } |
152 | 152 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 // Call the media feature evaluation function. Assume no prefix and let | 690 // Call the media feature evaluation function. Assume no prefix and let |
691 // trampoline functions override the prefix if prefix is used. | 691 // trampoline functions override the prefix if prefix is used. |
692 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); | 692 EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl()); |
693 if (func) | 693 if (func) |
694 return func(expr->value(), m_style.get(), m_frame, NoPrefix); | 694 return func(expr->value(), m_style.get(), m_frame, NoPrefix); |
695 | 695 |
696 return false; | 696 return false; |
697 } | 697 } |
698 | 698 |
699 } // namespace | 699 } // namespace |
OLD | NEW |