Bug 329437, Push DispatchClickEvent up to nsGenericElement r+sr=bz

git-svn-id: svn://10.0.0.236/trunk@192322 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
Olli.Pettay%helsinki.fi 2006-03-14 19:57:33 +00:00
parent 9d9fdd102a
commit a516ec74ad
5 changed files with 85 additions and 96 deletions

View File

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

View File

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

View File

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

View File

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

View File

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