/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ /* 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/. */
// Post a subclass of Event. // e.g. PostEvent(mozilla::MakeUnique<MyEvent>()); template <typename T, typename D> staticvoid PostEvent(mozilla::UniquePtr<T, D>&& event) {
mozilla::MutexAutoLock lock(*sAppShellLock); if (!sAppShell) { return;
}
sAppShell->mEventQueue.Post(std::move(event));
}
// Post a event that will call a lambda // e.g. PostEvent([=] { /* do something */ }); template <typename T> staticvoid PostEvent(T&& lambda) {
mozilla::MutexAutoLock lock(*sAppShellLock); if (!sAppShell) { return;
}
sAppShell->mEventQueue.Post(
mozilla::MakeUnique<LambdaEvent<T>>(std::move(lambda)));
}
// Post a event and wait for it to finish running on the Gecko thread. staticbool SyncRunEvent(
Event&& event,
mozilla::UniquePtr<Event> (*eventFactory)(mozilla::UniquePtr<Event>&&) =
nullptr, const mozilla::TimeDuration timeout = mozilla::TimeDuration::Forever());
class NativeCallbackEvent : public Event { // Capturing the nsAppShell instance is safe because if the app // shell is destroyed, this lambda will not be called either.
nsAppShell* const appShell;
// Ownership of event object transfers to the return value.
mozilla::UniquePtr<Event> event(mQueue.popFirst()); if (!event || !event->mPostTime) { return event;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.