OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
14 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" | 14 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" |
15 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 15 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
17 #include "content/public/browser/web_contents_view.h" | 17 #include "content/public/browser/web_contents_view.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/text_utils.h" |
21 #include "ui/views/controls/button/blue_button.h" | 21 #include "ui/views/controls/button/blue_button.h" |
22 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
23 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
24 #include "ui/views/layout/layout_constants.h" | 24 #include "ui/views/layout/layout_constants.h" |
25 | 25 |
26 | 26 |
27 // Helpers -------------------------------------------------------------------- | 27 // Helpers -------------------------------------------------------------------- |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Updates either the biggest possible width for the username field in the | 31 // Updates either the biggest possible width for the username field in the |
32 // manage passwords bubble or the biggest possible width for the password field. | 32 // manage passwords bubble or the biggest possible width for the password field. |
33 void UpdateBiggestWidth(const autofill::PasswordForm& password_form, | 33 void UpdateBiggestWidth(const autofill::PasswordForm& password_form, |
34 bool username, | 34 bool username, |
35 int* biggest_width) { | 35 int* biggest_width) { |
36 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 36 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
37 gfx::FontList font_list(rb->GetFontList(ui::ResourceBundle::BaseFont)); | 37 const gfx::FontList& font_list(rb->GetFontList(ui::ResourceBundle::BaseFont)); |
msw
2014/02/04 00:58:20
Isn't this equivalent to the FontList default ctor
Yuki
2014/02/04 03:03:07
Done.
| |
38 base::string16 display_string(username ? | 38 base::string16 display_string(username ? |
39 password_form.username_value : | 39 password_form.username_value : |
40 ManagePasswordItemView::GetPasswordDisplayString( | 40 ManagePasswordItemView::GetPasswordDisplayString( |
41 password_form.password_value)); | 41 password_form.password_value)); |
42 *biggest_width = std::max( | 42 *biggest_width = std::max(gfx::GetStringWidth(display_string, font_list), |
43 gfx::Canvas::GetStringWidth(display_string, font_list), *biggest_width); | 43 *biggest_width); |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 | 48 |
49 // ManagePasswordsBubbleView -------------------------------------------------- | 49 // ManagePasswordsBubbleView -------------------------------------------------- |
50 | 50 |
51 // static | 51 // static |
52 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 52 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
53 NULL; | 53 NULL; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 158 |
159 GridLayout* layout = new GridLayout(this); | 159 GridLayout* layout = new GridLayout(this); |
160 SetLayoutManager(layout); | 160 SetLayoutManager(layout); |
161 | 161 |
162 // This calculates the necessary widths for the list of credentials in the | 162 // This calculates the necessary widths for the list of credentials in the |
163 // bubble. We do not need to clamp the password field width because | 163 // bubble. We do not need to clamp the password field width because |
164 // ManagePasswordItemView::GetPasswordFisplayString() does this. | 164 // ManagePasswordItemView::GetPasswordFisplayString() does this. |
165 | 165 |
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
167 const int predefined_username_field_max_width = | 167 const int predefined_username_field_max_width = |
168 rb->GetFont(ui::ResourceBundle::BaseFont).GetAverageCharacterWidth() * 22; | 168 rb->GetFontList(ui::ResourceBundle::BaseFont).GetExpectedTextWidth(22); |
169 const int max_username_or_password_width = | 169 const int max_username_or_password_width = |
170 std::min(GetMaximumUsernameOrPasswordWidth(true), | 170 std::min(GetMaximumUsernameOrPasswordWidth(true), |
171 predefined_username_field_max_width); | 171 predefined_username_field_max_width); |
172 const int first_field_width = std::max(max_username_or_password_width, | 172 const int first_field_width = std::max(max_username_or_password_width, |
173 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)). | 173 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)). |
174 GetPreferredSize().width()); | 174 GetPreferredSize().width()); |
175 | 175 |
176 const int second_field_width = std::max( | 176 const int second_field_width = std::max( |
177 GetMaximumUsernameOrPasswordWidth(false), | 177 GetMaximumUsernameOrPasswordWidth(false), |
178 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)). | 178 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)). |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 manage_passwords_bubble_model_->manage_passwords_bubble_state() == | 356 manage_passwords_bubble_model_->manage_passwords_bubble_state() == |
357 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); | 357 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); |
358 Close(); | 358 Close(); |
359 } | 359 } |
360 | 360 |
361 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, | 361 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, |
362 int event_flags) { | 362 int event_flags) { |
363 DCHECK_EQ(source, manage_link_); | 363 DCHECK_EQ(source, manage_link_); |
364 manage_passwords_bubble_model_->OnManageLinkClicked(); | 364 manage_passwords_bubble_model_->OnManageLinkClicked(); |
365 } | 365 } |
OLD | NEW |