From 840e9c7671c5e7d95cdbf173bae4bbb46192a933 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 12:29:38 -0800 Subject: [PATCH 1/3] When removing an item from the collection view, we now unconditionally unhighlight it. We also reapply highlights after reloading finishes. Closes #248. --- AppKit/CPCollectionView.j | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 4a9ddecba..7558eb64f 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -333,6 +333,8 @@ while (count--) { [[_items[count] view] removeFromSuperview]; + [_items[count] setSelected:NO]; + _cachedItems.push(_items[count]); } @@ -351,7 +353,11 @@ [self addSubview:[_items[index] view]]; } - + + index = CPNotFound; + while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound) + [_items[index] setSelected:YES]; + [self tile]; } From 1c81e0eee05dbe7a2080e6f3318db2445acd4904 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 15:07:23 -0800 Subject: [PATCH 2/3] Closes #429. Doesn't necessarily address the root cause however. The problem stems from a bug in Safari which is allowing callbacks to interrupt running code (which should be impossible in JavaScript). The change essentially makes it so that in the case where this happens, which is rare, we'll end up accidentally creating an extra iframe. This isn't ideal, but it also isn't harmful, versus the current situation where code will simply break. --- AppKit/Platform/DOM/CPPlatform.j | 5 +++ AppKit/Platform/DOM/CPPlatformString.j | 52 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 47af4b175..60ac59129 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -21,6 +21,7 @@ */ CPPlatformDidClearBodyElementNotification = @"CPPlatformDidClearBodyElementNotification"; +CPPlatformWillClearBodyElementNotification = @"CPPlatformWillClearBodyElementNotification"; var screenNeedsInitialization = NO, mainBodyElement = nil; @@ -91,6 +92,10 @@ var screenNeedsInitialization = NO, screenNeedsInitialization = NO; + [[CPNotificationCenter defaultCenter] + postNotificationName:CPPlatformWillClearBodyElementNotification + object:self]; + var bodyElement = [self mainBodyElement]; // Get rid of any of the original contents of the page. diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index e0431b0d4..1beb80c6f 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -22,8 +22,8 @@ #include "../CoreGraphics/CGGeometry.h" - var DOMSpanElement = nil, + DOMIFrameElement = nil, DefaultFont = nil; @implementation CPPlatformString : CPBasePlatformString @@ -39,11 +39,20 @@ var DOMSpanElement = nil, selector:@selector(platformDidClearBodyElement:) name:CPPlatformDidClearBodyElementNotification object:CPPlatform]; + + [[CPNotificationCenter defaultCenter] + addObserver:self + selector:@selector(platformWillClearBodyElement:) + name:CPPlatformWillClearBodyElementNotification + object:CPPlatform]; } + (void)createDOMElements { - var DOMIFrameElement = document.createElement("iframe"); + if (DOMIFrameElement) + return; + + DOMIFrameElement = document.createElement("iframe"); // necessary for Safari caching bug: DOMIFrameElement.name = "iframe_" + FLOOR(RAND() * 10000); DOMIFrameElement.style.position = "absolute"; @@ -80,11 +89,27 @@ var DOMSpanElement = nil, DOMDivElement.appendChild(DOMSpanElement); } ++ (void)removeDOMElements +{ + var iframe = DOMIFrameElement, + bodyElement = [CPPlatform mainBodyElement]; + + DOMSpanElement = nil; + DOMIFrameElement = nil; + + bodyElement.removeChild(iframe); +} + + (void)platformDidClearBodyElement:(CPNotification)aNotification { [self createDOMElements]; } ++ (void)platformWillClearBodyElement:(CPNotification)aNotification +{ + [self removeDOMElements]; +} + + (CGSize)sizeOfString:(CPString)aString withFont:(CPFont)aFont forWidth:(float)aWidth { if (!aFont) @@ -95,35 +120,30 @@ var DOMSpanElement = nil, aFont = DefaultFont; } + if (!DOMIFrameElement) + [self createDOMElements]; + var style = DOMSpanElement.style; - if (aWidth === NULL) + if (!aWidth) { style.width = ""; style.whiteSpace = "pre"; } - else { style.width = ROUND(aWidth) + "px"; - - if (document.attachEvent) - style.wordWrap = "break-word"; - - else - { - style.whiteSpace = "-o-pre-wrap"; - style.whiteSpace = "-pre-wrap"; - style.whiteSpace = "-moz-pre-wrap"; - style.whiteSpace = "pre-wrap"; - } + style.wordWrap = "break-word"; + style.whiteSpace = "-o-pre-wrap"; + style.whiteSpace = "-pre-wrap"; + style.whiteSpace = "-moz-pre-wrap"; + style.whiteSpace = "pre-wrap"; } style.font = [aFont cssString]; if (CPFeatureIsCompatible(CPJavascriptInnerTextFeature)) DOMSpanElement.innerText = aString; - else if (CPFeatureIsCompatible(CPJavascriptTextContentFeature)) DOMSpanElement.textContent = aString; From c911dd8aa62307404112f49355f97e382d62e544 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 15:37:06 -0800 Subject: [PATCH 3/3] Slight order change. This really should not matter. --- AppKit/Platform/DOM/CPPlatformString.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index 1beb80c6f..371e41a0c 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -94,8 +94,8 @@ var DOMSpanElement = nil, var iframe = DOMIFrameElement, bodyElement = [CPPlatform mainBodyElement]; - DOMSpanElement = nil; DOMIFrameElement = nil; + DOMSpanElement = nil; bodyElement.removeChild(iframe); }