1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71

ash / system / locale / locale_feature_pod_controller.cc [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/system/locale/locale_feature_pod_controller.h"

#include "ash/constants/quick_settings_catalogs.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/locale_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/unified/feature_tile.h"
#include "ash/system/unified/quick_settings_metrics_util.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/i18n/case_conversion.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"

namespace ash {
namespace {

bool IsButtonVisible() {
  return !Shell::Get()->system_tray_model()->locale()->locale_list().empty();
}

std::u16string GetSubLabelText() {
  return base::i18n::ToUpper(base::UTF8ToUTF16(l10n_util::GetLanguage(
      Shell::Get()->system_tray_model()->locale()->current_locale_iso_code())));
}

}  // namespace

LocaleFeaturePodController::LocaleFeaturePodController(
    UnifiedSystemTrayController* tray_controller)
    : tray_controller_(tray_controller) {}

LocaleFeaturePodController::~LocaleFeaturePodController() = default;

std::unique_ptr<FeatureTile> LocaleFeaturePodController::CreateTile(
    bool compact) {
  auto tile = std::make_unique<FeatureTile>(
      base::BindRepeating(&LocaleFeaturePodController::OnIconPressed,
                          weak_factory_.GetWeakPtr()),
      /*is_togglable=*/false);
  const bool visible = IsButtonVisible();
  tile->SetVisible(visible);
  if (visible) {
    TrackVisibilityUMA();
    tile->SetVectorIcon(kUnifiedMenuLocaleIcon);
    tile->SetTooltipText(
        l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALE_TOOLTIP));
    tile->CreateDecorativeDrillInArrow();
    tile->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALE));
    tile->SetSubLabel(GetSubLabelText());
  }
  return tile;
}

QsFeatureCatalogName LocaleFeaturePodController::GetCatalogName() {
  return QsFeatureCatalogName::kLocale;
}

void LocaleFeaturePodController::OnIconPressed() {
  TrackDiveInUMA();
  tray_controller_->ShowLocaleDetailedView();
}

}  // namespace ash