Index: views/controls/textfield/textfield_model.h |
diff --git a/views/controls/textfield/textfield_model.h b/views/controls/textfield/textfield_model.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..98a02376c9c82f8d61b9d3b40c3904bb0489e779 |
--- /dev/null |
+++ b/views/controls/textfield/textfield_model.h |
@@ -0,0 +1,78 @@ |
+// 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. |
+ |
+#ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
+#define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
+#pragma once |
+ |
+#include <string> |
+#include <vector> |
tfarina
2010/11/18 11:55:31
It seems you don't need this include also.
|
+ |
+#include "base/gap_buffer.h" |
+#include "views/event.h" |
tfarina
2010/11/18 11:55:31
It seems you don't need this include here.
|
+ |
+namespace views { |
+ |
+// Model for a single line textfield. It uses a gap buffer under the hood to |
+// store data and perform cursor movement. |
+class TextfieldModel { |
+ public: |
+ TextfieldModel(); |
+ explicit TextfieldModel(const std::wstring& text); |
+ |
+ // Inserts a character at the current cursor position. |
+ void Insert(wchar_t c); |
+ |
+ // Deletes the first character after the current cursor position (as if, the |
+ // the user has pressed delete key in the textfield). |
+ wchar_t InsertDelete(); |
+ |
+ // Deletes the first character before the current cursor position (as if, the |
+ // the user has pressed backspace key in the textfield). |
+ wchar_t InsertBackspace(); |
+ |
+ // Returns the current cursor position. |
+ int GetCurrentCursorPos(); |
+ |
+ // Moves the cursor left by one position (as if, the user has pressed the left |
+ // arrow key). |
+ void MoveCursorLeft(); |
+ |
+ // Moves the cursor right by one position (as if, the user has pressed the |
+ // right arrow key). |
+ void MoveCursorRight(); |
+ |
+ // Moves the cursor left by one word (word boundry is defined by space). |
+ void MoveCursorToPreviousWord(); |
+ |
+ // Moves the cursor right by one word (word boundry is defined by space). |
+ void MoveCursorToNextWord(); |
+ |
+ // Moves the cursor to start of the textfield contents. |
+ void MoveCursorToStart(); |
+ |
+ // Moves the cursor to end of the textfield contents. |
+ void MoveCursorToEnd(); |
+ |
+ // Returns the current contents of the textfield model. |
+ std::wstring text(); |
tfarina
2010/11/18 11:55:31
Since this is not a trivial getter, can you name t
|
+ |
+ private: |
+ // Synchronizes this model's member field "text_" with the contents of the |
+ // underlying gap buffer. The need for synchronization is determined by the |
+ // "dirty_" flag. |
+ void SyncText(); |
+ |
+ scoped_ptr<base::GapBuffer<wchar_t> > buffer_; |
+ std::wstring text_; |
+ bool dirty_; |
+}; |
tfarina
2010/11/18 11:55:31
DISALLOW_COPY_AND_ASSIGN?
|
+ |
+class TextfieldController { |
tfarina
2010/11/18 11:55:31
Can you name this TextfieldDelegate or even Textfi
tfarina
2010/11/18 11:55:31
I'd also move this above, before the TextfieldMode
Ben Goodger (Google)
2010/11/18 15:52:45
TextfieldDelegate doesn't make sense... it's not d
|
+ public: |
+ virtual ~TextfieldController(); |
tfarina
2010/11/18 11:55:31
add a {} here?
|
+ virtual void TextChanged(const std::wstring new_text); |
tfarina
2010/11/18 11:55:31
It looks like this class is an interface. I think
|
+}; |
+}; |
tfarina
2010/11/18 11:55:31
// namespace views
Also don't need the ; here
|
+#endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |