2011-04-22 07:17:31 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04: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-22 07:17:31 +04:00
|
|
|
|
|
|
|
/* implements DOM interface for querying and observing media queries */
|
|
|
|
|
2013-12-16 18:03:19 +04:00
|
|
|
#ifndef mozilla_dom_MediaQueryList_h
|
|
|
|
#define mozilla_dom_MediaQueryList_h
|
2011-04-22 07:17:31 +04:00
|
|
|
|
2013-12-17 17:40:06 +04:00
|
|
|
#include "nsISupports.h"
|
2011-04-22 07:17:31 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "prclist.h"
|
2012-06-19 07:26:34 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-16 18:03:34 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "mozilla/dom/MediaQueryListBinding.h"
|
2011-04-22 07:17:31 +04:00
|
|
|
|
|
|
|
class nsPresContext;
|
|
|
|
class nsMediaList;
|
|
|
|
|
2013-12-16 18:03:19 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-12-17 17:40:06 +04:00
|
|
|
class MediaQueryList MOZ_FINAL : public nsISupports,
|
2013-12-16 18:03:34 +04:00
|
|
|
public nsWrapperCache,
|
2013-12-16 18:03:19 +04:00
|
|
|
public PRCList
|
2011-04-22 07:17:31 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The caller who constructs is responsible for calling Evaluate
|
|
|
|
// before calling any other methods.
|
2013-12-16 18:03:19 +04:00
|
|
|
MediaQueryList(nsPresContext *aPresContext,
|
|
|
|
const nsAString &aMediaQueryList);
|
2011-04-22 07:17:31 +04:00
|
|
|
private:
|
2013-12-16 18:03:19 +04:00
|
|
|
~MediaQueryList();
|
2011-04-22 07:17:31 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2013-12-16 18:03:34 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaQueryList)
|
2011-04-22 07:17:31 +04:00
|
|
|
|
2013-12-16 18:03:34 +04:00
|
|
|
nsISupports* GetParentObject() const;
|
|
|
|
|
2011-04-22 07:17:31 +04:00
|
|
|
struct HandleChangeData {
|
2013-12-16 18:03:19 +04:00
|
|
|
nsRefPtr<MediaQueryList> mql;
|
2014-03-18 04:23:03 +04:00
|
|
|
nsRefPtr<mozilla::dom::MediaQueryListListener> callback;
|
2011-04-22 07:17:31 +04:00
|
|
|
};
|
|
|
|
|
2013-12-16 18:03:34 +04:00
|
|
|
typedef FallibleTArray< nsRefPtr<mozilla::dom::MediaQueryListListener> > CallbackList;
|
2011-04-22 07:17:31 +04:00
|
|
|
typedef FallibleTArray<HandleChangeData> NotifyList;
|
|
|
|
|
|
|
|
// Appends listeners that need notification to aListenersToNotify
|
|
|
|
void MediumFeaturesChanged(NotifyList &aListenersToNotify);
|
|
|
|
|
2013-12-17 17:40:06 +04:00
|
|
|
bool HasListeners() const { return !mCallbacks.IsEmpty(); }
|
2012-03-01 08:47:55 +04:00
|
|
|
|
|
|
|
void RemoveAllListeners();
|
|
|
|
|
2014-04-09 02:27:18 +04:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-12-16 18:03:34 +04:00
|
|
|
|
|
|
|
// WebIDL methods
|
2013-12-17 17:40:06 +04:00
|
|
|
void GetMedia(nsAString& aMedia);
|
2013-12-16 18:03:34 +04:00
|
|
|
bool Matches();
|
|
|
|
void AddListener(mozilla::dom::MediaQueryListListener& aListener);
|
|
|
|
void RemoveListener(mozilla::dom::MediaQueryListListener& aListener);
|
|
|
|
|
2011-04-22 07:17:31 +04: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-29 10:19:26 +04:00
|
|
|
bool mMatches;
|
|
|
|
bool mMatchesValid;
|
2013-12-16 18:03:34 +04:00
|
|
|
CallbackList mCallbacks;
|
2011-04-22 07:17:31 +04:00
|
|
|
};
|
|
|
|
|
2013-12-16 18:03:19 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* !defined(mozilla_dom_MediaQueryList_h) */
|