| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/events/PointerEventFactory.h" | 5 #include "core/events/PointerEventFactory.h" |
| 6 | 6 |
| 7 #include "core/frame/FrameView.h" |
| 7 #include "platform/geometry/FloatSize.h" | 8 #include "platform/geometry/FloatSize.h" |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(
t); } | 14 inline int toInt(WebPointerProperties::PointerType t) { return static_cast<int>(
t); } |
| 14 | 15 |
| 15 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT
ype type) | 16 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT
ype type) |
| 16 { | 17 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 { | 83 { |
| 83 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter | 84 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter |
| 84 && type != EventTypeNames::pointerleave); | 85 && type != EventTypeNames::pointerleave); |
| 85 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter | 86 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter |
| 86 && type != EventTypeNames::pointerleave && type != EventTypeNames::point
ercancel); | 87 && type != EventTypeNames::pointerleave && type != EventTypeNames::point
ercancel); |
| 87 } | 88 } |
| 88 | 89 |
| 89 PointerEvent* PointerEventFactory::create( | 90 PointerEvent* PointerEventFactory::create( |
| 90 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, | 91 const AtomicString& mouseEventName, const PlatformMouseEvent& mouseEvent, |
| 91 EventTarget* relatedTarget, | 92 EventTarget* relatedTarget, |
| 92 AbstractView* view) | 93 LocalDOMWindow* view) |
| 93 { | 94 { |
| 94 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent
Name); | 95 AtomicString pointerEventName = pointerEventNameForMouseEventName(mouseEvent
Name); |
| 95 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi
fiers()); | 96 unsigned buttons = MouseEvent::platformModifiersToButtons(mouseEvent.getModi
fiers()); |
| 96 PointerEventInit pointerEventInit; | 97 PointerEventInit pointerEventInit; |
| 97 | 98 |
| 98 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); | 99 setIdTypeButtons(pointerEventInit, mouseEvent.pointerProperties(), buttons); |
| 99 setBubblesAndCancelable(pointerEventInit, pointerEventName); | 100 setBubblesAndCancelable(pointerEventInit, pointerEventName); |
| 100 | 101 |
| 101 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); | 102 pointerEventInit.setScreenX(mouseEvent.globalPosition().x()); |
| 102 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); | 103 pointerEventInit.setScreenY(mouseEvent.globalPosition().y()); |
| 103 pointerEventInit.setClientX(mouseEvent.position().x()); | 104 |
| 104 pointerEventInit.setClientY(mouseEvent.position().y()); | 105 IntPoint locationInFrameZoomed; |
| 106 if (view && view->frame() && view->frame()->view()) { |
| 107 LocalFrame* frame = view->frame(); |
| 108 FrameView* frameView = frame->view(); |
| 109 IntPoint locationInContents = frameView->rootFrameToContents(mouseEvent.
position()); |
| 110 locationInFrameZoomed = frameView->contentsToFrame(locationInContents); |
| 111 float scaleFactor = 1 / frame->pageZoomFactor(); |
| 112 locationInFrameZoomed.scale(scaleFactor, scaleFactor); |
| 113 } |
| 114 |
| 115 // Set up initial values for coordinates. |
| 116 pointerEventInit.setClientX(locationInFrameZoomed.x()); |
| 117 pointerEventInit.setClientY(locationInFrameZoomed.y()); |
| 105 | 118 |
| 106 if (pointerEventName == EventTypeNames::pointerdown | 119 if (pointerEventName == EventTypeNames::pointerdown |
| 107 || pointerEventName == EventTypeNames::pointerup) { | 120 || pointerEventName == EventTypeNames::pointerup) { |
| 108 pointerEventInit.setButton(mouseEvent.button()); | 121 pointerEventInit.setButton(mouseEvent.button()); |
| 109 } else { | 122 } else { |
| 110 // TODO(crbug.com/587955): We are setting NoButton for transition | 123 // TODO(crbug.com/587955): We are setting NoButton for transition |
| 111 // pointerevents should be resolved as part of this bug | 124 // pointerevents should be resolved as part of this bug |
| 112 pointerEventInit.setButton(NoButton); | 125 pointerEventInit.setButton(NoButton); |
| 113 } | 126 } |
| 114 pointerEventInit.setPressure(getPointerEventPressure( | 127 pointerEventInit.setPressure(getPointerEventPressure( |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if (properties.pointerType | 376 if (properties.pointerType |
| 364 == WebPointerProperties::PointerType::Mouse) | 377 == WebPointerProperties::PointerType::Mouse) |
| 365 return PointerEventFactory::s_mouseId; | 378 return PointerEventFactory::s_mouseId; |
| 366 IncomingId id(properties.pointerType, properties.id); | 379 IncomingId id(properties.pointerType, properties.id); |
| 367 if (m_pointerIncomingIdMapping.contains(id)) | 380 if (m_pointerIncomingIdMapping.contains(id)) |
| 368 return m_pointerIncomingIdMapping.get(id); | 381 return m_pointerIncomingIdMapping.get(id); |
| 369 return PointerEventFactory::s_invalidId; | 382 return PointerEventFactory::s_invalidId; |
| 370 } | 383 } |
| 371 | 384 |
| 372 } // namespace blink | 385 } // namespace blink |
| OLD | NEW |