commit d69796bf8b22d718cee552c7e64103da567d6646
parent 5e3d11f0ead24807497a6937d55bcfcf8405f2da
Author: Markus Stange <mstange.moz@gmail.com>
Date: Thu, 23 Oct 2025 04:49:51 +0000
Bug 1820168 - Some nsCursorManager cleanup. Tweak method names and return types, and remove excessive doc comments. r=mac-reviewers,bradwerth
Depends on D172481
Differential Revision: https://phabricator.services.mozilla.com/D172482
Diffstat:
2 files changed, 17 insertions(+), 73 deletions(-)
diff --git a/widget/cocoa/nsCursorManager.h b/widget/cocoa/nsCursorManager.h
@@ -8,15 +8,6 @@
#import <Cocoa/Cocoa.h>
#include "nsIWidget.h"
-/*! @class nsCursorManager
- @abstract Singleton service provides access to all cursors available in
- the application.
- @discussion Use <code>nsCusorManager</code> to set the current cursor using
- an XP <code>nsCusor</code> enum value.
- <code>nsCursorManager</code> encapsulates the details of
- setting different types of cursors, animating cursors and
- cleaning up cursors when they are no longer in use.
- */
@interface nsCursorManager : NSObject {
@private
NSMutableDictionary* mCursors;
@@ -24,14 +15,9 @@
nsCursor mCurrentCursorType;
}
-/*! @method setCursor:
- @abstract Sets the current cursor.
- @discussion Sets the current cursor to the cursor indicated by the XP
- cursor given in the argument. Resources associated with the
- previous cursor are cleaned up.
- @param aCursor the cursor to use
-*/
-- (nsresult)setNonCustomCursor:(const nsIWidget::Cursor&)aCursor;
+// Sets non-custom cursors and can be used as a fallback if setting
+// a custom cursor did not succeed.
+- (void)setNonCustomCursor:(const nsIWidget::Cursor&)aCursor;
// As above, but returns an error if the cursor isn't custom or we couldn't set
// it for some reason.
@@ -39,18 +25,7 @@
widgetScaleFactor:(CGFloat)aWidgetScaleFactor
forceUpdate:(bool)aForceUpdate;
-/*! @method sharedInstance
- @abstract Get the Singleton instance of the cursor manager.
- @discussion Use this method to obtain a reference to the cursor manager.
- @result a reference to the cursor manager
-*/
+ (nsCursorManager*)sharedInstance;
-
-/*! @method dispose
- @abstract Releases the shared instance of the cursor manager.
- @discussion Use dispose to clean up the cursor manager and associated
- cursors.
-*/
+ (void)dispose;
@end
diff --git a/widget/cocoa/nsCursorManager.mm b/widget/cocoa/nsCursorManager.mm
@@ -15,38 +15,12 @@ static CGFloat sCurrentCursorScaleFactor = 0.0f;
MOZ_RUNINIT static nsIWidget::Cursor sCurrentCursor;
static constexpr nsCursor kCustomCursor = eCursorCount;
-/*! @category nsCursorManager(PrivateMethods)
- Private methods for the cursor manager class.
-*/
@interface nsCursorManager (PrivateMethods)
-/*! @method getCursor:
- @abstract Get a reference to the native Mac representation of a cursor.
- @discussion Gets a reference to the Mac native implementation of a cursor.
- If the cursor has been requested before, it is retreived from
- the cursor cache, otherwise it is created and cached.
- @param aCursor the cursor to get
- @result the Mac native implementation of the cursor
-*/
-- (NSCursor*)getCursor:(nsCursor)aCursor;
-
-/*! @method setMacCursor:
- @abstract Set the current Mac native cursor
- @discussion Sets the current cursor - this routine is what actually causes the
- cursor to change. The argument is retained and the old cursor is
- released.
- @param aMacCursor the cursor to set
- @result NS_OK
- */
-- (nsresult)setMacCursor:(NSCursor*)aMacCursor;
-
-/*! @method createCursor:
- @abstract Create a Mac native representation of a cursor.
- @discussion Creates a version of the Mac native representation of this
- cursor.
- @param aCursor the cursor to create
- @result the Mac native implementation of the cursor
-*/
-+ (NSCursor*)createCursor:(enum nsCursor)aCursor;
++ (NSCursor*)freshCursorWithType:(nsCursor)aCursor;
+- (NSCursor*)cursorWithType:(nsCursor)aCursor;
+
+// Set the cursor.
+- (void)setCursor:(NSCursor*)aMacCursor;
@end
@@ -68,7 +42,7 @@ static constexpr nsCursor kCustomCursor = eCursorCount;
gInstance = nil;
}
-+ (NSCursor*)createCursor:(enum nsCursor)aCursor {
++ (NSCursor*)freshCursorWithType:(enum nsCursor)aCursor {
switch (aCursor) {
case eCursor_standard:
return [NSCursor arrowCursor];
@@ -184,15 +158,13 @@ static constexpr nsCursor kCustomCursor = eCursorCount;
return self;
}
-- (nsresult)setNonCustomCursor:(const nsIWidget::Cursor&)aCursor {
- [self setMacCursor:[self getCursor:aCursor.mDefaultCursor]
- type:aCursor.mDefaultCursor];
-
+- (void)setNonCustomCursor:(const nsIWidget::Cursor&)aCursor {
+ [self setCursor:[self cursorWithType:aCursor.mDefaultCursor]
+ type:aCursor.mDefaultCursor];
sCurrentCursor = aCursor;
- return NS_OK;
}
-- (nsresult)setMacCursor:(NSCursor*)aMacCursor type:(nsCursor)aType {
+- (void)setCursor:(NSCursor*)aMacCursor type:(nsCursor)aType {
if (mCurrentCursorType != aType) {
if (aType == eCursor_none) {
[NSCursor hide];
@@ -209,8 +181,6 @@ static constexpr nsCursor kCustomCursor = eCursorCount;
[mCurrentCursor release];
mCurrentCursor = aMacCursor;
}
-
- return NS_OK;
}
- (nsresult)setCustomCursor:(const nsIWidget::Cursor&)aCursor
@@ -258,17 +228,16 @@ static constexpr nsCursor kCustomCursor = eCursorCount;
uint32_t hotspotY =
aCursor.mHotspotY > (uint32_t(size.height) - 1) ? 0 : aCursor.mHotspotY;
NSPoint hotSpot = ::NSMakePoint(hotspotX, hotspotY);
- [self setMacCursor:[[NSCursor alloc] initWithImage:cursorImage
- hotSpot:hotSpot]
- type:kCustomCursor];
+ [self setCursor:[[NSCursor alloc] initWithImage:cursorImage hotSpot:hotSpot]
+ type:kCustomCursor];
[cursorImage release];
return NS_OK;
}
-- (NSCursor*)getCursor:(enum nsCursor)aCursor {
+- (NSCursor*)cursorWithType:(enum nsCursor)aCursor {
NSCursor* result = [mCursors objectForKey:[NSNumber numberWithInt:aCursor]];
if (!result) {
- result = [nsCursorManager createCursor:aCursor];
+ result = [nsCursorManager freshCursorWithType:aCursor];
[mCursors setObject:result forKey:[NSNumber numberWithInt:aCursor]];
}
return result;