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

Side by Side Diff: chrome/browser/ui/gtk/options/content_settings_window_gtk.cc

Issue 6670011: Options: Remove the GTK and Views native options code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/gtk/options/content_settings_window_gtk.h"
6
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/message_loop.h"
11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
15 #include "chrome/browser/ui/gtk/gtk_tree.h"
16 #include "chrome/browser/ui/gtk/gtk_util.h"
17 #include "chrome/common/content_settings_types.h"
18 #include "chrome/common/pref_names.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
21 #include "grit/locale_settings.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 namespace {
25
26 // The singleton options window object.
27 ContentSettingsWindowGtk* settings_window = NULL;
28
29 } // namespace
30
31 // static
32 void ContentSettingsWindowGtk::Show(GtkWindow* parent,
33 ContentSettingsType page,
34 Profile* profile) {
35 DCHECK(profile);
36
37 if (!settings_window) {
38 // Create the options window.
39 settings_window = new ContentSettingsWindowGtk(parent, profile);
40 }
41 settings_window->ShowContentSettingsTab(page);
42 }
43
44 ContentSettingsWindowGtk::ContentSettingsWindowGtk(GtkWindow* parent,
45 Profile* profile)
46 : profile_(profile),
47 cookie_page_(profile),
48 image_page_(profile, CONTENT_SETTINGS_TYPE_IMAGES),
49 javascript_page_(profile, CONTENT_SETTINGS_TYPE_JAVASCRIPT),
50 plugin_page_(profile, CONTENT_SETTINGS_TYPE_PLUGINS),
51 popup_page_(profile, CONTENT_SETTINGS_TYPE_POPUPS),
52 geolocation_page_(profile, CONTENT_SETTINGS_TYPE_GEOLOCATION),
53 notifications_page_(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
54 const struct {
55 int message_id;
56 GtkWidget* widget;
57 } kNotebookPages[] = {
58 { IDS_COOKIES_TAB_LABEL, cookie_page_.get_page_widget() },
59 { IDS_IMAGES_TAB_LABEL, image_page_.get_page_widget() },
60 { IDS_JAVASCRIPT_TAB_LABEL, javascript_page_.get_page_widget() },
61 { IDS_PLUGIN_TAB_LABEL, plugin_page_.get_page_widget() },
62 { IDS_POPUP_TAB_LABEL, popup_page_.get_page_widget() },
63 { IDS_GEOLOCATION_TAB_LABEL, geolocation_page_.get_page_widget() },
64 { IDS_NOTIFICATIONS_TAB_LABEL, notifications_page_.get_page_widget() },
65 };
66
67 // We don't need to observe changes in this value.
68 last_selected_page_.Init(prefs::kContentSettingsWindowLastTabIndex,
69 profile->GetPrefs(), NULL);
70
71 std::string dialog_name = l10n_util::GetStringUTF8(
72 IDS_CONTENT_SETTINGS_TITLE);
73 dialog_ = gtk_dialog_new_with_buttons(
74 dialog_name.c_str(),
75 parent,
76 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
77 GTK_STOCK_CLOSE,
78 GTK_RESPONSE_CLOSE,
79 NULL);
80 gtk_window_set_policy(GTK_WINDOW(dialog_), FALSE, FALSE, TRUE);
81
82 gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1);
83 // Allow browser windows to go in front of the options dialog in metacity.
84 gtk_window_set_type_hint(GTK_WINDOW(dialog_), GDK_WINDOW_TYPE_HINT_NORMAL);
85 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox),
86 gtk_util::kContentAreaSpacing);
87 gtk_util::SetWindowIcon(GTK_WINDOW(dialog_));
88
89 // Create hbox with list view and notebook.
90 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing);
91
92 list_ = gtk_tree_view_new();
93 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list_), FALSE);
94
95 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
96 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes(
97 "List Item", renderer, "text", 0, NULL);
98 gtk_tree_view_append_column(GTK_TREE_VIEW(list_), column);
99
100 const int kColumnCount = 1;
101 GtkListStore* store = gtk_list_store_new(kColumnCount, G_TYPE_STRING);
102 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNotebookPages); ++i) {
103 GtkTreeIter iter;
104 gtk_list_store_append(store, &iter);
105 std::string label = l10n_util::GetStringUTF8(kNotebookPages[i].message_id);
106 gtk_list_store_set(store, &iter, 0, label.c_str(), -1);
107 }
108 gtk_tree_view_set_model(GTK_TREE_VIEW(list_), GTK_TREE_MODEL(store));
109 g_object_unref(store);
110
111 // Needs to happen after the model is all set up.
112 GtkTreeSelection* selection = gtk_tree_view_get_selection(
113 GTK_TREE_VIEW(list_));
114 gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
115
116 // Wrap the list widget in a scrolled window in order to have a frame.
117 GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
118 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
119 GTK_SHADOW_ETCHED_IN);
120 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
121 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
122 gtk_container_add(GTK_CONTAINER(scrolled), list_);
123 gtk_box_pack_start(GTK_BOX(hbox), scrolled, FALSE, FALSE, 0);
124
125 notebook_ = gtk_notebook_new();
126 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kNotebookPages); ++i) {
127 gtk_notebook_append_page(GTK_NOTEBOOK(notebook_),
128 kNotebookPages[i].widget,
129 NULL);
130 }
131 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook_), FALSE);
132 gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook_), FALSE);
133 gtk_box_pack_start(GTK_BOX(hbox), notebook_, FALSE, FALSE, 0);
134 DCHECK_EQ(gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_)),
135 CONTENT_SETTINGS_NUM_TYPES);
136
137 // Create vbox with "Features:" text and hbox below.
138 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
139 GtkWidget* label = gtk_label_new(
140 l10n_util::GetStringUTF8(IDS_CONTENT_SETTINGS_FEATURES_LABEL).c_str());
141 gtk_misc_set_alignment(GTK_MISC(label), 0, .5);
142 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
143 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
144 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), vbox);
145
146 // Need to show the notebook before connecting switch-page signal, otherwise
147 // we'll immediately get a signal switching to page 0 and overwrite our
148 // last_selected_page_ value.
149 gtk_util::ShowDialogWithLocalizedSize(dialog_, -1, -1, true);
150
151 g_signal_connect(notebook_, "switch-page",
152 G_CALLBACK(OnSwitchPageThunk), this);
153 g_signal_connect(selection, "changed",
154 G_CALLBACK(OnListSelectionChangedThunk), this);
155
156 // We only have one button and don't do any special handling, so just hook it
157 // directly to gtk_widget_destroy.
158 g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL);
159
160 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroyThunk), this);
161 }
162
163 ContentSettingsWindowGtk::~ContentSettingsWindowGtk() {
164 }
165
166 void ContentSettingsWindowGtk::ShowContentSettingsTab(
167 ContentSettingsType page) {
168 // Bring options window to front if it already existed and isn't already
169 // in front
170 gtk_util::PresentWindow(dialog_, gtk_get_current_event_time());
171
172 if (page == CONTENT_SETTINGS_TYPE_DEFAULT) {
173 // Remember the last visited page from local state.
174 page = static_cast<ContentSettingsType>(last_selected_page_.GetValue());
175 if (page == CONTENT_SETTINGS_TYPE_DEFAULT)
176 page = CONTENT_SETTINGS_TYPE_COOKIES;
177 }
178 // If the page number is out of bounds, reset to the first tab.
179 if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_)))
180 page = CONTENT_SETTINGS_TYPE_COOKIES;
181
182 gtk_tree::SelectAndFocusRowNum(page, GTK_TREE_VIEW(list_));
183 }
184
185 void ContentSettingsWindowGtk::OnSwitchPage(
186 GtkWidget* notebook,
187 GtkNotebookPage* page,
188 guint page_num) {
189 int index = page_num;
190 DCHECK(index > CONTENT_SETTINGS_TYPE_DEFAULT &&
191 index < CONTENT_SETTINGS_NUM_TYPES);
192
193 // Keep list in sync.
194 GtkTreeModel* model;
195 GtkTreeIter iter;
196 if (gtk_tree_selection_get_selected(
197 gtk_tree_view_get_selection(GTK_TREE_VIEW(list_)), &model, &iter)) {
198 gint row_index = gtk_tree::GetRowNumForIter(model, &iter);
199 if (row_index == index)
200 return;
201 }
202 gtk_tree::SelectAndFocusRowNum(index, GTK_TREE_VIEW(list_));
203 }
204
205 void ContentSettingsWindowGtk::OnWindowDestroy(GtkWidget* widget) {
206 settings_window = NULL;
207 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
208 }
209
210 void ContentSettingsWindowGtk::OnListSelectionChanged(
211 GtkTreeSelection* selection) {
212 GtkTreeModel* model;
213 GtkTreeIter iter;
214 if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
215 NOTREACHED();
216 return;
217 }
218 gint row_index = gtk_tree::GetRowNumForIter(model, &iter);
219 DCHECK(row_index > CONTENT_SETTINGS_TYPE_DEFAULT &&
220 row_index < CONTENT_SETTINGS_NUM_TYPES);
221
222 last_selected_page_.SetValue(row_index);
223
224 if (row_index != gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook_)))
225 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), row_index);
226 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/options/content_settings_window_gtk.h ('k') | chrome/browser/ui/gtk/options/cookie_filter_page_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698