Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: Source/core/html/shadow/DateTimeNumericFieldElement.cpp

Issue 112513002: Remove keyboard input timeout for date, datetime-local, month, time, and week input types on non-An… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/shadow/DateTimeNumericFieldElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 19 matching lines...) Expand all
30 #include "CSSPropertyNames.h" 30 #include "CSSPropertyNames.h"
31 #include "CSSValueKeywords.h" 31 #include "CSSValueKeywords.h"
32 #include "core/events/KeyboardEvent.h" 32 #include "core/events/KeyboardEvent.h"
33 #include "platform/fonts/Font.h" 33 #include "platform/fonts/Font.h"
34 #include "platform/text/PlatformLocale.h" 34 #include "platform/text/PlatformLocale.h"
35 35
36 using namespace WTF::Unicode; 36 using namespace WTF::Unicode;
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 static const DOMTimeStamp typeAheadTimeout = 1000;
41
42 int DateTimeNumericFieldElement::Range::clampValue(int value) const 40 int DateTimeNumericFieldElement::Range::clampValue(int value) const
43 { 41 {
44 return std::min(std::max(value, minimum), maximum); 42 return std::min(std::max(value, minimum), maximum);
45 } 43 }
46 44
47 bool DateTimeNumericFieldElement::Range::isInRange(int value) const 45 bool DateTimeNumericFieldElement::Range::isInRange(int value) const
48 { 46 {
49 return value >= minimum && value <= maximum; 47 return value >= minimum && value <= maximum;
50 } 48 }
51 49
52 // ---------------------------- 50 // ----------------------------
53 51
54 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document& document, Fie ldOwner& fieldOwner, const Range& range, const Range& hardLimits, const String& placeholder, const DateTimeNumericFieldElement::Step& step) 52 DateTimeNumericFieldElement::DateTimeNumericFieldElement(Document& document, Fie ldOwner& fieldOwner, const Range& range, const Range& hardLimits, const String& placeholder, const DateTimeNumericFieldElement::Step& step)
55 : DateTimeFieldElement(document, fieldOwner) 53 : DateTimeFieldElement(document, fieldOwner)
56 , m_lastDigitCharTime(0)
57 , m_placeholder(placeholder) 54 , m_placeholder(placeholder)
58 , m_range(range) 55 , m_range(range)
59 , m_hardLimits(hardLimits) 56 , m_hardLimits(hardLimits)
60 , m_step(step) 57 , m_step(step)
61 , m_value(0) 58 , m_value(0)
62 , m_hasValue(false) 59 , m_hasValue(false)
63 { 60 {
64 ASSERT(m_step.step); 61 ASSERT(m_step.step);
65 ASSERT(m_range.minimum <= m_range.maximum); 62 ASSERT(m_range.minimum <= m_range.maximum);
66 ASSERT(m_hardLimits.minimum <= m_hardLimits.maximum); 63 ASSERT(m_hardLimits.minimum <= m_hardLimits.maximum);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ASSERT(!isDisabled()); 115 ASSERT(!isDisabled());
119 if (keyboardEvent->type() != EventTypeNames::keypress) 116 if (keyboardEvent->type() != EventTypeNames::keypress)
120 return; 117 return;
121 118
122 UChar charCode = static_cast<UChar>(keyboardEvent->charCode()); 119 UChar charCode = static_cast<UChar>(keyboardEvent->charCode());
123 String number = localeForOwner().convertFromLocalizedNumber(String(&charCode , 1)); 120 String number = localeForOwner().convertFromLocalizedNumber(String(&charCode , 1));
124 const int digit = number[0] - '0'; 121 const int digit = number[0] - '0';
125 if (digit < 0 || digit > 9) 122 if (digit < 0 || digit > 9)
126 return; 123 return;
127 124
128 DOMTimeStamp delta = keyboardEvent->timeStamp() - m_lastDigitCharTime;
129 m_lastDigitCharTime = keyboardEvent->timeStamp();
130
131 if (delta > typeAheadTimeout)
132 m_typeAheadBuffer.clear();
133 m_typeAheadBuffer.append(number); 125 m_typeAheadBuffer.append(number);
134
135 int newValue = typeAheadValue(); 126 int newValue = typeAheadValue();
136 if (newValue >= m_hardLimits.minimum) 127 if (newValue >= m_hardLimits.minimum)
137 setValueAsInteger(newValue, DispatchEvent); 128 setValueAsInteger(newValue, DispatchEvent);
138 else { 129 else {
139 m_hasValue = false; 130 m_hasValue = false;
140 updateVisibleValue(DispatchEvent); 131 updateVisibleValue(DispatchEvent);
141 } 132 }
142 133
143 if (m_typeAheadBuffer.length() >= DateTimeNumericFieldElement::formatValue(m _range.maximum).length() || newValue * 10 > m_range.maximum) 134 if (m_typeAheadBuffer.length() >= DateTimeNumericFieldElement::formatValue(m _range.maximum).length() || newValue * 10 > m_range.maximum)
144 focusOnNextField(); 135 focusOnNextField();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 if (n >= 0) 228 if (n >= 0)
238 n = (n + m_step.step - 1) / m_step.step * m_step.step; 229 n = (n + m_step.step - 1) / m_step.step * m_step.step;
239 else 230 else
240 n = -(-n / m_step.step * m_step.step); 231 n = -(-n / m_step.step * m_step.step);
241 return n + m_step.stepBase; 232 return n + m_step.stepBase;
242 } 233 }
243 234
244 } // namespace WebCore 235 } // namespace WebCore
245 236
246 #endif 237 #endif
OLDNEW
« no previous file with comments | « Source/core/html/shadow/DateTimeNumericFieldElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698