Commit 1020606a authored by avi@chromium.org's avatar avi@chromium.org

Don't draw a window title on browser windows.

BUG=380229
TEST=as in bug

Review URL: https://codereview.chromium.org/329793003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276855 0039d316-1c4b-4281-b951-d872f2087c98
parent caebd1b9
......@@ -240,4 +240,23 @@ typedef NSUInteger NSWindowOcclusionState;
#endif // MAC_OS_X_VERSION_10_9
#if !defined(MAC_OS_X_VERSION_10_10) || \
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10
enum {
NSWindowTitleVisible = 0,
NSWindowTitleHidden = 1,
NSWindowTitleHiddenWhenActive = 2,
};
typedef NSInteger NSWindowTitleVisibility;
@interface NSWindow (YosemiteSDK)
@property NSWindowTitleVisibility titleVisibility;
@end
#endif // MAC_OS_X_VERSION_10_10
#endif // BASE_MAC_SDK_FORWARD_DECLARATIONS_H_
......@@ -211,10 +211,29 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
@end
@implementation ShellNSWindow
- (instancetype)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)deferCreation {
if ((self = [super initWithContentRect:contentRect
styleMask:windowStyle
backing:bufferingType
defer:deferCreation])) {
if ([self respondsToSelector:@selector(setTitleVisibility:)])
self.titleVisibility = NSWindowTitleHidden;
}
return self;
}
// Similar to ChromeBrowserWindow, don't draw the title, but allow it to be seen
// in menus, Expose, etc.
- (BOOL)_isTitleHidden {
return YES;
// Only intervene with 10.6-10.9.
if ([self respondsToSelector:@selector(setTitleVisibility:)])
return [super _isTitleHidden];
else
return YES;
}
@end
......
......@@ -25,6 +25,7 @@ const NSInteger kFramedWindowButtonsWithoutTabStripOffsetFromLeft = 8;
// this. We also handle our own window controls and custom window frame drawing.
@interface FramedBrowserWindow : ChromeBrowserWindow {
@private
// Only used from 10.6-10.9.
BOOL shouldHideTitle_;
BOOL hasTabStrip_;
NSButton* closeButton_;
......@@ -66,10 +67,9 @@ const NSInteger kFramedWindowButtonsWithoutTabStripOffsetFromLeft = 8;
@interface NSWindow (UndocumentedAPI)
// Undocumented Cocoa API to suppress drawing of the window's title.
// -setTitle: still works, but the title set only applies to the
// miniwindow and menus (and, importantly, Expose). Overridden to
// return |shouldHideTitle_|.
// Undocumented Cocoa API (10.6-10.9) to suppress drawing of the window's title.
// -setTitle: still works, but the title set only applies to the miniwindow and
// menus (and, importantly, Expose). Overridden to return |shouldHideTitle_|.
-(BOOL)_isTitleHidden;
@end
......
......@@ -36,7 +36,7 @@ const CGFloat kWindowGradientHeight = 24.0;
}
@interface FramedBrowserWindow (Private)
@interface FramedBrowserWindow ()
- (void)adjustCloseButton:(NSNotification*)notification;
- (void)adjustMiniaturizeButton:(NSNotification*)notification;
......@@ -252,11 +252,18 @@ const CGFloat kWindowGradientHeight = 24.0;
}
- (void)setShouldHideTitle:(BOOL)flag {
shouldHideTitle_ = flag;
if ([self respondsToSelector:@selector(setTitleVisibility:)])
self.titleVisibility = flag ? NSWindowTitleHidden : NSWindowTitleVisible;
else
shouldHideTitle_ = flag;
}
- (BOOL)_isTitleHidden {
return shouldHideTitle_;
// Only intervene with 10.6-10.9.
if ([self respondsToSelector:@selector(setTitleVisibility:)])
return [super _isTitleHidden];
else
return shouldHideTitle_;
}
- (CGFloat)windowButtonsInterButtonSpacing {
......@@ -349,9 +356,12 @@ const CGFloat kWindowGradientHeight = 24.0;
bounds:windowRect
forceBlackBackground:NO];
// If the window needs a title and we painted over the title as drawn by the
// default window paint, paint it ourselves.
if (themed && [view respondsToSelector:@selector(_titlebarTitleRect)] &&
// In Yosemite: The title is drawn by a subview and not painted on. Therefore,
// never worry about drawing it. Pre-Yosemite: If the window needs a title and
// we painted over the title as drawn by the default window paint, paint it
// ourselves.
if (![self respondsToSelector:@selector(setTitleVisibility:)] &&
themed && [view respondsToSelector:@selector(_titlebarTitleRect)] &&
[view respondsToSelector:@selector(_drawTitleStringIn:withColor:)] &&
![self _isTitleHidden]) {
[view _drawTitleStringIn:[view _titlebarTitleRect]
......
......@@ -5,6 +5,7 @@
#import <Cocoa/Cocoa.h>
#include "base/debug/debugger.h"
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
......@@ -70,7 +71,7 @@ TEST_F(FramedBrowserWindowTest, ShowAndClose) {
[window_ display];
}
// Test that undocumented title-hiding API we're using does the job.
// Test that the title-hiding API we're using does the job.
TEST_F(FramedBrowserWindowTest, DoesHideTitle) {
// The -display calls are not strictly necessary, but they do
// make it easier to see what's happening when debugging (without
......@@ -97,8 +98,11 @@ TEST_F(FramedBrowserWindowTest, DoesHideTitle) {
// With our magic setting, the window with a title should look the
// same as the window with an empty title.
EXPECT_TRUE([window_ _isTitleHidden]);
EXPECT_TRUE([emptyTitleData isEqualToData:hiddenTitleData]);
// Test the secret API only on versions of the system in which it exists.
if (base::mac::IsOSMavericksOrEarlier())
EXPECT_TRUE([window_ _isTitleHidden]);
}
// Test to make sure that our window widgets are in the right place.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment