Bug 1531226 - Add support for alwaysontop windows for macOS. r=mstange
authorMike Conley <mconley@mozilla.com>
Wed, 23 Oct 2019 18:25:10 +0000
changeset 498778 fa3070ca5599947caf8136d2da173668897f1799
parent 498777 a7fd7e3432f406aec1d8fe2f2d2a69a1cdc0c213
child 498779 3d7b77564cb7ca0800deedbb46de66a8b630d1f6
push id98678
push usermconley@mozilla.com
push dateWed, 23 Oct 2019 19:57:49 +0000
treeherderautoland@fa3070ca5599 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1531226
milestone72.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 1531226 - Add support for alwaysontop windows for macOS. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D50275
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -384,15 +384,16 @@ class nsCocoaWindow final : public nsBas
   // we are in the DOM fullscreen where we do not use the native fullscreen.
   bool mInNativeFullScreenMode;
 
   bool mIsAnimationSuppressed;
 
   bool mInReportMoveEvent;  // true if in a call to ReportMoveEvent().
   bool mInResize;           // true if in a call to DoResize().
   bool mWindowTransformIsIdentity;
+  bool mAlwaysOnTop;
 
   int32_t mNumModalDescendents;
   InputContext mInputContext;
   NSWindowAnimationBehavior mWindowAnimationBehavior;
 };
 
 #endif  // nsCocoaWindow_h_
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -149,16 +149,17 @@ nsCocoaWindow::nsCocoaWindow()
       mModal(false),
       mFakeModal(false),
       mSupportsNativeFullScreen(false),
       mInNativeFullScreenMode(false),
       mIsAnimationSuppressed(false),
       mInReportMoveEvent(false),
       mInResize(false),
       mWindowTransformIsIdentity(true),
+      mAlwaysOnTop(false),
       mNumModalDescendents(0),
       mWindowAnimationBehavior(NSWindowAnimationBehaviorDefault) {
   if ([NSWindow respondsToSelector:@selector(setAllowsAutomaticWindowTabbing:)]) {
     // Disable automatic tabbing on 10.12. We need to do this before we
     // orderFront any of our windows.
     [NSWindow setAllowsAutomaticWindowTabbing:NO];
   }
 }
@@ -297,16 +298,17 @@ nsresult nsCocoaWindow::Create(nsIWidget
 
   // Ensure that the toolkit is created.
   nsToolkit::GetToolkit();
 
   Inherited::BaseCreate(aParent, aInitData);
 
   mParent = aParent;
   mAncestorLink = aParent;
+  mAlwaysOnTop = aInitData->mAlwaysOnTop;
 
   // Applications that use native popups don't want us to create popup windows.
   if ((mWindowType == eWindowType_popup) && UseNativePopupWindows()) return NS_OK;
 
   nsresult rv =
       CreateNativeWindow(nsCocoaUtils::GeckoRectToCocoaRect(newBounds), mBorderStyle, false);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -477,16 +479,20 @@ nsresult nsCocoaWindow::CreateNativeWind
     [mWindow setBackgroundColor:[NSColor clearColor]];
     [mWindow setOpaque:NO];
   } else {
     // Make sure that regular windows are opaque from the start, so that
     // nsChildView::WidgetTypeSupportsAcceleration returns true for them.
     [mWindow setOpaque:YES];
   }
 
+  if (mAlwaysOnTop) {
+    [mWindow setLevel:NSFloatingWindowLevel];
+  }
+
   [mWindow setContentMinSize:NSMakeSize(60, 60)];
   [mWindow disableCursorRects];
 
   if (StaticPrefs::gfx_core_animation_enabled_AtStartup()) {
     // Make the window use CoreAnimation from the start, so that we don't
     // switch from a non-CA window to a CA-window in the middle.
     [[mWindow contentView] setWantsLayer:YES];
   }