From 39702657874c629a7ed39b36c69a151499f8eb8f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 16 Dec 2016 10:54:02 +1100 Subject: [PATCH] Bug 1299335 (part 1) - Change some nsIWidget function return values from |NS_IMETHOD| to |virtual MOZ_MUST_USE nsresult|. r=jimm. Specifically: OnDefaultButtonLoaded, AttachNativeKeyEvent, BeginMoveDrag, BeginResizeDrag, GetAttention. These are all fallible functions whose result is always checked. The patch also moves some trivial function definitions from nsBaseWidget.cpp to nsBaseWidget.h, and removes the android BeginResizeDrag() because it can use the nsBaseWidget one. --HG-- extra : rebase_source : ef32a41b547bcbc21f7df0043f683307470b136e --- widget/android/nsWindow.h | 8 +------- widget/cocoa/nsChildView.h | 5 +++-- widget/cocoa/nsChildView.mm | 5 +++-- widget/cocoa/nsCocoaWindow.h | 2 +- widget/cocoa/nsCocoaWindow.mm | 3 ++- widget/gtk/nsWindow.cpp | 6 +++--- widget/gtk/nsWindow.h | 8 +++++--- widget/nsBaseWidget.cpp | 19 ------------------- widget/nsBaseWidget.h | 18 ++++++++++++------ widget/nsIWidget.h | 18 +++++++++++------- widget/windows/nsWindow.cpp | 10 +++++----- widget/windows/nsWindow.h | 7 ++++--- 12 files changed, 50 insertions(+), 59 deletions(-) diff --git a/widget/android/nsWindow.h b/widget/android/nsWindow.h index 1ba7fff25ffc..66d81660fa4e 100644 --- a/widget/android/nsWindow.h +++ b/widget/android/nsWindow.h @@ -204,13 +204,7 @@ public: void SetNativeData(uint32_t aDataType, uintptr_t aVal) override; NS_IMETHOD SetTitle(const nsAString& aTitle) override { return NS_OK; } NS_IMETHOD SetIcon(const nsAString& aIconSpec) override { return NS_OK; } - NS_IMETHOD GetAttention(int32_t aCycleCount) override { return NS_ERROR_NOT_IMPLEMENTED; } - NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, - int32_t aHorizontal, - int32_t aVertical) override - { - return NS_ERROR_NOT_IMPLEMENTED; - } + virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) override { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, const InputContextAction& aAction) override; diff --git a/widget/cocoa/nsChildView.h b/widget/cocoa/nsChildView.h index f0655b129dce..bd926312b765 100644 --- a/widget/cocoa/nsChildView.h +++ b/widget/cocoa/nsChildView.h @@ -365,7 +365,8 @@ public: NS_IMETHOD SetTitle(const nsAString& title) override; - NS_IMETHOD GetAttention(int32_t aCycleCount) override; + virtual MOZ_MUST_USE nsresult + GetAttention(int32_t aCycleCount) override; virtual bool HasPendingInputEvent() override; @@ -378,7 +379,7 @@ public: NS_IMETHOD_(InputContext) GetInputContext() override; NS_IMETHOD_(TextEventDispatcherListener*) GetNativeTextEventDispatcherListener() override; - NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override; + virtual MOZ_MUST_USE nsresult AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override; NS_IMETHOD_(bool) ExecuteNativeKeyBinding( NativeKeyBindingsType aType, const mozilla::WidgetKeyboardEvent& aEvent, diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index cf5ec0f17110..9bf3121012f7 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -1619,7 +1619,8 @@ NS_IMETHODIMP nsChildView::SetTitle(const nsAString& title) return NS_OK; } -NS_IMETHODIMP nsChildView::GetAttention(int32_t aCycleCount) +nsresult +nsChildView::GetAttention(int32_t aCycleCount) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; @@ -1788,7 +1789,7 @@ nsChildView::GetNativeTextEventDispatcherListener() return mTextInputHandler; } -NS_IMETHODIMP +nsresult nsChildView::AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) { NS_ENSURE_TRUE(mTextInputHandler, NS_ERROR_NOT_AVAILABLE); diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h index fe0db0cff948..4124db211fbf 100644 --- a/widget/cocoa/nsCocoaWindow.h +++ b/widget/cocoa/nsCocoaWindow.h @@ -308,7 +308,7 @@ public: nsEventStatus& aStatus) override; virtual void CaptureRollupEvents(nsIRollupListener * aListener, bool aDoCapture) override; - NS_IMETHOD GetAttention(int32_t aCycleCount) override; + virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) override; virtual bool HasPendingInputEvent() override; virtual nsTransparencyMode GetTransparencyMode() override; virtual void SetTransparencyMode(nsTransparencyMode aMode) override; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 8541fef979ba..a8d7ea9fefc2 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -2111,7 +2111,8 @@ nsCocoaWindow::CaptureRollupEvents(nsIRollupListener* aListener, NS_OBJC_END_TRY_ABORT_BLOCK; } -NS_IMETHODIMP nsCocoaWindow::GetAttention(int32_t aCycleCount) +nsresult +nsCocoaWindow::GetAttention(int32_t aCycleCount) { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 9e7ab8541c01..fa6398d6e846 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -1937,7 +1937,7 @@ nsWindow::CaptureRollupEvents(nsIRollupListener *aListener, } } -NS_IMETHODIMP +nsresult nsWindow::GetAttention(int32_t aCycleCount) { LOG(("nsWindow::GetAttention [%p]\n", (void *)this)); @@ -6627,7 +6627,7 @@ nsWindow::GetDragInfo(WidgetMouseEvent* aMouseEvent, return true; } -NS_IMETHODIMP +nsresult nsWindow::BeginMoveDrag(WidgetMouseEvent* aEvent) { MOZ_ASSERT(aEvent, "must have event"); @@ -6649,7 +6649,7 @@ nsWindow::BeginMoveDrag(WidgetMouseEvent* aEvent) return NS_OK; } -NS_IMETHODIMP +nsresult nsWindow::BeginResizeDrag(WidgetGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index b48fdad8c33d..1c72661f9940 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -148,7 +148,7 @@ public: virtual void CaptureMouse(bool aCapture) override; virtual void CaptureRollupEvents(nsIRollupListener *aListener, bool aDoCapture) override; - NS_IMETHOD GetAttention(int32_t aCycleCount) override; + virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) override; virtual nsresult SetWindowClipRegion(const nsTArray& aRects, bool aIntersectWithExisting) override; virtual bool HasPendingInputEvent() override; @@ -258,10 +258,12 @@ public: static guint32 sLastButtonPressTime; - NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, + virtual MOZ_MUST_USE nsresult + BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) override; - NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override; + virtual MOZ_MUST_USE nsresult + BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override; MozContainer* GetMozContainer() { return mContainer; } // GetMozContainerWidget returns the MozContainer even for undestroyed diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 0b7d014637ad..d4e27f2ad205 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -1604,11 +1604,6 @@ uint32_t nsBaseWidget::GetMaxTouchPoints() const return 0; } -NS_IMETHODIMP -nsBaseWidget::GetAttention(int32_t aCycleCount) { - return NS_OK; -} - bool nsBaseWidget::HasPendingInputEvent() { @@ -1694,20 +1689,6 @@ nsBaseWidget::ResolveIconName(const nsAString &aIconName, NS_ADDREF(*aResult = file); } -NS_IMETHODIMP -nsBaseWidget::BeginResizeDrag(WidgetGUIEvent* aEvent, - int32_t aHorizontal, - int32_t aVertical) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsBaseWidget::BeginMoveDrag(WidgetMouseEvent* aEvent) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - void nsBaseWidget::SetSizeConstraints(const SizeConstraints& aConstraints) { mSizeConstraints = aConstraints; diff --git a/widget/nsBaseWidget.h b/widget/nsBaseWidget.h index 7e4fdfc02272..88055eabf69c 100644 --- a/widget/nsBaseWidget.h +++ b/widget/nsBaseWidget.h @@ -243,7 +243,9 @@ public: NS_IMETHOD SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override; virtual LayoutDeviceIntPoint GetClientOffset() override; virtual void EnableDragDrop(bool aEnable) override {}; - NS_IMETHOD GetAttention(int32_t aCycleCount) override; + virtual MOZ_MUST_USE nsresult + GetAttention(int32_t aCycleCount) override + { return NS_OK; } virtual bool HasPendingInputEvent() override; NS_IMETHOD SetIcon(const nsAString &anIconSpec) override; virtual void SetWindowTitlebarColor(nscolor aColor, bool aActive) @@ -251,10 +253,14 @@ public: virtual void SetDrawsInTitlebar(bool aState) override {} virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override; virtual void FreeNativeData(void * data, uint32_t aDataType) override {} - NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, + virtual MOZ_MUST_USE nsresult + BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal, - int32_t aVertical) override; - NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override; + int32_t aVertical) override + { return NS_ERROR_NOT_IMPLEMENTED; } + virtual MOZ_MUST_USE nsresult + BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override + { return NS_ERROR_NOT_IMPLEMENTED; } virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; } virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) override final; @@ -270,7 +276,7 @@ public: virtual void DefaultProcOfPluginEvent( const mozilla::WidgetPluginEvent& aEvent) override { } - NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override { return NS_ERROR_NOT_IMPLEMENTED; } + virtual MOZ_MUST_USE nsresult AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override { return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD_(bool) ExecuteNativeKeyBinding( NativeKeyBindingsType aType, const mozilla::WidgetKeyboardEvent& aEvent, @@ -279,7 +285,7 @@ public: bool ComputeShouldAccelerate(); virtual bool WidgetTypeSupportsAcceleration() { return true; } virtual nsIMEUpdatePreference GetIMEUpdatePreference() override { return nsIMEUpdatePreference(); } - NS_IMETHOD OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override { return NS_ERROR_NOT_IMPLEMENTED; } + virtual MOZ_MUST_USE nsresult OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override { return NS_ERROR_NOT_IMPLEMENTED; } virtual already_AddRefed CreateChild(const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr, diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index 2d14cc107f11..dc9c4b745949 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -1417,7 +1417,7 @@ class nsIWidget : public nsISupports * conventions. If set to -1, cycles indefinitely until * window is brought into the foreground. */ - NS_IMETHOD GetAttention(int32_t aCycleCount) = 0; + virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) = 0; /** * Ask whether there user input events pending. All input events are @@ -1475,14 +1475,16 @@ class nsIWidget : public nsISupports /** * Begin a window resizing drag, based on the event passed in. */ - NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, - int32_t aHorizontal, - int32_t aVertical) = 0; + virtual MOZ_MUST_USE nsresult + BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, + int32_t aHorizontal, + int32_t aVertical) = 0; /** * Begin a window moving drag, based on the event passed in. */ - NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0; + virtual MOZ_MUST_USE nsresult + BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0; enum Modifiers { CAPS_LOCK = 0x01, // when CapsLock is active @@ -1811,7 +1813,8 @@ public: * keystrokes that trigger native key bindings (which require a native * event). */ - NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0; + virtual MOZ_MUST_USE nsresult + AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0; /* * Execute native key bindings for aType. @@ -1838,7 +1841,8 @@ public: * Call this method when a dialog is opened which has a default button. * The button's rectangle should be supplied in aButtonRect. */ - NS_IMETHOD OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) = 0; + virtual MOZ_MUST_USE nsresult + OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) = 0; /** * Return true if this process shouldn't use platform widgets, and diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index d896ecf933d8..38e63214440d 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -1483,7 +1483,7 @@ NS_IMETHODIMP nsWindow::Show(bool bState) ::ShowWindow(mWnd, SW_SHOWNORMAL); } else { ::ShowWindow(mWnd, SW_SHOWNOACTIVATE); - GetAttention(2); + Unused << GetAttention(2); } break; } @@ -1866,7 +1866,7 @@ NS_IMETHODIMP nsWindow::Resize(double aX, double aY, double aWidth, return NS_OK; } -NS_IMETHODIMP +nsresult nsWindow::BeginResizeDrag(WidgetGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) @@ -3720,7 +3720,7 @@ nsWindow::CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) **************************************************************/ // Draw user's attention to this window until it comes to foreground. -NS_IMETHODIMP +nsresult nsWindow::GetAttention(int32_t aCycleCount) { // Got window? @@ -3838,8 +3838,8 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager, * Called after the dialog is loaded and it has a default button. * **************************************************************/ - -NS_IMETHODIMP + +nsresult nsWindow::OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) { if (aButtonRect.IsEmpty()) diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index 145b113644c9..388e3f7ec7db 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -126,7 +126,8 @@ public: NS_IMETHOD Move(double aX, double aY) override; NS_IMETHOD Resize(double aWidth, double aHeight, bool aRepaint) override; NS_IMETHOD Resize(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override; - NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, + virtual MOZ_MUST_USE nsresult + BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) override; virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, bool aActivate) override; @@ -169,12 +170,12 @@ public: virtual void CaptureMouse(bool aCapture) override; virtual void CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) override; - NS_IMETHOD GetAttention(int32_t aCycleCount) override; + virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) override; virtual bool HasPendingInputEvent() override; virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override; - NS_IMETHOD OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override; + virtual MOZ_MUST_USE nsresult OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override; virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode, uint32_t aModifierFlags,