Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : /* implements DOM interface for querying and observing media queries */
8 :
9 : #ifndef mozilla_dom_MediaQueryList_h
10 : #define mozilla_dom_MediaQueryList_h
11 :
12 : #include "nsISupports.h"
13 : #include "nsCycleCollectionParticipant.h"
14 : #include "nsCOMPtr.h"
15 : #include "nsTArray.h"
16 : #include "mozilla/LinkedList.h"
17 : #include "mozilla/Attributes.h"
18 : #include "nsWrapperCache.h"
19 : #include "mozilla/DOMEventTargetHelper.h"
20 : #include "mozilla/dom/MediaQueryListBinding.h"
21 :
22 : class nsIDocument;
23 :
24 : namespace mozilla {
25 : namespace dom {
26 :
27 : class MediaList;
28 :
29 : class MediaQueryList final : public DOMEventTargetHelper,
30 : public mozilla::LinkedListElement<MediaQueryList>
31 : {
32 : public:
33 : // The caller who constructs is responsible for calling Evaluate
34 : // before calling any other methods.
35 : MediaQueryList(nsIDocument *aDocument,
36 : const nsAString &aMediaQueryList);
37 : private:
38 : ~MediaQueryList();
39 :
40 : public:
41 : NS_DECL_ISUPPORTS_INHERITED
42 33 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaQueryList, DOMEventTargetHelper)
43 :
44 : nsISupports* GetParentObject() const;
45 :
46 : void MaybeNotify();
47 :
48 : JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
49 :
50 : // WebIDL methods
51 : void GetMedia(nsAString& aMedia);
52 : bool Matches();
53 : void AddListener(EventListener* aListener, ErrorResult& aRv);
54 : void RemoveListener(EventListener* aListener, ErrorResult& aRv);
55 :
56 : using nsIDOMEventTarget::AddEventListener;
57 :
58 : virtual void AddEventListener(const nsAString& aType,
59 : EventListener* aCallback,
60 : const AddEventListenerOptionsOrBoolean& aOptions,
61 : const Nullable<bool>& aWantsUntrusted,
62 : ErrorResult& aRv) override;
63 :
64 0 : IMPL_EVENT_HANDLER(change)
65 :
66 : bool HasListeners();
67 :
68 : void Disconnect();
69 :
70 : private:
71 : void RecomputeMatches();
72 :
73 : // We only need a pointer to the document to support lazy
74 : // reevaluation following dynamic changes. However, this lazy
75 : // reevaluation is perhaps somewhat important, since some usage
76 : // patterns may involve the creation of large numbers of
77 : // MediaQueryList objects which almost immediately become garbage
78 : // (after a single call to the .matches getter).
79 : //
80 : // This pointer does make us a little more dependent on cycle
81 : // collection.
82 : //
83 : // We have a non-null mDocument for our entire lifetime except
84 : // after cycle collection unlinking. Having a non-null mDocument
85 : // is equivalent to being in that document's mDOMMediaQueryLists
86 : // linked list.
87 : nsCOMPtr<nsIDocument> mDocument;
88 :
89 : RefPtr<MediaList> mMediaList;
90 : bool mMatches;
91 : bool mMatchesValid;
92 : };
93 :
94 : } // namespace dom
95 : } // namespace mozilla
96 :
97 : #endif /* !defined(mozilla_dom_MediaQueryList_h) */
|