Further cleanup of encoding/decoding for AppKit classes.

Reviewed by me.
This commit is contained in:
Francisco Tolmasky committed 2009-05-16 17:39:22 -07:00
1 parent 9f237c2d1a
commit b23d62190d
3 files changed
+85 -93

No files matched your search

+12 -44
View File
@@ -103,9 +103,6 @@ var CPControlBlackColor = [CPColor blackColor];
CPSet _ephereralSubviews;
CPString _toolTip;
// FIXME: Who uses this?
BOOL _isBezeled;
}
+ (CPDictionary)themeAttributes
@@ -630,7 +627,7 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
var count = [_subviews count],
ephemeral
subviews = nil;
if (count > 0 && [_ephemeralSubviews count] > 0)
{
subviews = [_subviews.slice(0) copy];
@@ -639,18 +636,20 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
if ([_ephemeralSubviews containsObject:_subviews[count]])
_subviews.splice(count, 1);
}
[super encodeWithCoder:aCoder];
if (subviews)
_subviews = subviews;
[aCoder encodeObject:_value forKey:CPControlValueKey];
/*[aCoder encodeBool:_isEnabled forKey:CPControlIsEnabledKey];
*/
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
[aCoder encodeObject:_action forKey:CPControlActionKey];
if (_value !== nil)
[aCoder encodeObject:_value forKey:CPControlValueKey];
if (_target !== nil)
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
if (_action !== NULL)
[aCoder encodeObject:_action forKey:CPControlActionKey];
[aCoder encodeInt:_sendActionOn forKey:CPControlSendActionOnKey];
}
@@ -658,7 +657,6 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
@end
var _CPControlSizeIdentifiers = [],
_CPControlCachedThreePartImages = {},
_CPControlCachedColorWithPatternImages = {},
_CPControlCachedThreePartImagePattern = {};
@@ -694,36 +692,6 @@ function _CPControlColorWithPatternImage(sizes, aClassName)
return color;
}
function _CPControlThreePartImages(sizes, aClassName)
{
var index = 1,
count = arguments.length,
identifier = "";
for (; index < count; ++index)
identifier += arguments[index];
var images = _CPControlCachedThreePartImages[identifier];
if (!images)
{
var bundle = [CPBundle bundleForClass:[CPControl class]],
path = aClassName + "/" + identifier;
sizes = sizes[identifier];
images = [
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "0.png"] size:sizes[0]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "1.png"] size:sizes[1]],
[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:path + "2.png"] size:sizes[2]]
];
_CPControlCachedThreePartImages[identifier] = images;
}
return images;
}
function _CPControlThreePartImagePattern(isVertical, sizes, aClassName)
{
var index = 2,
+3 -1
View File
@@ -359,7 +359,9 @@ var CPResponderNextResponderKey = @"CPResponderNextResponderKey";
*/
- (void)encodeWithCoder:(CPCoder)aCoder
{
[aCoder encodeConditionalObject:_nextResponder forKey:CPResponderNextResponderKey];
// This will come out nil on the other side with decodeObjectForKey:
if (_nextResponder !== nil)
[aCoder encodeConditionalObject:_nextResponder forKey:CPResponderNextResponderKey];
}
@end
+70 -48
View File
@@ -906,7 +906,7 @@ var DOMElementPrototype = nil,
*/
- (void)setAutoresizesSubviews:(BOOL)aFlag
{
_autoresizesSubviews = aFlag;
_autoresizesSubviews = !!aFlag;
}
/*!
@@ -992,9 +992,9 @@ var DOMElementPrototype = nil,
{
if (!_isInFullScreenMode)
return;
_isInFullScreenMode = NO;
[self setFrame:_fullScreenModeState.frame];
[self setAutoresizingMask:_fullScreenModeState.autoresizingMask];
[_fullScreenModeState.superview _insertSubview:self atIndex:_fullScreenModeState.index];
@@ -1016,8 +1016,11 @@ var DOMElementPrototype = nil,
*/
- (void)setHidden:(BOOL)aFlag
{
if(_isHidden == aFlag)
aFlag = !!aFlag;
if(_isHidden === aFlag)
return;
// FIXME: Should we return to visibility? This breaks in FireFox, Opera, and IE.
// _DOMElement.style.visibility = (_isHidden = aFlag) ? "hidden" : "visible";
_isHidden = aFlag;
@@ -1128,7 +1131,7 @@ var DOMElementPrototype = nil,
*/
- (void)setHitTests:(BOOL)shouldHitTest
{
_hitTests = shouldHitTest;
_hitTests = !!shouldHitTest;
}
/*!
@@ -1374,11 +1377,13 @@ setFrameOrigin:
*/
- (void)setPostsFrameChangedNotifications:(BOOL)shouldPostFrameChangedNotifications
{
if (_postsFrameChangedNotifications == shouldPostFrameChangedNotifications)
shouldPostFrameChangedNotifications = !!shouldPostFrameChangedNotifications;
if (_postsFrameChangedNotifications === shouldPostFrameChangedNotifications)
return;
_postsFrameChangedNotifications = shouldPostFrameChangedNotifications;
if (_postsFrameChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewFrameDidChangeNotification object:self];
}
@@ -1405,11 +1410,13 @@ setBoundsOrigin:
*/
- (void)setPostsBoundsChangedNotifications:(BOOL)shouldPostBoundsChangedNotifications
{
if (_postsBoundsChangedNotifications == shouldPostBoundsChangedNotifications)
shouldPostBoundsChangedNotifications = !!shouldPostBoundsChangedNotifications;
if (_postsBoundsChangedNotifications === shouldPostBoundsChangedNotifications)
return;
_postsBoundsChangedNotifications = shouldPostBoundsChangedNotifications;
if (_postsBoundsChangedNotifications)
[CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self];
}
@@ -1937,7 +1944,7 @@ setBoundsOrigin:
*/
- (void)setWantsLayer:(BOOL)aFlag
{
_wantsLayer = aFlag;
_wantsLayer = !!aFlag;
}
/*!
@@ -2215,25 +2222,17 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
if (self)
{
_tag = -1;
if ([aCoder containsValueForKey:CPViewTagKey])
_tag = [aCoder decodeIntForKey:CPViewTagKey];
// We have to manually check because it may be 0, so we can't use ||
_tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1;
_window = [aCoder decodeObjectForKey:CPViewWindowKey];
if ([aCoder containsValueForKey:CPViewSubviewsKey])
_subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey];
else
_subviews = [];
_subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || [];
_superview = [aCoder decodeObjectForKey:CPViewSuperviewKey];
_autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] || 0;
_autoresizesSubviews = [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];
_hitTests = [aCoder decodeObjectForKey:CPViewHitTestsKey];
_opacity = [aCoder decodeIntForKey:CPViewOpacityKey];
_autoresizingMask = [aCoder decodeIntForKey:CPViewAutoresizingMaskKey] || CPViewNotSizable;
_autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey];
_hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeObjectForKey:CPViewHitTestsKey];
// DOM SETUP
#if PLATFORM(DOM)
@@ -2254,8 +2253,18 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
#endif
_displayHash = [self hash];
if ([aCoder containsValueForKey:CPViewIsHiddenKey])
[self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
else
_isHidden = NO;
if ([aCoder containsValueForKey:CPViewOpacityKey])
[self setAlphaValue:[aCoder decodeIntForKey:CPViewOpacityKey]];
else
_opacity = 1.0;
[self setBackgroundColor:[aCoder decodeObjectForKey:CPViewBackgroundColorKey]];
_theme = [CPTheme defaultTheme];
_themeState = CPThemeState([aCoder decodeIntForKey:CPViewThemeStateKey]);
_themeAttributes = {};
@@ -2271,13 +2280,8 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
_themeAttributes[attributeName] = CPThemeAttributeDecode(aCoder, attributeName, attributes[count], _theme, themeClass);
}
[self setNeedsDisplay:YES];
_isHidden = NO;
if ([aCoder containsValueForKey:CPViewIsHiddenKey])
[self setHidden:[aCoder decodeBoolForKey:CPViewIsHiddenKey]];
[self setNeedsDisplay:YES];
}
return self;
@@ -2293,30 +2297,48 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask",
if (_tag !== -1)
[aCoder encodeInt:_tag forKey:CPViewTagKey];
[aCoder encodeRect:_frame forKey:CPViewFrameKey];
[aCoder encodeRect:_bounds forKey:CPViewBoundsKey];
[aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
// This will come out nil on the other side with decodeObjectForKey:
if (_window !== nil)
[aCoder encodeConditionalObject:_window forKey:CPViewWindowKey];
if (_subviews.length > 0)
[aCoder encodeObject:_subviews forKey:CPViewSubviewsKey];
[aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
[aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
[aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
[aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
[aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
[aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
// This will come out nil on the other side with decodeObjectForKey:
if (_superview !== nil)
[aCoder encodeConditionalObject:_superview forKey:CPViewSuperviewKey];
if (_autoresizingMask !== CPViewNotSizable)
[aCoder encodeInt:_autoresizingMask forKey:CPViewAutoresizingMaskKey];
if (!_autoresizesSubviews)
[aCoder encodeBool:_autoresizesSubviews forKey:CPViewAutoresizesSubviewsKey];
if (_backgroundColor !== nil)
[aCoder encodeObject:_backgroundColor forKey:CPViewBackgroundColorKey];
if (_hitTests !== YES)
[aCoder encodeBool:_hitTests forKey:CPViewHitTestsKey];
if (_opacity !== 1.0)
[aCoder encodeFloat:_opacity forKey:CPViewOpacityKey];
if (_isHidden)
[aCoder encodeBool:_isHidden forKey:CPViewIsHiddenKey];
[aCoder encodeConditionalObject:[self nextKeyView] forKey:CPViewNextKeyViewKey];
[aCoder encodeConditionalObject:[self previousKeyView] forKey:CPViewPreviousKeyViewKey];
var nextKeyView = [self nextKeyView];
if (nextKeyView !== nil)
[aCoder encodeConditionalObject:nextKeyView forKey:CPViewNextKeyViewKey];
var previousKeyView = [self previousKeyView];
if (previousKeyView !== nil)
[aCoder encodeConditionalObject:previousKeyView forKey:CPViewPreviousKeyViewKey];
[aCoder encodeInt:CPThemeStateName(_themeState) forKey:CPViewThemeStateKey];