Bug 1423275: Ensure that the proper mouse cursor is shown on macOS when switching between custom and default system cursors. r=mstange
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 15 Dec 2017 16:49:23 -0600
changeset 396607 e15eeb9bbf33b6f73c2a41540931354f4b4ae7df
parent 396606 a2b87439996443fa69171fda33938c632bb1630a
child 396608 31be43353751a97126b1676ea36d11b7ef71fa5c
push id33099
push userncsoregi@mozilla.com
push dateSat, 16 Dec 2017 09:38:13 +0000
treeherdermozilla-central@4780efa5f110 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1423275
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1423275: Ensure that the proper mouse cursor is shown on macOS when switching between custom and default system cursors. r=mstange
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;
   }