Chromium Code Reviews| Index: ash/system/ime/tray_ime_chromeos.cc |
| diff --git a/ash/system/ime/tray_ime.cc b/ash/system/ime/tray_ime_chromeos.cc |
| similarity index 67% |
| rename from ash/system/ime/tray_ime.cc |
| rename to ash/system/ime/tray_ime_chromeos.cc |
| index 303b4fa0a1fa2b26e65ddb03f65c78d275735bf2..2ae2e15de3412d9de0571e5d6764866ba1932959 100644 |
| --- a/ash/system/ime/tray_ime.cc |
| +++ b/ash/system/ime/tray_ime_chromeos.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "ash/system/ime/tray_ime.h" |
| +#include "ash/system/ime/tray_ime_chromeos.h" |
| #include <vector> |
| @@ -20,6 +20,8 @@ |
| #include "ash/system/tray/tray_item_more.h" |
| #include "ash/system/tray/tray_item_view.h" |
| #include "ash/system/tray/tray_utils.h" |
| +#include "ash/system/tray_accessibility.h" |
| +#include "ash/virtual_keyboard_controller.h" |
| #include "base/logging.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "grit/ash_resources.h" |
| @@ -29,6 +31,7 @@ |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/font.h" |
| #include "ui/gfx/image/image.h" |
| +#include "ui/keyboard/keyboard_util.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/layout/box_layout.h" |
| #include "ui/views/widget/widget.h" |
| @@ -36,7 +39,7 @@ |
| namespace ash { |
| namespace tray { |
| -// A |HoverHighlightView| that uses bold or normal font depending on whetehr |
| +// A |HoverHighlightView| that uses bold or normal font depending on whether |
| // it is selected. This view exposes itself as a checkbox to the accessibility |
| // framework. |
| class SelectableHoverHighlightView : public HoverHighlightView { |
| @@ -45,8 +48,8 @@ class SelectableHoverHighlightView : public HoverHighlightView { |
| const base::string16& label, |
| bool selected) |
| : HoverHighlightView(listener), selected_(selected) { |
| - AddLabel( |
| - label, gfx::ALIGN_LEFT, selected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
| + AddLabel(label, gfx::ALIGN_LEFT, |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
According to style guide each parameter needs to g
rsadam
2015/01/09 23:45:07
Weird, git cl format changes it to the wrong thing
Mr4D (OOO till 08-26)
2015/01/10 00:42:09
Hmm. interesting - let me know how that goes!
(I
|
| + selected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
| } |
| ~SelectableHoverHighlightView() override {} |
| @@ -68,55 +71,59 @@ class SelectableHoverHighlightView : public HoverHighlightView { |
| class IMEDefaultView : public TrayItemMore { |
| public: |
| - explicit IMEDefaultView(SystemTrayItem* owner) |
| + explicit IMEDefaultView(SystemTrayItem* owner, const base::string16& label) |
| : TrayItemMore(owner, true) { |
| ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| - |
| - SetImage(bundle.GetImageNamed( |
| - IDR_AURA_UBER_TRAY_IME).ToImageSkia()); |
| - |
| - IMEInfo info; |
| - Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(&info); |
| - UpdateLabel(info); |
| + SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME).ToImageSkia()); |
| + UpdateLabel(label); |
| } |
| ~IMEDefaultView() override {} |
| - void UpdateLabel(const IMEInfo& info) { |
| - SetLabel(info.name); |
| - SetAccessibleName(info.name); |
| + void UpdateLabel(const base::string16& label) { |
| + SetLabel(label); |
| + SetAccessibleName(label); |
| } |
| private: |
| DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
| }; |
| -class IMEDetailedView : public TrayDetailsView, |
| - public ViewClickListener { |
| +class IMEDetailedView : public TrayDetailsView, public ViewClickListener { |
| public: |
| - IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) |
| - : TrayDetailsView(owner), |
| - login_(login) { |
| + IMEDetailedView(SystemTrayItem* owner, |
| + user::LoginStatus login, |
| + bool show_keyboard_toggle) |
| + : TrayDetailsView(owner), login_(login) { |
| SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| IMEInfoList list; |
| delegate->GetAvailableIMEList(&list); |
| IMEPropertyInfoList property_list; |
| delegate->GetCurrentIMEProperties(&property_list); |
| - Update(list, property_list); |
| + Update(list, property_list, show_keyboard_toggle); |
| } |
| ~IMEDetailedView() override {} |
| void Update(const IMEInfoList& list, |
| - const IMEPropertyInfoList& property_list) { |
| + const IMEPropertyInfoList& property_list, |
| + bool show_keyboard_toggle) { |
| Reset(); |
| + ime_map_.clear(); |
| + property_map_.clear(); |
| + CreateScrollableList(); |
| - AppendIMEList(list); |
| - if (!property_list.empty()) |
| + if (list.size() > 1) |
| + AppendIMEList(list); |
| + if (property_list.size() > 1) |
| AppendIMEProperties(property_list); |
| + if (list.size() > 1 || property_list.size() > 1) |
| + AddScrollSeparator(); |
| bool userAddingRunning = ash::Shell::GetInstance() |
| ->session_state_delegate() |
| ->IsInSecondaryLoginScreen(); |
| + if (show_keyboard_toggle) |
| + AppendKeyboardStatus(); |
| if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED && |
| !userAddingRunning) |
| @@ -128,13 +135,9 @@ class IMEDetailedView : public TrayDetailsView, |
| } |
| private: |
| - void AppendHeaderEntry() { |
| - CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); |
| - } |
| + void AppendHeaderEntry() { CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); } |
| void AppendIMEList(const IMEInfoList& list) { |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
I am not sure that this is correct. Isn't it conce
rsadam
2015/01/09 23:45:07
I'm not sure I follow. AppendIMEList is only ever
Mr4D (OOO till 08-26)
2015/01/10 00:42:10
Ah. I haven't seen that you have cleared the maps
|
| - ime_map_.clear(); |
| - CreateScrollableList(); |
| for (size_t i = 0; i < list.size(); i++) { |
| HoverHighlightView* container = new SelectableHoverHighlightView( |
| this, list[i].name, list[i].selected); |
| @@ -144,7 +147,6 @@ class IMEDetailedView : public TrayDetailsView, |
| } |
| void AppendIMEProperties(const IMEPropertyInfoList& property_list) { |
| - property_map_.clear(); |
| for (size_t i = 0; i < property_list.size(); i++) { |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
Same here. Shouldn't you check if the property doe
rsadam
2015/01/09 23:45:07
Same as above, I think the confusion might be in t
Mr4D (OOO till 08-26)
2015/01/10 00:42:09
Same reasoning. Yes, in the moment this is correct
|
| HoverHighlightView* container = new SelectableHoverHighlightView( |
| this, property_list[i].name, property_list[i].selected); |
| @@ -156,13 +158,24 @@ class IMEDetailedView : public TrayDetailsView, |
| } |
| } |
| + void AppendKeyboardStatus() { |
| + HoverHighlightView* container = new HoverHighlightView(this); |
| + int id = keyboard::IsKeyboardEnabled() |
| + ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD |
| + : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; |
| + container->AddLabel( |
| + ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), |
| + gfx::ALIGN_LEFT, gfx::Font::NORMAL); |
| + scroll_content()->AddChildView(container); |
| + keyboard_status_ = container; |
| + } |
| + |
| void AppendSettings() { |
| HoverHighlightView* container = new HoverHighlightView(this); |
| container->AddLabel( |
| ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| IDS_ASH_STATUS_TRAY_IME_SETTINGS), |
| - gfx::ALIGN_LEFT, |
| - gfx::Font::NORMAL); |
| + gfx::ALIGN_LEFT, gfx::Font::NORMAL); |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
As before: According to style guide: either all pa
rsadam
2015/01/09 23:45:07
Seems git cl format borked here as well. Manually
|
| AddChildView(container); |
| settings_ = container; |
| } |
| @@ -176,6 +189,10 @@ class IMEDetailedView : public TrayDetailsView, |
| Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); |
| delegate->ShowIMESettings(); |
| + } else if (sender == keyboard_status_) { |
| + Shell::GetInstance() |
| + ->virtual_keyboard_controller() |
| + ->ToggleIgnoreExternalKeyboard(); |
| } else { |
| std::map<views::View*, std::string>::const_iterator ime_find; |
| ime_find = ime_map_.find(sender); |
| @@ -202,6 +219,7 @@ class IMEDetailedView : public TrayDetailsView, |
| std::map<views::View*, std::string> ime_map_; |
| std::map<views::View*, std::string> property_map_; |
| views::View* settings_; |
| + views::View* keyboard_status_; |
| DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
| }; |
| @@ -212,12 +230,20 @@ TrayIME::TrayIME(SystemTray* system_tray) |
| : SystemTrayItem(system_tray), |
| tray_label_(NULL), |
| default_(NULL), |
| - detailed_(NULL) { |
| + detailed_(NULL), |
| + keyboard_suppressed_(false) { |
| Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); |
| + Shell::GetInstance()->system_tray_notifier()->AddVirtualKeyboardObserver( |
| + this); |
| + Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); |
| } |
| TrayIME::~TrayIME() { |
| Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); |
| + Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver( |
| + this); |
| + Shell::GetInstance()->system_tray_notifier()->RemoveAccessibilityObserver( |
| + this); |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
I know it does not make a difference - but could y
rsadam
2015/01/09 23:45:07
Done.
|
| } |
| void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| @@ -228,8 +254,8 @@ void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| if (!visible) |
| return; |
| if (current.third_party) { |
| - tray_label_->label()->SetText( |
| - current.short_name + base::UTF8ToUTF16("*")); |
| + tray_label_->label()->SetText(current.short_name + |
| + base::UTF8ToUTF16("*")); |
| } else { |
| tray_label_->label()->SetText(current.short_name); |
| } |
| @@ -244,7 +270,7 @@ views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
| tray_label_->CreateLabel(); |
| SetupLabelForTray(tray_label_->label()); |
| // Hide IME tray when it is created, it will be updated when it is notified |
| - // for IME refresh event. |
| + // of the IME refresh event. |
| tray_label_->SetVisible(false); |
| return tray_label_; |
| } |
| @@ -255,16 +281,36 @@ views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
| IMEPropertyInfoList property_list; |
| delegate->GetAvailableIMEList(&list); |
| delegate->GetCurrentIMEProperties(&property_list); |
| - if (list.size() <= 1 && property_list.size() <= 1) |
| + // Do not show the menu if there are no options to choose between. |
| + if (list.size() <= 1 && property_list.size() <= 1 && |
| + !ShouldShowKeyboardToggle()) { |
| return NULL; |
| + } |
| CHECK(default_ == NULL); |
| - default_ = new tray::IMEDefaultView(this); |
| + |
| + default_ = |
| + new tray::IMEDefaultView(this, GetDefaultViewLabel(list.size() > 1)); |
| return default_; |
| } |
| +base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) { |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
The order of the functions in the c++ file should
rsadam
2015/01/09 23:45:07
Done.
|
| + if (show_ime_label) { |
| + IMEInfo current; |
| + Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(¤t); |
| + return current.name; |
| + } else { |
| + // Display virtual keyboard status instead. |
| + int id = keyboard::IsKeyboardEnabled() |
| + ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED |
| + : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED; |
| + return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id); |
| + } |
| +} |
| + |
| views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { |
| CHECK(detailed_ == NULL); |
| - detailed_ = new tray::IMEDetailedView(this, status); |
| + detailed_ = |
| + new tray::IMEDetailedView(this, status, ShouldShowKeyboardToggle()); |
| return detailed_; |
| } |
| @@ -288,7 +334,26 @@ void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| tray_label_->Layout(); |
| } |
| -void TrayIME::OnIMERefresh() { |
| +void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) { |
| + keyboard_suppressed_ = suppressed; |
| + // Immediately update state if the window is currently opened. |
| + if (default_ || detailed_) |
| + Update(); |
| +} |
| + |
| +bool TrayIME::ShouldShowKeyboardToggle() { |
| + return keyboard_suppressed_ && |
| + !Shell::GetInstance() |
| + ->accessibility_delegate() |
| + ->IsVirtualKeyboardEnabled(); |
| +} |
| + |
| +void TrayIME::OnAccessibilityModeChanged( |
| + ui::AccessibilityNotificationVisibility notify) { |
| + Update(); |
| +} |
| + |
| +void TrayIME::Update() { |
| SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| IMEInfoList list; |
| IMEInfo current; |
| @@ -298,11 +363,14 @@ void TrayIME::OnIMERefresh() { |
| delegate->GetCurrentIMEProperties(&property_list); |
| UpdateTrayLabel(current, list.size()); |
| - |
| if (default_) |
| - default_->UpdateLabel(current); |
| + default_->UpdateLabel(GetDefaultViewLabel(list.size() > 1)); |
| if (detailed_) |
| - detailed_->Update(list, property_list); |
| + detailed_->Update(list, property_list, ShouldShowKeyboardToggle()); |
| +} |
| + |
| +void TrayIME::OnIMERefresh() { |
| + Update(); |
| } |
| } // namespace ash |