Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / system / ime / tray_ime.cc
index beec2f5..3bd0296 100644 (file)
@@ -10,7 +10,6 @@
 #include "ash/root_window_controller.h"
 #include "ash/shelf/shelf_widget.h"
 #include "ash/shell.h"
-#include "ash/system/system_notifier.h"
 #include "ash/system/tray/hover_highlight_view.h"
 #include "ash/system/tray/system_tray.h"
 #include "ash/system/tray/system_tray_delegate.h"
 #include "base/strings/utf_string_conversions.h"
 #include "grit/ash_resources.h"
 #include "grit/ash_strings.h"
+#include "ui/accessibility/ax_enums.h"
+#include "ui/accessibility/ax_view_state.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
 #include "ui/gfx/font.h"
 #include "ui/gfx/image/image.h"
-#include "ui/message_center/message_center.h"
-#include "ui/message_center/notification.h"
-#include "ui/message_center/notification_delegate.h"
 #include "ui/views/controls/label.h"
 #include "ui/views/layout/box_layout.h"
 #include "ui/views/widget/widget.h"
 
-using message_center::Notification;
+namespace ash {
+namespace tray {
+
+// A |HoverHighlightView| that uses bold or normal font depending on whetehr
+// it is selected.  This view exposes itself as a checkbox to the accessibility
+// framework.
+class SelectableHoverHighlightView : public HoverHighlightView {
+ public:
+  SelectableHoverHighlightView(ViewClickListener* listener,
+                               const base::string16& label,
+                               bool selected)
+      : HoverHighlightView(listener), selected_(selected) {
+    AddLabel(
+        label, gfx::ALIGN_LEFT, selected ? gfx::Font::BOLD : gfx::Font::NORMAL);
+  }
 
-namespace {
+  virtual ~SelectableHoverHighlightView() {}
 
-const char kIMENotificationId[] = "chrome://settings/ime";
+ protected:
+  // Overridden from views::View.
+  virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE {
+    HoverHighlightView::GetAccessibleState(state);
+    state->role = ui::AX_ROLE_CHECK_BOX;
+    if (selected_)
+      state->AddStateFlag(ui::AX_STATE_CHECKED);
+  }
 
-}  // namespace
+ private:
+  bool selected_;
 
-namespace ash {
-namespace internal {
-namespace tray {
+  DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView);
+};
 
 class IMEDefaultView : public TrayItemMore {
  public:
@@ -112,9 +131,8 @@ class IMEDetailedView : public TrayDetailsView,
     ime_map_.clear();
     CreateScrollableList();
     for (size_t i = 0; i < list.size(); i++) {
-      HoverHighlightView* container = new HoverHighlightView(this);
-      container->AddLabel(list[i].name,
-          list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL);
+      HoverHighlightView* container = new SelectableHoverHighlightView(
+          this, list[i].name, list[i].selected);
       scroll_content()->AddChildView(container);
       ime_map_[container] = list[i].id;
     }
@@ -123,10 +141,8 @@ class IMEDetailedView : public TrayDetailsView,
   void AppendIMEProperties(const IMEPropertyInfoList& property_list) {
     property_map_.clear();
     for (size_t i = 0; i < property_list.size(); i++) {
-      HoverHighlightView* container = new HoverHighlightView(this);
-      container->AddLabel(
-          property_list[i].name,
-          property_list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL);
+      HoverHighlightView* container = new SelectableHoverHighlightView(
+          this, property_list[i].name, property_list[i].selected);
       if (i == 0)
         container->SetBorder(views::Border::CreateSolidSidedBorder(
             1, 0, 0, 0, kBorderLightColor));
@@ -137,8 +153,10 @@ class IMEDetailedView : public TrayDetailsView,
 
   void AppendSettings() {
     HoverHighlightView* container = new HoverHighlightView(this);
-    container->AddLabel(ui::ResourceBundle::GetSharedInstance().
-        GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS),
+    container->AddLabel(
+        ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
+            IDS_ASH_STATUS_TRAY_IME_SETTINGS),
+        gfx::ALIGN_LEFT,
         gfx::Font::NORMAL);
     AddChildView(container);
     settings_ = container;
@@ -189,16 +207,12 @@ TrayIME::TrayIME(SystemTray* system_tray)
     : SystemTrayItem(system_tray),
       tray_label_(NULL),
       default_(NULL),
-      detailed_(NULL),
-      message_shown_(false),
-      weak_factory_(this) {
+      detailed_(NULL) {
   Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this);
 }
 
 TrayIME::~TrayIME() {
   Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this);
-  message_center::MessageCenter::Get()->RemoveNotification(
-      kIMENotificationId, false /* by_user */);
 }
 
 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) {
@@ -219,40 +233,6 @@ void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) {
   }
 }
 
-void TrayIME::UpdateOrCreateNotification() {
-  message_center::MessageCenter* message_center =
-      message_center::MessageCenter::Get();
-
-  if (!message_center->HasNotification(kIMENotificationId) && message_shown_)
-    return;
-
-  SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
-  IMEInfo current;
-  delegate->GetCurrentIME(&current);
-
-  ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
-  scoped_ptr<Notification> notification(new Notification(
-      message_center::NOTIFICATION_TYPE_SIMPLE,
-      kIMENotificationId,
-      // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE
-      // for third party IMEs
-      l10n_util::GetStringFUTF16(
-          IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE,
-          current.medium_name),
-      base::string16(),  // message
-      bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME),
-      base::string16(),  // display_source
-      message_center::NotifierId(
-          message_center::NotifierId::SYSTEM_COMPONENT,
-          system_notifier::kNotifierInputMethod),
-      message_center::RichNotificationData(),
-      new message_center::HandleNotificationClickedDelegate(
-          base::Bind(&TrayIME::PopupDetailedView,
-                     weak_factory_.GetWeakPtr(), 0, true))));
-  message_center->AddNotification(notification.Pass());
-  message_shown_ = true;
-}
-
 views::View* TrayIME::CreateTrayView(user::LoginStatus status) {
   CHECK(tray_label_ == NULL);
   tray_label_ = new TrayItemView(this);
@@ -303,7 +283,7 @@ void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
   tray_label_->Layout();
 }
 
-void TrayIME::OnIMERefresh(bool show_message) {
+void TrayIME::OnIMERefresh() {
   SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
   IMEInfoList list;
   IMEInfo current;
@@ -318,10 +298,6 @@ void TrayIME::OnIMERefresh(bool show_message) {
     default_->UpdateLabel(current);
   if (detailed_)
     detailed_->Update(list, property_list);
-
-  if (list.size() > 1 && show_message)
-    UpdateOrCreateNotification();
 }
 
-}  // namespace internal
 }  // namespace ash