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

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

Issue 87853004: Refactoring Manage Passwords Bubble Code to exclude TabSpecificContentSettings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@movingclasses
Patch Set: adding controller files Created 7 years 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
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_icon_controller.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/canvas.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
markusheintz_ 2013/11/26 12:44:37 Please remove these 3 lines. No need for special A
27 // Helpers --------------------------------------------------------------------
28
26 namespace { 29 namespace {
27 30
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.
28 void UpdateBiggestWidth(const autofill::PasswordForm& password_form, 33 void UpdateBiggestWidth(const autofill::PasswordForm& password_form,
29 bool username, 34 bool username,
30 int* biggest_width) { 35 int* biggest_width) {
31 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 36 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
32 gfx::FontList font_list(rb->GetFontList(ui::ResourceBundle::BaseFont)); 37 gfx::FontList font_list(rb->GetFontList(ui::ResourceBundle::BaseFont));
33 string16 display_string(username ? 38 string16 display_string(username ?
34 password_form.username_value : 39 password_form.username_value :
35 ManagePasswordItemView::GetPasswordDisplayString( 40 ManagePasswordItemView::GetPasswordDisplayString(
36 password_form.password_value)); 41 password_form.password_value));
37 *biggest_width = std::max( 42 *biggest_width = std::max(
38 gfx::Canvas::GetStringWidth(display_string, font_list), *biggest_width); 43 gfx::Canvas::GetStringWidth(display_string, font_list), *biggest_width);
39 } 44 }
40 45
41 } // namespace 46 } // namespace
42 47
48
markusheintz_ 2013/11/26 12:44:37 Please remove these 3 lines. (see comment above)
49 // ManagePasswordsBubbleView --------------------------------------------------
50
43 // static 51 // static
44 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 52 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
45 NULL; 53 NULL;
46 54
47 // static 55 // static
48 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 56 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
49 ManagePasswordsIconView* icon_view) { 57 ManagePasswordsIconView* icon_view) {
50 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 58 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
51 DCHECK(browser); 59 DCHECK(browser);
52 DCHECK(browser->window()); 60 DCHECK(browser->window());
53 DCHECK(browser->fullscreen_controller()); 61 DCHECK(browser->fullscreen_controller());
54 DCHECK(!IsShowing()); 62 DCHECK(!IsShowing());
55 63
56 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 64 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
57 bool is_fullscreen = browser_view->IsFullscreen(); 65 bool is_fullscreen = browser_view->IsFullscreen();
58 views::View* anchor_view = is_fullscreen ? 66 views::View* anchor_view = is_fullscreen ?
59 NULL : browser_view->GetLocationBarView()->manage_passwords_icon_view(); 67 NULL : browser_view->GetLocationBarView()->manage_passwords_icon_view();
60 manage_passwords_bubble_ = 68 manage_passwords_bubble_ =
61 new ManagePasswordsBubbleView(anchor_view, web_contents, icon_view); 69 new ManagePasswordsBubbleView(web_contents, anchor_view, icon_view);
62 70
63 if (is_fullscreen) { 71 if (is_fullscreen) {
64 manage_passwords_bubble_->set_parent_window( 72 manage_passwords_bubble_->set_parent_window(
65 web_contents->GetView()->GetTopLevelNativeWindow()); 73 web_contents->GetView()->GetTopLevelNativeWindow());
66 } 74 }
67 75
68 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); 76 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_);
69 77
70 // Adjust for fullscreen after creation as it relies on the content size. 78 // Adjust for fullscreen after creation as it relies on the content size.
71 if (is_fullscreen) { 79 if (is_fullscreen) {
(...skipping 11 matching lines...) Expand all
83 } 91 }
84 92
85 // static 93 // static
86 bool ManagePasswordsBubbleView::IsShowing() { 94 bool ManagePasswordsBubbleView::IsShowing() {
87 // The bubble may be in the process of closing. 95 // The bubble may be in the process of closing.
88 return (manage_passwords_bubble_ != NULL) && 96 return (manage_passwords_bubble_ != NULL) &&
89 manage_passwords_bubble_->GetWidget()->IsVisible(); 97 manage_passwords_bubble_->GetWidget()->IsVisible();
90 } 98 }
91 99
92 ManagePasswordsBubbleView::ManagePasswordsBubbleView( 100 ManagePasswordsBubbleView::ManagePasswordsBubbleView(
101 content::WebContents* web_contents,
93 views::View* anchor_view, 102 views::View* anchor_view,
94 content::WebContents* web_contents,
95 ManagePasswordsIconView* icon_view) 103 ManagePasswordsIconView* icon_view)
96 : BubbleDelegateView( 104 : BubbleDelegateView(
97 anchor_view, 105 anchor_view,
98 anchor_view ? 106 anchor_view ?
99 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), 107 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE),
100 manage_passwords_bubble_model_( 108 manage_passwords_bubble_model_(
101 new ManagePasswordsBubbleModel(web_contents)), 109 new ManagePasswordsBubbleModel(web_contents)),
102 icon_view_(icon_view) { 110 icon_view_(icon_view) {
103 // Compensate for built-in vertical padding in the anchor view's image. 111 // Compensate for built-in vertical padding in the anchor view's image.
104 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 112 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GetWidget()->Close(); 153 GetWidget()->Close();
146 } 154 }
147 155
148 void ManagePasswordsBubbleView::Init() { 156 void ManagePasswordsBubbleView::Init() {
149 using views::GridLayout; 157 using views::GridLayout;
150 158
151 GridLayout* layout = new GridLayout(this); 159 GridLayout* layout = new GridLayout(this);
152 SetLayoutManager(layout); 160 SetLayoutManager(layout);
153 161
154 // 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
155 // bubble. 163 // bubble; we do not need to clamp the password field width because
markusheintz_ 2013/11/26 12:44:37 nit: s/; we/. We/
npentrel 2013/11/26 14:25:55 Done.
164 // ManagePasswordItemView::GetPasswordFisplayString() does this.
156 165
157 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 166 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
158 const int kPredefinedFieldMaxWidth = 167 const int predefined_username_field_max_width =
markusheintz_ 2013/11/26 12:44:37 bad name format: Please follow the Google C++ styl
npentrel 2013/11/26 14:25:55 Not a compile time const.
159 rb->GetFont(ui::ResourceBundle::BaseFont).GetAverageCharacterWidth() * 22; 168 rb->GetFont(ui::ResourceBundle::BaseFont).GetAverageCharacterWidth() * 22;
160 const int kMaxUsernameFieldWidth = std::min( 169 const int max_username_or_password_width =
markusheintz_ 2013/11/26 12:44:37 bad name format: Please follow the Google C++ styl
npentrel 2013/11/26 14:25:55 Not a compile time const.
161 GetMaximumUsernameOrPasswordWidth(true), kPredefinedFieldMaxWidth); 170 std::min(GetMaximumUsernameOrPasswordWidth(true),
162 const int kFirstFieldWidth = std::max(kMaxUsernameFieldWidth, 171 predefined_username_field_max_width);
172 const int first_field_width = std::max(max_username_or_password_width,
markusheintz_ 2013/11/26 12:44:37 bad name format: Please follow the Google C++ styl
npentrel 2013/11/26 14:25:55 Not a compile time const.
163 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)). 173 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)).
164 GetPreferredSize().width()); 174 GetPreferredSize().width());
165 175
166 const int kMaxPasswordFieldWidth = GetMaximumUsernameOrPasswordWidth(false); 176 const int second_field_width = std::max(
markusheintz_ 2013/11/26 12:44:37 bad name format: Please follow the Google C++ styl
npentrel 2013/11/26 14:25:55 Not a compile time const.
167 const int kSecondFieldWidth = std::max(kMaxPasswordFieldWidth, 177 GetMaximumUsernameOrPasswordWidth(false),
168 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)). 178 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)).
169 GetPreferredSize().width()); 179 GetPreferredSize().width());
170 180
171 const int kSingleColumnSetId = 0; 181 const int kSingleColumnSetId = 0;
172 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId); 182 views::ColumnSet* column_set = layout->AddColumnSet(kSingleColumnSetId);
173 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 183 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
174 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0, 184 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
175 GridLayout::USE_PREF, 0, 0); 185 GridLayout::USE_PREF, 0, 0);
176 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 186 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
177 187
(...skipping 13 matching lines...) Expand all
191 views::ColumnSet* single_column = 201 views::ColumnSet* single_column =
192 layout->AddColumnSet(kSingleColumnCredentialsId); 202 layout->AddColumnSet(kSingleColumnCredentialsId);
193 single_column->AddPaddingColumn(0, views::kPanelHorizMargin); 203 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
194 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 204 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
195 GridLayout::USE_PREF, 0, 0); 205 GridLayout::USE_PREF, 0, 0);
196 single_column->AddPaddingColumn(0, views::kPanelHorizMargin); 206 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
197 207
198 layout->StartRow(0, kSingleColumnCredentialsId); 208 layout->StartRow(0, kSingleColumnCredentialsId);
199 ManagePasswordItemView* item = new ManagePasswordItemView( 209 ManagePasswordItemView* item = new ManagePasswordItemView(
200 manage_passwords_bubble_model_, 210 manage_passwords_bubble_model_,
201 manage_passwords_bubble_model_->pending_credentials(), kFirstFieldWidth, 211 manage_passwords_bubble_model_->pending_credentials(),
202 kSecondFieldWidth); 212 first_field_width, second_field_width);
203 item->set_border(views::Border::CreateSolidSidedBorder( 213 item->set_border(views::Border::CreateSolidSidedBorder(
204 1, 0, 1, 0, GetNativeTheme()->GetSystemColor( 214 1, 0, 1, 0, GetNativeTheme()->GetSystemColor(
205 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); 215 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
206 layout->AddView(item); 216 layout->AddView(item);
207 217
208 const int kDoubleColumnSetId = 2; 218 const int kDoubleColumnSetId = 2;
209 views::ColumnSet* double_column_set = 219 views::ColumnSet* double_column_set =
210 layout->AddColumnSet(kDoubleColumnSetId); 220 layout->AddColumnSet(kDoubleColumnSetId);
211 double_column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 221 double_column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
212 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1, 222 double_column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 1,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 257 single_column->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
248 GridLayout::USE_PREF, 0, 0); 258 GridLayout::USE_PREF, 0, 0);
249 single_column->AddPaddingColumn(0, views::kPanelHorizMargin); 259 single_column->AddPaddingColumn(0, views::kPanelHorizMargin);
250 260
251 if (!manage_passwords_bubble_model_->best_matches().empty()) { 261 if (!manage_passwords_bubble_model_->best_matches().empty()) {
252 for (autofill::PasswordFormMap::const_iterator i( 262 for (autofill::PasswordFormMap::const_iterator i(
253 manage_passwords_bubble_model_->best_matches().begin()); 263 manage_passwords_bubble_model_->best_matches().begin());
254 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { 264 i != manage_passwords_bubble_model_->best_matches().end(); ++i) {
255 layout->StartRow(0, kSingleColumnCredentialsId); 265 layout->StartRow(0, kSingleColumnCredentialsId);
256 ManagePasswordItemView* item = new ManagePasswordItemView( 266 ManagePasswordItemView* item = new ManagePasswordItemView(
257 manage_passwords_bubble_model_, *i->second, kFirstFieldWidth, 267 manage_passwords_bubble_model_, *i->second, first_field_width,
258 kSecondFieldWidth); 268 second_field_width);
259 if (i == manage_passwords_bubble_model_->best_matches().begin()) { 269 if (i == manage_passwords_bubble_model_->best_matches().begin()) {
260 item->set_border(views::Border::CreateSolidSidedBorder( 270 item->set_border(views::Border::CreateSolidSidedBorder(
261 1, 0, 1, 0, GetNativeTheme()->GetSystemColor( 271 1, 0, 1, 0, GetNativeTheme()->GetSystemColor(
262 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); 272 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
263 } else { 273 } else {
264 item->set_border(views::Border::CreateSolidSidedBorder( 274 item->set_border(views::Border::CreateSolidSidedBorder(
265 0, 0, 1, 0, GetNativeTheme()->GetSystemColor( 275 0, 0, 1, 0, GetNativeTheme()->GetSystemColor(
266 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); 276 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
267 } 277 }
268 layout->AddView(item); 278 layout->AddView(item);
269 } 279 }
270 } else if (!manage_passwords_bubble_model_->password_submitted()) { 280 } else if (!manage_passwords_bubble_model_->password_submitted()) {
271 views::Label* empty_label = new views::Label( 281 views::Label* empty_label = new views::Label(
272 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); 282 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS));
273 empty_label->SetMultiLine(true); 283 empty_label->SetMultiLine(true);
274 layout->StartRow(0, kSingleColumnSetId); 284 layout->StartRow(0, kSingleColumnSetId);
275 layout->AddView(empty_label); 285 layout->AddView(empty_label);
276 } 286 }
277 287
278 if (manage_passwords_bubble_model_->password_submitted()) { 288 if (manage_passwords_bubble_model_->password_submitted()) {
279 layout->StartRow(0, kSingleColumnCredentialsId); 289 layout->StartRow(0, kSingleColumnCredentialsId);
280 ManagePasswordItemView* item = new ManagePasswordItemView( 290 ManagePasswordItemView* item = new ManagePasswordItemView(
281 manage_passwords_bubble_model_, 291 manage_passwords_bubble_model_,
282 manage_passwords_bubble_model_->pending_credentials(), 292 manage_passwords_bubble_model_->pending_credentials(),
283 kFirstFieldWidth, kSecondFieldWidth); 293 first_field_width, second_field_width);
284 if (manage_passwords_bubble_model_->best_matches().empty()) { 294 if (manage_passwords_bubble_model_->best_matches().empty()) {
285 item->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, 295 item->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0,
286 GetNativeTheme()->GetSystemColor( 296 GetNativeTheme()->GetSystemColor(
287 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); 297 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
288 } else { 298 } else {
289 item->set_border(views::Border::CreateSolidSidedBorder(0, 0, 1, 0, 299 item->set_border(views::Border::CreateSolidSidedBorder(0, 0, 1, 0,
290 GetNativeTheme()->GetSystemColor( 300 GetNativeTheme()->GetSystemColor(
291 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor))); 301 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor)));
292 } 302 }
293 layout->AddView(item); 303 layout->AddView(item);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 manage_passwords_bubble_model_->manage_passwords_bubble_state() == 336 manage_passwords_bubble_model_->manage_passwords_bubble_state() ==
327 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED); 337 ManagePasswordsBubbleModel::PASSWORD_TO_BE_SAVED);
328 Close(); 338 Close();
329 } 339 }
330 340
331 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, 341 void ManagePasswordsBubbleView::LinkClicked(views::Link* source,
332 int event_flags) { 342 int event_flags) {
333 DCHECK_EQ(source, manage_link_); 343 DCHECK_EQ(source, manage_link_);
334 manage_passwords_bubble_model_->OnManageLinkClicked(); 344 manage_passwords_bubble_model_->OnManageLinkClicked();
335 } 345 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698