OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ | |
7 | |
8 #include <list> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/strings/string16.h" | |
12 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" | |
13 #include "ui/views/controls/textfield/textfield_controller.h" | |
14 #include "ui/views/view.h" | |
15 | |
16 namespace gfx { | |
17 class Image; | |
18 } | |
19 | |
20 namespace autofill { | |
21 | |
22 // A view that houses a stack of textfields. The stack grows as needed. | |
23 class ExpandingTextfield : public views::View, | |
24 public views::TextfieldController { | |
25 public: | |
26 static const char kViewClassName[]; | |
27 | |
28 // When |multiline| is false, the view acts pretty much like a normal | |
29 // DecoratedTextfield. | |
30 ExpandingTextfield(const base::string16& default_value, | |
31 const base::string16& placeholder, | |
32 bool multiline, | |
33 views::TextfieldController* controller); | |
34 ~ExpandingTextfield() override; | |
35 | |
36 // Sets the contents of the textfields. Textfield n is set to the nth line | |
37 // of |text|, as separated by line returns. | |
38 void SetText(const base::string16& text); | |
39 // Concatenates text contents of all textfields (with line returns as the | |
40 // joining character) and returns it. | |
41 base::string16 GetText(); | |
42 | |
43 // Sets whether to indicate the first textfield has invalid content. Latter | |
44 // textfields are always valid. | |
45 void SetInvalid(bool invalid); | |
46 bool invalid() { | |
47 return textfields_.front()->invalid(); | |
48 } | |
49 | |
50 // Like validity, this only cares about the first textfield. | |
51 void SetEditable(bool editable); | |
52 bool editable() { | |
53 return textfields_.front()->editable(); | |
54 } | |
55 | |
56 // DecoratedTextfield pass-throughs. | |
57 void SetDefaultWidthInCharacters(int chars); | |
58 void SetPlaceholderText(const base::string16& placeholder); | |
59 void SetIcon(const gfx::Image& icon); | |
60 void SetTooltipIcon(const base::string16& text); | |
61 | |
62 // View implementation. | |
63 const char* GetClassName() const override; | |
64 using views::View::needs_layout; | |
65 | |
66 // TextfieldController implementation. | |
67 void ContentsChanged(views::Textfield* sender, | |
68 const base::string16& new_contents) override; | |
69 bool HandleKeyEvent(views::Textfield* sender, | |
70 const ui::KeyEvent& key_event) override; | |
71 bool HandleMouseEvent(views::Textfield* sender, | |
72 const ui::MouseEvent& mouse_event) override; | |
73 | |
74 private: | |
75 // Calls a given function on every textfield. | |
76 template <typename BaseType, typename Param> | |
77 void ForEachTextfield(void (BaseType::* f)(Param), Param p) const; | |
78 | |
79 // The list of textfields. Owned as child views. | |
80 std::list<DecoratedTextfield*> textfields_; | |
81 | |
82 TextfieldController* controller_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(ExpandingTextfield); | |
85 }; | |
86 | |
87 } // namespace autofill | |
88 | |
89 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_EXPANDING_TEXTFIELD_H_ | |
OLD | NEW |