Commit 8f6850d6 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Show ISO code at the beginning of each locale item

Spent some time trying to extract and reuse the |ImeListItemView|, but
it's not easy since it contains IME specific logic (e.g.
|set_last_item_selected_with_keyboard|). In fact I believe we should
try to combine the class with |HoverHighlightView|, but it's a somewhat
large refactoring and is beyond the scope of this CL.

Bug: 877749
Change-Id: I9f4582fdcf865da7b3960a625cedbbdf710c7e4f
Reviewed-on: https://chromium-review.googlesource.com/c/1341065Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611530}
parent f66a7cf4
...@@ -4,14 +4,108 @@ ...@@ -4,14 +4,108 @@
#include "ash/system/locale/locale_detailed_view.h" #include "ash/system/locale/locale_detailed_view.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/hover_highlight_view.h" #include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
#include "ui/views/layout/fill_layout.h"
namespace ash { namespace ash {
namespace {
// The item that corresponds to a single locale in the locale list. The language
// portion of |iso_code| is shown at the beginning of the row, and
// |display_name| is shown in the middle. A checkmark is shown in the end if
// |checked| is true.
class LocaleItem : public ActionableView {
public:
LocaleItem(tray::LocaleDetailedView* locale_detailed_view,
const std::string& iso_code,
const base::string16& display_name,
bool checked)
: ActionableView(TrayPopupInkDropStyle::FILL_BOUNDS),
locale_detailed_view_(locale_detailed_view),
checked_(checked) {
SetInkDropMode(InkDropMode::ON);
TriView* tri_view = TrayPopupUtils::CreateDefaultRowView();
AddChildView(tri_view);
SetLayoutManager(std::make_unique<views::FillLayout>());
views::Label* iso_code_label = TrayPopupUtils::CreateDefaultLabel();
iso_code_label->SetEnabledColor(kUnifiedMenuTextColor);
iso_code_label->SetAutoColorReadabilityEnabled(false);
iso_code_label->SetText(base::i18n::ToUpper(
base::UTF8ToUTF16(l10n_util::GetLanguage(iso_code))));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::FontList& base_font_list =
rb.GetFontList(ui::ResourceBundle::MediumBoldFont);
iso_code_label->SetFontList(base_font_list);
tri_view->AddView(TriView::Container::START, iso_code_label);
auto* display_name_view = TrayPopupUtils::CreateDefaultLabel();
display_name_view->SetText(display_name);
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL,
true /* use_unified_theme */);
style.SetupLabel(display_name_view);
display_name_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
tri_view->AddView(TriView::Container::CENTER, display_name_view);
if (checked_) {
views::ImageView* checked_image = TrayPopupUtils::CreateMainImageView();
checked_image->SetImage(gfx::CreateVectorIcon(
kCheckCircleIcon, kMenuIconSize, gfx::kGoogleGreen700));
tri_view->AddView(TriView::Container::END, checked_image);
}
SetAccessibleName(display_name_view->text());
}
~LocaleItem() override = default;
// ActionableView:
bool PerformAction(const ui::Event& event) override {
locale_detailed_view_->HandleViewClicked(this);
return true;
}
// views::View:
void OnFocus() override {
ActionableView::OnFocus();
ScrollViewToVisible();
}
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
ActionableView::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kCheckBox;
node_data->SetCheckedState(checked_ ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse);
}
private:
tray::LocaleDetailedView* locale_detailed_view_;
const bool checked_;
DISALLOW_COPY_AND_ASSIGN(LocaleItem);
};
} // namespace
namespace tray { namespace tray {
LocaleDetailedView::LocaleDetailedView(DetailedViewDelegate* delegate) LocaleDetailedView::LocaleDetailedView(DetailedViewDelegate* delegate)
...@@ -32,16 +126,14 @@ void LocaleDetailedView::CreateItems() { ...@@ -32,16 +126,14 @@ void LocaleDetailedView::CreateItems() {
const bool checked = const bool checked =
entry->iso_code == entry->iso_code ==
Shell::Get()->system_tray_model()->current_locale_iso_code(); Shell::Get()->system_tray_model()->current_locale_iso_code();
HoverHighlightView* item = LocaleItem* item =
AddScrollListCheckableItem(entry->display_name, checked); new LocaleItem(this, entry->iso_code, entry->display_name, checked);
scroll_content()->AddChildView(item);
item->set_id(id); item->set_id(id);
id_to_locale_[id] = entry->iso_code; id_to_locale_[id] = entry->iso_code;
++id; ++id;
} }
scroll_content()->SizeToPreferredSize(); Layout();
scroller()->Layout();
// TODO(wzang): Show locale ISO codes at the beginning of each row, most
// likely by reusing the code in |ImeListItemView|.
} }
void LocaleDetailedView::HandleViewClicked(views::View* view) { void LocaleDetailedView::HandleViewClicked(views::View* view) {
......
...@@ -20,12 +20,12 @@ class LocaleDetailedView : public TrayDetailedView { ...@@ -20,12 +20,12 @@ class LocaleDetailedView : public TrayDetailedView {
explicit LocaleDetailedView(DetailedViewDelegate* delegate); explicit LocaleDetailedView(DetailedViewDelegate* delegate);
~LocaleDetailedView() override; ~LocaleDetailedView() override;
private:
void CreateItems();
// TrayDetailedView: // TrayDetailedView:
void HandleViewClicked(views::View* view) override; void HandleViewClicked(views::View* view) override;
private:
void CreateItems();
// The map between the id of the view and the locale it corresponds to. // The map between the id of the view and the locale it corresponds to.
base::flat_map<int, std::string> id_to_locale_; base::flat_map<int, std::string> id_to_locale_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/unified/feature_pod_button.h" #include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h" #include "ash/system/unified/unified_system_tray_controller.h"
#include "base/i18n/case_conversion.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -33,8 +34,9 @@ FeaturePodButton* LocaleFeaturePodController::CreateButton() { ...@@ -33,8 +34,9 @@ FeaturePodButton* LocaleFeaturePodController::CreateButton() {
button->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALE)); button->SetLabel(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALE));
button->ShowDetailedViewArrow(); button->ShowDetailedViewArrow();
button->DisableLabelButtonFocus(); button->DisableLabelButtonFocus();
button->SetSubLabel(base::UTF8ToUTF16( button->SetSubLabel(
Shell::Get()->system_tray_model()->current_locale_iso_code())); base::i18n::ToUpper(base::UTF8ToUTF16(l10n_util::GetLanguage(
Shell::Get()->system_tray_model()->current_locale_iso_code()))));
} }
return button; return button;
} }
......
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