Bug 1491442 - If CoreAnimation is enabled, don't clip the TitlebarGradientView to rounded corners, and don't draw the title string on top of it. r=mattwoodrow
authorMarkus Stange <mstange@themasta.com>
Fri, 16 Aug 2019 01:11:51 +0000
changeset 488406 9ffcdc648de567afa343e025298a2e2a424e7512
parent 488405 8e82722106c0d88adb7cbf322d764e72e7848838
child 488407 e89c3a6b2cd8eb8c8c328b86433765217ee7684e
push id36443
push userccoroiu@mozilla.com
push dateFri, 16 Aug 2019 09:48:15 +0000
treeherdermozilla-central@5d4cbfe103bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1491442
milestone70.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 1491442 - If CoreAnimation is enabled, don't clip the TitlebarGradientView to rounded corners, and don't draw the title string on top of it. r=mattwoodrow Unlike what the old comment in its drawRect method says, this isn't actually dependent on the NSFullSizeContentViewWindowMask. Any window that uses CoreAnimation layers for its window frame will apply these effects automatically. Differential Revision: https://phabricator.services.mozilla.com/D38753
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3146,44 +3146,46 @@ static const NSString* kStateWantsTitleD
 @implementation TitlebarGradientView
 
 - (void)drawRect:(NSRect)aRect {
   CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   ToolbarWindow* window = (ToolbarWindow*)[self window];
   nsNativeThemeCocoa::DrawNativeTitlebar(ctx, NSRectToCGRect([self bounds]),
                                          [window unifiedToolbarHeight], [window isMainWindow], NO);
 
-  // The following is only necessary because we're not using
-  // NSFullSizeContentViewWindowMask yet: We need to mask our drawing to the
-  // rounded top corners of the window, and we need to draw the title string
-  // on top. That's because the title string is drawn as part of the frame view
-  // and this view covers that drawing up.
-  // Once we use NSFullSizeContentViewWindowMask and remove our override of
-  // _wantsFloatingTitlebar, Cocoa will draw the title string as part of a
-  // separate view which sits on top of the window's content view, and we'll be
-  // able to remove the code below.
-
-  NSView* frameView = [[[self window] contentView] superview];
-  if (!frameView || ![frameView respondsToSelector:@selector(_maskCorners:clipRect:)] ||
-      ![frameView respondsToSelector:@selector(_drawTitleStringInClip:)]) {
-    return;
+  if (!StaticPrefs::gfx_core_animation_enabled_AtStartup()) {
+    // The following is only necessary when we're not using CoreAnimation for
+    // the window: We need to mask our drawing to the rounded top corners of the
+    // window, and we need to draw the title string on top. That's because, if
+    // CoreAnimation isn't used, the title string is drawn as part of the frame
+    // view and this view covers that drawing up.
+    // In a CoreAnimation-driven window, Cocoa will draw the title string in a
+    // separate NSView which sits on top of the window's content view, and we
+    // don't need the code below. It will also clip this view's drawing as part
+    // of the rounded corner clipping on the root CALayer of the window.
+
+    NSView* frameView = [[[self window] contentView] superview];
+    if (!frameView || ![frameView respondsToSelector:@selector(_maskCorners:clipRect:)] ||
+        ![frameView respondsToSelector:@selector(_drawTitleStringInClip:)]) {
+      return;
+    }
+
+    NSPoint offsetToFrameView = [self convertPoint:NSZeroPoint toView:frameView];
+    NSRect clipRect = {offsetToFrameView, [self bounds].size};
+
+    // Both this view and frameView return NO from isFlipped. Switch into
+    // frameView's coordinate system using a translation by the offset.
+    CGContextSaveGState(ctx);
+    CGContextTranslateCTM(ctx, -offsetToFrameView.x, -offsetToFrameView.y);
+
+    [frameView _maskCorners:2 clipRect:clipRect];
+    [frameView _drawTitleStringInClip:clipRect];
+
+    CGContextRestoreGState(ctx);
   }
-
-  NSPoint offsetToFrameView = [self convertPoint:NSZeroPoint toView:frameView];
-  NSRect clipRect = {offsetToFrameView, [self bounds].size};
-
-  // Both this view and frameView return NO from isFlipped. Switch into
-  // frameView's coordinate system using a translation by the offset.
-  CGContextSaveGState(ctx);
-  CGContextTranslateCTM(ctx, -offsetToFrameView.x, -offsetToFrameView.y);
-
-  [frameView _maskCorners:2 clipRect:clipRect];
-  [frameView _drawTitleStringInClip:clipRect];
-
-  CGContextRestoreGState(ctx);
 }
 
 - (BOOL)isOpaque {
   return YES;
 }
 
 - (BOOL)mouseDownCanMoveWindow {
   return YES;