AppKit: Fall back to declared default for title-bar-height in +[_CPTitleableWindowView titleBarHeight]

+[_CPTitleableWindowView titleBarHeight] read title-bar-height only from
the default theme. Without a default theme, or with a theme that sets no
value, it returned nil, so the frame and content rect conversions left out
only the title bar.

The window was allocated no space for its title bar, and the
content view started too high by the class default height
(32 points for a standard window),
while still sitting below the divider and any toolbar.

The method now uses the default that the window view class or one of its
superclasses declares, matching how a view resolves its other theme
attributes.
This commit is contained in:
David Richardson committed 2026-11-30 09:44:24 -06:00
1 parent f825aa5f7a
commit 212f6fbe1c
2 files changed
+41 -1

No files matched your search

+14 -1
View File
@@ -33,7 +33,20 @@
+ (int)titleBarHeight
{
return [[CPTheme defaultTheme] valueForAttributeWithName:@"title-bar-height" forClass:[self class]];
var titleBarHeight = [[CPTheme defaultTheme] valueForAttributeWithName:@"title-bar-height" forClass:[self class]];
/*
2026-11-30: without a default theme, or with a theme that sets no title bar height,
this method returned nil. The frame and content rect conversions then gave the
window no title bar, and the content view started at the top of the window. The
cause: the method read only the theme and ignored the default value that the
class and its superclasses declare in +themeAttributes. It now uses that default,
as a view does for its other theme attributes.
*/
for (var theClass = self; titleBarHeight == nil && theClass && theClass !== [CPObject class]; theClass = [theClass superclass])
titleBarHeight = [[theClass themeAttributes] objectForKey:@"title-bar-height"];
return titleBarHeight;
}
+ (CGRect)contentRectForFrameRect:(CGRect)aFrameRect
+27
View File
@@ -561,6 +561,33 @@
message:@"content view size " + CPStringFromSize([[window contentView] frameSize]) + " should be {480, 270}"];
}
/*
A theme need not set every attribute. Where it sets no title bar height, a titled
window uses the default its window view class declares: 32 points for the standard
window view. The content view starts below the title bar and the 1-point divider.
*/
- (void)testATitledWindowUsesTheDefaultTitleBarHeightWhenTheThemeSetsNone
{
var defaultTheme = [CPTheme defaultTheme];
[CPTheme setDefaultTheme:[[CPTheme alloc] initWithName:@"CPWindowTestNoTitleBarHeight"]];
try
{
var window = [[CPWindow alloc] initWithContentRect:CGRectMake(196.0, 540.0, 480.0, 270.0)
styleMask:CPTitledWindowMask | CPClosableWindowMask],
contentFrame = [[window contentView] frame];
[self assert:32 equals:[_CPStandardWindowView titleBarHeight]];
[self assertTrue:CGRectEqualToRect(contentFrame, CGRectMake(1.0, 33.0, 480.0, 270.0))
message:@"content view frame " + CPStringFromRect(contentFrame) + " should be {{1, 33}, {480, 270}}"];
}
finally
{
[CPTheme setDefaultTheme:defaultTheme];
}
}
@end
/*