Home | History | Annotate | Download | only in css
      1 /*
      2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
      3  *
      4  *  This library is free software; you can redistribute it and/or
      5  *  modify it under the terms of the GNU Library General Public
      6  *  License as published by the Free Software Foundation; either
      7  *  version 2 of the License, or (at your option) any later version.
      8  *
      9  *  This library is distributed in the hope that it will be useful,
     10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  *  Library General Public License for more details.
     13  *
     14  *  You should have received a copy of the GNU Library General Public License
     15  *  along with this library; see the file COPYING.LIB.  If not, write to
     16  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  *  Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef MediaQueryMatcher_h
     21 #define MediaQueryMatcher_h
     22 
     23 #include "platform/heap/Handle.h"
     24 #include "wtf/Forward.h"
     25 #include "wtf/RefCounted.h"
     26 
     27 namespace blink {
     28 
     29 class Document;
     30 class MediaQueryList;
     31 class MediaQueryListListener;
     32 class MediaQueryEvaluator;
     33 class MediaQuerySet;
     34 
     35 // MediaQueryMatcher class is responsible for keeping a vector of pairs
     36 // MediaQueryList x MediaQueryListListener. It is responsible for evaluating the queries
     37 // whenever it is needed and to call the listeners if the corresponding query has changed.
     38 // The listeners must be called in the very same order in which they have been added.
     39 
     40 class MediaQueryMatcher FINAL : public RefCountedWillBeGarbageCollectedFinalized<MediaQueryMatcher> {
     41     DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryMatcher)
     42 public:
     43     static PassRefPtrWillBeRawPtr<MediaQueryMatcher> create(Document&);
     44     void documentDetached();
     45 
     46     void addMediaQueryList(MediaQueryList*);
     47     void removeMediaQueryList(MediaQueryList*);
     48 
     49     void addViewportListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
     50     void removeViewportListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
     51 
     52     PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&);
     53 
     54     void mediaFeaturesChanged();
     55     void viewportChanged();
     56     bool evaluate(const MediaQuerySet*);
     57 
     58     void trace(Visitor*);
     59 
     60 private:
     61     explicit MediaQueryMatcher(Document&);
     62 
     63     PassOwnPtr<MediaQueryEvaluator> createEvaluator() const;
     64 
     65     RawPtrWillBeMember<Document> m_document;
     66     OwnPtr<MediaQueryEvaluator> m_evaluator;
     67 
     68     typedef WillBeHeapLinkedHashSet<RawPtrWillBeWeakMember<MediaQueryList> > MediaQueryListSet;
     69     MediaQueryListSet m_mediaLists;
     70 
     71     typedef WillBeHeapLinkedHashSet<RefPtrWillBeMember<MediaQueryListListener> > ViewportListenerSet;
     72     ViewportListenerSet m_viewportListeners;
     73 };
     74 
     75 }
     76 
     77 #endif // MediaQueryMatcher_h
     78