| 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/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
| 8 #include "ash/common/ash_constants.h" | 8 #include "ash/common/ash_constants.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 ImeMenuTray::~ImeMenuTray() { | 311 ImeMenuTray::~ImeMenuTray() { |
| 312 if (bubble_) | 312 if (bubble_) |
| 313 bubble_->bubble_view()->reset_delegate(); | 313 bubble_->bubble_view()->reset_delegate(); |
| 314 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); | 314 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void ImeMenuTray::ShowImeMenuBubble() { | 317 void ImeMenuTray::ShowImeMenuBubble() { |
| 318 should_block_shelf_auto_hide_ = true; | 318 should_block_shelf_auto_hide_ = true; |
| 319 views::TrayBubbleView::InitParams init_params( | 319 views::TrayBubbleView::InitParams init_params( |
| 320 views::TrayBubbleView::ANCHOR_TYPE_TRAY, GetAnchorAlignment(), | 320 GetAnchorAlignment(), kTrayPopupMinWidth, kTrayPopupMaxWidth); |
| 321 kTrayPopupMinWidth, kTrayPopupMaxWidth); | |
| 322 init_params.first_item_has_no_margin = true; | |
| 323 init_params.can_activate = true; | 321 init_params.can_activate = true; |
| 324 init_params.close_on_deactivate = true; | 322 init_params.close_on_deactivate = true; |
| 325 | 323 |
| 326 views::TrayBubbleView* bubble_view = | 324 views::TrayBubbleView* bubble_view = |
| 327 views::TrayBubbleView::Create(tray_container(), this, &init_params); | 325 views::TrayBubbleView::Create(GetBubbleAnchor(), this, &init_params); |
| 328 bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 326 bubble_view->set_anchor_view_insets(GetBubbleAnchorInsets()); |
| 329 | 327 |
| 330 // In the material design, we will add a title item with a separator on the | 328 // In the material design, we will add a title item with a separator on the |
| 331 // top of the IME menu. | 329 // top of the IME menu. |
| 332 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { | 330 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 333 bubble_view->SetLayoutManager( | 331 bubble_view->SetLayoutManager( |
| 334 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 332 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 335 bubble_view->AddChildView( | 333 bubble_view->AddChildView( |
| 336 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); | 334 new ImeTitleView(!ShouldShowEmojiHandwritingVoiceButtons())); |
| 337 } else { | 335 } else { |
| 338 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); | 336 bubble_view->set_margins(gfx::Insets(7, 0, 0, 0)); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 } | 481 } |
| 484 | 482 |
| 485 void ImeMenuTray::OnMouseEnteredView() {} | 483 void ImeMenuTray::OnMouseEnteredView() {} |
| 486 | 484 |
| 487 void ImeMenuTray::OnMouseExitedView() {} | 485 void ImeMenuTray::OnMouseExitedView() {} |
| 488 | 486 |
| 489 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { | 487 base::string16 ImeMenuTray::GetAccessibleNameForBubble() { |
| 490 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | 488 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 491 } | 489 } |
| 492 | 490 |
| 493 gfx::Rect ImeMenuTray::GetAnchorRect(views::Widget* anchor_widget, | |
| 494 AnchorType anchor_type, | |
| 495 AnchorAlignment anchor_alignment) const { | |
| 496 gfx::Rect rect = | |
| 497 GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | |
| 498 | |
| 499 if (IsHorizontalAlignment(shelf_alignment())) { | |
| 500 // Moves the bubble to make its center aligns the center of the tray. | |
| 501 int horizontal_offset = | |
| 502 -rect.width() + (tray_container()->width() + kTrayPopupMinWidth) / 2; | |
| 503 rect.Offset(horizontal_offset, 0); | |
| 504 } else { | |
| 505 // For vertical alignment, sets the bubble's bottom aligned to the bottom | |
| 506 // of the icon for now. | |
| 507 int vertical_offset = -rect.height() + tray_container()->height(); | |
| 508 rect.Offset(0, vertical_offset); | |
| 509 } | |
| 510 return rect; | |
| 511 } | |
| 512 | |
| 513 void ImeMenuTray::OnBeforeBubbleWidgetInit( | 491 void ImeMenuTray::OnBeforeBubbleWidgetInit( |
| 514 views::Widget* anchor_widget, | 492 views::Widget* anchor_widget, |
| 515 views::Widget* bubble_widget, | 493 views::Widget* bubble_widget, |
| 516 views::Widget::InitParams* params) const { | 494 views::Widget::InitParams* params) const { |
| 517 // Place the bubble in the same root window as |anchor_widget|. | 495 // Place the bubble in the same root window as |anchor_widget|. |
| 518 WmLookup::Get() | 496 WmLookup::Get() |
| 519 ->GetWindowForWidget(anchor_widget) | 497 ->GetWindowForWidget(anchor_widget) |
| 520 ->GetRootWindowController() | 498 ->GetRootWindowController() |
| 521 ->ConfigureWidgetInitParamsForContainer( | 499 ->ConfigureWidgetInitParamsForContainer( |
| 522 bubble_widget, kShellWindowId_SettingBubbleContainer, params); | 500 bubble_widget, kShellWindowId_SettingBubbleContainer, params); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); | 541 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); |
| 564 | 542 |
| 565 // Updates the tray label based on the current input method. | 543 // Updates the tray label based on the current input method. |
| 566 if (current_ime_.third_party) | 544 if (current_ime_.third_party) |
| 567 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | 545 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); |
| 568 else | 546 else |
| 569 label_->SetText(current_ime_.short_name); | 547 label_->SetText(current_ime_.short_name); |
| 570 } | 548 } |
| 571 | 549 |
| 572 } // namespace ash | 550 } // namespace ash |
| OLD | NEW |