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