Commit e4627b85 authored by Toni Barzic's avatar Toni Barzic Committed by Commit Bot

Update strings in status area widget on locale change

Has shelf layout manager notify the status area widget that the locale
has changed, which then forwards the notification to tray items, and
unified tray items so they can update any cached strings (e.g. string
used for item tooltips).

This added pure virtual  HandleLocaleChange() method to TrayItemView and
TrayBackgroundView to make sure that tray items added in future
implement this.

BUG=1077147, 1076318, 1076310, 1076302, 1076301

Change-Id: I09ae5b891a383a89eb748cd27f86aab8c461f3d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222949Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774936}
parent 48a6993d
......@@ -1149,6 +1149,7 @@ void ShelfLayoutManager::OnDisplayMetricsChanged(
void ShelfLayoutManager::OnLocaleChanged() {
shelf_->shelf_widget()->HandleLocaleChange();
shelf_->status_area_widget()->HandleLocaleChange();
shelf_->navigation_widget()->HandleLocaleChange();
// Layout update is needed when language changes between LTR and RTL.
......
......@@ -85,6 +85,11 @@ base::string16 DictationButtonTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_DICTATION_BUTTON_ACCESSIBLE_NAME);
}
void DictationButtonTray::HandleLocaleChange() {
icon_->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBILITY_DICTATION));
}
void DictationButtonTray::HideBubbleWithView(
const TrayBubbleView* bubble_view) {
// This class has no bubbles to hide.
......
......@@ -49,6 +49,7 @@ class ASH_EXPORT DictationButtonTray : public TrayBackgroundView,
void Initialize() override;
void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
// views::View:
......
......@@ -61,6 +61,11 @@ base::string16 SelectToSpeakTray::GetAccessibleNameForTray() {
IDS_ASH_SELECT_TO_SPEAK_TRAY_ACCESSIBLE_NAME);
}
void SelectToSpeakTray::HandleLocaleChange() {
icon_->set_tooltip_text(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_SELECT_TO_SPEAK));
}
const char* SelectToSpeakTray::GetClassName() const {
return kSelectToSpeakTrayClassName;
}
......
......@@ -29,6 +29,7 @@ class ASH_EXPORT SelectToSpeakTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
const char* GetClassName() const override;
bool PerformAction(const ui::Event& event) override;
// The SelectToSpeakTray does not have a bubble, so these functions are
......
......@@ -431,6 +431,16 @@ base::string16 ImeMenuTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
}
void ImeMenuTray::HandleLocaleChange() {
if (image_view_) {
image_view_->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME));
}
if (label_)
label_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME));
}
void ImeMenuTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
if (bubble_->bubble_view() == bubble_view)
CloseBubble();
......
......@@ -51,6 +51,7 @@ class ASH_EXPORT ImeMenuTray : public TrayBackgroundView,
// TrayBackgroundView:
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble() override;
bool PerformAction(const ui::Event& event) override;
......
......@@ -71,6 +71,10 @@ base::string16 NetworkTrayView::GetTooltipText(const gfx::Point& p) const {
return tooltip_;
}
void NetworkTrayView::HandleLocaleChange() {
UpdateConnectionStatus(false /* notify_a11y */);
}
void NetworkTrayView::NetworkIconChanged() {
UpdateNetworkStateHandlerIcon();
UpdateConnectionStatus(false /* notify_a11y */);
......
......@@ -38,6 +38,9 @@ class NetworkTrayView : public TrayItemView,
views::View* GetTooltipHandlerForPoint(const gfx::Point& point) override;
base::string16 GetTooltipText(const gfx::Point& p) const override;
// TrayItemView:
void HandleLocaleChange() override;
// network_icon::AnimationObserver:
void NetworkIconChanged() override;
......
......@@ -179,6 +179,8 @@ base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
}
void OverviewButtonTray::HandleLocaleChange() {}
void OverviewButtonTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
// This class has no bubbles to hide.
}
......
......@@ -71,6 +71,7 @@ class ASH_EXPORT OverviewButtonTray : public TrayBackgroundView,
void UpdateAfterLoginStatusChange() override;
void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
// views::View:
......
......@@ -297,6 +297,11 @@ base::string16 PaletteTray::GetAccessibleNameForTray() {
return l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE);
}
void PaletteTray::HandleLocaleChange() {
icon_->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_TITLE));
}
void PaletteTray::HideBubbleWithView(const TrayBubbleView* bubble_view) {
if (bubble_->bubble_view() == bubble_view)
HidePalette();
......
......@@ -73,6 +73,7 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
// TrayBackgroundView:
void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void AnchorUpdated() override;
void Initialize() override;
......
......@@ -77,6 +77,10 @@ const char* PowerTrayView::GetClassName() const {
return "PowerTrayView";
}
void PowerTrayView::HandleLocaleChange() {
UpdateStatus();
}
void PowerTrayView::OnPowerStatusChanged() {
UpdateStatus();
}
......
......@@ -31,6 +31,9 @@ class PowerTrayView : public TrayItemView,
base::string16 GetTooltipText(const gfx::Point& p) const override;
const char* GetClassName() const override;
// TrayItemView:
void HandleLocaleChange() override;
// PowerStatus::Observer:
void OnPowerStatusChanged() override;
......
......@@ -129,6 +129,10 @@ base::string16 LogoutButtonTray::GetAccessibleNameForTray() {
return button_->GetText();
}
void LogoutButtonTray::HandleLocaleChange() {
UpdateButtonTextAndImage();
}
void LogoutButtonTray::UpdateVisibility() {
LoginStatus login_status = shelf()->GetStatusAreaWidget()->login_status();
SetVisiblePreferred(show_logout_button_in_tray_ &&
......
......@@ -42,6 +42,7 @@ class ASH_EXPORT LogoutButtonTray : public TrayBackgroundView,
void ClickedOutsideBubble() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
const char* GetClassName() const override;
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
......
......@@ -248,6 +248,11 @@ void StatusAreaWidget::UpdateTargetBoundsForGesture(int shelf_position) {
target_bounds_.set_x(shelf_position);
}
void StatusAreaWidget::HandleLocaleChange() {
for (auto* tray_button : tray_buttons_)
tray_button->HandleLocaleChange();
}
void StatusAreaWidget::CalculateButtonVisibilityForCollapsedState() {
if (!initialized_)
return;
......
......@@ -82,6 +82,9 @@ class ASH_EXPORT StatusAreaWidget : public SessionObserver,
void UpdateLayout(bool animate) override;
void UpdateTargetBoundsForGesture(int shelf_position) override;
// Called by shelf layout manager when a locale change has been detected.
void HandleLocaleChange();
// Sets system tray visibility. Shows or hides widget if needed.
void SetSystemTrayVisibility(bool visible);
......
......@@ -34,6 +34,10 @@ void TimeTrayItemView::UpdateAlignmentForShelf(Shelf* shelf) {
time_view_->UpdateClockLayout(clock_layout);
}
void TimeTrayItemView::HandleLocaleChange() {
time_view_->Refresh();
}
void TimeTrayItemView::OnSessionStateChanged(
session_manager::SessionState state) {
time_view_->SetTextColor(TrayIconColor(state));
......
......@@ -25,6 +25,9 @@ class TimeTrayItemView : public TrayItemView, public SessionObserver {
void UpdateAlignmentForShelf(Shelf* shelf);
TimeView* time_view() { return time_view_; }
// TrayItemView:
void HandleLocaleChange() override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
......
......@@ -107,6 +107,8 @@ base::string16 StatusAreaOverflowButtonTray::GetAccessibleNameForTray() {
: IDS_ASH_STATUS_AREA_OVERFLOW_BUTTON_EXPAND);
}
void StatusAreaOverflowButtonTray::HandleLocaleChange() {}
void StatusAreaOverflowButtonTray::HideBubbleWithView(
const TrayBubbleView* bubble_view) {}
......
......@@ -37,6 +37,7 @@ class ASH_EXPORT StatusAreaOverflowButtonTray : public TrayBackgroundView {
// TrayBackgroundView:
void ClickedOutsideBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void Initialize() override;
bool PerformAction(const ui::Event& event) override;
......
......@@ -85,6 +85,11 @@ class ASH_EXPORT TrayBackgroundView : public ActionableView,
// Called from GetAccessibleNodeData, must return a valid accessible name.
virtual base::string16 GetAccessibleNameForTray() = 0;
// Called when a locale change is detected. It should reload any strings the
// view may be using. Note that the locale is not expected to change after the
// user logs in.
virtual void HandleLocaleChange() = 0;
// Called when the bubble is resized.
virtual void BubbleResized(const TrayBubbleView* bubble_view);
......
......@@ -59,6 +59,10 @@ class ASH_EXPORT TrayItemView : public views::View,
void CreateLabel();
void CreateImageView();
// Called when locale change is detected (which should not happen after the
// user session starts). It should reload any strings the view is using.
virtual void HandleLocaleChange() = 0;
IconizedLabel* label() const { return label_; }
views::ImageView* image_view() const { return image_view_; }
......
......@@ -54,4 +54,9 @@ const char* CurrentLocaleView::GetClassName() const {
return "CurrentLocaleView";
}
void CurrentLocaleView::HandleLocaleChange() {
// Nothing to do here, when this view is used, the locale will be updated
// using locale_model.
}
} // namespace ash
......@@ -23,6 +23,7 @@ class CurrentLocaleView : public TrayItemView, public LocaleModel::Observer {
// views::TrayItemView:
const char* GetClassName() const override;
void HandleLocaleChange() override;
private:
DISALLOW_COPY_AND_ASSIGN(CurrentLocaleView);
......
......@@ -65,6 +65,10 @@ const char* ImeModeView::GetClassName() const {
return "ImeModeView";
}
void ImeModeView::HandleLocaleChange() {
Update();
}
void ImeModeView::Update() {
// Hide the IME mode icon when the locale is shown, because showing locale and
// IME together is confusing.
......
......@@ -40,6 +40,7 @@ class ImeModeView : public TrayItemView,
// views::TrayItemView:
const char* GetClassName() const override;
void HandleLocaleChange() override;
private:
void Update();
......
......@@ -46,6 +46,10 @@ const char* ManagedDeviceTrayItemView::GetClassName() const {
return "ManagedDeviceTrayItemView";
}
void ManagedDeviceTrayItemView::HandleLocaleChange() {
Update();
}
void ManagedDeviceTrayItemView::Update() {
SessionControllerImpl* session = Shell::Get()->session_controller();
if (session->IsUserPublicAccount()) {
......
......@@ -30,6 +30,7 @@ class ManagedDeviceTrayItemView : public TrayItemView,
// views::TrayItemView:
const char* GetClassName() const override;
void HandleLocaleChange() override;
private:
void Update();
......
......@@ -132,6 +132,10 @@ base::string16 NotificationCounterView::GetAccessibleNameString() const {
message_center::MessageCenter::Get()->NotificationCount());
}
void NotificationCounterView::HandleLocaleChange() {
Update();
}
void NotificationCounterView::OnSessionStateChanged(
session_manager::SessionState state) {
Update();
......@@ -168,6 +172,11 @@ void QuietModeView::Update() {
}
}
void QuietModeView::HandleLocaleChange() {
image_view()->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_QUIET_MODE_TOOLTIP));
}
void QuietModeView::OnSessionStateChanged(session_manager::SessionState state) {
Update();
}
......
......@@ -22,6 +22,9 @@ class NotificationCounterView : public TrayItemView, public SessionObserver {
// Returns a string describing the current state for accessibility.
base::string16 GetAccessibleNameString() const;
// TrayItemView:
void HandleLocaleChange() override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
......@@ -46,6 +49,9 @@ class QuietModeView : public TrayItemView, public SessionObserver {
void Update();
// TrayItemView:
void HandleLocaleChange() override;
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;
......
......@@ -138,24 +138,24 @@ UnifiedSystemTray::UnifiedSystemTray(Shelf* shelf)
kUnifiedTrayContentPadding -
ShelfConfig::Get()->status_area_hit_region_padding(),
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_);
tray_container()->AddChildView(quiet_mode_view_);
AddTrayItemToContainer(current_locale_view_);
AddTrayItemToContainer(ime_mode_view_);
AddTrayItemToContainer(managed_device_view_);
AddTrayItemToContainer(notification_counter_item_);
AddTrayItemToContainer(quiet_mode_view_);
if (features::IsSeparateNetworkIconsEnabled()) {
network_tray_view_ =
new tray::NetworkTrayView(shelf, ActiveNetworkIcon::Type::kPrimary);
tray_container()->AddChildView(
AddTrayItemToContainer(
new tray::NetworkTrayView(shelf, ActiveNetworkIcon::Type::kCellular));
} else {
network_tray_view_ =
new tray::NetworkTrayView(shelf, ActiveNetworkIcon::Type::kSingle);
}
tray_container()->AddChildView(network_tray_view_);
tray_container()->AddChildView(new tray::PowerTrayView(shelf));
tray_container()->AddChildView(time_view_);
AddTrayItemToContainer(network_tray_view_);
AddTrayItemToContainer(new tray::PowerTrayView(shelf));
AddTrayItemToContainer(time_view_);
set_separator_visibility(false);
......@@ -391,6 +391,11 @@ base::string16 UnifiedSystemTray::GetAccessibleNameForQuickSettingsBubble() {
IDS_ASH_QUICK_SETTINGS_BUBBLE_ACCESSIBLE_DESCRIPTION);
}
void UnifiedSystemTray::HandleLocaleChange() {
for (TrayItemView* item : tray_items_)
item->HandleLocaleChange();
}
base::string16 UnifiedSystemTray::GetAccessibleNameForTray() {
base::string16 time = base::TimeFormatTimeOfDayWithHourClockType(
base::Time::Now(),
......@@ -478,4 +483,8 @@ UnifiedSystemTray::GetPopupViewForNotificationID(
return ui_delegate_->GetPopupViewForNotificationID(notification_id);
}
void UnifiedSystemTray::AddTrayItemToContainer(TrayItemView* tray_item) {
tray_items_.push_back(tray_item);
tray_container()->AddChildView(tray_item);
}
} // namespace ash
......@@ -5,6 +5,7 @@
#ifndef ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_H_
#define ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_H_
#include <list>
#include <memory>
#include "ash/ash_export.h"
......@@ -20,8 +21,8 @@ class MessagePopupView;
namespace ash {
namespace tray {
class TimeTrayItemView;
class NetworkTrayView;
class TimeTrayItemView;
} // namespace tray
class CurrentLocaleView;
......@@ -30,6 +31,7 @@ class ManagedDeviceTrayItemView;
class NotificationCounterView;
class QuietModeView;
class PrivacyScreenToastController;
class TrayItemView;
class UnifiedSliderBubbleController;
class UnifiedSystemTrayBubble;
class UnifiedSystemTrayModel;
......@@ -142,6 +144,7 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView,
void CloseBubble() override;
base::string16 GetAccessibleNameForBubble() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubble(const TrayBubbleView* bubble_view) override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble() override;
......@@ -181,6 +184,10 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView,
message_center::MessagePopupView* GetPopupViewForNotificationID(
const std::string& notification_id);
// Adds the tray item to the the unified system tray container.
// The container takes the ownership of |tray_item|.
void AddTrayItemToContainer(TrayItemView* tray_item);
const std::unique_ptr<UiDelegate> ui_delegate_;
std::unique_ptr<UnifiedSystemTrayBubble> bubble_;
......@@ -205,6 +212,9 @@ class ASH_EXPORT UnifiedSystemTray : public TrayBackgroundView,
tray::NetworkTrayView* network_tray_view_ = nullptr;
// Contains all tray items views added to tray_container().
std::list<TrayItemView*> tray_items_;
base::OneShotTimer timer_;
bool first_interaction_recorded_ = false;
......
......@@ -60,6 +60,11 @@ base::string16 VirtualKeyboardTray::GetAccessibleNameForTray() {
IDS_ASH_VIRTUAL_KEYBOARD_TRAY_ACCESSIBLE_NAME);
}
void VirtualKeyboardTray::HandleLocaleChange() {
icon_->set_tooltip_text(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_ACCESSIBILITY_VIRTUAL_KEYBOARD));
}
void VirtualKeyboardTray::HideBubbleWithView(
const TrayBubbleView* bubble_view) {}
......
......@@ -31,6 +31,7 @@ class VirtualKeyboardTray : public TrayBackgroundView,
// TrayBackgroundView:
void Initialize() override;
base::string16 GetAccessibleNameForTray() override;
void HandleLocaleChange() override;
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble() override;
bool PerformAction(const ui::Event& event) override;
......
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