OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/prefix_selector.h" | 5 #include "ui/views/controls/prefix_selector.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "ui/base/ime/text_input_type.h" | 8 #include "ui/base/ime/text_input_type.h" |
9 #include "ui/gfx/range/range.h" | 9 #include "ui/gfx/range/range.h" |
10 #include "ui/views/controls/prefix_delegate.h" | 10 #include "ui/views/controls/prefix_delegate.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } else { | 166 } else { |
167 current_text_ = text; | 167 current_text_ = text; |
168 if (prefix_delegate_->GetSelectedRow() >= 0) | 168 if (prefix_delegate_->GetSelectedRow() >= 0) |
169 row = (row + 1) % row_count; | 169 row = (row + 1) % row_count; |
170 } | 170 } |
171 time_of_last_key_ = now; | 171 time_of_last_key_ = now; |
172 | 172 |
173 const int start_row = row; | 173 const int start_row = row; |
174 const base::string16 lower_text(base::i18n::ToLower(current_text_)); | 174 const base::string16 lower_text(base::i18n::ToLower(current_text_)); |
175 do { | 175 do { |
176 if (TextAtRowMatchesText(row, current_text_)) { | 176 if (TextAtRowMatchesText(row, lower_text)) { |
177 prefix_delegate_->SetSelectedRow(row); | 177 prefix_delegate_->SetSelectedRow(row); |
178 return; | 178 return; |
179 } | 179 } |
180 row = (row + 1) % row_count; | 180 row = (row + 1) % row_count; |
181 } while (row != start_row); | 181 } while (row != start_row); |
182 } | 182 } |
183 | 183 |
184 bool PrefixSelector::TextAtRowMatchesText(int row, | 184 bool PrefixSelector::TextAtRowMatchesText(int row, |
185 const base::string16& lower_text) { | 185 const base::string16& lower_text) { |
186 const base::string16 model_text( | 186 const base::string16 model_text( |
187 base::i18n::ToLower(prefix_delegate_->GetTextForRow(row))); | 187 base::i18n::ToLower(prefix_delegate_->GetTextForRow(row))); |
188 return (model_text.size() >= lower_text.size()) && | 188 return (model_text.size() >= lower_text.size()) && |
189 (model_text.compare(0, lower_text.size(), lower_text) == 0); | 189 (model_text.compare(0, lower_text.size(), lower_text) == 0); |
190 } | 190 } |
191 | 191 |
192 void PrefixSelector::ClearText() { | 192 void PrefixSelector::ClearText() { |
193 current_text_.clear(); | 193 current_text_.clear(); |
194 time_of_last_key_ = base::TimeTicks(); | 194 time_of_last_key_ = base::TimeTicks(); |
195 } | 195 } |
196 | 196 |
197 } // namespace views | 197 } // namespace views |
OLD | NEW |