OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/views/autofill/password_generation_popup_view_views.
h" | 5 #include "chrome/browser/ui/views/autofill/password_generation_popup_view_views.
h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" | 8 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" |
9 #include "chrome/browser/ui/autofill/popup_constants.h" | 9 #include "chrome/browser/ui/autofill/popup_constants.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
14 #include "ui/views/border.h" | 14 #include "ui/views/border.h" |
15 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
16 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
17 #include "ui/views/controls/styled_label.h" | 17 #include "ui/views/controls/styled_label.h" |
18 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 namespace autofill { | 21 namespace autofill { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // The amount of whitespace that is present when there is no padding. Used | 25 // The amount of whitespace that is present when there is no padding. Used |
26 // to get the proper spacing in the help section. | 26 // to get the proper spacing in the help section. |
27 const int kHelpVerticalOffset = 5; | 27 const int kHelpVerticalOffset = 5; |
28 const int kPasswordSectionHeight = 62; | |
29 | 28 |
30 // Wrapper around just the text portions of the generation UI (password and | 29 // Wrapper around just the text portions of the generation UI (password and |
31 // prompting text). | 30 // prompting text). |
32 class PasswordTextBox : public views::View { | 31 class PasswordTextBox : public views::View { |
33 public: | 32 public: |
34 PasswordTextBox() {} | 33 PasswordTextBox() {} |
35 virtual ~PasswordTextBox() {} | 34 virtual ~PasswordTextBox() {} |
36 | 35 |
37 // |suggestion_text| prompts the user to select the password, | 36 // |suggestion_text| prompts the user to select the password, |
38 // |generated_password| is the generated password, and |font_list| is the font | 37 // |generated_password| is the generated password, and |font_list| is the font |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 password_view_->SetPosition(gfx::Point(kPopupBorderThickness, | 165 password_view_->SetPosition(gfx::Point(kPopupBorderThickness, |
167 kPopupBorderThickness)); | 166 kPopupBorderThickness)); |
168 password_view_->SizeToPreferredSize(); | 167 password_view_->SizeToPreferredSize(); |
169 AddChildView(password_view_); | 168 AddChildView(password_view_); |
170 } | 169 } |
171 | 170 |
172 gfx::Size PasswordGenerationPopupViewViews::GetPreferredSizeOfPasswordView() { | 171 gfx::Size PasswordGenerationPopupViewViews::GetPreferredSizeOfPasswordView() { |
173 int height = kPopupBorderThickness; | 172 int height = kPopupBorderThickness; |
174 if (controller_->display_password()) { | 173 if (controller_->display_password()) { |
175 // Add divider height as well. | 174 // Add divider height as well. |
176 height += kPasswordSectionHeight + 1; | 175 height += |
| 176 PasswordGenerationPopupController::kPopupPasswordSectionHeight + 1; |
177 } | 177 } |
178 int width = controller_->GetMinimumWidth(); | 178 int width = controller_->GetMinimumWidth(); |
179 int popup_width = width - 2 * kPopupBorderThickness; | 179 int popup_width = width - 2 * kPopupBorderThickness; |
180 height += help_label_->GetHeightForWidth(popup_width); | 180 height += help_label_->GetHeightForWidth(popup_width); |
181 return gfx::Size(width, height + kPopupBorderThickness); | 181 return gfx::Size(width, height + kPopupBorderThickness); |
182 } | 182 } |
183 | 183 |
184 void PasswordGenerationPopupViewViews::Show() { | 184 void PasswordGenerationPopupViewViews::Show() { |
185 DoShow(); | 185 DoShow(); |
186 } | 186 } |
(...skipping 23 matching lines...) Expand all Loading... |
210 void PasswordGenerationPopupViewViews::Layout() { | 210 void PasswordGenerationPopupViewViews::Layout() { |
211 // Need to leave room for the border. | 211 // Need to leave room for the border. |
212 int y = kPopupBorderThickness; | 212 int y = kPopupBorderThickness; |
213 int popup_width = bounds().width() - 2 * kPopupBorderThickness; | 213 int popup_width = bounds().width() - 2 * kPopupBorderThickness; |
214 if (controller_->display_password()) { | 214 if (controller_->display_password()) { |
215 // Currently the UI can change from not offering a password to offering | 215 // Currently the UI can change from not offering a password to offering |
216 // a password (e.g. the user is editing a generated password and deletes | 216 // a password (e.g. the user is editing a generated password and deletes |
217 // it), but it can't change the other way around. | 217 // it), but it can't change the other way around. |
218 CreatePasswordView(); | 218 CreatePasswordView(); |
219 password_view_->SetBounds( | 219 password_view_->SetBounds( |
220 kPopupBorderThickness, y, popup_width, kPasswordSectionHeight); | 220 kPopupBorderThickness, |
| 221 y, |
| 222 popup_width, |
| 223 PasswordGenerationPopupController::kPopupPasswordSectionHeight); |
221 divider_bounds_ = | 224 divider_bounds_ = |
222 gfx::Rect(kPopupBorderThickness, password_view_->bounds().bottom(), | 225 gfx::Rect(kPopupBorderThickness, password_view_->bounds().bottom(), |
223 popup_width, 1); | 226 popup_width, 1); |
224 y = divider_bounds_.bottom(); | 227 y = divider_bounds_.bottom(); |
225 } | 228 } |
226 | 229 |
227 help_label_->SetBounds(kPopupBorderThickness, y, popup_width, | 230 help_label_->SetBounds(kPopupBorderThickness, y, popup_width, |
228 help_label_->GetHeightForWidth(popup_width)); | 231 help_label_->GetHeightForWidth(popup_width)); |
229 } | 232 } |
230 | 233 |
(...skipping 30 matching lines...) Expand all Loading... |
261 | 264 |
262 // If the top level widget can't be found, cancel the popup since we can't | 265 // If the top level widget can't be found, cancel the popup since we can't |
263 // fully set it up. | 266 // fully set it up. |
264 if (!observing_widget) | 267 if (!observing_widget) |
265 return NULL; | 268 return NULL; |
266 | 269 |
267 return new PasswordGenerationPopupViewViews(controller, observing_widget); | 270 return new PasswordGenerationPopupViewViews(controller, observing_widget); |
268 } | 271 } |
269 | 272 |
270 } // namespace autofill | 273 } // namespace autofill |
OLD | NEW |