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

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

Issue 1996563002: Add ImeMenuTray element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove window related changes. Created 4 years, 5 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
new file mode 100644
index 0000000000000000000000000000000000000000..afcd859ddc8be955573ef049b2e6040c8db44204
--- /dev/null
+++ b/ash/common/system/chromeos/ime_menu/ime_menu_tray.cc
@@ -0,0 +1,106 @@
+// 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/common/system/chromeos/ime_menu/ime_menu_tray.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_shell.h"
+#include "ash/common/wm_window.h"
+#include "base/strings/utf_string_conversions.h"
+#include "grit/ash_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/label.h"
+
+namespace ash {
+
+namespace {
+
+class ImeMenuLabel : public views::Label {
+ public:
+ ImeMenuLabel() {}
+
James Cook 2016/07/12 17:53:37 nit: ~ImeMenuLabel() override {}
Azure Wei 2016/07/14 02:57:02 Done.
+ // views:Label:
+ gfx::Size GetPreferredSize() const override {
+ return gfx::Size(kTrayImeIconSize, kTrayImeIconSize);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
+};
+
+} // namespace
+
+ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
+ : TrayBackgroundView(wm_shelf),
+ label_(new ImeMenuLabel()),
+ is_active_(false) {
+ SetupLabelForTray(label_);
+ tray_container()->AddChildView(label_);
+ SetContentsBackground();
+ WmShell::Get()->system_tray_notifier()->AddIMEObserver(this);
+}
+
+ImeMenuTray::~ImeMenuTray() {
+ WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(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) {
+ is_active_ = !is_active_;
+ SetDrawBackgroundAsActive(is_active_);
+ return true;
+}
+
+void ImeMenuTray::OnIMERefresh() {
+ UpdateTrayLabel();
+}
+
+void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) {
+ SetVisible(is_activated);
+ if (is_activated)
James Cook 2016/07/12 17:53:37 Do you need to clear is_active when is_activated =
Azure Wei 2016/07/14 02:57:02 Done.
+ UpdateTrayLabel();
+}
+
+void ImeMenuTray::UpdateTrayLabel() {
+ WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_ime_);
+
+ // 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();
James Cook 2016/07/12 17:53:37 nit: const
Azure Wei 2016/07/14 02:57:02 Removed this method.
+ int label_height = label_->height();
James Cook 2016/07/12 17:53:37 nit: ditto
+ if ((label_width != 0 && label_width < kTrayImeIconSize) ||
+ (label_height != 0 && label_height < kTrayImeIconSize)) {
+ int left_padding = (kTrayImeIconSize - label_width) / 2;
+ int top_padding = (kTrayImeIconSize - label_height) / 2;
+ int bottom_padding = kTrayImeIconSize - label_height - top_padding;
+ int right_padding = kTrayImeIconSize - label_width - left_padding;
+ label_->SetBorder(views::Border::CreateEmptyBorder(
+ top_padding, left_padding, bottom_padding, right_padding));
+ }
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698