OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/common/system/chromeos/ime_menu/ime_menu_tray.h" | 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 TrayPopupHeaderButton* emoji_button_; | 131 TrayPopupHeaderButton* emoji_button_; |
132 TrayPopupHeaderButton* voice_button_; | 132 TrayPopupHeaderButton* voice_button_; |
133 TrayPopupHeaderButton* handwriting_button_; | 133 TrayPopupHeaderButton* handwriting_button_; |
134 TrayPopupHeaderButton* settings_button_; | 134 TrayPopupHeaderButton* settings_button_; |
135 | 135 |
136 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); | 136 DISALLOW_COPY_AND_ASSIGN(ImeButtonsView); |
137 }; | 137 }; |
138 | 138 |
139 } // namespace | 139 } // namespace |
140 | 140 |
141 // Class to wrap and manage the ImeListView, ImeButtonsView and | |
142 // TrayBubbleWrapper instances for the IME menu bubble. | |
143 class ImeBubbleWrapper { | |
James Cook
2016/08/23 16:38:33
Why do you need this class? Could the ImeListView*
Azure Wei
2016/08/24 05:22:43
This class is not unnecessary if storing ImeListVi
| |
144 public: | |
145 ImeBubbleWrapper(ImeMenuTray* tray) : tray_(tray) {} | |
James Cook
2016/08/23 16:38:32
nit: explicit
Azure Wei
2016/08/24 05:22:43
Removed this class.
| |
146 | |
147 // Initializes the bubble view and creates |bubble_wrapper_|. | |
148 void InitView() { | |
149 views::TrayBubbleView::InitParams init_params( | |
150 views::TrayBubbleView::ANCHOR_TYPE_TRAY, tray_->GetAnchorAlignment(), | |
151 kTrayPopupMinWidth, kTrayPopupMaxWidth); | |
152 init_params.first_item_has_no_margin = true; | |
153 init_params.can_activate = true; | |
154 init_params.close_on_deactivate = true; | |
155 | |
156 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( | |
157 tray_->tray_container(), tray_, &init_params); | |
158 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); | |
159 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
160 | |
161 list_view_.reset( | |
162 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME)); | |
163 | |
164 // Adds IME list to the bubble. | |
165 bubble_view->AddChildView(list_view_.get()); | |
James Cook
2016/08/23 16:38:33
AddChildView() takes ownership of list_view_, so l
Azure Wei
2016/08/24 05:22:43
Done.
| |
166 | |
167 // Adds IME buttons to the bubble if needed. | |
168 LoginStatus login = | |
169 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); | |
170 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && | |
171 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | |
172 button_view_.reset(new ImeButtonsView(false, false, false, true)); | |
173 bubble_view->AddChildView(button_view_.get()); | |
James Cook
2016/08/23 16:38:33
ditto
Azure Wei
2016/08/24 05:22:43
Done.
| |
174 bubble_wrapper_.reset(new ash::TrayBubbleWrapper(tray_, bubble_view)); | |
James Cook
2016/08/23 16:38:32
nit: no ash::
Azure Wei
2016/08/24 05:22:43
Done.
| |
175 } | |
176 | |
177 // Returns the bubble view. | |
178 views::TrayBubbleView* bubble_view() const { | |
179 if (bubble_wrapper_.get()) { | |
James Cook
2016/08/23 16:38:32
nit: no {}
Azure Wei
2016/08/24 05:22:43
Done.
| |
180 return bubble_wrapper_->bubble_view(); | |
181 } | |
182 return nullptr; | |
183 } | |
184 | |
185 // Returns the ImeListView. | |
186 ImeListView* list_view() const { return list_view_.get(); } | |
187 | |
188 private: | |
189 ImeMenuTray* tray_; | |
190 std::unique_ptr<ImeListView> list_view_; | |
191 std::unique_ptr<ImeButtonsView> button_view_; | |
192 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; | |
193 }; | |
James Cook
2016/08/23 16:38:32
DISALLOW_COPY_AND_ASSIGN
Azure Wei
2016/08/24 05:22:43
Removed this class.
| |
194 | |
141 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) | 195 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) |
142 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { | 196 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { |
143 SetupLabelForTray(label_); | 197 SetupLabelForTray(label_); |
144 tray_container()->AddChildView(label_); | 198 tray_container()->AddChildView(label_); |
145 SetContentsBackground(); | 199 SetContentsBackground(); |
146 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); | 200 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); |
147 } | 201 } |
148 | 202 |
149 ImeMenuTray::~ImeMenuTray() { | 203 ImeMenuTray::~ImeMenuTray() { |
150 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); | 204 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); |
(...skipping 21 matching lines...) Expand all Loading... | |
172 bool ImeMenuTray::PerformAction(const ui::Event& event) { | 226 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
173 if (bubble_) | 227 if (bubble_) |
174 HideImeMenuBubble(); | 228 HideImeMenuBubble(); |
175 else | 229 else |
176 ShowImeMenuBubble(); | 230 ShowImeMenuBubble(); |
177 return true; | 231 return true; |
178 } | 232 } |
179 | 233 |
180 void ImeMenuTray::OnIMERefresh() { | 234 void ImeMenuTray::OnIMERefresh() { |
181 UpdateTrayLabel(); | 235 UpdateTrayLabel(); |
236 if (bubble_ && bubble_->list_view()) { | |
237 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
238 IMEInfoList list; | |
239 delegate->GetAvailableIMEList(&list); | |
240 IMEPropertyInfoList property_list; | |
241 delegate->GetCurrentIMEProperties(&property_list); | |
242 bubble_->list_view()->Update(list, property_list, false, | |
243 ImeListView::SHOW_SINGLE_IME); | |
244 } | |
182 } | 245 } |
183 | 246 |
184 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | 247 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { |
185 SetVisible(is_activated); | 248 SetVisible(is_activated); |
186 if (is_activated) | 249 if (is_activated) |
187 UpdateTrayLabel(); | 250 UpdateTrayLabel(); |
188 else | 251 else |
189 HideImeMenuBubble(); | 252 HideImeMenuBubble(); |
190 } | 253 } |
191 | 254 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); | 304 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); |
242 | 305 |
243 // Updates the tray label based on the current input method. | 306 // Updates the tray label based on the current input method. |
244 if (current_ime_.third_party) | 307 if (current_ime_.third_party) |
245 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | 308 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); |
246 else | 309 else |
247 label_->SetText(current_ime_.short_name); | 310 label_->SetText(current_ime_.short_name); |
248 } | 311 } |
249 | 312 |
250 void ImeMenuTray::ShowImeMenuBubble() { | 313 void ImeMenuTray::ShowImeMenuBubble() { |
251 views::TrayBubbleView::InitParams init_params( | 314 bubble_.reset(new ImeBubbleWrapper(this)); |
252 views::TrayBubbleView::ANCHOR_TYPE_TRAY, GetAnchorAlignment(), | 315 bubble_->InitView(); |
253 kTrayPopupMinWidth, kTrayPopupMaxWidth); | |
254 init_params.first_item_has_no_margin = true; | |
255 init_params.can_activate = true; | |
256 init_params.close_on_deactivate = true; | |
257 | |
258 views::TrayBubbleView* bubble_view = | |
259 views::TrayBubbleView::Create(tray_container(), this, &init_params); | |
260 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); | |
261 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
262 | |
263 // Adds IME list to the bubble. | |
264 bubble_view->AddChildView( | |
265 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME)); | |
266 | |
267 // Adds IME buttons to the bubble if needed. | |
268 LoginStatus login = | |
269 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); | |
270 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && | |
271 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) | |
272 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); | |
273 | |
274 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); | |
275 SetDrawBackgroundAsActive(true); | 316 SetDrawBackgroundAsActive(true); |
276 } | 317 } |
277 | 318 |
278 void ImeMenuTray::HideImeMenuBubble() { | 319 void ImeMenuTray::HideImeMenuBubble() { |
279 bubble_.reset(); | 320 bubble_.reset(); |
280 SetDrawBackgroundAsActive(false); | 321 SetDrawBackgroundAsActive(false); |
281 } | 322 } |
282 | 323 |
324 // Returns ture if the bubble has been shown. | |
325 bool ImeMenuTray::IsBubbleShownForTesting() { | |
326 return (bubble_ && bubble_->bubble_view()); | |
James Cook
2016/08/23 16:38:32
nit: no extra ()
Azure Wei
2016/08/24 05:22:43
Done.
| |
327 } | |
328 | |
283 } // namespace ash | 329 } // namespace ash |
OLD | NEW |