Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / events / PendingFullscreenEvent.h
blobafd5e73b8327a09b6c92429020959ccf3f152893
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_PendingFullscreenEvent_h_
8 #define mozilla_PendingFullscreenEvent_h_
10 #include "mozilla/dom/Document.h"
11 #include "nsContentUtils.h"
13 namespace mozilla {
15 namespace dom {
16 class Document;
19 enum class FullscreenEventType {
20 Change,
21 Error,
25 * Class for dispatching a fullscreen event. It should be queued and
26 * invoked as part of "run the fullscreen steps" algorithm.
28 class PendingFullscreenEvent {
29 public:
30 PendingFullscreenEvent(FullscreenEventType aType, dom::Document* aDocument,
31 nsINode* aTarget)
32 : mDocument(aDocument), mTarget(aTarget), mType(aType) {
33 MOZ_ASSERT(aDocument);
34 MOZ_ASSERT(aTarget);
37 dom::Document* Document() const { return mDocument; }
39 void Dispatch() {
40 #ifdef DEBUG
41 MOZ_ASSERT(!mDispatched);
42 mDispatched = true;
43 #endif
44 nsString name;
45 switch (mType) {
46 case FullscreenEventType::Change:
47 name = u"fullscreenchange"_ns;
48 break;
49 case FullscreenEventType::Error:
50 name = u"fullscreenerror"_ns;
51 break;
53 nsINode* target = mTarget->GetComposedDoc() == mDocument ? mTarget.get()
54 : mDocument.get();
55 Unused << nsContentUtils::DispatchTrustedEvent(
56 mDocument, target, name, CanBubble::eYes, Cancelable::eNo,
57 Composed::eYes);
60 private:
61 RefPtr<dom::Document> mDocument;
62 nsCOMPtr<nsINode> mTarget;
63 FullscreenEventType mType;
64 #ifdef DEBUG
65 bool mDispatched = false;
66 #endif
69 } // namespace mozilla
71 #endif // mozilla_PendingFullscreenEvent_h_