diff --git a/AppKit/CPImage.j b/AppKit/CPImage.j index f51d44805a..b5baef5540 100644 --- a/AppKit/CPImage.j +++ b/AppKit/CPImage.j @@ -20,10 +20,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import -import import +import +import import +import import "CPGeometry.j" @@ -35,6 +36,8 @@ CPImageLoadStatusInvalidData = 4; CPImageLoadStatusUnexpectedEOF = 5; CPImageLoadStatusReadError = 6; +CPImageDidLoadNotification = @"CPImageDidLoadNotification"; + @implementation CPBundle (CPImageAdditions) - (CPString)pathForResource:(CPString)aFilename @@ -219,7 +222,11 @@ CPImageLoadStatusReadError = 6; // FIXME: IE is wrong on image sizes???? if (!_size || (_size.width == -1 && _size.height == -1)) _size = CGSizeMake(_image.width, _image.height); - + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPImageDidLoadNotification + object:self]; + if ([_delegate respondsToSelector:@selector(imageDidLoad:)]) [_delegate imageDidLoad:self]; diff --git a/AppKit/CPImageView.j b/AppKit/CPImageView.j index 6aa860c5c3..5cba2ae88f 100644 --- a/AppKit/CPImageView.j +++ b/AppKit/CPImageView.j @@ -20,8 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -import "CPImage.j" +import + import "CPControl.j" +import "CPImage.j" import "CPShadowView.j" #include "Platform/Platform.h" @@ -110,20 +112,35 @@ var LEFT_SHADOW_INSET = 3.0, if (_image == anImage) return; - _image = anImage; + var center = [CPNotificationCenter defaultCenter]; + if (_image) + [center removeObserver:self name:CPImageDidLoadNotification object:_image]; + + _image = anImage; _DOMImageElement.src = [anImage filename]; + + var size = [_image size]; - if (_imageScaling == CPScaleNone && _image) + if (size && size.width == -1 && size.height == -1) { - var size = [_image size]; + [center addObserver:self selector:@selector(imageDidLoad:) name:CPImageDidLoadNotification object:_image]; + + _DOMImageElement.width = 0; + _DOMImageElement.height = 0; - _DOMImageElement.width = ROUND(size.width); - _DOMImageElement.height = ROUND(size.height); + [_shadowView setHidden:YES]; } - + else + { + [self hideOrDisplayContents]; + [self tile]; + } +} + +- (void)imageDidLoad:(CPNotification)aNotification +{ [self hideOrDisplayContents]; - [self tile]; } @@ -181,13 +198,6 @@ var LEFT_SHADOW_INSET = 3.0, { CPDOMDisplayServerSetStyleLeftTop(_DOMImageElement, NULL, 0.0, 0.0); } - else if (_imageScaling == CPScaleNone && _image) - { - var size = [_image size]; - - _DOMImageElement.width = ROUND(size.width); - _DOMImageElement.height = ROUND(size.height); - } [self tile]; } @@ -240,7 +250,7 @@ var LEFT_SHADOW_INSET = 3.0, { if (!_image) return; - + var bounds = [self bounds], x = 0.0, y = 0.0, @@ -260,6 +270,9 @@ var LEFT_SHADOW_INSET = 3.0, { var size = [_image size]; + if (size.width == -1 && size.height == -1) + return; + if (_imageScaling == CPScaleProportionally) { // The max size it can be is size.width x size.height, so only @@ -289,6 +302,12 @@ var LEFT_SHADOW_INSET = 3.0, height = size.height; } + if (_imageScaling == CPScaleNone) + { + _DOMImageElement.width = ROUND(size.width); + _DOMImageElement.height = ROUND(size.height); + } + var x = (boundsWidth - width) / 2.0, y = (boundsHeight - height) / 2.0; diff --git a/Foundation/CPNotificationCenter.j b/Foundation/CPNotificationCenter.j index f0f3017558..c3b166fad7 100644 --- a/Foundation/CPNotificationCenter.j +++ b/Foundation/CPNotificationCenter.j @@ -219,7 +219,7 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */ while (key = [keys nextObject]) { var observers = [_objectObservers objectForKey:key], - count = observers.length; + count = observers ? observers.length : 0; while (count--) if ([observers[count] observer] == anObserver) @@ -231,7 +231,7 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */ observers.splice(count, 1); } - if (observers.length == 0) + if (!observers || observers.length == 0) removedKeys.push(key); } } @@ -239,7 +239,7 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */ { var key = [anObject hash], observers = [_objectObservers objectForKey:key]; - count = observers.length; + count = observers ? observers.length : 0; while (count--) if ([observers[count] observer] == anObserver) @@ -251,7 +251,7 @@ var _CPNotificationCenterPostNotification = function(/* CPNotificationCenter */ observers.splice(count, 1) } - if (observers.length == 0) + if (!observers || observers.length == 0) removedKeys.push(key); }