Changeset 272368 in webkit
- Timestamp:
- Feb 4, 2021 6:59:24 AM (18 months ago)
- Location:
- trunk
- Files:
-
- 2 added
- 15 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/forms/datetimelocal/datetimelocal-editable-components/datetimelocal-choose-value-from-picker-expected.txt (added)
-
LayoutTests/fast/forms/datetimelocal/datetimelocal-editable-components/datetimelocal-choose-value-from-picker.html (added)
-
LayoutTests/resources/ui-helper.js (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/BaseDateAndTimeInputType.cpp (modified) (4 diffs)
-
Source/WebCore/html/BaseDateAndTimeInputType.h (modified) (2 diffs)
-
Source/WebCore/html/HTMLInputElement.cpp (modified) (2 diffs)
-
Source/WebCore/html/HTMLInputElement.h (modified) (2 diffs)
-
Source/WebCore/platform/DateTimeChooserParameters.h (modified) (3 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm (modified) (2 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl (modified) (1 diff)
-
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h (modified) (1 diff)
-
Tools/WebKitTestRunner/mac/UIScriptControllerMac.h (modified) (1 diff)
-
Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r272366 r272368 1 2021-02-04 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Selecting a date on datetime-local inputs unexpectedly adds second and millisecond fields 4 https://bugs.webkit.org/show_bug.cgi?id=221350 5 <rdar://problem/73943517> 6 7 Reviewed by Devin Rousso. 8 9 Added a test to to verify that the presence of seconds and milliseconds 10 in the value of a datetime-local input after selecting a date using the 11 picker matches the configuration. 12 13 * fast/forms/datetimelocal/datetimelocal-editable-components/datetimelocal-choose-value-from-picker-expected.txt: Added. 14 * fast/forms/datetimelocal/datetimelocal-editable-components/datetimelocal-choose-value-from-picker.html: Added. 15 * resources/ui-helper.js: 16 (window.UIHelper.chooseDateTimePickerValue): 17 1 18 2021-02-04 Martin Robinson <mrobinson@igalia.com> 2 19 -
trunk/LayoutTests/resources/ui-helper.js
r272334 r272368 939 939 uiController.uiScriptComplete(uiController.dateTimePickerValue); 940 940 })()`, valueAsString => resolve(parseFloat(valueAsString))); 941 }); 942 } 943 944 static chooseDateTimePickerValue() 945 { 946 return new Promise((resolve) => { 947 testRunner.runUIScript(` 948 uiController.chooseDateTimePickerValue(); 949 uiController.uiScriptComplete(); 950 `, resolve); 941 951 }); 942 952 } -
trunk/Source/WebCore/ChangeLog
r272367 r272368 1 2021-02-04 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Selecting a date on datetime-local inputs unexpectedly adds second and millisecond fields 4 https://bugs.webkit.org/show_bug.cgi?id=221350 5 <rdar://problem/73943517> 6 7 Reviewed by Devin Rousso. 8 9 Currently, when setting the value of a datetime-local input using the 10 picker, the length of the current value of the input is used to determine 11 whether or not to return a value with second/millisecond precision. 12 13 This is approach is incorrect, since the value could be empty, while the 14 step attribute can specify second/millisecond precision. To fix, ensure 15 the DateTimeChooserParameters knows whether the input has second and 16 millisecond fields. That information can then be used by the UIProcess 17 to return a correctly formatted value to the WebProcess. 18 19 Test: fast/forms/datetimelocal/datetimelocal-editable-components/datetimelocal-choose-value-from-picker.html 20 21 * html/BaseDateAndTimeInputType.cpp: 22 (WebCore::BaseDateAndTimeInputType::handleDOMActivateEvent): 23 (WebCore::BaseDateAndTimeInputType::didChangeValueFromControl): 24 (WebCore::BaseDateAndTimeInputType::setupDateTimeChooserParameters): 25 26 Moved this method from HTMLInputElement to the input type, since it is 27 specific to date/time input types, and to leverage the existing 28 shouldHaveSecondField and shouldHaveMillisecondField methods when 29 building the DateTimeChooserParameters. 30 31 * html/BaseDateAndTimeInputType.h: 32 * html/HTMLInputElement.cpp: 33 * html/HTMLInputElement.h: 34 * platform/DateTimeChooserParameters.h: 35 36 Added hasSecondField and hasMillisecondField members, so that the UIProcess 37 knows whether or not to return a string that contains seconds/milliseconds. 38 39 (WebCore::DateTimeChooserParameters::encode const): 40 (WebCore::DateTimeChooserParameters::decode): 41 1 42 2021-02-04 Commit Queue <commit-queue@webkit.org> 2 43 -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp
r272097 r272368 41 41 #include "Decimal.h" 42 42 #include "FocusController.h" 43 #include "HTMLDataListElement.h" 43 44 #include "HTMLDivElement.h" 44 45 #include "HTMLInputElement.h" 45 46 #include "HTMLNames.h" 47 #include "HTMLOptionElement.h" 46 48 #include "KeyboardEvent.h" 47 49 #include "Page.h" … … 293 295 294 296 DateTimeChooserParameters parameters; 295 if (! element()->setupDateTimeChooserParameters(parameters))297 if (!setupDateTimeChooserParameters(parameters)) 296 298 return; 297 299 … … 461 463 462 464 DateTimeChooserParameters parameters; 463 if (! element()->setupDateTimeChooserParameters(parameters))465 if (!setupDateTimeChooserParameters(parameters)) 464 466 return; 465 467 … … 497 499 } 498 500 501 bool BaseDateAndTimeInputType::setupDateTimeChooserParameters(DateTimeChooserParameters& parameters) 502 { 503 ASSERT(element()); 504 505 auto& element = *this->element(); 506 auto& document = element.document(); 507 508 if (!document.view()) 509 return false; 510 511 parameters.type = element.type(); 512 parameters.minimum = element.minimum(); 513 parameters.maximum = element.maximum(); 514 parameters.required = element.isRequired(); 515 516 if (!document.settings().langAttributeAwareFormControlUIEnabled()) 517 parameters.locale = defaultLanguage(); 518 else { 519 AtomString computedLocale = element.computeInheritedLanguage(); 520 parameters.locale = computedLocale.isEmpty() ? AtomString(defaultLanguage()) : computedLocale; 521 } 522 523 auto stepRange = createStepRange(AnyStepHandling::Reject); 524 if (stepRange.hasStep()) { 525 parameters.step = stepRange.step().toDouble(); 526 parameters.stepBase = stepRange.stepBase().toDouble(); 527 } else { 528 parameters.step = 1.0; 529 parameters.stepBase = 0; 530 } 531 532 if (RenderElement* renderer = element.renderer()) 533 parameters.anchorRectInRootView = document.view()->contentsToRootView(renderer->absoluteBoundingBoxRect()); 534 else 535 parameters.anchorRectInRootView = IntRect(); 536 parameters.currentValue = element.value(); 537 538 auto* computedStyle = element.computedStyle(); 539 parameters.isAnchorElementRTL = computedStyle->direction() == TextDirection::RTL; 540 parameters.useDarkAppearance = document.useDarkAppearance(computedStyle); 541 542 auto date = parseToDateComponents(element.value()).valueOr(DateComponents()); 543 parameters.hasSecondField = shouldHaveSecondField(date); 544 parameters.hasMillisecondField = shouldHaveMillisecondField(date); 545 546 #if ENABLE(DATALIST_ELEMENT) 547 if (auto dataList = element.dataList()) { 548 for (auto& option : dataList->suggestions()) { 549 auto label = option.label(); 550 auto value = option.value(); 551 if (!element.isValidValue(value)) 552 continue; 553 parameters.suggestionValues.append(element.sanitizeValue(value)); 554 parameters.localizedSuggestionValues.append(element.localizeValue(value)); 555 parameters.suggestionLabels.append(value == label ? String() : label); 556 } 557 } 558 #endif 559 560 return true; 561 } 562 499 563 void BaseDateAndTimeInputType::closeDateTimeChooser() 500 564 { -
trunk/Source/WebCore/html/BaseDateAndTimeInputType.h
r272097 r272368 44 44 45 45 class DateComponents; 46 47 struct DateTimeChooserParameters; 46 48 47 49 // A super class of date, datetime, datetime-local, month, time, and week types. … … 134 136 void didEndChooser() final; 135 137 138 bool setupDateTimeChooserParameters(DateTimeChooserParameters&); 136 139 void closeDateTimeChooser(); 137 140 -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r272354 r272368 39 39 #include "DateComponents.h" 40 40 #include "DateTimeChooser.h" 41 #include "DateTimeChooserParameters.h"42 41 #include "Document.h" 43 42 #include "Editor.h" … … 2103 2102 } 2104 2103 2105 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)2106 2107 bool HTMLInputElement::setupDateTimeChooserParameters(DateTimeChooserParameters& parameters)2108 {2109 if (!document().view())2110 return false;2111 2112 parameters.type = type();2113 parameters.minimum = minimum();2114 parameters.maximum = maximum();2115 parameters.required = isRequired();2116 2117 if (!document().settings().langAttributeAwareFormControlUIEnabled())2118 parameters.locale = defaultLanguage();2119 else {2120 AtomString computedLocale = computeInheritedLanguage();2121 parameters.locale = computedLocale.isEmpty() ? AtomString(defaultLanguage()) : computedLocale;2122 }2123 2124 auto stepRange = createStepRange(AnyStepHandling::Reject);2125 if (stepRange.hasStep()) {2126 parameters.step = stepRange.step().toDouble();2127 parameters.stepBase = stepRange.stepBase().toDouble();2128 } else {2129 parameters.step = 1.0;2130 parameters.stepBase = 0;2131 }2132 2133 if (RenderElement* renderer = this->renderer())2134 parameters.anchorRectInRootView = document().view()->contentsToRootView(renderer->absoluteBoundingBoxRect());2135 else2136 parameters.anchorRectInRootView = IntRect();2137 parameters.currentValue = value();2138 2139 auto* computedStyle = this->computedStyle();2140 parameters.isAnchorElementRTL = computedStyle->direction() == TextDirection::RTL;2141 parameters.useDarkAppearance = document().useDarkAppearance(computedStyle);2142 2143 #if ENABLE(DATALIST_ELEMENT)2144 if (auto dataList = this->dataList()) {2145 for (auto& option : dataList->suggestions()) {2146 auto label = option.label();2147 auto value = option.value();2148 if (!isValidValue(value))2149 continue;2150 parameters.suggestionValues.append(sanitizeValue(value));2151 parameters.localizedSuggestionValues.append(localizeValue(value));2152 parameters.suggestionLabels.append(value == label ? String() : label);2153 }2154 }2155 #endif2156 2157 return true;2158 }2159 2160 #endif2161 2162 2104 void HTMLInputElement::capsLockStateMayHaveChanged() 2163 2105 { -
trunk/Source/WebCore/html/HTMLInputElement.h
r269587 r272368 43 43 class StepRange; 44 44 45 struct DateTimeChooserParameters;46 47 45 struct InputElementClickState { 48 46 bool stateful { false }; … … 327 325 HTMLImageLoader* imageLoader() { return m_imageLoader.get(); } 328 326 HTMLImageLoader& ensureImageLoader(); 329 330 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)331 bool setupDateTimeChooserParameters(DateTimeChooserParameters&);332 #endif333 327 334 328 void capsLockStateMayHaveChanged(); -
trunk/Source/WebCore/platform/DateTimeChooserParameters.h
r267131 r272368 44 44 Vector<String> localizedSuggestionValues; 45 45 Vector<String> suggestionLabels; 46 double minimum; 47 double maximum; 48 double step; 49 double stepBase; 50 bool required; 51 bool isAnchorElementRTL; 52 bool useDarkAppearance; 46 double minimum { 0 }; 47 double maximum { 0 }; 48 double step { 0 }; 49 double stepBase { 0 }; 50 bool required { false }; 51 bool isAnchorElementRTL { false }; 52 bool useDarkAppearance { false }; 53 bool hasSecondField { false }; 54 bool hasMillisecondField { false }; 53 55 54 56 template<class Encoder> void encode(Encoder&) const; … … 73 75 encoder << isAnchorElementRTL; 74 76 encoder << useDarkAppearance; 77 encoder << hasSecondField; 78 encoder << hasMillisecondField; 75 79 } 76 80 … … 134 138 return WTF::nullopt; 135 139 136 return {{ WTFMove(type), anchorRectInRootView, WTFMove(locale), WTFMove(currentValue), WTFMove(suggestionValues), WTFMove(localizedSuggestionValues), WTFMove(suggestionLabels), minimum, maximum, step, stepBase, required, isAnchorElementRTL, useDarkAppearance }}; 140 bool hasSecondField; 141 if (!decoder.decode(hasSecondField)) 142 return WTF::nullopt; 143 144 bool hasMillisecondField; 145 if (!decoder.decode(hasMillisecondField)) 146 return WTF::nullopt; 147 148 return {{ WTFMove(type), anchorRectInRootView, WTFMove(locale), WTFMove(currentValue), WTFMove(suggestionValues), WTFMove(localizedSuggestionValues), WTFMove(suggestionLabels), minimum, maximum, step, stepBase, required, isAnchorElementRTL, useDarkAppearance, hasSecondField, hasMillisecondField }}; 137 149 } 138 150 -
trunk/Source/WebKit/ChangeLog
r272362 r272368 1 2021-02-04 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Selecting a date on datetime-local inputs unexpectedly adds second and millisecond fields 4 https://bugs.webkit.org/show_bug.cgi?id=221350 5 <rdar://problem/73943517> 6 7 Reviewed by Devin Rousso. 8 9 * UIProcess/mac/WebDateTimePickerMac.mm: 10 (-[WKDateTimePicker updatePicker:]): 11 (-[WKDateTimePicker dateFormatStringForType:]): 12 13 Do not use the length of the value to determine whether or seconds and 14 milliseconds should be present, since the value can be empty. 15 16 Instead, use the new information in DateTimeChooserParameters, matching 17 the visual appearance of the input. 18 1 19 2021-02-04 Lauro Moura <lmoura@igalia.com> 2 20 -
trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm
r269540 r272368 241 241 NSString *currentDateValueString = _params.currentValue; 242 242 243 [_dateFormatter setDateFormat:[self dateFormatStringForType:_params.type value:currentDateValueString]];243 [_dateFormatter setDateFormat:[self dateFormatStringForType:_params.type]]; 244 244 245 245 if (![currentDateValueString length]) … … 277 277 } 278 278 279 - (NSString *)dateFormatStringForType:(NSString *)type value:(NSString *)value279 - (NSString *)dateFormatStringForType:(NSString *)type 280 280 { 281 281 if ([type isEqualToString:@"datetime-local"]) { 282 // Add two additional characters for the string delimiters in 'T'. 283 NSUInteger valueLengthForFormat = value.length + 2; 284 if (valueLengthForFormat == kDateTimeFormatString.length) 285 return kDateTimeFormatString; 286 if (valueLengthForFormat == kDateTimeWithSecondsFormatString.length) 282 if (_params.hasMillisecondField) 283 return kDateTimeWithMillisecondsFormatString; 284 if (_params.hasSecondField) 287 285 return kDateTimeWithSecondsFormatString; 288 return kDateTime WithMillisecondsFormatString;286 return kDateTimeFormatString; 289 287 } 290 288 -
trunk/Tools/ChangeLog
r272365 r272368 1 2021-02-04 Aditya Keerthi <akeerthi@apple.com> 2 3 [macOS] Selecting a date on datetime-local inputs unexpectedly adds second and millisecond fields 4 https://bugs.webkit.org/show_bug.cgi?id=221350 5 <rdar://problem/73943517> 6 7 Reviewed by Devin Rousso. 8 9 Added a method to UIScriptController to simulate selecting a date using 10 the presented date picker. 11 12 * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl: 13 * TestRunnerShared/UIScriptContext/UIScriptController.h: 14 (WTR::UIScriptController::chooseDateTimePickerValue): 15 * WebKitTestRunner/mac/UIScriptControllerMac.h: 16 * WebKitTestRunner/mac/UIScriptControllerMac.mm: 17 (WTR::UIScriptControllerMac::chooseDateTimePickerValue): 18 1 19 2021-02-04 Eleni Maria Stea <estea@igalia.com> 2 20 -
trunk/Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
r271786 r272368 230 230 readonly attribute boolean isShowingDateTimePicker; 231 231 readonly attribute double dateTimePickerValue; 232 undefined chooseDateTimePickerValue(); 232 233 233 234 // <datalist> -
trunk/Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
r271786 r272368 224 224 virtual bool isShowingDateTimePicker() const { notImplemented(); return false; } 225 225 virtual double dateTimePickerValue() const { notImplemented(); return 0; } 226 virtual void chooseDateTimePickerValue() { notImplemented(); } 226 227 virtual bool isShowingDataListSuggestions() const { notImplemented(); return false; } 227 228 virtual JSObjectRef calendarType() const { notImplemented(); return nullptr; } -
trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.h
r267761 r272368 46 46 bool isShowingDateTimePicker() const override; 47 47 double dateTimePickerValue() const override; 48 void chooseDateTimePickerValue() override; 48 49 bool isShowingDataListSuggestions() const override; 49 50 void activateDataListSuggestion(unsigned index, JSValueRef callback) override; -
trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm
r267761 r272368 120 120 } 121 121 122 void UIScriptControllerMac::chooseDateTimePickerValue() 123 { 124 for (NSWindow *childWindow in webView().window.childWindows) { 125 if ([childWindow isKindOfClass:NSClassFromString(@"WKDateTimePickerWindow")]) { 126 for (NSView *subview in childWindow.contentView.subviews) { 127 if ([subview isKindOfClass:[NSDatePicker class]]) { 128 NSDatePicker *datePicker = (NSDatePicker *)subview; 129 [datePicker.target performSelector:datePicker.action withObject:datePicker]; 130 return; 131 } 132 } 133 } 134 } 135 } 136 122 137 bool UIScriptControllerMac::isShowingDataListSuggestions() const 123 138 {
Note: See TracChangeset
for help on using the changeset viewer.