layout/style/MediaQueryList.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* implements DOM interface for querying and observing media queries */
michael@0 7
michael@0 8 #ifndef mozilla_dom_MediaQueryList_h
michael@0 9 #define mozilla_dom_MediaQueryList_h
michael@0 10
michael@0 11 #include "nsISupports.h"
michael@0 12 #include "nsCycleCollectionParticipant.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "nsTArray.h"
michael@0 15 #include "prclist.h"
michael@0 16 #include "mozilla/Attributes.h"
michael@0 17 #include "nsWrapperCache.h"
michael@0 18 #include "mozilla/dom/MediaQueryListBinding.h"
michael@0 19
michael@0 20 class nsPresContext;
michael@0 21 class nsMediaList;
michael@0 22
michael@0 23 namespace mozilla {
michael@0 24 namespace dom {
michael@0 25
michael@0 26 class MediaQueryList MOZ_FINAL : public nsISupports,
michael@0 27 public nsWrapperCache,
michael@0 28 public PRCList
michael@0 29 {
michael@0 30 public:
michael@0 31 // The caller who constructs is responsible for calling Evaluate
michael@0 32 // before calling any other methods.
michael@0 33 MediaQueryList(nsPresContext *aPresContext,
michael@0 34 const nsAString &aMediaQueryList);
michael@0 35 private:
michael@0 36 ~MediaQueryList();
michael@0 37
michael@0 38 public:
michael@0 39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 40 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
michael@0 41
michael@0 42 nsISupports* GetParentObject() const;
michael@0 43
michael@0 44 struct HandleChangeData {
michael@0 45 nsRefPtr<MediaQueryList> mql;
michael@0 46 nsRefPtr<mozilla::dom::MediaQueryListListener> callback;
michael@0 47 };
michael@0 48
michael@0 49 typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
michael@0 50 typedef FallibleTArray<HandleChangeData> NotifyList;
michael@0 51
michael@0 52 // Appends listeners that need notification to aListenersToNotify
michael@0 53 void MediumFeaturesChanged(NotifyList &aListenersToNotify);
michael@0 54
michael@0 55 bool HasListeners() const { return !mCallbacks.IsEmpty(); }
michael@0 56
michael@0 57 void RemoveAllListeners();
michael@0 58
michael@0 59 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 60
michael@0 61 // WebIDL methods
michael@0 62 void GetMedia(nsAString& aMedia);
michael@0 63 bool Matches();
michael@0 64 void AddListener(mozilla::dom::MediaQueryListListener& aListener);
michael@0 65 void RemoveListener(mozilla::dom::MediaQueryListListener& aListener);
michael@0 66
michael@0 67 private:
michael@0 68 void RecomputeMatches();
michael@0 69
michael@0 70 // We only need a pointer to the pres context to support lazy
michael@0 71 // reevaluation following dynamic changes. However, this lazy
michael@0 72 // reevaluation is perhaps somewhat important, since some usage
michael@0 73 // patterns may involve the creation of large numbers of
michael@0 74 // MediaQueryList objects which almost immediately become garbage
michael@0 75 // (after a single call to the .matches getter).
michael@0 76 //
michael@0 77 // This pointer does make us a little more dependent on cycle
michael@0 78 // collection.
michael@0 79 //
michael@0 80 // We have a non-null mPresContext for our entire lifetime except
michael@0 81 // after cycle collection unlinking. Having a non-null mPresContext
michael@0 82 // is equivalent to being in that pres context's mDOMMediaQueryLists
michael@0 83 // linked list.
michael@0 84 nsRefPtr<nsPresContext> mPresContext;
michael@0 85
michael@0 86 nsRefPtr<nsMediaList> mMediaList;
michael@0 87 bool mMatches;
michael@0 88 bool mMatchesValid;
michael@0 89 CallbackList mCallbacks;
michael@0 90 };
michael@0 91
michael@0 92 } // namespace dom
michael@0 93 } // namespace mozilla
michael@0 94
michael@0 95 #endif /* !defined(mozilla_dom_MediaQueryList_h) */

mercurial