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 "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" 30 31 namespace blink { 32 33 class ExecutionContext; 34 class MediaQueryListListener; 35 class MediaQueryMatcher; 36 class MediaQuerySet; 37 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. 42 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); 47 public: 48 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); 49 virtual ~MediaQueryList(); 50 51 String media() const; 52 bool matches(); 53 54 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); 55 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>); 60 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>); 64 65 // Will return true if a DOM event should be scheduled. 66 bool mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryListListener> >* listenersToNotify); 67 68 void trace(Visitor*); 69 70 // From ActiveDOMObject 71 virtual bool hasPendingActivity() const OVERRIDE; 72 virtual void stop() OVERRIDE; 73 74 virtual const AtomicString& interfaceName() const OVERRIDE; 75 virtual ExecutionContext* executionContext() const OVERRIDE; 76 77 private: 78 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); 79 80 bool updateMatches(); 81 82 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; 83 RefPtrWillBeMember<MediaQuerySet> m_media; 84 typedef WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryListListener> > ListenerList; 85 ListenerList m_listeners; 86 bool m_matchesDirty; 87 bool m_matches; 88 }; 89 90 } // namespace blink 91 92 #endif // MediaQueryList_h 93