Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / autofill / decorated_textfield.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_
7
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"
12 #include "ui/views/view_targeter_delegate.h"
13
14 namespace views {
15 class ImageView;
16 class TextfieldController;
17 }
18
19 namespace autofill {
20
21 // A class which holds a textfield and draws extra stuff on top, like
22 // invalid content indications.
23 class DecoratedTextfield : public views::Textfield,
24                            public views::ViewTargeterDelegate {
25  public:
26   static const char kViewClassName[];
27
28   DecoratedTextfield(const base::string16& default_value,
29                      const base::string16& placeholder,
30                      views::TextfieldController* controller);
31   ~DecoratedTextfield() override;
32
33   // Sets whether to indicate the textfield has invalid content.
34   void SetInvalid(bool invalid);
35   bool invalid() const { return invalid_; }
36
37   // See docs for |editable_|.
38   void SetEditable(bool editable);
39   bool editable() const { return editable_; }
40
41   // Sets the icon to display inside the textfield at the end of the text.
42   void SetIcon(const gfx::Image& icon);
43
44   // Sets a tooltip for this field. This will override the icon set with
45   // SetIcon(), if any, and will be overridden by future calls to SetIcon().
46   void SetTooltipIcon(const base::string16& text);
47
48   // views::Textfield implementation.
49   base::string16 GetPlaceholderText() const override;
50
51   // views::View implementation.
52   const char* GetClassName() const override;
53   gfx::Size GetPreferredSize() const override;
54   void Layout() override;
55
56  private:
57   FRIEND_TEST_ALL_PREFIXES(DecoratedTextfieldTest, HeightMatchesButton);
58
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.
66   void UpdateBorder();
67
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   scoped_ptr<views::ImageView> icon_view_;
73
74   // Whether the text contents are "invalid" (i.e. should special markers be
75   // shown to indicate invalidness).
76   bool invalid_;
77
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);
84 };
85
86 }  // namespace autofill
87
88 #endif  // CHROME_BROWSER_UI_VIEWS_AUTOFILL_DECORATED_TEXTFIELD_H_