| 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/common/autofill_messages.h" | 9 #include "chrome/common/autofill_messages.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| 11 #include "ui/views/controls/button/text_button.h" | 11 #include "ui/views/controls/button/text_button.h" |
| 12 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
| 13 #include "ui/views/controls/textfield/textfield.h" | 13 #include "ui/views/controls/textfield/textfield.h" |
| 14 #include "ui/views/layout/grid_layout.h" | 14 #include "ui/views/layout/grid_layout.h" |
| 15 #include "ui/views/layout/layout_constants.h" | 15 #include "ui/views/layout/layout_constants.h" |
| 16 | 16 |
| 17 using views::ColumnSet; | 17 using views::ColumnSet; |
| 18 using views::GridLayout; | 18 using views::GridLayout; |
| 19 | 19 |
| 20 PasswordGenerationBubbleView::PasswordGenerationBubbleView( | 20 PasswordGenerationBubbleView::PasswordGenerationBubbleView( |
| 21 const gfx::Rect& anchor_rect, | 21 const gfx::Rect& anchor_rect, |
| 22 views::View* anchor_view, | 22 views::View* anchor_view, |
| 23 content::RenderViewHost* render_view_host) | 23 content::RenderViewHost* render_view_host, |
| 24 autofill::PasswordGenerator* password_generator) |
| 24 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 25 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
| 25 accept_button_(NULL), | 26 accept_button_(NULL), |
| 26 text_field_(NULL), | 27 text_field_(NULL), |
| 27 anchor_rect_(anchor_rect), | 28 anchor_rect_(anchor_rect), |
| 28 render_view_host_(render_view_host) {} | 29 render_view_host_(render_view_host), |
| 30 password_generator_(password_generator) {} |
| 29 | 31 |
| 30 PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {} | 32 PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {} |
| 31 | 33 |
| 32 void PasswordGenerationBubbleView::Init() { | 34 void PasswordGenerationBubbleView::Init() { |
| 33 // TODO(gcasto): Localize text after we have finalized the UI. | 35 // TODO(gcasto): Localize text after we have finalized the UI. |
| 34 // crbug.com/118062 | 36 // crbug.com/118062 |
| 35 accept_button_ = new views::NativeTextButton(this, | 37 accept_button_ = new views::NativeTextButton(this, |
| 36 ASCIIToUTF16("Try It")); | 38 ASCIIToUTF16("Try It")); |
| 37 | 39 |
| 38 text_field_ = new views::Textfield(); | 40 text_field_ = new views::Textfield(); |
| 39 text_field_->SetText(ASCIIToUTF16(password_generator_.Generate())); | 41 text_field_->SetText( |
| 42 ASCIIToUTF16(password_generator_->Generate())); |
| 40 | 43 |
| 41 views::Label* title_label = new views::Label( | 44 views::Label* title_label = new views::Label( |
| 42 ASCIIToUTF16("Password Suggestion")); | 45 ASCIIToUTF16("Password Suggestion")); |
| 43 | 46 |
| 44 GridLayout* layout = new GridLayout(this); | 47 GridLayout* layout = new GridLayout(this); |
| 45 SetLayoutManager(layout); | 48 SetLayoutManager(layout); |
| 46 | 49 |
| 47 // Title row. | 50 // Title row. |
| 48 ColumnSet* cs = layout->AddColumnSet(0); | 51 ColumnSet* cs = layout->AddColumnSet(0); |
| 49 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 52 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 } | 73 } |
| 71 | 74 |
| 72 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, | 75 void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender, |
| 73 const views::Event& event) { | 76 const views::Event& event) { |
| 74 if (sender == accept_button_) { | 77 if (sender == accept_button_) { |
| 75 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( | 78 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( |
| 76 render_view_host_->GetRoutingID(), text_field_->text())); | 79 render_view_host_->GetRoutingID(), text_field_->text())); |
| 77 StartFade(false); | 80 StartFade(false); |
| 78 } | 81 } |
| 79 } | 82 } |
| OLD | NEW |