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

Side by Side Diff: ash/wm/sticky_keys.cc

Issue 81863002: Sticky keys modifies an entire scroll sequence instead of just a single event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebasing Created 7 years 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
« no previous file with comments | « ash/wm/sticky_keys.h ('k') | ash/wm/sticky_keys_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/wm/sticky_keys.h" 5 #include "ash/wm/sticky_keys.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/extensions/XInput2.h> 8 #include <X11/extensions/XInput2.h>
9 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
10 #undef RootWindow 10 #undef RootWindow
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 /////////////////////////////////////////////////////////////////////////////// 167 ///////////////////////////////////////////////////////////////////////////////
168 // StickyKeysHandler 168 // StickyKeysHandler
169 StickyKeysHandler::StickyKeysHandler(ui::EventFlags target_modifier_flag, 169 StickyKeysHandler::StickyKeysHandler(ui::EventFlags target_modifier_flag,
170 StickyKeysHandlerDelegate* delegate) 170 StickyKeysHandlerDelegate* delegate)
171 : modifier_flag_(target_modifier_flag), 171 : modifier_flag_(target_modifier_flag),
172 current_state_(DISABLED), 172 current_state_(DISABLED),
173 event_from_myself_(false), 173 event_from_myself_(false),
174 preparing_to_enable_(false), 174 preparing_to_enable_(false),
175 scroll_delta_(0),
175 delegate_(delegate) { 176 delegate_(delegate) {
176 } 177 }
177 178
178 StickyKeysHandler::~StickyKeysHandler() { 179 StickyKeysHandler::~StickyKeysHandler() {
179 } 180 }
180 181
181 StickyKeysHandler::StickyKeysHandlerDelegate::StickyKeysHandlerDelegate() { 182 StickyKeysHandler::StickyKeysHandlerDelegate::StickyKeysHandlerDelegate() {
182 } 183 }
183 184
184 StickyKeysHandler::StickyKeysHandlerDelegate::~StickyKeysHandlerDelegate() { 185 StickyKeysHandler::StickyKeysHandlerDelegate::~StickyKeysHandlerDelegate() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return true; 217 return true;
217 } 218 }
218 219
219 return false; 220 return false;
220 } 221 }
221 222
222 bool StickyKeysHandler::HandleScrollEvent(ui::ScrollEvent* event) { 223 bool StickyKeysHandler::HandleScrollEvent(ui::ScrollEvent* event) {
223 if (event_from_myself_ || current_state_ == DISABLED) 224 if (event_from_myself_ || current_state_ == DISABLED)
224 return false; 225 return false;
225 DCHECK(current_state_ == ENABLED || current_state_ == LOCKED); 226 DCHECK(current_state_ == ENABLED || current_state_ == LOCKED);
227 preparing_to_enable_ = false;
226 228
227 preparing_to_enable_ = false; 229 // We detect a direction change if the current |scroll_delta_| is assigned
228 AppendModifier(event); 230 // and the offset of the current scroll event has the opposing sign.
229 if (current_state_ == ENABLED) { 231 bool direction_changed = false;
232 if (current_state_ == ENABLED && event->type() == ui::ET_SCROLL) {
233 int offset = event->y_offset();
234 if (scroll_delta_)
235 direction_changed = offset * scroll_delta_ <= 0;
236 scroll_delta_ = offset;
237 }
238
239 if (!direction_changed)
240 AppendModifier(event);
241
242 // We want to modify all the scroll events in the scroll sequence, which ends
243 // with a fling start event. We also stop when the scroll sequence changes
244 // direction.
245 if (current_state_ == ENABLED &&
246 (event->type() == ui::ET_SCROLL_FLING_START || direction_changed)) {
230 current_state_ = DISABLED; 247 current_state_ = DISABLED;
248 scroll_delta_ = 0;
231 DispatchEventAndReleaseModifier(event); 249 DispatchEventAndReleaseModifier(event);
232 return true; 250 return true;
233 } 251 }
234 252
235 return false; 253 return false;
236 } 254 }
237 255
238 StickyKeysHandler::KeyEventType 256 StickyKeysHandler::KeyEventType
239 StickyKeysHandler::TranslateKeyEvent(ui::KeyEvent* event) { 257 StickyKeysHandler::TranslateKeyEvent(ui::KeyEvent* event) {
240 bool is_target_key = false; 258 bool is_target_key = false;
(...skipping 20 matching lines...) Expand all
261 } 279 }
262 return event->type() == ui::ET_KEY_PRESSED ? 280 return event->type() == ui::ET_KEY_PRESSED ?
263 OTHER_MODIFIER_DOWN : OTHER_MODIFIER_UP; 281 OTHER_MODIFIER_DOWN : OTHER_MODIFIER_UP;
264 } 282 }
265 283
266 bool StickyKeysHandler::HandleDisabledState(ui::KeyEvent* event) { 284 bool StickyKeysHandler::HandleDisabledState(ui::KeyEvent* event) {
267 switch (TranslateKeyEvent(event)) { 285 switch (TranslateKeyEvent(event)) {
268 case TARGET_MODIFIER_UP: 286 case TARGET_MODIFIER_UP:
269 if (preparing_to_enable_) { 287 if (preparing_to_enable_) {
270 preparing_to_enable_ = false; 288 preparing_to_enable_ = false;
289 scroll_delta_ = 0;
271 current_state_ = ENABLED; 290 current_state_ = ENABLED;
272 modifier_up_event_.reset(event->Copy()); 291 modifier_up_event_.reset(event->Copy());
273 return true; 292 return true;
274 } 293 }
275 return false; 294 return false;
276 case TARGET_MODIFIER_DOWN: 295 case TARGET_MODIFIER_DOWN:
277 preparing_to_enable_ = true; 296 preparing_to_enable_ = true;
278 return false; 297 return false;
279 case NORMAL_KEY_DOWN: 298 case NORMAL_KEY_DOWN:
280 preparing_to_enable_ = false; 299 preparing_to_enable_ = false;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 &xievent->mods.effective)); 437 &xievent->mods.effective));
419 } 438 }
420 } 439 }
421 #elif defined(USE_OZONE) 440 #elif defined(USE_OZONE)
422 NOTIMPLEMENTED() << "Modifier key is not handled"; 441 NOTIMPLEMENTED() << "Modifier key is not handled";
423 #endif 442 #endif
424 event->set_flags(event->flags() | modifier_flag_); 443 event->set_flags(event->flags() | modifier_flag_);
425 } 444 }
426 445
427 } // namespace ash 446 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/sticky_keys.h ('k') | ash/wm/sticky_keys_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698