Bug 1423275 - Ensure that the proper mouse cursor is shown on macOS when switching between custom and default system cursors. r=mstange, a=jcristau
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 15 Dec 2017 16:49:23 -0600
changeset 445431 13b3ee92ee381296b05ff6a0c66ad153558cf3c0
parent 445430 9e7435aeb7bd1cb9825c092db7f7eb938def0945
child 445432 0ef7163b1248c561490ae595c8ee7a9d997c5a7f
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, jcristau
bugs1423275
milestone58.0
Bug 1423275 - Ensure that the proper mouse cursor is shown on macOS when switching between custom and default system cursors. r=mstange, a=jcristau
widget/cocoa/nsCursorManager.mm
--- a/widget/cocoa/nsCursorManager.mm
+++ b/widget/cocoa/nsCursorManager.mm
@@ -190,44 +190,47 @@ static const nsCursor sCustomCursor = eC
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (nsresult) setCursor: (enum nsCursor) aCursor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
-  // Some plugins mess with our cursors and set a cursor that even
-  // [NSCursor currentCursor] doesn't know about. In case that happens, just
-  // reset the state.
-  [[NSCursor currentCursor] set];
-
   nsCursor oldType = [mCurrentMacCursor type];
-  if (oldType != aCursor) {
-    if (aCursor == eCursor_none) {
-      [NSCursor hide];
-    } else if (oldType == eCursor_none) {
-      [NSCursor unhide];
-    }
-  }
   [self setMacCursor:[self getCursor:aCursor]];
 
   // if a custom cursor was previously set, release sCursorImgContainer
   if (oldType == sCustomCursor) {
     NS_IF_RELEASE(sCursorImgContainer);
   }
   return NS_OK;
   
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
 - (nsresult) setMacCursor: (nsMacCursor*) aMacCursor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
 
+  // Some plugins mess with our cursors and set a cursor that even
+  // [NSCursor currentCursor] doesn't know about. In case that happens, just
+  // reset the state.
+  [[NSCursor currentCursor] set];
+
+  nsCursor oldType = [mCurrentMacCursor type];
+  nsCursor newType = [aMacCursor type];
+  if (oldType != newType) {
+    if (newType == eCursor_none) {
+      [NSCursor hide];
+    } else if (oldType == eCursor_none) {
+      [NSCursor unhide];
+    }
+  }
+
   if (mCurrentMacCursor != aMacCursor || ![mCurrentMacCursor isSet]) {
     [aMacCursor retain];
     [mCurrentMacCursor unset];
     [aMacCursor set];
     [mCurrentMacCursor release];
     mCurrentMacCursor = aMacCursor;
   }
 
@@ -239,18 +242,17 @@ static const nsCursor sCustomCursor = eC
 - (nsresult) setCursorWithImage: (imgIContainer*) aCursorImage hotSpotX: (uint32_t) aHotspotX hotSpotY: (uint32_t) aHotspotY scaleFactor: (CGFloat) scaleFactor
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
   // As the user moves the mouse, this gets called repeatedly with the same aCursorImage
   if (sCursorImgContainer == aCursorImage && sCursorScaleFactor == scaleFactor && mCurrentMacCursor) {
     [self setMacCursor:mCurrentMacCursor];
     return NS_OK;
   }
-  
-  [[NSCursor currentCursor] set];
+
   int32_t width = 0, height = 0;
   aCursorImage->GetWidth(&width);
   aCursorImage->GetHeight(&height);
   // prevent DoS attacks
   if (width > 128 || height > 128) {
     return NS_OK;
   }