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

Side by Side Diff: ui/events/test/event_generator.cc

Issue 1072193004: Take GetCharacterFromKeyCode() out behind the barn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/events/test/event_generator.h" 5 #include "ui/events/test/event_generator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if (window_context) 533 if (window_context)
534 current_location_ = delegate()->CenterOfWindow(window_context); 534 current_location_ = delegate()->CenterOfWindow(window_context);
535 current_target_ = delegate()->GetTargetAt(current_location_); 535 current_target_ = delegate()->GetTargetAt(current_location_);
536 } 536 }
537 537
538 void EventGenerator::DispatchKeyEvent(bool is_press, 538 void EventGenerator::DispatchKeyEvent(bool is_press,
539 ui::KeyboardCode key_code, 539 ui::KeyboardCode key_code,
540 int flags) { 540 int flags) {
541 #if defined(OS_WIN) 541 #if defined(OS_WIN)
542 UINT key_press = WM_KEYDOWN; 542 UINT key_press = WM_KEYDOWN;
543 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); 543 uint16 character = ui::DomCodeToUsLayoutCharacter(
544 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags);
Wez 2015/04/21 22:08:46 This changes the behaviour slightly - e.g. the top
kpschoedel 2015/04/21 22:36:38 GetCharacterFromKeyCode() was a hard-coded US layo
544 if (is_press && character) { 545 if (is_press && character) {
545 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; 546 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 };
546 TestKeyEvent keyev(native_event, flags); 547 TestKeyEvent keyev(native_event, flags);
547 Dispatch(&keyev); 548 Dispatch(&keyev);
548 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character 549 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character
549 // if the key event cooresponds to a real character. 550 // if the key event cooresponds to a real character.
550 key_press = WM_CHAR; 551 key_press = WM_CHAR;
551 key_code = static_cast<ui::KeyboardCode>(character); 552 key_code = static_cast<ui::KeyboardCode>(character);
552 } 553 }
553 MSG native_event = 554 MSG native_event =
554 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; 555 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 };
555 native_event.time = Now().InMicroseconds(); 556 native_event.time = Now().InMicroseconds();
556 TestKeyEvent keyev(native_event, flags); 557 TestKeyEvent keyev(native_event, flags);
Wez 2015/04/21 22:08:46 nit: Hadn't noticed this before... should we be (a
kpschoedel 2015/04/21 22:36:38 I've planned to visit this for crbug.com/444045
557 #elif defined(USE_X11) 558 #elif defined(USE_X11)
558 ui::ScopedXI2Event xevent; 559 ui::ScopedXI2Event xevent;
559 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, 560 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
560 key_code, 561 key_code,
561 flags); 562 flags);
562 static_cast<XEvent*>(xevent)->xkey.time = Now().InMicroseconds(); 563 static_cast<XEvent*>(xevent)->xkey.time = Now().InMicroseconds();
563 ui::KeyEvent keyev(xevent); 564 ui::KeyEvent keyev(xevent);
564 #else 565 #else
565 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; 566 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
566 ui::KeyEvent keyev(type, key_code, flags); 567 ui::KeyEvent keyev(type, key_code, flags);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return default_delegate; 659 return default_delegate;
659 } 660 }
660 661
661 EventGeneratorDelegate* EventGenerator::delegate() { 662 EventGeneratorDelegate* EventGenerator::delegate() {
662 return const_cast<EventGeneratorDelegate*>( 663 return const_cast<EventGeneratorDelegate*>(
663 const_cast<const EventGenerator*>(this)->delegate()); 664 const_cast<const EventGenerator*>(this)->delegate());
664 } 665 }
665 666
666 } // namespace test 667 } // namespace test
667 } // namespace ui 668 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698