diff --git a/AppKit/CPView.j b/AppKit/CPView.j index 7b1c193d6..8066cafe5 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -90,7 +90,7 @@ var CachedNotificationCenter = nil, #if PLATFORM(DOM) var DOMElementPrototype = nil, - + BackgroundTrivialColor = 0, BackgroundVerticalThreePartImage = 1, BackgroundHorizontalThreePartImage = 2, @@ -102,7 +102,7 @@ var CPViewFlags = { }, CPViewHasCustomDrawRect = 1 << 0, CPViewHasCustomLayoutSubviews = 1 << 1; -/*! +/*! @ingroup appkit @class CPView @@ -122,37 +122,37 @@ var CPViewFlags = { }, @implementation CPView : CPResponder { CPWindow _window; - + CPView _superview; CPArray _subviews; - + CPGraphicsContext _graphicsContext; - + int _tag; - + CGRect _frame; CGRect _bounds; CGAffineTransform _boundsTransform; CGAffineTransform _inverseBoundsTransform; - + CPSet _registeredDraggedTypes; CPArray _registeredDraggedTypesArray; - + BOOL _isHidden; BOOL _hitTests; BOOL _clipsToBounds; - + BOOL _postsFrameChangedNotifications; BOOL _postsBoundsChangedNotifications; BOOL _inhibitFrameAndBoundsChangedNotifications; - + #if PLATFORM(DOM) DOMElement _DOMElement; DOMElement _DOMContentsElement; - + CPArray _DOMImageParts; CPArray _DOMImageSizes; - + unsigned _backgroundType; #endif @@ -163,19 +163,19 @@ var CPViewFlags = { }, BOOL _autoresizesSubviews; unsigned _autoresizingMask; - + CALayer _layer; BOOL _wantsLayer; - + // Full Screen State BOOL _isInFullScreenMode; - + _CPViewFullScreenModeState _fullScreenModeState; - + // Layout Support BOOL _needsLayout; JSObject _ephemeralSubviews; - + // Theming Support CPTheme _theme; JSObject _themeAttributes; @@ -202,9 +202,9 @@ var CPViewFlags = { }, #if PLATFORM(DOM) DOMElementPrototype = document.createElement("div"); - + var style = DOMElementPrototype.style; - + style.overflow = "hidden"; style.position = "absolute"; style.visibility = "visible"; @@ -262,12 +262,12 @@ var CPViewFlags = { }, - (id)initWithFrame:(CGRect)aFrame { self = [super init]; - + if (self) { var width = _CGRectGetWidth(aFrame), height = _CGRectGetHeight(aFrame); - + _subviews = []; _registeredDraggedTypes = [CPSet set]; _registeredDraggedTypesArray = []; @@ -280,7 +280,7 @@ var CPViewFlags = { }, _autoresizingMask = CPViewNotSizable; _autoresizesSubviews = YES; _clipsToBounds = YES; - + _opacity = 1.0; _isHidden = NO; _hitTests = YES; @@ -290,11 +290,11 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(aFrame), _CGRectGetMinY(aFrame)); CPDOMDisplayServerSetStyleSize(_DOMElement, width, height); - + _DOMImageParts = []; _DOMImageSizes = []; #endif - + _theme = [CPTheme defaultTheme]; _themeState = CPThemeStateNormal; @@ -302,7 +302,7 @@ var CPViewFlags = { }, [self _loadThemeAttributes]; } - + return self; } @@ -350,15 +350,15 @@ var CPViewFlags = { }, - (void)addSubview:(CPView)aSubview positioned:(CPWindowOrderingMode)anOrderingMode relativeTo:(CPView)anotherView { var index = anotherView ? [_subviews indexOfObjectIdenticalTo:anotherView] : CPNotFound; - + // In other words, if no view, then either all the way at the bottom or all the way at the top. if (index === CPNotFound) index = (anOrderingMode === CPWindowAbove) ? [_subviews count] : 0; - + // else, if we have a view, above if above. else if (anOrderingMode === CPWindowAbove) ++index; - + [self _insertSubview:aSubview atIndex:index]; } @@ -375,20 +375,20 @@ var CPViewFlags = { }, if (aSubview._superview == self) { var index = [_subviews indexOfObjectIdenticalTo:aSubview]; - + // FIXME: should this be anIndex >= count? (last one) if (index === anIndex || index === count - 1 && anIndex === count) return; - + [_subviews removeObjectAtIndex:index]; - + #if PLATFORM(DOM) CPDOMDisplayServerRemoveChild(_DOMElement, aSubview._DOMElement); #endif if (anIndex > index) --anIndex; - + //We've effectively made the subviews array shorter, so represent that. --count; } @@ -397,16 +397,16 @@ var CPViewFlags = { }, // Remove the view from its previous superview. [aSubview removeFromSuperview]; - // Set the subview's window to our own. + // Set the subview's window to our own. [aSubview _setWindow:_window]; // Notify the subview that it will be moving. [aSubview viewWillMoveToSuperview:self]; - + // Set ourselves as the superview. aSubview._superview = self; } - + if (anIndex === CPNotFound || anIndex >= count) { _subviews.push(aSubview); @@ -419,16 +419,16 @@ var CPViewFlags = { }, else { _subviews.splice(anIndex, 0, aSubview); - + #if PLATFORM(DOM) // Attach the actual node. CPDOMDisplayServerInsertBefore(_DOMElement, aSubview._DOMElement, _subviews[anIndex + 1]._DOMElement); #endif } - + [aSubview setNextResponder:self]; [aSubview viewDidMoveToSuperview]; - + [self didAddSubview:aSubview]; } @@ -453,14 +453,14 @@ var CPViewFlags = { }, [[self window] _dirtyKeyViewLoop]; [_superview willRemoveSubview:self]; - + [_superview._subviews removeObject:self]; #if PLATFORM(DOM) CPDOMDisplayServerRemoveChild(_superview._DOMElement, _DOMElement); #endif _superview = nil; - + [self _setWindow:nil]; } @@ -473,11 +473,11 @@ var CPViewFlags = { }, { if (aSubview._superview != self) return; - + var index = [_subviews indexOfObjectIdenticalTo:aSubview]; - + [aSubview removeFromSuperview]; - + [self _insertSubview:aView atIndex:index]; } @@ -555,7 +555,7 @@ var CPViewFlags = { }, { if (_window === aWindow) return; - + [[self window] _dirtyKeyViewLoop]; // Clear out first responder if we're the first responder and leaving. @@ -579,7 +579,7 @@ var CPViewFlags = { }, while (count--) [_subviews[count] _setWindow:aWindow]; - + [self viewDidMoveToWindow]; [[self window] _dirtyKeyViewLoop]; @@ -592,13 +592,13 @@ var CPViewFlags = { }, - (BOOL)isDescendantOf:(CPView)aView { var view = self; - + do { if (view == aView) return YES; } while(view = [view superview]) - + return NO; } @@ -649,20 +649,20 @@ var CPViewFlags = { }, - (CPMenuItem)enclosingMenuItem { var view = self; - + while (view && ![view isKindOfClass:[_CPMenuItemView class]]) view = [view superview]; - + if (view) return view._menuItem; - + return nil; /* var view = self, enclosingMenuItem = _enclosingMenuItem; - + while (!enclosingMenuItem && (view = view._enclosingMenuItem)) view = [view superview]; - + return enclosingMenuItem;*/ } @@ -715,9 +715,9 @@ var CPViewFlags = { }, { if (_CGRectEqualToRect(_frame, aFrame)) return; - + _inhibitFrameAndBoundsChangedNotifications = YES; - + [self setFrameOrigin:aFrame.origin]; [self setFrameSize:aFrame.size]; @@ -747,19 +747,19 @@ var CPViewFlags = { }, } /*! - Moves the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system. - The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver - is configured to do so. If the specified origin is the same as the frame's current origin, the method will + Moves the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system. + The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver + is configured to do so. If the specified origin is the same as the frame's current origin, the method will simply return (and no notification will be posted). @param aPoint the new origin point */ - (void)setCenter:(CGPoint)aPoint { - [self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)]; + [self setFrameOrigin:CGPointMake(aPoint.x - _frame.size.width / 2.0, aPoint.y - _frame.size.height / 2.0)]; } /*! - Returns the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system. + Returns the center of the receiver's frame to the provided point. The point is defined in the superview's coordinate system. @return CGPoint the center point of the receiver's frame */ - (CGPoint)center @@ -768,16 +768,16 @@ var CPViewFlags = { }, } /*! - Sets the receiver's frame origin to the provided point. The point is defined in the superview's coordinate system. - The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver - is configured to do so. If the specified origin is the same as the frame's current origin, the method will + Sets the receiver's frame origin to the provided point. The point is defined in the superview's coordinate system. + The method posts a CPViewFrameDidChangeNotification to the default notification center if the receiver + is configured to do so. If the specified origin is the same as the frame's current origin, the method will simply return (and no notification will be posted). @param aPoint the new origin point */ - (void)setFrameOrigin:(CGPoint)aPoint { var origin = _frame.origin; - + if (!aPoint || _CGPointEqualToPoint(origin, aPoint)) return; @@ -803,7 +803,7 @@ var CPViewFlags = { }, - (void)setFrameSize:(CGSize)aSize { var size = _frame.size; - + if (!aSize || _CGSizeEqualToSize(size, aSize)) return; @@ -823,7 +823,7 @@ var CPViewFlags = { }, if (_autoresizesSubviews) [self resizeSubviewsWithOldSize:oldSize]; - + [self setNeedsLayout]; [self setNeedsDisplay:YES]; @@ -874,7 +874,7 @@ var CPViewFlags = { }, } /*! - Sets the receiver's bounds. The bounds define the size and location of the receiver inside it's frame. Posts a + Sets the receiver's bounds. The bounds define the size and location of the receiver inside it's frame. Posts a CPViewBoundsDidChangeNotification to the default notification center if the receiver is configured to do so. @param bounds the new bounds */ @@ -882,9 +882,9 @@ var CPViewFlags = { }, { if (_CGRectEqualToRect(_bounds, bounds)) return; - + _inhibitFrameAndBoundsChangedNotifications = YES; - + [self setBoundsOrigin:bounds.origin]; [self setBoundsSize:bounds.size]; @@ -922,13 +922,13 @@ var CPViewFlags = { }, - (void)setBoundsOrigin:(CGPoint)aPoint { var origin = _bounds.origin; - + if (_CGPointEqualToPoint(origin, aPoint)) return; - + origin.x = aPoint.x; origin.y = aPoint.y; - + if (origin.x != 0 || origin.y != 0) { _boundsTransform = _CGAffineTransformMakeTranslation(-origin.x, -origin.y); @@ -939,19 +939,19 @@ var CPViewFlags = { }, _boundsTransform = nil; _inverseBoundsTransform = nil; } - + #if PLATFORM(DOM) var index = _subviews.length; - + while (index--) { var view = _subviews[index], origin = view._frame.origin; - + CPDOMDisplayServerSetStyleLeftTop(view._DOMElement, _boundsTransform, origin.x, origin.y); } #endif - + if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications) [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self]; } @@ -965,7 +965,7 @@ var CPViewFlags = { }, - (void)setBoundsSize:(CGSize)aSize { var size = _bounds.size; - + if (_CGSizeEqualToSize(size, aSize)) return; @@ -974,22 +974,22 @@ var CPViewFlags = { }, if (!_CGSizeEqualToSize(size, frameSize)) { var origin = _bounds.origin; - + origin.x /= size.width / frameSize.width; origin.y /= size.height / frameSize.height; } - + size.width = aSize.width; size.height = aSize.height; - + if (!_CGSizeEqualToSize(size, frameSize)) { var origin = _bounds.origin; - + origin.x *= size.width / frameSize.width; origin.y *= size.height / frameSize.height; } - + if (_postsBoundsChangedNotifications && !_inhibitFrameAndBoundsChangedNotifications) [CachedNotificationCenter postNotificationName:CPViewBoundsDidChangeNotification object:self]; } @@ -1002,7 +1002,7 @@ var CPViewFlags = { }, - (void)resizeWithOldSuperviewSize:(CGSize)aSize { var mask = [self autoresizingMask]; - + if(mask == CPViewNotSizable) return; @@ -1017,7 +1017,7 @@ var CPViewFlags = { }, newFrame.origin.x += dX; if (mask & CPViewWidthSizable) newFrame.size.width += dX; - + if (mask & CPViewMinYMargin) newFrame.origin.y += dY; if (mask & CPViewHeightSizable) @@ -1033,7 +1033,7 @@ var CPViewFlags = { }, - (void)resizeSubviewsWithOldSize:(CGSize)aSize { var count = _subviews.length; - + while (count--) [_subviews[count] resizeWithOldSuperviewSize:aSize]; } @@ -1094,14 +1094,14 @@ var CPViewFlags = { }, - (BOOL)enterFullScreenMode:(CPScreen)aScreen withOptions:(CPDictionary)options { _fullScreenModeState = _CPViewFullScreenModeStateMake(self); - + var fullScreenWindow = [[CPWindow alloc] initWithContentRect:[[CPPlatformWindow primaryPlatformWindow] contentBounds] styleMask:CPBorderlessWindowMask]; - + [fullScreenWindow setLevel:CPScreenSaverWindowLevel]; [fullScreenWindow setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; - + var contentView = [fullScreenWindow contentView]; - + [contentView setBackgroundColor:[CPColor blackColor]]; [contentView addSubview:self]; @@ -1109,11 +1109,11 @@ var CPViewFlags = { }, [self setFrame:CGRectMakeCopy([contentView bounds])]; [fullScreenWindow makeKeyAndOrderFront:self]; - + [fullScreenWindow makeFirstResponder:self]; - + _isInFullScreenMode = YES; - + return YES; } @@ -1139,7 +1139,7 @@ var CPViewFlags = { }, [self setFrame:_fullScreenModeState.frame]; [self setAutoresizingMask:_fullScreenModeState.autoresizingMask]; [_fullScreenModeState.superview _insertSubview:self atIndex:_fullScreenModeState.index]; - + [[self window] orderOut:self]; } @@ -1175,17 +1175,41 @@ var CPViewFlags = { }, if ([view isKindOfClass:[CPView class]]) { - do + do { if (self == view) { [_window makeFirstResponder:[self nextValidKeyView]]; break; - } - } + } + } while (view = [view superview]); } + + [self _notifyViewDidHide]; } + else + { + [self _notifyViewDidUnhide]; + } +} + +- (void)_notifyViewDidHide +{ + [self viewDidHide]; + + var count = [_subviews count]; + while (count--) + [_subviews[count] _notifyViewDidHide]; +} + +- (void)_notifyViewDidUnhide +{ + [self viewDidUnhide]; + + var count = [_subviews count]; + while (count--) + [_subviews[count] _notifyViewDidUnhide]; } /*! @@ -1214,7 +1238,7 @@ var CPViewFlags = { }, } /*! - Sets the opacity of the receiver. The value must be in the range of 0.0 to 1.0, where 0.0 is + Sets the opacity of the receiver. The value must be in the range of 0.0 to 1.0, where 0.0 is completely transparent and 1.0 is completely opaque. @param anAlphaValue an alpha value ranging from 0.0 to 1.0. */ @@ -1222,11 +1246,11 @@ var CPViewFlags = { }, { if (_opacity == anAlphaValue) return; - + _opacity = anAlphaValue; - + #if PLATFORM(DOM) - + if (CPFeatureIsCompatible(CPOpacityRequiresFilterFeature)) { if (anAlphaValue === 1.0) @@ -1252,23 +1276,51 @@ var CPViewFlags = { }, /*! Returns \c YES if the receiver is hidden, or one of it's ancestor views is hidden. \c NO, otherwise. -*/ +*/ - (BOOL)isHiddenOrHasHiddenAncestor { var view = self; - + while (view && ![view isHidden]) view = [view superview]; - + return view !== nil; } +/*! + Called when the return value of isHiddenOrHasHiddenAncestor becomes YES, + e.g. when this view becomes hidden due to a setHidden:YES message to + itself or to one of its superviews. + + Note: in the current implementation, viewDidHide may be called multiple + times if additional superviews are hidden, even if + isHiddenOrHasHiddenAncestor was already YES. +*/ +- (void)viewDidHide +{ + +} + +/*! + Called when the return value of isHiddenOrHasHiddenAncestor becomes NO, + e.g. when this view stops being hidden due to a setHidden:NO message to + itself or to one of its superviews. + + Note: in the current implementation, viewDidUnhide may be called multiple + times if additional superviews are unhidden, even if + isHiddenOrHasHiddenAncestor was already NO. +*/ +- (void)viewDidUnhide +{ + +} + /*! Returns whether the receiver should be sent a \c -mouseDown: message for \c anEvent.
Returns \c YES by default. @return \c YES, if the view object accepts first mouse-down event. \c NO, otherwise. */ -//FIXME: should be NO by default? +//FIXME: should be NO by default? - (BOOL)acceptsFirstMouse:(CPEvent)anEvent { return YES; @@ -1301,7 +1353,7 @@ var CPViewFlags = { }, { if(_isHidden || !_hitTests || !CPRectContainsPoint(_frame, aPoint)) return nil; - + var view = nil, i = _subviews.length, adjustedPoint = _CGPointMake(aPoint.x - _CGRectGetMinX(_frame), aPoint.y - _CGRectGetMinY(_frame)); @@ -1467,7 +1519,7 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleSize(_DOMImageParts[5], _DOMImageSizes[5].width, height); CPDOMDisplayServerSetStyleSize(_DOMImageParts[7], width, _DOMImageSizes[7].height); - CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[0], NULL, 0.0, 0.0); + 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); CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[3], NULL, 0.0, _DOMImageSizes[1].height); @@ -1475,14 +1527,14 @@ var CPViewFlags = { }, CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[5], NULL, 0.0, _DOMImageSizes[1].height); CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[6], NULL, 0.0, 0.0); CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[7], NULL, _DOMImageSizes[6].width, 0.0); - CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[8], NULL, 0.0, 0.0); + CPDOMDisplayServerSetStyleRightBottom(_DOMImageParts[8], NULL, 0.0, 0.0); } 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); + CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[1], NULL, 0.0, _DOMImageSizes[0].height); CPDOMDisplayServerSetStyleLeftBottom(_DOMImageParts[2], NULL, 0.0, 0.0); } else if (_backgroundType == BackgroundHorizontalThreePartImage) @@ -1490,7 +1542,7 @@ var CPViewFlags = { }, 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); + CPDOMDisplayServerSetStyleLeftTop(_DOMImageParts[1], NULL, _DOMImageSizes[0].width, 0.0); CPDOMDisplayServerSetStyleRightTop(_DOMImageParts[2], NULL, 0.0, 0.0); } } @@ -1786,9 +1838,9 @@ setBoundsOrigin: - (void)displayRect:(CPRect)aRect { [self viewWillDraw]; - + [self displayRectIgnoringOpacity:aRect inContext:nil]; - + _dirtyRect = NULL; } @@ -1796,9 +1848,9 @@ setBoundsOrigin: { #if PLATFORM(DOM) [self lockFocus]; - + CGContextClearRect([[CPGraphicsContext currentContext] graphicsPort], aRect); - + [self drawRect:aRect]; [self unlockFocus]; #endif @@ -1816,18 +1868,18 @@ setBoundsOrigin: 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"; @@ -1838,9 +1890,9 @@ setBoundsOrigin: #endif _graphicsContext = [CPGraphicsContext graphicsContextWithGraphicsPort:graphicsPort flipped:YES]; } - + [CPGraphicsContext setCurrentContext:_graphicsContext]; - + CGContextSaveGState([_graphicsContext graphicsPort]); } @@ -1850,7 +1902,7 @@ setBoundsOrigin: - (void)unlockFocus { CGContextRestoreGState([_graphicsContext graphicsPort]); - + [CPGraphicsContext setCurrentContext:nil]; } @@ -1869,7 +1921,7 @@ setBoundsOrigin: if (_needsLayout) { _needsLayout = NO; - + [self layoutSubviews]; } } @@ -1893,7 +1945,7 @@ setBoundsOrigin: { if (!_superview) return _bounds; - + return CGRectIntersection([self convertRect:[_superview visibleRect] fromView:_superview], _bounds); } @@ -1904,7 +1956,7 @@ setBoundsOrigin: var superview = _superview, clipViewClass = [CPClipView class]; - while(superview && ![superview isKindOfClass:clipViewClass]) + while(superview && ![superview isKindOfClass:clipViewClass]) superview = superview._superview; return superview; @@ -1917,10 +1969,10 @@ setBoundsOrigin: - (void)scrollPoint:(CGPoint)aPoint { var clipView = [self _enclosingClipView]; - + if (!clipView) return; - + [clipView scrollToPoint:[self convertPoint:aPoint toView:clipView]]; } @@ -1932,35 +1984,35 @@ setBoundsOrigin: - (BOOL)scrollRectToVisible:(CGRect)aRect { var visibleRect = [self visibleRect]; - + // Make sure we have a rect that exists. aRect = CGRectIntersection(aRect, _bounds); - + // If aRect is empty or is already visible then no scrolling required. if (_CGRectIsEmpty(aRect) || CGRectContainsRect(visibleRect, aRect)) return NO; var enclosingClipView = [self _enclosingClipView]; - + // If we're not in a clip view, then there isn't much we can do. if (!enclosingClipView) return NO; - + var scrollPoint = _CGPointMakeCopy(visibleRect.origin); - + // One of the following has to be true since our current visible rect didn't contain aRect. if (_CGRectGetMinX(aRect) <= _CGRectGetMinX(visibleRect)) scrollPoint.x = _CGRectGetMinX(aRect); else if (_CGRectGetMaxX(aRect) > _CGRectGetMaxX(visibleRect)) scrollPoint.x += _CGRectGetMaxX(aRect) - _CGRectGetMaxX(visibleRect); - + if (_CGRectGetMinY(aRect) <= _CGRectGetMinY(visibleRect)) scrollPoint.y = CGRectGetMinY(aRect); else if (_CGRectGetMaxY(aRect) > _CGRectGetMaxY(visibleRect)) scrollPoint.y += _CGRectGetMaxY(aRect) - _CGRectGetMaxY(visibleRect); - + [enclosingClipView scrollToPoint:CGPointMake(scrollPoint.x, scrollPoint.y)]; - + return YES; } @@ -2000,7 +2052,7 @@ setBoundsOrigin: var superview = _superview, scrollViewClass = [CPScrollView class]; - while(superview && ![superview isKindOfClass:scrollViewClass]) + while(superview && ![superview isKindOfClass:scrollViewClass]) superview = superview._superview; return superview; @@ -2098,7 +2150,7 @@ setBoundsOrigin: { if (_layer == aLayer) return; - + if (_layer) { _layer._owningView = nil; @@ -2106,18 +2158,18 @@ setBoundsOrigin: _DOMElement.removeChild(_layer._DOMElement); #endif } - + _layer = aLayer; - + if (_layer) { var bounds = CGRectMakeCopy([self bounds]); - + [_layer _setOwningView:self]; - + #if PLATFORM(DOM) _layer._DOMElement.style.zIndex = 100; - + _DOMElement.appendChild(_layer._DOMElement); #endif } @@ -2229,7 +2281,7 @@ setBoundsOrigin: } var attributeDictionary = [theClass themeAttributes]; - + if (!attributeDictionary) continue; @@ -2262,14 +2314,14 @@ setBoundsOrigin: themeClass = [theClass themeClass]; _themeAttributes = {}; - + while (count--) { var attributeName = attributes[count--], attribute = [[_CPThemeAttribute alloc] initWithName:attributeName defaultValue:attributes[count]]; [attribute setParentAttribute:[theme _attributeWithName:attributeName forClass:themeClass]]; - + _themeAttributes[attributeName] = attribute; } } @@ -2278,9 +2330,9 @@ setBoundsOrigin: { if (_theme === aTheme) return; - + _theme = aTheme; - + [self viewDidChangeTheme]; } @@ -2387,7 +2439,7 @@ setBoundsOrigin: return _CGRectMakeZero(); } -- (CPView)layoutEphemeralSubviewNamed:(CPString)aViewName +- (CPView)layoutEphemeralSubviewNamed:(CPString)aViewName positioned:(CPWindowOrderingMode)anOrderingMode relativeToEphemeralSubviewNamed:(CPString)relativeToViewName { @@ -2452,9 +2504,9 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", */ - (id)initWithCoder:(CPCoder)aCoder { - // We create the DOMElement "early" because there is a chance that we - // will decode our superview before we are done decoding, at which point - // we have to have an element to place in the tree. Perhaps there is + // We create the DOMElement "early" because there is a chance that we + // will decode our superview before we are done decoding, at which point + // we have to have an element to place in the tree. Perhaps there is // a more "elegant" way to do this...? #if PLATFORM(DOM) _DOMElement = DOMElementPrototype.cloneNode(false); @@ -2465,16 +2517,16 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _bounds = [aCoder decodeRectForKey:CPViewBoundsKey]; self = [super initWithCoder:aCoder]; - + if (self) { // We have to manually check because it may be 0, so we can't use || _tag = [aCoder containsValueForKey:CPViewTagKey] ? [aCoder decodeIntForKey:CPViewTagKey] : -1; - + _window = [aCoder decodeObjectForKey:CPViewWindowKey]; _subviews = [aCoder decodeObjectForKey:CPViewSubviewsKey] || []; _superview = [aCoder decodeObjectForKey:CPViewSuperviewKey]; - + // FIXME: Should we encode/decode this? _registeredDraggedTypes = [CPSet set]; _registeredDraggedTypesArray = []; @@ -2483,7 +2535,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", _autoresizesSubviews = ![aCoder containsValueForKey:CPViewAutoresizesSubviewsKey] || [aCoder decodeBoolForKey:CPViewAutoresizesSubviewsKey]; _hitTests = ![aCoder containsValueForKey:CPViewHitTestsKey] || [aCoder decodeObjectForKey:CPViewHitTestsKey]; - + // DOM SETUP #if PLATFORM(DOM) _DOMImageParts = []; @@ -2491,10 +2543,10 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(_frame), _CGRectGetMinY(_frame)); CPDOMDisplayServerSetStyleSize(_DOMElement, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame)); - + var index = 0, count = _subviews.length; - + for (; index < count; ++index) { CPDOMDisplayServerAppendChild(_DOMElement, _subviews[index]._DOMElement); @@ -2546,7 +2598,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", - (void)encodeWithCoder:(CPCoder)aCoder { [super encodeWithCoder:aCoder]; - + if (_tag !== -1) [aCoder encodeInt:_tag forKey:CPViewTagKey]; @@ -2616,7 +2668,7 @@ var CPViewAutoresizingMaskKey = @"CPViewAutoresizingMask", var _CPViewFullScreenModeStateMake = function(aView) { var superview = aView._superview; - + return { autoresizingMask:aView._autoresizingMask, frame:CGRectMakeCopy(aView._frame), index:(superview ? [superview._subviews indexOfObjectIdenticalTo:aView] : 0), superview:superview }; } @@ -2626,93 +2678,93 @@ var _CPViewGetTransform = function(/*CPView*/ fromView, /*CPView */ toView) sameWindow = YES, fromWindow = nil, toWindow = nil; - + if (fromView) { var view = fromView; - + // FIXME: This doesn't handle the case when the outside views are equal. - // If we have a fromView, "climb up" the view tree until + // If we have a fromView, "climb up" the view tree until // we hit the root node or we hit the toLayer. while (view && view != toView) { var frame = view._frame; - + transform.tx += _CGRectGetMinX(frame); transform.ty += _CGRectGetMinY(frame); - + if (view._boundsTransform) { _CGAffineTransformConcatTo(transform, view._boundsTransform, transform); } - + view = view._superview; } - + // If we hit toView, then we're done. if (view === toView) return transform; - + else if (fromView && toView) { fromWindow = [fromView window]; toWindow = [toView window]; - + if (fromWindow && toWindow && fromWindow !== toWindow) { sameWindow = NO; - + var frame = [fromWindow frame]; - + transform.tx += _CGRectGetMinX(frame); transform.ty += _CGRectGetMinY(frame); } } } - + // FIXME: For now we can do things this way, but eventually we need to do them the "hard" way. var view = toView; - + while (view) { var frame = view._frame; - + transform.tx -= _CGRectGetMinX(frame); transform.ty -= _CGRectGetMinY(frame); - + if (view._boundsTransform) { _CGAffineTransformConcatTo(transform, view._inverseBoundsTransform, transform); } - + view = view._superview; } - + if (!sameWindow) { var frame = [toWindow frame]; - + transform.tx -= _CGRectGetMinX(frame); transform.ty -= _CGRectGetMinY(frame); } /* var views = [], view = toView; - + while (view) { views.push(view); view = view._superview; } - + var index = views.length; - + while (index--) { var frame = views[index]._frame; - + transform.tx -= _CGRectGetMinX(frame); transform.ty -= _CGRectGetMinY(frame); }*/ - + return transform; }