OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/events/MouseEvent.h" | 38 #include "core/events/MouseEvent.h" |
39 #include "core/events/TouchEvent.h" | 39 #include "core/events/TouchEvent.h" |
40 #include "core/events/WheelEvent.h" | 40 #include "core/events/WheelEvent.h" |
41 #include "core/frame/FrameHost.h" | 41 #include "core/frame/FrameHost.h" |
42 #include "core/frame/FrameView.h" | 42 #include "core/frame/FrameView.h" |
43 #include "core/frame/PinchViewport.h" | 43 #include "core/frame/PinchViewport.h" |
44 #include "core/page/Page.h" | 44 #include "core/page/Page.h" |
45 #include "core/rendering/RenderObject.h" | 45 #include "core/rendering/RenderObject.h" |
46 #include "platform/KeyboardCodes.h" | 46 #include "platform/KeyboardCodes.h" |
47 #include "platform/Widget.h" | 47 #include "platform/Widget.h" |
| 48 #include "public/web/WebViewClient.h" |
| 49 #include "web/WebViewImpl.h" |
48 | 50 |
49 namespace blink { | 51 namespace blink { |
50 | 52 |
51 static const double millisPerSecond = 1000.0; | 53 static const double millisPerSecond = 1000.0; |
52 | 54 |
53 static float scaleDeltaToWindow(const Widget* widget, float delta) | 55 static float scaleDeltaToWindow(const Widget* widget, float delta) |
54 { | 56 { |
55 float scale = 1; | 57 float scale = 1; |
56 if (widget) { | 58 if (widget) { |
57 FrameView* rootView = toFrameView(widget->root()); | 59 FrameView* rootView = toFrameView(widget->root()); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 case WebInputEvent::RawKeyDown: | 300 case WebInputEvent::RawKeyDown: |
299 return PlatformEvent::RawKeyDown; | 301 return PlatformEvent::RawKeyDown; |
300 case WebInputEvent::Char: | 302 case WebInputEvent::Char: |
301 return PlatformEvent::Char; | 303 return PlatformEvent::Char; |
302 default: | 304 default: |
303 ASSERT_NOT_REACHED(); | 305 ASSERT_NOT_REACHED(); |
304 } | 306 } |
305 return PlatformEvent::KeyDown; | 307 return PlatformEvent::KeyDown; |
306 } | 308 } |
307 | 309 |
308 PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(const WebKeyboardEven
t& e) | 310 static String getDomCodeStringFromEnum(Widget* widget, long domCode) |
| 311 { |
| 312 FrameView* view = toFrameView(widget->root()); |
| 313 if (view) { |
| 314 WebViewImpl* webView = WebViewImpl::fromPage(view->page()); |
| 315 if (webView) |
| 316 return webView->client()->domCodeStringFromEnum(domCode); |
| 317 } |
| 318 return String("Undefined"); |
| 319 } |
| 320 |
| 321 static int getDomEnumFromCodeString(const Widget* widget, const String& code) |
| 322 { |
| 323 FrameView* view = toFrameView(widget->root()); |
| 324 if (view) { |
| 325 WebViewImpl* webView = WebViewImpl::fromPage(view->page()); |
| 326 if (webView) |
| 327 return webView->client()->domEnumFromCodeString(code); |
| 328 } |
| 329 return 0; |
| 330 } |
| 331 |
| 332 PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(Widget* widget, const
WebKeyboardEvent& e) |
309 { | 333 { |
310 m_type = toPlatformKeyboardEventType(e.type); | 334 m_type = toPlatformKeyboardEventType(e.type); |
311 m_text = String(e.text); | 335 m_text = String(e.text); |
312 m_unmodifiedText = String(e.unmodifiedText); | 336 m_unmodifiedText = String(e.unmodifiedText); |
313 m_keyIdentifier = String(e.keyIdentifier); | 337 m_keyIdentifier = String(e.keyIdentifier); |
314 m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat); | 338 m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat); |
315 m_nativeVirtualKeyCode = e.nativeKeyCode; | 339 m_nativeVirtualKeyCode = e.nativeKeyCode; |
316 m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad); | 340 m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad); |
317 m_isSystemKey = e.isSystemKey; | 341 m_isSystemKey = e.isSystemKey; |
| 342 m_code = getDomCodeStringFromEnum(widget, e.domCode); |
318 | 343 |
319 m_modifiers = toPlatformEventModifiers(e.modifiers); | 344 m_modifiers = toPlatformEventModifiers(e.modifiers); |
320 | 345 |
321 // FIXME: PlatformKeyboardEvents expect a locational version of the keycode
(e.g. VK_LSHIFT | 346 // FIXME: PlatformKeyboardEvents expect a locational version of the keycode
(e.g. VK_LSHIFT |
322 // instead of VK_SHIFT). This should be changed so the location/keycode are
stored separately, | 347 // instead of VK_SHIFT). This should be changed so the location/keycode are
stored separately, |
323 // as in other places in the code. | 348 // as in other places in the code. |
324 m_windowsVirtualKeyCode = e.windowsKeyCode; | 349 m_windowsVirtualKeyCode = e.windowsKeyCode; |
325 if (e.windowsKeyCode == VK_SHIFT) { | 350 if (e.windowsKeyCode == VK_SHIFT) { |
326 if (e.modifiers & WebInputEvent::IsLeft) | 351 if (e.modifiers & WebInputEvent::IsLeft) |
327 m_windowsVirtualKeyCode = VK_LSHIFT; | 352 m_windowsVirtualKeyCode = VK_LSHIFT; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 type = WebInputEvent::MouseWheel; | 663 type = WebInputEvent::MouseWheel; |
639 updateWebMouseEventFromCoreMouseEvent(event, widget, *renderObject, *this); | 664 updateWebMouseEventFromCoreMouseEvent(event, widget, *renderObject, *this); |
640 deltaX = -event.deltaX(); | 665 deltaX = -event.deltaX(); |
641 deltaY = -event.deltaY(); | 666 deltaY = -event.deltaY(); |
642 wheelTicksX = event.ticksX(); | 667 wheelTicksX = event.ticksX(); |
643 wheelTicksY = event.ticksY(); | 668 wheelTicksY = event.ticksY(); |
644 scrollByPage = event.deltaMode() == WheelEvent::DOM_DELTA_PAGE; | 669 scrollByPage = event.deltaMode() == WheelEvent::DOM_DELTA_PAGE; |
645 canScroll = event.canScroll(); | 670 canScroll = event.canScroll(); |
646 } | 671 } |
647 | 672 |
648 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) | 673 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const Widget* widget, const Key
boardEvent& event) |
649 { | 674 { |
650 if (event.type() == EventTypeNames::keydown) | 675 if (event.type() == EventTypeNames::keydown) |
651 type = KeyDown; | 676 type = KeyDown; |
652 else if (event.type() == EventTypeNames::keyup) | 677 else if (event.type() == EventTypeNames::keyup) |
653 type = WebInputEvent::KeyUp; | 678 type = WebInputEvent::KeyUp; |
654 else if (event.type() == EventTypeNames::keypress) | 679 else if (event.type() == EventTypeNames::keypress) |
655 type = WebInputEvent::Char; | 680 type = WebInputEvent::Char; |
656 else | 681 else |
657 return; // Skip all other keyboard events. | 682 return; // Skip all other keyboard events. |
658 | 683 |
659 modifiers = getWebInputModifiers(event); | 684 modifiers = getWebInputModifiers(event); |
660 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) | 685 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) |
661 modifiers |= WebInputEvent::IsKeyPad; | 686 modifiers |= WebInputEvent::IsKeyPad; |
662 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) | 687 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) |
663 modifiers |= WebInputEvent::IsLeft; | 688 modifiers |= WebInputEvent::IsLeft; |
664 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) | 689 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) |
665 modifiers |= WebInputEvent::IsRight; | 690 modifiers |= WebInputEvent::IsRight; |
666 | 691 |
667 timeStampSeconds = event.timeStamp() / millisPerSecond; | 692 timeStampSeconds = event.timeStamp() / millisPerSecond; |
668 windowsKeyCode = event.keyCode(); | 693 windowsKeyCode = event.keyCode(); |
669 | 694 |
670 // The platform keyevent does not exist if the event was created using | 695 // The platform keyevent does not exist if the event was created using |
671 // initKeyboardEvent. | 696 // initKeyboardEvent. |
672 if (!event.keyEvent()) | 697 if (!event.keyEvent()) |
673 return; | 698 return; |
674 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); | 699 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); |
| 700 domCode = getDomEnumFromCodeString(widget, event.keyEvent()->code()); |
675 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st
atic_cast<unsigned>(textLengthCap)); | 701 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st
atic_cast<unsigned>(textLengthCap)); |
676 for (unsigned i = 0; i < numberOfCharacters; ++i) { | 702 for (unsigned i = 0; i < numberOfCharacters; ++i) { |
677 text[i] = event.keyEvent()->text()[i]; | 703 text[i] = event.keyEvent()->text()[i]; |
678 unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; | 704 unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; |
679 } | 705 } |
680 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentif
ier().length()); | 706 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentif
ier().length()); |
681 } | 707 } |
682 | 708 |
683 WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::Type type) | 709 WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::Type type) |
684 { | 710 { |
685 switch (type) { | 711 switch (type) { |
686 case PlatformEvent::KeyUp: | 712 case PlatformEvent::KeyUp: |
687 return WebInputEvent::KeyUp; | 713 return WebInputEvent::KeyUp; |
688 case PlatformEvent::KeyDown: | 714 case PlatformEvent::KeyDown: |
689 return WebInputEvent::KeyDown; | 715 return WebInputEvent::KeyDown; |
690 case PlatformEvent::RawKeyDown: | 716 case PlatformEvent::RawKeyDown: |
691 return WebInputEvent::RawKeyDown; | 717 return WebInputEvent::RawKeyDown; |
692 case PlatformEvent::Char: | 718 case PlatformEvent::Char: |
693 return WebInputEvent::Char; | 719 return WebInputEvent::Char; |
694 default: | 720 default: |
695 return WebInputEvent::Undefined; | 721 return WebInputEvent::Undefined; |
696 } | 722 } |
697 } | 723 } |
698 | 724 |
699 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const PlatformKeyboardEvent& ev
ent) | 725 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const Widget* widget, const Pla
tformKeyboardEvent& event) |
700 { | 726 { |
701 type = toWebKeyboardEventType(event.type()); | 727 type = toWebKeyboardEventType(event.type()); |
702 modifiers = toWebEventModifiers(event.modifiers()); | 728 modifiers = toWebEventModifiers(event.modifiers()); |
703 if (event.isAutoRepeat()) | 729 if (event.isAutoRepeat()) |
704 modifiers |= WebInputEvent::IsAutoRepeat; | 730 modifiers |= WebInputEvent::IsAutoRepeat; |
705 if (event.isKeypad()) | 731 if (event.isKeypad()) |
706 modifiers |= WebInputEvent::IsKeyPad; | 732 modifiers |= WebInputEvent::IsKeyPad; |
707 isSystemKey = event.isSystemKey(); | 733 isSystemKey = event.isSystemKey(); |
708 nativeKeyCode = event.nativeVirtualKeyCode(); | 734 nativeKeyCode = event.nativeVirtualKeyCode(); |
| 735 domCode = getDomEnumFromCodeString(widget, event.code()); |
709 | 736 |
710 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode()
); | 737 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode()
); |
711 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode
()); | 738 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode
()); |
712 | 739 |
713 event.text().copyTo(text, 0, textLengthCap); | 740 event.text().copyTo(text, 0, textLengthCap); |
714 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); | 741 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); |
715 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_
cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); | 742 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_
cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); |
716 } | 743 } |
717 | 744 |
718 static WebTouchPoint toWebTouchPoint(const Touch* touch, const RenderObject* ren
derObject, WebTouchPoint::State state) | 745 static WebTouchPoint toWebTouchPoint(const Touch* touch, const RenderObject* ren
derObject, WebTouchPoint::State state) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 modifiers = getWebInputModifiers(event); | 829 modifiers = getWebInputModifiers(event); |
803 | 830 |
804 globalX = event.screenX(); | 831 globalX = event.screenX(); |
805 globalY = event.screenY(); | 832 globalY = event.screenY(); |
806 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL
ocation(), *renderObject); | 833 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL
ocation(), *renderObject); |
807 x = localPoint.x(); | 834 x = localPoint.x(); |
808 y = localPoint.y(); | 835 y = localPoint.y(); |
809 } | 836 } |
810 | 837 |
811 } // namespace blink | 838 } // namespace blink |
OLD | NEW |