From 05f8a10b3d3080c6c6bfa9cb776dabc168c8bca4 Mon Sep 17 00:00:00 2001 From: aburkhalter Date: Thu, 18 Mar 2010 13:39:27 -0700 Subject: [PATCH 01/12] Trivial syntax fixes. --- Jakefile | 2 +- Tools/capp/Resources/Templates/Application/Jakefile | 4 ++-- Tools/capp/Resources/Templates/NibApplication/Jakefile | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Jakefile b/Jakefile index 94112040d..77a4ccc0a 100644 --- a/Jakefile +++ b/Jakefile @@ -281,7 +281,7 @@ function pushPackage(path, remote, branch) { branch = branch || "master"; - var pushPackagesPath = FILE.path(".push-package") + var pushPackagesPath = FILE.path(".push-package"); pushPackagesPath.mkdirs(); diff --git a/Tools/capp/Resources/Templates/Application/Jakefile b/Tools/capp/Resources/Templates/Application/Jakefile index 752b63495..2fa0c14f9 100644 --- a/Tools/capp/Resources/Templates/Application/Jakefile +++ b/Tools/capp/Resources/Templates/Application/Jakefile @@ -39,9 +39,9 @@ app ("__project.nameasidentifier__", function(task) function printResults(configuration) { - print("----------------------------") + print("----------------------------"); print(configuration+" app built at path: "+FILE.join("Build", configuration, "__project.nameasidentifier__")); - print("----------------------------") + print("----------------------------"); } task ("default", ["__project.nameasidentifier__"], function() diff --git a/Tools/capp/Resources/Templates/NibApplication/Jakefile b/Tools/capp/Resources/Templates/NibApplication/Jakefile index bbda96c09..41505c40a 100644 --- a/Tools/capp/Resources/Templates/NibApplication/Jakefile +++ b/Tools/capp/Resources/Templates/NibApplication/Jakefile @@ -40,9 +40,9 @@ app ("__project.nameasidentifier__", function(task) function printResults(configuration) { - print("----------------------------") + print("----------------------------"); print(configuration+" app built at path: "+FILE.join("Build", configuration, "__project.nameasidentifier__")); - print("----------------------------") + print("----------------------------"); } task ("default", ["__project.nameasidentifier__"], function() From 5d3eae9022fde66a1874e676e45f5f066465d92c Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Wed, 17 Mar 2010 16:50:43 -0700 Subject: [PATCH 02/12] deleteBackwards: => deleteBackward: --- AppKit/CPCollectionView.j | 2 +- AppKit/CPTextField.j | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index e6976c3ba..cf91c32cd 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -758,7 +758,7 @@ [self _scrollToSelection]; } -- (void)deleteBackwards:(id)sender +- (void)deleteBackward:(id)sender { if ([[self delegate] respondsToSelector:@selector(collectionView:shouldDeleteItemsAtIndexes:)]) { diff --git a/AppKit/CPTextField.j b/AppKit/CPTextField.j index e70984296..7459fa772 100644 --- a/AppKit/CPTextField.j +++ b/AppKit/CPTextField.j @@ -813,7 +813,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); if (![CPPlatform isBrowser]) { [self copy:sender]; - [self deleteBackwards:sender]; + [self deleteBackward:sender]; } } @@ -826,7 +826,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); if (![[pasteboard types] containsObject:CPStringPboardType]) return; - [self deleteBackwards:sender]; + [self deleteBackward:sender]; var selectedRange = [self selectedRange], stringValue = [self stringValue], @@ -912,7 +912,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder"); [self selectText:sender]; } -- (void)deleteBackwards:(id)sender +- (void)deleteBackward:(id)sender { var selectedRange = [self selectedRange], stringValue = [self stringValue], From 58179939bb812b51d842e0ccb1b725a628e2e234 Mon Sep 17 00:00:00 2001 From: Emmanuel Maillard Date: Tue, 9 Mar 2010 03:34:57 +0100 Subject: [PATCH 03/12] - fix a typo in documentation --- AppKit/CPApplication.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 2f67b076d..fd7bcfc47 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -873,7 +873,7 @@ CPRunContinuesResponse = -1002; Checks for a target in the following order:
  1. a responder from the key window
  2. -
  3. a responder frmo the main window
  4. +
  5. a responder from the main window
  6. the CPApplication instance
  7. the application delegate
  8. the document controller
  9. From 7aa1ae6bd45d3142aba2c5cb2bdf55615575b379 Mon Sep 17 00:00:00 2001 From: Emmanuel Maillard Date: Mon, 8 Mar 2010 01:20:28 +0100 Subject: [PATCH 04/12] - fix typo --- AppKit/CPFontManager.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPFontManager.j b/AppKit/CPFontManager.j index e95057b99..e4f9c8c68 100644 --- a/AppKit/CPFontManager.j +++ b/AppKit/CPFontManager.j @@ -51,7 +51,7 @@ var CPSharedFontManager = nil, // Changing the Default Font Conversion Classes /*! - Sets the class that will be used to create the applcation's + Sets the class that will be used to create the application's font manager. */ + (void)setFontManagerFactory:(Class)aClass From c8f3445fa6ecf7641e9d7a18a3a006477607005f Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Wed, 10 Mar 2010 14:09:54 +1100 Subject: [PATCH 05/12] Adding a unit test to verify fix to +[CPDictionary dictionaryWithJSObject:(JSObject)object recursively:(BOOL)recursively] --- Tests/Foundation/CPDictionaryTest.j | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j index f3936b26b..8a29cd853 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -16,6 +16,12 @@ string_dict = [[CPDictionary alloc] initWithObjects:[@"1", @"2"] forKeys:[@"key1", @"key2"]]; json_dict = [CPDictionary dictionaryWithJSObject:json recursively:YES]; + + json_with_nulls = { + "key1": ['1', '2', '3'], + "key2": "This is a string", + "key3": null + } } - (void)testInitWithDictionary @@ -58,6 +64,14 @@ [self assert:[[dict objectForKey:@"key3"] count] equals:1]; } +- (void)testDictionaryWithJSObjectRecursiveWithNull +{ + var dict = [CPDictionary dictionaryWithJSObject:json_with_nulls recursively:YES]; + [self assert:2 equals:[dict count]]; + [self assert:[@"key1", @"key2"] equals:[dict allKeys]]; + [self assert:[dict objectForKey:@"key3"] equals:nil]; +} + - (void)testDictionaryWithJSObjectNonRecursive { var non_recursive_dict = [CPDictionary dictionaryWithJSObject:json recursively:NO]; From 4e1e6f3c0bada5934a980d2655f4f4f308ef2e4d Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Wed, 24 Feb 2010 15:15:27 +1100 Subject: [PATCH 06/12] Little fix for CPDictionary, we should not try and recursively convert null JSON objects. --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index e6f83f56a..8b5af8392 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -154,7 +154,7 @@ var value = object[key]; - if (recursively) + if (recursively && value != null) { if (value.constructor === Object) value = [CPDictionary dictionaryWithJSObject:value recursively:YES]; From 35b62ca53f909c20df918fd561e238f124ee5550 Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Wed, 10 Mar 2010 17:31:42 +1100 Subject: [PATCH 07/12] Updated test and fix for gh issue #539 --- Foundation/CPDictionary.j | 8 +++++++- Tests/Foundation/CPDictionaryTest.j | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 8b5af8392..f0db3cfa1 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -153,8 +153,14 @@ continue; var value = object[key]; + + if (value == null) + { + [dictionary setObject:[CPNull null] forKey:key]; + continue; + } - if (recursively && value != null) + if (recursively) { if (value.constructor === Object) value = [CPDictionary dictionaryWithJSObject:value recursively:YES]; diff --git a/Tests/Foundation/CPDictionaryTest.j b/Tests/Foundation/CPDictionaryTest.j index 8a29cd853..3cdfd51df 100644 --- a/Tests/Foundation/CPDictionaryTest.j +++ b/Tests/Foundation/CPDictionaryTest.j @@ -67,9 +67,9 @@ - (void)testDictionaryWithJSObjectRecursiveWithNull { var dict = [CPDictionary dictionaryWithJSObject:json_with_nulls recursively:YES]; - [self assert:2 equals:[dict count]]; - [self assert:[@"key1", @"key2"] equals:[dict allKeys]]; - [self assert:[dict objectForKey:@"key3"] equals:nil]; + [self assert:3 equals:[dict count]]; + [self assert:[@"key1", @"key2", @"key3"] equals:[dict allKeys]]; + [self assert:[CPNull null] equals:[dict objectForKey:@"key3"]]; } - (void)testDictionaryWithJSObjectNonRecursive From 319b9ed00f0116ff6fbabf83415c893372d9b601 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 22 Mar 2010 14:53:49 -0700 Subject: [PATCH 08/12] Use === not ==. --- Foundation/CPDictionary.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index f0db3cfa1..28e7a1310 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -154,7 +154,7 @@ var value = object[key]; - if (value == null) + if (value === null) { [dictionary setObject:[CPNull null] forKey:key]; continue; From ef4c108b9e77a1807899e06955be71edd8056eaf Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 22 Mar 2010 15:08:29 -0700 Subject: [PATCH 09/12] Date test wasn't accurately accounting for daylight savings time. --- Tests/Foundation/CPDateTest.j | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Tests/Foundation/CPDateTest.j b/Tests/Foundation/CPDateTest.j index ccaf42666..4668d37af 100644 --- a/Tests/Foundation/CPDateTest.j +++ b/Tests/Foundation/CPDateTest.j @@ -63,12 +63,14 @@ - (void)testDescription { // Unfortunately the result will be different depending on the testing machine's timezone. - var expectedHour = 23 - var expectedMinute = 31; - var offsetHours = Math.floor(new Date().getTimezoneOffset() / 60); - var offsetMinutes = new Date().getTimezoneOffset() - offsetHours * 60; - var expectedString = [CPString stringWithFormat:"2009-02-13 %02d:%02d:30 +%02d%02d", expectedHour-offsetHours, expectedMinute-offsetMinutes, offsetHours, offsetMinutes]; - [self assert:expectedString equals: [[CPDate dateWithTimeIntervalSince1970: 1234567890] description]]; + var date = [CPDate dateWithTimeIntervalSince1970: 1234567890], + expectedHour = 23, + expectedMinute = 31, + offsetHours = Math.floor(date.getTimezoneOffset() / 60), + offsetMinutes = date.getTimezoneOffset() - offsetHours * 60, + expectedString = [CPString stringWithFormat:"2009-02-13 %02d:%02d:30 +%02d%02d", expectedHour-offsetHours, expectedMinute-offsetMinutes, offsetHours, offsetMinutes]; + + [self assert:expectedString equals:[date description]]; } - (void)testCopy From bb0835e2f3e2d8e1f9581e0aa08879f75b9580dd Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Mon, 8 Mar 2010 18:52:00 -0800 Subject: [PATCH 10/12] CPImageView should send action on drop, as in Cocoa --- AppKit/CPImageView.j | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AppKit/CPImageView.j b/AppKit/CPImageView.j index 817ffbd0b..234f74ceb 100644 --- a/AppKit/CPImageView.j +++ b/AppKit/CPImageView.j @@ -370,7 +370,10 @@ var LEFT_SHADOW_INSET = 3.0, var images = [CPKeyedUnarchiver unarchiveObjectWithData:[[aSender draggingPasteboard] dataForType:CPImagesPboardType]]; if ([images count]) + { [self setImage:images[0]]; + [self sendAction:[self action] to:[self target]]; + } } @end From f73d96af0885908270274fef0040ed027f5e8a90 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Mon, 22 Mar 2010 19:24:32 -0400 Subject: [PATCH 11/12] Fixed black background of dragview in Opera and IE. --- AppKit/CPTableView.j | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index af31a0a82..9a34956d4 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1763,25 +1763,18 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; return YES; } -- (CPImage)dragImageForRowsWithIndexes:(CPIndexSet)dragRows - tableColumns:(CPArray)theTableColumns - event:(CPEvent)dragEvent - offset:(CPPointPointer)dragImageOffset +- (CPImage)dragImageForRowsWithIndexes:(CPIndexSet)dragRows tableColumns:(CPArray)theTableColumns event:(CPEvent)dragEvent offset:(CPPointPointer)dragImageOffset { return [[CPImage alloc] initWithContentsOfFile:@"Frameworks/AppKit/Resources/GenericFile.png" size:CGSizeMake(32,32)]; } -- (CPView)dragViewForRowsWithIndexes:(CPIndexSet)theDraggedRows - tableColumns:(CPArray)theTableColumns - event:(CPEvent)theDragEvent - offset:(CPPoint)dragViewOffset +- (CPView)dragViewForRowsWithIndexes:(CPIndexSet)theDraggedRows tableColumns:(CPArray)theTableColumns event:(CPEvent)theDragEvent offset:(CPPoint)dragViewOffset { var bounds = [self bounds], view = [[CPView alloc] initWithFrame:bounds]; - - [view setBackgroundColor:[CPColor clearColor]]; + [view setAlphaValue:0.7]; - + // We have to fetch all the data views for the selected rows and columns // After that we can copy these add them to a transparent drag view and use that drag view // to make it appear we are dragging images of those rows (as you would do in regular Cocoa) @@ -1791,35 +1784,34 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; exposedRowsLength = [_exposedRows lastIndex] - firstExposedRow + 1, columns = [], rows = []; - + [_exposedColumns getIndexes:columns maxCount:-1 inIndexRange:CPMakeRange(firstExposedColumn, exposedColumnsLength)]; [theDraggedRows getIndexes:rows maxCount:-1 inIndexRange:CPMakeRange(firstExposedRow, exposedRowsLength)]; var columnIndex = [columns count]; - + while (columnIndex--) { var column = columns[columnIndex], tableColumn = [_tableColumns objectAtIndex:column], rowIndex = [rows count]; - + while (rowIndex--) { var row = rows[rowIndex]; var dataView = [self _newDataViewForRow:row tableColumn:tableColumn]; - - [dataView setBackgroundColor:[CPColor clearColor]]; + [dataView setFrame:[self frameOfDataViewAtColumn:column row:row]]; [dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]]; - + [view addSubview:dataView]; } } - + var dragPoint = [self convertPoint:[theDragEvent locationInWindow] fromView:nil]; dragViewOffset.x = CGRectGetWidth(bounds)/2 - dragPoint.x; dragViewOffset.y = CGRectGetHeight(bounds)/2 - dragPoint.y; - + return view; } @@ -1841,7 +1833,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; var numberOfRows = [self numberOfRows] + 1; var reason = @"Attempt to set dropRow=" + row + " dropOperation=CPTableViewDropOn when [0 - " + numberOfRows + "] is valid range of rows." - + [[CPException exceptionWithName:@"Error" reason:reason userInfo:nil] raise]; } @@ -1897,7 +1889,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; return; _sortDescriptors = newSortDescriptors; - + [self _sendDataSourceSortDescriptorsDidChange:oldSortDescriptors]; } From f8c13f1e308b12d524109bea58a90c567ee2415c Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Mon, 22 Mar 2010 19:00:08 -0700 Subject: [PATCH 12/12] Make semi-transparent background colors work in browsers that don't support RGBA. Closes #569. --- AppKit/CPColor.j | 76 ++++++++++-------------------------------------- AppKit/CPView.j | 74 ++++++++++++++++++++++++++++++---------------- 2 files changed, 64 insertions(+), 86 deletions(-) diff --git a/AppKit/CPColor.j b/AppKit/CPColor.j index cdc3af3a7..ee14fb397 100644 --- a/AppKit/CPColor.j +++ b/AppKit/CPColor.j @@ -437,51 +437,16 @@ var cachedBlackColor, if (self) { _components = components; - - if (!CPFeatureIsCompatible(CPCSSRGBAFeature) && _components[3] != 1.0 && window.Base64 && window.CRC32) - { - var bytes = [0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x1,0x8,0x3,0x0,0x0,0x0,0x28,0xcb,0x34,0xbb,0x0,0x0,0x3,0x0,0x50,0x4c,0x54,0x45,0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,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x0,0x0,0xff,0xff,0x3,0x0,0x0,0x2,0x0,0x1,0x24,0x7f,0x24,0xf1,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,0xff]; - var r_off = 41; - var g_off = 42; - var b_off = 43; - var a_off = 821; - var plte_crc_off = 809; - var trns_crc_off = 822; - var plte_type_off = 37; - var trns_type_off = 817; - - bytes[r_off] = Math.round(_components[0]*255); - bytes[g_off] = Math.round(_components[1]*255); - bytes[b_off] = Math.round(_components[2]*255); - bytes[a_off] = Math.round(_components[3]*255); - - // calculate new CRCs - var new_plte_crc = integerToBytes(CRC32.getCRC(bytes, plte_type_off, 4+768), 4); - var new_trns_crc = integerToBytes(CRC32.getCRC(bytes, trns_type_off, 4+1), 4); - - // overwrite old CRCs with new ones - for (var i = 0; i < 4; i++) - { - bytes[plte_crc_off+i] = new_plte_crc[i]; - bytes[trns_crc_off+i] = new_trns_crc[i]; - } - - // Base64 encode, strip whitespace and build data URL - var base64image = Base64.encode(bytes); //.replace(/[\s]/g, ""); - - _cssString = "url(\"data:image/png;base64," + base64image + "\")"; - } - else - { - 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]) : "") + ")"; - } + + 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]) : "") + ")"; } + return self; } @@ -494,6 +459,7 @@ var cachedBlackColor, { _patternImage = anImage; _cssString = "url(\"" + [_patternImage filename] + "\")"; + _components = []; } return self; @@ -512,7 +478,7 @@ var cachedBlackColor, */ - (float)alphaComponent { - return _components[3]; + return _components[3] || 0.0; } /*! @@ -520,7 +486,7 @@ var cachedBlackColor, */ - (float)blueComponent { - return _components[2]; + return _components[2] || 0.0; } /*! @@ -528,7 +494,7 @@ var cachedBlackColor, */ - (float)greenComponent { - return _components[1]; + return _components[1] || 0.0; } /*! @@ -536,7 +502,7 @@ var cachedBlackColor, */ - (float)redComponent { - return _components[0]; + return _components[0] || 0.0; } /*! @@ -736,7 +702,7 @@ var CPColorComponentsKey = @"CPColorComponentsKey", var hexCharacters = "0123456789ABCDEF"; // HACK: prevent these from becoming globals. workaround for obj-j "function foo(){}" behavior -var hexToRGB, integerToBytes, rgbToHex, byteToHex; +var hexToRGB, rgbToHex, byteToHex; /*! Used for the CPColor \c +colorWithHexString: implementation @@ -764,18 +730,6 @@ function hexToRGB(hex) return [red, green, blue, 1.0]; } -function integerToBytes(integer, length) { - if (!length) - length = (integer == 0) ? 1 : Math.round((Math.log(integer)/Math.log(2))/8+0.5); - - var bytes = new Array(length); - for (var i = length-1; i >= 0; i--) { - bytes[i] = integer & 255; - integer = integer >> 8 - } - return bytes; -} - function rgbToHex(r,g,b) { return byteToHex(r) + byteToHex(g) + byteToHex(b); } diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 90685cb6c..3b3fa55ca 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -1199,7 +1199,7 @@ var CPViewFlags = { }, if (CPFeatureIsCompatible(CPOpacityRequiresFilterFeature)) { - if (anAlphaValue == 1.0) + if (anAlphaValue === 1.0) try { _DOMElement.style.removeAttribute("filter") } catch (anException) { } else _DOMElement.style.filter = "alpha(opacity=" + anAlphaValue * 100 + ")"; @@ -1317,56 +1317,72 @@ var CPViewFlags = { }, { if (_backgroundColor == aColor) return; - + _backgroundColor = aColor; - + #if PLATFORM(DOM) var patternImage = [_backgroundColor patternImage], + colorExists = _backgroundColor && [_backgroundColor alphaComponent] > 0.0, + colorHasAlpha = colorExists && [_backgroundColor alphaComponent] < 1.0, + supportsRGBA = CPFeatureIsCompatible(CPCSSRGBAFeature), + colorNeedsDOMElement = colorHasAlpha && !supportsRGBA, amount = 0; - + if ([patternImage isThreePartImage]) { _backgroundType = [patternImage isVertical] ? BackgroundVerticalThreePartImage : BackgroundHorizontalThreePartImage; - amount = 3 - _DOMImageParts.length; } else if ([patternImage isNinePartImage]) { _backgroundType = BackgroundNinePartImage; - - amount = 9 - _DOMImageParts.length; + amount = 9 - _DOMImageParts.length; } else { _backgroundType = BackgroundTrivialColor; - - amount = 0 - _DOMImageParts.length; + amount = (colorNeedsDOMElement ? 1 : 0) - _DOMImageParts.length; } if (amount > 0) + { while (amount--) { var DOMElement = DOMElementPrototype.cloneNode(false); - + DOMElement.style.zIndex = -1000; - + _DOMImageParts.push(DOMElement); _DOMElement.appendChild(DOMElement); } + } else { amount = -amount; - while (amount--) _DOMElement.removeChild(_DOMImageParts.pop()); } - - if (_backgroundType == BackgroundTrivialColor) - - // Opera doesn't like DOM properties set to nil. - // https://trac.280north.com/ticket/7 - _DOMElement.style.background = _backgroundColor ? [_backgroundColor cssString] : ""; - + + if (_backgroundType === BackgroundTrivialColor) + { + var colorCSS = colorExists ? [_backgroundColor cssString] : ""; + + if (colorNeedsDOMElement) + { + _DOMElement.style.background = ""; + _DOMImageParts[0].style.background = [_backgroundColor cssString]; + + if (CPFeatureIsCompatible(CPOpacityRequiresFilterFeature)) + _DOMImageParts[0].style.filter = "alpha(opacity=" + [_backgroundColor alphaComponent] * 100 + ")"; + else + _DOMImageParts[0].style.opacity = [_backgroundColor alphaComponent]; + + var size = [self bounds].size; + CPDOMDisplayServerSetStyleSize(_DOMImageParts[0], size.width, size.height); + } + else + _DOMElement.style.background = colorCSS; + } else { var slices = [patternImage imageSlices], @@ -1377,23 +1393,31 @@ var CPViewFlags = { }, { var image = slices[count], size = _DOMImageSizes[count] = image ? [image size] : _CGSizeMakeZero(); - + CPDOMDisplayServerSetStyleSize(_DOMImageParts[count], size.width, size.height); _DOMImageParts[count].style.background = image ? "url(\"" + [image filename] + "\")" : ""; + + if (!supportsRGBA) + { + if (CPFeatureIsCompatible(CPOpacityRequiresFilterFeature)) + try { _DOMImageParts[count].style.removeAttribute("filter") } catch (anException) { } + else + _DOMImageParts[count].style.opacity = 1.0; + } } - + if (_backgroundType == BackgroundNinePartImage) { var width = frameSize.width - _DOMImageSizes[0].width - _DOMImageSizes[2].width, height = frameSize.height - _DOMImageSizes[0].height - _DOMImageSizes[6].height; - + CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], width, _DOMImageSizes[0].height); CPDOMDisplayServerSetStyleSize(_DOMImageParts[3], _DOMImageSizes[3].width, height); CPDOMDisplayServerSetStyleSize(_DOMImageParts[4], width, height); CPDOMDisplayServerSetStyleSize(_DOMImageParts[5], _DOMImageSizes[5].width, height); CPDOMDisplayServerSetStyleSize(_DOMImageParts[7], width, _DOMImageSizes[7].height); - + CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[0], NULL, 0.0, 0.0); CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[1], NULL, _DOMImageSizes[0].width, 0.0); CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[2], NULL, 0.0, 0.0); @@ -1407,7 +1431,7 @@ var CPViewFlags = { }, else if (_backgroundType == BackgroundVerticalThreePartImage) { CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], frameSize.width, frameSize.height - _DOMImageSizes[0].height - _DOMImageSizes[2].height); - + CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[0], NULL, 0.0, 0.0); CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[1], NULL, 0.0, _DOMImageSizes[0].height); CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[2], NULL, 0.0, 0.0); @@ -1415,7 +1439,7 @@ var CPViewFlags = { }, else if (_backgroundType == BackgroundHorizontalThreePartImage) { CPDOMDisplayServerSetStyleSize(_DOMImageParts[1], frameSize.width - _DOMImageSizes[0].width - _DOMImageSizes[2].width, frameSize.height); - + CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[0], NULL, 0.0, 0.0); CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[1], NULL, _DOMImageSizes[0].width, 0.0); CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[2], NULL, 0.0, 0.0);