Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/ui/views/autofill/decorated_textfield.h

Issue 135813002: Revert of Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 ImageView; 14 class FocusableBorder;
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 display inside the textfield at the end of the text. 39 // Sets the icon to be displayed inside the textfield at the end of the
40 // text.
40 void SetIcon(const gfx::Image& icon); 41 void SetIcon(const gfx::Image& icon);
41 42
42 // Sets a tooltip for this field. This will override the icon set with 43 // Sets a tooltip for this field. This will override the icon set with
43 // SetIcon(), if any, and will be overridden by future calls to SetIcon(). 44 // SetIcon(), if any, and will be overridden by future calls to SetIcon().
44 void SetTooltipIcon(const base::string16& text); 45 void SetTooltipIcon(const base::string16& text);
45 46
46 // views::Textfield implementation. 47 // views::Textfield implementation.
47 virtual base::string16 GetPlaceholderText() const OVERRIDE; 48 virtual base::string16 GetPlaceholderText() const OVERRIDE;
48 49
49 // views::View implementation. 50 // views::View implementation.
50 virtual const char* GetClassName() const OVERRIDE; 51 virtual const char* GetClassName() const OVERRIDE;
51 virtual gfx::Size GetPreferredSize() OVERRIDE; 52 virtual gfx::Size GetPreferredSize() OVERRIDE;
52 virtual void Layout() OVERRIDE; 53 virtual void Layout() OVERRIDE;
53 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE; 54 virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE;
55 virtual void OnFocus() OVERRIDE;
56 virtual void OnBlur() OVERRIDE;
54 57
55 private: 58 private:
56 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton); 59 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton);
57 60
58 // Updates the background after its color may have changed. 61 // Updates the background of |this| after it may have changed. This is
62 // necessary for the sake of the padding around the native textfield.
59 void UpdateBackground(); 63 void UpdateBackground();
60 64
61 // Updates the border after its color or insets may have changed. 65 // Called to update the layout after SetIcon or SetTooltipIcon has been
62 void UpdateBorder(); 66 // called.
67 void IconChanged();
63 68
64 // Called to update the layout after SetIcon or SetTooltipIcon was called. 69 // This number corresponds to the number of pixels in the images that
65 void IconChanged(); 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.
66 77
67 // The view that holds the icon at the end of the textfield. 78 // The view that holds the icon at the end of the textfield.
68 scoped_ptr<views::ImageView> icon_view_; 79 scoped_ptr<views::ImageView> icon_view_;
69 80
70 // Whether the text contents are "invalid" (i.e. should special markers be 81 // Whether the text contents are "invalid" (i.e. should special markers be
71 // shown to indicate invalidness). 82 // shown to indicate invalidness).
72 bool invalid_; 83 bool invalid_;
73 84
74 // Whether the user can edit the field. When not editable, many of the 85 // Whether the user can edit the field. When not editable, many of the
75 // pieces of the textfield disappear (border, background, icon, placeholder 86 // pieces of the textfield disappear (border, background, icon, placeholder
76 // text) and it can't receive focus. 87 // text) and it can't receive focus.
77 bool editable_; 88 bool editable_;
78 89
79 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield); 90 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield);
80 }; 91 };
81 92
82 } // namespace autofill 93 } // namespace autofill
83 94
84 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_ 95 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('k') | chrome/browser/ui/views/autofill/decorated_textfield.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698