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/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); | 60 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
61 }; | 61 }; |
62 | 62 |
63 class IMEDetailedView : public TrayDetailsView, | 63 class IMEDetailedView : public TrayDetailsView, |
64 public ViewClickListener { | 64 public ViewClickListener { |
65 public: | 65 public: |
66 IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) | 66 IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) |
67 : login_(login) { | 67 : TrayDetailsView(owner), |
| 68 login_(login) { |
68 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 69 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
69 IMEInfoList list; | 70 IMEInfoList list; |
70 delegate->GetAvailableIMEList(&list); | 71 delegate->GetAvailableIMEList(&list); |
71 IMEPropertyInfoList property_list; | 72 IMEPropertyInfoList property_list; |
72 delegate->GetCurrentIMEProperties(&property_list); | 73 delegate->GetCurrentIMEProperties(&property_list); |
73 Update(list, property_list); | 74 Update(list, property_list); |
74 } | 75 } |
75 | 76 |
76 virtual ~IMEDetailedView() {} | 77 virtual ~IMEDetailedView() {} |
77 | 78 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS), | 132 GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS), |
132 gfx::Font::NORMAL); | 133 gfx::Font::NORMAL); |
133 AddChildView(container); | 134 AddChildView(container); |
134 settings_ = container; | 135 settings_ = container; |
135 } | 136 } |
136 | 137 |
137 // Overridden from ViewClickListener. | 138 // Overridden from ViewClickListener. |
138 virtual void ClickedOn(views::View* sender) OVERRIDE { | 139 virtual void ClickedOn(views::View* sender) OVERRIDE { |
139 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 140 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
140 if (sender == footer()->content()) { | 141 if (sender == footer()->content()) { |
141 Shell::GetInstance()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 142 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
142 } else if (sender == settings_) { | 143 } else if (sender == settings_) { |
143 delegate->ShowIMESettings(); | 144 delegate->ShowIMESettings(); |
144 } else { | 145 } else { |
145 std::map<views::View*, std::string>::const_iterator ime_find; | 146 std::map<views::View*, std::string>::const_iterator ime_find; |
146 ime_find = ime_map_.find(sender); | 147 ime_find = ime_map_.find(sender); |
147 if (ime_find != ime_map_.end()) { | 148 if (ime_find != ime_map_.end()) { |
148 std::string ime_id = ime_find->second; | 149 std::string ime_id = ime_find->second; |
149 delegate->SwitchIME(ime_id); | 150 delegate->SwitchIME(ime_id); |
150 GetWidget()->Close(); | 151 GetWidget()->Close(); |
151 } else { | 152 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
164 | 165 |
165 std::map<views::View*, std::string> ime_map_; | 166 std::map<views::View*, std::string> ime_map_; |
166 std::map<views::View*, std::string> property_map_; | 167 std::map<views::View*, std::string> property_map_; |
167 views::View* settings_; | 168 views::View* settings_; |
168 | 169 |
169 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 170 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
170 }; | 171 }; |
171 | 172 |
172 class IMENotificationView : public TrayNotificationView { | 173 class IMENotificationView : public TrayNotificationView { |
173 public: | 174 public: |
174 explicit IMENotificationView(TrayIME* tray) | 175 explicit IMENotificationView(TrayIME* owner) |
175 : TrayNotificationView(tray, IDR_AURA_UBER_TRAY_IME) { | 176 : TrayNotificationView(owner, IDR_AURA_UBER_TRAY_IME) { |
176 InitView(GetLabel()); | 177 InitView(GetLabel()); |
177 } | 178 } |
178 | 179 |
179 void UpdateLabel() { | 180 void UpdateLabel() { |
180 RestartAutoCloseTimer(); | 181 RestartAutoCloseTimer(); |
181 UpdateView(GetLabel()); | 182 UpdateView(GetLabel()); |
182 } | 183 } |
183 | 184 |
184 void StartAutoCloseTimer(int seconds) { | 185 void StartAutoCloseTimer(int seconds) { |
185 autoclose_.Stop(); | 186 autoclose_.Stop(); |
186 autoclose_delay_ = seconds; | 187 autoclose_delay_ = seconds; |
187 if (autoclose_delay_) { | 188 if (autoclose_delay_) { |
188 autoclose_.Start(FROM_HERE, | 189 autoclose_.Start(FROM_HERE, |
189 base::TimeDelta::FromSeconds(autoclose_delay_), | 190 base::TimeDelta::FromSeconds(autoclose_delay_), |
190 this, &IMENotificationView::Close); | 191 this, &IMENotificationView::Close); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 void StopAutoCloseTimer() { | 195 void StopAutoCloseTimer() { |
195 autoclose_.Stop(); | 196 autoclose_.Stop(); |
196 } | 197 } |
197 | 198 |
198 void RestartAutoCloseTimer() { | 199 void RestartAutoCloseTimer() { |
199 if (autoclose_delay_) | 200 if (autoclose_delay_) |
200 StartAutoCloseTimer(autoclose_delay_); | 201 StartAutoCloseTimer(autoclose_delay_); |
201 } | 202 } |
202 | 203 |
203 // Overridden from TrayNotificationView. | 204 // Overridden from TrayNotificationView. |
204 virtual void OnClickAction() OVERRIDE { | 205 virtual void OnClickAction() OVERRIDE { |
205 tray()->PopupDetailedView(0, true); | 206 owner()->PopupDetailedView(0, true); |
206 } | 207 } |
207 | 208 |
208 private: | 209 private: |
209 void Close() { | 210 void Close() { |
210 tray()->HideNotificationView(); | 211 owner()->HideNotificationView(); |
211 } | 212 } |
212 | 213 |
213 views::Label* GetLabel() { | 214 views::Label* GetLabel() { |
214 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 215 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
215 IMEInfo current; | 216 IMEInfo current; |
216 delegate->GetCurrentIME(¤t); | 217 delegate->GetCurrentIME(¤t); |
217 | 218 |
218 // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE for | 219 // TODO(zork): Use IDS_ASH_STATUS_TRAY_THIRD_PARTY_IME_TURNED_ON_BUBBLE for |
219 // third party IMEs | 220 // third party IMEs |
220 views::Label* label = new views::Label( | 221 views::Label* label = new views::Label( |
221 l10n_util::GetStringFUTF16( | 222 l10n_util::GetStringFUTF16( |
222 IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, | 223 IDS_ASH_STATUS_TRAY_IME_TURNED_ON_BUBBLE, |
223 current.medium_name)); | 224 current.medium_name)); |
224 label->SetMultiLine(true); | 225 label->SetMultiLine(true); |
225 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 226 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
226 return label; | 227 return label; |
227 } | 228 } |
228 | 229 |
229 | 230 |
230 int autoclose_delay_; | 231 int autoclose_delay_; |
231 base::OneShotTimer<IMENotificationView> autoclose_; | 232 base::OneShotTimer<IMENotificationView> autoclose_; |
232 | 233 |
233 DISALLOW_COPY_AND_ASSIGN(IMENotificationView); | 234 DISALLOW_COPY_AND_ASSIGN(IMENotificationView); |
234 }; | 235 }; |
235 | 236 |
236 | 237 |
237 } // namespace tray | 238 } // namespace tray |
238 | 239 |
239 TrayIME::TrayIME() | 240 TrayIME::TrayIME(SystemTray* system_tray) |
240 : tray_label_(NULL), | 241 : SystemTrayItem(system_tray), |
| 242 tray_label_(NULL), |
241 default_(NULL), | 243 default_(NULL), |
242 detailed_(NULL), | 244 detailed_(NULL), |
243 notification_(NULL), | 245 notification_(NULL), |
244 message_shown_(false) { | 246 message_shown_(false) { |
245 } | 247 } |
246 | 248 |
247 TrayIME::~TrayIME() { | 249 TrayIME::~TrayIME() { |
248 } | 250 } |
249 | 251 |
250 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 252 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
251 if (tray_label_) { | 253 if (tray_label_) { |
252 if (current.third_party) { | 254 if (current.third_party) { |
253 tray_label_->label()->SetText(current.short_name + UTF8ToUTF16("*")); | 255 tray_label_->label()->SetText(current.short_name + UTF8ToUTF16("*")); |
254 } else { | 256 } else { |
255 tray_label_->label()->SetText(current.short_name); | 257 tray_label_->label()->SetText(current.short_name); |
256 } | 258 } |
257 tray_label_->SetVisible(count > 1); | 259 tray_label_->SetVisible(count > 1); |
258 SetTrayLabelItemBorder(tray_label_, | 260 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); |
259 ash::Shell::GetInstance()->system_tray()->shelf_alignment()); | |
260 tray_label_->Layout(); | 261 tray_label_->Layout(); |
261 } | 262 } |
262 } | 263 } |
263 | 264 |
264 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 265 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
265 CHECK(tray_label_ == NULL); | 266 CHECK(tray_label_ == NULL); |
266 tray_label_ = new TrayItemView; | 267 tray_label_ = new TrayItemView(this); |
267 tray_label_->CreateLabel(); | 268 tray_label_->CreateLabel(); |
268 SetupLabelForTray(tray_label_->label()); | 269 SetupLabelForTray(tray_label_->label()); |
269 return tray_label_; | 270 return tray_label_; |
270 } | 271 } |
271 | 272 |
272 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { | 273 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
273 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 274 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
274 IMEInfoList list; | 275 IMEInfoList list; |
275 IMEPropertyInfoList property_list; | 276 IMEPropertyInfoList property_list; |
276 delegate->GetAvailableIMEList(&list); | 277 delegate->GetAvailableIMEList(&list); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 } else if (!Shell::GetPrimaryRootWindowController()->shelf()->IsVisible() || | 343 } else if (!Shell::GetPrimaryRootWindowController()->shelf()->IsVisible() || |
343 !message_shown_) { | 344 !message_shown_) { |
344 ShowNotificationView(); | 345 ShowNotificationView(); |
345 message_shown_ = true; | 346 message_shown_ = true; |
346 } | 347 } |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 } // namespace internal | 351 } // namespace internal |
351 } // namespace ash | 352 } // namespace ash |
OLD | NEW |