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/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
11 #include "ash/system/tray/system_tray_delegate.h" | 11 #include "ash/system/tray/system_tray_delegate.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/system/tray/tray_item_more.h" | 13 #include "ash/system/tray/tray_item_more.h" |
14 #include "ash/system/tray/tray_item_view.h" | 14 #include "ash/system/tray/tray_item_view.h" |
15 #include "ash/system/tray/tray_views.h" | 15 #include "ash/system/tray/tray_views.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
19 #include "grit/ui_resources.h" | 19 #include "grit/ui_resources.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/widget/widget.h" |
25 | 26 |
26 namespace ash { | 27 namespace ash { |
27 namespace internal { | 28 namespace internal { |
28 | 29 |
29 namespace tray { | 30 namespace tray { |
30 | 31 |
31 class IMEDefaultView : public TrayItemMore { | 32 class IMEDefaultView : public TrayItemMore { |
32 public: | 33 public: |
33 explicit IMEDefaultView(SystemTrayItem* owner) | 34 explicit IMEDefaultView(SystemTrayItem* owner) |
34 : TrayItemMore(owner) { | 35 : TrayItemMore(owner) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 std::map<views::View*, std::string> ime_map_; | 174 std::map<views::View*, std::string> ime_map_; |
174 std::map<views::View*, std::string> property_map_; | 175 std::map<views::View*, std::string> property_map_; |
175 views::View* header_; | 176 views::View* header_; |
176 views::View* settings_; | 177 views::View* settings_; |
177 | 178 |
178 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 179 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
179 }; | 180 }; |
180 | 181 |
181 } // namespace tray | 182 } // namespace tray |
182 | 183 |
183 TrayIME::TrayIME() { | 184 TrayIME::TrayIME() |
| 185 : tray_label_(NULL), |
| 186 default_(NULL), |
| 187 detailed_(NULL) { |
184 } | 188 } |
185 | 189 |
186 TrayIME::~TrayIME() { | 190 TrayIME::~TrayIME() { |
187 } | 191 } |
188 | 192 |
189 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 193 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
190 tray_label_->label()->SetText(current.short_name); | 194 if (tray_label_) { |
191 tray_label_->SetVisible(count > 1); | 195 tray_label_->label()->SetText(current.short_name); |
| 196 tray_label_->SetVisible(count > 1); |
| 197 } |
192 } | 198 } |
193 | 199 |
194 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 200 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
195 tray_label_.reset(new TrayItemView); | 201 DCHECK(tray_label_ == NULL); |
| 202 tray_label_ = new TrayItemView; |
196 tray_label_->CreateLabel(); | 203 tray_label_->CreateLabel(); |
197 SetupLabelForTray(tray_label_->label()); | 204 SetupLabelForTray(tray_label_->label()); |
198 tray_label_->set_border( | 205 tray_label_->set_border( |
199 views::Border::CreateEmptyBorder(0, 2, 0, 2)); | 206 views::Border::CreateEmptyBorder(0, 2, 0, 2)); |
200 return tray_label_.get(); | 207 return tray_label_; |
201 } | 208 } |
202 | 209 |
203 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { | 210 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
204 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 211 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
205 IMEInfoList list; | 212 IMEInfoList list; |
206 IMEPropertyInfoList property_list; | 213 IMEPropertyInfoList property_list; |
207 delegate->GetAvailableIMEList(&list); | 214 delegate->GetAvailableIMEList(&list); |
208 delegate->GetCurrentIMEProperties(&property_list); | 215 delegate->GetCurrentIMEProperties(&property_list); |
209 if (list.size() <= 1 && property_list.size() <= 1) | 216 if (list.size() <= 1 && property_list.size() <= 1) |
210 return NULL; | 217 return NULL; |
211 default_.reset(new tray::IMEDefaultView(this)); | 218 DCHECK(detailed_ == NULL); |
212 return default_.get(); | 219 default_ = new tray::IMEDefaultView(this); |
| 220 return default_; |
213 } | 221 } |
214 | 222 |
215 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { | 223 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { |
216 detailed_.reset(new tray::IMEDetailedView(this, status)); | 224 DCHECK(detailed_ == NULL); |
217 return detailed_.get(); | 225 detailed_ = new tray::IMEDetailedView(this, status); |
| 226 return detailed_; |
218 } | 227 } |
219 | 228 |
220 void TrayIME::DestroyTrayView() { | 229 void TrayIME::DestroyTrayView() { |
221 tray_label_.reset(); | 230 tray_label_ = NULL; |
222 } | 231 } |
223 | 232 |
224 void TrayIME::DestroyDefaultView() { | 233 void TrayIME::DestroyDefaultView() { |
225 default_.reset(); | 234 default_ = NULL; |
226 } | 235 } |
227 | 236 |
228 void TrayIME::DestroyDetailedView() { | 237 void TrayIME::DestroyDetailedView() { |
229 detailed_.reset(); | 238 detailed_ = NULL; |
230 } | 239 } |
231 | 240 |
232 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 241 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
233 } | 242 } |
234 | 243 |
235 void TrayIME::OnIMERefresh() { | 244 void TrayIME::OnIMERefresh() { |
236 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 245 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
237 IMEInfoList list; | 246 IMEInfoList list; |
238 IMEInfo current; | 247 IMEInfo current; |
239 IMEPropertyInfoList property_list; | 248 IMEPropertyInfoList property_list; |
240 delegate->GetCurrentIME(¤t); | 249 delegate->GetCurrentIME(¤t); |
241 delegate->GetAvailableIMEList(&list); | 250 delegate->GetAvailableIMEList(&list); |
242 delegate->GetCurrentIMEProperties(&property_list); | 251 delegate->GetCurrentIMEProperties(&property_list); |
243 | 252 |
244 UpdateTrayLabel(current, list.size()); | 253 UpdateTrayLabel(current, list.size()); |
245 | 254 |
246 if (default_.get()) | 255 if (default_) |
247 default_->UpdateLabel(current); | 256 default_->UpdateLabel(current); |
248 if (detailed_.get()) | 257 if (detailed_) |
249 detailed_->Update(list, property_list); | 258 detailed_->Update(list, property_list); |
250 } | 259 } |
251 | 260 |
252 } // namespace internal | 261 } // namespace internal |
253 } // namespace ash | 262 } // namespace ash |
OLD | NEW |