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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 void TextfieldViewsModel::GetSelectedRange(TextRange* range) const { | 223 void TextfieldViewsModel::GetSelectedRange(TextRange* range) const { |
224 range->SetRange(selection_begin_, cursor_pos_); | 224 range->SetRange(selection_begin_, cursor_pos_); |
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.start()); |
229 cursor_pos_ = GetSafePosition(range.end()); | 229 cursor_pos_ = GetSafePosition(range.end()); |
230 } | 230 } |
231 | 231 |
232 void TextfieldViewsModel::SelectAll() { | 232 void TextfieldViewsModel::SelectAll() { |
233 cursor_pos_ = 0; | 233 // SelectAll selects towards the end. |
234 selection_begin_ = text_.length(); | 234 cursor_pos_ = text_.length(); |
| 235 selection_begin_ = 0; |
235 } | 236 } |
236 | 237 |
237 void TextfieldViewsModel::ClearSelection() { | 238 void TextfieldViewsModel::ClearSelection() { |
238 selection_begin_ = cursor_pos_; | 239 selection_begin_ = cursor_pos_; |
239 } | 240 } |
240 | 241 |
241 bool TextfieldViewsModel::Cut() { | 242 bool TextfieldViewsModel::Cut() { |
242 if (HasSelection()) { | 243 if (HasSelection()) { |
243 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate | 244 ui::ScopedClipboardWriter(views::ViewsDelegate::views_delegate |
244 ->GetClipboard()).WriteText(GetSelectedText()); | 245 ->GetClipboard()).WriteText(GetSelectedText()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 293 } |
293 | 294 |
294 size_t TextfieldViewsModel::GetSafePosition(size_t position) const { | 295 size_t TextfieldViewsModel::GetSafePosition(size_t position) const { |
295 if (position > text_.length()) { | 296 if (position > text_.length()) { |
296 return text_.length(); | 297 return text_.length(); |
297 } | 298 } |
298 return position; | 299 return position; |
299 } | 300 } |
300 | 301 |
301 } // namespace views | 302 } // namespace views |
OLD | NEW |