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