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

Side by Side Diff: chrome/browser/ui/views/options/content_page_view.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/views/options/content_page_view.h"
6
7 #include <shlobj.h>
8 #include <vsstyle.h>
9 #include <vssym32.h>
10 #include <windows.h>
11
12 #include <string>
13
14 #include "base/command_line.h"
15 #include "base/string_util.h"
16 #include "chrome/browser/autofill/autofill_dialog.h"
17 #include "chrome/browser/autofill/personal_data_manager.h"
18 #include "chrome/browser/browser_list.h"
19 #include "chrome/browser/browser_window.h"
20 #include "chrome/browser/importer/importer_data_types.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sync/sync_setup_wizard.h"
23 #include "chrome/browser/sync/sync_ui_util.h"
24 #include "chrome/browser/ui/views/importer/import_dialog_view.h"
25 #include "chrome/browser/ui/views/options/managed_prefs_banner_view.h"
26 #include "chrome/browser/ui/views/options/options_group_view.h"
27 #include "chrome/browser/ui/views/options/passwords_exceptions_window_view.h"
28 #include "chrome/common/pref_names.h"
29 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h"
31 #include "grit/locale_settings.h"
32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/gfx/canvas.h"
34 #include "ui/gfx/native_theme_win.h"
35 #include "views/controls/button/radio_button.h"
36 #include "views/layout/grid_layout.h"
37 #include "views/layout/layout_constants.h"
38 #include "views/widget/widget.h"
39 #include "views/window/window.h"
40
41 namespace {
42
43 // All the options pages are in the same view hierarchy. This means we need to
44 // make sure group identifiers don't collide across different pages.
45 const int kPasswordSavingRadioGroup = 201;
46 const int kFormAutofillRadioGroup = 202;
47
48 // Background color for the status label when it's showing an error.
49 static const SkColor kSyncLabelErrorBgColor = SkColorSetRGB(0xff, 0x9a, 0x9a);
50
51 static views::Background* CreateErrorBackground() {
52 return views::Background::CreateSolidBackground(kSyncLabelErrorBgColor);
53 }
54
55 } // namespace
56
57 ContentPageView::ContentPageView(Profile* profile)
58 : show_passwords_button_(NULL),
59 passwords_group_(NULL),
60 passwords_asktosave_radio_(NULL),
61 passwords_neversave_radio_(NULL),
62 change_autofill_settings_button_(NULL),
63 themes_group_(NULL),
64 themes_reset_button_(NULL),
65 themes_gallery_link_(NULL),
66 browsing_data_group_(NULL),
67 import_button_(NULL),
68 sync_group_(NULL),
69 sync_action_link_(NULL),
70 sync_status_label_(NULL),
71 sync_start_stop_button_(NULL),
72 sync_customize_button_(NULL),
73 privacy_dashboard_link_(NULL),
74 sync_service_(NULL),
75 OptionsPageView(profile) {
76 if (profile->GetProfileSyncService()) {
77 sync_service_ = profile->GetProfileSyncService();
78 sync_service_->AddObserver(this);
79 }
80 }
81
82 ContentPageView::~ContentPageView() {
83 if (sync_service_)
84 sync_service_->RemoveObserver(this);
85 }
86
87 ///////////////////////////////////////////////////////////////////////////////
88 // ContentPageView, views::ButtonListener implementation:
89
90 void ContentPageView::ButtonPressed(
91 views::Button* sender, const views::Event& event) {
92 if (sender == passwords_asktosave_radio_ ||
93 sender == passwords_neversave_radio_) {
94 bool enabled = passwords_asktosave_radio_->checked();
95 if (enabled) {
96 UserMetricsRecordAction(
97 UserMetricsAction("Options_PasswordManager_Enable"),
98 profile()->GetPrefs());
99 } else {
100 UserMetricsRecordAction(
101 UserMetricsAction("Options_PasswordManager_Disable"),
102 profile()->GetPrefs());
103 }
104 ask_to_save_passwords_.SetValue(enabled);
105 } else if (sender == show_passwords_button_) {
106 UserMetricsRecordAction(
107 UserMetricsAction("Options_ShowPasswordsExceptions"), NULL);
108 PasswordsExceptionsWindowView::Show(profile());
109 } else if (sender == change_autofill_settings_button_) {
110 // This button should be disabled if we lack PersonalDataManager.
111 DCHECK(profile()->GetPersonalDataManager());
112 ShowAutoFillDialog(GetWindow()->GetNativeWindow(),
113 profile()->GetPersonalDataManager(),
114 profile());
115 } else if (sender == themes_reset_button_) {
116 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"),
117 profile()->GetPrefs());
118 profile()->ClearTheme();
119 } else if (sender == import_button_) {
120 views::Window::CreateChromeWindow(
121 GetWindow()->GetNativeWindow(),
122 gfx::Rect(),
123 new ImportDialogView(profile(), importer::ALL))->Show();
124 } else if (sender == sync_start_stop_button_) {
125 DCHECK(sync_service_ && !sync_service_->IsManaged());
126
127 if (sync_service_->HasSyncSetupCompleted()) {
128 ConfirmMessageBoxDialog::RunWithCustomConfiguration(
129 GetWindow()->GetNativeWindow(),
130 this,
131 UTF16ToWide(l10n_util::GetStringUTF16(
132 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL)),
133 UTF16ToWide(l10n_util::GetStringUTF16(
134 IDS_SYNC_STOP_SYNCING_DIALOG_TITLE)),
135 UTF16ToWide(l10n_util::GetStringUTF16(
136 IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)),
137 UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL)),
138 gfx::Size(views::Window::GetLocalizedContentsSize(
139 IDS_CONFIRM_STOP_SYNCING_DIALOG_WIDTH_CHARS,
140 IDS_CONFIRM_STOP_SYNCING_DIALOG_HEIGHT_LINES)));
141 return;
142 } else {
143 sync_service_->ShowLoginDialog(GetWindow()->GetNativeWindow());
144 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS);
145 }
146 } else if (sender == sync_customize_button_) {
147 // sync_customize_button_ should be invisible if sync is not yet set up.
148 DCHECK(sync_service_->HasSyncSetupCompleted());
149 sync_service_->ShowConfigure(GetWindow()->GetNativeWindow());
150 }
151 }
152
153 void ContentPageView::LinkActivated(views::Link* source, int event_flags) {
154 if (source == themes_gallery_link_) {
155 UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"),
156 profile()->GetPrefs());
157 BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate();
158 return;
159 }
160 if (source == sync_action_link_) {
161 DCHECK(sync_service_ && !sync_service_->IsManaged());
162 sync_service_->ShowErrorUI(GetWindow()->GetNativeWindow());
163 return;
164 }
165 if (source == privacy_dashboard_link_) {
166 BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate();
167 return;
168 }
169 NOTREACHED() << "Invalid link source.";
170 }
171
172 ////////////////////////////////////////////////////////////////////////////////
173 // ContentPageView, OptionsPageView implementation:
174
175 void ContentPageView::InitControlLayout() {
176 using views::GridLayout;
177 using views::ColumnSet;
178
179 GridLayout* layout = new GridLayout(this);
180 layout->SetInsets(5, 5, 5, 5);
181 SetLayoutManager(layout);
182
183 const int single_column_view_set_id = 0;
184 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
185 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
186 GridLayout::USE_PREF, 0, 0);
187
188 layout->StartRow(0, single_column_view_set_id);
189 layout->AddView(
190 new ManagedPrefsBannerView(profile()->GetPrefs(), OPTIONS_PAGE_CONTENT));
191
192 if (sync_service_) {
193 layout->StartRow(0, single_column_view_set_id);
194 InitSyncGroup();
195 layout->AddView(sync_group_);
196 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
197 }
198
199 layout->StartRow(0, single_column_view_set_id);
200 InitPasswordSavingGroup();
201 layout->AddView(passwords_group_);
202 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
203
204 layout->StartRow(0, single_column_view_set_id);
205 InitFormAutofillGroup();
206 layout->AddView(form_autofill_group_);
207 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
208
209 layout->StartRow(0, single_column_view_set_id);
210 InitBrowsingDataGroup();
211 layout->AddView(browsing_data_group_);
212 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
213
214 layout->StartRow(0, single_column_view_set_id);
215 InitThemesGroup();
216 layout->AddView(themes_group_);
217 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
218
219 // Init member prefs so we can update the controls if prefs change.
220 ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled,
221 profile()->GetPrefs(), this);
222 form_autofill_enabled_.Init(prefs::kAutoFillEnabled,
223 profile()->GetPrefs(), this);
224 is_using_default_theme_.Init(prefs::kCurrentThemeID,
225 profile()->GetPrefs(), this);
226 }
227
228 void ContentPageView::NotifyPrefChanged(const std::string* pref_name) {
229 if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) {
230 if (ask_to_save_passwords_.GetValue()) {
231 passwords_asktosave_radio_->SetChecked(true);
232 } else {
233 passwords_neversave_radio_->SetChecked(true);
234 }
235
236 // Disable UI elements that are managed via policy.
237 bool enablePasswordManagerElements = !ask_to_save_passwords_.IsManaged();
238 passwords_asktosave_radio_->SetEnabled(enablePasswordManagerElements);
239 passwords_neversave_radio_->SetEnabled(enablePasswordManagerElements);
240 show_passwords_button_->SetEnabled(enablePasswordManagerElements ||
241 ask_to_save_passwords_.GetValue());
242 }
243 if (!pref_name || *pref_name == prefs::kAutoFillEnabled) {
244 bool disabled_by_policy = form_autofill_enabled_.IsManaged() &&
245 !form_autofill_enabled_.GetValue();
246 change_autofill_settings_button_->SetEnabled(
247 !disabled_by_policy && profile()->GetPersonalDataManager());
248 }
249 if (!pref_name || *pref_name == prefs::kCurrentThemeID) {
250 themes_reset_button_->SetEnabled(
251 is_using_default_theme_.GetValue().length() > 0);
252 }
253 }
254
255 ///////////////////////////////////////////////////////////////////////////////
256 // ContentsPageView, views::View overrides:
257
258 void ContentPageView::Layout() {
259 if (is_initialized())
260 UpdateSyncControls();
261 View::Layout();
262 }
263
264
265 ///////////////////////////////////////////////////////////////////////////////
266 // ContentsPageView, ProfileSyncServiceObserver implementation:
267
268 void ContentPageView::OnStateChanged() {
269 // If the UI controls are not yet initialized, then don't do anything. This
270 // can happen if the Options dialog is up, but the Content tab is not yet
271 // clicked.
272 if (is_initialized())
273 Layout();
274 }
275
276 ///////////////////////////////////////////////////////////////////////////////
277 // ContentPageView, private:
278
279 void ContentPageView::InitPasswordSavingGroup() {
280 passwords_asktosave_radio_ = new views::RadioButton(
281 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_ASKTOSAVE)),
282 kPasswordSavingRadioGroup);
283 passwords_asktosave_radio_->set_listener(this);
284 passwords_asktosave_radio_->SetMultiLine(true);
285 passwords_neversave_radio_ = new views::RadioButton(
286 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_NEVERSAVE)),
287 kPasswordSavingRadioGroup);
288 passwords_neversave_radio_->set_listener(this);
289 passwords_neversave_radio_->SetMultiLine(true);
290 show_passwords_button_ = new views::NativeButton(
291 this, UTF16ToWide(
292 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_SHOWPASSWORDS)));
293
294 using views::GridLayout;
295 using views::ColumnSet;
296
297 views::View* contents = new views::View;
298 GridLayout* layout = new GridLayout(contents);
299 contents->SetLayoutManager(layout);
300
301 const int single_column_view_set_id = 0;
302 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
303 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
304 GridLayout::USE_PREF, 0, 0);
305
306 layout->StartRow(0, single_column_view_set_id);
307 layout->AddView(passwords_asktosave_radio_, 1, 1,
308 GridLayout::FILL, GridLayout::LEADING);
309 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
310 layout->StartRow(0, single_column_view_set_id);
311 layout->AddView(passwords_neversave_radio_, 1, 1,
312 GridLayout::FILL, GridLayout::LEADING);
313 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
314 layout->StartRow(0, single_column_view_set_id);
315 layout->AddView(show_passwords_button_);
316
317 passwords_group_ = new OptionsGroupView(
318 contents,
319 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_GROUP_NAME)),
320 L"",
321 true);
322 }
323
324 void ContentPageView::InitFormAutofillGroup() {
325 change_autofill_settings_button_ = new views::NativeButton(
326 this, UTF16ToWide(l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS)));
327
328 using views::GridLayout;
329 using views::ColumnSet;
330
331 views::View* contents = new views::View;
332 GridLayout* layout = new GridLayout(contents);
333 contents->SetLayoutManager(layout);
334
335 const int fill_column_view_set_id = 0;
336 const int leading_column_view_set_id = 1;
337 ColumnSet* column_set = layout->AddColumnSet(fill_column_view_set_id);
338 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
339 GridLayout::USE_PREF, 0, 0);
340 column_set = layout->AddColumnSet(leading_column_view_set_id);
341 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
342 GridLayout::USE_PREF, 0, 0);
343
344 layout->StartRow(0, leading_column_view_set_id);
345 layout->AddView(change_autofill_settings_button_);
346
347 form_autofill_group_ = new OptionsGroupView(
348 contents,
349 UTF16ToWide(
350 l10n_util::GetStringUTF16(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME)),
351 L"", true);
352 }
353
354 void ContentPageView::InitThemesGroup() {
355 themes_reset_button_ = new views::NativeButton(this,
356 UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_RESET_BUTTON)));
357 themes_gallery_link_ = new views::Link(
358 UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_GALLERY_BUTTON)));
359 themes_gallery_link_->SetController(this);
360
361 using views::GridLayout;
362 using views::ColumnSet;
363
364 views::View* contents = new views::View;
365 GridLayout* layout = new GridLayout(contents);
366 contents->SetLayoutManager(layout);
367
368 const int double_column_view_set_id = 1;
369 ColumnSet* double_col_set = layout->AddColumnSet(double_column_view_set_id);
370 double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
371 GridLayout::USE_PREF, 0, 0);
372 double_col_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
373 double_col_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
374 GridLayout::USE_PREF, 0, 0);
375
376 layout->StartRow(0, double_column_view_set_id);
377 layout->AddView(themes_reset_button_);
378 layout->AddView(themes_gallery_link_);
379
380 themes_group_ = new OptionsGroupView(
381 contents, UTF16ToWide(l10n_util::GetStringUTF16(IDS_THEMES_GROUP_NAME)),
382 L"", false);
383 }
384
385 void ContentPageView::InitBrowsingDataGroup() {
386 import_button_ = new views::NativeButton(this,
387 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_IMPORT_DATA_BUTTON)));
388
389 using views::GridLayout;
390 using views::ColumnSet;
391
392 views::View* contents = new views::View;
393 GridLayout* layout = new GridLayout(contents);
394 contents->SetLayoutManager(layout);
395
396 // Add the browsing data import button.
397 const int single_column_view_set_id = 0;
398 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
399 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
400 GridLayout::USE_PREF, 0, 0);
401 layout->StartRow(0, single_column_view_set_id);
402 layout->AddView(import_button_);
403
404 browsing_data_group_ = new OptionsGroupView(
405 contents,
406 UTF16ToWide(
407 l10n_util::GetStringUTF16(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME)),
408 L"", true);
409 }
410
411 void ContentPageView::OnConfirmMessageAccept() {
412 sync_service_->DisableForUser();
413 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
414 }
415
416 void ContentPageView::InitSyncGroup() {
417 sync_status_label_ = new views::Label;
418 sync_status_label_->SetMultiLine(true);
419 sync_status_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
420
421 sync_action_link_ = new views::Link();
422 sync_action_link_->set_collapse_when_hidden(true);
423 sync_action_link_->SetController(this);
424
425 privacy_dashboard_link_ = new views::Link();
426 privacy_dashboard_link_->set_collapse_when_hidden(true);
427 privacy_dashboard_link_->SetController(this);
428 privacy_dashboard_link_->SetText(UTF16ToWide(
429 l10n_util::GetStringUTF16(IDS_SYNC_PRIVACY_DASHBOARD_LINK_LABEL)));
430
431 sync_start_stop_button_ = new views::NativeButton(this, std::wstring());
432 sync_customize_button_ = new views::NativeButton(this, std::wstring());
433
434 using views::GridLayout;
435 using views::ColumnSet;
436
437 views::View* contents = new views::View;
438 GridLayout* layout = new GridLayout(contents);
439 contents->SetLayoutManager(layout);
440
441 const int single_column_view_set_id = 0;
442 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
443 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
444 GridLayout::USE_PREF, 0, 0);
445 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
446 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
447 GridLayout::USE_PREF, 0, 0);
448
449 layout->StartRow(0, single_column_view_set_id);
450 layout->AddView(sync_status_label_, 3, 1,
451 GridLayout::FILL, GridLayout::LEADING);
452 layout->StartRow(0, single_column_view_set_id);
453 layout->AddView(sync_action_link_, 3, 1);
454 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
455 layout->StartRow(0, single_column_view_set_id);
456 layout->AddView(sync_start_stop_button_);
457 layout->AddView(sync_customize_button_);
458 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
459 layout->StartRow(0, single_column_view_set_id);
460 layout->AddView(privacy_dashboard_link_, 3, 1);
461
462 sync_group_ = new OptionsGroupView(
463 contents,
464 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_OPTIONS_GROUP_NAME)),
465 std::wstring(), true);
466 }
467
468 void ContentPageView::UpdateSyncControls() {
469 DCHECK(sync_service_);
470 std::wstring status_label;
471 std::wstring link_label;
472 std::wstring customize_button_label;
473 string16 button_label;
474 bool managed = sync_service_->IsManaged();
475 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted();
476 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_,
477 &status_label, &link_label) == sync_ui_util::SYNC_ERROR;
478 customize_button_label =
479 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL));
480 if (sync_setup_completed) {
481 button_label =
482 l10n_util::GetStringUTF16(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL);
483 } else if (sync_service_->SetupInProgress()) {
484 button_label = l10n_util::GetStringUTF16(IDS_SYNC_NTP_SETUP_IN_PROGRESS);
485 } else {
486 button_label = l10n_util::GetStringUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL);
487 }
488
489 sync_status_label_->SetText(status_label);
490 sync_start_stop_button_->SetEnabled(
491 !sync_service_->WizardIsVisible() && !managed);
492 sync_start_stop_button_->SetLabel(UTF16ToWide(button_label));
493 sync_customize_button_->SetLabel(customize_button_label);
494 sync_customize_button_->SetVisible(sync_setup_completed && !status_has_error);
495 sync_customize_button_->SetEnabled(!managed);
496 sync_action_link_->SetText(link_label);
497 sync_action_link_->SetVisible(!link_label.empty());
498 sync_action_link_->SetEnabled(!managed);
499
500 if (status_has_error) {
501 sync_status_label_->set_background(CreateErrorBackground());
502 sync_action_link_->set_background(CreateErrorBackground());
503 } else {
504 sync_status_label_->set_background(NULL);
505 sync_action_link_->set_background(NULL);
506 }
507 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/options/content_page_view.h ('k') | chrome/browser/ui/views/options/content_settings_window_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698