Commit 2122650c authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Update shelf localized content on locale change

Bug: 943491
Change-Id: I24fb4c0bb8ed7aacdde17509e89b145035f38f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1568188
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651801}
parent 89aadba3
......@@ -66,6 +66,8 @@ using session_manager::SessionState;
namespace ash {
namespace {
const char* kLoginShelfButtonClassName = "LoginShelfButton";
LoginMetricsRecorder::ShelfButtonClickTarget GetUserClickTarget(int button_id) {
switch (button_id) {
case LoginShelfView::kShutdown:
......@@ -132,10 +134,12 @@ void SetButtonHighlightPath(views::View* view) {
class LoginShelfButton : public views::LabelButton {
public:
LoginShelfButton(views::ButtonListener* listener,
const base::string16& text,
int text_resource_id,
const gfx::VectorIcon& icon)
: LabelButton(listener, text), icon_(icon) {
SetAccessibleName(text);
: LabelButton(listener, l10n_util::GetStringUTF16(text_resource_id)),
text_resource_id_(text_resource_id),
icon_(icon) {
SetAccessibleName(GetText());
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, kButtonIconColor));
SetImage(views::Button::STATE_DISABLED,
......@@ -169,12 +173,18 @@ class LoginShelfButton : public views::LabelButton {
~LoginShelfButton() override = default;
int text_resource_id() const { return text_resource_id_; }
// views::LabelButton:
gfx::Insets GetInsets() const override {
return gfx::Insets(kButtonMarginTopDp, kButtonMarginLeftDp,
kButtonMarginBottomDp, kButtonMarginRightDp);
}
const char* GetClassName() const override {
return kLoginShelfButtonClassName;
}
void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
SetButtonHighlightPath(this);
LabelButton::OnBoundsChanged(previous_bounds);
......@@ -208,6 +218,7 @@ class LoginShelfButton : public views::LabelButton {
}
private:
const int text_resource_id_;
const gfx::VectorIcon& icon_;
DISALLOW_COPY_AND_ASSIGN(LoginShelfButton);
......@@ -394,8 +405,8 @@ LoginShelfView::LoginShelfView(
auto add_button = [this](ButtonId id, int text_resource_id,
const gfx::VectorIcon& icon) {
const base::string16 text = l10n_util::GetStringUTF16(text_resource_id);
LoginShelfButton* button = new LoginShelfButton(this, text, icon);
LoginShelfButton* button =
new LoginShelfButton(this, text_resource_id, icon);
button->set_id(id);
AddChildView(button);
};
......@@ -420,6 +431,7 @@ LoginShelfView::LoginShelfView(
lock_screen_action_background_observer_.Add(lock_screen_action_background);
login_screen_controller_observer_.Add(
Shell::Get()->login_screen_controller());
locale_change_observer_.Add(Shell::Get()->locale_update_controller());
UpdateUi();
}
......@@ -584,6 +596,16 @@ void LoginShelfView::OnUsersChanged(
UpdateUi();
}
void LoginShelfView::OnLocaleChanged() {
for (views::View* child : children()) {
if (child->GetClassName() == kLoginShelfButtonClassName) {
auto* button = static_cast<LoginShelfButton*>(child);
button->SetText(l10n_util::GetStringUTF16(button->text_resource_id()));
button->SetAccessibleName(button->GetText());
}
}
}
bool LoginShelfView::LockScreenActionBackgroundAnimating() const {
return lock_screen_action_background_->state() ==
LockScreenActionBackgroundState::kShowing ||
......
......@@ -16,6 +16,7 @@
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "ash/shutdown_controller.h"
#include "ash/system/locale/locale_update_controller.h"
#include "ash/tray_action/tray_action_observer.h"
#include "base/scoped_observer.h"
#include "ui/views/controls/button/button.h"
......@@ -49,7 +50,8 @@ class ASH_EXPORT LoginShelfView : public views::View,
public LockScreenActionBackgroundObserver,
public ShutdownController::Observer,
public LoginScreenControllerObserver,
public LoginDataDispatcher::Observer {
public LoginDataDispatcher::Observer,
public LocaleChangeObserver {
public:
enum ButtonId {
kShutdown = 1, // Shut down the device.
......@@ -143,6 +145,9 @@ class ASH_EXPORT LoginShelfView : public views::View,
void OnUsersChanged(
const std::vector<mojom::LoginUserInfoPtr>& users) override;
// LocaleChangeObserver:
void OnLocaleChanged() override;
private:
bool LockScreenActionBackgroundAnimating() const;
......@@ -179,6 +184,9 @@ class ASH_EXPORT LoginShelfView : public views::View,
ScopedObserver<LoginScreenController, LoginScreenControllerObserver>
login_screen_controller_observer_;
ScopedObserver<LocaleUpdateController, LocaleChangeObserver>
locale_change_observer_{this};
KioskAppsButton* kiosk_apps_button_ = nullptr; // Owned by view hierarchy
// This is used in tests to wait until UI is updated.
......
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