Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: views/controls/textfield/textfield_views_model.cc

Issue 6314012: Make uneditable when readonly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield.h ('k') | views/controls/textfield/textfield_views_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698