Bug 1335191 - Override -[NSThemeFrame _unifiedToolbarFrame] in order to get a correctly-sized unified toolbar gradient drawn in the titlebar. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Sat, 24 Mar 2018 01:53:30 -0400
changeset 773209 88d208d0d268141c010533a2adfc8b1d8a7b0719
parent 773208 efe862b3f884adc463989f9e27e1be3fdcd0d3ed
child 773214 c62abf54c7cdad141aa669a490a51b33caeb85d6
push id104177
push userbmo:mstange@themasta.com
push dateTue, 27 Mar 2018 17:16:49 +0000
reviewersspohl
bugs1335191
milestone61.0a1
Bug 1335191 - Override -[NSThemeFrame _unifiedToolbarFrame] in order to get a correctly-sized unified toolbar gradient drawn in the titlebar. r?spohl This implements the only useful piece of functionality that the TitlebarAndBackgroundColor class was providing. MozReview-Commit-ID: FXC6ICgDaoZ
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -2915,16 +2915,17 @@ nsCocoaWindow::GetEditCommands(NativeKey
 }
 
 @end
 
 @interface NSView(FrameViewMethodSwizzling)
 - (NSPoint)FrameView__closeButtonOrigin;
 - (NSPoint)FrameView__fullScreenButtonOrigin;
 - (BOOL)FrameView__wantsFloatingTitlebar;
+- (NSRect)FrameView__unifiedToolbarFrame;
 @end
 
 @implementation NSView(FrameViewMethodSwizzling)
 
 - (NSPoint)FrameView__closeButtonOrigin
 {
   NSPoint defaultPosition = [self FrameView__closeButtonOrigin];
   if ([[self window] isKindOfClass:[ToolbarWindow class]]) {
@@ -2942,16 +2943,29 @@ nsCocoaWindow::GetEditCommands(NativeKey
   return defaultPosition;
 }
 
 - (BOOL)FrameView__wantsFloatingTitlebar
 {
   return NO;
 }
 
+- (NSRect)FrameView__unifiedToolbarFrame
+{
+  NSRect defaultFrame = [self FrameView__unifiedToolbarFrame];
+  if ([[self window] isKindOfClass:[ToolbarWindow class]]) {
+    CGFloat unifiedToolbarHeight = [(ToolbarWindow*)[self window] unifiedToolbarHeight];
+    CGFloat topEdge = NSMaxY(defaultFrame);
+    CGFloat bottomEdge = topEdge - unifiedToolbarHeight;
+    return NSMakeRect(defaultFrame.origin.x, bottomEdge,
+                      defaultFrame.size.width, unifiedToolbarHeight);
+  }
+  return defaultFrame;
+}
+
 @end
 
 static NSMutableSet *gSwizzledFrameViewClasses = nil;
 
 @interface NSWindow(PrivateSetNeedsDisplayInRectMethod)
  - (void)_setNeedsDisplayInRect:(NSRect)aRect;
 @end
 
@@ -3019,16 +3033,19 @@ static NSMutableSet *gSwizzledFrameViewC
     class_getMethodImplementation([NSView class],
                                   @selector(FrameView__closeButtonOrigin));
   static IMP our_fullScreenButtonOrigin =
     class_getMethodImplementation([NSView class],
                                   @selector(FrameView__fullScreenButtonOrigin));
   static IMP our_wantsFloatingTitlebar =
     class_getMethodImplementation([NSView class],
                                   @selector(FrameView__wantsFloatingTitlebar));
+  static IMP our_unifiedToolbarFrame =
+    class_getMethodImplementation([NSView class],
+                                  @selector(FrameView__unifiedToolbarFrame));
 
   if (![gSwizzledFrameViewClasses containsObject:frameViewClass]) {
     // Either of these methods might be implemented in both a subclass of
     // NSFrameView and one of its own subclasses.  Which means that if we
     // aren't careful we might end up swizzling the same method twice.
     // Since method swizzling involves swapping pointers, this would break
     // things.
     IMP _closeButtonOrigin =
@@ -3049,16 +3066,24 @@ static NSMutableSet *gSwizzledFrameViewC
     IMP _wantsFloatingTitlebar =
       class_getMethodImplementation(frameViewClass,
                                     @selector(_wantsFloatingTitlebar));
     if (_wantsFloatingTitlebar &&
         _wantsFloatingTitlebar != our_wantsFloatingTitlebar) {
       nsToolkit::SwizzleMethods(frameViewClass, @selector(_wantsFloatingTitlebar),
                                 @selector(FrameView__wantsFloatingTitlebar));
     }
+    IMP _unifiedToolbarFrame =
+      class_getMethodImplementation(frameViewClass,
+                                    @selector(_unifiedToolbarFrame));
+    if (_unifiedToolbarFrame &&
+        _unifiedToolbarFrame != our_unifiedToolbarFrame) {
+      nsToolkit::SwizzleMethods(frameViewClass, @selector(_unifiedToolbarFrame),
+                                @selector(FrameView__unifiedToolbarFrame));
+    }
     [gSwizzledFrameViewClasses addObject:frameViewClass];
   }
 
   return frameViewClass;
 }
 
 - (id)initWithContentRect:(NSRect)aContentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)aBufferingType defer:(BOOL)aFlag
 {