2011-04-21 20:17:31 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-04-21 20:17:31 -07:00
|
|
|
|
|
|
|
/* implements DOM interface for querying and observing media queries */
|
|
|
|
|
2013-12-16 06:03:19 -08:00
|
|
|
#ifndef mozilla_dom_MediaQueryList_h
|
|
|
|
#define mozilla_dom_MediaQueryList_h
|
2011-04-21 20:17:31 -07:00
|
|
|
|
2013-12-17 05:40:06 -08:00
|
|
|
#include "nsISupports.h"
|
2011-04-21 20:17:31 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "prclist.h"
|
2012-06-18 20:26:34 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-16 06:03:34 -08:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/dom/MediaQueryListBinding.h"
|
2011-04-21 20:17:31 -07:00
|
|
|
|
|
|
|
class nsPresContext;
|
|
|
|
class nsMediaList;
|
|
|
|
|
2013-12-16 06:03:19 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-12-17 05:40:06 -08:00
|
|
|
class MediaQueryList MOZ_FINAL : public nsISupports,
|
2013-12-16 06:03:34 -08:00
|
|
|
public nsWrapperCache,
|
2013-12-16 06:03:19 -08:00
|
|
|
public PRCList
|
2011-04-21 20:17:31 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The caller who constructs is responsible for calling Evaluate
|
|
|
|
// before calling any other methods.
|
2013-12-16 06:03:19 -08:00
|
|
|
MediaQueryList(nsPresContext *aPresContext,
|
|
|
|
const nsAString &aMediaQueryList);
|
2011-04-21 20:17:31 -07:00
|
|
|
private:
|
2013-12-16 06:03:19 -08:00
|
|
|
~MediaQueryList();
|
2011-04-21 20:17:31 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-12-16 06:03:34 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
|
2011-04-21 20:17:31 -07:00
|
|
|
|
2013-12-16 06:03:34 -08:00
|
|
|
nsISupports* GetParentObject() const;
|
|
|
|
|
2011-04-21 20:17:31 -07:00
|
|
|
struct HandleChangeData {
|
2013-12-16 06:03:19 -08:00
|
|
|
nsRefPtr<MediaQueryList> mql;
|
2013-12-16 06:03:34 -08:00
|
|
|
nsCOMPtr<mozilla::dom::MediaQueryListListener> callback;
|
2011-04-21 20:17:31 -07:00
|
|
|
};
|
|
|
|
|
2013-12-16 06:03:34 -08:00
|
|
|
typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
|
2011-04-21 20:17:31 -07:00
|
|
|
typedef FallibleTArray<HandleChangeData> NotifyList;
|
|
|
|
|
|
|
|
// Appends listeners that need notification to aListenersToNotify
|
|
|
|
void MediumFeaturesChanged(NotifyList &aListenersToNotify);
|
|
|
|
|
2013-12-17 05:40:06 -08:00
|
|
|
bool HasListeners() const { return !mCallbacks.IsEmpty(); }
|
2012-02-29 20:47:55 -08:00
|
|
|
|
|
|
|
void RemoveAllListeners();
|
|
|
|
|
2013-12-16 06:03:34 -08:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// WebIDL methods
|
2013-12-17 05:40:06 -08:00
|
|
|
void GetMedia(nsAString& aMedia);
|
2013-12-16 06:03:34 -08:00
|
|
|
bool Matches();
|
|
|
|
void AddListener(mozilla::dom::MediaQueryListListener& aListener);
|
|
|
|
void RemoveListener(mozilla::dom::MediaQueryListListener& aListener);
|
|
|
|
|
2011-04-21 20:17:31 -07:00
|
|
|
private:
|
|
|
|
void RecomputeMatches();
|
|
|
|
|
|
|
|
// We only need a pointer to the pres context to support lazy
|
|
|
|
// reevaluation following dynamic changes. However, this lazy
|
|
|
|
// reevaluation is perhaps somewhat important, since some usage
|
|
|
|
// patterns may involve the creation of large numbers of
|
|
|
|
// MediaQueryList objects which almost immediately become garbage
|
|
|
|
// (after a single call to the .matches getter).
|
|
|
|
//
|
|
|
|
// This pointer does make us a little more dependent on cycle
|
|
|
|
// collection.
|
|
|
|
//
|
|
|
|
// We have a non-null mPresContext for our entire lifetime except
|
|
|
|
// after cycle collection unlinking. Having a non-null mPresContext
|
|
|
|
// is equivalent to being in that pres context's mDOMMediaQueryLists
|
|
|
|
// linked list.
|
|
|
|
nsRefPtr<nsPresContext> mPresContext;
|
|
|
|
|
|
|
|
nsRefPtr<nsMediaList> mMediaList;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mMatches;
|
|
|
|
bool mMatchesValid;
|
2013-12-16 06:03:34 -08:00
|
|
|
CallbackList mCallbacks;
|
2011-04-21 20:17:31 -07:00
|
|
|
};
|
|
|
|
|
2013-12-16 06:03:19 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* !defined(mozilla_dom_MediaQueryList_h) */
|