Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: Source/core/css/MediaQueryList.h

Issue 396283004: Make the MediaQueryList listener an EventListener (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 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 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, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #ifndef MediaQueryList_h 20 #ifndef MediaQueryList_h
21 #define MediaQueryList_h 21 #define MediaQueryList_h
22 22
23 #include "bindings/core/v8/ScriptWrappable.h" 23 #include "bindings/core/v8/ScriptWrappable.h"
24 #include "core/dom/ActiveDOMObject.h" 24 #include "core/dom/ActiveDOMObject.h"
25 #include "core/events/EventTarget.h"
25 #include "platform/heap/Handle.h" 26 #include "platform/heap/Handle.h"
26 #include "wtf/Forward.h" 27 #include "wtf/Forward.h"
27 #include "wtf/RefCounted.h" 28 #include "wtf/RefCounted.h"
28 #include "wtf/RefPtr.h" 29 #include "wtf/RefPtr.h"
29 30
30 namespace blink { 31 namespace blink {
31 32
33 class Document;
32 class ExecutionContext; 34 class ExecutionContext;
33 class MediaQueryListListener; 35 class MediaQueryListListener;
34 class MediaQueryEvaluator; 36 class MediaQueryEvaluator;
35 class MediaQueryMatcher; 37 class MediaQueryMatcher;
36 class MediaQuerySet; 38 class MediaQuerySet;
37 39
38 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/# the-mediaquerylist-interface 40 // 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 41 // 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 listene rs that 42 // retrieve the current value of the given media query and to add/remove listene rs that
41 // will be called whenever the value of the query changes. 43 // will be called whenever the value of the query changes.
42 44
43 class MediaQueryList FINAL : public RefCountedWillBeGarbageCollectedFinalized<Me diaQueryList>, public ActiveDOMObject, public ScriptWrappable { 45 class MediaQueryList FINAL : public RefCountedWillBeGarbageCollectedFinalized<Me diaQueryList>, public EventTargetWithInlineData, public ActiveDOMObject {
46 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCounted<MediaQueryList>);
47 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaQueryList);
44 public: 48 public:
45 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, Pass RefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); 49 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, Pass RefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>);
46 virtual ~MediaQueryList(); 50 virtual ~MediaQueryList();
47 51
48 String media() const; 52 String media() const;
49 bool matches(); 53 bool matches();
50 54
55 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
56
57 // These two functions are provided for compatibility with JS code
58 // written before the change listener became a DOM event.
59 void addDeprecatedListener(PassRefPtr<EventListener>);
60 void removeDeprecatedListener(PassRefPtr<EventListener>);
61
62 // C++ code can use these functions to listen to changes instead of having t o use DOM event listeners.
51 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); 63 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
52 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); 64 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>);
53 65
54 void mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryList Listener> >* listenersToNotify); 66 // Will return true if a DOM event should be scheduled.
67 bool mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryList Listener> >* listenersToNotify);
55 68
56 void trace(Visitor*); 69 void trace(Visitor*);
57 70
58 // From ActiveDOMObject 71 // From ActiveDOMObject
59 virtual bool hasPendingActivity() const OVERRIDE; 72 virtual bool hasPendingActivity() const OVERRIDE;
60 virtual void stop() OVERRIDE; 73 virtual void stop() OVERRIDE;
61 74
75 virtual const AtomicString& interfaceName() const OVERRIDE;
76 virtual ExecutionContext* executionContext() const OVERRIDE;
77
62 private: 78 private:
63 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); 79 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>);
64 80
65 bool updateMatches(); 81 bool updateMatches();
66 82
67 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; 83 RefPtrWillBeMember<MediaQueryMatcher> m_matcher;
68 RefPtrWillBeMember<MediaQuerySet> m_media; 84 RefPtrWillBeMember<MediaQuerySet> m_media;
69 typedef WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryListListener> > L istenerList; 85 typedef WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryListListener> > L istenerList;
70 ListenerList m_listeners; 86 ListenerList m_listeners;
71 bool m_matchesDirty; 87 bool m_matchesDirty;
72 bool m_matches; 88 bool m_matches;
73 }; 89 };
74 90
75 } 91 }
76 92
77 #endif // MediaQueryList_h 93 #endif // MediaQueryList_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698