| 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/native_theme.h" | 19 #include "ui/base/native_theme/native_theme.h" |
| 20 #include "ui/gfx/render_text.h" | 20 #include "ui/gfx/render_text.h" |
| 21 #include "ui/views/controls/textfield/textfield.h" | 21 #include "ui/views/controls/textfield/textfield.h" |
| 22 #include "ui/views/views_delegate.h" | 22 #include "ui/views/views_delegate.h" |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 | 25 |
| 26 namespace internal { | 26 namespace internal { |
| 27 | 27 |
| 28 // An edit object holds enough information/state to undo/redo the | 28 // An edit object holds enough information/state to undo/redo the |
| 29 // change. Two edits are merged when possible, for example, when | 29 // change. Two edits are merged when possible, for example, when |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 ///////////////////////////////////////////////////////////////// | 277 ///////////////////////////////////////////////////////////////// |
| 278 // TextfieldViewsModel: public | 278 // TextfieldViewsModel: public |
| 279 | 279 |
| 280 TextfieldViewsModel::Delegate::~Delegate() { | 280 TextfieldViewsModel::Delegate::~Delegate() { |
| 281 } | 281 } |
| 282 | 282 |
| 283 TextfieldViewsModel::TextfieldViewsModel(Delegate* delegate) | 283 TextfieldViewsModel::TextfieldViewsModel(Delegate* delegate) |
| 284 : delegate_(delegate), | 284 : delegate_(delegate), |
| 285 render_text_(gfx::RenderText::CreateRenderText()), | 285 render_text_(gfx::RenderText::CreateRenderText()), |
| 286 current_edit_(edit_history_.end()) { | 286 current_edit_(edit_history_.end()) { |
| 287 const gfx::NativeTheme* theme = gfx::NativeTheme::instance(); | 287 const ui::NativeTheme* theme = ui::NativeTheme::instance(); |
| 288 render_text_->set_selection_color( | 288 render_text_->set_selection_color( |
| 289 theme->GetSystemColor( | 289 theme->GetSystemColor( |
| 290 gfx::NativeTheme::kColorId_TextfieldSelectionColor)); | 290 ui::NativeTheme::kColorId_TextfieldSelectionColor)); |
| 291 render_text_->set_selection_background_focused_color( | 291 render_text_->set_selection_background_focused_color( |
| 292 theme->GetSystemColor( | 292 theme->GetSystemColor( |
| 293 gfx::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); | 293 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); |
| 294 render_text_->set_selection_background_unfocused_color( | 294 render_text_->set_selection_background_unfocused_color( |
| 295 theme->GetSystemColor( | 295 theme->GetSystemColor( |
| 296 gfx::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); | 296 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); |
| 297 } | 297 } |
| 298 | 298 |
| 299 TextfieldViewsModel::~TextfieldViewsModel() { | 299 TextfieldViewsModel::~TextfieldViewsModel() { |
| 300 ClearEditHistory(); | 300 ClearEditHistory(); |
| 301 ClearComposition(); | 301 ClearComposition(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 const string16& TextfieldViewsModel::GetText() const { | 304 const string16& TextfieldViewsModel::GetText() const { |
| 305 return render_text_->text(); | 305 return render_text_->text(); |
| 306 } | 306 } |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 if (delete_from != delete_to) | 779 if (delete_from != delete_to) |
| 780 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); | 780 render_text_->SetText(text.erase(delete_from, delete_to - delete_from)); |
| 781 if (!new_text.empty()) | 781 if (!new_text.empty()) |
| 782 render_text_->SetText(text.insert(new_text_insert_at, new_text)); | 782 render_text_->SetText(text.insert(new_text_insert_at, new_text)); |
| 783 render_text_->SetCursorPosition(new_cursor_pos); | 783 render_text_->SetCursorPosition(new_cursor_pos); |
| 784 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). | 784 // TODO(oshima): mac selects the text that is just undone (but gtk doesn't). |
| 785 // This looks fine feature and we may want to do the same. | 785 // This looks fine feature and we may want to do the same. |
| 786 } | 786 } |
| 787 | 787 |
| 788 } // namespace views | 788 } // namespace views |
| OLD | NEW |