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
--- 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
{