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 #include "ui/views/view_targeter_delegate.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 class ImageView; | 15 class ImageView; |
15 class TextfieldController; | 16 class TextfieldController; |
16 } | 17 } |
17 | 18 |
18 namespace autofill { | 19 namespace autofill { |
19 | 20 |
20 // A class which holds a textfield and draws extra stuff on top, like | 21 // A class which holds a textfield and draws extra stuff on top, like |
21 // invalid content indications. | 22 // invalid content indications. |
22 class DecoratedTextfield : public views::Textfield { | 23 class DecoratedTextfield : public views::Textfield, |
| 24 public views::ViewTargeterDelegate { |
23 public: | 25 public: |
24 static const char kViewClassName[]; | 26 static const char kViewClassName[]; |
25 | 27 |
26 DecoratedTextfield(const base::string16& default_value, | 28 DecoratedTextfield(const base::string16& default_value, |
27 const base::string16& placeholder, | 29 const base::string16& placeholder, |
28 views::TextfieldController* controller); | 30 views::TextfieldController* controller); |
29 virtual ~DecoratedTextfield(); | 31 virtual ~DecoratedTextfield(); |
30 | 32 |
31 // Sets whether to indicate the textfield has invalid content. | 33 // Sets whether to indicate the textfield has invalid content. |
32 void SetInvalid(bool invalid); | 34 void SetInvalid(bool invalid); |
(...skipping 10 matching lines...) Expand all Loading... |
43 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). | 45 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). |
44 void SetTooltipIcon(const base::string16& text); | 46 void SetTooltipIcon(const base::string16& text); |
45 | 47 |
46 // views::Textfield implementation. | 48 // views::Textfield implementation. |
47 virtual base::string16 GetPlaceholderText() const OVERRIDE; | 49 virtual base::string16 GetPlaceholderText() const OVERRIDE; |
48 | 50 |
49 // views::View implementation. | 51 // views::View implementation. |
50 virtual const char* GetClassName() const OVERRIDE; | 52 virtual const char* GetClassName() const OVERRIDE; |
51 virtual gfx::Size GetPreferredSize() const OVERRIDE; | 53 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
52 virtual void Layout() OVERRIDE; | 54 virtual void Layout() OVERRIDE; |
53 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE; | |
54 | 55 |
55 private: | 56 private: |
56 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton); | 57 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton); |
57 | 58 |
| 59 // views::ViewTargeterDelegate: |
| 60 virtual views::View* TargetForRect(views::View* root, |
| 61 const gfx::Rect& rect) OVERRIDE; |
| 62 |
58 // Updates the background after its color may have changed. | 63 // Updates the background after its color may have changed. |
59 void UpdateBackground(); | 64 void UpdateBackground(); |
60 | 65 |
61 // Updates the border after its color or insets may have changed. | 66 // Updates the border after its color or insets may have changed. |
62 void UpdateBorder(); | 67 void UpdateBorder(); |
63 | 68 |
64 // Called to update the layout after SetIcon or SetTooltipIcon was called. | 69 // Called to update the layout after SetIcon or SetTooltipIcon was called. |
65 void IconChanged(); | 70 void IconChanged(); |
66 | 71 |
67 // The view that holds the icon at the end of the textfield. | 72 // The view that holds the icon at the end of the textfield. |
68 scoped_ptr<views::ImageView> icon_view_; | 73 scoped_ptr<views::ImageView> icon_view_; |
69 | 74 |
70 // Whether the text contents are "invalid" (i.e. should special markers be | 75 // Whether the text contents are "invalid" (i.e. should special markers be |
71 // shown to indicate invalidness). | 76 // shown to indicate invalidness). |
72 bool invalid_; | 77 bool invalid_; |
73 | 78 |
74 // Whether the user can edit the field. When not editable, many of the | 79 // Whether the user can edit the field. When not editable, many of the |
75 // pieces of the textfield disappear (border, background, icon, placeholder | 80 // pieces of the textfield disappear (border, background, icon, placeholder |
76 // text) and it can't receive focus. | 81 // text) and it can't receive focus. |
77 bool editable_; | 82 bool editable_; |
78 | 83 |
79 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); | 84 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); |
80 }; | 85 }; |
81 | 86 |
82 } // namespace autofill | 87 } // namespace autofill |
83 | 88 |
84 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ | 89 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ |
OLD | NEW |