OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
4 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights
reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights
reserved. |
7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
10 * | 10 * |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 TypeAhead::TypeAhead(TypeAheadDataSource* dataSource) | 38 TypeAhead::TypeAhead(TypeAheadDataSource* dataSource) |
39 : m_dataSource(dataSource) | 39 : m_dataSource(dataSource) |
40 , m_lastTypeTime(0) | 40 , m_lastTypeTime(0) |
41 , m_repeatingChar(0) | 41 , m_repeatingChar(0) |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 static const DOMTimeStamp typeAheadTimeout = 1000; | 45 static const double typeAheadTimeout = 1; // in seconds |
46 | 46 |
47 static String stripLeadingWhiteSpace(const String& string) | 47 static String stripLeadingWhiteSpace(const String& string) |
48 { | 48 { |
49 unsigned length = string.length(); | 49 unsigned length = string.length(); |
50 | 50 |
51 unsigned i; | 51 unsigned i; |
52 for (i = 0; i < length; ++i) { | 52 for (i = 0; i < length; ++i) { |
53 if (string[i] != noBreakSpaceCharacter && !isSpaceOrNewline(string[i])) | 53 if (string[i] != noBreakSpaceCharacter && !isSpaceOrNewline(string[i])) |
54 break; | 54 break; |
55 } | 55 } |
56 | 56 |
57 return string.substring(i, length - i); | 57 return string.substring(i, length - i); |
58 } | 58 } |
59 | 59 |
60 int TypeAhead::handleEvent(KeyboardEvent* event, MatchModeFlags matchMode) | 60 int TypeAhead::handleEvent(KeyboardEvent* event, MatchModeFlags matchMode) |
61 { | 61 { |
62 if (event->timeStamp() < m_lastTypeTime) | 62 if (event->platformTimeStamp() < m_lastTypeTime) |
63 return -1; | 63 return -1; |
64 | 64 |
65 int optionCount = m_dataSource->optionCount(); | 65 int optionCount = m_dataSource->optionCount(); |
66 DOMTimeStamp delta = event->timeStamp() - m_lastTypeTime; | 66 double delta = event->platformTimeStamp() - m_lastTypeTime; |
67 m_lastTypeTime = event->timeStamp(); | 67 m_lastTypeTime = event->platformTimeStamp(); |
68 | 68 |
69 UChar c = event->charCode(); | 69 UChar c = event->charCode(); |
70 | 70 |
71 if (delta > typeAheadTimeout) | 71 if (delta > typeAheadTimeout) |
72 m_buffer.clear(); | 72 m_buffer.clear(); |
73 | 73 |
74 m_buffer.append(c); | 74 m_buffer.append(c); |
75 | 75 |
76 if (optionCount < 1) | 76 if (optionCount < 1) |
77 return -1; | 77 return -1; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 bool ok = false; | 115 bool ok = false; |
116 int index = m_buffer.toString().toInt(&ok); | 116 int index = m_buffer.toString().toInt(&ok); |
117 if (index > 0 && index <= optionCount) | 117 if (index > 0 && index <= optionCount) |
118 return index - 1; | 118 return index - 1; |
119 } | 119 } |
120 return -1; | 120 return -1; |
121 } | 121 } |
122 | 122 |
123 bool TypeAhead::hasActiveSession(KeyboardEvent* event) | 123 bool TypeAhead::hasActiveSession(KeyboardEvent* event) |
124 { | 124 { |
125 DOMTimeStamp delta = event->timeStamp() - m_lastTypeTime; | 125 double delta = event->platformTimeStamp() - m_lastTypeTime; |
126 return delta <= typeAheadTimeout; | 126 return delta <= typeAheadTimeout; |
127 } | 127 } |
128 | 128 |
129 void TypeAhead::resetSession() | 129 void TypeAhead::resetSession() |
130 { | 130 { |
131 m_lastTypeTime = 0; | 131 m_lastTypeTime = 0; |
132 m_buffer.clear(); | 132 m_buffer.clear(); |
133 } | 133 } |
134 | 134 |
135 } // namespace blink | 135 } // namespace blink |
OLD | NEW |