| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 virtual ~Delegate(); | 62 virtual ~Delegate(); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 explicit TextfieldViewsModel(Delegate* delegate); | 65 explicit TextfieldViewsModel(Delegate* delegate); |
| 66 virtual ~TextfieldViewsModel(); | 66 virtual ~TextfieldViewsModel(); |
| 67 | 67 |
| 68 // Edit related methods. | 68 // Edit related methods. |
| 69 | 69 |
| 70 const string16& GetText() const; | 70 const string16& GetText() const { return text_; } |
| 71 // Sets the text. Returns true if the text has been modified. The | 71 // Sets the text. Returns true if the text has been modified. The |
| 72 // current composition text will be confirmed first. Setting | 72 // current composition text will be confirmed first. Setting |
| 73 // the same text will not add edit history because it's not user | 73 // the same text will not add edit history because it's not user |
| 74 // visible change nor user-initiated change. This allow a client | 74 // visible change nor user-initiated change. This allow a client |
| 75 // code to set the same text multiple times without worrying about | 75 // code to set the same text multiple times without worrying about |
| 76 // messing edit history. | 76 // messing edit history. |
| 77 bool SetText(const string16& text); | 77 bool SetText(const string16& text); |
| 78 | 78 |
| 79 // In an obscured (password) field, all text is drawn as asterisks or bullets. |
| 80 bool is_obscured() const { return obscured_; } |
| 81 void SetObscured(bool obscured); |
| 82 |
| 79 gfx::RenderText* render_text() { return render_text_.get(); } | 83 gfx::RenderText* render_text() { return render_text_.get(); } |
| 80 | 84 |
| 81 // Inserts given |text| at the current cursor position. | 85 // Inserts given |text| at the current cursor position. |
| 82 // The current composition text will be cleared. | 86 // The current composition text will be cleared. |
| 83 void InsertText(const string16& text) { | 87 void InsertText(const string16& text) { |
| 84 InsertTextInternal(text, false); | 88 InsertTextInternal(text, false); |
| 85 } | 89 } |
| 86 | 90 |
| 87 // Inserts a character at the current cursor position. | 91 // Inserts a character at the current cursor position. |
| 88 void InsertChar(char16 c) { | 92 void InsertChar(char16 c) { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // Note that the index is after deletion. | 283 // Note that the index is after deletion. |
| 280 // 3) Move the cursor to |new_cursor_pos|. | 284 // 3) Move the cursor to |new_cursor_pos|. |
| 281 void ModifyText(size_t delete_from, | 285 void ModifyText(size_t delete_from, |
| 282 size_t delete_to, | 286 size_t delete_to, |
| 283 const string16& new_text, | 287 const string16& new_text, |
| 284 size_t new_text_insert_at, | 288 size_t new_text_insert_at, |
| 285 size_t new_cursor_pos); | 289 size_t new_cursor_pos); |
| 286 | 290 |
| 287 void ClearComposition(); | 291 void ClearComposition(); |
| 288 | 292 |
| 293 void SetTextInternal(const string16& text); |
| 294 |
| 295 // Like GetText() except that it returns asterisks or bullets if this is an |
| 296 // obscured field. |
| 297 string16 GetDisplayText() const; |
| 298 |
| 299 // Functions for converting between indices into the text and indices into the |
| 300 // displayed text (which might be a bunch of asterisks). |
| 301 size_t FromDisplayIndex(size_t index) const; |
| 302 size_t ToDisplayIndex(size_t index) const; |
| 303 ui::Range FromDisplayRange(ui::Range range) const; |
| 304 ui::Range ToDisplayRange(ui::Range range) const; |
| 305 gfx::SelectionModel FromDisplaySelection( |
| 306 const gfx::SelectionModel& model) const; |
| 307 gfx::SelectionModel ToDisplaySelection( |
| 308 const gfx::SelectionModel& model) const; |
| 309 |
| 310 // The current text. |
| 311 string16 text_; |
| 312 |
| 313 // True if this is an obscured (password) field. |
| 314 bool obscured_; |
| 315 |
| 289 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by | 316 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by |
| 290 // the View object. | 317 // the View object. |
| 291 Delegate* delegate_; | 318 Delegate* delegate_; |
| 292 | 319 |
| 293 // The stylized text, cursor, selection, and the visual layout model. | 320 // The stylized text, cursor, selection, and the visual layout model. |
| 294 scoped_ptr<gfx::RenderText> render_text_; | 321 scoped_ptr<gfx::RenderText> render_text_; |
| 295 | 322 |
| 296 typedef std::list<internal::Edit*> EditHistory; | 323 typedef std::list<internal::Edit*> EditHistory; |
| 297 EditHistory edit_history_; | 324 EditHistory edit_history_; |
| 298 | 325 |
| 299 // An iterator that points to the current edit that can be undone. | 326 // An iterator that points to the current edit that can be undone. |
| 300 // This iterator moves from the |end()|, meaining no edit to undo, | 327 // This iterator moves from the |end()|, meaining no edit to undo, |
| 301 // to the last element (one before |end()|), meaning no edit to redo. | 328 // to the last element (one before |end()|), meaning no edit to redo. |
| 302 // There is no edit to undo (== end()) when: | 329 // There is no edit to undo (== end()) when: |
| 303 // 1) in initial state. (nothing to undo) | 330 // 1) in initial state. (nothing to undo) |
| 304 // 2) very 1st edit is undone. | 331 // 2) very 1st edit is undone. |
| 305 // 3) all edit history is removed. | 332 // 3) all edit history is removed. |
| 306 // There is no edit to redo (== last element or no element) when: | 333 // There is no edit to redo (== last element or no element) when: |
| 307 // 1) in initial state. (nothing to redo) | 334 // 1) in initial state. (nothing to redo) |
| 308 // 2) new edit is added. (redo history is cleared) | 335 // 2) new edit is added. (redo history is cleared) |
| 309 // 3) redone all undone edits. | 336 // 3) redone all undone edits. |
| 310 EditHistory::iterator current_edit_; | 337 EditHistory::iterator current_edit_; |
| 311 | 338 |
| 312 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 339 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
| 313 }; | 340 }; |
| 314 | 341 |
| 315 } // namespace views | 342 } // namespace views |
| 316 | 343 |
| 317 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 344 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| OLD | NEW |