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

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

Issue 396283004: Make the MediaQueryList listener an EventListener (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 6 years, 3 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
« no previous file with comments | « Source/core/css/MediaQueryList.h ('k') | Source/core/css/MediaQueryList.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "config.h" 20 #include "config.h"
21 #include "core/css/MediaQueryList.h" 21 #include "core/css/MediaQueryList.h"
22 22
23 #include "core/css/MediaList.h" 23 #include "core/css/MediaList.h"
24 #include "core/css/MediaQueryEvaluator.h" 24 #include "core/css/MediaQueryEvaluator.h"
25 #include "core/css/MediaQueryListListener.h" 25 #include "core/css/MediaQueryListListener.h"
26 #include "core/css/MediaQueryMatcher.h" 26 #include "core/css/MediaQueryMatcher.h"
27 #include "core/dom/Document.h"
27 28
28 namespace blink { 29 namespace blink {
29 30
30 PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(ExecutionContext* context, PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawP tr<MediaQuerySet> media) 31 PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(ExecutionContext* context, PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawP tr<MediaQuerySet> media)
31 { 32 {
32 RefPtrWillBeRawPtr<MediaQueryList> list = adoptRefWillBeNoop(new MediaQueryL ist(context, matcher, media)); 33 RefPtrWillBeRawPtr<MediaQueryList> list = adoptRefWillBeNoop(new MediaQueryL ist(context, matcher, media));
33 list->suspendIfNeeded(); 34 list->suspendIfNeeded();
34 return list.release(); 35 return list.release();
35 } 36 }
36 37
(...skipping 14 matching lines...) Expand all
51 #if !ENABLE(OILPAN) 52 #if !ENABLE(OILPAN)
52 m_matcher->removeMediaQueryList(this); 53 m_matcher->removeMediaQueryList(this);
53 #endif 54 #endif
54 } 55 }
55 56
56 String MediaQueryList::media() const 57 String MediaQueryList::media() const
57 { 58 {
58 return m_media->mediaText(); 59 return m_media->mediaText();
59 } 60 }
60 61
62 void MediaQueryList::addDeprecatedListener(PassRefPtr<EventListener> listener)
63 {
64 addEventListener(EventTypeNames::change, listener, false);
65 }
66
67 void MediaQueryList::removeDeprecatedListener(PassRefPtr<EventListener> listener )
68 {
69 removeEventListener(EventTypeNames::change, listener, false);
70 }
71
61 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener) 72 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
62 { 73 {
63 if (!listener) 74 if (!listener)
64 return; 75 return;
65 76
66 listener->setMediaQueryList(this); 77 listener->setMediaQueryList(this);
67 m_listeners.add(listener); 78 m_listeners.add(listener);
68 } 79 }
69 80
70 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene r> listener) 81 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene r> listener)
71 { 82 {
72 if (!listener) 83 if (!listener)
73 return; 84 return;
74 85
75 RefPtrWillBeRawPtr<MediaQueryList> protect(this); 86 RefPtrWillBeRawPtr<MediaQueryList> protect(this);
76 listener->clearMediaQueryList(); 87 listener->clearMediaQueryList();
77 88 m_listeners.remove(listener);
78 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end( ); it != end; ++it) {
79 // We can't just use m_listeners.remove() here, because we get a new wra pper for the
80 // listener callback every time. We have to use MediaQueryListListener:: operator==.
81 if (**it == *listener.get()) {
82 m_listeners.remove(it);
83 break;
84 }
85 }
86 } 89 }
87 90
88 bool MediaQueryList::hasPendingActivity() const 91 bool MediaQueryList::hasPendingActivity() const
89 { 92 {
90 return m_listeners.size(); 93 return m_listeners.size() || hasEventListeners(EventTypeNames::change);
91 } 94 }
92 95
93 void MediaQueryList::stop() 96 void MediaQueryList::stop()
94 { 97 {
95 // m_listeners.clear() can drop the last ref to this MediaQueryList. 98 // m_listeners.clear() can drop the last ref to this MediaQueryList.
96 RefPtrWillBeRawPtr<MediaQueryList> protect(this); 99 RefPtrWillBeRawPtr<MediaQueryList> protect(this);
97 m_listeners.clear(); 100 m_listeners.clear();
101 removeAllEventListeners();
98 } 102 }
99 103
100 void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify) 104 bool MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify)
101 { 105 {
102 m_matchesDirty = true; 106 m_matchesDirty = true;
103 if (!updateMatches()) 107 if (!updateMatches())
104 return; 108 return false;
105 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) { 109 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) {
106 listenersToNotify->append(*it); 110 listenersToNotify->append(*it);
107 } 111 }
112 return hasEventListeners(EventTypeNames::change);
108 } 113 }
109 114
110 bool MediaQueryList::updateMatches() 115 bool MediaQueryList::updateMatches()
111 { 116 {
112 m_matchesDirty = false; 117 m_matchesDirty = false;
113 if (m_matches != m_matcher->evaluate(m_media.get())) { 118 if (m_matches != m_matcher->evaluate(m_media.get())) {
114 m_matches = !m_matches; 119 m_matches = !m_matches;
115 return true; 120 return true;
116 } 121 }
117 return false; 122 return false;
118 } 123 }
119 124
120 bool MediaQueryList::matches() 125 bool MediaQueryList::matches()
121 { 126 {
122 updateMatches(); 127 updateMatches();
123 return m_matches; 128 return m_matches;
124 } 129 }
125 130
126 void MediaQueryList::trace(Visitor* visitor) 131 void MediaQueryList::trace(Visitor* visitor)
127 { 132 {
128 #if ENABLE(OILPAN) 133 #if ENABLE(OILPAN)
129 visitor->trace(m_matcher); 134 visitor->trace(m_matcher);
130 visitor->trace(m_media); 135 visitor->trace(m_media);
131 visitor->trace(m_listeners); 136 visitor->trace(m_listeners);
132 #endif 137 #endif
138 EventTargetWithInlineData::trace(visitor);
139 }
140
141 const AtomicString& MediaQueryList::interfaceName() const
142 {
143 return EventTargetNames::MediaQueryList;
144 }
145
146 ExecutionContext* MediaQueryList::executionContext() const
147 {
148 return ActiveDOMObject::executionContext();
133 } 149 }
134 150
135 } 151 }
OLDNEW
« no previous file with comments | « Source/core/css/MediaQueryList.h ('k') | Source/core/css/MediaQueryList.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698