Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: third_party/WebKit/Source/core/events/PointerEvent.cpp

Issue 1426643008: Cleaning up PointerIdManager and add id re-mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix EXPECT_EQ compilation error on Android Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "core/events/PointerEvent.h" 6 #include "core/events/PointerEvent.h"
7 7
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/events/EventDispatcher.h" 9 #include "core/events/EventDispatcher.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 namespace {
14
15 const char* pointerTypeNameForWebPointPointerType(WebPointerProperties::PointerT ype type)
16 {
17 switch (type) {
18 case WebPointerProperties::PointerType::Unknown:
19 return "";
20 case WebPointerProperties::PointerType::Touch:
21 return "touch";
22 case WebPointerProperties::PointerType::Pen:
23 return "pen";
24 case WebPointerProperties::PointerType::Mouse:
25 return "mouse";
26 }
27 ASSERT_NOT_REACHED();
28 return "";
29 }
30
31 }
32
33 PassRefPtrWillBeRawPtr<PointerEvent> PointerEvent::create(const AtomicString& ty pe,
34 const bool isPrimary, const PlatformMouseEvent& mouseEvent,
35 PassRefPtrWillBeRawPtr<Node> relatedTarget,
36 PassRefPtrWillBeRawPtr<AbstractView> view)
37 {
38 PointerEventInit pointerEventInit;
39
40 // TODO(crbug.com/537319): Define a constant somewhere for mouse id.
41 pointerEventInit.setPointerId(0);
42 pointerEventInit.setPointerType(
43 pointerTypeNameForWebPointPointerType(mouseEvent.pointerProperties().poi nterType));
44 pointerEventInit.setIsPrimary(true);
45
46 pointerEventInit.setScreenX(mouseEvent.globalPosition().x());
47 pointerEventInit.setScreenY(mouseEvent.globalPosition().y());
48 pointerEventInit.setClientX(mouseEvent.position().x());
49 pointerEventInit.setClientY(mouseEvent.position().y());
50
51 pointerEventInit.setButton(mouseEvent.button());
52 pointerEventInit.setButtons(MouseEvent::platformModifiersToButtons(mouseEven t.modifiers()));
53
54 pointerEventInit.setPressure(mouseEvent.pointerProperties().force);
55 pointerEventInit.setTiltX(mouseEvent.pointerProperties().tiltX);
56 pointerEventInit.setTiltY(mouseEvent.pointerProperties().tiltY);
57
58 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, mouseEvent.m odifiers());
59
60 pointerEventInit.setBubbles(type != EventTypeNames::pointerenter
61 && type != EventTypeNames::pointerleave);
62 pointerEventInit.setCancelable(type != EventTypeNames::pointerenter
63 && type != EventTypeNames::pointerleave && type != EventTypeNames::point ercancel);
64
65 pointerEventInit.setView(view);
66 if (relatedTarget)
67 pointerEventInit.setRelatedTarget(relatedTarget);
68
69 return PointerEvent::create(type, pointerEventInit);
70 }
71
72 PassRefPtrWillBeRawPtr<PointerEvent> PointerEvent::create(const AtomicString& ty pe,
73 const bool isPrimary, const PlatformTouchPoint& touchPoint,
74 PlatformEvent::Modifiers modifiers,
75 const double width, const double height,
76 const double clientX, const double clientY)
77 {
78 const unsigned& pointerId = touchPoint.id();
79 const PlatformTouchPoint::State pointState = touchPoint.state();
80
81 bool pointerReleasedOrCancelled = pointState == PlatformTouchPoint::TouchRel eased
82 || pointState == PlatformTouchPoint::TouchCancelled;
83
84 bool isEnterOrLeave = false;
85
86 PointerEventInit pointerEventInit;
87 pointerEventInit.setPointerId(pointerId);
88 pointerEventInit.setPointerType(
89 pointerTypeNameForWebPointPointerType(touchPoint.pointerProperties().poi nterType));
90 pointerEventInit.setIsPrimary(isPrimary);
91
92 pointerEventInit.setWidth(width);
93 pointerEventInit.setHeight(height);
94 pointerEventInit.setPressure(touchPoint.force());
95 pointerEventInit.setTiltX(touchPoint.pointerProperties().tiltX);
96 pointerEventInit.setTiltY(touchPoint.pointerProperties().tiltY);
97 pointerEventInit.setScreenX(touchPoint.screenPos().x());
98 pointerEventInit.setScreenY(touchPoint.screenPos().y());
99 pointerEventInit.setClientX(clientX);
100 pointerEventInit.setClientY(clientY);
101 pointerEventInit.setButton(0);
102 pointerEventInit.setButtons(pointerReleasedOrCancelled ? 0 : 1);
103
104 UIEventWithKeyState::setFromPlatformModifiers(pointerEventInit, modifiers);
105
106 pointerEventInit.setBubbles(!isEnterOrLeave);
107 pointerEventInit.setCancelable(!isEnterOrLeave && pointState != PlatformTouc hPoint::TouchCancelled);
108
109 return PointerEvent::create(type, pointerEventInit);
110 }
111
112 PointerEvent::PointerEvent() 13 PointerEvent::PointerEvent()
113 : m_pointerId(0) 14 : m_pointerId(0)
114 , m_width(0) 15 , m_width(0)
115 , m_height(0) 16 , m_height(0)
116 , m_pressure(0) 17 , m_pressure(0)
117 , m_tiltX(0) 18 , m_tiltX(0)
118 , m_tiltY(0) 19 , m_tiltY(0)
119 , m_isPrimary(false) 20 , m_isPrimary(false)
120 { 21 {
121 } 22 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ASSERT(!event().target() || event().target() != event().relatedTarget()); 95 ASSERT(!event().target() || event().target() != event().relatedTarget());
195 96
196 EventTarget* relatedTarget = event().relatedTarget(); 97 EventTarget* relatedTarget = event().relatedTarget();
197 event().eventPath().adjustForRelatedTarget(dispatcher.node(), relatedTarget) ; 98 event().eventPath().adjustForRelatedTarget(dispatcher.node(), relatedTarget) ;
198 99
199 dispatcher.dispatch(); 100 dispatcher.dispatch();
200 return !event().defaultHandled() && !event().defaultPrevented(); 101 return !event().defaultHandled() && !event().defaultPrevented();
201 } 102 }
202 103
203 } // namespace blink 104 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/PointerEvent.h ('k') | third_party/WebKit/Source/core/events/PointerEventFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698