29 - (void)imageDidLoad:(
CPImage)anImage;
30 - (void)imageDidError:(
CPImage)anImage;
31 - (void)imageDidAbort:(
CPImage)anImage;
74 var filename = arguments[0],
78 if (typeof(arguments[1]) ===
"number")
80 if (arguments[1] !== nil && arguments[1] !== undefined)
81 size = CGSizeMake(arguments[1], arguments[2]);
83 bundle = arguments[3];
85 else if (typeof(arguments[1]) ===
"object")
88 bundle = arguments[2];
131 id <CPImageDelegate> _delegate;
132 unsigned _loadStatus;
133 unsigned _implementedDelegateMethods;
152 - (id)initByReferencingFile:(
CPString)aFilename size:(CGSize)aSize
155 if (aFilename === undefined || aFilename === nil)
162 _size = CGSizeMakeCopy(aSize);
163 _filename = aFilename;
176 - (id)initWithContentsOfFile:(
CPString)aFilename size:(CGSize)aSize
209 var base64 = [someData
base64],
210 type = [base64 hasPrefix:@"/9j/4AAQSkZJRgABAQEASABIAAD/"] ?
@"jpg" :
@"png",
211 dataURL =
"data:image/" + type +
";base64," + base64;
233 if ([_filename hasPrefix:
@"data:image"])
237 var canvas = document.createElement(
"canvas"),
238 ctx = canvas.getContext(
"2d");
240 canvas.width = _image.width;
241 canvas.height = _image.height;
243 ctx.drawImage(_image, 0, 0);
245 dataURL = canvas.toDataURL(
"image/png");
250 var base64 = dataURL.replace(/^data:image\/png;base64,/,
"");
259 - (void)setSize:(CGSize)aSize
261 _size = CGSizeMakeCopy(aSize);
269 return CGSizeMakeCopy(_size);
284 if (!imageOrSize.isa)
286 imageOrSize =
CPAppKitImage(
"CPImage/" + aName +
".png", imageOrSize);
288 [imageOrSize setName:aName];
328 - (void)setDelegate:(
id <CPImageDelegate>)aDelegate
330 if (_delegate === aDelegate)
333 _delegate = aDelegate;
334 _implementedDelegateMethods = 0;
336 if ([_delegate respondsToSelector:
@selector(imageDidLoad:)])
339 if ([_delegate respondsToSelector:
@selector(imageDidError:)])
342 if ([_delegate respondsToSelector:
@selector(imageDidAbort:)])
357 - (unsigned)loadStatus
376 _image =
new Image();
378 var isSynchronous = YES;
381 _image.onload =
function ()
384 window.setTimeout(
function() { [
self _imageDidLoad]; }, 0);
387 [
self _imageDidLoad];
390 [
self _derefFromImage];
393 _image.onerror =
function ()
396 window.setTimeout(
function() { [
self _imageDidError]; }, 0);
399 [
self _imageDidError];
402 [
self _derefFromImage];
405 _image.onabort =
function ()
408 window.setTimeout(
function() { [
self _imageDidAbort]; }, 0);
411 [
self _imageDidAbort];
414 [
self _derefFromImage];
417 _image.src = _filename;
421 window.setTimeout(
function() { isSynchronous = NO; }, 0);
425 - (BOOL)isSingleImage
430 - (BOOL)isThreePartImage
435 - (BOOL)isNinePartImage
445 if (filename.indexOf(
"data:") === 0)
447 var index = filename.indexOf(
",");
450 filename = [
CPString stringWithFormat:@"%s,%s...%s", filename.substr(0, index), filename.substr(index + 1, 10), filename.substr(filename.length - 10)];
452 filename =
"data:<unknown type>";
459 - (void)_derefFromImage
461 _image.onload = null;
462 _image.onerror = null;
463 _image.onabort = null;
467 - (void)_imageDidLoad
472 if (!_size || (_size.width == -1 && _size.height == -1))
473 _size = CGSizeMake(_image.width, _image.height);
480 [_delegate imageDidLoad:self];
484 - (void)_imageDidError
489 [_delegate imageDidError:self];
493 - (void)_imageDidAbort
498 [_delegate imageDidAbort:self];
504 #pragma mark CSS Theming 562 return [[
CPImage alloc] initWithCSSDictionary:aDictionary beforeDictionary:nil afterDictionary:nil size:aSize];
567 return [[
CPImage alloc] initWithCSSDictionary:aDictionary beforeDictionary:beforeDictionary afterDictionary:afterDictionary size:aSize];
573 return [[
CPImage alloc] initWithCSSDictionary:@{} beforeDictionary:nil afterDictionary:nil size:aSize];
582 _size = CGSizeMakeCopy(aSize);
583 _filename =
@"CSS image";
585 _cssDictionary = aDictionary;
586 _cssBeforeDictionary = beforeDictionary;
587 _cssAfterDictionary = afterDictionary;
595 return !!(_cssDictionary || _cssBeforeDictionary || _cssAfterDictionary);
598 - (BOOL)hasCSSDictionary
600 return ([_cssDictionary count] > 0);
603 - (BOOL)hasCSSBeforeDictionary
605 return ([_cssBeforeDictionary count] > 0);
608 - (BOOL)hasCSSAfterDictionary
610 return ([_cssAfterDictionary count] > 0);
613 - (DOMElement)applyCSSImageForView:(
CPView)aView onDOMElement:(DOMElement)aDOMElement styleNode:(DOMElement)aStyleNode previousState:(CPArrayRef)aPreviousStateRef
618 var aPreviousState = @deref(aPreviousStateRef);
620 for (var i = 0, count = aPreviousState.length; i < count; i++)
621 aDOMElement.style[aPreviousState[i][0]] = aPreviousState[i][1];
623 aPreviousState = @[];
627 [_cssDictionary enumerateKeysAndObjectsUsingBlock:function(aKey, anObject, stop)
629 [aPreviousState addObject:@[aKey, aDOMElement.style[aKey]]];
630 aDOMElement.style[aKey] = anObject;
633 if (_cssBeforeDictionary || _cssAfterDictionary)
637 var styleClassName =
@".CP" + [aView UID],
640 if (_cssBeforeDictionary)
642 styleContent += styleClassName +
@"::before { ";
644 [_cssBeforeDictionary enumerateKeysAndObjectsUsingBlock:function(aKey, anObject, stop)
646 styleContent += aKey + ": " + anObject + "; ";
649 styleContent +=
"} ";
652 if (_cssAfterDictionary)
654 styleContent += styleClassName +
@"::after { ";
656 [_cssAfterDictionary enumerateKeysAndObjectsUsingBlock:function(aKey, anObject, stop)
658 styleContent += aKey + ": " + anObject + "; ";
661 styleContent +=
"} ";
664 var styleDescription = document.createTextNode(styleContent);
668 aStyleNode = document.createElement(
"style");
670 aView._DOMElement.insertBefore(aStyleNode, aView._DOMElement.firstChild);
672 aStyleNode.appendChild(styleDescription);
676 aStyleNode.replaceChild(styleDescription, aStyleNode.firstChild);
687 aView._DOMElement.removeChild(aStyleNode);
695 @deref(aPreviousStateRef) = aPreviousState;
719 return [
self initWithCSSDictionary:[aCoder decodeObjectForKey:CPImageCSSDictionaryKey]
beforeDictionary:[aCoder decodeObjectForKey:CPImageCSSBeforeDictionaryKey]
afterDictionary:[aCoder decodeObjectForKey:CPImageCSSAfterDictionaryKey]
size:[aCoder decodeSizeForKey:@"CPSize"]];
730 [aCoder encodeObject:_filename forKey:@"CPFilename"];
731 [aCoder encodeSize:_size forKey:@"CPSize"];
734 if ([
self isCSSBased])
736 [aCoder encodeObject:_cssDictionary forKey:CPImageCSSDictionaryKey];
737 [aCoder encodeObject:_cssBeforeDictionary forKey:CPImageCSSBeforeDictionaryKey];
738 [aCoder encodeObject:_cssAfterDictionary forKey:CPImageCSSAfterDictionaryKey];
746 CPArray _imageSlices;
750 - (id)initWithImageSlices:(CPArray)imageSlices isVertical:(BOOL)isVertical
756 _imageSlices = imageSlices;
757 _isVertical = isVertical;
768 - (CPArray)imageSlices
778 - (BOOL)isSingleImage
783 - (BOOL)isThreePartImage
788 - (BOOL)isNinePartImage
806 _imageSlices = [aCoder decodeObjectForKey:CPThreePartImageImageSlicesKey];
807 _isVertical = [aCoder decodeBoolForKey:CPThreePartImageIsVerticalKey];
815 [aCoder encodeObject:_imageSlices forKey:CPThreePartImageImageSlicesKey];
816 [aCoder encodeBool:_isVertical forKey:CPThreePartImageIsVerticalKey];
824 CPArray _imageSlices;
827 - (id)initWithImageSlices:(CPArray)imageSlices
832 _imageSlices = imageSlices;
842 - (CPArray)imageSlices
847 - (BOOL)isSingleImage
852 - (BOOL)isThreePartImage
857 - (BOOL)isNinePartImage
873 _imageSlices = [aCoder decodeObjectForKey:CPNinePartImageImageSlicesKey];
880 [aCoder encodeObject:_imageSlices forKey:CPNinePartImageImageSlicesKey];
CPImageLoadStatusUnexpectedEOF
function CPImageInBundle()
var CPThreePartImageIsVerticalKey
The main run loop for the application.
var ImageDescriptionFormat
CPImageNameColorPanelHighlighted
CPImageLoadStatusCompleted
var CPNinePartImageImageSlicesKey
A Cappuccino wrapper for any data type.
void postNotificationName:object:(CPString aNotificationName, [object] id anObject)
var CPImageDelegate_imageDidError_
CPImageLoadStatusInvalidData
CPNotificationCenter defaultCenter()
A mutable key-value pair collection.
CPRunLoop currentRunLoop()
var CPImageCSSBeforeDictionaryKey
An immutable string (collection of characters).
var CPThreePartImageImageSlicesKey
CPData dataWithBase64:(CPString aString)
function CPFeatureIsCompatible(aFeature)
CPImageDidLoadNotification
id initWithContentsOfFile:size:(CPString aFilename, [size] CGSize aSize)
function CPAppKitImage(aFilename, aSize)
CPImageLoadStatusReadError
id initWithContentsOfFile:(CPString aFilename)
CPDate limitDateForMode:(CPString aMode)
void setDOMClassName:(CPString aClassName)
CPImageLoadStatusCancelled
Defines methods for use when archiving & restoring (enc/decoding).
Sends messages (CPNotification) between objects.
var CPImageCSSDictionaryKey
CPImageLoadStatusInitialized
var CPImageDelegate_imageDidAbort_
id initByReferencingFile:size:(CPString aFilename, [size] CGSize aSize)
id initWithCSSDictionary:beforeDictionary:afterDictionary:size:(CPDictionary aDictionary, [beforeDictionary] CPDictionary beforeDictionary, [afterDictionary] CPDictionary afterDictionary, [size] CGSize aSize)
var CPImageDelegate_imageDidLoad_
var CPImageCSSAfterDictionaryKey
id stringWithFormat:(CPString format, [,] ...)
FrameUpdater prototype description