From 08df7735f7c10f245e7514050dfb6ea9db4b1f4b Mon Sep 17 00:00:00 2001 From: "Olli.Pettay%helsinki.fi" Date: Thu, 16 Nov 2006 21:35:39 +0000 Subject: [PATCH] Consolidate NS_MOUSE_***_UP/DOWN/CLICK/DBLCLICK events, r=jst,roc,josh,sergei_d,emaijala,mkaply git-svn-id: svn://10.0.0.236/trunk@215370 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/accessible/src/base/nsAccessible.cpp | 6 +- mozilla/content/base/src/nsGenericElement.cpp | 2 +- mozilla/content/events/src/nsDOMEvent.cpp | 42 ++-- .../content/events/src/nsDOMMouseEvent.cpp | 76 ++----- mozilla/content/events/src/nsDOMMouseEvent.h | 4 - .../events/src/nsEventListenerManager.cpp | 73 ++----- .../events/src/nsEventStateManager.cpp | 199 ++++++++---------- .../html/content/src/nsGenericHTMLElement.cpp | 56 ++--- .../html/content/src/nsHTMLButtonElement.cpp | 82 +++++--- .../html/content/src/nsHTMLImageElement.cpp | 5 +- .../html/content/src/nsHTMLInputElement.cpp | 55 ++--- .../html/content/src/nsHTMLLabelElement.cpp | 6 +- .../content/src/nsHTMLTextAreaElement.cpp | 5 +- .../content/xml/content/src/nsXMLElement.cpp | 27 +-- .../content/xul/content/src/nsXULElement.cpp | 6 +- mozilla/layout/base/nsPresShell.cpp | 12 +- mozilla/layout/forms/nsImageControlFrame.cpp | 16 +- mozilla/layout/generic/nsFrame.cpp | 29 ++- mozilla/layout/generic/nsFrameSetFrame.cpp | 24 ++- mozilla/layout/generic/nsImageFrame.cpp | 92 ++++---- mozilla/layout/generic/nsObjectFrame.cpp | 5 +- .../layout/xul/base/src/nsButtonBoxFrame.cpp | 6 +- mozilla/layout/xul/base/src/nsMenuFrame.cpp | 15 +- .../layout/xul/base/src/nsResizerFrame.cpp | 41 ++-- .../layout/xul/base/src/nsRootBoxFrame.cpp | 4 +- .../layout/xul/base/src/nsScrollBoxFrame.cpp | 8 +- .../xul/base/src/nsScrollbarButtonFrame.cpp | 27 ++- mozilla/layout/xul/base/src/nsSliderFrame.cpp | 39 ++-- .../layout/xul/base/src/nsSplitterFrame.cpp | 8 +- .../layout/xul/base/src/nsTitleBarFrame.cpp | 37 ++-- mozilla/view/src/nsViewManager.cpp | 2 +- mozilla/widget/public/nsGUIEvent.h | 94 +++++---- mozilla/widget/src/beos/nsWindow.cpp | 57 ++--- mozilla/widget/src/beos/nsWindow.h | 3 +- mozilla/widget/src/cocoa/nsChildView.mm | 28 +-- mozilla/widget/src/gtk/nsWidget.cpp | 41 ++-- mozilla/widget/src/gtk2/nsWindow.cpp | 29 +-- mozilla/widget/src/mac/nsMacControl.cpp | 13 +- mozilla/widget/src/mac/nsMacEventHandler.cpp | 46 ++-- mozilla/widget/src/mac/nsNativeScrollbar.cpp | 78 +++---- mozilla/widget/src/mac/nsWindow.cpp | 8 +- mozilla/widget/src/os2/nsWindow.cpp | 129 +++++++----- mozilla/widget/src/os2/nsWindow.h | 4 +- mozilla/widget/src/photon/nsWidget.cpp | 36 ++-- mozilla/widget/src/photon/nsWidget.h | 3 +- mozilla/widget/src/qt/nsCommonWidget.cpp | 40 ++-- mozilla/widget/src/windows/nsWindow.cpp | 187 ++++++++-------- mozilla/widget/src/windows/nsWindow.h | 13 +- mozilla/widget/src/xlib/nsAppShell.cpp | 15 +- mozilla/widget/src/xlib/nsWidget.cpp | 20 +- mozilla/widget/src/xpwidgets/nsBaseWidget.cpp | 16 +- 51 files changed, 946 insertions(+), 923 deletions(-) diff --git a/mozilla/accessible/src/base/nsAccessible.cpp b/mozilla/accessible/src/base/nsAccessible.cpp index fa8a07897ca..8e9cf7ae98d 100644 --- a/mozilla/accessible/src/base/nsAccessible.cpp +++ b/mozilla/accessible/src/base/nsAccessible.cpp @@ -2497,11 +2497,11 @@ void nsAccessible::DoCommandCallback(nsITimer *aTimer, void *aClosure) if (presShell && outerWindow) { nsAutoPopupStatePusher popupStatePusher(outerWindow, openAllowed); - nsMouseEvent downEvent(PR_TRUE, NS_MOUSE_LEFT_BUTTON_DOWN, nsnull, + nsMouseEvent downEvent(PR_TRUE, NS_MOUSE_BUTTON_DOWN, nsnull, nsMouseEvent::eSynthesized); - nsMouseEvent upEvent(PR_TRUE, NS_MOUSE_LEFT_BUTTON_UP, nsnull, + nsMouseEvent upEvent(PR_TRUE, NS_MOUSE_BUTTON_UP, nsnull, nsMouseEvent::eSynthesized); - nsMouseEvent clickEvent(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent clickEvent(PR_TRUE, NS_MOUSE_CLICK, nsnull, nsMouseEvent::eSynthesized); nsEventStatus eventStatus = nsEventStatus_eIgnore; diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 0b595e17de0..3dbdaf0fee9 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -2467,7 +2467,7 @@ nsGenericElement::DispatchClickEvent(nsPresContext* aPresContext, NS_PRECONDITION(aSourceEvent, "Must have source event"); NS_PRECONDITION(aStatus, "Null out param?"); - nsMouseEvent event(NS_IS_TRUSTED_EVENT(aSourceEvent), NS_MOUSE_LEFT_CLICK, + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aSourceEvent), NS_MOUSE_CLICK, aSourceEvent->widget, nsMouseEvent::eReal); event.refPoint = aSourceEvent->refPoint; PRUint32 clickCount = 1; diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 8366000a7f8..2549a38a928 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -378,13 +378,13 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg) if (mEvent->eventStructType == NS_MOUSE_EVENT) { if (atom == nsLayoutAtoms::onmousedown) - mEvent->message = NS_MOUSE_LEFT_BUTTON_DOWN; + mEvent->message = NS_MOUSE_BUTTON_DOWN; else if (atom == nsLayoutAtoms::onmouseup) - mEvent->message = NS_MOUSE_LEFT_BUTTON_UP; + mEvent->message = NS_MOUSE_BUTTON_UP; else if (atom == nsLayoutAtoms::onclick) - mEvent->message = NS_MOUSE_LEFT_CLICK; + mEvent->message = NS_MOUSE_CLICK; else if (atom == nsLayoutAtoms::ondblclick) - mEvent->message = NS_MOUSE_LEFT_DOUBLECLICK; + mEvent->message = NS_MOUSE_DOUBLECLICK; else if (atom == nsLayoutAtoms::onmouseover) mEvent->message = NS_MOUSE_ENTER_SYNTH; else if (atom == nsLayoutAtoms::onmouseout) @@ -622,6 +622,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData() mouseEvent->clickCount = oldMouseEvent->clickCount; mouseEvent->acceptActivation = oldMouseEvent->acceptActivation; mouseEvent->relatedTarget = oldMouseEvent->relatedTarget; + mouseEvent->button = oldMouseEvent->button; newEvent = mouseEvent; break; } @@ -670,6 +671,7 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData() mouseScrollEvent->scrollFlags = oldMouseScrollEvent->scrollFlags; mouseScrollEvent->delta = oldMouseScrollEvent->delta; mouseScrollEvent->relatedTarget = oldMouseScrollEvent->relatedTarget; + mouseScrollEvent->button = oldMouseScrollEvent->button; newEvent = mouseScrollEvent; break; } @@ -984,14 +986,14 @@ nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent) PRUint32 key = NS_STATIC_CAST(nsKeyEvent *, aEvent)->keyCode; switch(aEvent->message) { case NS_KEY_PRESS : - // return key on focused button. see note at NS_MOUSE_LEFT_CLICK. + // return key on focused button. see note at NS_MOUSE_CLICK. if (key == nsIDOMKeyEvent::DOM_VK_RETURN) abuse = openAllowed; else if (::PopupAllowedForEvent("keypress")) abuse = openControlled; break; case NS_KEY_UP : - // space key on focused button. see note at NS_MOUSE_LEFT_CLICK. + // space key on focused button. see note at NS_MOUSE_CLICK. if (key == nsIDOMKeyEvent::DOM_VK_SPACE) abuse = openAllowed; else if (::PopupAllowedForEvent("keyup")) @@ -1005,17 +1007,18 @@ nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent) } break; case NS_MOUSE_EVENT : - if (NS_IS_TRUSTED_EVENT(aEvent)) { + if (NS_IS_TRUSTED_EVENT(aEvent) && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { switch(aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP : + case NS_MOUSE_BUTTON_UP : if (::PopupAllowedForEvent("mouseup")) abuse = openControlled; break; - case NS_MOUSE_LEFT_BUTTON_DOWN : + case NS_MOUSE_BUTTON_DOWN : if (::PopupAllowedForEvent("mousedown")) abuse = openControlled; break; - case NS_MOUSE_LEFT_CLICK : + case NS_MOUSE_CLICK : /* Click events get special treatment because of their historical status as a more legitimate event handler. If click popups are enabled in the prefs, clear the popup @@ -1023,7 +1026,7 @@ nsDOMEvent::GetEventPopupControlState(nsEvent *aEvent) if (::PopupAllowedForEvent("click")) abuse = openAllowed; break; - case NS_MOUSE_LEFT_DOUBLECLICK : + case NS_MOUSE_DOUBLECLICK : if (::PopupAllowedForEvent("dblclick")) abuse = openControlled; break; @@ -1092,21 +1095,13 @@ nsDOMEvent::Shutdown() const char* nsDOMEvent::GetEventName(PRUint32 aEventType) { switch(aEventType) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: return sEventNames[eDOMEvents_mousedown]; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: return sEventNames[eDOMEvents_mouseup]; - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_CLICK: return sEventNames[eDOMEvents_click]; - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: + case NS_MOUSE_DOUBLECLICK: return sEventNames[eDOMEvents_dblclick]; case NS_MOUSE_ENTER_SYNTH: return sEventNames[eDOMEvents_mouseover]; @@ -1203,7 +1198,6 @@ const char* nsDOMEvent::GetEventName(PRUint32 aEventType) case NS_MUTATION_CHARACTERDATAMODIFIED: return sEventNames[eDOMEvents_characterdatamodified]; case NS_CONTEXTMENU: - case NS_CONTEXTMENU_KEY: return sEventNames[eDOMEvents_contextmenu]; case NS_UI_ACTIVATE: return sEventNames[eDOMEvents_DOMActivate]; diff --git a/mozilla/content/events/src/nsDOMMouseEvent.cpp b/mozilla/content/events/src/nsDOMMouseEvent.cpp index bcfb34b2477..272fac3b840 100644 --- a/mozilla/content/events/src/nsDOMMouseEvent.cpp +++ b/mozilla/content/events/src/nsDOMMouseEvent.cpp @@ -47,8 +47,7 @@ nsDOMMouseEvent::nsDOMMouseEvent(nsPresContext* aPresContext, nsInputEvent* aEvent) : nsDOMUIEvent(aPresContext, aEvent ? aEvent : new nsMouseEvent(PR_FALSE, 0, nsnull, - nsMouseEvent::eReal)), - mButton(-1) + nsMouseEvent::eReal)) { // 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 @@ -118,12 +117,8 @@ nsDOMMouseEvent::InitMouseEvent(const nsAString & aType, PRBool aCanBubble, PRBo case NS_MOUSE_EVENT: case NS_MOUSE_SCROLL_EVENT: { - if (mEvent->eventStructType == NS_MOUSE_EVENT) { - NS_STATIC_CAST(nsMouseEvent*, mEvent)->relatedTarget = aRelatedTarget; - } else { - NS_STATIC_CAST(nsMouseScrollEvent*, mEvent)->relatedTarget = - aRelatedTarget; - } + NS_STATIC_CAST(nsMouseEvent_base*, mEvent)->relatedTarget = aRelatedTarget; + NS_STATIC_CAST(nsMouseEvent_base*, mEvent)->button = aButton; nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, mEvent); inputEvent->isControl = aCtrlKey; inputEvent->isAlt = aAltKey; @@ -133,26 +128,7 @@ nsDOMMouseEvent::InitMouseEvent(const nsAString & aType, PRBool aCanBubble, PRBo mClientPoint.y = aClientY; inputEvent->refPoint.x = aScreenX; inputEvent->refPoint.y = aScreenY; - mButton = aButton; - // Now fix up mEvent->message, since nsDOMUIEvent::InitUIEvent - // doesn't have enough information to set it right. - // XXXbz AARGH. No useful constants for the buttons! - if (mEvent->message == NS_MOUSE_LEFT_CLICK) { - if (mButton == 1) { // Middle button - mEvent->message = NS_MOUSE_MIDDLE_CLICK; - } - else if (mButton == 2) { // Right button - mEvent->message = NS_MOUSE_RIGHT_CLICK; - } - } - if (mEvent->message == NS_MOUSE_LEFT_DOUBLECLICK) { - if (mButton == 1) { // Middle button - mEvent->message = NS_MOUSE_MIDDLE_DOUBLECLICK; - } - else if (mButton == 2) { // Right button - mEvent->message = NS_MOUSE_RIGHT_DOUBLECLICK; - } - } + if (mEvent->eventStructType == NS_MOUSE_SCROLL_EVENT) { nsMouseScrollEvent* scrollEvent = NS_STATIC_CAST(nsMouseScrollEvent*, mEvent); scrollEvent->delta = aDetail; @@ -173,42 +149,16 @@ 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: - case NS_CONTEXTMENU: - *aButton = 2; + switch(mEvent->eventStructType) + { + case NS_MOUSE_EVENT: + case NS_MOUSE_SCROLL_EVENT: + *aButton = NS_STATIC_CAST(nsMouseEvent_base*, mEvent)->button; break; default: - // This event doesn't have a mouse button associated with it - *aButton = (PRUint16)0; + NS_WARNING("Tried to get mouse button for non-mouse event!"); + *aButton = nsMouseEvent::eLeftButton; break; - } } return NS_OK; } @@ -222,10 +172,8 @@ nsDOMMouseEvent::GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget) switch(mEvent->eventStructType) { case NS_MOUSE_EVENT: - relatedTarget = NS_STATIC_CAST(nsMouseEvent*, mEvent)->relatedTarget; - break; case NS_MOUSE_SCROLL_EVENT: - relatedTarget = NS_STATIC_CAST(nsMouseScrollEvent*, mEvent)->relatedTarget; + relatedTarget = NS_STATIC_CAST(nsMouseEvent_base*, mEvent)->relatedTarget; break; default: break; diff --git a/mozilla/content/events/src/nsDOMMouseEvent.h b/mozilla/content/events/src/nsDOMMouseEvent.h index 3daf25b029c..a498484f268 100644 --- a/mozilla/content/events/src/nsDOMMouseEvent.h +++ b/mozilla/content/events/src/nsDOMMouseEvent.h @@ -63,10 +63,6 @@ public: // 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/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index b8405361330..9c38e4ad3c4 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -173,18 +173,10 @@ struct EventTypeData #define HANDLER(x) NS_REINTERPRET_CAST(GenericHandler, x) static const EventDispatchData sMouseEvents[] = { - { NS_MOUSE_LEFT_BUTTON_DOWN, HANDLER(&nsIDOMMouseListener::MouseDown) }, - { NS_MOUSE_MIDDLE_BUTTON_DOWN, HANDLER(&nsIDOMMouseListener::MouseDown) }, - { NS_MOUSE_RIGHT_BUTTON_DOWN, HANDLER(&nsIDOMMouseListener::MouseDown) }, - { NS_MOUSE_LEFT_BUTTON_UP, HANDLER(&nsIDOMMouseListener::MouseUp) }, - { NS_MOUSE_MIDDLE_BUTTON_UP, HANDLER(&nsIDOMMouseListener::MouseUp) }, - { NS_MOUSE_RIGHT_BUTTON_UP, HANDLER(&nsIDOMMouseListener::MouseUp) }, - { NS_MOUSE_LEFT_CLICK, HANDLER(&nsIDOMMouseListener::MouseClick) }, - { NS_MOUSE_MIDDLE_CLICK, HANDLER(&nsIDOMMouseListener::MouseClick) }, - { NS_MOUSE_RIGHT_CLICK, HANDLER(&nsIDOMMouseListener::MouseClick) }, - { NS_MOUSE_LEFT_DOUBLECLICK, HANDLER(&nsIDOMMouseListener::MouseDblClick) }, - { NS_MOUSE_MIDDLE_DOUBLECLICK, HANDLER(&nsIDOMMouseListener::MouseDblClick) }, - { NS_MOUSE_RIGHT_DOUBLECLICK, HANDLER(&nsIDOMMouseListener::MouseDblClick) }, + { NS_MOUSE_BUTTON_DOWN, HANDLER(&nsIDOMMouseListener::MouseDown) }, + { NS_MOUSE_BUTTON_UP, HANDLER(&nsIDOMMouseListener::MouseUp) }, + { NS_MOUSE_CLICK, HANDLER(&nsIDOMMouseListener::MouseClick) }, + { NS_MOUSE_DOUBLECLICK, HANDLER(&nsIDOMMouseListener::MouseDblClick) }, { NS_MOUSE_ENTER_SYNTH, HANDLER(&nsIDOMMouseListener::MouseOver) }, { NS_MOUSE_EXIT_SYNTH, HANDLER(&nsIDOMMouseListener::MouseOut) } }; @@ -194,8 +186,7 @@ static const EventDispatchData sMouseMotionEvents[] = { }; static const EventDispatchData sContextMenuEvents[] = { - { NS_CONTEXTMENU, HANDLER(&nsIDOMContextMenuListener::ContextMenu) }, - { NS_CONTEXTMENU_KEY, HANDLER(&nsIDOMContextMenuListener::ContextMenu) } + { NS_CONTEXTMENU, HANDLER(&nsIDOMContextMenuListener::ContextMenu) } }; static const EventDispatchData sCompositionEvents[] = { @@ -656,10 +647,10 @@ InitializeEventIdTable() { NS_ASSERTION(!gEventIdTable, "EventIdTable already initialized!"); static const EventId eventIdArray[] = { - { &nsGkAtoms::onmousedown, NS_MOUSE_LEFT_BUTTON_DOWN }, - { &nsGkAtoms::onmouseup, NS_MOUSE_LEFT_BUTTON_UP }, - { &nsGkAtoms::onclick, NS_MOUSE_LEFT_CLICK }, - { &nsGkAtoms::ondblclick, NS_MOUSE_LEFT_DOUBLECLICK }, + { &nsGkAtoms::onmousedown, NS_MOUSE_BUTTON_DOWN }, + { &nsGkAtoms::onmouseup, NS_MOUSE_BUTTON_UP }, + { &nsGkAtoms::onclick, NS_MOUSE_CLICK }, + { &nsGkAtoms::ondblclick, NS_MOUSE_DOUBLECLICK }, { &nsGkAtoms::onmouseover, NS_MOUSE_ENTER_SYNTH }, { &nsGkAtoms::onmouseout, NS_MOUSE_EXIT_SYNTH }, { &nsGkAtoms::onmousemove, NS_MOUSE_MOVE }, @@ -763,40 +754,7 @@ nsEventListenerManager::ListenerCanHandle(nsListenerStruct* aLs, // We don't want to check aLs->mEventType here, bug 276846. return (aEvent->userType && aLs->mTypeAtom == aEvent->userType); } - - // Because some event handlers can handle several kinds of events, - // event type must be converted to the one which is used when - // listener is registered. @see also nsDOMEvent::GetEventName. - PRUint32 event = aEvent->message; - switch(event) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - event = NS_MOUSE_LEFT_BUTTON_DOWN; - break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - event = NS_MOUSE_LEFT_BUTTON_UP; - break; - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_RIGHT_CLICK: - event = NS_MOUSE_LEFT_CLICK; - break; - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - event = NS_MOUSE_LEFT_DOUBLECLICK; - break; - case NS_CONTEXTMENU: - case NS_CONTEXTMENU_KEY: - event = NS_CONTEXTMENU; - break; - default: - break; - } - return (aLs->mEventType == event); + return (aLs->mEventType == aEvent->message); } NS_IMETHODIMP @@ -1346,8 +1304,7 @@ nsEventListenerManager::HandleEvent(nsPresContext* aPresContext, } PRUint16 currentGroup = aFlags & NS_EVENT_FLAG_SYSTEM_EVENT; - if ((aEvent->message == NS_CONTEXTMENU || - aEvent->message == NS_CONTEXTMENU_KEY) && + if (aEvent->message == NS_CONTEXTMENU && NS_FAILED(FixContextMenuEvent(aPresContext, aCurrentTarget, aEvent, aDOMEvent))) { NS_WARNING("failed to fix context menu event target"); @@ -1657,13 +1614,15 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, nsresult ret = NS_OK; + PRBool contextMenuKey = + NS_STATIC_CAST(nsMouseEvent*, aEvent)->context == nsMouseEvent::eContextMenuKey; if (nsnull == *aDOMEvent) { // If we're here because of the key-equiv for showing context menus, we // have to twiddle with the NS event to make sure the context menu comes // up in the upper left of the relevant content area before we create // the DOM event. Since we never call InitMouseEvent() on the event, // 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) { + if (contextMenuKey) { NS_IF_RELEASE(((nsGUIEvent*)aEvent)->widget); aPresContext->GetViewManager()->GetWidget(&((nsGUIEvent*)aEvent)->widget); aEvent->refPoint.x = 0; @@ -1674,7 +1633,7 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, } // see if we should use the caret position for the popup - if (aEvent->message == NS_CONTEXTMENU_KEY) { + if (contextMenuKey) { nsPoint caretPoint; if (PrepareToUseCaretPosition(((nsGUIEvent*)aEvent)->widget, shell, caretPoint)) { @@ -1691,7 +1650,7 @@ nsEventListenerManager::FixContextMenuEvent(nsPresContext* aPresContext, nsCOMPtr currentTarget = do_QueryInterface(aCurrentTarget); nsCOMPtr currentFocus; - if (aEvent->message == NS_CONTEXTMENU_KEY) { + if (contextMenuKey) { nsIDocument *doc = shell->GetDocument(); if (doc) { nsPIDOMWindow* privWindow = doc->GetWindow(); diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 04796c7e0e0..10da290b717 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -319,20 +319,11 @@ nsMouseWheelTransaction::OnEvent(nsEvent* aEvent) case NS_KEY_PRESS: case NS_KEY_UP: case NS_KEY_DOWN: - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_BUTTON_UP: + case NS_MOUSE_BUTTON_DOWN: + case NS_MOUSE_DOUBLECLICK: + case NS_MOUSE_CLICK: case NS_CONTEXTMENU: - case NS_CONTEXTMENU_KEY: case NS_DRAGDROP_DROP: EndTransaction(); return; @@ -614,39 +605,47 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, nsMouseWheelTransaction::OnEvent(aEvent); switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: + switch (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button) { + case nsMouseEvent::eLeftButton: #ifndef XP_OS2 - BeginTrackingDragGesture ( aPresContext, (nsMouseEvent*)aEvent, aTargetFrame ); + BeginTrackingDragGesture ( aPresContext, (nsMouseEvent*)aEvent, aTargetFrame ); #endif - mLClickCount = ((nsMouseEvent*)aEvent)->clickCount; - SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); - mNormalLMouseEventInProcess = PR_TRUE; - break; - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - mMClickCount = ((nsMouseEvent*)aEvent)->clickCount; - SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); - break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: + mLClickCount = ((nsMouseEvent*)aEvent)->clickCount; + SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + mNormalLMouseEventInProcess = PR_TRUE; + break; + case nsMouseEvent::eMiddleButton: + mMClickCount = ((nsMouseEvent*)aEvent)->clickCount; + SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + break; + case nsMouseEvent::eRightButton: #ifdef XP_OS2 - BeginTrackingDragGesture ( aPresContext, (nsMouseEvent*)aEvent, aTargetFrame ); + BeginTrackingDragGesture ( aPresContext, (nsMouseEvent*)aEvent, aTargetFrame ); #endif - mRClickCount = ((nsMouseEvent*)aEvent)->clickCount; - SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + mRClickCount = ((nsMouseEvent*)aEvent)->clickCount; + SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + break; + } break; - case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: + switch (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button) { + case nsMouseEvent::eLeftButton: #ifdef CLICK_HOLD_CONTEXT_MENUS - KillClickHoldTimer(); + KillClickHoldTimer(); #endif #ifndef XP_OS2 - StopTrackingDragGesture(); + StopTrackingDragGesture(); #endif - mNormalLMouseEventInProcess = PR_FALSE; - case NS_MOUSE_RIGHT_BUTTON_UP: + mNormalLMouseEventInProcess = PR_FALSE; + case nsMouseEvent::eRightButton: #ifdef XP_OS2 - StopTrackingDragGesture(); + StopTrackingDragGesture(); #endif - case NS_MOUSE_MIDDLE_BUTTON_UP: - SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + case nsMouseEvent::eMiddleButton: + SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus); + break; + } break; case NS_MOUSE_EXIT: // If the event coordinate is within the bounds of the view, @@ -1255,7 +1254,7 @@ nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext, // Propagate trusted state to the new event. nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_LEFT_CLICK, + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsAutoPopupStatePusher popupStatePusher(NS_IS_TRUSTED_EVENT(aEvent) ? @@ -2094,11 +2093,10 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext, if (!mCurrentTarget) return NS_ERROR_NULL_POINTER; switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: { - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && !mNormalLMouseEventInProcess) { + if (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton && + !mNormalLMouseEventInProcess) { //Our state is out of whack. We got a mouseup while still processing //the mousedown. Kill View-level mouse capture or it'll stay stuck if (aView) { @@ -2156,7 +2154,8 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext, } // The rest is left button-specific. - if (aEvent->message != NS_MOUSE_LEFT_BUTTON_DOWN) + if (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button != + nsMouseEvent::eLeftButton) break; if (activeContent) { @@ -2181,9 +2180,7 @@ nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext, } } break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: { SetContentState(nsnull, NS_EVENT_STATE_ACTIVE); if (!mCurrentTarget) { @@ -3130,57 +3127,54 @@ nsEventStateManager::SetClickCount(nsPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus) { - nsresult ret = NS_OK; nsCOMPtr mouseContent; - mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent)); - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - mLastLeftMouseDownContent = mouseContent; - break; - - case NS_MOUSE_LEFT_BUTTON_UP: - if (mLastLeftMouseDownContent == mouseContent) { - aEvent->clickCount = mLClickCount; - mLClickCount = 0; - } - else { - aEvent->clickCount = 0; - } - mLastLeftMouseDownContent = nsnull; - break; - - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - mLastMiddleMouseDownContent = mouseContent; - break; - - case NS_MOUSE_MIDDLE_BUTTON_UP: - if (mLastMiddleMouseDownContent == mouseContent) { - aEvent->clickCount = mMClickCount; - mMClickCount = 0; - } - else { - aEvent->clickCount = 0; + switch (aEvent->button) { + case nsMouseEvent::eLeftButton: + if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { + mLastLeftMouseDownContent = mouseContent; + } else if (aEvent->message == NS_MOUSE_BUTTON_UP) { + if (mLastLeftMouseDownContent == mouseContent) { + aEvent->clickCount = mLClickCount; + mLClickCount = 0; + } else { + aEvent->clickCount = 0; + } + mLastLeftMouseDownContent = nsnull; } break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: - mLastRightMouseDownContent = mouseContent; + case nsMouseEvent::eMiddleButton: + if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { + mLastMiddleMouseDownContent = mouseContent; + } else if (aEvent->message == NS_MOUSE_BUTTON_UP) { + if (mLastMiddleMouseDownContent == mouseContent) { + aEvent->clickCount = mMClickCount; + mMClickCount = 0; + } else { + aEvent->clickCount = 0; + } + // XXX Why we don't clear mLastMiddleMouseDownContent here? + } break; - case NS_MOUSE_RIGHT_BUTTON_UP: - if (mLastRightMouseDownContent == mouseContent) { - aEvent->clickCount = mRClickCount; - mRClickCount = 0; - } - else { - aEvent->clickCount = 0; + case nsMouseEvent::eRightButton: + if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { + mLastRightMouseDownContent = mouseContent; + } else if (aEvent->message == NS_MOUSE_BUTTON_UP) { + if (mLastRightMouseDownContent == mouseContent) { + aEvent->clickCount = mRClickCount; + mRClickCount = 0; + } else { + aEvent->clickCount = 0; + } + // XXX Why we don't clear mLastRightMouseDownContent here? } break; } - return ret; + return NS_OK; } nsresult @@ -3189,28 +3183,19 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, nsEventStatus* aStatus) { nsresult ret = NS_OK; - PRUint32 eventMsg = 0; PRInt32 flags = NS_EVENT_FLAG_NONE; //If mouse is still over same element, clickcount will be > 1. //If it has moved it will be zero, so no click. if (0 != aEvent->clickCount) { //fire click - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - eventMsg = NS_MOUSE_LEFT_CLICK; - break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - eventMsg = NS_MOUSE_MIDDLE_CLICK; - flags |= sLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE; - break; - case NS_MOUSE_RIGHT_BUTTON_UP: - eventMsg = NS_MOUSE_RIGHT_CLICK; - flags |= sLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE; - break; + if (aEvent->button == nsMouseEvent::eMiddleButton || + aEvent->button == nsMouseEvent::eRightButton) { + flags |= + sLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE; } - nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), eventMsg, aEvent->widget, + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_CLICK, aEvent->widget, nsMouseEvent::eReal); event.refPoint = aEvent->refPoint; event.clickCount = aEvent->clickCount; @@ -3220,6 +3205,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, event.isMeta = aEvent->isMeta; event.time = aEvent->time; event.flags |= flags; + event.button = aEvent->button; nsCOMPtr presShell = mPresContext->GetPresShell(); if (presShell) { @@ -3229,21 +3215,8 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, ret = presShell->HandleEventWithTarget(&event, mCurrentTarget, mouseContent, aStatus); if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2) { - eventMsg = 0; //fire double click - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - eventMsg = NS_MOUSE_LEFT_DOUBLECLICK; - break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - eventMsg = NS_MOUSE_MIDDLE_DOUBLECLICK; - break; - case NS_MOUSE_RIGHT_BUTTON_UP: - eventMsg = NS_MOUSE_RIGHT_DOUBLECLICK; - break; - } - - nsMouseEvent event2(NS_IS_TRUSTED_EVENT(aEvent), eventMsg, + nsMouseEvent event2(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_DOUBLECLICK, aEvent->widget, nsMouseEvent::eReal); event2.refPoint = aEvent->refPoint; event2.clickCount = aEvent->clickCount; @@ -3252,6 +3225,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, event2.isAlt = aEvent->isAlt; event2.isMeta = aEvent->isMeta; event2.flags |= flags; + event2.button = aEvent->button; ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, mouseContent, aStatus); @@ -4690,7 +4664,8 @@ NS_IMETHODIMP nsEventStateManager::EventStatusOK(nsGUIEvent* aEvent, PRBool *aOK) { *aOK = PR_TRUE; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) { + if (aEvent->message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { if (!mNormalLMouseEventInProcess) { *aOK = PR_FALSE; } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 3c712c00c21..f1c93637a88 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1481,40 +1481,44 @@ nsGenericHTMLElement::PostHandleEventForAnchors(nsEventChainPostVisitor& aVisito // specified. if (hrefURI) { switch (aVisitor.mEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: { - // don't make the link grab the focus if there is no link handler - nsILinkHandler *handler = aVisitor.mPresContext->GetLinkHandler(); - nsIDocument *document = GetCurrentDoc(); - if (handler && document && ShouldFocus(this)) { - // If the window is not active, do not allow the focus to bring the - // window to the front. We update the focus controller, but do - // nothing else. - nsPIDOMWindow *win = document->GetWindow(); - if (win) { - nsIFocusController *focusController = - win->GetRootFocusController(); - if (focusController) { - PRBool isActive = PR_FALSE; - focusController->GetActive(&isActive); - if (!isActive) { - nsCOMPtr domElement = do_QueryInterface(this); - if(domElement) - focusController->SetFocusedElement(domElement); - break; + if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eLeftButton) { + // don't make the link grab the focus if there is no link handler + nsILinkHandler *handler = aVisitor.mPresContext->GetLinkHandler(); + nsIDocument *document = GetCurrentDoc(); + if (handler && document && ShouldFocus(this)) { + // If the window is not active, do not allow the focus to bring the + // window to the front. We update the focus controller, but do + // nothing else. + nsPIDOMWindow *win = document->GetWindow(); + if (win) { + nsIFocusController *focusController = + win->GetRootFocusController(); + if (focusController) { + PRBool isActive = PR_FALSE; + focusController->GetActive(&isActive); + if (!isActive) { + nsCOMPtr domElement = do_QueryInterface(this); + if(domElement) + focusController->SetFocusedElement(domElement); + break; + } } } + + aVisitor.mPresContext->EventStateManager()-> + SetContentState(this, + NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); } - - aVisitor.mPresContext->EventStateManager()-> - SetContentState(this, - NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); } } break; - case NS_MOUSE_LEFT_CLICK: - if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT) { + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, aVisitor.mEvent); if (inputEvent->isControl || inputEvent->isMeta || diff --git a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp index 8fa466e8ed3..952920ba6d5 100644 --- a/mozilla/content/html/content/src/nsHTMLButtonElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLButtonElement.cpp @@ -213,7 +213,7 @@ nsHTMLButtonElement::Click() // called from chrome JS. Mark this event trusted if Click() // is called from chrome code. nsMouseEvent event(nsContentUtils::IsCallerChrome(), - NS_MOUSE_LEFT_CLICK, nsnull, + NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; nsEventDispatcher::Dispatch(NS_STATIC_CAST(nsIContent*, this), context, @@ -313,10 +313,10 @@ nsHTMLButtonElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) } } - //FIXME Should this use NS_UI_ACTIVATE, not NS_MOUSE_LEFT_CLICK? + //FIXME Should this use NS_UI_ACTIVATE, not NS_MOUSE_CLICK? // https://bugzilla.mozilla.org/show_bug.cgi?id=309348#c16 PRBool bInSubmitClick = mType == NS_FORM_BUTTON_SUBMIT && - aVisitor.mEvent->message == NS_MOUSE_LEFT_CLICK && + NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent) && mForm; if (bInSubmitClick) { @@ -361,7 +361,7 @@ nsHTMLButtonElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) nsEventStatus status = nsEventStatus_eIgnore; nsMouseEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), - NS_MOUSE_LEFT_CLICK, nsnull, + NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsEventDispatcher::Dispatch(NS_STATIC_CAST(nsIContent*, this), aVisitor.mPresContext, &event, nsnull, @@ -370,17 +370,19 @@ nsHTMLButtonElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) } break;// NS_KEY_PRESS - case NS_MOUSE_LEFT_CLICK: + case NS_MOUSE_CLICK: { - nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell(); - if (presShell) { - // single-click - nsUIEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), - NS_UI_ACTIVATE, 1); - nsEventStatus status = nsEventStatus_eIgnore; - - presShell->HandleDOMEventWithTarget(this, &event, &status); - aVisitor.mEventStatus = status; + if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { + nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell(); + if (presShell) { + // single-click + nsUIEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), + NS_UI_ACTIVATE, 1); + nsEventStatus status = nsEventStatus_eIgnore; + + presShell->HandleDOMEventWithTarget(this, &event, &status); + aVisitor.mEventStatus = status; + } } } break; @@ -408,32 +410,42 @@ nsHTMLButtonElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) } } } - break;// NS_MOUSE_LEFT_CLICK + break;// NS_MOUSE_CLICK - case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: { - aVisitor.mPresContext->EventStateManager()-> - SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); - aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; + if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT) { + if (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eLeftButton) { + aVisitor.mPresContext->EventStateManager()-> + SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); + aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; + } else if (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eMiddleButton || + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eRightButton) { + // cancel all of these events for buttons + //XXXsmaug What to do with these events? Why these should be cancelled? + aVisitor.mDOMEvent->StopPropagation(); + } + } } break; // cancel all of these events for buttons //XXXsmaug What to do with these events? Why these should be cancelled? - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: + case NS_MOUSE_DOUBLECLICK: { - if (aVisitor.mDOMEvent) { + if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + aVisitor.mDOMEvent && + (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eMiddleButton || + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eRightButton)) { aVisitor.mDOMEvent->StopPropagation(); - } else { - rv = NS_ERROR_FAILURE; } } - break; case NS_MOUSE_ENTER_SYNTH: @@ -462,7 +474,17 @@ nsHTMLButtonElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) // form.submit() in a left click handler or an activate // handler gets flushed, even if the event handler prevented // the default action. - case NS_MOUSE_LEFT_CLICK: + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { + 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 + // not ignored) so if there is a stored submission, it needs to + // be submitted immediatelly. + mForm->FlushPendingSubmission(); + } + } + break; case NS_UI_ACTIVATE: if (mForm && mType == NS_FORM_BUTTON_SUBMIT) { // Tell the form to flush a possible pending submission. diff --git a/mozilla/content/html/content/src/nsHTMLImageElement.cpp b/mozilla/content/html/content/src/nsHTMLImageElement.cpp index 5b968977576..17be20ec17f 100644 --- a/mozilla/content/html/content/src/nsHTMLImageElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLImageElement.cpp @@ -499,7 +499,10 @@ nsHTMLImageElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) // the Generic Element as this could cause a click event to fire // twice, once by the image frame for the map and once by the Anchor // element. (bug 39723) - if (NS_MOUSE_LEFT_CLICK == aVisitor.mEvent->message) { + if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + aVisitor.mEvent->message == NS_MOUSE_CLICK && + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eLeftButton) { PRBool isMap = PR_FALSE; GetIsMap(&isMap); if (isMap) { diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index e39fa70f21c..1e199a17bb5 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -1029,8 +1029,7 @@ nsHTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) NS_ASSERTION(submitContent, "Form control not implementing nsIContent?!"); // Fire the button's onclick handler and let the button handle // submitting the form. - nsMouseEvent event(PR_TRUE, NS_MOUSE_LEFT_CLICK, nsnull, - nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; shell->HandleDOMEventWithTarget(submitContent, &event, &status); } else if (mForm->HasSingleTextControl()) { @@ -1300,8 +1299,7 @@ nsHTMLInputElement::Click() // called from chrome JS. Mark this event trusted if Click() // is called from chrome code. nsMouseEvent event(nsContentUtils::IsCallerChrome(), - NS_MOUSE_LEFT_CLICK, nsnull, - nsMouseEvent::eReal); + NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; SET_BOOLBIT(mBitField, BF_HANDLING_CLICK, PR_TRUE); @@ -1365,7 +1363,7 @@ nsHTMLInputElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) // DOMActivate that was dispatched directly, this will be set, but if we're // a DOMActivate dispatched from click handling, it will not be set. PRBool outerActivateEvent = - (aVisitor.mEvent->message == NS_MOUSE_LEFT_CLICK || + (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent) || (aVisitor.mEvent->message == NS_UI_ACTIVATE && !GET_BOOLBIT(mBitField, BF_IN_INTERNAL_ACTIVATE))); @@ -1434,7 +1432,10 @@ nsHTMLInputElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH; } if ((mType == NS_FORM_INPUT_TEXT || mType == NS_FORM_INPUT_PASSWORD) && - aVisitor.mEvent->message == NS_MOUSE_MIDDLE_CLICK) { + aVisitor.mEvent->message == NS_MOUSE_CLICK && + aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eMiddleButton) { aVisitor.mEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH; } @@ -1464,7 +1465,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) // the click. if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault && mType != NS_FORM_INPUT_TEXT && - aVisitor.mEvent->message == NS_MOUSE_LEFT_CLICK) { + NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { nsUIEvent actEvent(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), NS_UI_ACTIVATE, 1); nsIPresShell *shell = aVisitor.mPresContext->GetPresShell(); @@ -1585,8 +1586,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) case NS_FORM_INPUT_IMAGE: // Bug 34418 { nsMouseEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), - NS_MOUSE_LEFT_CLICK, nsnull, - nsMouseEvent::eReal); + NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; nsEventDispatcher::Dispatch(NS_STATIC_CAST(nsIContent*, this), @@ -1620,7 +1620,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) if (NS_SUCCEEDED(rv)) { nsEventStatus status = nsEventStatus_eIgnore; nsMouseEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), - NS_MOUSE_LEFT_CLICK, nsnull, + NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); rv = nsEventDispatcher::Dispatch(radioContent, aVisitor.mPresContext, @@ -1688,25 +1688,28 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) } break; // NS_KEY_PRESS || NS_KEY_UP - // cancel all of these events for buttons - //XXXsmaug Why? - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_DOUBLECLICK: - case NS_MOUSE_RIGHT_DOUBLECLICK: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_DOWN: + case NS_MOUSE_BUTTON_UP: + case NS_MOUSE_DOUBLECLICK: { - if (mType == NS_FORM_INPUT_BUTTON || - mType == NS_FORM_INPUT_RESET || - mType == NS_FORM_INPUT_SUBMIT) { - if (aVisitor.mDOMEvent) { - aVisitor.mDOMEvent->StopPropagation(); - } else { - rv = NS_ERROR_FAILURE; + // cancel all of these events for buttons + //XXXsmaug Why? + if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eMiddleButton || + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eRightButton)) { + if (mType == NS_FORM_INPUT_BUTTON || + mType == NS_FORM_INPUT_RESET || + mType == NS_FORM_INPUT_SUBMIT) { + if (aVisitor.mDOMEvent) { + aVisitor.mDOMEvent->StopPropagation(); + } else { + rv = NS_ERROR_FAILURE; + } } - } + } break; } default: diff --git a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp index 0bf950533fa..845c0f7ffc9 100644 --- a/mozilla/content/html/content/src/nsHTMLLabelElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLLabelElement.cpp @@ -208,7 +208,7 @@ nsresult nsHTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) { if (mHandlingEvent || - (aVisitor.mEvent->message != NS_MOUSE_LEFT_CLICK && + (!NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent) && aVisitor.mEvent->message != NS_FOCUS_CONTENT) || aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault || !aVisitor.mPresContext) { @@ -219,8 +219,8 @@ nsHTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) if (content && !EventTargetIn(aVisitor.mEvent, content, this)) { mHandlingEvent = PR_TRUE; switch (aVisitor.mEvent->message) { - case NS_MOUSE_LEFT_CLICK: - if (aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT) { + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { if (ShouldFocus(this)) { // Focus the for content. content->SetFocus(aVisitor.mPresContext); diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index 0f87586bd4c..3b23823e8a8 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -620,7 +620,10 @@ nsHTMLTextAreaElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor) // middle clicks to go to text fields anyway. if (aVisitor.mEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH) aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH; - if (aVisitor.mEvent->message == NS_MOUSE_MIDDLE_CLICK) { + if (aVisitor.mEvent->message == NS_MOUSE_CLICK && + aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eMiddleButton) { aVisitor.mEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH; } diff --git a/mozilla/content/xml/content/src/nsXMLElement.cpp b/mozilla/content/xml/content/src/nsXMLElement.cpp index 508a213fddf..151fb7ccd8d 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.cpp +++ b/mozilla/content/xml/content/src/nsXMLElement.cpp @@ -264,23 +264,28 @@ nsXMLElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) { nsresult rv = NS_OK; if (mIsLink && nsEventStatus_eIgnore == aVisitor.mEventStatus) { - nsIDocument *document = GetCurrentDoc(); switch (aVisitor.mEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: { - if (aVisitor.mPresContext) { - aVisitor.mPresContext->EventStateManager()-> - SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); - - aVisitor.mEventStatus = nsEventStatus_eConsumeDoDefault; + if (aVisitor.mPresContext && + aVisitor.mEvent->eventStructType == NS_MOUSE_EVENT) { + if (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eLeftButton) { + aVisitor.mPresContext->EventStateManager()-> + SetContentState(this, NS_EVENT_STATE_ACTIVE | NS_EVENT_STATE_FOCUS); + aVisitor.mEventStatus = nsEventStatus_eConsumeDoDefault; + } else if (NS_STATIC_CAST(nsMouseEvent*, aVisitor.mEvent)->button == + nsMouseEvent::eRightButton) { + // XXX Bring up a contextual menu provided by the application + } } } break; - case NS_MOUSE_LEFT_CLICK: + case NS_MOUSE_CLICK: { if (nsEventStatus_eConsumeNoDefault != aVisitor.mEventStatus && - aVisitor.mPresContext) { + aVisitor.mPresContext && NS_IS_MOUSE_LEFT_CLICK(aVisitor.mEvent)) { nsInputEvent* inputEvent = NS_STATIC_CAST(nsInputEvent*, aVisitor.mEvent); if (inputEvent->isControl || inputEvent->isMeta || @@ -313,10 +318,6 @@ nsXMLElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) } break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: - // XXX Bring up a contextual menu provided by the application - break; - case NS_KEY_PRESS: if (aVisitor.mEvent->eventStructType == NS_KEY_EVENT) { nsKeyEvent* keyEvent = NS_STATIC_CAST(nsKeyEvent*, aVisitor.mEvent); diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index ccd74deb906..a06e1caa2c4 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -2178,11 +2178,11 @@ nsXULElement::Click() PRBool isCallerChrome = nsContentUtils::IsCallerChrome(); - nsMouseEvent eventDown(isCallerChrome, NS_MOUSE_LEFT_BUTTON_DOWN, + nsMouseEvent eventDown(isCallerChrome, NS_MOUSE_BUTTON_DOWN, nsnull, nsMouseEvent::eReal); - nsMouseEvent eventUp(isCallerChrome, NS_MOUSE_LEFT_BUTTON_UP, + nsMouseEvent eventUp(isCallerChrome, NS_MOUSE_BUTTON_UP, nsnull, nsMouseEvent::eReal); - nsMouseEvent eventClick(isCallerChrome, NS_MOUSE_LEFT_CLICK, nsnull, + nsMouseEvent eventClick(isCallerChrome, NS_MOUSE_CLICK, nsnull, nsMouseEvent::eReal); // send mouse down diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 91f133e7d0e..63682ddf774 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -5841,7 +5841,7 @@ PresShell::HandleEvent(nsIView *aView, PRBool dispatchUsingCoordinates = !NS_IS_KEY_EVENT(aEvent) && !NS_IS_IME_EVENT(aEvent) && - aEvent->message != NS_CONTEXTMENU_KEY && !NS_IS_FOCUS_EVENT(aEvent); + !NS_IS_CONTEXT_MENU_KEY(aEvent) && !NS_IS_FOCUS_EVENT(aEvent); // if this event has no frame, we need to retarget it at a parent // view that has a frame. @@ -5900,7 +5900,7 @@ PresShell::HandleEvent(nsIView *aView, nsIEventStateManager *esm = mPresContext->EventStateManager(); if (NS_IS_KEY_EVENT(aEvent) || NS_IS_IME_EVENT(aEvent) || - aEvent->message == NS_CONTEXTMENU_KEY) { + NS_IS_CONTEXT_MENU_KEY(aEvent)) { esm->GetFocusedFrame(&mCurrentEventFrame); if (mCurrentEventFrame) { esm->GetFocusedContent(getter_AddRefs(mCurrentEventContent)); @@ -6139,12 +6139,8 @@ PresShell::HandleEventInternal(nsEvent* aEvent, nsIView *aView, if (!nsContentUtils::IsCallerChrome()) { break; } - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_BUTTON_DOWN: + case NS_MOUSE_BUTTON_UP: case NS_KEY_PRESS: case NS_KEY_DOWN: case NS_KEY_UP: diff --git a/mozilla/layout/forms/nsImageControlFrame.cpp b/mozilla/layout/forms/nsImageControlFrame.cpp index 135284a1f30..25acb4f3208 100644 --- a/mozilla/layout/forms/nsImageControlFrame.cpp +++ b/mozilla/layout/forms/nsImageControlFrame.cpp @@ -230,15 +230,13 @@ nsImageControlFrame::HandleEvent(nsPresContext* aPresContext, *aEventStatus = nsEventStatus_eIgnore; - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - { - // Store click point for GetNamesValues - // Do this on MouseUp because the specs don't say and that's what IE does - nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); - TranslateEventCoords(pt, mLastClickPoint); - break; - } + if (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_UP && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { + // Store click point for GetNamesValues + // Do this on MouseUp because the specs don't say and that's what IE does + nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); + TranslateEventCoords(pt, mLastClickPoint); } return nsImageControlFrameSuper::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index eae8fe7b299..2af14c7be8f 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -1527,23 +1527,19 @@ nsFrame::HandleEvent(nsPresContext* aPresContext, nsGUIEvent* aEvent, nsEventStatus* aEventStatus) { - switch (aEvent->message) - { - case NS_MOUSE_MOVE: - { - HandleDrag(aPresContext, aEvent, aEventStatus); - }break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - { + + if (aEvent->message == NS_MOUSE_MOVE) { + return HandleDrag(aPresContext, aEvent, aEventStatus); + } + + if (aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { + if (aEvent->message == NS_MOUSE_BUTTON_DOWN) { HandlePress(aPresContext, aEvent, aEventStatus); - }break; - case NS_MOUSE_LEFT_BUTTON_UP: - { + } else if (aEvent->message == NS_MOUSE_BUTTON_UP) { HandleRelease(aPresContext, aEvent, aEventStatus); - } break; - default: - break; - }//end switch + } + } return NS_OK; } @@ -1574,7 +1570,8 @@ nsFrame::GetDataForTableSelection(nsFrameSelection *aFrameSelection, PRBool doTableSelection = displaySelection == nsISelectionDisplay::DISPLAY_ALL && selectingTableCells && (aMouseEvent->message == NS_MOUSE_MOVE || - aMouseEvent->message == NS_MOUSE_LEFT_BUTTON_UP || + (aMouseEvent->message == NS_MOUSE_BUTTON_UP && + aMouseEvent->button == nsMouseEvent::eLeftButton) || aMouseEvent->isShift); if (!doTableSelection) diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 84f5a3a5c07..6df774e8ded 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -792,8 +792,12 @@ NS_METHOD nsHTMLFramesetFrame::HandleEvent(nsPresContext* aPresContext, case NS_MOUSE_MOVE: MouseDrag(aPresContext, aEvent); break; - case NS_MOUSE_LEFT_BUTTON_UP: - EndMouseDrag(aPresContext); + case NS_MOUSE_BUTTON_UP: + if (aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) { + EndMouseDrag(aPresContext); + } break; } *aEventStatus = nsEventStatus_eConsumeNoDefault; @@ -1780,14 +1784,14 @@ nsHTMLFramesetBorderFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - nsHTMLFramesetFrame* parentFrame; - nsIFrame* fptr = GetParent(); - parentFrame = (nsHTMLFramesetFrame*) fptr; - parentFrame->StartMouseDrag(aPresContext, this, aEvent); - *aEventStatus = nsEventStatus_eConsumeNoDefault; - break; + if (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { + nsHTMLFramesetFrame* parentFrame; + nsIFrame* fptr = GetParent(); + parentFrame = (nsHTMLFramesetFrame*) fptr; + parentFrame->StartMouseDrag(aPresContext, this, aEvent); + *aEventStatus = nsEventStatus_eConsumeNoDefault; } return NS_OK; } diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index e87ea34a494..e367749dc9b 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -1665,60 +1665,56 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext, NS_ENSURE_ARG_POINTER(aEventStatus); nsImageMap* map; - switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MOVE: - { - map = GetImageMap(aPresContext); - PRBool isServerMap = IsServerImageMap(); - if ((nsnull != map) || isServerMap) { - nsPoint p; - TranslateEventCoords( - nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p); - PRBool inside = PR_FALSE; - // Even though client-side image map triggering happens - // through content, we need to make sure we're not inside - // (in case we deal with a case of both client-side and - // sever-side on the same image - it happens!) - if (nsnull != map) { - nsCOMPtr area; - inside = map->IsInside(p.x, p.y, getter_AddRefs(area)); - } + if (aEvent->eventStructType == NS_MOUSE_EVENT && + (aEvent->message == NS_MOUSE_BUTTON_UP && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) || + aEvent->message == NS_MOUSE_MOVE) { + map = GetImageMap(aPresContext); + PRBool isServerMap = IsServerImageMap(); + if ((nsnull != map) || isServerMap) { + nsPoint p; + TranslateEventCoords( + nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this), p); + PRBool inside = PR_FALSE; + // Even though client-side image map triggering happens + // through content, we need to make sure we're not inside + // (in case we deal with a case of both client-side and + // sever-side on the same image - it happens!) + if (nsnull != map) { + nsCOMPtr area; + inside = map->IsInside(p.x, p.y, getter_AddRefs(area)); + } - if (!inside && isServerMap) { + if (!inside && isServerMap) { - // Server side image maps use the href in a containing anchor - // element to provide the basis for the destination url. - nsCOMPtr uri; - nsAutoString target; - nsCOMPtr anchorNode; - if (GetAnchorHREFTargetAndNode(getter_AddRefs(uri), target, - getter_AddRefs(anchorNode))) { - // XXX if the mouse is over/clicked in the border/padding area - // we should probably just pretend nothing happened. Nav4 - // keeps the x,y coordinates positive as we do; IE doesn't - // bother. Both of them send the click through even when the - // mouse is over the border. - if (p.x < 0) p.x = 0; - if (p.y < 0) p.y = 0; - nsCAutoString spec; - uri->GetSpec(spec); - spec += nsPrintfCString("?%d,%d", p.x, p.y); - uri->SetSpec(spec); - - PRBool clicked = PR_FALSE; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) { - *aEventStatus = nsEventStatus_eConsumeDoDefault; - clicked = PR_TRUE; - } - TriggerLink(aPresContext, uri, target, anchorNode, clicked); + // Server side image maps use the href in a containing anchor + // element to provide the basis for the destination url. + nsCOMPtr uri; + nsAutoString target; + nsCOMPtr anchorNode; + if (GetAnchorHREFTargetAndNode(getter_AddRefs(uri), target, + getter_AddRefs(anchorNode))) { + // XXX if the mouse is over/clicked in the border/padding area + // we should probably just pretend nothing happened. Nav4 + // keeps the x,y coordinates positive as we do; IE doesn't + // bother. Both of them send the click through even when the + // mouse is over the border. + if (p.x < 0) p.x = 0; + if (p.y < 0) p.y = 0; + nsCAutoString spec; + uri->GetSpec(spec); + spec += nsPrintfCString("?%d,%d", p.x, p.y); + uri->SetSpec(spec); + + PRBool clicked = PR_FALSE; + if (aEvent->message == NS_MOUSE_BUTTON_UP) { + *aEventStatus = nsEventStatus_eConsumeDoDefault; + clicked = PR_TRUE; } + TriggerLink(aPresContext, uri, target, anchorNode, clicked); } } - break; } - default: - break; } return nsSplittableFrame::HandleEvent(aPresContext, aEvent, aEventStatus); diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index caa643e613c..b29af1f1aba 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -2989,7 +2989,10 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const nsGUIEvent& anEvent) mInstance->HandleEvent(&pluginEvent, &eventHandled); } - if (eventHandled && !(anEvent.message == NS_MOUSE_LEFT_BUTTON_DOWN && + if (eventHandled && !(anEvent.eventStructType == NS_MOUSE_EVENT && + anEvent.message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent, anEvent).button == + nsMouseEvent::eLeftButton && !mContentFocused)) rv = nsEventStatus_eConsumeNoDefault; diff --git a/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp b/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp index 7c8aa7c7292..4349d3da45e 100644 --- a/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsButtonBoxFrame.cpp @@ -133,8 +133,10 @@ nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext, aEvent); + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) { + MouseClicked(aPresContext, aEvent); + } break; } diff --git a/mozilla/layout/xul/base/src/nsMenuFrame.cpp b/mozilla/layout/xul/base/src/nsMenuFrame.cpp index 4885c329ebb..01baf34bd49 100644 --- a/mozilla/layout/xul/base/src/nsMenuFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuFrame.cpp @@ -418,7 +418,10 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, OpenMenu(!IsOpen()); #endif } - else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && !IsDisabled() && IsMenu() ) { + else if (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton && + !IsDisabled() && IsMenu()) { PRBool isMenuBar = PR_FALSE; if (mMenuParent) mMenuParent->IsMenuBar(isMenuBar); @@ -450,7 +453,10 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, } else if ( #ifndef NSCONTEXTMENUISMOUSEUP - aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP && + (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_UP && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eRightButton) && #else aEvent->message == NS_CONTEXTMENU && #endif @@ -472,7 +478,10 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, Execute(aEvent); } } - else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP && !IsMenu() && mMenuParent && !IsDisabled()) { + else if (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_UP && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton && + !IsMenu() && mMenuParent && !IsDisabled()) { // Execute the execute event handler. Execute(aEvent); } diff --git a/mozilla/layout/xul/base/src/nsResizerFrame.cpp b/mozilla/layout/xul/base/src/nsResizerFrame.cpp index 521e9551bc8..753743f84ab 100644 --- a/mozilla/layout/xul/base/src/nsResizerFrame.cpp +++ b/mozilla/layout/xul/base/src/nsResizerFrame.cpp @@ -97,28 +97,34 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: { + case NS_MOUSE_BUTTON_DOWN: { + if (aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) + { + // we're tracking. + mTrackingMouseMove = PR_TRUE; - // we're tracking. - mTrackingMouseMove = PR_TRUE; + // start capture. + aEvent->widget->CaptureMouse(PR_TRUE); + CaptureMouseEvents(aPresContext,PR_TRUE); - // start capture. - aEvent->widget->CaptureMouse(PR_TRUE); - CaptureMouseEvents(aPresContext,PR_TRUE); + // remember current mouse coordinates. + mLastPoint = aEvent->refPoint; + aEvent->widget->GetScreenBounds(mWidgetRect); - // remember current mouse coordinates. - mLastPoint = aEvent->refPoint; - aEvent->widget->GetScreenBounds(mWidgetRect); - - *aEventStatus = nsEventStatus_eConsumeNoDefault; - doDefault = PR_FALSE; + *aEventStatus = nsEventStatus_eConsumeNoDefault; + doDefault = PR_FALSE; + } } break; - case NS_MOUSE_LEFT_BUTTON_UP: { + case NS_MOUSE_BUTTON_UP: { - if(mTrackingMouseMove) + if(mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) { // we're done tracking. mTrackingMouseMove = PR_FALSE; @@ -227,8 +233,11 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, - case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext, aEvent); + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) + { + MouseClicked(aPresContext, aEvent); + } break; } diff --git a/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp b/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp index 5d844572f51..d819863fb54 100644 --- a/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp @@ -266,9 +266,7 @@ nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP || - aEvent->message == NS_MOUSE_MIDDLE_BUTTON_UP || - aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP) { + if (aEvent->message == NS_MOUSE_BUTTON_UP) { nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); } diff --git a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp index 0628c9d2a67..edf11a03bdc 100644 --- a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp @@ -138,9 +138,11 @@ nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext, mTrustedEvent = PR_FALSE; break; - case NS_MOUSE_LEFT_CLICK: - // skip button frame handling to prevent click handling - return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) { + // skip button frame handling to prevent click handling + return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus); + } break; } diff --git a/mozilla/layout/xul/base/src/nsScrollbarButtonFrame.cpp b/mozilla/layout/xul/base/src/nsScrollbarButtonFrame.cpp index 2deec289348..77859defd0c 100644 --- a/mozilla/layout/xul/base/src/nsScrollbarButtonFrame.cpp +++ b/mozilla/layout/xul/base/src/nsScrollbarButtonFrame.cpp @@ -86,10 +86,8 @@ nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, nsEventStatus* aEventStatus) { // XXX hack until handle release is actually called in nsframe. - if (aEvent->message == NS_MOUSE_EXIT_SYNTH || - aEvent->message == NS_MOUSE_RIGHT_BUTTON_UP || - aEvent->message == NS_MOUSE_LEFT_BUTTON_UP || - aEvent->message == NS_MOUSE_MIDDLE_BUTTON_UP) + if (aEvent->message == NS_MOUSE_EXIT_SYNTH || + aEvent->message == NS_MOUSE_BUTTON_UP) HandleRelease(aPresContext, aEvent, aEventStatus); // if we didn't handle the press ourselves, pass it on to the superclass @@ -106,14 +104,21 @@ nsScrollbarButtonFrame::HandleButtonPress(nsPresContext* aPresContext, { // Get the desired action for the scrollbar button. nsILookAndFeel::nsMetricID tmpAction; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) - tmpAction = nsILookAndFeel::eMetric_ScrollButtonLeftMouseButtonAction; - else if (aEvent->message == NS_MOUSE_MIDDLE_BUTTON_DOWN) - tmpAction = nsILookAndFeel::eMetric_ScrollButtonMiddleMouseButtonAction; - else if (aEvent->message == NS_MOUSE_RIGHT_BUTTON_DOWN) - tmpAction = nsILookAndFeel::eMetric_ScrollButtonRightMouseButtonAction; - else + if (aEvent->eventStructType == NS_MOUSE_EVENT && + aEvent->message == NS_MOUSE_BUTTON_DOWN) { + PRUint16 button = NS_STATIC_CAST(nsMouseEvent*, aEvent)->button; + if (button == nsMouseEvent::eLeftButton) { + tmpAction = nsILookAndFeel::eMetric_ScrollButtonLeftMouseButtonAction; + } else if (button == nsMouseEvent::eMiddleButton) { + tmpAction = nsILookAndFeel::eMetric_ScrollButtonMiddleMouseButtonAction; + } else if (button == nsMouseEvent::eRightButton) { + tmpAction = nsILookAndFeel::eMetric_ScrollButtonRightMouseButtonAction; + } else { + return PR_FALSE; + } + } else { return PR_FALSE; + } // Get the button action metric from the pres. shell. PRInt32 pressedButtonAction; diff --git a/mozilla/layout/xul/base/src/nsSliderFrame.cpp b/mozilla/layout/xul/base/src/nsSliderFrame.cpp index 035f86f6c40..02df109bb33 100644 --- a/mozilla/layout/xul/base/src/nsSliderFrame.cpp +++ b/mozilla/layout/xul/base/src/nsSliderFrame.cpp @@ -528,21 +528,24 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - if(!gMiddlePref) + case NS_MOUSE_BUTTON_UP: + if (aEvent->eventStructType != NS_MOUSE_EVENT || + (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eMiddleButton && + !gMiddlePref)) { break; - - case NS_MOUSE_LEFT_BUTTON_UP: - // stop capturing - //printf("stop capturing\n"); - AddListener(); - DragThumb(PR_FALSE); - if (mChange) { - nsRepeatService::GetInstance()->Stop(); - mChange = 0; } - mRedrawImmediate = PR_FALSE;//we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state. - return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); + + if (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) { + // stop capturing + AddListener(); + DragThumb(PR_FALSE); + if (mChange) { + nsRepeatService::GetInstance()->Stop(); + mChange = 0; + } + mRedrawImmediate = PR_FALSE;//we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state. + return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); + } } // we want to draw immediately if the user doing it directly with the @@ -551,9 +554,13 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, //return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); return NS_OK; - } - else if ((aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && ((nsMouseEvent *)aEvent)->isShift) - || (gMiddlePref && aEvent->message == NS_MOUSE_MIDDLE_BUTTON_DOWN)) { + } else if ((aEvent->message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->isShift) || + (gMiddlePref && aEvent->message == NS_MOUSE_BUTTON_DOWN && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eMiddleButton)) { // convert coord from twips to pixels nsPoint eventPoint = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); diff --git a/mozilla/layout/xul/base/src/nsSplitterFrame.cpp b/mozilla/layout/xul/base/src/nsSplitterFrame.cpp index 80f08947aac..a9aa2e2a14c 100644 --- a/mozilla/layout/xul/base/src/nsSplitterFrame.cpp +++ b/mozilla/layout/xul/base/src/nsSplitterFrame.cpp @@ -472,8 +472,12 @@ nsSplitterFrame::HandleEvent(nsPresContext* aPresContext, mInner->MouseDrag(aPresContext, aEvent); break; - case NS_MOUSE_LEFT_BUTTON_UP: - mInner->MouseUp(aPresContext, aEvent); + case NS_MOUSE_BUTTON_UP: + if (aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) { + mInner->MouseUp(aPresContext, aEvent); + } break; } diff --git a/mozilla/layout/xul/base/src/nsTitleBarFrame.cpp b/mozilla/layout/xul/base/src/nsTitleBarFrame.cpp index 780933303e8..3ecfd06788d 100644 --- a/mozilla/layout/xul/base/src/nsTitleBarFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTitleBarFrame.cpp @@ -114,28 +114,34 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, switch (aEvent->message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: { + case NS_MOUSE_BUTTON_DOWN: { + if (aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) + { - // we're tracking. - mTrackingMouseMove = PR_TRUE; + // we're tracking. + mTrackingMouseMove = PR_TRUE; - // start capture. - CaptureMouseEvents(aPresContext,PR_TRUE); + // start capture. + CaptureMouseEvents(aPresContext,PR_TRUE); - // remember current mouse coordinates. - mLastPoint = aEvent->refPoint; + // remember current mouse coordinates. + mLastPoint = aEvent->refPoint; - *aEventStatus = nsEventStatus_eConsumeNoDefault; - doDefault = PR_FALSE; + *aEventStatus = nsEventStatus_eConsumeNoDefault; + doDefault = PR_FALSE; + } } break; - case NS_MOUSE_LEFT_BUTTON_UP: { - - if(mTrackingMouseMove) + case NS_MOUSE_BUTTON_UP: { + if(mTrackingMouseMove && aEvent->eventStructType == NS_MOUSE_EVENT && + NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == + nsMouseEvent::eLeftButton) { // we're done tracking. mTrackingMouseMove = PR_FALSE; @@ -170,8 +176,11 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, - case NS_MOUSE_LEFT_CLICK: - MouseClicked(aPresContext, aEvent); + case NS_MOUSE_CLICK: + if (NS_IS_MOUSE_LEFT_CLICK(aEvent)) + { + MouseClicked(aPresContext, aEvent); + } break; } diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index de64e01aa8d..8c84b2256dc 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -1525,7 +1525,7 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS PRBool capturedEvent = PR_FALSE; if (!NS_IS_KEY_EVENT(aEvent) && !NS_IS_IME_EVENT(aEvent) && - aEvent->message != NS_CONTEXTMENU_KEY && !NS_IS_FOCUS_EVENT(aEvent)) { + !NS_IS_CONTEXT_MENU_KEY(aEvent) && !NS_IS_FOCUS_EVENT(aEvent)) { // will dispatch using coordinates. Pretty bogus but it's consistent // with what presshell does. view = GetDisplayRootFor(baseView); diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index b6bbce34d20..a35f502019b 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -199,27 +199,18 @@ class nsHashKey; #define NS_MOUSE_MESSAGE_START 300 #define NS_MOUSE_MOVE (NS_MOUSE_MESSAGE_START) -#define NS_MOUSE_LEFT_BUTTON_UP (NS_MOUSE_MESSAGE_START + 1) -#define NS_MOUSE_LEFT_BUTTON_DOWN (NS_MOUSE_MESSAGE_START + 2) -#define NS_MOUSE_MIDDLE_BUTTON_UP (NS_MOUSE_MESSAGE_START + 10) -#define NS_MOUSE_MIDDLE_BUTTON_DOWN (NS_MOUSE_MESSAGE_START + 11) -#define NS_MOUSE_RIGHT_BUTTON_UP (NS_MOUSE_MESSAGE_START + 20) -#define NS_MOUSE_RIGHT_BUTTON_DOWN (NS_MOUSE_MESSAGE_START + 21) +#define NS_MOUSE_BUTTON_UP (NS_MOUSE_MESSAGE_START + 1) +#define NS_MOUSE_BUTTON_DOWN (NS_MOUSE_MESSAGE_START + 2) #define NS_MOUSE_ENTER (NS_MOUSE_MESSAGE_START + 22) #define NS_MOUSE_EXIT (NS_MOUSE_MESSAGE_START + 23) -#define NS_MOUSE_LEFT_DOUBLECLICK (NS_MOUSE_MESSAGE_START + 24) -#define NS_MOUSE_MIDDLE_DOUBLECLICK (NS_MOUSE_MESSAGE_START + 25) -#define NS_MOUSE_RIGHT_DOUBLECLICK (NS_MOUSE_MESSAGE_START + 26) -#define NS_MOUSE_LEFT_CLICK (NS_MOUSE_MESSAGE_START + 27) -#define NS_MOUSE_MIDDLE_CLICK (NS_MOUSE_MESSAGE_START + 28) -#define NS_MOUSE_RIGHT_CLICK (NS_MOUSE_MESSAGE_START + 29) +#define NS_MOUSE_DOUBLECLICK (NS_MOUSE_MESSAGE_START + 24) +#define NS_MOUSE_CLICK (NS_MOUSE_MESSAGE_START + 27) #define NS_MOUSE_ACTIVATE (NS_MOUSE_MESSAGE_START + 30) #define NS_MOUSE_ENTER_SYNTH (NS_MOUSE_MESSAGE_START + 31) #define NS_MOUSE_EXIT_SYNTH (NS_MOUSE_MESSAGE_START + 32) #define NS_CONTEXTMENU_MESSAGE_START 500 #define NS_CONTEXTMENU (NS_CONTEXTMENU_MESSAGE_START) -#define NS_CONTEXTMENU_KEY (NS_CONTEXTMENU_MESSAGE_START + 1) #define NS_SCROLLBAR_MESSAGE_START 1000 #define NS_SCROLLBAR_POS (NS_SCROLLBAR_MESSAGE_START) @@ -619,29 +610,52 @@ public: * Mouse event */ -class nsMouseEvent : public nsInputEvent +class nsMouseEvent_base : public nsInputEvent { public: - enum reasonType { eReal, eSynthesized }; + nsMouseEvent_base(PRBool isTrusted, PRUint32 msg, nsIWidget *w, PRUint8 type) + : nsInputEvent(isTrusted, msg, w, type), button(0) {} + + /// The possible related target + nsCOMPtr relatedTarget; + + PRInt16 button; +}; + +class nsMouseEvent : public nsMouseEvent_base +{ +public: + enum buttonType { eLeftButton = 0, eMiddleButton = 1, eRightButton = 2 }; + enum reasonType { eReal, eSynthesized }; + enum contextType { eNormal, eContextMenuKey }; nsMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w, - reasonType aReason) - : nsInputEvent(isTrusted, msg, w, NS_MOUSE_EVENT), - clickCount(0), acceptActivation(PR_FALSE), reason(aReason) + reasonType aReason, contextType aContext = eNormal) + : nsMouseEvent_base(isTrusted, msg, w, NS_MOUSE_EVENT), + acceptActivation(PR_FALSE), reason(aReason), context(aContext), + clickCount(0) { if (msg == NS_MOUSE_MOVE) { flags |= NS_EVENT_FLAG_CANT_CANCEL; + } else if (msg == NS_CONTEXTMENU) { + button = eRightButton; } } +#ifdef NS_DEBUG + ~nsMouseEvent() { + NS_WARN_IF_FALSE(message != NS_CONTEXTMENU || button == eRightButton, + "Wrong button set to NS_CONTEXTMENU event?"); + } +#endif - /// The number of mouse clicks - PRUint32 clickCount; /// Special return code for MOUSE_ACTIVATE to signal /// if the target accepts activation (1), or denies it (0) - PRPackedBool acceptActivation; - reasonType reason : 8; - /// The possible related target - nsCOMPtr relatedTarget; + PRPackedBool acceptActivation; + reasonType reason : 4; + contextType context : 4; + + /// The number of mouse clicks + PRUint32 clickCount; }; /** @@ -738,7 +752,7 @@ public: nsTextEventReply theReply; }; -class nsMouseScrollEvent : public nsInputEvent +class nsMouseScrollEvent : public nsMouseEvent_base { public: enum nsMouseScrollFlags { @@ -749,15 +763,13 @@ public: }; nsMouseScrollEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w) - : nsInputEvent(isTrusted, msg, w, NS_MOUSE_SCROLL_EVENT), + : nsMouseEvent_base(isTrusted, msg, w, NS_MOUSE_SCROLL_EVENT), scrollFlags(0), delta(0) { } PRInt32 scrollFlags; PRInt32 delta; - /// The possible related target - nsCOMPtr relatedTarget; }; struct nsReconversionEventReply { @@ -950,18 +962,10 @@ enum nsDragDropEventStatus { #define NS_IS_MOUSE_EVENT(evnt) \ - (((evnt)->message == NS_MOUSE_LEFT_BUTTON_DOWN) || \ - ((evnt)->message == NS_MOUSE_LEFT_BUTTON_UP) || \ - ((evnt)->message == NS_MOUSE_LEFT_CLICK) || \ - ((evnt)->message == NS_MOUSE_LEFT_DOUBLECLICK) || \ - ((evnt)->message == NS_MOUSE_MIDDLE_BUTTON_DOWN) || \ - ((evnt)->message == NS_MOUSE_MIDDLE_BUTTON_UP) || \ - ((evnt)->message == NS_MOUSE_MIDDLE_CLICK) || \ - ((evnt)->message == NS_MOUSE_MIDDLE_DOUBLECLICK) || \ - ((evnt)->message == NS_MOUSE_RIGHT_BUTTON_DOWN) || \ - ((evnt)->message == NS_MOUSE_RIGHT_BUTTON_UP) || \ - ((evnt)->message == NS_MOUSE_RIGHT_CLICK) || \ - ((evnt)->message == NS_MOUSE_RIGHT_DOUBLECLICK) || \ + (((evnt)->message == NS_MOUSE_BUTTON_DOWN) || \ + ((evnt)->message == NS_MOUSE_BUTTON_UP) || \ + ((evnt)->message == NS_MOUSE_CLICK) || \ + ((evnt)->message == NS_MOUSE_DOUBLECLICK) || \ ((evnt)->message == NS_MOUSE_ENTER) || \ ((evnt)->message == NS_MOUSE_EXIT) || \ ((evnt)->message == NS_MOUSE_ACTIVATE) || \ @@ -969,6 +973,16 @@ enum nsDragDropEventStatus { ((evnt)->message == NS_MOUSE_EXIT_SYNTH) || \ ((evnt)->message == NS_MOUSE_MOVE)) +#define NS_IS_MOUSE_LEFT_CLICK(evnt) \ + ((evnt)->eventStructType == NS_MOUSE_EVENT && \ + (evnt)->message == NS_MOUSE_CLICK && \ + NS_STATIC_CAST(nsMouseEvent*, (evnt))->button == nsMouseEvent::eLeftButton) + +#define NS_IS_CONTEXT_MENU_KEY(evnt) \ + ((evnt)->eventStructType == NS_MOUSE_EVENT && \ + (evnt)->message == NS_CONTEXTMENU && \ + NS_STATIC_CAST(nsMouseEvent*, (evnt))->context == nsMouseEvent::eContextMenuKey) + #define NS_IS_DRAG_EVENT(evnt) \ (((evnt)->message == NS_DRAGDROP_ENTER) || \ ((evnt)->message == NS_DRAGDROP_OVER) || \ diff --git a/mozilla/widget/src/beos/nsWindow.cpp b/mozilla/widget/src/beos/nsWindow.cpp index ea1ff3b119d..9dff21b9d34 100644 --- a/mozilla/widget/src/beos/nsWindow.cpp +++ b/mozilla/widget/src/beos/nsWindow.cpp @@ -1828,16 +1828,14 @@ bool nsWindow::CallMethod(MethodInfo *info) case nsSwitchToUIThread::BTNCLICK : { - NS_ASSERTION(info->nArgs == 5, "Wrong number of arguments to CallMethod"); + NS_ASSERTION(info->nArgs == 6, "Wrong number of arguments to CallMethod"); if (!mEnabled) return false; // close popup when clicked outside of the popup window uint32 eventID = ((int32 *)info->args)[0]; PRBool rollup = PR_FALSE; - if ((eventID == NS_MOUSE_LEFT_BUTTON_DOWN || - eventID == NS_MOUSE_RIGHT_BUTTON_DOWN || - eventID == NS_MOUSE_MIDDLE_BUTTON_DOWN) && + if (eventID == NS_MOUSE_BUTTON_DOWN && mView && mView->LockLooper()) { BPoint p(((int32 *)info->args)[1], ((int32 *)info->args)[2]); @@ -1851,14 +1849,17 @@ bool nsWindow::CallMethod(MethodInfo *info) DispatchMouseEvent(((int32 *)info->args)[0], nsPoint(((int32 *)info->args)[1], ((int32 *)info->args)[2]), ((int32 *)info->args)[3], - ((int32 *)info->args)[4]); + ((int32 *)info->args)[4], + ((int32 *)info->args)[5]); - if (((int32 *)info->args)[0] == NS_MOUSE_RIGHT_BUTTON_DOWN) + if (((int32 *)info->args)[0] == NS_MOUSE_BUTTON_DOWN && + ((int32 *)info->args)[5] == nsMouseEvent::eRightButton) { DispatchMouseEvent (NS_CONTEXTMENU, nsPoint(((int32 *)info->args)[1], ((int32 *)info->args)[2]), ((int32 *)info->args)[3], - ((int32 *)info->args)[4]); + ((int32 *)info->args)[4], + ((int32 *)info->args)[5]); } } break; @@ -2658,7 +2659,8 @@ PRBool nsWindow::OnResize(nsRect &aWindowRect) // Deal with all sort of mouse event // //------------------------------------------------------------------------- -PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod) +PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod, + PRUint16 aButton) { PRBool result = PR_FALSE; if (nsnull != mEventCallback || nsnull != mMouseListener) @@ -2670,6 +2672,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint3 event.isAlt = mod & B_COMMAND_KEY; event.isMeta = mod & B_OPTION_KEY; event.clickCount = clicks; + event.button = aButton; // call the event callback if (nsnull != mEventCallback) @@ -2686,15 +2689,11 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint3 result = ConvertStatus(mMouseListener->MouseMoved(event)); break; - case NS_MOUSE_LEFT_BUTTON_DOWN : - case NS_MOUSE_MIDDLE_BUTTON_DOWN : - case NS_MOUSE_RIGHT_BUTTON_DOWN : + case NS_MOUSE_BUTTON_DOWN : result = ConvertStatus(mMouseListener->MousePressed(event)); break; - case NS_MOUSE_LEFT_BUTTON_UP : - case NS_MOUSE_MIDDLE_BUTTON_UP : - case NS_MOUSE_RIGHT_BUTTON_UP : + case NS_MOUSE_BUTTON_UP : result = ConvertStatus(mMouseListener->MouseReleased(event)) && ConvertStatus(mMouseListener->MouseClicked(event)); break; } @@ -3046,17 +3045,19 @@ void nsViewBeOS::MouseDown(BPoint point) if (t == NULL) return; - int32 ev = (buttons & B_PRIMARY_MOUSE_BUTTON) ? NS_MOUSE_LEFT_BUTTON_DOWN : - ((buttons & B_SECONDARY_MOUSE_BUTTON) ? NS_MOUSE_RIGHT_BUTTON_DOWN : - NS_MOUSE_MIDDLE_BUTTON_DOWN); - uint32 args[5]; - args[0] = ev; + PRUint16 eventButton = + (buttons & B_PRIMARY_MOUSE_BUTTON) ? nsMouseEvent::eLeftButton : + ((buttons & B_SECONDARY_MOUSE_BUTTON) ? nsMouseEvent::eRightButton : + nsMouseEvent::eMiddleButton); + uint32 args[6]; + args[0] = NS_MOUSE_BUTTON_DOWN; args[1] = (uint32) point.x; args[2] = (uint32) point.y; args[3] = clicks; args[4] = modifiers(); + args[5] = eventButton; MethodInfo *info = nsnull; - if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 5, args))) + if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 6, args))) t->CallMethodAsync(info); NS_RELEASE(t); } @@ -3129,11 +3130,10 @@ void nsViewBeOS::MouseUp(BPoint point) //To avoid generating extra mouseevents when there is no change in pos. mousePos = point; - int32 ev = (buttons & B_PRIMARY_MOUSE_BUTTON) ? NS_MOUSE_LEFT_BUTTON_UP : - ((buttons & B_SECONDARY_MOUSE_BUTTON) ? NS_MOUSE_RIGHT_BUTTON_UP : - NS_MOUSE_MIDDLE_BUTTON_UP); - - buttons = 0; + PRUint16 eventButton = + (buttons & B_PRIMARY_MOUSE_BUTTON) ? nsMouseEvent::eLeftButton : + ((buttons & B_SECONDARY_MOUSE_BUTTON) ? nsMouseEvent::eRightButton : + nsMouseEvent::eMiddleButton); nsWindow *w = (nsWindow *)GetMozillaWidget(); if (w == NULL) @@ -3143,14 +3143,15 @@ void nsViewBeOS::MouseUp(BPoint point) return; - uint32 args[5]; - args[0] = ev; + uint32 args[6]; + args[0] = NS_MOUSE_BUTTON_UP; args[1] = (uint32) point.x; args[2] = (int32) point.y; args[3] = 0; args[4] = modifiers(); + args[5] = eventButton; MethodInfo *info = nsnull; - if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 5, args))) + if (nsnull != (info = new MethodInfo(w, w, nsSwitchToUIThread::BTNCLICK, 6, args))) t->CallMethodAsync(info); NS_RELEASE(t); } diff --git a/mozilla/widget/src/beos/nsWindow.h b/mozilla/widget/src/beos/nsWindow.h index e4f62d91077..ef4c8f8585a 100644 --- a/mozilla/widget/src/beos/nsWindow.h +++ b/mozilla/widget/src/beos/nsWindow.h @@ -189,7 +189,8 @@ public: virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, - PRUint32 mod); + PRUint32 mod, + PRUint16 aButton = nsMouseEvent::eLeftButton); void InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull); diff --git a/mozilla/widget/src/cocoa/nsChildView.mm b/mozilla/widget/src/cocoa/nsChildView.mm index 18a5056717a..6ddf48fbd9d 100644 --- a/mozilla/widget/src/cocoa/nsChildView.mm +++ b/mozilla/widget/src/cocoa/nsChildView.mm @@ -1659,15 +1659,11 @@ PRBool nsChildView::DispatchMouseEvent(nsMouseEvent &aEvent) result = ConvertStatus(mMouseListener->MouseMoved(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); break; @@ -2688,8 +2684,9 @@ NSEvent* globalDragEvent = nil; #endif nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_LEFT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; geckoEvent.clickCount = [theEvent clickCount]; + geckoEvent.button = nsMouseEvent::eLeftButton; EventRecord macEvent; macEvent.what = mouseDown; @@ -2715,7 +2712,7 @@ NSEvent* globalDragEvent = nil; return; } nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_LEFT_BUTTON_UP toGeckoEvent:&geckoEvent]; + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_UP toGeckoEvent:&geckoEvent]; EventRecord macEvent; macEvent.what = mouseUp; @@ -2905,7 +2902,8 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w // The right mouse went down, fire off a right mouse down event to gecko nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_RIGHT_BUTTON_DOWN toGeckoEvent:&geckoEvent]; + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; + geckoEvent.button = nsMouseEvent::eRightButton; // plugins need a native event here EventRecord macEvent; @@ -2925,7 +2923,8 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w - (void)rightMouseUp:(NSEvent *)theEvent { nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_RIGHT_BUTTON_UP toGeckoEvent:&geckoEvent]; + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_UP toGeckoEvent:&geckoEvent]; + geckoEvent.button = nsMouseEvent::eRightButton; // plugins need a native event here EventRecord macEvent; @@ -2945,8 +2944,9 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w - (void)otherMouseDown:(NSEvent *)theEvent { nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_MIDDLE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_DOWN toGeckoEvent:&geckoEvent]; geckoEvent.clickCount = [theEvent clickCount]; + geckoEvent.button = nsMouseEvent::eMiddleButton; // send event into Gecko by going directly to the // the widget. @@ -2958,8 +2958,9 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w - (void)otherMouseUp:(NSEvent *)theEvent { nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - [self convertEvent:theEvent message:NS_MOUSE_MIDDLE_BUTTON_UP toGeckoEvent:&geckoEvent]; - + [self convertEvent:theEvent message:NS_MOUSE_BUTTON_UP toGeckoEvent:&geckoEvent]; + geckoEvent.button = nsMouseEvent::eMiddleButton; + // send event into Gecko by going directly to the // the widget. mGeckoChild->DispatchMouseEvent(geckoEvent); @@ -3076,6 +3077,7 @@ static nsEventStatus SendMouseEvent(PRBool isTrusted, PRUint32 msg, nsIWidget *w // Fire the context menu event into Gecko. nsMouseEvent geckoEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); [self convertEvent:theEvent message:NS_CONTEXTMENU toGeckoEvent:&geckoEvent]; + geckoEvent.button = nsMouseEvent::eRightButton; mGeckoChild->DispatchMouseEvent(geckoEvent); // Go up our view chain to fetch the correct menu to return. diff --git a/mozilla/widget/src/gtk/nsWidget.cpp b/mozilla/widget/src/gtk/nsWidget.cpp index 5e56a9eebc0..e08252d0054 100644 --- a/mozilla/widget/src/gtk/nsWidget.cpp +++ b/mozilla/widget/src/gtk/nsWidget.cpp @@ -75,7 +75,7 @@ nsWidget *nsWidget::sFocusWindow = 0; guint32 nsWidget::sLastEventTime = 0; // we should convert the context key to context menu event in the OnKey member -// function, and dispatch the NS_CONTEXTMENU_KEY instead of a normal key event. +// function, and dispatch the NS_CONTEXTMENU instead of a normal key event. PRBool nsWidget::OnKey(nsKeyEvent &aEvent) { @@ -122,7 +122,9 @@ ConvertKeyEventToContextMenuEvent(const nsKeyEvent* inKeyEvent, { *(nsInputEvent *)outCMEvent = *(nsInputEvent *)inKeyEvent; outCMEvent->eventStructType = NS_MOUSE_EVENT; - outCMEvent->message = NS_CONTEXTMENU_KEY; + outCMEvent->message = NS_CONTEXTMENU; + outCMEvent->button = nsMouseEvent::eRightButton; + outCMEvent->context = nsMouseEvent::eContextMenuKey; outCMEvent->isShift = outCMEvent->isControl = PR_FALSE; outCMEvent->isAlt = outCMEvent->isMeta = PR_FALSE; outCMEvent->clickCount = 0; @@ -1583,15 +1585,11 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) } break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); break; @@ -1858,6 +1856,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) { nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); PRUint32 eventType = 0; + PRInt16 button = nsMouseEvent::eLeftButton; // If you double click in GDK, it will actually generate a single // click event before sending the double click event, and this is @@ -1884,18 +1883,19 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) // Triple click. case GDK_3BUTTON_PRESS: + eventType = NS_MOUSE_BUTTON_DOWN; switch (aGdkButtonEvent->button) // Which button? { case 1: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + button = nsMouseEvent::eLeftButton; break; case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + button = nsMouseEvent::eMiddleButton; break; case 3: - eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + button = nsMouseEvent::eRightButton; break; case 4: @@ -1928,7 +1928,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) // Single-click default. default: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + button = nsMouseEvent::eLeftButton; break; } break; @@ -1939,6 +1939,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); InitMouseEvent(aGdkButtonEvent, event); + event.button = button; // Set the button motion target and remeber the widget and root coords sButtonMotionTarget = this; @@ -1962,7 +1963,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) // if we're a right-button-down on linux, we're trying to // popup a context menu. send that event to gecko also. - if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { + if (button == nsMouseEvent::eRightButton) { nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, nsMouseEvent::eReal); InitMouseEvent(aGdkButtonEvent, contextMenuEvent); @@ -1976,20 +1977,19 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) /* virtual */ void nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) { - PRUint32 eventType = 0; - + PRUint16 button; switch (aGdkButtonEvent->button) { case 1: - eventType = NS_MOUSE_LEFT_BUTTON_UP; + button = nsMouseEvent::eLeftButton; break; case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_UP; + button = nsMouseEvent::eMiddleButton; break; case 3: - eventType = NS_MOUSE_RIGHT_BUTTON_UP; + button = nsMouseEvent::eRightButton; break; case 4: @@ -2001,11 +2001,12 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) return; default: - eventType = NS_MOUSE_LEFT_BUTTON_UP; + button = nsMouseEvent::eLeftButton; break; } - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal); + event.button = button; InitMouseEvent(aGdkButtonEvent, event); if (sButtonMotionTarget) { diff --git a/mozilla/widget/src/gtk2/nsWindow.cpp b/mozilla/widget/src/gtk2/nsWindow.cpp index 117e8dc5ed7..fd0d8dbdb98 100644 --- a/mozilla/widget/src/gtk2/nsWindow.cpp +++ b/mozilla/widget/src/gtk2/nsWindow.cpp @@ -1858,7 +1858,6 @@ nsWindow::OnMotionNotifyEvent(GtkWidget *aWidget, GdkEventMotion *aEvent) void nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent) { - PRUint32 eventType; nsEventStatus status; // If you double click in GDK, it will actually generate a single @@ -1891,27 +1890,29 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent) PR_FALSE)) return; + PRUint16 domButton; switch (aEvent->button) { case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + domButton = nsMouseEvent::eMiddleButton; break; case 3: - eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + domButton = nsMouseEvent::eRightButton; break; default: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + domButton = nsMouseEvent::eLeftButton; break; } nsCOMPtr kungFuDeathGrip = this; - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal); + event.button = domButton; InitButtonEvent(event, aEvent); DispatchEvent(&event, status); // right menu click on linux should also pop up a context menu - if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { + if (domButton == nsMouseEvent::eRightButton) { nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, nsMouseEvent::eReal); InitButtonEvent(contextMenuEvent, aEvent); @@ -1922,16 +1923,15 @@ nsWindow::OnButtonPressEvent(GtkWidget *aWidget, GdkEventButton *aEvent) void nsWindow::OnButtonReleaseEvent(GtkWidget *aWidget, GdkEventButton *aEvent) { - PRUint32 eventType; - + PRUint16 domButton; mLastButtonReleaseTime = aEvent->time; switch (aEvent->button) { case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_UP; + domButton = nsMouseEvent::eMiddleButton; break; case 3: - eventType = NS_MOUSE_RIGHT_BUTTON_UP; + domButton = nsMouseEvent::eRightButton; break; // don't send events for these types case 4: @@ -1940,11 +1940,12 @@ nsWindow::OnButtonReleaseEvent(GtkWidget *aWidget, GdkEventButton *aEvent) break; // default including button 1 is left button up default: - eventType = NS_MOUSE_LEFT_BUTTON_UP; + domButton = nsMouseEvent::eLeftButton; break; } - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal); + event.button = domButton; InitButtonEvent(event, aEvent); nsEventStatus status; @@ -4707,7 +4708,9 @@ key_event_to_context_menu_event(const nsKeyEvent* aKeyEvent, { memcpy(aCMEvent, aKeyEvent, sizeof(nsInputEvent)); aCMEvent->eventStructType = NS_MOUSE_EVENT; - aCMEvent->message = NS_CONTEXTMENU_KEY; + aCMEvent->message = NS_CONTEXTMENU; + aCMEvent->context = nsMouseEvent::eContextMenuKey; + aCMEvent->button = nsMouseEvent::eRightButton; aCMEvent->isShift = aCMEvent->isControl = PR_FALSE; aCMEvent->isAlt = aCMEvent->isMeta = PR_FALSE; aCMEvent->clickCount = 0; diff --git a/mozilla/widget/src/mac/nsMacControl.cpp b/mozilla/widget/src/mac/nsMacControl.cpp index 4c451a38262..401d2673805 100644 --- a/mozilla/widget/src/mac/nsMacControl.cpp +++ b/mozilla/widget/src/mac/nsMacControl.cpp @@ -228,9 +228,9 @@ PRBool nsMacControl::DispatchMouseEvent(nsMouseEvent &aEvent) PRBool eatEvent = PR_FALSE; switch (aEvent.message) { - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_LEFT_BUTTON_DOWN: - if (mEnabled) + case NS_MOUSE_DOUBLECLICK: + case NS_MOUSE_BUTTON_DOWN: + if (aEvent.button == nsMouseEvent::eLeftButton && mEnabled) { mMouseInButton = PR_TRUE; mWidgetArmed = PR_TRUE; @@ -238,17 +238,20 @@ PRBool nsMacControl::DispatchMouseEvent(nsMouseEvent &aEvent) } break; - case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: + if (aEvent.button == nsMouseEvent::eLeftButton) + { // if the widget was not armed, eat the event if (!mWidgetArmed) eatEvent = PR_TRUE; // if the mouseUp happened on another widget, eat the event too // (the widget which got the mouseDown is always notified of the mouseUp) - if (! mMouseInButton) + if (!mMouseInButton) eatEvent = PR_TRUE; mWidgetArmed = PR_FALSE; if (mMouseInButton) Invalidate(PR_TRUE); + } break; case NS_MOUSE_EXIT: diff --git a/mozilla/widget/src/mac/nsMacEventHandler.cpp b/mozilla/widget/src/mac/nsMacEventHandler.cpp index cf3e2a1735a..2655203ce1b 100644 --- a/mozilla/widget/src/mac/nsMacEventHandler.cpp +++ b/mozilla/widget/src/mac/nsMacEventHandler.cpp @@ -1049,7 +1049,9 @@ ConvertKeyEventToContextMenuEvent(const nsKeyEvent* inKeyEvent, nsMouseEvent* ou *(nsInputEvent*)outCMEvent = *(nsInputEvent*)inKeyEvent; outCMEvent->eventStructType = NS_MOUSE_EVENT; - outCMEvent->message = NS_CONTEXTMENU_KEY; + outCMEvent->message = NS_CONTEXTMENU; + outCMEvent->context = nsMouseEvent::eContextMenuKey; + outCMEvent->button = nsMouseEvent::eRightButton; outCMEvent->isShift = outCMEvent->isControl = outCMEvent->isAlt = outCMEvent->isMeta = PR_FALSE; outCMEvent->clickCount = 0; @@ -1500,19 +1502,20 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent) if ( ignoreClickInContent ) break; - nsMouseEvent mouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - PRUint32 mouseButton = NS_MOUSE_LEFT_BUTTON_DOWN; + nsMouseEvent mouseEvent(PR_TRUE, NS_MOUSE_BUTTON_DOWN, nsnull, + nsMouseEvent::eReal); + mouseEvent.button = nsMouseEvent::eLeftButton; if ( aOSEvent.modifiers & controlKey ) - mouseButton = NS_MOUSE_RIGHT_BUTTON_DOWN; + mouseEvent.button = nsMouseEvent::eRightButton; // We've hacked our events to include the button. // Normally message is undefined in mouse click/drag events. if ( aOSEvent.message == kEventMouseButtonSecondary ) - mouseButton = NS_MOUSE_RIGHT_BUTTON_DOWN; + mouseEvent.button = nsMouseEvent::eRightButton; if ( aOSEvent.message == kEventMouseButtonTertiary ) - mouseButton = NS_MOUSE_MIDDLE_BUTTON_DOWN; + mouseEvent.button = nsMouseEvent::eMiddleButton; - ConvertOSEventToMouseEvent(aOSEvent, mouseEvent, mouseButton); + ConvertOSEventToMouseEvent(aOSEvent, mouseEvent); nsCOMPtr kungFuDeathGrip ( mouseEvent.widget ); // ensure widget doesn't go away nsWindow* widgetHit = NS_STATIC_CAST(nsWindow*, mouseEvent.widget); // while we're processing event @@ -1531,7 +1534,7 @@ PRBool nsMacEventHandler::HandleMouseDownEvent(EventRecord& aOSEvent) // if we're a control-click, send in an additional NS_CONTEXTMENU event // after the mouse down. - if ( mouseButton == NS_MOUSE_RIGHT_BUTTON_DOWN ) { + if (mouseEvent.button == nsMouseEvent::eRightButton) { nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); ConvertOSEventToMouseEvent(aOSEvent, contextMenuEvent, NS_CONTEXTMENU); @@ -1581,15 +1584,16 @@ PRBool nsMacEventHandler::HandleMouseUpEvent( { PRBool retVal = PR_FALSE; - nsMouseEvent mouseEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - PRUint32 mouseButton = NS_MOUSE_LEFT_BUTTON_UP; + nsMouseEvent mouseEvent(PR_TRUE, NS_MOUSE_BUTTON_UP, nsnull, + nsMouseEvent::eReal); + mouseEvent.button = nsMouseEvent::eLeftButton; // We've hacked our events to include the button. // Normally message is undefined in mouse click/drag events. if ( aOSEvent.message == kEventMouseButtonSecondary ) - mouseButton = NS_MOUSE_RIGHT_BUTTON_UP; + mouseEvent.button = nsMouseEvent::eRightButton; if ( aOSEvent.message == kEventMouseButtonTertiary ) - mouseButton = NS_MOUSE_MIDDLE_BUTTON_UP; + mouseEvent.button = nsMouseEvent::eMiddleButton; ConvertOSEventToMouseEvent(aOSEvent, mouseEvent, mouseButton); @@ -1724,21 +1728,16 @@ PRBool nsMacEventHandler::HandleMouseMoveEvent( EventRecord& aOSEvent ) //------------------------------------------------------------------------- void nsMacEventHandler::ConvertOSEventToMouseEvent( EventRecord& aOSEvent, - nsMouseEvent& aMouseEvent, - PRUint32 aMessage) + nsMouseEvent& aMouseEvent) { // we're going to time double-clicks from mouse *up* to next mouse *down* - if (aMessage == NS_MOUSE_LEFT_BUTTON_UP || - aMessage == NS_MOUSE_RIGHT_BUTTON_UP || - aMessage == NS_MOUSE_MIDDLE_BUTTON_UP) + if (aMouseEvent.message == NS_MOUSE_BUTTON_UP) { // remember when this happened for the next mouse down mLastMouseUpWhen = aOSEvent.when; mLastMouseUpWhere = aOSEvent.where; } - else if (aMessage == NS_MOUSE_LEFT_BUTTON_DOWN || - aMessage == NS_MOUSE_RIGHT_BUTTON_DOWN || - aMessage == NS_MOUSE_MIDDLE_BUTTON_DOWN) + else if (aMouseEvent.message == NS_MOUSE_BUTTON_DOWN) { // now look to see if we want to convert this to a double- or triple-click const short kDoubleClickMoveThreshold = 5; @@ -1750,7 +1749,7 @@ void nsMacEventHandler::ConvertOSEventToMouseEvent( mClickCount ++; // if (mClickCount == 2) -// aMessage = NS_MOUSE_LEFT_DOUBLECLICK; +// aMessage = NS_MOUSE_DOUBLECLICK; } else { @@ -1779,7 +1778,8 @@ void nsMacEventHandler::ConvertOSEventToMouseEvent( WindowRef lastWind = reinterpret_cast(lastWidgetHit->GetNativeData(NS_NATIVE_DISPLAY)); PRBool eventInSameWindowAsLastEvent = (windowThatHasEvent == lastWind); if ( eventInSameWindowAsLastEvent || !topLevelIsAPopup ) { - if (::StillDown() || aMessage == NS_MOUSE_LEFT_BUTTON_UP) + if (::StillDown() || (aMouseEvent.message == NS_MOUSE_BUTTON_UP && + aMouseEvent.button == nsMouseEvent::eLeftButton)) { widgetHit = lastWidgetHit; eventTargetWindow = lastWind; // make sure we use the correct window to fix the coords @@ -1838,6 +1838,8 @@ void nsMacEventHandler::ConvertOSEventToMouseEvent( // nsMouseEvent aMouseEvent.acceptActivation = PR_TRUE; + if (aMessage == NS_CONTEXTMENU) + aMouseEvent.button = nsMouseEvent::eRightButton; } //------------------------------------------------------------------------- diff --git a/mozilla/widget/src/mac/nsNativeScrollbar.cpp b/mozilla/widget/src/mac/nsNativeScrollbar.cpp index 7ce772b4b5c..876da1ecb6b 100644 --- a/mozilla/widget/src/mac/nsNativeScrollbar.cpp +++ b/mozilla/widget/src/mac/nsNativeScrollbar.cpp @@ -328,49 +328,53 @@ nsNativeScrollbar::DispatchMouseEvent(nsMouseEvent &aEvent) PRBool eatEvent = PR_FALSE; switch (aEvent.message) { - case NS_MOUSE_LEFT_DOUBLECLICK: - case NS_MOUSE_LEFT_BUTTON_DOWN: - mMouseDownInScroll = PR_TRUE; - NS_ASSERTION(this != 0, "NULL nsNativeScrollbar2"); - ::SetControlReference(mControl, (UInt32) this); - StartDraw(); - { - Point thePoint; - thePoint.h = aEvent.refPoint.x; - thePoint.v = aEvent.refPoint.y; - mClickedPartCode = ::TestControl(mControl, thePoint); - if (mClickedPartCode > 0) - ::HiliteControl(mControl, mClickedPartCode); - - switch (mClickedPartCode) + case NS_MOUSE_DOUBLECLICK: + case NS_MOUSE_BUTTON_DOWN: + if (aEvent.button == nsMouseEvent::eLeftButton) { + mMouseDownInScroll = PR_TRUE; + NS_ASSERTION(this != 0, "NULL nsNativeScrollbar2"); + ::SetControlReference(mControl, (UInt32) this); + StartDraw(); { - case kControlUpButtonPart: - case kControlDownButtonPart: - case kControlPageUpPart: - case kControlPageDownPart: - case kControlIndicatorPart: - // We are assuming Appearance 1.1 or later, so we - // have the "live scroll" variant of the scrollbar, - // which lets you pass the action proc to TrackControl - // for the thumb (this was illegal in previous - // versions of the defproc). - ::TrackControl(mControl, thePoint, ScrollbarActionProc()); - ::HiliteControl(mControl, 0); - // We don't dispatch the mouseDown event because mouseUp is eaten - // by TrackControl anyway and the only messages the app really - // cares about are the NS_SCROLLBAR_xxx messages. - eatEvent = PR_TRUE; - break; + Point thePoint; + thePoint.h = aEvent.refPoint.x; + thePoint.v = aEvent.refPoint.y; + mClickedPartCode = ::TestControl(mControl, thePoint); + if (mClickedPartCode > 0) + ::HiliteControl(mControl, mClickedPartCode); + + switch (mClickedPartCode) + { + case kControlUpButtonPart: + case kControlDownButtonPart: + case kControlPageUpPart: + case kControlPageDownPart: + case kControlIndicatorPart: + // We are assuming Appearance 1.1 or later, so we + // have the "live scroll" variant of the scrollbar, + // which lets you pass the action proc to TrackControl + // for the thumb (this was illegal in previous + // versions of the defproc). + ::TrackControl(mControl, thePoint, ScrollbarActionProc()); + ::HiliteControl(mControl, 0); + // We don't dispatch the mouseDown event because mouseUp is eaten + // by TrackControl anyway and the only messages the app really + // cares about are the NS_SCROLLBAR_xxx messages. + eatEvent = PR_TRUE; + break; + } + SetPosition(mValue); } - SetPosition(mValue); + EndDraw(); } - EndDraw(); break; - case NS_MOUSE_LEFT_BUTTON_UP: - mMouseDownInScroll = PR_FALSE; - mClickedPartCode = 0; + case NS_MOUSE_BUTTON_UP: + if (aEvent.button == nsMouseEvent::eLeftButton) { + mMouseDownInScroll = PR_FALSE; + mClickedPartCode = 0; + } break; case NS_MOUSE_EXIT: diff --git a/mozilla/widget/src/mac/nsWindow.cpp b/mozilla/widget/src/mac/nsWindow.cpp index 1779c8f1c44..c5866d6bfcf 100644 --- a/mozilla/widget/src/mac/nsWindow.cpp +++ b/mozilla/widget/src/mac/nsWindow.cpp @@ -1805,15 +1805,11 @@ PRBool nsWindow::DispatchMouseEvent(nsMouseEvent &aEvent) } break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); break; diff --git a/mozilla/widget/src/os2/nsWindow.cpp b/mozilla/widget/src/os2/nsWindow.cpp index a312223a730..f07eb0d593f 100644 --- a/mozilla/widget/src/os2/nsWindow.cpp +++ b/mozilla/widget/src/os2/nsWindow.cpp @@ -2761,7 +2761,7 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) case WM_BUTTON1DOWN: if (!mIsScrollBar) WinSetCapture( HWND_DESKTOP, mWnd); - result = DispatchMouseEvent( NS_MOUSE_LEFT_BUTTON_DOWN, mp1, mp2); + result = DispatchMouseEvent( NS_MOUSE_BUTTON_DOWN, mp1, mp2); // there's no need to clear this on button-up gLastButton1Down.x = XFROMMP(mp1); gLastButton1Down.y = YFROMMP(mp1); @@ -2771,24 +2771,27 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) case WM_BUTTON1UP: if (!mIsScrollBar) WinSetCapture( HWND_DESKTOP, 0); // release - result = DispatchMouseEvent( NS_MOUSE_LEFT_BUTTON_UP, mp1, mp2); + result = DispatchMouseEvent( NS_MOUSE_BUTTON_UP, mp1, mp2); break; case WM_BUTTON1DBLCLK: - result = DispatchMouseEvent( NS_MOUSE_LEFT_DOUBLECLICK, mp1, mp2); + result = DispatchMouseEvent( NS_MOUSE_DOUBLECLICK, mp1, mp2); break; case WM_BUTTON2DOWN: if (!mIsScrollBar) WinSetCapture( HWND_DESKTOP, mWnd); - result = DispatchMouseEvent( NS_MOUSE_RIGHT_BUTTON_DOWN, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, mp1, mp2, PR_FALSE, + nsMouseEvent::eRightButton); break; case WM_BUTTON2UP: if (!mIsScrollBar) WinSetCapture( HWND_DESKTOP, 0); // release - result = DispatchMouseEvent( NS_MOUSE_RIGHT_BUTTON_UP, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, mp1, mp2, PR_FALSE, + nsMouseEvent::eRightButton); break; case WM_BUTTON2DBLCLK: - result = DispatchMouseEvent( NS_MOUSE_RIGHT_DOUBLECLICK, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, mp1, mp2, + PR_FALSE, nsMouseEvent::eRightButton); break; case WM_CONTEXTMENU: if (SHORT2FROMMP(mp2) == TRUE) { @@ -2796,10 +2799,12 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) if (hwndCurrFocus != mWnd) { WinSendMsg(hwndCurrFocus, msg, mp1, mp2); } else { - result = DispatchMouseEvent( NS_CONTEXTMENU_KEY, mp1, mp2); + result = DispatchMouseEvent(NS_CONTEXTMENU, mp1, mp2, PR_TRUE, + nsMouseEvent::eRightButton); } } else { - result = DispatchMouseEvent( NS_CONTEXTMENU, mp1, mp2); + result = DispatchMouseEvent(NS_CONTEXTMENU, mp1, mp2, PR_FALSE, + nsMouseEvent::eRightButton); } break; @@ -2838,13 +2843,16 @@ PRBool nsWindow::ProcessMessage( ULONG msg, MPARAM mp1, MPARAM mp2, MRESULT &rc) break; case WM_BUTTON3DOWN: - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_BUTTON_DOWN, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, mp1, mp2, PR_FALSE, + nsMouseEvent::eMiddleButton); break; case WM_BUTTON3UP: - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_BUTTON_UP, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, mp1, mp2, PR_FALSE, + nsMouseEvent::eMiddleButton); break; case WM_BUTTON3DBLCLK: - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_DOUBLECLICK, mp1, mp2); + result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, mp1, mp2, PR_FALSE, + nsMouseEvent::eMiddleButton); break; case WM_MOUSEMOVE: @@ -3295,7 +3303,8 @@ PRBool nsWindow::DispatchResizeEvent( PRInt32 aX, PRInt32 aY) // Deal with all sort of mouse event // //------------------------------------------------------------------------- -PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2) +PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, MPARAM mp1, MPARAM mp2, + PRBool aIsContextMenuKey, PRInt16 aButton) { PRBool result = PR_FALSE; @@ -3303,13 +3312,17 @@ PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2 return result; } - nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal, + aIsContextMenuKey + ? nsMouseEvent::eContextMenuKey + : nsMouseEvent::eNormal); + event.button = aButton; // Mouse leave & enter messages don't seem to have position built in. if( aEventType && aEventType != NS_MOUSE_ENTER && aEventType != NS_MOUSE_EXIT) { POINTL ptl; - if (aEventType == NS_CONTEXTMENU_KEY) { + if (aEventType == NS_CONTEXTMENU && aIsContextMenuKey) { WinQueryPointerPos(HWND_DESKTOP, &ptl); WinMapWindowPoints( HWND_DESKTOP, mWnd, &ptl, 1 ); } else { @@ -3336,10 +3349,12 @@ PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2 event.isMeta = PR_FALSE; //Dblclicks are used to set the click count, then changed to mousedowns - if (aEventType == NS_MOUSE_LEFT_DOUBLECLICK || - aEventType == NS_MOUSE_RIGHT_DOUBLECLICK) { - event.message = (aEventType == NS_MOUSE_LEFT_DOUBLECLICK) ? - NS_MOUSE_LEFT_BUTTON_DOWN : NS_MOUSE_RIGHT_BUTTON_DOWN; + if (aEventType == NS_MOUSE_DOUBLECLICK && + (aButton == nsMouseEvent::eLeftButton || + aButton == nsMouseEvent::eRightButton)) { + event.message = NS_MOUSE_BUTTON_DOWN; + event.button = (aButton == nsMouseEvent::eLeftButton) ? + nsMouseEvent::eLeftButton : nsMouseEvent::eRightButton; event.clickCount = 2; } else { @@ -3350,32 +3365,50 @@ PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2 switch (aEventType)//~~~ { - case NS_MOUSE_LEFT_BUTTON_DOWN: - pluginEvent.event = WM_BUTTON1DOWN; + case NS_MOUSE_BUTTON_DOWN: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_BUTTON1DOWN; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_BUTTON3DOWN; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_BUTTON2DOWN; + break; + default: + break; + } break; - case NS_MOUSE_LEFT_BUTTON_UP: - pluginEvent.event = WM_BUTTON1UP; + case NS_MOUSE_BUTTON_UP: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_BUTTON1UP; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_BUTTON3UP; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_BUTTON2UP; + break; + default: + break; + } break; - case NS_MOUSE_LEFT_DOUBLECLICK: - pluginEvent.event = WM_BUTTON1DBLCLK; - break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: - pluginEvent.event = WM_BUTTON2DOWN; - break; - case NS_MOUSE_RIGHT_BUTTON_UP: - pluginEvent.event = WM_BUTTON2UP; - break; - case NS_MOUSE_RIGHT_DOUBLECLICK: - pluginEvent.event = WM_BUTTON2DBLCLK; - break; - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - pluginEvent.event = WM_BUTTON3DOWN; - break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - pluginEvent.event = WM_BUTTON3UP; - break; - case NS_MOUSE_MIDDLE_DOUBLECLICK: - pluginEvent.event = WM_BUTTON3DBLCLK; + case NS_MOUSE_DOUBLECLICK: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_BUTTON1DBLCLK; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_BUTTON3DBLCLK; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_BUTTON2DBLCLK; + break; + default: + break; + } break; case NS_MOUSE_MOVE: pluginEvent.event = WM_MOUSEMOVE; @@ -3497,22 +3530,16 @@ PRBool nsWindow::DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2 } break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(event)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(event)); // result = ConvertStatus(mMouseListener->MouseClicked(event)); break; - case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_MIDDLE_CLICK: - case NS_MOUSE_RIGHT_CLICK: + case NS_MOUSE_CLICK: result = ConvertStatus(mMouseListener->MouseClicked(event)); break; } // switch diff --git a/mozilla/widget/src/os2/nsWindow.h b/mozilla/widget/src/os2/nsWindow.h index 83fc21e4741..a5b1bd7e707 100644 --- a/mozilla/widget/src/os2/nsWindow.h +++ b/mozilla/widget/src/os2/nsWindow.h @@ -322,7 +322,9 @@ protected: PRBool DispatchStandardEvent( PRUint32 aMsg); PRBool DispatchAppCommandEvent(PRUint32 aEventCommand); PRBool DispatchDragDropEvent( PRUint32 aMsg); - virtual PRBool DispatchMouseEvent( PRUint32 aEventType, MPARAM mp1, MPARAM mp2); + virtual PRBool DispatchMouseEvent(PRUint32 aEventType, MPARAM mp1, MPARAM mp2, + PRBool aIsContextMenuKey = PR_FALSE, + PRInt16 aButton = nsMouseEvent::eLeftButton); virtual PRBool DispatchResizeEvent( PRInt32 aClientX, PRInt32 aClientY); void GetNonClientBounds(nsRect &aRect); void DeferPosition( HWND, HWND, long, long, long, long, ULONG); diff --git a/mozilla/widget/src/photon/nsWidget.cpp b/mozilla/widget/src/photon/nsWidget.cpp index bd7e9e494f3..000582f91a5 100644 --- a/mozilla/widget/src/photon/nsWidget.cpp +++ b/mozilla/widget/src/photon/nsWidget.cpp @@ -720,7 +720,8 @@ NS_IMETHODIMP nsWidget::DispatchEvent( nsGUIEvent *aEvent, nsEventStatus &aStatu void nsWidget::InitMouseEvent(PhPointerEvent_t *aPhButtonEvent, nsWidget * aWidget, nsMouseEvent &anEvent, - PRUint32 aEventType) + PRUint32 aEventType, + PRInt16 aButton) { anEvent.message = aEventType; anEvent.widget = aWidget; @@ -734,6 +735,7 @@ void nsWidget::InitMouseEvent(PhPointerEvent_t *aPhButtonEvent, anEvent.refPoint.x = aPhButtonEvent->pos.x; anEvent.refPoint.y = aPhButtonEvent->pos.y; anEvent.clickCount = aPhButtonEvent->click_count; + anEvent.button = aButton; } } @@ -756,15 +758,11 @@ PRBool nsWidget::DispatchMouseEvent( nsMouseEvent& aEvent ) { if (nsnull != mMouseListener) { switch (aEvent.message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); break; @@ -1025,11 +1023,14 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn ScreenToWidgetPos( ptrev->pos ); if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_LEFT_BUTTON_DOWN ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_BUTTON_DOWN, + nsMouseEvent::eLeftButton); else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_RIGHT_BUTTON_DOWN ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_BUTTON_DOWN, + nsMouseEvent::eRightButton); else // middle button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_MIDDLE_BUTTON_DOWN ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_BUTTON_DOWN, + nsMouseEvent::eMiddleButton); result = DispatchMouseEvent(theMouseEvent); @@ -1037,7 +1038,8 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn if( ptrev->buttons & Ph_BUTTON_MENU ) { nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - InitMouseEvent( ptrev, this, contextMenuEvent, NS_CONTEXTMENU ); + InitMouseEvent(ptrev, this, contextMenuEvent, NS_CONTEXTMENU, + nsMouseEvent::eRightButton); result = DispatchMouseEvent( contextMenuEvent ); } } @@ -1063,11 +1065,14 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn if (ptrev) { ScreenToWidgetPos( ptrev->pos ); if ( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_LEFT_BUTTON_UP ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_BUTTON_UP, + nsMouseEvent::eLeftButton); else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_RIGHT_BUTTON_UP ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_BUTTON_UP, + nsMouseEvent::eRightButton); else // middle button - InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE_MIDDLE_BUTTON_UP ); + InitMouseEvent(ptrev, this, theMouseEvent, NS_MOUSE__BUTTON_UP, + nsMouseEvent::eMiddleButton); result = DispatchMouseEvent(theMouseEvent); } @@ -1125,7 +1130,8 @@ inline PRBool nsWidget::HandleEvent( PtWidget_t *widget, PtCallbackInfo_t* aCbIn nsMouseEvent::eReal); PhPointerEvent_t* ptrev2 = (PhPointerEvent_t*) PhGetData( event ); ScreenToWidgetPos( ptrev2->pos ); - InitMouseEvent(ptrev2, this, theMouseEvent, NS_MOUSE_LEFT_BUTTON_UP ); + InitMouseEvent(ptrev2, this, theMouseEvent, NS_MOUSE_BUTTON_UP, + nsMouseEvent::eLeftButton); result = DispatchMouseEvent(theMouseEvent); } break; diff --git a/mozilla/widget/src/photon/nsWidget.h b/mozilla/widget/src/photon/nsWidget.h index 3641abd2519..94a83462d7e 100644 --- a/mozilla/widget/src/photon/nsWidget.h +++ b/mozilla/widget/src/photon/nsWidget.h @@ -313,7 +313,8 @@ protected: void InitMouseEvent( PhPointerEvent_t * aPhButtonEvent, nsWidget * aWidget, nsMouseEvent & anEvent, - PRUint32 aEventType ); + PRUint32 aEventType, + PRInt16 aButton); /* Convert Photon key codes to Mozilla key codes */ diff --git a/mozilla/widget/src/qt/nsCommonWidget.cpp b/mozilla/widget/src/qt/nsCommonWidget.cpp index 52825f3e1cf..5e327448f17 100644 --- a/mozilla/widget/src/qt/nsCommonWidget.cpp +++ b/mozilla/widget/src/qt/nsCommonWidget.cpp @@ -241,7 +241,9 @@ keyEventToContextMenuEvent(const nsKeyEvent* aKeyEvent, nsMouseEvent* aCMEvent) { memcpy(aCMEvent, aKeyEvent, sizeof(nsInputEvent)); - aCMEvent->message = NS_CONTEXTMENU_KEY; + aCMEvent->message = NS_CONTEXTMENU; + aCMEvent->button = nsMouseEvent::eRightButton; + aCMEvent->context = nsMouseEvent::eContextMenuKey; aCMEvent->isShift = aCMEvent->isControl = PR_FALSE; aCMEvent->isAlt = aCMEvent->isMeta = PR_FALSE; aCMEvent->clickCount = 0; @@ -870,21 +872,22 @@ nsCommonWidget::mousePressEvent(QMouseEvent *e) { //qDebug("mousePressEvent mWidget=%p", (void*)mWidget); // backTrace(); - PRUint32 eventType; + PRInt16 button; switch (e->button()) { case Qt::MidButton: - eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + button = nsMouseEvent::eMiddleButton; break; case Qt::RightButton: - eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + button = nsMouseEvent::eRightButton; break; default: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + button = nsMouseEvent::eLeftButton; break; } - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal); + event.button = button; InitMouseEvent(&event, e, 1); @@ -892,10 +895,11 @@ nsCommonWidget::mousePressEvent(QMouseEvent *e) DispatchEvent(&event, status); // right menu click on linux should also pop up a context menu - if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { + if (button == nsMouseEvent::eRightButton) { nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, nsMouseEvent::eReal); InitMouseEvent(&contextMenuEvent, e, 1); + contextMenuEvent.button = button; DispatchEvent(&contextMenuEvent, status); } @@ -906,21 +910,22 @@ bool nsCommonWidget::mouseReleaseEvent(QMouseEvent *e) { //qDebug("mouseReleaseEvent mWidget=%p", (void*)mWidget); - PRUint32 eventType; + PRInt16 button; switch (e->button()) { case Qt::MidButton: - eventType = NS_MOUSE_MIDDLE_BUTTON_UP; + button = nsMouseEvent::eMiddleButton; break; case Qt::RightButton: - eventType = NS_MOUSE_RIGHT_BUTTON_UP; + button = nsMouseEvent::eRightButton; break; default: - eventType = NS_MOUSE_LEFT_BUTTON_UP; + button = nsMouseEvent::eLeftButton; break; } - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal); + event.button = button; InitMouseEvent(&event, e, 1); @@ -933,23 +938,24 @@ nsCommonWidget::mouseReleaseEvent(QMouseEvent *e) bool nsCommonWidget::mouseDoubleClickEvent(QMouseEvent *e) { - PRUint32 eventType; + PRInt16 button; switch (e->button()) { case Qt::MidButton: - eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + button = nsMouseEvent::eMiddleButton; break; case Qt::RightButton: - eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + button = nsMouseEvent::eRightButton; break; default: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + button = nsMouseEvent::eLeftButton; break; } - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); + nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_DOWN, this, nsMouseEvent::eReal); InitMouseEvent(&event, e, 2); + event.button = button; //pressed nsEventStatus status; DispatchEvent(&event, status); diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 3c682da473d..5aaaa8f0ece 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -4615,24 +4615,28 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT shrg.dwFlags = SHRG_RETURNCMD; if (SHRecognizeGesture(&shrg) == GN_CONTEXTMENU) { - result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN, wParam, lParam); - result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_UP, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, + PR_FALSE, nsMouseEvent::eRightButton); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, lParam, + PR_FALSE, nsMouseEvent::eRightButton); break; } } #endif // check whether IME window do mouse operation - if (IMEMouseHandling(NS_MOUSE_LEFT_BUTTON_DOWN, IMEMOUSE_LDOWN, lParam)) + if (IMEMouseHandling(IMEMOUSE_LDOWN, lParam)) break; - result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_DOWN, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, + PR_FALSE, nsMouseEvent::eLeftButton); DispatchPendingEvents(); } break; case WM_LBUTTONUP: //RelayMouseEvent(msg,wParam, lParam); - result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_UP, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, lParam, + PR_FALSE, nsMouseEvent::eLeftButton); DispatchPendingEvents(); break; @@ -4654,60 +4658,68 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT // will be maxlong. Send a different event msg instead. PRUint32 msg; LPARAM pos; + PRBool contextMenukey = PR_FALSE; + msg = NS_CONTEXTMENU; if (lParam == 0xFFFFFFFF) { - msg = NS_CONTEXTMENU_KEY; + contextMenukey = PR_TRUE; pos = lParamToClient(GetMessagePos()); } else { - msg = NS_CONTEXTMENU; pos = lParamToClient(lParam); } - result = DispatchMouseEvent(msg, wParam, pos); + result = DispatchMouseEvent(msg, wParam, pos, contextMenukey); } break; case WM_LBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_LEFT_DOUBLECLICK, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, wParam, lParam, PR_FALSE, + nsMouseEvent::eLeftButton); break; case WM_MBUTTONDOWN: { // check whether IME window do mouse operation - if (IMEMouseHandling(NS_MOUSE_MIDDLE_BUTTON_DOWN, IMEMOUSE_MDOWN, lParam)) + if (IMEMouseHandling(IMEMOUSE_MDOWN, lParam)) break; - result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, PR_FALSE, + nsMouseEvent::eMiddleButton); DispatchPendingEvents(); } break; case WM_MBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_UP, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, lParam, PR_FALSE, + nsMouseEvent::eMiddleButton); DispatchPendingEvents(); break; case WM_MBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, PR_FALSE, + nsMouseEvent::eMiddleButton); break; case WM_RBUTTONDOWN: { // check whether IME window do mouse operation - if (IMEMouseHandling(NS_MOUSE_RIGHT_BUTTON_DOWN, IMEMOUSE_RDOWN, lParam)) + if (IMEMouseHandling(IMEMOUSE_RDOWN, lParam)) break; - result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, PR_FALSE, + nsMouseEvent::eRightButton); DispatchPendingEvents(); } break; case WM_RBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_UP, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, lParam, PR_FALSE, + nsMouseEvent::eRightButton); DispatchPendingEvents(); break; case WM_RBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_RIGHT_DOUBLECLICK, wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, wParam, lParam, PR_FALSE, + nsMouseEvent::eRightButton); break; case WM_APPCOMMAND: @@ -5983,7 +5995,9 @@ PRBool nsWindow::OnResize(nsRect &aWindowRect) // Deal with all sort of mouse event // //------------------------------------------------------------------------- -PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam) +PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, + LPARAM lParam, PRBool aIsContextMenuKey, + PRInt16 aButton) { PRBool result = PR_FALSE; @@ -5995,8 +6009,11 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l eventPoint.x = GET_X_LPARAM(lParam); eventPoint.y = GET_Y_LPARAM(lParam); - nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal); - if (aEventType == NS_CONTEXTMENU_KEY) { + nsMouseEvent event(PR_TRUE, aEventType, this, nsMouseEvent::eReal, + aIsContextMenuKey + ? nsMouseEvent::eContextMenuKey + : nsMouseEvent::eNormal); + if (aEventType == NS_CONTEXTMENU && aIsContextMenuKey) { nsPoint zero(0, 0); InitEvent(event, &zero); } else { @@ -6007,6 +6024,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l event.isControl = IS_VK_DOWN(NS_VK_CONTROL); event.isMeta = PR_FALSE; event.isAlt = IS_VK_DOWN(NS_VK_ALT); + event.button = aButton; nsRect mpWidget; nsRect mpScreen; @@ -6030,20 +6048,14 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l (abs(gLastMousePoint.y - eventPoint.y) < (short)::GetSystemMetrics(SM_CYDOUBLECLK)); BYTE eventButton; - switch (aEventType) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_LEFT_DOUBLECLICK: + switch (aButton) { + case nsMouseEvent::eLeftButton: eventButton = VK_LBUTTON; break; - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_MIDDLE_DOUBLECLICK: + case nsMouseEvent::eMiddleButton: eventButton = VK_MBUTTON; break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_UP: - case NS_MOUSE_RIGHT_DOUBLECLICK: + case nsMouseEvent::eRightButton: eventButton = VK_RBUTTON; break; default: @@ -6055,27 +6067,18 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l // We're going to time double-clicks from mouse *up* to next mouse *down* LONG curMsgTime = ::GetMessageTime(); - if (aEventType == NS_MOUSE_LEFT_DOUBLECLICK) { - event.message = NS_MOUSE_LEFT_BUTTON_DOWN; + if (aEventType == NS_MOUSE_DOUBLECLICK) { + event.message = NS_MOUSE_BUTTON_DOWN; + event.button = aButton; gLastClickCount = 2; } - else if (aEventType == NS_MOUSE_MIDDLE_DOUBLECLICK) { - event.message = NS_MOUSE_MIDDLE_BUTTON_DOWN; - gLastClickCount = 2; - } - else if (aEventType == NS_MOUSE_RIGHT_DOUBLECLICK) { - event.message = NS_MOUSE_RIGHT_BUTTON_DOWN; - gLastClickCount = 2; - } - else if (aEventType == NS_MOUSE_LEFT_BUTTON_UP || aEventType == NS_MOUSE_MIDDLE_BUTTON_UP || - aEventType == NS_MOUSE_RIGHT_BUTTON_UP) { + else if (aEventType == NS_MOUSE_BUTTON_UP) { // remember when this happened for the next mouse down gLastMousePoint.x = eventPoint.x; gLastMousePoint.y = eventPoint.y; gLastMouseButton = eventButton; } - else if (aEventType == NS_MOUSE_LEFT_BUTTON_DOWN || aEventType == NS_MOUSE_MIDDLE_BUTTON_DOWN || - aEventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { + else if (aEventType == NS_MOUSE_BUTTON_DOWN) { // now look to see if we want to convert this to a double- or triple-click #ifdef NS_DEBUG_XX @@ -6105,32 +6108,50 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l switch (aEventType) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - pluginEvent.event = WM_LBUTTONDOWN; + case NS_MOUSE_BUTTON_DOWN: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_LBUTTONDOWN; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_MBUTTONDOWN; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_RBUTTONDOWN; + break; + default: + break; + } break; - case NS_MOUSE_LEFT_BUTTON_UP: - pluginEvent.event = WM_LBUTTONUP; + case NS_MOUSE_BUTTON_UP: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_LBUTTONUP; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_MBUTTONUP; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_RBUTTONUP; + break; + default: + break; + } break; - case NS_MOUSE_LEFT_DOUBLECLICK: - pluginEvent.event = WM_LBUTTONDBLCLK; - break; - case NS_MOUSE_RIGHT_BUTTON_DOWN: - pluginEvent.event = WM_RBUTTONDOWN; - break; - case NS_MOUSE_RIGHT_BUTTON_UP: - pluginEvent.event = WM_RBUTTONUP; - break; - case NS_MOUSE_RIGHT_DOUBLECLICK: - pluginEvent.event = WM_RBUTTONDBLCLK; - break; - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - pluginEvent.event = WM_MBUTTONDOWN; - break; - case NS_MOUSE_MIDDLE_BUTTON_UP: - pluginEvent.event = WM_MBUTTONUP; - break; - case NS_MOUSE_MIDDLE_DOUBLECLICK: - pluginEvent.event = WM_MBUTTONDBLCLK; + case NS_MOUSE_DOUBLECLICK: + switch (aButton) { + case nsMouseEvent::eLeftButton: + pluginEvent.event = WM_LBUTTONDBLCLK; + break; + case nsMouseEvent::eMiddleButton: + pluginEvent.event = WM_MBUTTONDBLCLK; + break; + case nsMouseEvent::eRightButton: + pluginEvent.event = WM_RBUTTONDBLCLK; + break; + default: + break; + } break; case NS_MOUSE_MOVE: pluginEvent.event = WM_MOUSEMOVE; @@ -6204,15 +6225,11 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM l } break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(event)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(event)); result = ConvertStatus(mMouseListener->MouseClicked(event)); break; @@ -6333,7 +6350,8 @@ HBRUSH nsWindow::OnControlColor() // Deal with all sort of mouse event // //------------------------------------------------------------------------- -PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam) +PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam, + PRBool aIsContextMenuKey, PRInt16 aButton) { PRBool result = PR_FALSE; @@ -6342,15 +6360,11 @@ PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARA } switch (aEventType) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: CaptureMouse(PR_TRUE); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: if (!(wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON))) CaptureMouse(PR_FALSE); break; @@ -6360,7 +6374,8 @@ PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARA } // switch - return nsWindow::DispatchMouseEvent(aEventType, wParam, lParam); + return nsWindow::DispatchMouseEvent(aEventType, wParam, lParam, + aIsContextMenuKey, aButton); } //------------------------------------------------------------------------- @@ -7407,7 +7422,7 @@ NS_IMETHODIMP nsWindow::CancelIMEComposition() // Mouse operation of IME PRBool -nsWindow::IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam) +nsWindow::IMEMouseHandling(PRInt32 aAction, LPARAM lParam) { #ifndef WINCE POINT ptPos; @@ -7415,7 +7430,7 @@ nsWindow::IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam) ptPos.y = (short)HIWORD(lParam); if (sIMEIsComposing && nsWindow::uWM_MSIME_MOUSE) { - if (IMECompositionHitTest(aEventType, &ptPos)) + if (IMECompositionHitTest(&ptPos)) if (HandleMouseActionOfIME(aAction, &ptPos)) return PR_TRUE; } else { @@ -7423,7 +7438,7 @@ nsWindow::IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam) if (parentWnd) { nsWindow* parentWidget = GetNSWindowPtr(parentWnd); if (parentWidget && parentWidget->sIMEIsComposing && nsWindow::uWM_MSIME_MOUSE) { - if (parentWidget->IMECompositionHitTest(aEventType, &ptPos)) + if (parentWidget->IMECompositionHitTest(&ptPos)) if (parentWidget->HandleMouseActionOfIME(aAction, &ptPos)) return PR_TRUE; } @@ -7479,7 +7494,7 @@ nsWindow::HandleMouseActionOfIME(int aAction, POINT *ptPos) } //The coordinate is relative to the upper-left corner of the client area. -PRBool nsWindow::IMECompositionHitTest(PRUint32 aEventType, POINT * ptPos) +PRBool nsWindow::IMECompositionHitTest(POINT * ptPos) { PRBool IsHit = PR_FALSE; diff --git a/mozilla/widget/src/windows/nsWindow.h b/mozilla/widget/src/windows/nsWindow.h index 252b3cce11d..36c6fe2f9e5 100644 --- a/mozilla/widget/src/windows/nsWindow.h +++ b/mozilla/widget/src/windows/nsWindow.h @@ -230,8 +230,8 @@ public: NS_IMETHOD GetIMEEnabled(PRBool* aState); NS_IMETHOD CancelIMEComposition(); - PRBool IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam); - PRBool IMECompositionHitTest(PRUint32 aEventType, POINT * ptPos); + PRBool IMEMouseHandling(PRInt32 aAction, LPARAM lParam); + PRBool IMECompositionHitTest(POINT * ptPos); PRBool HandleMouseActionOfIME(PRInt32 aAction, POINT* ptPos); void GetCompositionWindowPos(HIMC hIMC, PRUint32 aEventType, COMPOSITIONFORM *cpForm); @@ -241,7 +241,10 @@ public: HWND GetWindowHandle() { return mWnd; } WNDPROC GetPrevWindowProc() { return mPrevWndProc; } - virtual PRBool DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam); + virtual PRBool DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, + LPARAM lParam, + PRBool aIsContextMenuKey = PR_FALSE, + PRInt16 aButton = nsMouseEvent::eLeftButton); #ifdef ACCESSIBILITY virtual PRBool DispatchAccessibleEvent(PRUint32 aEventType, nsIAccessible** aAccessible, nsPoint* aPoint = nsnull); already_AddRefed GetRootAccessible(); @@ -550,7 +553,9 @@ class ChildWindow : public nsWindow { public: ChildWindow() {} - PRBool DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam); + PRBool DispatchMouseEvent(PRUint32 aEventType, WPARAM wParam, LPARAM lParam, + PRBool aIsContextMenuKey = PR_FALSE, + PRInt16 aButton = nsMouseEvent::eLeftButton); protected: virtual DWORD WindowStyle(); diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index 245a78fe69a..d974274a9e1 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -622,6 +622,7 @@ void nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) { PRUint32 eventType = 0; + PRInt16 button = nsMouseEvent::eLeftButton; PRBool currentlyDragging = mDragging; nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, aWidget); @@ -631,18 +632,20 @@ nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) (event->type == ButtonPress ? "ButtonPress" : "ButtonRelease"))); switch(event->type) { case ButtonPress: + eventType = NS_MOUSE_BUTTON_DOWN; switch(event->xbutton.button) { case 1: - eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + button = nsMouseEvent::eLeftButton; mDragging = PR_TRUE; break; case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + button = nsMouseEvent::eMiddleButton; break; case 3: /* look back into this in case anything actually needs a * NS_MOUSE_RIGHT_BUTTON_DOWN */ eventType = NS_CONTEXTMENU; + button = nsMouseEvent::eRightButton; break; case 4: case 5: @@ -664,16 +667,17 @@ nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) } break; case ButtonRelease: + eventType = NS_MOUSE_BUTTON_UP; switch(event->xbutton.button) { case 1: - eventType = NS_MOUSE_LEFT_BUTTON_UP; + button = nsMouseEvent::eLeftButton; mDragging = PR_FALSE; break; case 2: - eventType = NS_MOUSE_MIDDLE_BUTTON_UP; + button = nsMouseEvent::eMiddleButton; break; case 3: - eventType = NS_MOUSE_RIGHT_BUTTON_UP; + button = nsMouseEvent::eRightButton; break; case 4: case 5: @@ -683,6 +687,7 @@ nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) } nsMouseEvent mevent(PR_TRUE, eventType, aWidget, nsMouseEvent::eReal); + mevent.button = button; mevent.isShift = mShiftDown; mevent.isControl = mCtrlDown; mevent.isAlt = mAltDown; diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp index 219dc3a474b..10774eacebc 100644 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ b/mozilla/widget/src/xlib/nsWidget.cpp @@ -1077,15 +1077,9 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) } /* If there was a mouse down event, check if any popups need to be notified */ - switch (aEvent.message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - if (HandlePopup(aEvent.refPoint.x, aEvent.refPoint.y)){ - // Should we return here as GTK does? - return PR_TRUE; - } - break; + if (aEvent.message == NS_MOUSE_BUTTON_DOWN && + HandlePopup(aEvent.refPoint.x, aEvent.refPoint.y)) { + return PR_TRUE; } if (nsnull != mEventCallback) { @@ -1097,14 +1091,10 @@ PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) case NS_MOUSE_MOVE: // XXX this isn't handled in gtk for some reason. break; - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: + case NS_MOUSE_BUTTON_DOWN: result = ConvertStatus(mMouseListener->MousePressed(aEvent)); break; - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: + case NS_MOUSE_BUTTON_UP: result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); break; diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp index c5701c5cfb7..13660695620 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp @@ -959,19 +959,11 @@ case _value: eventName.AssignWithConversion(_name) ; break _ASSIGN_eventName(NS_MENU_SELECTED,"NS_MENU_SELECTED"); _ASSIGN_eventName(NS_MOUSE_ENTER,"NS_MOUSE_ENTER"); _ASSIGN_eventName(NS_MOUSE_EXIT,"NS_MOUSE_EXIT"); - _ASSIGN_eventName(NS_MOUSE_LEFT_BUTTON_DOWN,"NS_MOUSE_LEFT_BTN_DOWN"); - _ASSIGN_eventName(NS_MOUSE_LEFT_BUTTON_UP,"NS_MOUSE_LEFT_BTN_UP"); - _ASSIGN_eventName(NS_MOUSE_LEFT_CLICK,"NS_MOUSE_LEFT_CLICK"); - _ASSIGN_eventName(NS_MOUSE_LEFT_DOUBLECLICK,"NS_MOUSE_LEFT_DBLCLICK"); - _ASSIGN_eventName(NS_MOUSE_MIDDLE_BUTTON_DOWN,"NS_MOUSE_MIDDLE_BTN_DOWN"); - _ASSIGN_eventName(NS_MOUSE_MIDDLE_BUTTON_UP,"NS_MOUSE_MIDDLE_BTN_UP"); - _ASSIGN_eventName(NS_MOUSE_MIDDLE_CLICK,"NS_MOUSE_MIDDLE_CLICK"); - _ASSIGN_eventName(NS_MOUSE_MIDDLE_DOUBLECLICK,"NS_MOUSE_MIDDLE_DBLCLICK"); + _ASSIGN_eventName(NS_MOUSE_BUTTON_DOWN,"NS_MOUSE_BUTTON_DOWN"); + _ASSIGN_eventName(NS_MOUSE_BUTTON_UP,"NS_MOUSE_BUTTON_UP"); + _ASSIGN_eventName(NS_MOUSE_CLICK,"NS_MOUSE_CLICK"); + _ASSIGN_eventName(NS_MOUSE_DOUBLECLICK,"NS_MOUSE_DBLCLICK"); _ASSIGN_eventName(NS_MOUSE_MOVE,"NS_MOUSE_MOVE"); - _ASSIGN_eventName(NS_MOUSE_RIGHT_BUTTON_DOWN,"NS_MOUSE_RIGHT_BTN_DOWN"); - _ASSIGN_eventName(NS_MOUSE_RIGHT_BUTTON_UP,"NS_MOUSE_RIGHT_BTN_UP"); - _ASSIGN_eventName(NS_MOUSE_RIGHT_CLICK,"NS_MOUSE_RIGHT_CLICK"); - _ASSIGN_eventName(NS_MOUSE_RIGHT_DOUBLECLICK,"NS_MOUSE_RIGHT_DBLCLICK"); _ASSIGN_eventName(NS_MOVE,"NS_MOVE"); _ASSIGN_eventName(NS_LOAD,"NS_LOAD"); _ASSIGN_eventName(NS_PAGE_UNLOAD,"NS_PAGE_UNLOAD");