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 DONT_MERGE, | |
|
msw
2011/06/02 10:16:42
nit: rename DO_NOT_MERGE, the DONT contraction wit
oshima
2011/06/02 19:11:42
Done.
| |
| 40 MERGEABLE, | |
| 41 MERGE_WITH_PREVIOUS, | |
| 42 }; | |
| 43 | |
| 37 } // namespace internal | 44 } // namespace internal |
| 38 | 45 |
| 39 typedef std::vector<internal::TextStyleRange*> TextStyleRanges; | 46 typedef std::vector<internal::TextStyleRange*> TextStyleRanges; |
| 40 | 47 |
| 41 // A model that represents a text content for TextfieldViews. | 48 // A model that represents a text content for TextfieldViews. |
| 42 // It supports editing, selection and cursor manipulation. | 49 // It supports editing, selection and cursor manipulation. |
| 43 class TextfieldViewsModel { | 50 class TextfieldViewsModel { |
| 44 public: | 51 public: |
| 45 | 52 |
| 46 // Delegate interface implemented by the textfield view class to provided | 53 // 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); | 313 void ReplaceTextInternal(const string16& text, bool mergeable); |
| 307 | 314 |
| 308 // Clears all edit history. | 315 // Clears all edit history. |
| 309 void ClearEditHistory(); | 316 void ClearEditHistory(); |
| 310 | 317 |
| 311 // Clears redo history. | 318 // Clears redo history. |
| 312 void ClearRedoHistory(); | 319 void ClearRedoHistory(); |
| 313 | 320 |
| 314 // Executes and records edit operations. | 321 // Executes and records edit operations. |
| 315 void ExecuteAndRecordDelete(size_t from, size_t to, bool mergeable); | 322 void ExecuteAndRecordDelete(size_t from, size_t to, bool mergeable); |
| 316 void ExecuteAndRecordReplace(const string16& text, bool mergeable); | 323 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, |
| 317 void ExecuteAndRecordReplaceAt(const string16& text, | 324 const string16& text); |
| 318 size_t at, | 325 void ExecuteAndRecordReplace(internal::MergeType merge_type, |
| 319 bool mergeable); | 326 size_t old_cursor_pos, |
| 327 size_t new_cursor_pos, | |
| 328 const string16& text, | |
| 329 size_t new_text_start); | |
| 320 void ExecuteAndRecordInsert(const string16& text, bool mergeable); | 330 void ExecuteAndRecordInsert(const string16& text, bool mergeable); |
| 321 | 331 |
| 322 // Adds or merge |edit| into edit history. Return true if the edit | 332 // Adds or merge |edit| into edit history. Return true if the edit |
| 323 // has been merged and must be deleted after redo. | 333 // has been merged and must be deleted after redo. |
| 324 bool AddOrMergeEditHistory(internal::Edit* edit); | 334 bool AddOrMergeEditHistory(internal::Edit* edit); |
| 325 | 335 |
| 326 // Modify the text buffer in following way: | 336 // Modify the text buffer in following way: |
| 327 // 1) Delete the string from |delete_from| to |delte_to|. | 337 // 1) Delete the string from |delete_from| to |delte_to|. |
| 328 // 2) Insert the |new_text| at the index |new_text_insert_at|. | 338 // 2) Insert the |new_text| at the index |new_text_insert_at|. |
| 329 // Note that the index is after deletion. | 339 // Note that the index is after deletion. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 | 398 |
| 389 // List of style ranges for composition text. | 399 // List of style ranges for composition text. |
| 390 TextStyleRanges composition_style_ranges_; | 400 TextStyleRanges composition_style_ranges_; |
| 391 | 401 |
| 392 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 402 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
| 393 }; | 403 }; |
| 394 | 404 |
| 395 } // namespace views | 405 } // namespace views |
| 396 | 406 |
| 397 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 407 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| OLD | NEW |