dom/events/EventTarget.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/EventTarget.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_dom_EventTarget_h_
    1.10 +#define mozilla_dom_EventTarget_h_
    1.11 +
    1.12 +#include "nsIDOMEventTarget.h"
    1.13 +#include "nsWrapperCache.h"
    1.14 +#include "nsIAtom.h"
    1.15 +
    1.16 +class nsIDOMWindow;
    1.17 +class nsIDOMEventListener;
    1.18 +
    1.19 +namespace mozilla {
    1.20 +
    1.21 +class ErrorResult;
    1.22 +class EventListenerManager;
    1.23 +
    1.24 +namespace dom {
    1.25 +
    1.26 +class Event;
    1.27 +class EventListener;
    1.28 +class EventHandlerNonNull;
    1.29 +template <class T> struct Nullable;
    1.30 +
    1.31 +// IID for the dom::EventTarget interface
    1.32 +#define NS_EVENTTARGET_IID \
    1.33 +{ 0xce3817d0, 0x177b, 0x402f, \
    1.34 + { 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
    1.35 +
    1.36 +class EventTarget : public nsIDOMEventTarget,
    1.37 +                    public nsWrapperCache
    1.38 +{
    1.39 +public:
    1.40 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_EVENTTARGET_IID)
    1.41 +
    1.42 +  // WebIDL API
    1.43 +  using nsIDOMEventTarget::AddEventListener;
    1.44 +  using nsIDOMEventTarget::RemoveEventListener;
    1.45 +  using nsIDOMEventTarget::DispatchEvent;
    1.46 +  virtual void AddEventListener(const nsAString& aType,
    1.47 +                                EventListener* aCallback,
    1.48 +                                bool aCapture,
    1.49 +                                const Nullable<bool>& aWantsUntrusted,
    1.50 +                                ErrorResult& aRv) = 0;
    1.51 +  virtual void RemoveEventListener(const nsAString& aType,
    1.52 +                                   EventListener* aCallback,
    1.53 +                                   bool aCapture,
    1.54 +                                   ErrorResult& aRv);
    1.55 +  bool DispatchEvent(Event& aEvent, ErrorResult& aRv);
    1.56 +
    1.57 +  // Note, this takes the type in onfoo form!
    1.58 +  EventHandlerNonNull* GetEventHandler(const nsAString& aType)
    1.59 +  {
    1.60 +    nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
    1.61 +    return GetEventHandler(type, EmptyString());
    1.62 +  }
    1.63 +
    1.64 +  // Note, this takes the type in onfoo form!
    1.65 +  void SetEventHandler(const nsAString& aType, EventHandlerNonNull* aHandler,
    1.66 +                       ErrorResult& rv);
    1.67 +
    1.68 +  // Note, for an event 'foo' aType will be 'onfoo'.
    1.69 +  virtual void EventListenerAdded(nsIAtom* aType) {}
    1.70 +  virtual void EventListenerRemoved(nsIAtom* aType) {}
    1.71 +
    1.72 +  // Returns an outer window that corresponds to the inner window this event
    1.73 +  // target is associated with.  Will return null if the inner window is not the
    1.74 +  // current inner or if there is no window around at all.
    1.75 +  virtual nsIDOMWindow* GetOwnerGlobal() = 0;
    1.76 +
    1.77 +  /**
    1.78 +   * Get the event listener manager, creating it if it does not already exist.
    1.79 +   */
    1.80 +  virtual EventListenerManager* GetOrCreateListenerManager() = 0;
    1.81 +
    1.82 +  /**
    1.83 +   * Get the event listener manager, returning null if it does not already
    1.84 +   * exist.
    1.85 +   */
    1.86 +  virtual EventListenerManager* GetExistingListenerManager() const = 0;
    1.87 +
    1.88 +protected:
    1.89 +  EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
    1.90 +                                       const nsAString& aTypeString);
    1.91 +  void SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
    1.92 +                       EventHandlerNonNull* aHandler);
    1.93 +};
    1.94 +
    1.95 +NS_DEFINE_STATIC_IID_ACCESSOR(EventTarget, NS_EVENTTARGET_IID)
    1.96 +
    1.97 +} // namespace dom
    1.98 +} // namespace mozilla
    1.99 +
   1.100 +#endif // mozilla_dom_EventTarget_h_

mercurial