Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: ash/common/system/chromeos/ime_menu/ime_menu_tray.cc

Issue 2277753006: Revert "Revert of Updates the IME list when the IME has refreshed. (patchset #7 id:120001 of https:… (Closed)
Patch Set: Add new test to cover the crash. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 }; 52 };
53 53
54 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener, 54 TrayPopupHeaderButton* CreateImeMenuButton(views::ButtonListener* listener,
55 int enabled_resource_id, 55 int enabled_resource_id,
56 int disabled_resource_id, 56 int disabled_resource_id,
57 int enabled_resource_id_hover, 57 int enabled_resource_id_hover,
58 int disabled_resource_id_hover, 58 int disabled_resource_id_hover,
59 int accessible_name_id, 59 int accessible_name_id,
60 int message_id, 60 int message_id,
61 int right_border) { 61 int right_border) {
62 TrayPopupHeaderButton* button = new ash::TrayPopupHeaderButton( 62 TrayPopupHeaderButton* button =
63 listener, enabled_resource_id, disabled_resource_id, 63 new TrayPopupHeaderButton(listener, enabled_resource_id,
64 enabled_resource_id_hover, disabled_resource_id_hover, 64 disabled_resource_id, enabled_resource_id_hover,
65 accessible_name_id); 65 disabled_resource_id_hover, accessible_name_id);
66 button->SetTooltipText(l10n_util::GetStringUTF16(message_id)); 66 button->SetTooltipText(l10n_util::GetStringUTF16(message_id));
67 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border, 67 button->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 0, right_border,
68 kBorderDarkColor)); 68 kBorderDarkColor));
69 return button; 69 return button;
70 } 70 }
71 71
72 class ImeButtonsView : public views::View, public views::ButtonListener { 72 class ImeButtonsView : public views::View, public views::ButtonListener {
73 public: 73 public:
74 ImeButtonsView(bool show_emoji_button, 74 ImeButtonsView(bool show_emoji_button,
75 bool show_voice_button, 75 bool show_voice_button,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) 148 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
149 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { 149 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
150 SetupLabelForTray(label_); 150 SetupLabelForTray(label_);
151 tray_container()->AddChildView(label_); 151 tray_container()->AddChildView(label_);
152 SetContentsBackground(); 152 SetContentsBackground();
153 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); 153 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this);
154 } 154 }
155 155
156 ImeMenuTray::~ImeMenuTray() { 156 ImeMenuTray::~ImeMenuTray() {
157 if (bubble_)
158 bubble_->bubble_view()->reset_delegate();
157 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); 159 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this);
158 } 160 }
159 161
160 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { 162 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) {
161 TrayBackgroundView::SetShelfAlignment(alignment); 163 TrayBackgroundView::SetShelfAlignment(alignment);
162 if (!ash::MaterialDesignController::IsShelfMaterial()) 164 if (!MaterialDesignController::IsShelfMaterial())
163 tray_container()->SetBorder(views::Border::NullBorder()); 165 tray_container()->SetBorder(views::Border::NullBorder());
164 } 166 }
165 167
166 base::string16 ImeMenuTray::GetAccessibleNameForTray() { 168 base::string16 ImeMenuTray::GetAccessibleNameForTray() {
167 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); 169 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
168 } 170 }
169 171
170 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { 172 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
171 if (bubble_->bubble_view() == bubble_view) 173 if (bubble_->bubble_view() == bubble_view)
172 HideImeMenuBubble(); 174 HideImeMenuBubble();
173 } 175 }
174 176
175 void ImeMenuTray::ClickedOutsideBubble() { 177 void ImeMenuTray::ClickedOutsideBubble() {
176 HideImeMenuBubble(); 178 HideImeMenuBubble();
177 } 179 }
178 180
179 bool ImeMenuTray::PerformAction(const ui::Event& event) { 181 bool ImeMenuTray::PerformAction(const ui::Event& event) {
180 if (bubble_) 182 if (bubble_)
181 HideImeMenuBubble(); 183 HideImeMenuBubble();
182 else 184 else
183 ShowImeMenuBubble(); 185 ShowImeMenuBubble();
184 return true; 186 return true;
185 } 187 }
186 188
187 void ImeMenuTray::OnIMERefresh() { 189 void ImeMenuTray::OnIMERefresh() {
188 UpdateTrayLabel(); 190 UpdateTrayLabel();
191 if (bubble_ && ime_list_view_) {
192 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
193 IMEInfoList list;
194 delegate->GetAvailableIMEList(&list);
195 IMEPropertyInfoList property_list;
196 delegate->GetCurrentIMEProperties(&property_list);
197 ime_list_view_->Update(list, property_list, false,
198 ImeListView::SHOW_SINGLE_IME);
199 }
189 } 200 }
190 201
191 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { 202 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
192 SetVisible(is_activated); 203 SetVisible(is_activated);
193 if (is_activated) 204 if (is_activated)
194 UpdateTrayLabel(); 205 UpdateTrayLabel();
195 else 206 else
196 HideImeMenuBubble(); 207 HideImeMenuBubble();
197 } 208 }
198 209
199 void ImeMenuTray::BubbleViewDestroyed() { 210 void ImeMenuTray::BubbleViewDestroyed() {
200 SetDrawBackgroundAsActive(false);
201 } 211 }
202 212
203 void ImeMenuTray::OnMouseEnteredView() {} 213 void ImeMenuTray::OnMouseEnteredView() {}
204 214
205 void ImeMenuTray::OnMouseExitedView() {} 215 void ImeMenuTray::OnMouseExitedView() {}
206 216
207 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { 217 base::string16 ImeMenuTray::GetAccessibleNameForBubble() {
208 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); 218 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
209 } 219 }
210 220
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 kTrayPopupMinWidth, kTrayPopupMaxWidth); 270 kTrayPopupMinWidth, kTrayPopupMaxWidth);
261 init_params.first_item_has_no_margin = true; 271 init_params.first_item_has_no_margin = true;
262 init_params.can_activate = true; 272 init_params.can_activate = true;
263 init_params.close_on_deactivate = true; 273 init_params.close_on_deactivate = true;
264 274
265 views::TrayBubbleView* bubble_view = 275 views::TrayBubbleView* bubble_view =
266 views::TrayBubbleView::Create(tray_container(), this, &init_params); 276 views::TrayBubbleView::Create(tray_container(), this, &init_params);
267 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); 277 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0));
268 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 278 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
269 279
270 ImeListView* ime_list_view = 280 // Adds IME list to the bubble.
281 ime_list_view_ =
271 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME); 282 new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME);
272 if (ime_list_view->scroll_content()->height() > GetImeListViewMaxHeight()) { 283 if (ime_list_view_->scroll_content()->height() > GetImeListViewMaxHeight()) {
273 ime_list_view->scroller()->SetFixedSize( 284 ime_list_view_->scroller()->SetFixedSize(
274 gfx::Size(kTrayPopupMaxWidth, GetImeListViewMaxHeight())); 285 gfx::Size(kTrayPopupMaxWidth, GetImeListViewMaxHeight()));
275 } 286 }
276 // Adds IME list to the bubble. 287 bubble_view->AddChildView(ime_list_view_);
277 bubble_view->AddChildView(ime_list_view);
278 288
279 // Adds IME buttons to the bubble if needed. 289 // Adds IME buttons to the bubble if needed.
280 LoginStatus login = 290 LoginStatus login =
281 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus(); 291 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus();
282 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED && 292 if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED &&
283 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) 293 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen())
284 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true)); 294 bubble_view->AddChildView(new ImeButtonsView(false, false, false, true));
285 295
286 bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view)); 296 bubble_.reset(new TrayBubbleWrapper(this, bubble_view));
287 SetDrawBackgroundAsActive(true); 297 SetDrawBackgroundAsActive(true);
288 } 298 }
289 299
290 void ImeMenuTray::HideImeMenuBubble() { 300 void ImeMenuTray::HideImeMenuBubble() {
291 bubble_.reset(); 301 bubble_.reset();
302 ime_list_view_ = nullptr;
292 SetDrawBackgroundAsActive(false); 303 SetDrawBackgroundAsActive(false);
293 } 304 }
294 305
295 } // namespace ash 306 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/ime_menu/ime_menu_tray.h ('k') | ash/common/system/chromeos/ime_menu/ime_menu_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698