diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 0f5ce818f2f..b409e7ebe99 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -2435,7 +2435,61 @@ nsGenericElement::doRemoveChildAt(PRUint32 aIndex, PRBool aNotify, return NS_OK; } +/* static */ +nsresult +nsGenericElement::DispatchEvent(nsPresContext* aPresContext, + nsEvent* aEvent, + nsIContent* aTarget, + PRBool aFullDispatch, + nsEventStatus* aStatus) +{ + NS_PRECONDITION(aTarget, "Must have target"); + NS_PRECONDITION(aEvent, "Must have source event"); + NS_PRECONDITION(aStatus, "Null out param?"); + if (!aPresContext) { + return NS_OK; + } + + nsIPresShell *shell = aPresContext->GetPresShell(); + if (!shell) { + return NS_OK; + } + + if (aFullDispatch) { + return shell->HandleEventWithTarget(aEvent, nsnull, aTarget, aStatus); + } + + return shell->HandleDOMEventWithTarget(aTarget, aEvent, aStatus); +} + +/* static */ +nsresult +nsGenericElement::DispatchClickEvent(nsPresContext* aPresContext, + nsInputEvent* aSourceEvent, + nsIContent* aTarget, + PRBool aFullDispatch, + nsEventStatus* aStatus) +{ + NS_PRECONDITION(aTarget, "Must have target"); + NS_PRECONDITION(aSourceEvent, "Must have source event"); + NS_PRECONDITION(aStatus, "Null out param?"); + + nsMouseEvent event(NS_IS_TRUSTED_EVENT(aSourceEvent), NS_MOUSE_LEFT_CLICK, + aSourceEvent->widget, nsMouseEvent::eReal); + event.refPoint = aSourceEvent->refPoint; + PRUint32 clickCount = 1; + if (aSourceEvent->eventStructType == NS_MOUSE_EVENT) { + clickCount = NS_STATIC_CAST(nsMouseEvent*, aSourceEvent)->clickCount; + } + event.clickCount = clickCount; + event.isShift = aSourceEvent->isShift; + event.isControl = aSourceEvent->isControl; + event.isAlt = aSourceEvent->isAlt; + event.isMeta = aSourceEvent->isMeta; + + return DispatchEvent(aPresContext, &event, aTarget, aFullDispatch, aStatus); +} //---------------------------------------------------------------------- diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index bbc39a8d2c9..a2816a1fe5a 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -716,7 +716,33 @@ public: nsIContent* aKid, nsIContent* aParent, nsIDocument* aDocument, nsAttrAndChildArray& aChildArray); + + /** + * Method to create and dispatch a left-click event loosely based on + * aSourceEvent. If aFullDispatch is true, the event will be dispatched + * through the full dispatching of the presshell of the aPresContext; if it's + * false the event will be dispatched only as a DOM event. + * If aPresContext is nsnull, this does nothing. + */ + static nsresult DispatchClickEvent(nsPresContext* aPresContext, + nsInputEvent* aSourceEvent, + nsIContent* aTarget, + PRBool aFullDispatch, + nsEventStatus* aStatus); + /** + * Method to dispatch aEvent to aTarget. If aFullDispatch is true, the event + * will be dispatched through the full dispatching of the presshell of the + * aPresContext; if it's false the event will be dispatched only as a DOM + * event. + * If aPresContext is nsnull, this does nothing. + */ + static nsresult DispatchEvent(nsPresContext* aPresContext, + nsEvent* aEvent, + nsIContent* aTarget, + PRBool aFullDispatch, + nsEventStatus* aStatus); + /** * Struct that stores info on an attribute. The name and value must * either both be null or both be non-null. diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 8aed90fdf66..9ebd48b67c9 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -1403,62 +1403,6 @@ IsArea(nsIContent *aContent) aContent->IsContentOfType(nsIContent::eHTML)); } -/* static */ -nsresult -nsGenericHTMLElement::DispatchEvent(nsPresContext* aPresContext, - nsEvent* aEvent, - nsIContent* aTarget, - PRBool aFullDispatch, - nsEventStatus* aStatus) -{ - NS_PRECONDITION(aTarget, "Must have target"); - NS_PRECONDITION(aEvent, "Must have source event"); - NS_PRECONDITION(aStatus, "Null out param?"); - - if (!aPresContext) { - return NS_OK; - } - - nsIPresShell *shell = aPresContext->GetPresShell(); - if (!shell) { - return NS_OK; - } - - if (aFullDispatch) { - return shell->HandleEventWithTarget(aEvent, nsnull, aTarget, aStatus); - } - - return shell->HandleDOMEventWithTarget(aTarget, aEvent, aStatus); -} - -/* static */ -nsresult -nsGenericHTMLElement::DispatchClickEvent(nsPresContext* aPresContext, - nsInputEvent* aSourceEvent, - nsIContent* aTarget, - PRBool aFullDispatch, - nsEventStatus* aStatus) -{ - NS_PRECONDITION(aTarget, "Must have target"); - NS_PRECONDITION(aSourceEvent, "Must have source event"); - NS_PRECONDITION(aStatus, "Null out param?"); - - nsMouseEvent event(NS_IS_TRUSTED_EVENT(aSourceEvent), NS_MOUSE_LEFT_CLICK, - aSourceEvent->widget, nsMouseEvent::eReal); - event.refPoint = aSourceEvent->refPoint; - PRUint32 clickCount = 1; - if (aSourceEvent->eventStructType == NS_MOUSE_EVENT) { - clickCount = NS_STATIC_CAST(nsMouseEvent*, aSourceEvent)->clickCount; - } - event.clickCount = clickCount; - event.isShift = aSourceEvent->isShift; - event.isControl = aSourceEvent->isControl; - event.isAlt = aSourceEvent->isAlt; - event.isMeta = aSourceEvent->isMeta; - - return DispatchEvent(aPresContext, &event, aTarget, aFullDispatch, aStatus); -} - nsresult nsGenericHTMLElement::PostHandleEventForAnchors(nsEventChainPostVisitor& aVisitor) { diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index 149a6705b8d..2a1a5d2ce36 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -195,26 +195,6 @@ public: virtual void RemoveFocus(nsPresContext *aPresContext); virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull); - /** - * Method to create and dispatch a left-click event loosely based on aSourceEvent. If - * aFullDispatch is true, the event will be dispatched in all event groups and so - * forth; if it's false it will be dispatched only as a DOM event. - */ - static nsresult DispatchClickEvent(nsPresContext* aPresContext, - nsInputEvent* aSourceEvent, - nsIContent* aTarget, - PRBool aFullDispatch, - nsEventStatus* aStatus); - - /** - * Method to dispatch aEvent to aTarget without crashing and all. - */ - static nsresult DispatchEvent(nsPresContext* aPresContext, - nsEvent* aEvent, - nsIContent* aTarget, - PRBool aFullDispatch, - nsEventStatus* aStatus); - nsresult PostHandleEventForAnchors(nsEventChainPostVisitor& aVisitor); // Used by A, AREA, LINK, and STYLE. diff --git a/mozilla/content/xml/content/src/nsXMLElement.cpp b/mozilla/content/xml/content/src/nsXMLElement.cpp index 082730fab1c..abfb2884fbd 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.cpp +++ b/mozilla/content/xml/content/src/nsXMLElement.cpp @@ -316,29 +316,14 @@ nsXMLElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) break; case NS_KEY_PRESS: - if (aVisitor.mEvent->eventStructType == NS_KEY_EVENT && - aVisitor.mPresContext) { + if (aVisitor.mEvent->eventStructType == NS_KEY_EVENT) { nsKeyEvent* keyEvent = NS_STATIC_CAST(nsKeyEvent*, aVisitor.mEvent); if (keyEvent->keyCode == NS_VK_RETURN) { nsEventStatus status = nsEventStatus_eIgnore; - - //fire click - nsGUIEvent* guiEvent = NS_STATIC_CAST(nsGUIEvent*, aVisitor.mEvent); - nsMouseEvent event(NS_IS_TRUSTED_EVENT(aVisitor.mEvent), - NS_MOUSE_LEFT_CLICK, - guiEvent->widget, nsMouseEvent::eReal); - event.refPoint = aVisitor.mEvent->refPoint; - event.clickCount = 1; - event.isShift = keyEvent->isShift; - event.isControl = keyEvent->isControl; - event.isAlt = keyEvent->isAlt; - event.isMeta = keyEvent->isMeta; - - nsIPresShell *presShell = aVisitor.mPresContext->GetPresShell(); - if (presShell) { - rv = presShell->HandleDOMEventWithTarget(this, &event, &status); - // presShell may no longer be alive, don't use it here - // unless you keep a reference. + rv = DispatchClickEvent(aVisitor.mPresContext, keyEvent, this, + PR_FALSE, &status); + if (NS_SUCCEEDED(rv)) { + aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; } } }