OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/textfield/textfield_views_model.h" | 5 #include "ui/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" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "ui/base/clipboard/clipboard.h" | 13 #include "ui/base/clipboard/clipboard.h" |
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 14 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
15 #include "ui/base/range/range.h" | 15 #include "ui/base/range/range.h" |
16 #include "ui/base/text/utf16_indexing.h" | 16 #include "ui/base/text/utf16_indexing.h" |
17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/font.h" | 18 #include "ui/gfx/font.h" |
19 #include "ui/gfx/render_text.h" | 19 #include "ui/gfx/render_text.h" |
20 #include "ui/gfx/text_constants.h" | 20 #include "ui/gfx/text_constants.h" |
21 #include "ui/native_theme/native_theme.h" | |
22 #include "ui/views/controls/textfield/textfield.h" | 21 #include "ui/views/controls/textfield/textfield.h" |
23 | 22 |
24 namespace views { | 23 namespace views { |
25 | 24 |
26 namespace internal { | 25 namespace internal { |
27 | 26 |
28 // An edit object holds enough information/state to undo/redo the | 27 // An edit object holds enough information/state to undo/redo the |
29 // change. Two edits are merged when possible, for example, when | 28 // change. Two edits are merged when possible, for example, when |
30 // you type new characters in sequence. |Commit()| can be used to | 29 // you type new characters in sequence. |Commit()| can be used to |
31 // mark an edit as an independent edit and it shouldn't be merged. | 30 // mark an edit as an independent edit and it shouldn't be merged. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ///////////////////////////////////////////////////////////////// | 276 ///////////////////////////////////////////////////////////////// |
278 // TextfieldViewsModel: public | 277 // TextfieldViewsModel: public |
279 | 278 |
280 TextfieldViewsModel::Delegate::~Delegate() { | 279 TextfieldViewsModel::Delegate::~Delegate() { |
281 } | 280 } |
282 | 281 |
283 TextfieldViewsModel::TextfieldViewsModel(Delegate* delegate) | 282 TextfieldViewsModel::TextfieldViewsModel(Delegate* delegate) |
284 : delegate_(delegate), | 283 : delegate_(delegate), |
285 render_text_(gfx::RenderText::CreateInstance()), | 284 render_text_(gfx::RenderText::CreateInstance()), |
286 current_edit_(edit_history_.end()) { | 285 current_edit_(edit_history_.end()) { |
287 const ui::NativeTheme* theme = ui::NativeTheme::instance(); | |
288 render_text_->set_selection_color( | |
289 theme->GetSystemColor( | |
290 ui::NativeTheme::kColorId_TextfieldSelectionColor)); | |
291 render_text_->set_selection_background_focused_color( | |
292 theme->GetSystemColor( | |
293 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); | |
294 render_text_->set_selection_background_unfocused_color( | |
295 theme->GetSystemColor( | |
296 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); | |
297 } | 286 } |
298 | 287 |
299 TextfieldViewsModel::~TextfieldViewsModel() { | 288 TextfieldViewsModel::~TextfieldViewsModel() { |
300 ClearEditHistory(); | 289 ClearEditHistory(); |
301 ClearComposition(); | 290 ClearComposition(); |
302 } | 291 } |
303 | 292 |
304 const string16& TextfieldViewsModel::GetText() const { | 293 const string16& TextfieldViewsModel::GetText() const { |
305 return render_text_->text(); | 294 return render_text_->text(); |
306 } | 295 } |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 if (delete_from != delete_to) | 769 if (delete_from != delete_to) |
781 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 770 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
782 if (!new_text.empty()) | 771 if (!new_text.empty()) |
783 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 772 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
784 render_text_->SetCursorPosition(new_cursor_pos); | 773 render_text_->SetCursorPosition(new_cursor_pos); |
785 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 774 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
786 // This looks fine feature and we may want to do the same. | 775 // This looks fine feature and we may want to do the same. |
787 } | 776 } |
788 | 777 |
789 } // namespace views | 778 } // namespace views |
OLD | NEW |