Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / password_generation_bubble_view.h
1 // Copyright (c) 2012 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_PASSWORD_GENERATION_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_
7
8 #include "base/basictypes.h"
9 #include "components/autofill/core/common/password_form.h"
10 #include "components/autofill/core/common/password_generation_util.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/views/bubble/bubble_delegate.h"
13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/textfield/textfield_controller.h"
15 #include "ui/views/view.h"
16
17 namespace autofill {
18 class PasswordGenerator;
19 }
20
21 namespace content {
22 class RenderViewHost;
23 }
24
25 namespace views {
26 class ImageButton;
27 class Label;
28 class LabelButton;
29 }
30
31 namespace password_manager {
32 class PasswordManager;
33 }
34
35 // PasswordGenerationBubbleView is a bubble used to show possible generated
36 // passwords to users. It is set in the page content, anchored at |anchor_rect|.
37 // If the generated password is accepted by the user, the renderer associated
38 // with |render_view_host| and the |password_manager| are informed.
39 class PasswordGenerationBubbleView : public views::BubbleDelegateView,
40                                      public views::ButtonListener,
41                                      public views::TextfieldController {
42  public:
43   PasswordGenerationBubbleView(
44       const autofill::PasswordForm& form,
45       const gfx::Rect& anchor_rect,
46       views::View* anchor_view,
47       content::RenderViewHost* render_view_host,
48       password_manager::PasswordManager* password_manager,
49       autofill::PasswordGenerator* password_generator,
50       ui::ThemeProvider* theme_provider);
51   virtual ~PasswordGenerationBubbleView();
52
53   // views::View
54   virtual gfx::Size GetPreferredSize() const OVERRIDE;
55   virtual void Layout() OVERRIDE;
56
57  private:
58   // views::BubbleDelegateView
59   virtual void Init() OVERRIDE;
60   virtual gfx::Rect GetAnchorRect() const OVERRIDE;
61   virtual void WindowClosing() OVERRIDE;
62
63   // views::ButtonListener
64   virtual void ButtonPressed(views::Button* sender,
65                              const ui::Event& event) OVERRIDE;
66
67   // views::TextfieldController
68   virtual void ContentsChanged(views::Textfield* sender,
69                                const base::string16& new_contents) OVERRIDE;
70   virtual bool HandleKeyEvent(views::Textfield* sender,
71                               const ui::KeyEvent& key_event) OVERRIDE;
72
73   // views::WidgetDelegate
74   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
75
76   // Subviews
77   views::Label* title_label_;
78   views::LabelButton* accept_button_;
79   views::Textfield* textfield_;
80   views::ImageButton* regenerate_button_;
81   views::View* textfield_wrapper_;
82
83   // The form associated with the password field(s) that we are generated.
84   autofill::PasswordForm form_;
85
86   // Location that the bubble points to
87   gfx::Rect anchor_rect_;
88
89   // RenderViewHost associated with the button that spawned this bubble.
90   content::RenderViewHost* render_view_host_;
91
92   // PasswordManager associated with this tab.
93   password_manager::PasswordManager* password_manager_;
94
95   // Object to generate passwords. The class won't take the ownership of it.
96   autofill::PasswordGenerator* password_generator_;
97
98   // Theme provider used to draw the regenerate button.
99   ui::ThemeProvider* theme_provider_;
100
101   // Store stats on the users actions for logging.
102   autofill::password_generation::PasswordGenerationActions actions_;
103
104   DISALLOW_COPY_AND_ASSIGN(PasswordGenerationBubbleView);
105 };
106
107 #endif  // CHROME_BROWSER_UI_VIEWS_PASSWORD_GENERATION_BUBBLE_VIEW_H_