Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1970)

Unified Diff: ash/system/ime/tray_ime_chromeos.cc

Issue 843603004: Moves smart deploy UI into the IME tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert accidental edit of a file. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 63%
rename from ash/system/ime/tray_ime.cc
rename to ash/system/ime/tray_ime_chromeos.cc
index 303b4fa0a1fa2b26e65ddb03f65c78d275735bf2..dacdb82fe6c66b2c2da8c854605faf721939004d 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,9 @@ 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,
+ selected ? gfx::Font::BOLD : gfx::Font::NORMAL);
}
~SelectableHoverHighlightView() override {}
@@ -68,56 +72,62 @@ 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 (show_keyboard_toggle) {
+ if (list.size() > 1 || property_list.size() > 1)
+ AddScrollSeparator();
+ AppendKeyboardStatus();
+ }
+
bool userAddingRunning = ash::Shell::GetInstance()
->session_state_delegate()
->IsInSecondaryLoginScreen();
-
if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED &&
!userAddingRunning)
AppendSettings();
@@ -128,13 +138,13 @@ class IMEDetailedView : public TrayDetailsView,
}
private:
- void AppendHeaderEntry() {
- CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this);
- }
+ friend class TrayIMETest;
Mr4D (OOO till 08-26) 2015/01/12 22:35:37 I think this can go...
rsadam 2015/01/13 00:05:34 Done.
+ void AppendHeaderEntry() { CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); }
+
+ // Appends the IMEs to the scrollable area of the detailed view.
void AppendIMEList(const IMEInfoList& list) {
- ime_map_.clear();
- CreateScrollableList();
+ DCHECK(ime_map_.empty());
for (size_t i = 0; i < list.size(); i++) {
HoverHighlightView* container = new SelectableHoverHighlightView(
this, list[i].name, list[i].selected);
@@ -143,8 +153,10 @@ class IMEDetailedView : public TrayDetailsView,
}
}
+ // Appends the IME listed to the scrollable area of the detailed
+ // view.
void AppendIMEProperties(const IMEPropertyInfoList& property_list) {
- property_map_.clear();
+ DCHECK(property_map_.empty());
for (size_t i = 0; i < property_list.size(); i++) {
HoverHighlightView* container = new SelectableHoverHighlightView(
this, property_list[i].name, property_list[i].selected);
@@ -156,13 +168,25 @@ 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/12 22:35:37 And another of this missing parameter line breaks
rsadam 2015/01/13 00:05:34 Oops. Removed.
AddChildView(container);
settings_ = container;
}
@@ -176,6 +200,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()
Mr4D (OOO till 08-26) 2015/01/12 22:35:37 Sorry for the nit, but you should be able to move
rsadam 2015/01/13 00:05:34 I completely missed that, thanks for pointing it o
+ ->virtual_keyboard_controller()
+ ->ToggleIgnoreExternalKeyboard();
} else {
std::map<views::View*, std::string>::const_iterator ime_find;
ime_find = ime_map_.find(sender);
@@ -202,6 +230,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 +241,40 @@ 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()->RemoveAccessibilityObserver(
+ this);
+ Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver(
+ this);
+}
+
+void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) {
+ keyboard_suppressed_ = suppressed;
+ Update();
+}
+
+void TrayIME::OnAccessibilityModeChanged(
+ ui::AccessibilityNotificationVisibility notify) {
+ Update();
+}
+
+void TrayIME::Update() {
+ UpdateTrayLabel(current_ime_, ime_list_.size());
+ if (default_) {
+ default_->SetVisible(ShouldDefaultViewBeVisible());
+ default_->UpdateLabel(GetDefaultViewLabel(ime_list_.size() > 1));
+ }
+ if (detailed_)
+ detailed_->Update(ime_list_, property_list_, ShouldShowKeyboardToggle());
}
void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) {
@@ -228,8 +285,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);
}
@@ -238,33 +295,50 @@ void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) {
}
}
+bool TrayIME::ShouldShowKeyboardToggle() {
+ return keyboard_suppressed_ &&
+ !Shell::GetInstance()
+ ->accessibility_delegate()
+ ->IsVirtualKeyboardEnabled();
+}
+
+base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) {
+ if (show_ime_label) {
+ IMEInfo current;
+ Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(&current);
+ 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::CreateTrayView(user::LoginStatus status) {
CHECK(tray_label_ == NULL);
tray_label_ = new TrayItemView(this);
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_;
}
views::View* TrayIME::CreateDefaultView(user::LoginStatus status) {
- SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
- IMEInfoList list;
- IMEPropertyInfoList property_list;
- delegate->GetAvailableIMEList(&list);
- delegate->GetCurrentIMEProperties(&property_list);
- if (list.size() <= 1 && property_list.size() <= 1)
- return NULL;
CHECK(default_ == NULL);
- default_ = new tray::IMEDefaultView(this);
+ default_ =
+ new tray::IMEDefaultView(this, GetDefaultViewLabel(ime_list_.size() > 1));
+ default_->SetVisible(ShouldDefaultViewBeVisible());
return default_;
}
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_;
}
@@ -289,20 +363,20 @@ void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
}
void TrayIME::OnIMERefresh() {
+ // Caches the current ime state.
SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
- IMEInfoList list;
- IMEInfo current;
- IMEPropertyInfoList property_list;
- delegate->GetCurrentIME(&current);
- delegate->GetAvailableIMEList(&list);
- delegate->GetCurrentIMEProperties(&property_list);
+ ime_list_.clear();
+ property_list_.clear();
+ delegate->GetCurrentIME(&current_ime_);
+ delegate->GetAvailableIMEList(&ime_list_);
+ delegate->GetCurrentIMEProperties(&property_list_);
- UpdateTrayLabel(current, list.size());
+ Update();
+}
- if (default_)
- default_->UpdateLabel(current);
- if (detailed_)
- detailed_->Update(list, property_list);
+bool TrayIME::ShouldDefaultViewBeVisible() {
+ return ime_list_.size() > 1 || property_list_.size() > 1 ||
+ ShouldShowKeyboardToggle();
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698