mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-28 01:12:03 +00:00
AppKit: Give every window, menu bar and menus included, its own corner radii
- Remove corner radii from Aristo3 values for every kind of window; menu bar and other borderless windows took sheet corners - Give doc-modal window and sheet 0/0/7/7 px, modal window 6 px, HUD window 5 px, tool tip 2 px - Remove border-radius from modal, doc-modal, HUD, bridge HUD and tool tip bezels - Take window view corners from background when theme gives none; menus keep corners of their style - Round content view to elliptical corners; lay out frame again on new background - Add corner tests for each kind of window, background corners and menu styles
This commit is contained in:
1 parent
fbd08705e9
commit
cf035ac182
5 files changed
+527
-30
No files matched your search
@@ -173,9 +173,22 @@ _CPMenuWindowAttachedMenuBackgroundStyle = 2;
|
||||
return color;
|
||||
}
|
||||
|
||||
/*
|
||||
The method read the menu view's pop-up colour for every style, so a menu under the menu bar
|
||||
took the pop-up background, with its top border and its rounded top corners. It now reads
|
||||
the menu view's value for the style it is given, in the menu view's current state, so that
|
||||
a state such as HUD still gives its own value.
|
||||
*/
|
||||
- (void)setBackgroundStyle:(_CPMenuWindowBackgroundStyle)aBackgroundStyle
|
||||
{
|
||||
var color = [_menuView currentValueForThemeAttribute:@"menu-window-pop-up-background-style-color"];
|
||||
var attributeName = nil;
|
||||
|
||||
if (aBackgroundStyle === _CPMenuWindowPopUpBackgroundStyle)
|
||||
attributeName = @"menu-window-pop-up-background-style-color";
|
||||
else if (aBackgroundStyle === _CPMenuWindowMenuBarBackgroundStyle)
|
||||
attributeName = @"menu-window-menu-bar-background-style-color";
|
||||
|
||||
var color = attributeName ? [_menuView currentValueForThemeAttribute:attributeName] : nil;
|
||||
|
||||
if (!color)
|
||||
color = [[self class] backgroundColorForBackgroundStyle:aBackgroundStyle];
|
||||
|
||||
@@ -46,6 +46,56 @@ var _CPWindowViewCornerResizeRectWidth = 10,
|
||||
|
||||
_CPWindowViewResizeSlop = 3;
|
||||
|
||||
/*
|
||||
Returns the parts of the CSS value aCSSValue that spaces separate. A part with parentheses,
|
||||
such as calc(1px + 2px), stays whole, and a slash outside parentheses is a part of its own.
|
||||
*/
|
||||
function _CPWindowViewCSSParts(aCSSValue)
|
||||
{
|
||||
var parts = [],
|
||||
part = "",
|
||||
depth = 0;
|
||||
|
||||
for (var i = 0, count = aCSSValue.length; i < count; i++)
|
||||
{
|
||||
var character = aCSSValue.charAt(i);
|
||||
|
||||
if (character === "(")
|
||||
depth++;
|
||||
else if (character === ")")
|
||||
depth--;
|
||||
|
||||
if (depth === 0 && (character === "/" || /\s/.test(character)))
|
||||
{
|
||||
if (part.length)
|
||||
parts.push(part);
|
||||
|
||||
if (character === "/")
|
||||
parts.push("/");
|
||||
|
||||
part = "";
|
||||
}
|
||||
else
|
||||
part += character;
|
||||
}
|
||||
|
||||
if (part.length)
|
||||
parts.push(part);
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the horizontal and the vertical component of the corner radius aRadius, which has
|
||||
one component for a circular corner or two for an elliptical one.
|
||||
*/
|
||||
function _CPWindowViewRadiusComponents(aRadius)
|
||||
{
|
||||
var parts = _CPWindowViewCSSParts(aRadius);
|
||||
|
||||
return [parts[0], parts[1] || parts[0]];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the CSS radius for the corner of a view that lies inside a window view corner of
|
||||
radius anOuterRadius, aHorizontalInset and aVerticalInset points from it. Each component is
|
||||
@@ -57,7 +107,9 @@ function _CPWindowViewInnerCornerRadius(anOuterRadius, aHorizontalInset, aVertic
|
||||
if (!anOuterRadius)
|
||||
return "";
|
||||
|
||||
return "max(0px, " + anOuterRadius + " - " + aHorizontalInset + "px) max(0px, " + anOuterRadius + " - " + aVerticalInset + "px)";
|
||||
var components = _CPWindowViewRadiusComponents(anOuterRadius);
|
||||
|
||||
return "max(0px, " + components[0] + " - " + aHorizontalInset + "px) max(0px, " + components[1] + " - " + aVerticalInset + "px)";
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -67,7 +119,106 @@ function _CPWindowViewInnerCornerRadius(anOuterRadius, aHorizontalInset, aVertic
|
||||
*/
|
||||
function _CPWindowViewFrameBorderRadius(anOuterRadius, aWidth)
|
||||
{
|
||||
return "calc(" + (anOuterRadius || "0px") + " + " + aWidth + "px)";
|
||||
var components = _CPWindowViewRadiusComponents(anOuterRadius || "0px"),
|
||||
horizontal = "calc(" + components[0] + " + " + aWidth + "px)";
|
||||
|
||||
return components[1] === components[0] ? horizontal : horizontal + " calc(" + components[1] + " + " + aWidth + "px)";
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the four radii that the parts someParts of one side of a border-radius shorthand
|
||||
give, in the order top left, top right, bottom right, bottom left, as CSS expands one to
|
||||
four values. Returns nil for any other number of parts.
|
||||
*/
|
||||
function _CPWindowViewExpandedCornerParts(someParts)
|
||||
{
|
||||
switch (someParts.length)
|
||||
{
|
||||
case 1:
|
||||
return [someParts[0], someParts[0], someParts[0], someParts[0]];
|
||||
|
||||
case 2:
|
||||
return [someParts[0], someParts[1], someParts[0], someParts[1]];
|
||||
|
||||
case 3:
|
||||
return [someParts[0], someParts[1], someParts[2], someParts[1]];
|
||||
|
||||
case 4:
|
||||
return someParts;
|
||||
|
||||
default:
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the corner radii that aValue, a CSS border-radius shorthand, gives, as an object
|
||||
with topLeft, topRight, bottomLeft and bottomRight, or nil for a value that is not valid.
|
||||
The radii after a slash are the vertical components.
|
||||
*/
|
||||
function _CPWindowViewCornerRadiiOfShorthand(aValue)
|
||||
{
|
||||
var parts = _CPWindowViewCSSParts(aValue),
|
||||
slash = parts.indexOf("/"),
|
||||
horizontal = _CPWindowViewExpandedCornerParts(slash === -1 ? parts : parts.slice(0, slash)),
|
||||
vertical = slash === -1 ? horizontal : _CPWindowViewExpandedCornerParts(parts.slice(slash + 1));
|
||||
|
||||
if (!horizontal || !vertical)
|
||||
return nil;
|
||||
|
||||
var corners = [];
|
||||
|
||||
for (var i = 0; i < 4; i++)
|
||||
corners.push(vertical[i] === horizontal[i] ? horizontal[i] : horizontal[i] + " " + vertical[i]);
|
||||
|
||||
return {
|
||||
topLeft: corners[0],
|
||||
topRight: corners[1],
|
||||
bottomRight: corners[2],
|
||||
bottomLeft: corners[3]
|
||||
};
|
||||
}
|
||||
|
||||
var _CPWindowViewCornerKeys = {
|
||||
topLeft: "border-top-left-radius",
|
||||
topRight: "border-top-right-radius",
|
||||
bottomLeft: "border-bottom-left-radius",
|
||||
bottomRight: "border-bottom-right-radius"
|
||||
};
|
||||
|
||||
/*
|
||||
Returns the corner radii that aColor, a background colour, declares in its CSS dictionary:
|
||||
the shorthand border-radius, with each corner's own key over it. Returns nil when aColor
|
||||
declares no radius.
|
||||
*/
|
||||
function _CPWindowViewCornerRadiiOfBackground(aColor)
|
||||
{
|
||||
var dictionary = [aColor isCSSBased] ? [aColor cssDictionary] : nil;
|
||||
|
||||
if (!dictionary)
|
||||
return nil;
|
||||
|
||||
var shorthand = [dictionary objectForKey:@"border-radius"],
|
||||
radii = (shorthand !== nil && shorthand !== undefined) ? _CPWindowViewCornerRadiiOfShorthand(_CPCSSValueString(shorthand)) : nil,
|
||||
found = !!radii;
|
||||
|
||||
radii = radii || {};
|
||||
|
||||
for (var corner in _CPWindowViewCornerKeys)
|
||||
{
|
||||
if (!_CPWindowViewCornerKeys.hasOwnProperty(corner))
|
||||
continue;
|
||||
|
||||
var value = [dictionary objectForKey:_CPWindowViewCornerKeys[corner]];
|
||||
|
||||
if (value !== nil && value !== undefined)
|
||||
{
|
||||
radii[corner] = _CPCSSValueString(value);
|
||||
found = YES;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? radii : nil;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1212,18 +1363,50 @@ function _CPWindowViewSetCornerRadii(aDOMElement, someRadii)
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the CSS radii of the receiver's corners, from the theme.
|
||||
Returns the CSS radii of the receiver's corners: the theme's radii for its kind of window,
|
||||
else the radii that its background declares.
|
||||
|
||||
A window that sets its shape in code gives it in its background, as a menu window does for
|
||||
each background style (-[_CPMenuWindow setBackgroundStyle:]). The receiver writes its radii
|
||||
on the same element at each layout, and without radii from the theme it wrote empty ones
|
||||
and removed the background's corners. The background is now the second source, so the
|
||||
receiver also rounds its content view to those corners.
|
||||
*/
|
||||
- (JSObject)_cornerRadii
|
||||
{
|
||||
var radii = {
|
||||
topLeft: [self _frameValueForThemeAttribute:@"border-top-left-radius"],
|
||||
topRight: [self _frameValueForThemeAttribute:@"border-top-right-radius"],
|
||||
bottomLeft: [self _frameValueForThemeAttribute:@"border-bottom-left-radius"],
|
||||
bottomRight: [self _frameValueForThemeAttribute:@"border-bottom-right-radius"]
|
||||
};
|
||||
|
||||
if (radii.topLeft == nil && radii.topRight == nil && radii.bottomLeft == nil && radii.bottomRight == nil)
|
||||
radii = _CPWindowViewCornerRadiiOfBackground(_backgroundColorResolved) || radii;
|
||||
|
||||
return {
|
||||
topLeft: [self _frameValueForThemeAttribute:@"border-top-left-radius"] || "",
|
||||
topRight: [self _frameValueForThemeAttribute:@"border-top-right-radius"] || "",
|
||||
bottomLeft: [self _frameValueForThemeAttribute:@"border-bottom-left-radius"] || "",
|
||||
bottomRight: [self _frameValueForThemeAttribute:@"border-bottom-right-radius"] || ""
|
||||
topLeft: radii.topLeft || "",
|
||||
topRight: radii.topRight || "",
|
||||
bottomLeft: radii.bottomLeft || "",
|
||||
bottomRight: radii.bottomRight || ""
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
The corners can come from the background (see -_cornerRadii), so a new background lays out
|
||||
the frame again. Only a change asks for layout: the layout of some window views sets their
|
||||
background each time.
|
||||
*/
|
||||
- (void)setBackgroundColor:(CPColor)aColor
|
||||
{
|
||||
var previousColor = _backgroundColor;
|
||||
|
||||
[super setBackgroundColor:aColor];
|
||||
|
||||
if (_backgroundColor !== previousColor)
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
/*
|
||||
Returns the CSS radii that make the corners of a subview with frame aFrame follow the
|
||||
receiver's corners.
|
||||
|
||||
@@ -8422,20 +8422,21 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
{
|
||||
var toolTipView = [[_CPToolTipWindowView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0) styleMask:_CPToolTipWindowMask],
|
||||
|
||||
// Pure DOM CSS dictionary for Standard Tooltip
|
||||
/*
|
||||
Pure DOM CSS dictionaries for the standard and the HUD tool tip. The corners are the
|
||||
window view's corner radii below. A border-radius in a bezel was overwritten by the
|
||||
window view at each layout.
|
||||
*/
|
||||
bezelColor =[CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": @"#FFFFCA",
|
||||
@"border": @"1px solid #B0B0B0",
|
||||
@"border-radius": @"2px",
|
||||
@"box-sizing": @"border-box",
|
||||
@"box-shadow": @"0px 1px 3px rgba(0,0,0,0.25)"
|
||||
}],
|
||||
|
||||
// Pure DOM CSS dictionary for HUD Tooltip
|
||||
|
||||
hudBezelColor =[CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": @"rgba(0, 0, 0, 0.85)",
|
||||
@"border": @"1px solid rgba(255, 255, 255, 0.25)",
|
||||
@"border-radius": @"2px",
|
||||
@"box-sizing": @"border-box",
|
||||
@"box-shadow": @"0px 2px 5px rgba(0,0,0,0.5)"
|
||||
}],
|
||||
@@ -8450,6 +8451,10 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
// --- Standard Theme Mappings ---
|
||||
[@"bezel-color", bezelColor],
|
||||
[@"color", [CPColor blackColor]],
|
||||
[@"border-top-left-radius", @"2px"],
|
||||
[@"border-top-right-radius", @"2px"],
|
||||
[@"border-bottom-left-radius", @"2px"],
|
||||
[@"border-bottom-right-radius", @"2px"],
|
||||
|
||||
// --- HUD Theme Mappings ---
|
||||
[@"bezel-color", hudBezelColor, CPThemeStateHUD],
|
||||
@@ -8998,17 +9003,23 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
{
|
||||
var modalWindowView = [[_CPModalWindowView alloc] initWithFrame:CGRectMake(0, 0, 200, 200) styleMask:_CPModalWindowView];
|
||||
|
||||
// Using pure CSS window frame
|
||||
/*
|
||||
Using pure CSS window frame. The corners are the window view's corner radii below. A
|
||||
border-radius in the bezel was overwritten by the window view at each layout.
|
||||
*/
|
||||
var bezelColor = [CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": A3ColorBackground,
|
||||
@"border": @[@"1px solid ", A3ColorWindowBorder],
|
||||
@"border-radius": @"6px",
|
||||
@"box-shadow": @"0 5px 15px rgba(0,0,0,0.5)"
|
||||
}],
|
||||
|
||||
themeValues =
|
||||
[
|
||||
[@"bezel-color", bezelColor]
|
||||
[@"bezel-color", bezelColor],
|
||||
[@"border-top-left-radius", @"6px"],
|
||||
[@"border-top-right-radius", @"6px"],
|
||||
[@"border-bottom-left-radius", @"6px"],
|
||||
[@"border-bottom-right-radius", @"6px"]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themeValues forView:modalWindowView];
|
||||
@@ -9031,7 +9042,13 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
"background-color": A3ColorActiveText
|
||||
} size:CGSizeMake(12, 12)],
|
||||
|
||||
// Global
|
||||
/*
|
||||
Values for every kind of window. They gave the corner radii of a sheet, 0, 0, 7 and 7
|
||||
points. A window view takes its frame values from the nearest class that has them,
|
||||
and the HUD and bridge views copy these values, so every kind of window took the
|
||||
sheet's rounded bottom corners: the menu bar, the full-page bridge window, tool tips
|
||||
and popovers too. Each kind of window that has rounded corners now gives its own.
|
||||
*/
|
||||
themedWindowViewValues =
|
||||
[
|
||||
[@"shadow-inset", CGInsetMake(0, 0, 0, 0)],
|
||||
@@ -9042,11 +9059,7 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
[@"shadow-height", 5],
|
||||
[@"shadown-horizontal-offset", 2],
|
||||
[@"sheet-vertical-offset", -1],
|
||||
[@"size-indicator", CGSizeMake(12, 12)],
|
||||
[@"border-top-left-radius", @"0px"],
|
||||
[@"border-top-right-radius", @"0px"],
|
||||
[@"border-bottom-left-radius", @"7px"],
|
||||
[@"border-bottom-right-radius", @"7px"]
|
||||
[@"size-indicator", CGSizeMake(12, 12)]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themedWindowViewValues forView:windowView];
|
||||
@@ -9058,9 +9071,12 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
{
|
||||
var HUDWindowView = [[_CPHUDWindowView alloc] initWithFrame:CGRectMake(0, 0, 200, 200) styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask],
|
||||
|
||||
/*
|
||||
The corners are the window view's corner radii below. A border-radius in the bezel was
|
||||
overwritten by the window view at each layout.
|
||||
*/
|
||||
HUDBezelColor = [CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": @"rgba(0, 0, 0, 0.85)",
|
||||
@"border-radius": @"5px"
|
||||
@"background-color": @"rgba(0, 0, 0, 0.85)"
|
||||
}],
|
||||
|
||||
closeImage = [CPImage imageWithCSSDictionary:@{
|
||||
@@ -9093,7 +9109,11 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
[@"title-alignment", CPCenterTextAlignment],
|
||||
[@"title-line-break-mode", CPLineBreakByTruncatingTail],
|
||||
[@"title-vertical-alignment", CPCenterVerticalTextAlignment],
|
||||
[@"title-bar-height", 26]
|
||||
[@"title-bar-height", 26],
|
||||
[@"border-top-left-radius", @"5px"],
|
||||
[@"border-top-right-radius", @"5px"],
|
||||
[@"border-bottom-left-radius", @"5px"],
|
||||
[@"border-bottom-right-radius", @"5px"]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themeValues forView:HUDWindowView inherit:themedWindowViewValues];
|
||||
@@ -9337,11 +9357,16 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
{
|
||||
var docModalWindowView = [[_CPDocModalWindowView alloc] initWithFrame:CGRectMake(0, 0, 200, 200) styleMask:nil];
|
||||
|
||||
// Apply the same styling as the standard Modal Window to cover the background
|
||||
/*
|
||||
Apply the same styling as the standard Modal Window to cover the background. A sheet
|
||||
hangs from the title bar of its parent, so its top corners are square and its bottom
|
||||
corners round: the window view's corner radii below, which a sheet of a standard window
|
||||
takes too. A border-radius in the bezel was overwritten by the window view at each
|
||||
layout.
|
||||
*/
|
||||
var bezelColor = [CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": A3ColorBackgroundWhite,
|
||||
@"border": @[@"1px solid ", A3ColorWindowBorder],
|
||||
@"border-radius": @"6px",
|
||||
@"box-shadow": @"0 5px 15px rgba(0,0,0,0.5)"
|
||||
}];
|
||||
|
||||
@@ -9349,7 +9374,11 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
[@"bezel-color", bezelColor],
|
||||
[@"body-color", [CPColor whiteColor]],
|
||||
[@"shadow-height", 0.0],
|
||||
[@"title-bar-height", 0.0]
|
||||
[@"title-bar-height", 0.0],
|
||||
[@"border-top-left-radius", @"0px"],
|
||||
[@"border-top-right-radius", @"0px"],
|
||||
[@"border-bottom-left-radius", @"7px"],
|
||||
[@"border-bottom-right-radius", @"7px"]
|
||||
];
|
||||
|
||||
[self registerThemeValues:themeValues forView:docModalWindowView];
|
||||
@@ -9367,10 +9396,16 @@ function A3MaskIcon(aMaskImage, aColor)
|
||||
@"border-bottom": @[@"1px solid ", A3ColorBorderLight]
|
||||
}],
|
||||
|
||||
// HUD Theme Window Background (Dark/Translucent)
|
||||
/*
|
||||
HUD Theme Window Background (Dark/Translucent)
|
||||
|
||||
This bezel declared a 5 px border-radius, copied from the HUD window's bezel. A bridge
|
||||
window fills the browser window and has square corners, so the bezel declares none.
|
||||
No code reads this value: the bridge view sets a black background for the HUD style
|
||||
itself, and its window view never takes the HUD state.
|
||||
*/
|
||||
hudBezelColor = [CPColor colorWithCSSDictionary:@{
|
||||
@"background-color": @"rgba(0, 0, 0, 0.85)",
|
||||
@"border-radius": @"5px",
|
||||
@"box-shadow": @"0 5px 15px rgba(0,0,0,0.5)"
|
||||
}],
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
@import <AppKit/CPApplication.j>
|
||||
@import <AppKit/CPText.j>
|
||||
|
||||
@import "BuiltThemes.j"
|
||||
|
||||
|
||||
@implementation CPMenuTest : OJTestCase
|
||||
{
|
||||
@@ -239,4 +241,34 @@
|
||||
undoWasCalled = YES;
|
||||
}
|
||||
|
||||
/*
|
||||
A menu window takes the background of the style it is given. Every style took the pop-up
|
||||
background. The test reads the built Aristo3 theme, so it needs the themes built first, as
|
||||
`npx jake build` does.
|
||||
*/
|
||||
- (void)testEachBackgroundStyleTakesItsOwnBackground
|
||||
{
|
||||
var aristo3 = BuiltThemeNamed(@"Aristo3"),
|
||||
previousTheme = [CPTheme defaultTheme];
|
||||
|
||||
[self assertNotNull:aristo3 message:@"The built blends hold no Aristo3 theme. Build the themes first."];
|
||||
|
||||
[CPTheme setDefaultTheme:aristo3];
|
||||
|
||||
try
|
||||
{
|
||||
var menuWindow = [[_CPMenuWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 100.0, 100.0) styleMask:CPBorderlessWindowMask];
|
||||
|
||||
[menuWindow setBackgroundStyle:_CPMenuWindowMenuBarBackgroundStyle];
|
||||
[self assert:[aristo3 valueForAttributeWithName:@"menu-window-menu-bar-background-style-color" forClass:_CPMenuView] same:[menuWindow backgroundColor]];
|
||||
|
||||
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
|
||||
[self assert:[aristo3 valueForAttributeWithName:@"menu-window-pop-up-background-style-color" forClass:_CPMenuView] same:[menuWindow backgroundColor]];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[CPTheme setDefaultTheme:previousTheme];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
@import "BuiltThemes.j"
|
||||
|
||||
@implementation CPWindowViewCornerTest : OJTestCase
|
||||
|
||||
- (void)setUp
|
||||
@@ -52,6 +54,36 @@
|
||||
[self assert:@"calc(0px + 1px)" equals:_CPWindowViewFrameBorderRadius(@"", 1)];
|
||||
}
|
||||
|
||||
- (void)testAnEllipticalCornerTakesEachComponentApart
|
||||
{
|
||||
[self assert:@"max(0px, 2px - 1px) max(0px, 4px - 3px)" equals:_CPWindowViewInnerCornerRadius(@"2px 4px", 1, 3)];
|
||||
[self assert:@"calc(2px + 1px) calc(4px + 1px)" equals:_CPWindowViewFrameBorderRadius(@"2px 4px", 1)];
|
||||
}
|
||||
|
||||
- (void)assertCorners:(CPArray)expected ofRadii:(JSObject)someRadii message:(CPString)aMessage
|
||||
{
|
||||
[self assertNotNull:someRadii message:aMessage];
|
||||
[self assert:expected[0] equals:someRadii.topLeft message:aMessage + @", top left"];
|
||||
[self assert:expected[1] equals:someRadii.topRight message:aMessage + @", top right"];
|
||||
[self assert:expected[2] equals:someRadii.bottomLeft message:aMessage + @", bottom left"];
|
||||
[self assert:expected[3] equals:someRadii.bottomRight message:aMessage + @", bottom right"];
|
||||
}
|
||||
|
||||
/*
|
||||
One to four values give the corners top left, top right, bottom right and bottom left, as
|
||||
CSS expands them. The values after a slash are the vertical radii.
|
||||
*/
|
||||
- (void)testTheBorderRadiusShorthandGivesEachCornerAsCSSExpandsIt
|
||||
{
|
||||
[self assertCorners:[@"6px", @"6px", @"6px", @"6px"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"6px") message:@"one value"];
|
||||
[self assertCorners:[@"1px", @"2px", @"2px", @"1px"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"1px 2px") message:@"two values"];
|
||||
[self assertCorners:[@"1px", @"2px", @"2px", @"3px"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"1px 2px 3px") message:@"three values"];
|
||||
[self assertCorners:[@"1px", @"2px", @"4px", @"3px"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"1px 2px 3px 4px") message:@"four values"];
|
||||
[self assertCorners:[@"2px 4px", @"2px 4px", @"2px 4px", @"2px 4px"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"2px / 4px") message:@"a slash"];
|
||||
[self assertCorners:[@"calc(1px + 2px)", @"calc(1px + 2px)", @"calc(1px + 2px)", @"calc(1px + 2px)"] ofRadii:_CPWindowViewCornerRadiiOfShorthand(@"calc(1px + 2px)") message:@"a value with spaces"];
|
||||
[self assertNull:_CPWindowViewCornerRadiiOfShorthand(@"1px 2px 3px 4px 5px") message:@"five values"];
|
||||
}
|
||||
|
||||
- (void)testASheetTakesTheFrameShapeOfADocumentModalWindow
|
||||
{
|
||||
var parent = [self window],
|
||||
@@ -108,4 +140,206 @@
|
||||
[self assert:otherView same:windowView._cornerClippedView message:@"The next layout rounds the new content view"];
|
||||
}
|
||||
|
||||
// MARK: Corners of each kind of window under Aristo3
|
||||
|
||||
/*
|
||||
These tests read the built Aristo3 theme, so they need the themes built first, as
|
||||
`npx jake build` does.
|
||||
*/
|
||||
- (CPTheme)aristo3
|
||||
{
|
||||
var theme = BuiltThemeNamed(@"Aristo3");
|
||||
|
||||
[self assertNotNull:theme message:@"The built blends hold no Aristo3 theme. Build the themes first."];
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
/*
|
||||
Returns a window view of aClass that takes its values from the built Aristo3 theme.
|
||||
*/
|
||||
- (_CPWindowView)aristo3WindowViewOfClass:(Class)aClass styleMask:(unsigned)aStyleMask
|
||||
{
|
||||
var windowView = [[aClass alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 200.0) styleMask:aStyleMask];
|
||||
|
||||
[windowView setTheme:[self aristo3]];
|
||||
|
||||
return windowView;
|
||||
}
|
||||
|
||||
- (void)assertCorners:(CPArray)expected of:(_CPWindowView)aWindowView
|
||||
{
|
||||
var radii = [aWindowView _cornerRadii],
|
||||
name = [aWindowView className];
|
||||
|
||||
[self assert:expected[0] equals:radii.topLeft message:name + @" top left"];
|
||||
[self assert:expected[1] equals:radii.topRight message:name + @" top right"];
|
||||
[self assert:expected[2] equals:radii.bottomLeft message:name + @" bottom left"];
|
||||
[self assert:expected[3] equals:radii.bottomRight message:name + @" bottom right"];
|
||||
}
|
||||
|
||||
/*
|
||||
The menu bar is a borderless window. These windows took the rounded bottom corners of a
|
||||
sheet from the values for every kind of window.
|
||||
*/
|
||||
- (void)testWindowsWithoutAFrameShapeHaveSquareCorners
|
||||
{
|
||||
[self assertCorners:[@"", @"", @"", @""] of:[self aristo3WindowViewOfClass:_CPBorderlessWindowView styleMask:CPBorderlessWindowMask]];
|
||||
[self assertCorners:[@"", @"", @"", @""] of:[self aristo3WindowViewOfClass:_CPBorderlessBridgeWindowView styleMask:CPBorderlessBridgeWindowMask]];
|
||||
[self assertCorners:[@"", @"", @"", @""] of:[self aristo3WindowViewOfClass:_CPPopoverWindowView styleMask:CPBorderlessWindowMask]];
|
||||
}
|
||||
|
||||
- (void)testEachKindOfWindowWithRoundedCornersGivesItsOwn
|
||||
{
|
||||
[self assertCorners:[@"6px", @"6px", @"7px", @"7px"] of:[self aristo3WindowViewOfClass:_CPStandardWindowView styleMask:CPTitledWindowMask]];
|
||||
[self assertCorners:[@"0px", @"0px", @"7px", @"7px"] of:[self aristo3WindowViewOfClass:_CPDocModalWindowView styleMask:CPDocModalWindowMask]];
|
||||
[self assertCorners:[@"6px", @"6px", @"6px", @"6px"] of:[self aristo3WindowViewOfClass:_CPModalWindowView styleMask:_CPModalWindowMask]];
|
||||
[self assertCorners:[@"5px", @"5px", @"5px", @"5px"] of:[self aristo3WindowViewOfClass:_CPHUDWindowView styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask]];
|
||||
[self assertCorners:[@"2px", @"2px", @"2px", @"2px"] of:[self aristo3WindowViewOfClass:_CPToolTipWindowView styleMask:_CPToolTipWindowMask]];
|
||||
}
|
||||
|
||||
- (void)testASheetHasTheCornersOfADocumentModalWindow
|
||||
{
|
||||
var parent = [self window],
|
||||
sheet = [self window],
|
||||
windowView = [sheet _windowView];
|
||||
|
||||
[windowView setTheme:[self aristo3]];
|
||||
[windowView _enableSheet:YES inWindow:parent];
|
||||
|
||||
[self assertCorners:[@"0px", @"0px", @"7px", @"7px"] of:windowView];
|
||||
}
|
||||
|
||||
/*
|
||||
The theme gives the corners of a kind of window in its corner radii. A border-radius in
|
||||
the bezel of the same kind would lose to them at each layout, and only confuse the reader.
|
||||
*/
|
||||
- (void)testNoWindowBezelGivesCornersOfItsOwn
|
||||
{
|
||||
var theme = [self aristo3],
|
||||
classes = [_CPWindowView, _CPStandardWindowView, _CPDocModalWindowView, _CPModalWindowView, _CPHUDWindowView,
|
||||
_CPBorderlessWindowView, _CPBorderlessBridgeWindowView, _CPToolTipWindowView, _CPPopoverWindowView],
|
||||
violations = [];
|
||||
|
||||
for (var i = 0; i < classes.length; i++)
|
||||
{
|
||||
var values = [[theme attributeWithName:@"bezel-color" forClass:classes[i]] values];
|
||||
|
||||
/*
|
||||
Some kinds of window, such as the base window view and the borderless window, have
|
||||
no bezel in the theme, so they have no bezel corners to check.
|
||||
*/
|
||||
if (!values)
|
||||
continue;
|
||||
|
||||
var states = [values allKeys];
|
||||
|
||||
for (var j = 0; j < states.length; j++)
|
||||
{
|
||||
var bezel = [values objectForKey:states[j]],
|
||||
location = class_getName(classes[i]) + @" (" + states[j] + @"): ";
|
||||
|
||||
if (!bezel || !bezel.isa || ![bezel isKindOfClass:[CPColor class]])
|
||||
continue;
|
||||
|
||||
[[bezel cssDictionary], [bezel cssBeforeDictionary], [bezel cssAfterDictionary]].forEach(function(aDictionary)
|
||||
{
|
||||
if (!aDictionary)
|
||||
return;
|
||||
|
||||
[aDictionary allKeys].forEach(function(aKey)
|
||||
{
|
||||
if (/radius/.test(aKey))
|
||||
violations.push(location + aKey);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[self assertTrue:violations.length === 0 message:violations.join("\n")];
|
||||
}
|
||||
|
||||
// MARK: Corners from the background
|
||||
|
||||
/*
|
||||
A window that the theme gives no corners takes the corners that its background declares,
|
||||
each corner's own key over the shorthand.
|
||||
*/
|
||||
- (void)testAWindowWithoutThemeCornersTakesTheCornersOfItsBackground
|
||||
{
|
||||
var windowView = [self aristo3WindowViewOfClass:_CPBorderlessWindowView styleMask:CPBorderlessWindowMask];
|
||||
|
||||
[windowView setBackgroundColor:[CPColor colorWithCSSDictionary:@{
|
||||
@"border-top-left-radius": @"0px",
|
||||
@"border-top-right-radius": @"0px",
|
||||
@"border-bottom-left-radius": @"7px",
|
||||
@"border-bottom-right-radius": @"7px"
|
||||
}]];
|
||||
[self assertCorners:[@"0px", @"0px", @"7px", @"7px"] of:windowView];
|
||||
|
||||
[windowView setBackgroundColor:[CPColor colorWithCSSDictionary:@{
|
||||
@"border-radius": @"6px",
|
||||
@"border-bottom-left-radius": @"1px"
|
||||
}]];
|
||||
[self assertCorners:[@"6px", @"6px", @"1px", @"6px"] of:windowView];
|
||||
|
||||
[windowView setBackgroundColor:[CPColor colorWithCSSDictionary:@{ @"background-color": @"rgb(1, 2, 3)" }]];
|
||||
[self assertCorners:[@"", @"", @"", @""] of:windowView];
|
||||
}
|
||||
|
||||
- (void)testTheThemeCornersComeBeforeTheBackground
|
||||
{
|
||||
var windowView = [self aristo3WindowViewOfClass:_CPModalWindowView styleMask:_CPModalWindowMask];
|
||||
|
||||
[windowView setBackgroundColor:[CPColor colorWithCSSDictionary:@{ @"border-radius": @"1px" }]];
|
||||
|
||||
[self assertCorners:[@"6px", @"6px", @"6px", @"6px"] of:windowView];
|
||||
}
|
||||
|
||||
/*
|
||||
The corners can come from the background, so a new background lays out the frame again.
|
||||
The same background does not.
|
||||
*/
|
||||
- (void)testANewBackgroundLaysOutTheFrameAgain
|
||||
{
|
||||
var windowView = [self aristo3WindowViewOfClass:_CPBorderlessWindowView styleMask:CPBorderlessWindowMask],
|
||||
background = [CPColor colorWithCSSDictionary:@{ @"border-radius": @"6px" }];
|
||||
|
||||
[windowView layoutIfNeeded];
|
||||
[windowView setBackgroundColor:background];
|
||||
|
||||
[self assertTrue:[windowView needsLayout] message:@"a new background"];
|
||||
|
||||
[windowView layoutIfNeeded];
|
||||
[windowView setBackgroundColor:background];
|
||||
|
||||
[self assertFalse:[windowView needsLayout] message:@"the same background"];
|
||||
}
|
||||
|
||||
/*
|
||||
A menu window gives its shape in its background, for each background style. The window
|
||||
view wrote empty radii over it and removed the menu's corners.
|
||||
*/
|
||||
- (void)testAMenuWindowHasTheCornersOfItsBackgroundStyle
|
||||
{
|
||||
var previousTheme = [CPTheme defaultTheme];
|
||||
|
||||
[CPTheme setDefaultTheme:[self aristo3]];
|
||||
|
||||
try
|
||||
{
|
||||
var menuWindow = [[_CPMenuWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 100.0, 100.0) styleMask:CPBorderlessWindowMask];
|
||||
|
||||
[menuWindow setBackgroundStyle:_CPMenuWindowMenuBarBackgroundStyle];
|
||||
[self assertCorners:[@"0px", @"0px", @"7px", @"7px"] of:[menuWindow _windowView]];
|
||||
|
||||
[menuWindow setBackgroundStyle:_CPMenuWindowPopUpBackgroundStyle];
|
||||
[self assertCorners:[@"6px", @"6px", @"7px", @"7px"] of:[menuWindow _windowView]];
|
||||
}
|
||||
finally
|
||||
{
|
||||
[CPTheme setDefaultTheme:previousTheme];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user