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

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: 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
« no previous file with comments | « win8/metro_driver/chrome_app_view_ash.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 29 matching lines...) Expand all
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) {
465 ProcessInputMessage(msg); 466 ProcessInputMessage(msg);
466 ::TranslateMessage(&msg); 467 // Don't call TranslateMessage() here but call TranslateMessage() in
468 // InputMethodWin, so that the WM_KEYDOWN/WM_KEYUP & WM_CHAR can be
469 // combined for key event flow. The combination of key events is required
470 // for Chrome IMEs, which can do IME related actions based on the single
471 // key event.
467 ::DispatchMessage(&msg); 472 ::DispatchMessage(&msg);
468 } 473 }
469 // TODO(cpu): figure what to do with msg.WParam which we would normally 474 // TODO(cpu): figure what to do with msg.WParam which we would normally
470 // return here. 475 // return here.
471 return S_OK; 476 return S_OK;
472 } 477 }
473 478
474 HRESULT STDMETHODCALLTYPE 479 HRESULT STDMETHODCALLTYPE
475 RunAsync(winui::Core::CoreDispatcherPriority priority, 480 RunAsync(winui::Core::CoreDispatcherPriority priority,
476 winui::Core::IDispatchedHandler* agileCallback, 481 winui::Core::IDispatchedHandler* agileCallback,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } else if ((msg.message >= WM_MOUSEFIRST) && 520 } else if ((msg.message >= WM_MOUSEFIRST) &&
516 (msg.message <= WM_MOUSELAST)) { 521 (msg.message <= WM_MOUSELAST)) {
517 ret = input_handler_->HandleMouseMessage(msg); 522 ret = input_handler_->HandleMouseMessage(msg);
518 } 523 }
519 } 524 }
520 return ret; 525 return ret;
521 } 526 }
522 527
523 bool HandleSystemKeys(const MSG& msg) { 528 bool HandleSystemKeys(const MSG& msg) {
524 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args; 529 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args;
525 event_args = mswr::Make<KeyEvent>(msg); 530 event_args = mswr::Make<KeyEvent>(msg, true);
526 accelerator_key_event_handler_->Invoke(this, event_args.Get()); 531 accelerator_key_event_handler_->Invoke(this, event_args.Get());
527 return true; 532 return true;
528 } 533 }
529 534
530 InputHandler* input_handler_; 535 InputHandler* input_handler_;
531 AcceleratorKeyEventHandler* accelerator_key_event_handler_; 536 AcceleratorKeyEventHandler* accelerator_key_event_handler_;
532 }; 537 };
533 538
534 class CoreWindowEmulation 539 class CoreWindowEmulation
535 : public mswr::RuntimeClass< 540 : public mswr::RuntimeClass<
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 911
907 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override { 912 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override {
908 return S_OK; 913 return S_OK;
909 } 914 }
910 915
911 // InputHandler 916 // InputHandler
912 bool HandleKeyboardMessage(const MSG& msg) override { 917 bool HandleKeyboardMessage(const MSG& msg) override {
913 switch (msg.message) { 918 switch (msg.message) {
914 case WM_KEYDOWN: 919 case WM_KEYDOWN:
915 case WM_KEYUP: { 920 case WM_KEYUP: {
921 ::TranslateMessage(&msg);
922 // Peek & remove the following messages in the message queue.
923 // - WM_CHAR (0x0102)
924 // - WM_DEADCHAR (0x0103)
925 // - WM_UNICHAR (0x0109)
926 // And for WM_UNICHAR, call DefWindowProc() to generate WM_CHAR.
927 // And only process WM_CHAR message in browser.
928 MSG char_msg;
929 while (::PeekMessage(&char_msg, msg.hwnd, WM_UNICHAR, WM_UNICHAR,
James Su 2015/08/07 04:55:55 did you try any unichar use case? As far as I unde
Shu Chen 2015/08/07 06:02:50 The change here is just for double insurance to ma
930 PM_REMOVE)) {
931 ::DefWindowProc(
932 msg.hwnd, WM_UNICHAR, char_msg.wParam, char_msg.lParam);
933 }
934 while (::PeekMessage(&char_msg, msg.hwnd, WM_CHAR, WM_DEADCHAR,
935 PM_REMOVE)) {
936 if (char_msg.message == WM_DEADCHAR)
937 continue;
938 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> char_args;
939 char_args = mswr::Make<KeyEvent>(char_msg, true);
940 character_received_handler_->Invoke(this, char_args.Get());
941 }
916 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args; 942 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args;
917 event_args = mswr::Make<KeyEvent>(msg); 943 event_args = mswr::Make<KeyEvent>(msg, true);
918 KeyEventHandler* handler = NULL; 944 KeyEventHandler* handler = NULL;
919 if (msg.message == WM_KEYDOWN) { 945 if (msg.message == WM_KEYDOWN) {
920 handler = key_down_handler_; 946 handler = key_down_handler_;
921 } else { 947 } else {
922 handler = key_up_handler_; 948 handler = key_up_handler_;
923 } 949 }
924 handler->Invoke(this, event_args.Get()); 950 handler->Invoke(this, event_args.Get());
925 break; 951 break;
926 } 952 }
927 953
928 case WM_CHAR: 954 case WM_CHAR: {
929 case WM_DEADCHAR:
930 case WM_UNICHAR: {
931 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args; 955 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args;
932 event_args = mswr::Make<KeyEvent>(msg); 956 event_args = mswr::Make<KeyEvent>(msg, false);
933 character_received_handler_->Invoke(this, event_args.Get()); 957 character_received_handler_->Invoke(this, event_args.Get());
934 break; 958 break;
935 } 959 }
936 960
937 default: 961 default:
938 return false; 962 return false;
939 } 963 }
940 return true; 964 return true;
941 } 965 }
942 966
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 }; 1242 };
1219 1243
1220 1244
1221 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 1245 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
1222 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 1246 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1223 if (FAILED(hr)) 1247 if (FAILED(hr))
1224 CHECK(false); 1248 CHECK(false);
1225 return mswr::Make<CoreApplicationWin7Emulation>(); 1249 return mswr::Make<CoreApplicationWin7Emulation>();
1226 } 1250 }
1227 1251
OLDNEW
« no previous file with comments | « 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