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/system/ime_menu/ime_menu_tray.h" | 5 #include "ash/system/ime_menu/ime_menu_tray.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/ime/ime_controller.h" | 10 #include "ash/ime/ime_controller.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 DCHECK(ime_menu_tray_); | 188 DCHECK(ime_menu_tray_); |
189 | 189 |
190 Init(show_emoji, show_handwriting, show_voice); | 190 Init(show_emoji, show_handwriting, show_voice); |
191 } | 191 } |
192 | 192 |
193 ~ImeButtonsView() override {} | 193 ~ImeButtonsView() override {} |
194 | 194 |
195 // views::ButtonListener: | 195 // views::ButtonListener: |
196 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 196 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
197 if (sender == settings_button_) { | 197 if (sender == settings_button_) { |
198 ime_menu_tray_->HideImeMenuBubble(); | 198 ime_menu_tray_->CloseBubble(); |
199 ShowIMESettings(); | 199 ShowIMESettings(); |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 // The |keyset| will be used for drawing input view keyset in IME | 203 // The |keyset| will be used for drawing input view keyset in IME |
204 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with | 204 // extensions. InputMethodManager::ShowKeyboardWithKeyset() will deal with |
205 // the |keyset| string to generate the right input view url. | 205 // the |keyset| string to generate the right input view url. |
206 std::string keyset; | 206 std::string keyset; |
207 if (sender == emoji_button_) { | 207 if (sender == emoji_button_) { |
208 keyset = "emoji"; | 208 keyset = "emoji"; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 voice_enabled_(false), | 305 voice_enabled_(false), |
306 weak_ptr_factory_(this) { | 306 weak_ptr_factory_(this) { |
307 DCHECK(ime_controller_); | 307 DCHECK(ime_controller_); |
308 SetInkDropMode(InkDropMode::ON); | 308 SetInkDropMode(InkDropMode::ON); |
309 SetupLabelForTray(label_); | 309 SetupLabelForTray(label_); |
310 label_->SetElideBehavior(gfx::TRUNCATE); | 310 label_->SetElideBehavior(gfx::TRUNCATE); |
311 tray_container()->AddChildView(label_); | 311 tray_container()->AddChildView(label_); |
312 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 312 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
313 tray_notifier->AddIMEObserver(this); | 313 tray_notifier->AddIMEObserver(this); |
314 tray_notifier->AddVirtualKeyboardObserver(this); | 314 tray_notifier->AddVirtualKeyboardObserver(this); |
| 315 |
| 316 if (!drag_controller()) |
| 317 set_drag_controller(base::MakeUnique<TrayDragController>(shelf)); |
315 } | 318 } |
316 | 319 |
317 ImeMenuTray::~ImeMenuTray() { | 320 ImeMenuTray::~ImeMenuTray() { |
318 if (bubble_) | 321 if (bubble_) |
319 bubble_->bubble_view()->ResetDelegate(); | 322 bubble_->bubble_view()->ResetDelegate(); |
320 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); | 323 SystemTrayNotifier* tray_notifier = Shell::Get()->system_tray_notifier(); |
321 tray_notifier->RemoveIMEObserver(this); | 324 tray_notifier->RemoveIMEObserver(this); |
322 tray_notifier->RemoveVirtualKeyboardObserver(this); | 325 tray_notifier->RemoveVirtualKeyboardObserver(this); |
323 keyboard::KeyboardController* keyboard_controller = | 326 keyboard::KeyboardController* keyboard_controller = |
324 keyboard::KeyboardController::GetInstance(); | 327 keyboard::KeyboardController::GetInstance(); |
325 if (keyboard_controller) | 328 if (keyboard_controller) |
326 keyboard_controller->RemoveObserver(this); | 329 keyboard_controller->RemoveObserver(this); |
327 } | 330 } |
328 | 331 |
329 void ImeMenuTray::ShowImeMenuBubble() { | |
330 keyboard::KeyboardController* keyboard_controller = | |
331 keyboard::KeyboardController::GetInstance(); | |
332 if (keyboard_controller && keyboard_controller->keyboard_visible()) { | |
333 show_bubble_after_keyboard_hidden_ = true; | |
334 keyboard_controller->AddObserver(this); | |
335 keyboard_controller->HideKeyboard( | |
336 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); | |
337 } else { | |
338 ShowImeMenuBubbleInternal(); | |
339 } | |
340 } | |
341 | |
342 void ImeMenuTray::ShowImeMenuBubbleInternal() { | 332 void ImeMenuTray::ShowImeMenuBubbleInternal() { |
343 views::TrayBubbleView::InitParams init_params; | 333 views::TrayBubbleView::InitParams init_params; |
344 init_params.delegate = this; | 334 init_params.delegate = this; |
345 init_params.parent_window = GetBubbleWindowContainer(); | 335 init_params.parent_window = GetBubbleWindowContainer(); |
346 init_params.anchor_view = GetBubbleAnchor(); | 336 init_params.anchor_view = GetBubbleAnchor(); |
347 init_params.anchor_alignment = GetAnchorAlignment(); | 337 init_params.anchor_alignment = GetAnchorAlignment(); |
348 init_params.min_width = kTrayMenuMinimumWidth; | 338 init_params.min_width = kTrayMenuMinimumWidth; |
349 init_params.max_width = kTrayMenuMinimumWidth; | 339 init_params.max_width = kTrayMenuMinimumWidth; |
350 init_params.close_on_deactivate = true; | 340 init_params.close_on_deactivate = true; |
351 | 341 |
(...skipping 12 matching lines...) Expand all Loading... |
364 | 354 |
365 if (show_bottom_buttons) { | 355 if (show_bottom_buttons) { |
366 bubble_view->AddChildView(new ImeButtonsView( | 356 bubble_view->AddChildView(new ImeButtonsView( |
367 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); | 357 this, emoji_enabled_, handwriting_enabled_, voice_enabled_)); |
368 } | 358 } |
369 | 359 |
370 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); | 360 bubble_.reset(new TrayBubbleWrapper(this, bubble_view)); |
371 SetIsActive(true); | 361 SetIsActive(true); |
372 } | 362 } |
373 | 363 |
374 void ImeMenuTray::HideImeMenuBubble() { | |
375 bubble_.reset(); | |
376 ime_list_view_ = nullptr; | |
377 SetIsActive(false); | |
378 shelf()->UpdateAutoHideState(); | |
379 } | |
380 | |
381 bool ImeMenuTray::IsImeMenuBubbleShown() { | |
382 return !!bubble_; | |
383 } | |
384 | |
385 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) { | 364 void ImeMenuTray::ShowKeyboardWithKeyset(const std::string& keyset) { |
386 HideImeMenuBubble(); | 365 CloseBubble(); |
387 | 366 |
388 // Overrides the keyboard url ref to make it shown with the given keyset. | 367 // Overrides the keyboard url ref to make it shown with the given keyset. |
389 if (InputMethodManager::Get()) | 368 if (InputMethodManager::Get()) |
390 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset); | 369 InputMethodManager::Get()->OverrideKeyboardUrlRef(keyset); |
391 | 370 |
392 // If onscreen keyboard has been enabled, shows the keyboard directly. | 371 // If onscreen keyboard has been enabled, shows the keyboard directly. |
393 keyboard::KeyboardController* keyboard_controller = | 372 keyboard::KeyboardController* keyboard_controller = |
394 keyboard::KeyboardController::GetInstance(); | 373 keyboard::KeyboardController::GetInstance(); |
395 show_keyboard_ = true; | 374 show_keyboard_ = true; |
396 if (keyboard_controller) { | 375 if (keyboard_controller) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 return keyboard_suppressed_ && | 433 return keyboard_suppressed_ && |
455 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); | 434 !Shell::Get()->accessibility_delegate()->IsVirtualKeyboardEnabled(); |
456 } | 435 } |
457 | 436 |
458 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | 437 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
459 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 438 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
460 } | 439 } |
461 | 440 |
462 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | 441 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
463 if (bubble_->bubble_view() == bubble_view) | 442 if (bubble_->bubble_view() == bubble_view) |
464 HideImeMenuBubble(); | 443 CloseBubble(); |
465 } | 444 } |
466 | 445 |
467 void ImeMenuTray::ClickedOutsideBubble() { | 446 void ImeMenuTray::ClickedOutsideBubble() { |
468 HideImeMenuBubble(); | 447 CloseBubble(); |
469 } | 448 } |
470 | 449 |
471 bool ImeMenuTray::PerformAction(const ui::Event& event) { | 450 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
472 if (bubble_) | 451 if (bubble_) |
473 HideImeMenuBubble(); | 452 CloseBubble(); |
474 else | 453 else |
475 ShowImeMenuBubble(); | 454 ShowBubble(); |
476 return true; | 455 return true; |
477 } | 456 } |
478 | 457 |
| 458 void ImeMenuTray::CloseBubble() { |
| 459 bubble_.reset(); |
| 460 ime_list_view_ = nullptr; |
| 461 SetIsActive(false); |
| 462 shelf()->UpdateAutoHideState(); |
| 463 } |
| 464 |
| 465 void ImeMenuTray::ShowBubble() { |
| 466 keyboard::KeyboardController* keyboard_controller = |
| 467 keyboard::KeyboardController::GetInstance(); |
| 468 if (keyboard_controller && keyboard_controller->keyboard_visible()) { |
| 469 show_bubble_after_keyboard_hidden_ = true; |
| 470 keyboard_controller->AddObserver(this); |
| 471 keyboard_controller->HideKeyboard( |
| 472 keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); |
| 473 } else { |
| 474 ShowImeMenuBubbleInternal(); |
| 475 } |
| 476 } |
| 477 |
| 478 views::TrayBubbleView* ImeMenuTray::GetBubbleView() { |
| 479 return bubble_ ? bubble_->bubble_view() : nullptr; |
| 480 } |
| 481 |
479 void ImeMenuTray::OnIMERefresh() { | 482 void ImeMenuTray::OnIMERefresh() { |
480 UpdateTrayLabel(); | 483 UpdateTrayLabel(); |
481 if (bubble_ && ime_list_view_) { | 484 if (bubble_ && ime_list_view_) { |
482 ime_list_view_->Update(ime_controller_->current_ime().id, | 485 ime_list_view_->Update(ime_controller_->current_ime().id, |
483 ime_controller_->available_imes(), | 486 ime_controller_->available_imes(), |
484 ime_controller_->current_ime_menu_items(), false, | 487 ime_controller_->current_ime_menu_items(), false, |
485 ImeListView::SHOW_SINGLE_IME); | 488 ImeListView::SHOW_SINGLE_IME); |
486 } | 489 } |
487 } | 490 } |
488 | 491 |
489 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | 492 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { |
490 SetVisible(is_activated); | 493 SetVisible(is_activated); |
491 if (is_activated) | 494 if (is_activated) |
492 UpdateTrayLabel(); | 495 UpdateTrayLabel(); |
493 else | 496 else |
494 HideImeMenuBubble(); | 497 CloseBubble(); |
495 } | 498 } |
496 | 499 |
497 void ImeMenuTray::BubbleViewDestroyed() { | 500 void ImeMenuTray::BubbleViewDestroyed() { |
498 } | 501 } |
499 | 502 |
500 void ImeMenuTray::OnMouseEnteredView() {} | 503 void ImeMenuTray::OnMouseEnteredView() {} |
501 | 504 |
502 void ImeMenuTray::OnMouseExitedView() {} | 505 void ImeMenuTray::OnMouseExitedView() {} |
503 | 506 |
504 void ImeMenuTray::RegisterAccelerators( | 507 void ImeMenuTray::RegisterAccelerators( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return; | 574 return; |
572 | 575 |
573 // Posts a task to disable the virtual keyboard. | 576 // Posts a task to disable the virtual keyboard. |
574 base::ThreadTaskRunnerHandle::Get()->PostTask( | 577 base::ThreadTaskRunnerHandle::Get()->PostTask( |
575 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard, | 578 FROM_HERE, base::Bind(&ImeMenuTray::DisableVirtualKeyboard, |
576 weak_ptr_factory_.GetWeakPtr())); | 579 weak_ptr_factory_.GetWeakPtr())); |
577 } | 580 } |
578 | 581 |
579 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) { | 582 void ImeMenuTray::OnKeyboardSuppressionChanged(bool suppressed) { |
580 if (suppressed != keyboard_suppressed_ && bubble_) | 583 if (suppressed != keyboard_suppressed_ && bubble_) |
581 HideImeMenuBubble(); | 584 CloseBubble(); |
582 keyboard_suppressed_ = suppressed; | 585 keyboard_suppressed_ = suppressed; |
583 } | 586 } |
584 | 587 |
585 void ImeMenuTray::UpdateTrayLabel() { | 588 void ImeMenuTray::UpdateTrayLabel() { |
586 const mojom::ImeInfo& current_ime = ime_controller_->current_ime(); | 589 const mojom::ImeInfo& current_ime = ime_controller_->current_ime(); |
587 | 590 |
588 // Updates the tray label based on the current input method. | 591 // Updates the tray label based on the current input method. |
589 if (current_ime.third_party) | 592 if (current_ime.third_party) |
590 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*")); | 593 label_->SetText(current_ime.short_name + base::UTF8ToUTF16("*")); |
591 else | 594 else |
592 label_->SetText(current_ime.short_name); | 595 label_->SetText(current_ime.short_name); |
593 } | 596 } |
594 | 597 |
595 void ImeMenuTray::DisableVirtualKeyboard() { | 598 void ImeMenuTray::DisableVirtualKeyboard() { |
596 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); | 599 Shell::Get()->accessibility_delegate()->SetVirtualKeyboardEnabled(false); |
597 force_show_keyboard_ = false; | 600 force_show_keyboard_ = false; |
598 } | 601 } |
599 | 602 |
600 } // namespace ash | 603 } // namespace ash |
OLD | NEW |