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

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

Powered by Google App Engine
This is Rietveld 408576698