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

Side by Side Diff: sky/engine/core/events/MouseRelatedEvent.cpp

Issue 873963003: Remove more mouse-specific code (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Build fixes Created 5 years, 11 months 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
« no previous file with comments | « sky/engine/core/events/MouseRelatedEvent.h ('k') | sky/engine/core/html/HTMLAnchorElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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, 2005, 2006, 2008 Apple Inc. All rights reserved.
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 #include "sky/engine/config.h"
24 #include "sky/engine/core/events/MouseRelatedEvent.h"
25
26 #include "sky/engine/core/dom/Document.h"
27 #include "sky/engine/core/frame/FrameView.h"
28 #include "sky/engine/core/frame/LocalDOMWindow.h"
29 #include "sky/engine/core/frame/LocalFrame.h"
30 #include "sky/engine/core/rendering/RenderLayer.h"
31 #include "sky/engine/core/rendering/RenderObject.h"
32
33 namespace blink {
34
35 MouseRelatedEvent::MouseRelatedEvent()
36 : m_isSimulated(false)
37 , m_hasCachedRelativePosition(false)
38 {
39 }
40
41 MouseRelatedEvent::MouseRelatedEvent(const AtomicString& eventType, bool canBubb le, bool cancelable, PassRefPtr<AbstractView> abstractView,
42 int detail, const IntPoint& screenLocation, const IntPoint& windowLocation,
43 const IntPoint& movementDelta,
44 bool ctrlKey, bool altKey, bool shiftKey, b ool metaKey, bool isSimulated)
45 : UIEventWithKeyState(eventType, canBubble, cancelable, abstractView, detail , ctrlKey, altKey, shiftKey, metaKey)
46 , m_screenLocation(screenLocation)
47 , m_movementDelta(movementDelta)
48 , m_isSimulated(isSimulated)
49 {
50 LayoutPoint adjustedPageLocation;
51
52 LocalFrame* frame = view() ? view()->frame() : 0;
53 if (frame && !isSimulated) {
54 if (FrameView* frameView = frame->view())
55 adjustedPageLocation = frameView->windowToContents(windowLocation);
56 }
57
58 m_clientLocation = adjustedPageLocation;
59 m_pageLocation = adjustedPageLocation;
60
61 initCoordinates();
62 }
63
64 void MouseRelatedEvent::initCoordinates()
65 {
66 // Set up initial values for coordinates.
67 // Correct values are computed lazily, see computeRelativePosition.
68 m_layerLocation = m_pageLocation;
69 m_offsetLocation = m_pageLocation;
70
71 computePageLocation();
72 m_hasCachedRelativePosition = false;
73 }
74
75 void MouseRelatedEvent::initCoordinates(const LayoutPoint& clientLocation)
76 {
77 // Set up initial values for coordinates.
78 // Correct values are computed lazily, see computeRelativePosition.
79 m_clientLocation = clientLocation;
80 // FIXME(sky): We don't need this anymore?
81 m_pageLocation = clientLocation;
82
83 m_layerLocation = m_pageLocation;
84 m_offsetLocation = m_pageLocation;
85
86 computePageLocation();
87 m_hasCachedRelativePosition = false;
88 }
89
90 void MouseRelatedEvent::computePageLocation()
91 {
92 setAbsoluteLocation(LayoutPoint(pageX(), pageY()));
93 }
94
95 void MouseRelatedEvent::receivedTarget()
96 {
97 m_hasCachedRelativePosition = false;
98 }
99
100 void MouseRelatedEvent::computeRelativePosition()
101 {
102 Node* targetNode = target() ? target()->toNode() : 0;
103 if (!targetNode)
104 return;
105
106 // Compute coordinates that are based on the target.
107 m_layerLocation = m_pageLocation;
108 m_offsetLocation = m_pageLocation;
109
110 // Must have an updated render tree for this math to work correctly.
111 targetNode->document().updateLayout();
112
113 // Adjust offsetLocation to be relative to the target's position.
114 if (RenderObject* r = targetNode->renderer()) {
115 FloatPoint localPos = r->absoluteToLocal(absoluteLocation(), UseTransfor ms);
116 m_offsetLocation = roundedLayoutPoint(localPos);
117 }
118
119 // Adjust layerLocation to be relative to the layer.
120 // FIXME: event.layerX and event.layerY are poorly defined,
121 // and probably don't always correspond to RenderLayer offsets.
122 // https://bugs.webkit.org/show_bug.cgi?id=21868
123 Node* n = targetNode;
124 while (n && !n->renderer())
125 n = n->parentNode();
126
127 if (n) {
128 // FIXME: This logic is a wrong implementation of convertToLayerCoords.
129 for (RenderLayer* layer = n->renderer()->enclosingLayer(); layer; layer = layer->parent())
130 m_layerLocation -= toLayoutSize(layer->location());
131 }
132
133 m_hasCachedRelativePosition = true;
134 }
135
136 int MouseRelatedEvent::layerX()
137 {
138 if (!m_hasCachedRelativePosition)
139 computeRelativePosition();
140 return m_layerLocation.x();
141 }
142
143 int MouseRelatedEvent::layerY()
144 {
145 if (!m_hasCachedRelativePosition)
146 computeRelativePosition();
147 return m_layerLocation.y();
148 }
149
150 int MouseRelatedEvent::offsetX()
151 {
152 if (isSimulated())
153 return 0;
154 if (!m_hasCachedRelativePosition)
155 computeRelativePosition();
156 return roundToInt(m_offsetLocation.x());
157 }
158
159 int MouseRelatedEvent::offsetY()
160 {
161 if (isSimulated())
162 return 0;
163 if (!m_hasCachedRelativePosition)
164 computeRelativePosition();
165 return roundToInt(m_offsetLocation.y());
166 }
167
168 int MouseRelatedEvent::pageX() const
169 {
170 return m_pageLocation.x();
171 }
172
173 int MouseRelatedEvent::pageY() const
174 {
175 return m_pageLocation.y();
176 }
177
178 int MouseRelatedEvent::x() const
179 {
180 // FIXME: This is not correct.
181 // See Microsoft documentation and <http://www.quirksmode.org/dom/w3c_events .html>.
182 return m_clientLocation.x();
183 }
184
185 int MouseRelatedEvent::y() const
186 {
187 // FIXME: This is not correct.
188 // See Microsoft documentation and <http://www.quirksmode.org/dom/w3c_events .html>.
189 return m_clientLocation.y();
190 }
191
192 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/events/MouseRelatedEvent.h ('k') | sky/engine/core/html/HTMLAnchorElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698