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 27 matching lines...) Expand all Loading... |
38 class VIEWS_EXPORT Textfield : public View, | 38 class VIEWS_EXPORT Textfield : public View, |
39 public TextfieldModel::Delegate, | 39 public TextfieldModel::Delegate, |
40 public ContextMenuController, | 40 public ContextMenuController, |
41 public DragController, | 41 public DragController, |
42 public ui::TouchEditable, | 42 public ui::TouchEditable, |
43 public ui::TextInputClient { | 43 public ui::TextInputClient { |
44 public: | 44 public: |
45 // The textfield's class name. | 45 // The textfield's class name. |
46 static const char kViewClassName[]; | 46 static const char kViewClassName[]; |
47 | 47 |
48 enum StyleFlags { | |
49 STYLE_DEFAULT = 0, | |
50 STYLE_OBSCURED = 1 << 0, | |
51 STYLE_LOWERCASE = 1 << 1 | |
52 }; | |
53 | |
54 // Returns the text cursor blink time in milliseconds, or 0 for no blinking. | 48 // Returns the text cursor blink time in milliseconds, or 0 for no blinking. |
55 static size_t GetCaretBlinkMs(); | 49 static size_t GetCaretBlinkMs(); |
56 | 50 |
57 Textfield(); | 51 Textfield(); |
58 explicit Textfield(StyleFlags style); | |
59 virtual ~Textfield(); | 52 virtual ~Textfield(); |
60 | 53 |
61 // TextfieldController accessors | 54 // Set the controller for this textfield. |
62 void SetController(TextfieldController* controller); | 55 void set_controller(TextfieldController* controller) { |
63 TextfieldController* GetController() const; | 56 controller_ = controller; |
| 57 } |
64 | 58 |
65 // Gets/Sets whether or not the Textfield is read-only. | 59 // Gets/Sets whether or not the Textfield is read-only. |
66 bool read_only() const { return read_only_; } | 60 bool read_only() const { return read_only_; } |
67 void SetReadOnly(bool read_only); | 61 void SetReadOnly(bool read_only); |
68 | 62 |
69 // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this | 63 // Sets the input type; displays only asterisks for TEXT_INPUT_TYPE_PASSWORD. |
70 // Textfield are displayed as asterisks/bullets. | |
71 bool IsObscured() const; | |
72 void SetObscured(bool obscured); | |
73 | |
74 // Sets the input type of this textfield. | |
75 void SetTextInputType(ui::TextInputType type); | 64 void SetTextInputType(ui::TextInputType type); |
76 | 65 |
77 // Gets the text currently displayed in the Textfield. | 66 // Gets the text currently displayed in the Textfield. |
78 const base::string16& text() const { return model_->text(); } | 67 const base::string16& text() const { return model_->text(); } |
79 | 68 |
80 // Sets the text currently displayed in the Textfield. This doesn't | 69 // Sets the text currently displayed in the Textfield. This doesn't |
81 // change the cursor position if the current cursor is within the | 70 // change the cursor position if the current cursor is within the |
82 // new text's range, or moves the cursor to the end if the cursor is | 71 // new text's range, or moves the cursor to the end if the cursor is |
83 // out of the new text's range. | 72 // out of the new text's range. |
84 void SetText(const base::string16& new_text); | 73 void SetText(const base::string16& new_text); |
(...skipping 14 matching lines...) Expand all Loading... |
99 // the logical beginning of the text; this generally shows the leading portion | 88 // the logical beginning of the text; this generally shows the leading portion |
100 // of text that overflows its display area. | 89 // of text that overflows its display area. |
101 void SelectAll(bool reversed); | 90 void SelectAll(bool reversed); |
102 | 91 |
103 // Clears the selection within the edit field and sets the caret to the end. | 92 // Clears the selection within the edit field and sets the caret to the end. |
104 void ClearSelection(); | 93 void ClearSelection(); |
105 | 94 |
106 // Checks if there is any selected text. | 95 // Checks if there is any selected text. |
107 bool HasSelection() const; | 96 bool HasSelection() const; |
108 | 97 |
109 // Accessor for |style_|. | |
110 StyleFlags style() const { return style_; } | |
111 | |
112 // Gets/Sets the text color to be used when painting the Textfield. | 98 // Gets/Sets the text color to be used when painting the Textfield. |
113 // Call |UseDefaultTextColor| to restore the default system color. | 99 // Call |UseDefaultTextColor| to restore the default system color. |
114 SkColor GetTextColor() const; | 100 SkColor GetTextColor() const; |
115 void SetTextColor(SkColor color); | 101 void SetTextColor(SkColor color); |
116 void UseDefaultTextColor(); | 102 void UseDefaultTextColor(); |
117 | 103 |
118 // Gets/Sets the background color to be used when painting the Textfield. | 104 // Gets/Sets the background color to be used when painting the Textfield. |
119 // Call |UseDefaultBackgroundColor| to restore the default system color. | 105 // Call |UseDefaultBackgroundColor| to restore the default system color. |
120 SkColor GetBackgroundColor() const; | 106 SkColor GetBackgroundColor() const; |
121 void SetBackgroundColor(SkColor color); | 107 void SetBackgroundColor(SkColor color); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 virtual void OnCandidateWindowHidden() OVERRIDE; | 277 virtual void OnCandidateWindowHidden() OVERRIDE; |
292 | 278 |
293 protected: | 279 protected: |
294 // Returns the TextfieldModel's text/cursor/selection rendering model. | 280 // Returns the TextfieldModel's text/cursor/selection rendering model. |
295 gfx::RenderText* GetRenderText() const; | 281 gfx::RenderText* GetRenderText() const; |
296 | 282 |
297 private: | 283 private: |
298 friend class TextfieldTest; | 284 friend class TextfieldTest; |
299 friend class TouchSelectionControllerImplTest; | 285 friend class TouchSelectionControllerImplTest; |
300 | 286 |
301 // Converts the raw text according to the current style, e.g. STYLE_LOWERCASE. | |
302 base::string16 GetTextForDisplay(const base::string16& raw); | |
303 | |
304 // Handles a request to change the value of this text field from software | 287 // Handles a request to change the value of this text field from software |
305 // using an accessibility API (typically automation software, screen readers | 288 // using an accessibility API (typically automation software, screen readers |
306 // don't normally use this). Sets the value and clears the selection. | 289 // don't normally use this). Sets the value and clears the selection. |
307 void AccessibilitySetValue(const base::string16& new_value); | 290 void AccessibilitySetValue(const base::string16& new_value); |
308 | 291 |
309 // Updates the painted background color. | 292 // Updates the painted background color. |
310 void UpdateBackgroundColor(); | 293 void UpdateBackgroundColor(); |
311 | 294 |
312 // Updates any colors that have not been explicitly set from the theme. | 295 // Updates any colors that have not been explicitly set from the theme. |
313 void UpdateColorsFromTheme(const ui::NativeTheme* theme); | 296 void UpdateColorsFromTheme(const ui::NativeTheme* theme); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 330 |
348 // Utility function to prepare the context menu. | 331 // Utility function to prepare the context menu. |
349 void UpdateContextMenu(); | 332 void UpdateContextMenu(); |
350 | 333 |
351 // Tracks the mouse clicks for single/double/triple clicks. | 334 // Tracks the mouse clicks for single/double/triple clicks. |
352 void TrackMouseClicks(const ui::MouseEvent& event); | 335 void TrackMouseClicks(const ui::MouseEvent& event); |
353 | 336 |
354 // Returns true if the current text input type allows access by the IME. | 337 // Returns true if the current text input type allows access by the IME. |
355 bool ImeEditingAllowed() const; | 338 bool ImeEditingAllowed() const; |
356 | 339 |
357 // Reveals the obscured char at |index| for the given |duration|. If |index| | 340 // Reveals the password character at |index| for a set duration. |
358 // is -1, existing revealed index will be cleared. | 341 // If |index| is -1, the existing revealed character will be reset. |
359 void RevealObscuredChar(int index, const base::TimeDelta& duration); | 342 void RevealPasswordChar(int index); |
360 | 343 |
361 void CreateTouchSelectionControllerAndNotifyIt(); | 344 void CreateTouchSelectionControllerAndNotifyIt(); |
362 | 345 |
363 // The text model. | 346 // The text model. |
364 scoped_ptr<TextfieldModel> model_; | 347 scoped_ptr<TextfieldModel> model_; |
365 | 348 |
366 // This is the current listener for events from this Textfield. | 349 // This is the current listener for events from this Textfield. |
367 TextfieldController* controller_; | 350 TextfieldController* controller_; |
368 | 351 |
369 // The mask of style options for this Textfield. | |
370 StyleFlags style_; | |
371 | |
372 // True if this Textfield cannot accept input and is read-only. | 352 // True if this Textfield cannot accept input and is read-only. |
373 bool read_only_; | 353 bool read_only_; |
374 | 354 |
375 // The default number of average characters for the width of this text field. | 355 // The default number of average characters for the width of this text field. |
376 // This will be reported as the "desired size". Defaults to 0. | 356 // This will be reported as the "desired size". Defaults to 0. |
377 int default_width_in_chars_; | 357 int default_width_in_chars_; |
378 | 358 |
379 scoped_ptr<Painter> focus_painter_; | 359 scoped_ptr<Painter> focus_painter_; |
380 | 360 |
381 // Text color. Only used if |use_default_text_color_| is false. | 361 // Text color. Only used if |use_default_text_color_| is false. |
(...skipping 13 matching lines...) Expand all Loading... |
395 | 375 |
396 // Placeholder text color. | 376 // Placeholder text color. |
397 SkColor placeholder_text_color_; | 377 SkColor placeholder_text_color_; |
398 | 378 |
399 // The accessible name of the text field. | 379 // The accessible name of the text field. |
400 base::string16 accessible_name_; | 380 base::string16 accessible_name_; |
401 | 381 |
402 // The input type of this text field. | 382 // The input type of this text field. |
403 ui::TextInputType text_input_type_; | 383 ui::TextInputType text_input_type_; |
404 | 384 |
405 // The duration to reveal the last typed char for obscured textfields. | 385 // The duration to reveal the last typed char for password textfields. |
406 base::TimeDelta obscured_reveal_duration_; | 386 base::TimeDelta password_reveal_duration_; |
407 | 387 |
408 // True if InputMethod::CancelComposition() should not be called. | 388 // True if InputMethod::CancelComposition() should not be called. |
409 bool skip_input_method_cancel_composition_; | 389 bool skip_input_method_cancel_composition_; |
410 | 390 |
411 // The text editing cursor repaint timer and visibility. | 391 // The text editing cursor repaint timer and visibility. |
412 base::RepeatingTimer<Textfield> cursor_repaint_timer_; | 392 base::RepeatingTimer<Textfield> cursor_repaint_timer_; |
413 bool cursor_visible_; | 393 bool cursor_visible_; |
414 | 394 |
415 // The drop cursor is a visual cue for where dragged text will be dropped. | 395 // The drop cursor is a visual cue for where dragged text will be dropped. |
416 bool drop_cursor_visible_; | 396 bool drop_cursor_visible_; |
417 gfx::SelectionModel drop_cursor_position_; | 397 gfx::SelectionModel drop_cursor_position_; |
418 | 398 |
419 // Is the user potentially dragging and dropping from this view? | 399 // Is the user potentially dragging and dropping from this view? |
420 bool initiating_drag_; | 400 bool initiating_drag_; |
421 | 401 |
422 // State variables used to track double and triple clicks. | 402 // State variables used to track double and triple clicks. |
423 size_t aggregated_clicks_; | 403 size_t aggregated_clicks_; |
424 base::TimeDelta last_click_time_; | 404 base::TimeDelta last_click_time_; |
425 gfx::Point last_click_location_; | 405 gfx::Point last_click_location_; |
426 gfx::Range double_click_word_; | 406 gfx::Range double_click_word_; |
427 | 407 |
428 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_; | 408 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_; |
429 | 409 |
430 // A timer to control the duration of showing the last typed char in | 410 // A timer to control the duration of showing the last typed char in |
431 // obscured text. When the timer is running, the last typed char is shown | 411 // password text. When the timer is running, the last typed char is shown |
432 // and when the time expires, the last typed char is obscured. | 412 // and when the time expires, the last typed char is password. |
433 base::OneShotTimer<Textfield> obscured_reveal_timer_; | 413 base::OneShotTimer<Textfield> password_reveal_timer_; |
434 | 414 |
435 // Context menu related members. | 415 // Context menu related members. |
436 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 416 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
437 scoped_ptr<views::MenuRunner> context_menu_runner_; | 417 scoped_ptr<views::MenuRunner> context_menu_runner_; |
438 | 418 |
439 // Used to bind callback functions to this object. | 419 // Used to bind callback functions to this object. |
440 base::WeakPtrFactory<Textfield> weak_ptr_factory_; | 420 base::WeakPtrFactory<Textfield> weak_ptr_factory_; |
441 | 421 |
442 DISALLOW_COPY_AND_ASSIGN(Textfield); | 422 DISALLOW_COPY_AND_ASSIGN(Textfield); |
443 }; | 423 }; |
444 | 424 |
445 } // namespace views | 425 } // namespace views |
446 | 426 |
447 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 427 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
OLD | NEW |