diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 24454c75b86..de34946f457 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -1159,8 +1159,9 @@ nsGenericElement::InternalIsSupported(const nsAString& aFeature, PL_strcasecmp(f, "CSS") == 0 || PL_strcasecmp(f, "CSS2") == 0 || PL_strcasecmp(f, "Events") == 0 || -// PL_strcasecmp(f, "UIEvents") == 0 || + PL_strcasecmp(f, "UIEvents") == 0 || PL_strcasecmp(f, "MouseEvents") == 0 || + // Non-standard! PL_strcasecmp(f, "MouseScrollEvents") == 0 || PL_strcasecmp(f, "HTMLEvents") == 0 || PL_strcasecmp(f, "Range") == 0) { diff --git a/mozilla/content/events/public/nsIPrivateDOMEvent.h b/mozilla/content/events/public/nsIPrivateDOMEvent.h index 686cad07a82..3b2175f0f9a 100644 --- a/mozilla/content/events/public/nsIPrivateDOMEvent.h +++ b/mozilla/content/events/public/nsIPrivateDOMEvent.h @@ -38,7 +38,6 @@ #ifndef nsIPrivateDOMEvent_h__ #define nsIPrivateDOMEvent_h__ -#include "nsEvent.h" #include "nsISupports.h" class nsPresContext; @@ -53,6 +52,7 @@ class nsPresContext; class nsIDOMEventTarget; class nsIDOMEvent; +struct nsEvent; class nsIPrivateDOMEvent : public nsISupports { @@ -71,11 +71,18 @@ public: }; nsresult -NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, - nsPresContext* aPresContext, const nsAString& aEventType, - nsEvent *aEvent); +NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsEvent *aEvent); nsresult -NS_NewDOMMutationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, - nsEvent* aEvent); +NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsGUIEvent *aEvent); +nsresult +NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsInputEvent *aEvent); +nsresult +NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, struct nsKeyEvent *aEvent); +nsresult +NS_NewDOMMutationEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsMutationEvent* aEvent); +nsresult +NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsPopupBlockedEvent* aEvent); +nsresult +NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, struct nsTextEvent* aEvent); #endif // nsIPrivateDOMEvent_h__ diff --git a/mozilla/content/events/src/Makefile.in b/mozilla/content/events/src/Makefile.in index bc5597b90cf..d99de1c5d7d 100644 --- a/mozilla/content/events/src/Makefile.in +++ b/mozilla/content/events/src/Makefile.in @@ -67,7 +67,12 @@ CPPSRCS = \ nsEventListenerManager.cpp \ nsEventStateManager.cpp \ nsDOMEvent.cpp \ + nsDOMUIEvent.cpp \ + nsDOMKeyboardEvent.cpp \ + nsDOMTextEvent.cpp \ + nsDOMMouseEvent.cpp \ nsDOMMutationEvent.cpp \ + nsDOMPopupBlockedEvent.cpp \ nsPrivateTextRange.cpp \ nsDOMEventGroup.cpp \ nsXMLEventsManager.cpp \ diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index b9203ce325c..fa813c28a8d 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Steve Clark (buster@netscape.com) + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -38,29 +39,19 @@ #include "nsCOMPtr.h" #include "nsDOMEvent.h" -#include "nsIDOMNode.h" #include "nsIEventStateManager.h" #include "nsIFrame.h" #include "nsIContent.h" -#include "nsIRenderingContext.h" -#include "nsIWidget.h" #include "nsIPresShell.h" -#include "nsPrivateTextRange.h" #include "nsIDocument.h" -#include "nsIViewManager.h" #include "nsIPrivateCompositionEvent.h" -#include "nsIScrollableView.h" #include "nsIDOMEventTarget.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" -#include "nsIDOMWindowInternal.h" -#include "nsIDOMAbstractView.h" #include "prmem.h" #include "nsLayoutAtoms.h" #include "nsMutationEvent.h" #include "nsContentUtils.h" -#include "nsIDOMKeyEvent.h" -#include "nsIDOMMutationEvent.h" #include "nsIURI.h" static const char* const sEventNames[] = { @@ -77,89 +68,47 @@ static const char* const sEventNames[] = { "popupBlocked", "DOMActivate", "DOMFocusIn", "DOMFocusOut" }; -/** event pool used as a simple recycler for objects of this class */ -static PRUint8 gEventPool[ sizeof(nsDOMEvent) ]; - -/* declare static class data */ -PRBool nsDOMEvent::gEventPoolInUse=PR_FALSE; - -#ifdef NS_DEBUG // metrics for measuring event pool use -static PRInt32 numEvents=0; -static PRInt32 numNewEvents=0; -static PRInt32 numDelEvents=0; -static PRInt32 numAllocFromPool=0; -//#define NOISY_EVENT_LEAKS // define NOISY_EVENT_LEAKS to get metrics printed to stdout for all nsDOMEvent allocations -#endif - -// allocate the memory for the object from the recycler, if possible -// otherwise, just grab it from the heap. -void* -nsDOMEvent::operator new(size_t aSize) CPP_THROW_NEW +nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent) { - -#ifdef NS_DEBUG - numEvents++; -#endif - - void *result = nsnull; - - if (!gEventPoolInUse && aSize <= sizeof(gEventPool)) { -#ifdef NS_DEBUG - numAllocFromPool++; -#endif - result = &gEventPool; - gEventPoolInUse = PR_TRUE; - } - else { -#ifdef NS_DEBUG - numNewEvents++; -#endif - result = ::operator new(aSize); - } - - if (result) { - memset(result, 0, aSize); - } - - return result; -} - -// Overridden to prevent the global delete from being called on objects from -// the recycler. Otherwise, just pass through to the global delete operator. -void -nsDOMEvent::operator delete(void* aPtr) -{ - if (aPtr==&gEventPool) { - gEventPoolInUse = PR_FALSE; - } - else { -#ifdef NS_DEBUG - numDelEvents++; -#endif - ::operator delete(aPtr); - } -#if defined(NS_DEBUG) && defined(NOISY_EVENT_LEAKS) - printf("total events =%d, from pool = %d, concurrent live events = %d\n", - numEvents, numAllocFromPool, numNewEvents-numDelEvents); -#endif -} - - - -nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, - const nsAString& aEventType) -{ - mPresContext = aPresContext; mEventIsTrusted = PR_FALSE; if (aEvent) { mEvent = aEvent; + mEventIsInternal = PR_FALSE; mEventIsTrusted = PR_TRUE; } else { mEventIsInternal = PR_TRUE; - AllocateEvent(aEventType); + mEventIsTrusted = PR_FALSE; + /* + A derived class might want to allocate its own type of aEvent + (derived from nsEvent). To do this, it should take care to pass + a non-NULL aEvent to this ctor, e.g.: + + nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent) + : nsDOMEvent(..., aEvent ? aEvent : new nsFooEvent()) + + Then, to override the mEventIsInternal and mEventIsTrusted + assignments done by the base ctor, it should do this in its own ctor: + + nsDOMFooEvent::nsDOMFooEvent(..., nsEvent* aEvent) + ... + { + ... + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + } + ... + } + */ + mEvent = new nsEvent(); + mEvent->time = PR_Now(); } // Get the explicit original target (if it's anonymous make it null) @@ -176,58 +125,6 @@ nsDOMEvent::nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, } } } - mText = nsnull; - mButton = -1; - if (aEvent) { - mScreenPoint.x = aEvent->refPoint.x; - mScreenPoint.y = aEvent->refPoint.y; - mClientPoint.x = aEvent->point.x; - mClientPoint.y = aEvent->point.y; - } else - mScreenPoint.x = mScreenPoint.y = mClientPoint.x = mClientPoint.y = 0; - - if (aEvent && aEvent->eventStructType == NS_TEXT_EVENT) { - // - // extract the IME composition string - // - - nsTextEvent *te = (nsTextEvent*)aEvent; - - mText = new nsString(te->theText); - - // - // build the range list -- ranges need to be DOM-ified since the - // IME transaction will hold a ref, the widget representation - // isn't persistent - // - nsIPrivateTextRange** tempTextRangeList = - new nsIPrivateTextRange*[te->rangeCount]; - - if (tempTextRangeList) { - PRUint16 i; - - for(i = 0; i < te->rangeCount; i++) { - nsPrivateTextRange* tempPrivateTextRange = new - nsPrivateTextRange(te->rangeArray[i].mStartOffset, - te->rangeArray[i].mEndOffset, - te->rangeArray[i].mRangeType); - - if (tempPrivateTextRange) { - NS_ADDREF(tempPrivateTextRange); - - tempTextRangeList[i] = (nsIPrivateTextRange*)tempPrivateTextRange; - } - } - } - - // We need to create mTextRange even rangeCount is 0. - // If rangeCount is 0, mac carbon will return 0 for new and - // tempTextRangeList will be null. but we should still create - // mTextRange, otherwise, we will crash it later when some code - // call GetInputRange and AddRef to the result - - mTextRange = new nsPrivateTextRangeList(te->rangeCount ,tempTextRangeList); - } } nsDOMEvent::~nsDOMEvent() @@ -235,35 +132,19 @@ nsDOMEvent::~nsDOMEvent() NS_ASSERT_OWNINGTHREAD(nsDOMEvent); if (mEventIsInternal) { - if (mEvent->userType) { - delete mEvent->userType; - } - if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { - nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); - NS_IF_RELEASE(event->mRequestingWindowURI); - NS_IF_RELEASE(event->mPopupWindowURI); - } + delete mEvent->userType; delete mEvent; } - - delete mText; } NS_IMPL_ADDREF(nsDOMEvent) NS_IMPL_RELEASE(nsDOMEvent) NS_INTERFACE_MAP_BEGIN(nsDOMEvent) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEvent, nsIDOMMouseEvent) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMUIEvent, nsIDOMMouseEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMMouseEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMNSUIEvent) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMNSEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMPopupBlockedEvent) NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent) - NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent) - NS_INTERFACE_MAP_ENTRY(nsIPrivateCompositionEvent) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseEvent) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Event) NS_INTERFACE_MAP_END @@ -294,7 +175,7 @@ NS_METHOD nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget) return NS_OK; } - *aTarget = nsnull; + *aTarget = nsnull; nsCOMPtr targetContent; @@ -421,14 +302,14 @@ nsDOMEvent::GetEventPhase(PRUint16* aEventPhase) { if (mEvent->flags & NS_EVENT_FLAG_CAPTURE) { if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) { - *aEventPhase = nsIDOMMouseEvent::AT_TARGET; + *aEventPhase = nsIDOMEvent::AT_TARGET; } else { - *aEventPhase = nsIDOMMouseEvent::CAPTURING_PHASE; + *aEventPhase = nsIDOMEvent::CAPTURING_PHASE; } } else if (mEvent->flags & NS_EVENT_FLAG_BUBBLE) { - *aEventPhase = nsIDOMMouseEvent::BUBBLING_PHASE; + *aEventPhase = nsIDOMEvent::BUBBLING_PHASE; } else { *aEventPhase = 0; @@ -492,636 +373,6 @@ nsDOMEvent::PreventDefault() return NS_OK; } - -NS_IMETHODIMP -nsDOMEvent::GetView(nsIDOMAbstractView** aView) -{ - NS_ENSURE_ARG_POINTER(aView); - *aView = nsnull; - nsresult rv = NS_OK; - - if (mPresContext) { - nsCOMPtr container = mPresContext->GetContainer(); - NS_ENSURE_TRUE(container, NS_OK); - - nsCOMPtr window = do_GetInterface(container); - NS_ENSURE_TRUE(window, NS_OK); - - CallQueryInterface(window, aView); - } - - return rv; -} - -NS_IMETHODIMP -nsDOMEvent::GetDetail(PRInt32* aDetail) -{ - if (!mEvent) { - *aDetail = 0; - return NS_OK; - } - - switch(mEvent->eventStructType) - { - case NS_SCROLLPORT_EVENT: - { - nsScrollPortEvent* scrollEvent = (nsScrollPortEvent*)mEvent; - *aDetail = (PRInt32)scrollEvent->orient; - return NS_OK; - } - - case NS_MOUSE_EVENT: - { - 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: - case NS_USER_DEFINED_EVENT: - *aDetail = ((nsMouseEvent*)mEvent)->clickCount; - break; - default: - break; - } - return NS_OK; - } - - case NS_MOUSE_SCROLL_EVENT: - *aDetail = ((nsMouseScrollEvent*)mEvent)->delta; - break; - - case NS_DOMUI_EVENT: - *aDetail = ((nsDOMUIEvent*)mEvent)->detail; - break; - - default: - *aDetail = 0; - return NS_OK; - } - - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetText(nsString& aText) -{ - if (mEvent->message == NS_TEXT_TEXT) { - aText = *mText; - return NS_OK; - } - aText.Truncate(); - return NS_ERROR_FAILURE; -} - -NS_METHOD nsDOMEvent::GetInputRange(nsIPrivateTextRangeList** aInputRange) -{ - NS_ENSURE_ARG_POINTER(aInputRange); - if (mEvent->message == NS_TEXT_TEXT) { - *aInputRange = mTextRange; - return NS_OK; - } - *aInputRange = 0; - return NS_ERROR_FAILURE; -} - -NS_METHOD nsDOMEvent::GetEventReply(nsTextEventReply** aReply) -{ - NS_ENSURE_ARG_POINTER(aReply); - if (mEvent->message==NS_TEXT_TEXT) { - *aReply = &(((nsTextEvent*)mEvent)->theReply); - return NS_OK; - } - *aReply = 0; - return NS_ERROR_FAILURE; -} - -NS_METHOD nsDOMEvent::GetCompositionReply(nsTextEventReply** aReply) -{ - NS_ENSURE_ARG_POINTER(aReply); - if((mEvent->message==NS_COMPOSITION_START) || - (mEvent->message==NS_COMPOSITION_QUERY)) { - *aReply = &(((nsCompositionEvent*)mEvent)->theReply); - return NS_OK; - } - *aReply = 0; - return NS_ERROR_FAILURE; -} - -NS_METHOD -nsDOMEvent::GetReconversionReply(nsReconversionEventReply** aReply) -{ - NS_ENSURE_ARG_POINTER(aReply); - *aReply = &(((nsReconversionEvent*)mEvent)->theReply); - return NS_OK; -} - -nsPoint nsDOMEvent::GetScreenPoint() { - if (!mEvent || - (mEvent->eventStructType != NS_MOUSE_EVENT && - mEvent->eventStructType != NS_POPUP_EVENT && - !NS_IS_DRAG_EVENT(mEvent))) { - return nsPoint(0, 0); - } - - if (!((nsGUIEvent*)mEvent)->widget ) { - return mScreenPoint; - } - - nsRect bounds(mEvent->refPoint, nsSize(1, 1)); - nsRect offset; - ((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset ); - return offset.TopLeft(); -} - -NS_METHOD nsDOMEvent::GetScreenX(PRInt32* aScreenX) -{ - NS_ENSURE_ARG_POINTER(aScreenX); - *aScreenX = GetScreenPoint().x; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetScreenY(PRInt32* aScreenY) -{ - NS_ENSURE_ARG_POINTER(aScreenY); - *aScreenY = GetScreenPoint().y; - return NS_OK; -} - -nsPoint nsDOMEvent::GetClientPoint() { - if (!mEvent || - (mEvent->eventStructType != NS_MOUSE_EVENT && - mEvent->eventStructType != NS_POPUP_EVENT && - !NS_IS_DRAG_EVENT(mEvent)) || - !mPresContext) { - return nsPoint(0, 0); - } - - if (!((nsGUIEvent*)mEvent)->widget ) { - return mClientPoint; - } - - //My god, man, there *must* be a better way to do this. - nsCOMPtr docWidget; - nsIPresShell *presShell = mPresContext->GetPresShell(); - if (presShell) { - nsIViewManager* vm = presShell->GetViewManager(); - if (vm) { - vm->GetWidget(getter_AddRefs(docWidget)); - } - } - - nsPoint pt = mEvent->refPoint; - - nsCOMPtr eventWidget = ((nsGUIEvent*)mEvent)->widget; - while (eventWidget && docWidget != eventWidget) { - nsWindowType windowType; - eventWidget->GetWindowType(windowType); - if (windowType == eWindowType_popup) - break; - - nsRect bounds; - eventWidget->GetBounds(bounds); - pt += bounds.TopLeft(); - eventWidget = dont_AddRef(eventWidget->GetParent()); - } - - if (eventWidget != docWidget) { - // docWidget wasn't on the chain from the event widget to the root - // of the widget tree (or the nearest popup). OK, so now pt is - // relative to eventWidget; to get it relative to docWidget, we - // need to subtract docWidget's offset from eventWidget. - while (docWidget && docWidget != eventWidget) { - nsWindowType windowType; - docWidget->GetWindowType(windowType); - if (windowType == eWindowType_popup) { - // oh dear. the doc and the event were in different popups? - // That shouldn't happen. - NS_NOTREACHED("doc widget and event widget are in different popups. That's dumb."); - break; - } - - nsRect bounds; - docWidget->GetBounds(bounds); - pt -= bounds.TopLeft(); - docWidget = docWidget->GetParent(); - } - } - - return pt; -} - -NS_METHOD nsDOMEvent::GetClientX(PRInt32* aClientX) -{ - NS_ENSURE_ARG_POINTER(aClientX); - *aClientX = GetClientPoint().x; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetClientY(PRInt32* aClientY) -{ - NS_ENSURE_ARG_POINTER(aClientY); - *aClientY = GetClientPoint().y; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetAltKey(PRBool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = ((nsInputEvent*)mEvent)->isAlt; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCtrlKey(PRBool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = ((nsInputEvent*)mEvent)->isControl; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetShiftKey(PRBool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = ((nsInputEvent*)mEvent)->isShift; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetMetaKey(PRBool* aIsDown) -{ - NS_ENSURE_ARG_POINTER(aIsDown); - *aIsDown = ((nsInputEvent*)mEvent)->isMeta; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCharCode(PRUint32* aCharCode) -{ - NS_ENSURE_ARG_POINTER(aCharCode); - if (!mEvent || mEvent->eventStructType != NS_KEY_EVENT) { - *aCharCode = 0; - return NS_OK; - } - - switch (mEvent->message) { - case NS_KEY_UP: - case NS_KEY_DOWN: -#if defined(NS_DEBUG) && defined(DEBUG_brade) - printf("GetCharCode used for wrong key event; should use onkeypress.\n"); -#endif - *aCharCode = 0; - break; - case NS_KEY_PRESS: - *aCharCode = ((nsKeyEvent*)mEvent)->charCode; - break; - default: - break; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetKeyCode(PRUint32* aKeyCode) -{ - NS_ENSURE_ARG_POINTER(aKeyCode); - if (!mEvent || mEvent->eventStructType != NS_KEY_EVENT) { - *aKeyCode = 0; - return NS_OK; - } - - switch (mEvent->message) { - case NS_KEY_UP: - case NS_KEY_PRESS: - case NS_KEY_DOWN: - *aKeyCode = ((nsKeyEvent*)mEvent)->keyCode; - break; - default: - break; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetButton(PRUint16* aButton) -{ - NS_ENSURE_ARG_POINTER(aButton); - if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { - NS_WARNING("Tried to get mouse button for null or non-mouse event!"); - *aButton = (PRUint16)-1; - return NS_OK; - } - - // If button has been set then use that instead. - if (mButton > 0) { - *aButton = (PRUint16)mButton; - } - else { - 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: - *aButton = 0; - break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - *aButton = 1; - break; - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_CLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - *aButton = 2; - break; - default: - break; - } - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) -{ - NS_ENSURE_ARG_POINTER(aRelatedTarget); - *aRelatedTarget = nsnull; - - if (!mPresContext) { - return NS_OK; - } - - nsCOMPtr relatedContent; - mPresContext->EventStateManager()-> - GetEventRelatedContent(getter_AddRefs(relatedContent)); - if (!relatedContent) { - return NS_OK; - } - - return CallQueryInterface(relatedContent, aRelatedTarget); -} - -// nsINSEventInterface -NS_METHOD nsDOMEvent::GetLayerX(PRInt32* aLayerX) -{ - NS_ENSURE_ARG_POINTER(aLayerX); - if (!mEvent || (mEvent->eventStructType != NS_MOUSE_EVENT) || - !mPresContext) { - *aLayerX = 0; - return NS_OK; - } - - float t2p; - t2p = mPresContext->TwipsToPixels(); - *aLayerX = NSTwipsToIntPixels(mEvent->point.x, t2p); - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetLayerY(PRInt32* aLayerY) -{ - NS_ENSURE_ARG_POINTER(aLayerY); - if (!mEvent || (mEvent->eventStructType != NS_MOUSE_EVENT) || - !mPresContext) { - *aLayerY = 0; - return NS_OK; - } - - float t2p; - t2p = mPresContext->TwipsToPixels(); - *aLayerY = NSTwipsToIntPixels(mEvent->point.y, t2p); - return NS_OK; -} - -nsresult nsDOMEvent::GetScrollInfo(nsIScrollableView** aScrollableView, - float* aP2T, float* aT2P) -{ - NS_ENSURE_ARG_POINTER(aScrollableView); - NS_ENSURE_ARG_POINTER(aP2T); - NS_ENSURE_ARG_POINTER(aT2P); - if (!mPresContext) { - *aScrollableView = nsnull; - return NS_ERROR_FAILURE; - } - - *aP2T = mPresContext->PixelsToTwips(); - *aT2P = mPresContext->TwipsToPixels(); - - nsIPresShell *presShell = mPresContext->GetPresShell(); - if (presShell) { - nsIViewManager* vm = presShell->GetViewManager(); - if(vm) { - return vm->GetRootScrollableView(aScrollableView); - } - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetPageX(PRInt32* aPageX) -{ - NS_ENSURE_ARG_POINTER(aPageX); - nsresult ret = NS_OK; - PRInt32 scrollX = 0; - nsIScrollableView* view = nsnull; - float p2t, t2p; - - GetScrollInfo(&view, &p2t, &t2p); - if(view) { - nscoord xPos, yPos; - ret = view->GetScrollPosition(xPos, yPos); - scrollX = NSTwipsToIntPixels(xPos, t2p); - } - - if (NS_SUCCEEDED(ret)) { - ret = GetClientX(aPageX); - } - - if (NS_SUCCEEDED(ret)) { - *aPageX += scrollX; - } - - return ret; -} - -NS_METHOD nsDOMEvent::GetPageY(PRInt32* aPageY) -{ - NS_ENSURE_ARG_POINTER(aPageY); - nsresult ret = NS_OK; - PRInt32 scrollY = 0; - nsIScrollableView* view = nsnull; - float p2t, t2p; - - GetScrollInfo(&view, &p2t, &t2p); - if(view) { - nscoord xPos, yPos; - ret = view->GetScrollPosition(xPos, yPos); - scrollY = NSTwipsToIntPixels(yPos, t2p); - } - - if (NS_SUCCEEDED(ret)) { - ret = GetClientY(aPageY); - } - - if (NS_SUCCEEDED(ret)) { - *aPageY += scrollY; - } - - return ret; -} - -NS_METHOD nsDOMEvent::GetWhich(PRUint32* aWhich) -{ - NS_ENSURE_ARG_POINTER(aWhich); - switch (mEvent->eventStructType) { - case NS_KEY_EVENT: - switch (mEvent->message) { - case NS_KEY_UP: - case NS_KEY_DOWN: - return GetKeyCode(aWhich); - case NS_KEY_PRESS: - //Special case for 4xp bug 62878. Try to make value of which - //more closely mirror the values that 4.x gave for RETURN and BACKSPACE - { - PRUint32 keyCode = ((nsKeyEvent*)mEvent)->keyCode; - if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) { - *aWhich = keyCode; - return NS_OK; - } - return GetCharCode(aWhich); - } - default: - break; - } - case NS_MOUSE_EVENT: - { - PRUint16 button; - (void) GetButton(&button); - *aWhich = button + 1; - break; - } - default: - *aWhich = 0; - break; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetRangeParent(nsIDOMNode** aRangeParent) -{ - NS_ENSURE_ARG_POINTER(aRangeParent); - nsIFrame* targetFrame = nsnull; - - if (mPresContext) { - mPresContext->EventStateManager()->GetEventTarget(&targetFrame); - } - - *aRangeParent = nsnull; - - if (targetFrame) { - nsCOMPtr parent; - PRInt32 offset, endOffset; - PRBool beginOfContent; - if (NS_SUCCEEDED(targetFrame->GetContentAndOffsetsFromPoint(mPresContext, - mEvent->point, - getter_AddRefs(parent), - offset, - endOffset, - beginOfContent))) { - if (parent) { - return CallQueryInterface(parent, aRangeParent); - } - } - } - - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetRangeOffset(PRInt32* aRangeOffset) -{ - NS_ENSURE_ARG_POINTER(aRangeOffset); - nsIFrame* targetFrame = nsnull; - - if (mPresContext) { - mPresContext->EventStateManager()->GetEventTarget(&targetFrame); - } - - if (targetFrame) { - nsIContent* parent = nsnull; - PRInt32 endOffset; - PRBool beginOfContent; - if (NS_SUCCEEDED(targetFrame->GetContentAndOffsetsFromPoint(mPresContext, - mEvent->point, - &parent, - *aRangeOffset, - endOffset, - beginOfContent))) { - NS_IF_RELEASE(parent); - return NS_OK; - } - } - *aRangeOffset = 0; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetCancelBubble(PRBool* aCancelBubble) -{ - NS_ENSURE_ARG_POINTER(aCancelBubble); - if (mEvent->flags & NS_EVENT_FLAG_BUBBLE || mEvent->flags & NS_EVENT_FLAG_INIT) { - *aCancelBubble = (mEvent->flags &= NS_EVENT_FLAG_STOP_DISPATCH) ? PR_TRUE : PR_FALSE; - } - else { - *aCancelBubble = PR_FALSE; - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::SetCancelBubble(PRBool aCancelBubble) -{ - if (mEvent->flags & NS_EVENT_FLAG_BUBBLE || mEvent->flags & NS_EVENT_FLAG_INIT) { - if (aCancelBubble) { - mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH; - } - else { - mEvent->flags &= ~NS_EVENT_FLAG_STOP_DISPATCH; - } - } - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetIsChar(PRBool* aIsChar) -{ - NS_ENSURE_ARG_POINTER(aIsChar); - if (!mEvent) { - *aIsChar = PR_FALSE; - return NS_OK; - } - if (mEvent->eventStructType == NS_KEY_EVENT) { - *aIsChar = ((nsKeyEvent*)mEvent)->isChar; - return NS_OK; - } - if (mEvent->eventStructType == NS_TEXT_EVENT) { - *aIsChar = ((nsTextEvent*)mEvent)->isChar; - return NS_OK; - } - - *aIsChar = PR_FALSE; - return NS_OK; -} - -NS_METHOD nsDOMEvent::GetPreventDefault(PRBool* aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - if (!mEvent) { - *aReturn = PR_FALSE; - } - else { - *aReturn = (mEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) ? PR_TRUE : PR_FALSE; - } - - return NS_OK; -} - nsresult nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) { @@ -1188,13 +439,13 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) mEvent->message = NS_MUTATION_NODEREMOVEDFROMDOCUMENT; else if (atom == nsLayoutAtoms::onDOMSubtreeModified) mEvent->message = NS_MUTATION_SUBTREEMODIFIED; - } else if (mEvent->eventStructType == NS_DOMUI_EVENT) { + } else if (mEvent->eventStructType == NS_UI_EVENT) { if (atom == nsLayoutAtoms::onDOMActivate) - mEvent->message = NS_DOMUI_ACTIVATE; + mEvent->message = NS_UI_ACTIVATE; else if (atom == nsLayoutAtoms::onDOMFocusIn) - mEvent->message = NS_DOMUI_FOCUSIN; + mEvent->message = NS_UI_FOCUSIN; else if (atom == nsLayoutAtoms::onDOMFocusOut) - mEvent->message = NS_DOMUI_FOCUSOUT; + mEvent->message = NS_UI_FOCUSOUT; } if (mEvent->message == NS_USER_DEFINED_EVENT) @@ -1213,151 +464,6 @@ nsDOMEvent::InitEvent(const nsAString& aEventTypeArg, PRBool aCanBubbleArg, PRBo return NS_OK; } -NS_IMETHODIMP -nsDOMEvent::InitUIEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, - nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg) -{ - nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); - - if (mEvent->eventStructType == NS_DOMUI_EVENT) { - nsDOMUIEvent *event = NS_STATIC_CAST(nsDOMUIEvent*, mEvent); - event->detail = aDetailArg; - return NS_OK; - } - - NS_ERROR("event type mismatch"); - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDOMEvent::InitMouseEvent(const nsAString & aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, - nsIDOMAbstractView *aViewArg, PRInt32 aDetailArg, PRInt32 aScreenXArg, - PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, - PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, - PRBool aMetaKeyArg, PRUint16 aButtonArg, nsIDOMEventTarget *aRelatedTargetArg) -{ - nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); - - NS_ASSERTION(mEvent->eventStructType == NS_MOUSE_EVENT || mEvent->eventStructType == NS_MOUSE_SCROLL_EVENT, "event type mismatch"); - if (mEvent->eventStructType == NS_MOUSE_EVENT || mEvent->eventStructType == NS_MOUSE_SCROLL_EVENT) { - nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, mEvent); - inputEvent->isControl = aCtrlKeyArg; - inputEvent->isAlt = aAltKeyArg; - inputEvent->isShift = aShiftKeyArg; - inputEvent->isMeta = aMetaKeyArg; - inputEvent->point.x = aClientXArg; - inputEvent->point.y = aClientYArg; - inputEvent->refPoint.x = aScreenXArg; - inputEvent->refPoint.y = aScreenYArg; - mScreenPoint.x = aScreenXArg; - mScreenPoint.y = aScreenYArg; - mClientPoint.x = aClientXArg; - mClientPoint.y = aClientYArg; - mButton = aButtonArg; - if (mEvent->eventStructType == NS_MOUSE_SCROLL_EVENT) { - nsMouseScrollEvent* scrollEvent = NS_STATIC_CAST(nsMouseScrollEvent*, mEvent); - scrollEvent->delta = aDetailArg; - } else { - nsMouseEvent* mouseEvent = NS_STATIC_CAST(nsMouseEvent*, mEvent); - mouseEvent->clickCount = aDetailArg; - } - return NS_OK; - } - //include a way to set view once we have more than one - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDOMEvent::InitKeyEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, - nsIDOMAbstractView* aViewArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, - PRBool aShiftKeyArg, PRBool aMetaKeyArg, - PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg) -{ - nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); - - NS_ASSERTION(mEvent->eventStructType == NS_KEY_EVENT, "event type mismatch"); - if (mEvent->eventStructType == NS_KEY_EVENT) { - nsKeyEvent* keyEvent = NS_STATIC_CAST(nsKeyEvent*, mEvent); - keyEvent->isControl = aCtrlKeyArg; - keyEvent->isAlt = aAltKeyArg; - keyEvent->isShift = aShiftKeyArg; - keyEvent->isMeta = aMetaKeyArg; - keyEvent->keyCode = aKeyCodeArg; - keyEvent->charCode = aCharCodeArg; - return NS_OK; - } - //include a way to set view once we have more than one - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsDOMEvent::InitPopupBlockedEvent(const nsAString & aTypeArg, - PRBool aCanBubbleArg, PRBool aCancelableArg, - nsIURI *aRequestingWindowURI, - nsIURI *aPopupWindowURI, - const nsAString & aPopupWindowFeatures) -{ - nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); - NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); - - NS_ASSERTION(mEvent->eventStructType == NS_POPUPBLOCKED_EVENT, "event type mismatch"); - if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { - nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); - event->mRequestingWindowURI = aRequestingWindowURI; - event->mPopupWindowURI = aPopupWindowURI; - NS_IF_ADDREF(event->mRequestingWindowURI); - NS_IF_ADDREF(event->mPopupWindowURI); - event->mPopupWindowFeatures = aPopupWindowFeatures; - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -/* readonly attribute nsIURI requestingWindowURI; */ -NS_IMETHODIMP nsDOMEvent::GetRequestingWindowURI(nsIURI **aRequestingWindowURI) -{ - NS_ENSURE_ARG_POINTER(aRequestingWindowURI); - if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { - nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); - *aRequestingWindowURI = event->mRequestingWindowURI; - NS_IF_ADDREF(*aRequestingWindowURI); - return NS_OK; - } - *aRequestingWindowURI = 0; - return NS_OK; // Don't throw an exception -} - -/* readonly attribute nsIURI popupWindowURI; */ -NS_IMETHODIMP nsDOMEvent::GetPopupWindowURI(nsIURI **aPopupWindowURI) -{ - NS_ENSURE_ARG_POINTER(aPopupWindowURI); - if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { - nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); - *aPopupWindowURI = event->mPopupWindowURI; - NS_IF_ADDREF(*aPopupWindowURI); - return NS_OK; - } - *aPopupWindowURI = 0; - return NS_OK; // Don't throw an exception -} - -/* readonly attribute DOMString popupFeatures; */ -NS_IMETHODIMP nsDOMEvent::GetPopupWindowFeatures(nsAString &aPopupWindowFeatures) -{ - if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { - nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); - aPopupWindowFeatures = event->mPopupWindowFeatures; - return NS_OK; - } - aPopupWindowFeatures.Truncate(); - return NS_OK; // Don't throw an exception -} - NS_METHOD nsDOMEvent::DuplicatePrivateData() { //XXX Write me! @@ -1540,11 +646,11 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) case NS_CONTEXTMENU: case NS_CONTEXTMENU_KEY: return sEventNames[eDOMEvents_contextmenu]; - case NS_DOMUI_ACTIVATE: + case NS_UI_ACTIVATE: return sEventNames[eDOMEvents_DOMActivate]; - case NS_DOMUI_FOCUSIN: + case NS_UI_FOCUSIN: return sEventNames[eDOMEvents_DOMFocusIn]; - case NS_DOMUI_FOCUSOUT: + case NS_UI_FOCUSOUT: return sEventNames[eDOMEvents_DOMFocusOut]; default: break; @@ -1552,48 +658,14 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) return nsnull; } -nsresult -NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, - nsPresContext* aPresContext, const nsAString& aEventType, - nsEvent *aEvent) +nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsEvent *aEvent) { - nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent, aEventType); - + nsDOMEvent* it = new nsDOMEvent(aPresContext, aEvent); if (nsnull == it) { return NS_ERROR_OUT_OF_MEMORY; } return CallQueryInterface(it, aInstancePtrResult); } - -void -nsDOMEvent::AllocateEvent(const nsAString& aEventType) -{ - //Allocate internal event - nsAutoString eventType(aEventType); - if (eventType.LowerCaseEqualsLiteral("mouseevents")) { - mEvent = new nsMouseEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("mousescrollevents")) { - mEvent = new nsMouseScrollEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("keyevents")) { - mEvent = new nsKeyEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("mutationevents")) { - mEvent = new nsMutationEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("popupevents")) { - mEvent = new nsGUIEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("popupblockedevents")) { - mEvent = new nsPopupBlockedEvent(); - } - else if (eventType.LowerCaseEqualsLiteral("uievents")) { - mEvent = new nsDOMUIEvent(); - } - else { - mEvent = new nsEvent(); - } - mEvent->time = PR_Now(); -} diff --git a/mozilla/content/events/src/nsDOMEvent.h b/mozilla/content/events/src/nsDOMEvent.h index c1122879ddf..4b6fd571640 100644 --- a/mozilla/content/events/src/nsDOMEvent.h +++ b/mozilla/content/events/src/nsDOMEvent.h @@ -38,34 +38,29 @@ #ifndef nsDOMEvent_h__ #define nsDOMEvent_h__ -#include "nsIDOMKeyEvent.h" -#include "nsIDOMMouseEvent.h" -#include "nsIDOMPopupBlockedEvent.h" -#include "nsIDOMNSUIEvent.h" +#include "nsIDOMEvent.h" #include "nsIDOMNSEvent.h" #include "nsISupports.h" #include "nsIPrivateDOMEvent.h" -#include "nsIPrivateCompositionEvent.h" -#include "nsIPrivateTextEvent.h" -#include "nsIPrivateTextRange.h" -#include "nsIDOMEvent.h" #include "nsCOMPtr.h" #include "nsIDOMEventTarget.h" #include "nsPresContext.h" #include "nsPoint.h" #include "nsGUIEvent.h" +#include "nsRecycled.h" class nsIContent; class nsIScrollableView; -class nsDOMEvent : public nsIDOMKeyEvent, +/* Currently we use a single-object recycler (nsRecycledSingle). + * With our current usage pattern, we almost never have more than + * a single nsDOMEvent active in memory at a time under normal circumstances. + */ + +class nsDOMEvent : public nsIDOMEvent, public nsIDOMNSEvent, - public nsIDOMMouseEvent, - public nsIDOMPopupBlockedEvent, - public nsIDOMNSUIEvent, public nsIPrivateDOMEvent, - public nsIPrivateTextEvent, - public nsIPrivateCompositionEvent + public nsRecycledSingle { public: @@ -127,8 +122,7 @@ public: eDOMEvents_DOMFocusOut }; - nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, - const nsAString& aEventType); + nsDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent); virtual ~nsDOMEvent(); NS_DECL_ISUPPORTS @@ -139,32 +133,6 @@ public: // nsIDOMNSEvent Interface NS_DECL_NSIDOMNSEVENT - // nsIDOMUIEvent Interface - NS_DECL_NSIDOMUIEVENT - - // nsIDOMPopupBlockedEvent interface - NS_DECL_NSIDOMPOPUPBLOCKEDEVENT - - // nsIDOMMouseEvent interface - NS_DECL_NSIDOMMOUSEEVENT - - // nsIDOMKeyEvent interface - NS_IMETHOD GetCharCode(PRUint32 *aCharCode); - NS_IMETHOD GetKeyCode(PRUint32 *aKeyCode); - // defined in nsIDOMMouseEvent - // NS_IMETHOD GetAltKey(PRBool *aAltKey); - // NS_IMETHOD GetCtrlKey(PRBool *aCtrlKey); - // NS_IMETHOD GetShiftKey(PRBool *aShiftKey); - // NS_IMETHOD GetMetaKey(PRBool *aMetaKey); - NS_IMETHOD InitKeyEvent(const nsAString &aTypeTag, PRBool aCanBubbleArg, - PRBool aCancelableArg, nsIDOMAbstractView *aViewArg, - PRBool aCtrlKeyArg, PRBool aAltKeyArg, - PRBool aShiftKeyArg, PRBool aMetaKeyArg, - PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg); - - // nsIDOMNSUIEvent interface - NS_DECL_NSIDOMNSUIEVENT - // nsIPrivateDOMEvent interface NS_IMETHOD DuplicatePrivateData(); NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget); @@ -179,47 +147,12 @@ public: NS_IMETHOD IsHandled(PRBool* aHandled); NS_IMETHOD SetHandled(PRBool aHandled); - // nsIPrivateTextEvent interface - NS_IMETHOD GetText(nsString& aText); - NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange); - NS_IMETHOD GetEventReply(nsTextEventReply** aReply); - - // nsIPrivateCompositionEvent interface - NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply); - NS_IMETHOD GetReconversionReply(nsReconversionEventReply** aReply); - - /** Overloaded new operator. Initializes the memory to 0. - * Relies on a recycler to perform the allocation, - * optionally from a pool. - */ - void* operator new(size_t sz) CPP_THROW_NEW; - - /** Overloaded delete operator. Relies on a recycler to either - * recycle the object or call the global delete operator, as needed. - */ - void operator delete(void* aPtr); - protected: - nsDOMEvent() {}; // private constructor for pool, not for general use - - /** bit to say whether the event pool is in use or not. - * note that it would be trivial to make this a bitmap if we ever - * wanted to increase the size of the pool from one. But with our - * current usage pattern, we almost never have more than a single - * nsDOMEvent active in memory at a time under normal circumstances. - */ - static PRBool gEventPoolInUse; - - //Internal helper funcs - nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, - float* aT2P); + // Internal helper functions nsresult SetEventType(const nsAString& aEventTypeArg); - const char* GetEventName(PRUint32 aEventType); + static const char* GetEventName(PRUint32 aEventType); already_AddRefed GetTargetFromFrame(); - void AllocateEvent(const nsAString& aEventType); - nsPoint GetClientPoint(); - nsPoint GetScreenPoint(); nsEvent* mEvent; nsCOMPtr mPresContext; @@ -228,17 +161,13 @@ protected: nsCOMPtr mOriginalTarget; nsCOMPtr mExplicitOriginalTarget; nsCOMPtr mTmpRealOriginalTarget; - nsString* mText; - nsCOMPtr mTextRange; PRPackedBool mEventIsInternal; PRPackedBool mEventIsTrusted; - //These are use for internal data for user created events - PRInt16 mButton; - nsPoint mScreenPoint; - nsPoint mClientPoint; - void* mScriptObject; }; +#define NS_FORWARD_TO_NSDOMEVENT \ + NS_FORWARD_NSIDOMEVENT(nsDOMEvent::) + #endif // nsDOMEvent_h__ diff --git a/mozilla/content/events/src/nsDOMKeyboardEvent.cpp b/mozilla/content/events/src/nsDOMKeyboardEvent.cpp new file mode 100644 index 00000000000..0c1ec2e2862 --- /dev/null +++ b/mozilla/content/events/src/nsDOMKeyboardEvent.cpp @@ -0,0 +1,201 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Steve Clark (buster@netscape.com) + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDOMKeyboardEvent.h" +#include "nsContentUtils.h" + + +nsDOMKeyboardEvent::nsDOMKeyboardEvent(nsPresContext* aPresContext, nsKeyEvent* aEvent) +: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsKeyEvent()) +{ + NS_ASSERTION(mEvent->eventStructType == NS_KEY_EVENT, "event type mismatch"); + + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + mEvent->time = PR_Now(); + } +} + +NS_IMPL_ADDREF_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMKeyboardEvent, nsDOMUIEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(KeyboardEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent) + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetAltKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isAlt; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetCtrlKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isControl; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetShiftKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isShift; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetMetaKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isMeta; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetCharCode(PRUint32* aCharCode) +{ + NS_ENSURE_ARG_POINTER(aCharCode); + + switch (mEvent->message) { + case NS_KEY_UP: + case NS_KEY_DOWN: +#if defined(NS_DEBUG) && defined(DEBUG_brade) + printf("GetCharCode used for wrong key event; should use onkeypress.\n"); +#endif + *aCharCode = 0; + break; + case NS_KEY_PRESS: + *aCharCode = ((nsKeyEvent*)mEvent)->charCode; + break; + default: + break; + } + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetKeyCode(PRUint32* aKeyCode) +{ + NS_ENSURE_ARG_POINTER(aKeyCode); + + switch (mEvent->message) { + case NS_KEY_UP: + case NS_KEY_PRESS: + case NS_KEY_DOWN: + *aKeyCode = ((nsKeyEvent*)mEvent)->keyCode; + break; + default: + *aKeyCode = 0; + break; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::GetWhich(PRUint32* aWhich) +{ + NS_ENSURE_ARG_POINTER(aWhich); + + switch (mEvent->message) { + case NS_KEY_UP: + case NS_KEY_DOWN: + return GetKeyCode(aWhich); + case NS_KEY_PRESS: + //Special case for 4xp bug 62878. Try to make value of which + //more closely mirror the values that 4.x gave for RETURN and BACKSPACE + { + PRUint32 keyCode = ((nsKeyEvent*)mEvent)->keyCode; + if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) { + *aWhich = keyCode; + return NS_OK; + } + return GetCharCode(aWhich); + } + break; + default: + *aWhich = 0; + break; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMKeyboardEvent::InitKeyEvent(const nsAString& aType, PRBool aCanBubble, PRBool aCancelable, + nsIDOMAbstractView* aView, PRBool aCtrlKey, PRBool aAltKey, + PRBool aShiftKey, PRBool aMetaKey, + PRUint32 aKeyCode, PRUint32 aCharCode) +{ + nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0); + NS_ENSURE_SUCCESS(rv, rv); + + nsKeyEvent* keyEvent = NS_STATIC_CAST(nsKeyEvent*, mEvent); + keyEvent->isControl = aCtrlKey; + keyEvent->isAlt = aAltKey; + keyEvent->isShift = aShiftKey; + keyEvent->isMeta = aMetaKey; + keyEvent->keyCode = aKeyCode; + keyEvent->charCode = aCharCode; + + return NS_OK; +} + +nsresult NS_NewDOMKeyboardEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsKeyEvent *aEvent) +{ + nsDOMKeyboardEvent* it = new nsDOMKeyboardEvent(aPresContext, aEvent); + if (nsnull == it) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/mozilla/content/events/src/nsDOMKeyboardEvent.h b/mozilla/content/events/src/nsDOMKeyboardEvent.h new file mode 100644 index 00000000000..6eb8245c107 --- /dev/null +++ b/mozilla/content/events/src/nsDOMKeyboardEvent.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMKeyboardEvent_h__ +#define nsDOMKeyboardEvent_h__ + +#include "nsIDOMKeyEvent.h" +#include "nsDOMUIEvent.h" + +class nsDOMKeyboardEvent : public nsIDOMKeyEvent, + public nsDOMUIEvent +{ +public: + nsDOMKeyboardEvent(nsPresContext* aPresContext, nsKeyEvent* aEvent); + + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMKeyEvent Interface + NS_DECL_NSIDOMKEYEVENT + + // Forward to base class + NS_FORWARD_TO_NSDOMUIEVENT_NO_WHICH + + // Specific implementation for a keyboard event. + NS_IMETHOD GetWhich(PRUint32 *aWhich); +}; + + +#endif // nsDOMKeyboardEvent_h__ diff --git a/mozilla/content/events/src/nsDOMMouseEvent.cpp b/mozilla/content/events/src/nsDOMMouseEvent.cpp new file mode 100644 index 00000000000..ab63144982c --- /dev/null +++ b/mozilla/content/events/src/nsDOMMouseEvent.cpp @@ -0,0 +1,271 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Steve Clark (buster@netscape.com) + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDOMMouseEvent.h" +#include "nsGUIEvent.h" +#include "nsIContent.h" +#include "nsIEventStateManager.h" +#include "nsContentUtils.h" + +nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext, nsInputEvent* aEvent) +: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsMouseEvent()), mButton(-1) +{ + // There's no way to make this class' ctor allocate an nsMouseScrollEvent. + // It's not that important, though, since a scroll event is not a real + // DOM event. + + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + mEvent->time = PR_Now(); + mEvent->refPoint.x = mEvent->refPoint.y = mEvent->point.x = mEvent->point.y = 0; + } + + switch (mEvent->eventStructType) + { + case NS_MOUSE_EVENT: + mDetail = NS_STATIC_CAST(nsMouseEvent*, mEvent)->clickCount; + break; + case NS_MOUSE_SCROLL_EVENT: + mDetail = NS_STATIC_CAST(nsMouseScrollEvent*, mEvent)->delta; + break; + default: + break; + } +} + +NS_IMPL_ADDREF_INHERITED(nsDOMMouseEvent, nsDOMUIEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMMouseEvent, nsDOMUIEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMMouseEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMMouseEvent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MouseEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent) + +NS_IMETHODIMP +nsDOMMouseEvent::InitMouseEvent(const nsAString & aType, PRBool aCanBubble, PRBool aCancelable, + nsIDOMAbstractView *aView, PRInt32 aDetail, PRInt32 aScreenX, + PRInt32 aScreenY, PRInt32 aClientX, PRInt32 aClientY, + PRBool aCtrlKey, PRBool aAltKey, PRBool aShiftKey, + PRBool aMetaKey, PRUint16 aButton, nsIDOMEventTarget *aRelatedTarget) +{ + nsresult rv = nsDOMUIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, aDetail); + NS_ENSURE_SUCCESS(rv, rv); + + switch(mEvent->eventStructType) + { + case NS_MOUSE_EVENT: + case NS_MOUSE_SCROLL_EVENT: + { + nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, mEvent); + inputEvent->isControl = aCtrlKey; + inputEvent->isAlt = aAltKey; + inputEvent->isShift = aShiftKey; + inputEvent->isMeta = aMetaKey; + inputEvent->point.x = aClientX; + inputEvent->point.y = aClientY; + inputEvent->refPoint.x = aScreenX; + inputEvent->refPoint.y = aScreenY; + mButton = aButton; + if (mEvent->eventStructType == NS_MOUSE_SCROLL_EVENT) { + nsMouseScrollEvent* scrollEvent = NS_STATIC_CAST(nsMouseScrollEvent*, mEvent); + scrollEvent->delta = aDetail; + } else { + nsMouseEvent* mouseEvent = NS_STATIC_CAST(nsMouseEvent*, mEvent); + mouseEvent->clickCount = aDetail; + } + break; + } + default: + break; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetButton(PRUint16* aButton) +{ + NS_ENSURE_ARG_POINTER(aButton); + if (!mEvent || mEvent->eventStructType != NS_MOUSE_EVENT) { + NS_WARNING("Tried to get mouse button for null or non-mouse event!"); + *aButton = (PRUint16)-1; + return NS_OK; + } + + // If button has been set then use that instead. + if (mButton > 0) { + *aButton = (PRUint16)mButton; + } + else { + 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: + *aButton = 0; + break; + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_CLICK: + case NS_MOUSE_MIDDLE_DOUBLECLICK: + *aButton = 1; + break; + case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_RIGHT_DOUBLECLICK: + *aButton = 2; + break; + default: + break; + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) +{ + NS_ENSURE_ARG_POINTER(aRelatedTarget); + *aRelatedTarget = nsnull; + + if (!mPresContext) { + return NS_OK; + } + + nsCOMPtr relatedContent; + mPresContext->EventStateManager()-> + GetEventRelatedContent(getter_AddRefs(relatedContent)); + if (!relatedContent) { + return NS_OK; + } + + return CallQueryInterface(relatedContent, aRelatedTarget); +} + +NS_METHOD nsDOMMouseEvent::GetScreenX(PRInt32* aScreenX) +{ + NS_ENSURE_ARG_POINTER(aScreenX); + *aScreenX = GetScreenPoint().x; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetScreenY(PRInt32* aScreenY) +{ + NS_ENSURE_ARG_POINTER(aScreenY); + *aScreenY = GetScreenPoint().y; + return NS_OK; +} + + +NS_METHOD nsDOMMouseEvent::GetClientX(PRInt32* aClientX) +{ + NS_ENSURE_ARG_POINTER(aClientX); + *aClientX = GetClientPoint().x; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetClientY(PRInt32* aClientY) +{ + NS_ENSURE_ARG_POINTER(aClientY); + *aClientY = GetClientPoint().y; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetAltKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isAlt; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetCtrlKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isControl; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetShiftKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isShift; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetMetaKey(PRBool* aIsDown) +{ + NS_ENSURE_ARG_POINTER(aIsDown); + *aIsDown = ((nsInputEvent*)mEvent)->isMeta; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMMouseEvent::GetWhich(PRUint32* aWhich) +{ + NS_ENSURE_ARG_POINTER(aWhich); + PRUint16 button; + (void) GetButton(&button); + *aWhich = button + 1; + return NS_OK; +} + +nsresult NS_NewDOMMouseEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsInputEvent *aEvent) +{ + nsDOMMouseEvent* it = new nsDOMMouseEvent(aPresContext, aEvent); + if (nsnull == it) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/mozilla/content/events/src/nsDOMMouseEvent.h b/mozilla/content/events/src/nsDOMMouseEvent.h new file mode 100644 index 00000000000..2cd04d9b8d2 --- /dev/null +++ b/mozilla/content/events/src/nsDOMMouseEvent.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMMouseEvent_h__ +#define nsDOMMouseEvent_h__ + +#include "nsIDOMMouseEvent.h" +#include "nsDOMUIEvent.h" + +class nsIContent; +class nsIScrollableView; +struct nsEvent; + +class nsDOMMouseEvent : public nsIDOMMouseEvent, + public nsDOMUIEvent +{ +public: + nsDOMMouseEvent(nsPresContext* aPresContext, nsInputEvent* aEvent); + + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMMouseEvent Interface + NS_DECL_NSIDOMMOUSEEVENT + + // Forward to base class + NS_FORWARD_TO_NSDOMUIEVENT_NO_WHICH + + // Specific implementation for a mouse event. + NS_IMETHOD GetWhich(PRUint32 *aWhich); + +protected: + // These are used for internal data for user created events + PRInt16 mButton; +}; + +#endif // nsDOMMouseEvent_h__ diff --git a/mozilla/content/events/src/nsDOMMutationEvent.cpp b/mozilla/content/events/src/nsDOMMutationEvent.cpp index 36a4567bbb6..9dd247679c6 100644 --- a/mozilla/content/events/src/nsDOMMutationEvent.cpp +++ b/mozilla/content/events/src/nsDOMMutationEvent.cpp @@ -36,96 +36,70 @@ * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" -#include "nsIDOMMutationEvent.h" -#include "nsDOMEvent.h" +#include "nsDOMMutationEvent.h" #include "nsMutationEvent.h" #include "nsContentUtils.h" class nsPresContext; -class nsDOMMutationEvent : public nsDOMEvent, public nsIDOMMutationEvent -{ - NS_DECL_NSIDOMMUTATIONEVENT - NS_FORWARD_NSIDOMEVENT(nsDOMEvent::) - - NS_DECL_ISUPPORTS_INHERITED - - nsDOMMutationEvent(nsPresContext* aPresContext, - nsEvent* aEvent); - - ~nsDOMMutationEvent(); -}; - -nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext, - nsEvent* aEvent) - :nsDOMEvent(aPresContext, aEvent, NS_LITERAL_STRING("MutationEvents")) +nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext, nsMutationEvent* aEvent) + :nsDOMEvent(aPresContext, aEvent ? aEvent : new nsMutationEvent()) { if ( aEvent ) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; nsMutationEvent* mutation = (nsMutationEvent*)aEvent; SetTarget(mutation->mTarget); } -} - -nsDOMMutationEvent::~nsDOMMutationEvent() { - + else + { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + } } NS_INTERFACE_MAP_BEGIN(nsDOMMutationEvent) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMutationEvent) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEvent, nsIDOMMutationEvent) - NS_INTERFACE_MAP_ENTRY(nsIPrivateDOMEvent) NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MutationEvent) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent) NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent) NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent) - NS_IMETHODIMP nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode) { *aRelatedNode = nsnull; - if (mEvent) { - nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - *aRelatedNode = mutation->mRelatedNode; - NS_IF_ADDREF(*aRelatedNode); - } - else *aRelatedNode = nsnull; - + nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); + *aRelatedNode = mutation->mRelatedNode; + NS_IF_ADDREF(*aRelatedNode); return NS_OK; } NS_IMETHODIMP nsDOMMutationEvent::GetPrevValue(nsAString& aPrevValue) { - if (mEvent) { - nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - if (mutation && mutation->mPrevAttrValue) - mutation->mPrevAttrValue->ToString(aPrevValue); - } + nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); + if (mutation->mPrevAttrValue) + mutation->mPrevAttrValue->ToString(aPrevValue); return NS_OK; } NS_IMETHODIMP nsDOMMutationEvent::GetNewValue(nsAString& aNewValue) { - if (mEvent) { - nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - if (mutation && mutation->mNewAttrValue) + nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); + if (mutation->mNewAttrValue) mutation->mNewAttrValue->ToString(aNewValue); - } return NS_OK; } NS_IMETHODIMP nsDOMMutationEvent::GetAttrName(nsAString& aAttrName) { - if (mEvent) { - nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - if (mutation && mutation->mAttrName) + nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); + if (mutation->mAttrName) mutation->mAttrName->ToString(aAttrName); - } return NS_OK; } @@ -133,45 +107,35 @@ NS_IMETHODIMP nsDOMMutationEvent::GetAttrChange(PRUint16* aAttrChange) { *aAttrChange = 0; - if (mEvent) { - nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - if (mutation && mutation->mAttrChange) + nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); + if (mutation->mAttrChange) *aAttrChange = mutation->mAttrChange; - } return NS_OK; } NS_IMETHODIMP -nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, - PRBool aCancelableArg, nsIDOMNode* aRelatedNodeArg, - const nsAString& aPrevValueArg, - const nsAString& aNewValueArg, - const nsAString& aAttrNameArg, - PRUint16 aAttrChangeArg) +nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMNode* aRelatedNodeArg, const nsAString& aPrevValueArg, const nsAString& aNewValueArg, const nsAString& aAttrNameArg, PRUint16 aAttrChangeArg) { - 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; + nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); + NS_ENSURE_SUCCESS(rv, rv); nsMutationEvent* mutation = NS_STATIC_CAST(nsMutationEvent*, mEvent); - if (mutation) { - mutation->mRelatedNode = aRelatedNodeArg; - if (!aPrevValueArg.IsEmpty()) - mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg); - if (!aNewValueArg.IsEmpty()) - mutation->mNewAttrValue = do_GetAtom(aNewValueArg); - if (!aAttrNameArg.IsEmpty()) { - mutation->mAttrName = do_GetAtom(aAttrNameArg); - } - mutation->mAttrChange = aAttrChangeArg; + mutation->mRelatedNode = aRelatedNodeArg; + if (!aPrevValueArg.IsEmpty()) + mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg); + if (!aNewValueArg.IsEmpty()) + mutation->mNewAttrValue = do_GetAtom(aNewValueArg); + if (!aAttrNameArg.IsEmpty()) { + mutation->mAttrName = do_GetAtom(aAttrNameArg); } + mutation->mAttrChange = aAttrChangeArg; return NS_OK; } nsresult NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, - nsEvent *aEvent) + nsMutationEvent *aEvent) { nsDOMMutationEvent* it = new nsDOMMutationEvent(aPresContext, aEvent); if (nsnull == it) { diff --git a/mozilla/content/events/src/nsDOMMutationEvent.h b/mozilla/content/events/src/nsDOMMutationEvent.h new file mode 100644 index 00000000000..744b4532b70 --- /dev/null +++ b/mozilla/content/events/src/nsDOMMutationEvent.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMMutationEvent_h__ +#define nsDOMMutationEvent_h__ + +#include "nsCOMPtr.h" +#include "nsIDOMMutationEvent.h" +#include "nsDOMEvent.h" +#include "nsContentUtils.h" + +class nsDOMMutationEvent : public nsIDOMMutationEvent, + public nsDOMEvent +{ +public: + nsDOMMutationEvent(nsPresContext* aPresContext, nsMutationEvent* aEvent); + + NS_DECL_ISUPPORTS_INHERITED + + NS_DECL_NSIDOMMUTATIONEVENT + + // Forward to base class + NS_FORWARD_TO_NSDOMEVENT +}; + +#endif // nsDOMMutationEvent_h__ diff --git a/mozilla/content/events/src/nsDOMPopupBlockedEvent.cpp b/mozilla/content/events/src/nsDOMPopupBlockedEvent.cpp new file mode 100644 index 00000000000..3c628fece14 --- /dev/null +++ b/mozilla/content/events/src/nsDOMPopupBlockedEvent.cpp @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Steve Clark (buster@netscape.com) + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDOMPopupBlockedEvent.h" +#include "nsIURI.h" +#include "nsContentUtils.h" + +nsDOMPopupBlockedEvent::nsDOMPopupBlockedEvent(nsPresContext* aPresContext, nsPopupBlockedEvent* aEvent) +: nsDOMEvent(aPresContext, aEvent ? aEvent : new nsPopupBlockedEvent()) +{ + NS_ASSERTION(mEvent->eventStructType == NS_POPUP_BLOCKED_EVENT, "event type mismatch"); + + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + mEvent->time = PR_Now(); + } +} + +nsDOMPopupBlockedEvent::~nsDOMPopupBlockedEvent() +{ + if (mEventIsInternal) { + if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + NS_IF_RELEASE(event->mRequestingWindowURI); + NS_IF_RELEASE(event->mPopupWindowURI); + } + } +} + +NS_IMPL_ADDREF_INHERITED(nsDOMPopupBlockedEvent, nsDOMEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMPopupBlockedEvent, nsDOMEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMPopupBlockedEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMPopupBlockedEvent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(PopupBlockedEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent) + +NS_IMETHODIMP +nsDOMPopupBlockedEvent::InitPopupBlockedEvent(const nsAString & aTypeArg, + PRBool aCanBubbleArg, PRBool aCancelableArg, + nsIURI *aRequestingWindowURI, + nsIURI *aPopupWindowURI, + const nsAString & aPopupWindowFeatures) +{ + nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg); + NS_ENSURE_SUCCESS(rv, rv); + + switch (mEvent->eventStructType) + { + case NS_POPUPBLOCKED_EVENT: + { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + event->mRequestingWindowURI = aRequestingWindowURI; + event->mPopupWindowURI = aPopupWindowURI; + NS_IF_ADDREF(event->mRequestingWindowURI); + NS_IF_ADDREF(event->mPopupWindowURI); + event->mPopupWindowFeatures = aPopupWindowFeatures; + break; + } + default: + break; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMPopupBlockedEvent::GetRequestingWindowURI(nsIURI **aRequestingWindowURI) +{ + NS_ENSURE_ARG_POINTER(aRequestingWindowURI); + if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + *aRequestingWindowURI = event->mRequestingWindowURI; + NS_IF_ADDREF(*aRequestingWindowURI); + return NS_OK; + } + *aRequestingWindowURI = 0; + return NS_OK; // Don't throw an exception +} + +NS_IMETHODIMP +nsDOMPopupBlockedEvent::GetPopupWindowURI(nsIURI **aPopupWindowURI) +{ + NS_ENSURE_ARG_POINTER(aPopupWindowURI); + if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + *aPopupWindowURI = event->mPopupWindowURI; + NS_IF_ADDREF(*aPopupWindowURI); + return NS_OK; + } + *aPopupWindowURI = 0; + return NS_OK; // Don't throw an exception +} + +NS_IMETHODIMP +nsDOMPopupBlockedEvent::GetPopupWindowFeatures(nsAString &aPopupWindowFeatures) +{ + if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + aPopupWindowFeatures = event->mPopupWindowFeatures; + return NS_OK; + } + aPopupWindowFeatures.Truncate(); + return NS_OK; // Don't throw an exception +} + +nsresult NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsPopupBlockedEvent *aEvent) +{ + nsDOMPopupBlockedEvent* it = new nsDOMPopupBlockedEvent(aPresContext, aEvent); + if (nsnull == it) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/mozilla/content/events/src/nsDOMPopupBlockedEvent.h b/mozilla/content/events/src/nsDOMPopupBlockedEvent.h new file mode 100644 index 00000000000..8fb35161fb4 --- /dev/null +++ b/mozilla/content/events/src/nsDOMPopupBlockedEvent.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMPopupBlockedEvent_h__ +#define nsDOMPopupBlockedEvent_h__ + +#include "nsIDOMPopupBlockedEvent.h" +#include "nsDOMEvent.h" + +class nsDOMPopupBlockedEvent : public nsIDOMPopupBlockedEvent, + public nsDOMEvent +{ +public: + + nsDOMPopupBlockedEvent(nsPresContext* aPresContext, nsPopupBlockedEvent* aEvent); + virtual ~nsDOMPopupBlockedEvent(); + + NS_DECL_ISUPPORTS_INHERITED + + // Forward to nsDOMEvent + NS_FORWARD_NSIDOMEVENT(nsDOMEvent::) + + // nsIDOMPopupBlockedEvent Interface + NS_DECL_NSIDOMPOPUPBLOCKEDEVENT +}; + +#endif // nsDOMPopupBlockedEvent_h__ diff --git a/mozilla/content/events/src/nsDOMTextEvent.cpp b/mozilla/content/events/src/nsDOMTextEvent.cpp new file mode 100644 index 00000000000..340a7d3be23 --- /dev/null +++ b/mozilla/content/events/src/nsDOMTextEvent.cpp @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDOMTextEvent.h" +#include "nsContentUtils.h" +#include "nsPrivateTextRange.h" + +nsDOMTextEvent::nsDOMTextEvent(nsPresContext* aPresContext, nsTextEvent* aEvent) +: nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsTextEvent()) +{ + NS_ASSERTION(mEvent->eventStructType == NS_TEXT_EVENT, "event type mismatch"); + + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + mEvent->time = PR_Now(); + } + + // + // extract the IME composition string + // + nsTextEvent *te = NS_STATIC_CAST(nsTextEvent*, aEvent); + mText = te->theText; + + // + // build the range list -- ranges need to be DOM-ified since the + // IME transaction will hold a ref, the widget representation + // isn't persistent + // + nsIPrivateTextRange** tempTextRangeList = new nsIPrivateTextRange*[te->rangeCount]; + if (tempTextRangeList) { + PRUint16 i; + + for(i = 0; i < te->rangeCount; i++) { + nsPrivateTextRange* tempPrivateTextRange = new + nsPrivateTextRange(te->rangeArray[i].mStartOffset, + te->rangeArray[i].mEndOffset, + te->rangeArray[i].mRangeType); + + if (tempPrivateTextRange) { + NS_ADDREF(tempPrivateTextRange); + + tempTextRangeList[i] = (nsIPrivateTextRange*)tempPrivateTextRange; + } + } + } + + // We need to create mTextRange even rangeCount is 0. + // If rangeCount is 0, mac carbon will return 0 for new and + // tempTextRangeList will be null. but we should still create + // mTextRange, otherwise, we will crash it later when some code + // call GetInputRange and AddRef to the result + mTextRange = new nsPrivateTextRangeList(te->rangeCount ,tempTextRangeList); +} + +NS_IMPL_ADDREF_INHERITED(nsDOMTextEvent, nsDOMUIEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMTextEvent, nsDOMUIEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMTextEvent) + NS_INTERFACE_MAP_ENTRY(nsIPrivateTextEvent) + NS_INTERFACE_MAP_ENTRY(nsIPrivateCompositionEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent) + +NS_METHOD nsDOMTextEvent::GetText(nsString& aText) +{ + aText = mText; + return NS_OK; +} + +NS_METHOD nsDOMTextEvent::GetInputRange(nsIPrivateTextRangeList** aInputRange) +{ + if (mEvent->message == NS_TEXT_TEXT) + { + *aInputRange = mTextRange; + return NS_OK; + } + aInputRange = 0; + return NS_ERROR_FAILURE; +} + +NS_METHOD nsDOMTextEvent::GetEventReply(nsTextEventReply** aReply) +{ + if (mEvent->message == NS_TEXT_TEXT) + { + *aReply = &(NS_STATIC_CAST(nsTextEvent*, mEvent)->theReply); + return NS_OK; + } + aReply = 0; + return NS_ERROR_FAILURE; +} + +nsresult NS_NewDOMTextEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsTextEvent *aEvent) +{ + nsDOMTextEvent* it = new nsDOMTextEvent(aPresContext, aEvent); + if (nsnull == it) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/mozilla/content/events/src/nsDOMTextEvent.h b/mozilla/content/events/src/nsDOMTextEvent.h new file mode 100644 index 00000000000..6575374c78a --- /dev/null +++ b/mozilla/content/events/src/nsDOMTextEvent.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMTextEvent_h__ +#define nsDOMTextEvent_h__ + +#include "nsDOMUIEvent.h" +#include "nsIPrivateTextEvent.h" +#include "nsIPrivateTextRange.h" + +class nsDOMTextEvent : public nsDOMUIEvent, + public nsIPrivateTextEvent +{ +public: + nsDOMTextEvent(nsPresContext* aPresContext, nsTextEvent* aEvent); + + NS_DECL_ISUPPORTS_INHERITED + + // Forward to base class + NS_FORWARD_TO_NSDOMUIEVENT + + // nsIPrivateTextEvent interface + NS_IMETHOD GetText(nsString& aText); + NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange); + NS_IMETHOD GetEventReply(nsTextEventReply** aReply); + +protected: + nsString mText; + nsCOMPtr mTextRange; +}; + +#endif // nsDOMTextEvent_h__ diff --git a/mozilla/content/events/src/nsDOMUIEvent.cpp b/mozilla/content/events/src/nsDOMUIEvent.cpp new file mode 100644 index 00000000000..78484ede345 --- /dev/null +++ b/mozilla/content/events/src/nsDOMUIEvent.cpp @@ -0,0 +1,484 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Steve Clark (buster@netscape.com) + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsCOMPtr.h" +#include "nsDOMUIEvent.h" +#include "nsIPresShell.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsIDOMWindowInternal.h" +#include "nsIDOMAbstractView.h" +#include "nsIDOMNode.h" +#include "nsIContent.h" +#include "nsContentUtils.h" +#include "nsIViewManager.h" +#include "nsIScrollableView.h" +#include "nsIWidget.h" +#include "nsIPresShell.h" +#include "nsIEventStateManager.h" +#include "nsIFrame.h" + +nsDOMUIEvent::nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent) +: nsDOMEvent(aPresContext, aEvent) +{ + if (aEvent) { + mEventIsInternal = PR_FALSE; + mEventIsTrusted = PR_TRUE; + } + else { + mEventIsInternal = PR_TRUE; + mEventIsTrusted = PR_FALSE; + mEvent->time = PR_Now(); + } + + // Fill mDetail and mView according to the mEvent (widget-generated event) we've got + switch(mEvent->eventStructType) + { + case NS_UI_EVENT: + { + nsUIEvent *event = NS_STATIC_CAST(nsUIEvent*, mEvent); + mDetail = event->detail; + break; + } + + case NS_SCROLLPORT_EVENT: + { + nsScrollPortEvent* scrollEvent = NS_STATIC_CAST(nsScrollPortEvent*, mEvent); + mDetail = (PRInt32)scrollEvent->orient; + break; + } + + default: + mDetail = 0; + break; + } + + mView = nsnull; + if (mPresContext) + { + nsCOMPtr container = mPresContext->GetContainer(); + if (container) + { + nsCOMPtr window = do_GetInterface(container); + if (window) + mView = do_QueryInterface(window); + } + } +} + +NS_IMPL_ADDREF_INHERITED(nsDOMUIEvent, nsDOMEvent) +NS_IMPL_RELEASE_INHERITED(nsDOMUIEvent, nsDOMEvent) + +NS_INTERFACE_MAP_BEGIN(nsDOMUIEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMUIEvent) + NS_INTERFACE_MAP_ENTRY(nsIDOMNSUIEvent) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(UIEvent) +NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent) + +nsPoint nsDOMUIEvent::GetScreenPoint() { + if (!mEvent || + (mEvent->eventStructType != NS_MOUSE_EVENT && + mEvent->eventStructType != NS_POPUP_EVENT && + !NS_IS_DRAG_EVENT(mEvent))) { + return nsPoint(0, 0); + } + + if (!((nsGUIEvent*)mEvent)->widget ) { + return mEvent->refPoint; + } + + nsRect bounds(mEvent->refPoint, nsSize(1, 1)); + nsRect offset; + ((nsGUIEvent*)mEvent)->widget->WidgetToScreen ( bounds, offset ); + return offset.TopLeft(); +} + +nsPoint nsDOMUIEvent::GetClientPoint() { + if (!mEvent || + (mEvent->eventStructType != NS_MOUSE_EVENT && + mEvent->eventStructType != NS_POPUP_EVENT && + !NS_IS_DRAG_EVENT(mEvent)) || + !mPresContext) { + return nsPoint(0, 0); + } + + if (!((nsGUIEvent*)mEvent)->widget ) { + return mEvent->point; + } + + //My god, man, there *must* be a better way to do this. + nsCOMPtr docWidget; + nsIPresShell *presShell = mPresContext->GetPresShell(); + if (presShell) { + nsIViewManager* vm = presShell->GetViewManager(); + if (vm) { + vm->GetWidget(getter_AddRefs(docWidget)); + } + } + + nsPoint pt = mEvent->refPoint; + + nsCOMPtr eventWidget = ((nsGUIEvent*)mEvent)->widget; + while (eventWidget && docWidget != eventWidget) { + nsWindowType windowType; + eventWidget->GetWindowType(windowType); + if (windowType == eWindowType_popup) + break; + + nsRect bounds; + eventWidget->GetBounds(bounds); + pt += bounds.TopLeft(); + eventWidget = dont_AddRef(eventWidget->GetParent()); + } + + if (eventWidget != docWidget) { + // docWidget wasn't on the chain from the event widget to the root + // of the widget tree (or the nearest popup). OK, so now pt is + // relative to eventWidget; to get it relative to docWidget, we + // need to subtract docWidget's offset from eventWidget. + while (docWidget && docWidget != eventWidget) { + nsWindowType windowType; + docWidget->GetWindowType(windowType); + if (windowType == eWindowType_popup) { + // oh dear. the doc and the event were in different popups? + // That shouldn't happen. + NS_NOTREACHED("doc widget and event widget are in different popups. That's dumb."); + break; + } + + nsRect bounds; + docWidget->GetBounds(bounds); + pt -= bounds.TopLeft(); + docWidget = docWidget->GetParent(); + } + } + + return pt; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetView(nsIDOMAbstractView** aView) +{ + *aView = mView; + NS_IF_ADDREF(*aView); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetDetail(PRInt32* aDetail) +{ + *aDetail = mDetail; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::InitUIEvent(const nsAString & typeArg, PRBool canBubbleArg, PRBool cancelableArg, nsIDOMAbstractView *viewArg, PRInt32 detailArg) +{ + nsresult rv = nsDOMEvent::InitEvent(typeArg, canBubbleArg, cancelableArg); + NS_ENSURE_SUCCESS(rv, rv); + + mDetail = detailArg; + mView = viewArg; + + return NS_OK; +} + +// ---- nsDOMNSUIEvent implementation ------------------- + +NS_IMETHODIMP +nsDOMUIEvent::GetPageX(PRInt32* aPageX) +{ + NS_ENSURE_ARG_POINTER(aPageX); + nsresult ret = NS_OK; + PRInt32 scrollX = 0; + nsIScrollableView* view = nsnull; + float p2t, t2p; + + GetScrollInfo(&view, &p2t, &t2p); + if(view) { + nscoord xPos, yPos; + ret = view->GetScrollPosition(xPos, yPos); + scrollX = NSTwipsToIntPixels(xPos, t2p); + } + + if (NS_SUCCEEDED(ret)) { + *aPageX = GetClientPoint().x + scrollX; + } + + return ret; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetPageY(PRInt32* aPageY) +{ + NS_ENSURE_ARG_POINTER(aPageY); + nsresult ret = NS_OK; + PRInt32 scrollY = 0; + nsIScrollableView* view = nsnull; + float p2t, t2p; + + GetScrollInfo(&view, &p2t, &t2p); + if(view) { + nscoord xPos, yPos; + ret = view->GetScrollPosition(xPos, yPos); + scrollY = NSTwipsToIntPixels(yPos, t2p); + } + + if (NS_SUCCEEDED(ret)) { + *aPageY = GetClientPoint().y + scrollY; + } + + return ret; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetWhich(PRUint32* aWhich) +{ + NS_ENSURE_ARG_POINTER(aWhich); + // Usually we never reach here, as this is reimplemented for mouse and keyboard events. + *aWhich = 0; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetRangeParent(nsIDOMNode** aRangeParent) +{ + NS_ENSURE_ARG_POINTER(aRangeParent); + nsIFrame* targetFrame = nsnull; + + if (mPresContext) { + mPresContext->EventStateManager()->GetEventTarget(&targetFrame); + } + + *aRangeParent = nsnull; + + if (targetFrame) { + nsCOMPtr parent; + PRInt32 offset, endOffset; + PRBool beginOfContent; + if (NS_SUCCEEDED(targetFrame->GetContentAndOffsetsFromPoint(mPresContext, + mEvent->point, + getter_AddRefs(parent), + offset, + endOffset, + beginOfContent))) { + if (parent) { + return CallQueryInterface(parent, aRangeParent); + } + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetRangeOffset(PRInt32* aRangeOffset) +{ + NS_ENSURE_ARG_POINTER(aRangeOffset); + nsIFrame* targetFrame = nsnull; + + if (mPresContext) { + mPresContext->EventStateManager()->GetEventTarget(&targetFrame); + } + + if (targetFrame) { + nsIContent* parent = nsnull; + PRInt32 endOffset; + PRBool beginOfContent; + if (NS_SUCCEEDED(targetFrame->GetContentAndOffsetsFromPoint(mPresContext, + mEvent->point, + &parent, + *aRangeOffset, + endOffset, + beginOfContent))) { + NS_IF_RELEASE(parent); + return NS_OK; + } + } + *aRangeOffset = 0; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetCancelBubble(PRBool* aCancelBubble) +{ + NS_ENSURE_ARG_POINTER(aCancelBubble); + if (mEvent->flags & NS_EVENT_FLAG_BUBBLE || mEvent->flags & NS_EVENT_FLAG_INIT) { + *aCancelBubble = (mEvent->flags &= NS_EVENT_FLAG_STOP_DISPATCH) ? PR_TRUE : PR_FALSE; + } + else { + *aCancelBubble = PR_FALSE; + } + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::SetCancelBubble(PRBool aCancelBubble) +{ + if (mEvent->flags & NS_EVENT_FLAG_BUBBLE || mEvent->flags & NS_EVENT_FLAG_INIT) { + if (aCancelBubble) { + mEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH; + } + else { + mEvent->flags &= ~NS_EVENT_FLAG_STOP_DISPATCH; + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetLayerX(PRInt32* aLayerX) +{ + NS_ENSURE_ARG_POINTER(aLayerX); + if (!mEvent || (mEvent->eventStructType != NS_MOUSE_EVENT) || + !mPresContext) { + *aLayerX = 0; + return NS_OK; + } + + float t2p; + t2p = mPresContext->TwipsToPixels(); + *aLayerX = NSTwipsToIntPixels(mEvent->point.x, t2p); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetLayerY(PRInt32* aLayerY) +{ + NS_ENSURE_ARG_POINTER(aLayerY); + if (!mEvent || (mEvent->eventStructType != NS_MOUSE_EVENT) || + !mPresContext) { + *aLayerY = 0; + return NS_OK; + } + + float t2p; + t2p = mPresContext->TwipsToPixels(); + *aLayerY = NSTwipsToIntPixels(mEvent->point.y, t2p); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetIsChar(PRBool* aIsChar) +{ + switch(mEvent->eventStructType) + { + case NS_KEY_EVENT: + *aIsChar = ((nsKeyEvent*)mEvent)->isChar; + return NS_OK; + case NS_TEXT_EVENT: + *aIsChar = ((nsTextEvent*)mEvent)->isChar; + return NS_OK; + default: + *aIsChar = PR_FALSE; + return NS_OK; + } +} + +NS_IMETHODIMP +nsDOMUIEvent::GetPreventDefault(PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = mEvent ? + ((mEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) ? PR_TRUE : PR_FALSE) : + PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMUIEvent::GetScrollInfo(nsIScrollableView** aScrollableView, + float* aP2T, float* aT2P) +{ + NS_ENSURE_ARG_POINTER(aScrollableView); + NS_ENSURE_ARG_POINTER(aP2T); + NS_ENSURE_ARG_POINTER(aT2P); + if (!mPresContext) { + *aScrollableView = nsnull; + return NS_ERROR_FAILURE; + } + + *aP2T = mPresContext->PixelsToTwips(); + *aT2P = mPresContext->TwipsToPixels(); + + nsIPresShell *presShell = mPresContext->GetPresShell(); + if (presShell) { + nsIViewManager* vm = presShell->GetViewManager(); + if(vm) { + return vm->GetRootScrollableView(aScrollableView); + } + } + return NS_OK; +} + +NS_METHOD nsDOMUIEvent::GetCompositionReply(nsTextEventReply** aReply) +{ + if((mEvent->eventStructType == NS_RECONVERSION_EVENT) || + (mEvent->message == NS_COMPOSITION_START) || + (mEvent->message == NS_COMPOSITION_QUERY)) + { + *aReply = &(NS_STATIC_CAST(nsCompositionEvent*, mEvent)->theReply); + return NS_OK; + } + *aReply = nsnull; + return NS_ERROR_FAILURE; +} + +NS_METHOD +nsDOMUIEvent::GetReconversionReply(nsReconversionEventReply** aReply) +{ + if (mEvent->eventStructType == NS_RECONVERSION_EVENT) + { + *aReply = &(NS_STATIC_CAST(nsReconversionEvent*, mEvent)->theReply); + return NS_OK; + } + aReply = nsnull; + return NS_ERROR_FAILURE; +} + +nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult, + nsPresContext* aPresContext, + nsGUIEvent *aEvent) +{ + nsDOMUIEvent* it = new nsDOMUIEvent(aPresContext, aEvent); + if (nsnull == it) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return CallQueryInterface(it, aInstancePtrResult); +} diff --git a/mozilla/content/events/src/nsDOMUIEvent.h b/mozilla/content/events/src/nsDOMUIEvent.h new file mode 100644 index 00000000000..8f5ca750e0d --- /dev/null +++ b/mozilla/content/events/src/nsDOMUIEvent.h @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDOMUIEvent_h__ +#define nsDOMUIEvent_h__ + +#include "nsIDOMUIEvent.h" +#include "nsIDOMNSUIEvent.h" +#include "nsIPrivateCompositionEvent.h" +#include "nsDOMEvent.h" + +class nsDOMUIEvent : public nsIDOMUIEvent, + public nsIDOMNSUIEvent, + public nsIPrivateCompositionEvent, + public nsDOMEvent +{ +public: + nsDOMUIEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent); + + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMUIEvent Interface + NS_DECL_NSIDOMUIEVENT + + // nsIDOMNSUIEvent Interface + NS_DECL_NSIDOMNSUIEVENT + + // nsIPrivateCompositionEvent interface + NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply); + NS_IMETHOD GetReconversionReply(nsReconversionEventReply** aReply); + + // Forward to nsDOMEvent + NS_FORWARD_NSIDOMEVENT(nsDOMEvent::) + +protected: + + // Internal helper functions + nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, + float* aT2P); + nsPoint GetClientPoint(); + nsPoint GetScreenPoint(); + +protected: + nsCOMPtr mView; + PRInt32 mDetail; +}; + +#define NS_FORWARD_NSIDOMNSUIEVENT_NO_WHICH(_to) \ + NS_IMETHOD GetPreventDefault(PRBool *_retval) { return _to GetPreventDefault(_retval); } \ + NS_IMETHOD GetLayerX(PRInt32 *aLayerX) { return _to GetLayerX(aLayerX); } \ + NS_IMETHOD GetLayerY(PRInt32 *aLayerY) { return _to GetLayerY(aLayerY); } \ + NS_IMETHOD GetPageX(PRInt32 *aPageX) { return _to GetPageX(aPageX); } \ + NS_IMETHOD GetPageY(PRInt32 *aPageY) { return _to GetPageY(aPageY); } \ + NS_IMETHOD GetRangeParent(nsIDOMNode * *aRangeParent) { return _to GetRangeParent(aRangeParent); } \ + NS_IMETHOD GetRangeOffset(PRInt32 *aRangeOffset) { return _to GetRangeOffset(aRangeOffset); } \ + NS_IMETHOD GetCancelBubble(PRBool *aCancelBubble) { return _to GetCancelBubble(aCancelBubble); } \ + NS_IMETHOD SetCancelBubble(PRBool aCancelBubble) { return _to SetCancelBubble(aCancelBubble); } \ + NS_IMETHOD GetIsChar(PRBool *aIsChar) { return _to GetIsChar(aIsChar); } + +#define NS_FORWARD_TO_NSDOMUIEVENT \ + NS_FORWARD_NSIDOMUIEVENT(nsDOMUIEvent::) \ + NS_FORWARD_NSIDOMNSUIEVENT(nsDOMUIEvent::) \ + NS_FORWARD_TO_NSDOMEVENT + +#define NS_FORWARD_TO_NSDOMUIEVENT_NO_WHICH \ + NS_FORWARD_NSIDOMUIEVENT(nsDOMUIEvent::) \ + NS_FORWARD_NSIDOMNSUIEVENT_NO_WHICH(nsDOMUIEvent::) \ + NS_FORWARD_TO_NSDOMEVENT + +#endif // nsDOMUIEvent_h__ diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index fd7956398a3..9808a83841c 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -301,12 +301,12 @@ static const EventDispatchData sMutationEvents[] = { }; static const EventDispatchData sUIEvents[] = { - { NS_DOMUI_ACTIVATE, HANDLER(&nsIDOMUIListener::Activate), - NS_EVENT_BITS_DOMUI_ACTIVATE }, - { NS_DOMUI_FOCUSIN, HANDLER(&nsIDOMUIListener::FocusIn), - NS_EVENT_BITS_DOMUI_FOCUSIN }, - { NS_DOMUI_FOCUSOUT, HANDLER(&nsIDOMUIListener::FocusOut), - NS_EVENT_BITS_DOMUI_FOCUSOUT } + { NS_UI_ACTIVATE, HANDLER(&nsIDOMUIListener::Activate), + NS_EVENT_BITS_UI_ACTIVATE }, + { NS_UI_FOCUSIN, HANDLER(&nsIDOMUIListener::FocusIn), + NS_EVENT_BITS_UI_FOCUSIN }, + { NS_UI_FOCUSOUT, HANDLER(&nsIDOMUIListener::FocusOut), + NS_EVENT_BITS_UI_FOCUSOUT } }; #define IMPL_EVENTTYPEDATA(type) \ @@ -979,15 +979,15 @@ nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, } else if (aType == nsLayoutAtoms::onDOMActivate) { *aArrayType = eEventArrayType_DOMUI; - *aFlags = NS_EVENT_BITS_DOMUI_ACTIVATE; + *aFlags = NS_EVENT_BITS_UI_ACTIVATE; } else if (aType == nsLayoutAtoms::onDOMFocusIn) { *aArrayType = eEventArrayType_DOMUI; - *aFlags = NS_EVENT_BITS_DOMUI_FOCUSIN; + *aFlags = NS_EVENT_BITS_UI_FOCUSIN; } else if (aType == nsLayoutAtoms::onDOMFocusOut) { *aArrayType = eEventArrayType_DOMUI; - *aFlags = NS_EVENT_BITS_DOMUI_FOCUSOUT; + *aFlags = NS_EVENT_BITS_UI_FOCUSOUT; } else { return NS_ERROR_FAILURE; @@ -1580,10 +1580,7 @@ nsresult nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, found: if (listeners) { if (!*aDOMEvent) { - if (aEvent->eventStructType == NS_MUTATION_EVENT) - ret = NS_NewDOMMutationEvent(aDOMEvent, aPresContext, aEvent); - else - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, EmptyString(), aEvent); + ret = CreateEvent(aPresContext, aEvent, EmptyString(), aDOMEvent); } if (NS_SUCCEEDED(ret)) { @@ -1627,22 +1624,55 @@ nsEventListenerManager::CreateEvent(nsPresContext* aPresContext, { *aDOMEvent = nsnull; - nsAutoString str(aEventType); - if (!aEvent && !str.LowerCaseEqualsLiteral("mouseevents") && - !str.LowerCaseEqualsLiteral("keyevents") && - !str.LowerCaseEqualsLiteral("htmlevents") && - !str.LowerCaseEqualsLiteral("mutationevents") && - !str.LowerCaseEqualsLiteral("mousescrollevents") && - !str.LowerCaseEqualsLiteral("popupblockedevents") && - !str.LowerCaseEqualsLiteral("uievents") && - !str.LowerCaseEqualsLiteral("events")) { + if (aEvent) + { + switch(aEvent->eventStructType) + { + case NS_MUTATION_EVENT: + return NS_NewDOMMutationEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsMutationEvent*,aEvent)); + case NS_GUI_EVENT: + return NS_NewDOMUIEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsGUIEvent*,aEvent)); + case NS_KEY_EVENT: + return NS_NewDOMKeyboardEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsKeyEvent*,aEvent)); + case NS_MOUSE_EVENT: + case NS_MOUSE_SCROLL_EVENT: + return NS_NewDOMMouseEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsInputEvent*,aEvent)); + case NS_POPUP_EVENT: + return NS_NewDOMPopupBlockedEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsPopupBlockedEvent*,aEvent)); + case NS_TEXT_EVENT: + return NS_NewDOMTextEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsTextEvent*,aEvent)); + default: + return NS_NewDOMEvent(aDOMEvent, aPresContext, aEvent); + } + } + else + { + nsAutoString str(aEventType); + if (str.EqualsIgnoreCase("MouseEvent") || + str.EqualsIgnoreCase("MouseEvents") || + str.EqualsIgnoreCase("MouseScrollEvents")) + return NS_NewDOMMouseEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsMouseEvent*,aEvent)); + if (str.EqualsIgnoreCase("KeyboardEvent") || + str.EqualsIgnoreCase("KeyEvents")) + return NS_NewDOMMouseEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsKeyEvent*,aEvent)); + if (str.EqualsIgnoreCase("MutationEvent") || + str.EqualsIgnoreCase("MutationEvents")) + return NS_NewDOMMutationEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsMutationEvent*,aEvent)); + if (str.EqualsIgnoreCase("TextEvent") || + str.EqualsIgnoreCase("TextEvents")) + return NS_NewDOMTextEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsTextEvent*,aEvent)); + if (str.EqualsIgnoreCase("PopupBlockedEvents")) + return NS_NewDOMPopupBlockedEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsPopupBlockedEvent*,aEvent)); + if (str.EqualsIgnoreCase("UIEvent") || + str.EqualsIgnoreCase("UIEvents")) + return NS_NewDOMUIEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsGUIEvent*,aEvent)); + if (str.EqualsIgnoreCase("Event") || + str.EqualsIgnoreCase("Events") || + str.EqualsIgnoreCase("HTMLEvents")) + return NS_NewDOMEvent(aDOMEvent, aPresContext, aEvent); + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; } - - if ((aEvent && aEvent->eventStructType == NS_MUTATION_EVENT) || - (!aEvent && str.LowerCaseEqualsLiteral("mutationevents"))) - return NS_NewDOMMutationEvent(aDOMEvent, aPresContext, aEvent); - return NS_NewDOMUIEvent(aDOMEvent, aPresContext, aEventType, aEvent); } /** @@ -2000,7 +2030,7 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, // the client X/Y will be 0,0. We can make use of that if the widget is null. if (aEvent->message == NS_CONTEXTMENU_KEY) NS_IF_RELEASE(((nsGUIEvent*)aEvent)->widget); // nulls out widget - ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, EmptyString(), aEvent); + ret = NS_NewDOMUIEvent(aDOMEvent, aPresContext, NS_STATIC_CAST(nsGUIEvent*,aEvent)); } if (NS_SUCCEEDED(ret)) { diff --git a/mozilla/content/events/src/nsEventListenerManager.h b/mozilla/content/events/src/nsEventListenerManager.h index 65d48132ed6..40fcfcb1cb2 100644 --- a/mozilla/content/events/src/nsEventListenerManager.h +++ b/mozilla/content/events/src/nsEventListenerManager.h @@ -339,9 +339,9 @@ protected: #define NS_EVENT_BITS_CONTEXT_MENU 0x01 // nsIDOMUIListener -#define NS_EVENT_BITS_DOMUI_NONE 0x00 -#define NS_EVENT_BITS_DOMUI_ACTIVATE 0x01 -#define NS_EVENT_BITS_DOMUI_FOCUSIN 0x02 -#define NS_EVENT_BITS_DOMUI_FOCUSOUT 0x04 +#define NS_EVENT_BITS_UI_NONE 0x00 +#define NS_EVENT_BITS_UI_ACTIVATE 0x01 +#define NS_EVENT_BITS_UI_FOCUSIN 0x02 +#define NS_EVENT_BITS_UI_FOCUSOUT 0x04 #endif // nsEventListenerManager_h__ diff --git a/mozilla/content/events/src/nsRecycled.h b/mozilla/content/events/src/nsRecycled.h new file mode 100644 index 00000000000..0ffc4c7b81b --- /dev/null +++ b/mozilla/content/events/src/nsRecycled.h @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ilya Konstantinov (mozilla-code@future.shiny.co.il) + * + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsRecycled_h__ +#define nsRecycled_h__ + +#include "nsAutoPtr.h" +#include "prtypes.h" + +/* + * A simple one-object recycler. + * Derive from this class if usually only one heap-allocated instance of your class + * exists at a time. This class accelerates heap allocations by keeping around + * a pre-allocated buffer the size of a single instance of your class. + * + * The OwnerType template parameter is given to differentiate inheriting classes. For instance, + * nsFoo should inherit from nsRecycledSingle. If a hierarchy inherits from nsFoo, + * the same preallocated buffer would be used for instances of all derived classes, so you + * should ensure that usually only one instance of any of those classes exists at a time. + * + * Example: + * class nsFoo : public nsIBar, nsRecycledSingle + * { + * ... + * }; + * + */ +template +class nsRecycledSingle +{ +public: + /* Initializes the memory to 0. */ + void* operator new(size_t sz) CPP_THROW_NEW + { + void* result = nsnull; + + if (!gPoolInUse) + { + if (gPoolSize >= sz) + { + result = gPool; + } + else + { + // Original pool, if any, is deleted by this plain assignment. + result = ::operator new(sz); + gPool = (char*)result; + gPoolSize = sz; + } + gPoolInUse = PR_TRUE; + } + else + { + if (sz > gPoolSize) + { + // This would be a good opportunity to throw away our + // current pool and replace it with this, larger one. + + // Original pool will die as a regular allocated buffer + // when its time is due. + gPool.forget(); + result = ::operator new(sz); + gPool = (char*)result; + gPoolSize = sz; + } + else + { + result = ::operator new(sz); + } + } + + if (result) { + memset(result, 0, sz); + } + + return result; + } + + void operator delete(void* aPtr) + { + if (gPool == aPtr) + { + gPoolInUse = PR_FALSE; + return; + } + else + { + ::operator delete(aPtr); + } + } + +protected: + static nsAutoPtr gPool; + static size_t gPoolSize; + static PRBool gPoolInUse; +}; + +template +nsAutoPtr nsRecycledSingle::gPool; +template +size_t nsRecycledSingle::gPoolSize = 0; +template +PRBool nsRecycledSingle::gPoolInUse = PR_FALSE; + +#endif // nsRecycled_h__ diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 65ac7c5a134..1de8eccafe6 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1459,7 +1459,7 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsPresContext* aPresContext, // The default action is simply to dispatch DOMActivate nsIPresShell *shell = aPresContext->GetPresShell(); if (shell) { - nsDOMUIEvent actEvent(NS_DOMUI_ACTIVATE, 1); // single-click + nsUIEvent actEvent(NS_UI_ACTIVATE, 1); // single-click nsEventStatus status = nsEventStatus_eIgnore; ret = shell->HandleDOMEventWithTarget(this, &actEvent, &status); @@ -1471,7 +1471,7 @@ nsGenericHTMLElement::HandleDOMEventForAnchors(nsPresContext* aPresContext, } break; - case NS_DOMUI_ACTIVATE: + case NS_UI_ACTIVATE: if (nsEventStatus_eConsumeNoDefault != *aEventStatus) { nsAutoString target; nsCOMPtr baseURI = GetBaseURI(); diff --git a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp index c19d6fbcbe0..26c3d942ceb 100644 --- a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp @@ -379,7 +379,7 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, { nsIPresShell *presShell = aPresContext->GetPresShell(); if (presShell) { - nsDOMUIEvent event(NS_DOMUI_ACTIVATE, 1); // single-click + nsUIEvent event(NS_UI_ACTIVATE, 1); // single-click nsEventStatus status = nsEventStatus_eIgnore; presShell->HandleDOMEventWithTarget(this, &event, &status); @@ -388,7 +388,7 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, } break; - case NS_DOMUI_ACTIVATE: + case NS_UI_ACTIVATE: { if (mForm) { if (mType == NS_FORM_BUTTON_SUBMIT || mType == NS_FORM_BUTTON_RESET) { @@ -468,7 +468,7 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, } } else { switch (aEvent->message) { - case NS_DOMUI_ACTIVATE: + case NS_UI_ACTIVATE: if (mForm && mType == NS_FORM_BUTTON_SUBMIT) { // tell the form to flush a possible pending submission. // the reason is that the script returned false (the event was @@ -476,7 +476,7 @@ nsHTMLButtonElement::HandleDOMEvent(nsPresContext* aPresContext, // be submitted immediatelly. mForm->FlushPendingSubmission(); } - break;// NS_DOMUI_ACTIVATE + break;// NS_UI_ACTIVATE } //switch } //if } //if diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index 68d14b56874..aef0993ce2a 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1276,7 +1276,7 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, // Track whether we're in the "outer" HandleDOMEvent invocation PRBool clickOrExtActivate = (aEvent->message == NS_MOUSE_LEFT_CLICK || - (aEvent->message == NS_DOMUI_ACTIVATE && + (aEvent->message == NS_UI_ACTIVATE && !GET_BOOLBIT(mBitField, BF_IN_INTERNAL_ACTIVATE))); PRBool originalCheckedValue = PR_FALSE; @@ -1361,7 +1361,7 @@ nsHTMLInputElement::HandleDOMEvent(nsPresContext* aPresContext, if (*aEventStatus != nsEventStatus_eConsumeNoDefault && !(aFlags & NS_EVENT_FLAG_SYSTEM_EVENT) && aEvent->message == NS_MOUSE_LEFT_CLICK && mType != NS_FORM_INPUT_TEXT) { - nsDOMUIEvent actEvent(NS_DOMUI_ACTIVATE, 1); + nsUIEvent actEvent(NS_UI_ACTIVATE, 1); nsIPresShell *shell = aPresContext->GetPresShell(); if (shell) { diff --git a/mozilla/dom/public/nsIDOMClassInfo.h b/mozilla/dom/public/nsIDOMClassInfo.h index 82ecdecac77..ac3386e48ea 100644 --- a/mozilla/dom/public/nsIDOMClassInfo.h +++ b/mozilla/dom/public/nsIDOMClassInfo.h @@ -79,6 +79,10 @@ enum nsDOMClassInfoID { // Event classes eDOMClassInfo_Event_id, eDOMClassInfo_MutationEvent_id, + eDOMClassInfo_UIEvent_id, + eDOMClassInfo_MouseEvent_id, + eDOMClassInfo_KeyboardEvent_id, + eDOMClassInfo_PopupBlockedEvent_id, // HTML classes eDOMClassInfo_HTMLDocument_id, diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index 534ad89f0ef..4b67484899a 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -197,6 +197,8 @@ #include "nsIDOMEntity.h" #include "nsIDOMEntityReference.h" #include "nsIDOMNotation.h" +#include "nsIDOMNSEvent.h" +#include "nsIDOMKeyEvent.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMPopupBlockedEvent.h" #include "nsIDOMMutationEvent.h" @@ -516,6 +518,14 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CLASSINFO_DATA(MutationEvent, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(UIEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(MouseEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(KeyboardEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(PopupBlockedEvent, nsDOMGenericSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS) // Misc HTML classes NS_DEFINE_CLASSINFO_DATA(HTMLDocument, nsHTMLDocumentSH, @@ -1345,6 +1355,15 @@ nsDOMClassInfo::RegisterExternalClasses() DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) \ DOM_CLASSINFO_MAP_ENTRY(nsIDOM3Node) +#define DOM_CLASSINFO_EVENT_MAP_ENTRIES \ + DOM_CLASSINFO_MAP_ENTRY(nsIDOMEvent) \ + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEvent) \ + +#define DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES \ + DOM_CLASSINFO_MAP_ENTRY(nsIDOMUIEvent) \ + DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSUIEvent) \ + DOM_CLASSINFO_EVENT_MAP_ENTRIES + #define DOM_CLASSINFO_MAP_END_WITH_XPATH \ xpathEvaluatorIID, \ DOM_CLASSINFO_MAP_END @@ -1547,17 +1566,33 @@ nsDOMClassInfo::Init() nsIDOMStyleSheetList) DOM_CLASSINFO_MAP_ENTRY(nsIDOMStyleSheetList) DOM_CLASSINFO_MAP_END - + DOM_CLASSINFO_MAP_BEGIN(Event, nsIDOMEvent) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEvent) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMKeyEvent) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMMouseEvent) + DOM_CLASSINFO_EVENT_MAP_ENTRIES + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(PopupBlockedEvent, nsIDOMPopupBlockedEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMPopupBlockedEvent) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSUIEvent) + DOM_CLASSINFO_EVENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(MutationEvent, nsIDOMMutationEvent) DOM_CLASSINFO_MAP_ENTRY(nsIDOMMutationEvent) + DOM_CLASSINFO_EVENT_MAP_ENTRIES + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(UIEvent, nsIDOMUIEvent) + DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(KeyboardEvent, nsIDOMKeyEvent) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMKeyEvent) + DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES + DOM_CLASSINFO_MAP_END + + DOM_CLASSINFO_MAP_BEGIN(MouseEvent, nsIDOMMouseEvent) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMMouseEvent) + DOM_CLASSINFO_UI_EVENT_MAP_ENTRIES DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(HTMLDocument, nsIDOMHTMLDocument) diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index 990e0ad2d23..4e56faf2f9d 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -89,7 +89,7 @@ class nsIURI; #define NS_APPCOMMAND_EVENT 24 #define NS_POPUPBLOCKED_EVENT 25 #define NS_BEFORE_PAGE_UNLOAD_EVENT 26 -#define NS_DOMUI_EVENT 27 +#define NS_UI_EVENT 27 #define NS_EVENT_FLAG_NONE 0x0000 #define NS_EVENT_FLAG_INIT 0x0001 @@ -102,6 +102,7 @@ class nsIURI; #define NS_PRIV_EVENT_FLAG_SCRIPT 0x0080 #define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100 #define NS_EVENT_FLAG_SYSTEM_EVENT 0x0200 +#define NS_EVENT_FLAG_STOP_DISPATCH_IMMEDIATELY 0x0400 // @see nsIDOM3Event::stopImmediatePropagation() #define NS_EVENT_CAPTURE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) #define NS_EVENT_BUBBLE_MASK (~(NS_EVENT_FLAG_INIT | NS_EVENT_FLAG_CAPTURE | NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) @@ -301,12 +302,12 @@ class nsIURI; #define NS_TEXT_START 2400 #define NS_TEXT_TEXT (NS_TEXT_START) -// DOM UI events -#define NS_DOMUI_EVENT_START 2500 +// UI events +#define NS_UI_EVENT_START 2500 // this is not to be confused with NS_ACTIVATE! -#define NS_DOMUI_ACTIVATE (NS_DOMUI_EVENT_START) -#define NS_DOMUI_FOCUSIN (NS_DOMUI_EVENT_START + 1) -#define NS_DOMUI_FOCUSOUT (NS_DOMUI_EVENT_START + 2) +#define NS_UI_ACTIVATE (NS_UI_EVENT_START) +#define NS_UI_FOCUSIN (NS_UI_EVENT_START + 1) +#define NS_UI_FOCUSOUT (NS_UI_EVENT_START + 2) /** * Return status for event processors, nsEventStatus, is defined in @@ -813,10 +814,10 @@ struct nsPopupBlockedEvent : public nsEvent /** * DOM UIEvent */ -struct nsDOMUIEvent : public nsEvent { - nsDOMUIEvent(PRUint32 msg = 0, +struct nsUIEvent : public nsEvent { + nsUIEvent(PRUint32 msg = 0, PRInt32 d = 0, - PRUint8 structType = NS_DOMUI_EVENT) + PRUint8 structType = NS_UI_EVENT) : nsEvent(msg, structType), detail(d) {