From 7d59762561ad4644ef9b2fffa355f5a5a1dbc6c0 Mon Sep 17 00:00:00 2001 From: David Richardson Date: Mon, 31 Aug 2026 17:04:24 -0600 Subject: [PATCH] AppKit: CPLayoutManager, CPStringDrawing, CPMenu, CPCookie PLATFORM conditional removal - 8 PLATFORM blocks resolved across four files: runtime CPDOMAvailable guards (3 wrapped, 2 early returns, 3 if/else preserving existing CommonJS branches) - CPMenu: @global _CPDOMEventStop declared; its definition resides in the DOM-only CPPlatformWindow+DOM category - zero preprocessor directives remain in these files - work-in-progress towards complete removal of CPP directives --- AppKit/CPCookie.j | 40 +++++++++++-------- AppKit/CPMenu/CPMenu.j | 16 +++++--- AppKit/CPStringDrawing.j | 60 +++++++++++++++-------------- AppKit/CPTextView/CPLayoutManager.j | 14 +++---- 4 files changed, 71 insertions(+), 59 deletions(-) diff --git a/AppKit/CPCookie.j b/AppKit/CPCookie.j index 1b05644c1..c63901f44 100644 --- a/AppKit/CPCookie.j +++ b/AppKit/CPCookie.j @@ -22,6 +22,7 @@ @import @import +@import "CPCompatibility.j" /*! @@ -95,32 +96,37 @@ else domain = ""; -#if PLATFORM(DOM) - document.cookie = _cookieName + "=" + value + expires + "; path=/" + domain; -#else - _cookieValue = value; - _expires = expires; -#endif + if (CPDOMAvailable) + { + document.cookie = _cookieName + "=" + value + expires + "; path=/" + domain; + } + else + { + _cookieValue = value; + _expires = expires; + } } /* @ignore */ - (CPString)_readCookieValue { -#if PLATFORM(DOM) - var nameEQ = _cookieName + "=", - ca = document.cookie.split(';'); - - for (var i = 0; i < ca.length; i++) + if (CPDOMAvailable) { - var c = ca[i]; + var nameEQ = _cookieName + "=", + ca = document.cookie.split(';'); - while (c.charAt(0) == ' ') - c = c.substring(1, c.length); + for (var i = 0; i < ca.length; i++) + { + var c = ca[i]; - if (c.indexOf(nameEQ) == 0) - return c.substring(nameEQ.length, c.length); + while (c.charAt(0) == ' ') + c = c.substring(1, c.length); + + if (c.indexOf(nameEQ) == 0) + return c.substring(nameEQ.length, c.length); + } } -#endif + return ""; } diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 90436c30a..00a3659ce 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -28,6 +28,7 @@ @import "CPKeyValueBinding.j" @import "CPMenuItem.j" @import "CALayer.j" +@import "CPCompatibility.j" @global CPApp @@ -136,9 +137,10 @@ var _CPMenuBarVisible = NO, [_CPMenuBarSharedWindow orderOut:self]; // FIXME: There must be a better way to do this. -#if PLATFORM(DOM) - [[CPPlatformWindow primaryPlatformWindow] resizeEvent:nil]; -#endif + if (CPDOMAvailable) + { + [[CPPlatformWindow primaryPlatformWindow] resizeEvent:nil]; + } } + (void)setMenuBarTitle:(CPString)aTitle @@ -1078,14 +1080,14 @@ var _CPMenuBarVisible = NO, anEvent._isKeyEquivalent = YES; // prevent the menu keystroke from beeing inserted into textview [self performActionForItemAtIndex:index]; -#if PLATFORM(DOM) // we are done with this event in cappuccino space. do not let the browser do something weird additionally (e.g. command-o). // but we must not stop copy/paste events as these can only be handled by the browser at this time even if they are in our menu // (until we move to CPTextView as the fieleditor) - if (characters != "c" && characters != "x" && characters != "v") + if (CPDOMAvailable && characters != "c" && characters != "x" && characters != "v") + { _CPDOMEventStop(anEvent._DOMEvent); -#endif + } } else { @@ -1389,3 +1391,5 @@ var CPMenuTitleKey = @"CPMenuTitleKey", @import "_CPMenuBarWindow.j" @import "_CPMenuWindow.j" + +@global _CPDOMEventStop diff --git a/AppKit/CPStringDrawing.j b/AppKit/CPStringDrawing.j index 81cdca94d..ebf903ed9 100644 --- a/AppKit/CPStringDrawing.j +++ b/AppKit/CPStringDrawing.j @@ -62,7 +62,8 @@ CPCanvasStringSizingIsFunctional = NO; if ([self class] != [CPString class]) return; -#if PLATFORM(DOM) + if (!CPDOMAvailable) return; + if (CPFeatureIsCompatible(CPHTMLCanvasFeature)) { if (!CPStringSizeMeasuringContext) @@ -73,46 +74,47 @@ CPCanvasStringSizingIsFunctional = NO; CPCanvasStringSizingIsFunctional = NO; } -#endif } - (CGSize)sizeWithFont:(CPFont)aFont inWidth:(float)aWidth { var size; -#if PLATFORM(DOM) - var sizeCacheForFont = CPStringSizeWithFontInWidthCache[self]; - - if (sizeCacheForFont === undefined) - sizeCacheForFont = CPStringSizeWithFontInWidthCache[self] = []; - - var cssString = [aFont cssString], - cacheKey = cssString + '_' + (aWidth ? aWidth : '0'); - - size = sizeCacheForFont[cacheKey]; - - if (size !== undefined && sizeCacheForFont.hasOwnProperty(cacheKey)) - return CGSizeMakeCopy(size); - - if (!CPCanvasStringSizingIsFunctional || aWidth) - size = [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth]; - else + if (CPDOMAvailable) { - if (CPPlatformHasBug(CPTextSizingAlwaysNeedsSetFontBug) || CPStringSizeMeasuringContext.font !== cssString) - CPStringSizeMeasuringContext.font = cssString; + var sizeCacheForFont = CPStringSizeWithFontInWidthCache[self]; - var fontHeight = CPStringSizeWithFontHeightCache[cssString]; + if (sizeCacheForFont === undefined) + sizeCacheForFont = CPStringSizeWithFontInWidthCache[self] = []; - if (fontHeight === undefined) - fontHeight = CPStringSizeWithFontHeightCache[cssString] = [aFont defaultLineHeightForFont]; + var cssString = [aFont cssString], + cacheKey = cssString + '_' + (aWidth ? aWidth : '0'); - size = CGSizeMake(CPStringSizeMeasuringContext.measureText(self).width, fontHeight); + size = sizeCacheForFont[cacheKey]; + + if (size !== undefined && sizeCacheForFont.hasOwnProperty(cacheKey)) + return CGSizeMakeCopy(size); + + if (!CPCanvasStringSizingIsFunctional || aWidth) + size = [CPPlatformString sizeOfString:self withFont:aFont forWidth:aWidth]; + else + { + if (CPPlatformHasBug(CPTextSizingAlwaysNeedsSetFontBug) || CPStringSizeMeasuringContext.font !== cssString) + CPStringSizeMeasuringContext.font = cssString; + + var fontHeight = CPStringSizeWithFontHeightCache[cssString]; + + if (fontHeight === undefined) + fontHeight = CPStringSizeWithFontHeightCache[cssString] = [aFont defaultLineHeightForFont]; + + size = CGSizeMake(CPStringSizeMeasuringContext.measureText(self).width, fontHeight); + } + + sizeCacheForFont[cacheKey] = size; } + else + size = CGSizeMake(0, 0); - sizeCacheForFont[cacheKey] = size; -#else - size = CGSizeMake(0, 0); -#endif return CGSizeMakeCopy(size); } diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index f971dd62f..2a14bd204 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -28,6 +28,7 @@ @import "CGContext.j" @import "CPTypesetter.j" @import "CPFont.j" +@import "CPCompatibility.j" @global _MakeRangeFromAbs @global document @@ -297,9 +298,10 @@ _oncontextmenuhandler = function () { return false; }; [_typesetter layoutGlyphsInLayoutManager:self startingAtGlyphIndex:startIndex maxNumberOfLineFragments:-1 nextGlyphIndex:nil]; -#if PLATFORM(DOM) - [self _cleanUpDOM]; -#endif + if (CPDOMAvailable) + { + [self _cleanUpDOM]; + } _isValidatingLayoutAndGlyphs = NO; } @@ -1145,7 +1147,8 @@ var _objectsInRange = function(aList, aRange) if (!aString || aString.length === 0) return nil; -#if PLATFORM(DOM) + if (!CPDOMAvailable) return nil; + var style, span = document.createElement("span"); @@ -1196,9 +1199,6 @@ var _objectsInRange = function(aList, aRange) span.textContent = aString; return span; -#else - return nil; -#endif } - (id)initWithRange:(CPRange)aRange textContainer:(CPTextContainer)aContainer textStorage:(CPTextStorage)textStorage