OLD | NEW |
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/chromeos/tray_caps_lock.h" | 5 #include "ash/common/system/chromeos/tray_caps_lock.h" |
6 | 6 |
7 #include "ash/common/accessibility_delegate.h" | 7 #include "ash/common/accessibility_delegate.h" |
8 #include "ash/common/material_design/material_design_controller.h" | |
9 #include "ash/common/system/tray/actionable_view.h" | 8 #include "ash/common/system/tray/actionable_view.h" |
10 #include "ash/common/system/tray/system_tray_delegate.h" | 9 #include "ash/common/system/tray/system_tray_delegate.h" |
11 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
12 #include "ash/common/system/tray/tray_popup_item_style.h" | 11 #include "ash/common/system/tray/tray_popup_item_style.h" |
13 #include "ash/common/system/tray/tray_popup_utils.h" | 12 #include "ash/common/system/tray/tray_popup_utils.h" |
14 #include "ash/common/system/tray/tri_view.h" | 13 #include "ash/common/system/tray/tri_view.h" |
15 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
16 #include "ash/resources/vector_icons/vector_icons.h" | 15 #include "ash/resources/vector_icons/vector_icons.h" |
17 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
18 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), | 51 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), |
53 text_label_(TrayPopupUtils::CreateDefaultLabel()), | 52 text_label_(TrayPopupUtils::CreateDefaultLabel()), |
54 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) { | 53 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) { |
55 shortcut_label_->SetEnabled(false); | 54 shortcut_label_->SetEnabled(false); |
56 | 55 |
57 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); | 56 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); |
58 SetLayoutManager(new views::FillLayout); | 57 SetLayoutManager(new views::FillLayout); |
59 AddChildView(tri_view); | 58 AddChildView(tri_view); |
60 | 59 |
61 auto image = TrayPopupUtils::CreateMainImageView(); | 60 auto image = TrayPopupUtils::CreateMainImageView(); |
62 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 61 image->SetEnabled(enabled()); |
63 image->SetEnabled(enabled()); | 62 TrayPopupItemStyle default_view_style( |
64 TrayPopupItemStyle default_view_style( | 63 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
65 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 64 image->SetImage(gfx::CreateVectorIcon(kSystemMenuCapsLockIcon, |
66 image->SetImage(gfx::CreateVectorIcon(kSystemMenuCapsLockIcon, | 65 default_view_style.GetIconColor())); |
67 default_view_style.GetIconColor())); | 66 default_view_style.SetupLabel(text_label_); |
68 default_view_style.SetupLabel(text_label_); | 67 |
69 TrayPopupItemStyle caption_style(TrayPopupItemStyle::FontStyle::CAPTION); | 68 TrayPopupItemStyle caption_style(TrayPopupItemStyle::FontStyle::CAPTION); |
70 caption_style.SetupLabel(shortcut_label_); | 69 caption_style.SetupLabel(shortcut_label_); |
71 SetInkDropMode(InkDropHostView::InkDropMode::ON); | 70 |
72 } else { | 71 SetInkDropMode(InkDropHostView::InkDropMode::ON); |
73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 72 |
74 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK) | |
75 .ToImageSkia()); | |
76 } | |
77 tri_view->AddView(TriView::Container::START, image); | 73 tri_view->AddView(TriView::Container::START, image); |
78 tri_view->AddView(TriView::Container::CENTER, text_label_); | 74 tri_view->AddView(TriView::Container::CENTER, text_label_); |
79 tri_view->AddView(TriView::Container::END, shortcut_label_); | 75 tri_view->AddView(TriView::Container::END, shortcut_label_); |
80 tri_view->SetContainerBorder( | 76 tri_view->SetContainerBorder( |
81 TriView::Container::END, | 77 TriView::Container::END, |
82 views::CreateEmptyBorder(0, 0, 0, kCaptionRightPadding)); | 78 views::CreateEmptyBorder(0, 0, 0, kCaptionRightPadding)); |
83 } | 79 } |
84 | 80 |
85 ~CapsLockDefaultView() override {} | 81 ~CapsLockDefaultView() override {} |
86 | 82 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // It indicates whether the Caps Lock is on or off. | 129 // It indicates whether the Caps Lock is on or off. |
134 views::Label* text_label_; | 130 views::Label* text_label_; |
135 | 131 |
136 // It indicates the shortcut can be used to turn on or turn off Caps Lock. | 132 // It indicates the shortcut can be used to turn on or turn off Caps Lock. |
137 views::Label* shortcut_label_; | 133 views::Label* shortcut_label_; |
138 | 134 |
139 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); | 135 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); |
140 }; | 136 }; |
141 | 137 |
142 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) | 138 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) |
143 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK, UMA_CAPS_LOCK), | 139 : TrayImageItem(system_tray, kSystemTrayCapsLockIcon, UMA_CAPS_LOCK), |
144 default_(NULL), | 140 default_(nullptr), |
145 detailed_(NULL), | 141 detailed_(nullptr), |
146 caps_lock_enabled_(CapsLockIsEnabled()), | 142 caps_lock_enabled_(CapsLockIsEnabled()), |
147 message_shown_(false) { | 143 message_shown_(false) { |
148 chromeos::input_method::InputMethodManager* ime = | 144 chromeos::input_method::InputMethodManager* ime = |
149 chromeos::input_method::InputMethodManager::Get(); | 145 chromeos::input_method::InputMethodManager::Get(); |
150 if (ime && ime->GetImeKeyboard()) | 146 if (ime && ime->GetImeKeyboard()) |
151 ime->GetImeKeyboard()->AddObserver(this); | 147 ime->GetImeKeyboard()->AddObserver(this); |
152 } | 148 } |
153 | 149 |
154 TrayCapsLock::~TrayCapsLock() { | 150 TrayCapsLock::~TrayCapsLock() { |
155 chromeos::input_method::InputMethodManager* ime = | 151 chromeos::input_method::InputMethodManager* ime = |
(...skipping 27 matching lines...) Expand all Loading... |
183 } | 179 } |
184 } | 180 } |
185 } | 181 } |
186 | 182 |
187 bool TrayCapsLock::GetInitialVisibility() { | 183 bool TrayCapsLock::GetInitialVisibility() { |
188 return CapsLockIsEnabled(); | 184 return CapsLockIsEnabled(); |
189 } | 185 } |
190 | 186 |
191 views::View* TrayCapsLock::CreateDefaultView(LoginStatus status) { | 187 views::View* TrayCapsLock::CreateDefaultView(LoginStatus status) { |
192 if (!caps_lock_enabled_) | 188 if (!caps_lock_enabled_) |
193 return NULL; | 189 return nullptr; |
194 DCHECK(default_ == NULL); | 190 DCHECK(!default_); |
195 default_ = new CapsLockDefaultView; | 191 default_ = new CapsLockDefaultView; |
196 default_->Update(caps_lock_enabled_); | 192 default_->Update(caps_lock_enabled_); |
197 return default_; | 193 return default_; |
198 } | 194 } |
199 | 195 |
200 views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) { | 196 views::View* TrayCapsLock::CreateDetailedView(LoginStatus status) { |
201 DCHECK(detailed_ == NULL); | 197 DCHECK(!detailed_); |
202 detailed_ = new views::View; | 198 detailed_ = new views::View; |
203 | 199 |
204 detailed_->SetLayoutManager(new views::BoxLayout( | 200 detailed_->SetLayoutManager(new views::BoxLayout( |
205 views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, 10, | 201 views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal, 10, |
206 kTrayPopupPaddingBetweenItems)); | 202 kTrayPopupPaddingBetweenItems)); |
207 | 203 |
208 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 204 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
209 views::ImageView* image = new views::ImageView; | 205 views::ImageView* image = new views::ImageView; |
210 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 206 image->SetImage( |
211 image->SetImage(CreateVectorIcon(kSystemMenuCapsLockIcon, kMenuIconSize, | 207 CreateVectorIcon(kSystemMenuCapsLockIcon, kMenuIconSize, kMenuIconColor)); |
212 kMenuIconColor)); | |
213 } else { | |
214 image->SetImage( | |
215 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK).ToImageSkia()); | |
216 } | |
217 | |
218 detailed_->AddChildView(image); | 208 detailed_->AddChildView(image); |
219 | 209 |
220 const int string_id = | 210 const int string_id = |
221 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock() | 211 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock() |
222 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH | 212 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_SEARCH |
223 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH; | 213 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_CANCEL_BY_ALT_SEARCH; |
224 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | 214 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); |
225 label->SetText(bundle.GetLocalizedString(string_id)); | 215 label->SetText(bundle.GetLocalizedString(string_id)); |
226 label->SetMultiLine(true); | 216 label->SetMultiLine(true); |
227 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 217 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
228 detailed_->AddChildView(label); | 218 detailed_->AddChildView(label); |
229 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED); | 219 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_CAPS_LOCK_DETAILED); |
230 | 220 |
231 return detailed_; | 221 return detailed_; |
232 } | 222 } |
233 | 223 |
234 void TrayCapsLock::DestroyDefaultView() { | 224 void TrayCapsLock::DestroyDefaultView() { |
235 default_ = NULL; | 225 default_ = nullptr; |
236 } | 226 } |
237 | 227 |
238 void TrayCapsLock::DestroyDetailedView() { | 228 void TrayCapsLock::DestroyDetailedView() { |
239 detailed_ = NULL; | 229 detailed_ = nullptr; |
240 } | 230 } |
241 | 231 |
242 } // namespace ash | 232 } // namespace ash |
OLD | NEW |