diff options
| author | Ben Murdoch <benm@google.com> | 2010-11-18 18:32:45 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2010-11-18 18:38:07 +0000 |
| commit | 513209b27ff55e2841eac0e4120199c23acce758 (patch) | |
| tree | aeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/gtk/options/general_page_gtk.cc | |
| parent | 164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff) | |
| download | external_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2 | |
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/gtk/options/general_page_gtk.cc')
| -rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 106 |
1 files changed, 96 insertions, 10 deletions
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index 1cc1ef9..01aef9e 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -9,21 +9,25 @@ #include "app/l10n_util.h" #include "base/callback.h" -#include "base/gtk_util.h" +#include "base/command_line.h" #include "base/utf_string_conversions.h" #include "chrome/browser/custom_home_pages_table_model.h" #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" +#include "chrome/browser/gtk/gtk_chrome_link_button.h" #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/gtk/keyword_editor_view.h" #include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h" #include "chrome/browser/gtk/options/options_layout_gtk.h" #include "chrome/browser/gtk/options/url_picker_dialog_gtk.h" +#include "chrome/browser/instant/instant_confirm_dialog.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" +#include "chrome/browser/show_options_url.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" @@ -69,6 +73,7 @@ bool IsNewTabUIURLString(const GURL& url) { GeneralPageGtk::GeneralPageGtk(Profile* profile) : OptionsPageBase(profile), template_url_model_(NULL), + instant_checkbox_(NULL), default_search_initializing_(true), initializing_(true), default_browser_worker_( @@ -104,6 +109,8 @@ GeneralPageGtk::GeneralPageGtk(Profile* profile) homepage_.Init(prefs::kHomePage, profile->GetPrefs(), this); show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); + instant_.Init(prefs::kInstantEnabled, profile->GetPrefs(), this); + // Load initial values NotifyPrefChanged(NULL); } @@ -115,6 +122,10 @@ GeneralPageGtk::~GeneralPageGtk() { default_browser_worker_->ObserverDestroyed(); } +GtkWindow* GeneralPageGtk::GetWindow() { + return GTK_WINDOW(gtk_widget_get_toplevel(page_)); +} + /////////////////////////////////////////////////////////////////////////////// // GeneralPageGtk, OptionsPageBase overrides: @@ -187,6 +198,12 @@ void GeneralPageGtk::NotifyPrefChanged(const std::string* pref_name) { !show_home_button_.IsManaged()); } + if ((!pref_name || *pref_name == prefs::kInstantEnabled) && + instant_checkbox_) { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(instant_checkbox_), instant_.GetValue()); + } + initializing_ = false; } @@ -277,21 +294,21 @@ GtkWidget* GeneralPageGtk::InitStartupGroup() { FALSE, FALSE, 0); startup_add_custom_page_button_ = gtk_button_new_with_mnemonic( - gtk_util::ConvertAcceleratorsFromWindowsStyle( + gfx::ConvertAcceleratorsFromWindowsStyle( l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_ADD_BUTTON)).c_str()); g_signal_connect(startup_add_custom_page_button_, "clicked", G_CALLBACK(OnStartupAddCustomPageClickedThunk), this); gtk_box_pack_start(GTK_BOX(url_list_buttons), startup_add_custom_page_button_, FALSE, FALSE, 0); startup_remove_custom_page_button_ = gtk_button_new_with_mnemonic( - gtk_util::ConvertAcceleratorsFromWindowsStyle( + gfx::ConvertAcceleratorsFromWindowsStyle( l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_REMOVE_BUTTON)).c_str()); g_signal_connect(startup_remove_custom_page_button_, "clicked", G_CALLBACK(OnStartupRemoveCustomPageClickedThunk), this); gtk_box_pack_start(GTK_BOX(url_list_buttons), startup_remove_custom_page_button_, FALSE, FALSE, 0); startup_use_current_page_button_ = gtk_button_new_with_mnemonic( - gtk_util::ConvertAcceleratorsFromWindowsStyle( + gfx::ConvertAcceleratorsFromWindowsStyle( l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_USE_CURRENT)).c_str()); g_signal_connect(startup_use_current_page_button_, "clicked", G_CALLBACK(OnStartupUseCurrentPageClickedThunk), this); @@ -337,7 +354,9 @@ GtkWidget* GeneralPageGtk::InitHomepageGroup() { } GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { - GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); + GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + GtkWidget* search_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); + gtk_box_pack_start(GTK_BOX(vbox), search_hbox, FALSE, FALSE, 0); default_search_engines_model_ = gtk_list_store_new(SEARCH_ENGINES_COL_COUNT, G_TYPE_UINT, @@ -347,7 +366,8 @@ GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { g_object_unref(default_search_engines_model_); g_signal_connect(default_search_engine_combobox_, "changed", G_CALLBACK(OnDefaultSearchEngineChangedThunk), this); - gtk_container_add(GTK_CONTAINER(hbox), default_search_engine_combobox_); + gtk_container_add(GTK_CONTAINER(search_hbox), + default_search_engine_combobox_); accessible_widget_helper_->SetWidgetName( default_search_engine_combobox_, IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME); @@ -371,10 +391,46 @@ GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK).c_str()); g_signal_connect(default_search_manage_engines_button_, "clicked", G_CALLBACK(OnDefaultSearchManageEnginesClickedThunk), this); - gtk_box_pack_end(GTK_BOX(hbox), default_search_manage_engines_button_, - FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(search_hbox), + default_search_manage_engines_button_, FALSE, FALSE, 0); + + // When the instant lab is on, add some options for instant. We want the + // warning text and link to align with the pref's checkbox's label. + // Need a new vbox as we don't want any spacing between these labels. + GtkWidget* instant_vbox = gtk_vbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), instant_vbox, FALSE, FALSE, 0); + + instant_checkbox_ = gtk_check_button_new_with_label( + l10n_util::GetStringUTF8(IDS_INSTANT_PREF).c_str()); + g_signal_connect(instant_checkbox_, "toggled", + G_CALLBACK(OnInstantToggledThunk), this); + gtk_box_pack_start(GTK_BOX(instant_vbox), instant_checkbox_, FALSE, FALSE, 0); + + // Relies on knowledge of GTK+ internals to find the checkbox's label child + // and then make the indent below match its vertical spacing. + GtkWidget* instant_label = gtk_bin_get_child(GTK_BIN(instant_checkbox_)); + if (instant_label && GTK_IS_LABEL(instant_label)) { + g_signal_connect(instant_label, "size-allocate", + G_CALLBACK(OnInstantLabelSizeAllocateThunk), this); + } - return hbox; + instant_indent_ = gtk_fixed_new(); + GtkWidget* explanation_box = gtk_hbox_new(FALSE, 0); + GtkWidget* explanation = gtk_label_new(( + l10n_util::GetStringUTF8(IDS_INSTANT_PREF_WARNING) + " ").c_str()); + GtkWidget* learn_more_link = gtk_chrome_link_button_new( + l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); + g_signal_connect(learn_more_link, "clicked", + G_CALLBACK(OnSearchLearnMoreClickedThunk), this); + gtk_box_pack_start(GTK_BOX(explanation_box), instant_indent_, + FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(explanation_box), explanation, + FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(explanation_box), learn_more_link, + FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(instant_vbox), explanation_box, FALSE, FALSE, 0); + + return vbox; } GtkWidget* GeneralPageGtk::InitDefaultBrowserGroup() { @@ -430,7 +486,7 @@ void GeneralPageGtk::OnStartupAddCustomPageClicked(GtkWidget* button) { new UrlPickerDialogGtk( NewCallback(this, &GeneralPageGtk::OnAddCustomUrl), profile(), - GTK_WINDOW(gtk_widget_get_toplevel(page_))); + GetWindow()); } void GeneralPageGtk::OnStartupRemoveCustomPageClicked(GtkWidget* button) { @@ -488,6 +544,23 @@ void GeneralPageGtk::OnShowHomeButtonToggled(GtkWidget* toggle_button) { } } +void GeneralPageGtk::OnInstantToggled(GtkWidget* toggle_button) { + if (initializing_) + return; + + bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); + + if (enabled) { + if (!instant_.GetValue()) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(instant_checkbox_), false); + browser::ShowInstantConfirmDialogIfNecessary(GetWindow(), profile()); + } else { + instant_.SetValue(enabled); + } + + // TODO(estade): UMA? +} + void GeneralPageGtk::OnDefaultSearchEngineChanged(GtkWidget* combo_box) { if (default_search_initializing_) return; @@ -719,3 +792,16 @@ void GeneralPageGtk::SetDefaultBrowserUIState( gtk_widget_set_sensitive(default_browser_use_as_default_button_, state == ShellIntegration::STATE_NOT_DEFAULT); } + +void GeneralPageGtk::OnInstantLabelSizeAllocate(GtkWidget* sender, + GtkAllocation* allocation) { + int desired_width = allocation->x - sender->parent->allocation.x; + GtkRequisition req; + gtk_widget_size_request(instant_indent_, &req); + if (req.width != desired_width) + gtk_widget_set_size_request(instant_indent_, desired_width, -1); +} + +void GeneralPageGtk::OnSearchLearnMoreClicked(GtkWidget* sender) { + browser::ShowOptionsURL(profile(), GURL(browser::kInstantLearnMoreURL)); +} |
