Commit bb75446b authored by psolanki@apple.com's avatar psolanki@apple.com

MediaQuery::expressions() should return a reference

<https://webkit.org/b/120215>

Reviewed by Anders Carlsson.

m_expressions is never NULL so we can just return a reference.

* css/MediaList.cpp:
(WebCore::reportMediaQueryWarningIfNeeded):
* css/MediaQuery.cpp:
(WebCore::MediaQuery::MediaQuery):
* css/MediaQuery.h:
(WebCore::MediaQuery::expressions):
* css/MediaQueryEvaluator.cpp:
(WebCore::MediaQueryEvaluator::eval):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154533 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1bc51e6c
2013-08-23 Pratik Solanki <psolanki@apple.com>
MediaQuery::expressions() should return a reference
<https://webkit.org/b/120215>
Reviewed by Anders Carlsson.
m_expressions is never NULL so we can just return a reference.
* css/MediaList.cpp:
(WebCore::reportMediaQueryWarningIfNeeded):
* css/MediaQuery.cpp:
(WebCore::MediaQuery::MediaQuery):
* css/MediaQuery.h:
(WebCore::MediaQuery::expressions):
* css/MediaQueryEvaluator.cpp:
(WebCore::MediaQueryEvaluator::eval):
2013-08-23 Ryosuke Niwa <rniwa@webkit.org>
Build fix after r154515.
......@@ -328,9 +328,9 @@ void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* me
const MediaQuery* query = mediaQueries[i].get();
String mediaType = query->mediaType();
if (!query->ignored() && !equalIgnoringCase(mediaType, "print")) {
const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions();
for (size_t j = 0; j < exps->size(); ++j) {
const MediaQueryExp* exp = exps->at(j).get();
const Vector<OwnPtr<MediaQueryExp>>& expressions = query->expressions();
for (size_t j = 0; j < expressions.size(); ++j) {
const MediaQueryExp* exp = expressions.at(j).get();
if (exp->mediaFeature() == MediaFeatureNames::resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::max_resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::min_resolutionMediaFeature) {
CSSValue* cssValue = exp->value();
if (cssValue && cssValue->isPrimitiveValue()) {
......
......@@ -79,14 +79,14 @@ static bool expressionCompare(const OwnPtr<MediaQueryExp>& a, const OwnPtr<Media
}
MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > exprs)
MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<ExpressionVector> exprs)
: m_restrictor(r)
, m_mediaType(mediaType.lower())
, m_expressions(exprs)
, m_ignored(false)
{
if (!m_expressions) {
m_expressions = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
m_expressions = adoptPtr(new ExpressionVector);
return;
}
......@@ -110,7 +110,7 @@ MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<
MediaQuery::MediaQuery(const MediaQuery& o)
: m_restrictor(o.m_restrictor)
, m_mediaType(o.m_mediaType)
, m_expressions(adoptPtr(new Vector<OwnPtr<MediaQueryExp> >(o.m_expressions->size())))
, m_expressions(adoptPtr(new ExpressionVector(o.m_expressions->size())))
, m_ignored(o.m_ignored)
, m_serializationCache(o.m_serializationCache)
{
......
......@@ -44,13 +44,13 @@ public:
Only, Not, None
};
typedef Vector<OwnPtr<MediaQueryExp> > ExpressionVector;
typedef Vector<OwnPtr<MediaQueryExp>> ExpressionVector;
MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<ExpressionVector> exprs);
MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp>>> exprs);
~MediaQuery();
Restrictor restrictor() const { return m_restrictor; }
const Vector<OwnPtr<MediaQueryExp> >* expressions() const { return m_expressions.get(); }
const Vector<OwnPtr<MediaQueryExp>>& expressions() const { return *m_expressions; }
String mediaType() const { return m_mediaType; }
bool operator==(const MediaQuery& other) const;
String cssText() const;
......
......@@ -142,21 +142,21 @@ bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, StyleResolver* sty
continue;
if (mediaTypeMatch(query->mediaType())) {
const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions();
const Vector<OwnPtr<MediaQueryExp>>& expressions = 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);
for (; j < expressions.size(); ++j) {
bool exprResult = eval(expressions.at(j).get());
if (styleResolver && expressions.at(j)->isViewportDependent())
styleResolver->addViewportDependentMediaQueryResult(expressions.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);
result = applyRestrictor(query->restrictor(), expressions.size() == j);
} else
result = applyRestrictor(query->restrictor(), false);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment