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/one_click_signin_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/callback_helpers.h" | |
10 #include "base/logging.h" | |
Peter Kasting
2012/05/24 22:25:18
Nit: Alphabetize
Roger Tawa OOO till Jul 10th
2012/05/25 16:04:08
I thought that the order of #includes is also base
Peter Kasting
2012/05/25 16:58:06
Nope, unix sort.
| |
9 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" | 13 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
13 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 14 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 15 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
15 #include "chrome/browser/ui/gtk/gtk_util.h" | 16 #include "chrome/browser/ui/gtk/gtk_util.h" |
16 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Padding between content and edge of bubble (in pixels). | 23 // Padding between content and edge of bubble (in pixels). |
23 const int kContentBorder = 7; | 24 const int kContentBorder = 7; |
24 | 25 |
25 } // namespace | 26 } // namespace |
26 | 27 |
27 OneClickSigninBubbleGtk::OneClickSigninBubbleGtk( | 28 OneClickSigninBubbleGtk::OneClickSigninBubbleGtk( |
28 BrowserWindowGtk* browser_window_gtk, | 29 BrowserWindowGtk* browser_window_gtk, |
29 const base::Closure& learn_more_callback, | 30 const BrowserWindow::StartSyncCallback& start_sync_callback) |
30 const base::Closure& advanced_callback) | |
31 : bubble_(NULL), | 31 : bubble_(NULL), |
32 learn_more_callback_(learn_more_callback), | 32 start_sync_callback_(start_sync_callback) { |
33 advanced_callback_(advanced_callback) { | |
34 | 33 |
35 // Setup the BubbleGtk content. | 34 // Setup the BubbleGtk content. |
36 GtkWidget* bubble_content = gtk_vbox_new(FALSE, 0); | 35 GtkWidget* bubble_content = gtk_vbox_new(FALSE, 0); |
37 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), | 36 gtk_container_set_border_width(GTK_CONTAINER(bubble_content), |
38 kContentBorder); | 37 kContentBorder); |
39 | 38 |
40 // Message. | 39 // Message. |
41 GtkWidget* message_label = gtk_label_new( | 40 GtkWidget* message_label = gtk_label_new( |
42 l10n_util::GetStringFUTF8( | 41 l10n_util::GetStringFUTF8( |
43 IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, | 42 IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, |
44 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)).c_str()); | 43 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)).c_str()); |
45 gtk_label_set_line_wrap(GTK_LABEL(message_label), TRUE); | 44 gtk_label_set_line_wrap(GTK_LABEL(message_label), TRUE); |
46 gtk_misc_set_alignment(GTK_MISC(message_label), 0.0, 0.5); | 45 gtk_misc_set_alignment(GTK_MISC(message_label), 0.0, 0.5); |
47 gtk_box_pack_start(GTK_BOX(bubble_content), message_label, FALSE, FALSE, 0); | 46 gtk_box_pack_start(GTK_BOX(bubble_content), message_label, FALSE, FALSE, 0); |
48 | 47 |
49 GtkThemeService* const theme_provider = GtkThemeService::GetFrom( | 48 GtkThemeService* const theme_provider = GtkThemeService::GetFrom( |
50 browser_window_gtk->browser()->profile()); | 49 browser_window_gtk->browser()->profile()); |
51 | 50 |
52 GtkWidget* learn_more_line = gtk_hbox_new(FALSE, kContentBorder); | |
53 gtk_box_pack_start(GTK_BOX(bubble_content), | |
54 learn_more_line, FALSE, FALSE, 0); | |
55 | |
56 // Learn more link. | |
57 GtkWidget* learn_more_link = theme_provider->BuildChromeLinkButton( | |
58 l10n_util::GetStringUTF8(IDS_SYNC_PROMO_NTP_BUBBLE_LEARN_MORE)); | |
59 g_signal_connect(learn_more_link, "clicked", | |
60 G_CALLBACK(OnClickLearnMoreLinkThunk), this); | |
61 gtk_box_pack_start(GTK_BOX(learn_more_line), | |
62 learn_more_link, FALSE, FALSE, 0); | |
63 | |
64 GtkWidget* bottom_line = gtk_hbox_new(FALSE, kContentBorder); | 51 GtkWidget* bottom_line = gtk_hbox_new(FALSE, kContentBorder); |
65 gtk_box_pack_start(GTK_BOX(bubble_content), | 52 gtk_box_pack_start(GTK_BOX(bubble_content), |
66 bottom_line, FALSE, FALSE, 0); | 53 bottom_line, FALSE, FALSE, 0); |
67 | 54 |
68 // Advanced link. | 55 // Advanced link. |
69 GtkWidget* advanced_link = theme_provider->BuildChromeLinkButton( | 56 GtkWidget* advanced_link = theme_provider->BuildChromeLinkButton( |
70 l10n_util::GetStringUTF8(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 57 l10n_util::GetStringUTF8(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
71 g_signal_connect(advanced_link, "clicked", | 58 g_signal_connect(advanced_link, "clicked", |
72 G_CALLBACK(OnClickAdvancedLinkThunk), this); | 59 G_CALLBACK(OnClickAdvancedLinkThunk), this); |
73 gtk_box_pack_start(GTK_BOX(bottom_line), | 60 gtk_box_pack_start(GTK_BOX(bottom_line), |
74 advanced_link, FALSE, FALSE, 0); | 61 advanced_link, FALSE, FALSE, 0); |
75 | 62 |
63 // Make the OK and Undo buttons the same size horizontally. | |
64 GtkSizeGroup* size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
65 | |
76 // OK Button. | 66 // OK Button. |
77 GtkWidget* ok_button = gtk_button_new_with_label( | 67 GtkWidget* ok_button = gtk_button_new_with_label( |
78 l10n_util::GetStringUTF8(IDS_OK).c_str()); | 68 l10n_util::GetStringUTF8(IDS_OK).c_str()); |
79 g_signal_connect(ok_button, "clicked", | 69 g_signal_connect(ok_button, "clicked", |
80 G_CALLBACK(OnClickOKThunk), this); | 70 G_CALLBACK(OnClickOKThunk), this); |
71 gtk_size_group_add_widget(size_group, ok_button); | |
81 gtk_box_pack_end(GTK_BOX(bottom_line), | 72 gtk_box_pack_end(GTK_BOX(bottom_line), |
82 ok_button, FALSE, FALSE, 0); | 73 ok_button, FALSE, FALSE, 0); |
83 | 74 |
75 // Undo Button. | |
76 // TODO(akalin): at the moment, the OK and undo buttons are not the same | |
77 // size and look kind of ugly. Figure out how to make it nicer. | |
Peter Kasting
2012/05/24 22:25:18
This comment seems out of date?
Roger Tawa OOO till Jul 10th
2012/05/25 16:04:08
Done.
| |
78 GtkWidget* undo_button = gtk_button_new_with_label( | |
79 l10n_util::GetStringUTF8(IDS_ONE_CLICK_BUBBLE_UNDO).c_str()); | |
80 g_signal_connect(undo_button, "clicked", | |
81 G_CALLBACK(OnClickUndoThunk), this); | |
82 gtk_size_group_add_widget(size_group, undo_button); | |
83 gtk_box_pack_end(GTK_BOX(bottom_line), | |
84 undo_button, FALSE, FALSE, 0); | |
85 | |
86 g_object_unref(size_group); | |
87 | |
84 GtkWidget* const app_menu_widget = | 88 GtkWidget* const app_menu_widget = |
85 browser_window_gtk->GetToolbar()->GetAppMenuButton(); | 89 browser_window_gtk->GetToolbar()->GetAppMenuButton(); |
86 gfx::Rect bounds = gtk_util::WidgetBounds(app_menu_widget); | 90 gfx::Rect bounds = gtk_util::WidgetBounds(app_menu_widget); |
87 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? | 91 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? |
88 BubbleGtk::ARROW_LOCATION_TOP_LEFT : BubbleGtk::ARROW_LOCATION_TOP_RIGHT; | 92 BubbleGtk::ARROW_LOCATION_TOP_LEFT : BubbleGtk::ARROW_LOCATION_TOP_RIGHT; |
89 bubble_ = | 93 bubble_ = |
90 BubbleGtk::Show(app_menu_widget, &bounds, bubble_content, | 94 BubbleGtk::Show(app_menu_widget, &bounds, bubble_content, |
91 arrow_location, | 95 arrow_location, |
92 BubbleGtk::MATCH_SYSTEM_THEME | | 96 BubbleGtk::MATCH_SYSTEM_THEME | |
93 BubbleGtk::POPUP_WINDOW | | 97 BubbleGtk::POPUP_WINDOW | |
94 BubbleGtk::GRAB_INPUT, | 98 BubbleGtk::GRAB_INPUT, |
95 theme_provider, this); | 99 theme_provider, this); |
96 gtk_widget_grab_focus(ok_button); | 100 gtk_widget_grab_focus(ok_button); |
97 } | 101 } |
98 | 102 |
99 void OneClickSigninBubbleGtk::BubbleClosing( | 103 void OneClickSigninBubbleGtk::BubbleClosing( |
100 BubbleGtk* bubble, bool closed_by_escape) { | 104 BubbleGtk* bubble, bool closed_by_escape) { |
105 if (!start_sync_callback_.is_null()) | |
106 base::ResetAndReturn(&start_sync_callback_).Run( | |
107 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
108 | |
101 delete this; | 109 delete this; |
102 } | 110 } |
103 | 111 |
104 void OneClickSigninBubbleGtk::ClickOKForTest() { | 112 void OneClickSigninBubbleGtk::ClickOKForTest() { |
105 OnClickOK(NULL); | 113 OnClickOK(NULL); |
106 } | 114 } |
107 | 115 |
108 void OneClickSigninBubbleGtk::ClickLearnMoreForTest() { | 116 void OneClickSigninBubbleGtk::ClickUndoForTest() { |
109 OnClickLearnMoreLink(NULL); | 117 OnClickUndo(NULL); |
110 } | 118 } |
111 | 119 |
112 void OneClickSigninBubbleGtk::ClickAdvancedForTest() { | 120 void OneClickSigninBubbleGtk::ClickAdvancedForTest() { |
113 OnClickAdvancedLink(NULL); | 121 OnClickAdvancedLink(NULL); |
114 } | 122 } |
115 | 123 |
116 void OneClickSigninBubbleGtk::OnClickLearnMoreLink(GtkWidget* link) { | 124 void OneClickSigninBubbleGtk::CloseForTest() { |
117 learn_more_callback_.Run(); | |
118 bubble_->Close(); | 125 bubble_->Close(); |
119 } | 126 } |
120 | 127 |
121 void OneClickSigninBubbleGtk::OnClickAdvancedLink(GtkWidget* link) { | 128 void OneClickSigninBubbleGtk::OnClickAdvancedLink(GtkWidget* link) { |
122 advanced_callback_.Run(); | 129 base::ResetAndReturn(&start_sync_callback_).Run( |
130 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | |
123 bubble_->Close(); | 131 bubble_->Close(); |
124 } | 132 } |
125 | 133 |
126 void OneClickSigninBubbleGtk::OnClickOK(GtkWidget* link) { | 134 void OneClickSigninBubbleGtk::OnClickOK(GtkWidget* link) { |
135 base::ResetAndReturn(&start_sync_callback_).Run( | |
136 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
127 bubble_->Close(); | 137 bubble_->Close(); |
128 } | 138 } |
129 | 139 |
130 OneClickSigninBubbleGtk::~OneClickSigninBubbleGtk() {} | 140 void OneClickSigninBubbleGtk::OnClickUndo(GtkWidget* link) { |
141 start_sync_callback_.Reset(); | |
142 bubble_->Close(); | |
143 } | |
144 | |
145 OneClickSigninBubbleGtk::~OneClickSigninBubbleGtk() { | |
146 } | |
OLD | NEW |