OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/controls/textfield/textfield_views_model.h" | 5 #include "views/controls/textfield/textfield_views_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/i18n/break_iterator.h" | 9 #include "base/i18n/break_iterator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 string16 TextfieldViewsModel::GetSelectedText() const { | 217 string16 TextfieldViewsModel::GetSelectedText() const { |
218 return text_.substr( | 218 return text_.substr( |
219 std::min(cursor_pos_, selection_begin_), | 219 std::min(cursor_pos_, selection_begin_), |
220 std::abs(static_cast<long>(cursor_pos_ - selection_begin_))); | 220 std::abs(static_cast<long>(cursor_pos_ - selection_begin_))); |
221 } | 221 } |
222 | 222 |
223 void TextfieldViewsModel::GetSelectedRange(TextRange* range) const { | 223 void TextfieldViewsModel::GetSelectedRange(TextRange* range) const { |
224 range->SetRange(selection_begin_, cursor_pos_); | 224 range->SetRange(cursor_pos_, selection_begin_); |
225 } | 225 } |
226 | 226 |
227 void TextfieldViewsModel::SelectRange(const TextRange& range) { | 227 void TextfieldViewsModel::SelectRange(const TextRange& range) { |
228 selection_begin_ = GetSafePosition(range.start()); | 228 selection_begin_ = GetSafePosition(range.end()); |
229 cursor_pos_ = GetSafePosition(range.end()); | 229 cursor_pos_ = GetSafePosition(range.start()); |
230 } | 230 } |
231 | 231 |
232 void TextfieldViewsModel::SelectAll() { | 232 void TextfieldViewsModel::SelectAll() { |
233 cursor_pos_ = 0; | 233 cursor_pos_ = 0; |
234 selection_begin_ = text_.length(); | 234 selection_begin_ = text_.length(); |
235 } | 235 } |
236 | 236 |
237 void TextfieldViewsModel::ClearSelection() { | 237 void TextfieldViewsModel::ClearSelection() { |
238 selection_begin_ = cursor_pos_; | 238 selection_begin_ = cursor_pos_; |
239 } | 239 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 size_t TextfieldViewsModel::GetSafePosition(size_t position) const { | 294 size_t TextfieldViewsModel::GetSafePosition(size_t position) const { |
295 if (position > text_.length()) { | 295 if (position > text_.length()) { |
296 return text_.length(); | 296 return text_.length(); |
297 } | 297 } |
298 return position; | 298 return position; |
299 } | 299 } |
300 | 300 |
301 } // namespace views | 301 } // namespace views |
OLD | NEW |