2014-10-03 11:15:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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"
|
2014-10-03 11:15:25 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2011-04-21 20:17:31 -07:00
|
|
|
#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
|
|
|
|
2014-10-03 11:15:25 -07:00
|
|
|
class nsIDocument;
|
2011-04-21 20:17:31 -07:00
|
|
|
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.
|
2014-10-03 11:15:25 -07:00
|
|
|
MediaQueryList(nsIDocument *aDocument,
|
2013-12-16 06:03:19 -08:00
|
|
|
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;
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<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();
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-12-16 06:03:34 -08:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2014-10-03 11:15:25 -07:00
|
|
|
// We only need a pointer to the document to support lazy
|
2011-04-21 20:17:31 -07:00
|
|
|
// 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.
|
|
|
|
//
|
2014-10-03 11:15:25 -07:00
|
|
|
// We have a non-null mDocument for our entire lifetime except
|
|
|
|
// after cycle collection unlinking. Having a non-null mDocument
|
|
|
|
// is equivalent to being in that document's mDOMMediaQueryLists
|
2011-04-21 20:17:31 -07:00
|
|
|
// linked list.
|
2014-10-03 11:15:25 -07:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2011-04-21 20:17:31 -07:00
|
|
|
|
|
|
|
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) */
|