mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-12 01:38:59 +00:00
Merge branch 'master' into slevenbits
This commit is contained in:
commit
10f6c8e8f6
3 files changed
+57
-7
No files matched your search
@@ -72,6 +72,7 @@ CPInputSetFontOutsideOfDOM = 1 << 28;
|
||||
|
||||
// Input elements have 1 px of extra padding on the left regardless of padding setting.
|
||||
CPInput1PxLeftPadding = 1 << 29;
|
||||
CPInputOnInputEventFeature = 1 << 30;
|
||||
|
||||
var USER_AGENT = "",
|
||||
PLATFORM_ENGINE = CPUnknownBrowserEngine,
|
||||
@@ -202,6 +203,16 @@ if (typeof document != "undefined")
|
||||
PLATFORM_FEATURES |= CPJavaScriptInnerTextFeature;
|
||||
else if (DOMElement.textContent != undefined)
|
||||
PLATFORM_FEATURES |= CPJavaScriptTextContentFeature;
|
||||
|
||||
var DOMInputElement = document.createElement("input");
|
||||
if ("oninput" in DOMInputElement)
|
||||
PLATFORM_FEATURES |= CPInputOnInputEventFeature;
|
||||
else
|
||||
{
|
||||
DOMInputElement.setAttribute("oninput", "return;");
|
||||
if (typeof DOMInputElement.oninput === "function")
|
||||
PLATFORM_FEATURES |= CPInputOnInputEventFeature;
|
||||
}
|
||||
}
|
||||
|
||||
function CPFeatureIsCompatible(aFeature)
|
||||
|
||||
+25
-3
@@ -46,7 +46,8 @@ var CPTextFieldDOMInputElement = nil,
|
||||
CPTextFieldInputIsActive = NO,
|
||||
CPTextFieldCachedSelectStartFunction = nil,
|
||||
CPTextFieldCachedDragFunction = nil,
|
||||
CPTextFieldBlurFunction = nil;
|
||||
CPTextFieldBlurFunction = nil,
|
||||
CPTextFieldInputFunction = nil;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -211,6 +212,25 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
};
|
||||
|
||||
if (CPFeatureIsCompatible(CPInputOnInputEventFeature))
|
||||
{
|
||||
CPTextFieldInputFunction = function(anEvent)
|
||||
{
|
||||
if (!CPTextFieldInputOwner)
|
||||
return;
|
||||
|
||||
var cappEvent = [CPEvent keyEventWithType:CPKeyUp location:_CGPointMakeZero() modifierFlags:0
|
||||
timestamp:[CPEvent currentTimestamp] windowNumber:[[CPApp keyWindow] windowNumber] context:nil
|
||||
characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:nil];
|
||||
|
||||
[CPTextFieldInputOwner keyUp:cappEvent];
|
||||
|
||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||
}
|
||||
|
||||
CPTextFieldDOMInputElement.oninput = CPTextFieldInputFunction;
|
||||
}
|
||||
|
||||
//FIXME make this not onblur
|
||||
CPTextFieldDOMInputElement.onblur = CPTextFieldBlurFunction;
|
||||
|
||||
@@ -1182,7 +1202,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
[self copy:sender];
|
||||
[self deleteBackward:sender];
|
||||
}
|
||||
else
|
||||
// If we don't have an oninput listener, we won't detect the change made by the cut and need to fake a key up "soon".
|
||||
else if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
|
||||
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
|
||||
}
|
||||
|
||||
@@ -1204,7 +1225,8 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
||||
[self setStringValue:newValue];
|
||||
[self setSelectedRange:CPMakeRange(selectedRange.location + pasteString.length, 0)];
|
||||
}
|
||||
else
|
||||
// If we don't have an oninput listener, we won't detect the change made by the cut and need to fake a key up "soon".
|
||||
else if (!CPFeatureIsCompatible(CPInputOnInputEventFeature))
|
||||
[CPTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(keyUp:) userInfo:nil repeats:NO];
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
[contentView addSubview:shadowLabel];
|
||||
[contentView addSubview:championOfLightLabel];
|
||||
|
||||
var jumpLabel = [CPTextField labelWithTitle:@"The text of these text fields should not move when a field becomes the first responder."];
|
||||
var jumpLabel = [CPTextField labelWithTitle:@"The text of these text fields should not move ('jump') when a field becomes the first responder. Labels on the right should replicate the input."];
|
||||
|
||||
[jumpLabel sizeToFit];
|
||||
[jumpLabel setFrameOrigin:CGPointMake(15, 150)];
|
||||
@@ -63,15 +63,24 @@
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
var size = 10 + 3 * i,
|
||||
textField = [CPTextField textFieldWithStringValue:@"Size " + size placeholder:@"Size " + size width:200];
|
||||
textField = [CPTextField textFieldWithStringValue:@"Size " + size placeholder:@"Size " + size width:200],
|
||||
echoField = [CPTextField labelWithTitle:""];
|
||||
|
||||
[textField setFont:[CPFont systemFontOfSize:size]];
|
||||
[textField sizeToFit];
|
||||
[textField setFrameOrigin:CGPointMake(15, y)];
|
||||
textField.echoField = echoField;
|
||||
[contentView addSubview:textField];
|
||||
|
||||
[echoField setFont:[CPFont systemFontOfSize:size]];
|
||||
[echoField setStringValue:[textField stringValue]];
|
||||
[echoField sizeToFit];
|
||||
[echoField setFrameOrigin:CGPointMake(CGRectGetMaxX([textField frame]) + 15, CGRectGetMidY([textField frame]) - CGRectGetHeight([echoField frame]) / 2.0)];
|
||||
[contentView addSubview:echoField];
|
||||
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:CPControlTextDidChangeNotification object:textField];
|
||||
|
||||
y = CGRectGetMaxY([textField frame]) + 6;
|
||||
|
||||
[contentView addSubview:textField];
|
||||
}
|
||||
|
||||
[theWindow orderFront:self];
|
||||
@@ -111,4 +120,12 @@
|
||||
[sender setEditable:NO];
|
||||
}
|
||||
|
||||
- (void)textDidChange:(CPNotification)aNotification
|
||||
{
|
||||
var changedField = [aNotification object];
|
||||
|
||||
[changedField.echoField setStringValue:[changedField stringValue]];
|
||||
[changedField.echoField sizeToFit];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user