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/system/chromeos/ime_menu/ime_menu_tray.h" | |
| 6 | |
| 7 #include "ash/aura/wm_window_aura.h" | |
| 8 #include "ash/common/system/tray/tray_constants.h" | |
| 9 #include "ash/common/system/tray/tray_utils.h" | |
| 10 #include "ash/common/wm/window_state.h" | |
| 11 #include "ash/common/wm_shell.h" | |
| 12 #include "ash/shell.h" | |
| 13 #include "ash/system/tray/system_tray_notifier.h" | |
| 14 #include "ash/wm/window_state_aura.h" | |
| 15 #include "ash/wm/window_util.h" | |
| 16 #include "base/strings/utf_string_conversions.h" | |
| 17 #include "grit/ash_strings.h" | |
| 18 #include "ui/aura/window.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 #include "ui/events/event.h" | |
| 21 #include "ui/views/controls/label.h" | |
| 22 | |
| 23 namespace ash { | |
| 24 | |
| 25 class ImeMenuLabel : public views::Label { | |
| 26 public: | |
| 27 ImeMenuLabel() : views::Label(base::string16()) {} | |
| 28 | |
| 29 gfx::Size GetPreferredSize() const override { | |
|
sadrul
2016/06/20 16:18:12
// views:Label:
Azure Wei
2016/06/22 01:47:10
Done.
| |
| 30 return gfx::Size(kTrayBarButtonWidth, kTrayBarButtonWidth); | |
| 31 } | |
| 32 }; | |
|
sadrul
2016/06/20 16:18:12
DISALLOW_COPY_AND_ASSIGN
Azure Wei
2016/06/22 01:47:10
Done.
| |
| 33 | |
| 34 ImeMenuTray::ImeMenuTray(StatusAreaWidget* status_area_widget) | |
| 35 : TrayBackgroundView(status_area_widget), | |
| 36 label_(nullptr), | |
| 37 window_state_(nullptr) { | |
| 38 label_ = new ImeMenuLabel(); | |
| 39 SetupLabelForTray(label_); | |
| 40 tray_container()->AddChildView(label_); | |
| 41 SetContentsBackground(); | |
| 42 // The Shell may not exist in some unit tests. | |
| 43 if (Shell::HasInstance()) | |
| 44 Shell::GetInstance()->system_tray_notifier()->AddIMEObserver(this); | |
| 45 } | |
| 46 | |
| 47 ImeMenuTray::~ImeMenuTray() { | |
| 48 // The Shell may not exist in some unit tests. | |
| 49 if (Shell::HasInstance()) | |
| 50 Shell::GetInstance()->system_tray_notifier()->RemoveIMEObserver(this); | |
| 51 if (window_state_) { | |
| 52 window_state_->RemoveObserver(this); | |
| 53 GetAuraWindow()->RemoveObserver(this); | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { | |
| 58 TrayBackgroundView::SetShelfAlignment(alignment); | |
| 59 tray_container()->SetBorder(views::Border::NullBorder()); | |
| 60 SetLabelBorder(); | |
| 61 } | |
| 62 | |
| 63 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | |
| 64 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | |
| 65 } | |
| 66 | |
| 67 void ImeMenuTray::SetLabelBorder() { | |
| 68 int label_width = label_->width(); | |
| 69 int label_height = label_->height(); | |
| 70 if ((label_width != 0 && label_width < kTrayBarButtonWidth) || | |
| 71 (label_height != 0 && label_height < kTrayBarButtonWidth)) { | |
| 72 int left_padding = (kTrayBarButtonWidth - label_width) / 2; | |
| 73 int top_padding = (kTrayBarButtonWidth - label_height) / 2; | |
| 74 int bottom_padding = kTrayBarButtonWidth - label_height - top_padding; | |
| 75 int right_padding = kTrayBarButtonWidth - label_width - left_padding; | |
| 76 label_->SetBorder(views::Border::CreateEmptyBorder( | |
| 77 top_padding, left_padding, bottom_padding, right_padding)); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | |
| 82 } | |
| 83 | |
| 84 void ImeMenuTray::ClickedOutsideBubble() {} | |
| 85 | |
| 86 bool ImeMenuTray::PerformAction(const ui::Event& event) { | |
| 87 if (window_state_) { | |
| 88 if (window_state_->IsMinimized()) | |
| 89 window_state_->Unminimize(); | |
| 90 else | |
| 91 window_state_->Minimize(); | |
| 92 } | |
| 93 return true; | |
| 94 } | |
| 95 | |
| 96 void ImeMenuTray::UpdateTray() { | |
| 97 if (!window_state_) | |
| 98 return; | |
| 99 // Sets the background color based on the window state. | |
| 100 SetDrawBackgroundAsActive(!window_state_->IsMinimized()); | |
| 101 // Updates the tray label base on the current input method. | |
| 102 if (current_ime_.third_party) | |
| 103 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | |
| 104 else | |
| 105 label_->SetText(current_ime_.short_name); | |
| 106 SetLabelBorder(); | |
| 107 } | |
| 108 | |
| 109 void ImeMenuTray::OnIMERefresh() { | |
| 110 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
| 111 delegate->GetCurrentIME(¤t_ime_); | |
| 112 UpdateTray(); | |
| 113 } | |
| 114 | |
| 115 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | |
| 116 SetVisible(is_activated); | |
| 117 if (!is_activated && window_state_) { | |
| 118 window_state_->RemoveObserver(this); | |
| 119 window_state_ = nullptr; | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void ImeMenuTray::OnPostWindowStateTypeChange(wm::WindowState* window_state, | |
| 124 wm::WindowStateType old_type) { | |
| 125 window_state_ = window_state; | |
|
sadrul
2016/06/20 16:18:12
This should be a DCHECK_EQ(window_state_, window_s
Azure Wei
2016/06/22 01:47:10
Done.
| |
| 126 UpdateTray(); | |
| 127 } | |
| 128 | |
| 129 void ImeMenuTray::OnWindowDestroying(aura::Window* window) { | |
| 130 if (window_state_) { | |
| 131 window_state_->RemoveObserver(this); | |
| 132 GetAuraWindow()->RemoveObserver(this); | |
| 133 window_state_ = nullptr; | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 aura::Window* ImeMenuTray::GetAuraWindow() { | |
| 138 return WmWindowAura::GetAuraWindow(window_state_->window()); | |
| 139 } | |
| 140 | |
| 141 void ImeMenuTray::SetWindowState(wm::WindowState* window_state) { | |
| 142 window_state_ = window_state; | |
| 143 window_state_->AddObserver(this); | |
| 144 GetAuraWindow()->AddObserver(this); | |
| 145 } | |
| 146 | |
| 147 base::string16 ImeMenuTray::GetLabelTextForTest() { | |
|
sadrul
2016/06/20 16:18:12
function order in .cc should match the order in .h
Azure Wei
2016/06/22 01:47:10
Done.
| |
| 148 return label_->text(); | |
| 149 } | |
| 150 | |
| 151 } // namespace ash | |
| OLD | NEW |