Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/system_tray_notifier.h" | |
| 8 #include "ash/common/system/tray/tray_constants.h" | |
| 9 #include "ash/common/system/tray/tray_utils.h" | |
| 10 #include "ash/common/wm_shell.h" | |
| 11 #include "ash/common/wm_window.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "grit/ash_strings.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/views/controls/label.h" | |
| 16 | |
| 17 namespace ash { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 class ImeMenuLabel : public views::Label { | |
| 22 public: | |
| 23 ImeMenuLabel() {} | |
| 24 ~ImeMenuLabel() override {} | |
| 25 | |
| 26 // views:Label: | |
| 27 gfx::Size GetPreferredSize() const override { | |
| 28 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize); | |
| 29 } | |
| 30 int GetHeightForWidth(int width) const override { | |
| 31 return GetPreferredSize().height(); | |
|
James Cook
2016/07/14 15:47:35
nit: just return kTrayImeIconSize
Azure Wei
2016/07/15 01:58:12
Done.
| |
| 32 } | |
| 33 | |
| 34 private: | |
| 35 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); | |
| 36 }; | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) | |
| 41 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { | |
| 42 SetupLabelForTray(label_); | |
| 43 tray_container()->AddChildView(label_); | |
| 44 SetContentsBackground(); | |
| 45 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); | |
| 46 } | |
| 47 | |
| 48 ImeMenuTray::~ImeMenuTray() { | |
| 49 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); | |
| 50 } | |
| 51 | |
| 52 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { | |
| 53 TrayBackgroundView::SetShelfAlignment(alignment); | |
| 54 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 55 } | |
| 56 | |
| 57 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | |
| 58 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | |
| 59 } | |
| 60 | |
| 61 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | |
| 62 } | |
| 63 | |
| 64 void ImeMenuTray::ClickedOutsideBubble() {} | |
| 65 | |
| 66 bool ImeMenuTray::PerformAction(const ui::Event& event) { | |
| 67 SetTrayActivation(!draw_background_as_active()); | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 void ImeMenuTray::OnIMERefresh() { | |
| 72 UpdateTrayLabel(); | |
| 73 } | |
| 74 | |
| 75 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | |
| 76 SetVisible(is_activated); | |
| 77 if (is_activated) | |
| 78 UpdateTrayLabel(); | |
| 79 else | |
| 80 SetTrayActivation(false); | |
| 81 } | |
| 82 | |
| 83 void ImeMenuTray::UpdateTrayLabel() { | |
| 84 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); | |
| 85 | |
| 86 // Updates the tray label based on the current input method. | |
| 87 if (current_ime_.third_party) | |
| 88 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | |
| 89 else | |
| 90 label_->SetText(current_ime_.short_name); | |
| 91 } | |
| 92 | |
| 93 void ImeMenuTray::SetTrayActivation(bool is_active_) { | |
|
James Cook
2016/07/14 15:47:35
as above, is_active_ -> is_active
Azure Wei
2016/07/15 01:58:12
Done.
| |
| 94 SetDrawBackgroundAsActive(is_active_); | |
| 95 // TODO(azurewei): Shows/hides the IME menu tray bubble based on |is_active_|. | |
| 96 } | |
| 97 | |
| 98 } // namespace ash | |
| OLD | NEW |