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

Side by Side Diff: win8/metro_driver/metro_driver_win7.cc

Issue 1267483003: Combine the WM_CHAR with WM_KEY* for key event flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed robliao@'s comments. Created 5 years, 4 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 "stdafx.h" 5 #include "stdafx.h"
6 #include <corewindow.h> 6 #include <corewindow.h>
7 #include <shobjidl.h> 7 #include <shobjidl.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 DISALLOW_COPY_AND_ASSIGN(MouseEvent); 364 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
365 }; 365 };
366 366
367 // This class implements the winrt interfaces needed to support keyboard 367 // This class implements the winrt interfaces needed to support keyboard
368 // character and system character messages. 368 // character and system character messages.
369 class KeyEvent : public mswr::RuntimeClass< 369 class KeyEvent : public mswr::RuntimeClass<
370 winui::Core::IKeyEventArgs, 370 winui::Core::IKeyEventArgs,
371 winui::Core::ICharacterReceivedEventArgs, 371 winui::Core::ICharacterReceivedEventArgs,
372 winui::Core::IAcceleratorKeyEventArgs> { 372 winui::Core::IAcceleratorKeyEventArgs> {
373 public: 373 public:
374 KeyEvent(const MSG& msg) 374 KeyEvent(const MSG& msg, bool was_key)
375 : msg_(msg) {} 375 : msg_(msg), was_key_(was_key) {}
376 376
377 // IKeyEventArgs implementation. 377 // IKeyEventArgs implementation.
378 HRESULT STDMETHODCALLTYPE 378 HRESULT STDMETHODCALLTYPE
379 get_VirtualKey(winsys::VirtualKey* virtual_key) override { 379 get_VirtualKey(winsys::VirtualKey* virtual_key) override {
380 *virtual_key = static_cast<winsys::VirtualKey>(msg_.wParam); 380 *virtual_key = static_cast<winsys::VirtualKey>(msg_.wParam);
381 return S_OK; 381 return S_OK;
382 } 382 }
383 383
384 HRESULT STDMETHODCALLTYPE 384 HRESULT STDMETHODCALLTYPE
385 get_KeyStatus(winui::Core::CorePhysicalKeyStatus* key_status) override { 385 get_KeyStatus(winui::Core::CorePhysicalKeyStatus* key_status) override {
386 // As per msdn documentation for the keyboard messages. 386 // As per msdn documentation for the keyboard messages.
387 key_status->RepeatCount = msg_.lParam & 0x0000FFFF; 387 key_status->RepeatCount = msg_.lParam & 0x0000FFFF;
388 key_status->ScanCode = (msg_.lParam >> 16) & 0x00FF; 388 key_status->ScanCode = (msg_.lParam >> 16) & 0x00FF;
389 key_status->IsExtendedKey = (msg_.lParam & (1 << 24)); 389 key_status->IsExtendedKey = (msg_.lParam & (1 << 24));
390 key_status->IsMenuKeyDown = (msg_.lParam & (1 << 29)); 390 key_status->IsMenuKeyDown = (msg_.lParam & (1 << 29));
391 key_status->WasKeyDown = (msg_.lParam & (1 << 30));
392 key_status->IsKeyReleased = (msg_.lParam & (1 << 31)); 391 key_status->IsKeyReleased = (msg_.lParam & (1 << 31));
392 key_status->WasKeyDown = was_key_;
393 return S_OK; 393 return S_OK;
394 } 394 }
395 395
396 // ICharacterReceivedEventArgs implementation. 396 // ICharacterReceivedEventArgs implementation.
397 HRESULT STDMETHODCALLTYPE get_KeyCode(uint32* key_code) override { 397 HRESULT STDMETHODCALLTYPE get_KeyCode(uint32* key_code) override {
398 *key_code = msg_.wParam; 398 *key_code = msg_.wParam;
399 return S_OK; 399 return S_OK;
400 } 400 }
401 401
402 // IAcceleratorKeyEventArgs implementation. 402 // IAcceleratorKeyEventArgs implementation.
403 HRESULT STDMETHODCALLTYPE 403 HRESULT STDMETHODCALLTYPE
404 get_EventType(winui::Core::CoreAcceleratorKeyEventType* event_type) override { 404 get_EventType(winui::Core::CoreAcceleratorKeyEventType* event_type) override {
405 if (msg_.message == WM_SYSKEYDOWN) { 405 if (msg_.message == WM_SYSKEYDOWN) {
406 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyDown; 406 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyDown;
407 } else if (msg_.message == WM_SYSKEYUP) { 407 } else if (msg_.message == WM_SYSKEYUP) {
408 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyUp; 408 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyUp;
409 } else if (msg_.message == WM_SYSCHAR) { 409 } else if (msg_.message == WM_SYSCHAR) {
410 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemCharacter; 410 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemCharacter;
411 } 411 }
412 return S_OK; 412 return S_OK;
413 } 413 }
414 414
415 private: 415 private:
416 MSG msg_; 416 MSG msg_;
417 bool was_key_;
417 }; 418 };
418 419
419 // The following classes are the emulation of the WinRT system as exposed 420 // The following classes are the emulation of the WinRT system as exposed
420 // to metro applications. There is one application (ICoreApplication) which 421 // to metro applications. There is one application (ICoreApplication) which
421 // contains a series of Views (ICoreApplicationView) each one of them 422 // contains a series of Views (ICoreApplicationView) each one of them
422 // containing a CoreWindow which represents a surface that can drawn to 423 // containing a CoreWindow which represents a surface that can drawn to
423 // and that receives events. 424 // and that receives events.
424 // 425 //
425 // Here is the general dependency hierachy in terms of interfaces: 426 // Here is the general dependency hierachy in terms of interfaces:
426 // 427 //
(...skipping 28 matching lines...) Expand all
455 456
456 HRESULT STDMETHODCALLTYPE 457 HRESULT STDMETHODCALLTYPE
457 ProcessEvents(winui::Core::CoreProcessEventsOption options) override { 458 ProcessEvents(winui::Core::CoreProcessEventsOption options) override {
458 // We don't support the other message pump modes. So we basically enter a 459 // We don't support the other message pump modes. So we basically enter a
459 // traditional message loop that we only exit a teardown. 460 // traditional message loop that we only exit a teardown.
460 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit) 461 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit)
461 return E_FAIL; 462 return E_FAIL;
462 463
463 MSG msg = {0}; 464 MSG msg = {0};
464 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) { 465 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) {
466 ::TranslateMessage(&msg);
465 ProcessInputMessage(msg); 467 ProcessInputMessage(msg);
466 ::TranslateMessage(&msg);
467 ::DispatchMessage(&msg); 468 ::DispatchMessage(&msg);
468 } 469 }
469 // TODO(cpu): figure what to do with msg.WParam which we would normally 470 // TODO(cpu): figure what to do with msg.WParam which we would normally
470 // return here. 471 // return here.
471 return S_OK; 472 return S_OK;
472 } 473 }
473 474
474 HRESULT STDMETHODCALLTYPE 475 HRESULT STDMETHODCALLTYPE
475 RunAsync(winui::Core::CoreDispatcherPriority priority, 476 RunAsync(winui::Core::CoreDispatcherPriority priority,
476 winui::Core::IDispatchedHandler* agileCallback, 477 winui::Core::IDispatchedHandler* agileCallback,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } else if ((msg.message >= WM_MOUSEFIRST) && 516 } else if ((msg.message >= WM_MOUSEFIRST) &&
516 (msg.message <= WM_MOUSELAST)) { 517 (msg.message <= WM_MOUSELAST)) {
517 ret = input_handler_->HandleMouseMessage(msg); 518 ret = input_handler_->HandleMouseMessage(msg);
518 } 519 }
519 } 520 }
520 return ret; 521 return ret;
521 } 522 }
522 523
523 bool HandleSystemKeys(const MSG& msg) { 524 bool HandleSystemKeys(const MSG& msg) {
524 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args; 525 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args;
525 event_args = mswr::Make<KeyEvent>(msg); 526 event_args = mswr::Make<KeyEvent>(msg, true);
526 accelerator_key_event_handler_->Invoke(this, event_args.Get()); 527 accelerator_key_event_handler_->Invoke(this, event_args.Get());
527 return true; 528 return true;
528 } 529 }
529 530
530 InputHandler* input_handler_; 531 InputHandler* input_handler_;
531 AcceleratorKeyEventHandler* accelerator_key_event_handler_; 532 AcceleratorKeyEventHandler* accelerator_key_event_handler_;
532 }; 533 };
533 534
534 class CoreWindowEmulation 535 class CoreWindowEmulation
535 : public mswr::RuntimeClass< 536 : public mswr::RuntimeClass<
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 907
907 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override { 908 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override {
908 return S_OK; 909 return S_OK;
909 } 910 }
910 911
911 // InputHandler 912 // InputHandler
912 bool HandleKeyboardMessage(const MSG& msg) override { 913 bool HandleKeyboardMessage(const MSG& msg) override {
913 switch (msg.message) { 914 switch (msg.message) {
914 case WM_KEYDOWN: 915 case WM_KEYDOWN:
915 case WM_KEYUP: { 916 case WM_KEYUP: {
917 // Peek & remove the following messages in the message queue.
robliao 2015/08/14 16:42:34 Similarly, this is clear from the code below. Inst
Shu Chen 2015/08/17 04:09:21 Done.
918 // - WM_CHAR (0x0102)
919 // - WM_DEADCHAR (0x0103)
920 // And only process WM_CHAR message in browser.
921 MSG char_msg;
922 while (::PeekMessage(&char_msg, msg.hwnd, WM_CHAR, WM_DEADCHAR,
923 PM_REMOVE)) {
924 if (char_msg.message == WM_DEADCHAR)
925 continue;
926 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> char_args;
927 char_args = mswr::Make<KeyEvent>(char_msg, true);
928 character_received_handler_->Invoke(this, char_args.Get());
929 }
916 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args; 930 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args;
917 event_args = mswr::Make<KeyEvent>(msg); 931 event_args = mswr::Make<KeyEvent>(msg, true);
918 KeyEventHandler* handler = NULL; 932 KeyEventHandler* handler = NULL;
919 if (msg.message == WM_KEYDOWN) { 933 if (msg.message == WM_KEYDOWN) {
920 handler = key_down_handler_; 934 handler = key_down_handler_;
921 } else { 935 } else {
922 handler = key_up_handler_; 936 handler = key_up_handler_;
923 } 937 }
924 handler->Invoke(this, event_args.Get()); 938 handler->Invoke(this, event_args.Get());
925 break; 939 break;
926 } 940 }
927 941
928 case WM_CHAR: 942 case WM_CHAR: {
929 case WM_DEADCHAR:
930 case WM_UNICHAR: {
931 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args; 943 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args;
robliao 2015/08/14 16:42:34 Have we confirmed no one sends WM_UNICHAR to us?
Shu Chen 2015/08/17 04:09:21 Some apps may send WM_UNICHAR to us. However, Wind
932 event_args = mswr::Make<KeyEvent>(msg); 944 event_args = mswr::Make<KeyEvent>(msg, false);
933 character_received_handler_->Invoke(this, event_args.Get()); 945 character_received_handler_->Invoke(this, event_args.Get());
934 break; 946 break;
935 } 947 }
936 948
937 default: 949 default:
938 return false; 950 return false;
939 } 951 }
940 return true; 952 return true;
941 } 953 }
942 954
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 }; 1230 };
1219 1231
1220 1232
1221 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 1233 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
1222 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 1234 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1223 if (FAILED(hr)) 1235 if (FAILED(hr))
1224 CHECK(false); 1236 CHECK(false);
1225 return mswr::Make<CoreApplicationWin7Emulation>(); 1237 return mswr::Make<CoreApplicationWin7Emulation>();
1226 } 1238 }
1227 1239
OLDNEW
« ui/base/ime/input_method_win.cc ('K') | « win8/metro_driver/chrome_app_view_ash.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698