Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 class TextStyle; | 28 class TextStyle; |
| 29 typedef std::vector<TextStyle*> TextStyles; | 29 typedef std::vector<TextStyle*> TextStyles; |
| 30 | 30 |
| 31 namespace internal { | 31 namespace internal { |
| 32 // Internal Edit class that keeps track of edits for undo/redo. | 32 // Internal Edit class that keeps track of edits for undo/redo. |
| 33 class Edit; | 33 class Edit; |
| 34 | 34 |
| 35 struct TextStyleRange; | 35 struct TextStyleRange; |
| 36 | 36 |
| 37 // C++ doesn't allow forward decl enum, so let's define here. | |
| 38 enum MergeType { | |
| 39 // The edit should not be merged with next edit. It still may | |
| 40 // be merged with an edit with MERGE_WITH_PREVIOUS. | |
| 41 DO_NOT_MERGE, // Never merge | |
|
msw
2011/06/02 21:02:57
nit: remove "never merge", the comment above is be
oshima
2011/06/03 00:39:24
Done.
| |
| 42 // The edit can be merged with next edit when possible. | |
| 43 MERGEABLE, | |
| 44 // Does the edit has to be merged with previous edit? | |
|
msw
2011/06/02 21:02:57
*have* to be
oshima
2011/06/03 00:39:24
Done.
| |
| 45 // This forces the merge even if the previous edit is marked | |
| 46 // as DO_NOT_MERGE. | |
| 47 MERGE_WITH_PREVIOUS, | |
| 48 }; | |
| 49 | |
| 37 } // namespace internal | 50 } // namespace internal |
| 38 | 51 |
| 39 typedef std::vector<internal::TextStyleRange*> TextStyleRanges; | 52 typedef std::vector<internal::TextStyleRange*> TextStyleRanges; |
| 40 | 53 |
| 41 // A model that represents a text content for TextfieldViews. | 54 // A model that represents a text content for TextfieldViews. |
| 42 // It supports editing, selection and cursor manipulation. | 55 // It supports editing, selection and cursor manipulation. |
| 43 class TextfieldViewsModel { | 56 class TextfieldViewsModel { |
| 44 public: | 57 public: |
| 45 | 58 |
| 46 // Delegate interface implemented by the textfield view class to provided | 59 // Delegate interface implemented by the textfield view class to provided |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 void ReplaceTextInternal(const string16& text, bool mergeable); | 319 void ReplaceTextInternal(const string16& text, bool mergeable); |
| 307 | 320 |
| 308 // Clears all edit history. | 321 // Clears all edit history. |
| 309 void ClearEditHistory(); | 322 void ClearEditHistory(); |
| 310 | 323 |
| 311 // Clears redo history. | 324 // Clears redo history. |
| 312 void ClearRedoHistory(); | 325 void ClearRedoHistory(); |
| 313 | 326 |
| 314 // Executes and records edit operations. | 327 // Executes and records edit operations. |
| 315 void ExecuteAndRecordDelete(size_t from, size_t to, bool mergeable); | 328 void ExecuteAndRecordDelete(size_t from, size_t to, bool mergeable); |
| 316 void ExecuteAndRecordReplace(const string16& text, bool mergeable); | 329 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, |
| 317 void ExecuteAndRecordReplaceAt(const string16& text, | 330 const string16& text); |
| 318 size_t at, | 331 void ExecuteAndRecordReplace(internal::MergeType merge_type, |
| 319 bool mergeable); | 332 size_t old_cursor_pos, |
| 333 size_t new_cursor_pos, | |
| 334 const string16& text, | |
| 335 size_t new_text_start); | |
| 320 void ExecuteAndRecordInsert(const string16& text, bool mergeable); | 336 void ExecuteAndRecordInsert(const string16& text, bool mergeable); |
| 321 | 337 |
| 322 // Adds or merge |edit| into edit history. Return true if the edit | 338 // Adds or merge |edit| into edit history. Return true if the edit |
| 323 // has been merged and must be deleted after redo. | 339 // has been merged and must be deleted after redo. |
| 324 bool AddOrMergeEditHistory(internal::Edit* edit); | 340 bool AddOrMergeEditHistory(internal::Edit* edit); |
| 325 | 341 |
| 326 // Modify the text buffer in following way: | 342 // Modify the text buffer in following way: |
| 327 // 1) Delete the string from |delete_from| to |delte_to|. | 343 // 1) Delete the string from |delete_from| to |delte_to|. |
| 328 // 2) Insert the |new_text| at the index |new_text_insert_at|. | 344 // 2) Insert the |new_text| at the index |new_text_insert_at|. |
| 329 // Note that the index is after deletion. | 345 // Note that the index is after deletion. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 | 404 |
| 389 // List of style ranges for composition text. | 405 // List of style ranges for composition text. |
| 390 TextStyleRanges composition_style_ranges_; | 406 TextStyleRanges composition_style_ranges_; |
| 391 | 407 |
| 392 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 408 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
| 393 }; | 409 }; |
| 394 | 410 |
| 395 } // namespace views | 411 } // namespace views |
| 396 | 412 |
| 397 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 413 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| OLD | NEW |