From 2cbd76aba8e33d79b7ede171b798aee691b7c419 Mon Sep 17 00:00:00 2001 From: roytam1 Date: Thu, 21 Apr 2022 09:50:10 +0800 Subject: [PATCH] import changes from `dev' branch of rmottola/Arctic-Fox: - Bug 895274 part.25 Rename NS_MOUSE_MOVE to eMouseMove r=smaug (fd637481f2) - Bug 895274 part.26 Rename NS_MOUSE_BUTTON_UP to eMouseUp r=smaug (01314a434b) - Bug 895274 part.27 Rename NS_MOUSE_BUTTON_DOWN to eMouseDown r=smaug (b4839f190c) - Bug 895274 part.28 Rename NS_MOUSE_ENTER_WIDGET to eMouseEnterIntoWidget r=smaug (148807ec51) - Bug 895274 part.29 Rename NS_MOUSE_EXIT_WIDGET to eMouseExitFromWidget r=smaug (249a5db8de) - Bug 1157195, null check for widget before generating drag events, r=masayuki (ca08721f76) - Bug 1156964, consume tab key also in e10s, r=felipe (4f169cb329) - Bug 1158633, if EventStateManager::mGestureDownContent is non-null, so should mGestureDownFrameOwner be, r=enndeakin (8975a44344) - Bug 895274 part.30 Rename NS_MOUSE_DOUBLECLICK to eMouseDoubleClick r=smaug (fe39991215) - style (5b3468be0c) - Bug 895274 part.31 Rename NS_MOUSE_CLICK to eMouseClick r=smaug (c442dc8a76) - Bug 895274 part.32 Rename NS_MOUSE_ACTIVATE to eMouseActivate r=smaug (46e3e0712a) - Bug 895274 part.33 Rename NS_MOUSE_OVER to eMouseOver r=smaug (fd9f4ad861) - Bug 895274 part.33 Rename NS_MOUSE_OVER to eMouseOver r=smaug (2631639696) - missing parts of Bug 1173725 - part 1: force top border to be visible on windows 10 (2533fe48c3) - Bug 1184942 - Use DPI scaling factor to ensure top window border is correct thickness. r=jimm (e0ffd4538a) - Bug 1163113 - Implement -moz-window-dragging on Windows for Graphene r=jimm (d4c02f04dd) - Bug 895274 part.35 Rename NS_MOUSE_MOZHITTEST to eMouseHitTest r=smaug (aea1520561) - reinstatiate full WebRTC configure options (7519d9431a) - Bug 1106958 - Use android.media.MediaCodec for decoding in WebRTC stack. r=snorp, r=gcp, r=ted (0a9f2ca886) - ... and add back missing file critical_section_win.cc in webrtc --- accessible/base/nsCoreUtils.cpp | 4 +- accessible/generic/Accessible.cpp | 8 +- build/gyp.mozbuild | 2 + configure.in | 64 +- dom/base/Element.cpp | 20 +- dom/base/FragmentOrElement.cpp | 6 +- dom/base/nsContentUtils.cpp | 12 +- dom/base/nsGlobalWindow.cpp | 8 +- dom/events/Event.cpp | 12 +- dom/events/EventNameList.h | 16 +- dom/events/EventStateManager.cpp | 116 +- dom/events/EventStateManager.h | 4 +- dom/events/IMEContentObserver.cpp | 4 +- dom/events/WheelHandlingHelper.cpp | 10 +- dom/html/HTMLButtonElement.cpp | 10 +- dom/html/HTMLInputElement.cpp | 36 +- dom/html/HTMLLabelElement.cpp | 10 +- dom/html/HTMLMenuItemElement.cpp | 4 +- dom/html/HTMLTextAreaElement.cpp | 2 +- dom/html/nsGenericHTMLElement.cpp | 10 +- dom/ipc/TabChild.cpp | 6 +- dom/ipc/TabParent.cpp | 6 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 92 +- dom/xul/nsXULElement.cpp | 131 +-- editor/libeditor/nsEditorEventListener.cpp | 12 +- gfx/layers/apz/src/APZCTreeManager.cpp | 10 +- gfx/layers/apz/util/APZCCallbackHelper.cpp | 12 +- layout/base/AccessibleCaretEventHub.cpp | 18 +- layout/base/SelectionCarets.cpp | 6 +- layout/base/TouchCaret.cpp | 6 +- .../gtest/TestAccessibleCaretEventHub.cpp | 6 +- layout/base/nsPresShell.cpp | 49 +- layout/forms/nsComboboxControlFrame.cpp | 2 +- layout/forms/nsImageControlFrame.cpp | 2 +- layout/forms/nsListControlFrame.cpp | 6 +- layout/generic/nsFrame.cpp | 10 +- layout/generic/nsFrameSetFrame.cpp | 6 +- layout/generic/nsImageFrame.cpp | 6 +- layout/generic/nsPluginFrame.cpp | 6 +- layout/xul/nsButtonBoxFrame.cpp | 2 +- layout/xul/nsMenuFrame.cpp | 10 +- layout/xul/nsResizerFrame.cpp | 10 +- layout/xul/nsRootBoxFrame.cpp | 2 +- layout/xul/nsScrollBoxFrame.cpp | 10 +- layout/xul/nsScrollbarButtonFrame.cpp | 8 +- layout/xul/nsSliderFrame.cpp | 18 +- layout/xul/nsSplitterFrame.cpp | 4 +- layout/xul/nsTitleBarFrame.cpp | 8 +- layout/xul/tree/nsTreeBodyFrame.cpp | 4 +- media/webrtc/moz.build | 3 + media/webrtc/signaling/signaling.gyp | 14 + .../media-conduit/MediaCodecVideoCodec.cpp | 31 + .../src/media-conduit/MediaCodecVideoCodec.h | 31 + .../WebrtcMediaCodecVP8VideoCodec.cpp | 1004 +++++++++++++++++ .../WebrtcMediaCodecVP8VideoCodec.h | 114 ++ .../peerconnection/MediaPipelineFactory.cpp | 68 +- .../source/critical_section_win.cc | 30 + view/nsViewManager.cpp | 4 +- widget/EventMessageList.h | 23 +- widget/InputData.cpp | 16 +- widget/MouseEvents.h | 2 +- widget/WidgetEventImpl.cpp | 22 +- widget/cocoa/nsChildView.mm | 24 +- widget/gtk/nsWindow.cpp | 17 +- widget/nsBaseWidget.cpp | 20 +- widget/qt/nsWindow.cpp | 11 +- widget/uikit/nsWindow.mm | 6 +- widget/windows/IMMHandler.cpp | 3 +- widget/windows/TSFTextStore.cpp | 10 +- widget/windows/WinUtils.cpp | 8 +- widget/windows/nsWindow.cpp | 164 +-- widget/windows/nsWindow.h | 4 + 72 files changed, 1895 insertions(+), 560 deletions(-) create mode 100644 media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.cpp create mode 100644 media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.h create mode 100644 media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp create mode 100644 media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h create mode 100644 media/webrtc/trunk/webrtc/system_wrappers/source/critical_section_win.cc diff --git a/accessible/base/nsCoreUtils.cpp b/accessible/base/nsCoreUtils.cpp index 251964eecc..017dd017ff 100644 --- a/accessible/base/nsCoreUtils.cpp +++ b/accessible/base/nsCoreUtils.cpp @@ -110,10 +110,10 @@ nsCoreUtils::DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj, presContext->AppUnitsToDevPixels(offset.y); // XUL is just desktop, so there is no real reason for senfing touch events. - DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, cnvdX, cnvdY, + DispatchMouseEvent(eMouseDown, cnvdX, cnvdY, tcContent, tcFrame, presShell, rootWidget); - DispatchMouseEvent(NS_MOUSE_BUTTON_UP, cnvdX, cnvdY, + DispatchMouseEvent(eMouseUp, cnvdX, cnvdY, tcContent, tcFrame, presShell, rootWidget); } diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index c36daa06f5..1e20b6aa8b 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -537,7 +537,7 @@ Accessible::ChildAtPoint(int32_t aX, int32_t aY, nsIntRect rootRect; rootWidget->GetScreenBounds(rootRect); - WidgetMouseEvent dummyEvent(true, NS_MOUSE_MOVE, rootWidget, + WidgetMouseEvent dummyEvent(true, eMouseMove, rootWidget, WidgetMouseEvent::eSynthesized); dummyEvent.refPoint = LayoutDeviceIntPoint(aX - rootRect.x, aY - rootRect.y); @@ -1832,9 +1832,11 @@ Accessible::DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex) // Simulate a touch interaction by dispatching touch events with mouse events. nsCoreUtils::DispatchTouchEvent(NS_TOUCH_START, x, y, aContent, frame, presShell, widget); - nsCoreUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, x, y, aContent, frame, presShell, widget); + nsCoreUtils::DispatchMouseEvent(eMouseDown, x, y, aContent, frame, + presShell, widget); nsCoreUtils::DispatchTouchEvent(NS_TOUCH_END, x, y, aContent, frame, presShell, widget); - nsCoreUtils::DispatchMouseEvent(NS_MOUSE_BUTTON_UP, x, y, aContent, frame, presShell, widget); + nsCoreUtils::DispatchMouseEvent(eMouseUp, x, y, aContent, frame, + presShell, widget); } void diff --git a/build/gyp.mozbuild b/build/gyp.mozbuild index 1577b5d580..be53d0defc 100644 --- a/build/gyp.mozbuild +++ b/build/gyp.mozbuild @@ -44,6 +44,7 @@ gyp_vars = { 'moz_widget_toolkit_gonk': 0, 'moz_webrtc_omx': 0, + 'moz_webrtc_mediacodec': 0, # (for vp8) chromium sets to 0 also 'use_temporal_layers': 0, @@ -80,6 +81,7 @@ elif os == 'Android': else: gyp_vars.update( gtest_target_type='executable', + moz_webrtc_mediacodec=1, android_toolchain=CONFIG['ANDROID_TOOLCHAIN'], ) diff --git a/configure.in b/configure.in index 2f4a1af5ac..d7e58b150a 100644 --- a/configure.in +++ b/configure.in @@ -3737,7 +3737,10 @@ else MOZ_FMP4= fi MOZ_FFMPEG= -MOZ_WEBRTC= +MOZ_WEBRTC=1 +MOZ_WEBRTC_SIGNALING= +MOZ_WEBRTC_ASSERT_ALWAYS=1 +MOZ_WEBRTC_HARDWARE_AEC_NS= MOZ_ANDROID_OMX= MOZ_MEDIA_NAVIGATOR= MOZ_OMX_PLUGIN= @@ -4898,13 +4901,46 @@ if test "${MOZ_WIDGET_TOOLKIT}" = "linuxgl" -a "$ACCESSIBILITY" != "1"; then AC_MSG_ERROR(["Accessibility is required for the linuxgl widget backend"]) fi +dnl Turn off webrtc for OS's we don't handle yet, but allow +dnl --enable-webrtc to override. Can disable for everything in +dnl the master list above. +if test -n "$MOZ_WEBRTC"; then + case "$target" in + *-linux*|*-mingw*|*-darwin*|*-android*|*-linuxandroid*|*-dragonfly*|*-freebsd*|*-netbsd*|*-openbsd*) + dnl Leave enabled + ;; + *) + dnl default to disabled for all others + MOZ_WEBRTC= + ;; + esac +fi + +AC_TRY_COMPILE([#include ], + [ struct ethtool_cmd cmd; cmd.speed_hi = 0; ], + MOZ_WEBRTC_HAVE_ETHTOOL_SPEED_HI=1) + +AC_SUBST(MOZ_WEBRTC_HAVE_ETHTOOL_SPEED_HI) + +# target_arch is from {ia32|x64|arm|ppc} +case "$CPU_ARCH" in +x86_64 | arm | x86 | ppc* | ia64) + : + ;; +*) +# unsupported arch for webrtc + MOZ_WEBRTC= + ;; + +esac + dnl ======================================================== -dnl = Enable WebRTC code +dnl = Disable WebRTC code dnl ======================================================== -MOZ_ARG_ENABLE_BOOL(webrtc, -[ --enable-webrtc Enable support for WebRTC], - MOZ_WEBRTC=1, - MOZ_WEBRTC=) +MOZ_ARG_DISABLE_BOOL(webrtc, +[ --disable-webrtc Disable support for WebRTC], + MOZ_WEBRTC=, + MOZ_WEBRTC=1) if test -n "$MOZ_WEBRTC"; then AC_DEFINE(MOZ_WEBRTC) @@ -4932,16 +4968,28 @@ else MOZ_SYNTH_PICO= fi +dnl ======================================================== +dnl = Force hardware AEC, disable webrtc.org AEC +dnl ======================================================== +MOZ_ARG_ENABLE_BOOL(hardware-aec-ns, +[ --enable-hardware-aec-ns Enable support for hardware AEC and noise suppression], + MOZ_WEBRTC_HARDWARE_AEC_NS=1, + MOZ_WEBRTC_HARDWARE_AEC_NS=) + +if test -n "$MOZ_WEBRTC_HARDWARE_AEC_NS"; then + AC_DEFINE(MOZ_WEBRTC_HARDWARE_AEC_NS) +fi + AC_SUBST(MOZ_WEBRTC) +AC_SUBST(MOZ_WEBRTC_LEAKING_TESTS) AC_SUBST(MOZ_WEBRTC_SIGNALING) AC_SUBST(MOZ_PEERCONNECTION) AC_SUBST(MOZ_WEBRTC_ASSERT_ALWAYS) +AC_SUBST(MOZ_WEBRTC_HARDWARE_AEC_NS) AC_SUBST(MOZ_SCTP) AC_SUBST(MOZ_SRTP) AC_SUBST_LIST(MOZ_WEBRTC_X11_LIBS) -dnl ======================================================== - dnl Use integers over floats for audio on B2G and Android dnl (regarless of the CPU architecture, because audio dnl backends for those platforms don't support floats. We also diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index a39eed406c..471c41ef6c 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2089,7 +2089,7 @@ Element::DispatchClickEvent(nsPresContext* aPresContext, NS_PRECONDITION(aSourceEvent, "Must have source event"); NS_PRECONDITION(aStatus, "Null out param?"); - WidgetMouseEvent event(aSourceEvent->mFlags.mIsTrusted, NS_MOUSE_CLICK, + WidgetMouseEvent event(aSourceEvent->mFlags.mIsTrusted, eMouseClick, aSourceEvent->widget, WidgetMouseEvent::eReal); event.refPoint = aSourceEvent->refPoint; uint32_t clickCount = 1; @@ -2903,7 +2903,7 @@ Element::CheckHandleEventForLinksPrecondition(EventChainVisitor& aVisitor, { if (aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault || (!aVisitor.mEvent->mFlags.mIsTrusted && - (aVisitor.mEvent->mMessage != NS_MOUSE_CLICK) && + (aVisitor.mEvent->mMessage != eMouseClick) && (aVisitor.mEvent->mMessage != eKeyPress) && (aVisitor.mEvent->mMessage != NS_UI_ACTIVATE)) || !aVisitor.mPresContext || @@ -2921,9 +2921,9 @@ Element::PreHandleEventForLinks(EventChainPreVisitor& aVisitor) // Optimisation: return early if this event doesn't interest us. // IMPORTANT: this switch and the switch below it must be kept in sync! switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_OVER: + case eMouseOver: case NS_FOCUS_CONTENT: - case NS_MOUSE_OUT: + case eMouseOut: case NS_BLUR_CONTENT: break; default: @@ -2942,7 +2942,7 @@ Element::PreHandleEventForLinks(EventChainPreVisitor& aVisitor) // updated even if the event is consumed before we have a chance to set it. switch (aVisitor.mEvent->mMessage) { // Set the status bar similarly for mouseover and focus - case NS_MOUSE_OVER: + case eMouseOver: aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; // FALL THROUGH case NS_FOCUS_CONTENT: { @@ -2957,7 +2957,7 @@ Element::PreHandleEventForLinks(EventChainPreVisitor& aVisitor) } break; } - case NS_MOUSE_OUT: + case eMouseOut: aVisitor.mEventStatus = nsEventStatus_eConsumeNoDefault; // FALL THROUGH case NS_BLUR_CONTENT: @@ -2982,8 +2982,8 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) // Optimisation: return early if this event doesn't interest us. // IMPORTANT: this switch and the switch below it must be kept in sync! switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_CLICK: + case eMouseDown: + case eMouseClick: case NS_UI_ACTIVATE: case eKeyPress: break; @@ -3000,7 +3000,7 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) nsresult rv = NS_OK; switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: { if (aVisitor.mEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { @@ -3023,7 +3023,7 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor) } break; - case NS_MOUSE_CLICK: { + case eMouseClick: { WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (mouseEvent->IsLeftClickEvent()) { if (mouseEvent->IsControl() || mouseEvent->IsMeta() || diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 7d59b48c9c..3179e1bf52 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -677,8 +677,8 @@ nsIContent::PreHandleEvent(EventChainPreVisitor& aVisitor) // Don't propagate mouseover and mouseout events when mouse is moving // inside chrome access only content. bool isAnonForEvents = IsRootOfChromeAccessOnlySubtree(); - if ((aVisitor.mEvent->mMessage == NS_MOUSE_OVER || - aVisitor.mEvent->mMessage == NS_MOUSE_OUT || + if ((aVisitor.mEvent->mMessage == eMouseOver || + aVisitor.mEvent->mMessage == eMouseOut || aVisitor.mEvent->mMessage == NS_POINTER_OVER || aVisitor.mEvent->mMessage == NS_POINTER_OUT) && // Check if we should stop event propagation when event has just been @@ -739,7 +739,7 @@ nsIContent::PreHandleEvent(EventChainPreVisitor& aVisitor) printf("Stopping %s propagation:" "\n\toriginalTarget=%s \n\tcurrentTarget=%s %s" "\n\trelatedTarget=%s %s \n%s", - (aVisitor.mEvent->mMessage == NS_MOUSE_OVER) + (aVisitor.mEvent->mMessage == eMouseOver) ? "mouseover" : "mouseout", NS_ConvertUTF16toUTF8(ot).get(), NS_ConvertUTF16toUTF8(ct).get(), diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 59f2a7b58d..ce0891c72e 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7839,20 +7839,20 @@ nsContentUtils::SendMouseEvent(nsCOMPtr aPresShell, EventMessage msg; bool contextMenuKey = false; if (aType.EqualsLiteral("mousedown")) - msg = NS_MOUSE_BUTTON_DOWN; + msg = eMouseDown; else if (aType.EqualsLiteral("mouseup")) - msg = NS_MOUSE_BUTTON_UP; + msg = eMouseUp; else if (aType.EqualsLiteral("mousemove")) - msg = NS_MOUSE_MOVE; + msg = eMouseMove; else if (aType.EqualsLiteral("mouseover")) - msg = NS_MOUSE_ENTER_WIDGET; + msg = eMouseEnterIntoWidget; else if (aType.EqualsLiteral("mouseout")) - msg = NS_MOUSE_EXIT_WIDGET; + msg = eMouseExitFromWidget; else if (aType.EqualsLiteral("contextmenu")) { msg = NS_CONTEXTMENU; contextMenuKey = (aButton == 0); } else if (aType.EqualsLiteral("MozMouseHittest")) - msg = NS_MOUSE_MOZHITTEST; + msg = eMouseHitTest; else return NS_ERROR_FAILURE; diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index d46b0b74c4..90f6fee629 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -3056,7 +3056,7 @@ nsGlobalWindow::PreHandleEvent(EventChainPreVisitor& aVisitor) aVisitor.mCanHandle = true; aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119 - if ((msg == NS_MOUSE_MOVE) && gEntropyCollector) { + if (msg == eMouseMove && gEntropyCollector) { //Chances are this counter will overflow during the life of the //process, but that's OK for our case. Means we get a little //more entropy. @@ -3079,11 +3079,9 @@ nsGlobalWindow::PreHandleEvent(EventChainPreVisitor& aVisitor) if (window) { mIsHandlingResizeEvent = true; } - } else if (msg == NS_MOUSE_BUTTON_DOWN && - aVisitor.mEvent->mFlags.mIsTrusted) { + } else if (msg == eMouseDown && aVisitor.mEvent->mFlags.mIsTrusted) { gMouseDown = true; - } else if ((msg == NS_MOUSE_BUTTON_UP || - msg == NS_DRAGDROP_END) && + } else if ((msg == eMouseUp || msg == NS_DRAGDROP_END) && aVisitor.mEvent->mFlags.mIsTrusted) { gMouseDown = false; if (gDragServiceDisabled) { diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 2968492c40..ae7713b204 100644 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -771,7 +771,7 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) uint32_t key = aEvent->AsKeyboardEvent()->keyCode; switch(aEvent->mMessage) { case eKeyPress: - // return key on focused button. see note at NS_MOUSE_CLICK. + // return key on focused button. see note at eMouseClick. if (key == nsIDOMKeyEvent::DOM_VK_RETURN) { abuse = openAllowed; } else if (PopupAllowedForEvent("keypress")) { @@ -779,7 +779,7 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) } break; case eKeyUp: - // space key on focused button. see note at NS_MOUSE_CLICK. + // space key on focused button. see note at eMouseClick. if (key == nsIDOMKeyEvent::DOM_VK_SPACE) { abuse = openAllowed; } else if (PopupAllowedForEvent("keyup")) { @@ -818,17 +818,17 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) if (aEvent->mFlags.mIsTrusted && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { switch(aEvent->mMessage) { - case NS_MOUSE_BUTTON_UP : + case eMouseUp: if (PopupAllowedForEvent("mouseup")) { abuse = openControlled; } break; - case NS_MOUSE_BUTTON_DOWN : + case eMouseDown: if (PopupAllowedForEvent("mousedown")) { abuse = openControlled; } break; - case NS_MOUSE_CLICK : + case eMouseClick: /* Click events get special treatment because of their historical status as a more legitimate event handler. If click popups are enabled in the prefs, clear the popup @@ -837,7 +837,7 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) abuse = openAllowed; } break; - case NS_MOUSE_DOUBLECLICK : + case eMouseDoubleClick: if (PopupAllowedForEvent("dblclick")) { abuse = openControlled; } diff --git a/dom/events/EventNameList.h b/dom/events/EventNameList.h index f843d36d4a..0e65b0c3f7 100644 --- a/dom/events/EventNameList.h +++ b/dom/events/EventNameList.h @@ -165,7 +165,7 @@ EVENT(change, EventNameType_HTMLXUL, eBasicEventClass) EVENT(click, - NS_MOUSE_CLICK, + eMouseClick, EventNameType_All, eMouseEventClass) EVENT(contextmenu, @@ -175,7 +175,7 @@ EVENT(contextmenu, // Not supported yet // EVENT(cuechange) EVENT(dblclick, - NS_MOUSE_DOUBLECLICK, + eMouseDoubleClick, EventNameType_HTMLXUL, eMouseEventClass) EVENT(drag, @@ -267,7 +267,7 @@ EVENT(loadstart, EventNameType_HTML, eBasicEventClass) EVENT(mousedown, - NS_MOUSE_BUTTON_DOWN, + eMouseDown, EventNameType_All, eMouseEventClass) EVENT(mouseenter, @@ -279,19 +279,19 @@ EVENT(mouseleave, EventNameType_All, eMouseEventClass) EVENT(mousemove, - NS_MOUSE_MOVE, + eMouseMove, EventNameType_All, eMouseEventClass) EVENT(mouseout, - NS_MOUSE_OUT, + eMouseOut, EventNameType_All, eMouseEventClass) EVENT(mouseover, - NS_MOUSE_OVER, + eMouseOver, EventNameType_All, eMouseEventClass) EVENT(mouseup, - NS_MOUSE_BUTTON_UP, + eMouseUp, EventNameType_All, eMouseEventClass) EVENT(mozfullscreenchange, @@ -602,7 +602,7 @@ DOCUMENT_ONLY_EVENT(visibilitychange, eBasicEventClass) NON_IDL_EVENT(MozMouseHittest, - NS_MOUSE_MOZHITTEST, + eMouseHitTest, EventNameType_None, eMouseEventClass) diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 85c0c33238..ade602db5e 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -494,13 +494,13 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, mCurrentTarget = aTargetFrame; mCurrentTargetContent = nullptr; - // Do not take account NS_MOUSE_ENTER_WIDGET/EXIT_WIDGET so that loading a page - // when user is not active doesn't change the state to active. + // Do not take account eMouseEnterIntoWidget/ExitFromWidget so that loading + // a page when user is not active doesn't change the state to active. WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (aEvent->mFlags.mIsTrusted && ((mouseEvent && mouseEvent->IsReal() && - mouseEvent->mMessage != NS_MOUSE_ENTER_WIDGET && - mouseEvent->mMessage != NS_MOUSE_EXIT_WIDGET) || + mouseEvent->mMessage != eMouseEnterIntoWidget && + mouseEvent->mMessage != eMouseExitFromWidget) || aEvent->mClass == eWheelEventClass || aEvent->mClass == ePointerEventClass || aEvent->mClass == eTouchEventClass || @@ -518,7 +518,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, nsCOMPtr node = do_QueryInterface(aTargetContent); if (node && - (aEvent->mMessage == eKeyUp || aEvent->mMessage == NS_MOUSE_BUTTON_UP || + (aEvent->mMessage == eKeyUp || aEvent->mMessage == eMouseUp || aEvent->mMessage == NS_WHEEL_WHEEL || aEvent->mMessage == NS_TOUCH_END || aEvent->mMessage == NS_POINTER_UP)) { nsIDocument* doc = node->OwnerDoc(); @@ -564,7 +564,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, return NS_ERROR_DOM_INVALID_STATE_ERR; } break; - case NS_MOUSE_BUTTON_DOWN: { + case eMouseDown: { switch (mouseEvent->button) { case WidgetMouseEvent::eLeftButton: BeginTrackingDragGesture(aPresContext, mouseEvent, aTargetFrame); @@ -583,7 +583,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, } break; } - case NS_MOUSE_BUTTON_UP: { + case eMouseUp: { switch (mouseEvent->button) { case WidgetMouseEvent::eLeftButton: if (Prefs::ClickHoldContextMenu()) { @@ -599,8 +599,8 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, } break; } - case NS_MOUSE_ENTER_WIDGET: - // In some cases on e10s NS_MOUSE_ENTER_WIDGET + case eMouseEnterIntoWidget: + // In some cases on e10s eMouseEnterIntoWidget // event was sent twice into child process of content. // (From specific widget code (sending is not permanent) and // from ESM::DispatchMouseOrPointerEvent (sending is permanent)). @@ -608,20 +608,21 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, // suppress sending accidental event from widget code. aEvent->mFlags.mNoCrossProcessBoundaryForwarding = true; break; - case NS_MOUSE_EXIT_WIDGET: - // If this is a remote frame, we receive NS_MOUSE_EXIT_WIDGET from the parent - // the mouse exits our content. Since the parent may update the cursor - // while the mouse is outside our frame, and since PuppetWidget caches the - // current cursor internally, re-entering our content (say from over a - // window edge) wont update the cursor if the cached value and the current - // cursor match. So when the mouse exits a remote frame, clear the cached - // widget cursor so a proper update will occur when the mouse re-enters. + case eMouseExitFromWidget: + // If this is a remote frame, we receive eMouseExitFromWidget from the + // parent the mouse exits our content. Since the parent may update the + // cursor while the mouse is outside our frame, and since PuppetWidget + // caches the current cursor internally, re-entering our content (say from + // over a window edge) wont update the cursor if the cached value and the + // current cursor match. So when the mouse exits a remote frame, clear the + // cached widget cursor so a proper update will occur when the mouse + // re-enters. if (XRE_IsContentProcess()) { ClearCachedWidgetCursor(mCurrentTarget); } // Flag helps to suppress double event sending into process of content. - // For more information see comment above, at NS_MOUSE_ENTER_WIDGET case. + // For more information see comment above, at eMouseEnterIntoWidget case. aEvent->mFlags.mNoCrossProcessBoundaryForwarding = true; // If the event is not a top-level window exit, then it's not @@ -631,7 +632,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, // Treat it as a synthetic move so we don't generate spurious // "exit" or "move" events. Any necessary "out" or "over" events // will be generated by GenerateMouseEnterExit - mouseEvent->mMessage = NS_MOUSE_MOVE; + mouseEvent->mMessage = eMouseMove; mouseEvent->reason = WidgetMouseEvent::eSynthesized; // then fall through... } else { @@ -644,7 +645,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext, aEvent->mMessage = eVoidEvent; break; } - case NS_MOUSE_MOVE: + case eMouseMove: case NS_POINTER_DOWN: case NS_POINTER_MOVE: { // on the Mac, GenerateDragGesture() may not return until the drag @@ -1186,12 +1187,12 @@ CrossProcessSafeEvent(const WidgetEvent& aEvent) return true; case eMouseEventClass: switch (aEvent.mMessage) { - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_MOVE: + case eMouseDown: + case eMouseUp: + case eMouseMove: case NS_CONTEXTMENU: - case NS_MOUSE_ENTER_WIDGET: - case NS_MOUSE_EXIT_WIDGET: + case eMouseEnterIntoWidget: + case eMouseExitFromWidget: return true; default: return false; @@ -1538,6 +1539,9 @@ EventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext, getter_AddRefs(mGestureDownContent)); mGestureDownFrameOwner = inDownFrame->GetContent(); + if (!mGestureDownFrameOwner) { + mGestureDownFrameOwner = mGestureDownContent; + } } mGestureModifiers = inDownEvent->modifiers; mGestureDownButtons = inDownEvent->buttons; @@ -1596,7 +1600,7 @@ EventStateManager::GenerateDragGesture(nsPresContext* aPresContext, if (IsTrackingDragGesture()) { mCurrentTarget = mGestureDownFrameOwner->GetPrimaryFrame(); - if (!mCurrentTarget) { + if (!mCurrentTarget || !mCurrentTarget->GetNearestWidget()) { StopTrackingDragGesture(); return; } @@ -2745,6 +2749,8 @@ EventStateManager::PostHandleKeyboardEvent(WidgetKeyboardEvent* aKeyboardEvent, case NS_VK_F6: // This is to prevent keyboard scrolling while alt modifier in use. if (!aKeyboardEvent->IsAlt()) { + aStatus = nsEventStatus_eConsumeNoDefault; + // Handling the tab event after it was sent to content is bad, // because to the FocusManager the remote-browser looks like one // element, so we would just move the focus to the next element @@ -2768,7 +2774,6 @@ EventStateManager::PostHandleKeyboardEvent(WidgetKeyboardEvent* aKeyboardEvent, nsIFocusManager::FLAG_BYKEY, getter_AddRefs(result)); } - aStatus = nsEventStatus_eConsumeNoDefault; } return; case 0: @@ -2807,8 +2812,8 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, // Most of the events we handle below require a frame. // Add special cases here. - if (!mCurrentTarget && aEvent->mMessage != NS_MOUSE_BUTTON_UP && - aEvent->mMessage != NS_MOUSE_BUTTON_DOWN) { + if (!mCurrentTarget && aEvent->mMessage != eMouseUp && + aEvent->mMessage != eMouseDown) { return NS_OK; } @@ -2817,7 +2822,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, nsresult ret = NS_OK; switch (aEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->button == WidgetMouseEvent::eLeftButton && @@ -3029,7 +3034,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, } break; } - case NS_MOUSE_BUTTON_UP: + case eMouseUp: { ClearGlobalActiveContent(this); WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); @@ -3348,7 +3353,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_ENTER_WIDGET: + case eMouseEnterIntoWidget: if (mCurrentTarget) { nsCOMPtr targetContent; mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent)); @@ -3357,7 +3362,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext, break; #ifdef XP_MACOSX - case NS_MOUSE_ACTIVATE: + case eMouseActivate: if (mCurrentTarget) { nsCOMPtr targetContent; mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent)); @@ -3773,8 +3778,8 @@ EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent, if (sIsPointerLocked && (aMessage == NS_MOUSELEAVE || aMessage == NS_MOUSEENTER || - aMessage == NS_MOUSE_OVER || - aMessage == NS_MOUSE_OUT)) { + aMessage == eMouseOver || + aMessage == eMouseOut)) { mCurrentTargetContent = nullptr; nsCOMPtr pointerLockedElement = do_QueryReferent(EventStateManager::sPointerLockedElement); @@ -3822,10 +3827,10 @@ EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent, // If we are entering/leaving remote content, dispatch a mouse enter/exit // event to the remote frame. if (IsRemoteTarget(aTargetContent)) { - if (aMessage == NS_MOUSE_OUT) { + if (aMessage == eMouseOut) { // For remote content, send a "top-level" widget mouse exit event. nsAutoPtr remoteEvent; - CreateMouseOrPointerWidgetEvent(aMouseEvent, NS_MOUSE_EXIT_WIDGET, + CreateMouseOrPointerWidgetEvent(aMouseEvent, eMouseExitFromWidget, aRelatedContent, remoteEvent); remoteEvent->exit = WidgetMouseEvent::eTopLevel; @@ -3835,9 +3840,9 @@ EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent, // proper target via GetEventTarget which will return mCurrentTarget. mCurrentTarget = targetFrame; HandleCrossProcessEvent(remoteEvent, &status); - } else if (aMessage == NS_MOUSE_OVER) { + } else if (aMessage == eMouseOver) { nsAutoPtr remoteEvent; - CreateMouseOrPointerWidgetEvent(aMouseEvent, NS_MOUSE_ENTER_WIDGET, + CreateMouseOrPointerWidgetEvent(aMouseEvent, eMouseEnterIntoWidget, aRelatedContent, remoteEvent); HandleCrossProcessEvent(remoteEvent, &status); } @@ -3963,7 +3968,7 @@ EventStateManager::NotifyMouseOut(WidgetMouseEvent* aMouseEvent, NS_MOUSELEAVE); // Fire mouseout - DispatchMouseOrPointerEvent(aMouseEvent, isPointer ? NS_POINTER_OUT : NS_MOUSE_OUT, + DispatchMouseOrPointerEvent(aMouseEvent, isPointer ? NS_POINTER_OUT : eMouseOut, wrapper->mLastOverElement, aMovingInto); wrapper->mLastOverFrame = nullptr; @@ -4037,7 +4042,7 @@ EventStateManager::NotifyMouseOver(WidgetMouseEvent* aMouseEvent, // Fire mouseover wrapper->mLastOverFrame = DispatchMouseOrPointerEvent(aMouseEvent, - isPointer ? NS_POINTER_OVER : NS_MOUSE_OVER, + isPointer ? NS_POINTER_OVER : eMouseOver, aContent, lastOverElement); wrapper->mLastOverElement = aContent; } else { @@ -4112,7 +4117,7 @@ EventStateManager::GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent) nsCOMPtr targetBeforeEvent = mCurrentTargetContent; switch(aMouseEvent->mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: { // Mouse movement is reported on the MouseEvent.movement{X,Y} fields. // Movement is calculated in UIEvent::GetMovementPoint() as: @@ -4196,7 +4201,7 @@ EventStateManager::GenerateMouseEnterExit(WidgetMouseEvent* aMouseEvent) break; case NS_POINTER_LEAVE: case NS_POINTER_CANCEL: - case NS_MOUSE_EXIT_WIDGET: + case eMouseExitFromWidget: { // This is actually the window mouse exit or pointer leave event. We're not moving // into any new element. @@ -4468,10 +4473,10 @@ EventStateManager::SetClickCount(nsPresContext* aPresContext, switch (aEvent->button) { case WidgetMouseEvent::eLeftButton: - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { mLastLeftMouseDownContent = mouseContent; mLastLeftMouseDownContentParent = mouseContentParent; - } else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (aEvent->mMessage == eMouseUp) { if (mLastLeftMouseDownContent == mouseContent || mLastLeftMouseDownContentParent == mouseContent || mLastLeftMouseDownContent == mouseContentParent) { @@ -4486,10 +4491,10 @@ EventStateManager::SetClickCount(nsPresContext* aPresContext, break; case WidgetMouseEvent::eMiddleButton: - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { mLastMiddleMouseDownContent = mouseContent; mLastMiddleMouseDownContentParent = mouseContentParent; - } else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (aEvent->mMessage == eMouseUp) { if (mLastMiddleMouseDownContent == mouseContent || mLastMiddleMouseDownContentParent == mouseContent || mLastMiddleMouseDownContent == mouseContentParent) { @@ -4504,10 +4509,10 @@ EventStateManager::SetClickCount(nsPresContext* aPresContext, break; case WidgetMouseEvent::eRightButton: - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { mLastRightMouseDownContent = mouseContent; mLastRightMouseDownContentParent = mouseContentParent; - } else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (aEvent->mMessage == eMouseUp) { if (mLastRightMouseDownContent == mouseContent || mLastRightMouseDownContentParent == mouseContent || mLastRightMouseDownContent == mouseContentParent) { @@ -4590,14 +4595,14 @@ EventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext, // HandleEvent clears out mCurrentTarget which we might need again nsWeakFrame currentTarget = mCurrentTarget; - ret = InitAndDispatchClickEvent(aEvent, aStatus, NS_MOUSE_CLICK, + ret = InitAndDispatchClickEvent(aEvent, aStatus, eMouseClick, presShell, mouseContent, currentTarget, notDispatchToContents); if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2 && mouseContent && mouseContent->IsInComposedDoc()) { - //fire double click - ret = InitAndDispatchClickEvent(aEvent, aStatus, NS_MOUSE_DOUBLECLICK, + // fire double click + ret = InitAndDispatchClickEvent(aEvent, aStatus, eMouseDoubleClick, presShell, mouseContent, currentTarget, notDispatchToContents); } @@ -4998,7 +5003,7 @@ EventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent) bool EventStateManager::EventStatusOK(WidgetGUIEvent* aEvent) { - return !(aEvent->mMessage == NS_MOUSE_BUTTON_DOWN && + return !(aEvent->mMessage == eMouseDown && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton && !sNormalLMouseEventInProcess); } @@ -5786,7 +5791,7 @@ AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher( WidgetEvent* aEvent, nsIDocument* aDocument) : mIsHandlingUserInput(aIsHandlingUserInput), - mIsMouseDown(aEvent && aEvent->mMessage == NS_MOUSE_BUTTON_DOWN), + mIsMouseDown(aEvent && aEvent->mMessage == eMouseDown), mResetFMMouseButtonHandlingState(false) { if (!aIsHandlingUserInput) { @@ -5801,8 +5806,7 @@ AutoHandlingUserInputStatePusher::AutoHandlingUserInputStatePusher( return; } mResetFMMouseButtonHandlingState = - (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN || - aEvent->mMessage == NS_MOUSE_BUTTON_UP); + (aEvent->mMessage == eMouseDown || aEvent->mMessage == eMouseUp); if (mResetFMMouseButtonHandlingState) { nsFocusManager* fm = nsFocusManager::GetFocusManager(); NS_ENSURE_TRUE_VOID(fm); diff --git a/dom/events/EventStateManager.h b/dom/events/EventStateManager.h index af637485b4..1c624959fe 100644 --- a/dom/events/EventStateManager.h +++ b/dom/events/EventStateManager.h @@ -965,7 +965,7 @@ private: // has no frame. This is required for Web compatibility. #define NS_EVENT_NEEDS_FRAME(event) \ (!(event)->HasPluginActivationEventMessage() && \ - (event)->mMessage != NS_MOUSE_CLICK && \ - (event)->mMessage != NS_MOUSE_DOUBLECLICK) + (event)->mMessage != eMouseClick && \ + (event)->mMessage != eMouseDoubleClick) #endif // mozilla_EventStateManager_h_ diff --git a/dom/events/IMEContentObserver.cpp b/dom/events/IMEContentObserver.cpp index 91cb93b9f2..354a43a8fd 100644 --- a/dom/events/IMEContentObserver.cpp +++ b/dom/events/IMEContentObserver.cpp @@ -462,8 +462,8 @@ IMEContentObserver::OnMouseButtonEvent(nsPresContext* aPresContext, } // Now, we need to notify only mouse down and mouse up event. switch (aMouseEvent->mMessage) { - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_BUTTON_DOWN: + case eMouseUp: + case eMouseDown: break; default: return false; diff --git a/dom/events/WheelHandlingHelper.cpp b/dom/events/WheelHandlingHelper.cpp index 3b59696388..f16eb4c975 100644 --- a/dom/events/WheelHandlingHelper.cpp +++ b/dom/events/WheelHandlingHelper.cpp @@ -184,7 +184,7 @@ WheelTransaction::OnEvent(WidgetEvent* aEvent) EndTransaction(); } return; - case NS_MOUSE_MOVE: + case eMouseMove: case NS_DRAGDROP_OVER: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->IsReal()) { @@ -210,10 +210,10 @@ WheelTransaction::OnEvent(WidgetEvent* aEvent) case eKeyPress: case eKeyUp: case eKeyDown: - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_DOUBLECLICK: - case NS_MOUSE_CLICK: + case eMouseUp: + case eMouseDown: + case eMouseDoubleClick: + case eMouseClick: case NS_CONTEXTMENU: case NS_DRAGDROP_DROP: EndTransaction(); diff --git a/dom/html/HTMLButtonElement.cpp b/dom/html/HTMLButtonElement.cpp index 48750ecb21..7e0bef9318 100644 --- a/dom/html/HTMLButtonElement.cpp +++ b/dom/html/HTMLButtonElement.cpp @@ -304,7 +304,7 @@ HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) } break; - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: { WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (mouseEvent->button == WidgetMouseEvent::eLeftButton) { @@ -332,8 +332,8 @@ HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) // cancel all of these events for buttons //XXXsmaug What to do with these events? Why these should be cancelled? - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_DOUBLECLICK: + case eMouseUp: + case eMouseDoubleClick: { WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (aVisitor.mDOMEvent && @@ -344,7 +344,7 @@ HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) } break; - case NS_MOUSE_OVER: + case eMouseOver: { aVisitor.mPresContext->EventStateManager()-> SetContentState(this, NS_EVENT_STATE_HOVER); @@ -353,7 +353,7 @@ HTMLButtonElement::PostHandleEvent(EventChainPostVisitor& aVisitor) break; // XXX this doesn't seem to do anything yet - case NS_MOUSE_OUT: + case eMouseOut: { aVisitor.mPresContext->EventStateManager()-> SetContentState(nullptr, NS_EVENT_STATE_HOVER); diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 2550786cc7..9a2d606a74 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -2798,8 +2798,7 @@ HTMLInputElement::MaybeSubmitForm(nsPresContext* aPresContext) NS_ASSERTION(submitContent, "Form control not implementing nsIContent?!"); // Fire the button's onclick handler and let the button handle // submitting the form. - WidgetMouseEvent event(true, NS_MOUSE_CLICK, nullptr, - WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseClick, nullptr, WidgetMouseEvent::eReal); nsEventStatus status = nsEventStatus_eIgnore; shell->HandleDOMEventWithTarget(submitContent, &event, &status); } else if (!mForm->ImplicitSubmissionIsDisabled() && @@ -3019,11 +3018,11 @@ HTMLInputElement::NeedToInitializeEditorForEvent( } switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_MOVE: - case NS_MOUSE_ENTER_WIDGET: - case NS_MOUSE_EXIT_WIDGET: - case NS_MOUSE_OVER: - case NS_MOUSE_OUT: + case eMouseMove: + case eMouseEnterIntoWidget: + case eMouseExitFromWidget: + case eMouseOver: + case eMouseOut: case NS_SCROLLPORT_UNDERFLOW: case NS_SCROLLPORT_OVERFLOW: return false; @@ -3146,7 +3145,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor) aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH; } if (IsSingleLineTextControl(false) && - aVisitor.mEvent->mMessage == NS_MOUSE_CLICK && + aVisitor.mEvent->mMessage == eMouseClick && aVisitor.mEvent->AsMouseEvent()->button == WidgetMouseEvent::eMiddleButton) { aVisitor.mEvent->mFlags.mNoContentDispatch = false; @@ -3189,7 +3188,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor) // we want to end the spin. We do this here (rather than in // PostHandleEvent) because we don't want to let content preventDefault() // the end of the spin. - if (aVisitor.mEvent->mMessage == NS_MOUSE_MOVE) { + if (aVisitor.mEvent->mMessage == eMouseMove) { // Be aggressive about stopping the spin: bool stopSpin = true; nsNumberControlFrame* numberControlFrame = @@ -3220,7 +3219,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor) if (stopSpin) { StopNumberControlSpinnerSpin(); } - } else if (aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (aVisitor.mEvent->mMessage == eMouseUp) { StopNumberControlSpinnerSpin(); } } @@ -3914,10 +3913,9 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) } break; // eKeyPress || eKeyUp - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_DOUBLECLICK: - { + case eMouseDown: + case eMouseUp: + case eMouseDoubleClick: { // cancel all of these events for buttons //XXXsmaug Why? WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); @@ -3943,7 +3941,7 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor) nsNumberControlFrame* numberControlFrame = do_QueryFrame(GetPrimaryFrame()); if (numberControlFrame) { - if (aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_DOWN && + if (aVisitor.mEvent->mMessage == eMouseDown && IsMutable()) { switch (numberControlFrame->GetSpinButtonForPointerEvent( aVisitor.mEvent->AsMouseEvent())) { @@ -4062,7 +4060,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor) switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: case NS_TOUCH_START: { if (mIsDraggingRange) { break; @@ -4077,7 +4075,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor) inputEvent->IsOS()) { break; // ignore } - if (aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aVisitor.mEvent->mMessage == eMouseDown) { if (aVisitor.mEvent->AsMouseEvent()->buttons == WidgetMouseEvent::eLeftButtonFlag) { StartRangeThumbDrag(inputEvent); @@ -4094,7 +4092,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor) aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true; } break; - case NS_MOUSE_MOVE: + case eMouseMove: case NS_TOUCH_MOVE: if (!mIsDraggingRange) { break; @@ -4109,7 +4107,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(EventChainPostVisitor& aVisitor) aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true; break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: case NS_TOUCH_END: if (!mIsDraggingRange) { break; diff --git a/dom/html/HTMLLabelElement.cpp b/dom/html/HTMLLabelElement.cpp index 02082b783d..282ee9e6a3 100644 --- a/dom/html/HTMLLabelElement.cpp +++ b/dom/html/HTMLLabelElement.cpp @@ -104,7 +104,7 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor) WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent(); if (mHandlingEvent || (!(mouseEvent && mouseEvent->IsLeftClickEvent()) && - aVisitor.mEvent->mMessage != NS_MOUSE_BUTTON_DOWN) || + aVisitor.mEvent->mMessage != eMouseDown) || aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault || !aVisitor.mPresContext || // Don't handle the event if it's already been handled by another label @@ -123,10 +123,10 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor) if (content) { mHandlingEvent = true; switch (aVisitor.mEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: if (mouseEvent->button == WidgetMouseEvent::eLeftButton) { // We reset the mouse-down point on every event because there is - // no guarantee we will reach the NS_MOUSE_CLICK code below. + // no guarantee we will reach the eMouseClick code below. LayoutDeviceIntPoint* curPoint = new LayoutDeviceIntPoint(mouseEvent->refPoint); SetProperty(nsGkAtoms::labelMouseDownPtProperty, @@ -135,7 +135,7 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor) } break; - case NS_MOUSE_CLICK: + case eMouseClick: if (mouseEvent->IsLeftClickEvent()) { LayoutDeviceIntPoint* mouseDownPoint = static_cast( @@ -226,7 +226,7 @@ HTMLLabelElement::PerformAccesskey(bool aKeyCausesActivation, return; // Click on it if the users prefs indicate to do so. - WidgetMouseEvent event(aIsTrustedEvent, NS_MOUSE_CLICK, + WidgetMouseEvent event(aIsTrustedEvent, eMouseClick, nullptr, WidgetMouseEvent::eReal); event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD; diff --git a/dom/html/HTMLMenuItemElement.cpp b/dom/html/HTMLMenuItemElement.cpp index 31bb2ffce9..8a45c7809a 100644 --- a/dom/html/HTMLMenuItemElement.cpp +++ b/dom/html/HTMLMenuItemElement.cpp @@ -254,7 +254,7 @@ HTMLMenuItemElement::SetChecked(bool aChecked) nsresult HTMLMenuItemElement::PreHandleEvent(EventChainPreVisitor& aVisitor) { - if (aVisitor.mEvent->mMessage == NS_MOUSE_CLICK) { + if (aVisitor.mEvent->mMessage == eMouseClick) { bool originalCheckedValue = false; switch (mType) { @@ -290,7 +290,7 @@ nsresult HTMLMenuItemElement::PostHandleEvent(EventChainPostVisitor& aVisitor) { // Check to see if the event was cancelled. - if (aVisitor.mEvent->mMessage == NS_MOUSE_CLICK && + if (aVisitor.mEvent->mMessage == eMouseClick && aVisitor.mItemFlags & NS_CHECKED_IS_TOGGLED && aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault) { bool originalCheckedValue = diff --git a/dom/html/HTMLTextAreaElement.cpp b/dom/html/HTMLTextAreaElement.cpp index f2d8cb0af9..eca1d6bcdf 100644 --- a/dom/html/HTMLTextAreaElement.cpp +++ b/dom/html/HTMLTextAreaElement.cpp @@ -497,7 +497,7 @@ HTMLTextAreaElement::PreHandleEvent(EventChainPreVisitor& aVisitor) if (aVisitor.mEvent->mFlags.mNoContentDispatch) { aVisitor.mItemFlags |= NS_NO_CONTENT_DISPATCH; } - if (aVisitor.mEvent->mMessage == NS_MOUSE_CLICK && + if (aVisitor.mEvent->mMessage == eMouseClick && aVisitor.mEvent->AsMouseEvent()->button == WidgetMouseEvent::eMiddleButton) { aVisitor.mEvent->mFlags.mNoContentDispatch = false; diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index e8983e91e0..c631bbcd51 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -2449,9 +2449,9 @@ nsGenericHTMLFormElement::IsElementDisabledForEvents(EventMessage aMessage, nsIFrame* aFrame) { switch (aMessage) { - case NS_MOUSE_MOVE: - case NS_MOUSE_OVER: - case NS_MOUSE_OUT: + case eMouseMove: + case eMouseOver: + case eMouseOut: case NS_MOUSEENTER: case NS_MOUSELEAVE: case NS_POINTER_MOVE: @@ -2690,7 +2690,7 @@ nsGenericHTMLElement::Click() // called from chrome JS. Mark this event trusted if Click() // is called from chrome code. WidgetMouseEvent event(nsContentUtils::IsCallerChrome(), - NS_MOUSE_CLICK, nullptr, WidgetMouseEvent::eReal); + eMouseClick, nullptr, WidgetMouseEvent::eReal); event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; EventDispatcher::Dispatch(static_cast(this), context, &event); @@ -2805,7 +2805,7 @@ nsGenericHTMLElement::DispatchSimulatedClick(nsGenericHTMLElement* aElement, bool aIsTrusted, nsPresContext* aPresContext) { - WidgetMouseEvent event(aIsTrusted, NS_MOUSE_CLICK, nullptr, + WidgetMouseEvent event(aIsTrusted, eMouseClick, nullptr, WidgetMouseEvent::eReal); event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD; return EventDispatcher::Dispatch(ToSupports(aElement), aPresContext, &event); diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 2f5eacba70..7a380dfebe 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -2071,11 +2071,11 @@ TabChild::UpdateTapState(const WidgetTouchEvent& aEvent, nsEventStatus aStatus) case NS_TOUCH_END: if (!TouchManager::gPreventMouseEvents) { APZCCallbackHelper::DispatchSynthesizedMouseEvent( - NS_MOUSE_MOVE, time, currentPoint, 0, mPuppetWidget); + eMouseMove, time, currentPoint, 0, mPuppetWidget); APZCCallbackHelper::DispatchSynthesizedMouseEvent( - NS_MOUSE_BUTTON_DOWN, time, currentPoint, 0, mPuppetWidget); + eMouseDown, time, currentPoint, 0, mPuppetWidget); APZCCallbackHelper::DispatchSynthesizedMouseEvent( - NS_MOUSE_BUTTON_UP, time, currentPoint, 0, mPuppetWidget); + eMouseUp, time, currentPoint, 0, mPuppetWidget); } // fall through case NS_TOUCH_CANCEL: diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 826a9310c7..23f784cb76 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1415,19 +1415,19 @@ bool TabParent::SendRealMouseEvent(WidgetMouseEvent& event) if (widget) { // When we mouseenter the tab, the tab's cursor should // become the current cursor. When we mouseexit, we stop. - if (NS_MOUSE_ENTER_WIDGET == event.mMessage) { + if (eMouseEnterIntoWidget == event.mMessage) { mTabSetsCursor = true; if (mCustomCursor) { widget->SetCursor(mCustomCursor, mCustomCursorHotspotX, mCustomCursorHotspotY); } else if (mCursor != nsCursor(-1)) { widget->SetCursor(mCursor); } - } else if (NS_MOUSE_EXIT_WIDGET == event.mMessage) { + } else if (eMouseExitFromWidget == event.mMessage) { mTabSetsCursor = false; } } - if (NS_MOUSE_MOVE == event.mMessage) { + if (eMouseMove == event.mMessage) { if (event.reason == WidgetMouseEvent::eSynthesized) { return SendSynthMouseMoveEvent(event); } else { diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index 9b68e0d1f4..a107046f07 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -1663,7 +1663,7 @@ nsresult nsPluginInstanceOwner::DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent, aMouseEvent->StopPropagation(); } } - if (mouseEvent->mMessage == NS_MOUSE_BUTTON_UP) { + if (mouseEvent->mMessage == eMouseUp) { mLastMouseDownButtonType = -1; } } @@ -1788,12 +1788,11 @@ CocoaEventTypeForEvent(const WidgetGUIEvent& anEvent, nsIFrame* aObjectFrame) } switch (anEvent.mMessage) { - case NS_MOUSE_OVER: + case eMouseOver: return NPCocoaEventMouseEntered; - case NS_MOUSE_OUT: + case eMouseOut: return NPCocoaEventMouseExited; - case NS_MOUSE_MOVE: - { + case eMouseMove: { // We don't know via information on events from the widget code whether or not // we're dragging. The widget code just generates mouse move events from native // drag events. If anybody is capturing, this is a drag event. @@ -1803,9 +1802,9 @@ CocoaEventTypeForEvent(const WidgetGUIEvent& anEvent, nsIFrame* aObjectFrame) return NPCocoaEventMouseMoved; } - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: return NPCocoaEventMouseDown; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: return NPCocoaEventMouseUp; case eKeyDown: return NPCocoaEventKeyDown; @@ -1828,12 +1827,12 @@ TranslateToNPCocoaEvent(WidgetGUIEvent* anEvent, nsIFrame* aObjectFrame) InitializeNPCocoaEvent(&cocoaEvent); cocoaEvent.type = CocoaEventTypeForEvent(*anEvent, aObjectFrame); - if (anEvent->mMessage == NS_MOUSE_MOVE || - anEvent->mMessage == NS_MOUSE_BUTTON_DOWN || - anEvent->mMessage == NS_MOUSE_BUTTON_UP || + if (anEvent->mMessage == eMouseMove || + anEvent->mMessage == eMouseDown || + anEvent->mMessage == eMouseUp || anEvent->mMessage == NS_MOUSE_SCROLL || - anEvent->mMessage == NS_MOUSE_OVER || - anEvent->mMessage == NS_MOUSE_OUT) + anEvent->mMessage == eMouseOver || + anEvent->mMessage == eMouseOut) { nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(anEvent, aObjectFrame) - aObjectFrame->GetContentRectRelativeToSelf().TopLeft(); @@ -1850,9 +1849,8 @@ TranslateToNPCocoaEvent(WidgetGUIEvent* anEvent, nsIFrame* aObjectFrame) } switch (anEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: - { + case eMouseDown: + case eMouseUp: { WidgetMouseEvent* mouseEvent = anEvent->AsMouseEvent(); if (mouseEvent) { switch (mouseEvent->button) { @@ -1870,7 +1868,7 @@ TranslateToNPCocoaEvent(WidgetGUIEvent* anEvent, nsIFrame* aObjectFrame) } cocoaEvent.data.mouse.clickCount = mouseEvent->clickCount; } else { - NS_WARNING("NS_MOUSE_BUTTON_UP/DOWN is not a WidgetMouseEvent?"); + NS_WARNING("eMouseUp/DOWN is not a WidgetMouseEvent?"); } break; } @@ -2022,7 +2020,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) } bool handled = (response == kNPEventHandled || response == kNPEventStartIME); - bool leftMouseButtonDown = (anEvent.mMessage == NS_MOUSE_BUTTON_DOWN) && + bool leftMouseButtonDown = (anEvent.mMessage == eMouseDown) && (anEvent.AsMouseEvent()->button == WidgetMouseEvent::eLeftButton); if (handled && !(leftMouseButtonDown && !mContentFocused)) { rv = nsEventStatus_eConsumeNoDefault; @@ -2042,10 +2040,10 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) pluginEvent.event = 0; const WidgetMouseEvent* mouseEvent = anEvent.AsMouseEvent(); switch (anEvent.mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: pluginEvent.event = WM_MOUSEMOVE; break; - case NS_MOUSE_BUTTON_DOWN: { + case eMouseDown: { static const int downMsgs[] = { WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN }; static const int dblClickMsgs[] = @@ -2057,13 +2055,13 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) } break; } - case NS_MOUSE_BUTTON_UP: { + case eMouseUp: { static const int upMsgs[] = { WM_LBUTTONUP, WM_MBUTTONUP, WM_RBUTTONUP }; pluginEvent.event = upMsgs[mouseEvent->button]; break; } - // don't synthesize anything for NS_MOUSE_DOUBLECLICK, since that + // don't synthesize anything for eMouseDoubleClick, since that // is a synthetic event generated on mouse-up, and Windows WM_*DBLCLK // messages are sent on mouse-down default: @@ -2086,12 +2084,12 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) // not the widget they were received on. // See use of NPEvent in widget/windows/nsWindow.cpp // for why this assert should be safe - NS_ASSERTION(anEvent.mMessage == NS_MOUSE_BUTTON_DOWN || - anEvent.mMessage == NS_MOUSE_BUTTON_UP || - anEvent.mMessage == NS_MOUSE_DOUBLECLICK || - anEvent.mMessage == NS_MOUSE_OVER || - anEvent.mMessage == NS_MOUSE_OUT || - anEvent.mMessage == NS_MOUSE_MOVE, + NS_ASSERTION(anEvent.mMessage == eMouseDown || + anEvent.mMessage == eMouseUp || + anEvent.mMessage == eMouseDoubleClick || + anEvent.mMessage == eMouseOver || + anEvent.mMessage == eMouseOut || + anEvent.mMessage == eMouseMove, "Incorrect event type for coordinate translation"); nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(&anEvent, mPluginFrame) - @@ -2147,10 +2145,9 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) switch(anEvent.mClass) { case eMouseEventClass: { - switch (anEvent.mMessage) - { - case NS_MOUSE_CLICK: - case NS_MOUSE_DOUBLECLICK: + switch (anEvent.mMessage) { + case eMouseClick: + case eMouseDoubleClick: // Button up/down events sent instead. return rv; default: @@ -2177,13 +2174,12 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) Window root = None; // Could XQueryTree, but this is not important. #endif - switch (anEvent.mMessage) - { - case NS_MOUSE_OVER: - case NS_MOUSE_OUT: + switch (anEvent.mMessage) { + case eMouseOver: + case eMouseOut: { XCrossingEvent& event = pluginEvent.xcrossing; - event.type = anEvent.mMessage == NS_MOUSE_OVER ? + event.type = anEvent.mMessage == eMouseOver ? EnterNotify : LeaveNotify; event.root = root; event.time = anEvent.time; @@ -2200,7 +2196,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.focus = mContentFocused; } break; - case NS_MOUSE_MOVE: + case eMouseMove: { XMotionEvent& event = pluginEvent.xmotion; event.type = MotionNotify; @@ -2217,11 +2213,11 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) event.same_screen = True; } break; - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: + case eMouseDown: + case eMouseUp: { XButtonEvent& event = pluginEvent.xbutton; - event.type = anEvent.mMessage == NS_MOUSE_BUTTON_DOWN ? + event.type = anEvent.mMessage == eMouseDown ? ButtonPress : ButtonRelease; event.root = root; event.time = anEvent.time; @@ -2354,10 +2350,9 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) switch(anEvent.mClass) { case eMouseEventClass: { - switch (anEvent.mMessage) - { - case NS_MOUSE_CLICK: - case NS_MOUSE_DOUBLECLICK: + switch (anEvent.mMessage) { + case eMouseClick: + case eMouseDoubleClick: // Button up/down events sent instead. return rv; default: @@ -2372,16 +2367,15 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) nsIntPoint pluginPoint(presContext->AppUnitsToDevPixels(appPoint.x), presContext->AppUnitsToDevPixels(appPoint.y)); - switch (anEvent.mMessage) - { - case NS_MOUSE_MOVE: + switch (anEvent.mMessage) { + case eMouseMove: { // are these going to be touch events? // pluginPoint.x; // pluginPoint.y; } break; - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: { ANPEvent event; event.inSize = sizeof(ANPEvent); @@ -2392,7 +2386,7 @@ nsEventStatus nsPluginInstanceOwner::ProcessEvent(const WidgetGUIEvent& anEvent) mInstance->HandleEvent(&event, nullptr, NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO); } break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: { ANPEvent event; event.inSize = sizeof(ANPEvent); diff --git a/dom/xul/nsXULElement.cpp b/dom/xul/nsXULElement.cpp index d88aa66e08..ca8bcc374b 100644 --- a/dom/xul/nsXULElement.cpp +++ b/dom/xul/nsXULElement.cpp @@ -285,8 +285,7 @@ nsXULElement::Create(nsXULPrototypeElement* aPrototype, nodeInfo = aDocument->NodeInfoManager()-> GetNodeInfo(ni->NameAtom(), ni->GetPrefixAtom(), ni->NamespaceID(), nsIDOMNode::ELEMENT_NODE); - } - else { + } else { nodeInfo = aPrototype->mNodeInfo; } @@ -531,7 +530,7 @@ static bool IsNonList(mozilla::dom::NodeInfo* aNodeInfo) bool nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) { - /* + /* * Returns true if an element may be focused, and false otherwise. The inout * argument aTabIndex will be set to the tab order index to be used; -1 for * elements that should not be part of the tab order and a greater value to @@ -567,7 +566,7 @@ nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) // or if it's a remote target, since the remote target must handle // the focus. if (aWithMouse && - IsNonList(mNodeInfo) && + IsNonList(mNodeInfo) && !EventStateManager::IsRemoteTarget(this)) { return false; @@ -596,8 +595,7 @@ nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) xulControl->GetTabIndex(&tabIndex); shouldFocus = *aTabIndex >= 0 || tabIndex >= 0; *aTabIndex = tabIndex; - } - else { + } else { // otherwise, if there is no tabindex attribute, just use the value of // *aTabIndex to indicate focusability. Reset any supplied tabindex to 0. shouldFocus = *aTabIndex >= 0; @@ -617,8 +615,7 @@ nsXULElement::IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) if (IsNonList(mNodeInfo)) *aTabIndex = -1; } - } - else { + } else { shouldFocus = *aTabIndex >= 0; } } @@ -986,10 +983,10 @@ nsXULElement::RemoveChildAt(uint32_t aIndex, bool aNotify) } nsStyledElement::RemoveChildAt(aIndex, aNotify); - - if (newCurrentIndex == -2) + + if (newCurrentIndex == -2) { controlElement->SetCurrentItem(nullptr); - else if (newCurrentIndex > -1) { + } else if (newCurrentIndex > -1) { // Make sure the index is still valid int32_t treeRows; listBox->GetRowCount(&treeRows); @@ -1066,11 +1063,10 @@ nsXULElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName, if (!oldValue.IsEmpty()) { RemoveBroadcaster(oldValue); } - } - else if (aNamespaceID == kNameSpaceID_None && - aValue && - mNodeInfo->Equals(nsGkAtoms::window) && - aName == nsGkAtoms::chromemargin) { + } else if (aNamespaceID == kNameSpaceID_None && + aValue && + mNodeInfo->Equals(nsGkAtoms::window) && + aName == nsGkAtoms::chromemargin) { nsAttrValue attrValue; // Make sure the margin format is valid first if (!attrValue.ParseIntMarginValue(aValue->String())) { @@ -1100,7 +1096,7 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, SetEventHandler(aName, body, true); } } - + nsIDocument* document = GetUncomposedDoc(); // Hide chrome if needed @@ -1108,13 +1104,10 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, if (aName == nsGkAtoms::hidechrome) { HideWindowChrome( aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters)); - } - else if (aName == nsGkAtoms::chromemargin) { + } else if (aName == nsGkAtoms::chromemargin) { SetChromeMargins(aValue); - } - - else if (aName == nsGkAtoms::windowtype && - document && document->GetRootElement() == this) { + } else if (aName == nsGkAtoms::windowtype && + document && document->GetRootElement() == this) { MaybeUpdatePrivateLifetime(); } } @@ -1123,9 +1116,8 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, if (document && document->GetRootElement() == this) { if (aName == nsGkAtoms::title) { document->NotifyPossibleTitleChange(false); - } - else if ((aName == nsGkAtoms::activetitlebarcolor || - aName == nsGkAtoms::inactivetitlebarcolor)) { + } else if ((aName == nsGkAtoms::activetitlebarcolor || + aName == nsGkAtoms::inactivetitlebarcolor)) { nscolor color = NS_RGBA(0, 0, 0, 0); if (aValue->Type() == nsAttrValue::eColor) { aValue->GetColorValue(color); @@ -1137,23 +1129,19 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, attrValue.GetColorValue(color); } SetTitlebarColor(color, aName == nsGkAtoms::activetitlebarcolor); - } - else if (aName == nsGkAtoms::drawintitlebar) { + } else if (aName == nsGkAtoms::drawintitlebar) { SetDrawsInTitlebar( aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters)); - } - else if (aName == nsGkAtoms::drawtitle) { + } else if (aName == nsGkAtoms::drawtitle) { SetDrawsTitle( aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters)); - } - else if (aName == nsGkAtoms::localedir) { + } else if (aName == nsGkAtoms::localedir) { // if the localedir changed on the root element, reset the document direction nsCOMPtr xuldoc = do_QueryInterface(document); if (xuldoc) { xuldoc->ResetDocumentDirection(); } - } - else if (aName == nsGkAtoms::lwtheme || + } else if (aName == nsGkAtoms::lwtheme || aName == nsGkAtoms::lwthemetextcolor) { // if the lwtheme changed, make sure to reset the document lwtheme cache nsCOMPtr xuldoc = do_QueryInterface(document); @@ -1161,55 +1149,48 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName, xuldoc->ResetDocumentLWTheme(); UpdateBrightTitlebarForeground(document); } - } - else if (aName == nsGkAtoms::brighttitlebarforeground) { + } else if (aName == nsGkAtoms::brighttitlebarforeground) { UpdateBrightTitlebarForeground(document); } } - + if (aName == nsGkAtoms::src && document) { LoadSrc(); } - } else { + } else { if (mNodeInfo->Equals(nsGkAtoms::window)) { if (aName == nsGkAtoms::hidechrome) { HideWindowChrome(false); - } - else if (aName == nsGkAtoms::chromemargin) { + } else if (aName == nsGkAtoms::chromemargin) { ResetChromeMargins(); } } - + nsIDocument* doc = GetUncomposedDoc(); if (doc && doc->GetRootElement() == this) { if ((aName == nsGkAtoms::activetitlebarcolor || aName == nsGkAtoms::inactivetitlebarcolor)) { // Use 0, 0, 0, 0 as the "none" color. SetTitlebarColor(NS_RGBA(0, 0, 0, 0), aName == nsGkAtoms::activetitlebarcolor); - } - else if (aName == nsGkAtoms::localedir) { + } else if (aName == nsGkAtoms::localedir) { // if the localedir changed on the root element, reset the document direction nsCOMPtr xuldoc = do_QueryInterface(doc); if (xuldoc) { xuldoc->ResetDocumentDirection(); } - } - else if ((aName == nsGkAtoms::lwtheme || - aName == nsGkAtoms::lwthemetextcolor)) { + } else if ((aName == nsGkAtoms::lwtheme || + aName == nsGkAtoms::lwthemetextcolor)) { // if the lwtheme changed, make sure to restyle appropriately nsCOMPtr xuldoc = do_QueryInterface(doc); if (xuldoc) { xuldoc->ResetDocumentLWTheme(); UpdateBrightTitlebarForeground(doc); } - } - else if (aName == nsGkAtoms::brighttitlebarforeground) { + } else if (aName == nsGkAtoms::brighttitlebarforeground) { UpdateBrightTitlebarForeground(doc); - } - else if (aName == nsGkAtoms::drawintitlebar) { + } else if (aName == nsGkAtoms::drawintitlebar) { SetDrawsInTitlebar(false); - } - else if (aName == nsGkAtoms::drawtitle) { + } else if (aName == nsGkAtoms::drawtitle) { SetDrawsTitle(false); } } @@ -1289,8 +1270,8 @@ nsXULElement::PreHandleEvent(EventChainPreVisitor& aVisitor) aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119 if (IsRootOfNativeAnonymousSubtree() && (IsAnyOfXULElements(nsGkAtoms::scrollbar, nsGkAtoms::scrollcorner)) && - (aVisitor.mEvent->mMessage == NS_MOUSE_CLICK || - aVisitor.mEvent->mMessage == NS_MOUSE_DOUBLECLICK || + (aVisitor.mEvent->mMessage == eMouseClick || + aVisitor.mEvent->mMessage == eMouseDoubleClick || aVisitor.mEvent->mMessage == NS_XUL_COMMAND || aVisitor.mEvent->mMessage == NS_CONTEXTMENU || aVisitor.mEvent->mMessage == NS_DRAGDROP_START || @@ -1760,13 +1741,13 @@ nsXULElement::ClickWithInputSource(uint16_t aInputSource) bool isCallerChrome = nsContentUtils::IsCallerChrome(); - WidgetMouseEvent eventDown(isCallerChrome, NS_MOUSE_BUTTON_DOWN, + WidgetMouseEvent eventDown(isCallerChrome, eMouseDown, nullptr, WidgetMouseEvent::eReal); - WidgetMouseEvent eventUp(isCallerChrome, NS_MOUSE_BUTTON_UP, + WidgetMouseEvent eventUp(isCallerChrome, eMouseUp, nullptr, WidgetMouseEvent::eReal); - WidgetMouseEvent eventClick(isCallerChrome, NS_MOUSE_CLICK, nullptr, + WidgetMouseEvent eventClick(isCallerChrome, eMouseClick, nullptr, WidgetMouseEvent::eReal); - eventDown.inputSource = eventUp.inputSource = eventClick.inputSource + eventDown.inputSource = eventUp.inputSource = eventClick.inputSource = aInputSource; // send mouse down @@ -1873,7 +1854,7 @@ nsXULElement::MakeHeavyweight(nsXULPrototypeElement* aPrototype) for (i = 0; i < aPrototype->mNumAttributes; ++i) { nsXULPrototypeAttribute* protoattr = &aPrototype->mAttributes[i]; nsAttrValue attrValue; - + // Style rules need to be cloned. if (protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) { nsRefPtr ruleClone = @@ -1884,16 +1865,14 @@ nsXULElement::MakeHeavyweight(nsXULPrototypeElement* aPrototype) nsRefPtr styleRule = do_QueryObject(ruleClone); attrValue.SetTo(styleRule, &stringValue); - } - else { + } else { attrValue.SetTo(protoattr->mValue); } // XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName if (protoattr->mName.IsAtom()) { rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.Atom(), attrValue); - } - else { + } else { rv = mAttrsAndChildren.SetAndSwapAttr(protoattr->mName.NodeInfo(), attrValue); } @@ -2126,8 +2105,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeNode) if (tmp->mType == nsXULPrototypeNode::eType_Element) { static_cast(tmp)->Unlink(); - } - else if (tmp->mType == nsXULPrototypeNode::eType_Script) { + } else if (tmp->mType == nsXULPrototypeNode::eType_Script) { static_cast(tmp)->UnlinkJSObjects(); } NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -2144,7 +2122,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeNode) if (!name.IsAtom()) { NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mAttributes[i].mName.NodeInfo()"); - cb.NoteNativeChild(name.NodeInfo(), + cb.NoteNativeChild(name.NodeInfo(), NS_CYCLE_COLLECTION_PARTICIPANT(NodeInfo)); } } @@ -2213,8 +2191,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream, kNameSpaceID_None, nsIDOMNode::ATTRIBUTE_NODE); NS_ASSERTION(ni, "the nodeinfo should already exist"); - } - else { + } else { ni = mAttributes[i].mName.NodeInfo(); } @@ -2479,15 +2456,13 @@ nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue, mAttributes[aPos].mValue.ParseAtom(aValue); return NS_OK; - } - else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) { + } else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) { mHasClassAttribute = true; // Compute the element's class list mAttributes[aPos].mValue.ParseAtomArray(aValue); return NS_OK; - } - else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) { + } else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) { mHasStyleAttribute = true; // Parse the element's 'style' attribute nsRefPtr rule; @@ -2626,7 +2601,7 @@ nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream, nsCOMPtr oos; rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos)); NS_ENSURE_SUCCESS(rv, rv); - + nsresult tmp = Serialize(oos, aProtoDoc, nullptr); if (NS_FAILED(tmp)) { rv = tmp; @@ -2678,13 +2653,13 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput, // AbortCaching if things look bad. nsresult rv = NS_OK; nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); - + nsCOMPtr objectInput = aInput; if (cache) { bool useXULCache = true; if (mSrcURI) { // NB: we must check the XUL script cache early, to avoid - // multiple deserialization attempts for a given script. + // multiple deserialization attempts for a given script. // Note that XULDocument::LoadScript // checks the XUL script cache too, in order to handle the // serialization case. @@ -2705,10 +2680,10 @@ nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput, if (!mScriptObject) { if (mSrcURI) { rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput)); - } - // If !mSrcURI, we have an inline script. We shouldn't have + } + // If !mSrcURI, we have an inline script. We shouldn't have // to do anything else in that case, I think. - + // We do reflect errors into rv, but our caller may want to // ignore our return value, because mScriptObject will be null // after any error, and that suffices to cause the script to diff --git a/editor/libeditor/nsEditorEventListener.cpp b/editor/libeditor/nsEditorEventListener.cpp index a5fbaa648a..9644378c10 100644 --- a/editor/libeditor/nsEditorEventListener.cpp +++ b/editor/libeditor/nsEditorEventListener.cpp @@ -408,7 +408,7 @@ nsEditorEventListener::HandleEvent(nsIDOMEvent* aEvent) return KeyPress(keyEvent); } // mousedown - case NS_MOUSE_BUTTON_DOWN: { + case eMouseDown: { nsCOMPtr mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); // nsEditorEventListener may receive (1) all mousedown, mouseup and click @@ -422,26 +422,26 @@ nsEditorEventListener::HandleEvent(nsIDOMEvent* aEvent) return mMouseDownOrUpConsumedByIME ? NS_OK : MouseDown(mouseEvent); } // mouseup - case NS_MOUSE_BUTTON_UP: { + case eMouseUp: { nsCOMPtr mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); - // See above comment in the NS_MOUSE_BUTTON_DOWN case, first. + // See above comment in the eMouseDown case, first. // This code assumes that case #1 is occuring. However, if case #3 may // occurs after case #2 and the mousedown is consumed, // mMouseDownOrUpConsumedByIME is true even though nsEditorEventListener // has not received the preceding mousedown event of this mouseup event. // So, mMouseDownOrUpConsumedByIME may be invalid here. However, // this is not a matter because mMouseDownOrUpConsumedByIME is referred - // only by NS_MOUSE_CLICK case but click event is fired only in case #1. + // only by eMouseClick case but click event is fired only in case #1. // So, before a click event is fired, mMouseDownOrUpConsumedByIME is - // always initialized in the NS_MOUSE_BUTTON_DOWN case if it's referred. + // always initialized in the eMouseDown case if it's referred. if (NotifyIMEOfMouseButtonEvent(mouseEvent)) { mMouseDownOrUpConsumedByIME = true; } return mMouseDownOrUpConsumedByIME ? NS_OK : MouseUp(mouseEvent); } // click - case NS_MOUSE_CLICK: { + case eMouseClick: { nsCOMPtr mouseEvent = do_QueryInterface(aEvent); NS_ENSURE_TRUE(mouseEvent, NS_OK); // If the preceding mousedown event or mouseup event was consumed, diff --git a/gfx/layers/apz/src/APZCTreeManager.cpp b/gfx/layers/apz/src/APZCTreeManager.cpp index 0af2452f6a..425ec16e4e 100644 --- a/gfx/layers/apz/src/APZCTreeManager.cpp +++ b/gfx/layers/apz/src/APZCTreeManager.cpp @@ -895,7 +895,7 @@ APZCTreeManager::UpdateWheelTransaction(WidgetInputEvent& aEvent) } switch (aEvent.mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: case NS_DRAGDROP_OVER: { WidgetMouseEvent* mouseEvent = aEvent.AsMouseEvent(); if (!mouseEvent->IsReal()) { @@ -910,10 +910,10 @@ APZCTreeManager::UpdateWheelTransaction(WidgetInputEvent& aEvent) case eKeyPress: case eKeyUp: case eKeyDown: - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_DOUBLECLICK: - case NS_MOUSE_CLICK: + case eMouseUp: + case eMouseDown: + case eMouseDoubleClick: + case eMouseClick: case NS_CONTEXTMENU: case NS_DRAGDROP_DROP: txn->EndTransaction(); diff --git a/gfx/layers/apz/util/APZCCallbackHelper.cpp b/gfx/layers/apz/util/APZCCallbackHelper.cpp index 274942cc23..62ab36611e 100644 --- a/gfx/layers/apz/util/APZCCallbackHelper.cpp +++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp @@ -496,8 +496,8 @@ APZCCallbackHelper::DispatchSynthesizedMouseEvent(EventMessage aMsg, Modifiers aModifiers, nsIWidget* aWidget) { - MOZ_ASSERT(aMsg == NS_MOUSE_MOVE || aMsg == NS_MOUSE_BUTTON_DOWN || - aMsg == NS_MOUSE_BUTTON_UP || aMsg == NS_MOUSE_MOZLONGTAP); + MOZ_ASSERT(aMsg == eMouseMove || aMsg == eMouseDown || + aMsg == eMouseUp || aMsg == NS_MOUSE_MOZLONGTAP); WidgetMouseEvent event(true, aMsg, nullptr, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); @@ -506,7 +506,7 @@ APZCCallbackHelper::DispatchSynthesizedMouseEvent(EventMessage aMsg, event.button = WidgetMouseEvent::eLeftButton; event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH; event.ignoreRootScrollFrame = true; - if (aMsg != NS_MOUSE_MOVE) { + if (aMsg != eMouseMove) { event.clickCount = 1; } event.modifiers = aModifiers; @@ -546,9 +546,9 @@ APZCCallbackHelper::FireSingleTapEvent(const LayoutDevicePoint& aPoint, APZCCH_LOG("Dispatching single-tap component events to %s\n", Stringify(aPoint).c_str()); int time = 0; - DispatchSynthesizedMouseEvent(NS_MOUSE_MOVE, time, aPoint, aModifiers, aWidget); - DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_DOWN, time, aPoint, aModifiers, aWidget); - DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_UP, time, aPoint, aModifiers, aWidget); + DispatchSynthesizedMouseEvent(eMouseMove, time, aPoint, aModifiers, aWidget); + DispatchSynthesizedMouseEvent(eMouseDown, time, aPoint, aModifiers, aWidget); + DispatchSynthesizedMouseEvent(eMouseUp, time, aPoint, aModifiers, aWidget); } static nsIScrollableFrame* diff --git a/layout/base/AccessibleCaretEventHub.cpp b/layout/base/AccessibleCaretEventHub.cpp index ddf7850225..05ad183252 100644 --- a/layout/base/AccessibleCaretEventHub.cpp +++ b/layout/base/AccessibleCaretEventHub.cpp @@ -496,23 +496,23 @@ AccessibleCaretEventHub::HandleMouseEvent(WidgetMouseEvent* aEvent) nsPoint point = GetMouseEventPosition(aEvent); switch (aEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: - AC_LOGV("Before NS_MOUSE_BUTTON_DOWN, state: %s", mState->Name()); + case eMouseDown: + AC_LOGV("Before eMouseDown, state: %s", mState->Name()); rv = mState->OnPress(this, point, id); - AC_LOGV("After NS_MOUSE_BUTTON_DOWN, state: %s, consume: %d", + AC_LOGV("After eMouseDown, state: %s, consume: %d", mState->Name(), rv); break; - case NS_MOUSE_MOVE: - AC_LOGV("Before NS_MOUSE_MOVE, state: %s", mState->Name()); + case eMouseMove: + AC_LOGV("Before eMouseMove, state: %s", mState->Name()); rv = mState->OnMove(this, point); - AC_LOGV("After NS_MOUSE_MOVE, state: %s, consume: %d", mState->Name(), rv); + AC_LOGV("After eMouseMove, state: %s, consume: %d", mState->Name(), rv); break; - case NS_MOUSE_BUTTON_UP: - AC_LOGV("Before NS_MOUSE_BUTTON_UP, state: %s", mState->Name()); + case eMouseUp: + AC_LOGV("Before eMouseUp, state: %s", mState->Name()); rv = mState->OnRelease(this); - AC_LOGV("After NS_MOUSE_BUTTON_UP, state: %s, consume: %d", mState->Name(), + AC_LOGV("After eMouseUp, state: %s, consume: %d", mState->Name(), rv); break; diff --git a/layout/base/SelectionCarets.cpp b/layout/base/SelectionCarets.cpp index 5115b2430a..19c884848e 100644 --- a/layout/base/SelectionCarets.cpp +++ b/layout/base/SelectionCarets.cpp @@ -198,7 +198,7 @@ SelectionCarets::HandleEvent(WidgetEvent* aEvent) nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, movePoint, rootFrame); if (aEvent->mMessage == NS_TOUCH_START || - (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN && + (aEvent->mMessage == eMouseDown && mouseEvent->button == WidgetMouseEvent::eLeftButton)) { // If having a active touch, ignore other touch down event if (aEvent->mMessage == NS_TOUCH_START && mActiveTouchId >= 0) { @@ -226,7 +226,7 @@ SelectionCarets::HandleEvent(WidgetEvent* aEvent) } } else if (aEvent->mMessage == NS_TOUCH_END || aEvent->mMessage == NS_TOUCH_CANCEL || - aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + aEvent->mMessage == eMouseUp) { CancelLongTapDetector(); if (mDragMode != NONE) { // Only care about same id @@ -238,7 +238,7 @@ SelectionCarets::HandleEvent(WidgetEvent* aEvent) return nsEventStatus_eConsumeNoDefault; } } else if (aEvent->mMessage == NS_TOUCH_MOVE || - aEvent->mMessage == NS_MOUSE_MOVE) { + aEvent->mMessage == eMouseMove) { if (mDragMode == START_FRAME || mDragMode == END_FRAME) { if (mActiveTouchId == nowTouchId) { ptInRoot.y += mCaretCenterToDownPointOffsetY; diff --git a/layout/base/TouchCaret.cpp b/layout/base/TouchCaret.cpp index fcbbb7aee2..6175ffa599 100644 --- a/layout/base/TouchCaret.cpp +++ b/layout/base/TouchCaret.cpp @@ -765,19 +765,19 @@ TouchCaret::HandleEvent(WidgetEvent* aEvent) case NS_TOUCH_START: status = HandleTouchDownEvent(aEvent->AsTouchEvent()); break; - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: status = HandleMouseDownEvent(aEvent->AsMouseEvent()); break; case NS_TOUCH_END: status = HandleTouchUpEvent(aEvent->AsTouchEvent()); break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: status = HandleMouseUpEvent(aEvent->AsMouseEvent()); break; case NS_TOUCH_MOVE: status = HandleTouchMoveEvent(aEvent->AsTouchEvent()); break; - case NS_MOUSE_MOVE: + case eMouseMove: status = HandleMouseMoveEvent(aEvent->AsMouseEvent()); break; case NS_TOUCH_CANCEL: diff --git a/layout/base/gtest/TestAccessibleCaretEventHub.cpp b/layout/base/gtest/TestAccessibleCaretEventHub.cpp index dff3158039..51dca9e25c 100644 --- a/layout/base/gtest/TestAccessibleCaretEventHub.cpp +++ b/layout/base/gtest/TestAccessibleCaretEventHub.cpp @@ -125,17 +125,17 @@ public: static UniquePtr CreateMousePressEvent(nscoord aX, nscoord aY) { - return CreateMouseEvent(NS_MOUSE_BUTTON_DOWN, aX, aY); + return CreateMouseEvent(eMouseDown, aX, aY); } static UniquePtr CreateMouseMoveEvent(nscoord aX, nscoord aY) { - return CreateMouseEvent(NS_MOUSE_MOVE, aX, aY); + return CreateMouseEvent(eMouseMove, aX, aY); } static UniquePtr CreateMouseReleaseEvent(nscoord aX, nscoord aY) { - return CreateMouseEvent(NS_MOUSE_BUTTON_UP, aX, aY); + return CreateMouseEvent(eMouseUp, aX, aY); } static UniquePtr CreateLongTapEvent(nscoord aX, nscoord aY) diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index f8d40257ef..b5bbda403a 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -468,8 +468,8 @@ public: virtual void HandleEvent(EventChainPostVisitor& aVisitor) override { if (aVisitor.mPresContext && aVisitor.mEvent->mClass != eBasicEventClass) { - if (aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_DOWN || - aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_UP) { + if (aVisitor.mEvent->mMessage == eMouseDown || + aVisitor.mEvent->mMessage == eMouseUp) { // Mouse-up and mouse-down events call nsFrame::HandlePress/Release // which call GetContentOffsetsFromPoint which requires up-to-date layout. // Bring layout up-to-date now so that GetCurrentEventFrame() below @@ -493,7 +493,7 @@ public: } nsIFrame* frame = mPresShell->GetCurrentEventFrame(); if (!frame && - (aVisitor.mEvent->mMessage == NS_MOUSE_BUTTON_UP || + (aVisitor.mEvent->mMessage == eMouseUp || aVisitor.mEvent->mMessage == NS_TOUCH_END)) { // Redirect BUTTON_UP and TOUCH_END events to the root frame to ensure // that capturing is released. @@ -5572,7 +5572,7 @@ PresShell::ProcessSynthMouseMoveEvent(bool aFromScroll) refpoint += view->ViewToWidgetOffset(); } NS_ASSERTION(view->GetWidget(), "view should have a widget here"); - WidgetMouseEvent event(true, NS_MOUSE_MOVE, view->GetWidget(), + WidgetMouseEvent event(true, eMouseMove, view->GetWidget(), WidgetMouseEvent::eSynthesized); event.refPoint = LayoutDeviceIntPoint::FromAppUnitsToNearest(refpoint, viewAPD); event.time = PR_IntervalNow(); @@ -6331,7 +6331,7 @@ void PresShell::UpdateActivePointerState(WidgetGUIEvent* aEvent) { switch (aEvent->mMessage) { - case NS_MOUSE_ENTER_WIDGET: + case eMouseEnterIntoWidget: // In this case we have to know information about available mouse pointers if (WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent()) { gActivePointersIds->Put(mouseEvent->pointerId, @@ -6356,7 +6356,7 @@ PresShell::UpdateActivePointerState(WidgetGUIEvent* aEvent) } } break; - case NS_MOUSE_EXIT_WIDGET: + case eMouseExitFromWidget: // In this case we have to remove information about disappeared mouse pointers if (WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent()) { gActivePointersIds->Remove(mouseEvent->pointerId); @@ -6552,11 +6552,11 @@ PresShell::RecordMouseLocation(WidgetGUIEvent* aEvent) return; } - if ((aEvent->mMessage == NS_MOUSE_MOVE && + if ((aEvent->mMessage == eMouseMove && aEvent->AsMouseEvent()->reason == WidgetMouseEvent::eReal) || - aEvent->mMessage == NS_MOUSE_ENTER_WIDGET || - aEvent->mMessage == NS_MOUSE_BUTTON_DOWN || - aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + aEvent->mMessage == eMouseEnterIntoWidget || + aEvent->mMessage == eMouseDown || + aEvent->mMessage == eMouseUp) { nsIFrame* rootFrame = GetRootFrame(); if (!rootFrame) { nsView* rootView = mViewManager->GetRootView(); @@ -6567,17 +6567,17 @@ PresShell::RecordMouseLocation(WidgetGUIEvent* aEvent) nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, rootFrame); } #ifdef DEBUG_MOUSE_LOCATION - if (aEvent->mMessage == NS_MOUSE_ENTER_WIDGET) { + if (aEvent->mMessage == eMouseEnterIntoWidget) { printf("[ps=%p]got mouse enter for %p\n", this, aEvent->widget); } printf("[ps=%p]setting mouse location to (%d,%d)\n", this, mMouseLocation.x, mMouseLocation.y); #endif - if (aEvent->mMessage == NS_MOUSE_ENTER_WIDGET) { + if (aEvent->mMessage == eMouseEnterIntoWidget) { SynthesizeMouseMove(false); } - } else if (aEvent->mMessage == NS_MOUSE_EXIT_WIDGET) { + } else if (aEvent->mMessage == eMouseExitFromWidget) { // Although we only care about the mouse moving into an area for which this // pres shell doesn't receive mouse move events, we don't check which widget // the mouse exit was for since this seems to vary by platform. Hopefully @@ -6655,16 +6655,16 @@ DispatchPointerFromMouseOrTouch(PresShell* aShell, } int16_t button = mouseEvent->button; switch (mouseEvent->mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: if (mouseEvent->buttons == 0) { button = -1; } pointerMessage = NS_POINTER_MOVE; break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: pointerMessage = NS_POINTER_UP; break; - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: pointerMessage = NS_POINTER_DOWN; break; default: @@ -7295,7 +7295,7 @@ PresShell::HandleEvent(nsIFrame* aFrame, } WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); - bool isWindowLevelMouseExit = (aEvent->mMessage == NS_MOUSE_EXIT_WIDGET) && + bool isWindowLevelMouseExit = (aEvent->mMessage == eMouseExitFromWidget) && (mouseEvent && mouseEvent->exit == WidgetMouseEvent::eTopLevel); // Get the frame at the event point. However, don't do this if we're @@ -7456,10 +7456,9 @@ PresShell::HandleEvent(nsIFrame* aFrame, // a document which needs events suppressed if (aEvent->mClass == eMouseEventClass && frame->PresContext()->Document()->EventHandlingSuppressed()) { - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { mNoDelayedMouseEvents = true; - } else if (!mNoDelayedMouseEvents && - aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (!mNoDelayedMouseEvents && aEvent->mMessage == eMouseUp) { DelayedEvent* event = new DelayedMouseEvent(aEvent->AsMouseEvent()); if (!mDelayedEvents.AppendElement(event)) { delete event; @@ -7868,8 +7867,8 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) } break; } - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: + case eMouseDown: + case eMouseUp: isHandlingUserInput = true; break; @@ -7911,7 +7910,7 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) AutoHandlingUserInputStatePusher userInpStatePusher(isHandlingUserInput, aEvent, mDocument); - if (aEvent->mFlags.mIsTrusted && aEvent->mMessage == NS_MOUSE_MOVE) { + if (aEvent->mFlags.mIsTrusted && aEvent->mMessage == eMouseMove) { nsIPresShell::AllowMouseCapture( EventStateManager::GetActiveEventStateManager() == manager); } @@ -7973,11 +7972,11 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, nsEventStatus* aStatus) } break; } - case NS_MOUSE_BUTTON_UP: + case eMouseUp: // reset the capturing content now that the mouse button is up SetCapturingContent(nullptr, 0); break; - case NS_MOUSE_MOVE: + case eMouseMove: nsIPresShell::AllowMouseCapture(false); break; default: diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 07b43bda37..b4bcf00b78 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -1138,7 +1138,7 @@ nsComboboxControlFrame::HandleEvent(nsPresContext* aPresContext, } #if COMBOBOX_ROLLUP_CONSUME_EVENT == 0 - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { nsIWidget* widget = GetNearestWidget(); if (widget && GetContent() == widget->GetLastRollup()) { // This event did a Rollup on this control - prevent it from opening diff --git a/layout/forms/nsImageControlFrame.cpp b/layout/forms/nsImageControlFrame.cpp index 13bdf23a4e..02f6ce2ba2 100644 --- a/layout/forms/nsImageControlFrame.cpp +++ b/layout/forms/nsImageControlFrame.cpp @@ -162,7 +162,7 @@ nsImageControlFrame::HandleEvent(nsPresContext* aPresContext, *aEventStatus = nsEventStatus_eIgnore; - if (aEvent->mMessage == NS_MOUSE_BUTTON_UP && + if (aEvent->mMessage == eMouseUp && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { // Store click point for HTMLInputElement::SubmitNamesValues // Do this on MouseUp because the specs don't say and that's what IE does diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 1eb2170064..7ff37880d1 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -881,7 +881,7 @@ nsListControlFrame::HandleEvent(nsPresContext* aPresContext, { NS_ENSURE_ARG_POINTER(aEventStatus); - /*const char * desc[] = {"NS_MOUSE_MOVE", + /*const char * desc[] = {"eMouseMove", "NS_MOUSE_LEFT_BUTTON_UP", "NS_MOUSE_LEFT_BUTTON_DOWN", "","","","","","","", @@ -890,8 +890,8 @@ nsListControlFrame::HandleEvent(nsPresContext* aPresContext, "","","","","","","","", "NS_MOUSE_RIGHT_BUTTON_UP", "NS_MOUSE_RIGHT_BUTTON_DOWN", - "NS_MOUSE_OVER", - "NS_MOUSE_OUT", + "eMouseOver", + "eMouseOut", "NS_MOUSE_LEFT_DOUBLECLICK", "NS_MOUSE_MIDDLE_DOUBLECLICK", "NS_MOUSE_RIGHT_DOUBLECLICK", diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 5ad8864e23..c71b98787c 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -2607,7 +2607,7 @@ nsFrame::HandleEvent(nsPresContext* aPresContext, nsEventStatus* aEventStatus) { - if (aEvent->mMessage == NS_MOUSE_MOVE) { + if (aEvent->mMessage == eMouseMove) { // XXX If the second argument of HandleDrag() is WidgetMouseEvent, // the implementation becomes simpler. return HandleDrag(aPresContext, aEvent, aEventStatus); @@ -2616,10 +2616,10 @@ nsFrame::HandleEvent(nsPresContext* aPresContext, if ((aEvent->mClass == eMouseEventClass && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) || aEvent->mClass == eTouchEventClass) { - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN || + if (aEvent->mMessage == eMouseDown || aEvent->mMessage == NS_TOUCH_START) { HandlePress(aPresContext, aEvent, aEventStatus); - } else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP || + } else if (aEvent->mMessage == eMouseUp || aEvent->mMessage == NS_TOUCH_END) { HandleRelease(aPresContext, aEvent, aEventStatus); } @@ -2653,8 +2653,8 @@ nsFrame::GetDataForTableSelection(const nsFrameSelection* aFrameSelection, // (Mouse down does normal selection unless Ctrl/Cmd is pressed) bool doTableSelection = displaySelection == nsISelectionDisplay::DISPLAY_ALL && selectingTableCells && - (aMouseEvent->mMessage == NS_MOUSE_MOVE || - (aMouseEvent->mMessage == NS_MOUSE_BUTTON_UP && + (aMouseEvent->mMessage == eMouseMove || + (aMouseEvent->mMessage == eMouseUp && aMouseEvent->button == WidgetMouseEvent::eLeftButton) || aMouseEvent->IsShift()); diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index 73ee86505c..54fc338d79 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -653,10 +653,10 @@ nsresult nsHTMLFramesetFrame::HandleEvent(nsPresContext* aPresContext, if (mDragger) { // the nsFramesetBorderFrame has captured NS_MOUSE_DOWN switch (aEvent->mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: MouseDrag(aPresContext, aEvent); break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { EndMouseDrag(aPresContext); } @@ -1546,7 +1546,7 @@ nsHTMLFramesetBorderFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN && + if (aEvent->mMessage == eMouseDown && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { nsHTMLFramesetFrame* parentFrame = do_QueryFrame(GetParent()); if (parentFrame) { diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index c7e335b6a8..2e3a7065f3 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1979,9 +1979,9 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext, { NS_ENSURE_ARG_POINTER(aEventStatus); - if ((aEvent->mMessage == NS_MOUSE_BUTTON_UP && + if ((aEvent->mMessage == eMouseUp && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) || - aEvent->mMessage == NS_MOUSE_MOVE) { + aEvent->mMessage == eMouseMove) { nsImageMap* map = GetImageMap(); bool isServerMap = IsServerImageMap(); if ((nullptr != map) || isServerMap) { @@ -2019,7 +2019,7 @@ nsImageFrame::HandleEvent(nsPresContext* aPresContext, uri->SetSpec(spec); bool clicked = false; - if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + if (aEvent->mMessage == eMouseUp) { *aEventStatus = nsEventStatus_eConsumeDoDefault; clicked = true; } diff --git a/layout/generic/nsPluginFrame.cpp b/layout/generic/nsPluginFrame.cpp index fea902112b..0a48191f22 100644 --- a/layout/generic/nsPluginFrame.cpp +++ b/layout/generic/nsPluginFrame.cpp @@ -1786,7 +1786,7 @@ nsPluginFrame::HandleEvent(nsPresContext* aPresContext, #ifdef XP_MACOSX // we want to process some native mouse events in the cocoa event model - if ((anEvent->mMessage == NS_MOUSE_ENTER_WIDGET || + if ((anEvent->mMessage == eMouseEnterIntoWidget || anEvent->mMessage == NS_WHEEL_WHEEL) && mInstanceOwner->GetEventModel() == NPEventModelCocoa) { *anEventStatus = mInstanceOwner->ProcessEvent(*anEvent); @@ -1799,7 +1799,7 @@ nsPluginFrame::HandleEvent(nsPresContext* aPresContext, // and mouse-up) are needed to make the routing of mouse events while // dragging conform to standard OS X practice, and to the Cocoa NPAPI spec. // See bug 525078 and bug 909678. - if (anEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (anEvent->mMessage == eMouseDown) { nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED); } #endif @@ -1810,7 +1810,7 @@ nsPluginFrame::HandleEvent(nsPresContext* aPresContext, // nsPluginFrameSuper::HandleEvent() might have killed us. #ifdef XP_MACOSX - if (anEvent->mMessage == NS_MOUSE_BUTTON_UP) { + if (anEvent->mMessage == eMouseUp) { nsIPresShell::SetCapturingContent(nullptr, 0); } #endif diff --git a/layout/xul/nsButtonBoxFrame.cpp b/layout/xul/nsButtonBoxFrame.cpp index 50be85dbe7..d1712bd627 100644 --- a/layout/xul/nsButtonBoxFrame.cpp +++ b/layout/xul/nsButtonBoxFrame.cpp @@ -110,7 +110,7 @@ nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext, break; } - case NS_MOUSE_CLICK: { + case eMouseClick: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->IsLeftClickEvent()) { MouseClicked(aPresContext, mouseEvent); diff --git a/layout/xul/nsMenuFrame.cpp b/layout/xul/nsMenuFrame.cpp index 99a3295c6a..a0bf10540c 100644 --- a/layout/xul/nsMenuFrame.cpp +++ b/layout/xul/nsMenuFrame.cpp @@ -413,7 +413,7 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, } #endif } - else if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN && + else if (aEvent->mMessage == eMouseDown && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton && !IsDisabled() && IsMenu()) { // The menu item was selected. Bring up the menu. @@ -431,7 +431,7 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, } else if ( #ifndef NSCONTEXTMENUISMOUSEUP - (aEvent->mMessage == NS_MOUSE_BUTTON_UP && + (aEvent->mMessage == eMouseUp && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eRightButton) && #else aEvent->mMessage == NS_CONTEXTMENU && @@ -452,14 +452,14 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, Execute(aEvent); } } - else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP && + else if (aEvent->mMessage == eMouseUp && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton && !IsMenu() && !IsDisabled()) { // Execute the execute event handler. *aEventStatus = nsEventStatus_eConsumeNoDefault; Execute(aEvent); } - else if (aEvent->mMessage == NS_MOUSE_OUT) { + else if (aEvent->mMessage == eMouseOut) { // Kill our timer if one is active. if (mOpenTimer) { mOpenTimer->Cancel(); @@ -479,7 +479,7 @@ nsMenuFrame::HandleEvent(nsPresContext* aPresContext, } } } - else if (aEvent->mMessage == NS_MOUSE_MOVE && + else if (aEvent->mMessage == eMouseMove && (onmenu || (menuParent && menuParent->IsMenuBar()))) { if (gEatMouseMove) { gEatMouseMove = false; diff --git a/layout/xul/nsResizerFrame.cpp b/layout/xul/nsResizerFrame.cpp index 5bf4e98d0f..9385064156 100644 --- a/layout/xul/nsResizerFrame.cpp +++ b/layout/xul/nsResizerFrame.cpp @@ -63,7 +63,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, switch (aEvent->mMessage) { case NS_TOUCH_START: - case NS_MOUSE_BUTTON_DOWN: { + case eMouseDown: { if (aEvent->mClass == eTouchEventClass || (aEvent->mClass == eMouseEventClass && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) { @@ -129,7 +129,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, break; case NS_TOUCH_END: - case NS_MOUSE_BUTTON_UP: { + case eMouseUp: { if (aEvent->mClass == eTouchEventClass || (aEvent->mClass == eMouseEventClass && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton)) { @@ -144,7 +144,7 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, break; case NS_TOUCH_MOVE: - case NS_MOUSE_MOVE: { + case eMouseMove: { if (mTrackingMouseMove) { nsCOMPtr window; @@ -287,14 +287,14 @@ nsResizerFrame::HandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_CLICK: { + case eMouseClick: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->IsLeftClickEvent()) { MouseClicked(aPresContext, mouseEvent); } break; } - case NS_MOUSE_DOUBLECLICK: + case eMouseDoubleClick: if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { nsCOMPtr window; nsIPresShell* presShell = aPresContext->GetPresShell(); diff --git a/layout/xul/nsRootBoxFrame.cpp b/layout/xul/nsRootBoxFrame.cpp index 945c03f0bb..718eda170d 100644 --- a/layout/xul/nsRootBoxFrame.cpp +++ b/layout/xul/nsRootBoxFrame.cpp @@ -205,7 +205,7 @@ nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext, return NS_OK; } - if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + if (aEvent->mMessage == eMouseUp) { nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); } diff --git a/layout/xul/nsScrollBoxFrame.cpp b/layout/xul/nsScrollBoxFrame.cpp index 091dcaf343..e3de4ed60c 100644 --- a/layout/xul/nsScrollBoxFrame.cpp +++ b/layout/xul/nsScrollBoxFrame.cpp @@ -87,23 +87,23 @@ nsAutoRepeatBoxFrame::HandleEvent(nsPresContext* aPresContext, // repeat mode may be "hover" for repeating while the mouse is hovering // over the element, otherwise repetition is done while the element is // active (pressed). - case NS_MOUSE_ENTER_WIDGET: - case NS_MOUSE_OVER: + case eMouseEnterIntoWidget: + case eMouseOver: if (IsActivatedOnHover()) { StartRepeat(); mTrustedEvent = aEvent->mFlags.mIsTrusted; } break; - case NS_MOUSE_EXIT_WIDGET: - case NS_MOUSE_OUT: + case eMouseExitFromWidget: + case eMouseOut: // always stop on mouse exit StopRepeat(); // Not really necessary but do this to be safe mTrustedEvent = false; break; - case NS_MOUSE_CLICK: { + case eMouseClick: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->IsLeftClickEvent()) { // skip button frame handling to prevent click handling diff --git a/layout/xul/nsScrollbarButtonFrame.cpp b/layout/xul/nsScrollbarButtonFrame.cpp index 0a172b12be..99af0f7400 100644 --- a/layout/xul/nsScrollbarButtonFrame.cpp +++ b/layout/xul/nsScrollbarButtonFrame.cpp @@ -53,20 +53,20 @@ nsScrollbarButtonFrame::HandleEvent(nsPresContext* aPresContext, } switch (aEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: mCursorOnThis = true; // if we didn't handle the press ourselves, pass it on to the superclass if (HandleButtonPress(aPresContext, aEvent, aEventStatus)) { return NS_OK; } break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: HandleRelease(aPresContext, aEvent, aEventStatus); break; - case NS_MOUSE_OUT: + case eMouseOut: mCursorOnThis = false; break; - case NS_MOUSE_MOVE: { + case eMouseMove: { nsPoint cursor = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); nsRect frameRect(nsPoint(0, 0), GetSize()); diff --git a/layout/xul/nsSliderFrame.cpp b/layout/xul/nsSliderFrame.cpp index 80bf2d4520..8c4e24a71c 100644 --- a/layout/xul/nsSliderFrame.cpp +++ b/layout/xul/nsSliderFrame.cpp @@ -443,7 +443,7 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, { switch (aEvent->mMessage) { case NS_TOUCH_MOVE: - case NS_MOUSE_MOVE: { + case eMouseMove: { nsPoint eventPoint; if (!GetEventPoint(aEvent, eventPoint)) { break; @@ -505,7 +505,7 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, break; case NS_TOUCH_END: - case NS_MOUSE_BUTTON_UP: + case eMouseUp: if (ShouldScrollForEvent(aEvent)) { StopDrag(); //we MUST call nsFrame HandleEvent for mouse ups to maintain the selection state and capture state. @@ -563,9 +563,9 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, aEvent->AsMouseEvent()->button == WidgetMouseEvent::eRightButton) { // HandlePress and HandleRelease are usually called via // nsFrame::HandleEvent, but only for the left mouse button. - if (aEvent->mMessage == NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage == eMouseDown) { HandlePress(aPresContext, aEvent, aEventStatus); - } else if (aEvent->mMessage == NS_MOUSE_BUTTON_UP) { + } else if (aEvent->mMessage == eMouseUp) { HandleRelease(aPresContext, aEvent, aEventStatus); } @@ -574,13 +574,13 @@ nsSliderFrame::HandleEvent(nsPresContext* aPresContext, #endif // XXX hack until handle release is actually called in nsframe. - // if (aEvent->mMessage == NS_MOUSE_OUT || + // if (aEvent->mMessage == eMouseOut || // aEvent->mMessage == NS_MOUSE_RIGHT_BUTTON_UP || // aEvent->mMessage == NS_MOUSE_LEFT_BUTTON_UP) { // HandleRelease(aPresContext, aEvent, aEventStatus); // } - if (aEvent->mMessage == NS_MOUSE_OUT && mChange) + if (aEvent->mMessage == eMouseOut && mChange) HandleRelease(aPresContext, aEvent, aEventStatus); return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); @@ -1014,8 +1014,8 @@ nsSliderFrame::ShouldScrollForEvent(WidgetGUIEvent* aEvent) case NS_TOUCH_START: case NS_TOUCH_END: return true; - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: { + case eMouseDown: + case eMouseUp: { uint16_t button = aEvent->AsMouseEvent()->button; #ifdef MOZ_WIDGET_GTK return (button == WidgetMouseEvent::eLeftButton) || @@ -1042,7 +1042,7 @@ nsSliderFrame::ShouldScrollToClickForEvent(WidgetGUIEvent* aEvent) return GetScrollToClick(); } - if (aEvent->mMessage != NS_MOUSE_BUTTON_DOWN) { + if (aEvent->mMessage != eMouseDown) { return false; } diff --git a/layout/xul/nsSplitterFrame.cpp b/layout/xul/nsSplitterFrame.cpp index d95420c74a..1057a7ad5b 100644 --- a/layout/xul/nsSplitterFrame.cpp +++ b/layout/xul/nsSplitterFrame.cpp @@ -389,11 +389,11 @@ nsSplitterFrame::HandleEvent(nsPresContext* aPresContext, nsWeakFrame weakFrame(this); nsRefPtr kungFuDeathGrip(mInner); switch (aEvent->mMessage) { - case NS_MOUSE_MOVE: + case eMouseMove: mInner->MouseDrag(aPresContext, aEvent); break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { mInner->MouseUp(aPresContext, aEvent); } diff --git a/layout/xul/nsTitleBarFrame.cpp b/layout/xul/nsTitleBarFrame.cpp index f9526e99fa..e2893ec401 100644 --- a/layout/xul/nsTitleBarFrame.cpp +++ b/layout/xul/nsTitleBarFrame.cpp @@ -68,7 +68,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, switch (aEvent->mMessage) { - case NS_MOUSE_BUTTON_DOWN: { + case eMouseDown: { if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { // titlebar has no effect in non-chrome shells nsCOMPtr dsti = aPresContext->GetDocShell(); @@ -92,7 +92,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, break; - case NS_MOUSE_BUTTON_UP: { + case eMouseUp: { if (mTrackingMouseMove && aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { // we're done tracking. @@ -107,7 +107,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_MOVE: { + case eMouseMove: { if(mTrackingMouseMove) { LayoutDeviceIntPoint nsMoveBy = aEvent->refPoint - mLastPoint; @@ -147,7 +147,7 @@ nsTitleBarFrame::HandleEvent(nsPresContext* aPresContext, } break; - case NS_MOUSE_CLICK: { + case eMouseClick: { WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent(); if (mouseEvent->IsLeftClickEvent()) { MouseClicked(aPresContext, mouseEvent); diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index db39c2888c..bdb1821d9c 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -2565,7 +2565,7 @@ nsTreeBodyFrame::HandleEvent(nsPresContext* aPresContext, WidgetGUIEvent* aEvent, nsEventStatus* aEventStatus) { - if (aEvent->mMessage == NS_MOUSE_OVER || aEvent->mMessage == NS_MOUSE_MOVE) { + if (aEvent->mMessage == eMouseOver || aEvent->mMessage == eMouseMove) { nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); int32_t xTwips = pt.x - mInnerBox.x; int32_t yTwips = pt.y - mInnerBox.y; @@ -2578,7 +2578,7 @@ nsTreeBodyFrame::HandleEvent(nsPresContext* aPresContext, if (mMouseOverRow != -1) InvalidateRow(mMouseOverRow); } - } else if (aEvent->mMessage == NS_MOUSE_OUT) { + } else if (aEvent->mMessage == eMouseOut) { if (mMouseOverRow != -1) { InvalidateRow(mMouseOverRow); mMouseOverRow = -1; diff --git a/media/webrtc/moz.build b/media/webrtc/moz.build index 7754fb622d..1c00e9a2d1 100644 --- a/media/webrtc/moz.build +++ b/media/webrtc/moz.build @@ -59,7 +59,9 @@ if CONFIG['MOZ_WEBRTC_SIGNALING']: 'signaling/src/jsep/JsepSessionImpl.cpp', 'signaling/src/media-conduit/AudioConduit.cpp', 'signaling/src/media-conduit/CodecStatistics.cpp', + 'signaling/src/media-conduit/MediaCodecVideoCodec.cpp', 'signaling/src/media-conduit/VideoConduit.cpp', + 'signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp', 'signaling/src/mediapipeline/MediaPipeline.cpp', 'signaling/src/mediapipeline/MediaPipelineFilter.cpp', 'signaling/src/mediapipeline/SrtpFlow.cpp', @@ -96,6 +98,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk': GYP_DIRS['signalingtest'].variables = gyp_vars.copy() GYP_DIRS['signalingtest'].variables.update( build_for_test=1, + moz_webrtc_mediacodec=0, build_for_standalone=0 ) GYP_DIRS['signalingtest'].non_unified_sources += signaling_non_unified_sources diff --git a/media/webrtc/signaling/signaling.gyp b/media/webrtc/signaling/signaling.gyp index efba116f67..c447989840 100644 --- a/media/webrtc/signaling/signaling.gyp +++ b/media/webrtc/signaling/signaling.gyp @@ -216,6 +216,20 @@ 'MOZ_WEBRTC_OMX' ], }], + ['moz_webrtc_mediacodec==1', { + 'include_dirs': [ + '../../../widget/android', + ], + 'sources': [ + './src/media-conduit/MediaCodecVideoCodec.h', + './src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h', + './src/media-conduit/MediaCodecVideoCodec.cpp', + './src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp', + ], + 'defines' : [ + 'MOZ_WEBRTC_MEDIACODEC', + ], + }], ['(build_for_test==0) and (build_for_standalone==0)', { 'defines' : [ 'MOZILLA_INTERNAL_API', diff --git a/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.cpp b/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.cpp new file mode 100644 index 0000000000..0c6c2fdde0 --- /dev/null +++ b/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.cpp @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "CSFLog.h" +#include "nspr.h" + +#include "WebrtcMediaCodecVP8VideoCodec.h" +#include "MediaCodecVideoCodec.h" + +namespace mozilla { + +static const char* logTag ="MediaCodecVideoCodec"; + +VideoEncoder* MediaCodecVideoCodec::CreateEncoder(CodecType aCodecType) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + if (aCodecType == CODEC_VP8) { + return new WebrtcMediaCodecVP8VideoEncoder(); + } + return nullptr; +} + +VideoDecoder* MediaCodecVideoCodec::CreateDecoder(CodecType aCodecType) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + if (aCodecType == CODEC_VP8) { + return new WebrtcMediaCodecVP8VideoDecoder(); + } + return nullptr; +} + +} diff --git a/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.h b/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.h new file mode 100644 index 0000000000..50dde82114 --- /dev/null +++ b/media/webrtc/signaling/src/media-conduit/MediaCodecVideoCodec.h @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MediaCodecVideoCodec_h__ +#define MediaCodecVideoCodec_h__ + +#include "MediaConduitInterface.h" + +namespace mozilla { +class MediaCodecVideoCodec { + public: + enum CodecType { + CODEC_VP8, + }; + /** + * Create encoder object for codec type |aCodecType|. Return |nullptr| when + * failed. + */ + static VideoEncoder* CreateEncoder(CodecType aCodecType); + + /** + * Create decoder object for codec type |aCodecType|. Return |nullptr| when + * failed. + */ + static VideoDecoder* CreateDecoder(CodecType aCodecType); +}; + +} + +#endif // MediaCodecVideoCodec_h__ diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp new file mode 100644 index 0000000000..c74925126c --- /dev/null +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.cpp @@ -0,0 +1,1004 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include +#include + +#include "CSFLog.h" +#include "nspr.h" + +#include "MediaCodec.h" +#include "WebrtcMediaCodecVP8VideoCodec.h" +#include "AndroidJNIWrapper.h" +#include "mozilla/Scoped.h" +#include "mozilla/ArrayUtils.h" +#include "nsThreadUtils.h" +#include "mozilla/Monitor.h" +#include "runnable_utils.h" + +#include "AudioConduit.h" +#include "VideoConduit.h" +#include "libyuv/convert_from.h" +#include "libyuv/convert.h" +#include "libyuv/row.h" + +#include + +using namespace mozilla; +using namespace mozilla::widget::sdk; + +static const int32_t DECODER_TIMEOUT = 10 * PR_USEC_PER_MSEC; // 10ms +static const char MEDIACODEC_VIDEO_MIME_VP8[] = "video/x-vnd.on2.vp8"; + +namespace mozilla { + +static const char* logTag ="WebrtcMediaCodecVP8VideoCodec"; + +static MediaCodec::LocalRef CreateDecoder(const char* aMimeType) +{ + if (!aMimeType) { + return nullptr; + } + + MediaCodec::LocalRef codec; + MediaCodec::CreateDecoderByType(aMimeType, &codec); + return codec; +} + +static MediaCodec::LocalRef CreateEncoder(const char* aMimeType) +{ + if (!aMimeType) { + return nullptr; + } + + MediaCodec::LocalRef codec; + MediaCodec::CreateEncoderByType(aMimeType, &codec); + return codec; +} + +static void +ShutdownThread(nsCOMPtr& aThread) +{ + aThread->Shutdown(); +} + +// Base runnable class to repeatly pull MediaCodec output buffers in seperate thread. +// How to use: +// - implementing DrainOutput() to get output. Remember to return false to tell +// drain not to pop input queue. +// - call QueueInput() to schedule a run to drain output. The input, aFrame, +// should contains corresponding info such as image size and timestamps for +// DrainOutput() implementation to construct data needed by encoded/decoded +// callbacks. +class MediaCodecOutputDrain : public nsRunnable +{ +public: + void Start() { + MonitorAutoLock lock(mMonitor); + if (mThread == nullptr) { + NS_NewNamedThread("OutputDrain", getter_AddRefs(mThread)); + } + mEnding = false; + mThread->Dispatch(this, NS_DISPATCH_NORMAL); + } + + void Stop() { + MonitorAutoLock lock(mMonitor); + mEnding = true; + lock.NotifyAll(); // In case Run() is waiting. + + if (mThread != nullptr) { + MonitorAutoUnlock unlock(mMonitor); + NS_DispatchToMainThread( + WrapRunnableNM >(&ShutdownThread, mThread)); + mThread = nullptr; + } + } + + void QueueInput(const EncodedFrame& aFrame) + { + MonitorAutoLock lock(mMonitor); + + MOZ_ASSERT(mThread); + + mInputFrames.push(aFrame); + // Notify Run() about queued input and it can start working. + lock.NotifyAll(); + } + + NS_IMETHODIMP Run() override + { + MOZ_ASSERT(mThread); + + MonitorAutoLock lock(mMonitor); + while (true) { + if (mInputFrames.empty()) { + // Wait for new input. + lock.Wait(); + } + + if (mEnding) { + // Stop draining. + break; + } + + MOZ_ASSERT(!mInputFrames.empty()); + { + // Release monitor while draining because it's blocking. + MonitorAutoUnlock unlock(mMonitor); + DrainOutput(); + } + } + + return NS_OK; + } + +protected: + MediaCodecOutputDrain() + : mMonitor("MediaCodecOutputDrain monitor") + , mEnding(false) + {} + + // Drain output buffer for input frame queue mInputFrames. + // mInputFrames contains info such as size and time of the input frames. + // We have to give a queue to handle encoder frame skips - we can input 10 + // frames and get one back. NOTE: any access of aInputFrames MUST be preceded + // locking mMonitor! + + // Blocks waiting for decoded buffers, but for a limited period because + // we need to check for shutdown. + virtual bool DrainOutput() = 0; + +protected: + // This monitor protects all things below it, and is also used to + // wait/notify queued input. + Monitor mMonitor; + std::queue mInputFrames; + +private: + // also protected by mMonitor + nsCOMPtr mThread; + bool mEnding; +}; + +class WebrtcAndroidMediaCodec { +public: + WebrtcAndroidMediaCodec() + : mEncoderCallback(nullptr) + , mDecoderCallback(nullptr) + , isStarted(false) + , mEnding(false) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + } + + virtual ~WebrtcAndroidMediaCodec() { + } + + nsresult Configure(uint32_t width, + uint32_t height, + const jobject aSurface, + uint32_t flags, + const char* mime, + bool encoder) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + nsresult res = NS_OK; + + if (!mCoder) { + mWidth = width; + mHeight = height; + + MediaFormat::LocalRef format; + + res = MediaFormat::CreateVideoFormat(nsCString(mime), + mWidth, + mHeight, + &format); + + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, CreateVideoFormat failed err = %d", __FUNCTION__, res); + return NS_ERROR_FAILURE; + } + + if (encoder) { + mCoder = CreateEncoder(mime); + + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, CreateEncoderByType failed err = %d", __FUNCTION__, res); + return NS_ERROR_FAILURE; + } + + res = format->SetInteger(nsCString("bitrate"), 1000*300); + res = format->SetInteger(nsCString("bitrate-mode"), 2); + res = format->SetInteger(nsCString("color-format"), 21); + res = format->SetInteger(nsCString("frame-rate"), 30); + res = format->SetInteger(nsCString("i-frame-interval"), 100); + + } else { + mCoder = CreateDecoder(mime); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, CreateDecoderByType failed err = %d", __FUNCTION__, res); + return NS_ERROR_FAILURE; + } + } + res = mCoder->Configure(format, nullptr, nullptr, flags); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, err = %d", __FUNCTION__, res); + } + } + + return res; + } + + nsresult Start() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + if (!mCoder) { + return NS_ERROR_FAILURE; + } + + mEnding = false; + + nsresult res; + res = mCoder->Start(); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, mCoder->start() return err = %d", + __FUNCTION__, res); + return res; + } + isStarted = true; + return NS_OK; + } + + nsresult Stop() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + mEnding = true; + + if (mOutputDrain != nullptr) { + mOutputDrain->Stop(); + mOutputDrain = nullptr; + } + + mCoder->Stop(); + mCoder->Release(); + isStarted = false; + return NS_OK; + } + + void GenerateVideoFrame( + size_t width, size_t height, uint32_t timeStamp, + void* decoded, + webrtc::I420VideoFrame* videoFrame, int color_format) { + + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + // TODO: eliminate extra pixel copy/color conversion + size_t widthUV = (width + 1) / 2; + if (videoFrame->CreateEmptyFrame(width, height, width, widthUV, widthUV)) { + return; + } + + uint8_t* src_nv12 = static_cast(decoded); + int src_nv12_y_size = width * height; + + uint8_t* dstY = videoFrame->buffer(webrtc::kYPlane); + uint8_t* dstU = videoFrame->buffer(webrtc::kUPlane); + uint8_t* dstV = videoFrame->buffer(webrtc::kVPlane); + + libyuv::NV12ToI420(src_nv12, width, + src_nv12 + src_nv12_y_size, (width + 1) & ~1, + dstY, width, + dstU, (width + 1) / 2, + dstV, + (width + 1) / 2, + width, height); + + videoFrame->set_timestamp(timeStamp); + } + + int32_t + FeedMediaCodecInput( + const webrtc::EncodedImage& inputImage, + int64_t renderTimeMs) { + +#ifdef WEBRTC_MEDIACODEC_DEBUG + uint32_t time = PR_IntervalNow(); + CSFLogDebug(logTag, "%s ", __FUNCTION__); +#endif + + int inputIndex = DequeueInputBuffer(DECODER_TIMEOUT); + if (inputIndex == -1) { + CSFLogError(logTag, "%s equeue input buffer failed", __FUNCTION__); + return inputIndex; + } + +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s dequeue input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); + time = PR_IntervalNow(); +#endif + + size_t size = inputImage._length; + + JNIEnv* env = jsjni_GetJNIForThread(); + jobject buffer = env->GetObjectArrayElement(mInputBuffers, inputIndex); + void* directBuffer = env->GetDirectBufferAddress(buffer); + + PodCopy((uint8_t*)directBuffer, inputImage._buffer, size); + + if (inputIndex >= 0) { + CSFLogError(logTag, "%s queue input buffer inputIndex = %d", __FUNCTION__, inputIndex); + QueueInputBuffer(inputIndex, 0, size, renderTimeMs, 0); + + { + if (mOutputDrain == nullptr) { + mOutputDrain = new OutputDrain(this); + mOutputDrain->Start(); + } + EncodedFrame frame; + frame.width_ = mWidth; + frame.height_ = mHeight; + frame.timeStamp_ = inputImage._timeStamp; + frame.decode_timestamp_ = renderTimeMs; + mOutputDrain->QueueInput(frame); + } + env->DeleteLocalRef(buffer); + } + + return inputIndex; + } + + nsresult + DrainOutput(std::queue& aInputFrames, Monitor& aMonitor) { + MOZ_ASSERT(mCoder != nullptr); + if (mCoder == nullptr) { + return NS_ERROR_FAILURE; + } + +#ifdef WEBRTC_MEDIACODEC_DEBUG + uint32_t time = PR_IntervalNow(); +#endif + nsresult res; + BufferInfo::LocalRef bufferInfo; + res = BufferInfo::New(&bufferInfo); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, BufferInfo::New return err = %d", + __FUNCTION__, res); + return res; + } + int32_t outputIndex = DequeueOutputBuffer(bufferInfo); + + if (outputIndex == MediaCodec::INFO_TRY_AGAIN_LATER) { + // Not an error: output not available yet. Try later. + CSFLogDebug(logTag, "%s dequeue output buffer try again:%d", __FUNCTION__, outputIndex); + } else if (outputIndex == MediaCodec::INFO_OUTPUT_FORMAT_CHANGED) { + // handle format change + CSFLogDebug(logTag, "%s dequeue output buffer format changed:%d", __FUNCTION__, outputIndex); + } else if (outputIndex == MediaCodec::INFO_OUTPUT_BUFFERS_CHANGED) { + CSFLogDebug(logTag, "%s dequeue output buffer changed:%d", __FUNCTION__, outputIndex); + GetOutputBuffers(); + } else if (outputIndex < 0) { + CSFLogDebug(logTag, "%s dequeue output buffer unknow error:%d", __FUNCTION__, outputIndex); + MonitorAutoLock lock(aMonitor); + aInputFrames.pop(); + } else { +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s dequeue output buffer# return status is %d took %u ms", __FUNCTION__, outputIndex, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); +#endif + EncodedFrame frame; + { + MonitorAutoLock lock(aMonitor); + frame = aInputFrames.front(); + aInputFrames.pop(); + } + + if (mEnding) { + ReleaseOutputBuffer(outputIndex, false); + return NS_OK; + } + + JNIEnv* env = jsjni_GetJNIForThread(); + jobject buffer = env->GetObjectArrayElement(mOutputBuffers, outputIndex); + if (buffer) { + // The buffer will be null on Android L if we are decoding to a Surface + void* directBuffer = env->GetDirectBufferAddress(buffer); + + int color_format = 0; + + CSFLogDebug(logTag, "%s generate video frame, width = %d, height = %d, timeStamp_ = %d", __FUNCTION__, frame.width_, frame.height_, frame.timeStamp_); + GenerateVideoFrame(frame.width_, frame.height_, frame.timeStamp_, directBuffer, &mVideoFrame, color_format); + mDecoderCallback->Decoded(mVideoFrame); + + ReleaseOutputBuffer(outputIndex, false); + env->DeleteLocalRef(buffer); + } + } + return NS_OK; + } + + int32_t DequeueInputBuffer(int64_t time) { + nsresult res; + int32_t inputIndex; + res = mCoder->DequeueInputBuffer(time, &inputIndex); + + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, mCoder->DequeueInputBuffer() return err = %d", + __FUNCTION__, res); + return -1; + } + return inputIndex; + } + + void QueueInputBuffer(int32_t inputIndex, int32_t offset, size_t size, int64_t renderTimes, int32_t flags) { + nsresult res = NS_OK; + res = mCoder->QueueInputBuffer(inputIndex, offset, size, renderTimes, flags); + + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, mCoder->QueueInputBuffer() return err = %d", + __FUNCTION__, res); + } + } + + int32_t DequeueOutputBuffer(BufferInfo::Param aInfo) { + nsresult res; + + int32_t outputStatus; + res = mCoder->DequeueOutputBuffer(aInfo, DECODER_TIMEOUT, &outputStatus); + + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, mCoder->DequeueOutputBuffer() return err = %d", + __FUNCTION__, res); + return -1; + } + + return outputStatus; + } + + void ReleaseOutputBuffer(int32_t index, bool flag) { + mCoder->ReleaseOutputBuffer(index, flag); + } + + jobjectArray GetInputBuffers() { + JNIEnv* env = jsjni_GetJNIForThread(); + + if (mInputBuffers) { + env->DeleteGlobalRef(mInputBuffers); + } + + nsresult res; + jni::ObjectArray::LocalRef inputBuffers; + res = mCoder->GetInputBuffers(&inputBuffers); + mInputBuffers = (jobjectArray) env->NewGlobalRef(inputBuffers.Get()); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, GetInputBuffers return err = %d", + __FUNCTION__, res); + return nullptr; + } + + return mInputBuffers; + } + + jobjectArray GetOutputBuffers() { + JNIEnv* env = jsjni_GetJNIForThread(); + + if (mOutputBuffers) { + env->DeleteGlobalRef(mOutputBuffers); + } + + nsresult res; + jni::ObjectArray::LocalRef outputBuffers; + res = mCoder->GetOutputBuffers(&outputBuffers); + mOutputBuffers = (jobjectArray) env->NewGlobalRef(outputBuffers.Get()); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcAndroidMediaCodec::%s, GetOutputBuffers return err = %d", + __FUNCTION__, res); + return nullptr; + } + + return mOutputBuffers; + } + + void SetDecoderCallback(webrtc::DecodedImageCallback* aCallback) { + mDecoderCallback = aCallback; + } + + void SetEncoderCallback(webrtc::EncodedImageCallback* aCallback) { + mEncoderCallback = aCallback; + } + +private: +class OutputDrain : public MediaCodecOutputDrain + { + public: + OutputDrain(WebrtcAndroidMediaCodec* aMediaCodec) + : MediaCodecOutputDrain() + , mMediaCodec(aMediaCodec) + {} + + protected: + virtual bool DrainOutput() override + { + return (mMediaCodec->DrainOutput(mInputFrames, mMonitor) == NS_OK); + } + + private: + WebrtcAndroidMediaCodec* mMediaCodec; + }; + + friend class WebrtcMediaCodecVP8VideoEncoder; + friend class WebrtcMediaCodecVP8VideoDecoder; + + MediaCodec::GlobalRef mCoder; + webrtc::EncodedImageCallback* mEncoderCallback; + webrtc::DecodedImageCallback* mDecoderCallback; + webrtc::I420VideoFrame mVideoFrame; + + jobjectArray mInputBuffers; + jobjectArray mOutputBuffers; + + RefPtr mOutputDrain; + uint32_t mWidth; + uint32_t mHeight; + bool isStarted; + bool mEnding; + + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcAndroidMediaCodec) +}; + +static bool I420toNV12(uint8_t* dstY, uint16_t* dstUV, const webrtc::I420VideoFrame& inputImage) { + uint8_t* buffer = dstY; + uint8_t* dst_y = buffer; + int dst_stride_y = inputImage.stride(webrtc::kYPlane); + uint8_t* dst_uv = buffer + inputImage.stride(webrtc::kYPlane) * + inputImage.height(); + int dst_stride_uv = inputImage.stride(webrtc::kUPlane) * 2; + + // Why NV12? Because COLOR_FORMAT_YUV420_SEMIPLANAR. Most hardware is NV12-friendly. + bool converted = !libyuv::I420ToNV12(inputImage.buffer(webrtc::kYPlane), + inputImage.stride(webrtc::kYPlane), + inputImage.buffer(webrtc::kUPlane), + inputImage.stride(webrtc::kUPlane), + inputImage.buffer(webrtc::kVPlane), + inputImage.stride(webrtc::kVPlane), + dst_y, + dst_stride_y, + dst_uv, + dst_stride_uv, + inputImage.width(), + inputImage.height()); + return converted; +} + +// Encoder. +WebrtcMediaCodecVP8VideoEncoder::WebrtcMediaCodecVP8VideoEncoder() + : mTimestamp(0) + , mCallback(nullptr) + , mMediaCodecEncoder(nullptr) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + memset(&mEncodedImage, 0, sizeof(mEncodedImage)); +} + +bool WebrtcMediaCodecVP8VideoEncoder::ResetInputBuffers() { + mInputBuffers = mMediaCodecEncoder->GetInputBuffers(); + + if (!mInputBuffers) + return false; + + return true; +} + +bool WebrtcMediaCodecVP8VideoEncoder::ResetOutputBuffers() { + mOutputBuffers = mMediaCodecEncoder->GetOutputBuffers(); + + if (!mOutputBuffers) + return false; + + return true; +} + +int32_t +WebrtcMediaCodecVP8VideoEncoder::VerifyAndAllocate(const uint32_t minimumSize) +{ + if(minimumSize > mEncodedImage._size) + { + // create buffer of sufficient size + uint8_t* newBuffer = new uint8_t[minimumSize]; + if (newBuffer == nullptr) { + return -1; + } + if(mEncodedImage._buffer) { + // copy old data + memcpy(newBuffer, mEncodedImage._buffer, mEncodedImage._size); + delete [] mEncodedImage._buffer; + } + mEncodedImage._buffer = newBuffer; + mEncodedImage._size = minimumSize; + } + return 0; +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::InitEncode( + const webrtc::VideoCodec* codecSettings, + int32_t numberOfCores, + uint32_t maxPayloadSize) { + mMaxPayloadSize = maxPayloadSize; + CSFLogDebug(logTag, "%s, w = %d, h = %d", __FUNCTION__, codecSettings->width, codecSettings->height); + + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::Encode( + const webrtc::I420VideoFrame& inputImage, + const webrtc::CodecSpecificInfo* codecSpecificInfo, + const std::vector* frame_types) { + CSFLogDebug(logTag, "%s, w = %d, h = %d", __FUNCTION__, inputImage.width(), inputImage.height()); + + if (!mMediaCodecEncoder) { + mMediaCodecEncoder = new WebrtcAndroidMediaCodec(); + } + + if (!mMediaCodecEncoder->isStarted) { + if (inputImage.width() == 0 || inputImage.height() == 0) { + return WEBRTC_VIDEO_CODEC_ERROR; + } else { + mFrameWidth = inputImage.width(); + mFrameHeight = inputImage.height(); + } + + mMediaCodecEncoder->SetEncoderCallback(mCallback); + nsresult res = mMediaCodecEncoder->Configure(mFrameWidth, mFrameHeight, nullptr, MediaCodec::CONFIGURE_FLAG_ENCODE, MEDIACODEC_VIDEO_MIME_VP8, true /* encoder */); + + if (res != NS_OK) { + CSFLogDebug(logTag, "%s, encoder configure return err = %d", + __FUNCTION__, res); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + res = mMediaCodecEncoder->Start(); + + if (NS_FAILED(res)) { + mMediaCodecEncoder->isStarted = false; + CSFLogDebug(logTag, "%s start encoder. err = %d", __FUNCTION__, res); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + bool retBool = ResetInputBuffers(); + if (!retBool) { + CSFLogDebug(logTag, "%s ResetInputBuffers failed.", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + retBool = ResetOutputBuffers(); + if (!retBool) { + CSFLogDebug(logTag, "%s ResetOutputBuffers failed.", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + mMediaCodecEncoder->isStarted = true; + } + +#ifdef WEBRTC_MEDIACODEC_DEBUG + uint32_t time = PR_IntervalNow(); +#endif + + size_t sizeY = inputImage.allocated_size(webrtc::kYPlane); + size_t sizeUV = inputImage.allocated_size(webrtc::kUPlane); + size_t size = sizeY + 2 * sizeUV; + + int inputIndex = mMediaCodecEncoder->DequeueInputBuffer(DECODER_TIMEOUT); + if (inputIndex == -1) { + CSFLogError(logTag, "%s dequeue input buffer failed", __FUNCTION__); + return inputIndex; + } + +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s WebrtcMediaCodecVP8VideoEncoder::Encode() dequeue OMX input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); +#endif + + if (inputIndex >= 0) { + JNIEnv* env = jsjni_GetJNIForThread(); + jobject buffer = env->GetObjectArrayElement(mInputBuffers, inputIndex); + void* directBuffer = env->GetDirectBufferAddress(buffer); + + uint8_t* dstY = static_cast(directBuffer); + uint16_t* dstUV = reinterpret_cast(dstY + sizeY); + + bool converted = I420toNV12(dstY, dstUV, inputImage); + if (!converted) { + CSFLogError(logTag, "%s WebrtcMediaCodecVP8VideoEncoder::Encode() convert input buffer to NV12 error.", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + env->DeleteLocalRef(buffer); + +#ifdef WEBRTC_MEDIACODEC_DEBUG + time = PR_IntervalNow(); + CSFLogError(logTag, "%s queue input buffer inputIndex = %d", __FUNCTION__, inputIndex); +#endif + + mMediaCodecEncoder->QueueInputBuffer(inputIndex, 0, size, inputImage.render_time_ms() * PR_USEC_PER_MSEC /* ms to us */, 0); +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s WebrtcMediaCodecVP8VideoEncoder::Encode() queue input buffer took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); +#endif + mEncodedImage._encodedWidth = inputImage.width(); + mEncodedImage._encodedHeight = inputImage.height(); + mEncodedImage._timeStamp = inputImage.timestamp(); + mEncodedImage.capture_time_ms_ = inputImage.timestamp(); + + nsresult res; + BufferInfo::LocalRef bufferInfo; + res = BufferInfo::New(&bufferInfo); + if (NS_FAILED(res)) { + CSFLogDebug(logTag, "WebrtcMediaCodecVP8VideoEncoder::%s, BufferInfo::New return err = %d", + __FUNCTION__, res); + return -1; + } + + int32_t outputIndex = mMediaCodecEncoder->DequeueOutputBuffer(bufferInfo); + + if (outputIndex == MediaCodec::INFO_TRY_AGAIN_LATER) { + // Not an error: output not available yet. Try later. + CSFLogDebug(logTag, "%s dequeue output buffer try again:%d", __FUNCTION__, outputIndex); + } else if (outputIndex == MediaCodec::INFO_OUTPUT_FORMAT_CHANGED) { + // handle format change + CSFLogDebug(logTag, "%s dequeue output buffer format changed:%d", __FUNCTION__, outputIndex); + } else if (outputIndex == MediaCodec::INFO_OUTPUT_BUFFERS_CHANGED) { + CSFLogDebug(logTag, "%s dequeue output buffer changed:%d", __FUNCTION__, outputIndex); + mMediaCodecEncoder->GetOutputBuffers(); + } else if (outputIndex < 0) { + CSFLogDebug(logTag, "%s dequeue output buffer unknow error:%d", __FUNCTION__, outputIndex); + } else { +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s dequeue output buffer return status is %d took %u ms", __FUNCTION__, outputIndex, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); +#endif + + JNIEnv* env = jsjni_GetJNIForThread(); + jobject buffer = env->GetObjectArrayElement(mOutputBuffers, outputIndex); + if (buffer) { + int32_t offset; + bufferInfo->Offset(&offset); + int32_t flags; + bufferInfo->Flags(&flags); + + // The buffer will be null on Android L if we are decoding to a Surface + void* directBuffer = reinterpret_cast(env->GetDirectBufferAddress(buffer)) + offset; + + if (flags == MediaCodec::BUFFER_FLAG_SYNC_FRAME) { + mEncodedImage._frameType = webrtc::kKeyFrame; + } else { + mEncodedImage._frameType = webrtc::kDeltaFrame; + } + mEncodedImage._completeFrame = true; + + int32_t size; + bufferInfo->Size(&size); +#ifdef WEBRTC_MEDIACODEC_DEBUG + CSFLogDebug(logTag, "%s dequeue output buffer ok, index:%d, buffer size = %d, buffer offset = %d, flags = %d", __FUNCTION__, outputIndex, size, offset, flags); +#endif + + if(VerifyAndAllocate(size) == -1) { + CSFLogDebug(logTag, "%s VerifyAndAllocate buffers failed", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + mEncodedImage._length = size; + + // xxx It's too bad the mediacodec API forces us to memcpy this.... + // we should find a way that able to 'hold' the buffer or transfer it from inputImage (ping-pong + // buffers or select them from a small pool) + memcpy(mEncodedImage._buffer, directBuffer, mEncodedImage._length); + + webrtc::CodecSpecificInfo info; + info.codecType = webrtc::kVideoCodecVP8; + info.codecSpecific.VP8.pictureId = -1; + info.codecSpecific.VP8.tl0PicIdx = -1; + info.codecSpecific.VP8.keyIdx = -1; + info.codecSpecific.VP8.temporalIdx = 1; + + // Generate a header describing a single fragment. + webrtc::RTPFragmentationHeader header; + memset(&header, 0, sizeof(header)); + header.VerifyAndAllocateFragmentationHeader(1); + header.fragmentationLength[0] = mEncodedImage._length; + + mCallback->Encoded(mEncodedImage, &info, &header); + + mMediaCodecEncoder->ReleaseOutputBuffer(outputIndex, false); + env->DeleteLocalRef(buffer); + } + } + } + + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback* callback) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + mCallback = callback; + + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::Release() { + + CSFLogDebug(logTag, "%s ", __FUNCTION__); + delete mMediaCodecEncoder; + mMediaCodecEncoder = nullptr; + + delete [] mEncodedImage._buffer; + mEncodedImage._buffer = nullptr; + mEncodedImage._size = 0; + + return WEBRTC_VIDEO_CODEC_OK; +} + +WebrtcMediaCodecVP8VideoEncoder::~WebrtcMediaCodecVP8VideoEncoder() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + Release(); +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::SetChannelParameters(uint32_t packetLoss, int rtt) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + if (!mMediaCodecEncoder) { + return WEBRTC_VIDEO_CODEC_UNINITIALIZED; + } + + // XXX + // 1. implement MediaCodec's setParameters method + // 2.find a way to initiate a Java Bundle instance as parameter for MediaCodec setParameters method. + // mMediaCodecEncoder->setParameters + + return WEBRTC_VIDEO_CODEC_OK; +} + +// Decoder. +WebrtcMediaCodecVP8VideoDecoder::WebrtcMediaCodecVP8VideoDecoder() + : mCallback(nullptr) + , mFrameWidth(0) + , mFrameHeight(0) + , mMediaCodecDecoder(nullptr) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); +} + +bool WebrtcMediaCodecVP8VideoDecoder::ResetInputBuffers() { + mInputBuffers = mMediaCodecDecoder->GetInputBuffers(); + + if (!mInputBuffers) + return false; + + return true; +} + +bool WebrtcMediaCodecVP8VideoDecoder::ResetOutputBuffers() { + mOutputBuffers = mMediaCodecDecoder->GetOutputBuffers(); + + if (!mOutputBuffers) + return false; + + return true; +} + + +int32_t WebrtcMediaCodecVP8VideoDecoder::InitDecode( + const webrtc::VideoCodec* codecSettings, + int32_t numberOfCores) { + + if (!mMediaCodecDecoder) { + mMediaCodecDecoder = new WebrtcAndroidMediaCodec(); + } + + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoDecoder::Decode( + const webrtc::EncodedImage& inputImage, + bool missingFrames, + const webrtc::RTPFragmentationHeader* fragmentation, + const webrtc::CodecSpecificInfo* codecSpecificInfo, + int64_t renderTimeMs) { + + CSFLogDebug(logTag, "%s, renderTimeMs = %lld ", __FUNCTION__, renderTimeMs); + + if (inputImage._length== 0 || !inputImage._buffer) { + CSFLogDebug(logTag, "%s, input Image invalid. length = %d", __FUNCTION__, inputImage._length); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + if (inputImage._frameType == webrtc::kKeyFrame) { + CSFLogDebug(logTag, "%s, inputImage is Golden frame", + __FUNCTION__); + mFrameWidth = inputImage._encodedWidth; + mFrameHeight = inputImage._encodedHeight; + } + + if (!mMediaCodecDecoder->isStarted) { + if (mFrameWidth == 0 || mFrameHeight == 0) { + return WEBRTC_VIDEO_CODEC_ERROR; + } + + mMediaCodecDecoder->SetDecoderCallback(mCallback); + nsresult res = mMediaCodecDecoder->Configure(mFrameWidth, mFrameHeight, nullptr, 0, MEDIACODEC_VIDEO_MIME_VP8, false /* decoder */); + + if (res != NS_OK) { + CSFLogDebug(logTag, "%s, decoder configure return err = %d", + __FUNCTION__, res); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + res = mMediaCodecDecoder->Start(); + + if (NS_FAILED(res)) { + mMediaCodecDecoder->isStarted = false; + CSFLogDebug(logTag, "%s start decoder. err = %d", __FUNCTION__, res); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + bool retBool = ResetInputBuffers(); + if (!retBool) { + CSFLogDebug(logTag, "%s ResetInputBuffers failed.", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + retBool = ResetOutputBuffers(); + if (!retBool) { + CSFLogDebug(logTag, "%s ResetOutputBuffers failed.", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_ERROR; + } + + mMediaCodecDecoder->isStarted = true; + } +#ifdef WEBRTC_MEDIACODEC_DEBUG + uint32_t time = PR_IntervalNow(); + CSFLogDebug(logTag, "%s start decoder took %u ms", __FUNCTION__, PR_IntervalToMilliseconds(PR_IntervalNow()-time)); +#endif + + bool feedFrame = true; + int32_t ret = WEBRTC_VIDEO_CODEC_ERROR; + + while (feedFrame) { + ret = mMediaCodecDecoder->FeedMediaCodecInput(inputImage, renderTimeMs); + feedFrame = (ret == -1); + } + + CSFLogDebug(logTag, "%s end, ret = %d", __FUNCTION__, ret); + + return ret; +} + +void WebrtcMediaCodecVP8VideoDecoder::DecodeFrame(EncodedFrame* frame) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); +} + +int32_t WebrtcMediaCodecVP8VideoDecoder::RegisterDecodeCompleteCallback(webrtc::DecodedImageCallback* callback) { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + mCallback = callback; + return WEBRTC_VIDEO_CODEC_OK; +} + +int32_t WebrtcMediaCodecVP8VideoDecoder::Release() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + delete mMediaCodecDecoder; + mMediaCodecDecoder = nullptr; + + return WEBRTC_VIDEO_CODEC_OK; +} + +WebrtcMediaCodecVP8VideoDecoder::~WebrtcMediaCodecVP8VideoDecoder() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + + Release(); +} + +int32_t WebrtcMediaCodecVP8VideoDecoder::Reset() { + CSFLogDebug(logTag, "%s ", __FUNCTION__); + return WEBRTC_VIDEO_CODEC_OK; +} + +} diff --git a/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h new file mode 100644 index 0000000000..72688e8403 --- /dev/null +++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaCodecVP8VideoCodec.h @@ -0,0 +1,114 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WebrtcMediaCodecVP8VideoCodec_h__ +#define WebrtcMediaCodecVP8VideoCodec_h__ + +#include "mozilla/Mutex.h" +#include "nsThreadUtils.h" +#include "nsAutoPtr.h" + +#include "MediaConduitInterface.h" +#include "AudioConduit.h" +#include "VideoConduit.h" + +namespace mozilla { + +struct EncodedFrame { + uint32_t width_; + uint32_t height_; + uint32_t timeStamp_; + uint64_t decode_timestamp_; +}; + +class WebrtcAndroidMediaCodec; + +class WebrtcMediaCodecVP8VideoEncoder : public WebrtcVideoEncoder { +public: + WebrtcMediaCodecVP8VideoEncoder(); + + virtual ~WebrtcMediaCodecVP8VideoEncoder() override; + + // Implement VideoEncoder interface. + virtual const uint64_t PluginID() override { return 0; } + + virtual int32_t InitEncode(const webrtc::VideoCodec* codecSettings, + int32_t numberOfCores, + uint32_t maxPayloadSize) override; + + virtual int32_t Encode(const webrtc::I420VideoFrame& inputImage, + const webrtc::CodecSpecificInfo* codecSpecificInfo, + const std::vector* frame_types) override; + + virtual int32_t RegisterEncodeCompleteCallback(webrtc::EncodedImageCallback* callback) override; + + virtual int32_t Release() override; + + virtual int32_t SetChannelParameters(uint32_t packetLoss, int rtt) override; + + virtual int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override; + +private: + int32_t VerifyAndAllocate(const uint32_t minimumSize); + bool ResetInputBuffers(); + bool ResetOutputBuffers(); + + size_t mMaxPayloadSize; + uint32_t mTimestamp; + webrtc::EncodedImage mEncodedImage; + webrtc::EncodedImageCallback* mCallback; + uint32_t mFrameWidth; + uint32_t mFrameHeight; + + WebrtcAndroidMediaCodec* mMediaCodecEncoder; + + jobjectArray mInputBuffers; + jobjectArray mOutputBuffers; +}; + +class WebrtcMediaCodecVP8VideoDecoder : public WebrtcVideoDecoder { +public: + WebrtcMediaCodecVP8VideoDecoder(); + + virtual ~WebrtcMediaCodecVP8VideoDecoder() override; + + // Implement VideoDecoder interface. + virtual const uint64_t PluginID() override { return 0; } + + virtual int32_t InitDecode(const webrtc::VideoCodec* codecSettings, + int32_t numberOfCores) override; + + virtual int32_t Decode(const webrtc::EncodedImage& inputImage, + bool missingFrames, + const webrtc::RTPFragmentationHeader* fragmentation, + const webrtc::CodecSpecificInfo* + codecSpecificInfo = NULL, + int64_t renderTimeMs = -1) override; + + virtual int32_t RegisterDecodeCompleteCallback(webrtc::DecodedImageCallback* callback) override; + + virtual int32_t Release() override; + + virtual int32_t Reset() override; + +private: + void DecodeFrame(EncodedFrame* frame); + void RunCallback(); + bool ResetInputBuffers(); + bool ResetOutputBuffers(); + + webrtc::DecodedImageCallback* mCallback; + + uint32_t mFrameWidth; + uint32_t mFrameHeight; + + WebrtcAndroidMediaCodec* mMediaCodecDecoder; + jobjectArray mInputBuffers; + jobjectArray mOutputBuffers; + +}; + +} + +#endif // WebrtcMediaCodecVP8VideoCodec_h__ diff --git a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp index 2d753e8af7..df063637fb 100644 --- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp +++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp @@ -3,6 +3,8 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "logging.h" +#include "nsIGfxInfo.h" +#include "nsServiceManagerUtils.h" #include "PeerConnectionImpl.h" #include "PeerConnectionMedia.h" @@ -30,6 +32,14 @@ #include "OMXCodecWrapper.h" #endif +#ifdef MOZ_WEBRTC_MEDIACODEC +#include "MediaCodecVideoCodec.h" +#endif + +#ifdef MOZILLA_INTERNAL_API +#include "mozilla/Preferences.h" +#endif + #include namespace mozilla { @@ -864,7 +874,63 @@ MediaPipelineFactory::EnsureExternalCodec(VideoSessionConduit& aConduit, VideoCodecConfig* aConfig, bool aIsSend) { - if (aConfig->mName == "VP8" || aConfig->mName == "VP9") { + if (aConfig->mName == "VP8") { +#ifdef MOZ_WEBRTC_MEDIACODEC + if (aIsSend) { +#ifdef MOZILLA_INTERNAL_API + bool enabled = mozilla::Preferences::GetBool("media.navigator.hardware.vp8_encode.acceleration_enabled", false); +#else + bool enabled = false; +#endif + if (enabled) { + nsCOMPtr gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); + if (gfxInfo) { + int32_t status; + if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION, &status))) { + if (status != nsIGfxInfo::FEATURE_STATUS_OK) { + NS_WARNING("VP8 encoder hardware is not whitelisted: disabling.\n"); + } else { + VideoEncoder* encoder = nullptr; + encoder = MediaCodecVideoCodec::CreateEncoder(MediaCodecVideoCodec::CodecType::CODEC_VP8); + if (encoder) { + return aConduit.SetExternalSendCodec(aConfig, encoder); + } else { + return kMediaConduitNoError; + } + } + } + } + } + } else { +#ifdef MOZILLA_INTERNAL_API + bool enabled = mozilla::Preferences::GetBool("media.navigator.hardware.vp8_decode.acceleration_enabled", false); +#else + bool enabled = false; +#endif + if (enabled) { + nsCOMPtr gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); + if (gfxInfo) { + int32_t status; + if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_WEBRTC_HW_ACCELERATION, &status))) { + if (status != nsIGfxInfo::FEATURE_STATUS_OK) { + NS_WARNING("VP8 decoder hardware is not whitelisted: disabling.\n"); + } else { + + VideoDecoder* decoder; + decoder = MediaCodecVideoCodec::CreateDecoder(MediaCodecVideoCodec::CodecType::CODEC_VP8); + if (decoder) { + return aConduit.SetExternalRecvCodec(aConfig, decoder); + } else { + return kMediaConduitNoError; + } + } + } + } + } + } +#endif + return kMediaConduitNoError; + } else if (aConfig->mName == "VP9") { return kMediaConduitNoError; } else if (aConfig->mName == "H264") { if (aConduit.CodecPluginID() != 0) { diff --git a/media/webrtc/trunk/webrtc/system_wrappers/source/critical_section_win.cc b/media/webrtc/trunk/webrtc/system_wrappers/source/critical_section_win.cc new file mode 100644 index 0000000000..46f2ecdb9f --- /dev/null +++ b/media/webrtc/trunk/webrtc/system_wrappers/source/critical_section_win.cc @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include "critical_section_win.h" +namespace webrtc { +CriticalSectionWindows::CriticalSectionWindows() +{ + InitializeCriticalSection(&crit); +} +CriticalSectionWindows::~CriticalSectionWindows() +{ + DeleteCriticalSection(&crit); +} +void +CriticalSectionWindows::Enter() +{ + EnterCriticalSection(&crit); +} +void +CriticalSectionWindows::Leave() +{ + LeaveCriticalSection(&crit); +} +} // namespace webrtc \ No newline at end of file diff --git a/view/nsViewManager.cpp b/view/nsViewManager.cpp index b503005fdf..8c6df92860 100644 --- a/view/nsViewManager.cpp +++ b/view/nsViewManager.cpp @@ -753,8 +753,8 @@ nsViewManager::DispatchEvent(WidgetGUIEvent *aEvent, // Ignore mouse exit and enter (we'll get moves if the user // is really moving the mouse) since we get them when we // create and destroy widgets. - mouseEvent->mMessage != NS_MOUSE_EXIT_WIDGET && - mouseEvent->mMessage != NS_MOUSE_ENTER_WIDGET) || + mouseEvent->mMessage != eMouseExitFromWidget && + mouseEvent->mMessage != eMouseEnterIntoWidget) || aEvent->HasKeyEventMessage() || aEvent->HasIMEEventMessage() || aEvent->mMessage == NS_PLUGIN_INPUT_EVENT) { diff --git a/widget/EventMessageList.h b/widget/EventMessageList.h index aa66e73e3d..5496fdb5de 100644 --- a/widget/EventMessageList.h +++ b/widget/EventMessageList.h @@ -46,17 +46,18 @@ NS_EVENT_MESSAGE(eOnline, eWindowEventFirst + 65) NS_EVENT_MESSAGE(eLanguageChange, eWindowEventFirst + 70) NS_EVENT_MESSAGE(eMouseEventFirst, 300) -NS_EVENT_MESSAGE(NS_MOUSE_MOVE, eMouseEventFirst) -NS_EVENT_MESSAGE(NS_MOUSE_BUTTON_UP, eMouseEventFirst + 1) -NS_EVENT_MESSAGE(NS_MOUSE_BUTTON_DOWN, eMouseEventFirst + 2) -NS_EVENT_MESSAGE(NS_MOUSE_ENTER_WIDGET, eMouseEventFirst + 22) -NS_EVENT_MESSAGE(NS_MOUSE_EXIT_WIDGET, eMouseEventFirst + 23) -NS_EVENT_MESSAGE(NS_MOUSE_DOUBLECLICK, eMouseEventFirst + 24) -NS_EVENT_MESSAGE(NS_MOUSE_CLICK, eMouseEventFirst + 27) -NS_EVENT_MESSAGE(NS_MOUSE_ACTIVATE, eMouseEventFirst + 30) -NS_EVENT_MESSAGE(NS_MOUSE_OVER, eMouseEventFirst + 31) -NS_EVENT_MESSAGE(NS_MOUSE_OUT, eMouseEventFirst + 32) -NS_EVENT_MESSAGE(NS_MOUSE_MOZHITTEST, eMouseEventFirst + 33) +NS_EVENT_MESSAGE(eMouseMove, eMouseEventFirst) +NS_EVENT_MESSAGE(eMouseUp, eMouseEventFirst + 1) +NS_EVENT_MESSAGE(eMouseDown, eMouseEventFirst + 2) +NS_EVENT_MESSAGE(eMouseEnterIntoWidget, eMouseEventFirst + 22) +NS_EVENT_MESSAGE(eMouseExitFromWidget, eMouseEventFirst + 23) +NS_EVENT_MESSAGE(eMouseDoubleClick, eMouseEventFirst + 24) +NS_EVENT_MESSAGE(eMouseClick, eMouseEventFirst + 27) +// eMouseActivate is fired when the widget is activated by a click. +NS_EVENT_MESSAGE(eMouseActivate, eMouseEventFirst + 30) +NS_EVENT_MESSAGE(eMouseOver, eMouseEventFirst + 31) +NS_EVENT_MESSAGE(eMouseOut, eMouseEventFirst + 32) +NS_EVENT_MESSAGE(eMouseHitTest, eMouseEventFirst + 33) NS_EVENT_MESSAGE(NS_MOUSEENTER, eMouseEventFirst + 34) NS_EVENT_MESSAGE(NS_MOUSELEAVE, eMouseEventFirst + 35) NS_EVENT_MESSAGE(NS_MOUSE_MOZLONGTAP, eMouseEventFirst + 36) diff --git a/widget/InputData.cpp b/widget/InputData.cpp index 0645562314..755e438ed9 100644 --- a/widget/InputData.cpp +++ b/widget/InputData.cpp @@ -125,14 +125,14 @@ MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const EventMessage mouseEventMessage = eVoidEvent; switch (mType) { case MultiTouchInput::MULTITOUCH_START: - mouseEventMessage = NS_MOUSE_BUTTON_DOWN; + mouseEventMessage = eMouseDown; break; case MultiTouchInput::MULTITOUCH_MOVE: - mouseEventMessage = NS_MOUSE_MOVE; + mouseEventMessage = eMouseMove; break; case MultiTouchInput::MULTITOUCH_CANCEL: case MultiTouchInput::MULTITOUCH_END: - mouseEventMessage = NS_MOUSE_BUTTON_UP; + mouseEventMessage = eMouseUp; break; default: MOZ_ASSERT_UNREACHABLE("Did not assign a type to WidgetMouseEvent"); @@ -151,7 +151,7 @@ MultiTouchInput::ToWidgetMouseEvent(nsIWidget* aWidget) const event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH; event.modifiers = modifiers; - if (mouseEventMessage != NS_MOUSE_MOVE) { + if (mouseEventMessage != eMouseMove) { event.clickCount = 1; } @@ -182,20 +182,20 @@ MultiTouchInput::MultiTouchInput(const WidgetMouseEvent& aMouseEvent) MOZ_ASSERT(NS_IsMainThread(), "Can only copy from WidgetMouseEvent on main thread"); switch (aMouseEvent.mMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: mType = MULTITOUCH_START; break; - case NS_MOUSE_MOVE: + case eMouseMove: mType = MULTITOUCH_MOVE; break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: mType = MULTITOUCH_END; break; // The mouse pointer has been interrupted in an implementation-specific // manner, such as a synchronous event or action cancelling the touch, or a // touch point leaving the document window and going into a non-document // area capable of handling user interactions. - case NS_MOUSE_EXIT_WIDGET: + case eMouseExitFromWidget: mType = MULTITOUCH_CANCEL; break; default: diff --git a/widget/MouseEvents.h b/widget/MouseEvents.h index 1081a1255e..b8c6c7a15f 100644 --- a/widget/MouseEvents.h +++ b/widget/MouseEvents.h @@ -155,7 +155,7 @@ public: */ bool IsLeftClickEvent() const { - return mMessage == NS_MOUSE_CLICK && button == eLeftButton; + return mMessage == eMouseClick && button == eLeftButton; } }; diff --git a/widget/WidgetEventImpl.cpp b/widget/WidgetEventImpl.cpp index 3bc59a080b..ed9a958b9f 100644 --- a/widget/WidgetEventImpl.cpp +++ b/widget/WidgetEventImpl.cpp @@ -78,17 +78,17 @@ bool WidgetEvent::HasMouseEventMessage() const { switch (mMessage) { - case NS_MOUSE_BUTTON_DOWN: - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_CLICK: - case NS_MOUSE_DOUBLECLICK: - case NS_MOUSE_ENTER_WIDGET: - case NS_MOUSE_EXIT_WIDGET: - case NS_MOUSE_ACTIVATE: - case NS_MOUSE_OVER: - case NS_MOUSE_OUT: - case NS_MOUSE_MOZHITTEST: - case NS_MOUSE_MOVE: + case eMouseDown: + case eMouseUp: + case eMouseClick: + case eMouseDoubleClick: + case eMouseEnterIntoWidget: + case eMouseExitFromWidget: + case eMouseActivate: + case eMouseOver: + case eMouseOut: + case eMouseHitTest: + case eMouseMove: return true; default: return false; diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 4e9e9b65a2..dc04e0c8bb 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -4496,7 +4496,7 @@ NSEvent* gLastDragMouseDownEvent = nil; NSUInteger modifierFlags = [theEvent modifierFlags]; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseDown, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; @@ -4530,7 +4530,7 @@ NSEvent* gLastDragMouseDownEvent = nil; nsAutoRetainCocoaObject kungFuDeathGrip(self); - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseUp, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; if ([theEvent modifierFlags] & NSControlKeyMask) @@ -4571,7 +4571,7 @@ NSEvent* gLastDragMouseDownEvent = nil; NSPoint windowEventLocation = nsCocoaUtils::EventLocationForWindow(aEvent, [self window]); NSPoint localEventLocation = [self convertPoint:windowEventLocation fromView:nil]; - EventMessage msg = aEnter ? NS_MOUSE_ENTER_WIDGET : NS_MOUSE_EXIT_WIDGET; + EventMessage msg = aEnter ? eMouseEnterIntoWidget : eMouseExitFromWidget; WidgetMouseEvent event(true, msg, mGeckoChild, WidgetMouseEvent::eReal); event.refPoint = LayoutDeviceIntPoint::FromUntyped( mGeckoChild->CocoaPointsToDevPixels(localEventLocation)); @@ -4662,7 +4662,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseMove, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; @@ -4680,7 +4680,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, gLastDragView = self; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseMove, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; @@ -4706,7 +4706,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, return; // The right mouse went down, fire off a right mouse down event to gecko - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseDown, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eRightButton; @@ -4729,7 +4729,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseUp, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eRightButton; @@ -4746,7 +4746,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseMove, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eRightButton; @@ -4769,7 +4769,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseDown, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eMiddleButton; @@ -4785,7 +4785,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseUp, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eMiddleButton; @@ -4799,7 +4799,7 @@ NewCGSRegionFromRegion(const nsIntRegion& aRegion, if (!mGeckoChild) return; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseMove, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent]; geckoEvent.button = WidgetMouseEvent::eMiddleButton; @@ -5590,7 +5590,7 @@ PanGestureTypeForEvent(NSEvent* aEvent) if (!mGeckoChild) return YES; - WidgetMouseEvent geckoEvent(true, NS_MOUSE_ACTIVATE, mGeckoChild, + WidgetMouseEvent geckoEvent(true, eMouseActivate, mGeckoChild, WidgetMouseEvent::eReal); [self convertCocoaMouseEvent:aEvent toGeckoEvent:&geckoEvent]; return (mGeckoChild->DispatchInputEvent(&geckoEvent) != nsEventStatus_eConsumeNoDefault); diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index cdcf0e513b..0e0478ba14 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -2375,7 +2375,8 @@ nsWindow::OnEnterNotifyEvent(GdkEventCrossing *aEvent) if (is_parent_ungrab_enter(aEvent)) return; - WidgetMouseEvent event(true, NS_MOUSE_ENTER_WIDGET, this, WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseEnterIntoWidget, this, + WidgetMouseEvent::eReal); event.refPoint.x = nscoord(aEvent->x); event.refPoint.y = nscoord(aEvent->y); @@ -2416,7 +2417,8 @@ nsWindow::OnLeaveNotifyEvent(GdkEventCrossing *aEvent) if (aEvent->subwindow != nullptr) return; - WidgetMouseEvent event(true, NS_MOUSE_EXIT_WIDGET, this, WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseExitFromWidget, this, + WidgetMouseEvent::eReal); event.refPoint.x = nscoord(aEvent->x); event.refPoint.y = nscoord(aEvent->y); @@ -2463,7 +2465,7 @@ nsWindow::OnMotionNotifyEvent(GdkEventMotion *aEvent) } #endif /* MOZ_X11 */ - WidgetMouseEvent event(true, NS_MOUSE_MOVE, this, WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseMove, this, WidgetMouseEvent::eReal); gdouble pressure = 0; gdk_event_get_axis ((GdkEvent*)aEvent, GDK_AXIS_PRESSURE, &pressure); @@ -2556,7 +2558,7 @@ nsWindow::DispatchMissedButtonReleases(GdkEventCrossing *aGdkEvent) // change in state. This event is marked as synthesized so that // it is not dispatched as a DOM event, because we don't know the // position, widget, modifiers, or time/order. - WidgetMouseEvent synthEvent(true, NS_MOUSE_BUTTON_UP, this, + WidgetMouseEvent synthEvent(true, eMouseUp, this, WidgetMouseEvent::eSynthesized); synthEvent.button = buttonType; DispatchInputEvent(&synthEvent); @@ -2581,7 +2583,7 @@ nsWindow::InitButtonEvent(WidgetMouseEvent& aEvent, guint modifierState = aGdkEvent->state; // aEvent's state doesn't include this event's information. Therefore, // if aEvent is mouse button down event, we need to set it manually. - // Note that we cannot do same thing for NS_MOUSE_BUTTON_UP because + // Note that we cannot do same thing for eMouseUp because // system may have two or more mice and same button of another mouse // may be still pressed. if (aGdkEvent->type != GDK_BUTTON_RELEASE) { @@ -2681,8 +2683,7 @@ nsWindow::OnButtonPressEvent(GdkEventButton *aEvent) gButtonState |= ButtonMaskFromGDKButton(aEvent->button); - WidgetMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, - WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseDown, this, WidgetMouseEvent::eReal); event.button = domButton; InitButtonEvent(event, aEvent); event.pressure = mLastMotionPressure; @@ -2722,7 +2723,7 @@ nsWindow::OnButtonReleaseEvent(GdkEventButton *aEvent) gButtonState &= ~ButtonMaskFromGDKButton(aEvent->button); - WidgetMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, + WidgetMouseEvent event(true, eMouseUp, this, WidgetMouseEvent::eReal); event.button = domButton; InitButtonEvent(event, aEvent); diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 40464b980b..eb7bdc4975 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -2618,13 +2618,13 @@ case _value: eventName.AssignLiteral(_name) ; break _ASSIGN_eventName(eKeyDown,"eKeyDown"); _ASSIGN_eventName(eKeyPress,"eKeyPress"); _ASSIGN_eventName(eKeyUp,"eKeyUp"); - _ASSIGN_eventName(NS_MOUSE_ENTER_WIDGET,"NS_MOUSE_ENTER_WIDGET"); - _ASSIGN_eventName(NS_MOUSE_EXIT_WIDGET,"NS_MOUSE_EXIT_WIDGET"); - _ASSIGN_eventName(NS_MOUSE_BUTTON_DOWN,"NS_MOUSE_BUTTON_DOWN"); - _ASSIGN_eventName(NS_MOUSE_BUTTON_UP,"NS_MOUSE_BUTTON_UP"); - _ASSIGN_eventName(NS_MOUSE_CLICK,"NS_MOUSE_CLICK"); - _ASSIGN_eventName(NS_MOUSE_DOUBLECLICK,"NS_MOUSE_DBLCLICK"); - _ASSIGN_eventName(NS_MOUSE_MOVE,"NS_MOUSE_MOVE"); + _ASSIGN_eventName(eMouseEnterIntoWidget,"eMouseEnterIntoWidget"); + _ASSIGN_eventName(eMouseExitFromWidget,"eMouseExitFromWidget"); + _ASSIGN_eventName(eMouseDown,"eMouseDown"); + _ASSIGN_eventName(eMouseUp,"eMouseUp"); + _ASSIGN_eventName(eMouseClick,"eMouseClick"); + _ASSIGN_eventName(eMouseDoubleClick,"eMouseDoubleClick"); + _ASSIGN_eventName(eMouseMove,"eMouseMove"); _ASSIGN_eventName(NS_LOAD,"NS_LOAD"); _ASSIGN_eventName(NS_POPSTATE,"NS_POPSTATE"); _ASSIGN_eventName(NS_BEFORE_SCRIPT_EXECUTE,"NS_BEFORE_SCRIPT_EXECUTE"); @@ -2773,13 +2773,13 @@ nsBaseWidget::debug_DumpEvent(FILE * aFileOut, const nsAutoCString & aWidgetName, int32_t aWindowID) { - if (aGuiEvent->mMessage == NS_MOUSE_MOVE) { + if (aGuiEvent->mMessage == eMouseMove) { if (!debug_GetCachedBoolPref("nglayout.debug.motion_event_dumping")) return; } - if (aGuiEvent->mMessage == NS_MOUSE_ENTER_WIDGET || - aGuiEvent->mMessage == NS_MOUSE_EXIT_WIDGET) { + if (aGuiEvent->mMessage == eMouseEnterIntoWidget || + aGuiEvent->mMessage == eMouseExitFromWidget) { if (!debug_GetCachedBoolPref("nglayout.debug.crossing_event_dumping")) return; } diff --git a/widget/qt/nsWindow.cpp b/widget/qt/nsWindow.cpp index 2d9692a1cd..d384797a2f 100644 --- a/widget/qt/nsWindow.cpp +++ b/widget/qt/nsWindow.cpp @@ -999,8 +999,7 @@ nsWindow::mousePressEvent(QMouseEvent* aEvent) return nsEventStatus_eIgnore; } - WidgetMouseEvent event(true, NS_MOUSE_BUTTON_DOWN, this, - WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseDown, this, WidgetMouseEvent::eReal); InitMouseEvent(event, aEvent, 1); nsEventStatus status = DispatchEvent(&event); @@ -1025,8 +1024,7 @@ nsWindow::mouseReleaseEvent(QMouseEvent* aEvent) if (!IsAcceptedButton(aEvent->button())) return nsEventStatus_eIgnore; - WidgetMouseEvent event(true, NS_MOUSE_BUTTON_UP, this, - WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseUp, this, WidgetMouseEvent::eReal); InitMouseEvent(event, aEvent, 1); return DispatchEvent(&event); } @@ -1040,7 +1038,7 @@ nsWindow::mouseDoubleClickEvent(QMouseEvent* aEvent) if (!IsAcceptedButton(aEvent->button())) return nsEventStatus_eIgnore; - WidgetMouseEvent event(true, NS_MOUSE_DOUBLECLICK, this, + WidgetMouseEvent event(true, eMouseDoubleClick, this, WidgetMouseEvent::eReal); InitMouseEvent(event, aEvent, 2); return DispatchEvent(&event); @@ -1964,8 +1962,7 @@ void nsWindow::ProcessMotionEvent() { if (mMoveEvent.needDispatch) { - WidgetMouseEvent event(true, NS_MOUSE_MOVE, this, - WidgetMouseEvent::eReal); + WidgetMouseEvent event(true, eMouseMove, this, WidgetMouseEvent::eReal); event.refPoint.x = nscoord(mMoveEvent.pos.x()); event.refPoint.y = nscoord(mMoveEvent.pos.y()); diff --git a/widget/uikit/nsWindow.mm b/widget/uikit/nsWindow.mm index 29e8fc9d0d..d53b40f17a 100644 --- a/widget/uikit/nsWindow.mm +++ b/widget/uikit/nsWindow.mm @@ -158,9 +158,9 @@ private: if (sender.state == UIGestureRecognizerStateEnded) { ALOG("[ChildView[%p] handleTap]", self); LayoutDeviceIntPoint lp = UIKitPointsToDevPixels([sender locationInView:self], [self contentScaleFactor]); - [self sendMouseEvent:NS_MOUSE_MOVE point:lp widget:mGeckoChild]; - [self sendMouseEvent:NS_MOUSE_BUTTON_DOWN point:lp widget:mGeckoChild]; - [self sendMouseEvent:NS_MOUSE_BUTTON_UP point:lp widget:mGeckoChild]; + [self sendMouseEvent:eMouseMove point:lp widget:mGeckoChild]; + [self sendMouseEvent:eMouseDown point:lp widget:mGeckoChild]; + [self sendMouseEvent:eMouseUp point:lp widget:mGeckoChild]; } } diff --git a/widget/windows/IMMHandler.cpp b/widget/windows/IMMHandler.cpp index 80660db5cb..7f37c8c86f 100644 --- a/widget/windows/IMMHandler.cpp +++ b/widget/windows/IMMHandler.cpp @@ -2601,8 +2601,7 @@ IMMHandler::OnMouseButtonEvent(nsWindow* aWindow, } // We need to handle only mousedown event. - if (aIMENotification.mMouseButtonEventData.mEventMessage != - NS_MOUSE_BUTTON_DOWN) { + if (aIMENotification.mMouseButtonEventData.mEventMessage != eMouseDown) { return NS_OK; } diff --git a/widget/windows/TSFTextStore.cpp b/widget/windows/TSFTextStore.cpp index 16c003b994..fb9a188d0c 100644 --- a/widget/windows/TSFTextStore.cpp +++ b/widget/windows/TSFTextStore.cpp @@ -538,10 +538,10 @@ static const char* GetEventMessageName(uint32_t aMessage) { switch (aMessage) { - case NS_MOUSE_BUTTON_DOWN: - return "NS_MOUSE_BUTTON_DOWN"; - case NS_MOUSE_BUTTON_UP: - return "NS_MOUSE_BUTTON_UP"; + case eMouseDown: + return "eMouseDown"; + case eMouseUp: + return "eMouseUp"; default: return "Unknown"; } @@ -4724,7 +4724,7 @@ TSFTextStore::OnMouseButtonEventInternal( ULONG edge = quadrant < 2 ? offset + 1 : offset; DWORD buttonStatus = 0; bool isMouseUp = - aIMENotification.mMouseButtonEventData.mEventMessage == NS_MOUSE_BUTTON_UP; + aIMENotification.mMouseButtonEventData.mEventMessage == eMouseUp; if (!isMouseUp) { switch (aIMENotification.mMouseButtonEventData.mButton) { case WidgetMouseEventBase::eLeftButton: diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp index 301c6abe72..3386a4e00b 100644 --- a/widget/windows/WinUtils.cpp +++ b/widget/windows/WinUtils.cpp @@ -945,10 +945,10 @@ WinUtils::GetIsMouseFromTouch(EventMessage aEventMessage) { const uint32_t MOZ_T_I_SIGNATURE = TABLET_INK_TOUCH | TABLET_INK_SIGNATURE; const uint32_t MOZ_T_I_CHECK_TCH = TABLET_INK_TOUCH | TABLET_INK_CHECK; - return ((aEventMessage == NS_MOUSE_MOVE || - aEventMessage == NS_MOUSE_BUTTON_DOWN || - aEventMessage == NS_MOUSE_BUTTON_UP || - aEventMessage == NS_MOUSE_DOUBLECLICK) && + return ((aEventMessage == eMouseMove || + aEventMessage == eMouseDown || + aEventMessage == eMouseUp || + aEventMessage == eMouseDoubleClick) && (GetMessageExtraInfo() & MOZ_T_I_SIGNATURE) == MOZ_T_I_CHECK_TCH); } diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 25b4a9ef4f..1e079cbf21 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -987,6 +987,12 @@ nsIWidget* nsWindow::GetParent(void) return GetParentWindow(false); } +static int32_t RoundDown(double aDouble) +{ + return aDouble > 0 ? static_cast(floor(aDouble)) : + static_cast(ceil(aDouble)); +} + float nsWindow::GetDPI() { HDC dc = ::GetDC(mWnd); @@ -2666,6 +2672,23 @@ void nsWindow::UpdateOpaqueRegion(const nsIntRegion &aOpaqueRegion) } } +/************************************************************** +* +* SECTION: nsIWidget::UpdateWindowDraggingRegion +* +* For setting the draggable titlebar region from CSS +* with -moz-window-dragging: drag. +* +**************************************************************/ + +void +nsWindow::UpdateWindowDraggingRegion(const nsIntRegion& aRegion) +{ + if (mDraggableRegion != aRegion) { + mDraggableRegion = aRegion; + } +} + void nsWindow::UpdateGlass() { MARGINS margins = mGlassMargins; @@ -3518,29 +3541,28 @@ nsWindow::UpdateThemeGeometries(const nsTArray& aThemeGeometries) if (!layerManager) { return; } - + nsIntRegion clearRegion; - // No glass or compositor -> classic metrics, so return. if (!HasGlass() || !nsUXThemeData::CheckForCompositor()) { // Make sure and clear old regions we've set previously. Note HasGlass can be false // for glass desktops if the window we are rendering to doesn't make use of glass // (e.g. fullscreen browsing). - layerManager->SetRegionToClear(clearRegion); + layerManager->SetRegionToClear(clearRegion); return; } - // On Win10, force show the top border on normal windows: + // On Win10, force show the top border: if (IsWin10OrLater() && mCustomNonClient && mSizeMode == nsSizeMode_Normal) { RECT rect; ::GetWindowRect(mWnd, &rect); - clearRegion.Or(clearRegion, nsIntRect(0, 0, rect.right - rect.left, 1.0)); + // We want 1 pixel of border for every whole 100% of scaling + double borderSize = RoundDown(GetDefaultScale().scale); + clearRegion.Or(clearRegion, nsIntRect(0, 0, rect.right - rect.left, borderSize)); } - - // We draw our own buttons on Win10 or later. Prevent the windows cutout for events. + if (!IsWin10OrLater()) { for (size_t i = 0; i < aThemeGeometries.Length(); i++) { - if (aThemeGeometries[i].mType == nsNativeThemeWin::eThemeGeometryTypeWindowButtons) - { + if (aThemeGeometries[i].mType == nsNativeThemeWin::eThemeGeometryTypeWindowButtons) { nsIntRect bounds = aThemeGeometries[i].mRect; clearRegion.Or(clearRegion, nsIntRect(bounds.X(), bounds.Y(), bounds.Width(), bounds.Height() - 2.0)); clearRegion.Or(clearRegion, nsIntRect(bounds.X() + 1.0, bounds.YMost() - 2.0, bounds.Width() - 1.0, 1.0)); @@ -3791,15 +3813,16 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, } switch (aEventMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: CaptureMouse(true); break; - // NS_MOUSE_MOVE and NS_MOUSE_EXIT_WIDGET are here because we need to make sure capture flag - // isn't left on after a drag where we wouldn't see a button up message (see bug 324131). - case NS_MOUSE_BUTTON_UP: - case NS_MOUSE_MOVE: - case NS_MOUSE_EXIT_WIDGET: + // eMouseMove and eMouseExitFromWidget are here because we need to make + // sure capture flag isn't left on after a drag where we wouldn't see a + // button up message (see bug 324131). + case eMouseUp: + case eMouseMove: + case eMouseExitFromWidget: if (!(wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)) && sIsInMouseCapture) CaptureMouse(false); break; @@ -3834,7 +3857,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, nsIntPoint mpScreen = eventPoint + WidgetToScreenOffsetUntyped(); // Suppress mouse moves caused by widget creation - if (aEventMessage == NS_MOUSE_MOVE) { + if (aEventMessage == eMouseMove) { if ((sLastMouseMovePoint.x == mpScreen.x) && (sLastMouseMovePoint.y == mpScreen.y)) return result; sLastMouseMovePoint.x = mpScreen.x; @@ -3865,19 +3888,19 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, LONG curMsgTime = ::GetMessageTime(); switch (aEventMessage) { - case NS_MOUSE_DOUBLECLICK: - event.mMessage = NS_MOUSE_BUTTON_DOWN; + case eMouseDoubleClick: + event.mMessage = eMouseDown; event.button = aButton; sLastClickCount = 2; sLastMouseDownTime = curMsgTime; break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: // remember when this happened for the next mouse down sLastMousePoint.x = eventPoint.x; sLastMousePoint.y = eventPoint.y; sLastMouseButton = eventButton; break; - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: // now look to see if we want to convert this to a double- or triple-click if (((curMsgTime - sLastMouseDownTime) < (LONG)::GetDoubleClickTime()) && insideMovementThreshold && @@ -3890,12 +3913,12 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, // Set last Click time on MouseDown only sLastMouseDownTime = curMsgTime; break; - case NS_MOUSE_MOVE: + case eMouseMove: if (!insideMovementThreshold) { sLastClickCount = 0; } break; - case NS_MOUSE_EXIT_WIDGET: + case eMouseExitFromWidget: event.exit = IsTopLevelMouseExit(mWnd) ? WidgetMouseEvent::eTopLevel : WidgetMouseEvent::eChild; break; @@ -3912,7 +3935,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, NPEvent pluginEvent; switch (aEventMessage) { - case NS_MOUSE_BUTTON_DOWN: + case eMouseDown: switch (aButton) { case WidgetMouseEvent::eLeftButton: pluginEvent.event = WM_LBUTTONDOWN; @@ -3927,7 +3950,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, break; } break; - case NS_MOUSE_BUTTON_UP: + case eMouseUp: switch (aButton) { case WidgetMouseEvent::eLeftButton: pluginEvent.event = WM_LBUTTONUP; @@ -3942,7 +3965,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, break; } break; - case NS_MOUSE_DOUBLECLICK: + case eMouseDoubleClick: switch (aButton) { case WidgetMouseEvent::eLeftButton: pluginEvent.event = WM_LBUTTONDBLCLK; @@ -3957,10 +3980,10 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, break; } break; - case NS_MOUSE_MOVE: + case eMouseMove: pluginEvent.event = WM_MOUSEMOVE; break; - case NS_MOUSE_EXIT_WIDGET: + case eMouseExitFromWidget: pluginEvent.event = WM_MOUSELEAVE; break; default: @@ -3977,7 +4000,7 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, if (mWidgetListener) { if (nsToolkit::gMouseTrailer) nsToolkit::gMouseTrailer->Disable(); - if (aEventMessage == NS_MOUSE_MOVE) { + if (aEventMessage == eMouseMove) { if (nsToolkit::gMouseTrailer && !sIsInMouseCapture) { nsToolkit::gMouseTrailer->SetMouseTrailerWindow(mWnd); } @@ -3990,20 +4013,22 @@ nsWindow::DispatchMouseEvent(EventMessage aEventMessage, WPARAM wParam, if (sCurrentWindow == nullptr || sCurrentWindow != this) { if ((nullptr != sCurrentWindow) && (!sCurrentWindow->mInDtor)) { LPARAM pos = sCurrentWindow->lParamToClient(lParamToScreen(lParam)); - sCurrentWindow->DispatchMouseEvent(NS_MOUSE_EXIT_WIDGET, wParam, pos, false, + sCurrentWindow->DispatchMouseEvent(eMouseExitFromWidget, + wParam, pos, false, WidgetMouseEvent::eLeftButton, aInputSource); } sCurrentWindow = this; if (!mInDtor) { LPARAM pos = sCurrentWindow->lParamToClient(lParamToScreen(lParam)); - sCurrentWindow->DispatchMouseEvent(NS_MOUSE_ENTER_WIDGET, wParam, pos, false, + sCurrentWindow->DispatchMouseEvent(eMouseEnterIntoWidget, + wParam, pos, false, WidgetMouseEvent::eLeftButton, aInputSource); } } } - } else if (aEventMessage == NS_MOUSE_EXIT_WIDGET) { + } else if (aEventMessage == eMouseExitFromWidget) { if (sCurrentWindow == this) { sCurrentWindow = nullptr; } @@ -4887,7 +4912,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, userMovedMouse = true; } - result = DispatchMouseEvent(NS_MOUSE_MOVE, wParam, lParam, + result = DispatchMouseEvent(eMouseMove, wParam, lParam, false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); if (userMovedMouse) { @@ -4898,14 +4923,14 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, case WM_NCMOUSEMOVE: // If we receive a mouse move event on non-client chrome, make sure and - // send an NS_MOUSE_EXIT_WIDGET event as well. + // send an eMouseExitFromWidget event as well. if (mMousePresent && !sIsInMouseCapture) SendMessage(mWnd, WM_MOUSELEAVE, 0, 0); break; case WM_LBUTTONDOWN: { - result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, lParam, + result = DispatchMouseEvent(eMouseDown, wParam, lParam, false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); DispatchPendingEvents(); @@ -4914,7 +4939,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, case WM_LBUTTONUP: { - result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, lParam, + result = DispatchMouseEvent(eMouseUp, wParam, lParam, false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); DispatchPendingEvents(); @@ -4935,7 +4960,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, // Synthesize an event position because we don't get one from // WM_MOUSELEAVE. LPARAM pos = lParamToClient(::GetMessagePos()); - DispatchMouseEvent(NS_MOUSE_EXIT_WIDGET, mouseState, pos, false, + DispatchMouseEvent(eMouseExitFromWidget, mouseState, pos, false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); } break; @@ -4943,7 +4968,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, case MOZ_WM_PEN_LEAVES_HOVER_OF_DIGITIZER: { LPARAM pos = lParamToClient(::GetMessagePos()); - DispatchMouseEvent(NS_MOUSE_EXIT_WIDGET, wParam, pos, false, + DispatchMouseEvent(eMouseExitFromWidget, wParam, pos, false, WidgetMouseEvent::eLeftButton, nsIDOMMouseEvent::MOZ_SOURCE_PEN); } @@ -4971,7 +4996,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); if (lParam != -1 && !result && mCustomNonClient) { - WidgetMouseEvent event(true, NS_MOUSE_MOZHITTEST, this, + WidgetMouseEvent event(true, eMouseHitTest, this, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); event.refPoint = LayoutDeviceIntPoint(GET_X_LPARAM(pos), GET_Y_LPARAM(pos)); @@ -4987,7 +5012,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_LBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, wParam, + result = DispatchMouseEvent(eMouseDoubleClick, wParam, lParam, false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); @@ -4995,7 +5020,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_MBUTTONDOWN: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, + result = DispatchMouseEvent(eMouseDown, wParam, lParam, false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5003,7 +5028,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_MBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, + result = DispatchMouseEvent(eMouseUp, wParam, lParam, false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5011,7 +5036,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_MBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, wParam, + result = DispatchMouseEvent(eMouseDoubleClick, wParam, lParam, false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5019,7 +5044,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCMBUTTONDOWN: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, 0, + result = DispatchMouseEvent(eMouseDown, 0, lParamToClient(lParam), false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5027,7 +5052,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCMBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, 0, + result = DispatchMouseEvent(eMouseUp, 0, lParamToClient(lParam), false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5035,7 +5060,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCMBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, 0, + result = DispatchMouseEvent(eMouseDoubleClick, 0, lParamToClient(lParam), false, WidgetMouseEvent::eMiddleButton, MOUSE_INPUT_SOURCE()); @@ -5043,7 +5068,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_RBUTTONDOWN: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, wParam, + result = DispatchMouseEvent(eMouseDown, wParam, lParam, false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5051,7 +5076,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_RBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, wParam, + result = DispatchMouseEvent(eMouseUp, wParam, lParam, false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5059,7 +5084,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_RBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, wParam, + result = DispatchMouseEvent(eMouseDoubleClick, wParam, lParam, false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5067,7 +5092,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCRBUTTONDOWN: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_DOWN, 0, + result = DispatchMouseEvent(eMouseDown, 0, lParamToClient(lParam), false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5075,7 +5100,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCRBUTTONUP: - result = DispatchMouseEvent(NS_MOUSE_BUTTON_UP, 0, + result = DispatchMouseEvent(eMouseUp, 0, lParamToClient(lParam), false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5083,7 +5108,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCRBUTTONDBLCLK: - result = DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, 0, + result = DispatchMouseEvent(eMouseDoubleClick, 0, lParamToClient(lParam), false, WidgetMouseEvent::eRightButton, MOUSE_INPUT_SOURCE()); @@ -5121,11 +5146,11 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, break; case WM_NCLBUTTONDBLCLK: - DispatchMouseEvent(NS_MOUSE_DOUBLECLICK, 0, lParamToClient(lParam), + DispatchMouseEvent(eMouseDoubleClick, 0, lParamToClient(lParam), false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); result = - DispatchMouseEvent(NS_MOUSE_BUTTON_UP, 0, lParamToClient(lParam), + DispatchMouseEvent(eMouseUp, 0, lParamToClient(lParam), false, WidgetMouseEvent::eLeftButton, MOUSE_INPUT_SOURCE()); DispatchPendingEvents(); @@ -5163,7 +5188,7 @@ nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, StopFlashing(); sJustGotActivate = true; - WidgetMouseEvent event(true, NS_MOUSE_ACTIVATE, this, + WidgetMouseEvent event(true, eMouseActivate, this, WidgetMouseEvent::eReal); InitEvent(event); ModifierKeyState modifierKeyState; @@ -5642,9 +5667,11 @@ nsWindow::ClientMarginHitTestPoint(int32_t mx, int32_t my) ::ScreenToClient(mWnd, &pt); if (pt.x == mCachedHitTestPoint.x && pt.y == mCachedHitTestPoint.y && TimeStamp::Now() - mCachedHitTestTime < TimeDuration::FromMilliseconds(HITTEST_CACHE_LIFETIME_MS)) { - testResult = mCachedHitTestResult; + return mCachedHitTestResult; + } else if (mDraggableRegion.Contains(pt.x, pt.y)) { + testResult = HTCAPTION; } else { - WidgetMouseEvent event(true, NS_MOUSE_MOZHITTEST, this, + WidgetMouseEvent event(true, eMouseHitTest, this, WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal); event.refPoint = LayoutDeviceIntPoint(pt.x, pt.y); @@ -5654,16 +5681,15 @@ nsWindow::ClientMarginHitTestPoint(int32_t mx, int32_t my) if (result) { // The mouse is over a blank area testResult = testResult == HTCLIENT ? HTCAPTION : testResult; - } else { // There's content over the mouse pointer. Set HTCLIENT // to possibly override a resizer border. testResult = HTCLIENT; } - mCachedHitTestPoint = pt; - mCachedHitTestTime = TimeStamp::Now(); - mCachedHitTestResult = testResult; } + mCachedHitTestPoint = pt; + mCachedHitTestTime = TimeStamp::Now(); + mCachedHitTestResult = testResult; } return testResult; @@ -6305,12 +6331,6 @@ bool nsWindow::OnTouch(WPARAM wParam, LPARAM lParam) return true; } -static int32_t RoundDown(double aDouble) -{ - return aDouble > 0 ? static_cast(floor(aDouble)) : - static_cast(ceil(aDouble)); -} - // Gesture event processing. Handles WM_GESTURE events. bool nsWindow::OnGesture(WPARAM wParam, LPARAM lParam) { @@ -6615,18 +6635,18 @@ bool nsWindow::AutoErase(HDC dc) return false; } -bool -nsWindow::IsPopup() -{ - return mWindowType == eWindowType_popup; -} - void nsWindow::ClearCompositor(nsWindow* aWindow) { aWindow->DestroyLayerManager(); } +bool +nsWindow::IsPopup() +{ + return mWindowType == eWindowType_popup; +} + bool nsWindow::ShouldUseOffMainThreadCompositing() { diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 4c8e857bc6..38a0d723ec 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -195,6 +195,7 @@ public: void SetDrawsInTitlebar(bool aState); already_AddRefed StartRemoteDrawing() override; virtual void EndRemoteDrawing() override; + virtual void UpdateWindowDraggingRegion(const nsIntRegion& aRegion) override; virtual void UpdateThemeGeometries(const nsTArray& aThemeGeometries) override; virtual uint32_t GetMaxTouchPoints() const override; @@ -527,6 +528,9 @@ protected: nsCOMPtr mIdleService; + // Draggable titlebar region maintained by UpdateWindowDraggingRegion + nsIntRegion mDraggableRegion; + // Hook Data Memebers for Dropdowns. sProcessHook Tells the // hook methods whether they should be processing the hook // messages.