Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/cappuccino/cappuccino
Browse files Browse the repository at this point in the history
  • Loading branch information
vhbit committed Dec 7, 2011
2 parents d4ecb03 + 3dff67e commit cce4f78
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 77 deletions.
23 changes: 15 additions & 8 deletions AppKit/CPColor.j
Expand Up @@ -480,7 +480,9 @@ function CPColorWithImages()
parts[3] ? parseFloat(parts[3], 10) : 1.0
];

_cssString = aString;
// We can't reuse aString as _cssString because the browser might not support the `rgba` syntax, and aString might
// use it (issue #1413.)
[self _initCSSStringFromComponents];

return self;
}
Expand All @@ -494,18 +496,23 @@ function CPColorWithImages()
{
_components = components;

var hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0;

_cssString = (hasAlpha ? "rgba(" : "rgb(") +
parseInt(_components[0] * 255.0) + ", " +
parseInt(_components[1] * 255.0) + ", " +
parseInt(_components[2] * 255.0) +
(hasAlpha ? (", " + _components[3]) : "") + ")";
[self _initCSSStringFromComponents];
}

return self;
}

- (void)_initCSSStringFromComponents
{
var hasAlpha = CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0;

_cssString = (hasAlpha ? "rgba(" : "rgb(") +
parseInt(_components[0] * 255.0) + ", " +
parseInt(_components[1] * 255.0) + ", " +
parseInt(_components[2] * 255.0) +
(hasAlpha ? (", " + _components[3]) : "") + ")";
}

/* @ignore */
- (id)_initWithPatternImage:(CPImage)anImage
{
Expand Down
8 changes: 2 additions & 6 deletions AppKit/CPTableView.j
Expand Up @@ -768,10 +768,6 @@ NOT YET IMPLEMENTED
*/
- (void)setSelectionHighlightStyle:(unsigned)aSelectionHighlightStyle
{
//early return for IE.
if (aSelectionHighlightStyle == CPTableViewSelectionHighlightStyleSourceList && !CPFeatureIsCompatible(CPHTMLCanvasFeature))
return;

_selectionHighlightStyle = aSelectionHighlightStyle;
[self setNeedsDisplay:YES];

Expand Down Expand Up @@ -3690,7 +3686,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
if (!count)
return;

var drawGradient = (_selectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList && [_selectedRowIndexes count] >= 1),
var drawGradient = (CPFeatureIsCompatible(CPHTMLCanvasFeature) && _selectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList && [_selectedRowIndexes count] >= 1),
deltaHeight = 0.5 * (_gridStyleMask & CPTableViewSolidHorizontalGridLineMask);

CGContextBeginPath(context);
Expand Down Expand Up @@ -3817,7 +3813,7 @@ Your delegate can implement this method to avoid subclassing the tableview to ad
*/
- (void)_drawGroupRowsForRects:(CPArray)rects
{
if (_selectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList || !rects.length)
if ((CPFeatureIsCompatible(CPHTMLCanvasFeature) && _selectionHighlightStyle === CPTableViewSelectionHighlightStyleSourceList) || !rects.length)
return;

var context = [[CPGraphicsContext currentContext] graphicsPort],
Expand Down
5 changes: 4 additions & 1 deletion AppKit/_CPImageAndTextView.j
Expand Up @@ -390,7 +390,10 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0,
var textStyle = hasDOMTextElement ? _DOMTextElement.style : nil;

// Create or destroy the DOM Text Shadow element as necessary.
var needsDOMTextShadowElement = hasDOMTextElement && !!_textShadowColor,
// If _textShadowColor's alphaComponent is 0, don't bother drawing anything (issue #1412).
// This improves performance as we get rid of an invisible element, and makes IE <9.0 capable
// of correctly 'rendering' shadows with [CPColor clearColor].
var needsDOMTextShadowElement = hasDOMTextElement && [_textShadowColor alphaComponent] > 0.0,
hasDOMTextShadowElement = !!_DOMTextShadowElement;

if (needsDOMTextShadowElement !== hasDOMTextShadowElement)
Expand Down
71 changes: 27 additions & 44 deletions Foundation/CPNotificationCenter.j
Expand Up @@ -85,7 +85,6 @@ var CPNotificationDefaultCenter = nil;

if (aNotificationName == nil)
registry = _unnamedRegistry;

else if (!(registry = [_namedRegistries objectForKey:aNotificationName]))
{
registry = [[_CPNotificationRegistry alloc] init];
Expand Down Expand Up @@ -181,7 +180,6 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */
@implementation _CPNotificationRegistry : CPObject
{
CPDictionary _objectObservers;
BOOL _observerRemovalCount;
}

- (id)init
Expand All @@ -190,7 +188,6 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */

if (self)
{
_observerRemovalCount = 0;
_objectObservers = [CPDictionary dictionary];
}

Expand All @@ -209,12 +206,12 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */

if (!observers)
{
observers = [];
observers = [CPMutableSet set];
[_objectObservers setObject:observers forKey:[anObject UID]];
}

// Add this observer.
observers.push(anObserver);
[observers addObject:anObserver];
}

- (void)removeObserver:(id)anObserver object:(id)anObject
Expand All @@ -231,33 +228,29 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */
while (key = [keys nextObject])
{
var observers = [_objectObservers objectForKey:key],
count = observers ? observers.length : 0;
observer = nil,
observersEnumerator = [observers objectEnumerator];

while (count--)
if ([observers[count] observer] == anObserver)
{
++_observerRemovalCount;
observers.splice(count, 1);
}
while ((observer = [observersEnumerator nextObject]) !== nil)
if ([observer observer] == anObserver)
[observers removeObject:observer];

if (!observers || observers.length == 0)
if (![observers count])
removedKeys.push(key);
}
}
else
{
var key = [anObject UID],
observers = [_objectObservers objectForKey:key],
count = observers ? observers.length : 0;
observer = nil,
observersEnumerator = [observers objectEnumerator];

while (count--)
if ([observers[count] observer] == anObserver)
{
++_observerRemovalCount;
observers.splice(count, 1)
}
while ((observer = [observersEnumerator nextObject]) !== nil)
if ([observer observer] == anObserver)
[observers removeObject:observer];

if (!observers || observers.length == 0)
if (![observers count])
removedKeys.push(key);
}

Expand All @@ -273,26 +266,20 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */
// during the posting of this notification, nor observers that get added. The
// best way to do this is to make a copy of the current observers (this avoids
// new observers from being notified) and double checking every observer against
// the current array (this avoids removed observers from receiving notifications).
// However, this is a very expensive operation (O(N) => O(N^2)), so to avoid it,
// we keep track of whether observers are added or removed, and only do our
// rigorous testing in those cases.
var observerRemovalCount = _observerRemovalCount,
object = [aNotification object],
observers = nil;
// the current set (this avoids removed observers from receiving notifications).
var object = [aNotification object],
currentObservers = nil;

if (object != nil && (currentObservers = [_objectObservers objectForKey:[object UID]]))
{
var observers = [currentObservers copy],
count = observers.length;
observer = nil,
observersEnumerator = [observers objectEnumerator];

while (count--)
while ((observer = [observersEnumerator nextObject]) !== nil)
{
var observer = observers[count];

// if there wasn't removal of an observer during this posting, or there
// was but we are still in the observer list...
if ((observerRemovalCount === _observerRemovalCount) || [currentObservers indexOfObjectIdenticalTo:observer] !== CPNotFound)
// CPSet containsObject is N(1) so this is a fast check.
if ([currentObservers containsObject:observer])
[observer postNotification:aNotification];
}
}
Expand All @@ -303,17 +290,13 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */
if (!currentObservers)
return;

var observerRemovalCount = _observerRemovalCount,
observers = [currentObservers copy],
count = observers.length;
var observers = [currentObservers copy],
observersEnumerator = [observers objectEnumerator];

while (count--)
while ((observer = [observersEnumerator nextObject]) !== nil)
{
var observer = observers[count];

// if there wasn't removal of an observer during this posting, or there
// was but we are still in the observer list...
if ((observerRemovalCount === _observerRemovalCount) || [currentObservers indexOfObjectIdenticalTo:observer] !== CPNotFound)
// CPSet containsObject is N(1) so this is a fast check.
if ([currentObservers containsObject:observer])
[observer postNotification:aNotification];
}
}
Expand Down
32 changes: 16 additions & 16 deletions Objective-J/CFDictionary.js
Expand Up @@ -35,7 +35,7 @@ CFDictionary.prototype.copy = function()
{
// Immutable, so no need to actually copy.
return this;
}
};

CFDictionary.prototype.mutableCopy = function()
{
Expand All @@ -58,12 +58,12 @@ CFDictionary.prototype.mutableCopy = function()
}

return newDictionary;
}
};

CFDictionary.prototype.containsKey = function(/*String*/ aKey)
{
return hasOwnProperty.apply(this._buckets, [aKey]);
}
};

DISPLAY_NAME(CFDictionary.prototype.containsKey);

Expand All @@ -79,21 +79,21 @@ CFDictionary.prototype.containsValue = function(/*id*/ anObject)
return YES;

return NO;
}
};

DISPLAY_NAME(CFDictionary.prototype.containsValue);

CFDictionary.prototype.count = function()
{
return this._count;
}
};

DISPLAY_NAME(CFDictionary.prototype.count);

CFDictionary.prototype.countOfKey = function(/*String*/ aKey)
{
return this.containsKey(aKey) ? 1 : 0;
}
};

DISPLAY_NAME(CFDictionary.prototype.countOfKey);

Expand All @@ -110,14 +110,14 @@ CFDictionary.prototype.countOfValue = function(/*id*/ anObject)
++countOfValue;

return countOfValue;
}
};

DISPLAY_NAME(CFDictionary.prototype.countOfValue);

CFDictionary.prototype.keys = function()
{
return this._keys.slice();
}
};

DISPLAY_NAME(CFDictionary.prototype.keys);

Expand All @@ -129,7 +129,7 @@ CFDictionary.prototype.valueForKey = function(/*String*/ aKey)
return nil;

return buckets[aKey];
}
};

DISPLAY_NAME(CFDictionary.prototype.valueForKey);

Expand All @@ -148,7 +148,7 @@ CFDictionary.prototype.toString = function()
}

return string + "}";
}
};

DISPLAY_NAME(CFDictionary.prototype.toString);

Expand All @@ -162,7 +162,7 @@ CFMutableDictionary.prototype = new CFDictionary();
CFMutableDictionary.prototype.copy = function()
{
return this.mutableCopy();
}
};

CFMutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Object*/ aValue)
{
Expand All @@ -173,7 +173,7 @@ CFMutableDictionary.prototype.addValueForKey = function(/*String*/ aKey, /*Objec

this._keys.push(aKey);
this._buckets[aKey] = aValue;
}
};

DISPLAY_NAME(CFMutableDictionary.prototype.addValueForKey);

Expand Down Expand Up @@ -204,7 +204,7 @@ CFMutableDictionary.prototype.removeValueForKey = function(/*String*/ aKey)

this._keys.splice(indexOfKey, 1);
delete this._buckets[aKey];
}
};

DISPLAY_NAME(CFMutableDictionary.prototype.removeValueForKey);

Expand All @@ -213,7 +213,7 @@ CFMutableDictionary.prototype.removeAllValues = function()
this._count = 0;
this._keys = [];
this._buckets = { };
}
};

DISPLAY_NAME(CFMutableDictionary.prototype.removeAllValues);

Expand All @@ -223,7 +223,7 @@ CFMutableDictionary.prototype.replaceValueForKey = function(/*String*/ aKey, /*O
return;

this._buckets[aKey] = aValue;
}
};

DISPLAY_NAME(CFMutableDictionary.prototype.replaceValueForKey);

Expand All @@ -237,6 +237,6 @@ CFMutableDictionary.prototype.setValueForKey = function(/*String*/ aKey, /*Objec

else
this.addValueForKey(aKey, aValue);
}
};

DISPLAY_NAME(CFMutableDictionary.prototype.setValueForKey);

0 comments on commit cce4f78

Please sign in to comment.