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#pragma once
21
22#include <wtf/Forward.h>
23#include <wtf/RefCounted.h>
24#include <wtf/RefPtr.h>
25
26namespace WebCore {
27
28class MediaQueryListListener;
29class MediaQueryEvaluator;
30class MediaQueryMatcher;
31class MediaQuerySet;
32
33// MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface
34// The objects of this class are returned by window.matchMedia. They may be used to
35// retrieve the current value of the given media query and to add/remove listeners that
36// will be called whenever the value of the query changes.
37
38class MediaQueryList final : public RefCounted<MediaQueryList> {
39public:
40 static Ref<MediaQueryList> create(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool);
41 ~MediaQueryList();
42
43 String media() const;
44 bool matches();
45
46 void addListener(RefPtr<MediaQueryListListener>&&);
47 void removeListener(RefPtr<MediaQueryListListener>&&);
48
49 void evaluate(MediaQueryEvaluator&, bool& notificationNeeded);
50
51private:
52 MediaQueryList(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool matches);
53
54 void setMatches(bool);
55
56 Ref<MediaQueryMatcher> m_matcher;
57 Ref<MediaQuerySet> 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