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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "ui/gfx/image/image.h"
11 #include "ui/views/controls/textfield/textfield.h"
15 class TextfieldController
;
20 // A class which holds a textfield and draws extra stuff on top, like
21 // invalid content indications.
22 class DecoratedTextfield
: public views::Textfield
{
24 static const char kViewClassName
[];
26 DecoratedTextfield(const base::string16
& default_value
,
27 const base::string16
& placeholder
,
28 views::TextfieldController
* controller
);
29 virtual ~DecoratedTextfield();
31 // Sets whether to indicate the textfield has invalid content.
32 void SetInvalid(bool invalid
);
33 bool invalid() const { return invalid_
; }
35 // See docs for |editable_|.
36 void SetEditable(bool editable
);
37 bool editable() const { return editable_
; }
39 // Sets the icon to display inside the textfield at the end of the text.
40 void SetIcon(const gfx::Image
& icon
);
42 // 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 void SetTooltipIcon(const base::string16
& text
);
46 // views::Textfield implementation.
47 virtual base::string16
GetPlaceholderText() const OVERRIDE
;
49 // views::View implementation.
50 virtual const char* GetClassName() const OVERRIDE
;
51 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
52 virtual void Layout() OVERRIDE
;
53 virtual views::View
* GetEventHandlerForRect(const gfx::Rect
& rect
) OVERRIDE
;
56 FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest
, HeightMatchesButton
);
58 // Updates the background after its color may have changed.
59 void UpdateBackground();
61 // Updates the border after its color or insets may have changed.
64 // Called to update the layout after SetIcon or SetTooltipIcon was called.
67 // The view that holds the icon at the end of the textfield.
68 scoped_ptr
<views::ImageView
> icon_view_
;
70 // Whether the text contents are "invalid" (i.e. should special markers be
71 // shown to indicate invalidness).
74 // Whether the user can edit the field. When not editable, many of the
75 // pieces of the textfield disappear (border, background, icon, placeholder
76 // text) and it can't receive focus.
79 DISALLOW_COPY_AND_ASSIGN(DecoratedTextfield
);
82 } // namespace autofill
84 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_