Bug 1256589 part.5 Add DefaultPrevented() and DefaultPreventedByContent() to WidgetEvent r=smaug

MozReview-Commit-ID: 5q3QUPTf12Z

--HG--
extra : rebase_source : 83ed946b44910713a61c80bd21202aba9430dd2a
extra : source : 4eb2193814ab1958a65add0c8c307d07c646d61c
This commit is contained in:
Masayuki Nakano 2016-03-22 16:47:52 +09:00
parent 6181d95afb
commit 8c8cbe0e4c
14 changed files with 38 additions and 27 deletions

View File

@ -1050,14 +1050,14 @@ Event::DefaultPrevented(JSContext* aCx) const
NS_ENSURE_TRUE(mEvent, false);
// If preventDefault() has never been called, just return false.
if (!mEvent->mFlags.mDefaultPrevented) {
if (!mEvent->DefaultPrevented()) {
return false;
}
// If preventDefault() has been called by content, return true. Otherwise,
// i.e., preventDefault() has been called by chrome, return true only when
// this is called by chrome.
return mEvent->mFlags.mDefaultPreventedByContent || IsChrome(aCx);
return mEvent->DefaultPreventedByContent() || IsChrome(aCx);
}
double

View File

@ -187,7 +187,7 @@ public:
bool DefaultPrevented() const
{
return mEvent->mFlags.mDefaultPrevented;
return mEvent->DefaultPrevented();
}
bool MultipleActionsPrevented() const

View File

@ -1190,7 +1190,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
nsEventStatus* aEventStatus)
{
//Set the value of the internal PreventDefault flag properly based on aEventStatus
if (!aEvent->mFlags.mDefaultPrevented &&
if (!aEvent->DefaultPrevented() &&
*aEventStatus == nsEventStatus_eConsumeNoDefault) {
// Assume that if only aEventStatus claims that the event has already been
// consumed, the consumer is default event handler.
@ -1309,7 +1309,7 @@ EventListenerManager::HandleEventInternal(nsPresContext* aPresContext,
mNoListenerForEventAtom = aEvent->userType;
}
if (aEvent->mFlags.mDefaultPrevented) {
if (aEvent->DefaultPrevented()) {
*aEventStatus = nsEventStatus_eConsumeNoDefault;
}
}

View File

@ -2225,7 +2225,7 @@ EventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
nsWeakFrame targetFrame(aTargetFrame);
MOZ_ASSERT(*aStatus != nsEventStatus_eConsumeNoDefault &&
!aEvent->mFlags.mDefaultPrevented,
!aEvent->DefaultPrevented(),
"If you make legacy events dispatched for default prevented wheel "
"event, you need to initialize stateX and stateY");
EventState stateX, stateY;
@ -2311,8 +2311,8 @@ EventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
EventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
&event, nullptr, &status);
aState.mDefaultPrevented =
event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
event.DefaultPrevented() || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.DefaultPreventedByContent();
}
void
@ -2351,8 +2351,8 @@ EventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
EventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
&event, nullptr, &status);
aState.mDefaultPrevented =
event.mFlags.mDefaultPrevented || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.mFlags.mDefaultPreventedByContent;
event.DefaultPrevented() || status == nsEventStatus_eConsumeNoDefault;
aState.mDefaultPreventedByContent = event.DefaultPreventedByContent();
}
nsIFrame*

View File

@ -757,7 +757,7 @@ IMEContentObserver::OnMouseButtonEvent(nsPresContext* aPresContext,
return false;
}
if (!aMouseEvent->mFlags.mIsTrusted ||
aMouseEvent->mFlags.mDefaultPrevented ||
aMouseEvent->DefaultPrevented() ||
!aMouseEvent->widget) {
return false;
}

View File

@ -3699,7 +3699,7 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
// - it's the left mouse button.
// We do not prevent non-trusted click because authors can already use
// .click(). However, the pickers will follow the rules of popup-blocking.
if (aVisitor.mEvent->mFlags.mDefaultPrevented) {
if (aVisitor.mEvent->DefaultPrevented()) {
return NS_OK;
}
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
@ -3890,7 +3890,7 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
// the editor's handling of up/down keypress events. For that reason we
// just ignore aVisitor.mEventStatus here and go ahead and handle the
// event to increase/decrease the value of the number control.
if (!aVisitor.mEvent->mFlags.mDefaultPreventedByContent && IsMutable()) {
if (!aVisitor.mEvent->DefaultPreventedByContent() && IsMutable()) {
StepNumberControlForUserEvent(keyEvent->keyCode == NS_VK_UP ? 1 : -1);
aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault;
}

View File

@ -2139,7 +2139,7 @@ TabParent::RecvDispatchAfterKeyboardEvent(const WidgetKeyboardEvent& aEvent)
PresShell::BeforeAfterKeyboardEventEnabled() &&
localEvent.mMessage != eKeyPress) {
presShell->DispatchAfterKeyboardEvent(mFrameElement, localEvent,
aEvent.mFlags.mDefaultPrevented);
aEvent.DefaultPrevented());
}
return true;

View File

@ -339,8 +339,7 @@ APZEventState::ProcessWheelEvent(const WidgetWheelEvent& aEvent,
{
// If this event starts a swipe, indicate that it shouldn't result in a
// scroll by setting defaultPrevented to true.
bool defaultPrevented =
aEvent.mFlags.mDefaultPrevented || aEvent.TriggersSwipe();
bool defaultPrevented = aEvent.DefaultPrevented() || aEvent.TriggersSwipe();
mContentReceivedInputBlockCallback(aGuid, aInputBlockId, defaultPrevented);
}

View File

@ -1143,8 +1143,7 @@ nsDocumentViewer::PermitUnloadInternal(bool *aShouldPrompt,
// the event being dispatched.
if (!sIsBeforeUnloadDisabled && *aShouldPrompt && dialogsAreEnabled && mDocument &&
(!sBeforeUnloadRequiresInteraction || mDocument->UserHasInteracted()) &&
(event->WidgetEventPtr()->mFlags.mDefaultPrevented ||
!text.IsEmpty())) {
(event->WidgetEventPtr()->DefaultPrevented() || !text.IsEmpty())) {
// Ask the user if it's ok to unload the current page
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(docShell);

View File

@ -6971,7 +6971,7 @@ PresShell::DispatchBeforeKeyboardEventInternal(const nsTArray<nsCOMPtr<Element>
beforeEvent.AssignBeforeAfterKeyEventData(aEvent, false);
EventDispatcher::Dispatch(eventTarget, mPresContext, &beforeEvent);
if (beforeEvent.mFlags.mDefaultPrevented) {
if (beforeEvent.DefaultPrevented()) {
aDefaultPrevented = true;
return;
}
@ -7005,7 +7005,7 @@ PresShell::DispatchAfterKeyboardEventInternal(const nsTArray<nsCOMPtr<Element> >
afterEvent.AssignBeforeAfterKeyEventData(aEvent, false);
afterEvent.mEmbeddedCancelled.SetValue(embeddedCancelled);
EventDispatcher::Dispatch(eventTarget, mPresContext, &afterEvent);
embeddedCancelled = afterEvent.mFlags.mDefaultPrevented;
embeddedCancelled = afterEvent.DefaultPrevented();
}
}
@ -7090,7 +7090,7 @@ PresShell::HandleKeyboardEvent(nsINode* aTarget,
EventDispatcher::Dispatch(aTarget, mPresContext,
&aEvent, nullptr, aStatus, aEventCB);
if (aEvent.mFlags.mDefaultPrevented) {
if (aEvent.DefaultPrevented()) {
// When embedder prevents the default action of actual key event, attribute
// 'embeddedCancelled' of after event is false, i.e. |!targetIsIframe|.
// On the contrary, if the defult action is prevented by embedded iframe,
@ -7105,8 +7105,7 @@ PresShell::HandleKeyboardEvent(nsINode* aTarget,
}
// Dispatch after events to all items in the chain.
DispatchAfterKeyboardEventInternal(chain, aEvent,
aEvent.mFlags.mDefaultPrevented);
DispatchAfterKeyboardEventInternal(chain, aEvent, aEvent.DefaultPrevented());
}
nsresult

View File

@ -2251,7 +2251,7 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent)
// XXX Not I18N compliant
// Don't do incremental search if the key event has already consumed.
if (keyEvent->mFlags.mDefaultPrevented) {
if (keyEvent->DefaultPrevented()) {
return NS_OK;
}

View File

@ -1712,7 +1712,7 @@ void
nsPluginFrame::HandleWheelEventAsDefaultAction(WidgetWheelEvent* aWheelEvent)
{
MOZ_ASSERT(WantsToHandleWheelEventAsDefaultAction());
MOZ_ASSERT(!aWheelEvent->mFlags.mDefaultPrevented);
MOZ_ASSERT(!aWheelEvent->DefaultPrevented());
if (NS_WARN_IF(!mInstanceOwner) ||
NS_WARN_IF(aWheelEvent->mMessage != eWheel)) {

View File

@ -164,6 +164,15 @@ public:
{
mDefaultPrevented = true;
}
inline bool DefaultPrevented() const
{
return mDefaultPrevented;
}
inline bool DefaultPreventedByContent() const
{
MOZ_ASSERT(!mDefaultPreventedByContent || DefaultPrevented());
return mDefaultPreventedByContent;
}
inline void Clear()
{
@ -354,6 +363,11 @@ public:
mFlags.PreventDefault(aCalledByDefaultHandler);
}
void PreventDefaultBeforeDispatch() { mFlags.PreventDefaultBeforeDispatch(); }
bool DefaultPrevented() const { return mFlags.DefaultPrevented(); }
bool DefaultPreventedByContent() const
{
return mFlags.DefaultPreventedByContent();
}
/**
* Utils for checking event types

View File

@ -1207,8 +1207,8 @@ NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
KeyboardLayout::NotifyIdleServiceOfUserActivity();
return aKeyEvent.mFlags.mDefaultPrevented ? nsEventStatus_eConsumeNoDefault :
nsEventStatus_eIgnore;
return aKeyEvent.DefaultPrevented() ? nsEventStatus_eConsumeNoDefault :
nsEventStatus_eIgnore;
}
bool