Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / MediaQueryMatcher.h
index abe8628..4d3523e 100644 (file)
@@ -23,9 +23,8 @@
 #include "platform/heap/Handle.h"
 #include "wtf/Forward.h"
 #include "wtf/RefCounted.h"
-#include "wtf/Vector.h"
 
-namespace WebCore {
+namespace blink {
 
 class Document;
 class MediaQueryList;
@@ -38,50 +37,39 @@ class MediaQuerySet;
 // whenever it is needed and to call the listeners if the corresponding query has changed.
 // The listeners must be called in the very same order in which they have been added.
 
-class MediaQueryMatcher FINAL : public RefCountedWillBeGarbageCollected<MediaQueryMatcher> {
-    DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryMatcher);
+class MediaQueryMatcher FINAL : public RefCountedWillBeGarbageCollectedFinalized<MediaQueryMatcher> {
+    DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryMatcher)
 public:
-    static PassRefPtrWillBeRawPtr<MediaQueryMatcher> create(Document* document) { return adoptRefWillBeNoop(new MediaQueryMatcher(document)); }
-    void documentDestroyed();
+    static PassRefPtrWillBeRawPtr<MediaQueryMatcher> create(Document&);
+    void documentDetached();
 
-    void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>, PassRefPtrWillBeRawPtr<MediaQueryList>);
-    void removeListener(MediaQueryListListener*, MediaQueryList*);
+    void addMediaQueryList(MediaQueryList*);
+    void removeMediaQueryList(MediaQueryList*);
+
+    void addViewportListener(MediaQueryListListener*);
+    void removeViewportListener(MediaQueryListListener*);
 
     PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&);
 
-    unsigned evaluationRound() const { return m_evaluationRound; }
-    void styleResolverChanged();
+    void mediaFeaturesChanged();
+    void viewportChanged();
     bool evaluate(const MediaQuerySet*);
 
     void trace(Visitor*);
 
 private:
-    class Listener FINAL : public NoBaseWillBeGarbageCollected<Listener> {
-    public:
-        Listener(PassRefPtrWillBeRawPtr<MediaQueryListListener>, PassRefPtrWillBeRawPtr<MediaQueryList>);
-        void evaluate(MediaQueryEvaluator*);
-
-        MediaQueryListListener* listener() { return m_listener.get(); }
-        MediaQueryList* query() { return m_query.get(); }
-
-        void trace(Visitor*);
+    explicit MediaQueryMatcher(Document&);
 
-    private:
-        RefPtrWillBeMember<MediaQueryListListener> m_listener;
-        RefPtrWillBeMember<MediaQueryList> m_query;
-    };
-
-    MediaQueryMatcher(Document*);
-    PassOwnPtr<MediaQueryEvaluator> prepareEvaluator() const;
-    AtomicString mediaType() const;
+    PassOwnPtr<MediaQueryEvaluator> createEvaluator() const;
 
     RawPtrWillBeMember<Document> m_document;
-    WillBeHeapVector<OwnPtrWillBeMember<Listener> > m_listeners;
+    OwnPtr<MediaQueryEvaluator> m_evaluator;
+
+    typedef WillBeHeapLinkedHashSet<RawPtrWillBeWeakMember<MediaQueryList> > MediaQueryListSet;
+    MediaQueryListSet m_mediaLists;
 
-    // This value is incremented at style selector changes.
-    // It is used to avoid evaluating queries more then once and to make sure
-    // that a media query result change is notified exactly once.
-    unsigned m_evaluationRound;
+    typedef WillBeHeapLinkedHashSet<RawPtrWillBeWeakMember<MediaQueryListListener> > ViewportListenerSet;
+    ViewportListenerSet m_viewportListeners;
 };
 
 }