Bug 813445 part.3 Remove NS_EVENT_FLAG_CANT_CANCEL and NS_EVENT_FLAG_CANT_BUBBLE r=smaug

This commit is contained in:
Masayuki Nakano 2012-12-16 10:26:03 +09:00
parent 06dbf6211e
commit 2c9891bdd2
18 changed files with 48 additions and 50 deletions

View File

@ -59,10 +59,8 @@ nsScriptElement::ScriptEvaluated(nsresult aResult,
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
uint32_t type = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_LOAD_ERROR; uint32_t type = NS_SUCCEEDED(aResult) ? NS_LOAD : NS_LOAD_ERROR;
nsEvent event(true, type); nsEvent event(true, type);
if (type == NS_LOAD) { // Load event doesn't bubble.
// Load event doesn't bubble. event.mFlags.mBubbles = (type != NS_LOAD);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
}
nsEventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status); nsEventDispatcher::Dispatch(cont, presContext, &event, nullptr, &status);
} }

View File

@ -17,7 +17,7 @@ public:
: nsEvent(isTrusted, msg, NS_MUTATION_EVENT), : nsEvent(isTrusted, msg, NS_MUTATION_EVENT),
mAttrChange(0) mAttrChange(0)
{ {
flags |= NS_EVENT_FLAG_CANT_CANCEL; mFlags.mCancelable = false;
} }
nsCOMPtr<nsIDOMNode> mRelatedNode; nsCOMPtr<nsIDOMNode> mRelatedNode;

View File

@ -24,7 +24,7 @@ nsDOMCompositionEvent::nsDOMCompositionEvent(nsPresContext* aPresContext,
// XXX compositionstart is cancelable in draft of DOM3 Events. // XXX compositionstart is cancelable in draft of DOM3 Events.
// However, it doesn't make sence for us, we cannot cancel composition // However, it doesn't make sence for us, we cannot cancel composition
// when we sends compositionstart event. // when we sends compositionstart event.
mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL; mEvent->mFlags.mCancelable = false;
} }
mData = static_cast<nsCompositionEvent*>(mEvent)->data; mData = static_cast<nsCompositionEvent*>(mEvent)->data;

View File

@ -340,14 +340,14 @@ nsDOMEvent::GetEventPhase(uint16_t* aEventPhase)
NS_IMETHODIMP NS_IMETHODIMP
nsDOMEvent::GetBubbles(bool* aBubbles) nsDOMEvent::GetBubbles(bool* aBubbles)
{ {
*aBubbles = !(mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE); *aBubbles = mEvent->mFlags.mBubbles;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDOMEvent::GetCancelable(bool* aCancelable) nsDOMEvent::GetCancelable(bool* aCancelable)
{ {
*aCancelable = !(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL); *aCancelable = mEvent->mFlags.mCancelable;
return NS_OK; return NS_OK;
} }
@ -427,7 +427,7 @@ nsDOMEvent::GetIsTrusted(bool *aIsTrusted)
NS_IMETHODIMP NS_IMETHODIMP
nsDOMEvent::PreventDefault() nsDOMEvent::PreventDefault()
{ {
if (!(mEvent->flags & NS_EVENT_FLAG_CANT_CANCEL)) { if (mEvent->mFlags.mCancelable) {
mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT; mEvent->flags |= NS_EVENT_FLAG_NO_DEFAULT;
// Need to set an extra flag for drag events. // Need to set an extra flag for drag events.
@ -471,17 +471,8 @@ nsDOMEvent::InitEvent(const nsAString& aEventTypeArg, bool aCanBubbleArg, bool a
SetEventType(aEventTypeArg); SetEventType(aEventTypeArg);
if (aCanBubbleArg) { mEvent->mFlags.mBubbles = aCanBubbleArg;
mEvent->flags &= ~NS_EVENT_FLAG_CANT_BUBBLE; mEvent->mFlags.mCancelable = aCancelableArg;
} else {
mEvent->flags |= NS_EVENT_FLAG_CANT_BUBBLE;
}
if (aCancelableArg) {
mEvent->flags &= ~NS_EVENT_FLAG_CANT_CANCEL;
} else {
mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL;
}
// Clearing the old targets, so that the event is targeted correctly when // Clearing the old targets, so that the event is targeted correctly when
// re-dispatching it. // re-dispatching it.

View File

@ -330,7 +330,7 @@ nsEventTargetChainItem::HandleEventTargetChain(nsEventChainPostVisitor& aVisitor
aVisitor.mEvent->target = newTarget; aVisitor.mEvent->target = newTarget;
} }
if (!(aVisitor.mEvent->flags & NS_EVENT_FLAG_CANT_BUBBLE) || newTarget) { if (aVisitor.mEvent->mFlags.mBubbles || newTarget) {
if ((!(aVisitor.mEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH) || if ((!(aVisitor.mEvent->flags & NS_EVENT_FLAG_NO_CONTENT_DISPATCH) ||
item->ForceContentDispatch()) && item->ForceContentDispatch()) &&
!(aVisitor.mEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) { !(aVisitor.mEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH)) {

View File

@ -86,7 +86,8 @@ nsHTMLMenuElement::SendShowEvent()
} }
nsEvent event(true, NS_SHOW_EVENT); nsEvent event(true, NS_SHOW_EVENT);
event.flags |= NS_EVENT_FLAG_CANT_CANCEL | NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
event.mFlags.mCancelable = false;
nsCOMPtr<nsIPresShell> shell = document->GetShell(); nsCOMPtr<nsIPresShell> shell = document->GetShell();
if (!shell) { if (!shell) {

View File

@ -25,8 +25,8 @@ nsDOMTimeEvent::nsDOMTimeEvent(nsPresContext* aPresContext, nsEvent* aEvent)
mDetail = event->detail; mDetail = event->detail;
} }
mEvent->flags |= NS_EVENT_FLAG_CANT_BUBBLE | mEvent->mFlags.mBubbles = false;
NS_EVENT_FLAG_CANT_CANCEL; mEvent->mFlags.mCancelable = false;
if (mPresContext) { if (mPresContext) {
nsCOMPtr<nsISupports> container = mPresContext->GetContainer(); nsCOMPtr<nsISupports> container = mPresContext->GetContainer();

View File

@ -23,10 +23,9 @@ nsDOMSVGEvent::nsDOMSVGEvent(nsPresContext* aPresContext,
mEvent->time = PR_Now(); mEvent->time = PR_Now();
} }
mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL; mEvent->mFlags.mCancelable = false;
if (mEvent->message == NS_SVG_LOAD || mEvent->message == NS_SVG_UNLOAD) { mEvent->mFlags.mBubbles =
mEvent->flags |= NS_EVENT_FLAG_CANT_BUBBLE; (mEvent->message != NS_SVG_LOAD && mEvent->message != NS_SVG_UNLOAD);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -32,7 +32,7 @@ nsDOMSVGZoomEvent::nsDOMSVGZoomEvent(nsPresContext* aPresContext,
mEvent->time = PR_Now(); mEvent->time = PR_Now();
} }
mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL; mEvent->mFlags.mCancelable = false;
// We must store the "Previous" and "New" values before this event is // We must store the "Previous" and "New" values before this event is
// dispatched. Reading the values from the root 'svg' element after we've // dispatched. Reading the values from the root 'svg' element after we've

View File

@ -1862,7 +1862,7 @@ public:
NS_IMETHOD Run() NS_IMETHOD Run()
{ {
nsFocusEvent event(true, mType); nsFocusEvent event(true, mType);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
event.fromRaise = mWindowRaised; event.fromRaise = mWindowRaised;
event.isRefocus = mIsRefocus; event.isRefocus = mIsRefocus;
return nsEventDispatcher::Dispatch(mTarget, mContext, &event); return nsEventDispatcher::Dispatch(mTarget, mContext, &event);

View File

@ -2664,7 +2664,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event(aVisitor.mEvent->mFlags.mIsTrusted, NS_LOAD); nsEvent event(aVisitor.mEvent->mFlags.mIsTrusted, NS_LOAD);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
// Most of the time we could get a pres context to pass in here, // Most of the time we could get a pres context to pass in here,
// but not always (i.e. if this window is not shown there won't // but not always (i.e. if this window is not shown there won't

View File

@ -1819,7 +1819,7 @@ public:
} }
nsEvent inputEvent(mIsTrusted, NS_FORM_INPUT); nsEvent inputEvent(mIsTrusted, NS_FORM_INPUT);
inputEvent.flags |= NS_EVENT_FLAG_CANT_CANCEL; inputEvent.mFlags.mCancelable = false;
inputEvent.time = static_cast<uint64_t>(PR_Now() / 1000); inputEvent.time = static_cast<uint64_t>(PR_Now() / 1000);
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsresult rv = nsresult rv =

View File

@ -1008,7 +1008,7 @@ nsDocumentViewer::LoadComplete(nsresult aStatus)
(NS_SUCCEEDED(aStatus) || aStatus == NS_ERROR_PARSED_DATA_CACHED)) { (NS_SUCCEEDED(aStatus) || aStatus == NS_ERROR_PARSED_DATA_CACHED)) {
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event(true, NS_LOAD); nsEvent event(true, NS_LOAD);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
// XXX Dispatching to |window|, but using |document| as the target. // XXX Dispatching to |window|, but using |document| as the target.
event.target = mDocument; event.target = mDocument;
@ -1289,7 +1289,7 @@ nsDocumentViewer::PageHide(bool aIsUnload)
// Now, fire an Unload event to the document... // Now, fire an Unload event to the document...
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event(true, NS_PAGE_UNLOAD); nsEvent event(true, NS_PAGE_UNLOAD);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
// XXX Dispatching to |window|, but using |document| as the target. // XXX Dispatching to |window|, but using |document| as the target.
event.target = mDocument; event.target = mDocument;

View File

@ -2847,7 +2847,7 @@ nsGfxScrollFrameInner::FireScrollEvent()
} else { } else {
// scroll events fired at elements don't bubble (although scroll events // scroll events fired at elements don't bubble (although scroll events
// fired at documents do, to the window) // fired at documents do, to the window)
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
nsEventDispatcher::Dispatch(content, prescontext, &event, nullptr, &status); nsEventDispatcher::Dispatch(content, prescontext, &event, nullptr, &status);
} }
} }

View File

@ -82,7 +82,7 @@ nsImageBoxFrameEvent::Run()
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event(true, mMessage); nsEvent event(true, mMessage);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
nsEventDispatcher::Dispatch(mContent, pres_context, &event, nullptr, &status); nsEventDispatcher::Dispatch(mContent, pres_context, &event, nullptr, &status);
return NS_OK; return NS_OK;
} }

View File

@ -4439,7 +4439,7 @@ nsTreeBodyFrame::FireScrollEvent()
mScrollEvent.Forget(); mScrollEvent.Forget();
nsScrollbarEvent event(true, NS_SCROLL_EVENT, nullptr); nsScrollbarEvent event(true, NS_SCROLL_EVENT, nullptr);
// scroll events fired at elements don't bubble // scroll events fired at elements don't bubble
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
nsEventDispatcher::Dispatch(GetContent(), PresContext(), &event); nsEventDispatcher::Dispatch(GetContent(), PresContext(), &event);
} }

View File

@ -20,7 +20,7 @@ nsHtml5SVGLoadDispatcher::Run()
{ {
nsEvent event(true, NS_SVG_LOAD); nsEvent event(true, NS_SVG_LOAD);
event.eventStructType = NS_SVG_EVENT; event.eventStructType = NS_SVG_EVENT;
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE; event.mFlags.mBubbles = false;
// Do we care about forcing presshell creation if it hasn't happened yet? // Do we care about forcing presshell creation if it hasn't happened yet?
// That is, should this code flush or something? Does it really matter? // That is, should this code flush or something? Does it really matter?
// For that matter, do we really want to try getting the prescontext? // For that matter, do we really want to try getting the prescontext?

View File

@ -113,8 +113,6 @@ enum nsEventStructType {
#define NS_EVENT_FLAG_CAPTURE 0x0004 #define NS_EVENT_FLAG_CAPTURE 0x0004
#define NS_EVENT_FLAG_STOP_DISPATCH 0x0008 #define NS_EVENT_FLAG_STOP_DISPATCH 0x0008
#define NS_EVENT_FLAG_NO_DEFAULT 0x0010 #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_PRIV_EVENT_FLAG_SCRIPT 0x0080
#define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100 #define NS_EVENT_FLAG_NO_CONTENT_DISPATCH 0x0100
#define NS_EVENT_FLAG_SYSTEM_EVENT 0x0200 #define NS_EVENT_FLAG_SYSTEM_EVENT 0x0200
@ -522,6 +520,12 @@ public:
bool mInBubblingPhase : 1; bool mInBubblingPhase : 1;
// If mInCapturePhase is true, the event is in capture phase or target phase. // If mInCapturePhase is true, the event is in capture phase or target phase.
bool mInCapturePhase : 1; bool mInCapturePhase : 1;
// If mCancelable is true, the event can be consumed. I.e., calling
// nsDOMEvent::PreventDefault() can prevent the default action.
bool mCancelable : 1;
// If mBubbles is true, the event can bubble. Otherwise, cannot be handled
// in bubbling phase.
bool mBubbles : 1;
// If the event is being handled in target phase, returns true. // If the event is being handled in target phase, returns true.
bool InTargetPhase() const bool InTargetPhase() const
@ -582,6 +586,8 @@ protected:
{ {
MOZ_COUNT_CTOR(nsEvent); MOZ_COUNT_CTOR(nsEvent);
mFlags.mIsTrusted = isTrusted; mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
} }
nsEvent() nsEvent()
@ -601,6 +607,8 @@ public:
{ {
MOZ_COUNT_CTOR(nsEvent); MOZ_COUNT_CTOR(nsEvent);
mFlags.mIsTrusted = isTrusted; mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
} }
~nsEvent() ~nsEvent()
@ -912,11 +920,12 @@ protected:
{ {
switch (msg) { switch (msg) {
case NS_MOUSE_MOVE: case NS_MOUSE_MOVE:
flags |= NS_EVENT_FLAG_CANT_CANCEL; mFlags.mCancelable = false;
break; break;
case NS_MOUSEENTER: case NS_MOUSEENTER:
case NS_MOUSELEAVE: case NS_MOUSELEAVE:
flags |= (NS_EVENT_FLAG_CANT_CANCEL & NS_EVENT_FLAG_CANT_BUBBLE); mFlags.mBubbles = false;
mFlags.mCancelable = false;
break; break;
default: default:
break; break;
@ -933,11 +942,12 @@ public:
{ {
switch (msg) { switch (msg) {
case NS_MOUSE_MOVE: case NS_MOUSE_MOVE:
flags |= NS_EVENT_FLAG_CANT_CANCEL; mFlags.mCancelable = false;
break; break;
case NS_MOUSEENTER: case NS_MOUSEENTER:
case NS_MOUSELEAVE: case NS_MOUSELEAVE:
flags |= (NS_EVENT_FLAG_CANT_CANCEL | NS_EVENT_FLAG_CANT_BUBBLE); mFlags.mBubbles = false;
mFlags.mCancelable = false;
break; break;
case NS_CONTEXTMENU: case NS_CONTEXTMENU:
button = (context == eNormal) ? eRightButton : eLeftButton; button = (context == eNormal) ? eRightButton : eLeftButton;
@ -982,11 +992,10 @@ public:
: nsMouseEvent(isTrusted, msg, w, NS_DRAG_EVENT, eReal), : nsMouseEvent(isTrusted, msg, w, NS_DRAG_EVENT, eReal),
userCancelled(false) userCancelled(false)
{ {
if (msg == NS_DRAGDROP_EXIT_SYNTH || mFlags.mCancelable =
msg == NS_DRAGDROP_LEAVE_SYNTH || (msg != NS_DRAGDROP_EXIT_SYNTH &&
msg == NS_DRAGDROP_END) { msg != NS_DRAGDROP_LEAVE_SYNTH &&
flags |= NS_EVENT_FLAG_CANT_CANCEL; msg != NS_DRAGDROP_END);
}
} }
nsCOMPtr<nsIDOMDataTransfer> dataTransfer; nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
@ -1209,7 +1218,7 @@ public:
// XXX compositionstart is cancelable in draft of DOM3 Events. // XXX compositionstart is cancelable in draft of DOM3 Events.
// However, it doesn't make sense for us, we cannot cancel composition // However, it doesn't make sense for us, we cannot cancel composition
// when we send compositionstart event. // when we send compositionstart event.
flags |= NS_EVENT_FLAG_CANT_CANCEL; mFlags.mCancelable = false;
} }
nsString data; nsString data;