| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Edit related methods. | 58 // Edit related methods. |
| 59 | 59 |
| 60 const base::string16& text() const { return render_text_->text(); } | 60 const base::string16& text() const { return render_text_->text(); } |
| 61 // Sets the text. Returns true if the text has been modified. The current | 61 // Sets the text. Returns true if the text has been modified. The current |
| 62 // composition text will be confirmed first. Setting the same text will not | 62 // composition text will be confirmed first. Setting the same text will not |
| 63 // add edit history because it's not user visible change nor user-initiated | 63 // add edit history because it's not user visible change nor user-initiated |
| 64 // change. This allow a client code to set the same text multiple times | 64 // change. This allow a client code to set the same text multiple times |
| 65 // without worrying about messing edit history. | 65 // without worrying about messing edit history. |
| 66 bool SetText(const base::string16& new_text); | 66 bool SetText(const base::string16& new_text); |
| 67 | 67 |
| 68 gfx::RenderText* render_text() { return render_text_.get(); } | 68 gfx::RenderText* render_text() const { return render_text_.get(); } |
| 69 | 69 |
| 70 // Inserts given |new_text| at the current cursor position. | 70 // Inserts given |new_text| at the current cursor position. |
| 71 // The current composition text will be cleared. | 71 // The current composition text will be cleared. |
| 72 void InsertText(const base::string16& new_text) { | 72 void InsertText(const base::string16& new_text) { |
| 73 InsertTextInternal(new_text, false); | 73 InsertTextInternal(new_text, false); |
| 74 } | 74 } |
| 75 | 75 |
| 76 // Inserts a character at the current cursor position. | 76 // Inserts a character at the current cursor position. |
| 77 void InsertChar(base::char16 c) { | 77 void InsertChar(base::char16 c) { |
| 78 InsertTextInternal(base::string16(&c, 1), true); | 78 InsertTextInternal(base::string16(&c, 1), true); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 void ExecuteAndRecordInsert(const base::string16& new_text, bool mergeable); | 248 void ExecuteAndRecordInsert(const base::string16& new_text, bool mergeable); |
| 249 | 249 |
| 250 // Adds or merge |edit| into edit history. Return true if the edit | 250 // Adds or merge |edit| into edit history. Return true if the edit |
| 251 // has been merged and must be deleted after redo. | 251 // has been merged and must be deleted after redo. |
| 252 bool AddOrMergeEditHistory(internal::Edit* edit); | 252 bool AddOrMergeEditHistory(internal::Edit* edit); |
| 253 | 253 |
| 254 // Modify the text buffer in following way: | 254 // Modify the text buffer in following way: |
| 255 // 1) Delete the string from |delete_from| to |delte_to|. | 255 // 1) Delete the string from |delete_from| to |delte_to|. |
| 256 // 2) Insert the |new_text| at the index |new_text_insert_at|. | 256 // 2) Insert the |new_text| at the index |new_text_insert_at|. |
| 257 // Note that the index is after deletion. | 257 // Note that the index is after deletion. |
| 258 // 3) Move the cursor to |new_cursor_pos|. | 258 // 3) Select |selection_range|. |
| 259 void ModifyText(size_t delete_from, | 259 void ModifyText(size_t delete_from, |
| 260 size_t delete_to, | 260 size_t delete_to, |
| 261 const base::string16& new_text, | 261 const base::string16& new_text, |
| 262 size_t new_text_insert_at, | 262 size_t new_text_insert_at, |
| 263 size_t new_cursor_pos); | 263 gfx::Range selection_range); |
| 264 | 264 |
| 265 void ClearComposition(); | 265 void ClearComposition(); |
| 266 | 266 |
| 267 // The TextfieldModel::Delegate instance should be provided by the owner. | 267 // The TextfieldModel::Delegate instance should be provided by the owner. |
| 268 Delegate* delegate_; | 268 Delegate* delegate_; |
| 269 | 269 |
| 270 // The stylized text, cursor, selection, and the visual layout model. | 270 // The stylized text, cursor, selection, and the visual layout model. |
| 271 std::unique_ptr<gfx::RenderText> render_text_; | 271 std::unique_ptr<gfx::RenderText> render_text_; |
| 272 | 272 |
| 273 // The composition range. | 273 // The composition range. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 289 // 2) new edit is added. (redo history is cleared) | 289 // 2) new edit is added. (redo history is cleared) |
| 290 // 3) redone all undone edits. | 290 // 3) redone all undone edits. |
| 291 EditHistory::iterator current_edit_; | 291 EditHistory::iterator current_edit_; |
| 292 | 292 |
| 293 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); | 293 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 } // namespace views | 296 } // namespace views |
| 297 | 297 |
| 298 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ | 298 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
| OLD | NEW |