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/chromeos/tray_caps_lock.h" | 5 #include "ash/system/chromeos/tray_caps_lock.h" |
6 | 6 |
7 #include "ash/common/system/tray/actionable_view.h" | 7 #include "ash/common/system/tray/actionable_view.h" |
8 #include "ash/common/system/tray/fixed_sized_image_view.h" | 8 #include "ash/common/system/tray/fixed_sized_image_view.h" |
9 #include "ash/common/system/tray/system_tray_delegate.h" | 9 #include "ash/common/system/tray/system_tray_delegate.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace ash { | 25 namespace ash { |
26 namespace { | 26 namespace { |
27 | 27 |
28 bool CapsLockIsEnabled() { | 28 bool CapsLockIsEnabled() { |
29 chromeos::input_method::InputMethodManager* ime = | 29 chromeos::input_method::InputMethodManager* ime = |
30 chromeos::input_method::InputMethodManager::Get(); | 30 chromeos::input_method::InputMethodManager::Get(); |
31 return (ime && ime->GetImeKeyboard()) | 31 return (ime && ime->GetImeKeyboard()) |
32 ? ime->GetImeKeyboard()->CapsLockIsEnabled() | 32 ? ime->GetImeKeyboard()->CapsLockIsEnabled() |
33 : false; | 33 : false; |
34 } | 34 } |
35 | |
36 } | 35 } |
37 | 36 |
38 class CapsLockDefaultView : public ActionableView { | 37 class CapsLockDefaultView : public ActionableView { |
39 public: | 38 public: |
40 CapsLockDefaultView() | 39 CapsLockDefaultView() |
41 : text_label_(new views::Label), | 40 : text_label_(new views::Label), shortcut_label_(new views::Label) { |
42 shortcut_label_(new views::Label) { | |
43 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 41 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
44 kTrayPopupPaddingHorizontal, | 42 kTrayPopupPaddingHorizontal, 0, |
45 0, | |
46 kTrayPopupPaddingBetweenItems)); | 43 kTrayPopupPaddingBetweenItems)); |
47 | 44 |
48 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 45 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
49 FixedSizedImageView* image = | 46 FixedSizedImageView* image = |
50 new FixedSizedImageView(0, kTrayPopupItemHeight); | 47 new FixedSizedImageView(0, kTrayPopupItemHeight); |
51 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK). | 48 image->SetImage( |
52 ToImageSkia()); | 49 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).ToImageSkia()); |
53 AddChildView(image); | 50 AddChildView(image); |
54 | 51 |
55 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 52 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
56 AddChildView(text_label_); | 53 AddChildView(text_label_); |
57 | 54 |
58 shortcut_label_->SetEnabled(false); | 55 shortcut_label_->SetEnabled(false); |
59 AddChildView(shortcut_label_); | 56 AddChildView(shortcut_label_); |
60 } | 57 } |
61 | 58 |
62 ~CapsLockDefaultView() override {} | 59 ~CapsLockDefaultView() override {} |
63 | 60 |
64 // Updates the label text and the shortcut text. | 61 // Updates the label text and the shortcut text. |
65 void Update(bool caps_lock_enabled) { | 62 void Update(bool caps_lock_enabled) { |
66 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 63 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
67 const int text_string_id = caps_lock_enabled ? | 64 const int text_string_id = caps_lock_enabled |
68 IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED : | 65 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED |
69 IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED; | 66 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED; |
70 text_label_->SetText(bundle.GetLocalizedString(text_string_id)); | 67 text_label_->SetText(bundle.GetLocalizedString(text_string_id)); |
71 | 68 |
72 int shortcut_string_id = 0; | 69 int shortcut_string_id = 0; |
73 bool search_mapped_to_caps_lock = | 70 bool search_mapped_to_caps_lock = |
74 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock(); | 71 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock(); |
75 if (caps_lock_enabled) { | 72 if (caps_lock_enabled) { |
76 shortcut_string_id = search_mapped_to_caps_lock ? | 73 shortcut_string_id = |
77 IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT : | 74 search_mapped_to_caps_lock |
78 IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT; | 75 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT |
| 76 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT; |
79 } else { | 77 } else { |
80 shortcut_string_id = search_mapped_to_caps_lock ? | 78 shortcut_string_id = |
81 IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH : | 79 search_mapped_to_caps_lock |
82 IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH; | 80 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH |
| 81 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH; |
83 } | 82 } |
84 shortcut_label_->SetText(bundle.GetLocalizedString(shortcut_string_id)); | 83 shortcut_label_->SetText(bundle.GetLocalizedString(shortcut_string_id)); |
85 | 84 |
86 Layout(); | 85 Layout(); |
87 } | 86 } |
88 | 87 |
89 private: | 88 private: |
90 // Overridden from views::View: | 89 // Overridden from views::View: |
91 void Layout() override { | 90 void Layout() override { |
92 views::View::Layout(); | 91 views::View::Layout(); |
93 | 92 |
94 // Align the shortcut text with the right end | 93 // Align the shortcut text with the right end |
95 const int old_x = shortcut_label_->x(); | 94 const int old_x = shortcut_label_->x(); |
96 const int new_x = | 95 const int new_x = |
97 width() - shortcut_label_->width() - kTrayPopupPaddingHorizontal; | 96 width() - shortcut_label_->width() - kTrayPopupPaddingHorizontal; |
98 shortcut_label_->SetX(new_x); | 97 shortcut_label_->SetX(new_x); |
99 const gfx::Size text_size = text_label_->size(); | 98 const gfx::Size text_size = text_label_->size(); |
100 text_label_->SetSize(gfx::Size(text_size.width() + new_x - old_x, | 99 text_label_->SetSize( |
101 text_size.height())); | 100 gfx::Size(text_size.width() + new_x - old_x, text_size.height())); |
102 } | 101 } |
103 | 102 |
104 void GetAccessibleState(ui::AXViewState* state) override { | 103 void GetAccessibleState(ui::AXViewState* state) override { |
105 state->role = ui::AX_ROLE_BUTTON; | 104 state->role = ui::AX_ROLE_BUTTON; |
106 state->name = text_label_->text(); | 105 state->name = text_label_->text(); |
107 } | 106 } |
108 | 107 |
109 // Overridden from ActionableView: | 108 // Overridden from ActionableView: |
110 bool PerformAction(const ui::Event& event) override { | 109 bool PerformAction(const ui::Event& event) override { |
111 chromeos::input_method::ImeKeyboard* keyboard = | 110 chromeos::input_method::ImeKeyboard* keyboard = |
112 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); | 111 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); |
113 if (keyboard) { | 112 if (keyboard) { |
114 WmShell::Get()->RecordUserMetricsAction( | 113 WmShell::Get()->RecordUserMetricsAction( |
115 keyboard->CapsLockIsEnabled() ? | 114 keyboard->CapsLockIsEnabled() |
116 UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK : | 115 ? UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK |
117 UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); | 116 : UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); |
118 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); | 117 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); |
119 } | 118 } |
120 return true; | 119 return true; |
121 } | 120 } |
122 | 121 |
123 views::Label* text_label_; | 122 views::Label* text_label_; |
124 views::Label* shortcut_label_; | 123 views::Label* shortcut_label_; |
125 | 124 |
126 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); | 125 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); |
127 }; | 126 }; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 DCHECK(default_ == NULL); | 176 DCHECK(default_ == NULL); |
178 default_ = new CapsLockDefaultView; | 177 default_ = new CapsLockDefaultView; |
179 default_->Update(caps_lock_enabled_); | 178 default_->Update(caps_lock_enabled_); |
180 return default_; | 179 return default_; |
181 } | 180 } |
182 | 181 |
183 views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) { | 182 views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) { |
184 DCHECK(detailed_ == NULL); | 183 DCHECK(detailed_ == NULL); |
185 detailed_ = new views::View; | 184 detailed_ = new views::View; |
186 | 185 |
187 detailed_->SetLayoutManager(new | 186 detailed_->SetLayoutManager(new views::BoxLayout( |
188 views::BoxLayout(views::BoxLayout::kHorizontal, | 187 views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, 10, |
189 kTrayPopupPaddingHorizontal, 10, kTrayPopupPaddingBetweenItems)); | 188 kTrayPopupPaddingBetweenItems)); |
190 | 189 |
191 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 190 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
192 views::ImageView* image = new views::ImageView; | 191 views::ImageView* image = new views::ImageView; |
193 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK). | 192 image->SetImage( |
194 ToImageSkia()); | 193 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).ToImageSkia()); |
195 | 194 |
196 detailed_->AddChildView(image); | 195 detailed_->AddChildView(image); |
197 | 196 |
198 const int string_id = | 197 const int string_id = |
199 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock() | 198 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock() |
200 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH | 199 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH |
201 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH; | 200 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH; |
202 views::Label* label = new views::Label(bundle.GetLocalizedString(string_id)); | 201 views::Label* label = new views::Label(bundle.GetLocalizedString(string_id)); |
203 label->SetMultiLine(true); | 202 label->SetMultiLine(true); |
204 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 203 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
205 detailed_->AddChildView(label); | 204 detailed_->AddChildView(label); |
206 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED); | 205 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED); |
207 | 206 |
208 return detailed_; | 207 return detailed_; |
209 } | 208 } |
210 | 209 |
211 void TrayCapsLock::DestroyDefaultView() { | 210 void TrayCapsLock::DestroyDefaultView() { |
212 default_ = NULL; | 211 default_ = NULL; |
213 } | 212 } |
214 | 213 |
215 void TrayCapsLock::DestroyDetailedView() { | 214 void TrayCapsLock::DestroyDetailedView() { |
216 detailed_ = NULL; | 215 detailed_ = NULL; |
217 } | 216 } |
218 | 217 |
219 } // namespace ash | 218 } // namespace ash |
OLD | NEW |