Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1490)

Side by Side Diff: views/controls/textfield/textfield_model.h

Issue 3142008: Model, View and Controller for a Gap Buffer based one line text field in view... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: added files that were missed in the last patch Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
7 #pragma once
8
9 #include <string>
10 #include <vector>
tfarina 2010/11/18 11:55:31 It seems you don't need this include also.
11
12 #include "base/gap_buffer.h"
13 #include "views/event.h"
tfarina 2010/11/18 11:55:31 It seems you don't need this include here.
14
15 namespace views {
16
17 // Model for a single line textfield. It uses a gap buffer under the hood to
18 // store data and perform cursor movement.
19 class TextfieldModel {
20 public:
21 TextfieldModel();
22 explicit TextfieldModel(const std::wstring& text);
23
24 // Inserts a character at the current cursor position.
25 void Insert(wchar_t c);
26
27 // Deletes the first character after the current cursor position (as if, the
28 // the user has pressed delete key in the textfield).
29 wchar_t InsertDelete();
30
31 // Deletes the first character before the current cursor position (as if, the
32 // the user has pressed backspace key in the textfield).
33 wchar_t InsertBackspace();
34
35 // Returns the current cursor position.
36 int GetCurrentCursorPos();
37
38 // Moves the cursor left by one position (as if, the user has pressed the left
39 // arrow key).
40 void MoveCursorLeft();
41
42 // Moves the cursor right by one position (as if, the user has pressed the
43 // right arrow key).
44 void MoveCursorRight();
45
46 // Moves the cursor left by one word (word boundry is defined by space).
47 void MoveCursorToPreviousWord();
48
49 // Moves the cursor right by one word (word boundry is defined by space).
50 void MoveCursorToNextWord();
51
52 // Moves the cursor to start of the textfield contents.
53 void MoveCursorToStart();
54
55 // Moves the cursor to end of the textfield contents.
56 void MoveCursorToEnd();
57
58 // Returns the current contents of the textfield model.
59 std::wstring text();
tfarina 2010/11/18 11:55:31 Since this is not a trivial getter, can you name t
60
61 private:
62 // Synchronizes this model's member field "text_" with the contents of the
63 // underlying gap buffer. The need for synchronization is determined by the
64 // "dirty_" flag.
65 void SyncText();
66
67 scoped_ptr<base::GapBuffer<wchar_t> > buffer_;
68 std::wstring text_;
69 bool dirty_;
70 };
tfarina 2010/11/18 11:55:31 DISALLOW_COPY_AND_ASSIGN?
71
72 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
73 public:
74 virtual ~TextfieldController();
tfarina 2010/11/18 11:55:31 add a {} here?
75 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
76 };
77 };
tfarina 2010/11/18 11:55:31 // namespace views Also don't need the ; here
78 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698