bool MediaQueryEvaluator::evalCheckingViewportDependentResults(const MediaQuerySet* querySet, Vector<std::unique_ptr<MediaQueryResult>>& results) { if (!querySet) return true; auto& queries = querySet->queryVector(); if (!queries.size()) return true; bool result = false; for (size_t i = 0; i < queries.size() && !result; ++i) { MediaQuery* query = queries[i].get(); if (query->ignored()) continue; if (mediaTypeMatch(query->mediaType())) { auto& expressions = query->expressions(); size_t j = 0; for (; j < expressions.size(); ++j) { bool exprResult = eval(expressions.at(j).get()); if (expressions.at(j)->isViewportDependent()) results.append(std::make_unique<MediaQueryResult>(*expressions.at(j), exprResult)); if (!exprResult) break; } result = applyRestrictor(query->restrictor(), expressions.size() == j); } else result = applyRestrictor(query->restrictor(), false); } return result; }
bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, StyleResolver* styleResolver) const { if (!querySet) return true; const Vector<OwnPtr<MediaQuery> >& queries = querySet->queryVector(); if (!queries.size()) return true; // empty query list evaluates to true // iterate over queries, stop if any of them eval to true (OR semantics) bool result = false; for (size_t i = 0; i < queries.size() && !result; ++i) { MediaQuery* query = queries[i].get(); if (query->ignored()) continue; if (mediaTypeMatch(query->mediaType())) { const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions(); // iterate through expressions, stop if any of them eval to false // (AND semantics) size_t j = 0; for (; j < exps->size(); ++j) { bool exprResult = eval(exps->at(j).get()); if (styleResolver && exps->at(j)->isViewportDependent()) styleResolver->addViewportDependentMediaQueryResult(exps->at(j).get(), exprResult); if (!exprResult) break; } // assume true if we are at the end of the list, // otherwise assume false result = applyRestrictor(query->restrictor(), exps->size() == j); } else result = applyRestrictor(query->restrictor(), false); } return result; }