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 void getDomCodeStringFromEnum(Widget* widget, String& code, long domCode) |
bokan
2015/01/20 17:05:58
Can we return the string, rather than using an out
Habib Virji
2015/01/22 16:01:30
Done.
| |
311 { | |
312 FrameView* view = toFrameView(widget->root()); | |
313 if (view) { | |
314 WebViewImpl* webView = WebViewImpl::fromPage(view->page()); | |
315 if (webView) | |
316 code = webView->client()->domCodeStringFromEnum(domCode); | |
317 } | |
Wez
2015/01/17 02:35:10
This leaves the |code| empty, which is also the st
Habib Virji
2015/01/22 16:01:30
I have sent mail to Gary with the questions.
For
| |
318 } | |
319 | |
320 static long getDomEnumFromCodeString(const Widget* widget, const String& code) | |
321 { | |
322 FrameView* view = toFrameView(widget->root()); | |
323 if (view) { | |
324 WebViewImpl* webView = WebViewImpl::fromPage(view->page()); | |
325 if (webView) | |
326 return webView->client()->domEnumFromCodeString(code.utf8().data()); | |
327 } | |
328 return 0; | |
Wez
2015/01/17 02:35:10
This means that the embedder cannot use zero as on
| |
329 } | |
330 | |
331 PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(Widget* widget, const WebKeyboardEvent& e) | |
309 { | 332 { |
310 m_type = toPlatformKeyboardEventType(e.type); | 333 m_type = toPlatformKeyboardEventType(e.type); |
311 m_text = String(e.text); | 334 m_text = String(e.text); |
312 m_unmodifiedText = String(e.unmodifiedText); | 335 m_unmodifiedText = String(e.unmodifiedText); |
313 m_keyIdentifier = String(e.keyIdentifier); | 336 m_keyIdentifier = String(e.keyIdentifier); |
314 m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat); | 337 m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat); |
315 m_nativeVirtualKeyCode = e.nativeKeyCode; | 338 m_nativeVirtualKeyCode = e.nativeKeyCode; |
316 m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad); | 339 m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad); |
317 m_isSystemKey = e.isSystemKey; | 340 m_isSystemKey = e.isSystemKey; |
341 getDomCodeStringFromEnum(widget, m_code, e.domCode); | |
318 | 342 |
319 m_modifiers = toPlatformEventModifiers(e.modifiers); | 343 m_modifiers = toPlatformEventModifiers(e.modifiers); |
320 | 344 |
321 // FIXME: PlatformKeyboardEvents expect a locational version of the keycode (e.g. VK_LSHIFT | 345 // 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, | 346 // instead of VK_SHIFT). This should be changed so the location/keycode are stored separately, |
323 // as in other places in the code. | 347 // as in other places in the code. |
324 m_windowsVirtualKeyCode = e.windowsKeyCode; | 348 m_windowsVirtualKeyCode = e.windowsKeyCode; |
325 if (e.windowsKeyCode == VK_SHIFT) { | 349 if (e.windowsKeyCode == VK_SHIFT) { |
326 if (e.modifiers & WebInputEvent::IsLeft) | 350 if (e.modifiers & WebInputEvent::IsLeft) |
327 m_windowsVirtualKeyCode = VK_LSHIFT; | 351 m_windowsVirtualKeyCode = VK_LSHIFT; |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 type = WebInputEvent::MouseWheel; | 662 type = WebInputEvent::MouseWheel; |
639 updateWebMouseEventFromCoreMouseEvent(event, widget, *renderObject, *this); | 663 updateWebMouseEventFromCoreMouseEvent(event, widget, *renderObject, *this); |
640 deltaX = -event.deltaX(); | 664 deltaX = -event.deltaX(); |
641 deltaY = -event.deltaY(); | 665 deltaY = -event.deltaY(); |
642 wheelTicksX = event.ticksX(); | 666 wheelTicksX = event.ticksX(); |
643 wheelTicksY = event.ticksY(); | 667 wheelTicksY = event.ticksY(); |
644 scrollByPage = event.deltaMode() == WheelEvent::DOM_DELTA_PAGE; | 668 scrollByPage = event.deltaMode() == WheelEvent::DOM_DELTA_PAGE; |
645 canScroll = event.canScroll(); | 669 canScroll = event.canScroll(); |
646 } | 670 } |
647 | 671 |
648 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) | 672 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const Widget* widget, const Key boardEvent& event) |
649 { | 673 { |
650 if (event.type() == EventTypeNames::keydown) | 674 if (event.type() == EventTypeNames::keydown) |
651 type = KeyDown; | 675 type = KeyDown; |
652 else if (event.type() == EventTypeNames::keyup) | 676 else if (event.type() == EventTypeNames::keyup) |
653 type = WebInputEvent::KeyUp; | 677 type = WebInputEvent::KeyUp; |
654 else if (event.type() == EventTypeNames::keypress) | 678 else if (event.type() == EventTypeNames::keypress) |
655 type = WebInputEvent::Char; | 679 type = WebInputEvent::Char; |
656 else | 680 else |
657 return; // Skip all other keyboard events. | 681 return; // Skip all other keyboard events. |
658 | 682 |
659 modifiers = getWebInputModifiers(event); | 683 modifiers = getWebInputModifiers(event); |
660 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) | 684 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) |
661 modifiers |= WebInputEvent::IsKeyPad; | 685 modifiers |= WebInputEvent::IsKeyPad; |
662 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) | 686 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) |
663 modifiers |= WebInputEvent::IsLeft; | 687 modifiers |= WebInputEvent::IsLeft; |
664 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) | 688 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) |
665 modifiers |= WebInputEvent::IsRight; | 689 modifiers |= WebInputEvent::IsRight; |
666 | 690 |
667 timeStampSeconds = event.timeStamp() / millisPerSecond; | 691 timeStampSeconds = event.timeStamp() / millisPerSecond; |
668 windowsKeyCode = event.keyCode(); | 692 windowsKeyCode = event.keyCode(); |
669 | 693 |
670 // The platform keyevent does not exist if the event was created using | 694 // The platform keyevent does not exist if the event was created using |
671 // initKeyboardEvent. | 695 // initKeyboardEvent. |
672 if (!event.keyEvent()) | 696 if (!event.keyEvent()) |
673 return; | 697 return; |
674 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); | 698 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); |
699 domCode = getDomEnumFromCodeString(widget, event.keyEvent()->code()); | |
675 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st atic_cast<unsigned>(textLengthCap)); | 700 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st atic_cast<unsigned>(textLengthCap)); |
676 for (unsigned i = 0; i < numberOfCharacters; ++i) { | 701 for (unsigned i = 0; i < numberOfCharacters; ++i) { |
677 text[i] = event.keyEvent()->text()[i]; | 702 text[i] = event.keyEvent()->text()[i]; |
678 unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; | 703 unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i]; |
679 } | 704 } |
680 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentif ier().length()); | 705 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), event.keyIdentif ier().length()); |
681 } | 706 } |
682 | 707 |
683 WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::Type type) | 708 WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::Type type) |
684 { | 709 { |
685 switch (type) { | 710 switch (type) { |
686 case PlatformEvent::KeyUp: | 711 case PlatformEvent::KeyUp: |
687 return WebInputEvent::KeyUp; | 712 return WebInputEvent::KeyUp; |
688 case PlatformEvent::KeyDown: | 713 case PlatformEvent::KeyDown: |
689 return WebInputEvent::KeyDown; | 714 return WebInputEvent::KeyDown; |
690 case PlatformEvent::RawKeyDown: | 715 case PlatformEvent::RawKeyDown: |
691 return WebInputEvent::RawKeyDown; | 716 return WebInputEvent::RawKeyDown; |
692 case PlatformEvent::Char: | 717 case PlatformEvent::Char: |
693 return WebInputEvent::Char; | 718 return WebInputEvent::Char; |
694 default: | 719 default: |
695 return WebInputEvent::Undefined; | 720 return WebInputEvent::Undefined; |
696 } | 721 } |
697 } | 722 } |
698 | 723 |
699 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const PlatformKeyboardEvent& ev ent) | 724 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const Widget* widget, const Pla tformKeyboardEvent& event) |
700 { | 725 { |
701 type = toWebKeyboardEventType(event.type()); | 726 type = toWebKeyboardEventType(event.type()); |
702 modifiers = toWebEventModifiers(event.modifiers()); | 727 modifiers = toWebEventModifiers(event.modifiers()); |
703 if (event.isAutoRepeat()) | 728 if (event.isAutoRepeat()) |
704 modifiers |= WebInputEvent::IsAutoRepeat; | 729 modifiers |= WebInputEvent::IsAutoRepeat; |
705 if (event.isKeypad()) | 730 if (event.isKeypad()) |
706 modifiers |= WebInputEvent::IsKeyPad; | 731 modifiers |= WebInputEvent::IsKeyPad; |
707 isSystemKey = event.isSystemKey(); | 732 isSystemKey = event.isSystemKey(); |
708 nativeKeyCode = event.nativeVirtualKeyCode(); | 733 nativeKeyCode = event.nativeVirtualKeyCode(); |
734 domCode = getDomEnumFromCodeString(widget, event.code()); | |
709 | 735 |
710 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() ); | 736 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() ); |
711 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ()); | 737 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ()); |
712 | 738 |
713 event.text().copyTo(text, 0, textLengthCap); | 739 event.text().copyTo(text, 0, textLengthCap); |
714 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); | 740 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); |
715 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); | 741 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); |
716 } | 742 } |
717 | 743 |
718 static WebTouchPoint toWebTouchPoint(const Touch* touch, const RenderObject* ren derObject, WebTouchPoint::State state) | 744 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); | 828 modifiers = getWebInputModifiers(event); |
803 | 829 |
804 globalX = event.screenX(); | 830 globalX = event.screenX(); |
805 globalY = event.screenY(); | 831 globalY = event.screenY(); |
806 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject); | 832 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject); |
807 x = localPoint.x(); | 833 x = localPoint.x(); |
808 y = localPoint.y(); | 834 y = localPoint.y(); |
809 } | 835 } |
810 | 836 |
811 } // namespace blink | 837 } // namespace blink |
OLD | NEW |