| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document& document, Fie
ldOwner& fieldOwner, const Range& range, const Range& hardLimits, const String&
placeholder, const DateTimeNumericFieldElement::Step& step) | 51 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document& document, Fie
ldOwner& fieldOwner, const Range& range, const Range& hardLimits, const String&
placeholder, const DateTimeNumericFieldElement::Step& step) |
| 52 : DateTimeFieldElement(document, fieldOwner) | 52 : DateTimeFieldElement(document, fieldOwner) |
| 53 , m_placeholder(placeholder) | 53 , m_placeholder(placeholder) |
| 54 , m_range(range) | 54 , m_range(range) |
| 55 , m_hardLimits(hardLimits) | 55 , m_hardLimits(hardLimits) |
| 56 , m_step(step) | 56 , m_step(step) |
| 57 , m_value(0) | 57 , m_value(0) |
| 58 , m_hasValue(false) | 58 , m_hasValue(false) |
| 59 { | 59 { |
| 60 ASSERT(m_step.step); | 60 DCHECK_NE(m_step.step, 0); |
| 61 ASSERT(m_range.minimum <= m_range.maximum); | 61 DCHECK_LE(m_range.minimum, m_range.maximum); |
| 62 ASSERT(m_hardLimits.minimum <= m_hardLimits.maximum); | 62 DCHECK_LE(m_hardLimits.minimum, m_hardLimits.maximum); |
| 63 | 63 |
| 64 // We show a direction-neutral string such as "--" as a placeholder. It | 64 // We show a direction-neutral string such as "--" as a placeholder. It |
| 65 // should follow the direction of numeric values. | 65 // should follow the direction of numeric values. |
| 66 if (localeForOwner().isRTL()) { | 66 if (localeForOwner().isRTL()) { |
| 67 CharDirection dir = direction(formatValue(this->maximum())[0]); | 67 CharDirection dir = direction(formatValue(this->maximum())[0]); |
| 68 if (dir == LeftToRight || dir == EuropeanNumber || dir == ArabicNumber)
{ | 68 if (dir == LeftToRight || dir == EuropeanNumber || dir == ArabicNumber)
{ |
| 69 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueBidiOverride)
; | 69 setInlineStyleProperty(CSSPropertyUnicodeBidi, CSSValueBidiOverride)
; |
| 70 setInlineStyleProperty(CSSPropertyDirection, CSSValueLtr); | 70 setInlineStyleProperty(CSSPropertyDirection, CSSValueLtr); |
| 71 } | 71 } |
| 72 } | 72 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 Locale& locale = localeForOwner(); | 106 Locale& locale = localeForOwner(); |
| 107 if (m_hardLimits.maximum > 999) | 107 if (m_hardLimits.maximum > 999) |
| 108 return locale.convertToLocalizedNumber(String::format("%04d", value)); | 108 return locale.convertToLocalizedNumber(String::format("%04d", value)); |
| 109 if (m_hardLimits.maximum > 99) | 109 if (m_hardLimits.maximum > 99) |
| 110 return locale.convertToLocalizedNumber(String::format("%03d", value)); | 110 return locale.convertToLocalizedNumber(String::format("%03d", value)); |
| 111 return locale.convertToLocalizedNumber(String::format("%02d", value)); | 111 return locale.convertToLocalizedNumber(String::format("%02d", value)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void DateTimeNumericFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEve
nt) | 114 void DateTimeNumericFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEve
nt) |
| 115 { | 115 { |
| 116 ASSERT(!isDisabled()); | 116 DCHECK(!isDisabled()); |
| 117 if (keyboardEvent->type() != EventTypeNames::keypress) | 117 if (keyboardEvent->type() != EventTypeNames::keypress) |
| 118 return; | 118 return; |
| 119 | 119 |
| 120 UChar charCode = static_cast<UChar>(keyboardEvent->charCode()); | 120 UChar charCode = static_cast<UChar>(keyboardEvent->charCode()); |
| 121 String number = localeForOwner().convertFromLocalizedNumber(String(&charCode
, 1)); | 121 String number = localeForOwner().convertFromLocalizedNumber(String(&charCode
, 1)); |
| 122 const int digit = number[0] - '0'; | 122 const int digit = number[0] - '0'; |
| 123 if (digit < 0 || digit > 9) | 123 if (digit < 0 || digit > 9) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 unsigned maximumLength = DateTimeNumericFieldElement::formatValue(m_range.ma
ximum).length(); | 126 unsigned maximumLength = DateTimeNumericFieldElement::formatValue(m_range.ma
ximum).length(); |
| 127 if (m_typeAheadBuffer.length() >= maximumLength) { | 127 if (m_typeAheadBuffer.length() >= maximumLength) { |
| 128 String current = m_typeAheadBuffer.toString(); | 128 String current = m_typeAheadBuffer.toString(); |
| 129 m_typeAheadBuffer.clear(); | 129 m_typeAheadBuffer.clear(); |
| 130 unsigned desiredLength = maximumLength - 1; | 130 unsigned desiredLength = maximumLength - 1; |
| 131 m_typeAheadBuffer.append(current, current.length() - desiredLength, desi
redLength); | 131 m_typeAheadBuffer.append(current, current.length() - desiredLength, desi
redLength); |
| 132 } | 132 } |
| 133 m_typeAheadBuffer.append(number); | 133 m_typeAheadBuffer.append(number); |
| 134 int newValue = typeAheadValue(); | 134 int newValue = typeAheadValue(); |
| 135 if (newValue >= m_hardLimits.minimum) | 135 if (newValue >= m_hardLimits.minimum) { |
| 136 setValueAsInteger(newValue, DispatchEvent); | 136 setValueAsInteger(newValue, DispatchEvent); |
| 137 else { | 137 } else { |
| 138 m_hasValue = false; | 138 m_hasValue = false; |
| 139 updateVisibleValue(DispatchEvent); | 139 updateVisibleValue(DispatchEvent); |
| 140 } | 140 } |
| 141 | 141 |
| 142 if (m_typeAheadBuffer.length() >= maximumLength || newValue * 10 > m_range.m
aximum) | 142 if (m_typeAheadBuffer.length() >= maximumLength || newValue * 10 > m_range.m
aximum) |
| 143 focusOnNextField(); | 143 focusOnNextField(); |
| 144 | 144 |
| 145 keyboardEvent->setDefaultHandled(); | 145 keyboardEvent->setDefaultHandled(); |
| 146 } | 146 } |
| 147 | 147 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 { | 234 { |
| 235 n -= m_step.stepBase; | 235 n -= m_step.stepBase; |
| 236 if (n >= 0) | 236 if (n >= 0) |
| 237 n = (n + m_step.step - 1) / m_step.step * m_step.step; | 237 n = (n + m_step.step - 1) / m_step.step * m_step.step; |
| 238 else | 238 else |
| 239 n = -(-n / m_step.step * m_step.step); | 239 n = -(-n / m_step.step * m_step.step); |
| 240 return n + m_step.stepBase; | 240 return n + m_step.stepBase; |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace blink | 243 } // namespace blink |
| OLD | NEW |