Bug 1335191 - Position sheets using the NSWindowDelegate method window:willPositionSheet:usingRect:. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Fri, 23 Mar 2018 17:50:02 -0400
changeset 773207 87eb80dbb6900a380962182b1ec73acdf3c8c48e
parent 772001 5dc49590c167f09c83dea865939389f94a3d3793
child 773208 efe862b3f884adc463989f9e27e1be3fdcd0d3ed
push id104177
push userbmo:mstange@themasta.com
push dateTue, 27 Mar 2018 17:16:49 +0000
reviewersspohl
bugs1335191
milestone61.0a1
Bug 1335191 - Position sheets using the NSWindowDelegate method window:willPositionSheet:usingRect:. r?spohl MozReview-Commit-ID: 1Dwwdvl6Fok
tools/profiler/core/platform.cpp
widget/cocoa/nsChildView.mm
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -1003,17 +1003,17 @@ MergeStacks(uint32_t aFeatures, bool aIs
       // the buffer, nsRefreshDriver would now be holding on to a backtrace
       // with stale JIT code return addresses.
       if (aIsSynchronous ||
           jsFrame.kind == JS::ProfilingFrameIterator::Frame_Wasm) {
         aCollector.CollectWasmFrame(jsFrame.label);
       } else {
         MOZ_ASSERT(jsFrame.kind == JS::ProfilingFrameIterator::Frame_Ion ||
                    jsFrame.kind == JS::ProfilingFrameIterator::Frame_Baseline);
-        aCollector.CollectJitReturnAddr(jsFrames[jsIndex].returnAddress);
+        aCollector.CollectJitReturnAddr(jsFrame.returnAddress);
       }
 
       jsIndex--;
       continue;
     }
 
     // If we reach here, there must be a native stack entry and it must be the
     // greatest entry.
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -2546,19 +2546,21 @@ nsChildView::UpdateThemeGeometries(const
     FindUnifiedToolbarBottom(aThemeGeometries, windowWidth, titlebarBottom);
   int32_t toolboxBottom =
     FindFirstRectOfType(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeToolbox).YMost();
 
   ToolbarWindow* win = (ToolbarWindow*)[mView window];
   int32_t titlebarHeight = CocoaPointsToDevPixels([win titlebarHeight]);
   int32_t devUnifiedHeight = titlebarHeight + unifiedToolbarBottom;
   [win setUnifiedToolbarHeight:DevPixelsToCocoaPoints(devUnifiedHeight)];
-  int32_t devSheetPosition = titlebarHeight +
-                             std::max(toolboxBottom, unifiedToolbarBottom);
-  [win setSheetAttachmentPosition:DevPixelsToCocoaPoints(devSheetPosition)];
+
+  int32_t sheetPositionDevPx = std::max(toolboxBottom, unifiedToolbarBottom);
+  NSPoint sheetPositionView = { 0, DevPixelsToCocoaPoints(sheetPositionDevPx) };
+  NSPoint sheetPositionWindow = [mView convertPoint:sheetPositionView toView:nil];
+  [win setSheetAttachmentPosition:sheetPositionWindow.y];
 
   // Update titlebar control offsets.
   LayoutDeviceIntRect windowButtonRect = FindFirstRectOfType(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeWindowButtons);
   [win placeWindowButtons:[mView convertRect:DevPixelsToCocoaPoints(windowButtonRect) toView:nil]];
   LayoutDeviceIntRect fullScreenButtonRect = FindFirstRectOfType(aThemeGeometries, nsNativeThemeCocoa::eThemeGeometryTypeFullscreenButton);
   [win placeFullScreenButton:[mView convertRect:DevPixelsToCocoaPoints(fullScreenButtonRect) toView:nil]];
 }
 
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -167,27 +167,29 @@ typedef struct _nsCocoaWindowList {
 - (id)initWithWindow:(ToolbarWindow*)aWindow;
 
 @end
 
 // NSWindow subclass for handling windows with toolbars.
 @interface ToolbarWindow : BaseWindow
 {
   CGFloat mUnifiedToolbarHeight;
+  CGFloat mSheetAttachmentPosition;
   NSRect mWindowButtonsRect;
   NSRect mFullScreenButtonRect;
 }
 - (void)setUnifiedToolbarHeight:(CGFloat)aHeight;
 - (CGFloat)unifiedToolbarHeight;
 - (CGFloat)titlebarHeight;
 - (NSRect)titlebarRect;
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect sync:(BOOL)aSync;
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect;
 - (void)setDrawsContentsIntoWindowFrame:(BOOL)aState;
 - (void)setSheetAttachmentPosition:(CGFloat)aY;
+- (CGFloat)sheetAttachmentPosition;
 - (void)placeWindowButtons:(NSRect)aRect;
 - (void)placeFullScreenButton:(NSRect)aRect;
 - (NSPoint)windowButtonsPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
 - (NSPoint)fullScreenButtonPositionWithDefaultPosition:(NSPoint)aDefaultPosition;
 @end
 
 class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa
 {
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2824,16 +2824,24 @@ nsCocoaWindow::GetEditCommands(NativeKey
 {
   if (!mHasEverBeenZoomed && [window isZoomed])
     return NO; // See bug 429954.
 
   mHasEverBeenZoomed = YES;
   return YES;
 }
 
+- (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet usingRect:(NSRect)rect
+{
+  if ([window isKindOfClass:[ToolbarWindow class]]) {
+    rect.origin.y = [(ToolbarWindow*)window sheetAttachmentPosition];
+  }
+  return rect;
+}
+
 - (void)didEndSheet:(NSWindow*)sheet returnCode:(int)returnCode contextInfo:(void*)contextInfo
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   // Note: 'contextInfo' (if it is set) is the window that is the parent of
   // the sheet.  The value of contextInfo is determined in
   // nsCocoaWindow::Show().  If it's set, 'contextInfo' is always the top-
   // level window, not another sheet itself.  But 'contextInfo' is nil if
@@ -3487,26 +3495,24 @@ static const NSString* kStateCollectionB
 
 - (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   aStyle = aStyle | NSTexturedBackgroundWindowMask;
   if ((self = [super initWithContentRect:aContentRect styleMask:aStyle backing:aBufferingType defer:aFlag])) {
     mUnifiedToolbarHeight = 22.0f;
+    mSheetAttachmentPosition = aContentRect.size.height;
     mWindowButtonsRect = NSZeroRect;
     mFullScreenButtonRect = NSZeroRect;
 
     // setBottomCornerRounded: is a private API call, so we check to make sure
     // we respond to it just in case.
     if ([self respondsToSelector:@selector(setBottomCornerRounded:)])
       [self setBottomCornerRounded:YES];
-
-    [self setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
-    [self setContentBorderThickness:0.0f forEdge:NSMaxYEdge];
   }
   return self;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
 }
 
 - (void)setTitlebarNeedsDisplayInRect:(NSRect)aRect
 {
@@ -3600,18 +3606,22 @@ static const NSString* kStateCollectionB
 - (void)setWantsTitleDrawn:(BOOL)aDrawTitle
 {
   [super setWantsTitleDrawn:aDrawTitle];
   [self setTitlebarNeedsDisplayInRect:[self titlebarRect]];
 }
 
 - (void)setSheetAttachmentPosition:(CGFloat)aY
 {
-  CGFloat topMargin = aY - [self titlebarHeight];
-  [self setContentBorderThickness:topMargin forEdge:NSMaxYEdge];
+  mSheetAttachmentPosition = aY;
+}
+
+- (CGFloat)sheetAttachmentPosition
+{
+  return mSheetAttachmentPosition;
 }
 
 - (void)placeWindowButtons:(NSRect)aRect
 {
   if (!NSEqualRects(mWindowButtonsRect, aRect)) {
     mWindowButtonsRect = aRect;
     [self reflowTitlebarElements];
   }