OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MODEL_H_ | 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ | 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::string16& new_text); | 260 const base::string16& new_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 base::string16& new_text, | 264 const base::string16& new_text, |
265 size_t new_text_start); | 265 size_t new_text_start); |
266 void ExecuteAndRecordInsert(const base::string16& new_text, bool mergeable); | 266 void ExecuteAndRecordInsert(const base::string16& new_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 ownership of the edit if the |
269 // has been merged and must be deleted after redo. | 269 // edit has been merged and must be deleted after redo. |
270 bool AddOrMergeEditHistory(internal::Edit* edit); | 270 std::unique_ptr<internal::Edit> AddOrMergeEditHistory( |
| 271 std::unique_ptr<internal::Edit> edit); |
271 | 272 |
272 // Modify the text buffer in following way: | 273 // Modify the text buffer in following way: |
273 // 1) Delete the string from |delete_from| to |delte_to|. | 274 // 1) Delete the string from |delete_from| to |delte_to|. |
274 // 2) Insert the |new_text| at the index |new_text_insert_at|. | 275 // 2) Insert the |new_text| at the index |new_text_insert_at|. |
275 // Note that the index is after deletion. | 276 // Note that the index is after deletion. |
276 // 3) Move the cursor to |new_cursor_pos|. | 277 // 3) Move the cursor to |new_cursor_pos|. |
277 void ModifyText(size_t delete_from, | 278 void ModifyText(size_t delete_from, |
278 size_t delete_to, | 279 size_t delete_to, |
279 const base::string16& new_text, | 280 const base::string16& new_text, |
280 size_t new_text_insert_at, | 281 size_t new_text_insert_at, |
281 size_t new_cursor_pos); | 282 size_t new_cursor_pos); |
282 | 283 |
283 void ClearComposition(); | 284 void ClearComposition(); |
284 | 285 |
285 // Clears the kill buffer. Used to clear global state between tests. | 286 // Clears the kill buffer. Used to clear global state between tests. |
286 static void ClearKillBuffer(); | 287 static void ClearKillBuffer(); |
287 | 288 |
288 // The TextfieldModel::Delegate instance should be provided by the owner. | 289 // The TextfieldModel::Delegate instance should be provided by the owner. |
289 Delegate* delegate_; | 290 Delegate* delegate_; |
290 | 291 |
291 // The stylized text, cursor, selection, and the visual layout model. | 292 // The stylized text, cursor, selection, and the visual layout model. |
292 std::unique_ptr<gfx::RenderText> render_text_; | 293 std::unique_ptr<gfx::RenderText> render_text_; |
293 | 294 |
294 // The composition range. | 295 // The composition range. |
295 gfx::Range composition_range_; | 296 gfx::Range composition_range_; |
296 | 297 |
297 typedef std::list<internal::Edit*> EditHistory; | 298 typedef std::list<std::unique_ptr<internal::Edit>> EditHistory; |
298 EditHistory edit_history_; | 299 EditHistory edit_history_; |
299 | 300 |
300 // An iterator that points to the current edit that can be undone. | 301 // An iterator that points to the current edit that can be undone. |
301 // This iterator moves from the |end()|, meaining no edit to undo, | 302 // This iterator moves from the |end()|, meaining no edit to undo, |
302 // to the last element (one before |end()|), meaning no edit to redo. | 303 // to the last element (one before |end()|), meaning no edit to redo. |
303 // | 304 // |
304 // There is no edit to undo (== end()) when: | 305 // There is no edit to undo (== end()) when: |
305 // 1) in initial state. (nothing to undo) | 306 // 1) in initial state. (nothing to undo) |
306 // 2) very 1st edit is undone. | 307 // 2) very 1st edit is undone. |
307 // 3) all edit history is removed. | 308 // 3) all edit history is removed. |
308 // There is no edit to redo (== last element or no element) when: | 309 // There is no edit to redo (== last element or no element) when: |
309 // 1) in initial state. (nothing to redo) | 310 // 1) in initial state. (nothing to redo) |
310 // 2) new edit is added. (redo history is cleared) | 311 // 2) new edit is added. (redo history is cleared) |
311 // 3) redone all undone edits. | 312 // 3) redone all undone edits. |
312 EditHistory::iterator current_edit_; | 313 EditHistory::iterator current_edit_; |
313 | 314 |
314 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); | 315 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); |
315 }; | 316 }; |
316 | 317 |
317 } // namespace views | 318 } // namespace views |
318 | 319 |
319 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ | 320 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
OLD | NEW |