LCOV - code coverage report
Current view: directory - dom/workers - ListenerManager.h (source / functions) Found Hit Coverage
Test: app.info Lines: 19 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

       1                 : /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
       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 Web Workers.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  *   The Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Ben Turner <bent.mozilla@gmail.com> (Original Author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef mozilla_dom_workers_listenermanager_h__
      40                 : #define mozilla_dom_workers_listenermanager_h__
      41                 : 
      42                 : #include "Workers.h"
      43                 : 
      44                 : #include "jsapi.h"
      45                 : #include "prclist.h"
      46                 : 
      47                 : BEGIN_WORKERS_NAMESPACE
      48                 : 
      49                 : namespace events {
      50                 : 
      51                 : // XXX Current impl doesn't divide into phases.
      52                 : // XXX Current impl doesn't handle event target chains.
      53                 : class ListenerManager
      54                 : {
      55                 : public:
      56                 :   enum Phase
      57                 :   {
      58                 :     All = 0,
      59                 :     Capturing,
      60                 :     Onfoo,
      61                 :     Bubbling
      62                 :   };
      63                 : 
      64                 : private:
      65                 :   PRCList mCollectionHead;
      66                 : 
      67                 : public:
      68               0 :   ListenerManager()
      69                 :   {
      70               0 :     PR_INIT_CLIST(&mCollectionHead);
      71               0 :   }
      72                 : 
      73                 : #ifdef DEBUG
      74                 :   ~ListenerManager();
      75                 : #endif
      76                 : 
      77                 :   void
      78               0 :   Trace(JSTracer* aTrc)
      79                 :   {
      80               0 :     if (!PR_CLIST_IS_EMPTY(&mCollectionHead)) {
      81               0 :       TraceInternal(aTrc);
      82                 :     }
      83               0 :   }
      84                 : 
      85                 :   void
      86               0 :   Finalize(JSContext* aCx)
      87                 :   {
      88               0 :     if (!PR_CLIST_IS_EMPTY(&mCollectionHead)) {
      89               0 :       FinalizeInternal(aCx);
      90                 :     }
      91               0 :   }
      92                 : 
      93                 :   bool
      94               0 :   AddEventListener(JSContext* aCx, JSString* aType, jsval aListener,
      95                 :                    bool aCapturing, bool aWantsUntrusted)
      96                 :   {
      97                 :     return Add(aCx, aType, aListener, aCapturing ? Capturing : Bubbling,
      98               0 :                aWantsUntrusted);
      99                 :   }
     100                 : 
     101                 :   bool
     102                 :   SetEventListener(JSContext* aCx, JSString* aType, jsval aListener);
     103                 : 
     104                 :   bool
     105               0 :   RemoveEventListener(JSContext* aCx, JSString* aType, jsval aListener,
     106                 :                       bool aCapturing)
     107                 :   {
     108               0 :     if (PR_CLIST_IS_EMPTY(&mCollectionHead)) {
     109               0 :       return true;
     110                 :     }
     111                 :     return Remove(aCx, aType, aListener, aCapturing ? Capturing : Bubbling,
     112               0 :                   true);
     113                 :   }
     114                 : 
     115                 :   bool
     116                 :   GetEventListener(JSContext* aCx, JSString* aType, jsval* aListener);
     117                 : 
     118                 :   bool
     119                 :   DispatchEvent(JSContext* aCx, JSObject* aTarget, JSObject* aEvent,
     120                 :                 bool* aPreventDefaultCalled);
     121                 : 
     122                 :   bool
     123               0 :   HasListeners()
     124                 :   {
     125               0 :     return !PR_CLIST_IS_EMPTY(&mCollectionHead);
     126                 :   }
     127                 : 
     128                 :   bool
     129                 :   HasListenersForType(JSContext* aCx, JSString* aType)
     130                 :   {
     131                 :     return HasListeners() && HasListenersForTypeInternal(aCx, aType);
     132                 :   }
     133                 : 
     134                 :   bool
     135                 :   HasListenersForTypeInternal(JSContext* aCx, JSString* aType);
     136                 : 
     137                 : private:
     138                 :   void
     139                 :   TraceInternal(JSTracer* aTrc);
     140                 : 
     141                 :   void
     142                 :   FinalizeInternal(JSContext* aCx);
     143                 : 
     144                 :   bool
     145                 :   Add(JSContext* aCx, JSString* aType, jsval aListener, Phase aPhase,
     146                 :       bool aWantsUntrusted);
     147                 : 
     148                 :   bool
     149                 :   Remove(JSContext* aCx, JSString* aType, jsval aListener, Phase aPhase,
     150                 :          bool aClearEmpty);
     151                 : };
     152                 : 
     153                 : } // namespace events
     154                 : 
     155                 : END_WORKERS_NAMESPACE
     156                 : 
     157                 : #endif /* mozilla_dom_workers_listenermanager_h__ */

Generated by: LCOV version 1.7