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

Side by Side Diff: ash/common/system/ime/tray_ime_chromeos.cc

Issue 2781793002: Remove non-MD code for IME tray and tray menu. (Closed)
Patch Set: resources Created 3 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/ime/tray_ime_chromeos.h" 5 #include "ash/common/system/ime/tray_ime_chromeos.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/system/tray/hover_highlight_view.h" 10 #include "ash/common/system/tray/hover_highlight_view.h"
tdanderson 2017/03/28 22:30:39 I think this can be removed too
Evan Stade 2017/03/28 22:47:39 Done.
12 #include "ash/common/system/tray/system_tray.h" 11 #include "ash/common/system/tray/system_tray.h"
13 #include "ash/common/system/tray/system_tray_controller.h" 12 #include "ash/common/system/tray/system_tray_controller.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 13 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/system_tray_notifier.h" 14 #include "ash/common/system/tray/system_tray_notifier.h"
16 #include "ash/common/system/tray/tray_constants.h" 15 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_details_view.h" 16 #include "ash/common/system/tray/tray_details_view.h"
18 #include "ash/common/system/tray/tray_item_more.h" 17 #include "ash/common/system/tray/tray_item_more.h"
19 #include "ash/common/system/tray/tray_item_view.h" 18 #include "ash/common/system/tray/tray_item_view.h"
20 #include "ash/common/system/tray/tray_popup_item_style.h" 19 #include "ash/common/system/tray/tray_popup_item_style.h"
21 #include "ash/common/system/tray/tray_popup_utils.h" 20 #include "ash/common/system/tray/tray_popup_utils.h"
22 #include "ash/common/system/tray/tray_utils.h" 21 #include "ash/common/system/tray/tray_utils.h"
23 #include "ash/common/system/tray/tri_view.h" 22 #include "ash/common/system/tray/tri_view.h"
24 #include "ash/common/system/tray_accessibility.h" 23 #include "ash/common/system/tray_accessibility.h"
25 #include "ash/common/wm_shell.h" 24 #include "ash/common/wm_shell.h"
26 #include "ash/resources/grit/ash_resources.h"
27 #include "ash/resources/vector_icons/vector_icons.h" 25 #include "ash/resources/vector_icons/vector_icons.h"
28 #include "ash/shell.h" 26 #include "ash/shell.h"
29 #include "ash/strings/grit/ash_strings.h" 27 #include "ash/strings/grit/ash_strings.h"
30 #include "base/logging.h" 28 #include "base/logging.h"
31 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
32 #include "ui/accessibility/ax_enums.h" 30 #include "ui/accessibility/ax_enums.h"
33 #include "ui/accessibility/ax_node_data.h" 31 #include "ui/accessibility/ax_node_data.h"
34 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/font.h" 33 #include "ui/gfx/font.h"
37 #include "ui/gfx/image/image.h" 34 #include "ui/gfx/image/image.h"
38 #include "ui/gfx/paint_vector_icon.h" 35 #include "ui/gfx/paint_vector_icon.h"
39 #include "ui/keyboard/keyboard_util.h" 36 #include "ui/keyboard/keyboard_util.h"
40 #include "ui/views/controls/image_view.h" 37 #include "ui/views/controls/image_view.h"
41 #include "ui/views/controls/label.h" 38 #include "ui/views/controls/label.h"
42 #include "ui/views/layout/box_layout.h" 39 #include "ui/views/layout/box_layout.h"
43 #include "ui/views/widget/widget.h" 40 #include "ui/views/widget/widget.h"
44 41
45 namespace ash { 42 namespace ash {
46 namespace tray { 43 namespace tray {
47 44
48 // A |HoverHighlightView| that uses bold or normal font depending on whether
49 // it is selected. This view exposes itself as a checkbox to the accessibility
50 // framework.
51 class SelectableHoverHighlightView : public HoverHighlightView {
52 public:
53 SelectableHoverHighlightView(ViewClickListener* listener,
54 const base::string16& label,
55 bool selected)
56 : HoverHighlightView(listener), selected_(selected) {
57 AddLabel(label, gfx::ALIGN_LEFT, selected);
58 }
59
60 ~SelectableHoverHighlightView() override {}
61
62 protected:
63 // Overridden from views::View.
64 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
65 HoverHighlightView::GetAccessibleNodeData(node_data);
66 node_data->role = ui::AX_ROLE_CHECK_BOX;
67 if (selected_)
68 node_data->AddStateFlag(ui::AX_STATE_CHECKED);
69 }
70
71 private:
72 bool selected_;
73
74 DISALLOW_COPY_AND_ASSIGN(SelectableHoverHighlightView);
75 };
76
77 class IMEDefaultView : public TrayItemMore { 45 class IMEDefaultView : public TrayItemMore {
78 public: 46 public:
79 IMEDefaultView(SystemTrayItem* owner, const base::string16& label) 47 IMEDefaultView(SystemTrayItem* owner, const base::string16& label)
80 : TrayItemMore(owner) { 48 : TrayItemMore(owner) {
81 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 49 SetImage(gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, kMenuIconColor));
82 SetImage(gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, kMenuIconColor));
83 } else {
84 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
85 SetImage(*bundle.GetImageNamed(IDR_AURA_UBER_TRAY_IME).ToImageSkia());
86 }
87 UpdateLabel(label); 50 UpdateLabel(label);
88 } 51 }
89 52
90 ~IMEDefaultView() override {} 53 ~IMEDefaultView() override {}
91 54
92 void UpdateLabel(const base::string16& label) { 55 void UpdateLabel(const base::string16& label) {
93 SetLabel(label); 56 SetLabel(label);
94 SetAccessibleName(label); 57 SetAccessibleName(label);
95 } 58 }
96 59
97 protected: 60 protected:
98 // TrayItemMore: 61 // TrayItemMore:
99 void UpdateStyle() override { 62 void UpdateStyle() override {
100 TrayItemMore::UpdateStyle(); 63 TrayItemMore::UpdateStyle();
101 64
102 if (!MaterialDesignController::IsSystemTrayMenuMaterial())
103 return;
104
105 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); 65 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle();
106 SetImage( 66 SetImage(
107 gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, style->GetIconColor())); 67 gfx::CreateVectorIcon(kSystemMenuKeyboardIcon, style->GetIconColor()));
108 } 68 }
109 69
110 private: 70 private:
111 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView); 71 DISALLOW_COPY_AND_ASSIGN(IMEDefaultView);
112 }; 72 };
113 73
114 class IMEDetailedView : public ImeListView { 74 class IMEDetailedView : public ImeListView {
115 public: 75 public:
116 IMEDetailedView(SystemTrayItem* owner, LoginStatus login) 76 IMEDetailedView(SystemTrayItem* owner, LoginStatus login)
117 : ImeListView(owner), 77 : ImeListView(owner), login_(login), settings_button_(nullptr) {}
118 login_(login),
119 settings_(nullptr),
120 settings_button_(nullptr) {}
121 78
122 ~IMEDetailedView() override {} 79 ~IMEDetailedView() override {}
123 80
124 void SetImeManagedMessage(base::string16 ime_managed_message) { 81 void SetImeManagedMessage(base::string16 ime_managed_message) {
125 ime_managed_message_ = ime_managed_message; 82 ime_managed_message_ = ime_managed_message;
126 } 83 }
127 84
128 void Update(const IMEInfoList& list, 85 void Update(const IMEInfoList& list,
129 const IMEPropertyInfoList& property_list, 86 const IMEPropertyInfoList& property_list,
130 bool show_keyboard_toggle, 87 bool show_keyboard_toggle,
131 SingleImeBehavior single_ime_behavior) override { 88 SingleImeBehavior single_ime_behavior) override {
132 ImeListView::Update(list, property_list, show_keyboard_toggle, 89 ImeListView::Update(list, property_list, show_keyboard_toggle,
133 single_ime_behavior); 90 single_ime_behavior);
134 if (!MaterialDesignController::IsSystemTrayMenuMaterial() &&
135 TrayPopupUtils::CanOpenWebUISettings(login_)) {
136 AppendSettings();
137 }
138
139 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME); 91 CreateTitleRow(IDS_ASH_STATUS_TRAY_IME);
140 } 92 }
141 93
142 private: 94 private:
143 // ImeListView: 95 // ImeListView:
144 void HandleViewClicked(views::View* view) override {
145 ImeListView::HandleViewClicked(view);
146 if (view == settings_)
147 ShowSettings();
148 }
149
150 void ResetImeListView() override { 96 void ResetImeListView() override {
151 ImeListView::ResetImeListView(); 97 ImeListView::ResetImeListView();
152 settings_button_ = nullptr; 98 settings_button_ = nullptr;
153 controlled_setting_icon_ = nullptr; 99 controlled_setting_icon_ = nullptr;
154 } 100 }
155 101
156 void HandleButtonPressed(views::Button* sender, 102 void HandleButtonPressed(views::Button* sender,
157 const ui::Event& event) override { 103 const ui::Event& event) override {
158 ImeListView::HandleButtonPressed(sender, event); 104 ImeListView::HandleButtonPressed(sender, event);
159 if (sender == settings_button_) 105 if (sender == settings_button_)
160 ShowSettings(); 106 ShowSettings();
161 } 107 }
162 108
163 void CreateExtraTitleRowButtons() override { 109 void CreateExtraTitleRowButtons() override {
164 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 110 if (!ime_managed_message_.empty()) {
165 if (!ime_managed_message_.empty()) { 111 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView();
166 controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView(); 112 controlled_setting_icon_->SetImage(
167 controlled_setting_icon_->SetImage( 113 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor));
168 gfx::CreateVectorIcon(kSystemMenuBusinessIcon, kMenuIconColor)); 114 controlled_setting_icon_->SetTooltipText(ime_managed_message_);
169 controlled_setting_icon_->SetTooltipText(ime_managed_message_); 115 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_);
170 tri_view()->AddView(TriView::Container::END, controlled_setting_icon_); 116 }
171 }
172 117
173 tri_view()->SetContainerVisible(TriView::Container::END, true); 118 tri_view()->SetContainerVisible(TriView::Container::END, true);
174 settings_button_ = 119 settings_button_ =
175 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_IME_SETTINGS); 120 CreateSettingsButton(login_, IDS_ASH_STATUS_TRAY_IME_SETTINGS);
176 tri_view()->AddView(TriView::Container::END, settings_button_); 121 tri_view()->AddView(TriView::Container::END, settings_button_);
177 }
178 }
179
180 void AppendSettings() {
181 HoverHighlightView* container = new HoverHighlightView(this);
182 container->AddLabel(
183 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
184 IDS_ASH_STATUS_TRAY_IME_SETTINGS),
185 gfx::ALIGN_LEFT, false /* highlight */);
186 AddChildView(container);
187 settings_ = container;
188 } 122 }
189 123
190 void ShowSettings() { 124 void ShowSettings() {
191 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED); 125 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_IME_SHOW_DETAILED);
192 Shell::Get()->system_tray_controller()->ShowIMESettings(); 126 Shell::Get()->system_tray_controller()->ShowIMESettings();
193 if (owner()->system_tray()) 127 if (owner()->system_tray())
194 owner()->system_tray()->CloseSystemBubble(); 128 owner()->system_tray()->CloseSystemBubble();
195 } 129 }
196 130
197 LoginStatus login_; 131 LoginStatus login_;
198 132
199 // Not used in material design.
200 views::View* settings_;
201
202 // Only used in material design.
203 views::Button* settings_button_; 133 views::Button* settings_button_;
204 134
205 // This icon says that the IMEs are managed by policy. 135 // This icon says that the IMEs are managed by policy.
206 views::ImageView* controlled_setting_icon_; 136 views::ImageView* controlled_setting_icon_;
207 // If non-empty, a controlled setting icon should be displayed with this 137 // If non-empty, a controlled setting icon should be displayed with this
208 // string as tooltip. 138 // string as tooltip.
209 base::string16 ime_managed_message_; 139 base::string16 ime_managed_message_;
210 140
211 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView); 141 DISALLOW_COPY_AND_ASSIGN(IMEDetailedView);
212 }; 142 };
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) { 212 base::string16 TrayIME::GetDefaultViewLabel(bool show_ime_label) {
283 if (show_ime_label) { 213 if (show_ime_label) {
284 IMEInfo current; 214 IMEInfo current;
285 Shell::Get()->system_tray_delegate()->GetCurrentIME(&current); 215 Shell::Get()->system_tray_delegate()->GetCurrentIME(&current);
286 return current.name; 216 return current.name;
287 } else { 217 } else {
288 // Display virtual keyboard status instead. 218 // Display virtual keyboard status instead.
289 int id = keyboard::IsKeyboardEnabled() 219 int id = keyboard::IsKeyboardEnabled()
290 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED 220 ? IDS_ASH_STATUS_TRAY_KEYBOARD_ENABLED
291 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED; 221 : IDS_ASH_STATUS_TRAY_KEYBOARD_DISABLED;
292 return ui::ResourceBundle::GetSharedInstance().GetLocalizedString(id); 222 return l10n_util::GetStringUTF16(id);
293 } 223 }
294 } 224 }
295 225
296 views::View* TrayIME::CreateTrayView(LoginStatus status) { 226 views::View* TrayIME::CreateTrayView(LoginStatus status) {
297 CHECK(tray_label_ == NULL); 227 CHECK(tray_label_ == NULL);
298 tray_label_ = new TrayItemView(this); 228 tray_label_ = new TrayItemView(this);
299 tray_label_->CreateLabel(); 229 tray_label_->CreateLabel();
300 SetupLabelForTray(tray_label_->label()); 230 SetupLabelForTray(tray_label_->label());
301 // Hide IME tray when it is created, it will be updated when it is notified 231 // Hide IME tray when it is created, it will be updated when it is notified
302 // of the IME refresh event. 232 // of the IME refresh event.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return ime_count >= threshold; 300 return ime_count >= threshold;
371 } 301 }
372 302
373 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() { 303 ImeListView::SingleImeBehavior TrayIME::GetSingleImeBehavior() {
374 // If managed, we also want to show a single IME. 304 // If managed, we also want to show a single IME.
375 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME 305 return IsIMEManaged() ? ImeListView::SHOW_SINGLE_IME
376 : ImeListView::HIDE_SINGLE_IME; 306 : ImeListView::HIDE_SINGLE_IME;
377 } 307 }
378 308
379 } // namespace ash 309 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698