OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 Loading... | |
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/17 16:42:35
Similarly, remove this comment section since it re
Shu Chen
2015/08/18 08:49:41
Done.
| |
918 // - WM_CHAR (0x0102) | |
919 // - WM_DEADCHAR (0x0103) | |
920 // And only process WM_CHAR message in browser. | |
921 // This is to combine the WM_KEY* and WM_CHAR messages in the event | |
922 // processing flow which is necessary to let Chrome IME extension to | |
923 // process the key event and perform corresponding IME actions. | |
924 // Chrome IME extension may wants to consume certain key events based | |
925 // on the character information of WM_CHAR messages. Holding WM_KEY* | |
926 // messages until WM_CHAR is processed by the IME extension is not | |
927 // feasible because there is no way to know wether there will or not | |
928 // be a WM_CHAR following the WM_KEY*. | |
929 // Chrome never handles dead chars so it is safe to remove/ignore | |
930 // WM_*DEADCHAR messages. | |
931 MSG char_msg; | |
932 while (::PeekMessage(&char_msg, msg.hwnd, WM_CHAR, WM_DEADCHAR, | |
933 PM_REMOVE)) { | |
934 if (char_msg.message == WM_DEADCHAR) | |
935 continue; | |
936 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> char_args; | |
937 char_args = mswr::Make<KeyEvent>(char_msg, true); | |
938 character_received_handler_->Invoke(this, char_args.Get()); | |
939 } | |
916 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args; | 940 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args; |
917 event_args = mswr::Make<KeyEvent>(msg); | 941 event_args = mswr::Make<KeyEvent>(msg, true); |
918 KeyEventHandler* handler = NULL; | 942 KeyEventHandler* handler = NULL; |
919 if (msg.message == WM_KEYDOWN) { | 943 if (msg.message == WM_KEYDOWN) { |
920 handler = key_down_handler_; | 944 handler = key_down_handler_; |
921 } else { | 945 } else { |
922 handler = key_up_handler_; | 946 handler = key_up_handler_; |
923 } | 947 } |
924 handler->Invoke(this, event_args.Get()); | 948 handler->Invoke(this, event_args.Get()); |
925 break; | 949 break; |
926 } | 950 } |
927 | 951 |
928 case WM_CHAR: | 952 case WM_CHAR: { |
929 case WM_DEADCHAR: | |
930 case WM_UNICHAR: { | |
931 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args; | 953 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args; |
932 event_args = mswr::Make<KeyEvent>(msg); | 954 event_args = mswr::Make<KeyEvent>(msg, false); |
933 character_received_handler_->Invoke(this, event_args.Get()); | 955 character_received_handler_->Invoke(this, event_args.Get()); |
934 break; | 956 break; |
935 } | 957 } |
936 | 958 |
937 default: | 959 default: |
938 return false; | 960 return false; |
939 } | 961 } |
940 return true; | 962 return true; |
941 } | 963 } |
942 | 964 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1218 }; | 1240 }; |
1219 | 1241 |
1220 | 1242 |
1221 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { | 1243 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { |
1222 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); | 1244 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); |
1223 if (FAILED(hr)) | 1245 if (FAILED(hr)) |
1224 CHECK(false); | 1246 CHECK(false); |
1225 return mswr::Make<CoreApplicationWin7Emulation>(); | 1247 return mswr::Make<CoreApplicationWin7Emulation>(); |
1226 } | 1248 } |
1227 | 1249 |
OLD | NEW |