dom/events/AsyncEventDispatcher.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_AsyncEventDispatcher_h_
     7 #define mozilla_AsyncEventDispatcher_h_
     9 #include "mozilla/Attributes.h"
    10 #include "nsCOMPtr.h"
    11 #include "nsIDocument.h"
    12 #include "nsIDOMEvent.h"
    13 #include "nsINode.h"
    14 #include "nsString.h"
    15 #include "nsThreadUtils.h"
    17 namespace mozilla {
    19 /**
    20  * Use nsAsyncDOMEvent to fire a DOM event that requires safe a stable DOM.
    21  * For example, you may need to fire an event from within layout, but
    22  * want to ensure that the event handler doesn't mutate the DOM at
    23  * the wrong time, in order to avoid resulting instability.
    24  */
    26 class AsyncEventDispatcher : public nsRunnable
    27 {
    28 public:
    29   AsyncEventDispatcher(nsINode* aEventNode, const nsAString& aEventType,
    30                        bool aBubbles, bool aDispatchChromeOnly)
    31     : mEventNode(aEventNode)
    32     , mEventType(aEventType)
    33     , mBubbles(aBubbles)
    34     , mDispatchChromeOnly(aDispatchChromeOnly)
    35   {
    36   }
    38   AsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
    39     : mEventNode(aEventNode)
    40     , mEvent(aEvent)
    41     , mDispatchChromeOnly(false)
    42   {
    43   }
    45   AsyncEventDispatcher(nsINode* aEventNode, WidgetEvent& aEvent);
    47   NS_IMETHOD Run() MOZ_OVERRIDE;
    48   nsresult PostDOMEvent();
    49   void RunDOMEventWhenSafe();
    51   nsCOMPtr<nsINode>     mEventNode;
    52   nsCOMPtr<nsIDOMEvent> mEvent;
    53   nsString              mEventType;
    54   bool                  mBubbles;
    55   bool                  mDispatchChromeOnly;
    56 };
    58 class LoadBlockingAsyncEventDispatcher MOZ_FINAL : public AsyncEventDispatcher
    59 {
    60 public:
    61   LoadBlockingAsyncEventDispatcher(nsINode* aEventNode,
    62                                    const nsAString& aEventType,
    63                                    bool aBubbles, bool aDispatchChromeOnly)
    64     : AsyncEventDispatcher(aEventNode, aEventType,
    65                            aBubbles, aDispatchChromeOnly)
    66     , mBlockedDoc(aEventNode->OwnerDoc())
    67   {
    68     if (mBlockedDoc) {
    69       mBlockedDoc->BlockOnload();
    70     }
    71   }
    73   LoadBlockingAsyncEventDispatcher(nsINode* aEventNode, nsIDOMEvent* aEvent)
    74     : AsyncEventDispatcher(aEventNode, aEvent)
    75     , mBlockedDoc(aEventNode->OwnerDoc())
    76   {
    77     if (mBlockedDoc) {
    78       mBlockedDoc->BlockOnload();
    79     }
    80   }
    82   ~LoadBlockingAsyncEventDispatcher();
    84 private:
    85   nsCOMPtr<nsIDocument> mBlockedDoc;
    86 };
    88 } // namespace mozilla
    90 #endif // mozilla_AsyncEventDispatcher_h_

mercurial