From c2223e3942a463e9ec97d37b74096e4e691e996b Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 23:06:23 -0800 Subject: [PATCH] Closes #429. This should actually resolve the issue by simply removing the potential race condition entirely. --- AppKit/Platform/DOM/CPPlatform.j | 14 ++++++-- AppKit/Platform/DOM/CPPlatformString.j | 40 +--------------------- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 15 ++------ 3 files changed, 15 insertions(+), 54 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 60ac59129..e3a621fb8 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -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) diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index 371e41a0c..1cbe99477 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -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) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 5c73c69cc..e6cff4912 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -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],