Chromium Code Reviews| 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_chromeos.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/metrics/user_metrics_recorder.h" | 9 #include "ash/metrics/user_metrics_recorder.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/session/session_state_delegate.h" | 11 #include "ash/session/session_state_delegate.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/system/tray/hover_highlight_view.h" | 14 #include "ash/system/tray/hover_highlight_view.h" |
| 15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 17 #include "ash/system/tray/system_tray_notifier.h" | 17 #include "ash/system/tray/system_tray_notifier.h" |
| 18 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 19 #include "ash/system/tray/tray_details_view.h" | 19 #include "ash/system/tray/tray_details_view.h" |
| 20 #include "ash/system/tray/tray_item_more.h" | 20 #include "ash/system/tray/tray_item_more.h" |
| 21 #include "ash/system/tray/tray_item_view.h" | 21 #include "ash/system/tray/tray_item_view.h" |
| 22 #include "ash/system/tray/tray_utils.h" | 22 #include "ash/system/tray/tray_utils.h" |
| 23 #include "ash/system/tray_accessibility.h" | |
| 24 #include "ash/virtual_keyboard_controller.h" | |
| 23 #include "base/logging.h" | 25 #include "base/logging.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 25 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 26 #include "grit/ash_strings.h" | 28 #include "grit/ash_strings.h" |
| 27 #include "ui/accessibility/ax_enums.h" | 29 #include "ui/accessibility/ax_enums.h" |
| 28 #include "ui/accessibility/ax_view_state.h" | 30 #include "ui/accessibility/ax_view_state.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/font.h" | 32 #include "ui/gfx/font.h" |
| 31 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 34 #include "ui/keyboard/keyboard_util.h" | |
| 32 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 33 #include "ui/views/layout/box_layout.h" | 36 #include "ui/views/layout/box_layout.h" |
| 34 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 35 | 38 |
| 36 namespace ash { | 39 namespace ash { |
| 37 namespace tray { | 40 namespace tray { |
| 38 | 41 |
| 39 // A |HoverHighlightView| that uses bold or normal font depending on whetehr | 42 // A |HoverHighlightView| that uses bold or normal font depending on whether |
| 40 // it is selected. This view exposes itself as a checkbox to the accessibility | 43 // it is selected. This view exposes itself as a checkbox to the accessibility |
| 41 // framework. | 44 // framework. |
| 42 class SelectableHoverHighlightView : public HoverHighlightView { | 45 class SelectableHoverHighlightView : public HoverHighlightView { |
| 43 public: | 46 public: |
| 44 SelectableHoverHighlightView(ViewClickListener* listener, | 47 SelectableHoverHighlightView(ViewClickListener* listener, |
| 45 const base::string16& label, | 48 const base::string16& label, |
| 46 bool selected) | 49 bool selected) |
| 47 : HoverHighlightView(listener), selected_(selected) { | 50 : HoverHighlightView(listener), selected_(selected) { |
| 48 AddLabel( | 51 AddLabel(label, gfx::ALIGN_LEFT, |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
According to style guide each parameter needs to g
rsadam
2015/01/09 23:45:07
Weird, git cl format changes it to the wrong thing
Mr4D (OOO till 08-26)
2015/01/10 00:42:09
Hmm. interesting - let me know how that goes!
(I
| |
| 49 label, gfx::ALIGN_LEFT, selected ? gfx::Font::BOLD : gfx::Font::NORMAL); | 52 selected ? gfx::Font::BOLD : gfx::Font::NORMAL); |
| 50 } | 53 } |
| 51 | 54 |
| 52 ~SelectableHoverHighlightView() override {} | 55 ~SelectableHoverHighlightView() override {} |
| 53 | 56 |
| 54 protected: | 57 protected: |
| 55 // Overridden from views::View. | 58 // Overridden from views::View. |
| 56 void GetAccessibleState(ui::AXViewState* state) override { | 59 void GetAccessibleState(ui::AXViewState* state) override { |
| 57 HoverHighlightView::GetAccessibleState(state); | 60 HoverHighlightView::GetAccessibleState(state); |
| 58 state->role = ui::AX_ROLE_CHECK_BOX; | 61 state->role = ui::AX_ROLE_CHECK_BOX; |
| 59 if (selected_) | 62 if (selected_) |
| 60 state->AddStateFlag(ui::AX_STATE_CHECKED); | 63 state->AddStateFlag(ui::AX_STATE_CHECKED); |
| 61 } | 64 } |
| 62 | 65 |
| 63 private: | 66 private: |
| 64 bool selected_; | 67 bool selected_; |
| 65 | 68 |
| 66 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); | 69 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView); |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 class IMEDefaultView : public TrayItemMore { | 72 class IMEDefaultView : public TrayItemMore { |
| 70 public: | 73 public: |
| 71 explicit IMEDefaultView(SystemTrayItem* owner) | 74 explicit IMEDefaultView(SystemTrayItem* owner, const base::string16& label) |
| 72 : TrayItemMore(owner, true) { | 75 : TrayItemMore(owner, true) { |
| 73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 76 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 74 | 77 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME).ToImageSkia()); |
| 75 SetImage(bundle.GetImageNamed( | 78 UpdateLabel(label); |
| 76 IDR_AURA_UBER_TRAY_IME).ToImageSkia()); | |
| 77 | |
| 78 IMEInfo info; | |
| 79 Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(&info); | |
| 80 UpdateLabel(info); | |
| 81 } | 79 } |
| 82 | 80 |
| 83 ~IMEDefaultView() override {} | 81 ~IMEDefaultView() override {} |
| 84 | 82 |
| 85 void UpdateLabel(const IMEInfo& info) { | 83 void UpdateLabel(const base::string16& label) { |
| 86 SetLabel(info.name); | 84 SetLabel(label); |
| 87 SetAccessibleName(info.name); | 85 SetAccessibleName(label); |
| 88 } | 86 } |
| 89 | 87 |
| 90 private: | 88 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); | 89 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); |
| 92 }; | 90 }; |
| 93 | 91 |
| 94 class IMEDetailedView : public TrayDetailsView, | 92 class IMEDetailedView : public TrayDetailsView, public ViewClickListener { |
| 95 public ViewClickListener { | |
| 96 public: | 93 public: |
| 97 IMEDetailedView(SystemTrayItem* owner, user::LoginStatus login) | 94 IMEDetailedView(SystemTrayItem* owner, |
| 98 : TrayDetailsView(owner), | 95 user::LoginStatus login, |
| 99 login_(login) { | 96 bool show_keyboard_toggle) |
| 97 : TrayDetailsView(owner), login_(login) { | |
| 100 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 98 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 101 IMEInfoList list; | 99 IMEInfoList list; |
| 102 delegate->GetAvailableIMEList(&list); | 100 delegate->GetAvailableIMEList(&list); |
| 103 IMEPropertyInfoList property_list; | 101 IMEPropertyInfoList property_list; |
| 104 delegate->GetCurrentIMEProperties(&property_list); | 102 delegate->GetCurrentIMEProperties(&property_list); |
| 105 Update(list, property_list); | 103 Update(list, property_list, show_keyboard_toggle); |
| 106 } | 104 } |
| 107 | 105 |
| 108 ~IMEDetailedView() override {} | 106 ~IMEDetailedView() override {} |
| 109 | 107 |
| 110 void Update(const IMEInfoList& list, | 108 void Update(const IMEInfoList& list, |
| 111 const IMEPropertyInfoList& property_list) { | 109 const IMEPropertyInfoList& property_list, |
| 110 bool show_keyboard_toggle) { | |
| 112 Reset(); | 111 Reset(); |
| 112 ime_map_.clear(); | |
| 113 property_map_.clear(); | |
| 114 CreateScrollableList(); | |
| 113 | 115 |
| 114 AppendIMEList(list); | 116 if (list.size() > 1) |
| 115 if (!property_list.empty()) | 117 AppendIMEList(list); |
| 118 if (property_list.size() > 1) | |
| 116 AppendIMEProperties(property_list); | 119 AppendIMEProperties(property_list); |
| 120 if (list.size() > 1 || property_list.size() > 1) | |
| 121 AddScrollSeparator(); | |
| 117 bool userAddingRunning = ash::Shell::GetInstance() | 122 bool userAddingRunning = ash::Shell::GetInstance() |
| 118 ->session_state_delegate() | 123 ->session_state_delegate() |
| 119 ->IsInSecondaryLoginScreen(); | 124 ->IsInSecondaryLoginScreen(); |
| 125 if (show_keyboard_toggle) | |
| 126 AppendKeyboardStatus(); | |
| 120 | 127 |
| 121 if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED && | 128 if (login_ != user::LOGGED_IN_NONE && login_ != user::LOGGED_IN_LOCKED && |
| 122 !userAddingRunning) | 129 !userAddingRunning) |
| 123 AppendSettings(); | 130 AppendSettings(); |
| 124 AppendHeaderEntry(); | 131 AppendHeaderEntry(); |
| 125 | 132 |
| 126 Layout(); | 133 Layout(); |
| 127 SchedulePaint(); | 134 SchedulePaint(); |
| 128 } | 135 } |
| 129 | 136 |
| 130 private: | 137 private: |
| 131 void AppendHeaderEntry() { | 138 void AppendHeaderEntry() { CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); } |
| 132 CreateSpecialRow(IDS_ASH_STATUS_TRAY_IME, this); | |
| 133 } | |
| 134 | 139 |
| 135 void AppendIMEList(const IMEInfoList& list) { | 140 void AppendIMEList(const IMEInfoList& list) { |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
I am not sure that this is correct. Isn't it conce
rsadam
2015/01/09 23:45:07
I'm not sure I follow. AppendIMEList is only ever
Mr4D (OOO till 08-26)
2015/01/10 00:42:10
Ah. I haven't seen that you have cleared the maps
| |
| 136 ime_map_.clear(); | |
| 137 CreateScrollableList(); | |
| 138 for (size_t i = 0; i < list.size(); i++) { | 141 for (size_t i = 0; i < list.size(); i++) { |
| 139 HoverHighlightView* container = new SelectableHoverHighlightView( | 142 HoverHighlightView* container = new SelectableHoverHighlightView( |
| 140 this, list[i].name, list[i].selected); | 143 this, list[i].name, list[i].selected); |
| 141 scroll_content()->AddChildView(container); | 144 scroll_content()->AddChildView(container); |
| 142 ime_map_[container] = list[i].id; | 145 ime_map_[container] = list[i].id; |
| 143 } | 146 } |
| 144 } | 147 } |
| 145 | 148 |
| 146 void AppendIMEProperties(const IMEPropertyInfoList& property_list) { | 149 void AppendIMEProperties(const IMEPropertyInfoList& property_list) { |
| 147 property_map_.clear(); | |
| 148 for (size_t i = 0; i < property_list.size(); i++) { | 150 for (size_t i = 0; i < property_list.size(); i++) { |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
Same here. Shouldn't you check if the property doe
rsadam
2015/01/09 23:45:07
Same as above, I think the confusion might be in t
Mr4D (OOO till 08-26)
2015/01/10 00:42:09
Same reasoning. Yes, in the moment this is correct
| |
| 149 HoverHighlightView* container = new SelectableHoverHighlightView( | 151 HoverHighlightView* container = new SelectableHoverHighlightView( |
| 150 this, property_list[i].name, property_list[i].selected); | 152 this, property_list[i].name, property_list[i].selected); |
| 151 if (i == 0) | 153 if (i == 0) |
| 152 container->SetBorder(views::Border::CreateSolidSidedBorder( | 154 container->SetBorder(views::Border::CreateSolidSidedBorder( |
| 153 1, 0, 0, 0, kBorderLightColor)); | 155 1, 0, 0, 0, kBorderLightColor)); |
| 154 scroll_content()->AddChildView(container); | 156 scroll_content()->AddChildView(container); |
| 155 property_map_[container] = property_list[i].key; | 157 property_map_[container] = property_list[i].key; |
| 156 } | 158 } |
| 157 } | 159 } |
| 158 | 160 |
| 161 void AppendKeyboardStatus() { | |
| 162 HoverHighlightView* container = new HoverHighlightView(this); | |
| 163 int id = keyboard::IsKeyboardEnabled() | |
| 164 ? IDS_ASH_STATUS_TRAY_DISABLE_KEYBOARD | |
| 165 : IDS_ASH_STATUS_TRAY_ENABLE_KEYBOARD; | |
| 166 container->AddLabel( | |
| 167 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id), | |
| 168 gfx::ALIGN_LEFT, gfx::Font::NORMAL); | |
| 169 scroll_content()->AddChildView(container); | |
| 170 keyboard_status_ = container; | |
| 171 } | |
| 172 | |
| 159 void AppendSettings() { | 173 void AppendSettings() { |
| 160 HoverHighlightView* container = new HoverHighlightView(this); | 174 HoverHighlightView* container = new HoverHighlightView(this); |
| 161 container->AddLabel( | 175 container->AddLabel( |
| 162 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 176 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 163 IDS_ASH_STATUS_TRAY_IME_SETTINGS), | 177 IDS_ASH_STATUS_TRAY_IME_SETTINGS), |
| 164 gfx::ALIGN_LEFT, | 178 gfx::ALIGN_LEFT, gfx::Font::NORMAL); |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
As before: According to style guide: either all pa
rsadam
2015/01/09 23:45:07
Seems git cl format borked here as well. Manually
| |
| 165 gfx::Font::NORMAL); | |
| 166 AddChildView(container); | 179 AddChildView(container); |
| 167 settings_ = container; | 180 settings_ = container; |
| 168 } | 181 } |
| 169 | 182 |
| 170 // Overridden from ViewClickListener. | 183 // Overridden from ViewClickListener. |
| 171 void OnViewClicked(views::View* sender) override { | 184 void OnViewClicked(views::View* sender) override { |
| 172 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 185 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 173 if (sender == footer()->content()) { | 186 if (sender == footer()->content()) { |
| 174 TransitionToDefaultView(); | 187 TransitionToDefaultView(); |
| 175 } else if (sender == settings_) { | 188 } else if (sender == settings_) { |
| 176 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 189 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 177 ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); | 190 ash::UMA_STATUS_AREA_IME_SHOW_DETAILED); |
| 178 delegate->ShowIMESettings(); | 191 delegate->ShowIMESettings(); |
| 192 } else if (sender == keyboard_status_) { | |
| 193 Shell::GetInstance() | |
| 194 ->virtual_keyboard_controller() | |
| 195 ->ToggleIgnoreExternalKeyboard(); | |
| 179 } else { | 196 } else { |
| 180 std::map<views::View*, std::string>::const_iterator ime_find; | 197 std::map<views::View*, std::string>::const_iterator ime_find; |
| 181 ime_find = ime_map_.find(sender); | 198 ime_find = ime_map_.find(sender); |
| 182 if (ime_find != ime_map_.end()) { | 199 if (ime_find != ime_map_.end()) { |
| 183 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 200 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 184 ash::UMA_STATUS_AREA_IME_SWITCH_MODE); | 201 ash::UMA_STATUS_AREA_IME_SWITCH_MODE); |
| 185 std::string ime_id = ime_find->second; | 202 std::string ime_id = ime_find->second; |
| 186 delegate->SwitchIME(ime_id); | 203 delegate->SwitchIME(ime_id); |
| 187 GetWidget()->Close(); | 204 GetWidget()->Close(); |
| 188 } else { | 205 } else { |
| 189 std::map<views::View*, std::string>::const_iterator prop_find; | 206 std::map<views::View*, std::string>::const_iterator prop_find; |
| 190 prop_find = property_map_.find(sender); | 207 prop_find = property_map_.find(sender); |
| 191 if (prop_find != property_map_.end()) { | 208 if (prop_find != property_map_.end()) { |
| 192 const std::string key = prop_find->second; | 209 const std::string key = prop_find->second; |
| 193 delegate->ActivateIMEProperty(key); | 210 delegate->ActivateIMEProperty(key); |
| 194 GetWidget()->Close(); | 211 GetWidget()->Close(); |
| 195 } | 212 } |
| 196 } | 213 } |
| 197 } | 214 } |
| 198 } | 215 } |
| 199 | 216 |
| 200 user::LoginStatus login_; | 217 user::LoginStatus login_; |
| 201 | 218 |
| 202 std::map<views::View*, std::string> ime_map_; | 219 std::map<views::View*, std::string> ime_map_; |
| 203 std::map<views::View*, std::string> property_map_; | 220 std::map<views::View*, std::string> property_map_; |
| 204 views::View* settings_; | 221 views::View* settings_; |
| 222 views::View* keyboard_status_; | |
| 205 | 223 |
| 206 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); | 224 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); |
| 207 }; | 225 }; |
| 208 | 226 |
| 209 } // namespace tray | 227 } // namespace tray |
| 210 | 228 |
| 211 TrayIME::TrayIME(SystemTray* system_tray) | 229 TrayIME::TrayIME(SystemTray* system_tray) |
| 212 : SystemTrayItem(system_tray), | 230 : SystemTrayItem(system_tray), |
| 213 tray_label_(NULL), | 231 tray_label_(NULL), |
| 214 default_(NULL), | 232 default_(NULL), |
| 215 detailed_(NULL) { | 233 detailed_(NULL), |
| 234 keyboard_suppressed_(false) { | |
| 216 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); | 235 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); |
| 236 Shell::GetInstance()->system_tray_notifier()->AddVirtualKeyboardObserver( | |
| 237 this); | |
| 238 Shell::GetInstance()->system_tray_notifier()->AddAccessibilityObserver(this); | |
| 217 } | 239 } |
| 218 | 240 |
| 219 TrayIME::~TrayIME() { | 241 TrayIME::~TrayIME() { |
| 220 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); | 242 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); |
| 243 Shell::GetInstance()->system_tray_notifier()->RemoveVirtualKeyboardObserver( | |
| 244 this); | |
| 245 Shell::GetInstance()->system_tray_notifier()->RemoveAccessibilityObserver( | |
| 246 this); | |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
I know it does not make a difference - but could y
rsadam
2015/01/09 23:45:07
Done.
| |
| 221 } | 247 } |
| 222 | 248 |
| 223 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { | 249 void TrayIME::UpdateTrayLabel(const IMEInfo& current, size_t count) { |
| 224 if (tray_label_) { | 250 if (tray_label_) { |
| 225 bool visible = count > 1; | 251 bool visible = count > 1; |
| 226 tray_label_->SetVisible(visible); | 252 tray_label_->SetVisible(visible); |
| 227 // Do not change label before hiding because this change is noticeable. | 253 // Do not change label before hiding because this change is noticeable. |
| 228 if (!visible) | 254 if (!visible) |
| 229 return; | 255 return; |
| 230 if (current.third_party) { | 256 if (current.third_party) { |
| 231 tray_label_->label()->SetText( | 257 tray_label_->label()->SetText(current.short_name + |
| 232 current.short_name + base::UTF8ToUTF16("*")); | 258 base::UTF8ToUTF16("*")); |
| 233 } else { | 259 } else { |
| 234 tray_label_->label()->SetText(current.short_name); | 260 tray_label_->label()->SetText(current.short_name); |
| 235 } | 261 } |
| 236 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); | 262 SetTrayLabelItemBorder(tray_label_, system_tray()->shelf_alignment()); |
| 237 tray_label_->Layout(); | 263 tray_label_->Layout(); |
| 238 } | 264 } |
| 239 } | 265 } |
| 240 | 266 |
| 241 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { | 267 views::View* TrayIME::CreateTrayView(user::LoginStatus status) { |
| 242 CHECK(tray_label_ == NULL); | 268 CHECK(tray_label_ == NULL); |
| 243 tray_label_ = new TrayItemView(this); | 269 tray_label_ = new TrayItemView(this); |
| 244 tray_label_->CreateLabel(); | 270 tray_label_->CreateLabel(); |
| 245 SetupLabelForTray(tray_label_->label()); | 271 SetupLabelForTray(tray_label_->label()); |
| 246 // Hide IME tray when it is created, it will be updated when it is notified | 272 // Hide IME tray when it is created, it will be updated when it is notified |
| 247 // for IME refresh event. | 273 // of the IME refresh event. |
| 248 tray_label_->SetVisible(false); | 274 tray_label_->SetVisible(false); |
| 249 return tray_label_; | 275 return tray_label_; |
| 250 } | 276 } |
| 251 | 277 |
| 252 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { | 278 views::View* TrayIME::CreateDefaultView(user::LoginStatus status) { |
| 253 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 279 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 254 IMEInfoList list; | 280 IMEInfoList list; |
| 255 IMEPropertyInfoList property_list; | 281 IMEPropertyInfoList property_list; |
| 256 delegate->GetAvailableIMEList(&list); | 282 delegate->GetAvailableIMEList(&list); |
| 257 delegate->GetCurrentIMEProperties(&property_list); | 283 delegate->GetCurrentIMEProperties(&property_list); |
| 258 if (list.size() <= 1 && property_list.size() <= 1) | 284 // Do not show the menu if there are no options to choose between. |
| 285 if (list.size() <= 1 && property_list.size() <= 1 && | |
| 286 !ShouldShowKeyboardToggle()) { | |
| 259 return NULL; | 287 return NULL; |
| 288 } | |
| 260 CHECK(default_ == NULL); | 289 CHECK(default_ == NULL); |
| 261 default_ = new tray::IMEDefaultView(this); | 290 |
| 291 default_ = | |
| 292 new tray::IMEDefaultView(this, GetDefaultViewLabel(list.size() > 1)); | |
| 262 return default_; | 293 return default_; |
| 263 } | 294 } |
| 264 | 295 |
| 296 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) { | |
|
Mr4D (OOO till 08-26)
2015/01/09 22:50:38
The order of the functions in the c++ file should
rsadam
2015/01/09 23:45:07
Done.
| |
| 297 if (show_ime_label) { | |
| 298 IMEInfo current; | |
| 299 Shell::GetInstance()->system_tray_delegate()->GetCurrentIME(¤t); | |
| 300 return current.name; | |
| 301 } else { | |
| 302 // Display virtual keyboard status instead. | |
| 303 int id = keyboard::IsKeyboardEnabled() | |
| 304 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED | |
| 305 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED; | |
| 306 return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id); | |
| 307 } | |
| 308 } | |
| 309 | |
| 265 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { | 310 views::View* TrayIME::CreateDetailedView(user::LoginStatus status) { |
| 266 CHECK(detailed_ == NULL); | 311 CHECK(detailed_ == NULL); |
| 267 detailed_ = new tray::IMEDetailedView(this, status); | 312 detailed_ = |
| 313 new tray::IMEDetailedView(this, status, ShouldShowKeyboardToggle()); | |
| 268 return detailed_; | 314 return detailed_; |
| 269 } | 315 } |
| 270 | 316 |
| 271 void TrayIME::DestroyTrayView() { | 317 void TrayIME::DestroyTrayView() { |
| 272 tray_label_ = NULL; | 318 tray_label_ = NULL; |
| 273 } | 319 } |
| 274 | 320 |
| 275 void TrayIME::DestroyDefaultView() { | 321 void TrayIME::DestroyDefaultView() { |
| 276 default_ = NULL; | 322 default_ = NULL; |
| 277 } | 323 } |
| 278 | 324 |
| 279 void TrayIME::DestroyDetailedView() { | 325 void TrayIME::DestroyDetailedView() { |
| 280 detailed_ = NULL; | 326 detailed_ = NULL; |
| 281 } | 327 } |
| 282 | 328 |
| 283 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 329 void TrayIME::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 284 } | 330 } |
| 285 | 331 |
| 286 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 332 void TrayIME::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 287 SetTrayLabelItemBorder(tray_label_, alignment); | 333 SetTrayLabelItemBorder(tray_label_, alignment); |
| 288 tray_label_->Layout(); | 334 tray_label_->Layout(); |
| 289 } | 335 } |
| 290 | 336 |
| 291 void TrayIME::OnIMERefresh() { | 337 void TrayIME::OnKeyboardSuppressionChanged(bool suppressed) { |
| 338 keyboard_suppressed_ = suppressed; | |
| 339 // Immediately update state if the window is currently opened. | |
| 340 if (default_ || detailed_) | |
| 341 Update(); | |
| 342 } | |
| 343 | |
| 344 bool TrayIME::ShouldShowKeyboardToggle() { | |
| 345 return keyboard_suppressed_ && | |
| 346 !Shell::GetInstance() | |
| 347 ->accessibility_delegate() | |
| 348 ->IsVirtualKeyboardEnabled(); | |
| 349 } | |
| 350 | |
| 351 void TrayIME::OnAccessibilityModeChanged( | |
| 352 ui::AccessibilityNotificationVisibility notify) { | |
| 353 Update(); | |
| 354 } | |
| 355 | |
| 356 void TrayIME::Update() { | |
| 292 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 357 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 293 IMEInfoList list; | 358 IMEInfoList list; |
| 294 IMEInfo current; | 359 IMEInfo current; |
| 295 IMEPropertyInfoList property_list; | 360 IMEPropertyInfoList property_list; |
| 296 delegate->GetCurrentIME(¤t); | 361 delegate->GetCurrentIME(¤t); |
| 297 delegate->GetAvailableIMEList(&list); | 362 delegate->GetAvailableIMEList(&list); |
| 298 delegate->GetCurrentIMEProperties(&property_list); | 363 delegate->GetCurrentIMEProperties(&property_list); |
| 299 | 364 |
| 300 UpdateTrayLabel(current, list.size()); | 365 UpdateTrayLabel(current, list.size()); |
| 366 if (default_) | |
| 367 default_->UpdateLabel(GetDefaultViewLabel(list.size() > 1)); | |
| 368 if (detailed_) | |
| 369 detailed_->Update(list, property_list, ShouldShowKeyboardToggle()); | |
| 370 } | |
| 301 | 371 |
| 302 if (default_) | 372 void TrayIME::OnIMERefresh() { |
| 303 default_->UpdateLabel(current); | 373 Update(); |
| 304 if (detailed_) | |
| 305 detailed_->Update(list, property_list); | |
| 306 } | 374 } |
| 307 | 375 |
| 308 } // namespace ash | 376 } // namespace ash |
| OLD | NEW |