Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Attributes
nsXMLEventsListener Class Reference

#include <nsXMLEventsManager.h>

Inheritance diagram for nsXMLEventsListener:
Inheritance graph
[legend]
Collaboration diagram for nsXMLEventsListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsXMLEventsListener (nsXMLEventsManager *aManager, nsIContent *aElement, nsIContent *aObserver, nsIContent *aHandler, const nsAString &aEvent, PRBool aPhase, PRBool aStopPropagation, PRBool aCancelDefault, const nsAString &aTarget)
 ~nsXMLEventsListener ()
void Unregister ()
void SetIncomplete ()
PRBool ObserverEquals (nsIContent *aTarget)
PRBool HandlerEquals (nsIContent *aTarget)
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Static Public Member Functions

static PRBool InitXMLEventsListener (nsIDocument *aDocument, nsXMLEventsManager *aManager, nsIContent *aContent)

Private Attributes

nsXMLEventsManagermManager
nsCOMPtr< nsIContentmElement
nsCOMPtr< nsIContentmObserver
nsCOMPtr< nsIContentmHandler
nsString mEvent
nsCOMPtr< nsIAtommTarget
PRPackedBool mPhase
PRPackedBool mStopPropagation
PRPackedBool mCancelDefault

Detailed Description

Definition at line 55 of file nsXMLEventsManager.h.


Constructor & Destructor Documentation

nsXMLEventsListener::nsXMLEventsListener ( nsXMLEventsManager aManager,
nsIContent aElement,
nsIContent aObserver,
nsIContent aHandler,
const nsAString &  aEvent,
PRBool  aPhase,
PRBool  aStopPropagation,
PRBool  aCancelDefault,
const nsAString &  aTarget 
)

Definition at line 170 of file nsXMLEventsManager.cpp.

 : mManager(aManager),
   mElement(aElement),
   mObserver(aObserver),
   mHandler(aHandler),
   mEvent(aEvent),
   mPhase(aPhase),
   mStopPropagation(aStopPropagation),
   mCancelDefault(aCancelDefault)
{
  if (!aTarget.IsEmpty())
    mTarget = do_GetAtom(aTarget);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 192 of file nsXMLEventsManager.cpp.

{
}

Member Function Documentation

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

Definition at line 218 of file nsXMLEventsManager.cpp.

{
  return aTarget == mHandler;
}
PRBool nsXMLEventsListener::InitXMLEventsListener ( nsIDocument aDocument,
nsXMLEventsManager aManager,
nsIContent aContent 
) [static]

Definition at line 52 of file nsXMLEventsManager.cpp.

{
  PRInt32 nameSpaceID;
  if (aContent->GetDocument() != aDocument)
    return PR_FALSE;
  if (aContent->GetNodeInfo()->Equals(nsHTMLAtoms::listener, kNameSpaceID_XMLEvents))
    nameSpaceID = kNameSpaceID_None;
  else
    nameSpaceID = kNameSpaceID_XMLEvents;
  nsAutoString eventType;
  nsresult rv = aContent->GetAttr(nameSpaceID, nsHTMLAtoms::_event, eventType);
  if (rv != NS_CONTENT_ATTR_HAS_VALUE)
    return PR_FALSE;
  nsAutoString handlerURIStr;
  PRBool hasHandlerURI = PR_FALSE;
  nsCOMPtr<nsIContent> handler;
  nsAutoString observerID;
  nsAutoString targetIdref;
  
  if (aContent->GetAttr(nameSpaceID, nsHTMLAtoms::handler, handlerURIStr) != 
      NS_CONTENT_ATTR_NOT_THERE) {
    hasHandlerURI = PR_TRUE;
    nsCAutoString handlerRef;
    nsCOMPtr<nsIURI> handlerURI;
    PRBool equals = PR_FALSE;
    nsIURI *docURI = aDocument->GetDocumentURI();
    nsIURI *baseURI = aDocument->GetBaseURI();
    rv = NS_NewURI( getter_AddRefs(handlerURI), handlerURIStr, nsnull, baseURI);
    if (NS_SUCCEEDED(rv)) {
      nsCOMPtr<nsIURL> handlerURL(do_QueryInterface(handlerURI));
      if (handlerURL) {
        handlerURL->GetRef(handlerRef);
        handlerURL->SetRef(EmptyCString());
        //We support only XML Events Basic.
        docURI->Equals(handlerURL, &equals);
        if (equals) {
          nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aDocument));
          if (doc) {
            nsCOMPtr<nsIDOMElement> domhandler;
            doc->GetElementById(NS_ConvertUTF8toUTF16(handlerRef),
                                getter_AddRefs(domhandler));
            handler = do_QueryInterface(domhandler);
          }
        }
      }
    }
  }
  else
    handler = aContent;
  if (!handler)
    return PR_FALSE;

  aContent->GetAttr(nameSpaceID, nsHTMLAtoms::target, targetIdref);

  PRBool hasObserver = 
    aContent->GetAttr(nameSpaceID, nsHTMLAtoms::observer, observerID) != 
    NS_CONTENT_ATTR_NOT_THERE;

  nsAutoString phase;
  PRBool capture =
    aContent->GetAttr(nameSpaceID, nsHTMLAtoms::phase, phase) !=
    NS_CONTENT_ATTR_NOT_THERE && phase.Equals(NS_LITERAL_STRING("capture"));

  nsAutoString prop;
  PRBool stopPropagation = 
    aContent->GetAttr(nameSpaceID, nsHTMLAtoms::propagate, prop) !=
    NS_CONTENT_ATTR_NOT_THERE && prop.Equals(NS_LITERAL_STRING("stop"));

  nsAutoString cancel;
  PRBool cancelDefault = 
    aContent->GetAttr(nameSpaceID, nsHTMLAtoms::defaultAction, cancel) !=
    NS_CONTENT_ATTR_NOT_THERE && cancel.Equals(NS_LITERAL_STRING("cancel"));

  nsCOMPtr<nsIContent> observer;
  if (!hasObserver) {
    if (!hasHandlerURI) //Parent should be the observer
      observer = aContent->GetParent();
    else //We have the handler, so this is the observer
      observer = aContent;
  }
  else if (!observerID.IsEmpty()) {
    nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aDocument));
    if (doc) {
      nsCOMPtr<nsIDOMElement> el;
      doc->GetElementById(observerID, getter_AddRefs(el));
      observer = do_QueryInterface(el);
    }
  }
  nsCOMPtr<nsIDOMEventTarget> eventObserver;
  if (observer)
    eventObserver = do_QueryInterface(observer);
  if (eventObserver) {
    nsXMLEventsListener * eli = new nsXMLEventsListener(aManager,
                                                        aContent,
                                                        observer,
                                                        handler,
                                                        eventType,
                                                        capture,
                                                        stopPropagation,
                                                        cancelDefault,
                                                        targetIdref);
    if (eli) {
      nsresult rv = eventObserver->AddEventListener(eventType, eli, capture);
      if (NS_SUCCEEDED(rv)) {
        aManager->RemoveXMLEventsContent(aContent);
        aManager->RemoveListener(aContent);
        aManager->AddListener(aContent, eli);
        return PR_TRUE;
      }
      else
        delete eli;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Definition at line 213 of file nsXMLEventsManager.cpp.

{
  return aTarget == mObserver;
}

Definition at line 206 of file nsXMLEventsManager.cpp.

Here is the call graph for this function:

Definition at line 196 of file nsXMLEventsManager.cpp.

{
  nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mObserver);
  if (target) {
    target->RemoveEventListener(mEvent, this, mPhase);
  }
  mObserver = nsnull;
  mHandler = nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 88 of file nsXMLEventsManager.h.

Definition at line 81 of file nsXMLEventsManager.h.

Definition at line 84 of file nsXMLEventsManager.h.

Definition at line 83 of file nsXMLEventsManager.h.

Definition at line 80 of file nsXMLEventsManager.h.

Definition at line 82 of file nsXMLEventsManager.h.

Definition at line 86 of file nsXMLEventsManager.h.

Definition at line 87 of file nsXMLEventsManager.h.

Definition at line 85 of file nsXMLEventsManager.h.


The documentation for this class was generated from the following files: