diff --git a/AppKit/CPBox.j b/AppKit/CPBox.j index ee4b63a3f..794c6ee8d 100644 --- a/AppKit/CPBox.j +++ b/AppKit/CPBox.j @@ -332,6 +332,16 @@ CPBelowBottom = 6; [_titleView setFont:aFont]; } +/*! + Return the text field used to display the receiver's title. + + This is the Cappuccino equivalent to the `titleCell` method. +*/ +- (CPTextField)titleView +{ + return _titleView; +} + - (void)_manageTitlePositioning { if (_titlePosition == CPNoTitle) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 813b4573d..e1c934f4c 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -690,6 +690,10 @@ - (void)mouseDragged:(CPEvent)anEvent { + // Don't crash if we never registered the intial click. + if (!_mouseDownEvent) + return; + var locationInWindow = [anEvent locationInWindow], mouseDownLocationInWindow = [_mouseDownEvent locationInWindow]; diff --git a/AppKit/CPTableColumn.j b/AppKit/CPTableColumn.j index 6a1765cad..335da30eb 100644 --- a/AppKit/CPTableColumn.j +++ b/AppKit/CPTableColumn.j @@ -582,7 +582,7 @@ CPTableColumnUserResizingMask = 1 << 1; return nil; var keyPath = [_info objectForKey:CPObservedKeyPathKey], - dotIndex = keyPath.lastIndexOf("."); + dotIndex = keyPath.indexOf("."); if (dotIndex === CPNotFound) return nil; diff --git a/AppKit/CPView.j b/AppKit/CPView.j index cd2637470..a1b1d42ba 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -333,6 +333,9 @@ var CPViewFlags = { }, if (_toolTip == aToolTip) return; + if (aToolTip && ![aToolTip isKindOfClass:CPString]) + aToolTip = [aToolTip description]; + _toolTip = aToolTip; if (_toolTip) diff --git a/AppKit/CPWebView.j b/AppKit/CPWebView.j index 020f695ac..57717d744 100644 --- a/AppKit/CPWebView.j +++ b/AppKit/CPWebView.j @@ -1032,6 +1032,11 @@ CPWebViewAppKitScrollMaxPollCount = 3; var documentURL = [CPURL URLWithString:window.location.href]; if ([documentURL isFileURL] && CPFeatureIsCompatible(CPSOPDisabledFromFileURLs)) return YES; + + // Relative URLs always pass the SOP. + if (![self scheme] && ![self host] && ![self port]) + return YES; + return ([documentURL scheme] == [self scheme] && [documentURL host] == [self host] && [documentURL port] == [self port]); } diff --git a/AppKit/_CPImageAndTextView.j b/AppKit/_CPImageAndTextView.j index c12661d1e..73e68a251 100644 --- a/AppKit/_CPImageAndTextView.j +++ b/AppKit/_CPImageAndTextView.j @@ -292,7 +292,7 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0, { [self layoutIfNeeded]; - var textFrame = CGRectMakeZero(); + var textFrame = _CGRectMakeZero(); if (_DOMTextElement) { @@ -681,38 +681,47 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0, textRectWidth = _CGRectGetWidth(textRect), textRectHeight = _CGRectGetHeight(textRect); - if (_verticalAlignment !== CPTopVerticalTextAlignment) + if (textRectWidth <= 0 || textRectHeight <= 0) { - if (!_textSize) + // Don't bother trying to position the text in an empty rect. + textRectWidth = 0; + textRectHeight = 0; + } + else + { + if (_verticalAlignment !== CPTopVerticalTextAlignment) { - if (_lineBreakMode === CPLineBreakByCharWrapping || - _lineBreakMode === CPLineBreakByWordWrapping) + if (!_textSize) { - _textSize = [_text sizeWithFont:_font inWidth:textRectWidth]; - } - else - { - _textSize = [_text sizeWithFont:_font]; + if (_lineBreakMode === CPLineBreakByCharWrapping || + _lineBreakMode === CPLineBreakByWordWrapping) + { + _textSize = [_text sizeWithFont:_font inWidth:textRectWidth]; + } + else + { + _textSize = [_text sizeWithFont:_font]; - // Account for possible fractional pixels at right edge - _textSize.width += 1; + // Account for possible fractional pixels at right edge + _textSize.width += 1; + } + + // Account for possible fractional pixels at bottom edge + _textSize.height += 1; } - // Account for possible fractional pixels at bottom edge - _textSize.height += 1; - } + if (_verticalAlignment === CPCenterVerticalTextAlignment) + { + // Since we added +1 px height above to show fractional pixels on the bottom, we have to remove that when calculating vertical centre. + textRectY = textRectY + (textRectHeight - _textSize.height + 1.0) / 2.0; + textRectHeight = _textSize.height; + } - if (_verticalAlignment === CPCenterVerticalTextAlignment) - { - // Since we added +1 px height above to show fractional pixels on the bottom, we have to remove that when calculating vertical centre. - textRectY = textRectY + (textRectHeight - _textSize.height + 1.0) / 2.0; - textRectHeight = _textSize.height; - } - - else //if (_verticalAlignment === CPBottomVerticalTextAlignment) - { - textRectY = textRectY + textRectHeight - _textSize.height; - textRectHeight = _textSize.height; + else //if (_verticalAlignment === CPBottomVerticalTextAlignment) + { + textRectY = textRectY + textRectHeight - _textSize.height; + textRectHeight = _textSize.height; + } } } @@ -740,7 +749,7 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0, - (void)sizeToFit { - var size = CGSizeMakeZero(); + var size = _CGSizeMakeZero(); if ((_imagePosition !== CPNoImage) && _image) { @@ -781,4 +790,13 @@ var _CPimageAndTextViewFrameSizeChangedFlag = 1 << 0, [self setFrameSize:size]; } +- (void)setFrameSize:(CGSize)aSize +{ + // If we're applying line breaks the height of the text size might change as a result of the bounds changing. + if ((_lineBreakMode === CPLineBreakByCharWrapping || _lineBreakMode === CPLineBreakByWordWrapping) && aSize.width !== [self frameSize].width) + _textSize = nil; + + [super setFrameSize:aSize]; +} + @end diff --git a/Foundation/CPGeometry.j b/Foundation/CPGeometry.j index ba3c249f4..3f61b4fdb 100644 --- a/Foundation/CPGeometry.j +++ b/Foundation/CPGeometry.j @@ -74,6 +74,18 @@ CPPointCreateCopy = CGPointMakeCopy; */ CPPointEqualToPoint = CGPointEqualToPoint; +/*! + Tests whether the CGPoint is contained by the CGRect. + @group CGPoint + @param aPoint the CGPoint to check + @param aRect the CGRect to check + @return BOOL \c YES if the rect contains the point. +*/ +CPPointInRect = function(aPoint, aRect) +{ + return CGRectContainsPoint(aRect, aPoint) +}; + /*! Test whether the two CGRects have the same origin and size @group CGRect