OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) | 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) |
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) | 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) |
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
5 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. | 5 * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 23 matching lines...) Expand all Loading... |
34 // Internal only: Helper class for what's common between mouse and wheel events. | 34 // Internal only: Helper class for what's common between mouse and wheel events. |
35 class CORE_EXPORT MouseRelatedEvent : public UIEventWithKeyState { | 35 class CORE_EXPORT MouseRelatedEvent : public UIEventWithKeyState { |
36 public: | 36 public: |
37 enum class PositionType { | 37 enum class PositionType { |
38 Position, | 38 Position, |
39 // Positionless mouse events are used, for example, for 'click' events from | 39 // Positionless mouse events are used, for example, for 'click' events from |
40 // keyboard input. It's kind of surprising for a mouse event not to have a | 40 // keyboard input. It's kind of surprising for a mouse event not to have a |
41 // position. | 41 // position. |
42 Positionless | 42 Positionless |
43 }; | 43 }; |
| 44 |
44 // Note that these values are adjusted to counter the effects of zoom, so that | 45 // Note that these values are adjusted to counter the effects of zoom, so that |
45 // values exposed via DOM APIs are invariant under zooming. | 46 // values exposed via DOM APIs are invariant under zooming. |
46 int screenX() const { return m_screenLocation.x(); } | 47 // TODO(mustaq): Remove the PointerEvent specific code when mouse has |
47 int screenY() const { return m_screenLocation.y(); } | 48 // fractional coordinates. See crbug.com/655786. |
48 const IntPoint& screenLocation() const { return m_screenLocation; } | 49 double screenX() const { |
49 int clientX() const { return m_clientLocation.x().toInt(); } | 50 return isPointerEvent() ? m_screenLocation.x() |
50 int clientY() const { return m_clientLocation.y().toInt(); } | 51 : static_cast<int>(m_screenLocation.x()); |
51 int movementX() const { return m_movementDelta.x().toInt(); } | 52 } |
52 int movementY() const { return m_movementDelta.y().toInt(); } | 53 double screenY() const { |
53 const LayoutPoint& clientLocation() const { return m_clientLocation; } | 54 return isPointerEvent() ? m_screenLocation.y() |
| 55 : static_cast<int>(m_screenLocation.y()); |
| 56 } |
| 57 |
| 58 double clientX() const { |
| 59 return isPointerEvent() ? m_clientLocation.x() |
| 60 : static_cast<int>(m_clientLocation.x()); |
| 61 } |
| 62 double clientY() const { |
| 63 return isPointerEvent() ? m_clientLocation.y() |
| 64 : static_cast<int>(m_clientLocation.y()); |
| 65 } |
| 66 |
| 67 int movementX() const { return m_movementDelta.x(); } |
| 68 int movementY() const { return m_movementDelta.y(); } |
| 69 |
54 int layerX(); | 70 int layerX(); |
55 int layerY(); | 71 int layerY(); |
| 72 |
56 int offsetX(); | 73 int offsetX(); |
57 int offsetY(); | 74 int offsetY(); |
58 int pageX() const; | 75 |
59 int pageY() const; | 76 double pageX() const { |
60 int x() const; | 77 return isPointerEvent() ? m_pageLocation.x() |
61 int y() const; | 78 : static_cast<int>(m_pageLocation.x()); |
| 79 } |
| 80 double pageY() const { |
| 81 return isPointerEvent() ? m_pageLocation.y() |
| 82 : static_cast<int>(m_pageLocation.y()); |
| 83 } |
| 84 |
| 85 double x() const { return clientX(); } |
| 86 double y() const { return clientY(); } |
| 87 |
62 bool hasPosition() const { return m_positionType == PositionType::Position; } | 88 bool hasPosition() const { return m_positionType == PositionType::Position; } |
63 | 89 |
64 // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative | 90 // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative |
65 // coords, usable with LayoutObject::absoluteToLocal) relative to view(), i.e. | 91 // coords, usable with LayoutObject::absoluteToLocal) relative to view(), i.e. |
66 // the local frame. | 92 // the local frame. |
67 const LayoutPoint& absoluteLocation() const { return m_absoluteLocation; } | 93 const DoublePoint& absoluteLocation() const { return m_absoluteLocation; } |
68 void setAbsoluteLocation(const LayoutPoint& p) { m_absoluteLocation = p; } | |
69 | 94 |
70 DECLARE_VIRTUAL_TRACE(); | 95 DECLARE_VIRTUAL_TRACE(); |
71 | 96 |
72 protected: | 97 protected: |
73 MouseRelatedEvent(); | 98 MouseRelatedEvent(); |
74 // TODO(lanwei): Will make this argument non-optional and all the callers need | 99 // TODO(lanwei): Will make this argument non-optional and all the callers need |
75 // to provide sourceCapabilities even when it is null, see | 100 // to provide sourceCapabilities even when it is null, see |
76 // https://crbug.com/476530. | 101 // https://crbug.com/476530. |
77 MouseRelatedEvent(const AtomicString& type, | 102 MouseRelatedEvent(const AtomicString& type, |
78 bool canBubble, | 103 bool canBubble, |
79 bool cancelable, | 104 bool cancelable, |
80 AbstractView*, | 105 AbstractView*, |
81 int detail, | 106 int detail, |
82 const IntPoint& screenLocation, | 107 const IntPoint& screenLocation, |
83 const IntPoint& rootFrameLocation, | 108 const IntPoint& rootFrameLocation, |
84 const IntPoint& movementDelta, | 109 const IntPoint& movementDelta, |
85 PlatformEvent::Modifiers, | 110 PlatformEvent::Modifiers, |
86 double platformTimeStamp, | 111 double platformTimeStamp, |
87 PositionType, | 112 PositionType, |
88 InputDeviceCapabilities* sourceCapabilities = nullptr); | 113 InputDeviceCapabilities* sourceCapabilities = nullptr); |
89 | 114 |
90 MouseRelatedEvent(const AtomicString& type, | 115 MouseRelatedEvent(const AtomicString& type, |
91 const MouseEventInit& initializer); | 116 const MouseEventInit& initializer); |
92 | 117 |
93 void initCoordinates(const LayoutPoint& clientLocation); | 118 void initCoordinates(const double clientX, const double clientY); |
94 void receivedTarget() final; | 119 void receivedTarget() final; |
95 | 120 |
96 void computePageLocation(); | 121 void computePageLocation(); |
97 void computeRelativePosition(); | 122 void computeRelativePosition(); |
98 | 123 |
99 // Expose these so MouseEvent::initMouseEvent can set them. | 124 // Expose these so MouseEvent::initMouseEvent can set them. |
100 IntPoint m_screenLocation; | 125 DoublePoint m_screenLocation; |
101 LayoutPoint m_clientLocation; | 126 DoublePoint m_clientLocation; |
102 LayoutPoint m_movementDelta; | 127 DoublePoint m_movementDelta; |
103 | 128 |
104 private: | 129 private: |
105 LayoutPoint m_pageLocation; | 130 DoublePoint m_pageLocation; |
106 LayoutPoint m_layerLocation; | 131 DoublePoint m_layerLocation; |
107 LayoutPoint m_offsetLocation; | 132 DoublePoint m_offsetLocation; |
108 LayoutPoint m_absoluteLocation; | 133 DoublePoint m_absoluteLocation; |
109 PositionType m_positionType; | 134 PositionType m_positionType; |
110 bool m_hasCachedRelativePosition; | 135 bool m_hasCachedRelativePosition; |
111 }; | 136 }; |
112 | 137 |
113 } // namespace blink | 138 } // namespace blink |
114 | 139 |
115 #endif // MouseRelatedEvent_h | 140 #endif // MouseRelatedEvent_h |
OLD | NEW |