Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 void ReplaceChar(base::char16 c) { | 88 void ReplaceChar(base::char16 c) { |
| 89 ReplaceTextInternal(base::string16(&c, 1), true); | 89 ReplaceTextInternal(base::string16(&c, 1), true); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Appends the text. | 92 // Appends the text. |
| 93 // The current composition text will be confirmed. | 93 // The current composition text will be confirmed. |
| 94 void Append(const base::string16& new_text); | 94 void Append(const base::string16& new_text); |
| 95 | 95 |
| 96 // Deletes the first character after the current cursor position (as if, the | 96 // Deletes the first character after the current cursor position (as if, the |
| 97 // the user has pressed delete key in the textfield). Returns true if | 97 // the user has pressed delete key in the textfield). Returns true if |
| 98 // the deletion is successful. | 98 // the deletion is successful. If |add_to_kill_buffer| is true, the deleted |
| 99 // text is copied to the kill buffer. | |
| 99 // If there is composition text, it'll be deleted instead. | 100 // If there is composition text, it'll be deleted instead. |
| 100 bool Delete(); | 101 bool Delete(bool add_to_kill_buffer = false); |
|
msw
2016/07/22 17:44:03
I thought chromium generally discouraged default p
| |
| 101 | 102 |
| 102 // Deletes the first character before the current cursor position (as if, the | 103 // Deletes the first character before the current cursor position (as if, the |
| 103 // the user has pressed backspace key in the textfield). Returns true if | 104 // the user has pressed backspace key in the textfield). Returns true if |
| 104 // the removal is successful. | 105 // the removal is successful. If |add_to_kill_buffer| is true, the deleted |
| 106 // text is copied to the kill buffer. | |
| 105 // If there is composition text, it'll be deleted instead. | 107 // If there is composition text, it'll be deleted instead. |
| 106 bool Backspace(); | 108 bool Backspace(bool add_to_kill_buffer = false); |
| 107 | 109 |
| 108 // Cursor related methods. | 110 // Cursor related methods. |
| 109 | 111 |
| 110 // Returns the current cursor position. | 112 // Returns the current cursor position. |
| 111 size_t GetCursorPosition() const; | 113 size_t GetCursorPosition() const; |
| 112 | 114 |
| 113 // Moves the cursor, see RenderText for additional details. | 115 // Moves the cursor, see RenderText for additional details. |
| 114 // The current composition text will be confirmed. | 116 // The current composition text will be confirmed. |
| 115 void MoveCursor(gfx::BreakType break_type, | 117 void MoveCursor(gfx::BreakType break_type, |
| 116 gfx::VisualCursorDirection direction, | 118 gfx::VisualCursorDirection direction, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 | 177 |
| 176 // Pastes text from the clipboard at current cursor position. Returns true | 178 // Pastes text from the clipboard at current cursor position. Returns true |
| 177 // if any text is pasted. | 179 // if any text is pasted. |
| 178 bool Paste(); | 180 bool Paste(); |
| 179 | 181 |
| 180 // Transposes the characters to either side of the insertion point and | 182 // Transposes the characters to either side of the insertion point and |
| 181 // advances the insertion point past both of them. Returns true if text is | 183 // advances the insertion point past both of them. Returns true if text is |
| 182 // changed. | 184 // changed. |
| 183 bool Transpose(); | 185 bool Transpose(); |
| 184 | 186 |
| 187 // Pastes text from the kill buffer at the current cursor position or | |
| 188 // selection. | |
|
msw
2016/07/22 17:44:03
nit: What does "or selection" mean? Just that a cu
karandeepb
2016/07/25 06:38:11
Done. Yeah it follows the standard paste behavior.
| |
| 189 bool Yank(); | |
| 190 | |
| 185 // Tells if any text is selected, even if the selection is in composition | 191 // Tells if any text is selected, even if the selection is in composition |
| 186 // text. | 192 // text. |
| 187 bool HasSelection() const; | 193 bool HasSelection() const; |
| 188 | 194 |
| 189 // Deletes the selected text. This method shouldn't be called with | 195 // Deletes the selected text. This method shouldn't be called with |
| 190 // composition text. | 196 // composition text. |
| 191 void DeleteSelection(); | 197 void DeleteSelection(); |
| 192 | 198 |
| 193 // Deletes the selected text (if any) and insert text at given position. | 199 // Deletes the selected text (if any) and insert text at given position. |
| 194 void DeleteSelectionAndInsertTextAt(const base::string16& new_text, | 200 void DeleteSelectionAndInsertTextAt(const base::string16& new_text, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 216 | 222 |
| 217 // Retrieves the range of current composition text. | 223 // Retrieves the range of current composition text. |
| 218 void GetCompositionTextRange(gfx::Range* range) const; | 224 void GetCompositionTextRange(gfx::Range* range) const; |
| 219 | 225 |
| 220 // Returns true if there is composition text. | 226 // Returns true if there is composition text. |
| 221 bool HasCompositionText() const; | 227 bool HasCompositionText() const; |
| 222 | 228 |
| 223 // Clears all edit history. | 229 // Clears all edit history. |
| 224 void ClearEditHistory(); | 230 void ClearEditHistory(); |
| 225 | 231 |
| 232 // Clears the kill buffer. Exposed to clear global state between tests. | |
| 233 static void ClearKillBufferForTesting(); | |
|
sky
2016/07/22 15:22:49
How about friending the helper and moving this to
karandeepb
2016/07/25 06:38:11
Done. But friending BridgedNativeWidgetTest here s
sky
2016/07/25 15:26:27
Another option is to friend a class that is used b
| |
| 234 | |
| 226 private: | 235 private: |
| 227 friend class internal::Edit; | 236 friend class internal::Edit; |
| 228 | 237 |
| 229 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_BasicTest); | 238 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_BasicTest); |
| 230 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_CutCopyPasteTest); | 239 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_CutCopyPasteTest); |
| 231 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_ReplaceTest); | 240 FRIEND_TEST_ALL_PREFIXES(TextfieldModelTest, UndoRedo_ReplaceTest); |
| 232 | 241 |
| 233 // Insert the given |new_text|. |mergeable| indicates if this insert operation | 242 // Insert the given |new_text|. |mergeable| indicates if this insert operation |
| 234 // can be merged with previous edits in the history. | 243 // can be merged with previous edits in the history. |
| 235 void InsertTextInternal(const base::string16& new_text, bool mergeable); | 244 void InsertTextInternal(const base::string16& new_text, bool mergeable); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // 2) new edit is added. (redo history is cleared) | 303 // 2) new edit is added. (redo history is cleared) |
| 295 // 3) redone all undone edits. | 304 // 3) redone all undone edits. |
| 296 EditHistory::iterator current_edit_; | 305 EditHistory::iterator current_edit_; |
| 297 | 306 |
| 298 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); | 307 DISALLOW_COPY_AND_ASSIGN(TextfieldModel); |
| 299 }; | 308 }; |
| 300 | 309 |
| 301 } // namespace views | 310 } // namespace views |
| 302 | 311 |
| 303 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ | 312 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_MODEL_H_ |
| OLD | NEW |