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 "core/css/MediaQueryList.h" | 20 #include "core/css/MediaQueryList.h" |
21 | 21 |
22 #include "core/css/MediaList.h" | 22 #include "core/css/MediaList.h" |
23 #include "core/css/MediaQueryEvaluator.h" | 23 #include "core/css/MediaQueryEvaluator.h" |
24 #include "core/css/MediaQueryListListener.h" | 24 #include "core/css/MediaQueryListListener.h" |
25 #include "core/css/MediaQueryMatcher.h" | 25 #include "core/css/MediaQueryMatcher.h" |
26 #include "core/dom/Document.h" | 26 #include "core/dom/Document.h" |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 | 29 |
30 RawPtr<MediaQueryList> MediaQueryList::create(ExecutionContext* context, RawPtr<
MediaQueryMatcher> matcher, RawPtr<MediaQuerySet> media) | 30 MediaQueryList* MediaQueryList::create(ExecutionContext* context, MediaQueryMatc
her* matcher, MediaQuerySet* media) |
31 { | 31 { |
32 RawPtr<MediaQueryList> list = new MediaQueryList(context, matcher, media); | 32 MediaQueryList* list = new MediaQueryList(context, matcher, media); |
33 list->suspendIfNeeded(); | 33 list->suspendIfNeeded(); |
34 return list.release(); | 34 return list; |
35 } | 35 } |
36 | 36 |
37 MediaQueryList::MediaQueryList(ExecutionContext* context, RawPtr<MediaQueryMatch
er> matcher, RawPtr<MediaQuerySet> media) | 37 MediaQueryList::MediaQueryList(ExecutionContext* context, MediaQueryMatcher* mat
cher, MediaQuerySet* media) |
38 : ActiveScriptWrappable(this) | 38 : ActiveScriptWrappable(this) |
39 , ActiveDOMObject(context) | 39 , ActiveDOMObject(context) |
40 , m_matcher(matcher) | 40 , m_matcher(matcher) |
41 , m_media(media) | 41 , m_media(media) |
42 , m_matchesDirty(true) | 42 , m_matchesDirty(true) |
43 , m_matches(false) | 43 , m_matches(false) |
44 { | 44 { |
45 m_matcher->addMediaQueryList(this); | 45 m_matcher->addMediaQueryList(this); |
46 updateMatches(); | 46 updateMatches(); |
47 } | 47 } |
48 | 48 |
49 MediaQueryList::~MediaQueryList() | 49 MediaQueryList::~MediaQueryList() |
50 { | 50 { |
51 #if !ENABLE(OILPAN) | 51 #if !ENABLE(OILPAN) |
52 m_matcher->removeMediaQueryList(this); | 52 m_matcher->removeMediaQueryList(this); |
53 #endif | 53 #endif |
54 } | 54 } |
55 | 55 |
56 String MediaQueryList::media() const | 56 String MediaQueryList::media() const |
57 { | 57 { |
58 return m_media->mediaText(); | 58 return m_media->mediaText(); |
59 } | 59 } |
60 | 60 |
61 void MediaQueryList::addDeprecatedListener(RawPtr<EventListener> listener) | 61 void MediaQueryList::addDeprecatedListener(EventListener* listener) |
62 { | 62 { |
63 if (!listener) | 63 if (!listener) |
64 return; | 64 return; |
65 | 65 |
66 addEventListener(EventTypeNames::change, listener, false); | 66 addEventListener(EventTypeNames::change, listener, false); |
67 } | 67 } |
68 | 68 |
69 void MediaQueryList::removeDeprecatedListener(RawPtr<EventListener> listener) | 69 void MediaQueryList::removeDeprecatedListener(EventListener* listener) |
70 { | 70 { |
71 if (!listener) | 71 if (!listener) |
72 return; | 72 return; |
73 | 73 |
74 removeEventListener(EventTypeNames::change, listener, false); | 74 removeEventListener(EventTypeNames::change, listener, false); |
75 } | 75 } |
76 | 76 |
77 void MediaQueryList::addListener(RawPtr<MediaQueryListListener> listener) | 77 void MediaQueryList::addListener(MediaQueryListListener* listener) |
78 { | 78 { |
79 if (!listener) | 79 if (!listener) |
80 return; | 80 return; |
81 | 81 |
82 m_listeners.add(listener); | 82 m_listeners.add(listener); |
83 } | 83 } |
84 | 84 |
85 void MediaQueryList::removeListener(RawPtr<MediaQueryListListener> listener) | 85 void MediaQueryList::removeListener(MediaQueryListListener* listener) |
86 { | 86 { |
87 if (!listener) | 87 if (!listener) |
88 return; | 88 return; |
89 | 89 |
90 RawPtr<MediaQueryList> protect(this); | |
91 m_listeners.remove(listener); | 90 m_listeners.remove(listener); |
92 } | 91 } |
93 | 92 |
94 bool MediaQueryList::hasPendingActivity() const | 93 bool MediaQueryList::hasPendingActivity() const |
95 { | 94 { |
96 return m_listeners.size() || hasEventListeners(EventTypeNames::change); | 95 return m_listeners.size() || hasEventListeners(EventTypeNames::change); |
97 } | 96 } |
98 | 97 |
99 void MediaQueryList::stop() | 98 void MediaQueryList::stop() |
100 { | 99 { |
101 // m_listeners.clear() can drop the last ref to this MediaQueryList. | |
102 RawPtr<MediaQueryList> protect(this); | |
103 m_listeners.clear(); | 100 m_listeners.clear(); |
104 removeAllEventListeners(); | 101 removeAllEventListeners(); |
105 } | 102 } |
106 | 103 |
107 bool MediaQueryList::mediaFeaturesChanged(HeapVector<Member<MediaQueryListListen
er>>* listenersToNotify) | 104 bool MediaQueryList::mediaFeaturesChanged(HeapVector<Member<MediaQueryListListen
er>>* listenersToNotify) |
108 { | 105 { |
109 m_matchesDirty = true; | 106 m_matchesDirty = true; |
110 if (!updateMatches()) | 107 if (!updateMatches()) |
111 return false; | 108 return false; |
112 for (const auto& listener : m_listeners) { | 109 for (const auto& listener : m_listeners) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 { | 141 { |
145 return EventTargetNames::MediaQueryList; | 142 return EventTargetNames::MediaQueryList; |
146 } | 143 } |
147 | 144 |
148 ExecutionContext* MediaQueryList::getExecutionContext() const | 145 ExecutionContext* MediaQueryList::getExecutionContext() const |
149 { | 146 { |
150 return ActiveDOMObject::getExecutionContext(); | 147 return ActiveDOMObject::getExecutionContext(); |
151 } | 148 } |
152 | 149 |
153 } // namespace blink | 150 } // namespace blink |
OLD | NEW |