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/. */
6 
7 #ifndef mozilla_PendingFullscreenEvent_h_
8 #define mozilla_PendingFullscreenEvent_h_
9 
10 #include "nsContentUtils.h"
11 
12 namespace mozilla {
13 
14 namespace dom {
15 class Document;
16 }
17 
18 enum class FullscreenEventType {
19   Change,
20   Error,
21 };
22 
23 /*
24  * Class for dispatching a fullscreen event. It should be queued and
25  * invoked as part of "run the fullscreen steps" algorithm.
26  */
27 class PendingFullscreenEvent {
28  public:
PendingFullscreenEvent(FullscreenEventType aType,dom::Document * aDocument,nsINode * aTarget)29   PendingFullscreenEvent(FullscreenEventType aType, dom::Document* aDocument,
30                          nsINode* aTarget)
31       : mDocument(aDocument), mTarget(aTarget), mType(aType) {
32     MOZ_ASSERT(aDocument);
33     MOZ_ASSERT(aTarget);
34   }
35 
Document()36   dom::Document* Document() const { return mDocument; }
37 
Dispatch()38   void Dispatch() {
39 #ifdef DEBUG
40     MOZ_ASSERT(!mDispatched);
41     mDispatched = true;
42 #endif
43     nsString name;
44     switch (mType) {
45       case FullscreenEventType::Change:
46         name = NS_LITERAL_STRING("fullscreenchange");
47         break;
48       case FullscreenEventType::Error:
49         name = NS_LITERAL_STRING("fullscreenerror");
50         break;
51     }
52     nsINode* target = mTarget->GetComposedDoc() == mDocument ? mTarget.get()
53                                                              : mDocument.get();
54     Unused << nsContentUtils::DispatchTrustedEvent(
55         mDocument, target, name, CanBubble::eYes, Cancelable::eNo,
56         Composed::eYes);
57   }
58 
59  private:
60   RefPtr<dom::Document> mDocument;
61   nsCOMPtr<nsINode> mTarget;
62   FullscreenEventType mType;
63 #ifdef DEBUG
64   bool mDispatched = false;
65 #endif
66 };
67 
68 }  // namespace mozilla
69 
70 #endif  // mozilla_PendingFullscreenEvent_h_
71