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 29 matching lines...) Expand all Loading... |
40 void PrefixSelector::SetCompositionText( | 40 void PrefixSelector::SetCompositionText( |
41 const ui::CompositionText& composition) { | 41 const ui::CompositionText& composition) { |
42 } | 42 } |
43 | 43 |
44 void PrefixSelector::ConfirmCompositionText() { | 44 void PrefixSelector::ConfirmCompositionText() { |
45 } | 45 } |
46 | 46 |
47 void PrefixSelector::ClearCompositionText() { | 47 void PrefixSelector::ClearCompositionText() { |
48 } | 48 } |
49 | 49 |
50 void PrefixSelector::InsertText(const string16& text) { | 50 void PrefixSelector::InsertText(const base::string16& text) { |
51 OnTextInput(text); | 51 OnTextInput(text); |
52 } | 52 } |
53 | 53 |
54 void PrefixSelector::InsertChar(char16 ch, int flags) { | 54 void PrefixSelector::InsertChar(char16 ch, int flags) { |
55 OnTextInput(string16(1, ch)); | 55 OnTextInput(base::string16(1, ch)); |
56 } | 56 } |
57 | 57 |
58 gfx::NativeWindow PrefixSelector::GetAttachedWindow() const { | 58 gfx::NativeWindow PrefixSelector::GetAttachedWindow() const { |
59 return prefix_delegate_->GetWidget()->GetNativeWindow(); | 59 return prefix_delegate_->GetWidget()->GetNativeWindow(); |
60 } | 60 } |
61 | 61 |
62 ui::TextInputType PrefixSelector::GetTextInputType() const { | 62 ui::TextInputType PrefixSelector::GetTextInputType() const { |
63 return ui::TEXT_INPUT_TYPE_TEXT; | 63 return ui::TEXT_INPUT_TYPE_TEXT; |
64 } | 64 } |
65 | 65 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 bool PrefixSelector::SetSelectionRange(const gfx::Range& range) { | 109 bool PrefixSelector::SetSelectionRange(const gfx::Range& range) { |
110 return false; | 110 return false; |
111 } | 111 } |
112 | 112 |
113 bool PrefixSelector::DeleteRange(const gfx::Range& range) { | 113 bool PrefixSelector::DeleteRange(const gfx::Range& range) { |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 bool PrefixSelector::GetTextFromRange(const gfx::Range& range, | 117 bool PrefixSelector::GetTextFromRange(const gfx::Range& range, |
118 string16* text) const { | 118 base::string16* text) const { |
119 return false; | 119 return false; |
120 } | 120 } |
121 | 121 |
122 void PrefixSelector::OnInputMethodChanged() { | 122 void PrefixSelector::OnInputMethodChanged() { |
123 ClearText(); | 123 ClearText(); |
124 } | 124 } |
125 | 125 |
126 bool PrefixSelector::ChangeTextDirectionAndLayoutAlignment( | 126 bool PrefixSelector::ChangeTextDirectionAndLayoutAlignment( |
127 base::i18n::TextDirection direction) { | 127 base::i18n::TextDirection direction) { |
128 return true; | 128 return true; |
129 } | 129 } |
130 | 130 |
131 void PrefixSelector::ExtendSelectionAndDelete(size_t before, size_t after) { | 131 void PrefixSelector::ExtendSelectionAndDelete(size_t before, size_t after) { |
132 } | 132 } |
133 | 133 |
134 void PrefixSelector::EnsureCaretInRect(const gfx::Rect& rect) { | 134 void PrefixSelector::EnsureCaretInRect(const gfx::Rect& rect) { |
135 } | 135 } |
136 | 136 |
137 void PrefixSelector::OnCandidateWindowShown() { | 137 void PrefixSelector::OnCandidateWindowShown() { |
138 } | 138 } |
139 | 139 |
140 void PrefixSelector::OnCandidateWindowUpdated() { | 140 void PrefixSelector::OnCandidateWindowUpdated() { |
141 } | 141 } |
142 | 142 |
143 void PrefixSelector::OnCandidateWindowHidden() { | 143 void PrefixSelector::OnCandidateWindowHidden() { |
144 } | 144 } |
145 | 145 |
146 void PrefixSelector::OnTextInput(const string16& text) { | 146 void PrefixSelector::OnTextInput(const base::string16& text) { |
147 // Small hack to filter out 'tab' and 'enter' input, as the expectation is | 147 // Small hack to filter out 'tab' and 'enter' input, as the expectation is |
148 // that they are control characters and will not affect the currently-active | 148 // that they are control characters and will not affect the currently-active |
149 // prefix. | 149 // prefix. |
150 if (text.length() == 1 && | 150 if (text.length() == 1 && |
151 (text[0] == L'\t' || text[0] == L'\r' || text[0] == L'\n')) | 151 (text[0] == L'\t' || text[0] == L'\r' || text[0] == L'\n')) |
152 return; | 152 return; |
153 | 153 |
154 const int row_count = prefix_delegate_->GetRowCount(); | 154 const int row_count = prefix_delegate_->GetRowCount(); |
155 if (row_count == 0) | 155 if (row_count == 0) |
156 return; | 156 return; |
157 | 157 |
158 // Search for |text| if it has been a while since the user typed, otherwise | 158 // Search for |text| if it has been a while since the user typed, otherwise |
159 // append |text| to |current_text_| and search for that. If it has been a | 159 // append |text| to |current_text_| and search for that. If it has been a |
160 // while search after the current row, otherwise search starting from the | 160 // while search after the current row, otherwise search starting from the |
161 // current row. | 161 // current row. |
162 int row = std::max(0, prefix_delegate_->GetSelectedRow()); | 162 int row = std::max(0, prefix_delegate_->GetSelectedRow()); |
163 const base::TimeTicks now(base::TimeTicks::Now()); | 163 const base::TimeTicks now(base::TimeTicks::Now()); |
164 if ((now - time_of_last_key_).InMilliseconds() < kTimeBeforeClearingMS) { | 164 if ((now - time_of_last_key_).InMilliseconds() < kTimeBeforeClearingMS) { |
165 current_text_ += text; | 165 current_text_ += text; |
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 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, current_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 string16& lower_text) { | 185 const base::string16& lower_text) { |
186 const 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 |