| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "core/frame/VisualViewport.h" | 43 #include "core/frame/VisualViewport.h" |
| 44 #include "core/layout/LayoutObject.h" | 44 #include "core/layout/LayoutObject.h" |
| 45 #include "core/page/ChromeClient.h" | 45 #include "core/page/ChromeClient.h" |
| 46 #include "core/page/Page.h" | 46 #include "core/page/Page.h" |
| 47 #include "platform/KeyboardCodes.h" | 47 #include "platform/KeyboardCodes.h" |
| 48 #include "platform/Widget.h" | 48 #include "platform/Widget.h" |
| 49 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 | 52 |
| 53 static const double millisPerSecond = 1000.0; | |
| 54 | |
| 55 static float scaleDeltaToWindow(const Widget* widget, float delta) | 53 static float scaleDeltaToWindow(const Widget* widget, float delta) |
| 56 { | 54 { |
| 57 float scale = 1; | 55 float scale = 1; |
| 58 if (widget) { | 56 if (widget) { |
| 59 FrameView* rootView = toFrameView(widget->root()); | 57 FrameView* rootView = toFrameView(widget->root()); |
| 60 if (rootView) | 58 if (rootView) |
| 61 scale = rootView->inputEventsScaleFactor(); | 59 scale = rootView->inputEventsScaleFactor(); |
| 62 } | 60 } |
| 63 return delta / scale; | 61 return delta / scale; |
| 64 } | 62 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 m_text = String(e.text); | 321 m_text = String(e.text); |
| 324 m_unmodifiedText = String(e.unmodifiedText); | 322 m_unmodifiedText = String(e.unmodifiedText); |
| 325 m_keyIdentifier = String(e.keyIdentifier); | 323 m_keyIdentifier = String(e.keyIdentifier); |
| 326 m_nativeVirtualKeyCode = e.nativeKeyCode; | 324 m_nativeVirtualKeyCode = e.nativeKeyCode; |
| 327 m_isSystemKey = e.isSystemKey; | 325 m_isSystemKey = e.isSystemKey; |
| 328 // TODO: BUG482880 Fix this initialization to lazy initialization. | 326 // TODO: BUG482880 Fix this initialization to lazy initialization. |
| 329 m_code = Platform::current()->domCodeStringFromEnum(e.domCode); | 327 m_code = Platform::current()->domCodeStringFromEnum(e.domCode); |
| 330 m_key = Platform::current()->domKeyStringFromEnum(e.domKey); | 328 m_key = Platform::current()->domKeyStringFromEnum(e.domKey); |
| 331 | 329 |
| 332 m_modifiers = toPlatformKeyboardEventModifiers(e.modifiers); | 330 m_modifiers = toPlatformKeyboardEventModifiers(e.modifiers); |
| 331 m_timestamp = e.timeStampSeconds; |
| 333 m_windowsVirtualKeyCode = e.windowsKeyCode; | 332 m_windowsVirtualKeyCode = e.windowsKeyCode; |
| 334 } | 333 } |
| 335 | 334 |
| 336 void PlatformKeyboardEventBuilder::setKeyType(Type type) | 335 void PlatformKeyboardEventBuilder::setKeyType(Type type) |
| 337 { | 336 { |
| 338 // According to the behavior of Webkit in Windows platform, | 337 // According to the behavior of Webkit in Windows platform, |
| 339 // we need to convert KeyDown to RawKeydown and Char events | 338 // we need to convert KeyDown to RawKeydown and Char events |
| 340 // See WebKit/WebKit/Win/WebView.cpp | 339 // See WebKit/WebKit/Win/WebView.cpp |
| 341 ASSERT(m_type == KeyDown); | 340 ASSERT(m_type == KeyDown); |
| 342 ASSERT(type == RawKeyDown || type == Char); | 341 ASSERT(type == RawKeyDown || type == Char); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 461 |
| 463 static IntPoint convertAbsoluteLocationForLayoutObject(const LayoutPoint& locati
on, const LayoutObject& layoutObject) | 462 static IntPoint convertAbsoluteLocationForLayoutObject(const LayoutPoint& locati
on, const LayoutObject& layoutObject) |
| 464 { | 463 { |
| 465 return roundedIntPoint(convertAbsoluteLocationForLayoutObjectFloat(location,
layoutObject)); | 464 return roundedIntPoint(convertAbsoluteLocationForLayoutObjectFloat(location,
layoutObject)); |
| 466 } | 465 } |
| 467 | 466 |
| 468 // FIXME: Change |widget| to const Widget& after RemoteFrames get | 467 // FIXME: Change |widget| to const Widget& after RemoteFrames get |
| 469 // RemoteFrameViews. | 468 // RemoteFrameViews. |
| 470 static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event
, const Widget* widget, const LayoutObject& layoutObject, WebMouseEvent& webEven
t) | 469 static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event
, const Widget* widget, const LayoutObject& layoutObject, WebMouseEvent& webEven
t) |
| 471 { | 470 { |
| 472 webEvent.timeStampSeconds = event.timeStamp() / millisPerSecond; | 471 webEvent.timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime())
; |
| 473 webEvent.modifiers = getWebInputModifiers(event); | 472 webEvent.modifiers = getWebInputModifiers(event); |
| 474 | 473 |
| 475 FrameView* view = widget ? toFrameView(widget->parent()) : 0; | 474 FrameView* view = widget ? toFrameView(widget->parent()) : 0; |
| 476 // FIXME: If view == nullptr, pointInRootFrame will really be pointInRootCon
tent. | 475 // FIXME: If view == nullptr, pointInRootFrame will really be pointInRootCon
tent. |
| 477 IntPoint pointInRootFrame = IntPoint(event.absoluteLocation().x(), event.abs
oluteLocation().y()); | 476 IntPoint pointInRootFrame = IntPoint(event.absoluteLocation().x(), event.abs
oluteLocation().y()); |
| 478 if (view) | 477 if (view) |
| 479 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); | 478 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
| 480 webEvent.globalX = event.screenX(); | 479 webEvent.globalX = event.screenX(); |
| 481 webEvent.globalY = event.screenY(); | 480 webEvent.globalY = event.screenY(); |
| 482 webEvent.windowX = pointInRootFrame.x(); | 481 webEvent.windowX = pointInRootFrame.x(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 551 |
| 553 if (event.type() == EventTypeNames::touchstart) | 552 if (event.type() == EventTypeNames::touchstart) |
| 554 type = MouseDown; | 553 type = MouseDown; |
| 555 else if (event.type() == EventTypeNames::touchmove) | 554 else if (event.type() == EventTypeNames::touchmove) |
| 556 type = MouseMove; | 555 type = MouseMove; |
| 557 else if (event.type() == EventTypeNames::touchend) | 556 else if (event.type() == EventTypeNames::touchend) |
| 558 type = MouseUp; | 557 type = MouseUp; |
| 559 else | 558 else |
| 560 return; | 559 return; |
| 561 | 560 |
| 562 timeStampSeconds = event.timeStamp() / millisPerSecond; | 561 // TODO(majidvp): Instead of using |Event::createTime| which is epoch time |
| 562 // we should instead use |Event::platformTimeStamp| which is the actual |
| 563 // platform monotonic time. See: crbug.com/538199 |
| 564 timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime()); |
| 563 modifiers = getWebInputModifiers(event); | 565 modifiers = getWebInputModifiers(event); |
| 564 | 566 |
| 565 // The mouse event co-ordinates should be generated from the co-ordinates of
the touch point. | 567 // The mouse event co-ordinates should be generated from the co-ordinates of
the touch point. |
| 566 FrameView* view = toFrameView(widget->parent()); | 568 FrameView* view = toFrameView(widget->parent()); |
| 567 // FIXME: if view == nullptr, pointInRootFrame will really be pointInRootCon
tent. | 569 // FIXME: if view == nullptr, pointInRootFrame will really be pointInRootCon
tent. |
| 568 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); | 570 IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); |
| 569 if (view) | 571 if (view) |
| 570 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); | 572 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
| 571 IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); | 573 IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); |
| 572 globalX = screenPoint.x(); | 574 globalX = screenPoint.x(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 return; // Skip all other keyboard events. | 613 return; // Skip all other keyboard events. |
| 612 | 614 |
| 613 modifiers = getWebInputModifiers(event); | 615 modifiers = getWebInputModifiers(event); |
| 614 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) | 616 if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_NUMPAD) |
| 615 modifiers |= WebInputEvent::IsKeyPad; | 617 modifiers |= WebInputEvent::IsKeyPad; |
| 616 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) | 618 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_LEFT) |
| 617 modifiers |= WebInputEvent::IsLeft; | 619 modifiers |= WebInputEvent::IsLeft; |
| 618 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) | 620 else if (event.location() == KeyboardEvent::DOM_KEY_LOCATION_RIGHT) |
| 619 modifiers |= WebInputEvent::IsRight; | 621 modifiers |= WebInputEvent::IsRight; |
| 620 | 622 |
| 621 timeStampSeconds = event.timeStamp() / millisPerSecond; | 623 timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime()); |
| 622 windowsKeyCode = event.keyCode(); | 624 windowsKeyCode = event.keyCode(); |
| 623 | 625 |
| 624 // The platform keyevent does not exist if the event was created using | 626 // The platform keyevent does not exist if the event was created using |
| 625 // initKeyboardEvent. | 627 // initKeyboardEvent. |
| 626 if (!event.keyEvent()) | 628 if (!event.keyEvent()) |
| 627 return; | 629 return; |
| 628 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); | 630 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode(); |
| 629 domCode = Platform::current()->domEnumFromCodeString(event.keyEvent()->code(
)); | 631 domCode = Platform::current()->domEnumFromCodeString(event.keyEvent()->code(
)); |
| 630 domKey = Platform::current()->domKeyEnumFromString(event.keyEvent()->key()); | 632 domKey = Platform::current()->domKeyEnumFromString(event.keyEvent()->key()); |
| 631 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st
atic_cast<unsigned>(textLengthCap)); | 633 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st
atic_cast<unsigned>(textLengthCap)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 type = TouchEnd; | 706 type = TouchEnd; |
| 705 else if (event.type() == EventTypeNames::touchcancel) | 707 else if (event.type() == EventTypeNames::touchcancel) |
| 706 type = TouchCancel; | 708 type = TouchCancel; |
| 707 else { | 709 else { |
| 708 ASSERT_NOT_REACHED(); | 710 ASSERT_NOT_REACHED(); |
| 709 type = Undefined; | 711 type = Undefined; |
| 710 return; | 712 return; |
| 711 } | 713 } |
| 712 | 714 |
| 713 modifiers = getWebInputModifiers(event); | 715 modifiers = getWebInputModifiers(event); |
| 714 timeStampSeconds = event.timeStamp() / millisPerSecond; | 716 timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime()); |
| 715 cancelable = event.cancelable(); | 717 cancelable = event.cancelable(); |
| 716 causesScrollingIfUncanceled = event.causesScrollingIfUncanceled(); | 718 causesScrollingIfUncanceled = event.causesScrollingIfUncanceled(); |
| 717 | 719 |
| 718 // Currently touches[] is empty, add stationary points as-is. | 720 // Currently touches[] is empty, add stationary points as-is. |
| 719 for (unsigned i = 0; i < event.touches()->length() && i < static_cast<unsign
ed>(WebTouchEvent::touchesLengthCap); ++i) { | 721 for (unsigned i = 0; i < event.touches()->length() && i < static_cast<unsign
ed>(WebTouchEvent::touchesLengthCap); ++i) { |
| 720 touches[i] = toWebTouchPoint(event.touches()->item(i), layoutObject, Web
TouchPoint::StateStationary); | 722 touches[i] = toWebTouchPoint(event.touches()->item(i), layoutObject, Web
TouchPoint::StateStationary); |
| 721 ++touchesLength; | 723 ++touchesLength; |
| 722 } | 724 } |
| 723 // If any existing points are also in the change list, we should update | 725 // If any existing points are also in the change list, we should update |
| 724 // their state, otherwise just add the new points. | 726 // their state, otherwise just add the new points. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 747 resendingPluginId = event.resendingPluginId(); | 749 resendingPluginId = event.resendingPluginId(); |
| 748 } else if (event.type() == EventTypeNames::gestureflingstart) { | 750 } else if (event.type() == EventTypeNames::gestureflingstart) { |
| 749 type = GestureFlingStart; | 751 type = GestureFlingStart; |
| 750 data.flingStart.velocityX = event.velocityX(); | 752 data.flingStart.velocityX = event.velocityX(); |
| 751 data.flingStart.velocityY = event.velocityY(); | 753 data.flingStart.velocityY = event.velocityY(); |
| 752 } else if (event.type() == EventTypeNames::gesturetap) { | 754 } else if (event.type() == EventTypeNames::gesturetap) { |
| 753 type = GestureTap; | 755 type = GestureTap; |
| 754 data.tap.tapCount = 1; | 756 data.tap.tapCount = 1; |
| 755 } | 757 } |
| 756 | 758 |
| 757 timeStampSeconds = event.timeStamp() / millisPerSecond; | 759 timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime()); |
| 758 modifiers = getWebInputModifiers(event); | 760 modifiers = getWebInputModifiers(event); |
| 759 | 761 |
| 760 globalX = event.screenX(); | 762 globalX = event.screenX(); |
| 761 globalY = event.screenY(); | 763 globalY = event.screenY(); |
| 762 IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteL
ocation(), *layoutObject); | 764 IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteL
ocation(), *layoutObject); |
| 763 x = localPoint.x(); | 765 x = localPoint.x(); |
| 764 y = localPoint.y(); | 766 y = localPoint.y(); |
| 765 } | 767 } |
| 766 | 768 |
| 767 } // namespace blink | 769 } // namespace blink |
| OLD | NEW |