Index: views/controls/textfield/textfield_model.cc |
diff --git a/views/controls/textfield/textfield_model.cc b/views/controls/textfield/textfield_model.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a4982a1f491fe19f1a258a7a5884a643cd014779 |
--- /dev/null |
+++ b/views/controls/textfield/textfield_model.cc |
@@ -0,0 +1,84 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "views/controls/textfield/textfield_model.h" |
+ |
+namespace views { |
+ |
+TextfieldModel::TextfieldModel() |
+ : text_(L""), |
+ dirty_(true) { |
+ this->buffer_.reset(new base::GapBuffer<wchar_t>(50)); |
tfarina
2010/11/18 11:55:31
Please, remove all the usages of |this->| in this
|
+} |
+ |
+TextfieldModel::TextfieldModel(const std::wstring& text) |
+ : text_(L""), |
+ dirty_(true) { |
+ scoped_array<wchar_t> text_array; |
+ text_array.reset(new wchar_t[text.length()]); |
+ this->buffer_.reset(new base::GapBuffer<wchar_t>(text.data(), text.length())); |
+} |
+ |
+void TextfieldModel::Insert(wchar_t c) { |
+ buffer_->InsertAtGapStart(c); |
+ dirty_ = true; |
+} |
+ |
+wchar_t TextfieldModel::InsertDelete() { |
+ dirty_ = true; |
+ return buffer_->RemoveFromGapEnd(); |
+} |
+ |
+wchar_t TextfieldModel::InsertBackspace() { |
+ dirty_ = true; |
+ return buffer_->RemoveFromGapStart(); |
+} |
+ |
+int TextfieldModel::GetCurrentCursorPos() { |
+ return buffer_->GetGapStart(); |
+} |
+ |
+void TextfieldModel::MoveCursorLeft() { |
+ buffer_->MoveGapLeft(1); |
tfarina
2010/11/18 11:55:31
extract this constant? You can put it before the n
|
+} |
+ |
+void TextfieldModel::MoveCursorRight() { |
+ buffer_->MoveGapRight(1); |
+} |
+ |
+void TextfieldModel::MoveCursorToPreviousWord() { |
+ buffer_->MoveGapLeft(1); |
+ buffer_->MoveGapLeftTo(' '); |
+} |
+ |
+void TextfieldModel::MoveCursorToNextWord() { |
+ buffer_->MoveGapRightTo(' '); |
+} |
+ |
+void TextfieldModel::MoveCursorToStart() { |
+ buffer_->MoveGapLeft(buffer_->GetCurrentSize()); |
+} |
+ |
+void TextfieldModel::MoveCursorToEnd() { |
+ buffer_->MoveGapRight(buffer_->GetCurrentSize()); |
+} |
+ |
+std::wstring TextfieldModel::text() { |
+ if (dirty_) { |
+ SyncText(); |
+ dirty_ = false; |
+ } |
+ return text_; |
+} |
+ |
+void TextfieldModel::SyncText() { |
+ std::vector<wchar_t> contents; |
+ buffer_->GetContents(&contents); |
+ std::vector<wchar_t>::const_iterator iter; |
tfarina
2010/11/18 11:55:31
Can you move this inside the for loop ?
|
+ text_ = L""; |
tfarina
2010/11/18 11:55:31
text_.clear() instead?
|
+ for (iter = contents.begin(); iter != contents.end(); iter++) { |
tfarina
2010/11/18 11:55:31
++iter
|
+ text_ += (*iter); |
+ } |
+} |
+}; |
tfarina
2010/11/18 11:55:31
Please add a blank line above.
// namespace views
|