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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/MediaQueryList.cpp
diff --git a/Source/core/css/MediaQueryList.cpp b/Source/core/css/MediaQueryList.cpp
index 08e83c554f791d9573289f8fb99b45f52f870191..33dd91fe70657fae3cc86ede075bde447a682d1d 100644
--- a/Source/core/css/MediaQueryList.cpp
+++ b/Source/core/css/MediaQueryList.cpp
@@ -24,6 +24,7 @@
#include "core/css/MediaQueryEvaluator.h"
#include "core/css/MediaQueryListListener.h"
#include "core/css/MediaQueryMatcher.h"
+#include "core/dom/Document.h"
namespace blink {
@@ -58,6 +59,16 @@ String MediaQueryList::media() const
return m_media->mediaText();
}
+void MediaQueryList::addDeprecatedListener(PassRefPtr<EventListener> listener)
+{
+ addEventListener("change", listener, false);
esprehn 2014/08/13 22:48:36 EventTypeNames::change
cbiesinger 2014/08/16 00:00:47 Done.
+}
+
+void MediaQueryList::removeDeprecatedListener(PassRefPtr<EventListener> listener)
+{
+ removeEventListener("change", listener.get(), false);
esprehn 2014/08/13 22:48:36 listener.release()
cbiesinger 2014/08/16 00:00:47 . ../../third_party/WebKit/Source/core/css/MediaQu
cbiesinger 2014/08/16 00:01:15 Er, fixed this differently (removed the .get())
+}
+
void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
{
if (!listener)
@@ -74,20 +85,12 @@ void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene
RefPtrWillBeRawPtr<MediaQueryList> protect(this);
listener->clearMediaQueryList();
-
- for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end(); it != end; ++it) {
- // We can't just use m_listeners.remove() here, because we get a new wrapper for the
- // listener callback every time. We have to use MediaQueryListListener::operator==.
- if (**it == *listener.get()) {
- m_listeners.remove(it);
- break;
- }
- }
+ m_listeners.remove(listener);
}
bool MediaQueryList::hasPendingActivity() const
{
- return m_listeners.size();
+ return m_listeners.size() || hasEventListeners(EventTypeNames::change);
}
void MediaQueryList::stop()
@@ -95,16 +98,18 @@ void MediaQueryList::stop()
// m_listeners.clear() can drop the last ref to this MediaQueryList.
RefPtrWillBeRawPtr<MediaQueryList> protect(this);
m_listeners.clear();
+ removeAllEventListeners();
}
-void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryListListener> >* listenersToNotify)
+bool MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryListListener> >* listenersToNotify)
{
m_matchesDirty = true;
if (!updateMatches())
- return;
+ return false;
for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listeners.end(); it != end; ++it) {
listenersToNotify->append(*it);
}
+ return hasEventListeners(EventTypeNames::change);
}
bool MediaQueryList::updateMatches()
@@ -130,6 +135,17 @@ void MediaQueryList::trace(Visitor* visitor)
visitor->trace(m_media);
visitor->trace(m_listeners);
#endif
+ EventTargetWithInlineData::trace(visitor);
+}
+
+const AtomicString& MediaQueryList::interfaceName() const
+{
+ return EventTargetNames::MediaQueryList;
+}
+
+ExecutionContext* MediaQueryList::executionContext() const
+{
+ return ActiveDOMObject::executionContext();
}
}

Powered by Google App Engine
This is Rietveld 408576698