| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/ime/tray_ime.h" | 5 #include "ash/system/ime/tray_ime.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/metrics/user_metrics_recorder.h" | 9 #include "ash/metrics/user_metrics_recorder.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/system/system_notifier.h" | |
| 14 #include "ash/system/tray/hover_highlight_view.h" | 13 #include "ash/system/tray/hover_highlight_view.h" |
| 15 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
| 17 #include "ash/system/tray/system_tray_notifier.h" | 16 #include "ash/system/tray/system_tray_notifier.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_details_view.h" | 18 #include "ash/system/tray/tray_details_view.h" |
| 20 #include "ash/system/tray/tray_item_more.h" | 19 #include "ash/system/tray/tray_item_more.h" |
| 21 #include "ash/system/tray/tray_item_view.h" | 20 #include "ash/system/tray/tray_item_view.h" |
| 22 #include "ash/system/tray/tray_utils.h" | 21 #include "ash/system/tray/tray_utils.h" |
| 23 #include "base/logging.h" | 22 #include "base/logging.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 25 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
| 26 #include "grit/ash_strings.h" | 25 #include "grit/ash_strings.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/font.h" | 28 #include "ui/gfx/font.h" |
| 30 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 31 #include "ui/message_center/message_center.h" | |
| 32 #include "ui/message_center/notification.h" | |
| 33 #include "ui/message_center/notification_delegate.h" | |
| 34 #include "ui/views/controls/label.h" | 30 #include "ui/views/controls/label.h" |
| 35 #include "ui/views/layout/box_layout.h" | 31 #include "ui/views/layout/box_layout.h" |
| 36 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| 37 | 33 |
| 38 using message_center::Notification; | |
| 39 | |
| 40 namespace { | |
| 41 | |
| 42 const char kIMENotificationId[] = "chrome://settings/ime"; | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 namespace ash { | 34 namespace ash { |
| 47 namespace internal { | 35 namespace internal { |
| 48 namespace tray { | 36 namespace tray { |
| 49 | 37 |
| 50 class IMEDefaultView : public TrayItemMore { | 38 class IMEDefaultView : public TrayItemMore { |
| 51 public: | 39 public: |
| 52 explicit IMEDefaultView(SystemTrayItem* owner) | 40 explicit IMEDefaultView(SystemTrayItem* owner) |
| 53 : TrayItemMore(owner, true) { | 41 : TrayItemMore(owner, true) { |
| 54 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 55 | 43 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 170 |
| 183 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 171 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
| 184 }; | 172 }; |
| 185 | 173 |
| 186 } // namespace tray | 174 } // namespace tray |
| 187 | 175 |
| 188 TrayIME::TrayIME(SystemTray* system_tray) | 176 TrayIME::TrayIME(SystemTray* system_tray) |
| 189 : SystemTrayItem(system_tray), | 177 : SystemTrayItem(system_tray), |
| 190 tray_label_(NULL), | 178 tray_label_(NULL), |
| 191 default_(NULL), | 179 default_(NULL), |
| 192 detailed_(NULL), | 180 detailed_(NULL) { |
| 193 message_shown_(false), | |
| 194 weak_factory_(this) { | |
| 195 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); | 181 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); |
| 196 } | 182 } |
| 197 | 183 |
| 198 TrayIME::~TrayIME() { | 184 TrayIME::~TrayIME() { |
| 199 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); | 185 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); |
| 200 message_center::MessageCenter::Get()->RemoveNotification( | |
| 201 kIMENotificationId, false /* by_user */); | |
| 202 } | 186 } |
| 203 | 187 |
| 204 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 188 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| 205 if (tray_label_) { | 189 if (tray_label_) { |
| 206 bool visible = count > 1; | 190 bool visible = count > 1; |
| 207 tray_label_->SetVisible(visible); | 191 tray_label_->SetVisible(visible); |
| 208 // Do not change label before hiding because this change is noticeable. | 192 // Do not change label before hiding because this change is noticeable. |
| 209 if (!visible) | 193 if (!visible) |
| 210 return; | 194 return; |
| 211 if (current.third_party) { | 195 if (current.third_party) { |
| 212 tray_label_->label()->SetText( | 196 tray_label_->label()->SetText( |
| 213 current.short_name + base::UTF8ToUTF16("*")); | 197 current.short_name + base::UTF8ToUTF16("*")); |
| 214 } else { | 198 } else { |
| 215 tray_label_->label()->SetText(current.short_name); | 199 tray_label_->label()->SetText(current.short_name); |
| 216 } | 200 } |
| 217 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); | 201 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); |
| 218 tray_label_->Layout(); | 202 tray_label_->Layout(); |
| 219 } | 203 } |
| 220 } | 204 } |
| 221 | 205 |
| 222 void TrayIME::UpdateOrCreateNotification() { | |
| 223 message_center::MessageCenter* message_center = | |
| 224 message_center::MessageCenter::Get(); | |
| 225 | |
| 226 if (!message_center->HasNotification(kIMENotificationId) && message_shown_) | |
| 227 return; | |
| 228 | |
| 229 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | |
| 230 IMEInfo current; | |
| 231 delegate->GetCurrentIME(¤t); | |
| 232 | |
| 233 ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 234 scoped_ptr<Notification> notification(new Notification( | |
| 235 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 236 kIMENotificationId, | |
| 237 // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE | |
| 238 // for third party IMEs | |
| 239 l10n_util::GetStringFUTF16( | |
| 240 IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, | |
| 241 current.medium_name), | |
| 242 base::string16(), // message | |
| 243 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME), | |
| 244 base::string16(), // display_source | |
| 245 message_center::NotifierId( | |
| 246 message_center::NotifierId::SYSTEM_COMPONENT, | |
| 247 system_notifier::kNotifierInputMethod), | |
| 248 message_center::RichNotificationData(), | |
| 249 new message_center::HandleNotificationClickedDelegate( | |
| 250 base::Bind(&TrayIME::PopupDetailedView, | |
| 251 weak_factory_.GetWeakPtr(), 0, true)))); | |
| 252 message_center->AddNotification(notification.Pass()); | |
| 253 message_shown_ = true; | |
| 254 } | |
| 255 | |
| 256 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 206 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
| 257 CHECK(tray_label_ == NULL); | 207 CHECK(tray_label_ == NULL); |
| 258 tray_label_ = new TrayItemView(this); | 208 tray_label_ = new TrayItemView(this); |
| 259 tray_label_->CreateLabel(); | 209 tray_label_->CreateLabel(); |
| 260 SetupLabelForTray(tray_label_->label()); | 210 SetupLabelForTray(tray_label_->label()); |
| 261 // Hide IME tray when it is created, it will be updated when it is notified | 211 // Hide IME tray when it is created, it will be updated when it is notified |
| 262 // for IME refresh event. | 212 // for IME refresh event. |
| 263 tray_label_->SetVisible(false); | 213 tray_label_->SetVisible(false); |
| 264 return tray_label_; | 214 return tray_label_; |
| 265 } | 215 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 296 } | 246 } |
| 297 | 247 |
| 298 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 248 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 299 } | 249 } |
| 300 | 250 |
| 301 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 251 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 302 SetTrayLabelItemBorder(tray_label_, alignment); | 252 SetTrayLabelItemBorder(tray_label_, alignment); |
| 303 tray_label_->Layout(); | 253 tray_label_->Layout(); |
| 304 } | 254 } |
| 305 | 255 |
| 306 void TrayIME::OnIMERefresh(bool show_message) { | 256 void TrayIME::OnIMERefresh() { |
| 307 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 257 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 308 IMEInfoList list; | 258 IMEInfoList list; |
| 309 IMEInfo current; | 259 IMEInfo current; |
| 310 IMEPropertyInfoList property_list; | 260 IMEPropertyInfoList property_list; |
| 311 delegate->GetCurrentIME(¤t); | 261 delegate->GetCurrentIME(¤t); |
| 312 delegate->GetAvailableIMEList(&list); | 262 delegate->GetAvailableIMEList(&list); |
| 313 delegate->GetCurrentIMEProperties(&property_list); | 263 delegate->GetCurrentIMEProperties(&property_list); |
| 314 | 264 |
| 315 UpdateTrayLabel(current, list.size()); | 265 UpdateTrayLabel(current, list.size()); |
| 316 | 266 |
| 317 if (default_) | 267 if (default_) |
| 318 default_->UpdateLabel(current); | 268 default_->UpdateLabel(current); |
| 319 if (detailed_) | 269 if (detailed_) |
| 320 detailed_->Update(list, property_list); | 270 detailed_->Update(list, property_list); |
| 321 | |
| 322 if (list.size() > 1 && show_message) | |
| 323 UpdateOrCreateNotification(); | |
| 324 } | 271 } |
| 325 | 272 |
| 326 } // namespace internal | 273 } // namespace internal |
| 327 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |