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

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: argh, forgot a --reset-results Created 6 years, 5 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 70943e0a5c10d6f506881ca65ea02b4eac5b4325..4b3408040e1960bbb629f62c7921a6ecf9643445 100644
--- a/Source/core/css/MediaQueryList.cpp
+++ b/Source/core/css/MediaQueryList.cpp
@@ -24,20 +24,23 @@
#include "core/css/MediaQueryEvaluator.h"
#include "core/css/MediaQueryListListener.h"
#include "core/css/MediaQueryMatcher.h"
+#include "core/dom/Document.h"
namespace WebCore {
-PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media)
+PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media, Document* document)
{
- return adoptRefWillBeNoop(new MediaQueryList(matcher, media));
+ return adoptRefWillBeNoop(new MediaQueryList(matcher, media, document));
}
-MediaQueryList::MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media)
+MediaQueryList::MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media, Document* document)
: m_matcher(matcher)
, m_media(media)
+ , m_document(document)
, m_matchesDirty(true)
, m_matches(false)
{
+ ScriptWrappable::init(this);
m_matcher->addMediaQueryList(this);
updateMatches();
}
@@ -54,7 +57,17 @@ String MediaQueryList::media() const
return m_media->mediaText();
}
-void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
+void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<EventListener> listener)
+{
+ addEventListener("change", listener, false);
+}
+
+void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<EventListener> listener)
+{
+ removeEventListener("change", listener.get(), false);
+}
+
+void MediaQueryList::addMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
{
if (!listener)
return;
@@ -63,7 +76,7 @@ void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>
m_listeners.add(listener);
}
-void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
+void MediaQueryList::removeMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
{
if (!listener)
return;
@@ -84,16 +97,18 @@ void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene
void MediaQueryList::documentDetached()
{
m_listeners.clear();
+ m_document = nullptr;
}
-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()
@@ -114,9 +129,20 @@ bool MediaQueryList::matches()
void MediaQueryList::trace(Visitor* visitor)
{
+ EventTargetWithInlineData::trace(visitor);
visitor->trace(m_matcher);
visitor->trace(m_media);
visitor->trace(m_listeners);
}
+const AtomicString& MediaQueryList::interfaceName() const
+{
+ return EventTargetNames::MediaQueryList;
+}
+
+ExecutionContext* MediaQueryList::executionContext() const
+{
+ return m_document.get();
+}
+
}

Powered by Google App Engine
This is Rietveld 408576698