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" | |
James Cook
2016/06/30 18:20:57
not needed
Azure Wei
2016/06/30 19:21:37
Removed.
| |
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_shell.h" | |
12 #include "ash/shell.h" | |
James Cook
2016/06/30 18:20:58
Not needed
Azure Wei
2016/06/30 19:21:38
Removed.
| |
13 #include "ash/system/status_area_widget.h" | |
14 #include "base/strings/utf_string_conversions.h" | |
15 #include "grit/ash_strings.h" | |
16 #include "ui/aura/window.h" | |
17 #include "ui/base/l10n/l10n_util.h" | |
18 #include "ui/events/event.h" | |
James Cook
2016/06/30 18:20:58
needed?
Azure Wei
2016/06/30 19:21:38
Removed.
| |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/wm/core/window_util.h" | |
21 | |
22 namespace ash { | |
23 | |
24 namespace { | |
25 | |
26 class ImeMenuLabel : public views::Label { | |
27 public: | |
28 ImeMenuLabel() : views::Label(base::string16()) {} | |
29 | |
30 // views:Label: | |
31 gfx::Size GetPreferredSize() const override { | |
32 return gfx::Size(kNotificationIconWidth, kNotificationIconWidth); | |
33 } | |
34 | |
35 private: | |
36 DISALLOW_COPY_AND_ASSIGN(ImeMenuLabel); | |
37 }; | |
38 | |
39 } // namespace | |
40 | |
41 ImeMenuTray::ImeMenuTray(StatusAreaWidget* status_area_widget) | |
James Cook
2016/06/30 18:20:58
This should take WmShelf directly, then you don't
Azure Wei
2016/06/30 19:21:37
Done.
| |
42 : TrayBackgroundView(status_area_widget->wm_shelf()), | |
43 label_(nullptr), | |
44 window_(nullptr) { | |
45 label_ = new ImeMenuLabel(); | |
46 SetupLabelForTray(label_); | |
47 tray_container()->AddChildView(label_); | |
48 SetContentsBackground(); | |
49 // The Shell may not exist in some unit tests. | |
James Cook
2016/06/30 18:20:57
Is this true? I think WmShell always exists when y
Azure Wei
2016/06/30 19:21:37
This is not necessary. Removed the HasInstance() c
| |
50 if (WmShell::HasInstance()) | |
51 WmShell::Get()->system_tray_notifier()->AddIMEObserver(this); | |
52 } | |
53 | |
54 ImeMenuTray::~ImeMenuTray() { | |
55 // The Shell may not exist in some unit tests. | |
56 if (WmShell::HasInstance()) | |
57 WmShell::Get()->system_tray_notifier()->RemoveIMEObserver(this); | |
58 if (window_) | |
59 window_->RemoveObserver(this); | |
60 } | |
61 | |
62 void ImeMenuTray::SetImeWindow(aura::Window* window) { | |
63 if (window_ == window) | |
64 return; | |
65 | |
66 // The tray could be set with different window state as there are more than | |
67 // one IME extensions to create the IME menu window. | |
68 if (window_) | |
69 window_->RemoveObserver(this); | |
70 | |
71 if (window) { | |
72 window_ = window; | |
73 window_->AddObserver(this); | |
74 } | |
75 SetDrawBackgroundAsActive(::wm::IsActiveWindow(window_)); | |
76 } | |
77 | |
78 void ImeMenuTray::SetShelfAlignment(ShelfAlignment alignment) { | |
79 TrayBackgroundView::SetShelfAlignment(alignment); | |
80 tray_container()->SetBorder(views::Border::NullBorder()); | |
81 SetLabelBorder(); | |
82 } | |
83 | |
84 base::string16 ImeMenuTray::GetAccessibleNameForTray() { | |
85 return l10n_util::GetStringUTF16(IDS_ASH_IME_MENU_ACCESSIBLE_NAME); | |
86 } | |
87 | |
88 void ImeMenuTray::HideBubbleWithView(const views::TrayBubbleView* bubble_view) { | |
89 } | |
90 | |
91 void ImeMenuTray::ClickedOutsideBubble() {} | |
92 | |
93 bool ImeMenuTray::PerformAction(const ui::Event& event) { | |
94 if (window_) { | |
95 if (::wm::IsActiveWindow(window_)) | |
96 ::wm::DeactivateWindow(window_); | |
97 else | |
98 ::wm::ActivateWindow(window_); | |
99 SetDrawBackgroundAsActive(::wm::IsActiveWindow(window_)); | |
100 } | |
101 return true; | |
102 } | |
103 | |
104 void ImeMenuTray::OnIMERefresh() { | |
105 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | |
106 delegate->GetCurrentIME(¤t_ime_); | |
107 UpdateTrayLabel(); | |
108 } | |
109 | |
110 void ImeMenuTray::OnIMEMenuActivationChanged(bool is_activated) { | |
111 SetVisible(is_activated); | |
112 if (!is_activated && window_) { | |
113 window_->RemoveObserver(this); | |
114 window_ = nullptr; | |
115 } | |
116 UpdateTrayLabel(); | |
117 } | |
118 | |
119 void ImeMenuTray::OnWindowVisibilityChanging(aura::Window* window, | |
120 bool visible) { | |
121 if (window_ == window) { | |
122 // Sets the background color based on the visiablity of the window. | |
123 SetDrawBackgroundAsActive(visible); | |
124 } | |
125 } | |
126 | |
127 void ImeMenuTray::OnWindowDestroying(aura::Window* window) { | |
128 if (window_ && window_ == window) { | |
129 window_->RemoveObserver(this); | |
130 window_ = nullptr; | |
131 SetVisible(false); | |
132 } | |
133 } | |
134 | |
135 void ImeMenuTray::UpdateTrayLabel() { | |
136 if (!window_) | |
137 return; | |
138 // Updates the tray label based on the current input method. | |
139 if (current_ime_.third_party) | |
140 label_->SetText(current_ime_.short_name + base::UTF8ToUTF16("*")); | |
141 else | |
142 label_->SetText(current_ime_.short_name); | |
143 SetLabelBorder(); | |
144 } | |
145 | |
146 void ImeMenuTray::SetLabelBorder() { | |
147 int label_width = label_->width(); | |
148 int label_height = label_->height(); | |
149 if ((label_width != 0 && label_width < kNotificationIconWidth) || | |
150 (label_height != 0 && label_height < kNotificationIconWidth)) { | |
151 int left_padding = (kNotificationIconWidth - label_width) / 2; | |
152 int top_padding = (kNotificationIconWidth - label_height) / 2; | |
153 int bottom_padding = kNotificationIconWidth - label_height - top_padding; | |
154 int right_padding = kNotificationIconWidth - label_width - left_padding; | |
155 label_->SetBorder(views::Border::CreateEmptyBorder( | |
156 top_padding, left_padding, bottom_padding, right_padding)); | |
157 } | |
158 } | |
159 | |
160 } // namespace ash | |
OLD | NEW |