Without this change, text fields with setEditable:NO but setSelectable:YES could not become the first responder, and so would not listen for copy: events.
This change allows selectable fields to become the first responder, taking advantage of the distinction between first responder and first key responder maintained internally in CPTextField - a merely selectable field does not become the first key responder.
Refs #1972.
Previously setObjectValue checked for a formatted value, and then called [self stringValue], which ended up formatting the value again.
Now all of the cases (no formatter, formatter succeeds, formatter fails) are handled explicitly in setObjectValue, eliminating the extra call to the formatter.
Previously, no attempt was made to become/resign first key responder when a CPTextField was unhidden/hidden. This could lead to a case where a hidden CPTextField was made first responder, then unhidden (and have a focus ring), but would not receive key input.
Previously, a case could arise where a text field was set as the initial first responder but during cib loading was not yet assigned to a window. In this case _isWithinUsablePlatformRect would fail.
Now _isWithinUsablePlatformRect checks to make sure the text field has a window.
Without this fix, when text was copied from a CPTextField, the value would be copied into the system clipboard (if possible), but not into the Cappuccino pasteboard. This meant that the text could not be pasted back in Cappuccino using e.g. Edit > Paste from the Cappuccino menu.
This fix ensures the appropriate text is copied both into Cappuccino's pasteboard and the system clipboard (when possible).
This fix switches to full native copy and paste in browsers which support it. This allows copy from anywhere - a collection view, a table view and so on - without the browser greying out the copy menu or beeping.
In the future this can easily be extended to copy and paste images as well.
This change also improves Safari paste support. In recent versions of Safari, pasting from the system clipboard into Cappuccino has been impossible. This remains impossible due to the lack of beforepaste events, but now the code cleanly switches to a Cappuccino-only paste at least.
Previously, when a text field became the key responder, first it was scrolled to visible, then a check was made to see if the text field was completely within the platform window bounds. The scrolling to visible would unfortunately cause problems because of the interaction between the blur handler in text fields and controls that can be clicked without becoming first responder.
This commit completely forbids text fields from becoming first responder if they are not completely within the platform window. That eliminates any possibility of unwanted browser scrolling of the text field.
Previously, Cappuccino was using preprocessor macros internally for the CGPoint/Size/Rect/Inset/Affine functions, as well as for CPRange. These macros had the same name as the corresponding function, but began with _. The functions were actually defined using the macros.
The motivation behind using macros was to increase performance by reducing function calls. However, there were a number of problems with this approach:
- There was an artificial dichotomy between _CG macros and the corresponding CG functions. We never completely replaced CG function calls with _CG macros. In fact, they were often mixed up in the same file. There was an extra burden on the programmer to remember to use the macro instead of the function.
- If a method call was passed as an argument to a macro, performance could actually be significantly *worse* than a function call. For example, _CGGetRectMakeCopy([view frame]) would expand to `{ origin:{ x:[view frame].origin.x, y:[view frame].origin.y }, size:{ width:[view frame].size.width, height:[view frame].size.height } }`. So instead of a single objj_msgSend and a single simple function call, we ended up with 4 objj_msgSend calls, which are way more expensive than simple function calls.
- Because of this expansion problem, to use macros efficiently required us to remember to use variables for all macro parameters. This didn't happen, and shouldn't have to happen.
- Finally, with modern Javascript engines, function call overhead is so small that it really isn't worth using the macros.
This commit eliminates the _CGGeometry, CGAffineTransformation and CPRange macros and replaces them with function calls.
BREAKING CHANGE:
The macros are no longer available. They could only be used with compiled code, but if there is any user code that used them, they will have to be replaced with the corresponding functions.
Previously, there were two instances in which a browser would forcibly scroll a text field into view, out of Cappuccino's control:
- A text field is first responder in the key window, is partially or fully offscreen, and you click somewhere else within the same window. If the target of the click does not accept first responder, the text field is refocused.
- A text field is first responder in a non-key window, is partially or fully offscreen, and you make its window the key window. In that case the text field is made first responder and is focused.
In both cases, focusing the text field causes the browser to scroll the viewport out of Cappuccino's control such that the text field is completely onscreen.
With this commit, before a text field is focused, it is checked to ensure it is completely within the usable content rect of the platform window. If not, it refuses first responder. If the window is becoming key, the first responder is set to nil.
- CPView and subclasses support multiple-value hidden bindings.
- CPControl and subclasses support multiple-value enabled bindings.
- CPWindow and CPBox support multiple-value title with pattern bindings.
- CPButton supports multiple argument + target bindings.
- CPImageView and CPTextField support multiple-value editable bindings.
- CPMenuItem supports multiple-value enabled bindings.
- Fixed bugs in CPObjectController with simple collection operators.
- CPColorWell uses black as the placeholder color.
- Runtime object attributes from a cib are applied as they are read, not deferred.
- NSNumberFormatter now reads the number style from the xib.
- Normalized some parameter names.
- Formatting.
- Test app for all binding types.
- Factored out blur handler from CPTokenField into CPTextField.
- CPTextField will no longer lose focus unnecessarily.
- Changed switch style in CPWindow -sendEvent.
- Added menu bar to KeyViewLoop test app.
- Removed unnecessary code at beginning of CPTextField -becomeFirstResponder that might have been a hack to get around a bug I fixed.
- Fixed race condition in setTimeout closure in CPTextField -becomeFirstResponder.
- CPWindow -setInitialFirstResponder now works reliably and follows Cocoa behavior in that if -makeFirstResponder is called with something other than the window before the window is first shown, it will override the initial first responder.
- Like Cocoa, until the first responder is set during window load, the first responder is the window by default, not the content view.
- Optimized search for any view that has a previous/next key view set.
- Sheets can become key windows again.
- CPWindow -recalculateKeyViewLoop now just marks the loop as dirty, per Cocoa docs.
- CPWindow -autorecalculatesKeyViewLoop now behaves per Cocoa, it only has an effect when views are added or removed.
- If the first responder does not have a valid previous/next key view, it does not resign to nil, per Cocoa behavior.
- Code optimization and cleanup.
- Test app (KeyViewLoopTest) that demonstrates various scenarios.
E.g. in a two window application, if a token field was the first responder and another window was made active and then the original window made active again, the token field would no longer be the first responder.
If the formatter rejected a change and prevented the first responder status from being surrendered, the text field would still stop listening to key window changes and break first responder behaviour when switching between windows.
will not scroll without the NSScrollView knowing about it
Issue #1675 and maybe a little of issue #1301
This fix will not work without pull
request #1678 - Fixed scrollRectToVisible in CPView
We were compensating for a bug in Safari, older versions of Chrome and Firefox in our input placement. But new Chrome and neither IE 8 nor IE 9 needed it which resulted in the text being off in those browsers.
Locking down the line height and vertical alignment explicitly seems to work in Safari 6, Chrome 21, Firefox 14 and IE 8 (although Chrome and IE exhibit some unrelated horizontal jumping.)
Only the first responder of the key window should receive text input. This is important in multi-window apps or windows with sheets.
In the multi window case it should be possible to switch between two windows with first responder text fields and keep right on typing. First responder status should not be lost, but new typing should always go into the first responder text field of the key window.
For sheets, a text field which was active when the sheet opened should not receive input nor look active while the sheet is open.