Chromium Code Reviews| 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 LayoutPoint scrollPosition; |
| 106 LayoutPoint adjustedPageLocation; | |
| 107 if (view && view->frame()) { | |
| 108 LocalFrame* frame = view->frame(); | |
| 109 if (FrameView* frameView = frame->view()) { | |
|
bokan
2016/05/10 22:24:09
Fold this check into the above one.
Navid Zolghadr
2016/05/11 18:09:43
Done.
| |
| 110 scrollPosition = frameView->scrollPosition(); | |
| 111 adjustedPageLocation = frameView->rootFrameToContents(mouseEvent.pos ition()); | |
|
bokan
2016/05/10 22:24:09
s/adjustedPageLocation/locationInContents
Navid Zolghadr
2016/05/11 18:09:43
Done.
| |
| 112 float scaleFactor = 1 / frame->pageZoomFactor(); | |
| 113 if (scaleFactor != 1.0f) { | |
|
bokan
2016/05/10 22:24:09
No need for the check here, just allow scaling by
Navid Zolghadr
2016/05/11 18:09:43
Done.
| |
| 114 adjustedPageLocation.scale(scaleFactor, scaleFactor); | |
| 115 scrollPosition.scale(scaleFactor, scaleFactor); | |
| 116 } | |
| 117 } | |
| 118 } | |
| 119 LayoutPoint clientPoint = adjustedPageLocation - toLayoutSize(scrollPosition ); | |
|
bokan
2016/05/10 22:24:09
I would do this like so:
locationInContents = fra
Navid Zolghadr
2016/05/11 18:09:43
Done.
| |
| 120 | |
| 121 // Set up initial values for coordinates. | |
| 122 // Set up initial values for coordinates. | |
| 123 pointerEventInit.setClientX(clientPoint.x().toInt()); | |
| 124 pointerEventInit.setClientY(clientPoint.y().toInt()); | |
| 105 | 125 |
| 106 if (pointerEventName == EventTypeNames::pointerdown | 126 if (pointerEventName == EventTypeNames::pointerdown |
| 107 || pointerEventName == EventTypeNames::pointerup) { | 127 || pointerEventName == EventTypeNames::pointerup) { |
| 108 pointerEventInit.setButton(mouseEvent.button()); | 128 pointerEventInit.setButton(mouseEvent.button()); |
| 109 } else { | 129 } else { |
| 110 // TODO(crbug.com/587955): We are setting NoButton for transition | 130 // TODO(crbug.com/587955): We are setting NoButton for transition |
| 111 // pointerevents should be resolved as part of this bug | 131 // pointerevents should be resolved as part of this bug |
| 112 pointerEventInit.setButton(NoButton); | 132 pointerEventInit.setButton(NoButton); |
| 113 } | 133 } |
| 114 pointerEventInit.setPressure(getPointerEventPressure( | 134 pointerEventInit.setPressure(getPointerEventPressure( |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 if (properties.pointerType | 383 if (properties.pointerType |
| 364 == WebPointerProperties::PointerType::Mouse) | 384 == WebPointerProperties::PointerType::Mouse) |
| 365 return PointerEventFactory::s_mouseId; | 385 return PointerEventFactory::s_mouseId; |
| 366 IncomingId id(properties.pointerType, properties.id); | 386 IncomingId id(properties.pointerType, properties.id); |
| 367 if (m_pointerIncomingIdMapping.contains(id)) | 387 if (m_pointerIncomingIdMapping.contains(id)) |
| 368 return m_pointerIncomingIdMapping.get(id); | 388 return m_pointerIncomingIdMapping.get(id); |
| 369 return PointerEventFactory::s_invalidId; | 389 return PointerEventFactory::s_invalidId; |
| 370 } | 390 } |
| 371 | 391 |
| 372 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |