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

Unified Diff: ash/common/system/chromeos/ime_menu/ime_menu_tray.cc

Issue 2271483003: Updates the IME list when the IME has refreshed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
diff --git a/ash/common/system/chromeos/ime_menu/ime_menu_tray.cc b/ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
index 4453ad526b30efb48793162702654a6623ea204a..ab60289ff456d2e84551fcecdaefc946af8be8b7 100644
--- a/ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
+++ b/ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
@@ -138,6 +138,60 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
} // namespace
+// Class to wrap and manage the ImeListView, ImeButtonsView and
+// TrayBubbleWrapper instances for the IME menu bubble.
+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
+ public:
+ 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.
+
+ // Initializes the bubble view and creates |bubble_wrapper_|.
+ void InitView() {
+ views::TrayBubbleView::InitParams init_params(
+ views::TrayBubbleView::ANCHOR_TYPE_TRAY, tray_->GetAnchorAlignment(),
+ kTrayPopupMinWidth, kTrayPopupMaxWidth);
+ init_params.first_item_has_no_margin = true;
+ init_params.can_activate = true;
+ init_params.close_on_deactivate = true;
+
+ views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create(
+ tray_->tray_container(), tray_, &init_params);
+ bubble_view->set_margins(gfx::Insets(7, 0, 0, 0));
+ bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
+
+ list_view_.reset(
+ new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME));
+
+ // Adds IME list to the bubble.
+ 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.
+
+ // Adds IME buttons to the bubble if needed.
+ LoginStatus login =
+ WmShell::Get()->system_tray_delegate()->GetUserLoginStatus();
+ if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED &&
+ !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen())
+ button_view_.reset(new ImeButtonsView(false, false, false, true));
+ bubble_view->AddChildView(button_view_.get());
James Cook 2016/08/23 16:38:33 ditto
Azure Wei 2016/08/24 05:22:43 Done.
+ 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.
+ }
+
+ // Returns the bubble view.
+ views::TrayBubbleView* bubble_view() const {
+ if (bubble_wrapper_.get()) {
James Cook 2016/08/23 16:38:32 nit: no {}
Azure Wei 2016/08/24 05:22:43 Done.
+ return bubble_wrapper_->bubble_view();
+ }
+ return nullptr;
+ }
+
+ // Returns the ImeListView.
+ ImeListView* list_view() const { return list_view_.get(); }
+
+ private:
+ ImeMenuTray* tray_;
+ std::unique_ptr<ImeListView> list_view_;
+ std::unique_ptr<ImeButtonsView> button_view_;
+ std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_;
+};
James Cook 2016/08/23 16:38:32 DISALLOW_COPY_AND_ASSIGN
Azure Wei 2016/08/24 05:22:43 Removed this class.
+
ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
: TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) {
SetupLabelForTray(label_);
@@ -179,6 +233,15 @@ bool ImeMenuTray::PerformAction(const ui::Event& event) {
void ImeMenuTray::OnIMERefresh() {
UpdateTrayLabel();
+ if (bubble_ && bubble_->list_view()) {
+ SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
+ IMEInfoList list;
+ delegate->GetAvailableIMEList(&list);
+ IMEPropertyInfoList property_list;
+ delegate->GetCurrentIMEProperties(&property_list);
+ bubble_->list_view()->Update(list, property_list, false,
+ ImeListView::SHOW_SINGLE_IME);
+ }
}
void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
@@ -248,30 +311,8 @@ void ImeMenuTray::UpdateTrayLabel() {
}
void ImeMenuTray::ShowImeMenuBubble() {
- views::TrayBubbleView::InitParams init_params(
- views::TrayBubbleView::ANCHOR_TYPE_TRAY, GetAnchorAlignment(),
- kTrayPopupMinWidth, kTrayPopupMaxWidth);
- init_params.first_item_has_no_margin = true;
- init_params.can_activate = true;
- init_params.close_on_deactivate = true;
-
- views::TrayBubbleView* bubble_view =
- views::TrayBubbleView::Create(tray_container(), this, &init_params);
- bubble_view->set_margins(gfx::Insets(7, 0, 0, 0));
- bubble_view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
-
- // Adds IME list to the bubble.
- bubble_view->AddChildView(
- new ImeListView(nullptr, false, ImeListView::SHOW_SINGLE_IME));
-
- // Adds IME buttons to the bubble if needed.
- LoginStatus login =
- WmShell::Get()->system_tray_delegate()->GetUserLoginStatus();
- if (login != LoginStatus::NOT_LOGGED_IN && login != LoginStatus::LOCKED &&
- !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen())
- bubble_view->AddChildView(new ImeButtonsView(false, false, false, true));
-
- bubble_.reset(new ash::TrayBubbleWrapper(this, bubble_view));
+ bubble_.reset(new ImeBubbleWrapper(this));
+ bubble_->InitView();
SetDrawBackgroundAsActive(true);
}
@@ -280,4 +321,9 @@ void ImeMenuTray::HideImeMenuBubble() {
SetDrawBackgroundAsActive(false);
}
+// Returns ture if the bubble has been shown.
+bool ImeMenuTray::IsBubbleShownForTesting() {
+ 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.
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698