| Index: ash/system/chromeos/ime_menu/ime_menu_tray.cc
|
| diff --git a/ash/system/chromeos/ime_menu/ime_menu_tray.cc b/ash/system/chromeos/ime_menu/ime_menu_tray.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1403d1f6cf8163849b76f04201d3056cb73a4b66
|
| --- /dev/null
|
| +++ b/ash/system/chromeos/ime_menu/ime_menu_tray.cc
|
| @@ -0,0 +1,151 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/system/chromeos/ime_menu/ime_menu_tray.h"
|
| +
|
| +#include "ash/aura/wm_window_aura.h"
|
| +#include "ash/common/system/tray/system_tray_notifier.h"
|
| +#include "ash/common/system/tray/tray_constants.h"
|
| +#include "ash/common/system/tray/tray_utils.h"
|
| +#include "ash/common/wm/window_state.h"
|
| +#include "ash/common/wm_shell.h"
|
| +#include "ash/shell.h"
|
| +#include "ash/system/status_area_widget.h"
|
| +#include "ash/wm/window_state_aura.h"
|
| +#include "ash/wm/window_util.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "grit/ash_strings.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/views/controls/label.h"
|
| +
|
| +namespace ash {
|
| +
|
| +namespace {
|
| +
|
| +class ImeMenuLabel : public views::Label {
|
| + public:
|
| + ImeMenuLabel() : views::Label(base::string16()) {}
|
| +
|
| + // views:Label:
|
| + gfx::Size GetPreferredSize() const override {
|
| + return gfx::Size(kNotificationIconWidth, kNotificationIconWidth);
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +ImeMenuTray::ImeMenuTray(StatusAreaWidget* status_area_widget)
|
| + : TrayBackgroundView(status_area_widget->wm_shelf()),
|
| + label_(nullptr),
|
| + window_state_(nullptr) {
|
| + label_ = new ImeMenuLabel();
|
| + SetupLabelForTray(label_);
|
| + tray_container()->AddChildView(label_);
|
| + SetContentsBackground();
|
| + // The Shell may not exist in some unit tests.
|
| + if (WmShell::HasInstance())
|
| + WmShell::Get()->system_tray_notifier()->AddIMEObserver(this);
|
| +}
|
| +
|
| +ImeMenuTray::~ImeMenuTray() {
|
| + // The Shell may not exist in some unit tests.
|
| + if (WmShell::HasInstance())
|
| + WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this);
|
| + if (window_state_)
|
| + window_state_->RemoveObserver(this);
|
| +}
|
| +
|
| +void ImeMenuTray::SetWindowState(wm::WindowState* window_state) {
|
| + if (window_state_ == window_state)
|
| + return;
|
| +
|
| + // The tray could be set with different window state as there are more than
|
| + // one IME extensions to create the IME menu window.
|
| + if (window_state_)
|
| + window_state_->RemoveObserver(this);
|
| +
|
| + if (window_state) {
|
| + window_state_ = window_state;
|
| + window_state_->AddObserver(this);
|
| + }
|
| +}
|
| +
|
| +void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) {
|
| + TrayBackgroundView::SetShelfAlignment(alignment);
|
| + tray_container()->SetBorder(views::Border::NullBorder());
|
| + SetLabelBorder();
|
| +}
|
| +
|
| +base::string16 ImeMenuTray::GetAccessibleNameForTray() {
|
| + return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
|
| +}
|
| +
|
| +void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
|
| +}
|
| +
|
| +void ImeMenuTray::ClickedOutsideBubble() {}
|
| +
|
| +bool ImeMenuTray::PerformAction(const ui::Event& event) {
|
| + if (window_state_) {
|
| + if (window_state_->IsActive())
|
| + window_state_->Deactivate();
|
| + else
|
| + window_state_->Activate();
|
| + SetDrawBackgroundAsActive(window_state_->IsActive());
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +void ImeMenuTray::OnIMERefresh() {
|
| + SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate();
|
| + delegate->GetCurrentIME(¤t_ime_);
|
| + UpdateTray();
|
| +}
|
| +
|
| +void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
|
| + SetVisible(is_activated);
|
| + if (!is_activated && window_state_) {
|
| + window_state_->RemoveObserver(this);
|
| + window_state_ = nullptr;
|
| + }
|
| +}
|
| +
|
| +void ImeMenuTray::OnPostWindowStateTypeChange(wm::WindowState* window_state,
|
| + wm::WindowStateType old_type) {
|
| + DCHECK_EQ(window_state_, window_state);
|
| + UpdateTray();
|
| +}
|
| +
|
| +void ImeMenuTray::UpdateTray() {
|
| + if (!window_state_)
|
| + return;
|
| + // Sets the background color based on the window state.
|
| + SetDrawBackgroundAsActive(window_state_->IsActive());
|
| + // Updates the tray label based on the current input method.
|
| + if (current_ime_.third_party)
|
| + label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*"));
|
| + else
|
| + label_->SetText(current_ime_.short_name);
|
| + SetLabelBorder();
|
| +}
|
| +
|
| +void ImeMenuTray::SetLabelBorder() {
|
| + int label_width = label_->width();
|
| + int label_height = label_->height();
|
| + if ((label_width != 0 && label_width < kNotificationIconWidth) ||
|
| + (label_height != 0 && label_height < kNotificationIconWidth)) {
|
| + int left_padding = (kNotificationIconWidth - label_width) / 2;
|
| + int top_padding = (kNotificationIconWidth - label_height) / 2;
|
| + int bottom_padding = kNotificationIconWidth - label_height - top_padding;
|
| + int right_padding = kNotificationIconWidth - label_width - left_padding;
|
| + label_->SetBorder(views::Border::CreateEmptyBorder(
|
| + top_padding, left_padding, bottom_padding, right_padding));
|
| + }
|
| +}
|
| +
|
| +} // namespace ash
|
|
|