Closes #429. This should actually resolve the issue by simply removing the potential race condition entirely.

This commit is contained in:
Ross Boucher committed 2010-01-31 23:06:23 -08:00
1 parent c911dd8aa6
commit c2223e3942
3 files changed
+15 -54

No files matched your search

+12 -2
View File
@@ -24,7 +24,8 @@ CPPlatformDidClearBodyElementNotification = @"CPPlatformDidClearBodyElementNot
CPPlatformWillClearBodyElementNotification = @"CPPlatformWillClearBodyElementNotification";
var screenNeedsInitialization = NO,
mainBodyElement = nil;
mainBodyElement = nil,
elementRemovalTest = new RegExp("\\bcpdontremove\\b", "g");
@implementation CPPlatform : CPBasePlatform
{
@@ -99,7 +100,16 @@ var screenNeedsInitialization = NO,
var bodyElement = [self mainBodyElement];
// Get rid of any of the original contents of the page.
bodyElement.innerHTML = "";
var children = bodyElement.childNodes,
length = children.length;
while (length--)
{
var element = children[length];
if (!element.className || element.className.match(elementRemovalTest) === null)
bodyElement.removeChild(element);
}
bodyElement.style.overflow = "hidden";
if (document.documentElement)
+1 -39
View File
@@ -33,25 +33,10 @@ var DOMSpanElement = nil,
+ (void)bootstrap
{
[self createDOMElements];
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(platformDidClearBodyElement:)
name:CPPlatformDidClearBodyElementNotification
object:CPPlatform];
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(platformWillClearBodyElement:)
name:CPPlatformWillClearBodyElementNotification
object:CPPlatform];
}
+ (void)createDOMElements
{
if (DOMIFrameElement)
return;
DOMIFrameElement = document.createElement("iframe");
// necessary for Safari caching bug:
DOMIFrameElement.name = "iframe_" + FLOOR(RAND() * 10000);
@@ -63,6 +48,7 @@ var DOMSpanElement = nil,
DOMIFrameElement.style.borderWidth = "0px";
DOMIFrameElement.style.overflow = "hidden";
DOMIFrameElement.style.zIndex = 100000000000;
DOMIFrameElement.className = "cpdontremove";
var bodyElement = [CPPlatform mainBodyElement];
@@ -89,27 +75,6 @@ var DOMSpanElement = nil,
DOMDivElement.appendChild(DOMSpanElement);
}
+ (void)removeDOMElements
{
var iframe = DOMIFrameElement,
bodyElement = [CPPlatform mainBodyElement];
DOMIFrameElement = nil;
DOMSpanElement = 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)
@@ -120,9 +85,6 @@ var DOMSpanElement = nil,
aFont = DefaultFont;
}
if (!DOMIFrameElement)
[self createDOMElements];
var style = DOMSpanElement.style;
if (!aWidth)
+2 -13
View File
@@ -239,6 +239,7 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
_DOMFocusElement.style.zIndex = "-1000";
_DOMFocusElement.style.opacity = "0";
_DOMFocusElement.style.filter = "alpha(opacity=0)";
_DOMFocusElement.className = "cpdontremove";
_DOMBodyElement.appendChild(_DOMFocusElement);
@@ -248,6 +249,7 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
_DOMPasteboardElement.style.position = "absolute";
_DOMPasteboardElement.style.top = "-10000px";
_DOMPasteboardElement.style.zIndex = "999";
_DOMPasteboardElement.className = "cpdontremove";
_DOMBodyElement.appendChild(_DOMPasteboardElement);
@@ -255,11 +257,6 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
_DOMPasteboardElement.blur();
}
- (void)platformDidClearBodyElement:(CPNotification)aNotification
{
[self createDOMElements];
}
- (void)registerDOMWindow
{
var theDocument = _DOMWindow.document;
@@ -273,14 +270,6 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop];
_DOMBodyElement.webkitTouchCallout = "none";
[self createDOMElements];
if (window === _DOMWindow)
[[CPNotificationCenter defaultCenter]
addObserver:self
selector:@selector(platformDidClearBodyElement:)
name:CPPlatformDidClearBodyElementNotification
object:CPPlatform];
[self _addLayers];
var theClass = [self class],