OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "ui/gfx/image/image.h" | |
13 #include "ui/views/controls/textfield/textfield.h" | 12 #include "ui/views/controls/textfield/textfield.h" |
14 #include "ui/views/view_targeter_delegate.h" | |
15 | 13 |
16 namespace views { | 14 namespace views { |
17 class ImageView; | |
18 class TextfieldController; | 15 class TextfieldController; |
19 } | 16 } |
20 | 17 |
21 namespace autofill { | 18 namespace autofill { |
22 | 19 |
23 // A class which holds a textfield and draws extra stuff on top, like | 20 // A class which holds a textfield and draws extra stuff on top, like |
24 // invalid content indications. | 21 // invalid content indications. |
25 class DecoratedTextfield : public views::Textfield, | 22 // TODO(estade): the usefulness of this class is dubious now that it's been |
26 public views::ViewTargeterDelegate { | 23 // stripped of most of its functionality. |
| 24 class DecoratedTextfield : public views::Textfield { |
27 public: | 25 public: |
28 static const char kViewClassName[]; | 26 static const char kViewClassName[]; |
29 | 27 |
30 DecoratedTextfield(const base::string16& default_value, | 28 DecoratedTextfield(const base::string16& default_value, |
31 const base::string16& placeholder, | 29 const base::string16& placeholder, |
32 views::TextfieldController* controller); | 30 views::TextfieldController* controller); |
33 ~DecoratedTextfield() override; | 31 ~DecoratedTextfield() override; |
34 | 32 |
35 // Sets whether to indicate the textfield has invalid content. | 33 // Sets whether to indicate the textfield has invalid content. |
36 void SetInvalid(bool invalid); | 34 void SetInvalid(bool invalid); |
37 bool invalid() const { return invalid_; } | 35 bool invalid() const { return invalid_; } |
38 | 36 |
39 // See docs for |editable_|. | |
40 void SetEditable(bool editable); | |
41 bool editable() const { return editable_; } | |
42 | |
43 // Sets the icon to display inside the textfield at the end of the text. | |
44 void SetIcon(const gfx::Image& icon); | |
45 | |
46 // Sets a tooltip for this field. This will override the icon set with | |
47 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). | |
48 void SetTooltipIcon(const base::string16& text); | |
49 | |
50 // views::Textfield implementation. | |
51 base::string16 GetPlaceholderText() const override; | |
52 | |
53 // views::View implementation. | 37 // views::View implementation. |
54 const char* GetClassName() const override; | 38 const char* GetClassName() const override; |
55 gfx::Size GetPreferredSize() const override; | |
56 void Layout() override; | |
57 | 39 |
58 private: | 40 private: |
59 // views::ViewTargeterDelegate: | |
60 views::View* TargetForRect(views::View* root, const gfx::Rect& rect) override; | |
61 | |
62 // Updates the background after its color may have changed. | |
63 void UpdateBackground(); | |
64 | |
65 // Updates the border after its color or insets may have changed. | 41 // Updates the border after its color or insets may have changed. |
66 void UpdateBorder(); | 42 void UpdateBorder(); |
67 | 43 |
68 // Called to update the layout after SetIcon or SetTooltipIcon was called. | |
69 void IconChanged(); | |
70 | |
71 // The view that holds the icon at the end of the textfield. | |
72 std::unique_ptr<views::ImageView> icon_view_; | |
73 | |
74 // Whether the text contents are "invalid" (i.e. should special markers be | 44 // Whether the text contents are "invalid" (i.e. should special markers be |
75 // shown to indicate invalidness). | 45 // shown to indicate invalidness). |
76 bool invalid_; | 46 bool invalid_; |
77 | 47 |
78 // Whether the user can edit the field. When not editable, many of the | |
79 // pieces of the textfield disappear (border, background, icon, placeholder | |
80 // text) and it can't receive focus. | |
81 bool editable_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); | 48 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); |
84 }; | 49 }; |
85 | 50 |
86 } // namespace autofill | 51 } // namespace autofill |
87 | 52 |
88 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ | 53 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ |
OLD | NEW |