Title: [118650] trunk/Source/WebCore
Revision
118650
Author
da...@apple.com
Date
2012-05-28 00:11:20 -0700 (Mon, 28 May 2012)

Log Message

StyleResolver need not allocate each MediaQueryResult on the heap
https://bugs.webkit.org/show_bug.cgi?id=75223

Reviewed by Daniel Bates.

* css/MediaQuery.cpp: Removed some comments that pointed to CSS documents.
There is no guarantee these links will be valid over time.
(WebCore::MediaQuery::MediaQuery): Rewrote for clarity, conventional WebKit coding
style, and simplicity.
(WebCore::MediaQuery::copy): Moved out of line; not performance critical, and this
allows us to cut down header dependencies.
(WebCore::MediaQuery::cssText): Updated for change to data member name.

* css/MediaQuery.h: Removed unneeded includes. Removed non-helpful argument name
"exprs". Changed expressions function to return a reference instead of
a pointer. Changed mediaType and cssText functions to return a reference. Renamed
m_serializationCache to m_serializedQuery. Moved copy function out of header.

* css/MediaQueryEvaluator.cpp: Renamed EvalFunc to MediaFeatureEvaluationFunction.
Broke a FIXME into three and reworded for clarity.
(WebCore::MediaQueryEvaluator): Updated for name changes.
(WebCore::MediaQueryEvaluator::eval): Rewrote this for clarity and to regularize
the logic a bit.
(WebCore::aspect_ratioMediaFeatureEval): Got rid of a != 0 that is contrary to the
normal WebKit style.
(WebCore::device_aspect_ratioMediaFeatureEval): Ditto.
(WebCore::transform_3dMediaFeatureEval): Fixed mangled #if that was here.
(WebCore::view_modeMediaFeatureEval): Replaced UNUSED_PARAM usage with ASSERT_UNUSED.
(WebCore::createFunctionMap): Changed this so it returns the map so we can use a
cleaner style in the caller.
(WebCore::MediaQueryEvaluator::eval): Updated to take a reference and improved the
comments and coding style a bit.

* css/MediaQueryEvaluator.h: Updated comment style. Removed unused constructor.
Removed unneeded destructor declaration. Renamed m_expResult to m_mediaFeatureResult.

* css/StyleResolver.cpp: Moved the MediaQueryResult class into this file
and made it a structure rather than a class.
(WebCore::StyleResolver::addViewportDependentMediaQueryResult): Updated to take
a reference argument instead of a pointer and for the new vector type.
(WebCore::StyleResolver::affectedByViewportChange): Updated for above changes.

* css/StyleResolver.h: Removed many unneeded includes and forward declarations of
classes, including now-unneeded include of MediaQueryExp.h. Replaced MediaQueryResult
definition with a forward declaration. Changed addViewportDependentMediaQueryResult
to take a reference instead of a pointer. Changed m_viewportDependentMediaQueryResults
to be a vector of values rather than of pointers.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118649 => 118650)


--- trunk/Source/WebCore/ChangeLog	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/ChangeLog	2012-05-28 07:11:20 UTC (rev 118650)
@@ -1,3 +1,53 @@
+2012-05-28  Darin Adler  <da...@apple.com>
+
+        StyleResolver need not allocate each MediaQueryResult on the heap
+        https://bugs.webkit.org/show_bug.cgi?id=75223
+
+        Reviewed by Daniel Bates.
+
+        * css/MediaQuery.cpp: Removed some comments that pointed to CSS documents.
+        There is no guarantee these links will be valid over time.
+        (WebCore::MediaQuery::MediaQuery): Rewrote for clarity, conventional WebKit coding
+        style, and simplicity.
+        (WebCore::MediaQuery::copy): Moved out of line; not performance critical, and this
+        allows us to cut down header dependencies.
+        (WebCore::MediaQuery::cssText): Updated for change to data member name.
+
+        * css/MediaQuery.h: Removed unneeded includes. Removed non-helpful argument name
+        "exprs". Changed expressions function to return a reference instead of
+        a pointer. Changed mediaType and cssText functions to return a reference. Renamed
+        m_serializationCache to m_serializedQuery. Moved copy function out of header.
+
+        * css/MediaQueryEvaluator.cpp: Renamed EvalFunc to MediaFeatureEvaluationFunction.
+        Broke a FIXME into three and reworded for clarity.
+        (WebCore::MediaQueryEvaluator): Updated for name changes.
+        (WebCore::MediaQueryEvaluator::eval): Rewrote this for clarity and to regularize
+        the logic a bit.
+        (WebCore::aspect_ratioMediaFeatureEval): Got rid of a != 0 that is contrary to the
+        normal WebKit style.
+        (WebCore::device_aspect_ratioMediaFeatureEval): Ditto.
+        (WebCore::transform_3dMediaFeatureEval): Fixed mangled #if that was here.
+        (WebCore::view_modeMediaFeatureEval): Replaced UNUSED_PARAM usage with ASSERT_UNUSED.
+        (WebCore::createFunctionMap): Changed this so it returns the map so we can use a
+        cleaner style in the caller.
+        (WebCore::MediaQueryEvaluator::eval): Updated to take a reference and improved the
+        comments and coding style a bit.
+
+        * css/MediaQueryEvaluator.h: Updated comment style. Removed unused constructor.
+        Removed unneeded destructor declaration. Renamed m_expResult to m_mediaFeatureResult.
+
+        * css/StyleResolver.cpp: Moved the MediaQueryResult class into this file
+        and made it a structure rather than a class.
+        (WebCore::StyleResolver::addViewportDependentMediaQueryResult): Updated to take
+        a reference argument instead of a pointer and for the new vector type.
+        (WebCore::StyleResolver::affectedByViewportChange): Updated for above changes.
+
+        * css/StyleResolver.h: Removed many unneeded includes and forward declarations of
+        classes, including now-unneeded include of MediaQueryExp.h. Replaced MediaQueryResult
+        definition with a forward declaration. Changed addViewportDependentMediaQueryResult
+        to take a reference instead of a pointer. Changed m_viewportDependentMediaQueryResults
+        to be a vector of values rather than of pointers.
+
 2012-05-27  Shinya Kawanaka  <shin...@chromium.org>
 
         cut, copy or paste event won't be fired in Shadow DOM.

Modified: trunk/Source/WebCore/css/MediaQuery.cpp (118649 => 118650)


--- trunk/Source/WebCore/css/MediaQuery.cpp	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/MediaQuery.cpp	2012-05-28 07:11:20 UTC (rev 118650)
@@ -35,7 +35,6 @@
 
 namespace WebCore {
 
-// http://dev.w3.org/csswg/cssom/#serialize-a-media-query
 String MediaQuery::serialize() const
 {
     StringBuilder result;
@@ -66,6 +65,7 @@
         result.append(" and ");
         result.append(m_expressions->at(i)->serialize());
     }
+
     return result.toString();
 }
 
@@ -74,32 +74,33 @@
     return codePointCompare(a->serialize(), b->serialize()) < 0;
 }
 
-
-MediaQuery::MediaQuery(Restrictor r, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > exprs)
-    : m_restrictor(r)
+MediaQuery::MediaQuery(Restrictor restrictor, const String& mediaType, PassOwnPtr<ExpressionVector> expressions)
+    : m_restrictor(restrictor)
     , m_mediaType(mediaType.lower())
-    , m_expressions(exprs)
+    , m_expressions(expressions)
     , m_ignored(false)
 {
     if (!m_expressions) {
-        m_expressions = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
+        m_expressions = adoptPtr(new ExpressionVector);
         return;
     }
 
-    nonCopyingSort(m_expressions->begin(), m_expressions->end(), expressionCompare);
+    ExpressionVector& vector = *m_expressions;
 
-    // remove all duplicated expressions
-    String key;
-    for (int i = m_expressions->size() - 1; i >= 0; --i) {
+    nonCopyingSort(vector.begin(), vector.end(), expressionCompare);
 
-        // if not all of the expressions is valid the media query must be ignored.
-        if (!m_ignored)
-            m_ignored = !m_expressions->at(i)->isValid();
+    String previousSerializedExpression;
+    for (size_t i = vector.size(); i; ) {
+        --i;
 
-        if (m_expressions->at(i)->serialize() == key)
-            m_expressions->remove(i);
-        else
-            key = m_expressions->at(i)->serialize();
+        // If any _expression_ is invalid, the entire media query must be ignored.
+        m_ignored = m_ignored || !vector[i]->isValid();
+
+        // Remove duplicate expressions.
+        String serializedExpression = vector[i]->serialize();
+        if (serializedExpression == previousSerializedExpression)
+            vector.remove(i);
+        previousSerializedExpression = serializedExpression;
     }
 }
 
@@ -108,29 +109,31 @@
     , m_mediaType(o.m_mediaType)
     , m_expressions(adoptPtr(new Vector<OwnPtr<MediaQueryExp> >(o.m_expressions->size())))
     , m_ignored(o.m_ignored)
-    , m_serializationCache(o.m_serializationCache)
+    , m_serializedQuery(o.m_serializedQuery)
 {
     for (unsigned i = 0; i < m_expressions->size(); ++i)
         (*m_expressions)[i] = o.m_expressions->at(i)->copy();
 }
 
+PassOwnPtr<MediaQuery> MediaQuery::copy() const
+{
+    return adoptPtr(new MediaQuery(*this));
+}
+
 MediaQuery::~MediaQuery()
 {
 }
 
-// http://dev.w3.org/csswg/cssom/#compare-media-queries
 bool MediaQuery::operator==(const MediaQuery& other) const
 {
     return cssText() == other.cssText();
 }
 
-// http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries
-String MediaQuery::cssText() const
+const String& MediaQuery::cssText() const
 {
-    if (m_serializationCache.isNull())
-        const_cast<MediaQuery*>(this)->m_serializationCache = serialize();
-
-    return m_serializationCache;
+    if (m_serializedQuery.isNull())
+        const_cast<MediaQuery*>(this)->m_serializedQuery = serialize();
+    return m_serializedQuery;
 }
 
-} //namespace
+} // namespace WebCore

Modified: trunk/Source/WebCore/css/MediaQuery.h (118649 => 118650)


--- trunk/Source/WebCore/css/MediaQuery.h	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/MediaQuery.h	2012-05-28 07:11:20 UTC (rev 118650)
@@ -30,44 +30,42 @@
 #define MediaQuery_h
 
 #include "PlatformString.h"
-#include <wtf/PassOwnPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/StringHash.h>
 
 namespace WebCore {
+
 class MediaQueryExp;
 
 class MediaQuery {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    enum Restrictor {
-        Only, Not, None
-    };
+    enum Restrictor { Only, Not, None };
 
     typedef Vector<OwnPtr<MediaQueryExp> > ExpressionVector;
 
-    MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<ExpressionVector> exprs);
+    MediaQuery(Restrictor, const String& mediaType, PassOwnPtr<ExpressionVector>);
     ~MediaQuery();
 
+    bool operator==(const MediaQuery&) const;
+
     Restrictor restrictor() const { return m_restrictor; }
-    const Vector<OwnPtr<MediaQueryExp> >* expressions() const { return m_expressions.get(); }
-    String mediaType() const { return m_mediaType; }
-    bool operator==(const MediaQuery& other) const;
-    String cssText() const;
+    const ExpressionVector& expressions() const { return *m_expressions; }
+    const String& mediaType() const { return m_mediaType; }
+    const String& cssText() const;
     bool ignored() const { return m_ignored; }
 
-    PassOwnPtr<MediaQuery> copy() const { return adoptPtr(new MediaQuery(*this)); }
+    PassOwnPtr<MediaQuery> copy() const;
 
- private:
+private:
     MediaQuery(const MediaQuery&);
+    void operator=(const MediaQuery&);
+    
+    String serialize() const;
 
     Restrictor m_restrictor;
     String m_mediaType;
     OwnPtr<ExpressionVector> m_expressions;
     bool m_ignored;
-    String m_serializationCache;
-
-    String serialize() const;
+    String m_serializedQuery;
 };
 
 } // namespace

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (118649 => 118650)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2012-05-28 07:11:20 UTC (rev 118650)
@@ -58,50 +58,40 @@
 
 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix };
 
-typedef bool (*EvalFunc)(CSSValue*, RenderStyle*, Frame*, MediaFeaturePrefix);
-typedef HashMap<AtomicStringImpl*, EvalFunc> FunctionMap;
-static FunctionMap* gFunctionMap;
+typedef bool (*MediaFeatureEvaluationFunction)(CSSValue*, RenderStyle*, Frame*, MediaFeaturePrefix);
+typedef HashMap<AtomicStringImpl*, MediaFeatureEvaluationFunction> FunctionMap;
 
-/*
- * FIXME: following media features are not implemented: color_index, scan, resolution
- *
- * color_index, min-color-index, max_color_index: It's unknown how to retrieve
- * the information if the display mode is indexed
- * scan: The "scan" media feature describes the scanning process of
- * tv output devices. It's unknown how to retrieve this information from
- * the platform
- * resolution, min-resolution, max-resolution: css parser doesn't seem to
- * support CSS_DIMENSION
- */
+// FIXME: color-index, min-color-index, and max-color-index are not implemented.
+// To implement them we'd have to add information about indexed color to the WebCore platform;
+// most modern platforms don't make use of indexed color, so it's not clear this is worthwhile.
 
-MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
-    : m_frame(0)
-    , m_style(0)
-    , m_expResult(mediaFeatureResult)
-{
-}
+// FIXME: scan is not implemented: This media feature describes the scanning process of
+// TV output devices. To implement this we'd have to add information to the WebCore platform.
 
-MediaQueryEvaluator:: MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult)
+// FIXME: resolution, min-resolution, max-resolution are not implemented: At the time this
+// was originally written the author said the CSS parser "didn't seem to support CSS_DIMENSION".
+
+MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult)
     : m_mediaType(acceptedMediaType)
     , m_frame(0)
     , m_style(0)
-    , m_expResult(mediaFeatureResult)
+    , m_mediaFeatureResult(mediaFeatureResult)
 {
 }
 
-MediaQueryEvaluator:: MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult)
+MediaQueryEvaluator::MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult)
     : m_mediaType(acceptedMediaType)
     , m_frame(0)
     , m_style(0)
-    , m_expResult(mediaFeatureResult)
+    , m_mediaFeatureResult(mediaFeatureResult)
 {
 }
 
-MediaQueryEvaluator:: MediaQueryEvaluator(const String& acceptedMediaType, Frame* frame, RenderStyle* style)
+MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, Frame* frame, RenderStyle* style)
     : m_mediaType(acceptedMediaType)
     , m_frame(frame)
     , m_style(style)
-    , m_expResult(false) // doesn't matter when we have m_frame and m_style
+    , m_mediaFeatureResult(false) // Ignored if both m_frame and m_style are non-null.
 {
 }
 
@@ -136,35 +126,35 @@
         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();
+    bool result = true;
 
-        if (query->ignored())
+    // Iterate over queries and stop if any of them eval to true ("or" semantics).
+    for (size_t i = 0; i < queries.size(); ++i) {
+        const MediaQuery& query = *queries[i];
+
+        result = false;
+
+        if (query.ignored())
             continue;
 
-        if (mediaTypeMatch(query->mediaType())) {
-            const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions();
+        if (mediaTypeMatch(query.mediaType())) {
+            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);
-                if (!exprResult)
+            for (; j < expressions.size(); ++j) {
+                result = eval(*expressions[j]);
+                if (styleResolver && expressions[j]->isViewportDependent())
+                    styleResolver->addViewportDependentMediaQueryResult(*expressions[j], result);
+                if (!result)
                     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);
+        result = applyRestrictor(query.restrictor(), result);
+        if (result)
+            break;
     }
 
     return result;
@@ -263,7 +253,7 @@
         int h = 0;
         int v = 0;
         if (parseAspectRatio(value, h, v))
-            return v != 0 && compareValue(width * v, height * h, op);
+            return v && compareValue(width * v, height * h, op);
         return false;
     }
 
@@ -279,7 +269,7 @@
         int h = 0;
         int v = 0;
         if (parseAspectRatio(value, h, v))
-            return v != 0  && compareValue(static_cast<int>(sg.width()) * v, static_cast<int>(sg.height()) * h, op);
+            return v && compareValue(static_cast<int>(sg.width()) * v, static_cast<int>(sg.height()) * h, op);
         return false;
     }
 
@@ -503,68 +493,51 @@
 
 static bool transform_3dMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, MediaFeaturePrefix op)
 {
-    bool returnValueIfNoParameter;
-    int have3dRendering;
-
-#if ENABLE(3D_RENDERING)
     bool threeDEnabled = false;
-#if USE(ACCELERATED_COMPOSITING)
+#if ENABLE(3D_RENDERING) && USE(ACCELERATED_COMPOSITING)
     if (RenderView* view = frame->contentRenderer())
         threeDEnabled = view->compositor()->canRender3DTransforms();
-#endif
-
-    returnValueIfNoParameter = threeDEnabled;
-    have3dRendering = threeDEnabled ? 1 : 0;
 #else
     UNUSED_PARAM(frame);
-    returnValueIfNoParameter = false;
-    have3dRendering = 0;
 #endif
-
     if (value) {
         float number;
-        return numberValue(value, number) && compareValue(have3dRendering, static_cast<int>(number), op);
+        return numberValue(value, number) && compareValue(static_cast<int>(threeDEnabled), static_cast<int>(number), op);
     }
-    return returnValueIfNoParameter;
+    return threeDEnabled;
 }
 
 static bool view_modeMediaFeatureEval(CSSValue* value, RenderStyle*, Frame* frame, MediaFeaturePrefix op)
 {
-    UNUSED_PARAM(op);
+    ASSERT_UNUSED(op, op == NoPrefix);
     if (!value)
         return true;
     return Page::stringToViewMode(static_cast<CSSPrimitiveValue*>(value)->getStringValue()) == frame->page()->viewMode();
 }
 
-static void createFunctionMap()
+static FunctionMap* createFunctionMap()
 {
-    // Create the table.
-    gFunctionMap = new FunctionMap;
+    FunctionMap* functionMap = new FunctionMap;
 #define ADD_TO_FUNCTIONMAP(name, str)  \
-    gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
+    functionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
     CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
 #undef ADD_TO_FUNCTIONMAP
+    return functionMap;
 }
 
-bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
+bool MediaQueryEvaluator::eval(const MediaQueryExp& _expression_) const
 {
     if (!m_frame || !m_style)
-        return m_expResult;
+        return m_mediaFeatureResult;
 
-    if (!expr->isValid())
+    if (!_expression_.isValid())
         return false;
 
-    if (!gFunctionMap)
-        createFunctionMap();
+    static FunctionMap* functionMap = createFunctionMap();
+    MediaFeatureEvaluationFunction function = functionMap->get(_expression_.mediaFeature().impl());
 
-    // call the media feature evaluation function. Assume no prefix
-    // and let trampoline functions override the prefix if prefix is
-    // used
-    EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
-    if (func)
-        return func(expr->value(), m_style.get(), m_frame, NoPrefix);
-
-    return false;
+    // Start with no prefix: Some trampoline functions add the prefix and call other media feature functions.
+    return function && function(_expression_.value(), m_style.get(), m_frame, NoPrefix);
 }
 
 } // namespace

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.h (118649 => 118650)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.h	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.h	2012-05-28 07:11:20 UTC (rev 118650)
@@ -31,42 +31,30 @@
 #include "PlatformString.h"
 
 namespace WebCore {
+
 class Frame;
 class MediaQueryExp;
 class MediaQuerySet;
 class RenderStyle;
 class StyleResolver;
 
-/**
- * Class that evaluates css media queries as defined in
- * CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/)
- * Special constructors are needed, if simple media queries are to be
- * evaluated without knowledge of the medium features. This can happen
- * for example when parsing UA stylesheets, if evaluation is done
- * right after parsing.
- *
- * the boolean parameter is used to approximate results of evaluation, if
- * the device characteristics are not known. This can be used to prune the loading
- * of stylesheets to only those which are probable to match.
- */
+// Class that evaluates CSS media queries as defined in CSS3 Module "Media Queries".
+//
+// Special constructors are supplied so that simple media queries can be
+// evaluated without knowledge of device characteristics. This is used, for example,
+// when parsing user agent stylesheets. The boolean parameter to the constructor is used
+// if the device characteristics are not known. This can be used to prune loading
+// of stylesheets to remove those that definitely won't match.
+
 class MediaQueryEvaluator {
      WTF_MAKE_NONCOPYABLE(MediaQueryEvaluator); WTF_MAKE_FAST_ALLOCATED;
 public:
-    /** Creates evaluator which evaluates only simple media queries
-     *  Evaluator returns true for "all", and returns value of \mediaFeatureResult
-     *  for any media features
-     */
-    MediaQueryEvaluator(bool mediaFeatureResult = false);
-
-    /** Creates evaluator which evaluates only simple media queries
-     *  Evaluator  returns true for acceptedMediaType and returns value of \mediafeatureResult
-     *  for any media features
-     */
+    // Creates evaluator which evaluates only simple media queries.
+    // Evaluator returns true for acceptedMediaType and uses mediaFeatureResult for any media features.
     MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult = false);
     MediaQueryEvaluator(const char* acceptedMediaType, bool mediaFeatureResult = false);
 
-    /** Creates evaluator which evaluates full media queries
-     */
+    // Creates evaluator which evaluates full media queries.
     MediaQueryEvaluator(const String& acceptedMediaType, Frame*, RenderStyle*);
 
     ~MediaQueryEvaluator();
@@ -74,18 +62,19 @@
     bool mediaTypeMatch(const String& mediaTypeToMatch) const;
     bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const;
 
-    /** Evaluates a list of media queries */
+    // Evaluates a list of media queries.
     bool eval(const MediaQuerySet*, StyleResolver* = 0) const;
 
-    /** Evaluates media query subexpression, ie "and (media-feature: value)" part */
-    bool eval(const MediaQueryExp*) const;
+    // Evaluates media query subexpression, i.e. "and (media-feature: value)" part.
+    bool eval(const MediaQueryExp&) const;
 
 private:
     String m_mediaType;
     Frame* m_frame; // not owned
     RefPtr<RenderStyle> m_style;
-    bool m_expResult;
+    bool m_mediaFeatureResult;
 };
 
-} // namespace
+} // namespace WebCore
+
 #endif

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (118649 => 118650)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-05-28 07:11:20 UTC (rev 118650)
@@ -77,6 +77,7 @@
 #include "MatrixTransformOperation.h"
 #include "MediaList.h"
 #include "MediaQueryEvaluator.h"
+#include "MediaQueryExp.h"
 #include "NodeRenderStyle.h"
 #include "Page.h"
 #include "PageGroup.h"
@@ -160,6 +161,17 @@
 
 using namespace HTMLNames;
 
+struct MediaQueryResult {
+    MediaQueryResult(const MediaQueryExp& _expression_, bool result)
+        : _expression_(_expression_)
+        , result(result)
+    {
+    }
+
+    MediaQueryExp _expression_;
+    bool result;
+};
+
 #define HANDLE_INHERIT(prop, Prop) \
 if (isInherit) { \
     m_style->set##Prop(m_parentStyle->prop()); \
@@ -5128,16 +5140,16 @@
     return m_features.attrsInRules.contains(attrname.impl());
 }
 
-void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
+void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp& _expression_, bool result)
 {
-    m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*expr, result)));
+    m_viewportDependentMediaQueryResults.append(MediaQueryResult(_expression_, result));
 }
 
 bool StyleResolver::affectedByViewportChange() const
 {
-    unsigned s = m_viewportDependentMediaQueryResults.size();
-    for (unsigned i = 0; i < s; i++) {
-        if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
+    unsigned size = m_viewportDependentMediaQueryResults.size();
+    for (unsigned i = 0; i < size; i++) {
+        if (m_medium->eval(m_viewportDependentMediaQueryResults[i]._expression_) != m_viewportDependentMediaQueryResults[i].result)
             return true;
     }
     return false;

Modified: trunk/Source/WebCore/css/StyleResolver.h (118649 => 118650)


--- trunk/Source/WebCore/css/StyleResolver.h	2012-05-28 05:48:45 UTC (rev 118649)
+++ trunk/Source/WebCore/css/StyleResolver.h	2012-05-28 07:11:20 UTC (rev 118650)
@@ -22,52 +22,32 @@
 #ifndef StyleResolver_h
 #define StyleResolver_h
 
-#include "CSSRule.h"
-#include "CSSValueList.h"
 #include "LinkHash.h"
-#include "MediaQueryExp.h"
 #include "RenderStyle.h"
 #include "SelectorChecker.h"
-#include <wtf/HashMap.h>
-#include <wtf/HashSet.h>
-#include <wtf/RefPtr.h>
-#include <wtf/Vector.h>
-#include <wtf/text/StringHash.h>
 
 namespace WebCore {
 
-enum ESmartMinimumForFontSize { DoNotUseSmartMinimumForFontSize, UseSmartMinimumForFontFize };
-
 class CSSFontSelector;
-class CSSPageRule;
-class CSSPrimitiveValue;
-class CSSProperty;
-class CSSRuleList;
-class CSSFontFace;
-class CSSFontFaceRule;
 class CSSImageGeneratorValue;
 class CSSImageSetValue;
 class CSSImageValue;
-class CSSSelector;
+class CSSRuleList;
 class CSSStyleRule;
 class CSSStyleSheet;
-class CSSValue;
 class ContainerNode;
 class CustomFilterOperation;
 class CustomFilterParameter;
 class Document;
 class Element;
-class Frame;
-class FrameView;
-class KURL;
 class KeyframeList;
 class KeyframeValue;
 class MediaQueryEvaluator;
+class MediaQueryExp;
 class Node;
 class RenderRegion;
 class RuleData;
 class RuleSet;
-class Settings;
 class StaticCSSRuleList;
 class StyleBuilder;
 class StyleImage;
@@ -77,32 +57,20 @@
 class StyleRule;
 class StyleRuleKeyframes;
 class StyleRulePage;
-class StyleRuleRegion;
 class StyleShader;
-class StyleSheet;
 class StyleSheetContents;
-class StyleSheetList;
 class StyledElement;
 class WebKitCSSFilterValue;
 class WebKitCSSShaderValue;
 
+struct MediaQueryResult;
+
+enum ESmartMinimumForFontSize { DoNotUseSmartMinimumForFontSize, UseSmartMinimumForFontFize };
+    
 #if ENABLE(CSS_SHADERS)
 typedef Vector<RefPtr<CustomFilterParameter> > CustomFilterParameterList;
 #endif
 
-class MediaQueryResult {
-    WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
-public:
-    MediaQueryResult(const MediaQueryExp& expr, bool result)
-        : m_expression(expr)
-        , m_result(result)
-    {
-    }
-
-    MediaQueryExp m_expression;
-    bool m_result;
-};
-
 enum StyleSharingBehavior {
     AllowStyleSharing,
     DisallowStyleSharing,
@@ -225,7 +193,7 @@
 
     CSSFontSelector* fontSelector() const { return m_fontSelector.get(); }
 
-    void addViewportDependentMediaQueryResult(const MediaQueryExp*, bool result);
+    void addViewportDependentMediaQueryResult(const MediaQueryExp&, bool result);
 
     bool affectedByViewportChange() const;
 
@@ -496,7 +464,7 @@
     bool m_sameOriginOnly;
 
     RefPtr<CSSFontSelector> m_fontSelector;
-    Vector<OwnPtr<MediaQueryResult> > m_viewportDependentMediaQueryResults;
+    Vector<MediaQueryResult> m_viewportDependentMediaQueryResults;
 
     bool m_applyPropertyToRegularStyle;
     bool m_applyPropertyToVisitedLinkStyle;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to