Commit a743e2b3 authored by joki%netscape.com's avatar joki%netscape.com
Browse files

Updating mozilla to DOM Level 2 events support. Fixes for bug 34722, 35378,...

Updating mozilla to DOM Level 2 events support.  Fixes for bug 34722, 35378, 8411, 10330, plus some others that weren't filed.
parent d7557a57
Loading
Loading
Loading
Loading
+60 −6
Original line number Diff line number Diff line
@@ -688,6 +688,12 @@ nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
    NS_ADDREF_THIS();
    return NS_OK;
  }
  if (aIID.Equals(NS_GET_IID(nsIDOMDocumentEvent))) {
    nsIDOMDocumentEvent* tmp = this;
    *aInstancePtr = (void*) tmp;
    NS_ADDREF_THIS();
    return NS_OK;
  }
  if (aIID.Equals(NS_GET_IID(nsIDOMDocumentStyle))) {
    nsIDOMDocumentStyle* tmp = this;
    *aInstancePtr = (void*) tmp;
@@ -2628,7 +2634,7 @@ nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePt

nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent)
{
  return NS_ERROR_FAILURE;
  return DispatchEvent(aEvent);
} 

nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, 
@@ -2640,9 +2646,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
  nsresult mRet = NS_OK;
  nsIDOMEvent* mDOMEvent = nsnull;

  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    aDOMEvent = &mDOMEvent;
    aEvent->flags = NS_EVENT_FLAG_NONE;
    aEvent->flags = aFlags;
    aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
  }
  
  //Capturing stage
@@ -2651,9 +2658,10 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
  }
  
  //Local handling stage
  if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
  if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
      !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
    aEvent->flags |= aFlags;
    mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
    mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
    aEvent->flags &= ~aFlags;
  }

@@ -2662,7 +2670,7 @@ nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext,
    mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus);
  }

  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    // We're leaving the DOM event loop so if we created a DOM event, release here.
    if (nsnull != *aDOMEvent) {
      nsrefcnt rc;
@@ -2731,6 +2739,52 @@ nsresult nsDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListe
  return NS_ERROR_FAILURE;
}

NS_IMETHODIMP
nsDocument::DispatchEvent(nsIDOMEvent* aEvent)
{
  // Obtain a presentation context
  PRInt32 count = GetNumberOfShells();
  if (count == 0)
    return NS_OK;

  nsCOMPtr<nsIPresShell> shell = getter_AddRefs(GetShellAt(0));
  
  // Retrieve the context
  nsCOMPtr<nsIPresContext> presContext;
  shell->GetPresContext(getter_AddRefs(presContext));

  nsCOMPtr<nsIEventStateManager> esm;
  if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) {
    return esm->DispatchNewEvent((nsISupports *)(nsIDOMDocument *)this, aEvent);
  }

  return NS_ERROR_FAILURE;
}

NS_IMETHODIMP
nsDocument::CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn)
{
  // Obtain a presentation context
  PRInt32 count = GetNumberOfShells();
  if (count == 0)
    return NS_OK;

  nsCOMPtr<nsIPresShell> shell = getter_AddRefs(GetShellAt(0));
  
  // Retrieve the context
  nsCOMPtr<nsIPresContext> presContext;
  shell->GetPresContext(getter_AddRefs(presContext));

  if (presContext) {
    nsCOMPtr<nsIEventListenerManager> lm;
    if (NS_SUCCEEDED(GetListenerManager(getter_AddRefs(lm)))) {
      return lm->CreateEvent(presContext, nsnull, aEventType, aReturn);
    }
  }

  return NS_ERROR_FAILURE;
}

PRBool    nsDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp)
{
  return PR_TRUE;
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "nsIPrincipal.h"
#include "nsIBindingManager.h"
#include "nsINodeInfo.h"
#include "nsIDOMDocumentEvent.h"

class nsIEventListenerManager;
class nsDOMStyleSheetList;
@@ -113,6 +114,7 @@ protected:
class nsDocument : public nsIDocument, 
                   public nsIDOMDocument, 
                   public nsIDOMNSDocument,
                   public nsIDOMDocumentEvent,
                   public nsIDOMDocumentStyle,
                   public nsIDOMDocumentView,
                   public nsIDiskDocument,
@@ -371,6 +373,9 @@ public:
  // nsIDOMDocumentView
  NS_DECL_IDOMDOCUMENTVIEW

  // nsIDOMDocumentEvent
  NS_DECL_IDOMDOCUMENTEVENT

  // nsIDOMEventReceiver interface
  NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
  NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
@@ -397,6 +402,7 @@ public:
                              PRBool aUseCapture);
  NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, 
                                 PRBool aUseCapture);
  NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent);


  NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, 
+13 −7
Original line number Diff line number Diff line
@@ -71,7 +71,10 @@ nsGenericDOMDataNode::nsGenericDOMDataNode()

nsGenericDOMDataNode::~nsGenericDOMDataNode()
{
  NS_IF_RELEASE(mListenerManager);
  if (mListenerManager) {
    mListenerManager->SetListenerTarget(nsnull);
    NS_RELEASE(mListenerManager);
  }
  delete mRangeList;
}

@@ -529,7 +532,7 @@ nsGenericDOMDataNode::SetScriptObject(void *aScriptObject)
//----------------------------------------------------------------------

nsresult
nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult)
nsGenericDOMDataNode::GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aResult)
{
  if (nsnull != mListenerManager) {
    NS_ADDREF(mListenerManager);
@@ -540,6 +543,7 @@ nsGenericDOMDataNode::GetListenerManager(nsIEventListenerManager** aResult)
  if (NS_OK == rv) {
    mListenerManager = *aResult;
    NS_ADDREF(mListenerManager);
    mListenerManager->SetListenerTarget(aOuterContent);
  }
  return rv;
}
@@ -748,9 +752,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
  nsresult ret = NS_OK;
  nsIDOMEvent* domEvent = nsnull;

  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    aDOMEvent = &domEvent;
    aEvent->flags = NS_EVENT_FLAG_NONE;
    aEvent->flags = aFlags;
    aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);

    //Initiate capturing phase.  Special case first call to document
    if (nsnull != mDocument) {
@@ -765,9 +770,10 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
  }
  
  //Local handling stage
  if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
  if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
      !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
    aEvent->flags |= aFlags;
    mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
    mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull, aFlags, aEventStatus);
    aEvent->flags &= ~aFlags;
  }

@@ -777,7 +783,7 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
                                  NS_EVENT_FLAG_BUBBLE, aEventStatus);
  }

  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    // We're leaving the DOM event loop so if we created a DOM event,
    // release here.
    if (nsnull != *aDOMEvent) {
+3 −3
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ struct nsGenericDOMDataNode {

  //----------------------------------------

  nsresult GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
  nsresult GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aInstancePtrResult);

  void ToCString(nsString& aBuf, PRInt32 aOffset, PRInt32 aLen) const;

@@ -609,14 +609,14 @@ struct nsGenericDOMDataNode {
  }                                                         \
  if (_id.Equals(kIDOMEventReceiverIID)) {                  \
    nsCOMPtr<nsIEventListenerManager> man;                  \
    if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \
    if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \
      return man->QueryInterface(kIDOMEventReceiverIID, (void**)_iptr); \
    }                                                       \
    return NS_NOINTERFACE;                                  \
  }                                                         \
  if (_id.Equals(kIDOMEventTargetIID)) {                    \
    nsCOMPtr<nsIEventListenerManager> man;                  \
    if (NS_SUCCEEDED(mInner.GetListenerManager(getter_AddRefs(man)))){ \
    if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \
      return man->QueryInterface(kIDOMEventTargetIID, (void**)_iptr); \
    }                                                       \
    return NS_NOINTERFACE;                                  \
+13 −6
Original line number Diff line number Diff line
@@ -401,7 +401,10 @@ nsGenericElement::~nsGenericElement()
      mDOMSlots->mAttributeMap->DropReference();
      NS_RELEASE(mDOMSlots->mAttributeMap);
    }
    NS_IF_RELEASE(mDOMSlots->mListenerManager);
    if (nsnull != mDOMSlots->mListenerManager) {
      mDOMSlots->mListenerManager->SetListenerTarget(nsnull);
      NS_RELEASE(mDOMSlots->mListenerManager);
    }
    // XXX Should really be arena managed
    PR_DELETE(mDOMSlots);
  }
@@ -1284,9 +1287,10 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
  nsresult ret = NS_OK;
  
  nsIDOMEvent* domEvent = nsnull;
  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    aDOMEvent = &domEvent;
    aEvent->flags = NS_EVENT_FLAG_NONE;
    aEvent->flags = aFlags;
    aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL);
  }
  
  //Capturing stage evaluation
@@ -1310,9 +1314,11 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
  }
  
  //Local handling stage
  if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
  if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
      !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
    aEvent->flags |= aFlags;
    mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
    nsCOMPtr<nsIDOMEventTarget> curTarg(do_QueryInterface(mContent));
    mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, curTarg, aFlags, aEventStatus);
    aEvent->flags &= ~aFlags;
  }

@@ -1334,7 +1340,7 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
    }
  }

  if (NS_EVENT_FLAG_INIT == aFlags) {
  if (NS_EVENT_FLAG_INIT & aFlags) {
    // We're leaving the DOM event loop so if we created a DOM event,
    // release here.
    if (nsnull != *aDOMEvent) {
@@ -1557,6 +1563,7 @@ nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult)
  if (NS_OK == rv) {
    slots->mListenerManager = *aResult;
    NS_ADDREF(slots->mListenerManager);
    slots->mListenerManager->SetListenerTarget(mContent);
  }
  return rv;
}
Loading