• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MediaQueryList_h
21 #define MediaQueryList_h
22 
23 #include "platform/heap/Handle.h"
24 #include "wtf/Forward.h"
25 #include "wtf/RefCounted.h"
26 #include "wtf/RefPtr.h"
27 
28 namespace WebCore {
29 
30 class MediaQueryListListener;
31 class MediaQueryEvaluator;
32 class MediaQueryMatcher;
33 class MediaQuerySet;
34 
35 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface
36 // The objects of this class are returned by window.matchMedia. They may be used to
37 // retrieve the current value of the given media query and to add/remove listeners that
38 // will be called whenever the value of the query changes.
39 
40 class MediaQueryList FINAL : public RefCountedWillBeGarbageCollected<MediaQueryList> {
41     DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryList);
42 public:
43     static PassRefPtrWillBeRawPtr<MediaQueryList> create(PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>, bool);
44     String media() const;
45     bool matches();
46 
47     void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
48     void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
49 
50     bool evaluate(MediaQueryEvaluator*);
51 
52     void trace(Visitor*);
53 
54 private:
55     MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>, bool matches);
56     void setMatches(bool);
57 
58     RefPtrWillBeMember<MediaQueryMatcher> m_matcher;
59     RefPtrWillBeMember<MediaQuerySet> m_media;
60     unsigned m_evaluationRound; // Indicates if the query has been evaluated after the last style selector change.
61     unsigned m_changeRound; // Used to know if the query has changed in the last style selector change.
62     bool m_matches;
63 };
64 
65 }
66 
67 #endif // MediaQueryList_h
68