Bug 625989 - Always draw in the titlebar on OSX. r=josh,dao f=mstange

This commit is contained in:
Mike Conley 2013-03-01 13:48:18 -05:00
Родитель 0a3bf3ab76
Коммит 58712ea44c
10 изменённых файлов: 110 добавлений и 37 удалений

Просмотреть файл

@ -6721,12 +6721,6 @@ let gPrivateBrowsingUI = {
document.getElementById("Tools:Sanitize").setAttribute("disabled", "true"); document.getElementById("Tools:Sanitize").setAttribute("disabled", "true");
if (window.location.href == getBrowserURL()) { if (window.location.href == getBrowserURL()) {
#ifdef XP_MACOSX
if (!PrivateBrowsingUtils.permanentPrivateBrowsing) {
document.documentElement.setAttribute("drawintitlebar", true);
}
#endif
// Adjust the window's title // Adjust the window's title
let docElement = document.documentElement; let docElement = document.documentElement;
if (!PrivateBrowsingUtils.permanentPrivateBrowsing) { if (!PrivateBrowsingUtils.permanentPrivateBrowsing) {

Просмотреть файл

@ -32,6 +32,7 @@
titlemodifier="" titlemodifier=""
titlemodifier_normal="" titlemodifier_normal=""
titlemodifier_privatebrowsing="&mainWindow.titlePrivateBrowsingSuffix;" titlemodifier_privatebrowsing="&mainWindow.titlePrivateBrowsingSuffix;"
chromemargin="0,-1,-1,-1"
#else #else
title_privatebrowsing="&mainWindow.titlemodifier;@PRE_RELEASE_SUFFIX@ &mainWindow.titlePrivateBrowsingSuffix;" title_privatebrowsing="&mainWindow.titlemodifier;@PRE_RELEASE_SUFFIX@ &mainWindow.titlePrivateBrowsingSuffix;"
titlemodifier="&mainWindow.titlemodifier;@PRE_RELEASE_SUFFIX@" titlemodifier="&mainWindow.titlemodifier;@PRE_RELEASE_SUFFIX@"

Просмотреть файл

@ -40,8 +40,7 @@
background-color: #eeeeee; background-color: #eeeeee;
} }
#titlebar-buttonbox-container, #titlebar-buttonbox-container {
#main-window:not([drawintitlebar=true]) > #titlebar {
display: none; display: none;
} }
@ -49,6 +48,10 @@
height: 22px; height: 22px;
} }
#main-window:not(:-moz-lwtheme):not([privatebrowsingmode=temporary]) > #titlebar {
-moz-appearance: -moz-window-titlebar;
}
#main-window[chromehidden~="toolbar"][chromehidden~="location"][chromehidden~="directories"] { #main-window[chromehidden~="toolbar"][chromehidden~="location"][chromehidden~="directories"] {
border-top: 1px solid rgba(0,0,0,0.65); border-top: 1px solid rgba(0,0,0,0.65);
} }

Просмотреть файл

@ -41,6 +41,9 @@ LightweightThemeConsumer.prototype = {
_lastData: null, _lastData: null,
_lastScreenWidth: null, _lastScreenWidth: null,
_lastScreenHeight: null, _lastScreenHeight: null,
#ifdef XP_MACOSX
_chromemarginDefault: undefined,
#endif
observe: function (aSubject, aTopic, aData) { observe: function (aSubject, aTopic, aData) {
if (aTopic != "lightweight-theme-styling-update") if (aTopic != "lightweight-theme-styling-update")
@ -108,10 +111,21 @@ LightweightThemeConsumer.prototype = {
} }
#ifdef XP_MACOSX #ifdef XP_MACOSX
if (active) // Sample whether or not we draw in the titlebar by default the first time we update.
root.setAttribute("drawintitlebar", "true"); // If the root has no chromemargin attribute, getAttribute will return null, and
else // we'll remove the attribute when the lw-theme is deactivated.
root.removeAttribute("drawintitlebar"); if (this._chromemarginDefault === undefined)
this._chromemarginDefault = root.getAttribute("chromemargin");
if (active) {
root.setAttribute("chromemargin", "0,-1,-1,-1");
}
else {
if (this._chromemarginDefault)
root.setAttribute("chromemargin", this._chromemarginDefault);
else
root.removeAttribute("chromemargin");
}
#endif #endif
} }
} }

Просмотреть файл

@ -540,6 +540,9 @@ public:
} }
// unit conversion convenience functions // unit conversion convenience functions
int32_t CocoaPointsToDevPixels(CGFloat aPts) {
return nsCocoaUtils::CocoaPointsToDevPixels(aPts, BackingScaleFactor());
}
nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) { nsIntPoint CocoaPointsToDevPixels(const NSPoint& aPt) {
return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor()); return nsCocoaUtils::CocoaPointsToDevPixels(aPt, BackingScaleFactor());
} }

Просмотреть файл

@ -2053,23 +2053,29 @@ nsChildView::MaybeDrawRoundedBottomCorners(GLManager* aManager, nsIntRect aRect)
void void
nsChildView::UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) nsChildView::UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries)
{ {
NSWindow* win = [mView window]; if (![mView window] || ![[mView window] isKindOfClass:[ToolbarWindow class]])
if (!win || ![win isKindOfClass:[ToolbarWindow class]])
return; return;
float unifiedToolbarHeight = 0; ToolbarWindow* win = (ToolbarWindow*)[mView window];
nsIntRect topPixelStrip(0, 0, [win frame].size.width, 1); bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame];
int32_t windowWidth = mBounds.width;
int32_t titlebarHeight = CocoaPointsToDevPixels([win titlebarHeight]);
int32_t underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0;
int32_t unifiedToolbarBottom = 0;
for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) { for (uint32_t i = 0; i < aThemeGeometries.Length(); ++i) {
const ThemeGeometry& g = aThemeGeometries[i]; const ThemeGeometry& g = aThemeGeometries[i];
if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR || if ((g.mWidgetType == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
g.mWidgetType == NS_THEME_TOOLBAR) && g.mWidgetType == NS_THEME_TOOLBAR) &&
g.mRect.Contains(topPixelStrip)) { g.mRect.X() <= 0 &&
unifiedToolbarHeight = g.mRect.YMost(); g.mRect.XMost() >= windowWidth &&
g.mRect.Y() <= underTitlebarPos) {
unifiedToolbarBottom = g.mRect.YMost();
} }
} }
[(ToolbarWindow*)win
setUnifiedToolbarHeight:DevPixelsToCocoaPoints(unifiedToolbarHeight)]; CGFloat unifiedHeight = DevPixelsToCocoaPoints(titlebarHeight + unifiedToolbarBottom - underTitlebarPos);
[win setUnifiedToolbarHeight:unifiedHeight];
} }
NS_IMETHODIMP NS_IMETHODIMP

Просмотреть файл

@ -269,6 +269,7 @@ public:
virtual void SetShowsToolbarButton(bool aShow); virtual void SetShowsToolbarButton(bool aShow);
virtual void SetShowsFullScreenButton(bool aShow); virtual void SetShowsFullScreenButton(bool aShow);
virtual void SetWindowAnimationType(WindowAnimationType aType); virtual void SetWindowAnimationType(WindowAnimationType aType);
NS_IMETHOD SetNonClientMargins(nsIntMargin &margins);
NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive); NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive);
virtual void SetDrawsInTitlebar(bool aState); virtual void SetDrawsInTitlebar(bool aState);
virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint, virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,

Просмотреть файл

@ -1954,6 +1954,15 @@ void nsCocoaWindow::SetWindowAnimationType(nsIWidget::WindowAnimationType aType)
mAnimationType = aType; mAnimationType = aType;
} }
NS_IMETHODIMP nsCocoaWindow::SetNonClientMargins(nsIntMargin &margins)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
SetDrawsInTitlebar(margins.top == 0);
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor, bool aActive) NS_IMETHODIMP nsCocoaWindow::SetWindowTitlebarColor(nscolor aColor, bool aActive)
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@ -2835,7 +2844,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
[super setBackgroundColor:mColor]; [super setBackgroundColor:mColor];
mBackgroundColor = [[NSColor whiteColor] retain]; mBackgroundColor = [[NSColor whiteColor] retain];
mUnifiedToolbarHeight = 0.0f; mUnifiedToolbarHeight = 22.0f;
// setBottomCornerRounded: is a private API call, so we check to make sure // setBottomCornerRounded: is a private API call, so we check to make sure
// we respond to it just in case. // we respond to it just in case.
@ -2909,6 +2918,7 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
[self frame].size.width, [self titlebarHeight]); [self frame].size.width, [self titlebarHeight]);
} }
// Returns the unified height of titlebar + toolbar.
- (float)unifiedToolbarHeight - (float)unifiedToolbarHeight
{ {
return mUnifiedToolbarHeight; return mUnifiedToolbarHeight;
@ -2920,15 +2930,16 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height; return frameRect.size.height - [self contentRectForFrameRect:frameRect].size.height;
} }
// Stores the complete height of titlebar + toolbar.
- (void)setUnifiedToolbarHeight:(float)aHeight - (void)setUnifiedToolbarHeight:(float)aHeight
{ {
if ([self drawsContentsIntoWindowFrame] || aHeight == mUnifiedToolbarHeight) if (aHeight == mUnifiedToolbarHeight)
return; return;
mUnifiedToolbarHeight = aHeight; mUnifiedToolbarHeight = aHeight;
// Update sheet positioning hint. // Update sheet positioning hint.
[self setContentBorderThickness:mUnifiedToolbarHeight forEdge:NSMaxYEdge]; [self setContentBorderThickness:mUnifiedToolbarHeight - [self titlebarHeight] forEdge:NSMaxYEdge];
// Redraw the title bar. If we're inside painting, we'll do it right now, // Redraw the title bar. If we're inside painting, we'll do it right now,
// otherwise we'll just invalidate it. // otherwise we'll just invalidate it.
@ -3123,18 +3134,18 @@ static const NSString* kStateShowsToolbarButton = @"showsToolbarButton";
static void static void
DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect, DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aToolbarHeight, BOOL aIsMain) float aUnifiedToolbarHeight, BOOL aIsMain)
{ {
if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) { if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) {
return; return;
} }
int unifiedHeight = aTitlebarRect.size.height + aToolbarHeight;
CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext, CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
@"kCUIWidgetWindowFrame", @"widget", @"kCUIWidgetWindowFrame", @"widget",
@"regularwin", @"windowtype", @"regularwin", @"windowtype",
(aIsMain ? @"normal" : @"inactive"), @"state", (aIsMain ? @"normal" : @"inactive"), @"state",
[NSNumber numberWithInt:unifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey", [NSNumber numberWithInt:aUnifiedToolbarHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
[NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey", [NSNumber numberWithBool:YES], @"kCUIWindowFrameDrawTitleSeparatorKey",
nil], nil],
nil); nil);

Просмотреть файл

@ -107,6 +107,8 @@ protected:
NSWindow* aWindow); NSWindow* aWindow);
void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect, void DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRect,
nsIFrame *aFrame); nsIFrame *aFrame);
void DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aUnifiedHeight, BOOL aIsMain);
void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame); void DrawResizer(CGContextRef cgContext, const HIRect& aRect, nsIFrame *aFrame);
// Scrollbars // Scrollbars

Просмотреть файл

@ -1789,16 +1789,18 @@ nsNativeThemeCocoa::GetParentScrollbarFrame(nsIFrame *aFrame)
static bool static bool
ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* aWindow) ToolbarCanBeUnified(CGContextRef cgContext, const HIRect& inBoxRect, NSWindow* aWindow)
{ {
if (![aWindow isKindOfClass:[ToolbarWindow class]] || if (![aWindow isKindOfClass:[ToolbarWindow class]])
[(ToolbarWindow*)aWindow drawsContentsIntoWindowFrame])
return false; return false;
float unifiedToolbarHeight = [(ToolbarWindow*)aWindow unifiedToolbarHeight]; ToolbarWindow* win = (ToolbarWindow*)aWindow;
CGAffineTransform ctm = CGContextGetUserSpaceToDeviceSpaceTransform(cgContext); float unifiedToolbarHeight = [win unifiedToolbarHeight];
CGRect deviceRect = CGRectApplyAffineTransform(inBoxRect, ctm); float titlebarHeight = [win titlebarHeight];
bool drawsContentsIntoWindowFrame = [win drawsContentsIntoWindowFrame];
float underTitlebarPos = drawsContentsIntoWindowFrame ? titlebarHeight : 0;
return inBoxRect.origin.x == 0 && return inBoxRect.origin.x == 0 &&
deviceRect.size.width >= [aWindow frame].size.width && inBoxRect.size.width >= [win frame].size.width &&
inBoxRect.origin.y <= 0.0 && inBoxRect.origin.y <= underTitlebarPos &&
floor(inBoxRect.origin.y + inBoxRect.size.height) <= unifiedToolbarHeight; floor(inBoxRect.origin.y + inBoxRect.size.height) <= unifiedToolbarHeight;
} }
@ -1808,15 +1810,14 @@ nsNativeThemeCocoa::DrawUnifiedToolbar(CGContextRef cgContext, const HIRect& inB
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK; NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
float titlebarHeight = [(ToolbarWindow*)aWindow titlebarHeight]; float unifiedHeight = [(ToolbarWindow*)aWindow unifiedToolbarHeight];
float unifiedHeight = titlebarHeight + inBoxRect.size.height;
BOOL isMain = [aWindow isMainWindow]; BOOL isMain = [aWindow isMainWindow];
CGContextSaveGState(cgContext); CGContextSaveGState(cgContext);
CGContextClipToRect(cgContext, inBoxRect); CGContextClipToRect(cgContext, inBoxRect);
CGRect drawRect = CGRectOffset(inBoxRect, 0, -titlebarHeight); CGRect drawRect = CGRectOffset(inBoxRect, 0, inBoxRect.size.height - unifiedHeight);
if (drawRect.size.width * drawRect.size.height <= CUIDRAW_MAX_AREA) { if (drawRect.size.width * drawRect.size.height <= CUIDRAW_MAX_AREA) {
CUIDraw([NSWindow coreUIRenderer], drawRect, cgContext, CUIDraw([NSWindow coreUIRenderer], drawRect, cgContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys: (CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
@ -1872,6 +1873,34 @@ nsNativeThemeCocoa::DrawStatusBar(CGContextRef cgContext, const HIRect& inBoxRec
NS_OBJC_END_TRY_ABORT_BLOCK; NS_OBJC_END_TRY_ABORT_BLOCK;
} }
void
nsNativeThemeCocoa::DrawNativeTitlebar(CGContextRef aContext, CGRect aTitlebarRect,
float aUnifiedHeight, BOOL aIsMain)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
if (aTitlebarRect.size.width * aTitlebarRect.size.height > CUIDRAW_MAX_AREA) {
return;
}
CGContextSaveGState(aContext);
CUIDraw([NSWindow coreUIRenderer], aTitlebarRect, aContext,
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:
@"kCUIWidgetWindowFrame", @"widget",
@"regularwin", @"windowtype",
(aIsMain ? @"normal" : @"inactive"), @"state",
[NSNumber numberWithInt:aUnifiedHeight], @"kCUIWindowFrameUnifiedTitleBarHeightKey",
[NSNumber numberWithBool:NO], @"kCUIWindowFrameDrawTitleSeparatorKey",
[NSNumber numberWithBool:YES], @"is.flipped",
nil],
nil);
CGContextRestoreGState(aContext);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
static void static void
RenderResizer(CGContextRef cgContext, const HIRect& aRenderRect, void* aData) RenderResizer(CGContextRef cgContext, const HIRect& aRenderRect, void* aData)
{ {
@ -2134,6 +2163,14 @@ nsNativeThemeCocoa::DrawWidgetBackground(nsRenderingContext* aContext,
} }
break; break;
case NS_THEME_WINDOW_TITLEBAR: {
NSWindow* win = NativeWindowForFrame(aFrame);
BOOL isMain = [win isMainWindow];
float unifiedToolbarHeight = [(ToolbarWindow*)win unifiedToolbarHeight];
DrawNativeTitlebar(cgContext, macRect, unifiedToolbarHeight, isMain);
}
break;
case NS_THEME_TOOLBOX: { case NS_THEME_TOOLBOX: {
HIThemeHeaderDrawInfo hdi = { 0, kThemeStateActive, kHIThemeHeaderKindWindow }; HIThemeHeaderDrawInfo hdi = { 0, kThemeStateActive, kHIThemeHeaderKindWindow };
HIThemeDrawHeader(&macRect, &hdi, cgContext, HITHEME_ORIENTATION); HIThemeDrawHeader(&macRect, &hdi, cgContext, HITHEME_ORIENTATION);
@ -2910,6 +2947,7 @@ nsNativeThemeCocoa::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* a
case NS_THEME_DIALOG: case NS_THEME_DIALOG:
case NS_THEME_WINDOW: case NS_THEME_WINDOW:
case NS_THEME_WINDOW_TITLEBAR:
case NS_THEME_MENUPOPUP: case NS_THEME_MENUPOPUP:
case NS_THEME_MENUITEM: case NS_THEME_MENUITEM:
case NS_THEME_MENUSEPARATOR: case NS_THEME_MENUSEPARATOR: