void MediaQueryList::AddListener(MediaQueryListListener& aListener) { if (!HasListeners()) { // When we have listeners, the pres context owns a reference to // this. This is a cyclic reference that can only be broken by // cycle collection. NS_ADDREF_THIS(); } if (!mMatchesValid) { MOZ_ASSERT(!HasListeners(), "when listeners present, must keep mMatches current"); RecomputeMatches(); } for (uint32_t i = 0; i < mCallbacks.Length(); ++i) { if (aListener == *mCallbacks[i]) { // Already registered return; } } if (!mCallbacks.AppendElement(&aListener, fallible)) { if (!HasListeners()) { // Append failed; undo the AddRef above. NS_RELEASE_THIS(); } } }
void MediaQueryList::MaybeNotify() { mMatchesValid = false; if (!HasListeners()) { return; } bool oldMatches = mMatches; RecomputeMatches(); // No need to notify the change. if (mMatches == oldMatches) { return; } MediaQueryListEventInit init; init.mBubbles = false; init.mCancelable = false; init.mMatches = mMatches; mMediaList->GetText(init.mMedia); RefPtr<MediaQueryListEvent> event = MediaQueryListEvent::Constructor(this, ONCHANGE_STRING, init); event->SetTrusted(true); bool dummy; DispatchEvent(event, &dummy); }
bool MediaQueryList::Matches() { if (!mMatchesValid) { MOZ_ASSERT(!HasListeners(), "when listeners present, must keep mMatches current"); RecomputeMatches(); } return mMatches; }
bool MediaQueryList::Matches() { if (!mMatchesValid) { NS_ABORT_IF_FALSE(!HasListeners(), "when listeners present, must keep mMatches current"); RecomputeMatches(); } return mMatches; }
NS_IMETHODIMP nsDOMMediaQueryList::GetMatches(bool *aMatches) { if (!mMatchesValid) { NS_ABORT_IF_FALSE(mListeners.Length() == 0, "when listeners present, must keep mMatches current"); RecomputeMatches(); } *aMatches = mMatches; return NS_OK; }
NS_IMETHODIMP nsDOMMediaQueryList::AddListener(nsIDOMMediaQueryListListener *aListener) { if (!mMatchesValid) { NS_ABORT_IF_FALSE(mListeners.Length() == 0, "when listeners present, must keep mMatches current"); RecomputeMatches(); } if (!mListeners.Contains(aListener)) { mListeners.AppendElement(aListener); } return NS_OK; }
void MediaQueryList::AddEventListener(const nsAString& aType, EventListener* aCallback, const AddEventListenerOptionsOrBoolean& aOptions, const dom::Nullable<bool>& aWantsUntrusted, ErrorResult& aRv) { if (!mMatchesValid) { MOZ_ASSERT(!HasListeners(), "when listeners present, must keep mMatches current"); RecomputeMatches(); } DOMEventTargetHelper::AddEventListener(aType, aCallback, aOptions, aWantsUntrusted, aRv); }
void nsDOMMediaQueryList::MediumFeaturesChanged(NotifyList &aListenersToNotify) { mMatchesValid = PR_FALSE; if (mListeners.Length()) { bool oldMatches = mMatches; RecomputeMatches(); if (mMatches != oldMatches) { for (PRUint32 i = 0, i_end = mListeners.Length(); i != i_end; ++i) { HandleChangeData *d = aListenersToNotify.AppendElement(); if (d) { d->mql = this; d->listener = mListeners[i]; } } } } }
void MediaQueryList::MediumFeaturesChanged(NotifyList &aListenersToNotify) { mMatchesValid = false; if (HasListeners()) { bool oldMatches = mMatches; RecomputeMatches(); if (mMatches != oldMatches) { for (uint32_t i = 0, i_end = mCallbacks.Length(); i != i_end; ++i) { HandleChangeData *d = aListenersToNotify.AppendElement(); if (d) { d->mql = this; d->callback = mCallbacks[i]; } } } } }