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_H_ | 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 void set_obscured_reveal_duration(const base::TimeDelta& duration) { | 84 void set_obscured_reveal_duration(const base::TimeDelta& duration) { |
85 obscured_reveal_duration_ = duration; | 85 obscured_reveal_duration_ = duration; |
86 } | 86 } |
87 | 87 |
88 // Gets/Sets the input type of this textfield. | 88 // Gets/Sets the input type of this textfield. |
89 ui::TextInputType GetTextInputType() const; | 89 ui::TextInputType GetTextInputType() const; |
90 void SetTextInputType(ui::TextInputType type); | 90 void SetTextInputType(ui::TextInputType type); |
91 | 91 |
92 // Gets/Sets the text currently displayed in the Textfield. | 92 // Gets/Sets the text currently displayed in the Textfield. |
93 const string16& text() const { return text_; } | 93 const base::string16& text() const { return text_; } |
94 | 94 |
95 // Sets the text currently displayed in the Textfield. This doesn't | 95 // Sets the text currently displayed in the Textfield. This doesn't |
96 // change the cursor position if the current cursor is within the | 96 // change the cursor position if the current cursor is within the |
97 // new text's range, or moves the cursor to the end if the cursor is | 97 // new text's range, or moves the cursor to the end if the cursor is |
98 // out of the new text's range. | 98 // out of the new text's range. |
99 void SetText(const string16& text); | 99 void SetText(const base::string16& text); |
100 | 100 |
101 // Appends the given string to the previously-existing text in the field. | 101 // Appends the given string to the previously-existing text in the field. |
102 void AppendText(const string16& text); | 102 void AppendText(const base::string16& text); |
103 | 103 |
104 // Inserts |text| at the current cursor position, replacing any selected text. | 104 // Inserts |text| at the current cursor position, replacing any selected text. |
105 void InsertOrReplaceText(const string16& text); | 105 void InsertOrReplaceText(const base::string16& text); |
106 | 106 |
107 // Returns the text direction. | 107 // Returns the text direction. |
108 base::i18n::TextDirection GetTextDirection() const; | 108 base::i18n::TextDirection GetTextDirection() const; |
109 | 109 |
110 // Returns the text that is currently selected. | 110 // Returns the text that is currently selected. |
111 string16 GetSelectedText() const; | 111 base::string16 GetSelectedText() const; |
112 | 112 |
113 // Select the entire text range. If |reversed| is true, the range will end at | 113 // Select the entire text range. If |reversed| is true, the range will end at |
114 // the logical beginning of the text; this generally shows the leading portion | 114 // the logical beginning of the text; this generally shows the leading portion |
115 // of text that overflows its display area. | 115 // of text that overflows its display area. |
116 void SelectAll(bool reversed); | 116 void SelectAll(bool reversed); |
117 | 117 |
118 // Clears the selection within the edit field and sets the caret to the end. | 118 // Clears the selection within the edit field and sets the caret to the end. |
119 void ClearSelection() const; | 119 void ClearSelection() const; |
120 | 120 |
121 // Checks if there is any selected text. | 121 // Checks if there is any selected text. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Sets the default width of the text control. See default_width_in_chars_. | 158 // Sets the default width of the text control. See default_width_in_chars_. |
159 void set_default_width_in_chars(int default_width) { | 159 void set_default_width_in_chars(int default_width) { |
160 default_width_in_chars_ = default_width; | 160 default_width_in_chars_ = default_width; |
161 } | 161 } |
162 | 162 |
163 // Removes the border from the edit box, giving it a 2D look. | 163 // Removes the border from the edit box, giving it a 2D look. |
164 bool draw_border() const { return draw_border_; } | 164 bool draw_border() const { return draw_border_; } |
165 void RemoveBorder(); | 165 void RemoveBorder(); |
166 | 166 |
167 // Sets the text to display when empty. | 167 // Sets the text to display when empty. |
168 void set_placeholder_text(const string16& text) { | 168 void set_placeholder_text(const base::string16& text) { |
169 placeholder_text_ = text; | 169 placeholder_text_ = text; |
170 } | 170 } |
171 virtual base::string16 GetPlaceholderText() const; | 171 virtual base::string16 GetPlaceholderText() const; |
172 | 172 |
173 SkColor placeholder_text_color() const { return placeholder_text_color_; } | 173 SkColor placeholder_text_color() const { return placeholder_text_color_; } |
174 void set_placeholder_text_color(SkColor color) { | 174 void set_placeholder_text_color(SkColor color) { |
175 placeholder_text_color_ = color; | 175 placeholder_text_color_ = color; |
176 } | 176 } |
177 | 177 |
178 // Getter for the horizontal margins that were set. Returns false if | 178 // Getter for the horizontal margins that were set. Returns false if |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // The respective |style| is applied if |value| is true, or removed if false. | 228 // The respective |style| is applied if |value| is true, or removed if false. |
229 // Empty and invalid ranges are ignored. This is views-implementation only and | 229 // Empty and invalid ranges are ignored. This is views-implementation only and |
230 // has to be called after the wrapper is created. | 230 // has to be called after the wrapper is created. |
231 void SetStyle(gfx::TextStyle style, bool value); | 231 void SetStyle(gfx::TextStyle style, bool value); |
232 void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); | 232 void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); |
233 | 233 |
234 // Clears Edit history. | 234 // Clears Edit history. |
235 void ClearEditHistory(); | 235 void ClearEditHistory(); |
236 | 236 |
237 // Set the accessible name of the text field. | 237 // Set the accessible name of the text field. |
238 void SetAccessibleName(const string16& name); | 238 void SetAccessibleName(const base::string16& name); |
239 | 239 |
240 // Performs the action associated with the specified command id. | 240 // Performs the action associated with the specified command id. |
241 void ExecuteCommand(int command_id); | 241 void ExecuteCommand(int command_id); |
242 | 242 |
243 void SetFocusPainter(scoped_ptr<Painter> focus_painter); | 243 void SetFocusPainter(scoped_ptr<Painter> focus_painter); |
244 | 244 |
245 // Provided only for testing: | 245 // Provided only for testing: |
246 gfx::NativeView GetTestingHandle() const { | 246 gfx::NativeView GetTestingHandle() const { |
247 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; | 247 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; |
248 } | 248 } |
(...skipping 29 matching lines...) Expand all Loading... |
278 // The object that actually implements the native text field. | 278 // The object that actually implements the native text field. |
279 NativeTextfieldWrapper* native_wrapper_; | 279 NativeTextfieldWrapper* native_wrapper_; |
280 | 280 |
281 private: | 281 private: |
282 // Returns the insets to the rectangle where text is actually painted. | 282 // Returns the insets to the rectangle where text is actually painted. |
283 gfx::Insets GetTextInsets() const; | 283 gfx::Insets GetTextInsets() const; |
284 | 284 |
285 // Handles a request to change the value of this text field from software | 285 // Handles a request to change the value of this text field from software |
286 // using an accessibility API (typically automation software, screen readers | 286 // using an accessibility API (typically automation software, screen readers |
287 // don't normally use this). Sets the value and clears the selection. | 287 // don't normally use this). Sets the value and clears the selection. |
288 void AccessibilitySetValue(const string16& new_value); | 288 void AccessibilitySetValue(const base::string16& new_value); |
289 | 289 |
290 // This is the current listener for events from this Textfield. | 290 // This is the current listener for events from this Textfield. |
291 TextfieldController* controller_; | 291 TextfieldController* controller_; |
292 | 292 |
293 // The mask of style options for this Textfield. | 293 // The mask of style options for this Textfield. |
294 StyleFlags style_; | 294 StyleFlags style_; |
295 | 295 |
296 // The fonts used to render the text in the Textfield. | 296 // The fonts used to render the text in the Textfield. |
297 gfx::FontList font_list_; | 297 gfx::FontList font_list_; |
298 | 298 |
299 // The text displayed in the Textfield. | 299 // The text displayed in the Textfield. |
300 string16 text_; | 300 base::string16 text_; |
301 | 301 |
302 // True if this Textfield cannot accept input and is read-only. | 302 // True if this Textfield cannot accept input and is read-only. |
303 bool read_only_; | 303 bool read_only_; |
304 | 304 |
305 // The default number of average characters for the width of this text field. | 305 // The default number of average characters for the width of this text field. |
306 // This will be reported as the "desired size". Defaults to 0. | 306 // This will be reported as the "desired size". Defaults to 0. |
307 int default_width_in_chars_; | 307 int default_width_in_chars_; |
308 | 308 |
309 // Whether the border is drawn. | 309 // Whether the border is drawn. |
310 bool draw_border_; | 310 bool draw_border_; |
(...skipping 11 matching lines...) Expand all Loading... |
322 bool use_default_background_color_; | 322 bool use_default_background_color_; |
323 | 323 |
324 // Holds inner textfield margins. | 324 // Holds inner textfield margins. |
325 gfx::Insets margins_; | 325 gfx::Insets margins_; |
326 | 326 |
327 // Holds whether margins were set. | 327 // Holds whether margins were set. |
328 bool horizontal_margins_were_set_; | 328 bool horizontal_margins_were_set_; |
329 bool vertical_margins_were_set_; | 329 bool vertical_margins_were_set_; |
330 | 330 |
331 // Text to display when empty. | 331 // Text to display when empty. |
332 string16 placeholder_text_; | 332 base::string16 placeholder_text_; |
333 | 333 |
334 // Placeholder text color. | 334 // Placeholder text color. |
335 SkColor placeholder_text_color_; | 335 SkColor placeholder_text_color_; |
336 | 336 |
337 // The accessible name of the text field. | 337 // The accessible name of the text field. |
338 string16 accessible_name_; | 338 base::string16 accessible_name_; |
339 | 339 |
340 // The input type of this text field. | 340 // The input type of this text field. |
341 ui::TextInputType text_input_type_; | 341 ui::TextInputType text_input_type_; |
342 | 342 |
343 // The duration to reveal the last typed char for obscured textfields. | 343 // The duration to reveal the last typed char for obscured textfields. |
344 base::TimeDelta obscured_reveal_duration_; | 344 base::TimeDelta obscured_reveal_duration_; |
345 | 345 |
346 // Used to bind callback functions to this object. | 346 // Used to bind callback functions to this object. |
347 base::WeakPtrFactory<Textfield> weak_ptr_factory_; | 347 base::WeakPtrFactory<Textfield> weak_ptr_factory_; |
348 | 348 |
349 scoped_ptr<Painter> focus_painter_; | 349 scoped_ptr<Painter> focus_painter_; |
350 | 350 |
351 DISALLOW_COPY_AND_ASSIGN(Textfield); | 351 DISALLOW_COPY_AND_ASSIGN(Textfield); |
352 }; | 352 }; |
353 | 353 |
354 } // namespace views | 354 } // namespace views |
355 | 355 |
356 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 356 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
OLD | NEW |