OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/controls/textfield/textfield_model.h" | |
6 | |
7 namespace views { | |
8 | |
9 TextfieldModel::TextfieldModel() | |
10 : text_(L""), | |
11 dirty_(true) { | |
12 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
| |
13 } | |
14 | |
15 TextfieldModel::TextfieldModel(const std::wstring& text) | |
16 : text_(L""), | |
17 dirty_(true) { | |
18 scoped_array<wchar_t> text_array; | |
19 text_array.reset(new wchar_t[text.length()]); | |
20 this->buffer_.reset(new base::GapBuffer<wchar_t>(text.data(), text.length())); | |
21 } | |
22 | |
23 void TextfieldModel::Insert(wchar_t c) { | |
24 buffer_->InsertAtGapStart(c); | |
25 dirty_ = true; | |
26 } | |
27 | |
28 wchar_t TextfieldModel::InsertDelete() { | |
29 dirty_ = true; | |
30 return buffer_->RemoveFromGapEnd(); | |
31 } | |
32 | |
33 wchar_t TextfieldModel::InsertBackspace() { | |
34 dirty_ = true; | |
35 return buffer_->RemoveFromGapStart(); | |
36 } | |
37 | |
38 int TextfieldModel::GetCurrentCursorPos() { | |
39 return buffer_->GetGapStart(); | |
40 } | |
41 | |
42 void TextfieldModel::MoveCursorLeft() { | |
43 buffer_->MoveGapLeft(1); | |
tfarina
2010/11/18 11:55:31
extract this constant? You can put it before the n
| |
44 } | |
45 | |
46 void TextfieldModel::MoveCursorRight() { | |
47 buffer_->MoveGapRight(1); | |
48 } | |
49 | |
50 void TextfieldModel::MoveCursorToPreviousWord() { | |
51 buffer_->MoveGapLeft(1); | |
52 buffer_->MoveGapLeftTo(' '); | |
53 } | |
54 | |
55 void TextfieldModel::MoveCursorToNextWord() { | |
56 buffer_->MoveGapRightTo(' '); | |
57 } | |
58 | |
59 void TextfieldModel::MoveCursorToStart() { | |
60 buffer_->MoveGapLeft(buffer_->GetCurrentSize()); | |
61 } | |
62 | |
63 void TextfieldModel::MoveCursorToEnd() { | |
64 buffer_->MoveGapRight(buffer_->GetCurrentSize()); | |
65 } | |
66 | |
67 std::wstring TextfieldModel::text() { | |
68 if (dirty_) { | |
69 SyncText(); | |
70 dirty_ = false; | |
71 } | |
72 return text_; | |
73 } | |
74 | |
75 void TextfieldModel::SyncText() { | |
76 std::vector<wchar_t> contents; | |
77 buffer_->GetContents(&contents); | |
78 std::vector<wchar_t>::const_iterator iter; | |
tfarina
2010/11/18 11:55:31
Can you move this inside the for loop ?
| |
79 text_ = L""; | |
tfarina
2010/11/18 11:55:31
text_.clear() instead?
| |
80 for (iter = contents.begin(); iter != contents.end(); iter++) { | |
tfarina
2010/11/18 11:55:31
++iter
| |
81 text_ += (*iter); | |
82 } | |
83 } | |
84 }; | |
tfarina
2010/11/18 11:55:31
Please add a blank line above.
// namespace views
| |
OLD | NEW |