From 0f5d459ed8c0c1df7d9669c6112b6840bae3e50f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 Oct 2012 11:21:42 +0100 Subject: [PATCH 1/7] Fixed: collection view crash on unepexted drag events. --- AppKit/CPCollectionView.j | 4 ++++ 1 file changed, 4 insertions(+) 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]; From 90d27133b0024915b1b0f6b298dd12e80ff68824 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 Oct 2012 11:22:24 +0100 Subject: [PATCH 2/7] Fixed: relative URLs were deemed to fail the SOP test by web views. --- AppKit/CPWebView.j | 5 +++++ 1 file changed, 5 insertions(+) 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]); } From fb155dec581299a68b2d2f157c4c633ddaf97d48 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 Oct 2012 11:44:21 +0100 Subject: [PATCH 3/7] Allow non-string tooltips. Technically the tooltip should be a `CPString` but if a date or a number is passed this will now work without a crash. --- AppKit/CPView.j | 3 +++ 1 file changed, 3 insertions(+) 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) From 7de4fe7afad4bb552e61ca1270fabf475b0aa1dc Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 Oct 2012 15:24:10 +0100 Subject: [PATCH 4/7] Fixed: automatic table view sort descriptors didn't work for deeper bindings. If a table view column showed for example `arrangedObjects.user.name`, it would try to sort arranged objects by `name` instead of `user.name`. --- AppKit/CPTableColumn.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 0d9973abb9e86874d6bdfc342af05a0283fc02e0 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 23 Oct 2012 16:19:11 +0100 Subject: [PATCH 5/7] Fixed: out of place table headers and other text positioning errors. A line breaking, vertically centred or bottom aligned `_CPImageAndTextView` would not properly recalculate text position when the height of the text changed due to the width of the field changing. This could cause, for example, table header text to be misaligned if the table was initialised with a zero height. --- AppKit/_CPImageAndTextView.j | 72 ++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 27 deletions(-) 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 From c3c61e188998f8cb499665757536e5e9fb614cf1 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 24 Oct 2012 15:32:45 +0100 Subject: [PATCH 6/7] `- CPBox titleView`. This method is the Cappuccino analog to `- NSBox titleCell`. --- AppKit/CPBox.j | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) From 797bfeec983359edd0480a2a22aa152581e2cb66 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 24 Oct 2012 15:35:42 +0100 Subject: [PATCH 7/7] Implement `CPPointInRect`. This improves source code compatibility with Cocoa when replacing NS with CP. --- Foundation/CPGeometry.j | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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