Fix for 71705, stop right click from triggering onclick handlers in base html content, though not in xml/xul/chrome. reviewed a while ago, lost in tree. r:saari,sr:hyatt

This commit is contained in:
joki%netscape.com 2001-11-07 06:29:29 +00:00
Родитель 35720e9017
Коммит 57040838f7
9 изменённых файлов: 49 добавлений и 16 удалений

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

@ -707,7 +707,8 @@ nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)
&& !(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
aEvent->flags |= aFlags;
mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull, aFlags, aEventStatus);
aEvent->flags &= ~aFlags;

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

@ -1871,7 +1871,8 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
//Local handling stage
if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) &&
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) {
!(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)
&& !(aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH)) {
aEvent->flags |= aFlags;
nsCOMPtr<nsIDOMEventTarget> curTarg(do_QueryInterface(NS_STATIC_CAST(nsIHTMLContent *, this)));
mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, curTarg, aFlags, aEventStatus);

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

@ -57,9 +57,6 @@ typedef struct {
PRUint8 mSubTypeCapture;
} nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80
//These define the internal type of the EventListenerManager
//No listener type defined, should happen only at creation
#define NS_ELM_NONE 0

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

@ -170,6 +170,7 @@ nsEventStateManager::nsEventStateManager()
mAccessKeys = nsnull;
mBrowseWithCaret = PR_FALSE;
hHover = PR_FALSE;
mLeftClickOnly = PR_TRUE;
NS_INIT_REFCNT();
@ -195,6 +196,7 @@ nsEventStateManager::Init()
if (NS_SUCCEEDED(rv)) {
mPrefService->GetBoolPref("nglayout.events.showHierarchicalHover", &hHover);
mPrefService->GetBoolPref("nglayout.events.dispatchLeftClickOnly", &mLeftClickOnly);
}
return rv;
@ -2457,6 +2459,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext,
nsresult ret = NS_OK;
nsMouseEvent event;
nsCOMPtr<nsIContent> mouseContent;
PRInt32 flags = NS_EVENT_FLAG_INIT;
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent));
@ -2470,9 +2473,11 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext,
break;
case NS_MOUSE_MIDDLE_BUTTON_UP:
event.message = NS_MOUSE_MIDDLE_CLICK;
flags |= mLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
break;
case NS_MOUSE_RIGHT_BUTTON_UP:
event.message = NS_MOUSE_RIGHT_CLICK;
flags |= mLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
break;
}
@ -2489,7 +2494,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext,
nsCOMPtr<nsIPresShell> presShell;
mPresContext->GetShell(getter_AddRefs(presShell));
if (presShell) {
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget, mouseContent, NS_EVENT_FLAG_INIT, aStatus);
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget, mouseContent, flags, aStatus);
if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2) {
nsMouseEvent event2;
//fire double click
@ -2515,7 +2520,7 @@ nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* aPresContext,
event2.isAlt = aEvent->isAlt;
event2.isMeta = aEvent->isMeta;
ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, mouseContent, NS_EVENT_FLAG_INIT, aStatus);
ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, mouseContent, flags, aStatus);
}
}
}

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

@ -234,6 +234,8 @@ protected:
nsIPresContext* mPresContext; // Not refcnted
nsIDocument* mDocument; // [OWNER], but doesn't need to be.
//Pref for dispatching middle and right clicks to content
PRBool mLeftClickOnly;
PRUint32 mLClickCount;
PRUint32 mMClickCount;

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

@ -1127,6 +1127,14 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
} //switch
}
// If NS_EVENT_FLAG_NO_CONTENT_DISPATCH is set we will not allow content to handle
// this event. But to allow middle mouse button paste to work we must allow
// middle clicks to go to text fields anyway.
PRBool noContentDispatch = aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH;
if (type == NS_FORM_INPUT_TEXT && aEvent->message == NS_MOUSE_MIDDLE_CLICK) {
aEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH;
}
// Try script event handlers first if its not a focus/blur event
//we dont want the doc to get these
rv = nsGenericHTMLLeafFormElement::HandleDOMEvent(aPresContext,
@ -1134,7 +1142,10 @@ nsHTMLInputElement::HandleDOMEvent(nsIPresContext* aPresContext,
aDOMEvent,
aFlags,
aEventStatus);
// XXX Should we check if the event failed?
// Reset the flag for other content besides this text field
aEvent->flags |= noContentDispatch ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
// now check to see if the event was "cancelled"
if (nsEventStatus_eConsumeNoDefault == *aEventStatus && checkWasSet
&& (type == NS_FORM_INPUT_CHECKBOX || type == NS_FORM_INPUT_RADIO)) {

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

@ -638,10 +638,21 @@ nsHTMLTextAreaElement::HandleDOMEvent(nsIPresContext* aPresContext,
}
}
// If NS_EVENT_FLAG_NO_CONTENT_DISPATCH is set we will not allow content to handle
// this event. But to allow middle mouse button paste to work we must allow
// middle clicks to go to text fields anyway.
PRBool noContentDispatch = aEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH;
if (aEvent->message == NS_MOUSE_MIDDLE_CLICK) {
aEvent->flags &= ~NS_EVENT_FLAG_NO_CONTENT_DISPATCH;
}
rv = nsGenericHTMLContainerFormElement::HandleDOMEvent(aPresContext, aEvent,
aDOMEvent,
aFlags, aEventStatus);
// Reset the flag for other content besides this text field
aEvent->flags |= noContentDispatch ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
// Finish the special anonymous content processing...
// If the event is starting here that's fine. If it's not
// init'ing here it started beneath us and needs modification.

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

@ -179,6 +179,9 @@ pref("nglayout.view.useViewManager2", true);
// css2 hover pref
pref("nglayout.events.showHierarchicalHover", false);
// dispatch left clicks only to content in browser (still allows clicks to chrome/xul)
pref("nglayout.events.dispatchLeftClickOnly", true);
// whether or not to use xbl form controls
pref("nglayout.debug.enable_xbl_forms", false);

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

@ -694,6 +694,8 @@ enum nsDragDropEventStatus {
#define NS_EVENT_FLAG_NO_DEFAULT 0x0010
#define NS_EVENT_FLAG_CANT_CANCEL 0x0020
#define NS_EVENT_FLAG_CANT_BUBBLE 0x0040
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x0080
#define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100
#define NS_APP_EVENT_FLAG_NONE 0x0000
#define NS_APP_EVENT_FLAG_HANDLED 0x0001 // Similar to NS_EVENT_FLAG_NO_DEFAULT, but it allows focus