#405: enable for input, min/max support, add second date field to widget

This commit is contained in:
Cameron Kaiser 2018-06-25 20:51:38 -07:00
parent 2f7aef6681
commit f89941f138
3 changed files with 185 additions and 58 deletions

View File

@ -638,6 +638,20 @@ HTMLInputElement::InitDatePicker()
nsresult rv = datePicker->Init(win, EmptyString()); // title NYI nsresult rv = datePicker->Init(win, EmptyString()); // title NYI
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = datePicker->SetDefaultDate(initialValue); rv = datePicker->SetDefaultDate(initialValue);
NS_ENSURE_SUCCESS(rv, rv);
if (HasAttr(kNameSpaceID_None, nsGkAtoms::min)) {
nsAutoString minStr;
GetAttr(kNameSpaceID_None, nsGkAtoms::min, minStr);
rv = datePicker->SetMinDate(minStr);
NS_ENSURE_SUCCESS(rv, rv);
}
if (HasAttr(kNameSpaceID_None, nsGkAtoms::max)) {
nsAutoString maxStr;
GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr);
rv = datePicker->SetMaxDate(maxStr);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIDatePickerShownCallback> callback = nsCOMPtr<nsIDatePickerShownCallback> callback =
new nsDatePickerShownCallback(this, datePicker); new nsDatePickerShownCallback(this, datePicker);
@ -2279,10 +2293,12 @@ HTMLInputElement::MozSetFileNameArray(const char16_t** aFileNames, uint32_t aLen
bool bool
HTMLInputElement::MozIsTextField(bool aExcludePassword) HTMLInputElement::MozIsTextField(bool aExcludePassword)
{ {
/*
// TODO: temporary until bug 773205 is fixed. // TODO: temporary until bug 773205 is fixed.
if (IsExperimentalMobileType(mType)) { if (IsExperimentalMobileType(mType)) {
return false; return false;
} }
*/
return IsSingleLineTextControl(aExcludePassword); return IsSingleLineTextControl(aExcludePassword);
} }
@ -4824,8 +4840,8 @@ HTMLInputElement::ParseAttribute(int32_t aNamespaceID,
bool success = aResult.ParseEnumValue(aValue, kInputTypeTable, false); bool success = aResult.ParseEnumValue(aValue, kInputTypeTable, false);
if (success) { if (success) {
newType = aResult.GetEnumValue(); newType = aResult.GetEnumValue();
if ((IsExperimentalMobileType(newType) && if (/* (IsExperimentalMobileType(newType) &&
!Preferences::GetBool("dom.experimental_forms", false)) || !Preferences::GetBool("dom.experimental_forms", false)) || */
(newType == NS_FORM_INPUT_DATE && (newType == NS_FORM_INPUT_DATE &&
!Preferences::GetBool("tenfourfox.dom.forms.date", false)) || !Preferences::GetBool("tenfourfox.dom.forms.date", false)) ||
(newType == NS_FORM_INPUT_TIME && (newType == NS_FORM_INPUT_TIME &&
@ -6328,10 +6344,12 @@ HTMLInputElement::PlaceholderApplies() const
bool bool
HTMLInputElement::DoesPatternApply() const HTMLInputElement::DoesPatternApply() const
{ {
/*
// TODO: temporary until bug 773205 is fixed. // TODO: temporary until bug 773205 is fixed.
if (IsExperimentalMobileType(mType)) { if (IsExperimentalMobileType(mType)) {
return false; return false;
} }
*/
return IsSingleLineTextControl(false); return IsSingleLineTextControl(false);
} }

View File

@ -41,7 +41,9 @@ protected:
bool mHasDefault; bool mHasDefault;
nsString mDefault; nsString mDefault;
nsString mMinDate; nsString mMinDate;
bool mHasMin;
nsString mMaxDate; nsString mMaxDate;
bool mHasMax;
}; };
#endif // nsDatePicker_h_ #endif // nsDatePicker_h_

View File

@ -28,37 +28,76 @@
- (id)buildAlertStyle:(int)fp8 title:(id)fp12 message:(id)fp16 first:(id)fp20 second:(id)fp24 third:(id)fp28 oldStyle:(BOOL)fp32 args:(char *)fp36; - (id)buildAlertStyle:(int)fp8 title:(id)fp12 message:(id)fp16 first:(id)fp20 second:(id)fp24 third:(id)fp28 oldStyle:(BOOL)fp32 args:(char *)fp36;
@end @end
////// NSPopUpDatePicker @class NSDoubleDatePicker; // forward declaration
@interface NSDoubleDateDelegate : NSObject {
NSDoubleDatePicker *_parentAlert;
NSDatePicker *_source;
}
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell
validateProposedDateValue:(NSDate **)proposedDateValue
timeInterval:(NSTimeInterval *)proposedTimeInterval;
- (void)setParentAlert:(NSDoubleDatePicker *)parentAlert
withSource:(NSDatePicker *)source;
@end
@implementation NSDoubleDateDelegate
- (void)datePickerCell:(NSDatePickerCell *)aDatePickerCell
validateProposedDateValue:(NSDate **)proposedDateValue
timeInterval:(NSTimeInterval *)proposedTimeInterval
{
//NSLog(@"validate");
[_parentAlert onSwitchControl:_source newDate:proposedDateValue];
}
- (void)setParentAlert:(NSDoubleDatePicker *)parentAlert
withSource:(NSDatePicker *)source
{
_parentAlert = parentAlert;
_source = source;
}
@end
////// NSDoubleDatePicker
////// based on NSAlertCheckbox, http://cocoadev.github.io/NSAlertCheckbox/ ////// based on NSAlertCheckbox, http://cocoadev.github.io/NSAlertCheckbox/
@interface NSPopUpDatePicker : NSAlert { @interface NSDoubleDatePicker : NSAlert {
NSDatePicker *_picker; NSDatePicker *_pickertop;
NSDatePicker *_pickerbottom;
NSDoubleDateDelegate *_topdelegate;
NSDoubleDateDelegate *_bottomdelegate;
} }
- (void)dealloc; - (void)dealloc;
- (NSPopUpDatePicker *)datePicker:(NSString *)message - (NSDoubleDatePicker *)datePicker:(NSString *)message
defaultButton:(NSString *)defaultButton defaultButton:(NSString *)defaultButton
alternateButton:(NSString *)alternateButton alternateButton:(NSString *)alternateButton
otherButton:(NSString *)otherButton otherButton:(NSString *)otherButton
informativeTextWithFormat:(NSString *)format; informativeTextWithFormat:(NSString *)format;
- (void)onSwitchControl:(NSDatePicker *)which newDate:(NSDate **)newDate;
- (NSDate *)date; - (NSDate *)date;
- (void)setDate:(NSDate *)date; - (void)setDate:(NSDate *)date;
@end @end
@interface NSPopUpDatePicker(Private) @interface NSDoubleDatePicker(Private)
- (void)_ensureDatePicker; - (void)_ensureDatePickers;
- (void)_addDatePickerToAlert; - (void)_addDatePickersToAlert;
@end @end
@implementation NSPopUpDatePicker @implementation NSDoubleDatePicker
- (void)dealloc - (void)dealloc
{ {
[_picker release]; //NSLog(@"dealloc");
[_pickertop release];
[_pickerbottom release];
[_topdelegate release];
[_bottomdelegate release];
[super dealloc]; [super dealloc];
} }
- (NSPopUpDatePicker *)datePicker:(NSString *)message - (NSDoubleDatePicker *)datePicker:(NSString *)message
defaultButton:(NSString *)defaultButton defaultButton:(NSString *)defaultButton
alternateButton:(NSString *)alternateButton alternateButton:(NSString *)alternateButton
otherButton:(NSString *)otherButton otherButton:(NSString *)otherButton
@ -69,7 +108,7 @@
alternateButton:alternateButton alternateButton:alternateButton
otherButton:otherButton otherButton:otherButton
informativeTextWithFormat:format]; informativeTextWithFormat:format];
return (NSPopUpDatePicker *)alert; return (NSDoubleDatePicker *)alert;
} }
- (id)buildAlertStyle:(int)fp8 - (id)buildAlertStyle:(int)fp8
@ -87,7 +126,7 @@
second:fp24 second:fp24
third:fp28 third:fp28
oldStyle:fp32]; oldStyle:fp32];
[self _addDatePickerToAlert]; [self _addDatePickersToAlert];
return rv; return rv;
} }
@ -108,33 +147,79 @@
third:fp28 third:fp28
oldStyle:fp32 oldStyle:fp32
args:fp36]; args:fp36];
[self _addDatePickerToAlert]; [self _addDatePickersToAlert];
return rv; return rv;
} }
- (void)onSwitchControl:(NSDatePicker *)which newDate:(NSDate **)newDate
{
// Halt the delegate on the one we're setting first.
if (which == _pickertop) {
//NSLog(@"control event: top");
[_pickerbottom setDelegate:nil];
[_pickerbottom setDateValue:*newDate];
[_pickerbottom setDelegate:_bottomdelegate];
} else if (which == _pickerbottom) {
//NSLog(@"control event: bottom");
[_pickertop setDelegate:nil];
[_pickertop setDateValue:*newDate];
[_pickertop setDelegate:_topdelegate];
} else
NSLog(@"wtf");
}
- (NSDate *)date - (NSDate *)date
{ {
[self _ensureDatePicker]; [self _ensureDatePickers];
return [_picker dateValue]; return [_pickertop dateValue];
} }
- (void)setDate:(NSDate *)date - (void)setDate:(NSDate *)date
{ {
[self _ensureDatePicker]; [self _ensureDatePickers];
[_picker setDateValue:date]; [_pickertop setDateValue:date];
[_pickerbottom setDateValue:date];
}
- (void)setMinDate:(NSDate *)date
{
[self _ensureDatePickers];
[_pickertop setMinDate:date];
[_pickerbottom setMinDate:date];
}
- (void)setMaxDate:(NSDate *)date
{
[self _ensureDatePickers];
[_pickertop setMaxDate:date];
[_pickerbottom setMaxDate:date];
} }
@end @end
@implementation NSPopUpDatePicker(Private) @implementation NSDoubleDatePicker(Private)
- (void)_ensureDatePicker - (void)_ensureDatePickers
{ {
if (!_picker) { if (!_pickertop) {
_picker = [[NSDatePicker alloc] initWithFrame:NSMakeRect(10,10,295,154)]; // NSLog(@"picker init");
[_picker setDatePickerStyle:NSClockAndCalendarDatePickerStyle]; _pickertop = [[NSDatePicker alloc] initWithFrame:NSMakeRect(10,10,295,154)];
[_picker setDatePickerElements:NSYearMonthDayDatePickerElementFlag]; [_pickertop setDatePickerStyle:NSClockAndCalendarDatePickerStyle];
[_pickertop setDatePickerElements:NSYearMonthDayDatePickerElementFlag];
_topdelegate = [[NSDoubleDateDelegate alloc] init];
[_topdelegate setParentAlert:self withSource:_pickertop];
[_pickertop setDelegate:_topdelegate];
_pickerbottom = [[NSDatePicker alloc] initWithFrame:NSMakeRect(10,10,295,154)];
[_pickerbottom setDatePickerStyle:NSTextFieldAndStepperDatePickerStyle];
[_pickerbottom setDatePickerElements:NSYearMonthDayDatePickerElementFlag];
_bottomdelegate = [[NSDoubleDateDelegate alloc] init];
[_bottomdelegate setParentAlert:self withSource:_pickerbottom];
[_pickerbottom setDelegate:_bottomdelegate];
} }
} }
- (void)_addDatePickerToAlert
- (void)_addDatePickersToAlert
{ {
NSWindow *window = [self window]; NSWindow *window = [self window];
NSView *content = [window contentView]; NSView *content = [window contentView];
@ -146,7 +231,7 @@
NSTextField *messageText = nil; NSTextField *messageText = nil;
int count = 0; int count = 0;
[self _ensureDatePicker]; [self _ensureDatePickers];
// Find the main text field. // Find the main text field.
while (subview = [en nextObject]) { while (subview = [en nextObject]) {
@ -156,24 +241,35 @@
} }
} }
if (messageText) { if (messageText) {
[content addSubview:_picker]; [content addSubview:_pickertop];
[_picker sizeToFit]; [_pickertop sizeToFit];
[content addSubview:_pickerbottom];
[_pickerbottom sizeToFit];
// Expand the alert window. // Expand the alert window.
NSRect windowFrame = [window frame]; NSRect windowFrame = [window frame];
NSRect pickerFrame = [_picker frame]; NSRect topPickerFrame = [_pickertop frame];
NSRect bottomPickerFrame = [_pickerbottom frame];
windowFrame.size.height += pickerFrame.size.height + padding; windowFrame.size.height += topPickerFrame.size.height + padding +
bottomPickerFrame.size.height + padding;
[window setFrame:windowFrame display:YES]; [window setFrame:windowFrame display:YES];
// Insert the picker below the main text field. // Insert the pickers below the main text field.
pickerFrame.origin.y = [messageText frame].origin.y - topPickerFrame.origin.y = [messageText frame].origin.y -
pickerFrame.size.height - padding; bottomPickerFrame.size.height - padding -
pickerFrame.origin.x = [messageText frame].origin.x; topPickerFrame.size.height - padding;
topPickerFrame.origin.x = [messageText frame].origin.x;
[_picker setFrame:pickerFrame]; bottomPickerFrame.origin.y = topPickerFrame.origin.y +
topPickerFrame.size.height + padding;
bottomPickerFrame.origin.x = topPickerFrame.origin.x;
[_pickertop setFrame:topPickerFrame];
[_pickerbottom setFrame:bottomPickerFrame];
//NSLog(@"Picker installed");
} else } else
fprintf(stderr, "Could not insinuate modal NSDatePicker.\n"); NSLog(@"Couldn't find message text, did not add pickers");
} }
@end @end
@ -215,37 +311,46 @@ int16_t
nsDatePicker::GetDate() nsDatePicker::GetDate()
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
int16_t retVal = returnCancel;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[formatter setDateFormat:@"yyyy-MM-dd"]; [formatter setDateFormat:@"yyyy-MM-dd"];
NSPopUpDatePicker *alert = [NSPopUpDatePicker NSDoubleDatePicker *alert = [NSDoubleDatePicker
alertWithMessageText:@"One" alertWithMessageText:@" "// XXX: localize this eventually
defaultButton:@"OK" defaultButton:nil // "OK"
alternateButton:@"Cancel" alternateButton:nil // "Cancel"
otherButton:nil otherButton:nil // nothin'
informativeTextWithFormat:@"Blah blah"]; informativeTextWithFormat:@""];
if (mHasDefault) { if (mHasDefault) {
NSDate *newDate = [formatter dateFromString:nsCocoaUtils::ToNSString(mDefault)]; NSDate *newDate = [formatter dateFromString:nsCocoaUtils::ToNSString(mDefault)];
[alert setDate:newDate]; if (newDate)
[alert setDate:newDate];
} else } else
[alert setDate:[NSDate date]]; [alert setDate:[NSDate date]];
if (mHasMin) {
NSDate *newDate = [formatter dateFromString:nsCocoaUtils::ToNSString(mMinDate)];
if (newDate)
[alert setMinDate:newDate];
}
if (mHasMax) {
NSDate *newDate = [formatter dateFromString:nsCocoaUtils::ToNSString(mMaxDate)];
if (newDate)
[alert setMaxDate:newDate];
}
nsCocoaUtils::PrepareForNativeAppModalDialog(); nsCocoaUtils::PrepareForNativeAppModalDialog();
int result = [alert runModal]; //[NSApp runModalForWindow:pwin]; int result = [alert runModal];
nsCocoaUtils::CleanUpAfterNativeAppModalDialog(); nsCocoaUtils::CleanUpAfterNativeAppModalDialog();
if (result == NSFileHandlingPanelCancelButton) if (result == NSAlertAlternateReturn) // cancel
return retVal; return returnCancel;
nsCocoaUtils::GetStringForNSString([formatter stringFromDate:[alert date]], nsCocoaUtils::GetStringForNSString([formatter stringFromDate:[alert date]],
mDate); mDate);
return retVal; return returnOK;
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(returnCancel); NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(returnCancel);
} }
// XXX Not used // XXX Not used currently, needs localization
// Sets the dialog title to whatever it should be. If it fails, eh, // Sets the dialog title to whatever it should be. If it fails, eh,
// the OS will provide a sensible default. // the OS will provide a sensible default.
void void
@ -272,6 +377,7 @@ NS_IMETHODIMP nsDatePicker::GetDefaultDate(nsAString& aString)
NS_IMETHODIMP nsDatePicker::SetMinDate(const nsAString& aString) NS_IMETHODIMP nsDatePicker::SetMinDate(const nsAString& aString)
{ {
mHasMin = true;
mMinDate = aString; mMinDate = aString;
return NS_OK; return NS_OK;
} }
@ -283,6 +389,7 @@ NS_IMETHODIMP nsDatePicker::GetMinDate(nsAString& aString)
NS_IMETHODIMP nsDatePicker::SetMaxDate(const nsAString& aString) NS_IMETHODIMP nsDatePicker::SetMaxDate(const nsAString& aString)
{ {
mHasMax = true;
mMaxDate = aString; mMaxDate = aString;
return NS_OK; return NS_OK;
} }