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 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
15 #include "ui/base/ime/composition_text.h" | 15 #include "ui/base/ime/composition_text.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/render_text.h" | 17 #include "ui/gfx/render_text.h" |
18 #include "ui/gfx/text_constants.h" | 18 #include "ui/gfx/text_constants.h" |
19 #include "ui/views/views_export.h" | 19 #include "ui/views/views_export.h" |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
| 22 class Range; |
22 class RenderText; | 23 class RenderText; |
23 } // namespace gfx | 24 } // namespace gfx |
24 | 25 |
25 namespace ui { | |
26 class Range; | |
27 } // namespace ui | |
28 | |
29 namespace views { | 26 namespace views { |
30 | 27 |
31 namespace internal { | 28 namespace internal { |
32 // Internal Edit class that keeps track of edits for undo/redo. | 29 // Internal Edit class that keeps track of edits for undo/redo. |
33 class Edit; | 30 class Edit; |
34 | 31 |
35 // C++ doesn't allow forward decl enum, so let's define here. | 32 // C++ doesn't allow forward decl enum, so let's define here. |
36 enum MergeType { | 33 enum MergeType { |
37 // The edit should not be merged with next edit. It still may | 34 // The edit should not be merged with next edit. It still may |
38 // be merged with an edit with MERGE_WITH_PREVIOUS. | 35 // be merged with an edit with MERGE_WITH_PREVIOUS. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 bool MoveCursorTo(const gfx::Point& point, bool select); | 134 bool MoveCursorTo(const gfx::Point& point, bool select); |
138 | 135 |
139 // Selection related method | 136 // Selection related method |
140 | 137 |
141 // Returns the selected text. | 138 // Returns the selected text. |
142 string16 GetSelectedText() const; | 139 string16 GetSelectedText() const; |
143 | 140 |
144 // The current composition text will be confirmed. The selection starts with | 141 // The current composition text will be confirmed. The selection starts with |
145 // the range's start position, and ends with the range's end position, | 142 // the range's start position, and ends with the range's end position, |
146 // therefore the cursor position becomes the end position. | 143 // therefore the cursor position becomes the end position. |
147 void SelectRange(const ui::Range& range); | 144 void SelectRange(const gfx::Range& range); |
148 | 145 |
149 // The current composition text will be confirmed. | 146 // The current composition text will be confirmed. |
150 // render_text_'s selection model is set to |sel|. | 147 // render_text_'s selection model is set to |sel|. |
151 void SelectSelectionModel(const gfx::SelectionModel& sel); | 148 void SelectSelectionModel(const gfx::SelectionModel& sel); |
152 | 149 |
153 // Select the entire text range. If |reversed| is true, the range will end at | 150 // Select the entire text range. If |reversed| is true, the range will end at |
154 // the logical beginning of the text; this generally shows the leading portion | 151 // the logical beginning of the text; this generally shows the leading portion |
155 // of text that overflows its display area. | 152 // of text that overflows its display area. |
156 // The current composition text will be confirmed. | 153 // The current composition text will be confirmed. |
157 void SelectAll(bool reversed); | 154 void SelectAll(bool reversed); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // Deletes the selected text. This method shouldn't be called with | 194 // Deletes the selected text. This method shouldn't be called with |
198 // composition text. | 195 // composition text. |
199 void DeleteSelection(); | 196 void DeleteSelection(); |
200 | 197 |
201 // Deletes the selected text (if any) and insert text at given | 198 // Deletes the selected text (if any) and insert text at given |
202 // position. | 199 // position. |
203 void DeleteSelectionAndInsertTextAt( | 200 void DeleteSelectionAndInsertTextAt( |
204 const string16& text, size_t position); | 201 const string16& text, size_t position); |
205 | 202 |
206 // Retrieves the text content in a given range. | 203 // Retrieves the text content in a given range. |
207 string16 GetTextFromRange(const ui::Range& range) const; | 204 string16 GetTextFromRange(const gfx::Range& range) const; |
208 | 205 |
209 // Retrieves the range containing all text in the model. | 206 // Retrieves the range containing all text in the model. |
210 void GetTextRange(ui::Range* range) const; | 207 void GetTextRange(gfx::Range* range) const; |
211 | 208 |
212 // Sets composition text and attributes. If there is composition text already, | 209 // Sets composition text and attributes. If there is composition text already, |
213 // it'll be replaced by the new one. Otherwise, current selection will be | 210 // it'll be replaced by the new one. Otherwise, current selection will be |
214 // replaced. If there is no selection, the composition text will be inserted | 211 // replaced. If there is no selection, the composition text will be inserted |
215 // at the insertion point. | 212 // at the insertion point. |
216 // Any changes to the model except text insertion will confirm the current | 213 // Any changes to the model except text insertion will confirm the current |
217 // composition text. | 214 // composition text. |
218 void SetCompositionText(const ui::CompositionText& composition); | 215 void SetCompositionText(const ui::CompositionText& composition); |
219 | 216 |
220 // Converts current composition text into final content. | 217 // Converts current composition text into final content. |
221 void ConfirmCompositionText(); | 218 void ConfirmCompositionText(); |
222 | 219 |
223 // Removes current composition text. | 220 // Removes current composition text. |
224 void CancelCompositionText(); | 221 void CancelCompositionText(); |
225 | 222 |
226 // Retrieves the range of current composition text. | 223 // Retrieves the range of current composition text. |
227 void GetCompositionTextRange(ui::Range* range) const; | 224 void GetCompositionTextRange(gfx::Range* range) const; |
228 | 225 |
229 // Returns true if there is composition text. | 226 // Returns true if there is composition text. |
230 bool HasCompositionText() const; | 227 bool HasCompositionText() const; |
231 | 228 |
232 private: | 229 private: |
233 friend class NativeTextfieldViews; | 230 friend class NativeTextfieldViews; |
234 friend class NativeTextfieldViewsTest; | 231 friend class NativeTextfieldViewsTest; |
235 friend class TextfieldViewsModelTest; | 232 friend class TextfieldViewsModelTest; |
236 friend class UndoRedo_BasicTest; | 233 friend class UndoRedo_BasicTest; |
237 friend class UndoRedo_CutCopyPasteTest; | 234 friend class UndoRedo_CutCopyPasteTest; |
(...skipping 13 matching lines...) Expand all Loading... |
251 // edit in the edit history. | 248 // edit in the edit history. |
252 void ReplaceTextInternal(const string16& text, bool mergeable); | 249 void ReplaceTextInternal(const string16& text, bool mergeable); |
253 | 250 |
254 // Clears all edit history. | 251 // Clears all edit history. |
255 void ClearEditHistory(); | 252 void ClearEditHistory(); |
256 | 253 |
257 // Clears redo history. | 254 // Clears redo history. |
258 void ClearRedoHistory(); | 255 void ClearRedoHistory(); |
259 | 256 |
260 // Executes and records edit operations. | 257 // Executes and records edit operations. |
261 void ExecuteAndRecordDelete(ui::Range range, bool mergeable); | 258 void ExecuteAndRecordDelete(gfx::Range range, bool mergeable); |
262 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, | 259 void ExecuteAndRecordReplaceSelection(internal::MergeType merge_type, |
263 const string16& text); | 260 const string16& text); |
264 void ExecuteAndRecordReplace(internal::MergeType merge_type, | 261 void ExecuteAndRecordReplace(internal::MergeType merge_type, |
265 size_t old_cursor_pos, | 262 size_t old_cursor_pos, |
266 size_t new_cursor_pos, | 263 size_t new_cursor_pos, |
267 const string16& text, | 264 const string16& text, |
268 size_t new_text_start); | 265 size_t new_text_start); |
269 void ExecuteAndRecordInsert(const string16& text, bool mergeable); | 266 void ExecuteAndRecordInsert(const string16& text, bool mergeable); |
270 | 267 |
271 // Adds or merge |edit| into edit history. Return true if the edit | 268 // Adds or merge |edit| into edit history. Return true if the edit |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // 2) new edit is added. (redo history is cleared) | 304 // 2) new edit is added. (redo history is cleared) |
308 // 3) redone all undone edits. | 305 // 3) redone all undone edits. |
309 EditHistory::iterator current_edit_; | 306 EditHistory::iterator current_edit_; |
310 | 307 |
311 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); | 308 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModel); |
312 }; | 309 }; |
313 | 310 |
314 } // namespace views | 311 } // namespace views |
315 | 312 |
316 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ | 313 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_VIEWS_MODEL_H_ |
OLD | NEW |