tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PendingFullscreenEvent.h (2101B)


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