void DateTimeNumericFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEvent) { ASSERT(!isDisabled()); if (keyboardEvent->type() != EventTypeNames::keypress) return; UChar charCode = static_cast<UChar>(keyboardEvent->charCode()); String number = localeForOwner().convertFromLocalizedNumber(String(&charCode, 1)); const int digit = number[0] - '0'; if (digit < 0 || digit > 9) return; DOMTimeStamp delta = keyboardEvent->timeStamp() - m_lastDigitCharTime; m_lastDigitCharTime = keyboardEvent->timeStamp(); if (delta > typeAheadTimeout) m_typeAheadBuffer.clear(); m_typeAheadBuffer.append(number); int newValue = typeAheadValue(); if (newValue >= m_hardLimits.minimum) setValueAsInteger(newValue, DispatchEvent); else { m_hasValue = false; updateVisibleValue(DispatchEvent); } if (m_typeAheadBuffer.length() >= DateTimeNumericFieldElement::formatValue(m_range.maximum).length() || newValue * 10 > m_range.maximum) focusOnNextField(); keyboardEvent->setDefaultHandled(); }
void DateTimeNumericFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEvent) { ASSERT(!isDisabled()); if (keyboardEvent->type() != EventTypeNames::keypress) return; UChar charCode = static_cast<UChar>(keyboardEvent->charCode()); String number = localeForOwner().convertFromLocalizedNumber(String(&charCode, 1)); const int digit = number[0] - '0'; if (digit < 0 || digit > 9) return; unsigned maximumLength = DateTimeNumericFieldElement::formatValue(m_range.maximum).length(); if (m_typeAheadBuffer.length() >= maximumLength) { String current = m_typeAheadBuffer.toString(); m_typeAheadBuffer.clear(); unsigned desiredLength = maximumLength - 1; m_typeAheadBuffer.append(current, current.length() - desiredLength, desiredLength); } m_typeAheadBuffer.append(number); int newValue = typeAheadValue(); if (newValue >= m_hardLimits.minimum) setValueAsInteger(newValue, DispatchEvent); else { m_hasValue = false; updateVisibleValue(DispatchEvent); } if (m_typeAheadBuffer.length() >= maximumLength || newValue * 10 > m_range.maximum) focusOnNextField(); keyboardEvent->setDefaultHandled(); }
void DateTimeNumericFieldElement::didBlur() { int value = typeAheadValue(); m_typeAheadBuffer.clear(); if (value >= 0) setValueAsInteger(value, DispatchEvent); DateTimeFieldElement::didBlur(); }
void DateTimeNumericFieldElement::setFocused(bool value) { if (!value) { int value = typeAheadValue(); m_typeAheadBuffer.clear(); if (value >= 0) setValueAsInteger(value, DispatchEvent); } DateTimeFieldElement::setFocused(value); }
String DateTimeNumericFieldElement::visibleValue() const { if (m_typeAheadBuffer.length()) return formatValue(typeAheadValue()); return m_hasValue ? value() : m_placeholder; }