Commit bdf77345 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Add current locale icon to status tray

We want to show a visual indicator in the status tray when the language
toggle is available (in demo mode). It should show the abbreviation of
the locale such as "DA".

The only caveat is that the IME indicator may also be shown in the same
place, so showing two strings with the same format may confuse users.
PM confirms that we want to hide the IME indicator as long as the
locale indicator is available.

Bug: 877749
Change-Id: Ieca21dd46c846b81147bd44798b2deb25d9d57fa
Reviewed-on: https://chromium-review.googlesource.com/c/1370886Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615740}
parent c33916c6
......@@ -762,6 +762,8 @@ component("ash") {
"system/model/clock_model.h",
"system/model/enterprise_domain_model.cc",
"system/model/enterprise_domain_model.h",
"system/model/locale_model.cc",
"system/model/locale_model.h",
"system/model/session_length_limit_model.cc",
"system/model/session_length_limit_model.h",
"system/model/system_tray_model.cc",
......@@ -974,6 +976,8 @@ component("ash") {
"system/tray/view_click_listener.h",
"system/unified/collapse_button.cc",
"system/unified/collapse_button.h",
"system/unified/current_locale_view.cc",
"system/unified/current_locale_view.h",
"system/unified/detailed_view_controller.h",
"system/unified/feature_pod_button.cc",
"system/unified/feature_pod_button.h",
......
......@@ -282,6 +282,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_INDICATOR_IME_TOOLTIP" desc="The tooltip text for the status area icon to tell the type of keyboard or input method engine.">
Using <ph name="IME_NAME">$1<ex>US keyboard</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_INDICATOR_LOCALE_TOOLTIP" desc="The tooltip text for the status area icon to indicate the current locale.">
Using <ph name="LOCALE_NAME">$1<ex>English (United States)</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_NOTIFICATIONS_COUNT_TOOLTIP" desc="The tooltip text for a status area icon to describe number of notifications. [ICU Syntax]">
{NUM_NOTIFICATIONS, plural,
=1 {1 notification}
......
1d44fa540505bd2b9a690905d46e2f6919a24beb
\ No newline at end of file
......@@ -7,6 +7,7 @@
#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/tray/actionable_view.h"
#include "ash/system/tray/tray_popup_item_style.h"
......@@ -120,12 +121,12 @@ void LocaleDetailedView::CreateItems() {
CreateScrollableList();
const std::vector<mojom::LocaleInfoPtr>& locales =
Shell::Get()->system_tray_model()->locale_list();
Shell::Get()->system_tray_model()->locale()->locale_list();
int id = 0;
for (auto& entry : locales) {
const bool checked =
entry->iso_code ==
Shell::Get()->system_tray_model()->current_locale_iso_code();
Shell::Get()->system_tray_model()->locale()->current_locale_iso_code();
LocaleItem* item =
new LocaleItem(this, entry->iso_code, entry->display_name, checked);
scroll_content()->AddChildView(item);
......@@ -141,7 +142,7 @@ void LocaleDetailedView::HandleViewClicked(views::View* view) {
DCHECK(it != id_to_locale_.end());
const std::string locale_iso_code = it->second;
if (locale_iso_code !=
Shell::Get()->system_tray_model()->current_locale_iso_code()) {
Shell::Get()->system_tray_model()->locale()->current_locale_iso_code()) {
Shell::Get()->system_tray_model()->client_ptr()->SetLocaleAndExit(
locale_iso_code);
}
......
......@@ -7,6 +7,7 @@
#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_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
......@@ -25,7 +26,7 @@ LocaleFeaturePodController::~LocaleFeaturePodController() = default;
FeaturePodButton* LocaleFeaturePodController::CreateButton() {
auto* button = new FeaturePodButton(this);
const bool visible =
!Shell::Get()->system_tray_model()->locale_list().empty();
!Shell::Get()->system_tray_model()->locale()->locale_list().empty();
button->SetVisible(visible);
if (visible) {
button->SetVectorIcon(kUnifiedMenuLocaleIcon);
......@@ -34,9 +35,11 @@ FeaturePodButton* LocaleFeaturePodController::CreateButton() {
button->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALE));
button->ShowDetailedViewArrow();
button->DisableLabelButtonFocus();
button->SetSubLabel(
base::i18n::ToUpper(base::UTF8ToUTF16(l10n_util::GetLanguage(
Shell::Get()->system_tray_model()->current_locale_iso_code()))));
button->SetSubLabel(base::i18n::ToUpper(base::UTF8ToUTF16(
l10n_util::GetLanguage(Shell::Get()
->system_tray_model()
->locale()
->current_locale_iso_code()))));
}
return button;
}
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/model/locale_model.h"
namespace ash {
LocaleModel::Observer::~Observer() = default;
LocaleModel::LocaleModel() = default;
LocaleModel::~LocaleModel() = default;
void LocaleModel::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void LocaleModel::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void LocaleModel::SetLocaleList(std::vector<mojom::LocaleInfoPtr> locale_list,
const std::string& current_locale_iso_code) {
locale_list_ = std::move(locale_list);
current_locale_iso_code_ = current_locale_iso_code;
for (auto& observer : observers_)
observer.OnLocaleListSet();
}
bool LocaleModel::ShouldShowCurrentLocaleInStatusArea() const {
return !current_locale_iso_code_.empty();
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_MODEL_LOCALE_MODEL_H_
#define ASH_SYSTEM_MODEL_LOCALE_MODEL_H_
#include <string>
#include <vector>
#include "ash/public/interfaces/system_tray.mojom.h"
#include "base/macros.h"
#include "base/observer_list.h"
namespace ash {
// Model to store system locale list.
class LocaleModel {
public:
class Observer {
public:
virtual ~Observer();
// Notify the observer that the locale list is set.
virtual void OnLocaleListSet() = 0;
};
LocaleModel();
~LocaleModel();
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void SetLocaleList(std::vector<mojom::LocaleInfoPtr> locale_list,
const std::string& current_locale_iso_code);
bool ShouldShowCurrentLocaleInStatusArea() const;
const std::vector<mojom::LocaleInfoPtr>& locale_list() {
return locale_list_;
}
std::string current_locale_iso_code() const {
return current_locale_iso_code_;
}
private:
std::vector<mojom::LocaleInfoPtr> locale_list_;
std::string current_locale_iso_code_;
base::ObserverList<Observer>::Unchecked observers_;
DISALLOW_COPY_AND_ASSIGN(LocaleModel);
};
} // namespace ash
#endif // ASH_SYSTEM_MODEL_LOCALE_MODEL_H_
......@@ -8,6 +8,7 @@
#include "ash/shell.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/system/model/locale_model.h"
#include "ash/system/model/session_length_limit_model.h"
#include "ash/system/model/tracing_model.h"
#include "ash/system/model/update_model.h"
......@@ -21,6 +22,7 @@ namespace ash {
SystemTrayModel::SystemTrayModel()
: clock_(std::make_unique<ClockModel>()),
enterprise_domain_(std::make_unique<EnterpriseDomainModel>()),
locale_(std::make_unique<LocaleModel>()),
session_length_limit_(std::make_unique<SessionLengthLimitModel>()),
tracing_(std::make_unique<TracingModel>()),
update_model_(std::make_unique<UpdateModel>()),
......@@ -70,8 +72,7 @@ void SystemTrayModel::SetPerformanceTracingIconVisible(bool visible) {
void SystemTrayModel::SetLocaleList(
std::vector<mojom::LocaleInfoPtr> locale_list,
const std::string& current_locale_iso_code) {
locale_list_ = std::move(locale_list);
current_locale_iso_code_ = current_locale_iso_code;
locale()->SetLocaleList(std::move(locale_list), current_locale_iso_code);
}
void SystemTrayModel::ShowUpdateIcon(mojom::UpdateSeverity severity,
......
......@@ -15,6 +15,7 @@ namespace ash {
class ClockModel;
class EnterpriseDomainModel;
class LocaleModel;
class SessionLengthLimitModel;
class TracingModel;
class UpdateModel;
......@@ -54,6 +55,7 @@ class SystemTrayModel : public mojom::SystemTray {
EnterpriseDomainModel* enterprise_domain() {
return enterprise_domain_.get();
}
LocaleModel* locale() { return locale_.get(); }
SessionLengthLimitModel* session_length_limit() {
return session_length_limit_.get();
}
......@@ -61,26 +63,17 @@ class SystemTrayModel : public mojom::SystemTray {
UpdateModel* update_model() { return update_model_.get(); }
VirtualKeyboardModel* virtual_keyboard() { return virtual_keyboard_.get(); }
const std::vector<mojom::LocaleInfoPtr>& locale_list() {
return locale_list_;
}
std::string current_locale_iso_code() const {
return current_locale_iso_code_;
}
const mojom::SystemTrayClientPtr& client_ptr() { return client_ptr_; }
private:
std::unique_ptr<ClockModel> clock_;
std::unique_ptr<EnterpriseDomainModel> enterprise_domain_;
std::unique_ptr<LocaleModel> locale_;
std::unique_ptr<SessionLengthLimitModel> session_length_limit_;
std::unique_ptr<TracingModel> tracing_;
std::unique_ptr<UpdateModel> update_model_;
std::unique_ptr<VirtualKeyboardModel> virtual_keyboard_;
std::vector<mojom::LocaleInfoPtr> locale_list_;
std::string current_locale_iso_code_;
// TODO(tetsui): Add following as a sub-model of SystemTrayModel:
// * BluetoothModel
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/unified/current_locale_view.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
#include "base/i18n/case_conversion.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/label.h"
namespace ash {
CurrentLocaleView::CurrentLocaleView(Shelf* shelf) : TrayItemView(shelf) {
SetVisible(false);
CreateLabel();
SetupLabelForTray(label());
Shell::Get()->system_tray_model()->locale()->AddObserver(this);
}
CurrentLocaleView::~CurrentLocaleView() {
Shell::Get()->system_tray_model()->locale()->RemoveObserver(this);
}
void CurrentLocaleView::OnLocaleListSet() {
LocaleModel* const locale_model = Shell::Get()->system_tray_model()->locale();
SetVisible(locale_model->ShouldShowCurrentLocaleInStatusArea());
label()->SetText(base::i18n::ToUpper(base::UTF8ToUTF16(
l10n_util::GetLanguage(locale_model->current_locale_iso_code()))));
label()->SetEnabledColor(
TrayIconColor(Shell::Get()->session_controller()->GetSessionState()));
const std::vector<mojom::LocaleInfoPtr>& locales =
locale_model->locale_list();
for (auto& entry : locales) {
if (entry->iso_code == locale_model->current_locale_iso_code()) {
const base::string16 description = l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_INDICATOR_LOCALE_TOOLTIP, entry->display_name);
label()->SetTooltipText(description);
label()->SetCustomAccessibleName(description);
break;
}
}
Layout();
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_UNIFIED_CURRENT_LOCALE_VIEW_H_
#define ASH_SYSTEM_UNIFIED_CURRENT_LOCALE_VIEW_H_
#include "ash/system/model/locale_model.h"
#include "ash/system/tray/tray_item_view.h"
#include "base/macros.h"
namespace ash {
// The current locale view in UnifiedSystemTray button. The view shows the
// abbreviation of the current locale (e.g. "DA").
class CurrentLocaleView : public TrayItemView, public LocaleModel::Observer {
public:
explicit CurrentLocaleView(Shelf* shelf);
~CurrentLocaleView() override;
// LocaleModel::Observer:
void OnLocaleListSet() override;
private:
DISALLOW_COPY_AND_ASSIGN(CurrentLocaleView);
};
} // namespace ash
#endif // ASH_SYSTEM_UNIFIED_CURRENT_LOCALE_VIEW_H_
......@@ -8,6 +8,7 @@
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
......@@ -24,12 +25,14 @@ ImeModeView::ImeModeView(Shelf* shelf) : TrayItemView(shelf) {
Update();
Shell::Get()->system_tray_notifier()->AddIMEObserver(this);
Shell::Get()->system_tray_model()->locale()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this);
}
ImeModeView::~ImeModeView() {
if (Shell::Get()->tablet_mode_controller())
Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
Shell::Get()->system_tray_model()->locale()->RemoveObserver(this);
Shell::Get()->system_tray_notifier()->RemoveIMEObserver(this);
}
......@@ -42,6 +45,10 @@ void ImeModeView::OnIMEMenuActivationChanged(bool is_active) {
Update();
}
void ImeModeView::OnLocaleListSet() {
Update();
}
void ImeModeView::OnTabletModeStarted() {
Update();
}
......@@ -55,6 +62,16 @@ void ImeModeView::OnSessionStateChanged(session_manager::SessionState state) {
}
void ImeModeView::Update() {
// Hide the IME mode icon when the locale is shown, because showing locale and
// IME together is confusing.
if (Shell::Get()
->system_tray_model()
->locale()
->ShouldShowCurrentLocaleInStatusArea()) {
SetVisible(false);
return;
}
// Do not show IME mode icon in tablet mode as it's less useful and screen
// space is limited.
if (Shell::Get()
......
......@@ -7,6 +7,7 @@
#include "ash/session/session_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/model/locale_model.h"
#include "ash/system/tray/tray_item_view.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/macros.h"
......@@ -16,6 +17,7 @@ namespace ash {
// An IME mode icon view in UnifiedSystemTray button.
class ImeModeView : public TrayItemView,
public IMEObserver,
public LocaleModel::Observer,
public TabletModeObserver,
public SessionObserver {
public:
......@@ -26,6 +28,9 @@ class ImeModeView : public TrayItemView,
void OnIMERefresh() override;
void OnIMEMenuActivationChanged(bool is_active) override;
// LocaleModel::Observer:
void OnLocaleListSet() override;
// TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
......
......@@ -22,6 +22,7 @@
#include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_container.h"
#include "ash/system/unified/current_locale_view.h"
#include "ash/system/unified/ime_mode_view.h"
#include "ash/system/unified/managed_device_view.h"
#include "ash/system/unified/notification_counter_view.h"
......@@ -122,12 +123,14 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
slider_bubble_controller_(
std::make_unique<UnifiedSliderBubbleController>(this)),
network_icon_purger_(std::make_unique<NetworkIconPurger>()),
current_locale_view_(new CurrentLocaleView(shelf)),
ime_mode_view_(new ImeModeView(shelf)),
managed_device_view_(new ManagedDeviceView(shelf)),
notification_counter_item_(new NotificationCounterView(shelf)),
quiet_mode_view_(new QuietModeView(shelf)),
time_view_(new tray::TimeTrayItemView(shelf)) {
tray_container()->SetMargin(kUnifiedTrayContentPadding, 0);
tray_container()->AddChildView(current_locale_view_);
tray_container()->AddChildView(ime_mode_view_);
tray_container()->AddChildView(managed_device_view_);
tray_container()->AddChildView(notification_counter_item_);
......
......@@ -18,6 +18,7 @@ namespace tray {
class TimeTrayItemView;
} // namespace tray
class CurrentLocaleView;
class ImeModeView;
class ManagedDeviceView;
class NotificationCounterView;
......@@ -126,6 +127,7 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView {
const std::unique_ptr<NetworkIconPurger> network_icon_purger_;
CurrentLocaleView* const current_locale_view_;
ImeModeView* const ime_mode_view_;
ManagedDeviceView* const managed_device_view_;
NotificationCounterView* const notification_counter_item_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment