LCOV - app.info - content/events/src/nsAsyncDOMEvent.cpp

LCOV - code coverage report
| Current view: | directory - content/events/src - nsAsyncDOMEvent.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 32 | 24 | 75.0 %
| Date: | 2012-07-07 | Functions: | 6 | 3 | 50.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is mozilla.org code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Aaron Leventhal (aaronleventhal@moonset.net)
          19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : #include "nsAsyncDOMEvent.h"
          39                 : #include "nsIDOMEvent.h"
          40                 : #include "nsIPrivateDOMEvent.h"
          41                 : #include "nsIDOMDocument.h"
          42                 : #include "nsIDOMEventTarget.h"
          43                 : #include "nsContentUtils.h"
          44                 : #include "nsEventDispatcher.h"
          45                 : #include "nsGUIEvent.h"
          46                 :
          47              44 : nsAsyncDOMEvent::nsAsyncDOMEvent(nsINode *aEventNode, nsEvent &aEvent)
          48              44 :   : mEventNode(aEventNode), mDispatchChromeOnly(false)
          49                 : {
          50              44 :   bool trusted = NS_IS_TRUSTED_EVENT(&aEvent);
          51              44 :   nsEventDispatcher::CreateEvent(nsnull, &aEvent, EmptyString(),
          52              88 :                                  getter_AddRefs(mEvent));
          53              44 :   NS_ASSERTION(mEvent, "Should never fail to create an event");
          54              88 :   nsCOMPtr<nsIPrivateDOMEvent> priv = do_QueryInterface(mEvent);
          55              44 :   NS_ASSERTION(priv, "Should also not fail to QI to nsIDOMEventPrivate");
          56              44 :   priv->DuplicatePrivateData();
          57              44 :   priv->SetTrusted(trusted);
          58              44 : }
          59                 :
          60            4369 : NS_IMETHODIMP nsAsyncDOMEvent::Run()
          61                 : {
          62            4369 :   if (!mEventNode) {
          63               0 :     return NS_OK;
          64                 :   }
          65                 :
          66            4369 :   if (mEvent) {
          67              44 :     NS_ASSERTION(!mDispatchChromeOnly, "Can't do that");
          68              88 :     nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mEventNode);
          69                 :     bool defaultActionEnabled; // This is not used because the caller is async
          70              44 :     target->DispatchEvent(mEvent, &defaultActionEnabled);
          71                 :   } else {
          72            4325 :     nsIDocument* doc = mEventNode->OwnerDoc();
          73            4325 :     if (mDispatchChromeOnly) {
          74                 :       nsContentUtils::DispatchChromeEvent(doc, mEventNode, mEventType,
          75               0 :                                           mBubbles, false);
          76                 :     } else {
          77                 :       nsContentUtils::DispatchTrustedEvent(doc, mEventNode, mEventType,
          78            4325 :                                            mBubbles, false);
          79                 :     }
          80                 :   }
          81                 :
          82            4369 :   return NS_OK;
          83                 : }
          84                 :
          85               0 : nsresult nsAsyncDOMEvent::PostDOMEvent()
          86                 : {
          87               0 :   return NS_DispatchToCurrentThread(this);
          88                 : }
          89                 :
          90            4369 : void nsAsyncDOMEvent::RunDOMEventWhenSafe()
          91                 : {
          92            4369 :   nsContentUtils::AddScriptRunner(this);
          93            4369 : }
          94                 :
          95               0 : nsLoadBlockingAsyncDOMEvent::~nsLoadBlockingAsyncDOMEvent()
          96                 : {
          97               0 :   if (mBlockedDoc) {
          98               0 :     mBlockedDoc->UnblockOnload(true);
          99                 :   }
         100               0 : }

Generated by: LCOV version 1.7