| 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 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // Called when the current composition text is confirmed or cleared. | 58 // Called when the current composition text is confirmed or cleared. |
| 59 virtual void OnCompositionTextConfirmedOrCleared() = 0; | 59 virtual void OnCompositionTextConfirmedOrCleared() = 0; |
| 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 void set_is_password(bool is_password) { | |
| 69 is_password_ = is_password; | |
| 70 } | |
| 71 | |
| 72 // Edit related methods. | 68 // Edit related methods. |
| 73 | 69 |
| 74 const string16& GetText() const; | 70 const string16& GetText() const; |
| 75 // 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 |
| 76 // current composition text will be confirmed first. Setting | 72 // current composition text will be confirmed first. Setting |
| 77 // 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 |
| 78 // visible change nor user-initiated change. This allow a client | 74 // visible change nor user-initiated change. This allow a client |
| 79 // code to set the same text multiple times without worrying about | 75 // code to set the same text multiple times without worrying about |
| 80 // messing edit history. | 76 // messing edit history. |
| 81 bool SetText(const string16& text); | 77 bool SetText(const string16& text); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 171 |
| 176 // Returns true if there is an redoable edit. | 172 // Returns true if there is an redoable edit. |
| 177 bool CanRedo(); | 173 bool CanRedo(); |
| 178 | 174 |
| 179 // Undo edit. Returns true if undo changed the text. | 175 // Undo edit. Returns true if undo changed the text. |
| 180 bool Undo(); | 176 bool Undo(); |
| 181 | 177 |
| 182 // Redo edit. Returns true if redo changed the text. | 178 // Redo edit. Returns true if redo changed the text. |
| 183 bool Redo(); | 179 bool Redo(); |
| 184 | 180 |
| 185 // Returns visible text. If the field is password, it returns the | |
| 186 // sequence of "*". | |
| 187 string16 GetVisibleText() const; | |
| 188 | |
| 189 // Cuts the currently selected text and puts it to clipboard. Returns true | 181 // Cuts the currently selected text and puts it to clipboard. Returns true |
| 190 // if text has changed after cutting. | 182 // if text has changed after cutting. |
| 191 bool Cut(); | 183 bool Cut(); |
| 192 | 184 |
| 193 // Copies the currently selected text and puts it to clipboard. | 185 // Copies the currently selected text and puts it to clipboard. |
| 194 void Copy(); | 186 void Copy(); |
| 195 | 187 |
| 196 // Pastes text from the clipboard at current cursor position. Returns true | 188 // Pastes text from the clipboard at current cursor position. Returns true |
| 197 // if text has changed after pasting. | 189 // if text has changed after pasting. |
| 198 bool Paste(); | 190 bool Paste(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 friend class TextfieldViewsModelTest; | 234 friend class TextfieldViewsModelTest; |
| 243 friend class UndoRedo_BasicTest; | 235 friend class UndoRedo_BasicTest; |
| 244 friend class UndoRedo_CutCopyPasteTest; | 236 friend class UndoRedo_CutCopyPasteTest; |
| 245 friend class UndoRedo_ReplaceTest; | 237 friend class UndoRedo_ReplaceTest; |
| 246 friend class internal::Edit; | 238 friend class internal::Edit; |
| 247 | 239 |
| 248 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_BasicTest); | 240 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_BasicTest); |
| 249 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest); | 241 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest); |
| 250 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_ReplaceTest); | 242 FRIEND_TEST_ALL_PREFIXES(TextfieldViewsModelTest, UndoRedo_ReplaceTest); |
| 251 | 243 |
| 252 // Returns the visible text given |start| and |end|. | |
| 253 string16 GetVisibleText(size_t start, size_t end) const; | |
| 254 | |
| 255 // Insert the given |text|. |mergeable| indicates if this insert | 244 // Insert the given |text|. |mergeable| indicates if this insert |
| 256 // operation can be merged to previous edit in the edit history. | 245 // operation can be merged to previous edit in the edit history. |
| 257 void InsertTextInternal(const string16& text, bool mergeable); | 246 void InsertTextInternal(const string16& text, bool mergeable); |
| 258 | 247 |
| 259 // Replace the current text with the given |text|. |mergeable| | 248 // Replace the current text with the given |text|. |mergeable| |
| 260 // indicates if this replace operation can be merged to previous | 249 // indicates if this replace operation can be merged to previous |
| 261 // edit in the edit history. | 250 // edit in the edit history. |
| 262 void ReplaceTextInternal(const string16& text, bool mergeable); | 251 void ReplaceTextInternal(const string16& text, bool mergeable); |
| 263 | 252 |
| 264 // Clears all edit history. | 253 // Clears all edit history. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 295 | 284 |
| 296 void ClearComposition(); | 285 void ClearComposition(); |
| 297 | 286 |
| 298 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by | 287 // Pointer to a TextfieldViewsModel::Delegate instance, should be provided by |
| 299 // the View object. | 288 // the View object. |
| 300 Delegate* delegate_; | 289 Delegate* delegate_; |
| 301 | 290 |
| 302 // The stylized text, cursor, selection, and the visual layout model. | 291 // The stylized text, cursor, selection, and the visual layout model. |
| 303 scoped_ptr<gfx::RenderText> render_text_; | 292 scoped_ptr<gfx::RenderText> render_text_; |
| 304 | 293 |
| 305 // True if the text is the password. | |
| 306 bool is_password_; | |
| 307 | |
| 308 typedef std::list<internal::Edit*> EditHistory; | 294 typedef std::list<internal::Edit*> EditHistory; |
| 309 EditHistory edit_history_; | 295 EditHistory edit_history_; |
| 310 | 296 |
| 311 // An iterator that points to the current edit that can be undone. | 297 // An iterator that points to the current edit that can be undone. |
| 312 // This iterator moves from the |end()|, meaining no edit to undo, | 298 // This iterator moves from the |end()|, meaining no edit to undo, |
| 313 // to the last element (one before |end()|), meaning no edit to redo. | 299 // to the last element (one before |end()|), meaning no edit to redo. |
| 314 // There is no edit to undo (== end()) when: | 300 // There is no edit to undo (== end()) when: |
| 315 // 1) in initial state. (nothing to undo) | 301 // 1) in initial state. (nothing to undo) |
| 316 // 2) very 1st edit is undone. | 302 // 2) very 1st edit is undone. |
| 317 // 3) all edit history is removed. | 303 // 3) all edit history is removed. |
| 318 // There is no edit to redo (== last element or no element) when: | 304 // There is no edit to redo (== last element or no element) when: |
| 319 // 1) in initial state. (nothing to redo) | 305 // 1) in initial state. (nothing to redo) |
| 320 // 2) new edit is added. (redo history is cleared) | 306 // 2) new edit is added. (redo history is cleared) |
| 321 // 3) redone all undone edits. | 307 // 3) redone all undone edits. |
| 322 EditHistory::iterator current_edit_; | 308 EditHistory::iterator current_edit_; |
| 323 | 309 |
| 324 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 310 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
| 325 }; | 311 }; |
| 326 | 312 |
| 327 } // namespace views | 313 } // namespace views |
| 328 | 314 |
| 329 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 315 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
| OLD | NEW |