Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / ui / autofill / password_generation_popup_controller_impl.h
blob5507fd36e136eb91cb1053316773f0b9b5ea0796
1 // Copyright 2014 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_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h"
13 #include "chrome/browser/ui/autofill/popup_controller_common.h"
14 #include "components/autofill/core/common/password_form.h"
15 #include "ui/gfx/font_list.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/range/range.h"
18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/rect_f.h"
21 namespace content {
22 struct NativeWebKeyboardEvent;
23 class WebContents;
26 namespace password_manager {
27 class PasswordManager;
30 namespace autofill {
32 class PasswordGenerator;
33 class PasswordGenerationPopupObserver;
34 class PasswordGenerationPopupView;
36 // This class controls a PasswordGenerationPopupView. It is responsible for
37 // determining the location of the popup, handling keypress events while the
38 // popup is active, and notifying both the renderer and the password manager
39 // if the password is accepted.
40 class PasswordGenerationPopupControllerImpl
41 : public PasswordGenerationPopupController {
42 public:
43 // Create a controller or return |previous| if it is suitable. Will hide
44 // |previous| if it is not returned. |bounds| is the bounds of the element
45 // that we are showing the dropdown for in screen space. |form| is the
46 // identifier for the form that we are filling, and is used to notify
47 // |password_manager| if the password is generated. |max_length| is used to
48 // determine the length of the password shown. If not NULL, |observer| will
49 // be notified of changes of the popup state.
50 static base::WeakPtr<PasswordGenerationPopupControllerImpl> GetOrCreate(
51 base::WeakPtr<PasswordGenerationPopupControllerImpl> previous,
52 const gfx::RectF& bounds,
53 const PasswordForm& form,
54 int max_length,
55 password_manager::PasswordManager* password_manager,
56 PasswordGenerationPopupObserver* observer,
57 content::WebContents* web_contents,
58 gfx::NativeView container_view);
59 virtual ~PasswordGenerationPopupControllerImpl();
61 // Create a PasswordGenerationPopupView if one doesn't already exist.
62 // If |display_password| is true, a generated password is shown that can be
63 // selected by the user. Otherwise just the text explaining generated
64 // passwords is shown.
65 void Show(bool display_password);
67 // Hides the popup and destroys |this|.
68 void HideAndDestroy();
70 // Accessors.
71 content::WebContents* web_contents() {
72 return controller_common_.web_contents();
74 const gfx::RectF& element_bounds() {
75 return controller_common_.element_bounds();
78 private:
79 PasswordGenerationPopupControllerImpl(
80 const gfx::RectF& bounds,
81 const PasswordForm& form,
82 int max_length,
83 password_manager::PasswordManager* password_manager,
84 PasswordGenerationPopupObserver* observer,
85 content::WebContents* web_contents,
86 gfx::NativeView container_view);
88 // PasswordGenerationPopupController implementation:
89 virtual void Hide() OVERRIDE;
90 virtual void ViewDestroyed() OVERRIDE;
91 virtual void SetSelectionAtPoint(const gfx::Point& point) OVERRIDE;
92 virtual bool AcceptSelectedLine() OVERRIDE;
93 virtual void SelectionCleared() OVERRIDE;
94 virtual void OnSavedPasswordsLinkClicked() OVERRIDE;
95 virtual gfx::NativeView container_view() OVERRIDE;
96 virtual const gfx::FontList& font_list() const OVERRIDE;
97 virtual const gfx::Rect& popup_bounds() const OVERRIDE;
98 virtual const gfx::Rect& password_bounds() const OVERRIDE;
99 virtual const gfx::Rect& divider_bounds() const OVERRIDE;
100 virtual const gfx::Rect& help_bounds() const OVERRIDE;
101 virtual bool display_password() const OVERRIDE;
102 virtual bool password_selected() const OVERRIDE;
103 virtual base::string16 password() const OVERRIDE;
104 virtual base::string16 SuggestedText() OVERRIDE;
105 virtual const base::string16& HelpText() OVERRIDE;
106 virtual const gfx::Range& HelpTextLinkRange() OVERRIDE;
108 base::WeakPtr<PasswordGenerationPopupControllerImpl> GetWeakPtr();
110 bool HandleKeyPressEvent(const content::NativeWebKeyboardEvent& event);
112 // Set if the password is currently selected.
113 void PasswordSelected(bool selected);
115 // Accept the password. Causes the controller to hide itself as the popup
116 // is no longer necessary.
117 void PasswordAccepted();
119 // Accept password if it's selected.
120 bool PossiblyAcceptPassword();
122 // Get desired size of popup. Height depends on width because we do text
123 // wrapping.
124 int GetDesiredWidth();
125 int GetDesiredHeight(int width);
126 void CalculateBounds();
128 PasswordForm form_;
129 password_manager::PasswordManager* password_manager_;
131 // May be NULL.
132 PasswordGenerationPopupObserver* observer_;
134 // Controls how passwords are generated.
135 scoped_ptr<PasswordGenerator> generator_;
137 // Contains common popup functionality.
138 PopupControllerCommon controller_common_;
140 // Handle to the popup. May be NULL if popup isn't showing.
141 PasswordGenerationPopupView* view_;
143 // Font list used in the popup.
144 const gfx::FontList& font_list_;
146 // Help text and the range in the text that corresponds to the saved passwords
147 // link.
148 base::string16 help_text_;
149 gfx::Range link_range_;
151 base::string16 current_password_;
152 bool password_selected_;
154 // If a password will be shown in this popup.
155 bool display_password_;
157 // Bounds for all the elements of the popup.
158 gfx::Rect popup_bounds_;
159 gfx::Rect password_bounds_;
160 gfx::Rect divider_bounds_;
161 gfx::Rect help_bounds_;
163 base::WeakPtrFactory<PasswordGenerationPopupControllerImpl> weak_ptr_factory_;
165 DISALLOW_COPY_AND_ASSIGN(PasswordGenerationPopupControllerImpl);
168 } // namespace autofill
170 #endif // CHROME_BROWSER_UI_AUTOFILL_PASSWORD_GENERATION_POPUP_CONTROLLER_IMPL_H_