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/gtk/password_generation_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/password_generation_bubble_gtk.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/platform_util.h" | |
|
Garrett Casto
2012/04/26 21:45:15
Why did you add this?
zysxqn
2012/04/26 23:46:25
Forgot to remove this after I decided not to use s
| |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_window.h" | |
| 8 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 11 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
| 12 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | |
| 13 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 9 #include "chrome/browser/ui/gtk/theme_service_gtk.h" | 14 #include "chrome/browser/ui/gtk/theme_service_gtk.h" |
| 10 #include "chrome/common/autofill_messages.h" | 15 #include "chrome/common/autofill_messages.h" |
| 16 #include "chrome/common/url_constants.h" | |
| 11 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
| 18 #include "grit/generated_resources.h" | |
| 12 #include "ui/base/gtk/gtk_hig_constants.h" | 19 #include "ui/base/gtk/gtk_hig_constants.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 13 | 21 |
| 14 const int kContentBorder = 4; | 22 const int kContentBorder = 4; |
| 15 const int kHorizontalSpacing = 4; | 23 const int kHorizontalSpacing = 4; |
| 16 | 24 |
| 17 PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk( | 25 PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk( |
| 18 const gfx::Rect& anchor_rect, | 26 const gfx::Rect& anchor_rect, |
| 19 GtkWidget* anchor_widget, | 27 GtkWidget* anchor_widget, |
| 20 Profile* profile, | 28 Profile* profile, |
| 21 content::RenderViewHost* render_view_host) | 29 content::RenderViewHost* render_view_host) |
| 22 : render_view_host_(render_view_host) { | 30 : profile_(profile), render_view_host_(render_view_host) { |
| 23 // TODO(gcasto): Localize text after we have finalized the UI. | 31 // TODO(gcasto): Localize text after we have finalized the UI. |
| 24 // crbug.com/118062 | 32 // crbug.com/118062 |
| 25 GtkWidget* content = gtk_vbox_new(FALSE, 5); | 33 GtkWidget* content = gtk_vbox_new(FALSE, 5); |
| 26 | 34 |
| 27 // We have two lines of content. The first is just the title, | 35 // We have two lines of content. The first is the title and learn more link. |
| 28 GtkWidget* title_line = gtk_hbox_new(FALSE, 0); | 36 GtkWidget* title_line = gtk_hbox_new(FALSE, 0); |
| 29 GtkWidget* title = gtk_label_new("Password Suggestion"); | 37 GtkWidget* title = gtk_label_new("Password Suggestion"); |
| 30 gtk_box_pack_start(GTK_BOX(title_line), title, FALSE, FALSE, 0); | 38 gtk_box_pack_start(GTK_BOX(title_line), title, FALSE, FALSE, 0); |
| 39 GtkWidget* learn_more_link = gtk_chrome_link_button_new( | |
| 40 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | |
| 41 gtk_button_set_alignment(GTK_BUTTON(learn_more_link), 0.0, 0.5); | |
| 42 gtk_box_pack_start(GTK_BOX(title_line), | |
| 43 gtk_util::IndentWidget(learn_more_link), | |
| 44 FALSE, FALSE, 0); | |
| 45 g_signal_connect(learn_more_link, "clicked", | |
|
Garrett Casto
2012/04/26 21:45:15
nit: I would put all the callback registrations to
zysxqn
2012/04/26 23:46:25
Done.
| |
| 46 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); | |
| 31 | 47 |
| 32 // The second contains the password in a text field and an accept button. | 48 // The second contains the password in a text field and an accept button. |
| 33 GtkWidget* password_line = gtk_hbox_new(FALSE, kHorizontalSpacing); | 49 GtkWidget* password_line = gtk_hbox_new(FALSE, kHorizontalSpacing); |
| 34 text_field_ = gtk_entry_new(); | 50 text_field_ = gtk_entry_new(); |
| 35 gtk_entry_set_text(GTK_ENTRY(text_field_), | 51 gtk_entry_set_text(GTK_ENTRY(text_field_), |
| 36 password_generator_.Generate().c_str()); | 52 password_generator_.Generate().c_str()); |
| 37 gtk_entry_set_max_length(GTK_ENTRY(text_field_), 15); | 53 gtk_entry_set_max_length(GTK_ENTRY(text_field_), 15); |
| 38 GtkWidget* accept_button = gtk_button_new_with_label("Try It"); | 54 GtkWidget* accept_button = gtk_button_new_with_label("Try It"); |
| 39 gtk_box_pack_start(GTK_BOX(password_line), text_field_, TRUE, TRUE, 0); | 55 gtk_box_pack_start(GTK_BOX(password_line), text_field_, TRUE, TRUE, 0); |
| 40 gtk_box_pack_start(GTK_BOX(password_line), accept_button, TRUE, TRUE, 0); | 56 gtk_box_pack_start(GTK_BOX(password_line), accept_button, TRUE, TRUE, 0); |
| 41 | 57 |
| 42 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); | 58 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); |
| 43 gtk_box_pack_start(GTK_BOX(content), title_line, TRUE, TRUE, 0); | 59 gtk_box_pack_start(GTK_BOX(content), title_line, TRUE, TRUE, 0); |
| 44 gtk_box_pack_start(GTK_BOX(content), password_line, TRUE, TRUE, 0); | 60 gtk_box_pack_start(GTK_BOX(content), password_line, TRUE, TRUE, 0); |
| 45 | 61 |
| 46 bubble_ = BubbleGtk::Show(anchor_widget, | 62 bubble_ = BubbleGtk::Show(anchor_widget, |
| 47 &anchor_rect, | 63 &anchor_rect, |
| 48 content, | 64 content, |
| 49 BubbleGtk::ARROW_LOCATION_TOP_LEFT, | 65 BubbleGtk::ARROW_LOCATION_TOP_LEFT, |
| 50 true, // match_system_theme | 66 true, // match_system_theme |
| 51 true, // grab_input | 67 true, // grab_input |
| 52 ThemeServiceGtk::GetFrom(profile), | 68 ThemeServiceGtk::GetFrom(profile_), |
| 53 NULL); // delegate | 69 NULL); // delegate |
| 54 | 70 |
| 55 g_signal_connect(content, "destroy", | 71 g_signal_connect(content, "destroy", |
| 56 G_CALLBACK(&OnDestroyThunk), this); | 72 G_CALLBACK(&OnDestroyThunk), this); |
| 57 g_signal_connect(accept_button, "clicked", | 73 g_signal_connect(accept_button, "clicked", |
| 58 G_CALLBACK(&OnAcceptClickedThunk), this); | 74 G_CALLBACK(&OnAcceptClickedThunk), this); |
| 59 } | 75 } |
| 60 | 76 |
| 61 PasswordGenerationBubbleGtk::~PasswordGenerationBubbleGtk() {} | 77 PasswordGenerationBubbleGtk::~PasswordGenerationBubbleGtk() {} |
| 62 | 78 |
| 63 void PasswordGenerationBubbleGtk::OnDestroy(GtkWidget* widget) { | 79 void PasswordGenerationBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 64 // We are self deleting, we have a destroy signal setup to catch when we are | 80 // We are self deleting, we have a destroy signal setup to catch when we are |
| 65 // destroyed (via the BubbleGtk being destroyed), and delete ourself. | 81 // destroyed (via the BubbleGtk being destroyed), and delete ourself. |
| 66 delete this; | 82 delete this; |
| 67 } | 83 } |
| 68 | 84 |
| 69 void PasswordGenerationBubbleGtk::OnAcceptClicked(GtkWidget* widget) { | 85 void PasswordGenerationBubbleGtk::OnAcceptClicked(GtkWidget* widget) { |
| 70 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( | 86 render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted( |
| 71 render_view_host_->GetRoutingID(), | 87 render_view_host_->GetRoutingID(), |
| 72 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(text_field_))))); | 88 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(text_field_))))); |
| 73 bubble_->Close(); | 89 bubble_->Close(); |
| 74 } | 90 } |
| 91 | |
| 92 void PasswordGenerationBubbleGtk::OnLearnMoreLinkClicked(GtkButton* button) { | |
| 93 // We open a new browser window so the Options dialog doesn't get lost behind | |
| 94 // other windows. | |
| 95 Browser* browser = Browser::Create(profile_); | |
|
Garrett Casto
2012/04/26 21:45:15
Don't open a new window, open a new tab in the cur
zysxqn
2012/04/26 23:46:25
Changed to open a new tab in the same window.
My
| |
| 96 browser->AddSelectedTabWithURL( | |
| 97 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), | |
| 98 content::PAGE_TRANSITION_LINK); | |
| 99 browser->window()->Show(); | |
| 100 } | |
| OLD | NEW |