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/passwords/manage_passwords_bubble_ui_controller.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" | 15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" |
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
17 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.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/base/models/combobox_model.h" | 20 #include "ui/base/models/combobox_model.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/text_utils.h" | 22 #include "ui/gfx/text_utils.h" |
23 #include "ui/views/controls/button/blue_button.h" | 23 #include "ui/views/controls/button/blue_button.h" |
24 #include "ui/views/controls/button/label_button.h" | 24 #include "ui/views/controls/button/label_button.h" |
25 #include "ui/views/controls/combobox/combobox.h" | 25 #include "ui/views/controls/combobox/combobox.h" |
| 26 #include "ui/views/layout/fill_layout.h" |
26 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
27 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
28 | 29 |
29 | 30 |
30 // Helpers -------------------------------------------------------------------- | 31 // Helpers -------------------------------------------------------------------- |
31 | 32 |
32 namespace { | 33 namespace { |
| 34 enum ColumnSetType { |
| 35 // | | (FILL, FILL) | | |
| 36 // Used for the bubble's header, the credentials list, and for simple |
| 37 // messages like "No passwords". |
| 38 SINGLE_VIEW_COLUMN_SET = 0, |
33 | 39 |
34 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; | 40 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | | |
| 41 // Used for buttons at the bottom of the bubble which should nest at the |
| 42 // bottom-right corner. |
| 43 DOUBLE_BUTTON_COLUMN_SET = 1, |
35 | 44 |
36 // Upper limit on the size of the username and password fields. | 45 // | | (LEADING, CENTER) | | (TRAILING, CENTER) | | |
37 const int kUsernameFieldSize = 30; | 46 // Used for buttons at the bottom of the bubble which should occupy |
38 const int kPasswordFieldSize = 22; | 47 // the corners. |
| 48 LINK_BUTTON_COLUMN_SET = 2, |
| 49 }; |
39 | 50 |
40 // Returns the width of |type| field. | 51 // Construct an appropriate ColumnSet for the given |type|, and add it |
41 int GetFieldWidth(FieldType type) { | 52 // to |layout|. |
42 return ui::ResourceBundle::GetSharedInstance() | 53 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) { |
43 .GetFontList(ui::ResourceBundle::SmallFont) | 54 views::ColumnSet* column_set = layout->AddColumnSet(type); |
44 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize | 55 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
45 : kPasswordFieldSize); | 56 switch (type) { |
| 57 case SINGLE_VIEW_COLUMN_SET: |
| 58 column_set->AddColumn(views::GridLayout::FILL, |
| 59 views::GridLayout::FILL, |
| 60 0, |
| 61 views::GridLayout::USE_PREF, |
| 62 0, |
| 63 0); |
| 64 break; |
| 65 |
| 66 case DOUBLE_BUTTON_COLUMN_SET: |
| 67 column_set->AddColumn(views::GridLayout::TRAILING, |
| 68 views::GridLayout::CENTER, |
| 69 1, |
| 70 views::GridLayout::USE_PREF, |
| 71 0, |
| 72 0); |
| 73 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 74 column_set->AddColumn(views::GridLayout::TRAILING, |
| 75 views::GridLayout::CENTER, |
| 76 0, |
| 77 views::GridLayout::USE_PREF, |
| 78 0, |
| 79 0); |
| 80 break; |
| 81 case LINK_BUTTON_COLUMN_SET: |
| 82 column_set->AddColumn(views::GridLayout::LEADING, |
| 83 views::GridLayout::CENTER, |
| 84 1, |
| 85 views::GridLayout::USE_PREF, |
| 86 0, |
| 87 0); |
| 88 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 89 column_set->AddColumn(views::GridLayout::TRAILING, |
| 90 views::GridLayout::CENTER, |
| 91 0, |
| 92 views::GridLayout::USE_PREF, |
| 93 0, |
| 94 0); |
| 95 break; |
| 96 } |
| 97 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
| 98 } |
| 99 |
| 100 // Given a layout and a model, add an appropriate title using a |
| 101 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row. |
| 102 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) { |
| 103 views::Label* title_label = new views::Label(model->title()); |
| 104 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 105 title_label->SetMultiLine(true); |
| 106 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 107 ui::ResourceBundle::MediumFont)); |
| 108 |
| 109 // Add the title to the layout with appropriate padding. |
| 110 layout->StartRowWithPadding( |
| 111 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
| 112 layout->AddView(title_label); |
| 113 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
46 } | 114 } |
47 | 115 |
48 } // namespace | 116 } // namespace |
49 | 117 |
50 | 118 |
51 // Globals -------------------------------------------------------------------- | 119 // Globals -------------------------------------------------------------------- |
52 | 120 |
53 namespace chrome { | 121 namespace chrome { |
54 | 122 |
55 void ShowManagePasswordsBubble(content::WebContents* web_contents) { | 123 void ShowManagePasswordsBubble(content::WebContents* web_contents) { |
56 ManagePasswordsBubbleUIController* controller = | 124 ManagePasswordsBubbleUIController* controller = |
57 ManagePasswordsBubbleUIController::FromWebContents(web_contents); | 125 ManagePasswordsBubbleUIController::FromWebContents(web_contents); |
58 ManagePasswordsBubbleView::ShowBubble( | 126 ManagePasswordsBubbleView::ShowBubble( |
59 web_contents, | 127 web_contents, |
60 controller->manage_passwords_bubble_needs_showing() ? | 128 controller->manage_passwords_bubble_needs_showing() ? |
61 ManagePasswordsBubbleView::AUTOMATIC : | 129 ManagePasswordsBubbleView::AUTOMATIC : |
62 ManagePasswordsBubbleView::USER_ACTION); | 130 ManagePasswordsBubbleView::USER_ACTION); |
63 } | 131 } |
64 | 132 |
65 } // namespace chrome | 133 } // namespace chrome |
66 | 134 |
67 | 135 |
| 136 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
| 137 |
| 138 ManagePasswordsBubbleView::PendingView::PendingView( |
| 139 ManagePasswordsBubbleView* parent) |
| 140 : parent_(parent) { |
| 141 views::GridLayout* layout = new views::GridLayout(this); |
| 142 SetLayoutManager(layout); |
| 143 |
| 144 // Create the pending credential item, save button and refusal combobox. |
| 145 ManagePasswordItemView* item = |
| 146 new ManagePasswordItemView(parent->model(), |
| 147 parent->model()->pending_credentials(), |
| 148 ManagePasswordItemView::FIRST_ITEM); |
| 149 save_button_ = new views::BlueButton( |
| 150 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
| 151 |
| 152 combobox_model_.reset(new SavePasswordRefusalComboboxModel()); |
| 153 refuse_combobox_.reset(new views::Combobox(combobox_model_.get())); |
| 154 refuse_combobox_->set_listener(this); |
| 155 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); |
| 156 |
| 157 // Title row. |
| 158 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 159 AddTitleRow(layout, parent_->model()); |
| 160 |
| 161 // Credential row. |
| 162 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 163 layout->AddView(item); |
| 164 |
| 165 // Button row. |
| 166 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 167 layout->StartRowWithPadding( |
| 168 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| 169 layout->AddView(save_button_); |
| 170 layout->AddView(refuse_combobox_.get()); |
| 171 |
| 172 // Extra padding for visual awesomeness. |
| 173 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 174 } |
| 175 |
| 176 ManagePasswordsBubbleView::PendingView::~PendingView() { |
| 177 } |
| 178 |
| 179 void ManagePasswordsBubbleView::PendingView::ButtonPressed( |
| 180 views::Button* sender, |
| 181 const ui::Event& event) { |
| 182 DCHECK(sender == save_button_); |
| 183 parent_->model()->OnSaveClicked(); |
| 184 parent_->Close(); |
| 185 } |
| 186 |
| 187 void ManagePasswordsBubbleView::PendingView::OnPerformAction( |
| 188 views::Combobox* source) { |
| 189 DCHECK_EQ(source, refuse_combobox_); |
| 190 switch (refuse_combobox_->selected_index()) { |
| 191 case SavePasswordRefusalComboboxModel::INDEX_NOPE: |
| 192 parent_->model()->OnNopeClicked(); |
| 193 break; |
| 194 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
| 195 parent_->model()->OnNeverForThisSiteClicked(); |
| 196 break; |
| 197 } |
| 198 parent_->Close(); |
| 199 } |
| 200 |
| 201 // ManagePasswordsBubbleView::ManageView -------------------------------------- |
| 202 |
| 203 ManagePasswordsBubbleView::ManageView::ManageView( |
| 204 ManagePasswordsBubbleView* parent) |
| 205 : parent_(parent) { |
| 206 views::GridLayout* layout = new views::GridLayout(this); |
| 207 SetLayoutManager(layout); |
| 208 |
| 209 // Add the title. |
| 210 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 211 AddTitleRow(layout, parent_->model()); |
| 212 |
| 213 // If we have a list of passwords to store for the current site, display |
| 214 // them to the user for management. Otherwise, render a "No passwords for |
| 215 // this site" message. |
| 216 if (!parent_->model()->best_matches().empty()) { |
| 217 for (autofill::PasswordFormMap::const_iterator i( |
| 218 parent_->model()->best_matches().begin()); |
| 219 i != parent_->model()->best_matches().end(); |
| 220 ++i) { |
| 221 ManagePasswordItemView* item = new ManagePasswordItemView( |
| 222 parent_->model(), |
| 223 *i->second, |
| 224 i == parent_->model()->best_matches().begin() |
| 225 ? ManagePasswordItemView::FIRST_ITEM |
| 226 : ManagePasswordItemView::SUBSEQUENT_ITEM); |
| 227 |
| 228 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 229 layout->AddView(item); |
| 230 } |
| 231 } else { |
| 232 views::Label* empty_label = new views::Label( |
| 233 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
| 234 empty_label->SetMultiLine(true); |
| 235 |
| 236 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 237 layout->AddView(empty_label); |
| 238 } |
| 239 |
| 240 // Then add the "manage passwords" link and "Done" button. |
| 241 manage_link_ = new views::Link(parent_->model()->manage_link()); |
| 242 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 243 manage_link_->SetUnderline(false); |
| 244 manage_link_->set_listener(this); |
| 245 |
| 246 done_button_ = |
| 247 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
| 248 done_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 249 |
| 250 BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); |
| 251 layout->StartRowWithPadding( |
| 252 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| 253 layout->AddView(manage_link_); |
| 254 layout->AddView(done_button_); |
| 255 |
| 256 // Extra padding for visual awesomeness. |
| 257 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 258 } |
| 259 |
| 260 ManagePasswordsBubbleView::ManageView::~ManageView() { |
| 261 } |
| 262 |
| 263 void ManagePasswordsBubbleView::ManageView::ButtonPressed( |
| 264 views::Button* sender, |
| 265 const ui::Event& event) { |
| 266 DCHECK(sender == done_button_); |
| 267 parent_->model()->OnDoneClicked(); |
| 268 parent_->Close(); |
| 269 } |
| 270 |
| 271 void ManagePasswordsBubbleView::ManageView::LinkClicked(views::Link* source, |
| 272 int event_flags) { |
| 273 DCHECK_EQ(source, manage_link_); |
| 274 parent_->model()->OnManageLinkClicked(); |
| 275 parent_->Close(); |
| 276 } |
| 277 |
| 278 |
68 // ManagePasswordsBubbleView -------------------------------------------------- | 279 // ManagePasswordsBubbleView -------------------------------------------------- |
69 | 280 |
70 // static | 281 // static |
71 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 282 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
72 NULL; | 283 NULL; |
73 | 284 |
74 // static | 285 // static |
75 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 286 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
76 DisplayReason reason) { | 287 DisplayReason reason) { |
77 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 288 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 BubbleDelegateView(anchor_view, | 337 BubbleDelegateView(anchor_view, |
127 anchor_view ? views::BubbleBorder::TOP_RIGHT | 338 anchor_view ? views::BubbleBorder::TOP_RIGHT |
128 : views::BubbleBorder::NONE) { | 339 : views::BubbleBorder::NONE) { |
129 // Compensate for built-in vertical padding in the anchor view's image. | 340 // Compensate for built-in vertical padding in the anchor view's image. |
130 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 341 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
131 set_notify_enter_exit_on_child(true); | 342 set_notify_enter_exit_on_child(true); |
132 } | 343 } |
133 | 344 |
134 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} | 345 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} |
135 | 346 |
136 void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout, | |
137 ColumnSetType type) { | |
138 views::ColumnSet* column_set = layout->AddColumnSet(type); | |
139 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
140 switch (type) { | |
141 case SINGLE_VIEW_COLUMN_SET: | |
142 column_set->AddColumn(views::GridLayout::FILL, | |
143 views::GridLayout::FILL, | |
144 0, | |
145 views::GridLayout::USE_PREF, | |
146 0, | |
147 0); | |
148 break; | |
149 | |
150 case DOUBLE_BUTTON_COLUMN_SET: | |
151 column_set->AddColumn(views::GridLayout::TRAILING, | |
152 views::GridLayout::CENTER, | |
153 1, | |
154 views::GridLayout::USE_PREF, | |
155 0, | |
156 0); | |
157 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
158 column_set->AddColumn(views::GridLayout::TRAILING, | |
159 views::GridLayout::CENTER, | |
160 0, | |
161 views::GridLayout::USE_PREF, | |
162 0, | |
163 0); | |
164 break; | |
165 case LINK_BUTTON_COLUMN_SET: | |
166 column_set->AddColumn(views::GridLayout::LEADING, | |
167 views::GridLayout::CENTER, | |
168 1, | |
169 views::GridLayout::USE_PREF, | |
170 0, | |
171 0); | |
172 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
173 column_set->AddColumn(views::GridLayout::TRAILING, | |
174 views::GridLayout::CENTER, | |
175 0, | |
176 views::GridLayout::USE_PREF, | |
177 0, | |
178 0); | |
179 break; | |
180 } | |
181 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
182 } | |
183 | |
184 void ManagePasswordsBubbleView::AdjustForFullscreen( | 347 void ManagePasswordsBubbleView::AdjustForFullscreen( |
185 const gfx::Rect& screen_bounds) { | 348 const gfx::Rect& screen_bounds) { |
186 if (GetAnchorView()) | 349 if (GetAnchorView()) |
187 return; | 350 return; |
188 | 351 |
189 // The bubble's padding from the screen edge, used in fullscreen. | 352 // The bubble's padding from the screen edge, used in fullscreen. |
190 const int kFullscreenPaddingEnd = 20; | 353 const int kFullscreenPaddingEnd = 20; |
191 const size_t bubble_half_width = width() / 2; | 354 const size_t bubble_half_width = width() / 2; |
192 const int x_pos = base::i18n::IsRTL() ? | 355 const int x_pos = base::i18n::IsRTL() ? |
193 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 356 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
194 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 357 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
195 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 358 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
196 } | 359 } |
197 | 360 |
198 void ManagePasswordsBubbleView::Close() { | 361 void ManagePasswordsBubbleView::Close() { |
199 GetWidget()->Close(); | 362 GetWidget()->Close(); |
200 } | 363 } |
201 | 364 |
202 void ManagePasswordsBubbleView::CloseWithoutLogging() { | 365 void ManagePasswordsBubbleView::CloseWithoutLogging() { |
203 model()->OnCloseWithoutLogging(); | 366 model()->OnCloseWithoutLogging(); |
204 GetWidget()->Close(); | 367 GetWidget()->Close(); |
205 } | 368 } |
206 | 369 |
207 void ManagePasswordsBubbleView::Init() { | 370 void ManagePasswordsBubbleView::Init() { |
208 using views::GridLayout; | 371 views::FillLayout* layout = new views::FillLayout(); |
| 372 SetLayoutManager(layout); |
| 373 SetFocusable(true); |
209 | 374 |
210 GridLayout* layout = new GridLayout(this); | 375 if (model()->WaitingToSavePassword()) |
211 SetFocusable(true); | 376 AddChildView(new PendingView(this)); |
212 SetLayoutManager(layout); | 377 else |
213 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 378 AddChildView(new ManageView(this)); |
214 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); | |
215 BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); | |
216 | |
217 // This calculates the necessary widths for credential columns in the bubble. | |
218 const int first_field_width = std::max( | |
219 GetFieldWidth(USERNAME_FIELD), | |
220 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) | |
221 .GetPreferredSize() | |
222 .width()); | |
223 | |
224 const int second_field_width = std::max( | |
225 GetFieldWidth(PASSWORD_FIELD), | |
226 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) | |
227 .GetPreferredSize() | |
228 .width()); | |
229 | |
230 // Build and populate the header. | |
231 views::Label* title_label = new views::Label(model()->title()); | |
232 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
233 title_label->SetMultiLine(true); | |
234 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
235 ui::ResourceBundle::MediumFont)); | |
236 | |
237 layout->StartRowWithPadding( | |
238 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); | |
239 layout->AddView(title_label); | |
240 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
241 | |
242 if (model()->WaitingToSavePassword()) { | |
243 // If we've got a password that we're deciding whether or not to save, | |
244 // then we need to display a single-view columnset containing the | |
245 // ManagePasswordItemView, followed by double-view columnset containing | |
246 // a "Save" and "Reject" button. | |
247 ManagePasswordItemView* item = | |
248 new ManagePasswordItemView(model(), | |
249 model()->pending_credentials(), | |
250 first_field_width, | |
251 second_field_width, | |
252 ManagePasswordItemView::FIRST_ITEM); | |
253 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
254 layout->AddView(item); | |
255 | |
256 combobox_model_.reset(new SavePasswordRefusalComboboxModel()); | |
257 refuse_combobox_.reset(new views::Combobox(combobox_model_.get())); | |
258 refuse_combobox_->set_listener(this); | |
259 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); | |
260 | |
261 save_button_ = new views::BlueButton( | |
262 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); | |
263 | |
264 layout->StartRowWithPadding( | |
265 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
266 layout->AddView(save_button_); | |
267 layout->AddView(refuse_combobox_.get()); | |
268 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
269 } else { | |
270 // If we have a list of passwords to store for the current site, display | |
271 // them to the user for management. Otherwise, render a "No passwords for | |
272 // this site" message. | |
273 // | |
274 // TODO(mkwst): Do we really want the "No passwords" case? It would probably | |
275 // be better to only clear the pending password upon navigation, rather than | |
276 // as soon as the bubble closes. | |
277 if (!model()->best_matches().empty()) { | |
278 for (autofill::PasswordFormMap::const_iterator i( | |
279 model()->best_matches().begin()); | |
280 i != model()->best_matches().end(); | |
281 ++i) { | |
282 ManagePasswordItemView* item = new ManagePasswordItemView( | |
283 model(), | |
284 *i->second, | |
285 first_field_width, | |
286 second_field_width, | |
287 i == model()->best_matches().begin() | |
288 ? ManagePasswordItemView::FIRST_ITEM | |
289 : ManagePasswordItemView::SUBSEQUENT_ITEM); | |
290 | |
291 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
292 layout->AddView(item); | |
293 } | |
294 } else { | |
295 views::Label* empty_label = new views::Label( | |
296 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | |
297 empty_label->SetMultiLine(true); | |
298 | |
299 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
300 layout->AddView(empty_label); | |
301 } | |
302 | |
303 // Build a "manage" link and "done" button, and throw them both into a new | |
304 // row | |
305 // containing a double-view columnset. | |
306 manage_link_ = new views::Link(model()->manage_link()); | |
307 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
308 manage_link_->SetUnderline(false); | |
309 manage_link_->set_listener(this); | |
310 | |
311 done_button_ = | |
312 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | |
313 done_button_->SetStyle(views::Button::STYLE_BUTTON); | |
314 | |
315 layout->StartRowWithPadding( | |
316 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
317 layout->AddView(manage_link_); | |
318 layout->AddView(done_button_); | |
319 } | |
320 } | 379 } |
321 | 380 |
322 void ManagePasswordsBubbleView::WindowClosing() { | 381 void ManagePasswordsBubbleView::WindowClosing() { |
323 // Close() closes the window asynchronously, so by the time we reach here, | 382 // Close() closes the window asynchronously, so by the time we reach here, |
324 // |manage_passwords_bubble_| may have already been reset. | 383 // |manage_passwords_bubble_| may have already been reset. |
325 if (manage_passwords_bubble_ == this) | 384 if (manage_passwords_bubble_ == this) |
326 manage_passwords_bubble_ = NULL; | 385 manage_passwords_bubble_ = NULL; |
327 } | 386 } |
328 | |
329 void ManagePasswordsBubbleView::ButtonPressed(views::Button* sender, | |
330 const ui::Event& event) { | |
331 DCHECK(sender == save_button_ || sender == done_button_); | |
332 | |
333 if (sender == save_button_) | |
334 model()->OnSaveClicked(); | |
335 else | |
336 model()->OnDoneClicked(); | |
337 Close(); | |
338 } | |
339 | |
340 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, | |
341 int event_flags) { | |
342 DCHECK_EQ(source, manage_link_); | |
343 model()->OnManageLinkClicked(); | |
344 Close(); | |
345 } | |
346 | |
347 void ManagePasswordsBubbleView::OnPerformAction(views::Combobox* source) { | |
348 DCHECK_EQ(source, refuse_combobox_); | |
349 switch (refuse_combobox_->selected_index()) { | |
350 case SavePasswordRefusalComboboxModel::INDEX_NOPE: | |
351 model()->OnNopeClicked(); | |
352 break; | |
353 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: | |
354 model()->OnNeverForThisSiteClicked(); | |
355 break; | |
356 default: | |
357 NOTREACHED(); | |
358 break; | |
359 } | |
360 Close(); | |
361 } | |
OLD | NEW |