From bd0114aa0622bdd75ed33e3cf5ae1361a904494c Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 26 Jul 2012 13:42:01 +0100 Subject: [PATCH 01/17] Refs #1632. Remove debug logging. --- Tests/Foundation/CPUndoManagerTest.j | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/Foundation/CPUndoManagerTest.j b/Tests/Foundation/CPUndoManagerTest.j index 67ef6308c..480d4a0ed 100644 --- a/Tests/Foundation/CPUndoManagerTest.j +++ b/Tests/Foundation/CPUndoManagerTest.j @@ -52,7 +52,6 @@ // The default run loop undo grouping won't be closed until the next run loop cycle. [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; - CPLog.error("receivedNotifications: %@", receivedNotifications); [self assert:CPUndoManagerDidCloseUndoGroupNotification equals:[receivedNotifications[0] name]]; [[CPNotificationCenter defaultCenter] removeObserver:self]; From 9d2bdea8d94091c2263e41b21dfefd31d7191144 Mon Sep 17 00:00:00 2001 From: Eduardo Gonzalez Date: Fri, 27 Jul 2012 20:51:29 +0900 Subject: [PATCH 02/17] Removed tailing comma from CPColorWithImages call. The extra comma causes IE to think it was passed an array with 4 values and causes CPColorWithImages to return a NinePartImage even though it only has three parts. --- AppKit/CPWindow/_CPBorderlessBridgeWindowView.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j b/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j index 24faf9ba8..05959e4b5 100644 --- a/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j +++ b/AppKit/CPWindow/_CPBorderlessBridgeWindowView.j @@ -38,7 +38,7 @@ var _CPToolbarViewBackgroundColor = nil; _CPToolbarViewBackgroundColor = CPColorWithImages([ ["_CPToolbarView/toolbar-background-top.png", 1, 1, bundle], ["_CPToolbarView/toolbar-background-center.png", 1, 57.0, bundle], - ["_CPToolbarView/toolbar-background-bottom.png", 1, 1, bundle], + ["_CPToolbarView/toolbar-background-bottom.png", 1, 1, bundle] ], CPColorPatternIsVertical); } From f42b241469bb3d348ff533b2819c0d269a70c58a Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 27 Jul 2012 20:19:20 +0200 Subject: [PATCH 03/17] CPCib -initWithContentsOfURL: return nil if the requested data is nil --- AppKit/Cib/CPCib.j | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AppKit/Cib/CPCib.j b/AppKit/Cib/CPCib.j index c9c9a3da0..c1b2a46d6 100644 --- a/AppKit/Cib/CPCib.j +++ b/AppKit/Cib/CPCib.j @@ -61,6 +61,10 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey"; if (self) { _data = [CPURLConnection sendSynchronousRequest:[CPURLRequest requestWithURL:aURL] returningResponse:nil]; + + if (!_data) + return nil; + _awakenCustomResources = YES; } From df5a7104b1f9ae16dc2b2bdabc6c127a98afd8d4 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 28 Jul 2012 01:58:41 +0100 Subject: [PATCH 04/17] Fixes #1638. The case of the incomplete optimisation. --- Objective-J/CFData.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Objective-J/CFData.js b/Objective-J/CFData.js index f4b08f86b..44841fbb9 100644 --- a/Objective-J/CFData.js +++ b/Objective-J/CFData.js @@ -285,7 +285,6 @@ CFData.bytesToUtf16String = function(bytes) return String.fromCharCode.apply(NULL, temp); }; - CFData.encodeBase64Utf16String = function(input) { // charCodeAt returns UTF-16. @@ -293,8 +292,8 @@ CFData.encodeBase64Utf16String = function(input) for (var i = 0; i < input.length; i++) { var c = input.charCodeAt(i); - temp.push(input.charCodeAt(i) & 0xFF); - temp.push((input.charCodeAt(i) & 0xFF00) >> 8); + temp.push(c & 0xFF); + temp.push((c & 0xFF00) >> 8); } return CFData.encodeBase64Array(temp); From 22b882648b84aa04881d8757084fc2bf154c3b30 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 28 Jul 2012 02:06:05 +0100 Subject: [PATCH 05/17] Formatting. --- Objective-J/CFData.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objective-J/CFData.js b/Objective-J/CFData.js index 44841fbb9..4075608df 100644 --- a/Objective-J/CFData.js +++ b/Objective-J/CFData.js @@ -229,12 +229,12 @@ CFData.encodeBase64Array = function(input) // pad with "=" and revert array to previous state if (pad > 0) { - output[output.length-1] = "="; + output[output.length - 1] = "="; input.pop(); } if (pad > 1) { - output[output.length-2] = "="; + output[output.length - 2] = "="; input.pop(); } @@ -279,8 +279,8 @@ CFData.bytesToUtf16String = function(bytes) { // Strings are encoded with 16 bits per character. var temp = []; - for (var i = 0; i < bytes.length; i+=2) - temp.push(bytes[i+1] << 8 | bytes[i]); + for (var i = 0; i < bytes.length; i += 2) + temp.push(bytes[i + 1] << 8 | bytes[i]); // This is relatively efficient, I think: return String.fromCharCode.apply(NULL, temp); }; From 7537f4d032a49cb644f1d7f5d6a21ca6cb753c7e Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 1 Aug 2012 16:35:34 +0100 Subject: [PATCH 06/17] Eliminate some duplicate methods. --- .../Manual/TableTest/OldTest/AppController.j | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Tests/Manual/TableTest/OldTest/AppController.j b/Tests/Manual/TableTest/OldTest/AppController.j index c72f7746e..a1ba38639 100644 --- a/Tests/Manual/TableTest/OldTest/AppController.j +++ b/Tests/Manual/TableTest/OldTest/AppController.j @@ -299,20 +299,9 @@ tableTestDragType = @"CPTableViewTestDragType"; [aTableView reloadData]; } - -- (void)tableViewSelectionIsChanging:(CPNotification)aNotification -{ - //CPLog.debug(@"changing! %@", [aNotification description]); -} - -- (void)tableViewSelectionDidChange:(CPNotification)aNotification -{ - //CPLog.debug(@"did change! %@", [aNotification description]); -} - - (BOOL)tableView:(CPTableView)aTableView shouldSelectRow:(int)rowIndex { - //CPLog.debug(@"tableView:shouldSelectRow"); + CPLog.debug(@"tableView:shouldSelectRow"); return true; } @@ -324,18 +313,19 @@ tableTestDragType = @"CPTableViewTestDragType"; - (void)tableViewSelectionDidChange:(id)notification { - //CPLogConsole(_cmd + [notification description]); + CPLogConsole(_cmd + [notification description]); } - (void)tableViewSelectionIsChanging:(id)notification { - //CPLogConsole(_cmd + [notification description]); + CPLogConsole(_cmd + [notification description]); } - (void)_tableViewColumnDidResize:(id)notification { - //CPLogConsole(_cmd + [notification description]); + CPLogConsole(_cmd + [notification description]); } + - (BOOL)tableView:(CPTableView)aTableView shouldEditTableColumn:(CPTableColumn)tableColumn row:(int)row { if (aTableView === tableView3) @@ -425,8 +415,8 @@ tableTestDragType = @"CPTableViewTestDragType"; } else { - var destIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(row, [sourceIndexes count])]; - var sourceObjects = [sourceDataSet objectsAtIndexes:sourceIndexes]; + var destIndexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(row, [sourceIndexes count])], + sourceObjects = [sourceDataSet objectsAtIndexes:sourceIndexes]; [destinationDataSet insertObjects:sourceObjects atIndexes:destIndexes]; [destinationTable reloadData]; From 31ab70d6fca4c1a75e9c4e92ebcef99fc26c2d8f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 1 Aug 2012 18:58:35 +0100 Subject: [PATCH 07/17] Refs #1530. Fixed: table views could not be interacted with if they couldn't become the first responder. --- AppKit/CPTableView.j | 7 +-- Tests/AppKit/CPTableViewTest.j | 48 ++++++++++++++----- .../Manual/TableTest/OldTest/AppController.j | 26 ++++++++-- 3 files changed, 59 insertions(+), 22 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 61045d64e..8d8361921 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -4037,8 +4037,8 @@ Your delegate can implement this method to avoid subclassing the tableview to ad */ - (BOOL)startTrackingAt:(CGPoint)aPoint { - if (![[self window] makeFirstResponder:self]) - return NO; + // Try to become the first responder, but if we can't, that's okay. + [[self window] makeFirstResponder:self]; var row = [self rowAtPoint:aPoint]; @@ -4189,9 +4189,6 @@ Your delegate can implement this method to avoid subclassing the tableview to ad */ - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp { - if ([[self window] firstResponder] !== self) - return; - _isSelectingSession = NO; var CLICK_TIME_DELTA = 1000, diff --git a/Tests/AppKit/CPTableViewTest.j b/Tests/AppKit/CPTableViewTest.j index e07a63664..a65de663f 100644 --- a/Tests/AppKit/CPTableViewTest.j +++ b/Tests/AppKit/CPTableViewTest.j @@ -4,6 +4,7 @@ @implementation CPTableViewTest : OJTestCase { + CPWindow theWindow; CPTableView tableView; CPTableColumn tableColumn; @@ -15,19 +16,21 @@ - (void)setUp { // setup a reasonable table - tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) + styleMask:CPWindowNotSizable]; + + tableView = [[FirstResponderConfigurableTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; tableColumn = [[CPTableColumn alloc] initWithIdentifier:@"Foo"]; + tableView.acceptsFirstResponder = YES; [tableView addTableColumn:tableColumn]; + + [[theWindow contentView] addSubview:tableView]; } - (void)testDoubleAction { doubleActionReceived = NO; - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) - styleMask:CPWindowNotSizable]; - [[theWindow contentView] addSubview:tableView]; - [tableView setTarget:self]; [tableView setDoubleAction:@selector(doubleAction:)]; @@ -44,6 +47,20 @@ [tableView trackMouse:dblClkUp]; [self assertTrue:doubleActionReceived]; + + // The event should also work even if the table is not the first responder. + tableView.acceptsFirstResponder = NO; + [theWindow makeFirstResponder:nil]; + + doubleActionReceived = NO; + + [[CPApplication sharedApplication] sendEvent:dblClkDown]; + [tableView trackMouse:dblClkDown]; + + [[CPApplication sharedApplication] sendEvent:dblClkUp]; + [tableView trackMouse:dblClkUp]; + + [self assertTrue:doubleActionReceived]; } - (void)doubleAction:(id)sender @@ -124,11 +141,6 @@ */ - (void)testEditCell { - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 200, 150) - styleMask:CPWindowNotSizable]; - - [[theWindow contentView] addSubview:tableView]; - var dataSource = [TestDataSource new]; [dataSource setTableEntries:["A", "B", "C"]]; @@ -230,9 +242,7 @@ - (void)testContentBinding { - var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0, 0, 200, 150) - styleMask:CPWindowNotSizable], - contentBindingTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], + var contentBindingTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)], tableColumn = [[CPTableColumn alloc] initWithIdentifier:@"A"], delegate = [ContentBindingTableDelegate new]; @@ -259,6 +269,18 @@ @end +@implementation FirstResponderConfigurableTableView : CPTableView +{ + BOOL acceptsFirstResponder; +} + +- (BOOL)acceptsFirstResponder +{ + return acceptsFirstResponder; +} + +@end + @implementation TestDataSource : CPObject { CPArray tableEntries @accessors; diff --git a/Tests/Manual/TableTest/OldTest/AppController.j b/Tests/Manual/TableTest/OldTest/AppController.j index a1ba38639..901a9bafd 100644 --- a/Tests/Manual/TableTest/OldTest/AppController.j +++ b/Tests/Manual/TableTest/OldTest/AppController.j @@ -10,6 +10,7 @@ tableTestDragType = @"CPTableViewTestDragType"; CPImage iconImage; CPArray dataSet1; CPArray dataSet2; + CPArray dataSet3; CPTableColumn randomColumn; } @@ -28,9 +29,15 @@ tableTestDragType = @"CPTableViewTestDragType"; } var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(50,50,700,500) styleMask:CPClosableWindowMask], - contentView = [theWindow contentView]; + contentView = [theWindow contentView], + label = [CPTextField new]; - tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)]; + [label setStringValue:@"This table refuses to become the first responder but can still be interacted with."]; + [label sizeToFit]; + [label setFrameOrigin:CGPointMake(200, 10)] + [contentView addSubview:label]; + + tableView = [[CUTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)]; [tableView setAllowsMultipleSelection:YES]; [tableView setAllowsColumnSelection:YES]; @@ -172,7 +179,6 @@ tableTestDragType = @"CPTableViewTestDragType"; - (void)newWindow { - var window2 = [[CPWindow alloc] initWithContentRect:CGRectMake(450, 50, 500, 400) styleMask:CPTitledWindowMask | CPResizableWindowMask]; tableView2 = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)]; @@ -186,7 +192,6 @@ tableTestDragType = @"CPTableViewTestDragType"; [tableView2 setDelegate:self]; [tableView2 setDataSource:self]; - var checkBox = [[CPCheckBox alloc] initWithFrame:CGRectMake(5,3,24,24)], checkBoxColumn = [[CPTableColumn alloc] initWithIdentifier:@"checkBox"]; [checkBoxColumn setDataView:checkBox]; @@ -475,3 +480,16 @@ tableTestDragType = @"CPTableViewTestDragType"; } @end + + +@implementation CUTableView : CPTableView +{ + +} + +- (BOOL)acceptsFirstResponder +{ + return NO; +} + +@end From 90ae5766e646f5a9daafcc8ddca568372dc263ca Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 1 Aug 2012 19:18:40 +0100 Subject: [PATCH 08/17] Fixed: token fields would sometimes unexpectedly steal first responder status. If an autocomplete choice was made followed by immediately focusing on another control, the token field would reclaim first responder status a moment later. --- AppKit/_CPAutocompleteMenu.j | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/AppKit/_CPAutocompleteMenu.j b/AppKit/_CPAutocompleteMenu.j index a79c1ae80..78d1be533 100644 --- a/AppKit/_CPAutocompleteMenu.j +++ b/AppKit/_CPAutocompleteMenu.j @@ -65,7 +65,7 @@ var _CPAutocompleteMenuMaximumHeight = 307; [scrollView setHasHorizontalScroller:NO]; [contentView addSubview:scrollView]; - tableView = [[CPTableView alloc] initWithFrame:CPRectMakeZero()]; + tableView = [[_CPNonFirstResponderTableView alloc] initWithFrame:CPRectMakeZero()]; var tableColumn = [CPTableColumn new]; [tableColumn setResizingMask:CPTableColumnAutoresizingMask]; @@ -251,14 +251,14 @@ var _CPAutocompleteMenuMaximumHeight = 307; return [contentArray objectAtIndex:row]; } -- (void)tableViewSelectionDidChange:(CPNotification)notification +@end + + +@implementation _CPNonFirstResponderTableView : CPTableView + +- (BOOL)acceptsFirstResponder { - // FIXME - // make sure a mouse click in the tableview doesn't steal first responder state - window.setTimeout(function() - { - [[textField window] makeFirstResponder:textField]; - }, 2.0); + return NO; } @end From 41783e87a31997eda2a4f9cb6fdbd4c17bdf243f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Wed, 1 Aug 2012 21:12:53 +0100 Subject: [PATCH 09/17] Fixed: in recent builds token field text didn't align. Text inside of tokens appeared 1 px higher than text typed in the text field area. --- AppKit/Themes/Aristo/ThemeDescriptors.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index e1652f4f3..094be44ad 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -1089,7 +1089,7 @@ var themedButtonValues = nil, [@"text-color", textHighlightedColor, CPThemeStateHighlighted], [@"bezel-inset", CGInsetMakeZero(), CPThemeStateBezeled], - [@"content-inset", CGInsetMake(1.0, 22.0, 3.0, 15.0), CPThemeStateBezeled], + [@"content-inset", CGInsetMake(2.0, 22.0, 2.0, 15.0), CPThemeStateBezeled], // Minimum height == maximum height since tokens are fixed height. [@"min-size", CGSizeMake(0.0, 19.0)], From 26c26914dab2acb8602095cbbf87d1b3896b4742 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 00:38:21 +0100 Subject: [PATCH 10/17] Fixed: token field scrolling away from selected token. Sometimes clicking a token would cause the token field to scroll to some other spot. This appears to have been caused by the inactive input element gaining focus. We no longer need the input element for keyboard navigation so we can hide it entirely when it's not used to input a new token. Also, avoid focusing the input element needlessly. --- AppKit/CPTokenField.j | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 7791be27a..82f99f04a 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -1074,8 +1074,15 @@ var CPScrollDestinationNone = 0, if (isEditing && _selectedRange.length) { _inputFrame = nil; - [self _inputElement].style.left = "-10000px"; - [self _inputElement].focus(); + var inputElement = [self _inputElement]; + inputElement.style.display = "none"; + } + else if (isEditing) + { + var inputElement = [self _inputElement]; + inputElement.style.display = "block"; + if (document.focusedElement !== inputElement) + inputElement.focus(); } // Trim off any excess height downwards. From 9768ea4af96692f7d7f099029cbf9e53afe17d91 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 00:44:58 +0100 Subject: [PATCH 11/17] Fixed: multiple rows of tokens in token fields wouldn't scroll right. In recent versions, moving the cursor to a new row of tokens would place the scroll point somewhere halfway between the two rows of tokens. --- AppKit/CPTokenField.j | 17 ++++++++++------- AppKit/Themes/Aristo/ThemeDescriptors.j | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 82f99f04a..5e7b9e564 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -1008,8 +1008,9 @@ var CPScrollDestinationNone = 0, r.origin.y = offset.y; // Make sure the frame fits. - if (_CGRectGetHeight([contentView bounds]) < offset.y + height) - [contentView setFrame:_CGRectMake(0, 0, _CGRectGetWidth([_tokenScrollView bounds]), offset.y + height)]; + var scrollHeight = offset.y + tokenHeight + CEIL(spaceBetweenTokens.height / 2.0); + if (_CGRectGetHeight([contentView bounds]) < scrollHeight) + [contentView setFrameSize:_CGSizeMake(_CGRectGetWidth([_tokenScrollView bounds]), scrollHeight)]; offset.x += width + spaceBetweenTokens.width; @@ -1033,6 +1034,7 @@ var CPScrollDestinationNone = 0, } _inputFrame = fitAndFrame(textWidth, tokenHeight); + _inputFrame.size.height = lineHeight; element.style.left = (_inputFrame.origin.x + editorInset.left) + "px"; @@ -1042,7 +1044,7 @@ var CPScrollDestinationNone = 0, // When editing, always scroll to the cursor. if (_selectedRange.length == 0) - [[_tokenScrollView documentView] scrollRectToVisible:_inputFrame]; + [[_tokenScrollView documentView] scrollPoint:_CGPointMake(0, _inputFrame.origin.y)]; }; for (var i = 0, count = [tokens count]; i < count; i++) @@ -1085,9 +1087,10 @@ var CPScrollDestinationNone = 0, inputElement.focus(); } - // Trim off any excess height downwards. - if (_CGRectGetHeight([contentView bounds]) > offset.y + tokenHeight) - [contentView setFrame:_CGRectMake(0, 0, _CGRectGetWidth([_tokenScrollView bounds]), offset.y + tokenHeight)]; + // Trim off any excess height downwards (in case we shrank). + var scrollHeight = offset.y + tokenHeight + CEIL(spaceBetweenTokens.height / 2.0); + if (_CGRectGetHeight([contentView bounds]) > scrollHeight) + [contentView setFrameSize:_CGSizeMake(_CGRectGetWidth([_tokenScrollView bounds]), scrollHeight)]; if (_shouldScrollTo !== CPScrollDestinationNone) { @@ -1112,7 +1115,7 @@ var CPScrollDestinationNone = 0, if (!aToken) return; - return [[_tokenScrollView documentView] scrollRectToVisible:[aToken frame]]; + return [[_tokenScrollView documentView] scrollPoint:_CGPointMake(0, [aToken frameOrigin].y)]; } @end diff --git a/AppKit/Themes/Aristo/ThemeDescriptors.j b/AppKit/Themes/Aristo/ThemeDescriptors.j index 094be44ad..d5f368fbc 100755 --- a/AppKit/Themes/Aristo/ThemeDescriptors.j +++ b/AppKit/Themes/Aristo/ThemeDescriptors.j @@ -1031,13 +1031,13 @@ var themedButtonValues = nil, [@"editor-inset", CGInsetMake(2.0, 0.0, 0.0, 0.0)], // Non-bezeled token field with tokens - [@"content-inset", CGInsetMake(5.0, 8.0, 4.0, 8.0)], + [@"content-inset", CGInsetMake(6.0, 8.0, 4.0, 8.0)], // Non-bezeled token field with no tokens [@"content-inset", CGInsetMake(7.0, 8.0, 6.0, 8.0), CPTextFieldStatePlaceholder], // Bezeled token field with tokens - [@"content-inset", CGInsetMake(6.0, 8.0, 2.0, 8.0), CPThemeStateBezeled], + [@"content-inset", CGInsetMake(6.0, 5.0, 4.0, 5.0), CPThemeStateBezeled], // Bezeled token field with no tokens [@"content-inset", CGInsetMake(8.0, 8.0, 7.0, 8.0), CPThemeStateBezeled | CPTextFieldStatePlaceholder] From f06be56fa3f85f6f8e0903dcabd45d83138f9949 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 00:45:33 +0100 Subject: [PATCH 12/17] Fixed: accidental global. --- AppKit/_CPPopUpList.j | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AppKit/_CPPopUpList.j b/AppKit/_CPPopUpList.j index 20ebac313..10f66136f 100644 --- a/AppKit/_CPPopUpList.j +++ b/AppKit/_CPPopUpList.j @@ -104,7 +104,7 @@ var ListColumnIdentifier = @"1"; _tableView = [self makeTableView]; // Start with a default size, we will resize it later - frame = CGRectMake(0, 0, 200, 200); + var frame = CGRectMake(0, 0, 200, 200); _tableColumn = [[CPTableColumn alloc] initWithIdentifier:ListColumnIdentifier]; [_tableColumn setWidth:CGRectGetWidth(frame) - [CPScroller scrollerWidth]]; @@ -656,6 +656,7 @@ var ListColumnIdentifier = @"1"; else return YES; } + #pragma mark Internal Helpers /*! @ignore */ From 1fb09dcfae42a595001d4be8d4abd89b78d52c88 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 00:53:30 +0100 Subject: [PATCH 13/17] Fix typo. --- AppKit/CPTokenField.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index 5e7b9e564..8f45054e1 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -1083,7 +1083,7 @@ var CPScrollDestinationNone = 0, { var inputElement = [self _inputElement]; inputElement.style.display = "block"; - if (document.focusedElement !== inputElement) + if (document.activeElement !== inputElement) inputElement.focus(); } From d3b38ac5e8d2e6234b555a69ab2cca950b26eb5c Mon Sep 17 00:00:00 2001 From: Ilya Kulakov Date: Tue, 31 Jul 2012 23:37:51 +0700 Subject: [PATCH 14/17] Add +[CPEvent modifierFlags]. --- AppKit/CPApplication.j | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index f92a27412..e55592577 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -33,7 +33,8 @@ var CPMainCibFile = @"CPMainCibFile", - CPMainCibFileHumanFriendly = @"Main cib file base name"; + CPMainCibFileHumanFriendly = @"Main cib file base name", + CPEventModifierFlags = 0; CPApp = nil; @@ -575,6 +576,7 @@ CPRunContinuesResponse = -1002; - (void)sendEvent:(CPEvent)anEvent { _currentEvent = anEvent; + CPEventModifierFlags = [anEvent modifierFlags]; #if PLATFORM(DOM) var willPropagate = [[[anEvent window] platformWindow] _willPropagateCurrentDOMEvent]; @@ -1379,3 +1381,16 @@ var _CPAppBootstrapperActions = nil; } @end + + +@implementation CPEvent (CPApplicationModifierFlags) + +/*! + Returns the currently pressed modifier flags. +*/ ++ (unsigned)modifierFlags +{ + return CPEventModifierFlags; +} + +@end From 1ccd89ddd893fecd45f640dfeccc3b960674714e Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 15:44:19 +0100 Subject: [PATCH 15/17] Refs #1640. Unit test. --- Tests/AppKit/CPEventTest.j | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Tests/AppKit/CPEventTest.j b/Tests/AppKit/CPEventTest.j index 160024ad2..02981fd3d 100644 --- a/Tests/AppKit/CPEventTest.j +++ b/Tests/AppKit/CPEventTest.j @@ -1,9 +1,16 @@ +@import @import @implementation CPEventTest : OJTestCase { } +- (void)setUp +{ + // CPApplication must be initialised for some event handling to work. + [CPApplication sharedApplication]; +} + /*! This test isn't very useful but it checks for any trouble related to issue #1202. */ @@ -16,4 +23,20 @@ [self assert:0 equals:[anEvent deltaZ] message:"default event delta Z should be 0"]; } -@end \ No newline at end of file +- (void)testModifierFlags +{ + [self assert:0 equals:[CPEvent modifierFlags] message:@"no modifier flags active in a newly started app"]; + + var anEvent = [CPEvent keyEventWithType:CPKeyDown location:CGPointMakeZero() modifierFlags:CPShiftKeyMask timestamp:0 windowNumber:0 context:nil characters:"A" charactersIgnoringModifiers:"a" isARepeat:NO keyCode:0]; + [CPApp sendEvent:anEvent]; + + [self assert:CPShiftKeyMask equals:[CPEvent modifierFlags] message:@"shift key pressed"]; + + // When the key up event is sent the modifier flags are cleared. + anEvent = [CPEvent keyEventWithType:CPKeyUp location:CGPointMakeZero() modifierFlags:0 timestamp:0 windowNumber:0 context:nil characters:"A" charactersIgnoringModifiers:"a" isARepeat:NO keyCode:0]; + [CPApp sendEvent:anEvent]; + + [self assert:0 equals:[CPEvent modifierFlags] message:@"shift key released"]; +} + +@end From 6b660a0c76f9a6f701ccb0ea92d1f2c8d8117ba7 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 15:53:04 +0100 Subject: [PATCH 16/17] Fixed: CPEvent data1 and data2 weren't stored right. They were stored in globals instead of ivars, allowing only one data1 or data2 in the whole app. --- AppKit/CPEvent.j | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/AppKit/CPEvent.j b/AppKit/CPEvent.j index a5fe949bd..2d3c3cf49 100644 --- a/AppKit/CPEvent.j +++ b/AppKit/CPEvent.j @@ -204,6 +204,8 @@ var _CPEventPeriodicEventPeriod = 0, BOOL _isARepeat; unsigned _keyCode; DOMEvent _DOMEvent; + int _data1; + int _data2; float _deltaX; float _deltaY; @@ -517,6 +519,16 @@ var _CPEventPeriodicEventPeriod = 0, return _DOMEvent; } +- (int)data1 +{ + return _data1; +} + +- (int)data2 +{ + return _data2; +} + // Getting Scroll Wheel Event Information /*! Returns the change in the x-axis for a mouse event. From b4cfa8cefbeb6643e89d1140c02e530036b0494f Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 2 Aug 2012 15:53:27 +0100 Subject: [PATCH 17/17] CPEvent description. --- AppKit/CPEvent.j | 23 +++++++++++++++++++++++ Tests/AppKit/CPEventTest.j | 15 +++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/AppKit/CPEvent.j b/AppKit/CPEvent.j index 2d3c3cf49..543dcaadd 100644 --- a/AppKit/CPEvent.j +++ b/AppKit/CPEvent.j @@ -642,6 +642,29 @@ var _CPEventPeriodicEventPeriod = 0, _CPEventPeriodicEventTimer = nil; } +- (CPString)description +{ + switch (_type) + { + case CPKeyDown: + case CPKeyUp: + case CPFlagsChanged: + return [CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ chars=\"%@\" unmodchars=\"%@\" repeat=%d keyCode=%d", _type, CPStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _characters, _charactersIgnoringModifiers, _isARepeat, _keyCode]; + case CPLeftMouseDown: + case CPLeftMouseUp: + case CPRightMouseDown: + case CPRightMouseUp: + case CPMouseMoved: + case CPLeftMouseDragged: + case CPRightMouseDragged: + case CPMouseEntered: + case CPMouseExited: + return [CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ evNum=%d click=%d buttonNumber=%d pressure=%f", _type, CPStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _eventNumber, _clickCount, [self buttonNumber], _pressure]; + default: + return [CPString stringWithFormat:@"CPEvent: type=%d loc=%@ time=%.1f flags=0x%X win=%@ winNum=%d ctxt=%@ subtype=%d data1=%d data2=%d", _type, CPStringFromPoint(_location), _timestamp, _modifierFlags, _window, _windowNumber, _context, _subtype, _data1, _data2]; + } +} + @end function _CPEventFirePeriodEvent() diff --git a/Tests/AppKit/CPEventTest.j b/Tests/AppKit/CPEventTest.j index 02981fd3d..0313a7ba4 100644 --- a/Tests/AppKit/CPEventTest.j +++ b/Tests/AppKit/CPEventTest.j @@ -23,6 +23,21 @@ [self assert:0 equals:[anEvent deltaZ] message:"default event delta Z should be 0"]; } +- (void)testDescription +{ + var anEvent = [CPEvent mouseEventWithType:CPLeftMouseUp location:CGPointMake(50, 50) modifierFlags:CPShiftKeyMask + timestamp:400.5 windowNumber:300 context:nil eventNumber:0 clickCount:2 pressure:0.5]; + [self assert:@"CPEvent: type=2 loc={50, 50} time=400.5 flags=0x20000 win=undefined winNum=0 ctxt=null evNum=0 click=2 buttonNumber=0 pressure=0.5" equals:[anEvent description]]; + + anEvent = [CPEvent keyEventWithType:CPKeyDown location:CGPointMakeZero() modifierFlags:CPShiftKeyMask | CPCommandKeyMask timestamp:12345.6 windowNumber:10 context:nil characters:"X" charactersIgnoringModifiers:"x" isARepeat:NO keyCode:10]; + + [self assert:@"CPEvent: type=10 loc={0, 0} time=12345.6 flags=0x120000 win=null winNum=10 ctxt=null chars=\"X\" unmodchars=\"x\" repeat=0 keyCode=10" equals:[anEvent description]]; + + anEvent = [CPEvent otherEventWithType:CPApplicationDefined location:CGPointMakeZero() modifierFlags:0 timestamp:500.5 windowNumber:2 context:nil subtype:5 data1:15 data2:25]; + + [self assert:@"CPEvent: type=15 loc={0, 0} time=500.5 flags=0x0 win=null winNum=0 ctxt=null subtype=5 data1=15 data2=25" equals:[anEvent description]]; +} + - (void)testModifierFlags { [self assert:0 equals:[CPEvent modifierFlags] message:@"no modifier flags active in a newly started app"];