15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/tray_caps_lock.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/metrics/user_metrics_recorder.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/actionable_view.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/fixed_sized_image_view.h"
115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_constants.h"
14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/sys_info.h"
15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chromeos/ime/ime_keyboard.h"
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chromeos/ime/input_method_manager.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_resources.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_strings.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/accessibility/ax_view_state.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/image_view.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/label.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/box_layout.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace {
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool CapsLockIsEnabled() {
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  chromeos::input_method::InputMethodManager* ime =
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      chromeos::input_method::InputMethodManager::Get();
33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return (ime && ime->GetImeKeyboard())
34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch             ? ime->GetImeKeyboard()->CapsLockIsEnabled()
35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch             : false;
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CapsLockDefaultView : public ActionableView {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CapsLockDefaultView()
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : text_label_(new views::Label),
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        shortcut_label_(new views::Label) {
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          kTrayPopupPaddingHorizontal,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          0,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          kTrayPopupPaddingBetweenItems));
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FixedSizedImageView* image =
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        new FixedSizedImageView(0, kTrayPopupItemHeight);
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        ToImageSkia());
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddChildView(image);
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddChildView(text_label_);
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    shortcut_label_->SetEnabled(false);
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AddChildView(shortcut_label_);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~CapsLockDefaultView() {}
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Updates the label text and the shortcut text.
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void Update(bool caps_lock_enabled) {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const int text_string_id = caps_lock_enabled ?
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED :
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    text_label_->SetText(bundle.GetLocalizedString(text_string_id));
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    int shortcut_string_id = 0;
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bool search_mapped_to_caps_lock = Shell::GetInstance()->
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        system_tray_delegate()->IsSearchKeyMappedToCapsLock();
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (caps_lock_enabled) {
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      shortcut_string_id = search_mapped_to_caps_lock ?
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT :
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } else {
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      shortcut_string_id = search_mapped_to_caps_lock ?
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH :
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH;
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    shortcut_label_->SetText(bundle.GetLocalizedString(shortcut_string_id));
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Layout();
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from views::View:
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Layout() OVERRIDE {
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    views::View::Layout();
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Align the shortcut text with the right end
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const int old_x = shortcut_label_->x();
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const int new_x =
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        width() - shortcut_label_->width() - kTrayPopupPaddingHorizontal;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    shortcut_label_->SetX(new_x);
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::Size text_size = text_label_->size();
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    text_label_->SetSize(gfx::Size(text_size.width() + new_x - old_x,
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   text_size.height()));
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE {
107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    state->role = ui::AX_ROLE_BUTTON;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    state->name = text_label_->text();
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Overridden from ActionableView:
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool PerformAction(const ui::Event& event) OVERRIDE {
113a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    chromeos::input_method::ImeKeyboard* keyboard =
114a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
115f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    if (keyboard) {
116f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      Shell::GetInstance()->metrics()->RecordUserMetricsAction(
117f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)          keyboard->CapsLockIsEnabled() ?
118f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)          ash::UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK :
119f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)          ash::UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK);
120f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
121f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    }
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Label* text_label_;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Label* shortcut_label_;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView);
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK),
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      default_(NULL),
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      detailed_(NULL),
135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      caps_lock_enabled_(CapsLockIsEnabled()),
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      message_shown_(false) {
137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  chromeos::input_method::InputMethodManager* ime =
138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      chromeos::input_method::InputMethodManager::Get();
139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (ime && ime->GetImeKeyboard())
140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    ime->GetImeKeyboard()->AddObserver(this);
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayCapsLock::~TrayCapsLock() {
144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  chromeos::input_method::InputMethodManager* ime =
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      chromeos::input_method::InputMethodManager::Get();
146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (ime && ime->GetImeKeyboard())
147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    ime->GetImeKeyboard()->RemoveObserver(this);
148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void TrayCapsLock::OnCapsLockChanged(bool enabled) {
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  caps_lock_enabled_ = enabled;
152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
153a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (tray_view())
154a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    tray_view()->SetVisible(caps_lock_enabled_);
155a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
156a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (default_) {
157a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    default_->Update(caps_lock_enabled_);
158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  } else {
159a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    if (caps_lock_enabled_) {
160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      if (!message_shown_) {
161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        Shell::GetInstance()->metrics()->RecordUserMetricsAction(
162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP);
163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        message_shown_ = true;
165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      }
166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    } else if (detailed_) {
167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      detailed_->GetWidget()->Close();
168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool TrayCapsLock::GetInitialVisibility() {
173a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return CapsLockIsEnabled();
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) {
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!caps_lock_enabled_)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return NULL;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(default_ == NULL);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_ = new CapsLockDefaultView;
181a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  default_->Update(caps_lock_enabled_);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return default_;
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayCapsLock::CreateDetailedView(user::LoginStatus status) {
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DCHECK(detailed_ == NULL);
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  detailed_ = new views::View;
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  detailed_->SetLayoutManager(new
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      views::BoxLayout(views::BoxLayout::kHorizontal,
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems));
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::ImageView* image = new views::ImageView;
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      ToImageSkia());
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  detailed_->AddChildView(image);
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
200a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const int string_id = Shell::GetInstance()->system_tray_delegate()->
201a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                            IsSearchKeyMappedToCapsLock() ?
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH :
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH;
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  views::Label* label = new views::Label(bundle.GetLocalizedString(string_id));
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  label->SetMultiLine(true);
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  detailed_->AddChildView(label);
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Shell::GetInstance()->metrics()->RecordUserMetricsAction(
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ash::UMA_STATUS_AREA_CAPS_LOCK_DETAILED);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return detailed_;
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayCapsLock::DestroyDefaultView() {
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  default_ = NULL;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayCapsLock::DestroyDetailedView() {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  detailed_ = NULL;
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
223