current_locale_view.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 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. #include "ash/system/unified/current_locale_view.h"
  5. #include "ash/session/session_controller_impl.h"
  6. #include "ash/shell.h"
  7. #include "ash/strings/grit/ash_strings.h"
  8. #include "ash/system/model/system_tray_model.h"
  9. #include "ash/system/tray/tray_constants.h"
  10. #include "ash/system/tray/tray_utils.h"
  11. #include "base/i18n/case_conversion.h"
  12. #include "base/strings/utf_string_conversions.h"
  13. #include "ui/base/l10n/l10n_util.h"
  14. #include "ui/views/border.h"
  15. #include "ui/views/controls/label.h"
  16. namespace ash {
  17. CurrentLocaleView::CurrentLocaleView(Shelf* shelf) : TrayItemView(shelf) {
  18. SetVisible(false);
  19. CreateLabel();
  20. SetupLabelForTray(label());
  21. SetBorder(views::CreateEmptyBorder(gfx::Insets::TLBR(
  22. kUnifiedTrayTextTopPadding, 0, 0, kUnifiedTrayTextRightPadding)));
  23. Shell::Get()->system_tray_model()->locale()->AddObserver(this);
  24. }
  25. CurrentLocaleView::~CurrentLocaleView() {
  26. Shell::Get()->system_tray_model()->locale()->RemoveObserver(this);
  27. }
  28. void CurrentLocaleView::OnLocaleListSet() {
  29. LocaleModel* const locale_model = Shell::Get()->system_tray_model()->locale();
  30. SetVisible(locale_model->ShouldShowCurrentLocaleInStatusArea());
  31. label()->SetText(base::i18n::ToUpper(base::UTF8ToUTF16(
  32. l10n_util::GetLanguage(locale_model->current_locale_iso_code()))));
  33. label()->SetEnabledColor(
  34. TrayIconColor(Shell::Get()->session_controller()->GetSessionState()));
  35. const std::vector<LocaleInfo>& locales = locale_model->locale_list();
  36. for (auto& entry : locales) {
  37. if (entry.iso_code == locale_model->current_locale_iso_code()) {
  38. const std::u16string description = l10n_util::GetStringFUTF16(
  39. IDS_ASH_STATUS_TRAY_INDICATOR_LOCALE_TOOLTIP, entry.display_name);
  40. label()->SetTooltipText(description);
  41. label()->SetCustomAccessibleName(description);
  42. break;
  43. }
  44. }
  45. Layout();
  46. }
  47. const char* CurrentLocaleView::GetClassName() const {
  48. return "CurrentLocaleView";
  49. }
  50. void CurrentLocaleView::HandleLocaleChange() {
  51. // Nothing to do here, when this view is used, the locale will be updated
  52. // using locale_model.
  53. }
  54. } // namespace ash