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

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 yukawa@'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/base_switches.h"
10 #include "base/command_line.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/profiler/scoped_tracker.h" 12 #include "base/profiler/scoped_tracker.h"
11 #include "ui/gfx/geometry/safe_integer_conversions.h" 13 #include "ui/gfx/geometry/safe_integer_conversions.h"
12 #include "ui/gfx/win/msg_util.h" 14 #include "ui/gfx/win/msg_util.h"
13 15
14 #pragma comment(lib, "shell32.lib") 16 #pragma comment(lib, "shell32.lib")
15 17
16 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 18 EXTERN_C IMAGE_DOS_HEADER __ImageBase;
17 // Even though we only create a single window, we need to keep this 19 // Even though we only create a single window, we need to keep this
18 // count because of the hidden window used by the UI message loop of 20 // count because of the hidden window used by the UI message loop of
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 DISALLOW_COPY_AND_ASSIGN(MouseEvent); 366 DISALLOW_COPY_AND_ASSIGN(MouseEvent);
365 }; 367 };
366 368
367 // This class implements the winrt interfaces needed to support keyboard 369 // This class implements the winrt interfaces needed to support keyboard
368 // character and system character messages. 370 // character and system character messages.
369 class KeyEvent : public mswr::RuntimeClass< 371 class KeyEvent : public mswr::RuntimeClass<
370 winui::Core::IKeyEventArgs, 372 winui::Core::IKeyEventArgs,
371 winui::Core::ICharacterReceivedEventArgs, 373 winui::Core::ICharacterReceivedEventArgs,
372 winui::Core::IAcceleratorKeyEventArgs> { 374 winui::Core::IAcceleratorKeyEventArgs> {
373 public: 375 public:
374 KeyEvent(const MSG& msg) 376 KeyEvent(const MSG& msg, bool was_key)
375 : msg_(msg) {} 377 : msg_(msg), was_key_(was_key) {}
376 378
377 // IKeyEventArgs implementation. 379 // IKeyEventArgs implementation.
378 HRESULT STDMETHODCALLTYPE 380 HRESULT STDMETHODCALLTYPE
379 get_VirtualKey(winsys::VirtualKey* virtual_key) override { 381 get_VirtualKey(winsys::VirtualKey* virtual_key) override {
380 *virtual_key = static_cast<winsys::VirtualKey>(msg_.wParam); 382 *virtual_key = static_cast<winsys::VirtualKey>(msg_.wParam);
381 return S_OK; 383 return S_OK;
382 } 384 }
383 385
384 HRESULT STDMETHODCALLTYPE 386 HRESULT STDMETHODCALLTYPE
385 get_KeyStatus(winui::Core::CorePhysicalKeyStatus* key_status) override { 387 get_KeyStatus(winui::Core::CorePhysicalKeyStatus* key_status) override {
386 // As per msdn documentation for the keyboard messages. 388 // As per msdn documentation for the keyboard messages.
387 key_status->RepeatCount = msg_.lParam & 0x0000FFFF; 389 key_status->RepeatCount = msg_.lParam & 0x0000FFFF;
388 key_status->ScanCode = (msg_.lParam >> 16) & 0x00FF; 390 key_status->ScanCode = (msg_.lParam >> 16) & 0x00FF;
389 key_status->IsExtendedKey = (msg_.lParam & (1 << 24)); 391 key_status->IsExtendedKey = (msg_.lParam & (1 << 24));
390 key_status->IsMenuKeyDown = (msg_.lParam & (1 << 29)); 392 key_status->IsMenuKeyDown = (msg_.lParam & (1 << 29));
391 key_status->WasKeyDown = (msg_.lParam & (1 << 30));
392 key_status->IsKeyReleased = (msg_.lParam & (1 << 31)); 393 key_status->IsKeyReleased = (msg_.lParam & (1 << 31));
394 key_status->WasKeyDown = was_key_;
393 return S_OK; 395 return S_OK;
394 } 396 }
395 397
396 // ICharacterReceivedEventArgs implementation. 398 // ICharacterReceivedEventArgs implementation.
397 HRESULT STDMETHODCALLTYPE get_KeyCode(uint32* key_code) override { 399 HRESULT STDMETHODCALLTYPE get_KeyCode(uint32* key_code) override {
398 *key_code = msg_.wParam; 400 *key_code = msg_.wParam;
399 return S_OK; 401 return S_OK;
400 } 402 }
401 403
402 // IAcceleratorKeyEventArgs implementation. 404 // IAcceleratorKeyEventArgs implementation.
403 HRESULT STDMETHODCALLTYPE 405 HRESULT STDMETHODCALLTYPE
404 get_EventType(winui::Core::CoreAcceleratorKeyEventType* event_type) override { 406 get_EventType(winui::Core::CoreAcceleratorKeyEventType* event_type) override {
405 if (msg_.message == WM_SYSKEYDOWN) { 407 if (msg_.message == WM_SYSKEYDOWN) {
406 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyDown; 408 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyDown;
407 } else if (msg_.message == WM_SYSKEYUP) { 409 } else if (msg_.message == WM_SYSKEYUP) {
408 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyUp; 410 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemKeyUp;
409 } else if (msg_.message == WM_SYSCHAR) { 411 } else if (msg_.message == WM_SYSCHAR) {
410 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemCharacter; 412 *event_type = winui::Core::CoreAcceleratorKeyEventType_SystemCharacter;
411 } 413 }
412 return S_OK; 414 return S_OK;
413 } 415 }
414 416
415 private: 417 private:
416 MSG msg_; 418 MSG msg_;
419 bool was_key_;
417 }; 420 };
418 421
419 // The following classes are the emulation of the WinRT system as exposed 422 // The following classes are the emulation of the WinRT system as exposed
420 // to metro applications. There is one application (ICoreApplication) which 423 // to metro applications. There is one application (ICoreApplication) which
421 // contains a series of Views (ICoreApplicationView) each one of them 424 // contains a series of Views (ICoreApplicationView) each one of them
422 // containing a CoreWindow which represents a surface that can drawn to 425 // containing a CoreWindow which represents a surface that can drawn to
423 // and that receives events. 426 // and that receives events.
424 // 427 //
425 // Here is the general dependency hierachy in terms of interfaces: 428 // Here is the general dependency hierachy in terms of interfaces:
426 // 429 //
(...skipping 28 matching lines...) Expand all
455 458
456 HRESULT STDMETHODCALLTYPE 459 HRESULT STDMETHODCALLTYPE
457 ProcessEvents(winui::Core::CoreProcessEventsOption options) override { 460 ProcessEvents(winui::Core::CoreProcessEventsOption options) override {
458 // We don't support the other message pump modes. So we basically enter a 461 // We don't support the other message pump modes. So we basically enter a
459 // traditional message loop that we only exit a teardown. 462 // traditional message loop that we only exit a teardown.
460 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit) 463 if (options != winui::Core::CoreProcessEventsOption_ProcessUntilQuit)
461 return E_FAIL; 464 return E_FAIL;
462 465
463 MSG msg = {0}; 466 MSG msg = {0};
464 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) { 467 while((::GetMessage(&msg, NULL, 0, 0) != 0) && g_window_count > 0) {
465 ProcessInputMessage(msg); 468 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
466 ::TranslateMessage(&msg); 469 switches::kDisableMergeKeyCharEvents)) {
470 ::TranslateMessage(&msg);
471 ProcessInputMessage(msg);
472 } else {
473 // Preserve the old behavior when merge- key-char-events is disabled.
474 ProcessInputMessage(msg);
475 ::TranslateMessage(&msg);
476 }
467 ::DispatchMessage(&msg); 477 ::DispatchMessage(&msg);
468 } 478 }
469 // TODO(cpu): figure what to do with msg.WParam which we would normally 479 // TODO(cpu): figure what to do with msg.WParam which we would normally
470 // return here. 480 // return here.
471 return S_OK; 481 return S_OK;
472 } 482 }
473 483
474 HRESULT STDMETHODCALLTYPE 484 HRESULT STDMETHODCALLTYPE
475 RunAsync(winui::Core::CoreDispatcherPriority priority, 485 RunAsync(winui::Core::CoreDispatcherPriority priority,
476 winui::Core::IDispatchedHandler* agileCallback, 486 winui::Core::IDispatchedHandler* agileCallback,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } else if ((msg.message >= WM_MOUSEFIRST) && 525 } else if ((msg.message >= WM_MOUSEFIRST) &&
516 (msg.message <= WM_MOUSELAST)) { 526 (msg.message <= WM_MOUSELAST)) {
517 ret = input_handler_->HandleMouseMessage(msg); 527 ret = input_handler_->HandleMouseMessage(msg);
518 } 528 }
519 } 529 }
520 return ret; 530 return ret;
521 } 531 }
522 532
523 bool HandleSystemKeys(const MSG& msg) { 533 bool HandleSystemKeys(const MSG& msg) {
524 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args; 534 mswr::ComPtr<winui::Core::IAcceleratorKeyEventArgs> event_args;
525 event_args = mswr::Make<KeyEvent>(msg); 535 event_args = mswr::Make<KeyEvent>(msg, true);
526 accelerator_key_event_handler_->Invoke(this, event_args.Get()); 536 accelerator_key_event_handler_->Invoke(this, event_args.Get());
527 return true; 537 return true;
528 } 538 }
529 539
530 InputHandler* input_handler_; 540 InputHandler* input_handler_;
531 AcceleratorKeyEventHandler* accelerator_key_event_handler_; 541 AcceleratorKeyEventHandler* accelerator_key_event_handler_;
532 }; 542 };
533 543
534 class CoreWindowEmulation 544 class CoreWindowEmulation
535 : public mswr::RuntimeClass< 545 : public mswr::RuntimeClass<
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 916
907 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override { 917 HRESULT STDMETHODCALLTYPE put_MessageHandled(boolean value) override {
908 return S_OK; 918 return S_OK;
909 } 919 }
910 920
911 // InputHandler 921 // InputHandler
912 bool HandleKeyboardMessage(const MSG& msg) override { 922 bool HandleKeyboardMessage(const MSG& msg) override {
913 switch (msg.message) { 923 switch (msg.message) {
914 case WM_KEYDOWN: 924 case WM_KEYDOWN:
915 case WM_KEYUP: { 925 case WM_KEYUP: {
926 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
927 switches::kDisableMergeKeyCharEvents)) {
928 // Combines the WM_KEY* and WM_CHAR messages in the event processing
929 // flow which is necessary to let Chrome IME extension to process the
930 // key event and perform corresponding IME actions.
931 // Chrome IME extension may wants to consume certain key events based
932 // on the character information of WM_CHAR messages. Holding WM_KEY*
933 // messages until WM_CHAR is processed by the IME extension is not
934 // feasible because there is no way to know wether there will or not
935 // be a WM_CHAR following the WM_KEY*.
936 // Chrome never handles dead chars so it is safe to remove/ignore
937 // WM_*DEADCHAR messages.
938 MSG char_msg;
939 while (::PeekMessage(&char_msg, msg.hwnd, WM_CHAR, WM_DEADCHAR,
940 PM_REMOVE)) {
941 if (char_msg.message == WM_DEADCHAR)
942 continue;
943 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> char_args;
944 char_args = mswr::Make<KeyEvent>(char_msg, true);
945 character_received_handler_->Invoke(this, char_args.Get());
946 }
947 }
916 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args; 948 mswr::ComPtr<winui::Core::IKeyEventArgs> event_args;
917 event_args = mswr::Make<KeyEvent>(msg); 949 event_args = mswr::Make<KeyEvent>(msg, true);
918 KeyEventHandler* handler = NULL; 950 KeyEventHandler* handler = NULL;
919 if (msg.message == WM_KEYDOWN) { 951 if (msg.message == WM_KEYDOWN) {
920 handler = key_down_handler_; 952 handler = key_down_handler_;
921 } else { 953 } else {
922 handler = key_up_handler_; 954 handler = key_up_handler_;
923 } 955 }
924 handler->Invoke(this, event_args.Get()); 956 handler->Invoke(this, event_args.Get());
925 break; 957 break;
926 } 958 }
927 959
928 case WM_CHAR: 960 case WM_CHAR: {
929 case WM_DEADCHAR:
930 case WM_UNICHAR: {
931 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args; 961 mswr::ComPtr<winui::Core::ICharacterReceivedEventArgs> event_args;
932 event_args = mswr::Make<KeyEvent>(msg); 962 event_args = mswr::Make<KeyEvent>(msg, false);
933 character_received_handler_->Invoke(this, event_args.Get()); 963 character_received_handler_->Invoke(this, event_args.Get());
934 break; 964 break;
935 } 965 }
936 966
937 default: 967 default:
938 return false; 968 return false;
939 } 969 }
940 return true; 970 return true;
941 } 971 }
942 972
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 }; 1248 };
1219 1249
1220 1250
1221 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() { 1251 mswr::ComPtr<winapp::Core::ICoreApplication> InitWindows7() {
1222 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); 1252 HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
1223 if (FAILED(hr)) 1253 if (FAILED(hr))
1224 CHECK(false); 1254 CHECK(false);
1225 return mswr::Make<CoreApplicationWin7Emulation>(); 1255 return mswr::Make<CoreApplicationWin7Emulation>();
1226 } 1256 }
1227 1257
OLDNEW
« base/base_switches.h ('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