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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #if !ENABLE(OILPAN) | 47 #if !ENABLE(OILPAN) |
48 m_matcher->removeMediaQueryList(this); | 48 m_matcher->removeMediaQueryList(this); |
49 #endif | 49 #endif |
50 } | 50 } |
51 | 51 |
52 String MediaQueryList::media() const | 52 String MediaQueryList::media() const |
53 { | 53 { |
54 return m_media->mediaText(); | 54 return m_media->mediaText(); |
55 } | 55 } |
56 | 56 |
57 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>
listener) | 57 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<Listener> listener) |
58 { | 58 { |
59 if (!listener) | 59 if (!listener) |
60 return; | 60 return; |
61 | 61 |
62 listener->setMediaQueryList(this); | 62 listener->setMediaQueryList(this); |
63 m_listeners.add(listener); | 63 m_listeners.add(listener); |
64 } | 64 } |
65 | 65 |
66 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListene
r> listener) | 66 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<Listener> listener) |
67 { | 67 { |
68 if (!listener) | 68 if (!listener) |
69 return; | 69 return; |
70 | 70 |
71 RefPtrWillBeRawPtr<MediaQueryList> protect(this); | 71 RefPtrWillBeRawPtr<MediaQueryList> protect(this); |
72 listener->clearMediaQueryList(); | 72 listener->clearMediaQueryList(); |
73 | 73 |
| 74 // We can't just use m_listeners.remove() here, because we get a new wrapper
for the |
| 75 // listener callback every time. We have to use MediaQueryListListener::oper
ator==. |
74 for (ListenerList::iterator it = m_listeners.begin(), end = m_listeners.end(
); it != end; ++it) { | 76 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 | 77 if ((*it)->equals(listener.get())) { |
76 // listener callback every time. We have to use MediaQueryListListener::
operator==. | |
77 if (**it == *listener.get()) { | |
78 m_listeners.remove(it); | 78 m_listeners.remove(it); |
79 break; | 79 break; |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void MediaQueryList::documentDetached() | 84 void MediaQueryList::documentDetached() |
85 { | 85 { |
86 m_listeners.clear(); | 86 m_listeners.clear(); |
87 } | 87 } |
88 | 88 |
89 void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Me
diaQueryListListener> >* toNotify) | 89 void MediaQueryList::mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Li
stener> >* listenersToNotify) |
90 { | 90 { |
91 m_matchesDirty = true; | 91 m_matchesDirty = true; |
92 if (!updateMatches()) | 92 if (!updateMatches()) |
93 return; | 93 return; |
94 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener
s.end(); it != end; ++it) { | 94 for (ListenerList::const_iterator it = m_listeners.begin(), end = m_listener
s.end(); it != end; ++it) { |
95 toNotify->append(*it); | 95 listenersToNotify->append(*it); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 bool MediaQueryList::updateMatches() | 99 bool MediaQueryList::updateMatches() |
100 { | 100 { |
101 m_matchesDirty = false; | 101 m_matchesDirty = false; |
102 if (m_matches != m_matcher->evaluate(m_media.get())) { | 102 if (m_matches != m_matcher->evaluate(m_media.get())) { |
103 m_matches = !m_matches; | 103 m_matches = !m_matches; |
104 return true; | 104 return true; |
105 } | 105 } |
106 return false; | 106 return false; |
107 } | 107 } |
108 | 108 |
109 bool MediaQueryList::matches() | 109 bool MediaQueryList::matches() |
110 { | 110 { |
111 updateMatches(); | 111 updateMatches(); |
112 return m_matches; | 112 return m_matches; |
113 } | 113 } |
114 | 114 |
115 void MediaQueryList::trace(Visitor* visitor) | 115 void MediaQueryList::trace(Visitor* visitor) |
116 { | 116 { |
117 visitor->trace(m_matcher); | 117 visitor->trace(m_matcher); |
118 visitor->trace(m_media); | 118 visitor->trace(m_media); |
119 visitor->trace(m_listeners); | 119 visitor->trace(m_listeners); |
120 } | 120 } |
121 | 121 |
122 } | 122 } |
OLD | NEW |