| 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 { return kTrayImeIconSize; } |
| 31 |
| 32 private: |
| 33 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); |
| 34 }; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf) |
| 39 : TrayBackgroundView(wm_shelf), label_(new ImeMenuLabel()) { |
| 40 SetupLabelForTray(label_); |
| 41 tray_container()->AddChildView(label_); |
| 42 SetContentsBackground(); |
| 43 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); |
| 44 } |
| 45 |
| 46 ImeMenuTray::~ImeMenuTray() { |
| 47 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); |
| 48 } |
| 49 |
| 50 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 51 TrayBackgroundView::SetShelfAlignment(alignment); |
| 52 tray_container()->SetBorder(views::Border::NullBorder()); |
| 53 } |
| 54 |
| 55 base::string16 ImeMenuTray::GetAccessibleNameForTray() { |
| 56 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); |
| 57 } |
| 58 |
| 59 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { |
| 60 } |
| 61 |
| 62 void ImeMenuTray::ClickedOutsideBubble() {} |
| 63 |
| 64 bool ImeMenuTray::PerformAction(const ui::Event& event) { |
| 65 SetTrayActivation(!draw_background_as_active()); |
| 66 return true; |
| 67 } |
| 68 |
| 69 void ImeMenuTray::OnIMERefresh() { |
| 70 UpdateTrayLabel(); |
| 71 } |
| 72 |
| 73 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { |
| 74 SetVisible(is_activated); |
| 75 if (is_activated) |
| 76 UpdateTrayLabel(); |
| 77 else |
| 78 SetTrayActivation(false); |
| 79 } |
| 80 |
| 81 void ImeMenuTray::UpdateTrayLabel() { |
| 82 WmShell::Get()->system_tray_delegate()->GetCurrentIME(¤t_ime_); |
| 83 |
| 84 // Updates the tray label based on the current input method. |
| 85 if (current_ime_.third_party) |
| 86 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); |
| 87 else |
| 88 label_->SetText(current_ime_.short_name); |
| 89 } |
| 90 |
| 91 void ImeMenuTray::SetTrayActivation(bool is_active) { |
| 92 SetDrawBackgroundAsActive(is_active); |
| 93 // TODO(azurewei): Shows/hides the IME menu tray bubble based on |is_active|. |
| 94 } |
| 95 |
| 96 } // namespace ash |
| OLD | NEW |