diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index 933ee6a2d..18d9081c0 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -327,7 +327,7 @@ function ThemeState(stateNames) { if (!stateNames.hasOwnProperty(key)) continue; - if (key != 'normal') + if (key !== 'normal') { this._stateNames[key] = true; stateNameKeys.push(key); @@ -356,13 +356,15 @@ ThemeState.prototype.toString = function() ThemeState.prototype.hasThemeState = function(aState) { - if (aState === undefined || aState === nil || aState._stateNames === undefined) + if (!aState || !aState._stateNames) return false; + // We can do this in O(n) because both states have their stateNames already sorted. for (var stateName in aState._stateNames) { if (!aState._stateNames.hasOwnProperty(stateName)) continue; + if (!this._stateNames[stateName]) return false; } @@ -374,10 +376,11 @@ ThemeState.prototype.isSubsetOf = function(aState) if (aState._stateNameCount < this._stateNameCount) return false; - for (key in this._stateNames) + for (var key in this._stateNames) { if (!this._stateNames.hasOwnProperty(key)) continue; + if (!aState._stateNames[key]) return false; } @@ -386,7 +389,7 @@ ThemeState.prototype.isSubsetOf = function(aState) ThemeState.prototype.without = function(aState) { - if (aState === undefined || aState === nil || aState === [CPNull null]) + if (!aState || aState === [CPNull null]) return aState; var newStates = {}; @@ -445,7 +448,7 @@ function CPThemeState() var stateNames = {}; for (var argIndex = 0; argIndex < arguments.length; argIndex++) { - if (arguments[argIndex] === [CPNull null] || arguments[argIndex] === nil || arguments[argIndex] === undefined) + if (arguments[argIndex] === [CPNull null] || !arguments[argIndex]) continue; if (typeof arguments[argIndex] === 'object') @@ -582,8 +585,8 @@ CPThemeStateKeyWindow = CPThemeState("keyWindow"); - (id)valueForState:(ThemeState)aState { - var stateName = String(aState); - var value = _cache[stateName]; + var stateName = String(aState), + value = _cache[stateName]; // This can be nil. if (value !== undefined) diff --git a/Tests/AppKit/CPThemeTest.j b/Tests/AppKit/CPThemeTest.j index 1803c6619..b033202b0 100644 --- a/Tests/AppKit/CPThemeTest.j +++ b/Tests/AppKit/CPThemeTest.j @@ -62,4 +62,5 @@ [themeAttribute setValue:9 forState:CPThemeState('aState3')]; [self assertTrue:([themeAttribute valueForState:CPThemeState("aState8+aState3+aState4")] == 10) message:"Return the largest partial subset match for a combined state that isn't a perfect match"]; } + @end diff --git a/Tools/nib2cib/_NSCornerView.j b/Tools/nib2cib/_NSCornerView.j index 541b3acb5..d488de69c 100644 --- a/Tools/nib2cib/_NSCornerView.j +++ b/Tools/nib2cib/_NSCornerView.j @@ -51,7 +51,7 @@ { var theme = [Nib2Cib defaultTheme], height = [theme valueForAttributeWithName:@"default-row-height" forClass:[CPTableView class]], - width = [theme valueForAttributeWithName:@"scroller-width" inState:CPThemeState(CPThemeStateVertical, CPThemeStateScrollViewLegacy) forClass:[CPScroller class]]; + width = [theme valueForAttributeWithName:@"scroller-width" inState:CPThemeState(CPThemeStateVertical, CPThemeStateScrollViewLegacy) forClass:[CPScroller class]]; _frame.size.height = height; _bounds.size.height = height;