| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document& document, F
ieldOwner& fieldOwner, const Vector<String>& symbols, int minimum, int maximum) | 49 DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement(Document& document, F
ieldOwner& fieldOwner, const Vector<String>& symbols, int minimum, int maximum) |
| 50 : DateTimeFieldElement(document, fieldOwner) | 50 : DateTimeFieldElement(document, fieldOwner) |
| 51 , m_symbols(symbols) | 51 , m_symbols(symbols) |
| 52 , m_visibleEmptyValue(makeVisibleEmptyValue(symbols)) | 52 , m_visibleEmptyValue(makeVisibleEmptyValue(symbols)) |
| 53 , m_selectedIndex(-1) | 53 , m_selectedIndex(-1) |
| 54 , m_typeAhead(this) | 54 , m_typeAhead(this) |
| 55 , m_minimumIndex(minimum) | 55 , m_minimumIndex(minimum) |
| 56 , m_maximumIndex(maximum) | 56 , m_maximumIndex(maximum) |
| 57 { | 57 { |
| 58 ASSERT(!symbols.isEmpty()); | 58 DCHECK(!symbols.isEmpty()); |
| 59 ASSERT(m_minimumIndex >= 0); | 59 DCHECK_GE(m_minimumIndex, 0); |
| 60 ASSERT_WITH_SECURITY_IMPLICATION(m_maximumIndex < static_cast<int>(m_symbols
.size())); | 60 SECURITY_DCHECK(m_maximumIndex < static_cast<int>(m_symbols.size())); |
| 61 ASSERT(m_minimumIndex <= m_maximumIndex); | 61 DCHECK_LE(m_minimumIndex, m_maximumIndex); |
| 62 } | 62 } |
| 63 | 63 |
| 64 float DateTimeSymbolicFieldElement::maximumWidth(const ComputedStyle& style) | 64 float DateTimeSymbolicFieldElement::maximumWidth(const ComputedStyle& style) |
| 65 { | 65 { |
| 66 float maximumWidth = computeTextWidth(style, visibleEmptyValue()); | 66 float maximumWidth = computeTextWidth(style, visibleEmptyValue()); |
| 67 for (unsigned index = 0; index < m_symbols.size(); ++index) | 67 for (unsigned index = 0; index < m_symbols.size(); ++index) |
| 68 maximumWidth = std::max(maximumWidth, computeTextWidth(style, m_symbols[
index])); | 68 maximumWidth = std::max(maximumWidth, computeTextWidth(style, m_symbols[
index])); |
| 69 return maximumWidth + DateTimeFieldElement::maximumWidth(style); | 69 return maximumWidth + DateTimeFieldElement::maximumWidth(style); |
| 70 } | 70 } |
| 71 | 71 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 { | 111 { |
| 112 m_selectedIndex = std::max(0, std::min(newSelectedIndex, static_cast<int>(m_
symbols.size() - 1))); | 112 m_selectedIndex = std::max(0, std::min(newSelectedIndex, static_cast<int>(m_
symbols.size() - 1))); |
| 113 updateVisibleValue(eventBehavior); | 113 updateVisibleValue(eventBehavior); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void DateTimeSymbolicFieldElement::stepDown() | 116 void DateTimeSymbolicFieldElement::stepDown() |
| 117 { | 117 { |
| 118 if (hasValue()) { | 118 if (hasValue()) { |
| 119 if (!indexIsInRange(--m_selectedIndex)) | 119 if (!indexIsInRange(--m_selectedIndex)) |
| 120 m_selectedIndex = m_maximumIndex; | 120 m_selectedIndex = m_maximumIndex; |
| 121 } else | 121 } else { |
| 122 m_selectedIndex = m_maximumIndex; | 122 m_selectedIndex = m_maximumIndex; |
| 123 } |
| 123 updateVisibleValue(DispatchEvent); | 124 updateVisibleValue(DispatchEvent); |
| 124 } | 125 } |
| 125 | 126 |
| 126 void DateTimeSymbolicFieldElement::stepUp() | 127 void DateTimeSymbolicFieldElement::stepUp() |
| 127 { | 128 { |
| 128 if (hasValue()) { | 129 if (hasValue()) { |
| 129 if (!indexIsInRange(++m_selectedIndex)) | 130 if (!indexIsInRange(++m_selectedIndex)) |
| 130 m_selectedIndex = m_minimumIndex; | 131 m_selectedIndex = m_minimumIndex; |
| 131 } else | 132 } else { |
| 132 m_selectedIndex = m_minimumIndex; | 133 m_selectedIndex = m_minimumIndex; |
| 134 } |
| 133 updateVisibleValue(DispatchEvent); | 135 updateVisibleValue(DispatchEvent); |
| 134 } | 136 } |
| 135 | 137 |
| 136 String DateTimeSymbolicFieldElement::value() const | 138 String DateTimeSymbolicFieldElement::value() const |
| 137 { | 139 { |
| 138 return hasValue() ? m_symbols[m_selectedIndex] : emptyString(); | 140 return hasValue() ? m_symbols[m_selectedIndex] : emptyString(); |
| 139 } | 141 } |
| 140 | 142 |
| 141 int DateTimeSymbolicFieldElement::valueAsInteger() const | 143 int DateTimeSymbolicFieldElement::valueAsInteger() const |
| 142 { | 144 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 168 { | 170 { |
| 169 return m_symbols.size(); | 171 return m_symbols.size(); |
| 170 } | 172 } |
| 171 | 173 |
| 172 String DateTimeSymbolicFieldElement::optionAtIndex(int index) const | 174 String DateTimeSymbolicFieldElement::optionAtIndex(int index) const |
| 173 { | 175 { |
| 174 return m_symbols[index]; | 176 return m_symbols[index]; |
| 175 } | 177 } |
| 176 | 178 |
| 177 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |