Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(942)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 152343006: Clean-up: Replaces obsolete Font/FontList methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 const gfx::FontList font_list;
37 gfx::FontList font_list(rb->GetFontList(ui::ResourceBundle::BaseFont));
38 base::string16 display_string(username ? 37 base::string16 display_string(username ?
39 password_form.username_value : 38 password_form.username_value :
40 ManagePasswordItemView::GetPasswordDisplayString( 39 ManagePasswordItemView::GetPasswordDisplayString(
41 password_form.password_value)); 40 password_form.password_value));
42 *biggest_width = std::max( 41 *biggest_width = std::max(gfx::GetStringWidth(display_string, font_list),
43 gfx::Canvas::GetStringWidth(display_string, font_list), *biggest_width); 42 *biggest_width);
44 } 43 }
45 44
46 } // namespace 45 } // namespace
47 46
48 47
49 // ManagePasswordsBubbleView -------------------------------------------------- 48 // ManagePasswordsBubbleView --------------------------------------------------
50 49
51 // static 50 // static
52 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 51 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
53 NULL; 52 NULL;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void ManagePasswordsBubbleView::Init() { 155 void ManagePasswordsBubbleView::Init() {
157 using views::GridLayout; 156 using views::GridLayout;
158 157
159 GridLayout* layout = new GridLayout(this); 158 GridLayout* layout = new GridLayout(this);
160 SetLayoutManager(layout); 159 SetLayoutManager(layout);
161 160
162 // This calculates the necessary widths for the list of credentials in the 161 // 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 162 // bubble. We do not need to clamp the password field width because
164 // ManagePasswordItemView::GetPasswordFisplayString() does this. 163 // ManagePasswordItemView::GetPasswordFisplayString() does this.
165 164
166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
167 const int predefined_username_field_max_width = 165 const int predefined_username_field_max_width =
168 rb->GetFont(ui::ResourceBundle::BaseFont).GetAverageCharacterWidth() * 22; 166 gfx::FontList().GetExpectedTextWidth(22);
169 const int max_username_or_password_width = 167 const int max_username_or_password_width =
170 std::min(GetMaximumUsernameOrPasswordWidth(true), 168 std::min(GetMaximumUsernameOrPasswordWidth(true),
171 predefined_username_field_max_width); 169 predefined_username_field_max_width);
172 const int first_field_width = std::max(max_username_or_password_width, 170 const int first_field_width = std::max(max_username_or_password_width,
173 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)). 171 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)).
174 GetPreferredSize().width()); 172 GetPreferredSize().width());
175 173
176 const int second_field_width = std::max( 174 const int second_field_width = std::max(
177 GetMaximumUsernameOrPasswordWidth(false), 175 GetMaximumUsernameOrPasswordWidth(false),
178 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)). 176 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)).
179 GetPreferredSize().width()); 177 GetPreferredSize().width());
180 178
181 const int kSingleColumnSetId = 0; 179 const int kSingleColumnSetId = 0;
182 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); 180 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
183 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 181 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
184 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, 182 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
185 GridLayout::USE_PREF, 0, 0); 183 GridLayout::USE_PREF, 0, 0);
186 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 184 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
187 185
186 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
188 views::Label* title_label = 187 views::Label* title_label =
189 new views::Label(manage_passwords_bubble_model_->title()); 188 new views::Label(manage_passwords_bubble_model_->title());
190 title_label->SetMultiLine(true); 189 title_label->SetMultiLine(true);
191 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont)); 190 title_label->SetFontList(rb->GetFontList(ui::ResourceBundle::MediumFont));
192 191
193 layout->StartRowWithPadding(0, kSingleColumnSetId, 192 layout->StartRowWithPadding(0, kSingleColumnSetId,
194 0, views::kRelatedControlSmallVerticalSpacing); 193 0, views::kRelatedControlSmallVerticalSpacing);
195 layout->AddView(title_label); 194 layout->AddView(title_label);
196 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 195 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
197 196
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 manage_passwords_bubble_model_->manage_passwords_bubble_state() == 355 manage_passwords_bubble_model_->manage_passwords_bubble_state() ==
357 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); 356 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED);
358 Close(); 357 Close();
359 } 358 }
360 359
361 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, 360 void ManagePasswordsBubbleView::LinkClicked(views::Link* source,
362 int event_flags) { 361 int event_flags) {
363 DCHECK_EQ(source, manage_link_); 362 DCHECK_EQ(source, manage_link_);
364 manage_passwords_bubble_model_->OnManageLinkClicked(); 363 manage_passwords_bubble_model_->OnManageLinkClicked();
365 } 364 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698