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 #ifndef MediaQueryList_h | 20 #ifndef MediaQueryList_h |
21 #define MediaQueryList_h | 21 #define MediaQueryList_h |
22 | 22 |
| 23 #include "bindings/core/v8/ActiveScriptWrappable.h" |
23 #include "bindings/core/v8/ScriptWrappable.h" | 24 #include "bindings/core/v8/ScriptWrappable.h" |
24 #include "core/CoreExport.h" | 25 #include "core/CoreExport.h" |
25 #include "core/dom/ActiveDOMObject.h" | 26 #include "core/dom/ActiveDOMObject.h" |
26 #include "core/events/EventTarget.h" | 27 #include "core/events/EventTarget.h" |
27 #include "platform/heap/Handle.h" | 28 #include "platform/heap/Handle.h" |
28 #include "wtf/Forward.h" | 29 #include "wtf/Forward.h" |
29 #include "wtf/RefCounted.h" | 30 #include "wtf/RefCounted.h" |
30 #include "wtf/RefPtr.h" | 31 #include "wtf/RefPtr.h" |
31 | 32 |
32 namespace blink { | 33 namespace blink { |
33 | 34 |
34 class ExecutionContext; | 35 class ExecutionContext; |
35 class MediaQueryListListener; | 36 class MediaQueryListListener; |
36 class MediaQueryMatcher; | 37 class MediaQueryMatcher; |
37 class MediaQuerySet; | 38 class MediaQuerySet; |
38 | 39 |
39 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#
the-mediaquerylist-interface | 40 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#
the-mediaquerylist-interface |
40 // The objects of this class are returned by window.matchMedia. They may be used
to | 41 // The objects of this class are returned by window.matchMedia. They may be used
to |
41 // retrieve the current value of the given media query and to add/remove listene
rs that | 42 // retrieve the current value of the given media query and to add/remove listene
rs that |
42 // will be called whenever the value of the query changes. | 43 // will be called whenever the value of the query changes. |
43 | 44 |
44 class CORE_EXPORT MediaQueryList final : public EventTargetWithInlineData, publi
c RefCountedWillBeNoBase<MediaQueryList>, public ActiveDOMObject { | 45 class CORE_EXPORT MediaQueryList final : public EventTargetWithInlineData, publi
c RefCountedWillBeNoBase<MediaQueryList>, public ActiveScriptWrappable, public A
ctiveDOMObject { |
45 REFCOUNTED_EVENT_TARGET(MediaQueryList); | 46 REFCOUNTED_EVENT_TARGET(MediaQueryList); |
46 DEFINE_WRAPPERTYPEINFO(); | 47 DEFINE_WRAPPERTYPEINFO(); |
47 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaQueryList); | 48 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MediaQueryList); |
48 public: | 49 public: |
49 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, Pass
RefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); | 50 static PassRefPtrWillBeRawPtr<MediaQueryList> create(ExecutionContext*, Pass
RefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); |
50 ~MediaQueryList() override; | 51 ~MediaQueryList() override; |
51 | 52 |
52 String media() const; | 53 String media() const; |
53 bool matches(); | 54 bool matches(); |
54 | 55 |
55 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); | 56 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
56 | 57 |
57 // These two functions are provided for compatibility with JS code | 58 // These two functions are provided for compatibility with JS code |
58 // written before the change listener became a DOM event. | 59 // written before the change listener became a DOM event. |
59 void addDeprecatedListener(PassRefPtrWillBeRawPtr<EventListener>); | 60 void addDeprecatedListener(PassRefPtrWillBeRawPtr<EventListener>); |
60 void removeDeprecatedListener(PassRefPtrWillBeRawPtr<EventListener>); | 61 void removeDeprecatedListener(PassRefPtrWillBeRawPtr<EventListener>); |
61 | 62 |
62 // C++ code can use these functions to listen to changes instead of having t
o use DOM event listeners. | 63 // C++ code can use these functions to listen to changes instead of having t
o use DOM event listeners. |
63 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); | 64 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); |
64 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); | 65 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); |
65 | 66 |
66 // Will return true if a DOM event should be scheduled. | 67 // Will return true if a DOM event should be scheduled. |
67 bool mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryList
Listener>>* listenersToNotify); | 68 bool mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryList
Listener>>* listenersToNotify); |
68 | 69 |
69 DECLARE_VIRTUAL_TRACE(); | 70 DECLARE_VIRTUAL_TRACE(); |
70 | 71 |
| 72 // From ActiveScriptWrappable |
| 73 bool hasPendingActivity() const final; |
| 74 |
71 // From ActiveDOMObject | 75 // From ActiveDOMObject |
72 bool hasPendingActivity() const override; | |
73 void stop() override; | 76 void stop() override; |
74 | 77 |
75 const AtomicString& interfaceName() const override; | 78 const AtomicString& interfaceName() const override; |
76 ExecutionContext* getExecutionContext() const override; | 79 ExecutionContext* getExecutionContext() const override; |
77 | 80 |
78 private: | 81 private: |
79 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>,
PassRefPtrWillBeRawPtr<MediaQuerySet>); | 82 MediaQueryList(ExecutionContext*, PassRefPtrWillBeRawPtr<MediaQueryMatcher>,
PassRefPtrWillBeRawPtr<MediaQuerySet>); |
80 | 83 |
81 bool updateMatches(); | 84 bool updateMatches(); |
82 | 85 |
83 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; | 86 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; |
84 RefPtrWillBeMember<MediaQuerySet> m_media; | 87 RefPtrWillBeMember<MediaQuerySet> m_media; |
85 using ListenerList = WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryList
Listener>>; | 88 using ListenerList = WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryList
Listener>>; |
86 ListenerList m_listeners; | 89 ListenerList m_listeners; |
87 bool m_matchesDirty; | 90 bool m_matchesDirty; |
88 bool m_matches; | 91 bool m_matches; |
89 }; | 92 }; |
90 | 93 |
91 } // namespace blink | 94 } // namespace blink |
92 | 95 |
93 #endif // MediaQueryList_h | 96 #endif // MediaQueryList_h |
OLD | NEW |