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 "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
11 #include "ui/views/controls/textfield/textfield.h" | 11 #include "ui/views/controls/textfield/textfield.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 class FocusableBorder; | 14 class ImageView; |
15 class TextfieldController; | 15 class TextfieldController; |
16 } | 16 } |
17 | 17 |
18 namespace autofill { | 18 namespace autofill { |
19 | 19 |
20 // 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 |
21 // invalid content indications. | 21 // invalid content indications. |
22 class DecoratedTextfield : public views::Textfield { | 22 class DecoratedTextfield : public views::Textfield { |
23 public: | 23 public: |
24 static const char kViewClassName[]; | 24 static const char kViewClassName[]; |
25 | 25 |
26 DecoratedTextfield(const base::string16& default_value, | 26 DecoratedTextfield(const base::string16& default_value, |
27 const base::string16& placeholder, | 27 const base::string16& placeholder, |
28 views::TextfieldController* controller); | 28 views::TextfieldController* controller); |
29 virtual ~DecoratedTextfield(); | 29 virtual ~DecoratedTextfield(); |
30 | 30 |
31 // Sets whether to indicate the textfield has invalid content. | 31 // Sets whether to indicate the textfield has invalid content. |
32 void SetInvalid(bool invalid); | 32 void SetInvalid(bool invalid); |
33 bool invalid() const { return invalid_; } | 33 bool invalid() const { return invalid_; } |
34 | 34 |
35 // See docs for |editable_|. | 35 // See docs for |editable_|. |
36 void SetEditable(bool editable); | 36 void SetEditable(bool editable); |
37 bool editable() const { return editable_; } | 37 bool editable() const { return editable_; } |
38 | 38 |
39 // Sets the icon to be displayed inside the textfield at the end of the | 39 // Sets the icon to display inside the textfield at the end of the text. |
40 // text. | |
41 void SetIcon(const gfx::Image& icon); | 40 void SetIcon(const gfx::Image& icon); |
42 | 41 |
43 // Sets a tooltip for this field. This will override the icon set with | 42 // Sets a tooltip for this field. This will override the icon set with |
44 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). | 43 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). |
45 void SetTooltipIcon(const base::string16& text); | 44 void SetTooltipIcon(const base::string16& text); |
46 | 45 |
47 // views::Textfield implementation. | 46 // views::Textfield implementation. |
48 virtual base::string16 GetPlaceholderText() const OVERRIDE; | 47 virtual base::string16 GetPlaceholderText() const OVERRIDE; |
49 | 48 |
50 // views::View implementation. | 49 // views::View implementation. |
51 virtual const char* GetClassName() const OVERRIDE; | 50 virtual const char* GetClassName() const OVERRIDE; |
52 virtual gfx::Size GetPreferredSize() OVERRIDE; | 51 virtual gfx::Size GetPreferredSize() OVERRIDE; |
53 virtual void Layout() OVERRIDE; | 52 virtual void Layout() OVERRIDE; |
54 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE; | 53 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE; |
55 virtual void OnFocus() OVERRIDE; | |
56 virtual void OnBlur() OVERRIDE; | |
57 | 54 |
58 private: | 55 private: |
59 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton); | 56 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton); |
60 | 57 |
61 // Updates the background of |this| after it may have changed. This is | 58 // Updates the background after its color may have changed. |
62 // necessary for the sake of the padding around the native textfield. | |
63 void UpdateBackground(); | 59 void UpdateBackground(); |
64 | 60 |
65 // Called to update the layout after SetIcon or SetTooltipIcon has been | 61 // Updates the border after its color or insets may have changed. |
66 // called. | 62 void UpdateBorder(); |
| 63 |
| 64 // Called to update the layout after SetIcon or SetTooltipIcon was called. |
67 void IconChanged(); | 65 void IconChanged(); |
68 | 66 |
69 // This number corresponds to the number of pixels in the images that | |
70 // are used to draw a views button which are above or below the actual border. | |
71 // This number is encoded in the button assets themselves, so there's no other | |
72 // way to get it than to hardcode it here. | |
73 static const int kMagicInsetNumber; | |
74 | |
75 // We draw the border. | |
76 views::FocusableBorder* border_; // Weak. | |
77 | |
78 // The view that holds the icon at the end of the textfield. | 67 // The view that holds the icon at the end of the textfield. |
79 scoped_ptr<views::ImageView> icon_view_; | 68 scoped_ptr<views::ImageView> icon_view_; |
80 | 69 |
81 // Whether the text contents are "invalid" (i.e. should special markers be | 70 // Whether the text contents are "invalid" (i.e. should special markers be |
82 // shown to indicate invalidness). | 71 // shown to indicate invalidness). |
83 bool invalid_; | 72 bool invalid_; |
84 | 73 |
85 // Whether the user can edit the field. When not editable, many of the | 74 // Whether the user can edit the field. When not editable, many of the |
86 // pieces of the textfield disappear (border, background, icon, placeholder | 75 // pieces of the textfield disappear (border, background, icon, placeholder |
87 // text) and it can't receive focus. | 76 // text) and it can't receive focus. |
88 bool editable_; | 77 bool editable_; |
89 | 78 |
90 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); | 79 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); |
91 }; | 80 }; |
92 | 81 |
93 } // namespace autofill | 82 } // namespace autofill |
94 | 83 |
95 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ | 84 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ |
OLD | NEW |