- Revision
- 266461
- Author
- akeer...@apple.com
- Date
- 2020-09-02 08:35:57 -0700 (Wed, 02 Sep 2020)
Log Message
[macOS] Update date picker when the inner control is edited
https://bugs.webkit.org/show_bug.cgi?id=216004
Reviewed by Wenson Hsieh.
Source/WebCore:
The value of the attached date picker should match the value in the
inner control. In order to achieve this behavior, m_dateTimeChooser
is notified whenever didChangeValueFromControl is called.
Note that the attached date picker's value is not updated on a
programmatic edit (setting input.value), as a sudden change not
triggered by the user would result in a poor user experience.
Test: fast/forms/date/date-editable-components/date-picker-update-on-edit.html
* html/BaseChooserOnlyDateAndTimeInputType.cpp:
(WebCore::BaseChooserOnlyDateAndTimeInputType::didChangeValueFromControl):
Source/WebKit:
* UIProcess/mac/WebDateTimePickerMac.mm:
(WebKit::WebDateTimePickerMac::showDateTimePicker):
If showDateTimePicker is called while a picker is already being
displayed, call updatePicker: rather than showPicker:.
(-[WKDateTimePicker initWithParams:inView:]):
The NSDatePicker and NSDateFormatter should use a UTC timezone.
This is necessary as all double values passed into WKDateTimePicker
are UTC timestamps. This has no effect on the value returned to
the WebProcess on user selection, as a timezone-agnostic format
string is used.
(-[WKDateTimePicker updatePicker:]):
Set the date value of the owned NSDatePicker to the value in the
DateTimeChooserParameters.
Tools:
Added dateTimePickerValue testing hook in order to enable testing the
current value of the presented date picker. The returned value is a
UTC timestamp is milliseconds, matching the date input's valueAsNumber.
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
* TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::dateTimePickerValue const):
* WebKitTestRunner/mac/UIScriptControllerMac.h:
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::dateTimePickerValue const):
LayoutTests:
Added a test to verify that the date picker is updated when the user edits the control.
* fast/forms/date/date-editable-components/date-picker-update-on-edit-expected.txt: Added.
* fast/forms/date/date-editable-components/date-picker-update-on-edit.html: Added.
* resources/ui-helper.js:
(window.UIHelper.dateTimePickerValue):
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (266460 => 266461)
--- trunk/LayoutTests/ChangeLog 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/LayoutTests/ChangeLog 2020-09-02 15:35:57 UTC (rev 266461)
@@ -1,3 +1,17 @@
+2020-09-02 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Update date picker when the inner control is edited
+ https://bugs.webkit.org/show_bug.cgi?id=216004
+
+ Reviewed by Wenson Hsieh.
+
+ Added a test to verify that the date picker is updated when the user edits the control.
+
+ * fast/forms/date/date-editable-components/date-picker-update-on-edit-expected.txt: Added.
+ * fast/forms/date/date-editable-components/date-picker-update-on-edit.html: Added.
+ * resources/ui-helper.js:
+ (window.UIHelper.dateTimePickerValue):
+
2020-09-02 Per Arne Vollan <pvol...@apple.com>
[Win] Update test expectations for failures only seen on one specific bot
Added: trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit-expected.txt (0 => 266461)
--- trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit-expected.txt 2020-09-02 15:35:57 UTC (rev 266461)
@@ -0,0 +1,24 @@
+Tests that a user edit in the control updates the date picker.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Check that picker is displayed
+PASS showingPicker is true
+
+Check initial value
+PASS input.value is "2020-09-16"
+PASS input.valueAsNumber is pickerValue
+
+Check picker value after user edit
+PASS input.value is "2020-03-24"
+PASS input.valueAsNumber is pickerValue
+
+Check picker value after programmatic change
+PASS input.value is "2020-12-30"
+PASS input.valueAsNumber is not pickerValue
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit.html (0 => 266461)
--- trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit.html (rev 0)
+++ trunk/LayoutTests/fast/forms/date/date-editable-components/date-picker-update-on-edit.html 2020-09-02 15:35:57 UTC (rev 266461)
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+
+<input id="input" type="date" value="2020-09-16"/>
+
+<script>
+
+jsTestIsAsync = true;
+
+addEventListener("load", async () => {
+ description("Tests that a user edit in the control updates the date picker.");
+ await UIHelper.activateElementAndWaitForInputSession(input);
+
+ debug("Check that picker is displayed");
+ showingPicker = await UIHelper.isShowingDateTimePicker();
+ shouldBeTrue("showingPicker");
+ debug("");
+
+ debug("Check initial value");
+ pickerValue = await UIHelper.dateTimePickerValue();
+ shouldBeEqualToString("input.value", "2020-09-16");
+ shouldBe("input.valueAsNumber", "pickerValue");
+ debug("");
+
+ debug("Check picker value after user edit");
+ // Ensure we are at the first field of the input.
+ UIHelper.keyDown("leftArrow");
+ UIHelper.keyDown("leftArrow");
+ // Edit month.
+ UIHelper.keyDown("3");
+ UIHelper.keyDown("rightArrow");
+ // Edit day.
+ UIHelper.keyDown("2");
+ UIHelper.keyDown("4");
+ shouldBeEqualToString("input.value", "2020-03-24")
+ pickerValue = await UIHelper.dateTimePickerValue();
+ shouldBe("input.valueAsNumber", "pickerValue");
+ debug("");
+
+ debug("Check picker value after programmatic change");
+ input.value = "2020-12-30";
+ shouldBeEqualToString("input.value", "2020-12-30")
+ pickerValue = await UIHelper.dateTimePickerValue();
+ shouldNotBe("input.valueAsNumber", "pickerValue");
+ debug("");
+
+ finishJSTest();
+});
+</script>
+
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/resources/ui-helper.js (266460 => 266461)
--- trunk/LayoutTests/resources/ui-helper.js 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/LayoutTests/resources/ui-helper.js 2020-09-02 15:35:57 UTC (rev 266461)
@@ -856,6 +856,15 @@
});
}
+ static dateTimePickerValue()
+ {
+ return new Promise(resolve => {
+ testRunner.runUIScript(`(() => {
+ uiController.uiScriptComplete(uiController.dateTimePickerValue);
+ })()`, valueAsString => resolve(parseFloat(valueAsString)));
+ });
+ }
+
static zoomScale()
{
return new Promise(resolve => {
Modified: trunk/Source/WebCore/ChangeLog (266460 => 266461)
--- trunk/Source/WebCore/ChangeLog 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Source/WebCore/ChangeLog 2020-09-02 15:35:57 UTC (rev 266461)
@@ -1,3 +1,23 @@
+2020-09-02 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Update date picker when the inner control is edited
+ https://bugs.webkit.org/show_bug.cgi?id=216004
+
+ Reviewed by Wenson Hsieh.
+
+ The value of the attached date picker should match the value in the
+ inner control. In order to achieve this behavior, m_dateTimeChooser
+ is notified whenever didChangeValueFromControl is called.
+
+ Note that the attached date picker's value is not updated on a
+ programmatic edit (setting input.value), as a sudden change not
+ triggered by the user would result in a poor user experience.
+
+ Test: fast/forms/date/date-editable-components/date-picker-update-on-edit.html
+
+ * html/BaseChooserOnlyDateAndTimeInputType.cpp:
+ (WebCore::BaseChooserOnlyDateAndTimeInputType::didChangeValueFromControl):
+
2020-09-02 Alex Christensen <achristen...@webkit.org>
Align UTF-16 decoder with Chrome, Firefox, and specification
Modified: trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp (266460 => 266461)
--- trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp 2020-09-02 15:35:57 UTC (rev 266461)
@@ -311,6 +311,13 @@
{
String value = sanitizeValue(m_dateTimeEditElement->value());
BaseDateAndTimeInputType::setValue(value, value != element()->value(), DispatchInputAndChangeEvent);
+
+ DateTimeChooserParameters parameters;
+ if (!element()->setupDateTimeChooserParameters(parameters))
+ return;
+
+ if (m_dateTimeChooser)
+ m_dateTimeChooser->showChooser(parameters);
}
AtomString BaseChooserOnlyDateAndTimeInputType::localeIdentifier() const
Modified: trunk/Source/WebKit/ChangeLog (266460 => 266461)
--- trunk/Source/WebKit/ChangeLog 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Source/WebKit/ChangeLog 2020-09-02 15:35:57 UTC (rev 266461)
@@ -1,3 +1,29 @@
+2020-09-02 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Update date picker when the inner control is edited
+ https://bugs.webkit.org/show_bug.cgi?id=216004
+
+ Reviewed by Wenson Hsieh.
+
+ * UIProcess/mac/WebDateTimePickerMac.mm:
+ (WebKit::WebDateTimePickerMac::showDateTimePicker):
+
+ If showDateTimePicker is called while a picker is already being
+ displayed, call updatePicker: rather than showPicker:.
+
+ (-[WKDateTimePicker initWithParams:inView:]):
+
+ The NSDatePicker and NSDateFormatter should use a UTC timezone.
+ This is necessary as all double values passed into WKDateTimePicker
+ are UTC timestamps. This has no effect on the value returned to
+ the WebProcess on user selection, as a timezone-agnostic format
+ string is used.
+
+ (-[WKDateTimePicker updatePicker:]):
+
+ Set the date value of the owned NSDatePicker to the value in the
+ DateTimeChooserParameters.
+
2020-09-01 Hector Lopez <hector_i_lo...@apple.com>
Unreviewed, reverting r266408.
Modified: trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm (266460 => 266461)
--- trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm 2020-09-02 15:35:57 UTC (rev 266461)
@@ -36,11 +36,13 @@
constexpr NSString * kDateFormatString = @"yyyy-MM-dd";
constexpr NSString * kDateTimeFormatString = @"yyyy-MM-dd'T'HH:mm";
constexpr NSString * kDefaultLocaleIdentifier = @"en_US_POSIX";
+constexpr NSString * kDefaultTimeZoneIdentifier = @"UTC";
@interface WKDateTimePicker : NSObject
- (id)initWithParams:(WebCore::DateTimeChooserParameters&&)params inView:(NSView *)view;
- (void)showPicker:(WebKit::WebDateTimePickerMac&)picker;
+- (void)updatePicker:(WebCore::DateTimeChooserParameters&&)params;
- (void)invalidate;
@end
@@ -75,8 +77,10 @@
void WebDateTimePickerMac::showDateTimePicker(WebCore::DateTimeChooserParameters&& params)
{
- if (m_picker)
+ if (m_picker) {
+ [m_picker updatePicker:WTFMove(params)];
return;
+ }
m_picker = adoptNS([[WKDateTimePicker alloc] initWithParams:WTFMove(params) inView:m_view.get().get()]);
[m_picker showPicker:*this];
@@ -163,6 +167,12 @@
windowRect.size.width = kCalendarWidth;
windowRect.size.height = kCalendarHeight;
+ // Use a UTC timezone as all incoming double values are UTC timestamps. This also ensures that
+ // the date value of the NSDatePicker matches the date value returned by _javascript_. The timezone
+ // has no effect on the value returned to the WebProcess, as a timezone-agnostic format string is
+ // used to return the date.
+ NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:kDefaultTimeZoneIdentifier];
+
_enclosingWindow = adoptNS([[WKDateTimePickerWindow alloc] initWithContentRect:NSZeroRect styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskFullSizeContentView) backing:NSBackingStoreBuffered defer:NO]);
[_enclosingWindow setFrame:windowRect display:YES];
@@ -169,6 +179,7 @@
_datePicker = adoptNS([[NSDatePicker alloc] initWithFrame:[_enclosingWindow contentView].bounds]);
[_datePicker setDatePickerStyle:NSDatePickerStyleClockAndCalendar];
[_datePicker setDatePickerElements:NSDatePickerElementFlagYearMonthDay];
+ [_datePicker setTimeZone:timeZone];
[_datePicker setTarget:self];
[_datePicker setAction:@selector(didChooseDate:)];
@@ -176,6 +187,7 @@
_dateFormatter = adoptNS([[NSDateFormatter alloc] init]);
[_dateFormatter setDateFormat:[self dateFormatStringForType:_params.type]];
[_dateFormatter setLocale:englishLocale.get()];
+ [_dateFormatter setTimeZone:timeZone];
NSString *currentDateValueString = _params.currentValue;
if (![currentDateValueString length])
@@ -197,6 +209,17 @@
[[_presentingView window] addChildWindow:_enclosingWindow.get() ordered:NSWindowAbove];
}
+- (void)updatePicker:(WebCore::DateTimeChooserParameters&&)params
+{
+ _params = WTFMove(params);
+
+ NSString *currentDateValueString = _params.currentValue;
+ if (![currentDateValueString length])
+ [_datePicker setDateValue:[NSDate date]];
+ else
+ [_datePicker setDateValue:[_dateFormatter dateFromString:currentDateValueString]];
+}
+
- (void)invalidate
{
[_datePicker removeFromSuperviewWithoutNeedingDisplay];
Modified: trunk/Tools/ChangeLog (266460 => 266461)
--- trunk/Tools/ChangeLog 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Tools/ChangeLog 2020-09-02 15:35:57 UTC (rev 266461)
@@ -1,3 +1,21 @@
+2020-09-02 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Update date picker when the inner control is edited
+ https://bugs.webkit.org/show_bug.cgi?id=216004
+
+ Reviewed by Wenson Hsieh.
+
+ Added dateTimePickerValue testing hook in order to enable testing the
+ current value of the presented date picker. The returned value is a
+ UTC timestamp is milliseconds, matching the date input's valueAsNumber.
+
+ * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+ * TestRunnerShared/UIScriptContext/UIScriptController.h:
+ (WTR::UIScriptController::dateTimePickerValue const):
+ * WebKitTestRunner/mac/UIScriptControllerMac.h:
+ * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+ (WTR::UIScriptControllerMac::dateTimePickerValue const):
+
2020-09-02 Per Arne Vollan <pvol...@apple.com>
[Win] The WPT server is not always starting when running layout tests
Modified: trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (266460 => 266461)
--- trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl 2020-09-02 15:35:57 UTC (rev 266461)
@@ -224,6 +224,7 @@
readonly attribute double timePickerValueMinute;
readonly attribute boolean isShowingDateTimePicker;
+ readonly attribute double dateTimePickerValue;
// <datalist>
readonly attribute boolean isShowingDataListSuggestions;
Modified: trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (266460 => 266461)
--- trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h 2020-09-02 15:35:57 UTC (rev 266461)
@@ -217,6 +217,7 @@
virtual double timePickerValueHour() const { notImplemented(); return -1; }
virtual double timePickerValueMinute() const { notImplemented(); return -1; }
virtual bool isShowingDateTimePicker() const { notImplemented(); return false; }
+ virtual double dateTimePickerValue() const { notImplemented(); return 0; }
virtual bool isShowingDataListSuggestions() const { notImplemented(); return false; }
virtual JSObjectRef calendarType() const { notImplemented(); return nullptr; }
virtual void setDefaultCalendarType(JSStringRef calendarIdentifier, JSStringRef localeIdentifier) { notImplemented(); }
Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h (266460 => 266461)
--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h 2020-09-02 15:35:57 UTC (rev 266461)
@@ -43,6 +43,7 @@
double zoomScale() const override;
void simulateAccessibilitySettingsChangeNotification(JSValueRef) override;
bool isShowingDateTimePicker() const override;
+ double dateTimePickerValue() const override;
bool isShowingDataListSuggestions() const override;
void activateDataListSuggestion(unsigned index, JSValueRef callback) override;
void beginBackSwipe(JSValueRef) override;
Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (266460 => 266461)
--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm 2020-09-02 15:32:44 UTC (rev 266460)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm 2020-09-02 15:35:57 UTC (rev 266461)
@@ -106,6 +106,19 @@
return false;
}
+double UIScriptControllerMac::dateTimePickerValue() const
+{
+ for (NSWindow *childWindow in webView().window.childWindows) {
+ if ([childWindow isKindOfClass:NSClassFromString(@"WKDateTimePickerWindow")]) {
+ for (NSView *subview in childWindow.contentView.subviews) {
+ if ([subview isKindOfClass:[NSDatePicker class]])
+ return [[(NSDatePicker *)subview dateValue] timeIntervalSince1970] * 1000;
+ }
+ }
+ }
+ return 0;
+}
+
bool UIScriptControllerMac::isShowingDataListSuggestions() const
{
return dataListSuggestionsTableView();