1/*
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2013 Apple Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#pragma once
25
26#include "LayoutPoint.h"
27#include "UIEventWithKeyState.h"
28
29namespace WebCore {
30
31class FrameView;
32
33struct MouseRelatedEventInit : public EventModifierInit {
34 int screenX { 0 };
35 int screenY { 0 };
36};
37
38// Internal only: Helper class for what's common between mouse and wheel events.
39class MouseRelatedEvent : public UIEventWithKeyState {
40public:
41 enum class IsSimulated : uint8_t { Yes, No };
42
43 // Note that these values are adjusted to counter the effects of zoom, so that values
44 // exposed via DOM APIs are invariant under zooming.
45 int screenX() const { return m_screenLocation.x(); }
46 int screenY() const { return m_screenLocation.y(); }
47 const IntPoint& screenLocation() const { return m_screenLocation; }
48 int clientX() const { return m_clientLocation.x(); }
49 int clientY() const { return m_clientLocation.y(); }
50#if ENABLE(POINTER_LOCK)
51 int movementX() const { return m_movementDelta.x(); }
52 int movementY() const { return m_movementDelta.y(); }
53#endif
54 const LayoutPoint& clientLocation() const { return m_clientLocation; }
55 int layerX() override;
56 int layerY() override;
57 WEBCORE_EXPORT int offsetX();
58 WEBCORE_EXPORT int offsetY();
59 bool isSimulated() const { return m_isSimulated; }
60 void setIsSimulated(bool value) { m_isSimulated = value; }
61 int pageX() const final;
62 int pageY() const final;
63 FloatPoint locationInRootViewCoordinates() const;
64 virtual const LayoutPoint& pageLocation() const;
65 WEBCORE_EXPORT int x() const;
66 WEBCORE_EXPORT int y() const;
67
68 // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative coords,
69 // usable with RenderObject::absoluteToLocal).
70 const LayoutPoint& absoluteLocation() const { return m_absoluteLocation; }
71
72 static FrameView* frameViewFromWindowProxy(WindowProxy*);
73
74 static LayoutPoint pagePointToClientPoint(LayoutPoint pagePoint, FrameView*);
75 static LayoutPoint pagePointToAbsolutePoint(LayoutPoint pagePoint, FrameView*);
76
77protected:
78 MouseRelatedEvent() = default;
79 MouseRelatedEvent(const AtomString& type, CanBubble, IsCancelable, IsComposed, MonotonicTime, RefPtr<WindowProxy>&&, int detail,
80 const IntPoint& screenLocation, const IntPoint& windowLocation, const IntPoint& movementDelta, OptionSet<Modifier> modifiers,
81 IsSimulated = IsSimulated::No, IsTrusted = IsTrusted::Yes);
82 MouseRelatedEvent(const AtomString& type, IsCancelable, MonotonicTime, RefPtr<WindowProxy>&&, const IntPoint& globalLocation, OptionSet<Modifier>);
83 MouseRelatedEvent(const AtomString& type, const MouseRelatedEventInit&, IsTrusted = IsTrusted::No);
84
85 void initCoordinates();
86 void initCoordinates(const LayoutPoint& clientLocation);
87 void receivedTarget() final;
88
89 void computePageLocation();
90 void computeRelativePosition();
91
92 float documentToAbsoluteScaleFactor() const;
93
94 // Expose these so MouseEvent::initMouseEvent can set them.
95 IntPoint m_screenLocation;
96 LayoutPoint m_clientLocation;
97#if ENABLE(POINTER_LOCK)
98 LayoutPoint m_movementDelta;
99#endif
100
101private:
102 void init(bool isSimulated, const IntPoint&);
103
104 LayoutPoint m_pageLocation;
105 LayoutPoint m_layerLocation;
106 LayoutPoint m_offsetLocation;
107 LayoutPoint m_absoluteLocation;
108 bool m_isSimulated { false };
109 bool m_hasCachedRelativePosition { false };
110};
111
112} // namespace WebCore
113