| 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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 private: | 59 private: |
| 60 views::Label* label_; | 60 views::Label* label_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); | 62 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class IMEDetailedView : public views::View, | 65 class IMEDetailedView : public views::View, |
| 66 public ViewClickListener { | 66 public ViewClickListener { |
| 67 public: | 67 public: |
| 68 explicit IMEDetailedView(SystemTrayItem* owner) | 68 IMEDetailedView(SystemTrayItem* owner, user::LoginStatus status) |
| 69 : header_(NULL) { | 69 : header_(NULL), |
| 70 status_(status) { |
| 70 SetLayoutManager(new views::BoxLayout( | 71 SetLayoutManager(new views::BoxLayout( |
| 71 views::BoxLayout::kVertical, 1, 1, 1)); | 72 views::BoxLayout::kVertical, 1, 1, 1)); |
| 72 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 73 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 74 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 73 IMEInfoList list; | 75 IMEInfoList list; |
| 74 Shell::GetInstance()->tray_delegate()->GetAvailableIMEList(&list); | 76 delegate->GetAvailableIMEList(&list); |
| 75 Update(list); | 77 IMEPropertyInfoList property_list; |
| 78 delegate->GetCurrentIMEProperties(&property_list); |
| 79 Update(list, property_list); |
| 76 } | 80 } |
| 77 | 81 |
| 78 virtual ~IMEDetailedView() {} | 82 virtual ~IMEDetailedView() {} |
| 79 | 83 |
| 80 void Update(const IMEInfoList& list) { | 84 void Update(const IMEInfoList& list, |
| 85 const IMEPropertyInfoList& property_list) { |
| 81 RemoveAllChildViews(true); | 86 RemoveAllChildViews(true); |
| 82 | 87 |
| 83 header_ = NULL; | 88 header_ = NULL; |
| 84 | 89 |
| 85 AppendHeaderEntry(); | 90 AppendHeaderEntry(); |
| 86 AppendIMEList(list); | 91 AppendIMEList(list); |
| 87 AppendSettings(); | 92 if (!property_list.empty()) |
| 93 AppendIMEProperties(property_list); |
| 94 if (status_ != user::LOGGED_IN_NONE) |
| 95 AppendSettings(); |
| 88 | 96 |
| 89 Layout(); | 97 Layout(); |
| 98 SchedulePaint(); |
| 90 } | 99 } |
| 91 | 100 |
| 92 private: | 101 private: |
| 93 void AppendHeaderEntry() { | 102 void AppendHeaderEntry() { |
| 94 header_ = CreateDetailedHeaderEntry(IDS_ASH_STATUS_TRAY_IME, this); | 103 header_ = CreateDetailedHeaderEntry(IDS_ASH_STATUS_TRAY_IME, this); |
| 95 AddChildView(header_); | 104 AddChildView(header_); |
| 96 } | 105 } |
| 97 | 106 |
| 98 void AppendIMEList(const IMEInfoList& list) { | 107 void AppendIMEList(const IMEInfoList& list) { |
| 99 views::View* imes = new views::View; | 108 views::View* imes = new views::View; |
| 100 imes->SetLayoutManager(new views::BoxLayout( | 109 imes->SetLayoutManager(new views::BoxLayout( |
| 101 views::BoxLayout::kVertical, 0, 0, 1)); | 110 views::BoxLayout::kVertical, 0, 0, 1)); |
| 102 for (size_t i = 0; i < list.size(); i++) { | 111 for (size_t i = 0; i < list.size(); i++) { |
| 103 HoverHighlightView* container = new HoverHighlightView(this); | 112 HoverHighlightView* container = new HoverHighlightView(this); |
| 104 container->AddLabel(list[i].name, | 113 container->AddLabel(list[i].name, |
| 105 list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL); | 114 list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
| 106 imes->AddChildView(container); | 115 imes->AddChildView(container); |
| 107 ime_map_[container] = list[i].id; | 116 ime_map_[container] = list[i].id; |
| 108 } | 117 } |
| 109 imes->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, | 118 imes->set_border(views::Border::CreateSolidSidedBorder(1, 0, 1, 0, |
| 110 kBorderLightColor)); | 119 kBorderLightColor)); |
| 111 AddChildView(imes); | 120 AddChildView(imes); |
| 112 } | 121 } |
| 113 | 122 |
| 123 void AppendIMEProperties(const IMEPropertyInfoList& property_list) { |
| 124 views::View* properties = new views::View; |
| 125 properties->SetLayoutManager(new views::BoxLayout( |
| 126 views::BoxLayout::kVertical, 0, 0, 1)); |
| 127 for (size_t i = 0; i < property_list.size(); i++) { |
| 128 HoverHighlightView* container = new HoverHighlightView(this); |
| 129 container->AddLabel( |
| 130 property_list[i].name, |
| 131 property_list[i].selected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
| 132 properties->AddChildView(container); |
| 133 property_map_[container] = property_list[i].key; |
| 134 } |
| 135 properties->set_border(views::Border::CreateSolidSidedBorder( |
| 136 0, 0, 1, 0, kBorderLightColor)); |
| 137 AddChildView(properties); |
| 138 } |
| 139 |
| 114 void AppendSettings() { | 140 void AppendSettings() { |
| 115 HoverHighlightView* container = new HoverHighlightView(this); | 141 HoverHighlightView* container = new HoverHighlightView(this); |
| 116 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). | 142 container->AddLabel(ui::ResourceBundle::GetSharedInstance(). |
| 117 GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS), | 143 GetLocalizedString(IDS_ASH_STATUS_TRAY_IME_SETTINGS), |
| 118 gfx::Font::NORMAL); | 144 gfx::Font::NORMAL); |
| 119 AddChildView(container); | 145 AddChildView(container); |
| 120 settings_ = container; | 146 settings_ = container; |
| 121 } | 147 } |
| 122 | 148 |
| 123 // Overridden from ViewClickListener. | 149 // Overridden from ViewClickListener. |
| 124 virtual void ClickedOn(views::View* sender) OVERRIDE { | 150 virtual void ClickedOn(views::View* sender) OVERRIDE { |
| 125 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 151 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 126 if (sender == header_) { | 152 if (sender == header_) { |
| 127 Shell::GetInstance()->tray()->ShowDefaultView(); | 153 Shell::GetInstance()->tray()->ShowDefaultView(); |
| 128 } else if (sender == settings_) { | 154 } else if (sender == settings_) { |
| 129 delegate->ShowIMESettings(); | 155 delegate->ShowIMESettings(); |
| 130 } else { | 156 } else { |
| 131 std::map<views::View*, std::string>::iterator find; | 157 std::map<views::View*, std::string>::const_iterator ime_find; |
| 132 find = ime_map_.find(sender); | 158 ime_find = ime_map_.find(sender); |
| 133 if (find != ime_map_.end()) { | 159 if (ime_find != ime_map_.end()) { |
| 134 std::string ime_id = find->second; | 160 std::string ime_id = ime_find->second; |
| 135 delegate->SwitchIME(ime_id); | 161 delegate->SwitchIME(ime_id); |
| 162 } else { |
| 163 std::map<views::View*, std::string>::const_iterator prop_find; |
| 164 prop_find = property_map_.find(sender); |
| 165 if (prop_find != property_map_.end()) { |
| 166 std::string key = prop_find->second; |
| 167 delegate->ActivateIMEProperty(key); |
| 168 } |
| 136 } | 169 } |
| 137 } | 170 } |
| 138 } | 171 } |
| 139 | 172 |
| 140 std::map<views::View*, std::string> ime_map_; | 173 std::map<views::View*, std::string> ime_map_; |
| 174 std::map<views::View*, std::string> property_map_; |
| 141 views::View* header_; | 175 views::View* header_; |
| 142 views::View* settings_; | 176 views::View* settings_; |
| 177 user::LoginStatus status_; |
| 143 | 178 |
| 144 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 179 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
| 145 }; | 180 }; |
| 146 | 181 |
| 147 } // namespace tray | 182 } // namespace tray |
| 148 | 183 |
| 149 TrayIME::TrayIME() { | 184 TrayIME::TrayIME() { |
| 150 } | 185 } |
| 151 | 186 |
| 152 TrayIME::~TrayIME() { | 187 TrayIME::~TrayIME() { |
| 153 } | 188 } |
| 154 | 189 |
| 155 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 190 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| 156 tray_label_->SetText(current.short_name); | 191 tray_label_->SetText(current.short_name); |
| 157 tray_label_->SetVisible(count > 1); | 192 tray_label_->SetVisible(count > 1); |
| 158 } | 193 } |
| 159 | 194 |
| 160 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 195 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
| 161 tray_label_.reset(new views::Label); | 196 tray_label_.reset(new views::Label); |
| 162 SetupLabelForTray(tray_label_.get()); | 197 SetupLabelForTray(tray_label_.get()); |
| 163 return tray_label_.get(); | 198 return tray_label_.get(); |
| 164 } | 199 } |
| 165 | 200 |
| 166 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { | 201 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
| 167 default_.reset(new tray::IMEDefaultView(this)); | 202 default_.reset(new tray::IMEDefaultView(this)); |
| 168 return default_.get(); | 203 return default_.get(); |
| 169 } | 204 } |
| 170 | 205 |
| 171 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { | 206 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { |
| 172 detailed_.reset(new tray::IMEDetailedView(this)); | 207 detailed_.reset(new tray::IMEDetailedView(this, status)); |
| 173 return detailed_.get(); | 208 return detailed_.get(); |
| 174 } | 209 } |
| 175 | 210 |
| 176 void TrayIME::DestroyTrayView() { | 211 void TrayIME::DestroyTrayView() { |
| 177 tray_label_.reset(); | 212 tray_label_.reset(); |
| 178 } | 213 } |
| 179 | 214 |
| 180 void TrayIME::DestroyDefaultView() { | 215 void TrayIME::DestroyDefaultView() { |
| 181 default_.reset(); | 216 default_.reset(); |
| 182 } | 217 } |
| 183 | 218 |
| 184 void TrayIME::DestroyDetailedView() { | 219 void TrayIME::DestroyDetailedView() { |
| 185 detailed_.reset(); | 220 detailed_.reset(); |
| 186 } | 221 } |
| 187 | 222 |
| 188 void TrayIME::OnIMERefresh() { | 223 void TrayIME::OnIMERefresh() { |
| 189 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 224 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 190 IMEInfoList list; | 225 IMEInfoList list; |
| 191 IMEInfo current; | 226 IMEInfo current; |
| 227 IMEPropertyInfoList property_list; |
| 192 delegate->GetCurrentIME(¤t); | 228 delegate->GetCurrentIME(¤t); |
| 193 delegate->GetAvailableIMEList(&list); | 229 delegate->GetAvailableIMEList(&list); |
| 230 delegate->GetCurrentIMEProperties(&property_list); |
| 194 | 231 |
| 195 UpdateTrayLabel(current, list.size()); | 232 UpdateTrayLabel(current, list.size()); |
| 196 | 233 |
| 197 if (default_.get()) | 234 if (default_.get()) |
| 198 default_->UpdateLabel(current); | 235 default_->UpdateLabel(current); |
| 199 if (detailed_.get()) | 236 if (detailed_.get()) |
| 200 detailed_->Update(list); | 237 detailed_->Update(list, property_list); |
| 201 } | 238 } |
| 202 | 239 |
| 203 } // namespace internal | 240 } // namespace internal |
| 204 } // namespace ash | 241 } // namespace ash |
| OLD | NEW |