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