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
This commit is contained in:
parent
53004c4014
commit
4dd46f4f63
@ -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);
|
||||
};
|
||||
|
||||
|
||||
@ -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<nsIEventListenerManager> 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;
|
||||
}
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user