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

Side by Side Diff: ash/common/system/chromeos/tray_caps_lock.cc

Issue 2661023006: Remove unused references to NativeTheme in TrayPopupItemStyle. (Closed)
Patch Set: slight improvement Created 3 years, 10 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/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" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/system/tray/actionable_view.h" 9 #include "ash/common/system/tray/actionable_view.h"
10 #include "ash/common/system/tray/system_tray_delegate.h" 10 #include "ash/common/system/tray/system_tray_delegate.h"
11 #include "ash/common/system/tray/tray_constants.h" 11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_popup_item_style.h" 12 #include "ash/common/system/tray/tray_popup_item_style.h"
13 #include "ash/common/system/tray/tray_popup_utils.h" 13 #include "ash/common/system/tray/tray_popup_utils.h"
14 #include "ash/common/system/tray/tri_view.h" 14 #include "ash/common/system/tray/tri_view.h"
15 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
16 #include "ash/resources/vector_icons/vector_icons.h" 16 #include "ash/resources/vector_icons/vector_icons.h"
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "grit/ash_resources.h" 18 #include "grit/ash_resources.h"
19 #include "grit/ash_strings.h" 19 #include "grit/ash_strings.h"
20 #include "ui/accessibility/ax_node_data.h" 20 #include "ui/accessibility/ax_node_data.h"
21 #include "ui/base/ime/chromeos/ime_keyboard.h" 21 #include "ui/base/ime/chromeos/ime_keyboard.h"
22 #include "ui/base/ime/chromeos/input_method_manager.h" 22 #include "ui/base/ime/chromeos/input_method_manager.h"
23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
26 #include "ui/views/border.h" 27 #include "ui/views/border.h"
27 #include "ui/views/controls/image_view.h" 28 #include "ui/views/controls/image_view.h"
28 #include "ui/views/controls/label.h" 29 #include "ui/views/controls/label.h"
29 #include "ui/views/layout/box_layout.h" 30 #include "ui/views/layout/box_layout.h"
30 #include "ui/views/layout/fill_layout.h" 31 #include "ui/views/layout/fill_layout.h"
31 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
32 33
33 namespace ash { 34 namespace ash {
34 namespace { 35 namespace {
35 36
36 // Padding used to position the caption in the caps lock default view row. 37 // Padding used to position the caption in the caps lock default view row.
37 const int kCaptionRightPadding = 6; 38 const int kCaptionRightPadding = 6;
38 39
39 bool CapsLockIsEnabled() { 40 bool CapsLockIsEnabled() {
40 chromeos::input_method::InputMethodManager* ime = 41 chromeos::input_method::InputMethodManager* ime =
41 chromeos::input_method::InputMethodManager::Get(); 42 chromeos::input_method::InputMethodManager::Get();
42 return (ime && ime->GetImeKeyboard()) 43 return (ime && ime->GetImeKeyboard())
43 ? ime->GetImeKeyboard()->CapsLockIsEnabled() 44 ? ime->GetImeKeyboard()->CapsLockIsEnabled()
44 : false; 45 : false;
45 } 46 }
46 } 47 }
47 48
48 class CapsLockDefaultView : public ActionableView { 49 class CapsLockDefaultView : public ActionableView {
49 public: 50 public:
50 CapsLockDefaultView() 51 CapsLockDefaultView()
51 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), 52 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
52 image_(TrayPopupUtils::CreateMainImageView()),
53 text_label_(TrayPopupUtils::CreateDefaultLabel()), 53 text_label_(TrayPopupUtils::CreateDefaultLabel()),
54 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) { 54 shortcut_label_(TrayPopupUtils::CreateDefaultLabel()) {
55 shortcut_label_->SetEnabled(false); 55 shortcut_label_->SetEnabled(false);
56 56
57 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); 57 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView());
58 SetLayoutManager(new views::FillLayout); 58 SetLayoutManager(new views::FillLayout);
59 AddChildView(tri_view); 59 AddChildView(tri_view);
60 60
61 auto image = TrayPopupUtils::CreateMainImageView();
61 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { 62 if (MaterialDesignController::UseMaterialDesignSystemIcons()) {
62 image_->SetEnabled(enabled()); 63 image->SetEnabled(enabled());
63 UpdateStyle(); 64 TrayPopupItemStyle default_view_style(
65 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
66 image->SetImage(gfx::CreateVectorIcon(kSystemMenuCapsLockIcon,
67 default_view_style.GetIconColor()));
68 default_view_style.SetupLabel(text_label_);
69 TrayPopupItemStyle caption_style(TrayPopupItemStyle::FontStyle::CAPTION);
70 caption_style.SetupLabel(shortcut_label_);
64 SetInkDropMode(InkDropHostView::InkDropMode::ON); 71 SetInkDropMode(InkDropHostView::InkDropMode::ON);
65 } else { 72 } else {
66 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 73 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
67 image_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK) 74 image->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAPS_LOCK_DARK)
68 .ToImageSkia()); 75 .ToImageSkia());
69 } 76 }
70 tri_view->AddView(TriView::Container::START, image_); 77 tri_view->AddView(TriView::Container::START, image);
71 tri_view->AddView(TriView::Container::CENTER, text_label_); 78 tri_view->AddView(TriView::Container::CENTER, text_label_);
72 tri_view->AddView(TriView::Container::END, shortcut_label_); 79 tri_view->AddView(TriView::Container::END, shortcut_label_);
73 tri_view->SetContainerBorder( 80 tri_view->SetContainerBorder(
74 TriView::Container::END, 81 TriView::Container::END,
75 views::CreateEmptyBorder(0, 0, 0, kCaptionRightPadding)); 82 views::CreateEmptyBorder(0, 0, 0, kCaptionRightPadding));
76 } 83 }
77 84
78 ~CapsLockDefaultView() override {} 85 ~CapsLockDefaultView() override {}
79 86
80 // Updates the label text and the shortcut text. 87 // Updates the label text and the shortcut text.
81 void Update(bool caps_lock_enabled) { 88 void Update(bool caps_lock_enabled) {
82 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
83 const int text_string_id = caps_lock_enabled 89 const int text_string_id = caps_lock_enabled
84 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED 90 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_ENABLED
85 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED; 91 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_DISABLED;
86 text_label_->SetText(bundle.GetLocalizedString(text_string_id)); 92 text_label_->SetText(l10n_util::GetStringUTF16(text_string_id));
87 93
88 int shortcut_string_id = 0; 94 int shortcut_string_id = 0;
89 bool search_mapped_to_caps_lock = 95 bool search_mapped_to_caps_lock =
90 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock(); 96 WmShell::Get()->system_tray_delegate()->IsSearchKeyMappedToCapsLock();
91 if (caps_lock_enabled) { 97 if (caps_lock_enabled) {
92 shortcut_string_id = 98 shortcut_string_id =
93 search_mapped_to_caps_lock 99 search_mapped_to_caps_lock
94 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT 100 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH_OR_SHIFT
95 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT; 101 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH_OR_SHIFT;
96 } else { 102 } else {
97 shortcut_string_id = 103 shortcut_string_id =
98 search_mapped_to_caps_lock 104 search_mapped_to_caps_lock
99 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH 105 ? IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_SEARCH
100 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH; 106 : IDS_ASH_STATUS_TRAY_CAPS_LOCK_SHORTCUT_ALT_SEARCH;
101 } 107 }
102 shortcut_label_->SetText(bundle.GetLocalizedString(shortcut_string_id)); 108 shortcut_label_->SetText(l10n_util::GetStringUTF16(shortcut_string_id));
103 109
104 UpdateStyle();
105 Layout(); 110 Layout();
106 } 111 }
107 112
108 // ActionableView:
109 void OnNativeThemeChanged(const ui::NativeTheme* theme) override {
110 ActionableView::OnNativeThemeChanged(theme);
111 UpdateStyle();
112 }
113
114 private: 113 private:
115 void GetAccessibleNodeData(ui::AXNodeData* node_data) override { 114 void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
116 node_data->role = ui::AX_ROLE_BUTTON; 115 node_data->role = ui::AX_ROLE_BUTTON;
117 node_data->SetName(text_label_->text()); 116 node_data->SetName(text_label_->text());
118 } 117 }
119 118
120 // Update the Text theme and style based on the current theme.
121 void UpdateStyle() {
122 TrayPopupItemStyle default_view_style(
123 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
124 // Set image and label styles for Material Design Caps Lock default view.
125 image_->SetImage(gfx::CreateVectorIcon(kSystemMenuCapsLockIcon,
126 default_view_style.GetIconColor()));
127 default_view_style.SetupLabel(text_label_);
128 TrayPopupItemStyle caption_style(GetNativeTheme(),
129 TrayPopupItemStyle::FontStyle::CAPTION);
130 caption_style.SetupLabel(shortcut_label_);
131 }
132
133 // ActionableView: 119 // ActionableView:
134 bool PerformAction(const ui::Event& event) override { 120 bool PerformAction(const ui::Event& event) override {
135 chromeos::input_method::ImeKeyboard* keyboard = 121 chromeos::input_method::ImeKeyboard* keyboard =
136 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard(); 122 chromeos::input_method::InputMethodManager::Get()->GetImeKeyboard();
137 if (keyboard) { 123 if (keyboard) {
138 WmShell::Get()->RecordUserMetricsAction( 124 WmShell::Get()->RecordUserMetricsAction(
139 keyboard->CapsLockIsEnabled() 125 keyboard->CapsLockIsEnabled()
140 ? UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK 126 ? UMA_STATUS_AREA_CAPS_LOCK_DISABLED_BY_CLICK
141 : UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK); 127 : UMA_STATUS_AREA_CAPS_LOCK_ENABLED_BY_CLICK);
142 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled()); 128 keyboard->SetCapsLockEnabled(!keyboard->CapsLockIsEnabled());
143 } 129 }
144 return true; 130 return true;
145 } 131 }
146 132
147 // It contains the image represents the Caps Lock.
148 views::ImageView* image_;
149
150 // It indicates whether the Caps Lock is on or off. 133 // It indicates whether the Caps Lock is on or off.
151 views::Label* text_label_; 134 views::Label* text_label_;
152 135
153 // It indicates the shortcut can be used to turn on or turn off Caps Lock. 136 // It indicates the shortcut can be used to turn on or turn off Caps Lock.
154 views::Label* shortcut_label_; 137 views::Label* shortcut_label_;
155 138
156 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); 139 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView);
157 }; 140 };
158 141
159 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) 142 TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 233
251 void TrayCapsLock::DestroyDefaultView() { 234 void TrayCapsLock::DestroyDefaultView() {
252 default_ = NULL; 235 default_ = NULL;
253 } 236 }
254 237
255 void TrayCapsLock::DestroyDetailedView() { 238 void TrayCapsLock::DestroyDetailedView() {
256 detailed_ = NULL; 239 detailed_ = NULL;
257 } 240 }
258 241
259 } // namespace ash 242 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/screen_security/screen_tray_item.cc ('k') | ash/common/system/chromeos/tray_tracing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698