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

Side by Side Diff: webkit/glue/webview_impl.cc

Issue 27332: Fixing WebKeyboardEvent. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webinputevent_win.cc ('k') | webkit/glue/webwidget_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 Google Inc. All Rights Reserved. 2 * Copyright 2007 Google Inc. All Rights Reserved.
3 * 3 *
4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
5 * 5 *
6 * ***** BEGIN LICENSE BLOCK ***** 6 * ***** BEGIN LICENSE BLOCK *****
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 if (event.button == WebMouseEvent::BUTTON_RIGHT) 473 if (event.button == WebMouseEvent::BUTTON_RIGHT)
474 MouseContextMenu(event); 474 MouseContextMenu(event);
475 } 475 }
476 476
477 void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) { 477 void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) {
478 MakePlatformWheelEvent platform_event(main_frame()->frameview(), event); 478 MakePlatformWheelEvent platform_event(main_frame()->frameview(), event);
479 main_frame()->frame()->eventHandler()->handleWheelEvent(platform_event); 479 main_frame()->frame()->eventHandler()->handleWheelEvent(platform_event);
480 } 480 }
481 481
482 bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) { 482 bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
483 DCHECK((event.type == WebInputEvent::KEY_DOWN) || 483 DCHECK((event.type == WebInputEvent::RAW_KEY_DOWN) ||
484 (event.type == WebInputEvent::KEY_DOWN) ||
484 (event.type == WebInputEvent::KEY_UP)); 485 (event.type == WebInputEvent::KEY_UP));
485 486
486 // Please refer to the comments explaining the suppress_next_keypress_event_ 487 // Please refer to the comments explaining the suppress_next_keypress_event_
487 // member. 488 // member.
488 // The suppress_next_keypress_event_ is set if the KeyDown is handled by 489 // The suppress_next_keypress_event_ is set if the KeyDown is handled by
489 // Webkit. A keyDown event is typically associated with a keyPress(char) 490 // Webkit. A keyDown event is typically associated with a keyPress(char)
490 // event and a keyUp event. We reset this flag here as this is a new keyDown 491 // event and a keyUp event. We reset this flag here as this is a new keyDown
491 // event. 492 // event.
492 suppress_next_keypress_event_ = false; 493 suppress_next_keypress_event_ = false;
493 494
494 // Give autocomplete a chance to consume the key events it is interested in. 495 // Give autocomplete a chance to consume the key events it is interested in.
495 if (AutocompleteHandleKeyEvent(event)) 496 if (AutocompleteHandleKeyEvent(event))
496 return true; 497 return true;
497 498
498 Frame* frame = GetFocusedWebCoreFrame(); 499 Frame* frame = GetFocusedWebCoreFrame();
499 if (!frame) 500 if (!frame)
500 return false; 501 return false;
501 502
502 EventHandler* handler = frame->eventHandler(); 503 EventHandler* handler = frame->eventHandler();
503 if (!handler) 504 if (!handler)
504 return KeyEventDefault(event); 505 return KeyEventDefault(event);
505 506
506 #if defined(OS_WIN) 507 #if defined(OS_WIN)
507 // TODO(pinkerton): figure out these keycodes on non-windows 508 // TODO(pinkerton): figure out these keycodes on non-windows
508 if (((event.modifiers == 0) && (event.key_code == VK_APPS)) || 509 if (((event.modifiers == 0) && (event.windows_key_code == VK_APPS)) ||
509 ((event.modifiers == WebInputEvent::SHIFT_KEY) && 510 ((event.modifiers == WebInputEvent::SHIFT_KEY) &&
510 (event.key_code == VK_F10))) { 511 (event.windows_key_code == VK_F10))) {
511 SendContextMenuEvent(event); 512 SendContextMenuEvent(event);
512 return true; 513 return true;
513 } 514 }
514 #endif 515 #endif
515 516
516 MakePlatformKeyboardEvent evt(event); 517 MakePlatformKeyboardEvent evt(event);
517 518
518 #if !defined(OS_MACOSX) 519 if (WebInputEvent::RAW_KEY_DOWN == event.type) {
519 if (WebInputEvent::KEY_DOWN == event.type) { 520 if (handler->keyEvent(evt) && !evt.isSystemKey()) {
520 MakePlatformKeyboardEvent evt_rawkeydown = evt;
521 evt_rawkeydown.SetKeyType(WebCore::PlatformKeyboardEvent::RawKeyDown);
522 if (handler->keyEvent(evt_rawkeydown) && !evt_rawkeydown.isSystemKey()) {
523 suppress_next_keypress_event_ = true; 521 suppress_next_keypress_event_ = true;
524 return true; 522 return true;
525 } 523 }
526 } else { 524 } else {
527 if (handler->keyEvent(evt)) { 525 if (handler->keyEvent(evt)) {
528 return true; 526 return true;
529 } 527 }
530 } 528 }
531 #else
532 // Windows and Cocoa handle events in rather different ways. On Windows,
533 // you get two events: WM_KEYDOWN/WM_KEYUP and WM_CHAR. In
534 // PlatformKeyboardEvent, RawKeyDown represents the raw messages. When
535 // processing them, we don't process text editing events, since we'll be
536 // getting the data soon enough. In Cocoa, we get one event with both the
537 // raw and processed data. Therefore we need to keep the type as KeyDown, so
538 // that we'll know that this is the only time we'll have the event and that
539 // we need to do our thing.
540 if (handler->keyEvent(evt)) {
541 return true;
542 }
543 #endif
544 529
545 return KeyEventDefault(event); 530 return KeyEventDefault(event);
546 } 531 }
547 532
548 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { 533 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) {
549 if (!autocomplete_popup_showing_ || 534 if (!autocomplete_popup_showing_ ||
550 // Home and End should be left to the text field to process. 535 // Home and End should be left to the text field to process.
551 event.key_code == base::VKEY_HOME || event.key_code == base::VKEY_END) { 536 event.windows_key_code == base::VKEY_HOME ||
537 event.windows_key_code == base::VKEY_END) {
552 return false; 538 return false;
553 } 539 }
554 540
555 if (!autocomplete_popup_->isInterestedInEventForKey(event.key_code)) 541 if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code))
556 return false; 542 return false;
557 543
558 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { 544 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) {
559 #if defined(OS_WIN) 545 #if defined(OS_WIN)
560 // We need to ignore the next CHAR event after this otherwise pressing 546 // We need to ignore the next CHAR event after this otherwise pressing
561 // enter when selecting an item in the menu will go to the page. 547 // enter when selecting an item in the menu will go to the page.
562 if (WebInputEvent::KEY_DOWN == event.type) 548 if (WebInputEvent::RAW_KEY_DOWN == event.type)
563 suppress_next_keypress_event_ = true; 549 suppress_next_keypress_event_ = true;
564 #endif 550 #endif
565 return true; 551 return true;
566 } 552 }
567 553
568 return false; 554 return false;
569 } 555 }
570 556
571 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) { 557 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) {
572 DCHECK(event.type == WebInputEvent::CHAR); 558 DCHECK(event.type == WebInputEvent::CHAR);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 672
687 bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { 673 bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) {
688 Frame* frame = GetFocusedWebCoreFrame(); 674 Frame* frame = GetFocusedWebCoreFrame();
689 if (!frame) 675 if (!frame)
690 return false; 676 return false;
691 677
692 switch (event.type) { 678 switch (event.type) {
693 case WebInputEvent::CHAR: { 679 case WebInputEvent::CHAR: {
694 #if defined(OS_WIN) 680 #if defined(OS_WIN)
695 // TODO(pinkerton): hook this up for non-win32 681 // TODO(pinkerton): hook this up for non-win32
696 if (event.key_code == VK_SPACE) { 682 if (event.windows_key_code == VK_SPACE) {
697 int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ? 683 int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ?
698 VK_PRIOR : VK_NEXT); 684 VK_PRIOR : VK_NEXT);
699 return ScrollViewWithKeyboard(key_code); 685 return ScrollViewWithKeyboard(key_code);
700 } 686 }
701 #endif 687 #endif
702 break; 688 break;
703 } 689 }
704 690
705 case WebInputEvent::KEY_DOWN: { 691 case WebInputEvent::RAW_KEY_DOWN: {
706 if (event.modifiers == WebInputEvent::CTRL_KEY) { 692 if (event.modifiers == WebInputEvent::CTRL_KEY) {
707 switch (event.key_code) { 693 switch (event.windows_key_code) {
708 case 'A': 694 case 'A':
709 GetFocusedFrame()->SelectAll(); 695 GetFocusedFrame()->SelectAll();
710 return true; 696 return true;
711 #if defined(OS_WIN) 697 #if defined(OS_WIN)
712 case VK_INSERT: 698 case VK_INSERT:
713 #endif 699 #endif
714 case 'C': 700 case 'C':
715 GetFocusedFrame()->Copy(); 701 GetFocusedFrame()->Copy();
716 return true; 702 return true;
717 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl 703 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl
718 // key combinations which affect scrolling. Safari is buggy in the 704 // key combinations which affect scrolling. Safari is buggy in the
719 // sense that it scrolls the page for all Ctrl+scrolling key 705 // sense that it scrolls the page for all Ctrl+scrolling key
720 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. 706 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc.
721 #if defined(OS_WIN) 707 #if defined(OS_WIN)
722 case VK_HOME: 708 case VK_HOME:
723 case VK_END: 709 case VK_END:
724 #endif 710 #endif
725 break; 711 break;
726 default: 712 default:
727 return false; 713 return false;
728 } 714 }
729 } 715 }
730 #if defined(OS_WIN) 716 #if defined(OS_WIN)
731 if (!event.system_key) { 717 if (!event.system_key) {
732 return ScrollViewWithKeyboard(event.key_code); 718 return ScrollViewWithKeyboard(event.windows_key_code);
733 } 719 }
734 #endif 720 #endif
735 break; 721 break;
736 } 722 }
737 723
738 default: 724 default:
739 break; 725 break;
740 } 726 }
741 return false; 727 return false;
742 } 728 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 953
968 case WebInputEvent::MOUSE_DOWN: 954 case WebInputEvent::MOUSE_DOWN:
969 case WebInputEvent::MOUSE_DOUBLE_CLICK: 955 case WebInputEvent::MOUSE_DOUBLE_CLICK:
970 MouseDown(*static_cast<const WebMouseEvent*>(input_event)); 956 MouseDown(*static_cast<const WebMouseEvent*>(input_event));
971 break; 957 break;
972 958
973 case WebInputEvent::MOUSE_UP: 959 case WebInputEvent::MOUSE_UP:
974 MouseUp(*static_cast<const WebMouseEvent*>(input_event)); 960 MouseUp(*static_cast<const WebMouseEvent*>(input_event));
975 break; 961 break;
976 962
963 case WebInputEvent::RAW_KEY_DOWN:
977 case WebInputEvent::KEY_DOWN: 964 case WebInputEvent::KEY_DOWN:
978 case WebInputEvent::KEY_UP: 965 case WebInputEvent::KEY_UP:
979 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event)); 966 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event));
980 break; 967 break;
981 968
982 case WebInputEvent::CHAR: 969 case WebInputEvent::CHAR:
983 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event)); 970 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event));
984 break; 971 break;
985 default: 972 default:
986 handled = false; 973 handled = false;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 } 1212 }
1226 } 1213 }
1227 1214
1228 void WebViewImpl::SetInitialFocus(bool reverse) { 1215 void WebViewImpl::SetInitialFocus(bool reverse) {
1229 if (page_.get()) { 1216 if (page_.get()) {
1230 // So RestoreFocus does not focus anything when it is called. 1217 // So RestoreFocus does not focus anything when it is called.
1231 ReleaseFocusReferences(); 1218 ReleaseFocusReferences();
1232 1219
1233 // Since we don't have a keyboard event, we'll create one. 1220 // Since we don't have a keyboard event, we'll create one.
1234 WebKeyboardEvent keyboard_event; 1221 WebKeyboardEvent keyboard_event;
1235 keyboard_event.type = WebInputEvent::KEY_DOWN; 1222 keyboard_event.type = WebInputEvent::RAW_KEY_DOWN;
1236 if (reverse) 1223 if (reverse)
1237 keyboard_event.modifiers = WebInputEvent::SHIFT_KEY; 1224 keyboard_event.modifiers = WebInputEvent::SHIFT_KEY;
1238 // VK_TAB which is only defined on Windows. 1225 // VK_TAB which is only defined on Windows.
1239 keyboard_event.key_code = 0x09; 1226 keyboard_event.windows_key_code = 0x09;
1240 MakePlatformKeyboardEvent platform_event(keyboard_event); 1227 MakePlatformKeyboardEvent platform_event(keyboard_event);
1241 // We have to set the key type explicitly to avoid an assert in the 1228 // We have to set the key type explicitly to avoid an assert in the
1242 // KeyboardEvent constructor. 1229 // KeyboardEvent constructor.
1243 platform_event.SetKeyType(PlatformKeyboardEvent::RawKeyDown);
1244 RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event, 1230 RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event,
1245 NULL); 1231 NULL);
1246 page()->focusController()->setInitialFocus( 1232 page()->focusController()->setInitialFocus(
1247 reverse ? WebCore::FocusDirectionBackward : 1233 reverse ? WebCore::FocusDirectionBackward :
1248 WebCore::FocusDirectionForward, 1234 WebCore::FocusDirectionForward,
1249 webkit_event.get()); 1235 webkit_event.get());
1250 } 1236 }
1251 } 1237 }
1252 1238
1253 // Releases references used to restore focus. 1239 // Releases references used to restore focus.
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 Frame* frame = page_->focusController()->focusedFrame(); 1698 Frame* frame = page_->focusController()->focusedFrame();
1713 if (!frame) 1699 if (!frame)
1714 return NULL; 1700 return NULL;
1715 1701
1716 Document* document = frame->document(); 1702 Document* document = frame->document();
1717 if (!document) 1703 if (!document)
1718 return NULL; 1704 return NULL;
1719 1705
1720 return document->focusedNode(); 1706 return document->focusedNode();
1721 } 1707 }
OLDNEW
« no previous file with comments | « webkit/glue/webinputevent_win.cc ('k') | webkit/glue/webwidget_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698