OLD | NEW |
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 Loading... |
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::RAW_KEY_DOWN) || | 483 DCHECK((event.type == WebInputEvent::KEY_DOWN) || |
484 (event.type == WebInputEvent::KEY_DOWN) || | |
485 (event.type == WebInputEvent::KEY_UP)); | 484 (event.type == WebInputEvent::KEY_UP)); |
486 | 485 |
487 // Please refer to the comments explaining the suppress_next_keypress_event_ | 486 // Please refer to the comments explaining the suppress_next_keypress_event_ |
488 // member. | 487 // member. |
489 // The suppress_next_keypress_event_ is set if the KeyDown is handled by | 488 // The suppress_next_keypress_event_ is set if the KeyDown is handled by |
490 // Webkit. A keyDown event is typically associated with a keyPress(char) | 489 // Webkit. A keyDown event is typically associated with a keyPress(char) |
491 // event and a keyUp event. We reset this flag here as this is a new keyDown | 490 // event and a keyUp event. We reset this flag here as this is a new keyDown |
492 // event. | 491 // event. |
493 suppress_next_keypress_event_ = false; | 492 suppress_next_keypress_event_ = false; |
494 | 493 |
495 // Give autocomplete a chance to consume the key events it is interested in. | 494 // Give autocomplete a chance to consume the key events it is interested in. |
496 if (AutocompleteHandleKeyEvent(event)) | 495 if (AutocompleteHandleKeyEvent(event)) |
497 return true; | 496 return true; |
498 | 497 |
499 Frame* frame = GetFocusedWebCoreFrame(); | 498 Frame* frame = GetFocusedWebCoreFrame(); |
500 if (!frame) | 499 if (!frame) |
501 return false; | 500 return false; |
502 | 501 |
503 EventHandler* handler = frame->eventHandler(); | 502 EventHandler* handler = frame->eventHandler(); |
504 if (!handler) | 503 if (!handler) |
505 return KeyEventDefault(event); | 504 return KeyEventDefault(event); |
506 | 505 |
507 #if defined(OS_WIN) | 506 #if defined(OS_WIN) |
508 // TODO(pinkerton): figure out these keycodes on non-windows | 507 // TODO(pinkerton): figure out these keycodes on non-windows |
509 if (((event.modifiers == 0) && (event.windows_key_code == VK_APPS)) || | 508 if (((event.modifiers == 0) && (event.key_code == VK_APPS)) || |
510 ((event.modifiers == WebInputEvent::SHIFT_KEY) && | 509 ((event.modifiers == WebInputEvent::SHIFT_KEY) && |
511 (event.windows_key_code == VK_F10))) { | 510 (event.key_code == VK_F10))) { |
512 SendContextMenuEvent(event); | 511 SendContextMenuEvent(event); |
513 return true; | 512 return true; |
514 } | 513 } |
515 #endif | 514 #endif |
516 | 515 |
517 MakePlatformKeyboardEvent evt(event); | 516 MakePlatformKeyboardEvent evt(event); |
518 | 517 |
519 if (WebInputEvent::RAW_KEY_DOWN == event.type) { | 518 #if !defined(OS_MACOSX) |
| 519 if (WebInputEvent::KEY_DOWN == event.type) { |
520 MakePlatformKeyboardEvent evt_rawkeydown = evt; | 520 MakePlatformKeyboardEvent evt_rawkeydown = evt; |
| 521 evt_rawkeydown.SetKeyType(WebCore::PlatformKeyboardEvent::RawKeyDown); |
521 if (handler->keyEvent(evt_rawkeydown) && !evt_rawkeydown.isSystemKey()) { | 522 if (handler->keyEvent(evt_rawkeydown) && !evt_rawkeydown.isSystemKey()) { |
522 suppress_next_keypress_event_ = true; | 523 suppress_next_keypress_event_ = true; |
523 return true; | 524 return true; |
524 } | 525 } |
525 } else { | 526 } else { |
526 if (handler->keyEvent(evt)) { | 527 if (handler->keyEvent(evt)) { |
527 return true; | 528 return true; |
528 } | 529 } |
529 } | 530 } |
| 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 |
530 | 544 |
531 return KeyEventDefault(event); | 545 return KeyEventDefault(event); |
532 } | 546 } |
533 | 547 |
534 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { | 548 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) { |
535 if (!autocomplete_popup_showing_ || | 549 if (!autocomplete_popup_showing_ || |
536 // Home and End should be left to the text field to process. | 550 // Home and End should be left to the text field to process. |
537 event.windows_key_code == base::VKEY_HOME || | 551 event.key_code == base::VKEY_HOME || event.key_code == base::VKEY_END) { |
538 event.windows_key_code == base::VKEY_END) { | |
539 return false; | 552 return false; |
540 } | 553 } |
541 | 554 |
542 if (!autocomplete_popup_->isInterestedInEventForKey(event.windows_key_code)) | 555 if (!autocomplete_popup_->isInterestedInEventForKey(event.key_code)) |
543 return false; | 556 return false; |
544 | 557 |
545 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { | 558 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) { |
546 #if defined(OS_WIN) | 559 #if defined(OS_WIN) |
547 // We need to ignore the next CHAR event after this otherwise pressing | 560 // We need to ignore the next CHAR event after this otherwise pressing |
548 // enter when selecting an item in the menu will go to the page. | 561 // enter when selecting an item in the menu will go to the page. |
549 if (WebInputEvent::RAW_KEY_DOWN == event.type) | 562 if (WebInputEvent::KEY_DOWN == event.type) |
550 suppress_next_keypress_event_ = true; | 563 suppress_next_keypress_event_ = true; |
551 #endif | 564 #endif |
552 return true; | 565 return true; |
553 } | 566 } |
554 | 567 |
555 return false; | 568 return false; |
556 } | 569 } |
557 | 570 |
558 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) { | 571 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) { |
559 DCHECK(event.type == WebInputEvent::CHAR); | 572 DCHECK(event.type == WebInputEvent::CHAR); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 | 686 |
674 bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { | 687 bool WebViewImpl::KeyEventDefault(const WebKeyboardEvent& event) { |
675 Frame* frame = GetFocusedWebCoreFrame(); | 688 Frame* frame = GetFocusedWebCoreFrame(); |
676 if (!frame) | 689 if (!frame) |
677 return false; | 690 return false; |
678 | 691 |
679 switch (event.type) { | 692 switch (event.type) { |
680 case WebInputEvent::CHAR: { | 693 case WebInputEvent::CHAR: { |
681 #if defined(OS_WIN) | 694 #if defined(OS_WIN) |
682 // TODO(pinkerton): hook this up for non-win32 | 695 // TODO(pinkerton): hook this up for non-win32 |
683 if (event.windows_key_code == VK_SPACE) { | 696 if (event.key_code == VK_SPACE) { |
684 int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ? | 697 int key_code = ((event.modifiers & WebInputEvent::SHIFT_KEY) ? |
685 VK_PRIOR : VK_NEXT); | 698 VK_PRIOR : VK_NEXT); |
686 return ScrollViewWithKeyboard(key_code); | 699 return ScrollViewWithKeyboard(key_code); |
687 } | 700 } |
688 #endif | 701 #endif |
689 break; | 702 break; |
690 } | 703 } |
691 | 704 |
692 case WebInputEvent::RAW_KEY_DOWN: { | 705 case WebInputEvent::KEY_DOWN: { |
693 if (event.modifiers == WebInputEvent::CTRL_KEY) { | 706 if (event.modifiers == WebInputEvent::CTRL_KEY) { |
694 switch (event.windows_key_code) { | 707 switch (event.key_code) { |
695 case 'A': | 708 case 'A': |
696 GetFocusedFrame()->SelectAll(); | 709 GetFocusedFrame()->SelectAll(); |
697 return true; | 710 return true; |
698 #if defined(OS_WIN) | 711 #if defined(OS_WIN) |
699 case VK_INSERT: | 712 case VK_INSERT: |
700 #endif | 713 #endif |
701 case 'C': | 714 case 'C': |
702 GetFocusedFrame()->Copy(); | 715 GetFocusedFrame()->Copy(); |
703 return true; | 716 return true; |
704 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl | 717 // Match FF behavior in the sense that Ctrl+home/end are the only Ctrl |
705 // key combinations which affect scrolling. Safari is buggy in the | 718 // key combinations which affect scrolling. Safari is buggy in the |
706 // sense that it scrolls the page for all Ctrl+scrolling key | 719 // sense that it scrolls the page for all Ctrl+scrolling key |
707 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. | 720 // combinations. For e.g. Ctrl+pgup/pgdn/up/down, etc. |
708 #if defined(OS_WIN) | 721 #if defined(OS_WIN) |
709 case VK_HOME: | 722 case VK_HOME: |
710 case VK_END: | 723 case VK_END: |
711 #endif | 724 #endif |
712 break; | 725 break; |
713 default: | 726 default: |
714 return false; | 727 return false; |
715 } | 728 } |
716 } | 729 } |
717 #if defined(OS_WIN) | 730 #if defined(OS_WIN) |
718 if (!event.system_key) { | 731 if (!event.system_key) { |
719 return ScrollViewWithKeyboard(event.windows_key_code); | 732 return ScrollViewWithKeyboard(event.key_code); |
720 } | 733 } |
721 #endif | 734 #endif |
722 break; | 735 break; |
723 } | 736 } |
724 | 737 |
725 default: | 738 default: |
726 break; | 739 break; |
727 } | 740 } |
728 return false; | 741 return false; |
729 } | 742 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 967 |
955 case WebInputEvent::MOUSE_DOWN: | 968 case WebInputEvent::MOUSE_DOWN: |
956 case WebInputEvent::MOUSE_DOUBLE_CLICK: | 969 case WebInputEvent::MOUSE_DOUBLE_CLICK: |
957 MouseDown(*static_cast<const WebMouseEvent*>(input_event)); | 970 MouseDown(*static_cast<const WebMouseEvent*>(input_event)); |
958 break; | 971 break; |
959 | 972 |
960 case WebInputEvent::MOUSE_UP: | 973 case WebInputEvent::MOUSE_UP: |
961 MouseUp(*static_cast<const WebMouseEvent*>(input_event)); | 974 MouseUp(*static_cast<const WebMouseEvent*>(input_event)); |
962 break; | 975 break; |
963 | 976 |
964 case WebInputEvent::RAW_KEY_DOWN: | |
965 case WebInputEvent::KEY_DOWN: | 977 case WebInputEvent::KEY_DOWN: |
966 case WebInputEvent::KEY_UP: | 978 case WebInputEvent::KEY_UP: |
967 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event)); | 979 handled = KeyEvent(*static_cast<const WebKeyboardEvent*>(input_event)); |
968 break; | 980 break; |
969 | 981 |
970 case WebInputEvent::CHAR: | 982 case WebInputEvent::CHAR: |
971 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event)); | 983 handled = CharEvent(*static_cast<const WebKeyboardEvent*>(input_event)); |
972 break; | 984 break; |
973 default: | 985 default: |
974 handled = false; | 986 handled = false; |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 } | 1227 } |
1216 } | 1228 } |
1217 | 1229 |
1218 void WebViewImpl::SetInitialFocus(bool reverse) { | 1230 void WebViewImpl::SetInitialFocus(bool reverse) { |
1219 if (page_.get()) { | 1231 if (page_.get()) { |
1220 // So RestoreFocus does not focus anything when it is called. | 1232 // So RestoreFocus does not focus anything when it is called. |
1221 ReleaseFocusReferences(); | 1233 ReleaseFocusReferences(); |
1222 | 1234 |
1223 // Since we don't have a keyboard event, we'll create one. | 1235 // Since we don't have a keyboard event, we'll create one. |
1224 WebKeyboardEvent keyboard_event; | 1236 WebKeyboardEvent keyboard_event; |
1225 keyboard_event.type = WebInputEvent::RAW_KEY_DOWN; | 1237 keyboard_event.type = WebInputEvent::KEY_DOWN; |
1226 if (reverse) | 1238 if (reverse) |
1227 keyboard_event.modifiers = WebInputEvent::SHIFT_KEY; | 1239 keyboard_event.modifiers = WebInputEvent::SHIFT_KEY; |
1228 // VK_TAB which is only defined on Windows. | 1240 // VK_TAB which is only defined on Windows. |
1229 keyboard_event.windows_key_code = 0x09; | 1241 keyboard_event.key_code = 0x09; |
1230 MakePlatformKeyboardEvent platform_event(keyboard_event); | 1242 MakePlatformKeyboardEvent platform_event(keyboard_event); |
1231 // We have to set the key type explicitly to avoid an assert in the | 1243 // We have to set the key type explicitly to avoid an assert in the |
1232 // KeyboardEvent constructor. | 1244 // KeyboardEvent constructor. |
| 1245 platform_event.SetKeyType(PlatformKeyboardEvent::RawKeyDown); |
1233 RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event, | 1246 RefPtr<KeyboardEvent> webkit_event = KeyboardEvent::create(platform_event, |
1234 NULL); | 1247 NULL); |
1235 page()->focusController()->setInitialFocus( | 1248 page()->focusController()->setInitialFocus( |
1236 reverse ? WebCore::FocusDirectionBackward : | 1249 reverse ? WebCore::FocusDirectionBackward : |
1237 WebCore::FocusDirectionForward, | 1250 WebCore::FocusDirectionForward, |
1238 webkit_event.get()); | 1251 webkit_event.get()); |
1239 } | 1252 } |
1240 } | 1253 } |
1241 | 1254 |
1242 // Releases references used to restore focus. | 1255 // Releases references used to restore focus. |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 Frame* frame = page_->focusController()->focusedFrame(); | 1723 Frame* frame = page_->focusController()->focusedFrame(); |
1711 if (!frame) | 1724 if (!frame) |
1712 return NULL; | 1725 return NULL; |
1713 | 1726 |
1714 Document* document = frame->document(); | 1727 Document* document = frame->document(); |
1715 if (!document) | 1728 if (!document) |
1716 return NULL; | 1729 return NULL; |
1717 | 1730 |
1718 return document->focusedNode(); | 1731 return document->focusedNode(); |
1719 } | 1732 } |
OLD | NEW |