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

Side by Side 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 unified diff | Download patch
OLDNEW
(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
James Cook 2016/07/12 17:53:37 nit: ~ImeMenuLabel() override {}
Azure Wei 2016/07/14 02:57:02 Done.
25 // views:Label:
26 gfx::Size GetPreferredSize() const override {
27 return gfx::Size(kTrayImeIconSize, kTrayImeIconSize);
28 }
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel);
32 };
33
34 } // namespace
35
36 ImeMenuTray::ImeMenuTray(WmShelf* wm_shelf)
37 : TrayBackgroundView(wm_shelf),
38 label_(new ImeMenuLabel()),
39 is_active_(false) {
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 SetLabelBorder();
54 }
55
56 base::string16 ImeMenuTray::GetAccessibleNameForTray() {
57 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME);
58 }
59
60 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) {
61 }
62
63 void ImeMenuTray::ClickedOutsideBubble() {}
64
65 bool ImeMenuTray::PerformAction(const ui::Event& event) {
66 is_active_ = !is_active_;
67 SetDrawBackgroundAsActive(is_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)
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.
78 UpdateTrayLabel();
79 }
80
81 void ImeMenuTray::UpdateTrayLabel() {
82 WmShell::Get()->system_tray_delegate()->GetCurrentIME(&current_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 SetLabelBorder();
90 }
91
92 void ImeMenuTray::SetLabelBorder() {
93 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.
94 int label_height = label_->height();
James Cook 2016/07/12 17:53:37 nit: ditto
95 if ((label_width != 0 && label_width < kTrayImeIconSize) ||
96 (label_height != 0 && label_height < kTrayImeIconSize)) {
97 int left_padding = (kTrayImeIconSize - label_width) / 2;
98 int top_padding = (kTrayImeIconSize - label_height) / 2;
99 int bottom_padding = kTrayImeIconSize - label_height - top_padding;
100 int right_padding = kTrayImeIconSize - label_width - left_padding;
101 label_->SetBorder(views::Border::CreateEmptyBorder(
102 top_padding, left_padding, bottom_padding, right_padding));
103 }
104 }
105
106 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698