From 905deb8f3ad20bb019c3fa16d5a03dc0f2cde63c Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 9 Sep 2008 16:21:37 -0700 Subject: [PATCH 1/2] Removed Frameworks symlink that should have never gone in. Reviewed by me. --- Tools/NibApp/Frameworks | 1 - 1 file changed, 1 deletion(-) delete mode 120000 Tools/NibApp/Frameworks diff --git a/Tools/NibApp/Frameworks b/Tools/NibApp/Frameworks deleted file mode 120000 index 50d7dd1d21..0000000000 --- a/Tools/NibApp/Frameworks +++ /dev/null @@ -1 +0,0 @@ -/Users/tolmasky/Development/Build/Release \ No newline at end of file From 5618b628cf50f00959d3538d5dc7935723a2bb1c Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Wed, 10 Sep 2008 20:26:36 -0700 Subject: [PATCH 2/2] Modernized CPView drawing. Fix for http://cappuccino.lighthouseapp.com/projects/16499-cappuccino/tickets/31-make-cpview-use-run-loop-drawing. Fix for http://cappuccino.lighthouseapp.com/projects/16499/tickets/28-drawrect-is-called-twice. [#31 state:resolved] [#28 state:resolved] Reviewed by Tom. --- AppKit/CPView.j | 152 +++++++++++++------- AppKit/Platform/DOM/CPDOMDisplayServer.h | 43 +++++- AppKit/Platform/DOM/CPDOMDisplayServer.j | 175 ++++++++++++++--------- Foundation/CPObject.j | 2 +- 4 files changed, 247 insertions(+), 125 deletions(-) diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 51cf412de8..f96a54756e 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -55,14 +55,14 @@ var _DOMOriginUpdateMask = 1 << 0, var _CPViewNotificationCenter = nil; #if PLATFORM(DOM) -var DOMCanvasElementZIndex = -1, - DOMBackgroundElementZIndex = -2, - DOMElementPrototype = nil, +var DOMElementPrototype = nil, BackgroundTrivialColor = 0, BackgroundVerticalThreePartImage = 1, BackgroundHorizontalThreePartImage = 2, - BackgroundNinePartImage = 3; + BackgroundNinePartImage = 3, + + CustomDrawRectViews = {}; #endif @implementation CPView : CPResponder @@ -92,14 +92,16 @@ var DOMCanvasElementZIndex = -1, #if PLATFORM(DOM) DOMElement _DOMElement; + DOMElement _DOMContentsElement; + CPArray _DOMImageParts; CPArray _DOMImageSizes; unsigned _backgroundType; - - DOMElement _DOMGraphicsElement; #endif + CGRect _dirtyRect; + float _opacity; CPColor _backgroundColor; @@ -117,6 +119,9 @@ var DOMCanvasElementZIndex = -1, + (void)initialize { + if ([self instanceMethodForSelector:@selector(drawRect:)] != [CPView instanceMethodForSelector:@selector(drawRect:)]) + CustomDrawRectViews[[self hash]] = YES; + if (self != [CPView class]) return; @@ -333,7 +338,7 @@ var DOMCanvasElementZIndex = -1, - (void)viewDidMoveToSuperview { - if (_graphicsContext) +// if (_graphicsContext) [self setNeedsDisplay:YES]; } @@ -443,10 +448,18 @@ var DOMCanvasElementZIndex = -1, if (_autoresizesSubviews) [self resizeSubviewsWithOldSize:oldSize]; + + [self setNeedsDisplay:YES]; #if PLATFORM(DOM) CPDOMDisplayServerSetStyleSize(_DOMElement, size.width, size.height); + if (_DOMContentsElement) + { + CPDOMDisplayServerSetSize(_DOMContentsElement, size.width, size.height); + CPDOMDisplayServerSetStyleSize(_DOMContentsElement, size.width, size.height); + } + if (_backgroundType == BackgroundTrivialColor) return; @@ -984,78 +997,115 @@ var DOMCanvasElementZIndex = -1, } -// Focus +// Displaying -- (void)lockFocus +- (void)setNeedsDisplay:(BOOL)aFlag { - // If we don't yet have a graphics context, then we must first create a - // canvas element, then use its 2d context. - if (!_graphicsContext) - { - var context = CGBitmapGraphicsContextCreate(); - + if (aFlag) + [self setNeedsDisplayInRect:[self bounds]]; #if PLATFORM(DOM) - _DOMGraphicsElement = context.DOMElement; - - _DOMGraphicsElement.style.position = "absolute"; - _DOMGraphicsElement.style.top = "0px"; - _DOMGraphicsElement.style.left = "0px"; - _DOMGraphicsElement.style.zIndex = DOMCanvasElementZIndex; - - _DOMGraphicsElement.width = CPRectGetWidth(_frame); - _DOMGraphicsElement.height = CPRectGetHeight(_frame); - - _DOMGraphicsElement.style.width = CPRectGetWidth(_frame) + "px"; - _DOMGraphicsElement.style.height = CPRectGetHeight(_frame) + "px"; - - _DOMElement.appendChild(_DOMGraphicsElement); + else + CPDOMDisplayServerRemoveView(self); #endif - _graphicsContext = [CPGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]; - } - - [CPGraphicsContext setCurrentContext:_graphicsContext]; - - CGContextSaveGState([_graphicsContext graphicsPort]); } -- (void)unlockFocus +- (void)setNeedsDisplayInRect:(CPRect)aRect { - var graphicsPort = [_graphicsContext graphicsPort]; - - CGContextRestoreGState(graphicsPort); + if (!CustomDrawRectViews[[[self class] hash]]) + return; + + if (_CGRectIsEmpty(aRect)) + return; - [CPGraphicsContext setCurrentContext:nil]; -} - -// Displaying + if (_dirtyRect && !_CGRectIsEmpty(_dirtyRect)) + _dirtyRect = CGRectUnion(aRect, _dirtyRect); + else + _dirtyRect = _CGRectMakeCopy(aRect); -- (void)setNeedsDisplay:(BOOL)aFlag -{ - if (aFlag) - [self display]; +#if PLATFORM(DOM) + CPDOMDisplayServerAddView(self); +#endif } -- (void)setNeedsDisplayInRect:(CPRect)aRect +- (BOOL)needsDisplay { - [self displayRect:aRect]; + return _dirtyRect && !_CGRectIsEmpty(_dirtyRect); } - (void)displayIfNeeded { + if ([self needsDisplay]) + [self displayRect:_dirtyRect]; } - (void)display { - [self displayRect:_bounds]; + [self displayRect:[self visibleRect]]; +} + +- (void)displayIfNeededInRect:(CGRect)aRect +{ + if ([self needsDisplay]) + [self displayRect:aRect]; } - (void)displayRect:(CPRect)aRect -{ +{ + [self displayRectIgnoringOpacity:aRect inContext:nil]; + + _dirtyRect = NULL; +} + +- (void)displayRectIgnoringOpacity:(CGRect)aRect inContext:(CPGraphicsContext)aGraphicsContext +{ [self lockFocus]; + + CGContextClearRect([[CPGraphicsContext currentContext] graphicsPort], aRect); + [self drawRect:aRect]; [self unlockFocus]; } + +- (void)lockFocus +{ + if (!_graphicsContext) + { + var graphicsPort = CGBitmapGraphicsContextCreate(); + + _DOMContentsElement = graphicsPort.DOMElement; + + _DOMContentsElement.style.zIndex = -100; + + _DOMContentsElement.style.overflow = "hidden"; + _DOMContentsElement.style.position = "absolute"; + _DOMContentsElement.style.visibility = "visible"; + + _DOMContentsElement.width = ROUND(_CGRectGetWidth(_frame)); + _DOMContentsElement.height = ROUND(_CGRectGetHeight(_frame)); + + _DOMContentsElement.style.top = "0px"; + _DOMContentsElement.style.left = "0px"; + _DOMContentsElement.style.width = ROUND(_CGRectGetWidth(_frame)) + "px"; + _DOMContentsElement.style.height = ROUND(_CGRectGetHeight(_frame)) + "px"; + + CPDOMDisplayServerAppendChild(_DOMElement, _DOMContentsElement); + + _graphicsContext = [CPGraphicsContext graphicsContextWithGraphicsPort:graphicsPort flipped:YES]; + } + + [CPGraphicsContext setCurrentContext:_graphicsContext]; + + CGContextSaveGState([_graphicsContext graphicsPort]); +} + +- (void)unlockFocus +{ + CGContextRestoreGState([_graphicsContext graphicsPort]); + + [CPGraphicsContext setCurrentContext:nil]; +} + - (BOOL)isOpaque { return NO; diff --git a/AppKit/Platform/DOM/CPDOMDisplayServer.h b/AppKit/Platform/DOM/CPDOMDisplayServer.h index 7afa071074..9216ab9014 100644 --- a/AppKit/Platform/DOM/CPDOMDisplayServer.h +++ b/AppKit/Platform/DOM/CPDOMDisplayServer.h @@ -26,9 +26,10 @@ #define SetStyleLeftBottom 2 #define SetStyleRightBottom 3 #define SetStyleSize 4 -#define AppendChild 5 -#define InsertBefore 6 -#define RemoveChild 7 +#define SetSize 5 +#define AppendChild 6 +#define InsertBefore 7 +#define RemoveChild 8 #define CPDOMDisplayServerSetStyleOrigin(anInstruction, aDOMElement, aTransform, x, y)\ if (!aDOMElement.CPDOMDisplayContext)\ @@ -67,6 +68,20 @@ CPDOMDisplayServerInstructions[__index + 2] = aWidth;\ CPDOMDisplayServerInstructions[__index + 3] = aHeight; +#define CPDOMDisplayServerSetSize(aDOMElement, aWidth, aHeight)\ + if (!aDOMElement.CPDOMDisplayContext)\ + aDOMElement.CPDOMDisplayContext = [];\ + var __index = aDOMElement.CPDOMDisplayContext[SetSize];\ + if (!(__index >= 0))\ + {\ + __index = aDOMElement.CPDOMDisplayContext[SetSize] = CPDOMDisplayServerInstructionCount;\ + CPDOMDisplayServerInstructionCount += 4;\ + }\ + CPDOMDisplayServerInstructions[__index] = SetSize;\ + CPDOMDisplayServerInstructions[__index + 1] = aDOMElement;\ + CPDOMDisplayServerInstructions[__index + 2] = aWidth;\ + CPDOMDisplayServerInstructions[__index + 3] = aHeight; + #define CPDOMDisplayServerAppendChild(aParentElement, aChildElement)\ if (aChildElement.CPDOMDisplayContext) aChildElement.CPDOMDisplayContext[SetStyleOrigin] = -1;\ CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = AppendChild;\ @@ -86,3 +101,25 @@ CPDOMDisplayServerInstructions[CPDOMDisplayServerInstructionCount++] = aChildElement; //#dfeine CPDOMDisplayServerCustomAction() + +#define CPDOMDisplayServerAddView(aView)\ + {\ + var ___hash = [aView hash];\ + if (typeof (CPDOMDisplayServerViewsContext[___hash]) == "undefined")\ + {\ + CPDOMDisplayServerViews[CPDOMDisplayServerViewsCount++] = aView;\ + CPDOMDisplayServerViewsContext[___hash] = aView;\ + }\ + }\ + +#define CPDOMDisplayServerRemoveView(aView)\ + {\ + var index = CPDOMDisplayServerViewsContext[[aView hash]];\ + if (typeof index != "undefined") \ + {\ + CPDOMDisplayServerViewsContext[[aView hash]];\ + CPDOMDisplayServerViews[index] = NULL;\ + }\ + }\ + + \ No newline at end of file diff --git a/AppKit/Platform/DOM/CPDOMDisplayServer.j b/AppKit/Platform/DOM/CPDOMDisplayServer.j index c089458669..0e34fef893 100644 --- a/AppKit/Platform/DOM/CPDOMDisplayServer.j +++ b/AppKit/Platform/DOM/CPDOMDisplayServer.j @@ -28,8 +28,12 @@ import var CPDOMDisplayRunLoop = nil; -CPDOMDisplayServerInstructions = []; -CPDOMDisplayServerInstructionCount = 0; +CPDOMDisplayServerInstructions = []; +CPDOMDisplayServerInstructionCount = 0; + +CPDOMDisplayServerViews = []; +CPDOMDisplayServerViewsCount = 0; +CPDOMDisplayServerViewsContext = {}; @implementation CPDOMDisplayServer : CPObject { @@ -44,83 +48,114 @@ CPDOMDisplayServerInstructionCount = 0; + (void)run { - var index = 0; - - while (index < CPDOMDisplayServerInstructionCount) + while (CPDOMDisplayServerInstructionCount || CPDOMDisplayServerViewsCount) { - var instruction = CPDOMDisplayServerInstructions[index++]; -try{ - switch (instruction) + var index = 0; + + while (index < CPDOMDisplayServerInstructionCount) { - case SetStyleLeftTop: - case SetStyleRightTop: - case SetStyleLeftBottom: - case SetStyleRightBottom: var element = CPDOMDisplayServerInstructions[index], - style = element.style, - x = (instruction == SetStyleLeftTop || instruction == SetStyleLeftBottom) ? "left" : "right", - y = (instruction == SetStyleLeftTop || instruction == SetStyleRightTop) ? "top" : "bottom"; - - CPDOMDisplayServerInstructions[index++] = nil; - - var transform = CPDOMDisplayServerInstructions[index++]; + var instruction = CPDOMDisplayServerInstructions[index++]; + try{ + switch (instruction) + { + case SetStyleLeftTop: + case SetStyleRightTop: + case SetStyleLeftBottom: + case SetStyleRightBottom: var element = CPDOMDisplayServerInstructions[index], + style = element.style, + x = (instruction == SetStyleLeftTop || instruction == SetStyleLeftBottom) ? "left" : "right", + y = (instruction == SetStyleLeftTop || instruction == SetStyleRightTop) ? "top" : "bottom"; - if (transform) - { - var point = _CGPointMake(CPDOMDisplayServerInstructions[index++], CPDOMDisplayServerInstructions[index++]), - transformed = _CGPointApplyAffineTransform(point, transform); - - style[x] = ROUND(transformed.x) + "px"; - style[y] = ROUND(transformed.y) + "px"; + CPDOMDisplayServerInstructions[index++] = nil; + + var transform = CPDOMDisplayServerInstructions[index++]; + + if (transform) + { + var point = _CGPointMake(CPDOMDisplayServerInstructions[index++], CPDOMDisplayServerInstructions[index++]), + transformed = _CGPointApplyAffineTransform(point, transform); + + style[x] = ROUND(transformed.x) + "px"; + style[y] = ROUND(transformed.y) + "px"; + + } + else + { + style[x] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px"; + style[y] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px"; + } + + element.CPDOMDisplayContext[SetStyleOrigin] = -1; + + break; + + case SetStyleSize: var element = CPDOMDisplayServerInstructions[index], + style = element.style; + + CPDOMDisplayServerInstructions[index++] = nil; + + element.CPDOMDisplayContext[SetStyleSize] = -1; + + style.width = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px"; + style.height = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px"; + + break; - } - else - { - style[x] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px"; - style[y] = ROUND(CPDOMDisplayServerInstructions[index++]) + "px"; - } + case SetSize: var element = CPDOMDisplayServerInstructions[index]; + + CPDOMDisplayServerInstructions[index++] = nil; + + element.CPDOMDisplayContext[SetSize] = -1; + + element.width = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])); + element.height = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])); - element.CPDOMDisplayContext[SetStyleOrigin] = -1; - - break; + break; + + case AppendChild: CPDOMDisplayServerInstructions[index].appendChild(CPDOMDisplayServerInstructions[index + 1]); - case SetStyleSize: var element = CPDOMDisplayServerInstructions[index], - style = element.style; - - CPDOMDisplayServerInstructions[index++] = nil; - - element.CPDOMDisplayContext[SetStyleSize] = -1; - - style.width = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px"; - style.height = MAX(0.0, ROUND(CPDOMDisplayServerInstructions[index++])) + "px"; - - break; + CPDOMDisplayServerInstructions[index++] = nil; + CPDOMDisplayServerInstructions[index++] = nil; + + break; + + case InsertBefore: CPDOMDisplayServerInstructions[index].insertBefore(CPDOMDisplayServerInstructions[index + 1], CPDOMDisplayServerInstructions[index + 2]); + + CPDOMDisplayServerInstructions[index++] = nil; + CPDOMDisplayServerInstructions[index++] = nil; + CPDOMDisplayServerInstructions[index++] = nil; + + break; - case AppendChild: CPDOMDisplayServerInstructions[index].appendChild(CPDOMDisplayServerInstructions[index + 1]); - - CPDOMDisplayServerInstructions[index++] = nil; - CPDOMDisplayServerInstructions[index++] = nil; - - break; - - case InsertBefore: CPDOMDisplayServerInstructions[index].insertBefore(CPDOMDisplayServerInstructions[index + 1], CPDOMDisplayServerInstructions[index + 2]); - - CPDOMDisplayServerInstructions[index++] = nil; - CPDOMDisplayServerInstructions[index++] = nil; - CPDOMDisplayServerInstructions[index++] = nil; - - break; - - case RemoveChild: CPDOMDisplayServerInstructions[index].removeChild(CPDOMDisplayServerInstructions[index + 1]); - - CPDOMDisplayServerInstructions[index++] = nil; - CPDOMDisplayServerInstructions[index++] = nil; - - break; - }}catch(e) { alert("here?" + instruction) } - } + case RemoveChild: CPDOMDisplayServerInstructions[index].removeChild(CPDOMDisplayServerInstructions[index + 1]); + + CPDOMDisplayServerInstructions[index++] = nil; + CPDOMDisplayServerInstructions[index++] = nil; + + break; + }}catch(e) { alert("here?" + instruction) } + } + + CPDOMDisplayServerInstructionCount = 0; - CPDOMDisplayServerInstructionCount = 0; + var views = CPDOMDisplayServerViews, + index = 0, + count = CPDOMDisplayServerViewsCount; + + // We don't reset CPDOMDisplayServerViewsContext because it can serve for displays that are coming... + CPDOMDisplayServerViews = []; + CPDOMDisplayServerViewsCount = 0; + for (; index < count; ++index) + { + var view = views[index]; + + delete CPDOMDisplayServerViewsContext[[view hash]]; + + [view displayIfNeeded]; + } + } + [CPDOMDisplayRunLoop performSelector:@selector(run) target:CPDOMDisplayServer argument:nil order:0 modes:[CPDefaultRunLoopMode]]; } diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 35587acec0..ff7acd041c 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -127,7 +127,7 @@ + (IMP)instanceMethodForSelector:(SEL)aSelector { - return class_getInstanceMethod(isa, aSelector); + return class_getInstanceMethod(self, aSelector); } - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector