Updating mozilla to DOM Level 2 events support. Fixes for bug 34722, 35378, 8411, 10330, plus some others that weren't filed.

This commit is contained in:
joki%netscape.com 2000-05-16 11:35:12 +00:00
Родитель 1cdf7b1070
Коммит b2e873d830
122 изменённых файлов: 1791 добавлений и 4223 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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,

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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; \

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -30,6 +30,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIScriptObjectOwner;
class nsIDOMEventTarget;
/*
* Event listener manager interface.
@ -104,6 +105,7 @@ public:
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus) = 0;
@ -114,6 +116,7 @@ public:
*/
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent) = 0;
/**
@ -133,6 +136,12 @@ public:
* manager.
*/
virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0;
/**
* Removes all event listeners registered by this instance of the listener
* manager.
*/
virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0;
};
extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult);

Просмотреть файл

@ -83,6 +83,8 @@ public:
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor) = 0;
//Method for centralized distribution of new DOM events
NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) = 0;
};
#define NS_EVENT_STATE_UNSPECIFIED 0x0000

Просмотреть файл

@ -36,7 +36,7 @@ class nsIPresContext;
0x80a98c80, 0x2036, 0x11d2, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIDOMNode;
class nsIDOMEventTarget;
class nsIDOMEvent;
class nsIPrivateDOMEvent : public nsISupports {
@ -45,11 +45,15 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMEVENT_IID; return iid; }
NS_IMETHOD DuplicatePrivateData() = 0;
NS_IMETHOD SetTarget(nsIDOMNode* aNode) = 0;
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
};
extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);
extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);
extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsIPresContext* aPresContext,
const nsString& aEventType,
nsEvent *aEvent);
#endif // nsIPrivateDOMEvent_h__

Просмотреть файл

@ -34,6 +34,12 @@
#include "nsIViewManager.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIScrollableView.h"
#include "nsIDOMEventTarget.h"
#include "nsIInterfaceRequestor.h"
#include "nsIDOMWindow.h"
#include "nsIDOMAbstractView.h"
#include "prmem.h"
#include "nsLayoutAtoms.h"
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -46,16 +52,39 @@ static char* mEventNames[] = {
"dragenter", "dragover", "dragexit", "dragdrop", "draggesture"
};
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType) {
mPresContext = aPresContext;
if (mPresContext)
NS_ADDREF(mPresContext);
mEvent = aEvent;
if (aEvent) {
mEventIsInternal = PR_FALSE;
mEvent = aEvent;
}
else {
//Allocate internal event
if (aEventType.EqualsIgnoreCase("MouseEvent")) {
mEvent = PR_NEWZAP(nsMouseEvent);
mEvent->eventStructType = NS_MOUSE_EVENT;
}
else if (aEventType.EqualsIgnoreCase("KeyEvent")) {
mEvent = PR_NEWZAP(nsKeyEvent);
mEvent->eventStructType = NS_KEY_EVENT;
}
else if (aEventType.EqualsIgnoreCase("HTMLEvent")) {
mEvent = PR_NEWZAP(nsEvent);
mEvent->eventStructType = NS_EVENT;
}
else {
mEvent = PR_NEWZAP(nsEvent);
mEvent->eventStructType = NS_EVENT;
}
}
mTarget = nsnull;
mCurrentTarget = nsnull;
mText = nsnull;
mTextRange = nsnull;
if (aEvent->eventStructType ==NS_TEXT_EVENT) {
if (aEvent->eventStructType == NS_TEXT_EVENT) {
//
// extract the IME composition string
//
@ -87,8 +116,13 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
nsDOMEvent::~nsDOMEvent() {
NS_IF_RELEASE(mPresContext);
NS_IF_RELEASE(mTarget);
NS_IF_RELEASE(mCurrentTarget);
NS_IF_RELEASE(mTextRange);
if (mEventIsInternal) {
PR_DELETE(mEvent);
}
if (mText!=nsnull)
delete mText;
}
@ -121,7 +155,7 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
{
if (nsnull != mTarget) {
*aTarget = mTarget;
@ -138,7 +172,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
if (targetContent) {
if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) {
if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) {
*aTarget = mTarget;
NS_ADDREF(mTarget);
}
@ -154,7 +188,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
if (doc) {
if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) {
if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) {
*aTarget = mTarget;
NS_ADDREF(mTarget);
}
@ -166,9 +200,9 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
NS_IMETHODIMP
nsDOMEvent::GetCurrentNode(nsIDOMNode** aCurrentNode)
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
{
*aCurrentNode = nsnull;
*aCurrentTarget = nsnull;
return NS_OK;
}
@ -194,13 +228,29 @@ nsDOMEvent::GetEventPhase(PRUint16* aEventPhase)
NS_IMETHODIMP
nsDOMEvent::GetBubbles(PRBool* aBubbles)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aBubbles = mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetCancelable(PRBool* aCancelable)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aCancelable = mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp)
{
*aTimeStamp = mEvent->time;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::StopPropagation()
{
mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
return NS_OK;
}
NS_IMETHODIMP
@ -224,20 +274,64 @@ nsDOMEvent::PreventCapture()
NS_IMETHODIMP
nsDOMEvent::PreventDefault()
{
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) {
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetView(nsIDOMAbstractView** aView)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER(aView);
*aView = nsnull;
nsresult rv = NS_OK;
nsCOMPtr<nsISupports> container;
rv = mPresContext->GetContainer(getter_AddRefs(container));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv);
nsCOMPtr<nsIInterfaceRequestor> ifrq(do_QueryInterface(container));
NS_ENSURE_TRUE(ifrq, NS_OK);
nsCOMPtr<nsIDOMWindow> window;
ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window));
NS_ENSURE_TRUE(window, NS_OK);
window->QueryInterface(NS_GET_IID(nsIDOMAbstractView), (void **)aView);
return rv;
}
NS_IMETHODIMP
nsDOMEvent::GetDetail(PRInt32* aDetail)
{
return NS_ERROR_NOT_IMPLEMENTED;
//detail is valid for more than just mouseevents but we don't
//use it for anything else right now
if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) {
*aDetail = 0;
return NS_OK;
}
switch (mEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_CLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
*aDetail = ((nsMouseEvent*)mEvent)->clickCount;
break;
default:
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetText(nsString& aText)
@ -515,35 +609,7 @@ NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton)
return NS_OK;
}
NS_METHOD nsDOMEvent::GetClickCount(PRUint16* aClickCount)
{
if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) {
*aClickCount = 0;
return NS_OK;
}
switch (mEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_CLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
*aClickCount = ((nsMouseEvent*)mEvent)->clickCount;
break;
default:
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
{
nsIEventStateManager *manager;
nsIContent *relatedContent = nsnull;
@ -555,11 +621,11 @@ NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
}
if (relatedContent) {
ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aRelatedNode);
ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)aRelatedTarget);
NS_RELEASE(relatedContent);
}
else {
*aRelatedNode = nsnull;
*aRelatedTarget = nsnull;
}
return ret;
@ -793,30 +859,109 @@ NS_METHOD nsDOMEvent::GetPreventDefault(PRBool* aReturn)
return NS_OK;
}
//XXX The following four methods are for custom event dispatch inside the DOM.
//They will be implemented post-beta
nsresult
nsDOMEvent::SetEventType(const nsString& aEventTypeArg)
{
nsAutoString str; str.AssignWithConversion("on");
nsIAtom* atom;
str.Append(aEventTypeArg);
atom = NS_NewAtom(str);
if (atom == nsLayoutAtoms::onmousedown && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN;
}
else if (atom == nsLayoutAtoms::onmouseup && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_BUTTON_UP;
}
else if (atom == nsLayoutAtoms::onclick && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_CLICK;
}
else if (atom == nsLayoutAtoms::onmouseover && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_ENTER_SYNTH;
}
else if (atom == nsLayoutAtoms::onmouseout && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_EXIT_SYNTH;
}
else if (atom == nsLayoutAtoms::onmousemove && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_MOVE;
}
else if (atom == nsLayoutAtoms::onkeydown && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_DOWN;
}
else if (atom == nsLayoutAtoms::onkeyup && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_UP;
}
else if (atom == nsLayoutAtoms::onkeypress && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_PRESS;
}
else if (atom == nsLayoutAtoms::onfocus && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FOCUS_CONTENT;
}
else if (atom == nsLayoutAtoms::onblur && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_BLUR_CONTENT;
}
else if (atom == nsLayoutAtoms::onsubmit && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_SUBMIT;
}
else if (atom == nsLayoutAtoms::onreset && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_RESET;
}
else if (atom == nsLayoutAtoms::onchange && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_CHANGE;
}
else if (atom == nsLayoutAtoms::onselect && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_SELECTED;
}
else if (atom == nsLayoutAtoms::onload && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_PAGE_LOAD;
}
else if (atom == nsLayoutAtoms::onunload && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_PAGE_UNLOAD;
}
else if (atom == nsLayoutAtoms::onabort && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_IMAGE_ABORT;
}
else if (atom == nsLayoutAtoms::onerror && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_IMAGE_ERROR;
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitEvent(const nsString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE);
mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitUIEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDOMEvent::InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE);
//mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
//mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitKeyEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE);
mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
@ -828,7 +973,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData()
return NS_OK;
}
NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget)
NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
{
if (mTarget != aTarget) {
NS_IF_RELEASE(mTarget);
@ -838,6 +983,16 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget)
return NS_OK;
}
NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget)
{
if (mCurrentTarget != aCurrentTarget) {
NS_IF_RELEASE(mCurrentTarget);
NS_IF_ADDREF(aCurrentTarget);
mCurrentTarget = aCurrentTarget;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped)
{
@ -936,9 +1091,12 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return nsnull;
}
nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent)
nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsIPresContext* aPresContext,
const nsString& aEventType,
nsEvent *aEvent)
{
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent);
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -85,18 +85,20 @@ public:
eDOMEvents_draggesture
};
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType);
virtual ~nsDOMEvent();
NS_DECL_ISUPPORTS
// nsIDOMEvent Interface
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode);
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget);
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget);
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase);
NS_IMETHOD GetBubbles(PRBool* aBubbles);
NS_IMETHOD GetCancelable(PRBool* aCancelable);
NS_IMETHOD GetTimeStamp(PRUint64* aTimestamp);
NS_IMETHOD StopPropagation();
NS_IMETHOD PreventBubble();
NS_IMETHOD PreventCapture();
NS_IMETHOD PreventDefault();
@ -117,8 +119,7 @@ public:
NS_IMETHOD GetShiftKey(PRBool* aShiftKey);
NS_IMETHOD GetMetaKey(PRBool* aMetaKey);
NS_IMETHOD GetButton(PRUint16* aButton);
NS_IMETHOD GetClickCount(PRUint16* aClickCount);
NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode);
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget);
NS_IMETHOD GetCharCode(PRUint32* aCharCode);
NS_IMETHOD GetKeyCode(PRUint32* aKeyCode);
NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg);
@ -139,7 +140,8 @@ public:
// nsIPrivateDOMEvent interface
NS_IMETHOD DuplicatePrivateData();
NS_IMETHOD SetTarget(nsIDOMNode* aNode);
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget);
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget);
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
// nsIPrivateTextEvent interface
@ -154,10 +156,13 @@ protected:
//Internal helper funcs
nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P);
nsresult SetEventType(const nsString& aEventTypeArg);
nsEvent* mEvent;
PRBool mEventIsInternal;
nsIPresContext* mPresContext;
nsIDOMNode* mTarget;
nsIDOMEventTarget* mTarget;
nsIDOMEventTarget* mCurrentTarget;
nsString* mText;
nsIPrivateTextRangeList* mTextRange;
const char* GetEventName(PRUint32 aEventType);

Просмотреть файл

@ -22,7 +22,6 @@
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsIPresContext.h"
#include "nsDOMEvent.h"
#include "nsEventListenerManager.h"
#include "nsIDOMEventListener.h"
@ -54,6 +53,8 @@
#include "nsDOMPropEnums.h"
#include "nsDOMError.h"
#include "nsIJSContextStack.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -75,6 +76,7 @@ nsEventListenerManager::nsEventListenerManager()
mCompositionListeners = nsnull;
mMenuListeners = nsnull;
mDestroyed = PR_FALSE;
mTarget = nsnull;
NS_INIT_REFCNT();
}
@ -616,6 +618,7 @@ nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *a
nsresult
nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags)
{
@ -700,7 +703,10 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
}
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIPrivateDOMEvent> aPrivDOMEvent(do_QueryInterface(aDOMEvent));
aPrivDOMEvent->SetCurrentTarget(aCurrentTarget);
result = aListenerStruct->mListener->HandleEvent(aDOMEvent);
aPrivDOMEvent->SetCurrentTarget(nsnull);
}
return result;
@ -714,6 +720,7 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
@ -727,6 +734,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
keys which cause window deletion, can destroy this object
before we're ready. */
nsCOMPtr<nsIEventListenerManager> kungFuDeathGrip(this);
nsAutoString empty;
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
@ -745,7 +753,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_EXIT_SYNTH:
if (nsnull != mMouseListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMouseListeners && i<mMouseListeners->Count(); i++) {
@ -840,7 +848,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -852,7 +860,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_MOVE:
if (nsnull != mMouseMotionListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMouseMotionListeners && i<mMouseMotionListeners->Count(); i++) {
@ -886,7 +894,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -903,7 +911,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
#endif
if (nsnull != mCompositionListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent);
}
if (NS_OK == ret) {
for(int i=0; mTextListeners && i<mTextListeners->Count();i++) {
@ -951,7 +959,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -965,7 +973,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
#endif
if (nsnull != mTextListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent);
}
if (NS_OK == ret) {
for (int i=0; mTextListeners && i<mTextListeners->Count(); i++) {
@ -986,7 +994,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
correctSubType = PR_TRUE;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1000,7 +1008,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_KEY_PRESS:
if (nsnull != mKeyListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mKeyListeners && i<mKeyListeners->Count(); i++) {
@ -1052,7 +1060,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1065,7 +1073,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_BLUR_CONTENT:
if (nsnull != mFocusListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mFocusListeners && i<mFocusListeners->Count(); i++) {
@ -1108,7 +1116,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1124,7 +1132,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_FORM_INPUT:
if (nsnull != mFormListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mFormListeners && i<mFormListeners->Count(); i++) {
@ -1194,7 +1202,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1211,7 +1219,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
if (nsnull != mLoadListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mLoadListeners && i<mLoadListeners->Count(); i++) {
@ -1266,7 +1274,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1278,7 +1286,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_PAINT:
if (nsnull != mPaintListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mPaintListeners && i<mPaintListeners->Count(); i++) {
@ -1300,7 +1308,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
correctSubType = PR_TRUE;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1316,7 +1324,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_DRAGDROP_GESTURE:
if (nsnull != mDragListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
@ -1379,7 +1387,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE)
ret = HandleEventSubType(dragStruct, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(dragStruct, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1395,7 +1403,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_XUL_COMMAND_UPDATE:
if (nsnull != mMenuListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMenuListeners && i<mMenuListeners->Count(); i++) {
@ -1474,7 +1482,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1505,9 +1513,15 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent)
{
return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
if (!aEvent && !aEventType.EqualsIgnoreCase("MouseEvent") && !aEventType.EqualsIgnoreCase("KeyEvent") &&
!aEventType.EqualsIgnoreCase("HTMLEvent")) {
return NS_ERROR_FAILURE;
}
return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEventType, aEvent);
}
/**
@ -1753,6 +1767,13 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly)
return NS_OK;
}
nsresult nsEventListenerManager::SetListenerTarget(nsISupports* aTarget)
{
//WEAK reference, must be set back to nsnull when done
mTarget = aTarget;
return NS_OK;
}
// nsIDOMEventTarget interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListener(const nsString& aType,
@ -1774,6 +1795,38 @@ nsEventListenerManager::RemoveEventListener(const nsString& aType,
return RemoveEventListenerByType(aListener, aType, flags);
}
NS_IMETHODIMP
nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent)
{
//If we don't have a target set this doesn't work.
if (mTarget) {
nsCOMPtr<nsIContent> targetContent(do_QueryInterface(mTarget));
if (targetContent) {
nsCOMPtr<nsIDocument> document;
targetContent->GetDocument(*getter_AddRefs(document));
if (document) {
// Obtain a presentation context
PRInt32 count = document->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(document->GetShellAt(0));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(mTarget, aEvent);
}
}
}
}
return NS_ERROR_FAILURE;
}
// nsIDOMEventReceiver interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener,
@ -1806,7 +1859,7 @@ nsEventListenerManager::GetNewListenerManager(nsIEventListenerManager **aInstanc
NS_IMETHODIMP
nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult)

Просмотреть файл

@ -41,7 +41,7 @@ typedef struct {
} nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x20
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80
/*
* Event listener manager
@ -94,15 +94,19 @@ public:
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent);
virtual nsresult RemoveAllListeners(PRBool aScriptOnly);
virtual nsresult SetListenerTarget(nsISupports* aTarget);
static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType);
// nsIDOMEventTarget interface
@ -112,6 +116,7 @@ public:
NS_IMETHOD RemoveEventListener(const nsString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent);
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
@ -123,6 +128,7 @@ public:
protected:
nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags);
nsListenerStruct* FindJSEventListener(REFNSIID aIID);
@ -146,6 +152,8 @@ protected:
nsVoidArray* mMenuListeners;
nsCOMPtr<nsIPrincipal> mPrincipal;
PRBool mDestroyed;
nsISupports* mTarget; //WEAK
};

Просмотреть файл

@ -899,7 +899,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
{
if (sv) {
if (action == MOUSE_SCROLL_N_LINES)
sv->ScrollByLines(numLines);
sv->ScrollByLines(0, numLines);
else
sv->ScrollByPages((numLines > 0) ? 1 : -1);
ForceViewUpdate(focusView);
@ -996,7 +996,27 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
nsIViewManager* vm = nsnull;
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
// I'd use Composite here, but it doesn't always work.
// vm->Composite();
vm->ForceUpdate();
NS_RELEASE(vm);
}
}
}
break;
case NS_VK_LEFT:
case NS_VK_RIGHT:
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -2579,6 +2599,12 @@ void nsEventStateManager::ForceViewUpdate(nsIView* aView)
}
}
NS_IMETHODIMP
nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
{
nsresult rv;

Просмотреть файл

@ -99,6 +99,9 @@ public:
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor);
//Method for centralized distribution of new DOM events
NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent);
protected:
void UpdateCursor(nsIPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
void GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent);

Просмотреть файл

@ -389,7 +389,7 @@ nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext,
// Now a little special trickery because we are a label:
// We need to pass this event on to our child iff it is a focus,
// keypress/up/dn, mouseclick/dblclick/up/down.
if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT == aFlags) &&
if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT & aFlags) &&
((nsEventStatus_eIgnore == *aEventStatus) ||
(nsEventStatus_eConsumeNoDefault == *aEventStatus)) ) {
PRBool isFormElement = PR_FALSE;

Просмотреть файл

@ -134,7 +134,7 @@ nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
}
if (aIID.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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -131,7 +131,7 @@ nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
}
if (aIID.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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -137,7 +137,7 @@ nsXMLProcessingInstruction::QueryInterface(REFNSIID aIID, void** aInstancePtrRes
}
if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) {
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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -2060,6 +2060,28 @@ nsXULElement::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aL
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::DispatchEvent(nsIDOMEvent* aEvent)
{
// Obtain a presentation context
PRInt32 count = mDocument->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(mDocument->GetShellAt(0));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(NS_STATIC_CAST(nsIStyledContent*, this), aEvent);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -2090,7 +2112,7 @@ nsXULElement::GetNewListenerManager(nsIEventListenerManager **aResult)
NS_IMETHODIMP
nsXULElement::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
@ -3449,9 +3471,10 @@ nsXULElement::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);
// In order for the event to have a proper target for events that don't go through
// the presshell (onselect, oncommand, oncreate, ondestroy) we need to set our target
// ourselves. Also, key sets and menus don't have frames and therefore need their
@ -3474,7 +3497,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
NS_ERROR("Unable to instantiate a listener manager on this event.");
return ret;
}
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, aDOMEvent))) {
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) {
NS_ERROR("This event will fail without the ability to create the event early.");
return ret;
}
@ -3522,7 +3546,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
@ -3556,7 +3580,7 @@ nsXULElement::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) {

Просмотреть файл

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

Просмотреть файл

@ -47,7 +47,7 @@
#include "nsIDOMMouseEvent.h"
#include "nsITimer.h"
#include "nsIDOMNSUIEvent.h"
#include "nsIDOMEventTarget.h"
////////////////////////////////////////////////////////////////////////
@ -193,8 +193,10 @@ XULPopupListenerImpl::MouseDown(nsIDOMEvent* aMouseEvent)
}
// Get the node that was clicked on.
nsCOMPtr<nsIDOMEventTarget> target;
mouseEvent->GetTarget( getter_AddRefs( target ) );
nsCOMPtr<nsIDOMNode> targetNode;
mouseEvent->GetTarget( getter_AddRefs( targetNode ) );
if (target) targetNode = do_QueryInterface(target);
// Get the document with the popup.
nsCOMPtr<nsIDocument> document;
@ -279,9 +281,11 @@ XULPopupListenerImpl::MouseMove(nsIDOMEvent* aMouseEvent)
NS_NewTimer ( getter_AddRefs(mTooltipTimer) );
if ( mTooltipTimer ) {
nsCOMPtr<nsIDOMNode> eventTarget;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
nsCOMPtr<nsIDOMNode> eventTargetNode;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
mPossibleTooltipNode = eventTarget.get();
if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget);
mPossibleTooltipNode = eventTargetNode.get();
mTooltipTimer->Init(sTooltipCallback, this, 500, NS_PRIORITY_HIGH); // 500 ms delay
}
else
@ -317,10 +321,12 @@ XULPopupListenerImpl::MouseOut(nsIDOMEvent* aMouseEvent)
mPopupContent = nsnull; // release the popup
// clear out the tooltip node on the document
nsCOMPtr<nsIDOMNode> eventTarget;
nsCOMPtr<nsIDOMEventTarget> eventTarget;
nsCOMPtr<nsIDOMNode> eventTargetNode;
aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
if (eventTarget) eventTargetNode = do_QueryInterface(eventTarget);
nsCOMPtr<nsIDOMXULDocument> doc;
FindDocumentForNode ( eventTarget, getter_AddRefs(doc) );
FindDocumentForNode ( eventTargetNode, getter_AddRefs(doc) );
if ( doc )
doc->SetTooltipNode(nsnull);
}

Просмотреть файл

@ -47,6 +47,7 @@
#include "nsRDFCID.h"
#include "nsXULCommandDispatcher.h"
#include "prlog.h"
#include "nsIDOMEventTarget.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gLog;
@ -350,7 +351,7 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent)
if (mSuppressFocus)
return NS_OK;
nsCOMPtr<nsIDOMNode> t;
nsCOMPtr<nsIDOMEventTarget> t;
aEvent->GetTarget(getter_AddRefs(t));
#ifdef DEBUG_hyatt
@ -419,7 +420,7 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent)
if (mSuppressFocus)
return NS_OK;
nsCOMPtr<nsIDOMNode> t;
nsCOMPtr<nsIDOMEventTarget> t;
aEvent->GetTarget(getter_AddRefs(t));
#ifdef DEBUG_hyatt

Просмотреть файл

@ -76,6 +76,7 @@
#include "nsIFormControl.h"
#include "nsIHTMLContent.h"
#include "nsIElementFactory.h"
#include "nsIEventStateManager.h"
#include "nsIInputStream.h"
#include "nsILoadGroup.h"
#include "nsINameSpace.h"
@ -573,6 +574,9 @@ nsXULDocument::QueryInterface(REFNSIID iid, void** result)
else if (iid.Equals(NS_GET_IID(nsIDOMNSDocument))) {
*result = NS_STATIC_CAST(nsIDOMNSDocument*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOMDocumentEvent))) {
*result = NS_STATIC_CAST(nsIDOMDocumentEvent*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOMDocumentView))) {
*result = NS_STATIC_CAST(nsIDOMDocumentView*, this);
}
@ -1952,9 +1956,10 @@ nsXULDocument::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
@ -1965,7 +1970,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
@ -1974,7 +1979,7 @@ nsXULDocument::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;
@ -4002,6 +4007,52 @@ nsXULDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListener* a
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::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(NS_STATIC_CAST(nsIDocument*, this), aEvent);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::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;
}
NS_IMETHODIMP
nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -4031,7 +4082,7 @@ nsXULDocument::GetNewListenerManager(nsIEventListenerManager **aResult)
NS_IMETHODIMP
nsXULDocument::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
nsresult

Просмотреть файл

@ -67,6 +67,7 @@
#include "nsIStreamLoader.h"
#include "nsIBindingManager.h"
#include "nsINodeInfo.h"
#include "nsIDOMDocumentEvent.h"
class nsIAtom;
class nsIElementFactory;
@ -93,6 +94,7 @@ class nsXULDocument : public nsIDocument,
public nsIXULDocument,
public nsIStreamLoadableDocument,
public nsIDOMXULDocument,
public nsIDOMDocumentEvent,
public nsIDOMDocumentView,
public nsIDOMNSDocument,
public nsIDOMEventCapturer,
@ -335,10 +337,14 @@ public:
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent);
// nsIDOMDocument interface
NS_DECL_IDOMDOCUMENT
// nsIDOMDocumentEvent interface
NS_DECL_IDOMDOCUMENTEVENT
// nsIDOMDocumentView interface
NS_DECL_IDOMDOCUMENTVIEW

Просмотреть файл

@ -1926,7 +1926,7 @@ NS_IMETHODIMP nsDocShell::ScrollByLines(PRInt32 numLines)
NS_ENSURE_SUCCESS(GetRootScrollableView(getter_AddRefs(scrollView)),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(scrollView->ScrollByLines(numLines), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(scrollView->ScrollByLines(0, numLines), NS_ERROR_FAILURE);
return NS_OK;
}

Просмотреть файл

@ -32,7 +32,7 @@ class nsIDOMDocumentView;
#define NS_IDOMABSTRACTVIEW_IID \
{ 0xf51ebade, 0x8b1a, 0x11d3, \
{ 0xaa, 0xe7, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } }
{ 0xaa, 0xe7, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } }
class nsIDOMAbstractView : public nsISupports {
public:

Просмотреть файл

@ -27,6 +27,7 @@ nsIDOMComment.h
nsIDOMDOMImplementation.h
nsIDOMDocument.h
nsIDOMDocumentCSS.h
nsIDOMDocumentEvent.h
nsIDOMDocumentFragment.h
nsIDOMDocumentStyle.h
nsIDOMDocumentType.h

Просмотреть файл

@ -36,6 +36,7 @@ EXPORTS = \
nsIDOMDOMImplementation.h \
nsIDOMDocument.h \
nsIDOMDocumentCSS.h \
nsIDOMDocumentEvent.h \
nsIDOMDocumentFragment.h \
nsIDOMDocumentStyle.h \
nsIDOMDocumentType.h \

Просмотреть файл

@ -31,6 +31,7 @@ EXPORTS = \
nsIDOMDOMImplementation.h \
nsIDOMDocument.h \
nsIDOMDocumentCSS.h \
nsIDOMDocumentEvent.h \
nsIDOMDocumentFragment.h \
nsIDOMDocumentStyle.h \
nsIDOMDocumentType.h \

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMDocumentEvent_h__
#define nsIDOMDocumentEvent_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMEvent;
#define NS_IDOMDOCUMENTEVENT_IID \
{ 0x46b91d66, 0x28e2, 0x11d4, \
{ 0xab, 0x1e, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } }
class nsIDOMDocumentEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IDOMDOCUMENTEVENT_IID; return iid; }
NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn)=0;
};
#define NS_DECL_IDOMDOCUMENTEVENT \
NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn); \
#define NS_FORWARD_IDOMDOCUMENTEVENT(_to) \
NS_IMETHOD CreateEvent(const nsString& aEventType, nsIDOMEvent** aReturn) { return _to CreateEvent(aEventType, aReturn); } \
#endif // nsIDOMDocumentEvent_h__

Просмотреть файл

@ -28,7 +28,7 @@
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNode;
class nsIDOMEventTarget;
#define NS_IDOMEVENT_IID \
{ 0xa66b7b80, 0xff46, 0xbd97, \
@ -80,9 +80,9 @@ public:
NS_IMETHOD GetType(nsString& aType)=0;
NS_IMETHOD GetTarget(nsIDOMNode** aTarget)=0;
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget)=0;
NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode)=0;
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)=0;
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase)=0;
@ -90,6 +90,10 @@ public:
NS_IMETHOD GetCancelable(PRBool* aCancelable)=0;
NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp)=0;
NS_IMETHOD StopPropagation()=0;
NS_IMETHOD PreventBubble()=0;
NS_IMETHOD PreventCapture()=0;
@ -102,11 +106,13 @@ public:
#define NS_DECL_IDOMEVENT \
NS_IMETHOD GetType(nsString& aType); \
NS_IMETHOD GetTarget(nsIDOMNode** aTarget); \
NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode); \
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget); \
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget); \
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase); \
NS_IMETHOD GetBubbles(PRBool* aBubbles); \
NS_IMETHOD GetCancelable(PRBool* aCancelable); \
NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp); \
NS_IMETHOD StopPropagation(); \
NS_IMETHOD PreventBubble(); \
NS_IMETHOD PreventCapture(); \
NS_IMETHOD PreventDefault(); \
@ -116,11 +122,13 @@ public:
#define NS_FORWARD_IDOMEVENT(_to) \
NS_IMETHOD GetType(nsString& aType) { return _to GetType(aType); } \
NS_IMETHOD GetTarget(nsIDOMNode** aTarget) { return _to GetTarget(aTarget); } \
NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode) { return _to GetCurrentNode(aCurrentNode); } \
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget) { return _to GetTarget(aTarget); } \
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget) { return _to GetCurrentTarget(aCurrentTarget); } \
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase) { return _to GetEventPhase(aEventPhase); } \
NS_IMETHOD GetBubbles(PRBool* aBubbles) { return _to GetBubbles(aBubbles); } \
NS_IMETHOD GetCancelable(PRBool* aCancelable) { return _to GetCancelable(aCancelable); } \
NS_IMETHOD GetTimeStamp(PRUint64* aTimeStamp) { return _to GetTimeStamp(aTimeStamp); } \
NS_IMETHOD StopPropagation() { return _to StopPropagation(); } \
NS_IMETHOD PreventBubble() { return _to PreventBubble(); } \
NS_IMETHOD PreventCapture() { return _to PreventCapture(); } \
NS_IMETHOD PreventDefault() { return _to PreventDefault(); } \

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsIScriptContext.h"
class nsIDOMEventListener;
class nsIDOMEvent;
#define NS_IDOMEVENTTARGET_IID \
{ 0x1c773b30, 0xd1cf, 0x11d2, \
@ -41,18 +42,22 @@ public:
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)=0;
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture)=0;
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt)=0;
};
#define NS_DECL_IDOMEVENTTARGET \
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); \
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture); \
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt); \
#define NS_FORWARD_IDOMEVENTTARGET(_to) \
NS_IMETHOD AddEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) { return _to AddEventListener(aType, aListener, aUseCapture); } \
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener, PRBool aUseCapture) { return _to RemoveEventListener(aType, aListener, aUseCapture); } \
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvt) { return _to DispatchEvent(aEvt); } \
#endif // nsIDOMEventTarget_h__

Просмотреть файл

@ -29,7 +29,7 @@
#include "nsIScriptContext.h"
#include "nsIDOMUIEvent.h"
class nsIDOMNode;
class nsIDOMEventTarget;
#define NS_IDOMMOUSEEVENT_IID \
{ 0xff751edc, 0x8b02, 0xaae7, \
@ -57,9 +57,7 @@ public:
NS_IMETHOD GetButton(PRUint16* aButton)=0;
NS_IMETHOD GetClickCount(PRUint16* aClickCount)=0;
NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode)=0;
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)=0;
NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg)=0;
};
@ -75,8 +73,7 @@ public:
NS_IMETHOD GetShiftKey(PRBool* aShiftKey); \
NS_IMETHOD GetMetaKey(PRBool* aMetaKey); \
NS_IMETHOD GetButton(PRUint16* aButton); \
NS_IMETHOD GetClickCount(PRUint16* aClickCount); \
NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode); \
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget); \
NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg); \
@ -91,8 +88,7 @@ public:
NS_IMETHOD GetShiftKey(PRBool* aShiftKey) { return _to GetShiftKey(aShiftKey); } \
NS_IMETHOD GetMetaKey(PRBool* aMetaKey) { return _to GetMetaKey(aMetaKey); } \
NS_IMETHOD GetButton(PRUint16* aButton) { return _to GetButton(aButton); } \
NS_IMETHOD GetClickCount(PRUint16* aClickCount) { return _to GetClickCount(aClickCount); } \
NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode) { return _to GetRelatedNode(aRelatedNode); } \
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) { return _to GetRelatedTarget(aRelatedTarget); } \
NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg) { return _to InitMouseEvent(aTypeArg, aCtrlKeyArg, aAltKeyArg, aShiftKeyArg, aMetaKeyArg, aScreenXArg, aScreenYArg, aClientXArg, aClientYArg, aButtonArg, aDetailArg); } \

Просмотреть файл

@ -91,6 +91,7 @@ interface EventTarget {
void addEventListener(in DOMString type, in function EventListener listener, in boolean useCapture);
void removeEventListener(in DOMString type, in function EventListener listener, in boolean useCapture);
void dispatchEvent(in Event evt);
};
// Introduced in DOM Level 2:

Просмотреть файл

@ -64,6 +64,14 @@ interface DocumentCSS : DocumentStyle {
in DOMString pseudoElt);
};
// Introduced in DOM Level 2:
interface DocumentEvent {
/* IID: { 0x46b91d66, 0x28e2, 0x11d4, \
{ 0xab, 0x1e, 0x00, 0x10, 0x83, 0x01, 0x23, 0xb4 } } */
Event createEvent(in DOMString eventType);
};
interface NSDocument {
/* IID: { 0xa6cf90cd, 0x15b3, 0x11d2, \
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } */

Просмотреть файл

@ -62,4 +62,5 @@
void addEventListener(in DOMString type, in function EventListener listener, in boolean useCapture);
void removeEventListener(in DOMString type, in function EventListener listener, in boolean useCapture);
};
void dispatchEvent(in Event evt);
};

Просмотреть файл

@ -45,13 +45,15 @@
const int META_MASK = 0x00000008;
readonly attribute wstring type;
readonly attribute Node target;
readonly attribute Node currentNode;
readonly attribute unsigned short eventPhase;
readonly attribute boolean bubbles;
readonly attribute boolean cancelable;
readonly attribute wstring type;
readonly attribute EventTarget target;
readonly attribute EventTarget currentTarget;
readonly attribute unsigned short eventPhase;
readonly attribute boolean bubbles;
readonly attribute boolean cancelable;
readonly attribute unsigned longlong timeStamp;
void stopPropagation();
void preventBubble();
void preventCapture();
void preventDefault();

Просмотреть файл

@ -159,9 +159,8 @@
noscript readonly attribute boolean shiftKey;
noscript readonly attribute boolean metaKey;
readonly attribute unsigned short button;
readonly attribute unsigned short clickCount;
readonly attribute Node relatedNode;
readonly attribute unsigned short button;
readonly attribute EventTarget relatedTarget;
void initMouseEvent(in DOMString typeArg,
in boolean ctrlKeyArg,

Просмотреть файл

@ -248,6 +248,7 @@ enum nsDOMProp {
NS_DOM_PROP_DOCUMENT_IMPLEMENTATION,
NS_DOM_PROP_DOCUMENT_IMPORTNODE,
NS_DOM_PROP_DOCUMENTCSS_GETOVERRIDESTYLE,
NS_DOM_PROP_DOCUMENTEVENT_CREATEEVENT,
NS_DOM_PROP_DOCUMENTSTYLE_STYLESHEETS,
NS_DOM_PROP_DOCUMENTTYPE_ENTITIES,
NS_DOM_PROP_DOCUMENTTYPE_INTERNALSUBSET,
@ -285,15 +286,18 @@ enum nsDOMProp {
NS_DOM_PROP_ENTITY_SYSTEMID,
NS_DOM_PROP_EVENT_BUBBLES,
NS_DOM_PROP_EVENT_CANCELABLE,
NS_DOM_PROP_EVENT_CURRENTNODE,
NS_DOM_PROP_EVENT_CURRENTTARGET,
NS_DOM_PROP_EVENT_EVENTPHASE,
NS_DOM_PROP_EVENT_INITEVENT,
NS_DOM_PROP_EVENT_PREVENTBUBBLE,
NS_DOM_PROP_EVENT_PREVENTCAPTURE,
NS_DOM_PROP_EVENT_PREVENTDEFAULT,
NS_DOM_PROP_EVENT_STOPPROPAGATION,
NS_DOM_PROP_EVENT_TARGET,
NS_DOM_PROP_EVENT_TIMESTAMP,
NS_DOM_PROP_EVENT_TYPE,
NS_DOM_PROP_EVENTTARGET_ADDEVENTLISTENER,
NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT,
NS_DOM_PROP_EVENTTARGET_REMOVEEVENTLISTENER,
NS_DOM_PROP_HISTORY_BACK,
NS_DOM_PROP_HISTORY_CURRENT,
@ -685,11 +689,10 @@ enum nsDOMProp {
NS_DOM_PROP_MIMETYPEARRAY_LENGTH,
NS_DOM_PROP_MIMETYPEARRAY_NAMEDITEM,
NS_DOM_PROP_MOUSEEVENT_BUTTON,
NS_DOM_PROP_MOUSEEVENT_CLICKCOUNT,
NS_DOM_PROP_MOUSEEVENT_CLIENTX,
NS_DOM_PROP_MOUSEEVENT_CLIENTY,
NS_DOM_PROP_MOUSEEVENT_INITMOUSEEVENT,
NS_DOM_PROP_MOUSEEVENT_RELATEDNODE,
NS_DOM_PROP_MOUSEEVENT_RELATEDTARGET,
NS_DOM_PROP_MOUSEEVENT_SCREENX,
NS_DOM_PROP_MOUSEEVENT_SCREENY,
NS_DOM_PROP_NAMEDNODEMAP_GETNAMEDITEM,

Просмотреть файл

@ -247,6 +247,7 @@
"document.implementation", \
"document.importnode", \
"documentcss.getoverridestyle", \
"documentevent.createevent", \
"documentstyle.stylesheets", \
"documenttype.entities", \
"documenttype.internalsubset", \
@ -284,15 +285,18 @@
"entity.systemid", \
"event.bubbles", \
"event.cancelable", \
"event.currentnode", \
"event.currenttarget", \
"event.eventphase", \
"event.initevent", \
"event.preventbubble", \
"event.preventcapture", \
"event.preventdefault", \
"event.stoppropagation", \
"event.target", \
"event.timestamp", \
"event.type", \
"eventtarget.addeventlistener", \
"eventtarget.dispatchevent", \
"eventtarget.removeeventlistener", \
"history.back", \
"history.current", \
@ -684,11 +688,10 @@
"mimetypearray.length", \
"mimetypearray.nameditem", \
"mouseevent.button", \
"mouseevent.clickcount", \
"mouseevent.clientx", \
"mouseevent.clienty", \
"mouseevent.initmouseevent", \
"mouseevent.relatednode", \
"mouseevent.relatedtarget", \
"mouseevent.screenx", \
"mouseevent.screeny", \
"namednodemap.getnameditem", \

Просмотреть файл

@ -376,10 +376,11 @@ NS_IMETHODIMP GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
nsCOMPtr<nsIChromeEventHandler> kungFuDeathGrip1(mChromeEventHandler);
nsCOMPtr<nsIScriptContext> kungFuDeathGrip2(mContext);
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
@ -391,11 +392,11 @@ NS_IMETHODIMP GlobalWindowImpl::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;
}
@ -415,7 +416,7 @@ NS_IMETHODIMP GlobalWindowImpl::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(*aDOMEvent)
@ -2147,6 +2148,31 @@ NS_IMETHODIMP GlobalWindowImpl::RemoveEventListener(const nsString& aType,
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP GlobalWindowImpl::DispatchEvent(nsIDOMEvent* aEvent)
{
if (mDocument) {
nsCOMPtr<nsIDocument> idoc(do_QueryInterface(mDocument));
if (idoc) {
// Obtain a presentation context
PRInt32 count = idoc->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(idoc->GetShellAt(0));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(NS_STATIC_CAST(nsIScriptGlobalObject*, this), aEvent);
}
}
}
return NS_ERROR_FAILURE;
}
//*****************************************************************************
// GlobalWindowImpl::nsIDOMEventReceiver
//*****************************************************************************
@ -2203,7 +2229,7 @@ NS_IMETHODIMP GlobalWindowImpl::GetNewListenerManager(nsIEventListenerManager **
NS_IMETHODIMP GlobalWindowImpl::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
//*****************************************************************************

Просмотреть файл

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

Просмотреть файл

@ -44,8 +44,8 @@
#include "nsIDOMAbstractView.h"
#include "nsIDOMScreen.h"
#include "nsIDOMHistory.h"
#include "nsIDOMWindowCollection.h"
#include "nsIDOMEvent.h"
#include "nsIDOMWindowCollection.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
#include "nsISidebar.h"
@ -69,8 +69,8 @@ static NS_DEFINE_IID(kIBarPropIID, NS_IDOMBARPROP_IID);
static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID);
static NS_DEFINE_IID(kIScreenIID, NS_IDOMSCREEN_IID);
static NS_DEFINE_IID(kIHistoryIID, NS_IDOMHISTORY_IID);
static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID);
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIWindowCollectionIID, NS_IDOMWINDOWCOLLECTION_IID);
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_IID(kISidebarIID, NS_ISIDEBAR_IID);
@ -2610,6 +2610,58 @@ EventTargetRemoveEventListener(JSContext *cx, JSObject *obj, uintN argc, jsval *
}
//
// Native method DispatchEvent
//
PR_STATIC_CALLBACK(JSBool)
EventTargetDispatchEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMWindow *privateThis = (nsIDOMWindow*)nsJSUtils::nsGetNativeThis(cx, obj);
nsCOMPtr<nsIDOMEventTarget> nativeThis;
nsresult result = NS_OK;
if (NS_OK != privateThis->QueryInterface(kIEventTargetIID, getter_AddRefs(nativeThis))) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
}
nsCOMPtr<nsIDOMEvent> b0;
// If there's no private data, this must be the prototype, so ignore
if (!nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
kIEventIID,
NS_ConvertASCIItoUCS2("Event"),
cx,
argv[0])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->DispatchEvent(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method GetComputedStyle
//
@ -2775,6 +2827,7 @@ static JSFunctionSpec WindowMethods[] =
{"getSelection", WindowGetSelection, 0},
{"addEventListener", EventTargetAddEventListener, 3},
{"removeEventListener", EventTargetRemoveEventListener, 3},
{"dispatchEvent", EventTargetDispatchEvent, 1},
{"getComputedStyle", ViewCSSGetComputedStyle, 2},
{0}
};

Просмотреть файл

@ -44,6 +44,8 @@
#include "nsIDOMAbstractView.h"
#include "nsIDOMNode.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOMEvent.h"
#include "nsIDOMText.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMDocumentType.h"
@ -70,6 +72,8 @@ static NS_DEFINE_IID(kIProcessingInstructionIID, NS_IDOMPROCESSINGINSTRUCTION_II
static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kICDATASectionIID, NS_IDOMCDATASECTION_IID);
static NS_DEFINE_IID(kIDocumentEventIID, NS_IDOMDOCUMENTEVENT_IID);
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kITextIID, NS_IDOMTEXT_IID);
static NS_DEFINE_IID(kIDOMImplementationIID, NS_IDOMDOMIMPLEMENTATION_IID);
static NS_DEFINE_IID(kIDocumentTypeIID, NS_IDOMDOCUMENTTYPE_IID);
@ -985,6 +989,53 @@ DocumentCSSGetOverrideStyle(JSContext *cx, JSObject *obj, uintN argc, jsval *arg
}
//
// Native method CreateEvent
//
PR_STATIC_CALLBACK(JSBool)
DocumentEventCreateEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *privateThis = (nsIDOMDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
nsCOMPtr<nsIDOMDocumentEvent> nativeThis;
nsresult result = NS_OK;
if (NS_OK != privateThis->QueryInterface(kIDocumentEventIID, getter_AddRefs(nativeThis))) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
}
nsIDOMEvent* nativeRet;
nsAutoString b0;
// If there's no private data, this must be the prototype, so ignore
if (!nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTEVENT_CREATEEVENT, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
result = nativeThis->CreateEvent(b0, &nativeRet);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval);
}
return JS_TRUE;
}
//
// Native method CreateElementWithNameSpace
//
@ -1180,6 +1231,7 @@ static JSFunctionSpec DocumentMethods[] =
{"getElementsByTagNameNS", DocumentGetElementsByTagNameNS, 2},
{"getElementById", DocumentGetElementById, 1},
{"getOverrideStyle", DocumentCSSGetOverrideStyle, 2},
{"createEvent", DocumentEventCreateEvent, 1},
{"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2},
{"createRange", NSDocumentCreateRange, 0},
{"load", NSDocumentLoad, 2},

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMNode.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMNodeList.h"
@ -49,6 +50,7 @@ static NS_DEFINE_IID(kIDocumentIID, NS_IDOMDOCUMENT_IID);
static NS_DEFINE_IID(kINamedNodeMapIID, NS_IDOMNAMEDNODEMAP_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
@ -850,6 +852,58 @@ EventTargetRemoveEventListener(JSContext *cx, JSObject *obj, uintN argc, jsval *
}
//
// Native method DispatchEvent
//
PR_STATIC_CALLBACK(JSBool)
EventTargetDispatchEvent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNode *privateThis = (nsIDOMNode*)nsJSUtils::nsGetNativeThis(cx, obj);
nsCOMPtr<nsIDOMEventTarget> nativeThis;
nsresult result = NS_OK;
if (NS_OK != privateThis->QueryInterface(kIEventTargetIID, getter_AddRefs(nativeThis))) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
}
nsCOMPtr<nsIDOMEvent> b0;
// If there's no private data, this must be the prototype, so ignore
if (!nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENTTARGET_DISPATCHEVENT, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0),
kIEventIID,
NS_ConvertASCIItoUCS2("Event"),
cx,
argv[0])) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR);
}
result = nativeThis->DispatchEvent(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for Node
@ -908,6 +962,7 @@ static JSFunctionSpec NodeMethods[] =
{"supports", NodeSupports, 2},
{"addEventListener", EventTargetAddEventListener, 3},
{"removeEventListener", EventTargetRemoveEventListener, 3},
{"dispatchEvent", EventTargetDispatchEvent, 1},
{0}
};

Просмотреть файл

@ -34,15 +34,15 @@
#include "nsCOMPtr.h"
#include "nsDOMPropEnums.h"
#include "nsString.h"
#include "nsIDOMNode.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
//
// Event property ids
@ -50,10 +50,11 @@ static NS_DEFINE_IID(kIEventIID, NS_IDOMEVENT_IID);
enum Event_slots {
EVENT_TYPE = -1,
EVENT_TARGET = -2,
EVENT_CURRENTNODE = -3,
EVENT_CURRENTTARGET = -3,
EVENT_EVENTPHASE = -4,
EVENT_BUBBLES = -5,
EVENT_CANCELABLE = -6
EVENT_CANCELABLE = -6,
EVENT_TIMESTAMP = -7
};
/***********************************************************************/
@ -92,7 +93,7 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_TARGET, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMNode* prop;
nsIDOMEventTarget* prop;
rv = a->GetTarget(&prop);
if (NS_SUCCEEDED(rv)) {
// get the js object
@ -101,12 +102,12 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case EVENT_CURRENTNODE:
case EVENT_CURRENTTARGET:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_CURRENTNODE, PR_FALSE);
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_CURRENTTARGET, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMNode* prop;
rv = a->GetCurrentNode(&prop);
nsIDOMEventTarget* prop;
rv = a->GetCurrentTarget(&prop);
if (NS_SUCCEEDED(rv)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
@ -150,6 +151,18 @@ GetEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case EVENT_TIMESTAMP:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_TIMESTAMP, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRUint64 prop;
rv = a->GetTimeStamp(&prop);
if (NS_SUCCEEDED(rv)) {
*vp = INT_TO_JSVAL(prop);
}
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -228,6 +241,41 @@ ResolveEvent(JSContext *cx, JSObject *obj, jsval id)
}
//
// Native method StopPropagation
//
PR_STATIC_CALLBACK(JSBool)
EventStopPropagation(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMEvent *nativeThis = (nsIDOMEvent*)nsJSUtils::nsGetNativeThis(cx, obj);
nsresult result = NS_OK;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_EVENT_STOPPROPAGATION, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
result = nativeThis->StopPropagation();
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method PreventBubble
//
@ -409,10 +457,11 @@ static JSPropertySpec EventProperties[] =
{
{"type", EVENT_TYPE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"target", EVENT_TARGET, JSPROP_ENUMERATE | JSPROP_READONLY},
{"currentNode", EVENT_CURRENTNODE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"currentTarget", EVENT_CURRENTTARGET, JSPROP_ENUMERATE | JSPROP_READONLY},
{"eventPhase", EVENT_EVENTPHASE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"bubbles", EVENT_BUBBLES, JSPROP_ENUMERATE | JSPROP_READONLY},
{"cancelable", EVENT_CANCELABLE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"timeStamp", EVENT_TIMESTAMP, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};
@ -422,6 +471,7 @@ static JSPropertySpec EventProperties[] =
//
static JSFunctionSpec EventMethods[] =
{
{"stopPropagation", EventStopPropagation, 0},
{"preventBubble", EventPreventBubble, 0},
{"preventCapture", EventPreventCapture, 0},
{"preventDefault", EventPreventDefault, 0},

Просмотреть файл

@ -37,7 +37,7 @@
#include "nsIDOMMouseEvent.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMAbstractView.h"
#include "nsIDOMNode.h"
#include "nsIDOMEventTarget.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -46,7 +46,7 @@ static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIMouseEventIID, NS_IDOMMOUSEEVENT_IID);
static NS_DEFINE_IID(kIKeyEventIID, NS_IDOMKEYEVENT_IID);
static NS_DEFINE_IID(kIAbstractViewIID, NS_IDOMABSTRACTVIEW_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIEventTargetIID, NS_IDOMEVENTTARGET_IID);
//
// KeyEvent property ids
@ -63,8 +63,7 @@ enum KeyEvent_slots {
MOUSEEVENT_CLIENTX = -9,
MOUSEEVENT_CLIENTY = -10,
MOUSEEVENT_BUTTON = -11,
MOUSEEVENT_CLICKCOUNT = -12,
MOUSEEVENT_RELATEDNODE = -13
MOUSEEVENT_RELATEDTARGET = -12
};
/***********************************************************************/
@ -254,33 +253,14 @@ GetKeyEventProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case MOUSEEVENT_CLICKCOUNT:
case MOUSEEVENT_RELATEDTARGET:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_CLICKCOUNT, PR_FALSE);
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_RELATEDTARGET, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
PRUint16 prop;
nsIDOMEventTarget* prop;
nsIDOMMouseEvent* b;
if (NS_OK == a->QueryInterface(kIMouseEventIID, (void **)&b)) {
rv = b->GetClickCount(&prop);
if(NS_SUCCEEDED(rv)) {
*vp = INT_TO_JSVAL(prop);
}
NS_RELEASE(b);
}
else {
rv = NS_ERROR_DOM_WRONG_TYPE_ERR;
}
}
break;
}
case MOUSEEVENT_RELATEDNODE:
{
rv = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_MOUSEEVENT_RELATEDNODE, PR_FALSE);
if (NS_SUCCEEDED(rv)) {
nsIDOMNode* prop;
nsIDOMMouseEvent* b;
if (NS_OK == a->QueryInterface(kIMouseEventIID, (void **)&b)) {
rv = b->GetRelatedNode(&prop);
rv = b->GetRelatedTarget(&prop);
if(NS_SUCCEEDED(rv)) {
// get the js object
nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, obj, vp);
@ -574,8 +554,7 @@ static JSPropertySpec KeyEventProperties[] =
{"clientX", MOUSEEVENT_CLIENTX, JSPROP_ENUMERATE | JSPROP_READONLY},
{"clientY", MOUSEEVENT_CLIENTY, JSPROP_ENUMERATE | JSPROP_READONLY},
{"button", MOUSEEVENT_BUTTON, JSPROP_ENUMERATE | JSPROP_READONLY},
{"clickCount", MOUSEEVENT_CLICKCOUNT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"relatedNode", MOUSEEVENT_RELATEDNODE, JSPROP_ENUMERATE | JSPROP_READONLY},
{"relatedTarget", MOUSEEVENT_RELATEDTARGET, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};

Просмотреть файл

@ -125,12 +125,18 @@ FileGen::GetVariableTypeForMethodLocal(char *aBuffer, IdlVariable &aVariable)
case TYPE_LONG:
strcpy(aBuffer, "PRInt32");
break;
case TYPE_LONG_LONG:
strcpy(aBuffer, "PRInt64");
break;
case TYPE_SHORT:
strcpy(aBuffer, "PRInt32");
break;
case TYPE_ULONG:
strcpy(aBuffer, "PRUint32");
break;
case TYPE_ULONG_LONG:
strcpy(aBuffer, "PRUint64");
break;
case TYPE_USHORT:
strcpy(aBuffer, "PRUint32");
break;
@ -177,12 +183,18 @@ FileGen::GetVariableTypeForLocal(char *aBuffer, IdlVariable &aVariable)
case TYPE_LONG:
strcpy(aBuffer, "PRInt32");
break;
case TYPE_LONG_LONG:
strcpy(aBuffer, "PRInt64");
break;
case TYPE_SHORT:
strcpy(aBuffer, "PRInt16");
break;
case TYPE_ULONG:
strcpy(aBuffer, "PRUint32");
break;
case TYPE_ULONG_LONG:
strcpy(aBuffer, "PRUint64");
break;
case TYPE_USHORT:
strcpy(aBuffer, "PRUint16");
break;
@ -229,12 +241,18 @@ FileGen::GetVariableTypeForParameter(char *aBuffer, IdlVariable &aVariable)
case TYPE_LONG:
strcpy(aBuffer, "PRInt32");
break;
case TYPE_LONG_LONG:
strcpy(aBuffer, "PRInt64");
break;
case TYPE_SHORT:
strcpy(aBuffer, "PRInt16");
break;
case TYPE_ULONG:
strcpy(aBuffer, "PRUint32");
break;
case TYPE_ULONG_LONG:
strcpy(aBuffer, "PRUint64");
break;
case TYPE_USHORT:
strcpy(aBuffer, "PRUint16");
break;

Просмотреть файл

@ -1,444 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "IdlInterface.h"
#include "nsVoidArray.h"
#include "IdlEnum.h"
#include "IdlAttribute.h"
#include "IdlFunction.h"
#include <string.h>
#include <ostream.h>
ostream& operator<<(ostream &s, IdlInterface &aInterface)
{
int i;
// write the interface header
s << "interface " << aInterface.GetName();
long count = aInterface.BaseClassCount();
if (count) {
s << " : ";
for (int i = 0; i < count - 1; i++) {
s << aInterface.GetBaseClassAt(i) << ", ";
}
s << aInterface.GetBaseClassAt(count - 1);
}
// write the interface body
s << " { \n";
// all the consts
for (i = 0; i < aInterface.ConstCount(); i++) {
IdlVariable *constObj = aInterface.GetConstAt(i);
char type[128];
constObj->GetTypeAsString(type, 128);
s << " const " << type << " " << constObj->GetName() << " = ";
Type constType = constObj->GetType();
if (constType == TYPE_INT ||
constType == TYPE_LONG ||
constType == TYPE_SHORT ||
constType == TYPE_UINT ||
constType == TYPE_ULONG ||
constType == TYPE_USHORT) {
s << constObj->GetLongValue() << ";\n";
}
//XXX finish the other cases (string, double,...)
}
// all the enums
for (i = 0; i < aInterface.EnumCount(); i++) {
s << *(aInterface.GetEnumAt(i));
}
// all the attribute
for (i = 0; i < aInterface.AttributeCount(); i++) {
s << " " << *(aInterface.GetAttributeAt(i)) << "\n";
}
// all the functions
for (i = 0; i < aInterface.FunctionCount(); i++) {
s << " " << *(aInterface.GetFunctionAt(i)) << "\n";
}
return s << "}; \n";
}
IdlInterface::IdlInterface()
{
mIIDs = (nsVoidArray *)0;
mBaseClasses = (nsVoidArray*)0;
mAttributes = (nsVoidArray*)0;
mFunctions = (nsVoidArray*)0;
mEnums = (nsVoidArray*)0;
mStructs = (nsVoidArray*)0;
mUnions = (nsVoidArray*)0;
mConsts = (nsVoidArray*)0;
mTypedefs = (nsVoidArray*)0;
mExceptions = (nsVoidArray*)0;
}
IdlInterface::~IdlInterface()
{
if (mIIDs) {
for (int i = 0; i < mIIDs->Count(); i++) {
char *iid = (char*)mIIDs->ElementAt(i);
delete [] iid;
}
}
if (mBaseClasses) {
for (int i = 0; i < mBaseClasses->Count(); i++) {
char *baseClass = (char*)mBaseClasses->ElementAt(i);
delete[] baseClass;
}
}
if (mAttributes) {
for (int i = 0; i < mAttributes->Count(); i++) {
IdlAttribute *attrObj = (IdlAttribute*)mAttributes->ElementAt(i);
delete attrObj;
}
}
if (mFunctions) {
for (int i = 0; i < mFunctions->Count(); i++) {
IdlFunction *funcObj = (IdlFunction*)mFunctions->ElementAt(i);
delete funcObj;
}
}
if (mEnums) {
for (int i = 0; i < mEnums->Count(); i++) {
IdlEnum *enumObj = (IdlEnum*)mEnums->ElementAt(i);
delete enumObj;
}
}
if (mStructs) {
for (int i = 0; i < mStructs->Count(); i++) {
IdlStruct *structObj = (IdlStruct*)mStructs->ElementAt(i);
delete structObj;
}
}
if (mUnions) {
for (int i = 0; i < mUnions->Count(); i++) {
IdlUnion *unionObj = (IdlUnion*)mUnions->ElementAt(i);
delete unionObj;
}
}
if (mConsts) {
for (int i = 0; i < mConsts->Count(); i++) {
IdlVariable *constObj = (IdlVariable*)mConsts->ElementAt(i);
delete constObj;
}
}
if (mTypedefs) {
for (int i = 0; i < mTypedefs->Count(); i++) {
IdlTypedef *typedefObj = (IdlTypedef*)mTypedefs->ElementAt(i);
delete typedefObj;
}
}
if (mExceptions) {
for (int i = 0; i < mExceptions->Count(); i++) {
IdlException *exceptionObj = (IdlException*)mExceptions->ElementAt(i);
delete exceptionObj;
}
}
}
void IdlInterface::AddIID(char *aIID)
{
if (aIID) {
char *iid = new char[strlen(aIID) + 1];
strcpy(iid, aIID);
if (!mIIDs) {
mIIDs = new nsVoidArray();
}
mIIDs->AppendElement((void*)iid);
}
}
long IdlInterface::IIDCount()
{
if (mIIDs) {
return mIIDs->Count();
}
return 0;
}
char* IdlInterface::GetIIDAt(long aIndex)
{
char *iid = (char*)0;
if (mIIDs) {
iid = (char*)mIIDs->ElementAt(aIndex);
}
return iid;
}
void IdlInterface::InheritsFrom(char *aBase)
{
if (aBase) {
char *baseName = new char[strlen(aBase) + 1];
strcpy(baseName, aBase);
if (!mBaseClasses) {
mBaseClasses = new nsVoidArray();
}
mBaseClasses->AppendElement((void*)baseName);
}
}
long IdlInterface::BaseClassCount()
{
if (mBaseClasses) {
return mBaseClasses->Count();
}
return 0;
}
char* IdlInterface::GetBaseClassAt(long aIndex)
{
char *base = (char*)0;
if (mBaseClasses) {
base = (char*)mBaseClasses->ElementAt(aIndex);
}
return base;
}
void IdlInterface::AddTypedef(IdlTypedef *aTypedef)
{
if (aTypedef) {
if (!mTypedefs) {
mTypedefs = new nsVoidArray();
}
mTypedefs->AppendElement((void*)aTypedef);
}
}
long IdlInterface::TypedefCount()
{
if (mTypedefs) {
return mTypedefs->Count();
}
return 0;
}
IdlTypedef* IdlInterface::GetTypedefAt(long aIndex)
{
IdlTypedef *typedefObj = (IdlTypedef*)0;
if (mTypedefs) {
typedefObj = (IdlTypedef*)mTypedefs->ElementAt(aIndex);
}
return typedefObj;
}
void IdlInterface::AddStruct(IdlStruct *aStruct)
{
if (aStruct) {
if (!mStructs) {
mStructs = new nsVoidArray();
}
mStructs->AppendElement((void*)aStruct);
}
}
long IdlInterface::StructCount()
{
if (mStructs) {
return mStructs->Count();
}
return 0;
}
IdlStruct* IdlInterface::GetStructAt(long aIndex)
{
IdlStruct *structObj = (IdlStruct*)0;
if (mStructs) {
structObj = (IdlStruct*)mStructs->ElementAt(aIndex);
}
return structObj;
}
void IdlInterface::AddEnum(IdlEnum *aEnum)
{
if (aEnum) {
if (!mEnums) {
mEnums = new nsVoidArray();
}
mEnums->AppendElement((void*)aEnum);
}
}
long IdlInterface::EnumCount()
{
if (mEnums) {
return mEnums->Count();
}
return 0;
}
IdlEnum* IdlInterface::GetEnumAt(long aIndex)
{
IdlEnum *enumObj = (IdlEnum*)0;
if (mEnums) {
enumObj = (IdlEnum*)mEnums->ElementAt(aIndex);
}
return enumObj;
}
void IdlInterface::AddUnion(IdlUnion *aUnion)
{
if (aUnion) {
if (!mUnions) {
mUnions = new nsVoidArray();
}
mUnions->AppendElement((void*)aUnion);
}
}
long IdlInterface::UnionCount()
{
if (mUnions) {
return mUnions->Count();
}
return 0;
}
IdlUnion* IdlInterface::GetUnionAt(long aIndex)
{
IdlUnion *unionObj = (IdlUnion*)0;
if (mUnions) {
unionObj = (IdlUnion*)mUnions->ElementAt(aIndex);
}
return unionObj;
}
void IdlInterface::AddConst(IdlVariable *aConst)
{
if (aConst) {
if (!mConsts) {
mConsts = new nsVoidArray();
}
mConsts->AppendElement((void*)aConst);
}
}
long IdlInterface::ConstCount()
{
if (mConsts) {
return mConsts->Count();
}
return 0;
}
IdlVariable* IdlInterface::GetConstAt(long aIndex)
{
IdlVariable *constObj = (IdlVariable*)0;
if (mConsts) {
constObj = (IdlVariable*)mConsts->ElementAt(aIndex);
}
return constObj;
}
void IdlInterface::AddException(IdlException *aException)
{
if (aException) {
if (!mExceptions) {
mExceptions = new nsVoidArray();
}
mExceptions->AppendElement((void*)aException);
}
}
long IdlInterface::ExceptionCount()
{
if (mExceptions) {
return mExceptions->Count();
}
return 0;
}
IdlException* IdlInterface::GetExceptionAt(long aIndex)
{
IdlException *excObj = (IdlException*)0;
if (mExceptions) {
excObj = (IdlException*)mExceptions->ElementAt(aIndex);
}
return excObj;
}
void IdlInterface::AddAttribute(IdlAttribute *aAttribute)
{
if (aAttribute) {
if (!mAttributes) {
mAttributes = new nsVoidArray();
}
mAttributes->AppendElement((void*)aAttribute);
}
}
long IdlInterface::AttributeCount()
{
if (mAttributes) {
return mAttributes->Count();
}
return 0;
}
IdlAttribute* IdlInterface::GetAttributeAt(long aIndex)
{
IdlAttribute *attrObj = (IdlAttribute*)0;
if (mAttributes) {
attrObj = (IdlAttribute*)mAttributes->ElementAt(aIndex);
}
return attrObj;
}
void IdlInterface::AddFunction(IdlFunction *aFunction)
{
if (aFunction) {
if (!mFunctions) {
mFunctions = new nsVoidArray();
}
mFunctions->AppendElement((void*)aFunction);
}
}
long IdlInterface::FunctionCount()
{
if (mFunctions) {
return mFunctions->Count();
}
return 0;
}
IdlFunction* IdlInterface::GetFunctionAt(long aIndex)
{
IdlFunction *funcObj = (IdlFunction*)0;
if (mFunctions) {
funcObj = (IdlFunction*)mFunctions->ElementAt(aIndex);
}
return funcObj;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,222 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _IdlScanner_h__
#define _IdlScanner_h__
#include <string.h>
#ifdef XP_MAC
#include <fstream.h> // required for namespace resolution
#else
class ifstream;
#endif
#define MAX_ID_LENGTH 256
enum EIDLTokenType {
EOF_TOKEN = -1,
ERROR_TOKEN = 0,
COMMENT_TOKEN = 1,
INTERFACE_TOKEN,
TYPEDEF_TOKEN,
STRUCT_TOKEN,
ENUM_TOKEN,
UNION_TOKEN,
CONST_TOKEN,
EXCEPTION_TOKEN,
READONLY_TOKEN,
OPTIONAL_TOKEN,
XPIDL_TOKEN,
FUNC_TOKEN,
ELLIPSIS_TOKEN,
IID_TOKEN,
ATTRIBUTE_TOKEN,
IDENTIFIER_TOKEN,
BOOLEAN_TOKEN,
FLOAT_TOKEN,
DOUBLE_TOKEN,
LONG_TOKEN,
SHORT_TOKEN,
ULONG_TOKEN,
USHORT_TOKEN,
CHAR_TOKEN,
INT_TOKEN,
UINT_TOKEN,
STRING_TOKEN,
JSVAL_TOKEN,
INPUT_PARAM_TOKEN,
OUTPUT_PARAM_TOKEN,
INOUT_PARAM_TOKEN,
RAISES_TOKEN,
INHERITANCE_SPEC_TOKEN, // ':'
SEPARATOR_TOKEN, // ','
BEGIN_BLOCK_TOKEN, // '{'
END_BLOCK_TOKEN, // '}'
TERMINATOR_TOKEN, // ';'
ASSIGNEMENT_TOKEN, // '='
FUNC_PARAMS_SPEC_BEGIN_TOKEN, // '('
FUNC_PARAMS_SPEC_END_TOKEN, // ')'
VOID_TOKEN,
NOSCRIPT_TOKEN,
UNKNOWN_TOKEN,
REPLACEABLE_TOKEN,
// constant values
INTEGER_CONSTANT = 1000,
STRING_CONSTANT
};
struct Token {
int id;
char *stringID;
union {
// long is the only one used so far
unsigned long vLong;
// still unused...
char vChar;
char *vString;
double vDouble;
} value;
Token()
{
id = 0;
stringID = (char*)0;
memset(&value, 0, sizeof(value));
}
~Token()
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
delete[] stringID;
}
void SetToken(int aID, char *aString = 0)
{
if (STRING_CONSTANT == id) {
delete[] value.vString;
}
id = aID;
if (stringID) {
delete[] stringID;
}
if (aString) {
stringID = new char[strlen(aString) + 1];
memcpy(stringID, aString, strlen(aString) + 1);
}
else {
stringID = (char*)0;
}
memset(&value, 0, sizeof(value));
}
void SetTokenValue(int aID, long aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vLong = (unsigned long)aValue;
}
void SetTokenValue(int aID, char aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vChar = aValue;
}
void SetTokenValue(int aID, char *aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vString = aValue;
}
void SetTokenValue(int aID, double aValue, char *aString = 0)
{
SetToken(aID, aString);
value.vDouble = aValue;
}
};
class IdlScanner {
private:
ifstream *mInputFile;
char *mFileName;
Token *mToken1;
Token *mToken2;
Token *mCurrentToken;
long mLineNumber;
int mTokenPeeked;
char mTokenName[MAX_ID_LENGTH];
public:
IdlScanner();
~IdlScanner();
char* GetFileName();
void SetFileName(char *aFileName);
long GetLineNumber();
int Open(char *aFileName);
int CanReadMoreData();
Token* PeekToken();
Token* NextToken();
protected:
void SetCurrentToken();
int EatWhiteSpace();
void AKeywords(char *aCurrentPos, Token *aToken);
void BKeywords(char *aCurrentPos, Token *aToken);
void CKeywords(char *aCurrentPos, Token *aToken);
void DKeywords(char *aCurrentPos, Token *aToken);
void EKeywords(char *aCurrentPos, Token *aToken);
void FKeywords(char *aCurrentPos, Token *aToken);
void IKeywords(char *aCurrentPos, Token *aToken);
void JKeywords(char *aCurrentPos, Token *aToken);
void LKeywords(char *aCurrentPos, Token *aToken);
void NKeywords(char *aCurrentPos, Token *aToken);
void OKeywords(char *aCurrentPos, Token *aToken);
void RKeywords(char *aCurrentPos, Token *aToken);
void SKeywords(char *aCurrentPos, Token *aToken);
void TKeywords(char *aCurrentPos, Token *aToken);
void UKeywords(char *aCurrentPos, Token *aToken);
void VKeywords(char *aCurrentPos, Token *aToken);
void WKeywords(char *aCurrentPos, Token *aToken);
void XKeywords(char *aCurrentPos, Token *aToken);
void Identifier(char *aCurrentPos, Token *aToken);
void Number(int aStartChar, Token *aToken);
void String(int aStartChar, Token *aToken);
void Char(int aStartChar, Token *aToken);
void Comment(char *aCurrentPos, Token *aToken);
void KeywordMismatch(int aChar, char *aCurrentPos, Token *aToken);
};
#endif // _IdlScanner_h__

Просмотреть файл

@ -1,215 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "IdlVariable.h"
#include <string.h>
IdlVariable::IdlVariable()
{
mType = (Type)0;
mTypeName = 0;
memset(&mValue, 0, sizeof(mValue));
}
IdlVariable::~IdlVariable()
{
if (mTypeName) {
delete[] mTypeName;
}
if (TYPE_STRING == mType) {
delete[] mValue.vString;
}
}
void IdlVariable::SetType(Type aType)
{
mType = aType;
}
Type IdlVariable::GetType()
{
return mType;
}
void IdlVariable::SetTypeName(char *aTypeName)
{
if (mTypeName) {
delete[] mTypeName;
mTypeName = 0;
}
if (aTypeName) {
size_t length = strlen(aTypeName) + 1;
mTypeName = new char[length];
strcpy(mTypeName, aTypeName);
}
}
char* IdlVariable::GetTypeName()
{
return mTypeName;
}
void IdlVariable::GetTypeAsString(char *aString, size_t aStringSize)
{
switch(mType) {
case TYPE_BOOLEAN:
if (aStringSize > 7) {
strcpy(aString, "boolean");
}
break;
case TYPE_FLOAT:
if (aStringSize > 5) {
strcpy(aString, "float");
}
break;
case TYPE_DOUBLE:
if (aStringSize > 6) {
strcpy(aString, "double");
}
break;
case TYPE_LONG:
if (aStringSize > 4) {
strcpy(aString, "long");
}
break;
case TYPE_SHORT:
if (aStringSize > 5) {
strcpy(aString, "short");
}
break;
case TYPE_ULONG:
if (aStringSize > 13) {
strcpy(aString, "unsigned long");
}
break;
case TYPE_USHORT:
if (aStringSize > 14) {
strcpy(aString, "unsigned short");
}
break;
case TYPE_CHAR:
if (aStringSize > 4) {
strcpy(aString, "char");
}
break;
case TYPE_INT:
if (aStringSize > 3) {
strcpy(aString, "int");
}
break;
case TYPE_UINT:
if (aStringSize > 12) {
strcpy(aString, "unsigned int");
}
break;
case TYPE_STRING:
if (aStringSize > 6) {
strcpy(aString, "wstring");
}
break;
case TYPE_OBJECT:
if (aStringSize > strlen(mTypeName)) {
strcpy(aString, mTypeName);
}
break;
case TYPE_VOID:
if (aStringSize > 4) {
strcpy(aString, "void");
}
case TYPE_JSVAL:
if (aStringSize > 4) {
strcpy(aString, "jsval");
}
break;
}
}
void IdlVariable::SetValue(unsigned long aValue)
{
DeleteStringType();
mValue.vLong = aValue;
}
void IdlVariable::SetValue(char aValue)
{
DeleteStringType();
mValue.vChar = aValue;
}
void IdlVariable::SetValue(char *aValue)
{
DeleteStringType();
size_t length = strlen(aValue) + 1;
mValue.vString = new char[length];
strcpy(mValue.vString, aValue);
}
void IdlVariable::SetValue(double aValue)
{
DeleteStringType();
mValue.vDouble = aValue;
}
void IdlVariable::SetValue(void *aValue)
{
DeleteStringType();
mValue.vObject = aValue;
}
unsigned long IdlVariable::GetLongValue()
{
return mValue.vLong;
}
char IdlVariable::GetCharValue()
{
return mValue.vChar;
}
char* IdlVariable::GetStringValue()
{
return mValue.vString;
}
double IdlVariable::GetDoubleValue()
{
return mValue.vDouble;
}
void* IdlVariable::GetObjectValue()
{
return mValue.vObject;
}
void IdlVariable::DeleteStringType()
{
if (TYPE_STRING == mType) {
if (mValue.vString) {
delete[] mValue.vString;
}
}
}

Просмотреть файл

@ -1,91 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _IdlVariable_h__
#define _IdlVariable_h__
#if defined(XP_UNIX) || defined (XP_MAC) || defined (XP_BEOS)
#include <stddef.h>
#endif
#include "IdlObject.h"
enum Type {
TYPE_BOOLEAN = 1,
TYPE_FLOAT,
TYPE_DOUBLE,
TYPE_LONG,
TYPE_SHORT,
TYPE_ULONG,
TYPE_USHORT,
TYPE_CHAR,
TYPE_INT,
TYPE_UINT,
TYPE_STRING,
TYPE_OBJECT,
TYPE_XPIDL_OBJECT,
TYPE_FUNC,
TYPE_VOID,
TYPE_JSVAL,
TYPE_UNKNOWN
};
class IdlVariable : public IdlObject {
private:
Type mType;
char *mTypeName;
union {
unsigned long vLong;
char vChar;
char *vString;
double vDouble;
void *vObject;
} mValue;
public:
IdlVariable();
~IdlVariable();
void SetType(Type aType);
Type GetType();
void SetTypeName(char *aTypeName);
char* GetTypeName(void);
void GetTypeAsString(char *aString, size_t aStringSize);
void SetValue(unsigned long aValue);
void SetValue(char aValue);
void SetValue(char *aValue);
void SetValue(double aValue);
void SetValue(void *aValue);
unsigned long GetLongValue();
char GetCharValue();
char* GetStringValue();
double GetDoubleValue();
void* GetObjectValue();
private:
void DeleteStringType();
};
#endif

Просмотреть файл

@ -744,8 +744,10 @@ JSStubGen::GeneratePropGetter(ofstream *file,
case_str = kBoolGetCaseStr;
break;
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_SHORT:
case TYPE_ULONG:
case TYPE_ULONG_LONG:
case TYPE_USHORT:
case TYPE_CHAR:
case TYPE_INT:
@ -904,8 +906,10 @@ JSStubGen::GeneratePropSetter(ofstream *file,
sprintf(case_buf, kBoolSetCaseStr);
break;
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_SHORT:
case TYPE_ULONG:
case TYPE_ULONG_LONG:
case TYPE_USHORT:
case TYPE_CHAR:
case TYPE_INT:
@ -1423,8 +1427,10 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec)
JSGEN_GENERATE_BOOLPARAM(buf, p);
break;
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_SHORT:
case TYPE_ULONG:
case TYPE_ULONG_LONG:
case TYPE_USHORT:
case TYPE_CHAR:
case TYPE_INT:
@ -1494,8 +1500,10 @@ JSStubGen::GenerateMethods(IdlSpecification &aSpec)
*file << kMethodBoolRetStr;
break;
case TYPE_LONG:
case TYPE_LONG_LONG:
case TYPE_SHORT:
case TYPE_ULONG:
case TYPE_ULONG_LONG:
case TYPE_USHORT:
case TYPE_CHAR:
case TYPE_INT:

Просмотреть файл

@ -30,6 +30,7 @@
#include "nsIDOMElement.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMSelection.h"
#include "nsIDOMEventTarget.h"
/*
* nsEditorShellMouseListener implementation
@ -100,11 +101,11 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
// What about Mac?
if (mEditorShell && buttonNumber == 3)
{
nsCOMPtr<nsIDOMNode> node;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node)
nsCOMPtr<nsIDOMEventTarget> target;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target)
{
// We are only interested in elements, not text nodes
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (element)
{
// Set selection to node clicked on
@ -125,11 +126,11 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
// Detect double click message:
PRUint16 clickCount;
nsresult res = mouseEvent->GetClickCount(&clickCount);
PRInt32 clickCount;
nsresult res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIDOMEventTarget> node;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node)
{
// We are only interested in elements, not text nodes

Просмотреть файл

@ -30,6 +30,7 @@
#include "nsIDOMElement.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMSelection.h"
#include "nsIDOMEventTarget.h"
/*
* nsEditorShellMouseListener implementation
@ -100,11 +101,11 @@ nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
// What about Mac?
if (mEditorShell && buttonNumber == 3)
{
nsCOMPtr<nsIDOMNode> node;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node)
nsCOMPtr<nsIDOMEventTarget> target;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target)
{
// We are only interested in elements, not text nodes
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (element)
{
// Set selection to node clicked on
@ -125,11 +126,11 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
// Detect double click message:
PRUint16 clickCount;
nsresult res = mouseEvent->GetClickCount(&clickCount);
PRInt32 clickCount;
nsresult res = mouseEvent->GetDetail(&clickCount);
if (NS_FAILED(res)) return res;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsIDOMEventTarget> node;
if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node)
{
// We are only interested in elements, not text nodes

Просмотреть файл

@ -198,7 +198,7 @@ function addPoint(event, pointX, pointY, start){
pointX = event.clientX;
pointY = event.clientY;
event.preventBubble();
if (event.clickCount == 2){
if (event.detail == 2){
polyFinish();
return;
}
@ -636,7 +636,7 @@ function clickMouse(event){
startX = event.clientX;
startY = event.clientY;
if (currentTool == "poly"){
//dump(event.clickCount+"\n");
//dump(event.detail+"\n");
if (event.target != currentPoly){
//else if (event.target.getAttribute("class").indexOf("point") == -1)
Poly();

Просмотреть файл

@ -418,10 +418,10 @@ function HandleEvent(eventObj, eventType, targetType, entryNumber,
} else if (eventType === "click") {
dump("clickCount="+eventObj.clickCount+"\n");
dump("clickCount="+eventObj.detail+"\n");
var shiftClick = eventObj.shiftKey;
var dblClick = (eventObj.clickCount == 2);
var dblClick = (eventObj.detail == 2);
// Execute shell commands only on double-click for safety
// Use single click for "selection" and prompt expansion only

Просмотреть файл

@ -1995,7 +1995,7 @@ PresShell::ScrollLine(PRBool aForward)
result = viewManager->GetRootScrollableView(&scrollView);
if (NS_SUCCEEDED(result) && scrollView)
{
scrollView->ScrollByLines(aForward ? 1 : -1);
scrollView->ScrollByLines(0, aForward ? 1 : -1);
//NEW FOR LINES
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -2012,7 +2012,26 @@ PresShell::ScrollLine(PRBool aForward)
NS_IMETHODIMP
PresShell::ScrollHorizontal(PRBool aLeft)
{
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsIViewManager> viewManager;
nsresult result = GetViewManager(getter_AddRefs(viewManager));
if (NS_SUCCEEDED(result) && viewManager)
{
nsIScrollableView *scrollView;
result = viewManager->GetRootScrollableView(&scrollView);
if (NS_SUCCEEDED(result) && scrollView)
{
scrollView->ScrollByLines(aLeft ? -1 : 1, 0);
//NEW FOR LINES
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
// I'd use Composite here, but it doesn't always work.
// vm->Composite();
viewManager->ForceUpdate();
}
}
return result;
}
NS_IMETHODIMP

Просмотреть файл

@ -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;

Просмотреть файл

@ -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,

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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; \

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -30,6 +30,7 @@
class nsIPresContext;
class nsIDOMEventListener;
class nsIScriptObjectOwner;
class nsIDOMEventTarget;
/*
* Event listener manager interface.
@ -104,6 +105,7 @@ public:
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus) = 0;
@ -114,6 +116,7 @@ public:
*/
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent) = 0;
/**
@ -133,6 +136,12 @@ public:
* manager.
*/
virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0;
/**
* Removes all event listeners registered by this instance of the listener
* manager.
*/
virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0;
};
extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult);

Просмотреть файл

@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIEventStateManager_h__
#define nsIEventStateManager_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsVoidArray.h"
class nsIContent;
class nsIPresContext;
class nsIDOMEvent;
class nsIFrame;
class nsIView;
class nsIWidget;
/*
* Event listener manager interface.
*/
#define NS_IEVENTSTATEMANAGER_IID \
{ /* 80a98c80-2036-11d2-bd89-00805f8ae3f4 */ \
0x80a98c80, 0x2036, 0x11d2, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIEventStateManager : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IEVENTSTATEMANAGER_IID; return iid; }
NS_IMETHOD Init() = 0;
NS_IMETHOD PreHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView) = 0;
NS_IMETHOD PostHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView) = 0;
NS_IMETHOD SetPresContext(nsIPresContext* aPresContext) = 0;
NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame) = 0;
NS_IMETHOD GetEventTarget(nsIFrame **aFrame) = 0;
NS_IMETHOD GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent) = 0;
NS_IMETHOD GetEventRelatedContent(nsIContent** aContent) = 0;
NS_IMETHOD GetContentState(nsIContent *aContent, PRInt32& aState) = 0;
NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState) = 0;
NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0;
NS_IMETHOD SetFocusedContent(nsIContent* aContent) = 0;
// This is an experiement and may be temporary
NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0;
// Access Key Registration
NS_IMETHOD RegisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey) = 0;
NS_IMETHOD UnregisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey) = 0;
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor) = 0;
};
#define NS_EVENT_STATE_UNSPECIFIED 0x0000
#define NS_EVENT_STATE_ACTIVE 0x0001 // mouse is down on content
#define NS_EVENT_STATE_FOCUS 0x0002 // content has focus
#define NS_EVENT_STATE_HOVER 0x0004 // mouse is hovering over content
#define NS_EVENT_STATE_DRAGOVER 0x0008 // drag is hovering over content
#endif // nsIEventStateManager_h__

Просмотреть файл

@ -36,7 +36,7 @@ class nsIPresContext;
0x80a98c80, 0x2036, 0x11d2, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIDOMNode;
class nsIDOMEventTarget;
class nsIDOMEvent;
class nsIPrivateDOMEvent : public nsISupports {
@ -45,11 +45,15 @@ public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMEVENT_IID; return iid; }
NS_IMETHOD DuplicatePrivateData() = 0;
NS_IMETHOD SetTarget(nsIDOMNode* aNode) = 0;
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
};
extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);
extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);
extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsIPresContext* aPresContext,
const nsString& aEventType,
nsEvent *aEvent);
#endif // nsIPrivateDOMEvent_h__

Просмотреть файл

@ -34,6 +34,12 @@
#include "nsIViewManager.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIScrollableView.h"
#include "nsIDOMEventTarget.h"
#include "nsIInterfaceRequestor.h"
#include "nsIDOMWindow.h"
#include "nsIDOMAbstractView.h"
#include "prmem.h"
#include "nsLayoutAtoms.h"
static NS_DEFINE_IID(kIFrameIID, NS_IFRAME_IID);
@ -46,16 +52,39 @@ static char* mEventNames[] = {
"dragenter", "dragover", "dragexit", "dragdrop", "draggesture"
};
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType) {
mPresContext = aPresContext;
if (mPresContext)
NS_ADDREF(mPresContext);
mEvent = aEvent;
if (aEvent) {
mEventIsInternal = PR_FALSE;
mEvent = aEvent;
}
else {
//Allocate internal event
if (aEventType.EqualsIgnoreCase("MouseEvent")) {
mEvent = PR_NEWZAP(nsMouseEvent);
mEvent->eventStructType = NS_MOUSE_EVENT;
}
else if (aEventType.EqualsIgnoreCase("KeyEvent")) {
mEvent = PR_NEWZAP(nsKeyEvent);
mEvent->eventStructType = NS_KEY_EVENT;
}
else if (aEventType.EqualsIgnoreCase("HTMLEvent")) {
mEvent = PR_NEWZAP(nsEvent);
mEvent->eventStructType = NS_EVENT;
}
else {
mEvent = PR_NEWZAP(nsEvent);
mEvent->eventStructType = NS_EVENT;
}
}
mTarget = nsnull;
mCurrentTarget = nsnull;
mText = nsnull;
mTextRange = nsnull;
if (aEvent->eventStructType ==NS_TEXT_EVENT) {
if (aEvent->eventStructType == NS_TEXT_EVENT) {
//
// extract the IME composition string
//
@ -87,8 +116,13 @@ nsDOMEvent::nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent) {
nsDOMEvent::~nsDOMEvent() {
NS_IF_RELEASE(mPresContext);
NS_IF_RELEASE(mTarget);
NS_IF_RELEASE(mCurrentTarget);
NS_IF_RELEASE(mTextRange);
if (mEventIsInternal) {
PR_DELETE(mEvent);
}
if (mText!=nsnull)
delete mText;
}
@ -121,7 +155,7 @@ NS_METHOD nsDOMEvent::GetType(nsString& aType)
return NS_ERROR_FAILURE;
}
NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
{
if (nsnull != mTarget) {
*aTarget = mTarget;
@ -138,7 +172,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
if (targetContent) {
if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) {
if (NS_OK == targetContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) {
*aTarget = mTarget;
NS_ADDREF(mTarget);
}
@ -154,7 +188,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
if (doc) {
if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&mTarget)) {
if (NS_OK == doc->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)&mTarget)) {
*aTarget = mTarget;
NS_ADDREF(mTarget);
}
@ -166,9 +200,9 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMNode** aTarget)
}
NS_IMETHODIMP
nsDOMEvent::GetCurrentNode(nsIDOMNode** aCurrentNode)
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
{
*aCurrentNode = nsnull;
*aCurrentTarget = nsnull;
return NS_OK;
}
@ -194,13 +228,29 @@ nsDOMEvent::GetEventPhase(PRUint16* aEventPhase)
NS_IMETHODIMP
nsDOMEvent::GetBubbles(PRBool* aBubbles)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aBubbles = mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetCancelable(PRBool* aCancelable)
{
return NS_ERROR_NOT_IMPLEMENTED;
*aCancelable = mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetTimeStamp(PRUint64* aTimeStamp)
{
*aTimeStamp = mEvent->time;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::StopPropagation()
{
mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
return NS_OK;
}
NS_IMETHODIMP
@ -224,20 +274,64 @@ nsDOMEvent::PreventCapture()
NS_IMETHODIMP
nsDOMEvent::PreventDefault()
{
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) {
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::GetView(nsIDOMAbstractView** aView)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_ARG_POINTER(aView);
*aView = nsnull;
nsresult rv = NS_OK;
nsCOMPtr<nsISupports> container;
rv = mPresContext->GetContainer(getter_AddRefs(container));
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv);
nsCOMPtr<nsIInterfaceRequestor> ifrq(do_QueryInterface(container));
NS_ENSURE_TRUE(ifrq, NS_OK);
nsCOMPtr<nsIDOMWindow> window;
ifrq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(window));
NS_ENSURE_TRUE(window, NS_OK);
window->QueryInterface(NS_GET_IID(nsIDOMAbstractView), (void **)aView);
return rv;
}
NS_IMETHODIMP
nsDOMEvent::GetDetail(PRInt32* aDetail)
{
return NS_ERROR_NOT_IMPLEMENTED;
//detail is valid for more than just mouseevents but we don't
//use it for anything else right now
if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) {
*aDetail = 0;
return NS_OK;
}
switch (mEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_CLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
*aDetail = ((nsMouseEvent*)mEvent)->clickCount;
break;
default:
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetText(nsString& aText)
@ -515,35 +609,7 @@ NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton)
return NS_OK;
}
NS_METHOD nsDOMEvent::GetClickCount(PRUint16* aClickCount)
{
if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) {
*aClickCount = 0;
return NS_OK;
}
switch (mEvent->message) {
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_LEFT_CLICK:
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_CLICK:
case NS_MOUSE_MIDDLE_DOUBLECLICK:
case NS_MOUSE_RIGHT_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
case NS_MOUSE_RIGHT_CLICK:
case NS_MOUSE_RIGHT_DOUBLECLICK:
*aClickCount = ((nsMouseEvent*)mEvent)->clickCount;
break;
default:
break;
}
return NS_OK;
}
NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget)
{
nsIEventStateManager *manager;
nsIContent *relatedContent = nsnull;
@ -555,11 +621,11 @@ NS_METHOD nsDOMEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
}
if (relatedContent) {
ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aRelatedNode);
ret = relatedContent->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)aRelatedTarget);
NS_RELEASE(relatedContent);
}
else {
*aRelatedNode = nsnull;
*aRelatedTarget = nsnull;
}
return ret;
@ -793,30 +859,109 @@ NS_METHOD nsDOMEvent::GetPreventDefault(PRBool* aReturn)
return NS_OK;
}
//XXX The following four methods are for custom event dispatch inside the DOM.
//They will be implemented post-beta
nsresult
nsDOMEvent::SetEventType(const nsString& aEventTypeArg)
{
nsAutoString str; str.AssignWithConversion("on");
nsIAtom* atom;
str.Append(aEventTypeArg);
atom = NS_NewAtom(str);
if (atom == nsLayoutAtoms::onmousedown && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN;
}
else if (atom == nsLayoutAtoms::onmouseup && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_BUTTON_UP;
}
else if (atom == nsLayoutAtoms::onclick && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_LEFT_CLICK;
}
else if (atom == nsLayoutAtoms::onmouseover && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_ENTER_SYNTH;
}
else if (atom == nsLayoutAtoms::onmouseout && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_EXIT_SYNTH;
}
else if (atom == nsLayoutAtoms::onmousemove && mEvent->eventStructType == NS_MOUSE_EVENT) {
mEvent->message = NS_MOUSE_MOVE;
}
else if (atom == nsLayoutAtoms::onkeydown && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_DOWN;
}
else if (atom == nsLayoutAtoms::onkeyup && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_UP;
}
else if (atom == nsLayoutAtoms::onkeypress && mEvent->eventStructType == NS_KEY_EVENT) {
mEvent->message = NS_KEY_PRESS;
}
else if (atom == nsLayoutAtoms::onfocus && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FOCUS_CONTENT;
}
else if (atom == nsLayoutAtoms::onblur && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_BLUR_CONTENT;
}
else if (atom == nsLayoutAtoms::onsubmit && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_SUBMIT;
}
else if (atom == nsLayoutAtoms::onreset && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_RESET;
}
else if (atom == nsLayoutAtoms::onchange && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_CHANGE;
}
else if (atom == nsLayoutAtoms::onselect && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_FORM_SELECTED;
}
else if (atom == nsLayoutAtoms::onload && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_PAGE_LOAD;
}
else if (atom == nsLayoutAtoms::onunload && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_PAGE_UNLOAD;
}
else if (atom == nsLayoutAtoms::onabort && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_IMAGE_ABORT;
}
else if (atom == nsLayoutAtoms::onerror && mEvent->eventStructType == NS_EVENT) {
mEvent->message = NS_IMAGE_ERROR;
}
else {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitEvent(const nsString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aEventTypeArg), NS_ERROR_FAILURE);
mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitUIEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDOMEvent::InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE);
//mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
//mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::InitKeyEvent(const nsString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg)
{
return NS_ERROR_NOT_IMPLEMENTED;
NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE);
mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE;
mEvent->flags |= aCancelableArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_CANCEL;
return NS_OK;
}
@ -828,7 +973,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData()
return NS_OK;
}
NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget)
NS_METHOD nsDOMEvent::SetTarget(nsIDOMEventTarget* aTarget)
{
if (mTarget != aTarget) {
NS_IF_RELEASE(mTarget);
@ -838,6 +983,16 @@ NS_METHOD nsDOMEvent::SetTarget(nsIDOMNode* aTarget)
return NS_OK;
}
NS_METHOD nsDOMEvent::SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget)
{
if (mCurrentTarget != aCurrentTarget) {
NS_IF_RELEASE(mCurrentTarget);
NS_IF_ADDREF(aCurrentTarget);
mCurrentTarget = aCurrentTarget;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMEvent::IsDispatchStopped(PRBool* aIsDispatchStopped)
{
@ -936,9 +1091,12 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType)
return nsnull;
}
nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent)
nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsIPresContext* aPresContext,
const nsString& aEventType,
nsEvent *aEvent)
{
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent);
nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -85,18 +85,20 @@ public:
eDOMEvents_draggesture
};
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent);
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsString& aEventType);
virtual ~nsDOMEvent();
NS_DECL_ISUPPORTS
// nsIDOMEvent Interface
NS_IMETHOD GetType(nsString& aType);
NS_IMETHOD GetTarget(nsIDOMNode** aTarget);
NS_IMETHOD GetCurrentNode(nsIDOMNode** aCurrentNode);
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget);
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget);
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase);
NS_IMETHOD GetBubbles(PRBool* aBubbles);
NS_IMETHOD GetCancelable(PRBool* aCancelable);
NS_IMETHOD GetTimeStamp(PRUint64* aTimestamp);
NS_IMETHOD StopPropagation();
NS_IMETHOD PreventBubble();
NS_IMETHOD PreventCapture();
NS_IMETHOD PreventDefault();
@ -117,8 +119,7 @@ public:
NS_IMETHOD GetShiftKey(PRBool* aShiftKey);
NS_IMETHOD GetMetaKey(PRBool* aMetaKey);
NS_IMETHOD GetButton(PRUint16* aButton);
NS_IMETHOD GetClickCount(PRUint16* aClickCount);
NS_IMETHOD GetRelatedNode(nsIDOMNode** aRelatedNode);
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget);
NS_IMETHOD GetCharCode(PRUint32* aCharCode);
NS_IMETHOD GetKeyCode(PRUint32* aKeyCode);
NS_IMETHOD InitMouseEvent(const nsString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg);
@ -139,7 +140,8 @@ public:
// nsIPrivateDOMEvent interface
NS_IMETHOD DuplicatePrivateData();
NS_IMETHOD SetTarget(nsIDOMNode* aNode);
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget);
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget);
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
// nsIPrivateTextEvent interface
@ -154,10 +156,13 @@ protected:
//Internal helper funcs
nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P);
nsresult SetEventType(const nsString& aEventTypeArg);
nsEvent* mEvent;
PRBool mEventIsInternal;
nsIPresContext* mPresContext;
nsIDOMNode* mTarget;
nsIDOMEventTarget* mTarget;
nsIDOMEventTarget* mCurrentTarget;
nsString* mText;
nsIPrivateTextRangeList* mTextRange;
const char* GetEventName(PRUint32 aEventType);

Просмотреть файл

@ -22,7 +22,6 @@
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsIPresContext.h"
#include "nsDOMEvent.h"
#include "nsEventListenerManager.h"
#include "nsIDOMEventListener.h"
@ -54,6 +53,8 @@
#include "nsDOMPropEnums.h"
#include "nsDOMError.h"
#include "nsIJSContextStack.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
static NS_DEFINE_IID(kIEventListenerManagerIID, NS_IEVENTLISTENERMANAGER_IID);
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
@ -75,6 +76,7 @@ nsEventListenerManager::nsEventListenerManager()
mCompositionListeners = nsnull;
mMenuListeners = nsnull;
mDestroyed = PR_FALSE;
mTarget = nsnull;
NS_INIT_REFCNT();
}
@ -616,6 +618,7 @@ nsresult nsEventListenerManager::RegisterScriptEventListener(nsIScriptContext *a
nsresult
nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags)
{
@ -700,7 +703,10 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
}
if (NS_SUCCEEDED(result)) {
nsCOMPtr<nsIPrivateDOMEvent> aPrivDOMEvent(do_QueryInterface(aDOMEvent));
aPrivDOMEvent->SetCurrentTarget(aCurrentTarget);
result = aListenerStruct->mListener->HandleEvent(aDOMEvent);
aPrivDOMEvent->SetCurrentTarget(nsnull);
}
return result;
@ -714,6 +720,7 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
@ -727,6 +734,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
keys which cause window deletion, can destroy this object
before we're ready. */
nsCOMPtr<nsIEventListenerManager> kungFuDeathGrip(this);
nsAutoString empty;
switch(aEvent->message) {
case NS_MOUSE_LEFT_BUTTON_DOWN:
@ -745,7 +753,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_EXIT_SYNTH:
if (nsnull != mMouseListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMouseListeners && i<mMouseListeners->Count(); i++) {
@ -840,7 +848,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -852,7 +860,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_MOUSE_MOVE:
if (nsnull != mMouseMotionListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMouseMotionListeners && i<mMouseMotionListeners->Count(); i++) {
@ -886,7 +894,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -903,7 +911,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
#endif
if (nsnull != mCompositionListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent);
}
if (NS_OK == ret) {
for(int i=0; mTextListeners && i<mTextListeners->Count();i++) {
@ -951,7 +959,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -965,7 +973,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
#endif
if (nsnull != mTextListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent,aPresContext,empty,aEvent);
}
if (NS_OK == ret) {
for (int i=0; mTextListeners && i<mTextListeners->Count(); i++) {
@ -986,7 +994,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
correctSubType = PR_TRUE;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1000,7 +1008,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_KEY_PRESS:
if (nsnull != mKeyListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mKeyListeners && i<mKeyListeners->Count(); i++) {
@ -1052,7 +1060,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1065,7 +1073,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_BLUR_CONTENT:
if (nsnull != mFocusListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mFocusListeners && i<mFocusListeners->Count(); i++) {
@ -1108,7 +1116,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1124,7 +1132,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_FORM_INPUT:
if (nsnull != mFormListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mFormListeners && i<mFormListeners->Count(); i++) {
@ -1194,7 +1202,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1211,7 +1219,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
if (nsnull != mLoadListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mLoadListeners && i<mLoadListeners->Count(); i++) {
@ -1266,7 +1274,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1278,7 +1286,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_PAINT:
if (nsnull != mPaintListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mPaintListeners && i<mPaintListeners->Count(); i++) {
@ -1300,7 +1308,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
correctSubType = PR_TRUE;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1316,7 +1324,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_DRAGDROP_GESTURE:
if (nsnull != mDragListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
@ -1379,7 +1387,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || dragStruct->mSubType == NS_EVENT_BITS_DRAG_NONE)
ret = HandleEventSubType(dragStruct, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(dragStruct, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1395,7 +1403,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
case NS_XUL_COMMAND_UPDATE:
if (nsnull != mMenuListeners) {
if (nsnull == *aDOMEvent) {
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, empty, aEvent);
}
if (NS_OK == ret) {
for (int i=0; mMenuListeners && i<mMenuListeners->Count(); i++) {
@ -1474,7 +1482,7 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
break;
}
if (correctSubType || ls->mSubType == NS_EVENT_BITS_NONE) {
ret = HandleEventSubType(ls, *aDOMEvent, subType, aFlags);
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, subType, aFlags);
}
}
}
@ -1505,9 +1513,15 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
nsresult nsEventListenerManager::CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent)
{
return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEvent);
if (!aEvent && !aEventType.EqualsIgnoreCase("MouseEvent") && !aEventType.EqualsIgnoreCase("KeyEvent") &&
!aEventType.EqualsIgnoreCase("HTMLEvent")) {
return NS_ERROR_FAILURE;
}
return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEventType, aEvent);
}
/**
@ -1753,6 +1767,13 @@ nsresult nsEventListenerManager::RemoveAllListeners(PRBool aScriptOnly)
return NS_OK;
}
nsresult nsEventListenerManager::SetListenerTarget(nsISupports* aTarget)
{
//WEAK reference, must be set back to nsnull when done
mTarget = aTarget;
return NS_OK;
}
// nsIDOMEventTarget interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListener(const nsString& aType,
@ -1774,6 +1795,38 @@ nsEventListenerManager::RemoveEventListener(const nsString& aType,
return RemoveEventListenerByType(aListener, aType, flags);
}
NS_IMETHODIMP
nsEventListenerManager::DispatchEvent(nsIDOMEvent* aEvent)
{
//If we don't have a target set this doesn't work.
if (mTarget) {
nsCOMPtr<nsIContent> targetContent(do_QueryInterface(mTarget));
if (targetContent) {
nsCOMPtr<nsIDocument> document;
targetContent->GetDocument(*getter_AddRefs(document));
if (document) {
// Obtain a presentation context
PRInt32 count = document->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(document->GetShellAt(0));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(mTarget, aEvent);
}
}
}
}
return NS_ERROR_FAILURE;
}
// nsIDOMEventReceiver interface
NS_IMETHODIMP
nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener,
@ -1806,7 +1859,7 @@ nsEventListenerManager::GetNewListenerManager(nsIEventListenerManager **aInstanc
NS_IMETHODIMP
nsEventListenerManager::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult)

Просмотреть файл

@ -41,7 +41,7 @@ typedef struct {
} nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x20
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80
/*
* Event listener manager
@ -94,15 +94,19 @@ public:
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsEvent* aEvent,
const nsString& aEventType,
nsIDOMEvent** aDOMEvent);
virtual nsresult RemoveAllListeners(PRBool aScriptOnly);
virtual nsresult SetListenerTarget(nsISupports* aTarget);
static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType);
// nsIDOMEventTarget interface
@ -112,6 +116,7 @@ public:
NS_IMETHOD RemoveEventListener(const nsString& aType,
nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent);
// nsIDOMEventReceiver interface
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID);
@ -123,6 +128,7 @@ public:
protected:
nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags);
nsListenerStruct* FindJSEventListener(REFNSIID aIID);
@ -146,6 +152,8 @@ protected:
nsVoidArray* mMenuListeners;
nsCOMPtr<nsIPrincipal> mPrincipal;
PRBool mDestroyed;
nsISupports* mTarget; //WEAK
};

Просмотреть файл

@ -899,7 +899,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
{
if (sv) {
if (action == MOUSE_SCROLL_N_LINES)
sv->ScrollByLines(numLines);
sv->ScrollByLines(0, numLines);
else
sv->ScrollByPages((numLines > 0) ? 1 : -1);
ForceViewUpdate(focusView);
@ -996,7 +996,27 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext,
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
nsIViewManager* vm = nsnull;
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
// I'd use Composite here, but it doesn't always work.
// vm->Composite();
vm->ForceUpdate();
NS_RELEASE(vm);
}
}
}
break;
case NS_VK_LEFT:
case NS_VK_RIGHT:
if (!mCurrentFocus) {
nsIScrollableView* sv = GetNearestScrollingView(aView);
if (sv) {
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0);
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -2579,6 +2599,12 @@ void nsEventStateManager::ForceViewUpdate(nsIView* aView)
}
}
NS_IMETHODIMP
nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent)
{
return NS_OK;
}
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
{
nsresult rv;

Просмотреть файл

@ -99,6 +99,9 @@ public:
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor);
//Method for centralized distribution of new DOM events
NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent);
protected:
void UpdateCursor(nsIPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
void GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent);

Просмотреть файл

@ -57,6 +57,7 @@
#include "nsIFontMetrics.h"
#include "nsVoidArray.h"
#include "nsIScrollableFrame.h"
#include "nsIDOMEventTarget.h"
#include "nsISelectElement.h"
@ -2381,15 +2382,16 @@ nsListControlFrame::SelectionChanged(nsIContent* aContent)
// Here we create our own DOM event and set the target to the Select
// We'll pass this DOM event in, in hopes that the target is used.
nsIDOMEvent* DOMEvent = nsnull;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event);
nsAutoString empty;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event);
if (NS_SUCCEEDED(res) && DOMEvent && mContent) {
nsCOMPtr<nsIDOMNode> node;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node));
if (NS_SUCCEEDED(res) && node) {
nsCOMPtr<nsIDOMEventTarget> target;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target));
if (NS_SUCCEEDED(res) && target) {
nsCOMPtr<nsIPrivateDOMEvent> pDOMEvent;
res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent));
if (NS_SUCCEEDED(res) && pDOMEvent) {
res = pDOMEvent->SetTarget(node);
res = pDOMEvent->SetTarget(target);
if (NS_SUCCEEDED(res)) {
// Have the content handle the event.
res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status);

Просмотреть файл

@ -1995,7 +1995,7 @@ PresShell::ScrollLine(PRBool aForward)
result = viewManager->GetRootScrollableView(&scrollView);
if (NS_SUCCEEDED(result) && scrollView)
{
scrollView->ScrollByLines(aForward ? 1 : -1);
scrollView->ScrollByLines(0, aForward ? 1 : -1);
//NEW FOR LINES
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
@ -2012,7 +2012,26 @@ PresShell::ScrollLine(PRBool aForward)
NS_IMETHODIMP
PresShell::ScrollHorizontal(PRBool aLeft)
{
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsIViewManager> viewManager;
nsresult result = GetViewManager(getter_AddRefs(viewManager));
if (NS_SUCCEEDED(result) && viewManager)
{
nsIScrollableView *scrollView;
result = viewManager->GetRootScrollableView(&scrollView);
if (NS_SUCCEEDED(result) && scrollView)
{
scrollView->ScrollByLines(aLeft ? -1 : 1, 0);
//NEW FOR LINES
// force the update to happen now, otherwise multiple scrolls can
// occur before the update is processed. (bug #7354)
// I'd use Composite here, but it doesn't always work.
// vm->Composite();
viewManager->ForceUpdate();
}
}
return result;
}
NS_IMETHODIMP

Просмотреть файл

@ -389,7 +389,7 @@ nsHTMLLabelElement::HandleDOMEvent(nsIPresContext* aPresContext,
// Now a little special trickery because we are a label:
// We need to pass this event on to our child iff it is a focus,
// keypress/up/dn, mouseclick/dblclick/up/down.
if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT == aFlags) &&
if ((NS_OK == rv) && (NS_EVENT_FLAG_INIT & aFlags) &&
((nsEventStatus_eIgnore == *aEventStatus) ||
(nsEventStatus_eConsumeNoDefault == *aEventStatus)) ) {
PRBool isFormElement = PR_FALSE;

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsLayoutAtoms.h"
#include "nsIFontMetrics.h"
#include "nsVoidArray.h"
#include "nsIDOMEventTarget.h"
#include "nsISelectElement.h"
#include "nsIScrollableFrame.h"
@ -2537,15 +2538,16 @@ nsGfxListControlFrame::SelectionChanged(nsIContent* aContent)
// Here we create our own DOM event and set the target to the Select
// We'll pass this DOM event in, in hopes that the target is used.
nsIDOMEvent* DOMEvent = nsnull;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event);
nsAutoString empty;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event);
if (NS_SUCCEEDED(res) && DOMEvent && mContent) {
nsCOMPtr<nsIDOMNode> node;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node));
if (NS_SUCCEEDED(res) && node) {
nsCOMPtr<nsIDOMEventTarget> target;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target));
if (NS_SUCCEEDED(res) && target) {
nsCOMPtr<nsIPrivateDOMEvent> pDOMEvent;
res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent));
if (NS_SUCCEEDED(res) && pDOMEvent) {
res = pDOMEvent->SetTarget(node);
res = pDOMEvent->SetTarget(target);
if (NS_SUCCEEDED(res)) {
// Have the content handle the event.
res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status);

Просмотреть файл

@ -4184,8 +4184,8 @@ nsEnderEventListener::DispatchMouseEvent(nsIDOMMouseEvent *aEvent, PRInt32 aEven
aEvent->GetScreenX(&(event.point.x));
aEvent->GetScreenY(&(event.point.y));
PRUint16 clickCount;
aEvent->GetClickCount(&clickCount);
PRInt32 clickCount;
aEvent->GetDetail(&clickCount);
event.clickCount = clickCount;
event.message = aEventType;
GetWidgetForView(mView, event.widget);

Просмотреть файл

@ -57,6 +57,7 @@
#include "nsIFontMetrics.h"
#include "nsVoidArray.h"
#include "nsIScrollableFrame.h"
#include "nsIDOMEventTarget.h"
#include "nsISelectElement.h"
@ -2381,15 +2382,16 @@ nsListControlFrame::SelectionChanged(nsIContent* aContent)
// Here we create our own DOM event and set the target to the Select
// We'll pass this DOM event in, in hopes that the target is used.
nsIDOMEvent* DOMEvent = nsnull;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, &event);
nsAutoString empty;
nsresult res = NS_NewDOMUIEvent(&DOMEvent, mPresContext, empty, &event);
if (NS_SUCCEEDED(res) && DOMEvent && mContent) {
nsCOMPtr<nsIDOMNode> node;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(node));
if (NS_SUCCEEDED(res) && node) {
nsCOMPtr<nsIDOMEventTarget> target;
res = mContent->QueryInterface(kIDOMNodeIID, (void**)getter_AddRefs(target));
if (NS_SUCCEEDED(res) && target) {
nsCOMPtr<nsIPrivateDOMEvent> pDOMEvent;
res = DOMEvent->QueryInterface(kIPrivateDOMEventIID, (void**)getter_AddRefs(pDOMEvent));
if (NS_SUCCEEDED(res) && pDOMEvent) {
res = pDOMEvent->SetTarget(node);
res = pDOMEvent->SetTarget(target);
if (NS_SUCCEEDED(res)) {
// Have the content handle the event.
res = mContent->HandleDOMEvent(mPresContext, &event, &DOMEvent, NS_EVENT_FLAG_BUBBLE, &status);

Просмотреть файл

@ -365,6 +365,15 @@ nsTableOuterFrame::GetFrameForPoint(nsIPresContext* aPresContext,
nsFramePaintLayer aWhichLayer,
nsIFrame** aFrame)
{
nsresult rv;
// caption frames live in a different list which we need to check separately
if (mCaptionFrame) {
rv = GetFrameForPointUsing(aPresContext, aPoint, nsLayoutAtoms::captionList, NS_FRAME_PAINT_LAYER_FOREGROUND, PR_FALSE, aFrame);
if (NS_OK == rv) {
return NS_OK;
}
}
// this should act like a block, so we need to override
return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame);
}

Просмотреть файл

@ -365,6 +365,15 @@ nsTableOuterFrame::GetFrameForPoint(nsIPresContext* aPresContext,
nsFramePaintLayer aWhichLayer,
nsIFrame** aFrame)
{
nsresult rv;
// caption frames live in a different list which we need to check separately
if (mCaptionFrame) {
rv = GetFrameForPointUsing(aPresContext, aPoint, nsLayoutAtoms::captionList, NS_FRAME_PAINT_LAYER_FOREGROUND, PR_FALSE, aFrame);
if (NS_OK == rv) {
return NS_OK;
}
}
// this should act like a block, so we need to override
return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame);
}

Просмотреть файл

@ -157,7 +157,7 @@ nsXMLDocumentType::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
}
if (aIID.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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -134,7 +134,7 @@ nsXMLEntity::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
}
if (aIID.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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -131,7 +131,7 @@ nsXMLNotation::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
}
if (aIID.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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -137,7 +137,7 @@ nsXMLProcessingInstruction::QueryInterface(REFNSIID aIID, void** aInstancePtrRes
}
if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver))) {
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**)aInstancePtrResult);
}
return NS_NOINTERFACE;

Просмотреть файл

@ -35,6 +35,7 @@
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIDOMEventTarget.h"
NS_IMPL_ADDREF(nsToolbarDragListener)
@ -323,15 +324,20 @@ nsToolbarDragListener::DragExit(nsIDOMEvent* aDragEvent)
if ( !mouseEvent )
return NS_OK;
nsCOMPtr<nsIDOMEventTarget> relatedTarget;
mouseEvent->GetRelatedTarget ( getter_AddRefs(relatedTarget) );
nsCOMPtr<nsIDOMNode> relatedNode;
mouseEvent->GetRelatedNode ( getter_AddRefs(relatedNode) );
nsCOMPtr<nsIDOMNode> target;
if (relatedTarget) relatedNode = do_QueryInterface(relatedTarget);
nsCOMPtr<nsIDOMEventTarget> target;
aDragEvent->GetTarget ( getter_AddRefs(target) );
nsCOMPtr<nsIDOMNode> targetNode = nsnull;
if (target) targetNode = do_QueryInterface(target);
// we only care about the case where the toolbar or one of its children
// is the target of this dragExit event. Recall we get all exit events because
// they will bubble up to us.
if ( !IsNodeAChild(target) )
if ( !IsNodeAChild(targetNode) )
return NS_OK;
if ( ! IsNodeAChild(relatedNode) ) {

Просмотреть файл

@ -31,6 +31,7 @@ class nsToolbarFrame;
class nsIPresContext;
class nsIDOMEvent;
class nsIFrame;
class nsIDOMNode;
class nsToolbarDragListener : public nsIDOMDragListener

Просмотреть файл

@ -35,6 +35,7 @@
#include "nsIDOMXULDocument.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIDOMEventTarget.h"
NS_IMPL_ADDREF(nsTreeItemDragCapturer)
@ -306,17 +307,21 @@ nsTreeItemDragCapturer :: IsEventTargetMyTreeItem ( nsIDOMEvent* inEvent )
// get the treeItem associated with the target. Remember that the tree cell is the
// actual target, so we have to go up two levels to get to its treeItem.
nsCOMPtr<nsIDOMEventTarget> target;
nsCOMPtr<nsIDOMNode> targetCell;
inEvent->GetTarget ( getter_AddRefs(targetCell) );
nsCOMPtr<nsIDOMNode> targetRow;
nsCOMPtr<nsIDOMNode> targetTreeItem;
if ( targetCell ) {
targetCell->GetParentNode(getter_AddRefs(targetRow));
if ( targetRow ) {
targetRow->GetParentNode(getter_AddRefs(targetTreeItem));
// the critical comparison. are
if ( myDomNode == targetTreeItem )
retVal = PR_TRUE;
inEvent->GetTarget ( getter_AddRefs(target) );
if ( target ) {
targetCell = do_QueryInterface( target );
if ( targetCell ) {
targetCell->GetParentNode(getter_AddRefs(targetRow));
if ( targetRow ) {
targetRow->GetParentNode(getter_AddRefs(targetTreeItem));
// the critical comparison. are
if ( myDomNode == targetTreeItem )
retVal = PR_TRUE;
}
}
}

Просмотреть файл

@ -1,117 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsTreeTwistyListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsCOMPtr.h"
#include "nsIDOMUIEvent.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsXULAtoms.h"
/*
* nsTreeTwistyListener implementation
*/
NS_IMPL_ADDREF(nsTreeTwistyListener)
NS_IMPL_RELEASE(nsTreeTwistyListener)
NS_IMPL_QUERY_INTERFACE1(nsTreeTwistyListener, nsIDOMMouseListener)
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::nsTreeTwistyListener()
{
NS_INIT_REFCNT();
}
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::~nsTreeTwistyListener()
{
}
////////////////////////////////////////////////////////////////////////
static void GetTreeItem(nsIDOMElement* aElement, nsIDOMElement** aResult)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
while (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::treeitem) {
nsCOMPtr<nsIDOMElement> result = do_QueryInterface(content);
*aResult = result.get();
NS_IF_ADDREF(*aResult);
return;
}
nsCOMPtr<nsIContent> parent;
content->GetParent(*getter_AddRefs(parent));
content = parent;
}
}
nsresult
nsTreeTwistyListener::MouseDown(nsIDOMEvent* aEvent)
{
// Get the target of the event. If it's a titledbutton, we care.
nsCOMPtr<nsIDOMNode> target;
aEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (!element)
return NS_OK;
// Find out if we're the twisty.
nsAutoString twistyAttr;
element->GetAttribute(NS_ConvertASCIItoUCS2("twisty"), twistyAttr);
if (twistyAttr.EqualsWithConversion("true")) {
// Retrieve the parent treeitem.
nsCOMPtr<nsIDOMElement> treeItem;
GetTreeItem(element, getter_AddRefs(treeItem));
if (!treeItem)
return NS_OK;
nsAutoString empty;
treeItem->GetAttribute(NS_ConvertASCIItoUCS2("empty"), empty);
if (empty.EqualsWithConversion("true"))
return NS_OK;
// Eat the event.
aEvent->PreventCapture();
aEvent->PreventBubble();
aEvent->PreventDefault();
nsAutoString open;
treeItem->GetAttribute(NS_ConvertASCIItoUCS2("open"), open);
if (open.EqualsWithConversion("true"))
treeItem->RemoveAttribute(NS_ConvertASCIItoUCS2("open"));
else treeItem->SetAttribute(NS_ConvertASCIItoUCS2("open"), NS_ConvertASCIItoUCS2("true"));
}
return NS_OK;
}

Просмотреть файл

@ -31,7 +31,7 @@ Rights Reserved.
datasources="rdf:addressdirectory rdf:addresscard"
onselect="top.ResultsPaneSelectionChange(); document.commandDispatcher.updateCommands('tree-select');"
onblur="goOnEvent(this,'blur')"
onclick="if ( event.clickCount == 2 ) top.AbEditCard();"
onclick="if ( event.detail == 2 ) top.AbEditCard();"
containment="http://home.netscape.com/NC-rdf#CardChild"
allownegativeassertions="false"
coalesceduplicatearcs="false"

Просмотреть файл

@ -608,7 +608,7 @@ function ThreadPaneOnClick(event)
msgNavigationService.OpenTreeitemAndDescendants(treeitem);
}
}
else if(event.clickCount == 2)
else if(event.detail == 2)
{
ThreadPaneDoubleClick(event.target.parentNode.parentNode);
}
@ -681,7 +681,7 @@ function FolderPaneOnClick(event)
}
}
}
else if(event.clickCount == 2)
else if(event.detail == 2)
{
var item = event.target.parentNode.parentNode;
if (item.nodeName == "treeitem")

Просмотреть файл

@ -277,7 +277,7 @@ function ReverseState(uri)
function SubscribeOnClick(event)
{
if (event.clickCount == 2) {
if (event.detail == 2) {
ReverseStateFromNode(event.target.parentNode.parentNode);
}
else {

Просмотреть файл

@ -268,7 +268,7 @@ function HandleKeyEvent( aEvent )
function HandleClickEvent( aEvent )
{
if( aEvent.clickCount == 2 && aEvent.which == 1 ) {
if( aEvent.detail == 2 && aEvent.which == 1 ) {
if( aEvent.target.nodeName.toLowerCase() == "treecell" &&
aEvent.target.parentNode.parentNode.nodeName.toLowerCase() != "treehead" )
return onStart();

Просмотреть файл

@ -47,6 +47,7 @@
#include "nsRDFCID.h"
#include "nsXULCommandDispatcher.h"
#include "prlog.h"
#include "nsIDOMEventTarget.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gLog;
@ -350,7 +351,7 @@ nsXULCommandDispatcher::Focus(nsIDOMEvent* aEvent)
if (mSuppressFocus)
return NS_OK;
nsCOMPtr<nsIDOMNode> t;
nsCOMPtr<nsIDOMEventTarget> t;
aEvent->GetTarget(getter_AddRefs(t));
#ifdef DEBUG_hyatt
@ -419,7 +420,7 @@ nsXULCommandDispatcher::Blur(nsIDOMEvent* aEvent)
if (mSuppressFocus)
return NS_OK;
nsCOMPtr<nsIDOMNode> t;
nsCOMPtr<nsIDOMEventTarget> t;
aEvent->GetTarget(getter_AddRefs(t));
#ifdef DEBUG_hyatt

Просмотреть файл

@ -76,6 +76,7 @@
#include "nsIFormControl.h"
#include "nsIHTMLContent.h"
#include "nsIElementFactory.h"
#include "nsIEventStateManager.h"
#include "nsIInputStream.h"
#include "nsILoadGroup.h"
#include "nsINameSpace.h"
@ -573,6 +574,9 @@ nsXULDocument::QueryInterface(REFNSIID iid, void** result)
else if (iid.Equals(NS_GET_IID(nsIDOMNSDocument))) {
*result = NS_STATIC_CAST(nsIDOMNSDocument*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOMDocumentEvent))) {
*result = NS_STATIC_CAST(nsIDOMDocumentEvent*, this);
}
else if (iid.Equals(NS_GET_IID(nsIDOMDocumentView))) {
*result = NS_STATIC_CAST(nsIDOMDocumentView*, this);
}
@ -1952,9 +1956,10 @@ nsXULDocument::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
@ -1965,7 +1970,7 @@ nsXULDocument::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
@ -1974,7 +1979,7 @@ nsXULDocument::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;
@ -4002,6 +4007,52 @@ nsXULDocument::RemoveEventListener(const nsString& aType, nsIDOMEventListener* a
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::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(NS_STATIC_CAST(nsIDocument*, this), aEvent);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::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;
}
NS_IMETHODIMP
nsXULDocument::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -4031,7 +4082,7 @@ nsXULDocument::GetNewListenerManager(nsIEventListenerManager **aResult)
NS_IMETHODIMP
nsXULDocument::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
nsresult

Просмотреть файл

@ -67,6 +67,7 @@
#include "nsIStreamLoader.h"
#include "nsIBindingManager.h"
#include "nsINodeInfo.h"
#include "nsIDOMDocumentEvent.h"
class nsIAtom;
class nsIElementFactory;
@ -93,6 +94,7 @@ class nsXULDocument : public nsIDocument,
public nsIXULDocument,
public nsIStreamLoadableDocument,
public nsIDOMXULDocument,
public nsIDOMDocumentEvent,
public nsIDOMDocumentView,
public nsIDOMNSDocument,
public nsIDOMEventCapturer,
@ -335,10 +337,14 @@ public:
PRBool aUseCapture);
NS_IMETHOD RemoveEventListener(const nsString& aType, nsIDOMEventListener* aListener,
PRBool aUseCapture);
NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent);
// nsIDOMDocument interface
NS_DECL_IDOMDOCUMENT
// nsIDOMDocumentEvent interface
NS_DECL_IDOMDOCUMENTEVENT
// nsIDOMDocumentView interface
NS_DECL_IDOMDOCUMENTVIEW

Просмотреть файл

@ -2060,6 +2060,28 @@ nsXULElement::RemoveEventListener(const nsString& aType, nsIDOMEventListener* aL
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::DispatchEvent(nsIDOMEvent* aEvent)
{
// Obtain a presentation context
PRInt32 count = mDocument->GetNumberOfShells();
if (count == 0)
return NS_OK;
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(mDocument->GetShellAt(0));
// Retrieve the context
nsCOMPtr<nsIPresContext> aPresContext;
shell->GetPresContext(getter_AddRefs(aPresContext));
nsCOMPtr<nsIEventStateManager> esm;
if (NS_SUCCEEDED(aPresContext->GetEventStateManager(getter_AddRefs(esm)))) {
return esm->DispatchNewEvent(NS_STATIC_CAST(nsIStyledContent*, this), aEvent);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
{
@ -2090,7 +2112,7 @@ nsXULElement::GetNewListenerManager(nsIEventListenerManager **aResult)
NS_IMETHODIMP
nsXULElement::HandleEvent(nsIDOMEvent *aEvent)
{
return NS_ERROR_FAILURE;
return DispatchEvent(aEvent);
}
@ -3449,9 +3471,10 @@ nsXULElement::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);
// In order for the event to have a proper target for events that don't go through
// the presshell (onselect, oncommand, oncreate, ondestroy) we need to set our target
// ourselves. Also, key sets and menus don't have frames and therefore need their
@ -3474,7 +3497,8 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
NS_ERROR("Unable to instantiate a listener manager on this event.");
return ret;
}
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, aDOMEvent))) {
nsAutoString empty;
if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) {
NS_ERROR("This event will fail without the ability to create the event early.");
return ret;
}
@ -3522,7 +3546,7 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, aFlags, aEventStatus);
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;
}
@ -3556,7 +3580,7 @@ nsXULElement::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) {

Просмотреть файл

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

Просмотреть файл

@ -62,6 +62,7 @@
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIPresContext.h"
#include "nsIDOMEventTarget.h"
enum {
VK_CANCEL = 3,
@ -491,7 +492,7 @@ nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventTy
return ret;
// Get DOMEvent target
nsCOMPtr<nsIDOMNode> target = nsnull;
nsCOMPtr<nsIDOMEventTarget> target = nsnull;
aKeyEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsPIDOMWindow> piWindow;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше