- Revision
- 266524
- Author
- akeer...@apple.com
- Date
- 2020-09-03 09:28:11 -0700 (Thu, 03 Sep 2020)
Log Message
[macOS] Support stepping using keyboard in date inputs
https://bugs.webkit.org/show_bug.cgi?id=216090
Reviewed by Darin Adler.
Source/WebCore:
Users should be able to step through dates using the up and down arrow
keys, matching the functionality of NSDatePicker. To achieve this
functionality, stepUp and stepDown methods were added to
DateTimeFieldElement, incrementing and decrementing the value of the
focused field on an up arrow keypress and a down arrow keypress
respectively. If the currently focused field is empty during the
keypress, stepping up will start from the minimum value and stepping
down will start from the maximum value.
Covered by a new test case in an existing test file.
* html/shadow/DateTimeFieldElement.cpp:
(WebCore::DateTimeFieldElement::defaultKeyboardEventHandler):
* html/shadow/DateTimeFieldElement.h:
* html/shadow/DateTimeNumericFieldElement.cpp:
(WebCore::DateTimeNumericFieldElement::setValueAsIntegerByStepping):
(WebCore::DateTimeNumericFieldElement::stepDown):
(WebCore::DateTimeNumericFieldElement::stepUp):
* html/shadow/DateTimeNumericFieldElement.h:
* html/shadow/DateTimeSymbolicFieldElement.cpp:
(WebCore::DateTimeSymbolicFieldElement::stepDown):
(WebCore::DateTimeSymbolicFieldElement::stepUp):
* html/shadow/DateTimeSymbolicFieldElement.h:
LayoutTests:
Added a new test case to the existing set of keyboard testcases for editable date inputs.
* fast/forms/date/date-editable-components/date-editable-components-keyboard-events-expected.txt:
* fast/forms/date/date-editable-components/date-editable-components-keyboard-events.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (266523 => 266524)
--- trunk/LayoutTests/ChangeLog 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/LayoutTests/ChangeLog 2020-09-03 16:28:11 UTC (rev 266524)
@@ -1,3 +1,15 @@
+2020-09-03 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Support stepping using keyboard in date inputs
+ https://bugs.webkit.org/show_bug.cgi?id=216090
+
+ Reviewed by Darin Adler.
+
+ Added a new test case to the existing set of keyboard testcases for editable date inputs.
+
+ * fast/forms/date/date-editable-components/date-editable-components-keyboard-events-expected.txt:
+ * fast/forms/date/date-editable-components/date-editable-components-keyboard-events.html:
+
2020-09-03 Alex Christensen <achristen...@webkit.org>
Rebase Windows test expectations after r266466
Modified: trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events-expected.txt (266523 => 266524)
--- trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events-expected.txt 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events-expected.txt 2020-09-03 16:28:11 UTC (rev 266524)
@@ -35,6 +35,14 @@
PASS changeEventsFired is 3
PASS inputEventsFired is 3
+Up/Down arrow keys
+PASS input.value is "2020-01-20"
+PASS input.value is "2020-02-20"
+PASS input.value is "2020-01-20"
+PASS input.value is "2020-12-20"
+PASS changeEventsFired is 4
+PASS inputEventsFired is 4
+
Tab key
PASS input.value is "0002-02-02"
PASS document.activeElement.id is "after"
Modified: trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events.html (266523 => 266524)
--- trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events.html 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/LayoutTests/fast/forms/date/date-editable-components/date-editable-components-keyboard-events.html 2020-09-03 16:28:11 UTC (rev 266524)
@@ -130,6 +130,18 @@
shouldBe("changeEventsFired", "3");
shouldBe("inputEventsFired", "3");
+ beginTest("Up/Down arrow keys", "2020-12-20"); // [12]/20/2020
+ UIHelper.keyDown("upArrow"); // [01]/20/2020
+ shouldBeEqualToString("input.value", "2020-01-20");
+ UIHelper.keyDown("upArrow"); // [02]/20/2020
+ shouldBeEqualToString("input.value", "2020-02-20");
+ UIHelper.keyDown("downArrow"); // [01]/20/2020
+ shouldBeEqualToString("input.value", "2020-01-20");
+ UIHelper.keyDown("downArrow"); // [12]/20/2020
+ shouldBeEqualToString("input.value", "2020-12-20");
+ shouldBe("changeEventsFired", "4");
+ shouldBe("inputEventsFired", "4");
+
beginTest("Tab key");
UIHelper.keyDown("2"); // -> [02]/dd/yyyy
UIHelper.keyDown("\t"); // -> 02/[dd]/yyyy
Modified: trunk/Source/WebCore/ChangeLog (266523 => 266524)
--- trunk/Source/WebCore/ChangeLog 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/ChangeLog 2020-09-03 16:28:11 UTC (rev 266524)
@@ -1,3 +1,34 @@
+2020-09-03 Aditya Keerthi <akeer...@apple.com>
+
+ [macOS] Support stepping using keyboard in date inputs
+ https://bugs.webkit.org/show_bug.cgi?id=216090
+
+ Reviewed by Darin Adler.
+
+ Users should be able to step through dates using the up and down arrow
+ keys, matching the functionality of NSDatePicker. To achieve this
+ functionality, stepUp and stepDown methods were added to
+ DateTimeFieldElement, incrementing and decrementing the value of the
+ focused field on an up arrow keypress and a down arrow keypress
+ respectively. If the currently focused field is empty during the
+ keypress, stepping up will start from the minimum value and stepping
+ down will start from the maximum value.
+
+ Covered by a new test case in an existing test file.
+
+ * html/shadow/DateTimeFieldElement.cpp:
+ (WebCore::DateTimeFieldElement::defaultKeyboardEventHandler):
+ * html/shadow/DateTimeFieldElement.h:
+ * html/shadow/DateTimeNumericFieldElement.cpp:
+ (WebCore::DateTimeNumericFieldElement::setValueAsIntegerByStepping):
+ (WebCore::DateTimeNumericFieldElement::stepDown):
+ (WebCore::DateTimeNumericFieldElement::stepUp):
+ * html/shadow/DateTimeNumericFieldElement.h:
+ * html/shadow/DateTimeSymbolicFieldElement.cpp:
+ (WebCore::DateTimeSymbolicFieldElement::stepDown):
+ (WebCore::DateTimeSymbolicFieldElement::stepUp):
+ * html/shadow/DateTimeSymbolicFieldElement.h:
+
2020-09-03 Sam Weinig <wei...@apple.com>
Update WebIDL parser to more closely align with current WebIDL spec
Modified: trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp 2020-09-03 16:28:11 UTC (rev 266524)
@@ -98,10 +98,22 @@
if (isFieldOwnerReadOnly())
return;
+ if (key == "Up") {
+ stepUp();
+ keyboardEvent.setDefaultHandled();
+ return;
+ }
+
+ if (key == "Down") {
+ stepDown();
+ keyboardEvent.setDefaultHandled();
+ return;
+ }
+
// Clear value when pressing backspace or delete.
if (key == "U+0008" || key == "U+007F") {
+ setEmptyValue(DispatchInputAndChangeEvents);
keyboardEvent.setDefaultHandled();
- setEmptyValue(DispatchInputAndChangeEvents);
return;
}
}
Modified: trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h 2020-09-03 16:28:11 UTC (rev 266524)
@@ -63,6 +63,8 @@
virtual void setEmptyValue(EventBehavior = DispatchNoEvent) = 0;
virtual void setValueAsDate(const DateComponents&) = 0;
virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) = 0;
+ virtual void stepDown() = 0;
+ virtual void stepUp() = 0;
virtual String value() const = 0;
virtual String visibleValue() const = 0;
Modified: trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp 2020-09-03 16:28:11 UTC (rev 266524)
@@ -93,6 +93,28 @@
updateVisibleValue(eventBehavior);
}
+void DateTimeNumericFieldElement::setValueAsIntegerByStepping(int value)
+{
+ m_typeAheadBuffer.clear();
+ setValueAsInteger(value, DispatchInputAndChangeEvents);
+}
+
+void DateTimeNumericFieldElement::stepDown()
+{
+ int newValue = m_hasValue ? m_value - 1 : m_range.maximum;
+ if (!m_range.isInRange(newValue))
+ newValue = m_range.maximum;
+ setValueAsIntegerByStepping(newValue);
+}
+
+void DateTimeNumericFieldElement::stepUp()
+{
+ int newValue = m_hasValue ? m_value + 1 : m_range.minimum;
+ if (!m_range.isInRange(newValue))
+ newValue = m_range.minimum;
+ setValueAsIntegerByStepping(newValue);
+}
+
String DateTimeNumericFieldElement::value() const
{
return m_hasValue ? formatValue(m_value) : emptyString();
Modified: trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h 2020-09-03 16:28:11 UTC (rev 266524)
@@ -55,6 +55,8 @@
void initialize(const AtomString&);
void setEmptyValue(EventBehavior = DispatchNoEvent) final;
void setValueAsInteger(int, EventBehavior = DispatchNoEvent) final;
+ void stepDown() final;
+ void stepUp() final;
int valueAsInteger() const final;
String visibleValue() const final;
@@ -65,6 +67,7 @@
void didBlur() final;
String formatValue(int) const;
+ void setValueAsIntegerByStepping(int);
const Range m_range;
const String m_placeholder;
Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp 2020-09-03 16:28:11 UTC (rev 266524)
@@ -75,6 +75,22 @@
updateVisibleValue(eventBehavior);
}
+void DateTimeSymbolicFieldElement::stepDown()
+{
+ int newValue = hasValue() ? m_selectedIndex - 1 : m_symbols.size() - 1;
+ if (newValue < 0)
+ newValue = m_symbols.size() - 1;
+ setValueAsInteger(newValue, DispatchInputAndChangeEvents);
+}
+
+void DateTimeSymbolicFieldElement::stepUp()
+{
+ int newValue = hasValue() ? m_selectedIndex + 1 : 0;
+ if (newValue >= static_cast<int>(m_symbols.size()))
+ newValue = 0;
+ setValueAsInteger(newValue, DispatchInputAndChangeEvents);
+}
+
String DateTimeSymbolicFieldElement::value() const
{
return hasValue() ? m_symbols[m_selectedIndex] : emptyString();
Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h (266523 => 266524)
--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h 2020-09-03 16:27:46 UTC (rev 266523)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h 2020-09-03 16:28:11 UTC (rev 266524)
@@ -49,6 +49,8 @@
String visibleEmptyValue() const;
// DateTimeFieldElement functions:
+ void stepDown() final;
+ void stepUp() final;
String value() const final;
String visibleValue() const final;
void handleKeyboardEvent(KeyboardEvent&) final;