OLD | NEW |
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/chromeos/options/system_page_view.h" | 5 #include "chrome/browser/chromeos/options/system_page_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/chromeos/cros/cros_library.h" | 16 #include "chrome/browser/chromeos/cros/cros_library.h" |
17 #include "chrome/browser/chromeos/cros/keyboard_library.h" | 17 #include "chrome/browser/chromeos/cros/keyboard_library.h" |
18 #include "chrome/browser/chromeos/cros/system_library.h" | 18 #include "chrome/browser/chromeos/cros/system_library.h" |
19 #include "chrome/browser/chromeos/language_preferences.h" | 19 #include "chrome/browser/chromeos/language_preferences.h" |
20 #include "chrome/browser/chromeos/options/language_config_util.h" | |
21 #include "chrome/browser/chromeos/options/language_config_view.h" | |
22 #include "chrome/browser/chromeos/options/options_window_view.h" | 20 #include "chrome/browser/chromeos/options/options_window_view.h" |
23 #include "chrome/browser/prefs/pref_member.h" | 21 #include "chrome/browser/prefs/pref_member.h" |
24 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
26 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
27 #include "ui/base/models/combobox_model.h" | 25 #include "ui/base/models/combobox_model.h" |
28 #include "unicode/timezone.h" | 26 #include "unicode/timezone.h" |
29 #include "views/controls/button/checkbox.h" | 27 #include "views/controls/button/checkbox.h" |
30 #include "views/controls/button/native_button.h" | 28 #include "views/controls/button/native_button.h" |
31 #include "views/controls/combobox/combobox.h" | 29 #include "views/controls/combobox/combobox.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) { | 295 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) { |
298 bool enabled = tap_to_click_enabled_.GetValue(); | 296 bool enabled = tap_to_click_enabled_.GetValue(); |
299 enable_tap_to_click_checkbox_->SetChecked(enabled); | 297 enable_tap_to_click_checkbox_->SetChecked(enabled); |
300 } | 298 } |
301 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { | 299 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) { |
302 double value = sensitivity_.GetValue(); | 300 double value = sensitivity_.GetValue(); |
303 sensitivity_slider_->SetValue(value); | 301 sensitivity_slider_->SetValue(value); |
304 } | 302 } |
305 } | 303 } |
306 | 304 |
307 //////////////////////////////////////////////////////////////////////////////// | |
308 // LanguageSection | |
309 | |
310 // TextInput section for text input settings. | |
311 class LanguageSection : public SettingsPageSection, | |
312 public views::ButtonListener, | |
313 public views::Combobox::Listener { | |
314 public: | |
315 explicit LanguageSection(Profile* profile); | |
316 virtual ~LanguageSection() {} | |
317 | |
318 private: | |
319 enum ButtonTag { | |
320 kCustomizeLanguagesButton, | |
321 }; | |
322 // Overridden from SettingsPageSection: | |
323 virtual void InitContents(GridLayout* layout); | |
324 void NotifyPrefChanged(const std::string* pref_name); | |
325 | |
326 // Overridden from views::ButtonListener: | |
327 virtual void ButtonPressed(views::Button* sender, | |
328 const views::Event& event); | |
329 | |
330 // Overridden from views::Combobox::Listener: | |
331 virtual void ItemChanged(views::Combobox* sender, | |
332 int prev_index, | |
333 int new_index); | |
334 | |
335 IntegerPrefMember xkb_remap_search_key_pref_; | |
336 IntegerPrefMember xkb_remap_control_key_pref_; | |
337 IntegerPrefMember xkb_remap_alt_key_pref_; | |
338 views::Combobox* xkb_modifier_combobox_; | |
339 chromeos::LanguageComboboxModel<int> xkb_modifier_combobox_model_; | |
340 | |
341 DISALLOW_COPY_AND_ASSIGN(LanguageSection); | |
342 }; | |
343 | |
344 LanguageSection::LanguageSection(Profile* profile) | |
345 : SettingsPageSection(profile, | |
346 IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE), | |
347 xkb_modifier_combobox_(NULL), | |
348 xkb_modifier_combobox_model_( | |
349 &language_prefs::kXkbModifierMultipleChoicePrefs) { | |
350 xkb_remap_search_key_pref_.Init( | |
351 prefs::kLanguageXkbRemapSearchKeyTo, profile->GetPrefs(), this); | |
352 xkb_remap_control_key_pref_.Init( | |
353 prefs::kLanguageXkbRemapControlKeyTo, profile->GetPrefs(), this); | |
354 xkb_remap_alt_key_pref_.Init( | |
355 prefs::kLanguageXkbRemapAltKeyTo, profile->GetPrefs(), this); | |
356 } | |
357 | |
358 void LanguageSection::InitContents(GridLayout* layout) { | |
359 // Add the customize button and XKB combobox. | |
360 layout->StartRow(0, double_column_view_set_id()); | |
361 views::NativeButton* customize_languages_button = new views::NativeButton( | |
362 this, | |
363 UTF16ToWide(l10n_util::GetStringUTF16( | |
364 IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE))); | |
365 customize_languages_button->set_tag(kCustomizeLanguagesButton); | |
366 | |
367 xkb_modifier_combobox_ = new views::Combobox(&xkb_modifier_combobox_model_); | |
368 xkb_modifier_combobox_->set_listener(this); | |
369 | |
370 // Initialize the combobox to what's saved in user preferences. Otherwise, | |
371 // ItemChanged() will be called with |new_index| == 0. | |
372 NotifyPrefChanged(NULL); | |
373 | |
374 layout->AddView(customize_languages_button, 1, 1, | |
375 GridLayout::LEADING, GridLayout::CENTER); | |
376 layout->AddView(xkb_modifier_combobox_); | |
377 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | |
378 } | |
379 | |
380 void LanguageSection::ButtonPressed( | |
381 views::Button* sender, const views::Event& event) { | |
382 if (sender->tag() == kCustomizeLanguagesButton) { | |
383 LanguageConfigView::Show(profile(), GetOptionsViewParent()); | |
384 } | |
385 } | |
386 | |
387 void LanguageSection::ItemChanged(views::Combobox* sender, | |
388 int prev_index, | |
389 int new_index) { | |
390 VLOG(1) << "Changing XKB modofier pref to " << new_index; | |
391 switch (new_index) { | |
392 default: | |
393 LOG(ERROR) << "Unexpected mapping: " << new_index; | |
394 /* fall through */ | |
395 case language_prefs::kNoRemap: | |
396 xkb_remap_search_key_pref_.SetValue(kSearchKey); | |
397 xkb_remap_control_key_pref_.SetValue(kLeftControlKey); | |
398 xkb_remap_alt_key_pref_.SetValue(kLeftAltKey); | |
399 break; | |
400 case language_prefs::kSwapCtrlAndAlt: | |
401 xkb_remap_search_key_pref_.SetValue(kSearchKey); | |
402 xkb_remap_control_key_pref_.SetValue(kLeftAltKey); | |
403 xkb_remap_alt_key_pref_.SetValue(kLeftControlKey); | |
404 break; | |
405 case language_prefs::kSwapSearchAndCtrl: | |
406 xkb_remap_search_key_pref_.SetValue(kLeftControlKey); | |
407 xkb_remap_control_key_pref_.SetValue(kSearchKey); | |
408 xkb_remap_alt_key_pref_.SetValue(kLeftAltKey); | |
409 break; | |
410 } | |
411 } | |
412 | |
413 void LanguageSection::NotifyPrefChanged(const std::string* pref_name) { | |
414 if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo || | |
415 *pref_name == prefs::kLanguageXkbRemapControlKeyTo || | |
416 *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) { | |
417 const int search_remap = xkb_remap_search_key_pref_.GetValue(); | |
418 const int control_remap = xkb_remap_control_key_pref_.GetValue(); | |
419 const int alt_remap = xkb_remap_alt_key_pref_.GetValue(); | |
420 if ((search_remap == kSearchKey) && | |
421 (control_remap == kLeftControlKey) && | |
422 (alt_remap == kLeftAltKey)) { | |
423 xkb_modifier_combobox_->SetSelectedItem(language_prefs::kNoRemap); | |
424 } else if ((search_remap == kLeftControlKey) && | |
425 (control_remap == kSearchKey) && | |
426 (alt_remap == kLeftAltKey)) { | |
427 xkb_modifier_combobox_->SetSelectedItem( | |
428 language_prefs::kSwapSearchAndCtrl); | |
429 } else if ((search_remap == kSearchKey) && | |
430 (control_remap == kLeftAltKey) && | |
431 (alt_remap == kLeftControlKey)) { | |
432 xkb_modifier_combobox_->SetSelectedItem(language_prefs::kSwapCtrlAndAlt); | |
433 } else { | |
434 LOG(ERROR) << "Unexpected mapping. The prefs are updated by DOMUI?"; | |
435 xkb_modifier_combobox_->SetSelectedItem(language_prefs::kNoRemap); | |
436 } | |
437 } | |
438 } | |
439 | |
440 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
441 // AccessibilitySection | 306 // AccessibilitySection |
442 | 307 |
443 // Checkbox for specifying if accessibility should be enabled for this profile | 308 // Checkbox for specifying if accessibility should be enabled for this profile |
444 class AccessibilitySection : public SettingsPageSection, | 309 class AccessibilitySection : public SettingsPageSection, |
445 public views::ButtonListener { | 310 public views::ButtonListener { |
446 public: | 311 public: |
447 explicit AccessibilitySection(Profile* profile); | 312 explicit AccessibilitySection(Profile* profile); |
448 virtual ~AccessibilitySection() {} | 313 virtual ~AccessibilitySection() {} |
449 | 314 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 387 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
523 GridLayout::USE_PREF, 0, 0); | 388 GridLayout::USE_PREF, 0, 0); |
524 | 389 |
525 layout->StartRow(0, single_column_view_set_id); | 390 layout->StartRow(0, single_column_view_set_id); |
526 layout->AddView(new DateTimeSection(profile())); | 391 layout->AddView(new DateTimeSection(profile())); |
527 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 392 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
528 layout->StartRow(0, single_column_view_set_id); | 393 layout->StartRow(0, single_column_view_set_id); |
529 layout->AddView(new TouchpadSection(profile())); | 394 layout->AddView(new TouchpadSection(profile())); |
530 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 395 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
531 layout->StartRow(0, single_column_view_set_id); | 396 layout->StartRow(0, single_column_view_set_id); |
532 layout->AddView(new LanguageSection(profile())); | |
533 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
534 layout->StartRow(0, single_column_view_set_id); | |
535 layout->AddView(new AccessibilitySection(profile())); | 397 layout->AddView(new AccessibilitySection(profile())); |
536 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 398 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
537 } | 399 } |
538 | 400 |
539 } // namespace chromeos | 401 } // namespace chromeos |
OLD | NEW |