| Index: views/controls/textfield/textfield_model.cc
|
| ===================================================================
|
| --- views/controls/textfield/textfield_model.cc (revision 0)
|
| +++ views/controls/textfield/textfield_model.cc (revision 0)
|
| @@ -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));
|
| +}
|
| +
|
| +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);
|
| +}
|
| +
|
| +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;
|
| + text_ = L"";
|
| + for (iter = contents.begin(); iter != contents.end(); iter++) {
|
| + text_ += (*iter);
|
| + }
|
| +}
|
| +};
|
|
|
| Property changes on: views/controls/textfield/textfield_model.cc
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|