Bumping manifests a=b2g-bump
[gecko.git] / layout / style / MediaQueryList.h
blob5b02a7c641063f7c1db96176b0891391e8faed15
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/. */
7 /* implements DOM interface for querying and observing media queries */
9 #ifndef mozilla_dom_MediaQueryList_h
10 #define mozilla_dom_MediaQueryList_h
12 #include "nsISupports.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsAutoPtr.h"
15 #include "nsCOMPtr.h"
16 #include "nsTArray.h"
17 #include "prclist.h"
18 #include "mozilla/Attributes.h"
19 #include "nsWrapperCache.h"
20 #include "mozilla/dom/MediaQueryListBinding.h"
22 class nsIDocument;
23 class nsMediaList;
25 namespace mozilla {
26 namespace dom {
28 class MediaQueryList MOZ_FINAL : public nsISupports,
29 public nsWrapperCache,
30 public PRCList
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();
40 public:
41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
42 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
44 nsISupports* GetParentObject() const;
46 struct HandleChangeData {
47 nsRefPtr<MediaQueryList> mql;
48 nsRefPtr<mozilla::dom::MediaQueryListListener> callback;
51 typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
52 typedef FallibleTArray<HandleChangeData> NotifyList;
54 // Appends listeners that need notification to aListenersToNotify
55 void MediumFeaturesChanged(NotifyList &aListenersToNotify);
57 bool HasListeners() const { return !mCallbacks.IsEmpty(); }
59 void RemoveAllListeners();
61 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
63 // WebIDL methods
64 void GetMedia(nsAString& aMedia);
65 bool Matches();
66 void AddListener(mozilla::dom::MediaQueryListListener& aListener);
67 void RemoveListener(mozilla::dom::MediaQueryListListener& aListener);
69 private:
70 void RecomputeMatches();
72 // We only need a pointer to the document to support lazy
73 // reevaluation following dynamic changes. However, this lazy
74 // reevaluation is perhaps somewhat important, since some usage
75 // patterns may involve the creation of large numbers of
76 // MediaQueryList objects which almost immediately become garbage
77 // (after a single call to the .matches getter).
79 // This pointer does make us a little more dependent on cycle
80 // collection.
82 // We have a non-null mDocument for our entire lifetime except
83 // after cycle collection unlinking. Having a non-null mDocument
84 // is equivalent to being in that document's mDOMMediaQueryLists
85 // linked list.
86 nsCOMPtr<nsIDocument> mDocument;
88 nsRefPtr<nsMediaList> mMediaList;
89 bool mMatches;
90 bool mMatchesValid;
91 CallbackList mCallbacks;
94 } // namespace dom
95 } // namespace mozilla
97 #endif /* !defined(mozilla_dom_MediaQueryList_h) */