OLD | NEW |
---|---|
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 |
37 MediaQueryList::MediaQueryList(ExecutionContext* context, PassRefPtrWillBeRawPtr <MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media) | 38 MediaQueryList::MediaQueryList(ExecutionContext* context, PassRefPtrWillBeRawPtr <MediaQueryMatcher> matcher, PassRefPtrWillBeRawPtr<MediaQuerySet> media) |
38 : ActiveDOMObject(context) | 39 : ActiveDOMObject(context) |
39 , m_matcher(matcher) | 40 , m_matcher(matcher) |
40 , m_media(media) | 41 , m_media(media) |
41 , m_matchesDirty(true) | 42 , m_matchesDirty(true) |
42 , m_matches(false) | 43 , m_matches(false) |
43 { | 44 { |
45 ScriptWrappable::init(this); | |
44 m_matcher->addMediaQueryList(this); | 46 m_matcher->addMediaQueryList(this); |
45 updateMatches(); | 47 updateMatches(); |
46 } | 48 } |
47 | 49 |
48 MediaQueryList::~MediaQueryList() | 50 MediaQueryList::~MediaQueryList() |
49 { | 51 { |
50 #if !ENABLE(OILPAN) | 52 #if !ENABLE(OILPAN) |
51 m_matcher->removeMediaQueryList(this); | 53 m_matcher->removeMediaQueryList(this); |
52 #endif | 54 #endif |
53 } | 55 } |
54 | 56 |
55 String MediaQueryList::media() const | 57 String MediaQueryList::media() const |
56 { | 58 { |
57 return m_media->mediaText(); | 59 return m_media->mediaText(); |
58 } | 60 } |
59 | 61 |
60 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener) | 62 void MediaQueryList::addListener(PassRefPtr<EventListener> listener) |
63 { | |
64 addEventListener("change", listener, false); | |
65 } | |
66 | |
67 void MediaQueryList::removeListener(PassRefPtr<EventListener> listener) | |
68 { | |
69 removeEventListener("change", listener.get(), false); | |
70 } | |
71 | |
72 void MediaQueryList::addMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQuery ListListener> listener) | |
haraken
2014/07/20 05:14:49
Just help me understand: Why do we want to use m_l
cbiesinger
2014/07/21 22:07:19
I've been told that using DOM events for C++ liste
haraken
2014/07/22 01:30:12
I think Elliott would know better.
| |
61 { | 73 { |
62 if (!listener) | 74 if (!listener) |
63 return; | 75 return; |
64 | 76 |
65 listener->setMediaQueryList(this); | 77 listener->setMediaQueryList(this); |
66 m_listeners.add(listener); | 78 m_listeners.add(listener); |
67 } | 79 } |
68 | 80 |
69 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene r> listener) | 81 void MediaQueryList::removeMediaQueryListListener(PassRefPtrWillBeRawPtr<MediaQu eryListListener> listener) |
70 { | 82 { |
71 if (!listener) | 83 if (!listener) |
72 return; | 84 return; |
73 | 85 |
74 RefPtrWillBeRawPtr<MediaQueryList> protect(this); | 86 RefPtrWillBeRawPtr<MediaQueryList> protect(this); |
75 listener->clearMediaQueryList(); | 87 listener->clearMediaQueryList(); |
76 | 88 |
77 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end( ); it != end; ++it) { | 89 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end( ); it != end; ++it) { |
78 // We can't just use m_listeners.remove() here, because we get a new wra pper for the | 90 // We can't just use m_listeners.remove() here, because we get a new wra pper for the |
79 // listener callback every time. We have to use MediaQueryListListener:: operator==. | 91 // listener callback every time. We have to use MediaQueryListListener:: operator==. |
80 if (**it == *listener.get()) { | 92 if (**it == *listener.get()) { |
81 m_listeners.remove(it); | 93 m_listeners.remove(it); |
82 break; | 94 break; |
83 } | 95 } |
84 } | 96 } |
85 } | 97 } |
86 | 98 |
87 bool MediaQueryList::hasPendingActivity() const | 99 bool MediaQueryList::hasPendingActivity() const |
88 { | 100 { |
89 return m_listeners.size(); | 101 return m_listeners.size() || hasEventListeners(EventTypeNames::change); |
90 } | 102 } |
91 | 103 |
92 void MediaQueryList::stop() | 104 void MediaQueryList::stop() |
93 { | 105 { |
94 m_listeners.clear(); | 106 m_listeners.clear(); |
107 removeAllEventListeners(); | |
haraken
2014/07/20 05:14:49
This will remove all event listeners other than on
cbiesinger
2014/07/21 22:07:19
By my understanding of ActiveDOMEvent::stop that i
| |
95 } | 108 } |
96 | 109 |
97 void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify) | 110 bool MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me diaQueryListListener> >* listenersToNotify) |
98 { | 111 { |
99 m_matchesDirty = true; | 112 m_matchesDirty = true; |
100 if (!updateMatches()) | 113 if (!updateMatches()) |
101 return; | 114 return false; |
102 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) { | 115 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener s.end(); it != end; ++it) { |
103 listenersToNotify->append(*it); | 116 listenersToNotify->append(*it); |
104 } | 117 } |
118 return hasEventListeners(EventTypeNames::change); | |
105 } | 119 } |
106 | 120 |
107 bool MediaQueryList::updateMatches() | 121 bool MediaQueryList::updateMatches() |
108 { | 122 { |
109 m_matchesDirty = false; | 123 m_matchesDirty = false; |
110 if (m_matches != m_matcher->evaluate(m_media.get())) { | 124 if (m_matches != m_matcher->evaluate(m_media.get())) { |
111 m_matches = !m_matches; | 125 m_matches = !m_matches; |
112 return true; | 126 return true; |
113 } | 127 } |
114 return false; | 128 return false; |
115 } | 129 } |
116 | 130 |
117 bool MediaQueryList::matches() | 131 bool MediaQueryList::matches() |
118 { | 132 { |
119 updateMatches(); | 133 updateMatches(); |
120 return m_matches; | 134 return m_matches; |
121 } | 135 } |
122 | 136 |
123 void MediaQueryList::trace(Visitor* visitor) | 137 void MediaQueryList::trace(Visitor* visitor) |
124 { | 138 { |
139 EventTargetWithInlineData::trace(visitor); | |
haraken
2014/07/20 05:14:49
Nit: We normally make this a tail call of the trac
cbiesinger
2014/07/21 22:07:19
Done.
| |
125 #if ENABLE(OILPAN) | 140 #if ENABLE(OILPAN) |
126 visitor->trace(m_matcher); | 141 visitor->trace(m_matcher); |
127 visitor->trace(m_media); | 142 visitor->trace(m_media); |
128 visitor->trace(m_listeners); | 143 visitor->trace(m_listeners); |
129 #endif | 144 #endif |
130 } | 145 } |
131 | 146 |
147 const AtomicString& MediaQueryList::interfaceName() const | |
148 { | |
149 return EventTargetNames::MediaQueryList; | |
132 } | 150 } |
151 | |
152 ExecutionContext* MediaQueryList::executionContext() const | |
153 { | |
154 return ActiveDOMObject::executionContext(); | |
155 } | |
156 | |
157 } | |
OLD | NEW |