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

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

Issue 231753002: Fixing caps lock problems under ChromeOS where the tray does not properly follow the real caps lock… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
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/system/chromeos/tray_caps_lock.h" 5 #include "ash/system/chromeos/tray_caps_lock.h"
6 6
7 #include "ash/metrics/user_metrics_recorder.h" 7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/tray/actionable_view.h" 9 #include "ash/system/tray/actionable_view.h"
10 #include "ash/system/tray/fixed_sized_image_view.h" 10 #include "ash/system/tray/fixed_sized_image_view.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView); 123 DISALLOW_COPY_AND_ASSIGN(CapsLockDefaultView);
124 }; 124 };
125 125
126 TrayCapsLock::TrayCapsLock(SystemTray* system_tray) 126 TrayCapsLock::TrayCapsLock(SystemTray* system_tray)
127 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK), 127 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_CAPS_LOCK),
128 default_(NULL), 128 default_(NULL),
129 detailed_(NULL), 129 detailed_(NULL),
130 caps_lock_enabled_(CapsLockIsEnabled()), 130 caps_lock_enabled_(CapsLockIsEnabled()),
131 message_shown_(false) { 131 message_shown_(false) {
132 // Make sure the event is processed by this before the IME. 132 chromeos::input_method::XKeyboard* xkeyboard =
133 Shell::GetInstance()->PrependPreTargetHandler(this); 133 chromeos::input_method::InputMethodManager::Get()->GetXKeyboard();
134 xkeyboard->AddObserver(this);
134 } 135 }
135 136
136 TrayCapsLock::~TrayCapsLock() { 137 TrayCapsLock::~TrayCapsLock() {
137 Shell::GetInstance()->RemovePreTargetHandler(this); 138 chromeos::input_method::XKeyboard* xkeyboard =
139 chromeos::input_method::InputMethodManager::Get()->GetXKeyboard();
140 xkeyboard->RemoveObserver(this);
138 } 141 }
139 142
140 void TrayCapsLock::OnCapsLockChanged(bool enabled) { 143 void TrayCapsLock::OnCapsLockChanged() {
144 caps_lock_enabled_ = !caps_lock_enabled_;
Daniel Erat 2014/04/09 20:27:00 i don't like this -- it seems like it's too easy t
Mr4D (OOO till 08-26) 2014/04/09 23:27:02 Done!
145
141 if (tray_view()) 146 if (tray_view())
142 tray_view()->SetVisible(enabled); 147 tray_view()->SetVisible(caps_lock_enabled_);
143
144 caps_lock_enabled_ = enabled;
145 148
146 if (default_) { 149 if (default_) {
147 default_->Update(enabled); 150 default_->Update(caps_lock_enabled_);
148 } else { 151 } else {
149 if (enabled) { 152 if (caps_lock_enabled_) {
150 if (!message_shown_) { 153 if (!message_shown_) {
151 Shell::GetInstance()->metrics()->RecordUserMetricsAction( 154 Shell::GetInstance()->metrics()->RecordUserMetricsAction(
152 ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP); 155 ash::UMA_STATUS_AREA_CAPS_LOCK_POPUP);
153 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 156 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
154 message_shown_ = true; 157 message_shown_ = true;
155 } 158 }
156 } else if (detailed_) { 159 } else if (detailed_) {
157 detailed_->GetWidget()->Close(); 160 detailed_->GetWidget()->Close();
158 } 161 }
159 } 162 }
160 } 163 }
161 164
162 void TrayCapsLock::OnKeyEvent(ui::KeyEvent* key) {
163 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_CAPITAL)
164 OnCapsLockChanged(!caps_lock_enabled_);
165 }
166
167 bool TrayCapsLock::GetInitialVisibility() { 165 bool TrayCapsLock::GetInitialVisibility() {
168 return CapsLockIsEnabled(); 166 return CapsLockIsEnabled();
169 } 167 }
170 168
171 views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) { 169 views::View* TrayCapsLock::CreateDefaultView(user::LoginStatus status) {
172 if (!caps_lock_enabled_) 170 if (!caps_lock_enabled_)
173 return NULL; 171 return NULL;
174 DCHECK(default_ == NULL); 172 DCHECK(default_ == NULL);
175 default_ = new CapsLockDefaultView; 173 default_ = new CapsLockDefaultView;
176 default_->Update(caps_lock_enabled_); 174 default_->Update(caps_lock_enabled_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 206
209 void TrayCapsLock::DestroyDefaultView() { 207 void TrayCapsLock::DestroyDefaultView() {
210 default_ = NULL; 208 default_ = NULL;
211 } 209 }
212 210
213 void TrayCapsLock::DestroyDetailedView() { 211 void TrayCapsLock::DestroyDetailedView() {
214 detailed_ = NULL; 212 detailed_ = NULL;
215 } 213 }
216 214
217 } // namespace ash 215 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698