2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
20 #ifndef MediaQueryList_h
21 #define MediaQueryList_h
23 #include "bindings/core/v8/ScriptWrappable.h"
24 #include "core/dom/ActiveDOMObject.h"
25 #include "core/events/EventTarget.h"
26 #include "platform/heap/Handle.h"
27 #include "wtf/Forward.h"
28 #include "wtf/RefCounted.h"
29 #include "wtf/RefPtr.h"
33 class ExecutionContext;
34 class MediaQueryListListener;
35 class MediaQueryMatcher;
38 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface
39 // The objects of this class are returned by window.matchMedia. They may be used to
40 // retrieve the current value of the given media query and to add/remove listeners that
41 // will be called whenever the value of the query changes.
43 class MediaQueryList final : public RefCountedWillBeGarbageCollectedFinalized<MediaQueryList>, public EventTargetWithInlineData, public ActiveDOMObject {
44 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCounted<MediaQueryList>);
45 DEFINE_WRAPPERTYPEINFO();
46 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaQueryList);
48 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>);
49 virtual ~MediaQueryList();
54 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
56 // These two functions are provided for compatibility with JS code
57 // written before the change listener became a DOM event.
58 void addDeprecatedListener(PassRefPtr<EventListener>);
59 void removeDeprecatedListener(PassRefPtr<EventListener>);
61 // C++ code can use these functions to listen to changes instead of having to use DOM event listeners.
62 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
63 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
65 // Will return true if a DOM event should be scheduled.
66 bool mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryListListener> >* listenersToNotify);
70 // From ActiveDOMObject
71 virtual bool hasPendingActivity() const override;
72 virtual void stop() override;
74 virtual const AtomicString& interfaceName() const override;
75 virtual ExecutionContext* executionContext() const override;
78 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>);
82 RefPtrWillBeMember<MediaQueryMatcher> m_matcher;
83 RefPtrWillBeMember<MediaQuerySet> m_media;
84 typedef WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryListListener> > ListenerList;
85 ListenerList m_listeners;
92 #endif // MediaQueryList_h