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

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: 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 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 #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 WebCore { 29 namespace WebCore {
29 30
30 PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(PassRefPtrWillBeRa wPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media) 31 PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(PassRefPtrWillBeRa wPtr<MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media, Do cument* document)
31 { 32 {
32 return adoptRefWillBeNoop(new MediaQueryList(matcher, media)); 33 return adoptRefWillBeNoop(new MediaQueryList(matcher, media, document));
33 } 34 }
34 35
35 MediaQueryList::MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher , PassRefPtrWillBeRawPtr<MediaQuerySet> media) 36 MediaQueryList::MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher> matcher , PassRefPtrWillBeRawPtr<MediaQuerySet> media, Document* document)
36 : m_matcher(matcher) 37 : m_matcher(matcher)
37 , m_media(media) 38 , m_media(media)
39 , m_document(document)
38 , m_matchesDirty(true) 40 , m_matchesDirty(true)
39 , m_matches(false) 41 , m_matches(false)
40 { 42 {
43 ScriptWrappable::init(this);
41 m_matcher->addMediaQueryList(this); 44 m_matcher->addMediaQueryList(this);
42 updateMatches(); 45 updateMatches();
43 } 46 }
44 47
45 MediaQueryList::~MediaQueryList() 48 MediaQueryList::~MediaQueryList()
46 { 49 {
47 #if !ENABLE(OILPAN) 50 #if !ENABLE(OILPAN)
48 m_matcher->removeMediaQueryList(this); 51 m_matcher->removeMediaQueryList(this);
49 #endif 52 #endif
50 } 53 }
51 54
52 String MediaQueryList::media() const 55 String MediaQueryList::media() const
53 { 56 {
54 return m_media->mediaText(); 57 return m_media->mediaText();
55 } 58 }
56 59
57 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener) 60 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<EventListener> listener)
61 {
62 addEventListener("change", listener, false);
63 }
64
65 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<EventListener> listen er)
66 {
67 removeEventListener("change", listener.get(), false);
68 }
69
70 void MediaQueryList::addMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQuery ListListener> listener)
58 { 71 {
59 if (!listener) 72 if (!listener)
60 return; 73 return;
61 74
62 listener->setMediaQueryList(this); 75 listener->setMediaQueryList(this);
63 m_listeners.add(listener); 76 m_listeners.add(listener);
64 } 77 }
65 78
66 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene r> listener) 79 void MediaQueryList::removeMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQu eryListListener> listener)
67 { 80 {
68 if (!listener) 81 if (!listener)
69 return; 82 return;
70 83
71 RefPtrWillBeRawPtr<MediaQueryList> protect(this); 84 RefPtrWillBeRawPtr<MediaQueryList> protect(this);
72 listener->clearMediaQueryList(); 85 listener->clearMediaQueryList();
73 86
74 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end( ); it != end; ++it) { 87 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end( ); it != end; ++it) {
75 // We can't just use m_listeners.remove() here, because we get a new wra pper for the 88 // We can't just use m_listeners.remove() here, because we get a new wra pper for the
76 // listener callback every time. We have to use MediaQueryListListener:: operator==. 89 // listener callback every time. We have to use MediaQueryListListener:: operator==.
77 if (**it == *listener.get()) { 90 if (**it == *listener.get()) {
78 m_listeners.remove(it); 91 m_listeners.remove(it);
79 break; 92 break;
80 } 93 }
81 } 94 }
82 } 95 }
83 96
84 void MediaQueryList::documentDetached() 97 void MediaQueryList::documentDetached()
85 { 98 {
86 m_listeners.clear(); 99 m_listeners.clear();
100 m_document = nullptr;
87 } 101 }
88 102
89 void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify) 103 bool MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify)
90 { 104 {
91 m_matchesDirty = true; 105 m_matchesDirty = true;
92 if (!updateMatches()) 106 if (!updateMatches())
93 return; 107 return false;
94 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) { 108 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) {
95 listenersToNotify->append(*it); 109 listenersToNotify->append(*it);
96 } 110 }
111 return hasEventListeners(EventTypeNames::change);
97 } 112 }
98 113
99 bool MediaQueryList::updateMatches() 114 bool MediaQueryList::updateMatches()
100 { 115 {
101 m_matchesDirty = false; 116 m_matchesDirty = false;
102 if (m_matches != m_matcher->evaluate(m_media.get())) { 117 if (m_matches != m_matcher->evaluate(m_media.get())) {
103 m_matches = !m_matches; 118 m_matches = !m_matches;
104 return true; 119 return true;
105 } 120 }
106 return false; 121 return false;
107 } 122 }
108 123
109 bool MediaQueryList::matches() 124 bool MediaQueryList::matches()
110 { 125 {
111 updateMatches(); 126 updateMatches();
112 return m_matches; 127 return m_matches;
113 } 128 }
114 129
115 void MediaQueryList::trace(Visitor* visitor) 130 void MediaQueryList::trace(Visitor* visitor)
116 { 131 {
132 EventTargetWithInlineData::trace(visitor);
117 visitor->trace(m_matcher); 133 visitor->trace(m_matcher);
118 visitor->trace(m_media); 134 visitor->trace(m_media);
119 visitor->trace(m_listeners); 135 visitor->trace(m_listeners);
120 } 136 }
121 137
138 const AtomicString& MediaQueryList::interfaceName() const
139 {
140 return EventTargetNames::MediaQueryList;
122 } 141 }
142
143 ExecutionContext* MediaQueryList::executionContext() const
144 {
145 return m_document.get();
146 }
147
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698