From 4dd46f4f63cb6bd27e72d98dfe2b59139e008f8d Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Wed, 13 Oct 2004 16:05:13 +0000 Subject: [PATCH] Fixing bug 263649. Add handleDefault(nsIDOMEvent) method to nsIXTFElement. Patch by smaug@welho.com, r=bryner@brianryner.com, sr=jst@mozilla.org git-svn-id: svn://10.0.0.236/trunk@163656 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xtf/public/nsIXTFElement.idl | 9 ++++ .../content/xtf/src/nsXTFElementWrapper.cpp | 48 +++++++++++++++++++ mozilla/content/xtf/src/nsXTFElementWrapper.h | 5 ++ 3 files changed, 62 insertions(+) diff --git a/mozilla/content/xtf/public/nsIXTFElement.idl b/mozilla/content/xtf/public/nsIXTFElement.idl index 162348e8bb7..97f2dff8dd4 100644 --- a/mozilla/content/xtf/public/nsIXTFElement.idl +++ b/mozilla/content/xtf/public/nsIXTFElement.idl @@ -41,6 +41,7 @@ interface nsIAtom; interface nsIDOMDocument; interface nsIDOMElement; interface nsIDOMNode; +interface nsIDOMEvent; [scriptable, uuid(f0617ed1-db6a-4704-ac4b-67bf15a77788)] interface nsIXTFElement : nsISupports @@ -114,6 +115,8 @@ interface nsIXTFElement : nsISupports const unsigned long NOTIFY_DONE_ADDING_CHILDREN = 0x00004000; + const unsigned long NOTIFY_HANDLE_DEFAULT = 0x00008000; + // Event notifications: void willChangeDocument(in nsIDOMDocument newDoc); @@ -138,5 +141,11 @@ interface nsIXTFElement : nsISupports void attributeRemoved(in nsIAtom name); void doneAddingChildren(); + + // The default handler for DOM Events. + // This method is called after the normal DOM event flow. + // If the return value is true, the event is marked as handled and + // other default handlers won't be able to handle it again. + boolean handleDefault(in nsIDOMEvent aEvent); }; diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.cpp b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp index 331ab0c548d..0ea1bb32289 100644 --- a/mozilla/content/xtf/src/nsXTFElementWrapper.cpp +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.cpp @@ -46,6 +46,9 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsIDocument.h" #include "nsHTMLAtoms.h" // XXX only needed for nsHTMLAtoms::id +#include "nsIEventListenerManager.h" +#include "nsIDOMEvent.h" +#include "nsGUIEvent.h" nsXTFElementWrapper::nsXTFElementWrapper(nsINodeInfo* aNodeInfo) : nsXTFElementWrapperBase(aNodeInfo), @@ -558,3 +561,48 @@ nsXTFElementWrapper::HandledByInner(nsIAtom *attr) const mAttributeHandler->HandlesAttribute(attr, &retval); return retval; } + +nsresult +nsXTFElementWrapper::HandleDOMEvent(nsPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus) +{ + nsresult rv = nsXTFElementWrapperBase::HandleDOMEvent(aPresContext, aEvent, + aDOMEvent, aFlags, + aEventStatus); + + if (NS_FAILED(rv) || + (nsEventStatus_eIgnore != *aEventStatus) || + !(mNotificationMask & nsIXTFElement::NOTIFY_HANDLE_DEFAULT) || + (aFlags & (NS_EVENT_FLAG_SYSTEM_EVENT | NS_EVENT_FLAG_CAPTURE))) + return rv; + + nsIDOMEvent* domEvent = nsnull; + if (!aDOMEvent) + aDOMEvent = &domEvent; + + if (!*aDOMEvent) { + // We haven't made a DOMEvent yet. Force making one now. + nsCOMPtr listenerManager; + if (NS_FAILED(rv = GetListenerManager(getter_AddRefs(listenerManager)))) + return rv; + + nsAutoString empty; + if (NS_FAILED(rv = listenerManager->CreateEvent(aPresContext, aEvent, + empty, aDOMEvent))) + return rv; + } + if (!*aDOMEvent) + return NS_ERROR_FAILURE; + + PRBool defaultHandled = PR_FALSE; + nsIXTFElement * xtfElement = GetXTFElement(); + if (xtfElement) + rv = xtfElement->HandleDefault(*aDOMEvent, &defaultHandled); + if (defaultHandled) + *aEventStatus = nsEventStatus_eConsumeNoDefault; + return rv; +} + diff --git a/mozilla/content/xtf/src/nsXTFElementWrapper.h b/mozilla/content/xtf/src/nsXTFElementWrapper.h index fa40537778b..5eb843181f3 100644 --- a/mozilla/content/xtf/src/nsXTFElementWrapper.h +++ b/mozilla/content/xtf/src/nsXTFElementWrapper.h @@ -109,6 +109,11 @@ public: // nsIClassInfo interface NS_DECL_NSICLASSINFO + + virtual nsresult HandleDOMEvent(nsPresContext* aPresContext, + nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus); protected: // to be implemented by subclasses: