initial import
[vuplus_webkit] / Source / WebCore / css / MediaQueryList.h
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 <wtf/Forward.h>
24 #include <wtf/RefCounted.h>
25 #include <wtf/RefPtr.h>
26
27 namespace WebCore {
28
29 class MediaList;
30 class MediaQueryListListener;
31 class MediaQueryEvaluator;
32 class MediaQueryMatcher;
33
34 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface
35 // The objects of this class are returned by window.matchMedia. They may be used to
36 // retrieve the current value of the given media query and to add/remove listeners that
37 // will be called whenever the value of the query changes.
38
39 class MediaQueryList : public RefCounted<MediaQueryList> {
40 public:
41     static PassRefPtr<MediaQueryList> create(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaList>, bool);
42     ~MediaQueryList();
43
44     String media() const;
45     bool matches();
46
47     void addListener(PassRefPtr<MediaQueryListListener>);
48     void removeListener(PassRefPtr<MediaQueryListListener>);
49
50     void evaluate(MediaQueryEvaluator*, bool& notificationNeeded);
51
52 private:
53     MediaQueryList(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaList>, bool matches);
54     void setMatches(bool);
55
56     RefPtr<MediaQueryMatcher> m_matcher;
57     RefPtr<MediaList> m_media;
58     unsigned m_evaluationRound; // Indicates if the query has been evaluated after the last style selector change.
59     unsigned m_changeRound; // Used to know if the query has changed in the last style selector change.
60     bool m_matches;
61 };
62
63 }
64
65 #endif // MediaQueryList_h