Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/gtk/options/general_page_gtk.cc

Issue 4277001: [GTK] add instant pref (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky review Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/options/general_page_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/options/general_page_gtk.h" 5 #include "chrome/browser/gtk/options/general_page_gtk.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/custom_home_pages_table_model.h" 14 #include "chrome/browser/custom_home_pages_table_model.h"
14 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" 15 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h"
16 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
15 #include "chrome/browser/gtk/gtk_util.h" 17 #include "chrome/browser/gtk/gtk_util.h"
16 #include "chrome/browser/gtk/keyword_editor_view.h" 18 #include "chrome/browser/gtk/keyword_editor_view.h"
17 #include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h" 19 #include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h"
18 #include "chrome/browser/gtk/options/options_layout_gtk.h" 20 #include "chrome/browser/gtk/options/options_layout_gtk.h"
19 #include "chrome/browser/gtk/options/url_picker_dialog_gtk.h" 21 #include "chrome/browser/gtk/options/url_picker_dialog_gtk.h"
22 #include "chrome/browser/instant/instant_confirm_dialog.h"
20 #include "chrome/browser/net/url_fixer_upper.h" 23 #include "chrome/browser/net/url_fixer_upper.h"
21 #include "chrome/browser/prefs/pref_service.h" 24 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/prefs/session_startup_pref.h" 25 #include "chrome/browser/prefs/session_startup_pref.h"
23 #include "chrome/browser/profile.h" 26 #include "chrome/browser/profile.h"
24 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
25 #include "chrome/browser/search_engines/template_url_model.h" 28 #include "chrome/browser/search_engines/template_url_model.h"
29 #include "chrome/browser/show_options_url.h"
30 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/notification_service.h" 31 #include "chrome/common/notification_service.h"
27 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
29 #include "gfx/gtk_util.h" 34 #include "gfx/gtk_util.h"
30 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
31 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
32 37
33 namespace { 38 namespace {
34 39
35 // Markup for the text showing the current state of the default browser 40 // Markup for the text showing the current state of the default browser
(...skipping 25 matching lines...) Expand all
61 } 66 }
62 67
63 } // namespace 68 } // namespace
64 69
65 /////////////////////////////////////////////////////////////////////////////// 70 ///////////////////////////////////////////////////////////////////////////////
66 // GeneralPageGtk, public: 71 // GeneralPageGtk, public:
67 72
68 GeneralPageGtk::GeneralPageGtk(Profile* profile) 73 GeneralPageGtk::GeneralPageGtk(Profile* profile)
69 : OptionsPageBase(profile), 74 : OptionsPageBase(profile),
70 template_url_model_(NULL), 75 template_url_model_(NULL),
76 instant_checkbox_(NULL),
71 default_search_initializing_(true), 77 default_search_initializing_(true),
72 initializing_(true), 78 initializing_(true),
73 default_browser_worker_( 79 default_browser_worker_(
74 new ShellIntegration::DefaultBrowserWorker(this)), 80 new ShellIntegration::DefaultBrowserWorker(this)),
75 managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_GENERAL) { 81 managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_GENERAL) {
76 scoped_ptr<OptionsLayoutBuilderGtk> 82 scoped_ptr<OptionsLayoutBuilderGtk>
77 options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout()); 83 options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout());
78 page_ = options_builder->get_page_widget(); 84 page_ = options_builder->get_page_widget();
79 accessible_widget_helper_.reset(new AccessibleWidgetHelper(page_, profile)); 85 accessible_widget_helper_.reset(new AccessibleWidgetHelper(page_, profile));
80 86
(...skipping 15 matching lines...) Expand all
96 102
97 registrar_.Init(profile->GetPrefs()); 103 registrar_.Init(profile->GetPrefs());
98 registrar_.Add(prefs::kRestoreOnStartup, this); 104 registrar_.Add(prefs::kRestoreOnStartup, this);
99 registrar_.Add(prefs::kURLsToRestoreOnStartup, this); 105 registrar_.Add(prefs::kURLsToRestoreOnStartup, this);
100 106
101 new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, 107 new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage,
102 profile->GetPrefs(), this); 108 profile->GetPrefs(), this);
103 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), this); 109 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), this);
104 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); 110 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this);
105 111
112 instant_.Init(prefs::kInstantEnabled, profile->GetPrefs(), this);
113
106 // Load initial values 114 // Load initial values
107 NotifyPrefChanged(NULL); 115 NotifyPrefChanged(NULL);
108 } 116 }
109 117
110 GeneralPageGtk::~GeneralPageGtk() { 118 GeneralPageGtk::~GeneralPageGtk() {
111 if (template_url_model_) 119 if (template_url_model_)
112 template_url_model_->RemoveObserver(this); 120 template_url_model_->RemoveObserver(this);
113 121
114 default_browser_worker_->ObserverDestroyed(); 122 default_browser_worker_->ObserverDestroyed();
115 } 123 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 187
180 if (!pref_name || *pref_name == prefs::kShowHomeButton) { 188 if (!pref_name || *pref_name == prefs::kShowHomeButton) {
181 gtk_toggle_button_set_active( 189 gtk_toggle_button_set_active(
182 GTK_TOGGLE_BUTTON(homepage_show_home_button_checkbox_), 190 GTK_TOGGLE_BUTTON(homepage_show_home_button_checkbox_),
183 show_home_button_.GetValue()); 191 show_home_button_.GetValue());
184 gtk_widget_set_sensitive( 192 gtk_widget_set_sensitive(
185 homepage_show_home_button_checkbox_, 193 homepage_show_home_button_checkbox_,
186 !show_home_button_.IsManaged()); 194 !show_home_button_.IsManaged());
187 } 195 }
188 196
197 if ((!pref_name || *pref_name == prefs::kInstantEnabled) &&
198 instant_checkbox_) {
199 gtk_toggle_button_set_active(
200 GTK_TOGGLE_BUTTON(instant_checkbox_),
201 instant_.GetValue());
202 }
203
189 initializing_ = false; 204 initializing_ = false;
190 } 205 }
191 206
192 void GeneralPageGtk::HighlightGroup(OptionsGroup highlight_group) { 207 void GeneralPageGtk::HighlightGroup(OptionsGroup highlight_group) {
193 // TODO(mattm): implement group highlighting 208 // TODO(mattm): implement group highlighting
194 } 209 }
195 210
196 /////////////////////////////////////////////////////////////////////////////// 211 ///////////////////////////////////////////////////////////////////////////////
197 // GeneralPageGtk, private: 212 // GeneralPageGtk, private:
198 213
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 homepage_show_home_button_checkbox_ = gtk_check_button_new_with_label( 344 homepage_show_home_button_checkbox_ = gtk_check_button_new_with_label(
330 l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON).c_str()); 345 l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON).c_str());
331 g_signal_connect(homepage_show_home_button_checkbox_, "toggled", 346 g_signal_connect(homepage_show_home_button_checkbox_, "toggled",
332 G_CALLBACK(OnShowHomeButtonToggledThunk), this); 347 G_CALLBACK(OnShowHomeButtonToggledThunk), this);
333 gtk_container_add(GTK_CONTAINER(vbox), homepage_show_home_button_checkbox_); 348 gtk_container_add(GTK_CONTAINER(vbox), homepage_show_home_button_checkbox_);
334 349
335 return vbox; 350 return vbox;
336 } 351 }
337 352
338 GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { 353 GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() {
339 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); 354 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
355 GtkWidget* search_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing);
356 gtk_box_pack_start(GTK_BOX(vbox), search_hbox, FALSE, FALSE, 0);
340 357
341 default_search_engines_model_ = gtk_list_store_new(SEARCH_ENGINES_COL_COUNT, 358 default_search_engines_model_ = gtk_list_store_new(SEARCH_ENGINES_COL_COUNT,
342 G_TYPE_UINT, 359 G_TYPE_UINT,
343 G_TYPE_STRING); 360 G_TYPE_STRING);
344 default_search_engine_combobox_ = gtk_combo_box_new_with_model( 361 default_search_engine_combobox_ = gtk_combo_box_new_with_model(
345 GTK_TREE_MODEL(default_search_engines_model_)); 362 GTK_TREE_MODEL(default_search_engines_model_));
346 g_object_unref(default_search_engines_model_); 363 g_object_unref(default_search_engines_model_);
347 g_signal_connect(default_search_engine_combobox_, "changed", 364 g_signal_connect(default_search_engine_combobox_, "changed",
348 G_CALLBACK(OnDefaultSearchEngineChangedThunk), this); 365 G_CALLBACK(OnDefaultSearchEngineChangedThunk), this);
349 gtk_container_add(GTK_CONTAINER(hbox), default_search_engine_combobox_); 366 gtk_container_add(GTK_CONTAINER(search_hbox),
367 default_search_engine_combobox_);
350 accessible_widget_helper_->SetWidgetName( 368 accessible_widget_helper_->SetWidgetName(
351 default_search_engine_combobox_, IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME); 369 default_search_engine_combobox_, IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME);
352 370
353 GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); 371 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
354 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_search_engine_combobox_), 372 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_search_engine_combobox_),
355 renderer, TRUE); 373 renderer, TRUE);
356 gtk_cell_layout_set_attributes( 374 gtk_cell_layout_set_attributes(
357 GTK_CELL_LAYOUT(default_search_engine_combobox_), renderer, 375 GTK_CELL_LAYOUT(default_search_engine_combobox_), renderer,
358 "text", SEARCH_ENGINES_COL_TITLE, 376 "text", SEARCH_ENGINES_COL_TITLE,
359 NULL); 377 NULL);
360 378
361 template_url_model_ = profile()->GetTemplateURLModel(); 379 template_url_model_ = profile()->GetTemplateURLModel();
362 if (template_url_model_) { 380 if (template_url_model_) {
363 template_url_model_->Load(); 381 template_url_model_->Load();
364 template_url_model_->AddObserver(this); 382 template_url_model_->AddObserver(this);
365 } 383 }
366 OnTemplateURLModelChanged(); 384 OnTemplateURLModelChanged();
367 385
368 default_search_manage_engines_button_ = gtk_button_new_with_label( 386 default_search_manage_engines_button_ = gtk_button_new_with_label(
369 l10n_util::GetStringUTF8( 387 l10n_util::GetStringUTF8(
370 IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK).c_str()); 388 IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK).c_str());
371 g_signal_connect(default_search_manage_engines_button_, "clicked", 389 g_signal_connect(default_search_manage_engines_button_, "clicked",
372 G_CALLBACK(OnDefaultSearchManageEnginesClickedThunk), this); 390 G_CALLBACK(OnDefaultSearchManageEnginesClickedThunk), this);
373 gtk_box_pack_end(GTK_BOX(hbox), default_search_manage_engines_button_, 391 gtk_box_pack_start(GTK_BOX(search_hbox),
374 FALSE, FALSE, 0); 392 default_search_manage_engines_button_, FALSE, FALSE, 0);
375 393
376 return hbox; 394 // When the instant lab is on, add some options for instant. We want the
395 // warning text and link to align with the pref's checkbox's label.
396 // Need a new vbox as we don't want any spacing between these labels.
397 GtkWidget* instant_vbox = gtk_vbox_new(FALSE, 0);
398 gtk_box_pack_start(GTK_BOX(vbox), instant_vbox, FALSE, FALSE, 0);
399
400 instant_checkbox_ = gtk_check_button_new_with_label(
401 l10n_util::GetStringUTF8(IDS_INSTANT_PREF).c_str());
402 g_signal_connect(instant_checkbox_, "toggled",
403 G_CALLBACK(OnInstantToggledThunk), this);
404 gtk_box_pack_start(GTK_BOX(instant_vbox), instant_checkbox_, FALSE, FALSE, 0);
405
406 // Relies on knowledge of GTK+ internals to find the checkbox's label child
407 // and then make the indent below match its vertical spacing.
408 GtkWidget* instant_label = gtk_bin_get_child(GTK_BIN(instant_checkbox_));
409 if (instant_label && GTK_IS_LABEL(instant_label)) {
410 g_signal_connect(instant_label, "size-allocate",
411 G_CALLBACK(OnInstantLabelSizeAllocateThunk), this);
412 }
413
414 instant_indent_ = gtk_fixed_new();
415 GtkWidget* explanation_box = gtk_hbox_new(FALSE, 0);
416 GtkWidget* explanation = gtk_label_new((
417 l10n_util::GetStringUTF8(IDS_INSTANT_PREF_WARNING) + " ").c_str());
418 GtkWidget* learn_more_link = gtk_chrome_link_button_new(
419 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str());
420 g_signal_connect(learn_more_link, "clicked",
421 G_CALLBACK(OnSearchLearnMoreClickedThunk), this);
422 gtk_box_pack_start(GTK_BOX(explanation_box), instant_indent_,
423 FALSE, FALSE, 0);
424 gtk_box_pack_start(GTK_BOX(explanation_box), explanation,
425 FALSE, FALSE, 0);
426 gtk_box_pack_start(GTK_BOX(explanation_box), learn_more_link,
427 FALSE, FALSE, 0);
428 gtk_box_pack_start(GTK_BOX(instant_vbox), explanation_box, FALSE, FALSE, 0);
429
430 return vbox;
377 } 431 }
378 432
379 GtkWidget* GeneralPageGtk::InitDefaultBrowserGroup() { 433 GtkWidget* GeneralPageGtk::InitDefaultBrowserGroup() {
380 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); 434 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
381 435
382 // TODO(mattm): the label should be created with a text like "checking for 436 // TODO(mattm): the label should be created with a text like "checking for
383 // default" to be displayed while we wait for the check to complete. 437 // default" to be displayed while we wait for the check to complete.
384 default_browser_status_label_ = gtk_label_new(NULL); 438 default_browser_status_label_ = gtk_label_new(NULL);
385 gtk_box_pack_start(GTK_BOX(vbox), default_browser_status_label_, 439 gtk_box_pack_start(GTK_BOX(vbox), default_browser_status_label_,
386 FALSE, FALSE, 0); 440 FALSE, FALSE, 0);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 UserMetricsRecordAction( 534 UserMetricsRecordAction(
481 UserMetricsAction("Options_Homepage_ShowHomeButton"), 535 UserMetricsAction("Options_Homepage_ShowHomeButton"),
482 profile()->GetPrefs()); 536 profile()->GetPrefs());
483 } else { 537 } else {
484 UserMetricsRecordAction( 538 UserMetricsRecordAction(
485 UserMetricsAction("Options_Homepage_HideHomeButton"), 539 UserMetricsAction("Options_Homepage_HideHomeButton"),
486 profile()->GetPrefs()); 540 profile()->GetPrefs());
487 } 541 }
488 } 542 }
489 543
544 void GeneralPageGtk::OnInstantToggled(GtkWidget* toggle_button) {
545 if (initializing_)
546 return;
547
548 // TODO(estade): show confirm dialog.
549 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button));
550 instant_.SetValue(enabled);
551
552 // TODO(estade): UMA?
553 }
554
490 void GeneralPageGtk::OnDefaultSearchEngineChanged(GtkWidget* combo_box) { 555 void GeneralPageGtk::OnDefaultSearchEngineChanged(GtkWidget* combo_box) {
491 if (default_search_initializing_) 556 if (default_search_initializing_)
492 return; 557 return;
493 SetDefaultSearchEngineFromComboBox(); 558 SetDefaultSearchEngineFromComboBox();
494 } 559 }
495 560
496 void GeneralPageGtk::OnDefaultSearchManageEnginesClicked(GtkWidget* button) { 561 void GeneralPageGtk::OnDefaultSearchManageEnginesClicked(GtkWidget* button) {
497 KeywordEditorView::Show(profile()); 562 KeywordEditorView::Show(profile());
498 } 563 }
499 564
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 if (color) { 776 if (color) {
712 char* markup = g_markup_printf_escaped(kDefaultBrowserLabelMarkup, 777 char* markup = g_markup_printf_escaped(kDefaultBrowserLabelMarkup,
713 color, text.c_str()); 778 color, text.c_str());
714 gtk_label_set_markup(GTK_LABEL(default_browser_status_label_), markup); 779 gtk_label_set_markup(GTK_LABEL(default_browser_status_label_), markup);
715 g_free(markup); 780 g_free(markup);
716 } 781 }
717 782
718 gtk_widget_set_sensitive(default_browser_use_as_default_button_, 783 gtk_widget_set_sensitive(default_browser_use_as_default_button_,
719 state == ShellIntegration::STATE_NOT_DEFAULT); 784 state == ShellIntegration::STATE_NOT_DEFAULT);
720 } 785 }
786
787 void GeneralPageGtk::OnInstantLabelSizeAllocate(GtkWidget* sender,
788 GtkAllocation* allocation) {
789 int desired_width = allocation->x - sender->parent->allocation.x;
790 GtkRequisition req;
791 gtk_widget_size_request(instant_indent_, &req);
792 if (req.width != desired_width)
793 gtk_widget_set_size_request(instant_indent_, desired_width, -1);
794 }
795
796 void GeneralPageGtk::OnSearchLearnMoreClicked(GtkWidget* sender) {
797 browser::ShowOptionsURL(profile(), GURL(browser::kInstantLearnMoreURL));
798 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/general_page_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698