Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/password_generation_bubble_view.h" | 5 #include "chrome/browser/ui/views/password_generation_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autofill/password_generator.h" | 8 #include "chrome/browser/autofill/password_generator.h" |
| 9 #include "chrome/browser/password_manager/password_manager.h" | 9 #include "chrome/browser/password_manager/password_manager.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/common/autofill_messages.h" | 12 #include "chrome/common/autofill_messages.h" |
| 13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "content/public/browser/page_navigator.h" | 14 #include "content/public/browser/page_navigator.h" |
| 15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources_standard.h" | |
| 19 #include "ui/base/theme_provider.h" | |
| 18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/views/controls/button/image_button.h" | |
| 19 #include "ui/views/controls/button/text_button.h" | 22 #include "ui/views/controls/button/text_button.h" |
| 20 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/controls/link.h" | 24 #include "ui/views/controls/link.h" |
| 22 #include "ui/views/controls/textfield/textfield.h" | 25 #include "ui/views/controls/textfield/textfield.h" |
| 23 #include "ui/views/layout/grid_layout.h" | 26 #include "ui/views/layout/grid_layout.h" |
| 24 #include "ui/views/layout/layout_constants.h" | 27 #include "ui/views/layout/layout_constants.h" |
| 25 | 28 |
| 26 using views::ColumnSet; | 29 using views::ColumnSet; |
| 27 using views::GridLayout; | 30 using views::GridLayout; |
| 28 | 31 |
| 29 PasswordGenerationBubbleView::PasswordGenerationBubbleView( | 32 PasswordGenerationBubbleView::PasswordGenerationBubbleView( |
| 30 const gfx::Rect& anchor_rect, | 33 const gfx::Rect& anchor_rect, |
| 31 const webkit::forms::PasswordForm& form, | 34 const webkit::forms::PasswordForm& form, |
| 32 views::View* anchor_view, | 35 views::View* anchor_view, |
| 33 content::RenderViewHost* render_view_host, | 36 content::RenderViewHost* render_view_host, |
| 34 autofill::PasswordGenerator* password_generator, | 37 autofill::PasswordGenerator* password_generator, |
| 35 content::PageNavigator* navigator, | 38 content::PageNavigator* navigator, |
| 36 PasswordManager* password_manager) | 39 PasswordManager* password_manager, |
| 40 ui::ThemeProvider* theme_provider) | |
| 37 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 41 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
| 38 accept_button_(NULL), | 42 accept_button_(NULL), |
| 43 regenerate_button_(NULL), | |
| 39 text_field_(NULL), | 44 text_field_(NULL), |
| 40 anchor_rect_(anchor_rect), | 45 anchor_rect_(anchor_rect), |
| 41 form_(form), | 46 form_(form), |
| 42 render_view_host_(render_view_host), | 47 render_view_host_(render_view_host), |
| 43 password_generator_(password_generator), | 48 password_generator_(password_generator), |
| 44 navigator_(navigator), | 49 navigator_(navigator), |
| 45 password_manager_(password_manager) {} | 50 password_manager_(password_manager), |
| 51 theme_provider_(theme_provider){} | |
|
Ben Goodger (Google)
2012/06/22 16:19:31
you deleted a space here, put it back
zysxqn
2012/06/22 23:42:52
Done.
| |
| 46 | 52 |
| 47 PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {} | 53 PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {} |
| 48 | 54 |
| 49 void PasswordGenerationBubbleView::Init() { | 55 void PasswordGenerationBubbleView::Init() { |
| 50 // TODO(gcasto): Localize text after we have finalized the UI. | 56 // TODO(gcasto): Localize text after we have finalized the UI. |
| 51 // crbug.com/118062 | 57 // crbug.com/118062 |
| 52 accept_button_ = new views::NativeTextButton(this, | 58 accept_button_ = new views::NativeTextButton(this, |
| 53 ASCIIToUTF16("Try It")); | 59 ASCIIToUTF16("Try It")); |
| 54 | 60 |
| 61 regenerate_button_ = new views::ImageButton(this); | |
| 62 regenerate_button_->SetImage(views::CustomButton::BS_NORMAL, | |
| 63 theme_provider_->GetImageSkiaNamed(IDR_RELOAD)); | |
| 64 regenerate_button_->SetImage(views::CustomButton::BS_HOT, | |
| 65 theme_provider_->GetImageSkiaNamed(IDR_RELOAD_H)); | |
| 66 regenerate_button_->SetImage(views::CustomButton::BS_PUSHED, | |
| 67 theme_provider_->GetImageSkiaNamed(IDR_RELOAD_P)); | |
| 68 regenerate_button_->SetTooltipText(ASCIIToUTF16("Regenerate")); | |
| 69 | |
| 55 text_field_ = new views::Textfield(); | 70 text_field_ = new views::Textfield(); |
| 56 text_field_->SetText( | 71 text_field_->SetText( |
| 57 ASCIIToUTF16(password_generator_->Generate())); | 72 ASCIIToUTF16(password_generator_->Generate())); |
| 58 | 73 |
| 59 views::Label* title_label = new views::Label( | 74 views::Label* title_label = new views::Label( |
| 60 ASCIIToUTF16("Password Suggestion")); | 75 ASCIIToUTF16("Password Suggestion")); |
| 61 | 76 |
| 62 views::Link* learn_more_link = new views::Link( | 77 views::Link* learn_more_link = new views::Link( |
| 63 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 78 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
| 64 learn_more_link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 79 learn_more_link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 65 learn_more_link->set_listener(this); | 80 learn_more_link->set_listener(this); |
| 66 | 81 |
| 67 GridLayout* layout = new GridLayout(this); | 82 GridLayout* layout = new GridLayout(this); |
| 68 SetLayoutManager(layout); | 83 SetLayoutManager(layout); |
| 69 | 84 |
| 70 // Title row. | 85 // Title row. |
| 71 ColumnSet* cs = layout->AddColumnSet(0); | 86 ColumnSet* cs = layout->AddColumnSet(0); |
| 72 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | 87 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 73 GridLayout::USE_PREF, 0, 100); | 88 GridLayout::USE_PREF, 0, 100); |
| 74 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 89 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
| 75 cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 90 cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 76 GridLayout::USE_PREF, 0, 0); | 91 GridLayout::USE_PREF, 0, 0); |
| 77 | 92 |
| 78 // Input row | 93 // Input row |
| 79 cs = layout->AddColumnSet(1); | 94 cs = layout->AddColumnSet(1); |
| 80 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | 95 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 81 GridLayout::USE_PREF, 0, 100); | 96 GridLayout::USE_PREF, 0, 100); |
| 97 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, GridLayout::FIXED, | |
| 98 regenerate_button_->GetPreferredSize().width(), 100); | |
| 82 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 99 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
| 83 cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, | 100 cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0, |
| 84 GridLayout::USE_PREF, 0, 0); | 101 GridLayout::USE_PREF, 0, 0); |
| 85 | 102 |
| 86 layout->StartRow(0, 0); | 103 layout->StartRow(0, 0); |
| 87 layout->AddView(title_label); | 104 layout->AddView(title_label); |
| 88 layout->AddView(learn_more_link); | 105 layout->AddView(learn_more_link); |
| 89 | 106 |
| 90 layout->StartRow(0, 1); | 107 layout->StartRow(0, 1); |
| 91 layout->AddView(text_field_); | 108 layout->AddView(text_field_); |
| 109 layout->AddView(regenerate_button_); | |
| 92 layout->AddView(accept_button_); | 110 layout->AddView(accept_button_); |
| 93 } | 111 } |
| 94 | 112 |
| 95 gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() { | 113 gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() { |
| 96 return anchor_rect_; | 114 return anchor_rect_; |
| 97 } | 115 } |
| 98 | 116 |
| 99 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, | 117 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, |
| 100 const views::Event& event) { | 118 const views::Event& event) { |
| 101 if (sender == accept_button_) { | 119 if (sender == accept_button_) { |
| 102 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( | 120 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( |
| 103 render_view_host_->GetRoutingID(), text_field_->text())); | 121 render_view_host_->GetRoutingID(), text_field_->text())); |
| 104 password_manager_->SetFormHasGeneratedPassword(form_); | 122 password_manager_->SetFormHasGeneratedPassword(form_); |
| 105 StartFade(false); | 123 StartFade(false); |
| 124 } else if (sender == regenerate_button_) { | |
| 125 text_field_->SetText( | |
| 126 ASCIIToUTF16(password_generator_->Generate())); | |
| 106 } | 127 } |
| 107 } | 128 } |
| 108 | 129 |
| 109 void PasswordGenerationBubbleView::LinkClicked(views::Link* source, | 130 void PasswordGenerationBubbleView::LinkClicked(views::Link* source, |
| 110 int event_flags) { | 131 int event_flags) { |
| 111 content::OpenURLParams params( | 132 content::OpenURLParams params( |
| 112 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), | 133 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), |
| 113 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | 134 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); |
| 114 navigator_->OpenURL(params); | 135 navigator_->OpenURL(params); |
| 115 StartFade(false); | 136 StartFade(false); |
| 116 } | 137 } |
| 117 | 138 |
| 118 views::View* PasswordGenerationBubbleView::GetInitiallyFocusedView() { | 139 views::View* PasswordGenerationBubbleView::GetInitiallyFocusedView() { |
| 119 return text_field_; | 140 return text_field_; |
| 120 } | 141 } |
| OLD | NEW |