OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 protected: | 58 protected: |
59 virtual ~Delegate(); | 59 virtual ~Delegate(); |
60 }; | 60 }; |
61 | 61 |
62 explicit TextfieldViewsModel(Delegate* delegate); | 62 explicit TextfieldViewsModel(Delegate* delegate); |
63 virtual ~TextfieldViewsModel(); | 63 virtual ~TextfieldViewsModel(); |
64 | 64 |
65 // Edit related methods. | 65 // Edit related methods. |
66 | 66 |
67 const string16& GetText() const; | 67 const base::string16& GetText() const; |
68 // Sets the text. Returns true if the text has been modified. The | 68 // Sets the text. Returns true if the text has been modified. The |
69 // current composition text will be confirmed first. Setting | 69 // current composition text will be confirmed first. Setting |
70 // the same text will not add edit history because it's not user | 70 // the same text will not add edit history because it's not user |
71 // visible change nor user-initiated change. This allow a client | 71 // visible change nor user-initiated change. This allow a client |
72 // code to set the same text multiple times without worrying about | 72 // code to set the same text multiple times without worrying about |
73 // messing edit history. | 73 // messing edit history. |
74 bool SetText(const string16& text); | 74 bool SetText(const base::string16& text); |
75 | 75 |
76 gfx::RenderText* render_text() { return render_text_.get(); } | 76 gfx::RenderText* render_text() { return render_text_.get(); } |
77 | 77 |
78 // Inserts given |text| at the current cursor position. | 78 // Inserts given |text| at the current cursor position. |
79 // The current composition text will be cleared. | 79 // The current composition text will be cleared. |
80 void InsertText(const string16& text) { | 80 void InsertText(const base::string16& text) { |
81 InsertTextInternal(text, false); | 81 InsertTextInternal(text, false); |
82 } | 82 } |
83 | 83 |
84 // Inserts a character at the current cursor position. | 84 // Inserts a character at the current cursor position. |
85 void InsertChar(char16 c) { | 85 void InsertChar(char16 c) { |
86 InsertTextInternal(string16(&c, 1), true); | 86 InsertTextInternal(base::string16(&c, 1), true); |
87 } | 87 } |
88 | 88 |
89 // Replaces characters at the current position with characters in given text. | 89 // Replaces characters at the current position with characters in given text. |
90 // The current composition text will be cleared. | 90 // The current composition text will be cleared. |
91 void ReplaceText(const string16& text) { | 91 void ReplaceText(const base::string16& text) { |
92 ReplaceTextInternal(text, false); | 92 ReplaceTextInternal(text, false); |
93 } | 93 } |
94 | 94 |
95 // Replaces the char at the current position with given character. | 95 // Replaces the char at the current position with given character. |
96 void ReplaceChar(char16 c) { | 96 void ReplaceChar(char16 c) { |
97 ReplaceTextInternal(string16(&c, 1), true); | 97 ReplaceTextInternal(base::string16(&c, 1), true); |
98 } | 98 } |
99 | 99 |
100 // Appends the text. | 100 // Appends the text. |
101 // The current composition text will be confirmed. | 101 // The current composition text will be confirmed. |
102 void Append(const string16& text); | 102 void Append(const base::string16& text); |
103 | 103 |
104 // Deletes the first character after the current cursor position (as if, the | 104 // Deletes the first character after the current cursor position (as if, the |
105 // the user has pressed delete key in the textfield). Returns true if | 105 // the user has pressed delete key in the textfield). Returns true if |
106 // the deletion is successful. | 106 // the deletion is successful. |
107 // If there is composition text, it'll be deleted instead. | 107 // If there is composition text, it'll be deleted instead. |
108 bool Delete(); | 108 bool Delete(); |
109 | 109 |
110 // Deletes the first character before the current cursor position (as if, the | 110 // Deletes the first character before the current cursor position (as if, the |
111 // the user has pressed backspace key in the textfield). Returns true if | 111 // the user has pressed backspace key in the textfield). Returns true if |
112 // the removal is successful. | 112 // the removal is successful. |
(...skipping 16 matching lines...) Expand all Loading... |
129 // selection range, and it overrides the selection_start to which the | 129 // selection range, and it overrides the selection_start to which the |
130 // selection will move to. | 130 // selection will move to. |
131 bool MoveCursorTo(const gfx::SelectionModel& selection); | 131 bool MoveCursorTo(const gfx::SelectionModel& selection); |
132 | 132 |
133 // Helper function to call MoveCursorTo on the TextfieldViewsModel. | 133 // Helper function to call MoveCursorTo on the TextfieldViewsModel. |
134 bool MoveCursorTo(const gfx::Point& point, bool select); | 134 bool MoveCursorTo(const gfx::Point& point, bool select); |
135 | 135 |
136 // Selection related method | 136 // Selection related method |
137 | 137 |
138 // Returns the selected text. | 138 // Returns the selected text. |
139 string16 GetSelectedText() const; | 139 base::string16 GetSelectedText() const; |
140 | 140 |
141 // The current composition text will be confirmed. The selection starts with | 141 // The current composition text will be confirmed. The selection starts with |
142 // the range's start position, and ends with the range's end position, | 142 // the range's start position, and ends with the range's end position, |
143 // therefore the cursor position becomes the end position. | 143 // therefore the cursor position becomes the end position. |
144 void SelectRange(const gfx::Range& range); | 144 void SelectRange(const gfx::Range& range); |
145 | 145 |
146 // The current composition text will be confirmed. | 146 // The current composition text will be confirmed. |
147 // render_text_'s selection model is set to |sel|. | 147 // render_text_'s selection model is set to |sel|. |
148 void SelectSelectionModel(const gfx::SelectionModel& sel); | 148 void SelectSelectionModel(const gfx::SelectionModel& sel); |
149 | 149 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // text. | 191 // text. |
192 bool HasSelection() const; | 192 bool HasSelection() const; |
193 | 193 |
194 // Deletes the selected text. This method shouldn't be called with | 194 // Deletes the selected text. This method shouldn't be called with |
195 // composition text. | 195 // composition text. |
196 void DeleteSelection(); | 196 void DeleteSelection(); |
197 | 197 |
198 // Deletes the selected text (if any) and insert text at given | 198 // Deletes the selected text (if any) and insert text at given |
199 // position. | 199 // position. |
200 void DeleteSelectionAndInsertTextAt( | 200 void DeleteSelectionAndInsertTextAt( |
201 const string16& text, size_t position); | 201 const base::string16& text, size_t position); |
202 | 202 |
203 // Retrieves the text content in a given range. | 203 // Retrieves the text content in a given range. |
204 string16 GetTextFromRange(const gfx::Range& range) const; | 204 base::string16 GetTextFromRange(const gfx::Range& range) const; |
205 | 205 |
206 // Retrieves the range containing all text in the model. | 206 // Retrieves the range containing all text in the model. |
207 void GetTextRange(gfx::Range* range) const; | 207 void GetTextRange(gfx::Range* range) const; |
208 | 208 |
209 // Sets composition text and attributes. If there is composition text already, | 209 // Sets composition text and attributes. If there is composition text already, |
210 // it'll be replaced by the new one. Otherwise, current selection will be | 210 // it'll be replaced by the new one. Otherwise, current selection will be |
211 // replaced. If there is no selection, the composition text will be inserted | 211 // replaced. If there is no selection, the composition text will be inserted |
212 // at the insertion point. | 212 // at the insertion point. |
213 // Any changes to the model except text insertion will confirm the current | 213 // Any changes to the model except text insertion will confirm the current |
214 // composition text. | 214 // composition text. |
(...skipping 19 matching lines...) Expand all Loading... |
234 friend class UndoRedo_CutCopyPasteTest; | 234 friend class UndoRedo_CutCopyPasteTest; |
235 friend class UndoRedo_ReplaceTest; | 235 friend class UndoRedo_ReplaceTest; |
236 friend class internal::Edit; | 236 friend class internal::Edit; |
237 | 237 |
238 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_BasicTest); | 238 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_BasicTest); |
239 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest); | 239 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest); |
240 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_ReplaceTest); | 240 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_ReplaceTest); |
241 | 241 |
242 // Insert the given |text|. |mergeable| indicates if this insert | 242 // Insert the given |text|. |mergeable| indicates if this insert |
243 // operation can be merged to previous edit in the edit history. | 243 // operation can be merged to previous edit in the edit history. |
244 void InsertTextInternal(const string16& text, bool mergeable); | 244 void InsertTextInternal(const base::string16& text, bool mergeable); |
245 | 245 |
246 // Replace the current text with the given |text|. |mergeable| | 246 // Replace the current text with the given |text|. |mergeable| |
247 // indicates if this replace operation can be merged to previous | 247 // indicates if this replace operation can be merged to previous |
248 // edit in the edit history. | 248 // edit in the edit history. |
249 void ReplaceTextInternal(const string16& text, bool mergeable); | 249 void ReplaceTextInternal(const base::string16& text, bool mergeable); |
250 | 250 |
251 // Clears all edit history. | 251 // Clears all edit history. |
252 void ClearEditHistory(); | 252 void ClearEditHistory(); |
253 | 253 |
254 // Clears redo history. | 254 // Clears redo history. |
255 void ClearRedoHistory(); | 255 void ClearRedoHistory(); |
256 | 256 |
257 // Executes and records edit operations. | 257 // Executes and records edit operations. |
258 void ExecuteAndRecordDelete(gfx::Range range, bool mergeable); | 258 void ExecuteAndRecordDelete(gfx::Range range, bool mergeable); |
259 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, | 259 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, |
260 const string16& text); | 260 const base::string16& text); |
261 void ExecuteAndRecordReplace(internal::MergeType merge_type, | 261 void ExecuteAndRecordReplace(internal::MergeType merge_type, |
262 size_t old_cursor_pos, | 262 size_t old_cursor_pos, |
263 size_t new_cursor_pos, | 263 size_t new_cursor_pos, |
264 const string16& text, | 264 const base::string16& text, |
265 size_t new_text_start); | 265 size_t new_text_start); |
266 void ExecuteAndRecordInsert(const string16& text, bool mergeable); | 266 void ExecuteAndRecordInsert(const base::string16& text, bool mergeable); |
267 | 267 |
268 // Adds or merge |edit| into edit history. Return true if the edit | 268 // Adds or merge |edit| into edit history. Return true if the edit |
269 // has been merged and must be deleted after redo. | 269 // has been merged and must be deleted after redo. |
270 bool AddOrMergeEditHistory(internal::Edit* edit); | 270 bool AddOrMergeEditHistory(internal::Edit* edit); |
271 | 271 |
272 // Modify the text buffer in following way: | 272 // Modify the text buffer in following way: |
273 // 1) Delete the string from |delete_from| to |delte_to|. | 273 // 1) Delete the string from |delete_from| to |delte_to|. |
274 // 2) Insert the |new_text| at the index |new_text_insert_at|. | 274 // 2) Insert the |new_text| at the index |new_text_insert_at|. |
275 // Note that the index is after deletion. | 275 // Note that the index is after deletion. |
276 // 3) Move the cursor to |new_cursor_pos|. | 276 // 3) Move the cursor to |new_cursor_pos|. |
277 void ModifyText(size_t delete_from, | 277 void ModifyText(size_t delete_from, |
278 size_t delete_to, | 278 size_t delete_to, |
279 const string16& new_text, | 279 const base::string16& new_text, |
280 size_t new_text_insert_at, | 280 size_t new_text_insert_at, |
281 size_t new_cursor_pos); | 281 size_t new_cursor_pos); |
282 | 282 |
283 void ClearComposition(); | 283 void ClearComposition(); |
284 | 284 |
285 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by | 285 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by |
286 // the View object. | 286 // the View object. |
287 Delegate* delegate_; | 287 Delegate* delegate_; |
288 | 288 |
289 // The stylized text, cursor, selection, and the visual layout model. | 289 // The stylized text, cursor, selection, and the visual layout model. |
(...skipping 14 matching lines...) Expand all Loading... |
304 // 2) new edit is added. (redo history is cleared) | 304 // 2) new edit is added. (redo history is cleared) |
305 // 3) redone all undone edits. | 305 // 3) redone all undone edits. |
306 EditHistory::iterator current_edit_; | 306 EditHistory::iterator current_edit_; |
307 | 307 |
308 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 308 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
309 }; | 309 }; |
310 | 310 |
311 } // namespace views | 311 } // namespace views |
312 | 312 |
313 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 313 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
OLD | NEW |