0
|
1 |
/*
|
|
2 |
* Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
|
|
3 |
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
|
|
4 |
*
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
6 |
* modification, are permitted provided that the following conditions
|
|
7 |
* are met:
|
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
|
9 |
* notice, this list of conditions and the following disclaimer.
|
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
|
12 |
* documentation and/or other materials provided with the distribution.
|
|
13 |
*
|
|
14 |
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
|
15 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
17 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
|
18 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
19 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
20 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
21 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
22 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
23 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
25 |
*/
|
|
26 |
|
|
27 |
#include "config.h"
|
|
28 |
#include "EventHandler.h"
|
|
29 |
|
|
30 |
#include "AXObjectCache.h"
|
|
31 |
#include "CachedImage.h"
|
|
32 |
#include "ChromeClient.h"
|
|
33 |
#include "Cursor.h"
|
|
34 |
#include "Document.h"
|
|
35 |
#include "DragController.h"
|
|
36 |
#include "Editor.h"
|
|
37 |
#include "EventNames.h"
|
|
38 |
#include "FloatPoint.h"
|
|
39 |
#include "FloatRect.h"
|
|
40 |
#include "FocusController.h"
|
|
41 |
#include "Frame.h"
|
|
42 |
#include "FrameLoader.h"
|
|
43 |
#include "FrameTree.h"
|
|
44 |
#include "FrameView.h"
|
|
45 |
#include "HTMLFrameElementBase.h"
|
|
46 |
#include "HTMLFrameSetElement.h"
|
|
47 |
#include "HTMLInputElement.h"
|
|
48 |
#include "HTMLNames.h"
|
|
49 |
#include "HitTestRequest.h"
|
|
50 |
#include "HitTestResult.h"
|
|
51 |
#include "Image.h"
|
|
52 |
#include "InspectorController.h"
|
|
53 |
#include "KeyboardEvent.h"
|
|
54 |
#include "MouseEvent.h"
|
|
55 |
#include "MouseEventWithHitTestResults.h"
|
|
56 |
#include "Page.h"
|
|
57 |
#include "PlatformKeyboardEvent.h"
|
|
58 |
#include "PlatformWheelEvent.h"
|
|
59 |
#include "RenderFrameSet.h"
|
|
60 |
#include "RenderTextControlSingleLine.h"
|
|
61 |
#include "RenderView.h"
|
|
62 |
#include "RenderWidget.h"
|
|
63 |
#include "Scrollbar.h"
|
|
64 |
#include "SelectionController.h"
|
|
65 |
#include "Settings.h"
|
|
66 |
#include "TextEvent.h"
|
|
67 |
#include "htmlediting.h" // for comparePositions()
|
|
68 |
#include <wtf/StdLibExtras.h>
|
|
69 |
|
|
70 |
#if ENABLE(SVG)
|
|
71 |
#include "SVGDocument.h"
|
|
72 |
#include "SVGElementInstance.h"
|
|
73 |
#include "SVGNames.h"
|
|
74 |
#include "SVGUseElement.h"
|
|
75 |
#endif
|
|
76 |
|
|
77 |
namespace WebCore {
|
|
78 |
|
|
79 |
using namespace HTMLNames;
|
|
80 |
|
|
81 |
#if ENABLE(DRAG_SUPPORT)
|
|
82 |
// The link drag hysteresis is much larger than the others because there
|
|
83 |
// needs to be enough space to cancel the link press without starting a link drag,
|
|
84 |
// and because dragging links is rare.
|
|
85 |
const int LinkDragHysteresis = 40;
|
|
86 |
const int ImageDragHysteresis = 5;
|
|
87 |
const int TextDragHysteresis = 3;
|
|
88 |
const int GeneralDragHysteresis = 3;
|
|
89 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
90 |
|
|
91 |
// Match key code of composition keydown event on windows.
|
|
92 |
// IE sends VK_PROCESSKEY which has value 229;
|
|
93 |
const int CompositionEventKeyCode = 229;
|
|
94 |
|
|
95 |
#if ENABLE(SVG)
|
|
96 |
using namespace SVGNames;
|
|
97 |
#endif
|
|
98 |
|
|
99 |
// When the autoscroll or the panScroll is triggered when do the scroll every 0.05s to make it smooth
|
|
100 |
const double autoscrollInterval = 0.05;
|
|
101 |
|
|
102 |
static Frame* subframeForHitTestResult(const MouseEventWithHitTestResults&);
|
|
103 |
|
|
104 |
static inline void scrollAndAcceptEvent(float delta, ScrollDirection positiveDirection, ScrollDirection negativeDirection, PlatformWheelEvent& e, Node* node, Node** stopNode)
|
|
105 |
{
|
|
106 |
if (!delta)
|
|
107 |
return;
|
|
108 |
|
|
109 |
// Find the nearest enclosing box.
|
|
110 |
RenderBox* enclosingBox = node->renderer()->enclosingBox();
|
|
111 |
|
|
112 |
if (e.granularity() == ScrollByPageWheelEvent) {
|
|
113 |
if (enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPage, 1, stopNode))
|
|
114 |
e.accept();
|
|
115 |
return;
|
|
116 |
}
|
|
117 |
|
|
118 |
float pixelsToScroll = delta > 0 ? delta : -delta;
|
|
119 |
if (enclosingBox->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPixel, pixelsToScroll, stopNode))
|
|
120 |
e.accept();
|
|
121 |
}
|
|
122 |
|
|
123 |
#if !PLATFORM(MAC)
|
|
124 |
|
|
125 |
inline bool EventHandler::eventLoopHandleMouseUp(const MouseEventWithHitTestResults&)
|
|
126 |
{
|
|
127 |
return false;
|
|
128 |
}
|
|
129 |
|
|
130 |
#if ENABLE(DRAG_SUPPORT)
|
|
131 |
inline bool EventHandler::eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&)
|
|
132 |
{
|
|
133 |
return false;
|
|
134 |
}
|
|
135 |
#endif
|
|
136 |
|
|
137 |
#endif
|
|
138 |
|
|
139 |
EventHandler::EventHandler(Frame* frame)
|
|
140 |
: m_frame(frame)
|
|
141 |
, m_mousePressed(false)
|
|
142 |
, m_capturesDragging(false)
|
|
143 |
, m_mouseDownMayStartSelect(false)
|
|
144 |
#if ENABLE(DRAG_SUPPORT)
|
|
145 |
, m_mouseDownMayStartDrag(false)
|
|
146 |
#endif
|
|
147 |
, m_mouseDownWasSingleClickInSelection(false)
|
|
148 |
, m_beganSelectingText(false)
|
|
149 |
, m_panScrollInProgress(false)
|
|
150 |
, m_panScrollButtonPressed(false)
|
|
151 |
, m_springLoadedPanScrollInProgress(false)
|
|
152 |
, m_hoverTimer(this, &EventHandler::hoverTimerFired)
|
|
153 |
, m_autoscrollTimer(this, &EventHandler::autoscrollTimerFired)
|
|
154 |
, m_autoscrollRenderer(0)
|
|
155 |
, m_autoscrollInProgress(false)
|
|
156 |
, m_mouseDownMayStartAutoscroll(false)
|
|
157 |
, m_mouseDownWasInSubframe(false)
|
|
158 |
#if ENABLE(SVG)
|
|
159 |
, m_svgPan(false)
|
|
160 |
#endif
|
|
161 |
, m_resizeLayer(0)
|
|
162 |
, m_capturingMouseEventsNode(0)
|
|
163 |
, m_clickCount(0)
|
|
164 |
, m_mouseDownTimestamp(0)
|
|
165 |
, m_useLatchedWheelEventNode(false)
|
|
166 |
, m_widgetIsLatched(false)
|
|
167 |
#if PLATFORM(MAC)
|
|
168 |
, m_mouseDownView(nil)
|
|
169 |
, m_sendingEventToSubview(false)
|
|
170 |
, m_activationEventNumber(0)
|
|
171 |
#endif
|
|
172 |
{
|
|
173 |
}
|
|
174 |
|
|
175 |
EventHandler::~EventHandler()
|
|
176 |
{
|
|
177 |
}
|
|
178 |
|
|
179 |
#if ENABLE(DRAG_SUPPORT)
|
|
180 |
EventHandler::EventHandlerDragState& EventHandler::dragState()
|
|
181 |
{
|
|
182 |
DEFINE_STATIC_LOCAL(EventHandlerDragState, state, ());
|
|
183 |
return state;
|
|
184 |
}
|
|
185 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
186 |
|
|
187 |
void EventHandler::clear()
|
|
188 |
{
|
|
189 |
m_hoverTimer.stop();
|
|
190 |
m_resizeLayer = 0;
|
|
191 |
m_nodeUnderMouse = 0;
|
|
192 |
m_lastNodeUnderMouse = 0;
|
|
193 |
#if ENABLE(SVG)
|
|
194 |
m_instanceUnderMouse = 0;
|
|
195 |
m_lastInstanceUnderMouse = 0;
|
|
196 |
#endif
|
|
197 |
m_lastMouseMoveEventSubframe = 0;
|
|
198 |
m_lastScrollbarUnderMouse = 0;
|
|
199 |
m_clickCount = 0;
|
|
200 |
m_clickNode = 0;
|
|
201 |
m_frameSetBeingResized = 0;
|
|
202 |
#if ENABLE(DRAG_SUPPORT)
|
|
203 |
m_dragTarget = 0;
|
|
204 |
#endif
|
|
205 |
m_currentMousePosition = IntPoint();
|
|
206 |
m_mousePressNode = 0;
|
|
207 |
m_mousePressed = false;
|
|
208 |
m_capturesDragging = false;
|
|
209 |
m_capturingMouseEventsNode = 0;
|
|
210 |
m_latchedWheelEventNode = 0;
|
|
211 |
m_previousWheelScrolledNode = 0;
|
|
212 |
}
|
|
213 |
|
|
214 |
void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
|
|
215 |
{
|
|
216 |
Node* innerNode = result.targetNode();
|
|
217 |
VisibleSelection newSelection;
|
|
218 |
|
|
219 |
if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
|
|
220 |
VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
|
|
221 |
if (pos.isNotNull()) {
|
|
222 |
newSelection = VisibleSelection(pos);
|
|
223 |
newSelection.expandUsingGranularity(WordGranularity);
|
|
224 |
}
|
|
225 |
|
|
226 |
if (newSelection.isRange()) {
|
|
227 |
m_frame->setSelectionGranularity(WordGranularity);
|
|
228 |
m_beganSelectingText = true;
|
|
229 |
if (result.event().clickCount() == 2 && m_frame->editor()->isSelectTrailingWhitespaceEnabled())
|
|
230 |
newSelection.appendTrailingWhitespace();
|
|
231 |
}
|
|
232 |
|
|
233 |
if (m_frame->shouldChangeSelection(newSelection))
|
|
234 |
m_frame->selection()->setSelection(newSelection);
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& result)
|
|
239 |
{
|
|
240 |
if (!result.hitTestResult().isLiveLink())
|
|
241 |
return selectClosestWordFromMouseEvent(result);
|
|
242 |
|
|
243 |
Node* innerNode = result.targetNode();
|
|
244 |
|
|
245 |
if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
|
|
246 |
VisibleSelection newSelection;
|
|
247 |
Element* URLElement = result.hitTestResult().URLElement();
|
|
248 |
VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
|
|
249 |
if (pos.isNotNull() && pos.deepEquivalent().node()->isDescendantOf(URLElement))
|
|
250 |
newSelection = VisibleSelection::selectionFromContentsOfNode(URLElement);
|
|
251 |
|
|
252 |
if (newSelection.isRange()) {
|
|
253 |
m_frame->setSelectionGranularity(WordGranularity);
|
|
254 |
m_beganSelectingText = true;
|
|
255 |
}
|
|
256 |
|
|
257 |
if (m_frame->shouldChangeSelection(newSelection))
|
|
258 |
m_frame->selection()->setSelection(newSelection);
|
|
259 |
}
|
|
260 |
}
|
|
261 |
|
|
262 |
bool EventHandler::handleMousePressEventDoubleClick(const MouseEventWithHitTestResults& event)
|
|
263 |
{
|
|
264 |
if (event.event().button() != LeftButton)
|
|
265 |
return false;
|
|
266 |
|
|
267 |
if (m_frame->selection()->isRange())
|
|
268 |
// A double-click when range is already selected
|
|
269 |
// should not change the selection. So, do not call
|
|
270 |
// selectClosestWordFromMouseEvent, but do set
|
|
271 |
// m_beganSelectingText to prevent handleMouseReleaseEvent
|
|
272 |
// from setting caret selection.
|
|
273 |
m_beganSelectingText = true;
|
|
274 |
else
|
|
275 |
selectClosestWordFromMouseEvent(event);
|
|
276 |
|
|
277 |
return true;
|
|
278 |
}
|
|
279 |
|
|
280 |
bool EventHandler::handleMousePressEventTripleClick(const MouseEventWithHitTestResults& event)
|
|
281 |
{
|
|
282 |
if (event.event().button() != LeftButton)
|
|
283 |
return false;
|
|
284 |
|
|
285 |
Node* innerNode = event.targetNode();
|
|
286 |
if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
|
|
287 |
return false;
|
|
288 |
|
|
289 |
VisibleSelection newSelection;
|
|
290 |
VisiblePosition pos(innerNode->renderer()->positionForPoint(event.localPoint()));
|
|
291 |
if (pos.isNotNull()) {
|
|
292 |
newSelection = VisibleSelection(pos);
|
|
293 |
newSelection.expandUsingGranularity(ParagraphGranularity);
|
|
294 |
}
|
|
295 |
if (newSelection.isRange()) {
|
|
296 |
m_frame->setSelectionGranularity(ParagraphGranularity);
|
|
297 |
m_beganSelectingText = true;
|
|
298 |
}
|
|
299 |
|
|
300 |
if (m_frame->shouldChangeSelection(newSelection))
|
|
301 |
m_frame->selection()->setSelection(newSelection);
|
|
302 |
|
|
303 |
return true;
|
|
304 |
}
|
|
305 |
|
|
306 |
bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestResults& event)
|
|
307 |
{
|
|
308 |
Node* innerNode = event.targetNode();
|
|
309 |
if (!(innerNode && innerNode->renderer() && m_mouseDownMayStartSelect))
|
|
310 |
return false;
|
|
311 |
|
|
312 |
// Extend the selection if the Shift key is down, unless the click is in a link.
|
|
313 |
bool extendSelection = event.event().shiftKey() && !event.isOverLink();
|
|
314 |
|
|
315 |
// Don't restart the selection when the mouse is pressed on an
|
|
316 |
// existing selection so we can allow for text dragging.
|
|
317 |
if (FrameView* view = m_frame->view()) {
|
|
318 |
IntPoint vPoint = view->windowToContents(event.event().pos());
|
|
319 |
if (!extendSelection && m_frame->selection()->contains(vPoint)) {
|
|
320 |
m_mouseDownWasSingleClickInSelection = true;
|
|
321 |
return false;
|
|
322 |
}
|
|
323 |
}
|
|
324 |
|
|
325 |
VisiblePosition visiblePos(innerNode->renderer()->positionForPoint(event.localPoint()));
|
|
326 |
if (visiblePos.isNull())
|
|
327 |
visiblePos = VisiblePosition(innerNode, 0, DOWNSTREAM);
|
|
328 |
Position pos = visiblePos.deepEquivalent();
|
|
329 |
|
|
330 |
VisibleSelection newSelection = m_frame->selection()->selection();
|
|
331 |
if (extendSelection && newSelection.isCaretOrRange()) {
|
|
332 |
m_frame->selection()->setLastChangeWasHorizontalExtension(false);
|
|
333 |
|
|
334 |
// See <rdar://problem/3668157> REGRESSION (Mail): shift-click deselects when selection
|
|
335 |
// was created right-to-left
|
|
336 |
Position start = newSelection.start();
|
|
337 |
Position end = newSelection.end();
|
|
338 |
if (comparePositions(pos, start) <= 0)
|
|
339 |
newSelection = VisibleSelection(pos, end);
|
|
340 |
else
|
|
341 |
newSelection = VisibleSelection(start, pos);
|
|
342 |
|
|
343 |
if (m_frame->selectionGranularity() != CharacterGranularity)
|
|
344 |
newSelection.expandUsingGranularity(m_frame->selectionGranularity());
|
|
345 |
m_beganSelectingText = true;
|
|
346 |
} else {
|
|
347 |
newSelection = VisibleSelection(visiblePos);
|
|
348 |
m_frame->setSelectionGranularity(CharacterGranularity);
|
|
349 |
}
|
|
350 |
|
|
351 |
if (m_frame->shouldChangeSelection(newSelection))
|
|
352 |
m_frame->selection()->setSelection(newSelection);
|
|
353 |
|
|
354 |
return true;
|
|
355 |
}
|
|
356 |
|
|
357 |
bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& event)
|
|
358 |
{
|
|
359 |
#if ENABLE(DRAG_SUPPORT)
|
|
360 |
// Reset drag state.
|
|
361 |
dragState().m_dragSrc = 0;
|
|
362 |
#endif
|
|
363 |
|
|
364 |
if (ScrollView* scrollView = m_frame->view()) {
|
|
365 |
if (scrollView->isPointInScrollbarCorner(event.event().pos()))
|
|
366 |
return false;
|
|
367 |
}
|
|
368 |
|
|
369 |
bool singleClick = event.event().clickCount() <= 1;
|
|
370 |
|
|
371 |
// If we got the event back, that must mean it wasn't prevented,
|
|
372 |
// so it's allowed to start a drag or selection.
|
|
373 |
m_mouseDownMayStartSelect = canMouseDownStartSelect(event.targetNode());
|
|
374 |
|
|
375 |
#if ENABLE(DRAG_SUPPORT)
|
|
376 |
// Careful that the drag starting logic stays in sync with eventMayStartDrag()
|
|
377 |
m_mouseDownMayStartDrag = singleClick;
|
|
378 |
#endif
|
|
379 |
|
|
380 |
m_mouseDownWasSingleClickInSelection = false;
|
|
381 |
|
|
382 |
m_mouseDown = event.event();
|
|
383 |
|
|
384 |
if (event.isOverWidget() && passWidgetMouseDownEventToWidget(event))
|
|
385 |
return true;
|
|
386 |
|
|
387 |
#if ENABLE(SVG)
|
|
388 |
if (m_frame->document()->isSVGDocument() &&
|
|
389 |
static_cast<SVGDocument*>(m_frame->document())->zoomAndPanEnabled()) {
|
|
390 |
if (event.event().shiftKey() && singleClick) {
|
|
391 |
m_svgPan = true;
|
|
392 |
static_cast<SVGDocument*>(m_frame->document())->startPan(event.event().pos());
|
|
393 |
return true;
|
|
394 |
}
|
|
395 |
}
|
|
396 |
#endif
|
|
397 |
|
|
398 |
// We don't do this at the start of mouse down handling,
|
|
399 |
// because we don't want to do it until we know we didn't hit a widget.
|
|
400 |
if (singleClick)
|
|
401 |
focusDocumentView();
|
|
402 |
|
|
403 |
Node* innerNode = event.targetNode();
|
|
404 |
|
|
405 |
m_mousePressNode = innerNode;
|
|
406 |
#if ENABLE(DRAG_SUPPORT)
|
|
407 |
m_dragStartPos = event.event().pos();
|
|
408 |
#endif
|
|
409 |
|
|
410 |
bool swallowEvent = false;
|
|
411 |
m_frame->selection()->setCaretBlinkingSuspended(true);
|
|
412 |
m_mousePressed = true;
|
|
413 |
m_beganSelectingText = false;
|
|
414 |
|
|
415 |
if (event.event().clickCount() == 2)
|
|
416 |
swallowEvent = handleMousePressEventDoubleClick(event);
|
|
417 |
else if (event.event().clickCount() >= 3)
|
|
418 |
swallowEvent = handleMousePressEventTripleClick(event);
|
|
419 |
else
|
|
420 |
swallowEvent = handleMousePressEventSingleClick(event);
|
|
421 |
|
|
422 |
m_mouseDownMayStartAutoscroll = m_mouseDownMayStartSelect ||
|
|
423 |
(m_mousePressNode && m_mousePressNode->renderBox() && m_mousePressNode->renderBox()->canBeProgramaticallyScrolled(true));
|
|
424 |
|
|
425 |
return swallowEvent;
|
|
426 |
}
|
|
427 |
|
|
428 |
#if ENABLE(DRAG_SUPPORT)
|
|
429 |
bool EventHandler::handleMouseDraggedEvent(const MouseEventWithHitTestResults& event)
|
|
430 |
{
|
|
431 |
if (handleDrag(event))
|
|
432 |
return true;
|
|
433 |
|
|
434 |
if (!m_mousePressed)
|
|
435 |
return false;
|
|
436 |
|
|
437 |
Node* targetNode = event.targetNode();
|
|
438 |
if (event.event().button() != LeftButton || !targetNode || !targetNode->renderer())
|
|
439 |
return false;
|
|
440 |
|
|
441 |
#if PLATFORM(MAC) // FIXME: Why does this assertion fire on other platforms?
|
|
442 |
ASSERT(m_mouseDownMayStartSelect || m_mouseDownMayStartAutoscroll);
|
|
443 |
#endif
|
|
444 |
|
|
445 |
m_mouseDownMayStartDrag = false;
|
|
446 |
|
|
447 |
if (m_mouseDownMayStartAutoscroll && !m_panScrollInProgress) {
|
|
448 |
// If the selection is contained in a layer that can scroll, that layer should handle the autoscroll
|
|
449 |
// Otherwise, let the bridge handle it so the view can scroll itself.
|
|
450 |
RenderObject* renderer = targetNode->renderer();
|
|
451 |
while (renderer && (!renderer->isBox() || !toRenderBox(renderer)->canBeScrolledAndHasScrollableArea())) {
|
|
452 |
if (!renderer->parent() && renderer->node() == renderer->document() && renderer->document()->ownerElement())
|
|
453 |
renderer = renderer->document()->ownerElement()->renderer();
|
|
454 |
else
|
|
455 |
renderer = renderer->parent();
|
|
456 |
}
|
|
457 |
|
|
458 |
if (renderer) {
|
|
459 |
m_autoscrollInProgress = true;
|
|
460 |
handleAutoscroll(renderer);
|
|
461 |
}
|
|
462 |
|
|
463 |
m_mouseDownMayStartAutoscroll = false;
|
|
464 |
}
|
|
465 |
|
|
466 |
updateSelectionForMouseDrag(targetNode, event.localPoint());
|
|
467 |
return true;
|
|
468 |
}
|
|
469 |
|
|
470 |
bool EventHandler::eventMayStartDrag(const PlatformMouseEvent& event) const
|
|
471 |
{
|
|
472 |
// This is a pre-flight check of whether the event might lead to a drag being started. Be careful
|
|
473 |
// that its logic needs to stay in sync with handleMouseMoveEvent() and the way we setMouseDownMayStartDrag
|
|
474 |
// in handleMousePressEvent
|
|
475 |
|
|
476 |
if (!m_frame->contentRenderer() || !m_frame->contentRenderer()->hasLayer())
|
|
477 |
return false;
|
|
478 |
|
|
479 |
if (event.button() != LeftButton || event.clickCount() != 1)
|
|
480 |
return false;
|
|
481 |
|
|
482 |
bool DHTMLFlag;
|
|
483 |
bool UAFlag;
|
|
484 |
allowDHTMLDrag(DHTMLFlag, UAFlag);
|
|
485 |
if (!DHTMLFlag && !UAFlag)
|
|
486 |
return false;
|
|
487 |
|
|
488 |
FrameView* view = m_frame->view();
|
|
489 |
if (!view)
|
|
490 |
return false;
|
|
491 |
|
|
492 |
HitTestRequest request(HitTestRequest::ReadOnly);
|
|
493 |
HitTestResult result(view->windowToContents(event.pos()));
|
|
494 |
m_frame->contentRenderer()->layer()->hitTest(request, result);
|
|
495 |
bool srcIsDHTML;
|
|
496 |
return result.innerNode() && result.innerNode()->renderer()->draggableNode(DHTMLFlag, UAFlag, result.point().x(), result.point().y(), srcIsDHTML);
|
|
497 |
}
|
|
498 |
|
|
499 |
void EventHandler::updateSelectionForMouseDrag()
|
|
500 |
{
|
|
501 |
FrameView* view = m_frame->view();
|
|
502 |
if (!view)
|
|
503 |
return;
|
|
504 |
RenderView* renderer = m_frame->contentRenderer();
|
|
505 |
if (!renderer)
|
|
506 |
return;
|
|
507 |
RenderLayer* layer = renderer->layer();
|
|
508 |
if (!layer)
|
|
509 |
return;
|
|
510 |
|
|
511 |
HitTestRequest request(HitTestRequest::ReadOnly |
|
|
512 |
HitTestRequest::Active |
|
|
513 |
HitTestRequest::MouseMove);
|
|
514 |
HitTestResult result(view->windowToContents(m_currentMousePosition));
|
|
515 |
layer->hitTest(request, result);
|
|
516 |
updateSelectionForMouseDrag(result.innerNode(), result.localPoint());
|
|
517 |
}
|
|
518 |
|
|
519 |
void EventHandler::updateSelectionForMouseDrag(Node* targetNode, const IntPoint& localPoint)
|
|
520 |
{
|
|
521 |
if (!m_mouseDownMayStartSelect)
|
|
522 |
return;
|
|
523 |
|
|
524 |
if (!targetNode)
|
|
525 |
return;
|
|
526 |
|
|
527 |
RenderObject* targetRenderer = targetNode->renderer();
|
|
528 |
if (!targetRenderer)
|
|
529 |
return;
|
|
530 |
|
|
531 |
if (!canMouseDragExtendSelect(targetNode))
|
|
532 |
return;
|
|
533 |
|
|
534 |
VisiblePosition targetPosition(targetRenderer->positionForPoint(localPoint));
|
|
535 |
|
|
536 |
// Don't modify the selection if we're not on a node.
|
|
537 |
if (targetPosition.isNull())
|
|
538 |
return;
|
|
539 |
|
|
540 |
// Restart the selection if this is the first mouse move. This work is usually
|
|
541 |
// done in handleMousePressEvent, but not if the mouse press was on an existing selection.
|
|
542 |
VisibleSelection newSelection = m_frame->selection()->selection();
|
|
543 |
|
|
544 |
#if ENABLE(SVG)
|
|
545 |
// Special case to limit selection to the containing block for SVG text.
|
|
546 |
// FIXME: Isn't there a better non-SVG-specific way to do this?
|
|
547 |
if (Node* selectionBaseNode = newSelection.base().node())
|
|
548 |
if (RenderObject* selectionBaseRenderer = selectionBaseNode->renderer())
|
|
549 |
if (selectionBaseRenderer->isSVGText())
|
|
550 |
if (targetNode->renderer()->containingBlock() != selectionBaseRenderer->containingBlock())
|
|
551 |
return;
|
|
552 |
#endif
|
|
553 |
|
|
554 |
if (!m_beganSelectingText) {
|
|
555 |
m_beganSelectingText = true;
|
|
556 |
newSelection = VisibleSelection(targetPosition);
|
|
557 |
}
|
|
558 |
|
|
559 |
newSelection.setExtent(targetPosition);
|
|
560 |
if (m_frame->selectionGranularity() != CharacterGranularity)
|
|
561 |
newSelection.expandUsingGranularity(m_frame->selectionGranularity());
|
|
562 |
|
|
563 |
if (m_frame->shouldChangeSelection(newSelection)) {
|
|
564 |
m_frame->selection()->setLastChangeWasHorizontalExtension(false);
|
|
565 |
m_frame->selection()->setSelection(newSelection);
|
|
566 |
}
|
|
567 |
}
|
|
568 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
569 |
|
|
570 |
bool EventHandler::handleMouseUp(const MouseEventWithHitTestResults& event)
|
|
571 |
{
|
|
572 |
if (eventLoopHandleMouseUp(event))
|
|
573 |
return true;
|
|
574 |
|
|
575 |
// If this was the first click in the window, we don't even want to clear the selection.
|
|
576 |
// This case occurs when the user clicks on a draggable element, since we have to process
|
|
577 |
// the mouse down and drag events to see if we might start a drag. For other first clicks
|
|
578 |
// in a window, we just don't acceptFirstMouse, and the whole down-drag-up sequence gets
|
|
579 |
// ignored upstream of this layer.
|
|
580 |
return eventActivatedView(event.event());
|
|
581 |
}
|
|
582 |
|
|
583 |
bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& event)
|
|
584 |
{
|
|
585 |
if (m_autoscrollInProgress)
|
|
586 |
stopAutoscrollTimer();
|
|
587 |
|
|
588 |
if (handleMouseUp(event))
|
|
589 |
return true;
|
|
590 |
|
|
591 |
// Used to prevent mouseMoveEvent from initiating a drag before
|
|
592 |
// the mouse is pressed again.
|
|
593 |
m_frame->selection()->setCaretBlinkingSuspended(false);
|
|
594 |
m_mousePressed = false;
|
|
595 |
m_capturesDragging = false;
|
|
596 |
#if ENABLE(DRAG_SUPPORT)
|
|
597 |
m_mouseDownMayStartDrag = false;
|
|
598 |
#endif
|
|
599 |
m_mouseDownMayStartSelect = false;
|
|
600 |
m_mouseDownMayStartAutoscroll = false;
|
|
601 |
m_mouseDownWasInSubframe = false;
|
|
602 |
|
|
603 |
bool handled = false;
|
|
604 |
|
|
605 |
// Clear the selection if the mouse didn't move after the last mouse
|
|
606 |
// press and it's not a context menu click. We do this so when clicking
|
|
607 |
// on the selection, the selection goes away. However, if we are
|
|
608 |
// editing, place the caret.
|
|
609 |
if (m_mouseDownWasSingleClickInSelection && !m_beganSelectingText
|
|
610 |
#if ENABLE(DRAG_SUPPORT)
|
|
611 |
&& m_dragStartPos == event.event().pos()
|
|
612 |
#endif
|
|
613 |
&& m_frame->selection()->isRange()
|
|
614 |
&& event.event().button() != RightButton) {
|
|
615 |
VisibleSelection newSelection;
|
|
616 |
Node *node = event.targetNode();
|
|
617 |
bool caretBrowsing = m_frame->settings()->caretBrowsingEnabled();
|
|
618 |
if (node && (caretBrowsing || node->isContentEditable()) && node->renderer()) {
|
|
619 |
VisiblePosition pos = node->renderer()->positionForPoint(event.localPoint());
|
|
620 |
newSelection = VisibleSelection(pos);
|
|
621 |
}
|
|
622 |
if (m_frame->shouldChangeSelection(newSelection))
|
|
623 |
m_frame->selection()->setSelection(newSelection);
|
|
624 |
|
|
625 |
handled = true;
|
|
626 |
}
|
|
627 |
|
|
628 |
m_frame->notifyRendererOfSelectionChange(true);
|
|
629 |
|
|
630 |
m_frame->selection()->selectFrameElementInParentIfFullySelected();
|
|
631 |
|
|
632 |
return handled;
|
|
633 |
}
|
|
634 |
|
|
635 |
void EventHandler::handleAutoscroll(RenderObject* renderer)
|
|
636 |
{
|
|
637 |
// We don't want to trigger the autoscroll or the panScroll if it's already active
|
|
638 |
if (m_autoscrollTimer.isActive())
|
|
639 |
return;
|
|
640 |
|
|
641 |
setAutoscrollRenderer(renderer);
|
|
642 |
|
|
643 |
#if ENABLE(PAN_SCROLLING)
|
|
644 |
if (m_panScrollInProgress) {
|
|
645 |
m_panScrollStartPos = currentMousePosition();
|
|
646 |
if (FrameView* view = m_frame->view())
|
|
647 |
view->addPanScrollIcon(m_panScrollStartPos);
|
|
648 |
// If we're not in the top frame we notify it that we doing a panScroll.
|
|
649 |
if (Page* page = m_frame->page()) {
|
|
650 |
Frame* mainFrame = page->mainFrame();
|
|
651 |
if (m_frame != mainFrame)
|
|
652 |
mainFrame->eventHandler()->setPanScrollInProgress(true);
|
|
653 |
}
|
|
654 |
}
|
|
655 |
#endif
|
|
656 |
|
|
657 |
startAutoscrollTimer();
|
|
658 |
}
|
|
659 |
|
|
660 |
void EventHandler::autoscrollTimerFired(Timer<EventHandler>*)
|
|
661 |
{
|
|
662 |
RenderObject* r = autoscrollRenderer();
|
|
663 |
if (!r || !r->isBox()) {
|
|
664 |
stopAutoscrollTimer();
|
|
665 |
return;
|
|
666 |
}
|
|
667 |
|
|
668 |
if (m_autoscrollInProgress) {
|
|
669 |
if (!m_mousePressed) {
|
|
670 |
stopAutoscrollTimer();
|
|
671 |
return;
|
|
672 |
}
|
|
673 |
toRenderBox(r)->autoscroll();
|
|
674 |
} else {
|
|
675 |
// we verify that the main frame hasn't received the order to stop the panScroll
|
|
676 |
if (Page* page = m_frame->page()) {
|
|
677 |
if (!page->mainFrame()->eventHandler()->panScrollInProgress()) {
|
|
678 |
stopAutoscrollTimer();
|
|
679 |
return;
|
|
680 |
}
|
|
681 |
}
|
|
682 |
#if ENABLE(PAN_SCROLLING)
|
|
683 |
updatePanScrollState();
|
|
684 |
toRenderBox(r)->panScroll(m_panScrollStartPos);
|
|
685 |
#endif
|
|
686 |
}
|
|
687 |
}
|
|
688 |
|
|
689 |
#if ENABLE(PAN_SCROLLING)
|
|
690 |
|
|
691 |
void EventHandler::updatePanScrollState()
|
|
692 |
{
|
|
693 |
FrameView* view = m_frame->view();
|
|
694 |
if (!view)
|
|
695 |
return;
|
|
696 |
|
|
697 |
// At the original click location we draw a 4 arrowed icon. Over this icon there won't be any scroll
|
|
698 |
// So we don't want to change the cursor over this area
|
|
699 |
bool east = m_panScrollStartPos.x() < (m_currentMousePosition.x() - ScrollView::noPanScrollRadius);
|
|
700 |
bool west = m_panScrollStartPos.x() > (m_currentMousePosition.x() + ScrollView::noPanScrollRadius);
|
|
701 |
bool north = m_panScrollStartPos.y() > (m_currentMousePosition.y() + ScrollView::noPanScrollRadius);
|
|
702 |
bool south = m_panScrollStartPos.y() < (m_currentMousePosition.y() - ScrollView::noPanScrollRadius);
|
|
703 |
|
|
704 |
if ((east || west || north || south) && m_panScrollButtonPressed)
|
|
705 |
m_springLoadedPanScrollInProgress = true;
|
|
706 |
|
|
707 |
if (north) {
|
|
708 |
if (east)
|
|
709 |
view->setCursor(northEastPanningCursor());
|
|
710 |
else if (west)
|
|
711 |
view->setCursor(northWestPanningCursor());
|
|
712 |
else
|
|
713 |
view->setCursor(northPanningCursor());
|
|
714 |
} else if (south) {
|
|
715 |
if (east)
|
|
716 |
view->setCursor(southEastPanningCursor());
|
|
717 |
else if (west)
|
|
718 |
view->setCursor(southWestPanningCursor());
|
|
719 |
else
|
|
720 |
view->setCursor(southPanningCursor());
|
|
721 |
} else if (east)
|
|
722 |
view->setCursor(eastPanningCursor());
|
|
723 |
else if (west)
|
|
724 |
view->setCursor(westPanningCursor());
|
|
725 |
else
|
|
726 |
view->setCursor(middlePanningCursor());
|
|
727 |
}
|
|
728 |
|
|
729 |
#endif // ENABLE(PAN_SCROLLING)
|
|
730 |
|
|
731 |
RenderObject* EventHandler::autoscrollRenderer() const
|
|
732 |
{
|
|
733 |
return m_autoscrollRenderer;
|
|
734 |
}
|
|
735 |
|
|
736 |
void EventHandler::updateAutoscrollRenderer()
|
|
737 |
{
|
|
738 |
if (!m_autoscrollRenderer)
|
|
739 |
return;
|
|
740 |
|
|
741 |
HitTestResult hitTest = hitTestResultAtPoint(m_panScrollStartPos, true);
|
|
742 |
|
|
743 |
if (Node* nodeAtPoint = hitTest.innerNode())
|
|
744 |
m_autoscrollRenderer = nodeAtPoint->renderer();
|
|
745 |
|
|
746 |
while (m_autoscrollRenderer && (!m_autoscrollRenderer->isBox() || !toRenderBox(m_autoscrollRenderer)->canBeScrolledAndHasScrollableArea()))
|
|
747 |
m_autoscrollRenderer = m_autoscrollRenderer->parent();
|
|
748 |
}
|
|
749 |
|
|
750 |
void EventHandler::setAutoscrollRenderer(RenderObject* renderer)
|
|
751 |
{
|
|
752 |
m_autoscrollRenderer = renderer;
|
|
753 |
}
|
|
754 |
|
|
755 |
#if ENABLE(DRAG_SUPPORT)
|
|
756 |
void EventHandler::allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const
|
|
757 |
{
|
|
758 |
flagDHTML = false;
|
|
759 |
flagUA = false;
|
|
760 |
|
|
761 |
if (!m_frame)
|
|
762 |
return;
|
|
763 |
|
|
764 |
Page* page = m_frame->page();
|
|
765 |
if (!page)
|
|
766 |
return;
|
|
767 |
|
|
768 |
FrameView* view = m_frame->view();
|
|
769 |
if (!view)
|
|
770 |
return;
|
|
771 |
|
|
772 |
unsigned mask = page->dragController()->delegateDragSourceAction(view->contentsToWindow(m_mouseDownPos));
|
|
773 |
flagDHTML = (mask & DragSourceActionDHTML) != DragSourceActionNone;
|
|
774 |
flagUA = ((mask & DragSourceActionImage) || (mask & DragSourceActionLink) || (mask & DragSourceActionSelection));
|
|
775 |
}
|
|
776 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
777 |
|
|
778 |
HitTestResult EventHandler::hitTestResultAtPoint(const IntPoint& point, bool allowShadowContent, bool ignoreClipping, HitTestScrollbars testScrollbars)
|
|
779 |
{
|
|
780 |
HitTestResult result(point);
|
|
781 |
if (!m_frame->contentRenderer())
|
|
782 |
return result;
|
|
783 |
int hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
|
|
784 |
if (ignoreClipping)
|
|
785 |
hitType |= HitTestRequest::IgnoreClipping;
|
|
786 |
m_frame->contentRenderer()->layer()->hitTest(HitTestRequest(hitType), result);
|
|
787 |
|
|
788 |
while (true) {
|
|
789 |
Node* n = result.innerNode();
|
|
790 |
if (!result.isOverWidget() || !n || !n->renderer() || !n->renderer()->isWidget())
|
|
791 |
break;
|
|
792 |
RenderWidget* renderWidget = toRenderWidget(n->renderer());
|
|
793 |
Widget* widget = renderWidget->widget();
|
|
794 |
if (!widget || !widget->isFrameView())
|
|
795 |
break;
|
|
796 |
Frame* frame = static_cast<HTMLFrameElementBase*>(n)->contentFrame();
|
|
797 |
if (!frame || !frame->contentRenderer())
|
|
798 |
break;
|
|
799 |
FrameView* view = static_cast<FrameView*>(widget);
|
|
800 |
IntPoint widgetPoint(result.localPoint().x() + view->scrollX() - renderWidget->borderLeft() - renderWidget->paddingLeft(),
|
|
801 |
result.localPoint().y() + view->scrollY() - renderWidget->borderTop() - renderWidget->paddingTop());
|
|
802 |
HitTestResult widgetHitTestResult(widgetPoint);
|
|
803 |
frame->contentRenderer()->layer()->hitTest(HitTestRequest(hitType), widgetHitTestResult);
|
|
804 |
result = widgetHitTestResult;
|
|
805 |
|
|
806 |
if (testScrollbars == ShouldHitTestScrollbars) {
|
|
807 |
Scrollbar* eventScrollbar = view->scrollbarAtPoint(point);
|
|
808 |
if (eventScrollbar)
|
|
809 |
result.setScrollbar(eventScrollbar);
|
|
810 |
}
|
|
811 |
}
|
|
812 |
|
|
813 |
// If our HitTestResult is not visible, then we started hit testing too far down the frame chain.
|
|
814 |
// Another hit test at the main frame level should get us the correct visible result.
|
|
815 |
Frame* resultFrame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document()->frame() : 0;
|
|
816 |
if (Page* page = m_frame->page()) {
|
|
817 |
Frame* mainFrame = page->mainFrame();
|
|
818 |
if (m_frame != mainFrame && resultFrame && resultFrame != mainFrame && !resultFrame->editor()->insideVisibleArea(result.point())) {
|
|
819 |
FrameView* resultView = resultFrame->view();
|
|
820 |
FrameView* mainView = mainFrame->view();
|
|
821 |
if (resultView && mainView) {
|
|
822 |
IntPoint windowPoint = resultView->contentsToWindow(result.point());
|
|
823 |
IntPoint mainFramePoint = mainView->windowToContents(windowPoint);
|
|
824 |
result = mainFrame->eventHandler()->hitTestResultAtPoint(mainFramePoint, allowShadowContent, ignoreClipping);
|
|
825 |
}
|
|
826 |
}
|
|
827 |
}
|
|
828 |
|
|
829 |
if (!allowShadowContent)
|
|
830 |
result.setToNonShadowAncestor();
|
|
831 |
|
|
832 |
return result;
|
|
833 |
}
|
|
834 |
|
|
835 |
|
|
836 |
void EventHandler::startAutoscrollTimer()
|
|
837 |
{
|
|
838 |
m_autoscrollTimer.startRepeating(autoscrollInterval);
|
|
839 |
}
|
|
840 |
|
|
841 |
void EventHandler::stopAutoscrollTimer(bool rendererIsBeingDestroyed)
|
|
842 |
{
|
|
843 |
if (m_autoscrollInProgress) {
|
|
844 |
if (m_mouseDownWasInSubframe) {
|
|
845 |
if (Frame* subframe = subframeForTargetNode(m_mousePressNode.get()))
|
|
846 |
subframe->eventHandler()->stopAutoscrollTimer(rendererIsBeingDestroyed);
|
|
847 |
return;
|
|
848 |
}
|
|
849 |
}
|
|
850 |
|
|
851 |
if (autoscrollRenderer()) {
|
|
852 |
if (!rendererIsBeingDestroyed && (m_autoscrollInProgress || m_panScrollInProgress))
|
|
853 |
toRenderBox(autoscrollRenderer())->stopAutoscroll();
|
|
854 |
#if ENABLE(PAN_SCROLLING)
|
|
855 |
if (m_panScrollInProgress) {
|
|
856 |
if (FrameView* view = m_frame->view()) {
|
|
857 |
view->removePanScrollIcon();
|
|
858 |
view->setCursor(pointerCursor());
|
|
859 |
}
|
|
860 |
}
|
|
861 |
#endif
|
|
862 |
|
|
863 |
setAutoscrollRenderer(0);
|
|
864 |
}
|
|
865 |
|
|
866 |
m_autoscrollTimer.stop();
|
|
867 |
|
|
868 |
m_panScrollInProgress = false;
|
|
869 |
m_springLoadedPanScrollInProgress = false;
|
|
870 |
|
|
871 |
// If we're not in the top frame we notify it that we are not doing a panScroll any more.
|
|
872 |
if (Page* page = m_frame->page()) {
|
|
873 |
Frame* mainFrame = page->mainFrame();
|
|
874 |
if (m_frame != mainFrame)
|
|
875 |
mainFrame->eventHandler()->setPanScrollInProgress(false);
|
|
876 |
}
|
|
877 |
|
|
878 |
m_autoscrollInProgress = false;
|
|
879 |
}
|
|
880 |
|
|
881 |
Node* EventHandler::mousePressNode() const
|
|
882 |
{
|
|
883 |
return m_mousePressNode.get();
|
|
884 |
}
|
|
885 |
|
|
886 |
void EventHandler::setMousePressNode(PassRefPtr<Node> node)
|
|
887 |
{
|
|
888 |
m_mousePressNode = node;
|
|
889 |
}
|
|
890 |
|
|
891 |
bool EventHandler::scrollOverflow(ScrollDirection direction, ScrollGranularity granularity)
|
|
892 |
{
|
|
893 |
Node* node = m_frame->document()->focusedNode();
|
|
894 |
if (!node)
|
|
895 |
node = m_mousePressNode.get();
|
|
896 |
|
|
897 |
if (node) {
|
|
898 |
RenderObject* r = node->renderer();
|
|
899 |
if (r && !r->isListBox() && r->enclosingBox()->scroll(direction, granularity)) {
|
|
900 |
setFrameWasScrolledByUser();
|
|
901 |
return true;
|
|
902 |
}
|
|
903 |
}
|
|
904 |
|
|
905 |
return false;
|
|
906 |
}
|
|
907 |
|
|
908 |
bool EventHandler::scrollRecursively(ScrollDirection direction, ScrollGranularity granularity)
|
|
909 |
{
|
|
910 |
bool handled = scrollOverflow(direction, granularity);
|
|
911 |
if (!handled) {
|
|
912 |
Frame* frame = m_frame;
|
|
913 |
do {
|
|
914 |
FrameView* view = frame->view();
|
|
915 |
handled = view ? view->scroll(direction, granularity) : false;
|
|
916 |
frame = frame->tree()->parent();
|
|
917 |
} while (!handled && frame);
|
|
918 |
}
|
|
919 |
|
|
920 |
return handled;
|
|
921 |
}
|
|
922 |
|
|
923 |
IntPoint EventHandler::currentMousePosition() const
|
|
924 |
{
|
|
925 |
return m_currentMousePosition;
|
|
926 |
}
|
|
927 |
|
|
928 |
Frame* subframeForHitTestResult(const MouseEventWithHitTestResults& hitTestResult)
|
|
929 |
{
|
|
930 |
if (!hitTestResult.isOverWidget())
|
|
931 |
return 0;
|
|
932 |
return EventHandler::subframeForTargetNode(hitTestResult.targetNode());
|
|
933 |
}
|
|
934 |
|
|
935 |
Frame* EventHandler::subframeForTargetNode(Node* node)
|
|
936 |
{
|
|
937 |
if (!node)
|
|
938 |
return 0;
|
|
939 |
|
|
940 |
RenderObject* renderer = node->renderer();
|
|
941 |
if (!renderer || !renderer->isWidget())
|
|
942 |
return 0;
|
|
943 |
|
|
944 |
Widget* widget = toRenderWidget(renderer)->widget();
|
|
945 |
if (!widget || !widget->isFrameView())
|
|
946 |
return 0;
|
|
947 |
|
|
948 |
return static_cast<FrameView*>(widget)->frame();
|
|
949 |
}
|
|
950 |
|
|
951 |
static bool isSubmitImage(Node* node)
|
|
952 |
{
|
|
953 |
return node && node->hasTagName(inputTag)
|
|
954 |
&& static_cast<HTMLInputElement*>(node)->inputType() == HTMLInputElement::IMAGE;
|
|
955 |
}
|
|
956 |
|
|
957 |
// Returns true if the node's editable block is not current focused for editing
|
|
958 |
static bool nodeIsNotBeingEdited(Node* node, Frame* frame)
|
|
959 |
{
|
|
960 |
return frame->selection()->rootEditableElement() != node->rootEditableElement();
|
|
961 |
}
|
|
962 |
|
|
963 |
Cursor EventHandler::selectCursor(const MouseEventWithHitTestResults& event, Scrollbar* scrollbar)
|
|
964 |
{
|
|
965 |
// During selection, use an I-beam no matter what we're over.
|
|
966 |
// If you're capturing mouse events for a particular node, don't treat this as a selection.
|
|
967 |
if (m_mousePressed && m_mouseDownMayStartSelect && m_frame->selection()->isCaretOrRange() && !m_capturingMouseEventsNode)
|
|
968 |
return iBeamCursor();
|
|
969 |
|
|
970 |
Node* node = event.targetNode();
|
|
971 |
RenderObject* renderer = node ? node->renderer() : 0;
|
|
972 |
RenderStyle* style = renderer ? renderer->style() : 0;
|
|
973 |
|
|
974 |
if (renderer && renderer->isFrameSet()) {
|
|
975 |
RenderFrameSet* frameSetRenderer = toRenderFrameSet(renderer);
|
|
976 |
if (frameSetRenderer->canResizeRow(event.localPoint()))
|
|
977 |
return rowResizeCursor();
|
|
978 |
if (frameSetRenderer->canResizeColumn(event.localPoint()))
|
|
979 |
return columnResizeCursor();
|
|
980 |
}
|
|
981 |
|
|
982 |
if (style && style->cursors()) {
|
|
983 |
const CursorList* cursors = style->cursors();
|
|
984 |
for (unsigned i = 0; i < cursors->size(); ++i) {
|
|
985 |
CachedImage* cimage = (*cursors)[i].cursorImage.get();
|
|
986 |
IntPoint hotSpot = (*cursors)[i].hotSpot;
|
|
987 |
if (!cimage)
|
|
988 |
continue;
|
|
989 |
// Limit the size of cursors so that they cannot be used to cover UI elements in chrome.
|
|
990 |
IntSize size = cimage->image()->size();
|
|
991 |
if (size.width() > 128 || size.height() > 128)
|
|
992 |
continue;
|
|
993 |
// Do not let the hotspot be outside the bounds of the image.
|
|
994 |
if (hotSpot.x() < 0 || hotSpot.y() < 0 || hotSpot.x() > size.width() || hotSpot.y() > size.height())
|
|
995 |
continue;
|
|
996 |
if (cimage->image()->isNull())
|
|
997 |
break;
|
|
998 |
if (!cimage->errorOccurred())
|
|
999 |
return Cursor(cimage->image(), hotSpot);
|
|
1000 |
}
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
switch (style ? style->cursor() : CURSOR_AUTO) {
|
|
1004 |
case CURSOR_AUTO: {
|
|
1005 |
bool editable = (node && node->isContentEditable());
|
|
1006 |
bool editableLinkEnabled = false;
|
|
1007 |
|
|
1008 |
// If the link is editable, then we need to check the settings to see whether or not the link should be followed
|
|
1009 |
if (editable) {
|
|
1010 |
ASSERT(m_frame->settings());
|
|
1011 |
switch (m_frame->settings()->editableLinkBehavior()) {
|
|
1012 |
default:
|
|
1013 |
case EditableLinkDefaultBehavior:
|
|
1014 |
case EditableLinkAlwaysLive:
|
|
1015 |
editableLinkEnabled = true;
|
|
1016 |
break;
|
|
1017 |
|
|
1018 |
case EditableLinkNeverLive:
|
|
1019 |
editableLinkEnabled = false;
|
|
1020 |
break;
|
|
1021 |
|
|
1022 |
case EditableLinkLiveWhenNotFocused:
|
|
1023 |
editableLinkEnabled = nodeIsNotBeingEdited(node, m_frame) || event.event().shiftKey();
|
|
1024 |
break;
|
|
1025 |
|
|
1026 |
case EditableLinkOnlyLiveWithShiftKey:
|
|
1027 |
editableLinkEnabled = event.event().shiftKey();
|
|
1028 |
break;
|
|
1029 |
}
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
if ((event.isOverLink() || isSubmitImage(node)) && (!editable || editableLinkEnabled))
|
|
1033 |
return handCursor();
|
|
1034 |
bool inResizer = false;
|
|
1035 |
if (renderer) {
|
|
1036 |
if (RenderLayer* layer = renderer->enclosingLayer()) {
|
|
1037 |
if (FrameView* view = m_frame->view())
|
|
1038 |
inResizer = layer->isPointInResizeControl(view->windowToContents(event.event().pos()));
|
|
1039 |
}
|
|
1040 |
}
|
|
1041 |
if ((editable || (renderer && renderer->isText() && node->canStartSelection())) && !inResizer && !scrollbar)
|
|
1042 |
return iBeamCursor();
|
|
1043 |
return pointerCursor();
|
|
1044 |
}
|
|
1045 |
case CURSOR_CROSS:
|
|
1046 |
return crossCursor();
|
|
1047 |
case CURSOR_POINTER:
|
|
1048 |
return handCursor();
|
|
1049 |
case CURSOR_MOVE:
|
|
1050 |
return moveCursor();
|
|
1051 |
case CURSOR_ALL_SCROLL:
|
|
1052 |
return moveCursor();
|
|
1053 |
case CURSOR_E_RESIZE:
|
|
1054 |
return eastResizeCursor();
|
|
1055 |
case CURSOR_W_RESIZE:
|
|
1056 |
return westResizeCursor();
|
|
1057 |
case CURSOR_N_RESIZE:
|
|
1058 |
return northResizeCursor();
|
|
1059 |
case CURSOR_S_RESIZE:
|
|
1060 |
return southResizeCursor();
|
|
1061 |
case CURSOR_NE_RESIZE:
|
|
1062 |
return northEastResizeCursor();
|
|
1063 |
case CURSOR_SW_RESIZE:
|
|
1064 |
return southWestResizeCursor();
|
|
1065 |
case CURSOR_NW_RESIZE:
|
|
1066 |
return northWestResizeCursor();
|
|
1067 |
case CURSOR_SE_RESIZE:
|
|
1068 |
return southEastResizeCursor();
|
|
1069 |
case CURSOR_NS_RESIZE:
|
|
1070 |
return northSouthResizeCursor();
|
|
1071 |
case CURSOR_EW_RESIZE:
|
|
1072 |
return eastWestResizeCursor();
|
|
1073 |
case CURSOR_NESW_RESIZE:
|
|
1074 |
return northEastSouthWestResizeCursor();
|
|
1075 |
case CURSOR_NWSE_RESIZE:
|
|
1076 |
return northWestSouthEastResizeCursor();
|
|
1077 |
case CURSOR_COL_RESIZE:
|
|
1078 |
return columnResizeCursor();
|
|
1079 |
case CURSOR_ROW_RESIZE:
|
|
1080 |
return rowResizeCursor();
|
|
1081 |
case CURSOR_TEXT:
|
|
1082 |
return iBeamCursor();
|
|
1083 |
case CURSOR_WAIT:
|
|
1084 |
return waitCursor();
|
|
1085 |
case CURSOR_HELP:
|
|
1086 |
return helpCursor();
|
|
1087 |
case CURSOR_VERTICAL_TEXT:
|
|
1088 |
return verticalTextCursor();
|
|
1089 |
case CURSOR_CELL:
|
|
1090 |
return cellCursor();
|
|
1091 |
case CURSOR_CONTEXT_MENU:
|
|
1092 |
return contextMenuCursor();
|
|
1093 |
case CURSOR_PROGRESS:
|
|
1094 |
return progressCursor();
|
|
1095 |
case CURSOR_NO_DROP:
|
|
1096 |
return noDropCursor();
|
|
1097 |
case CURSOR_ALIAS:
|
|
1098 |
return aliasCursor();
|
|
1099 |
case CURSOR_COPY:
|
|
1100 |
return copyCursor();
|
|
1101 |
case CURSOR_NONE:
|
|
1102 |
return noneCursor();
|
|
1103 |
case CURSOR_NOT_ALLOWED:
|
|
1104 |
return notAllowedCursor();
|
|
1105 |
case CURSOR_DEFAULT:
|
|
1106 |
return pointerCursor();
|
|
1107 |
case CURSOR_WEBKIT_ZOOM_IN:
|
|
1108 |
return zoomInCursor();
|
|
1109 |
case CURSOR_WEBKIT_ZOOM_OUT:
|
|
1110 |
return zoomOutCursor();
|
|
1111 |
case CURSOR_WEBKIT_GRAB:
|
|
1112 |
return grabCursor();
|
|
1113 |
case CURSOR_WEBKIT_GRABBING:
|
|
1114 |
return grabbingCursor();
|
|
1115 |
}
|
|
1116 |
return pointerCursor();
|
|
1117 |
}
|
|
1118 |
|
|
1119 |
static IntPoint documentPointForWindowPoint(Frame* frame, const IntPoint& windowPoint)
|
|
1120 |
{
|
|
1121 |
FrameView* view = frame->view();
|
|
1122 |
// FIXME: Is it really OK to use the wrong coordinates here when view is 0?
|
|
1123 |
// Historically the code would just crash; this is clearly no worse than that.
|
|
1124 |
return view ? view->windowToContents(windowPoint) : windowPoint;
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
bool EventHandler::handleMousePressEvent(const PlatformMouseEvent& mouseEvent)
|
|
1128 |
{
|
|
1129 |
RefPtr<FrameView> protector(m_frame->view());
|
|
1130 |
|
|
1131 |
m_mousePressed = true;
|
|
1132 |
m_capturesDragging = true;
|
|
1133 |
m_currentMousePosition = mouseEvent.pos();
|
|
1134 |
m_mouseDownTimestamp = mouseEvent.timestamp();
|
|
1135 |
#if ENABLE(DRAG_SUPPORT)
|
|
1136 |
m_mouseDownMayStartDrag = false;
|
|
1137 |
#endif
|
|
1138 |
m_mouseDownMayStartSelect = false;
|
|
1139 |
m_mouseDownMayStartAutoscroll = false;
|
|
1140 |
if (FrameView* view = m_frame->view())
|
|
1141 |
m_mouseDownPos = view->windowToContents(mouseEvent.pos());
|
|
1142 |
else {
|
|
1143 |
invalidateClick();
|
|
1144 |
return false;
|
|
1145 |
}
|
|
1146 |
m_mouseDownWasInSubframe = false;
|
|
1147 |
|
|
1148 |
HitTestRequest request(HitTestRequest::Active);
|
|
1149 |
// Save the document point we generate in case the window coordinate is invalidated by what happens
|
|
1150 |
// when we dispatch the event.
|
|
1151 |
IntPoint documentPoint = documentPointForWindowPoint(m_frame, mouseEvent.pos());
|
|
1152 |
MouseEventWithHitTestResults mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
|
|
1153 |
|
|
1154 |
if (!mev.targetNode()) {
|
|
1155 |
invalidateClick();
|
|
1156 |
return false;
|
|
1157 |
}
|
|
1158 |
|
|
1159 |
m_mousePressNode = mev.targetNode();
|
|
1160 |
|
|
1161 |
#if ENABLE(INSPECTOR)
|
|
1162 |
if (Page* page = m_frame->page()) {
|
|
1163 |
InspectorController* inspector = page->inspectorController();
|
|
1164 |
if (inspector && inspector->enabled() && inspector->searchingForNodeInPage()) {
|
|
1165 |
inspector->handleMousePressOnNode(m_mousePressNode.get());
|
|
1166 |
invalidateClick();
|
|
1167 |
return true;
|
|
1168 |
}
|
|
1169 |
}
|
|
1170 |
#endif
|
|
1171 |
|
|
1172 |
Frame* subframe = subframeForHitTestResult(mev);
|
|
1173 |
if (subframe && passMousePressEventToSubframe(mev, subframe)) {
|
|
1174 |
// Start capturing future events for this frame. We only do this if we didn't clear
|
|
1175 |
// the m_mousePressed flag, which may happen if an AppKit widget entered a modal event loop.
|
|
1176 |
m_capturesDragging = subframe->eventHandler()->capturesDragging();
|
|
1177 |
if (m_mousePressed && m_capturesDragging)
|
|
1178 |
m_capturingMouseEventsNode = mev.targetNode();
|
|
1179 |
invalidateClick();
|
|
1180 |
return true;
|
|
1181 |
}
|
|
1182 |
|
|
1183 |
#if ENABLE(PAN_SCROLLING)
|
|
1184 |
Page* page = m_frame->page();
|
|
1185 |
if (page && page->mainFrame()->eventHandler()->panScrollInProgress() || m_autoscrollInProgress) {
|
|
1186 |
stopAutoscrollTimer();
|
|
1187 |
invalidateClick();
|
|
1188 |
return true;
|
|
1189 |
}
|
|
1190 |
|
|
1191 |
if (mouseEvent.button() == MiddleButton && !mev.isOverLink()) {
|
|
1192 |
RenderObject* renderer = mev.targetNode()->renderer();
|
|
1193 |
|
|
1194 |
while (renderer && (!renderer->isBox() || !toRenderBox(renderer)->canBeScrolledAndHasScrollableArea())) {
|
|
1195 |
if (!renderer->parent() && renderer->node() == renderer->document() && renderer->document()->ownerElement())
|
|
1196 |
renderer = renderer->document()->ownerElement()->renderer();
|
|
1197 |
else
|
|
1198 |
renderer = renderer->parent();
|
|
1199 |
}
|
|
1200 |
|
|
1201 |
if (renderer) {
|
|
1202 |
m_panScrollInProgress = true;
|
|
1203 |
m_panScrollButtonPressed = true;
|
|
1204 |
handleAutoscroll(renderer);
|
|
1205 |
invalidateClick();
|
|
1206 |
return true;
|
|
1207 |
}
|
|
1208 |
}
|
|
1209 |
#endif
|
|
1210 |
|
|
1211 |
m_clickCount = mouseEvent.clickCount();
|
|
1212 |
m_clickNode = mev.targetNode();
|
|
1213 |
|
|
1214 |
if (FrameView* view = m_frame->view()) {
|
|
1215 |
RenderLayer* layer = m_clickNode->renderer() ? m_clickNode->renderer()->enclosingLayer() : 0;
|
|
1216 |
IntPoint p = view->windowToContents(mouseEvent.pos());
|
|
1217 |
if (layer && layer->isPointInResizeControl(p)) {
|
|
1218 |
layer->setInResizeMode(true);
|
|
1219 |
m_resizeLayer = layer;
|
|
1220 |
m_offsetFromResizeCorner = layer->offsetFromResizeCorner(p);
|
|
1221 |
invalidateClick();
|
|
1222 |
return true;
|
|
1223 |
}
|
|
1224 |
}
|
|
1225 |
|
|
1226 |
bool swallowEvent = dispatchMouseEvent(eventNames().mousedownEvent, mev.targetNode(), true, m_clickCount, mouseEvent, true);
|
|
1227 |
m_capturesDragging = !swallowEvent;
|
|
1228 |
|
|
1229 |
// If the hit testing originally determined the event was in a scrollbar, refetch the MouseEventWithHitTestResults
|
|
1230 |
// in case the scrollbar widget was destroyed when the mouse event was handled.
|
|
1231 |
if (mev.scrollbar()) {
|
|
1232 |
const bool wasLastScrollBar = mev.scrollbar() == m_lastScrollbarUnderMouse.get();
|
|
1233 |
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
|
|
1234 |
mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
|
|
1235 |
if (wasLastScrollBar && mev.scrollbar() != m_lastScrollbarUnderMouse.get())
|
|
1236 |
m_lastScrollbarUnderMouse = 0;
|
|
1237 |
}
|
|
1238 |
|
|
1239 |
if (swallowEvent) {
|
|
1240 |
// scrollbars should get events anyway, even disabled controls might be scrollable
|
|
1241 |
Scrollbar* scrollbar = mev.scrollbar();
|
|
1242 |
|
|
1243 |
updateLastScrollbarUnderMouse(scrollbar, true);
|
|
1244 |
|
|
1245 |
if (scrollbar)
|
|
1246 |
passMousePressEventToScrollbar(mev, scrollbar);
|
|
1247 |
} else {
|
|
1248 |
// Refetch the event target node if it currently is the shadow node inside an <input> element.
|
|
1249 |
// If a mouse event handler changes the input element type to one that has a widget associated,
|
|
1250 |
// we'd like to EventHandler::handleMousePressEvent to pass the event to the widget and thus the
|
|
1251 |
// event target node can't still be the shadow node.
|
|
1252 |
if (mev.targetNode()->isShadowNode() && mev.targetNode()->shadowParentNode()->hasTagName(inputTag)) {
|
|
1253 |
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
|
|
1254 |
mev = m_frame->document()->prepareMouseEvent(request, documentPoint, mouseEvent);
|
|
1255 |
}
|
|
1256 |
|
|
1257 |
FrameView* view = m_frame->view();
|
|
1258 |
Scrollbar* scrollbar = view ? view->scrollbarAtPoint(mouseEvent.pos()) : 0;
|
|
1259 |
if (!scrollbar)
|
|
1260 |
scrollbar = mev.scrollbar();
|
|
1261 |
|
|
1262 |
updateLastScrollbarUnderMouse(scrollbar, true);
|
|
1263 |
|
|
1264 |
if (scrollbar && passMousePressEventToScrollbar(mev, scrollbar))
|
|
1265 |
swallowEvent = true;
|
|
1266 |
else
|
|
1267 |
swallowEvent = handleMousePressEvent(mev);
|
|
1268 |
}
|
|
1269 |
|
|
1270 |
return swallowEvent;
|
|
1271 |
}
|
|
1272 |
|
|
1273 |
// This method only exists for platforms that don't know how to deliver
|
|
1274 |
bool EventHandler::handleMouseDoubleClickEvent(const PlatformMouseEvent& mouseEvent)
|
|
1275 |
{
|
|
1276 |
RefPtr<FrameView> protector(m_frame->view());
|
|
1277 |
|
|
1278 |
// We get this instead of a second mouse-up
|
|
1279 |
m_mousePressed = false;
|
|
1280 |
m_currentMousePosition = mouseEvent.pos();
|
|
1281 |
|
|
1282 |
HitTestRequest request(HitTestRequest::Active);
|
|
1283 |
MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent);
|
|
1284 |
Frame* subframe = subframeForHitTestResult(mev);
|
|
1285 |
if (subframe && passMousePressEventToSubframe(mev, subframe)) {
|
|
1286 |
m_capturingMouseEventsNode = 0;
|
|
1287 |
return true;
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
m_clickCount = mouseEvent.clickCount();
|
|
1291 |
bool swallowMouseUpEvent = dispatchMouseEvent(eventNames().mouseupEvent, mev.targetNode(), true, m_clickCount, mouseEvent, false);
|
|
1292 |
|
|
1293 |
bool swallowClickEvent = false;
|
|
1294 |
// Don't ever dispatch click events for right clicks
|
|
1295 |
if (mouseEvent.button() != RightButton && mev.targetNode() == m_clickNode)
|
|
1296 |
swallowClickEvent = dispatchMouseEvent(eventNames().clickEvent, mev.targetNode(), true, m_clickCount, mouseEvent, true);
|
|
1297 |
|
|
1298 |
if (m_lastScrollbarUnderMouse)
|
|
1299 |
swallowMouseUpEvent = m_lastScrollbarUnderMouse->mouseUp();
|
|
1300 |
|
|
1301 |
bool swallowMouseReleaseEvent = false;
|
|
1302 |
if (!swallowMouseUpEvent)
|
|
1303 |
swallowMouseReleaseEvent = handleMouseReleaseEvent(mev);
|
|
1304 |
|
|
1305 |
invalidateClick();
|
|
1306 |
|
|
1307 |
return swallowMouseUpEvent || swallowClickEvent || swallowMouseReleaseEvent;
|
|
1308 |
}
|
|
1309 |
|
|
1310 |
bool EventHandler::mouseMoved(const PlatformMouseEvent& event)
|
|
1311 |
{
|
|
1312 |
HitTestResult hoveredNode = HitTestResult(IntPoint());
|
|
1313 |
bool result = handleMouseMoveEvent(event, &hoveredNode);
|
|
1314 |
|
|
1315 |
Page* page = m_frame->page();
|
|
1316 |
if (!page)
|
|
1317 |
return result;
|
|
1318 |
|
|
1319 |
hoveredNode.setToNonShadowAncestor();
|
|
1320 |
page->chrome()->mouseDidMoveOverElement(hoveredNode, event.modifierFlags());
|
|
1321 |
page->chrome()->setToolTip(hoveredNode);
|
|
1322 |
return result;
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& mouseEvent, HitTestResult* hoveredNode)
|
|
1326 |
{
|
|
1327 |
// in Radar 3703768 we saw frequent crashes apparently due to the
|
|
1328 |
// part being null here, which seems impossible, so check for nil
|
|
1329 |
// but also assert so that we can try to figure this out in debug
|
|
1330 |
// builds, if it happens.
|
|
1331 |
ASSERT(m_frame);
|
|
1332 |
if (!m_frame)
|
|
1333 |
return false;
|
|
1334 |
|
|
1335 |
RefPtr<FrameView> protector(m_frame->view());
|
|
1336 |
m_currentMousePosition = mouseEvent.pos();
|
|
1337 |
|
|
1338 |
if (m_hoverTimer.isActive())
|
|
1339 |
m_hoverTimer.stop();
|
|
1340 |
|
|
1341 |
#if ENABLE(SVG)
|
|
1342 |
if (m_svgPan) {
|
|
1343 |
static_cast<SVGDocument*>(m_frame->document())->updatePan(m_currentMousePosition);
|
|
1344 |
return true;
|
|
1345 |
}
|
|
1346 |
#endif
|
|
1347 |
|
|
1348 |
if (m_frameSetBeingResized)
|
|
1349 |
return dispatchMouseEvent(eventNames().mousemoveEvent, m_frameSetBeingResized.get(), false, 0, mouseEvent, false);
|
|
1350 |
|
|
1351 |
// Send events right to a scrollbar if the mouse is pressed.
|
|
1352 |
if (m_lastScrollbarUnderMouse && m_mousePressed)
|
|
1353 |
return m_lastScrollbarUnderMouse->mouseMoved(mouseEvent);
|
|
1354 |
|
|
1355 |
// Treat mouse move events while the mouse is pressed as "read-only" in prepareMouseEvent
|
|
1356 |
// if we are allowed to select.
|
|
1357 |
// This means that :hover and :active freeze in the state they were in when the mouse
|
|
1358 |
// was pressed, rather than updating for nodes the mouse moves over as you hold the mouse down.
|
|
1359 |
int hitType = HitTestRequest::MouseMove;
|
|
1360 |
if (m_mousePressed && m_mouseDownMayStartSelect)
|
|
1361 |
hitType |= HitTestRequest::ReadOnly;
|
|
1362 |
if (m_mousePressed)
|
|
1363 |
hitType |= HitTestRequest::Active;
|
|
1364 |
HitTestRequest request(hitType);
|
|
1365 |
MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent);
|
|
1366 |
if (hoveredNode)
|
|
1367 |
*hoveredNode = mev.hitTestResult();
|
|
1368 |
|
|
1369 |
Scrollbar* scrollbar = 0;
|
|
1370 |
|
|
1371 |
if (m_resizeLayer && m_resizeLayer->inResizeMode())
|
|
1372 |
m_resizeLayer->resize(mouseEvent, m_offsetFromResizeCorner);
|
|
1373 |
else {
|
|
1374 |
if (FrameView* view = m_frame->view())
|
|
1375 |
scrollbar = view->scrollbarAtPoint(mouseEvent.pos());
|
|
1376 |
|
|
1377 |
if (!scrollbar)
|
|
1378 |
scrollbar = mev.scrollbar();
|
|
1379 |
|
|
1380 |
updateLastScrollbarUnderMouse(scrollbar, !m_mousePressed);
|
|
1381 |
}
|
|
1382 |
|
|
1383 |
bool swallowEvent = false;
|
|
1384 |
RefPtr<Frame> newSubframe = m_capturingMouseEventsNode.get() ? subframeForTargetNode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev);
|
|
1385 |
|
|
1386 |
// We want mouseouts to happen first, from the inside out. First send a move event to the last subframe so that it will fire mouseouts.
|
|
1387 |
if (m_lastMouseMoveEventSubframe && m_lastMouseMoveEventSubframe->tree()->isDescendantOf(m_frame) && m_lastMouseMoveEventSubframe != newSubframe)
|
|
1388 |
passMouseMoveEventToSubframe(mev, m_lastMouseMoveEventSubframe.get());
|
|
1389 |
|
|
1390 |
if (newSubframe) {
|
|
1391 |
// Update over/out state before passing the event to the subframe.
|
|
1392 |
updateMouseEventTargetNode(mev.targetNode(), mouseEvent, true);
|
|
1393 |
|
|
1394 |
// Event dispatch in updateMouseEventTargetNode may have caused the subframe of the target
|
|
1395 |
// node to be detached from its FrameView, in which case the event should not be passed.
|
|
1396 |
if (newSubframe->view())
|
|
1397 |
swallowEvent |= passMouseMoveEventToSubframe(mev, newSubframe.get(), hoveredNode);
|
|
1398 |
} else {
|
|
1399 |
if (scrollbar && !m_mousePressed)
|
|
1400 |
scrollbar->mouseMoved(mouseEvent); // Handle hover effects on platforms that support visual feedback on scrollbar hovering.
|
|
1401 |
if (Page* page = m_frame->page()) {
|
|
1402 |
if ((!m_resizeLayer || !m_resizeLayer->inResizeMode()) && !page->mainFrame()->eventHandler()->panScrollInProgress()) {
|
|
1403 |
if (FrameView* view = m_frame->view())
|
|
1404 |
view->setCursor(selectCursor(mev, scrollbar));
|
|
1405 |
}
|
|
1406 |
}
|
|
1407 |
}
|
|
1408 |
|
|
1409 |
m_lastMouseMoveEventSubframe = newSubframe;
|
|
1410 |
|
|
1411 |
if (swallowEvent)
|
|
1412 |
return true;
|
|
1413 |
|
|
1414 |
swallowEvent = dispatchMouseEvent(eventNames().mousemoveEvent, mev.targetNode(), false, 0, mouseEvent, true);
|
|
1415 |
#if ENABLE(DRAG_SUPPORT)
|
|
1416 |
if (!swallowEvent)
|
|
1417 |
swallowEvent = handleMouseDraggedEvent(mev);
|
|
1418 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
1419 |
|
|
1420 |
return swallowEvent;
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
void EventHandler::invalidateClick()
|
|
1424 |
{
|
|
1425 |
m_clickCount = 0;
|
|
1426 |
m_clickNode = 0;
|
|
1427 |
}
|
|
1428 |
|
|
1429 |
bool EventHandler::handleMouseReleaseEvent(const PlatformMouseEvent& mouseEvent)
|
|
1430 |
{
|
|
1431 |
RefPtr<FrameView> protector(m_frame->view());
|
|
1432 |
|
|
1433 |
#if ENABLE(PAN_SCROLLING)
|
|
1434 |
if (mouseEvent.button() == MiddleButton)
|
|
1435 |
m_panScrollButtonPressed = false;
|
|
1436 |
if (m_springLoadedPanScrollInProgress)
|
|
1437 |
stopAutoscrollTimer();
|
|
1438 |
#endif
|
|
1439 |
|
|
1440 |
m_mousePressed = false;
|
|
1441 |
m_currentMousePosition = mouseEvent.pos();
|
|
1442 |
|
|
1443 |
#if ENABLE(SVG)
|
|
1444 |
if (m_svgPan) {
|
|
1445 |
m_svgPan = false;
|
|
1446 |
static_cast<SVGDocument*>(m_frame->document())->updatePan(m_currentMousePosition);
|
|
1447 |
return true;
|
|
1448 |
}
|
|
1449 |
#endif
|
|
1450 |
|
|
1451 |
if (m_frameSetBeingResized)
|
|
1452 |
return dispatchMouseEvent(eventNames().mouseupEvent, m_frameSetBeingResized.get(), true, m_clickCount, mouseEvent, false);
|
|
1453 |
|
|
1454 |
if (m_lastScrollbarUnderMouse) {
|
|
1455 |
invalidateClick();
|
|
1456 |
return m_lastScrollbarUnderMouse->mouseUp();
|
|
1457 |
}
|
|
1458 |
|
|
1459 |
HitTestRequest request(HitTestRequest::MouseUp);
|
|
1460 |
MouseEventWithHitTestResults mev = prepareMouseEvent(request, mouseEvent);
|
|
1461 |
Frame* subframe = m_capturingMouseEventsNode.get() ? subframeForTargetNode(m_capturingMouseEventsNode.get()) : subframeForHitTestResult(mev);
|
|
1462 |
if (subframe && passMouseReleaseEventToSubframe(mev, subframe)) {
|
|
1463 |
m_capturingMouseEventsNode = 0;
|
|
1464 |
return true;
|
|
1465 |
}
|
|
1466 |
|
|
1467 |
bool swallowMouseUpEvent = dispatchMouseEvent(eventNames().mouseupEvent, mev.targetNode(), true, m_clickCount, mouseEvent, false);
|
|
1468 |
|
|
1469 |
// Don't ever dispatch click events for right clicks
|
|
1470 |
bool swallowClickEvent = false;
|
|
1471 |
if (m_clickCount > 0 && mouseEvent.button() != RightButton && mev.targetNode() == m_clickNode)
|
|
1472 |
swallowClickEvent = dispatchMouseEvent(eventNames().clickEvent, mev.targetNode(), true, m_clickCount, mouseEvent, true);
|
|
1473 |
|
|
1474 |
if (m_resizeLayer) {
|
|
1475 |
m_resizeLayer->setInResizeMode(false);
|
|
1476 |
m_resizeLayer = 0;
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
bool swallowMouseReleaseEvent = false;
|
|
1480 |
if (!swallowMouseUpEvent)
|
|
1481 |
swallowMouseReleaseEvent = handleMouseReleaseEvent(mev);
|
|
1482 |
|
|
1483 |
invalidateClick();
|
|
1484 |
|
|
1485 |
return swallowMouseUpEvent || swallowClickEvent || swallowMouseReleaseEvent;
|
|
1486 |
}
|
|
1487 |
|
|
1488 |
#if ENABLE(DRAG_SUPPORT)
|
|
1489 |
bool EventHandler::dispatchDragEvent(const AtomicString& eventType, Node* dragTarget, const PlatformMouseEvent& event, Clipboard* clipboard)
|
|
1490 |
{
|
|
1491 |
FrameView* view = m_frame->view();
|
|
1492 |
|
|
1493 |
// FIXME: We might want to dispatch a dragleave even if the view is gone.
|
|
1494 |
if (!view)
|
|
1495 |
return false;
|
|
1496 |
|
|
1497 |
view->resetDeferredRepaintDelay();
|
|
1498 |
IntPoint contentsPos = view->windowToContents(event.pos());
|
|
1499 |
|
|
1500 |
RefPtr<MouseEvent> me = MouseEvent::create(eventType,
|
|
1501 |
true, true, m_frame->document()->defaultView(),
|
|
1502 |
0, event.globalX(), event.globalY(), contentsPos.x(), contentsPos.y(),
|
|
1503 |
event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
|
|
1504 |
0, 0, clipboard);
|
|
1505 |
|
|
1506 |
ExceptionCode ec;
|
|
1507 |
dragTarget->dispatchEvent(me.get(), ec);
|
|
1508 |
return me->defaultPrevented();
|
|
1509 |
}
|
|
1510 |
|
|
1511 |
bool EventHandler::updateDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
|
|
1512 |
{
|
|
1513 |
bool accept = false;
|
|
1514 |
|
|
1515 |
if (!m_frame->view())
|
|
1516 |
return false;
|
|
1517 |
|
|
1518 |
HitTestRequest request(HitTestRequest::ReadOnly);
|
|
1519 |
MouseEventWithHitTestResults mev = prepareMouseEvent(request, event);
|
|
1520 |
|
|
1521 |
// Drag events should never go to text nodes (following IE, and proper mouseover/out dispatch)
|
|
1522 |
Node* newTarget = mev.targetNode();
|
|
1523 |
if (newTarget && newTarget->isTextNode())
|
|
1524 |
newTarget = newTarget->parentNode();
|
|
1525 |
if (newTarget)
|
|
1526 |
newTarget = newTarget->shadowAncestorNode();
|
|
1527 |
|
|
1528 |
if (m_dragTarget != newTarget) {
|
|
1529 |
// FIXME: this ordering was explicitly chosen to match WinIE. However,
|
|
1530 |
// it is sometimes incorrect when dragging within subframes, as seen with
|
|
1531 |
// LayoutTests/fast/events/drag-in-frames.html.
|
|
1532 |
if (newTarget) {
|
|
1533 |
Frame* frame = (newTarget->hasTagName(frameTag) || newTarget->hasTagName(iframeTag)) ? static_cast<HTMLFrameElementBase*>(newTarget)->contentFrame() : 0;
|
|
1534 |
if (frame)
|
|
1535 |
accept = frame->eventHandler()->updateDragAndDrop(event, clipboard);
|
|
1536 |
else
|
|
1537 |
accept = dispatchDragEvent(eventNames().dragenterEvent, newTarget, event, clipboard);
|
|
1538 |
}
|
|
1539 |
|
|
1540 |
if (m_dragTarget) {
|
|
1541 |
Frame* frame = (m_dragTarget->hasTagName(frameTag) || m_dragTarget->hasTagName(iframeTag)) ? static_cast<HTMLFrameElementBase*>(m_dragTarget.get())->contentFrame() : 0;
|
|
1542 |
if (frame)
|
|
1543 |
accept = frame->eventHandler()->updateDragAndDrop(event, clipboard);
|
|
1544 |
else
|
|
1545 |
dispatchDragEvent(eventNames().dragleaveEvent, m_dragTarget.get(), event, clipboard);
|
|
1546 |
}
|
|
1547 |
} else {
|
|
1548 |
if (newTarget) {
|
|
1549 |
Frame* frame = (newTarget->hasTagName(frameTag) || newTarget->hasTagName(iframeTag)) ? static_cast<HTMLFrameElementBase*>(newTarget)->contentFrame() : 0;
|
|
1550 |
if (frame)
|
|
1551 |
accept = frame->eventHandler()->updateDragAndDrop(event, clipboard);
|
|
1552 |
else
|
|
1553 |
accept = dispatchDragEvent(eventNames().dragoverEvent, newTarget, event, clipboard);
|
|
1554 |
}
|
|
1555 |
}
|
|
1556 |
m_dragTarget = newTarget;
|
|
1557 |
|
|
1558 |
return accept;
|
|
1559 |
}
|
|
1560 |
|
|
1561 |
void EventHandler::cancelDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
|
|
1562 |
{
|
|
1563 |
if (m_dragTarget) {
|
|
1564 |
Frame* frame = (m_dragTarget->hasTagName(frameTag) || m_dragTarget->hasTagName(iframeTag))
|
|
1565 |
? static_cast<HTMLFrameElementBase*>(m_dragTarget.get())->contentFrame() : 0;
|
|
1566 |
if (frame)
|
|
1567 |
frame->eventHandler()->cancelDragAndDrop(event, clipboard);
|
|
1568 |
else
|
|
1569 |
dispatchDragEvent(eventNames().dragleaveEvent, m_dragTarget.get(), event, clipboard);
|
|
1570 |
}
|
|
1571 |
clearDragState();
|
|
1572 |
}
|
|
1573 |
|
|
1574 |
bool EventHandler::performDragAndDrop(const PlatformMouseEvent& event, Clipboard* clipboard)
|
|
1575 |
{
|
|
1576 |
bool accept = false;
|
|
1577 |
if (m_dragTarget) {
|
|
1578 |
Frame* frame = (m_dragTarget->hasTagName(frameTag) || m_dragTarget->hasTagName(iframeTag))
|
|
1579 |
? static_cast<HTMLFrameElementBase*>(m_dragTarget.get())->contentFrame() : 0;
|
|
1580 |
if (frame)
|
|
1581 |
accept = frame->eventHandler()->performDragAndDrop(event, clipboard);
|
|
1582 |
else
|
|
1583 |
accept = dispatchDragEvent(eventNames().dropEvent, m_dragTarget.get(), event, clipboard);
|
|
1584 |
}
|
|
1585 |
clearDragState();
|
|
1586 |
return accept;
|
|
1587 |
}
|
|
1588 |
|
|
1589 |
void EventHandler::clearDragState()
|
|
1590 |
{
|
|
1591 |
m_dragTarget = 0;
|
|
1592 |
m_capturingMouseEventsNode = 0;
|
|
1593 |
#if PLATFORM(MAC)
|
|
1594 |
m_sendingEventToSubview = false;
|
|
1595 |
#endif
|
|
1596 |
}
|
|
1597 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
1598 |
|
|
1599 |
void EventHandler::setCapturingMouseEventsNode(PassRefPtr<Node> n)
|
|
1600 |
{
|
|
1601 |
m_capturingMouseEventsNode = n;
|
|
1602 |
}
|
|
1603 |
|
|
1604 |
MouseEventWithHitTestResults EventHandler::prepareMouseEvent(const HitTestRequest& request, const PlatformMouseEvent& mev)
|
|
1605 |
{
|
|
1606 |
ASSERT(m_frame);
|
|
1607 |
ASSERT(m_frame->document());
|
|
1608 |
|
|
1609 |
return m_frame->document()->prepareMouseEvent(request, documentPointForWindowPoint(m_frame, mev.pos()), mev);
|
|
1610 |
}
|
|
1611 |
|
|
1612 |
#if ENABLE(SVG)
|
|
1613 |
static inline SVGElementInstance* instanceAssociatedWithShadowTreeElement(Node* referenceNode)
|
|
1614 |
{
|
|
1615 |
if (!referenceNode || !referenceNode->isSVGElement())
|
|
1616 |
return 0;
|
|
1617 |
|
|
1618 |
Node* shadowTreeElement = referenceNode->shadowTreeRootNode();
|
|
1619 |
if (!shadowTreeElement)
|
|
1620 |
return 0;
|
|
1621 |
|
|
1622 |
Node* shadowTreeParentElement = shadowTreeElement->shadowParentNode();
|
|
1623 |
if (!shadowTreeParentElement)
|
|
1624 |
return 0;
|
|
1625 |
|
|
1626 |
ASSERT(shadowTreeParentElement->hasTagName(useTag));
|
|
1627 |
return static_cast<SVGUseElement*>(shadowTreeParentElement)->instanceForShadowTreeElement(referenceNode);
|
|
1628 |
}
|
|
1629 |
#endif
|
|
1630 |
|
|
1631 |
void EventHandler::updateMouseEventTargetNode(Node* targetNode, const PlatformMouseEvent& mouseEvent, bool fireMouseOverOut)
|
|
1632 |
{
|
|
1633 |
Node* result = targetNode;
|
|
1634 |
|
|
1635 |
// If we're capturing, we always go right to that node.
|
|
1636 |
if (m_capturingMouseEventsNode)
|
|
1637 |
result = m_capturingMouseEventsNode.get();
|
|
1638 |
else {
|
|
1639 |
// If the target node is a text node, dispatch on the parent node - rdar://4196646
|
|
1640 |
if (result && result->isTextNode())
|
|
1641 |
result = result->parentNode();
|
|
1642 |
if (result)
|
|
1643 |
result = result->shadowAncestorNode();
|
|
1644 |
}
|
|
1645 |
m_nodeUnderMouse = result;
|
|
1646 |
#if ENABLE(SVG)
|
|
1647 |
m_instanceUnderMouse = instanceAssociatedWithShadowTreeElement(result);
|
|
1648 |
|
|
1649 |
// <use> shadow tree elements may have been recloned, update node under mouse in any case
|
|
1650 |
if (m_lastInstanceUnderMouse) {
|
|
1651 |
SVGElement* lastCorrespondingElement = m_lastInstanceUnderMouse->correspondingElement();
|
|
1652 |
SVGElement* lastCorrespondingUseElement = m_lastInstanceUnderMouse->correspondingUseElement();
|
|
1653 |
|
|
1654 |
if (lastCorrespondingElement && lastCorrespondingUseElement) {
|
|
1655 |
HashSet<SVGElementInstance*> instances = lastCorrespondingElement->instancesForElement();
|
|
1656 |
|
|
1657 |
// Locate the recloned shadow tree element for our corresponding instance
|
|
1658 |
HashSet<SVGElementInstance*>::iterator end = instances.end();
|
|
1659 |
for (HashSet<SVGElementInstance*>::iterator it = instances.begin(); it != end; ++it) {
|
|
1660 |
SVGElementInstance* instance = (*it);
|
|
1661 |
ASSERT(instance->correspondingElement() == lastCorrespondingElement);
|
|
1662 |
|
|
1663 |
if (instance == m_lastInstanceUnderMouse)
|
|
1664 |
continue;
|
|
1665 |
|
|
1666 |
if (instance->correspondingUseElement() != lastCorrespondingUseElement)
|
|
1667 |
continue;
|
|
1668 |
|
|
1669 |
SVGElement* shadowTreeElement = instance->shadowTreeElement();
|
|
1670 |
if (!shadowTreeElement->inDocument() || m_lastNodeUnderMouse == shadowTreeElement)
|
|
1671 |
continue;
|
|
1672 |
|
|
1673 |
m_lastNodeUnderMouse = shadowTreeElement;
|
|
1674 |
m_lastInstanceUnderMouse = instance;
|
|
1675 |
break;
|
|
1676 |
}
|
|
1677 |
}
|
|
1678 |
}
|
|
1679 |
#endif
|
|
1680 |
|
|
1681 |
// Fire mouseout/mouseover if the mouse has shifted to a different node.
|
|
1682 |
if (fireMouseOverOut) {
|
|
1683 |
if (m_lastNodeUnderMouse && m_lastNodeUnderMouse->document() != m_frame->document()) {
|
|
1684 |
m_lastNodeUnderMouse = 0;
|
|
1685 |
m_lastScrollbarUnderMouse = 0;
|
|
1686 |
#if ENABLE(SVG)
|
|
1687 |
m_lastInstanceUnderMouse = 0;
|
|
1688 |
#endif
|
|
1689 |
}
|
|
1690 |
|
|
1691 |
if (m_lastNodeUnderMouse != m_nodeUnderMouse) {
|
|
1692 |
// send mouseout event to the old node
|
|
1693 |
if (m_lastNodeUnderMouse)
|
|
1694 |
m_lastNodeUnderMouse->dispatchMouseEvent(mouseEvent, eventNames().mouseoutEvent, 0, m_nodeUnderMouse.get());
|
|
1695 |
// send mouseover event to the new node
|
|
1696 |
if (m_nodeUnderMouse)
|
|
1697 |
m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventNames().mouseoverEvent, 0, m_lastNodeUnderMouse.get());
|
|
1698 |
}
|
|
1699 |
m_lastNodeUnderMouse = m_nodeUnderMouse;
|
|
1700 |
#if ENABLE(SVG)
|
|
1701 |
m_lastInstanceUnderMouse = instanceAssociatedWithShadowTreeElement(m_nodeUnderMouse.get());
|
|
1702 |
#endif
|
|
1703 |
}
|
|
1704 |
}
|
|
1705 |
|
|
1706 |
bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targetNode, bool /*cancelable*/, int clickCount, const PlatformMouseEvent& mouseEvent, bool setUnder)
|
|
1707 |
{
|
|
1708 |
if (FrameView* view = m_frame->view())
|
|
1709 |
view->resetDeferredRepaintDelay();
|
|
1710 |
|
|
1711 |
updateMouseEventTargetNode(targetNode, mouseEvent, setUnder);
|
|
1712 |
|
|
1713 |
bool swallowEvent = false;
|
|
1714 |
|
|
1715 |
if (m_nodeUnderMouse)
|
|
1716 |
swallowEvent = m_nodeUnderMouse->dispatchMouseEvent(mouseEvent, eventType, clickCount);
|
|
1717 |
|
|
1718 |
if (!swallowEvent && eventType == eventNames().mousedownEvent) {
|
|
1719 |
// The layout needs to be up to date to determine if an element is focusable.
|
|
1720 |
m_frame->document()->updateLayoutIgnorePendingStylesheets();
|
|
1721 |
|
|
1722 |
// Blur current focus node when a link/button is clicked; this
|
|
1723 |
// is expected by some sites that rely on onChange handlers running
|
|
1724 |
// from form fields before the button click is processed.
|
|
1725 |
Node* node = m_nodeUnderMouse.get();
|
|
1726 |
RenderObject* renderer = node ? node->renderer() : 0;
|
|
1727 |
|
|
1728 |
// Walk up the render tree to search for a node to focus.
|
|
1729 |
// Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields.
|
|
1730 |
while (renderer) {
|
|
1731 |
node = renderer->node();
|
|
1732 |
if (node && node->isFocusable()) {
|
|
1733 |
// To fix <rdar://problem/4895428> Can't drag selected ToDo, we don't focus a
|
|
1734 |
// node on mouse down if it's selected and inside a focused node. It will be
|
|
1735 |
// focused if the user does a mouseup over it, however, because the mouseup
|
|
1736 |
// will set a selection inside it, which will call setFocuseNodeIfNeeded.
|
|
1737 |
ExceptionCode ec = 0;
|
|
1738 |
Node* n = node->isShadowNode() ? node->shadowParentNode() : node;
|
|
1739 |
if (m_frame->selection()->isRange() &&
|
|
1740 |
m_frame->selection()->toNormalizedRange()->compareNode(n, ec) == Range::NODE_INSIDE &&
|
|
1741 |
n->isDescendantOf(m_frame->document()->focusedNode()))
|
|
1742 |
return false;
|
|
1743 |
|
|
1744 |
break;
|
|
1745 |
}
|
|
1746 |
|
|
1747 |
renderer = renderer->parent();
|
|
1748 |
}
|
|
1749 |
|
|
1750 |
// If focus shift is blocked, we eat the event. Note we should never clear swallowEvent
|
|
1751 |
// if the page already set it (e.g., by canceling default behavior).
|
|
1752 |
if (Page* page = m_frame->page()) {
|
|
1753 |
if (node && node->isMouseFocusable()) {
|
|
1754 |
if (!page->focusController()->setFocusedNode(node, m_frame))
|
|
1755 |
swallowEvent = true;
|
|
1756 |
} else if (!node || !node->focused()) {
|
|
1757 |
if (!page->focusController()->setFocusedNode(0, m_frame))
|
|
1758 |
swallowEvent = true;
|
|
1759 |
}
|
|
1760 |
}
|
|
1761 |
}
|
|
1762 |
|
|
1763 |
return swallowEvent;
|
|
1764 |
}
|
|
1765 |
|
|
1766 |
#if !PLATFORM(GTK)
|
|
1767 |
bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult&) const
|
|
1768 |
{
|
|
1769 |
return false;
|
|
1770 |
}
|
|
1771 |
#endif
|
|
1772 |
|
|
1773 |
bool EventHandler::handleWheelEvent(PlatformWheelEvent& e)
|
|
1774 |
{
|
|
1775 |
Document* doc = m_frame->document();
|
|
1776 |
|
|
1777 |
RenderObject* docRenderer = doc->renderer();
|
|
1778 |
if (!docRenderer)
|
|
1779 |
return false;
|
|
1780 |
|
|
1781 |
RefPtr<FrameView> protector(m_frame->view());
|
|
1782 |
|
|
1783 |
FrameView* view = m_frame->view();
|
|
1784 |
if (!view)
|
|
1785 |
return false;
|
|
1786 |
setFrameWasScrolledByUser();
|
|
1787 |
IntPoint vPoint = view->windowToContents(e.pos());
|
|
1788 |
|
|
1789 |
Node* node;
|
|
1790 |
bool isOverWidget;
|
|
1791 |
bool didSetLatchedNode = false;
|
|
1792 |
|
|
1793 |
HitTestRequest request(HitTestRequest::ReadOnly);
|
|
1794 |
HitTestResult result(vPoint);
|
|
1795 |
doc->renderView()->layer()->hitTest(request, result);
|
|
1796 |
|
|
1797 |
if (m_useLatchedWheelEventNode) {
|
|
1798 |
if (!m_latchedWheelEventNode) {
|
|
1799 |
m_latchedWheelEventNode = result.innerNode();
|
|
1800 |
m_widgetIsLatched = result.isOverWidget();
|
|
1801 |
didSetLatchedNode = true;
|
|
1802 |
}
|
|
1803 |
|
|
1804 |
node = m_latchedWheelEventNode.get();
|
|
1805 |
isOverWidget = m_widgetIsLatched;
|
|
1806 |
} else {
|
|
1807 |
if (m_latchedWheelEventNode)
|
|
1808 |
m_latchedWheelEventNode = 0;
|
|
1809 |
if (m_previousWheelScrolledNode)
|
|
1810 |
m_previousWheelScrolledNode = 0;
|
|
1811 |
|
|
1812 |
node = result.innerNode();
|
|
1813 |
isOverWidget = result.isOverWidget();
|
|
1814 |
}
|
|
1815 |
|
|
1816 |
if (shouldTurnVerticalTicksIntoHorizontal(result))
|
|
1817 |
e.turnVerticalTicksIntoHorizontal();
|
|
1818 |
|
|
1819 |
if (node) {
|
|
1820 |
// Figure out which view to send the event to.
|
|
1821 |
RenderObject* target = node->renderer();
|
|
1822 |
|
|
1823 |
if (isOverWidget && target && target->isWidget()) {
|
|
1824 |
Widget* widget = toRenderWidget(target)->widget();
|
|
1825 |
if (widget && passWheelEventToWidget(e, widget)) {
|
|
1826 |
e.accept();
|
|
1827 |
return true;
|
|
1828 |
}
|
|
1829 |
}
|
|
1830 |
|
|
1831 |
node = node->shadowAncestorNode();
|
|
1832 |
node->dispatchWheelEvent(e);
|
|
1833 |
if (e.isAccepted())
|
|
1834 |
return true;
|
|
1835 |
|
|
1836 |
// If we don't have a renderer, send the wheel event to the first node we find with a renderer.
|
|
1837 |
// This is needed for <option> and <optgroup> elements so that <select>s get a wheel scroll.
|
|
1838 |
while (node && !node->renderer())
|
|
1839 |
node = node->parent();
|
|
1840 |
|
|
1841 |
if (node && node->renderer()) {
|
|
1842 |
// Just break up into two scrolls if we need to. Diagonal movement on
|
|
1843 |
// a MacBook pro is an example of a 2-dimensional mouse wheel event (where both deltaX and deltaY can be set).
|
|
1844 |
Node* stopNode = m_previousWheelScrolledNode.get();
|
|
1845 |
scrollAndAcceptEvent(e.deltaX(), ScrollLeft, ScrollRight, e, node, &stopNode);
|
|
1846 |
scrollAndAcceptEvent(e.deltaY(), ScrollUp, ScrollDown, e, node, &stopNode);
|
|
1847 |
if (!m_useLatchedWheelEventNode)
|
|
1848 |
m_previousWheelScrolledNode = stopNode;
|
|
1849 |
}
|
|
1850 |
}
|
|
1851 |
|
|
1852 |
if (e.isAccepted())
|
|
1853 |
return true;
|
|
1854 |
|
|
1855 |
view = m_frame->view();
|
|
1856 |
if (!view)
|
|
1857 |
return false;
|
|
1858 |
|
|
1859 |
view->wheelEvent(e);
|
|
1860 |
return e.isAccepted();
|
|
1861 |
}
|
|
1862 |
|
|
1863 |
#if ENABLE(CONTEXT_MENUS)
|
|
1864 |
bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
|
|
1865 |
{
|
|
1866 |
Document* doc = m_frame->document();
|
|
1867 |
FrameView* v = m_frame->view();
|
|
1868 |
if (!v)
|
|
1869 |
return false;
|
|
1870 |
|
|
1871 |
bool swallowEvent;
|
|
1872 |
IntPoint viewportPos = v->windowToContents(event.pos());
|
|
1873 |
HitTestRequest request(HitTestRequest::Active);
|
|
1874 |
MouseEventWithHitTestResults mev = doc->prepareMouseEvent(request, viewportPos, event);
|
|
1875 |
|
|
1876 |
// Context menu events shouldn't select text in GTK+ applications or in Chromium.
|
|
1877 |
// FIXME: This should probably be configurable by embedders. Consider making it a WebPreferences setting.
|
|
1878 |
// See: https://bugs.webkit.org/show_bug.cgi?id=15279
|
|
1879 |
#if !PLATFORM(GTK) && !PLATFORM(CHROMIUM)
|
|
1880 |
if (!m_frame->selection()->contains(viewportPos) &&
|
|
1881 |
// FIXME: In the editable case, word selection sometimes selects content that isn't underneath the mouse.
|
|
1882 |
// If the selection is non-editable, we do word selection to make it easier to use the contextual menu items
|
|
1883 |
// available for text selections. But only if we're above text.
|
|
1884 |
(m_frame->selection()->isContentEditable() || (mev.targetNode() && mev.targetNode()->isTextNode()))) {
|
|
1885 |
m_mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
|
|
1886 |
selectClosestWordOrLinkFromMouseEvent(mev);
|
|
1887 |
}
|
|
1888 |
#endif
|
|
1889 |
|
|
1890 |
swallowEvent = dispatchMouseEvent(eventNames().contextmenuEvent, mev.targetNode(), true, 0, event, true);
|
|
1891 |
|
|
1892 |
return swallowEvent;
|
|
1893 |
}
|
|
1894 |
#endif // ENABLE(CONTEXT_MENUS)
|
|
1895 |
|
|
1896 |
void EventHandler::scheduleHoverStateUpdate()
|
|
1897 |
{
|
|
1898 |
if (!m_hoverTimer.isActive())
|
|
1899 |
m_hoverTimer.startOneShot(0);
|
|
1900 |
}
|
|
1901 |
|
|
1902 |
// Whether or not a mouse down can begin the creation of a selection. Fires the selectStart event.
|
|
1903 |
bool EventHandler::canMouseDownStartSelect(Node* node)
|
|
1904 |
{
|
|
1905 |
if (!node || !node->renderer())
|
|
1906 |
return true;
|
|
1907 |
|
|
1908 |
// Some controls and images can't start a select on a mouse down.
|
|
1909 |
if (!node->canStartSelection())
|
|
1910 |
return false;
|
|
1911 |
|
|
1912 |
for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) {
|
|
1913 |
if (Node* node = curr->node())
|
|
1914 |
return node->dispatchEvent(Event::create(eventNames().selectstartEvent, true, true));
|
|
1915 |
}
|
|
1916 |
|
|
1917 |
return true;
|
|
1918 |
}
|
|
1919 |
|
|
1920 |
#if ENABLE(DRAG_SUPPORT)
|
|
1921 |
bool EventHandler::canMouseDragExtendSelect(Node* node)
|
|
1922 |
{
|
|
1923 |
if (!node || !node->renderer())
|
|
1924 |
return true;
|
|
1925 |
|
|
1926 |
for (RenderObject* curr = node->renderer(); curr; curr = curr->parent()) {
|
|
1927 |
if (Node* node = curr->node())
|
|
1928 |
return node->dispatchEvent(Event::create(eventNames().selectstartEvent, true, true));
|
|
1929 |
}
|
|
1930 |
|
|
1931 |
return true;
|
|
1932 |
}
|
|
1933 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
1934 |
|
|
1935 |
void EventHandler::setResizingFrameSet(HTMLFrameSetElement* frameSet)
|
|
1936 |
{
|
|
1937 |
m_frameSetBeingResized = frameSet;
|
|
1938 |
}
|
|
1939 |
|
|
1940 |
void EventHandler::resizeLayerDestroyed()
|
|
1941 |
{
|
|
1942 |
ASSERT(m_resizeLayer);
|
|
1943 |
m_resizeLayer = 0;
|
|
1944 |
}
|
|
1945 |
|
|
1946 |
void EventHandler::hoverTimerFired(Timer<EventHandler>*)
|
|
1947 |
{
|
|
1948 |
m_hoverTimer.stop();
|
|
1949 |
|
|
1950 |
ASSERT(m_frame);
|
|
1951 |
ASSERT(m_frame->document());
|
|
1952 |
|
|
1953 |
if (RenderView* renderer = m_frame->contentRenderer()) {
|
|
1954 |
if (FrameView* view = m_frame->view()) {
|
|
1955 |
HitTestRequest request(HitTestRequest::MouseMove);
|
|
1956 |
HitTestResult result(view->windowToContents(m_currentMousePosition));
|
|
1957 |
renderer->layer()->hitTest(request, result);
|
|
1958 |
m_frame->document()->updateStyleIfNeeded();
|
|
1959 |
}
|
|
1960 |
}
|
|
1961 |
}
|
|
1962 |
|
|
1963 |
static Node* eventTargetNodeForDocument(Document* doc)
|
|
1964 |
{
|
|
1965 |
if (!doc)
|
|
1966 |
return 0;
|
|
1967 |
Node* node = doc->focusedNode();
|
|
1968 |
if (!node && doc->isHTMLDocument())
|
|
1969 |
node = doc->body();
|
|
1970 |
if (!node)
|
|
1971 |
node = doc->documentElement();
|
|
1972 |
return node;
|
|
1973 |
}
|
|
1974 |
|
|
1975 |
bool EventHandler::handleAccessKey(const PlatformKeyboardEvent& evt)
|
|
1976 |
{
|
|
1977 |
// FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do.
|
|
1978 |
// IE matches lower and upper case access keys regardless of Shift key state - but if both upper and
|
|
1979 |
// lower case variants are present in a document, the correct element is matched based on Shift key state.
|
|
1980 |
// Firefox only matches an access key if Shift is not pressed, and does that case-insensitively.
|
|
1981 |
ASSERT(!(accessKeyModifiers() & PlatformKeyboardEvent::ShiftKey));
|
|
1982 |
if ((evt.modifiers() & ~PlatformKeyboardEvent::ShiftKey) != accessKeyModifiers())
|
|
1983 |
return false;
|
|
1984 |
String key = evt.unmodifiedText();
|
|
1985 |
Element* elem = m_frame->document()->getElementByAccessKey(key.lower());
|
|
1986 |
if (!elem)
|
|
1987 |
return false;
|
|
1988 |
elem->accessKeyAction(false);
|
|
1989 |
return true;
|
|
1990 |
}
|
|
1991 |
|
|
1992 |
#if !PLATFORM(MAC)
|
|
1993 |
bool EventHandler::needsKeyboardEventDisambiguationQuirks() const
|
|
1994 |
{
|
|
1995 |
return false;
|
|
1996 |
}
|
|
1997 |
#endif
|
|
1998 |
|
|
1999 |
bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent)
|
|
2000 |
{
|
|
2001 |
#if ENABLE(PAN_SCROLLING)
|
|
2002 |
if (Page* page = m_frame->page()) {
|
|
2003 |
if (page->mainFrame()->eventHandler()->panScrollInProgress() || m_autoscrollInProgress) {
|
|
2004 |
// If a key is pressed while the autoscroll/panScroll is in progress then we want to stop
|
|
2005 |
if (initialKeyEvent.type() == PlatformKeyboardEvent::KeyDown || initialKeyEvent.type() == PlatformKeyboardEvent::RawKeyDown)
|
|
2006 |
stopAutoscrollTimer();
|
|
2007 |
|
|
2008 |
// If we were in autoscroll/panscroll mode, we swallow the key event
|
|
2009 |
return true;
|
|
2010 |
}
|
|
2011 |
}
|
|
2012 |
#endif
|
|
2013 |
|
|
2014 |
// Check for cases where we are too early for events -- possible unmatched key up
|
|
2015 |
// from pressing return in the location bar.
|
|
2016 |
RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document());
|
|
2017 |
if (!node)
|
|
2018 |
return false;
|
|
2019 |
|
|
2020 |
if (FrameView* view = m_frame->view())
|
|
2021 |
view->resetDeferredRepaintDelay();
|
|
2022 |
|
|
2023 |
// FIXME: what is this doing here, in keyboard event handler?
|
|
2024 |
m_frame->loader()->resetMultipleFormSubmissionProtection();
|
|
2025 |
|
|
2026 |
// In IE, access keys are special, they are handled after default keydown processing, but cannot be canceled - this is hard to match.
|
|
2027 |
// On Mac OS X, we process them before dispatching keydown, as the default keydown handler implements Emacs key bindings, which may conflict
|
|
2028 |
// with access keys. Then we dispatch keydown, but suppress its default handling.
|
|
2029 |
// On Windows, WebKit explicitly calls handleAccessKey() instead of dispatching a keypress event for WM_SYSCHAR messages.
|
|
2030 |
// Other platforms currently match either Mac or Windows behavior, depending on whether they send combined KeyDown events.
|
|
2031 |
bool matchedAnAccessKey = false;
|
|
2032 |
if (initialKeyEvent.type() == PlatformKeyboardEvent::KeyDown)
|
|
2033 |
matchedAnAccessKey = handleAccessKey(initialKeyEvent);
|
|
2034 |
|
|
2035 |
// FIXME: it would be fair to let an input method handle KeyUp events before DOM dispatch.
|
|
2036 |
if (initialKeyEvent.type() == PlatformKeyboardEvent::KeyUp || initialKeyEvent.type() == PlatformKeyboardEvent::Char)
|
|
2037 |
return !node->dispatchKeyEvent(initialKeyEvent);
|
|
2038 |
|
|
2039 |
bool backwardCompatibilityMode = needsKeyboardEventDisambiguationQuirks();
|
|
2040 |
|
|
2041 |
ExceptionCode ec;
|
|
2042 |
PlatformKeyboardEvent keyDownEvent = initialKeyEvent;
|
|
2043 |
if (keyDownEvent.type() != PlatformKeyboardEvent::RawKeyDown)
|
|
2044 |
keyDownEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown, backwardCompatibilityMode);
|
|
2045 |
RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame->document()->defaultView());
|
|
2046 |
if (matchedAnAccessKey)
|
|
2047 |
keydown->setDefaultPrevented(true);
|
|
2048 |
keydown->setTarget(node);
|
|
2049 |
|
|
2050 |
if (initialKeyEvent.type() == PlatformKeyboardEvent::RawKeyDown) {
|
|
2051 |
node->dispatchEvent(keydown, ec);
|
|
2052 |
return keydown->defaultHandled() || keydown->defaultPrevented();
|
|
2053 |
}
|
|
2054 |
|
|
2055 |
// Run input method in advance of DOM event handling. This may result in the IM
|
|
2056 |
// modifying the page prior the keydown event, but this behaviour is necessary
|
|
2057 |
// in order to match IE:
|
|
2058 |
// 1. preventing default handling of keydown and keypress events has no effect on IM input;
|
|
2059 |
// 2. if an input method handles the event, its keyCode is set to 229 in keydown event.
|
|
2060 |
m_frame->editor()->handleInputMethodKeydown(keydown.get());
|
|
2061 |
|
|
2062 |
bool handledByInputMethod = keydown->defaultHandled();
|
|
2063 |
|
|
2064 |
if (handledByInputMethod) {
|
|
2065 |
keyDownEvent.setWindowsVirtualKeyCode(CompositionEventKeyCode);
|
|
2066 |
keydown = KeyboardEvent::create(keyDownEvent, m_frame->document()->defaultView());
|
|
2067 |
keydown->setTarget(node);
|
|
2068 |
keydown->setDefaultHandled();
|
|
2069 |
}
|
|
2070 |
|
|
2071 |
node->dispatchEvent(keydown, ec);
|
|
2072 |
bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented();
|
|
2073 |
if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode))
|
|
2074 |
return keydownResult;
|
|
2075 |
|
|
2076 |
// Focus may have changed during keydown handling, so refetch node.
|
|
2077 |
// But if we are dispatching a fake backward compatibility keypress, then we pretend that the keypress happened on the original node.
|
|
2078 |
if (!keydownResult) {
|
|
2079 |
node = eventTargetNodeForDocument(m_frame->document());
|
|
2080 |
if (!node)
|
|
2081 |
return false;
|
|
2082 |
}
|
|
2083 |
|
|
2084 |
PlatformKeyboardEvent keyPressEvent = initialKeyEvent;
|
|
2085 |
keyPressEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::Char, backwardCompatibilityMode);
|
|
2086 |
if (keyPressEvent.text().isEmpty())
|
|
2087 |
return keydownResult;
|
|
2088 |
RefPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressEvent, m_frame->document()->defaultView());
|
|
2089 |
keypress->setTarget(node);
|
|
2090 |
if (keydownResult)
|
|
2091 |
keypress->setDefaultPrevented(true);
|
|
2092 |
#if PLATFORM(MAC)
|
|
2093 |
keypress->keypressCommands() = keydown->keypressCommands();
|
|
2094 |
#endif
|
|
2095 |
node->dispatchEvent(keypress, ec);
|
|
2096 |
|
|
2097 |
return keydownResult || keypress->defaultPrevented() || keypress->defaultHandled();
|
|
2098 |
}
|
|
2099 |
|
|
2100 |
void EventHandler::handleKeyboardSelectionMovement(KeyboardEvent* event)
|
|
2101 |
{
|
|
2102 |
if (!event)
|
|
2103 |
return;
|
|
2104 |
|
|
2105 |
String key = event->keyIdentifier();
|
|
2106 |
bool isShifted = event->getModifierState("Shift");
|
|
2107 |
bool isOptioned = event->getModifierState("Alt");
|
|
2108 |
bool isCommanded = event->getModifierState("Meta");
|
|
2109 |
|
|
2110 |
if (key == "Up") {
|
|
2111 |
m_frame->selection()->modify((isShifted) ? SelectionController::EXTEND : SelectionController::MOVE, SelectionController::BACKWARD, (isCommanded) ? DocumentBoundary : LineGranularity, true);
|
|
2112 |
event->setDefaultHandled();
|
|
2113 |
}
|
|
2114 |
else if (key == "Down") {
|
|
2115 |
m_frame->selection()->modify((isShifted) ? SelectionController::EXTEND : SelectionController::MOVE, SelectionController::FORWARD, (isCommanded) ? DocumentBoundary : LineGranularity, true);
|
|
2116 |
event->setDefaultHandled();
|
|
2117 |
}
|
|
2118 |
else if (key == "Left") {
|
|
2119 |
m_frame->selection()->modify((isShifted) ? SelectionController::EXTEND : SelectionController::MOVE, SelectionController::LEFT, (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity, true);
|
|
2120 |
event->setDefaultHandled();
|
|
2121 |
}
|
|
2122 |
else if (key == "Right") {
|
|
2123 |
m_frame->selection()->modify((isShifted) ? SelectionController::EXTEND : SelectionController::MOVE, SelectionController::RIGHT, (isCommanded) ? LineBoundary : (isOptioned) ? WordGranularity : CharacterGranularity, true);
|
|
2124 |
event->setDefaultHandled();
|
|
2125 |
}
|
|
2126 |
}
|
|
2127 |
|
|
2128 |
void EventHandler::defaultKeyboardEventHandler(KeyboardEvent* event)
|
|
2129 |
{
|
|
2130 |
if (event->type() == eventNames().keydownEvent) {
|
|
2131 |
m_frame->editor()->handleKeyboardEvent(event);
|
|
2132 |
if (event->defaultHandled())
|
|
2133 |
return;
|
|
2134 |
if (event->keyIdentifier() == "U+0009")
|
|
2135 |
defaultTabEventHandler(event);
|
|
2136 |
|
|
2137 |
// provides KB navigation and selection for enhanced accessibility users
|
|
2138 |
if (AXObjectCache::accessibilityEnhancedUserInterfaceEnabled())
|
|
2139 |
handleKeyboardSelectionMovement(event);
|
|
2140 |
}
|
|
2141 |
if (event->type() == eventNames().keypressEvent) {
|
|
2142 |
m_frame->editor()->handleKeyboardEvent(event);
|
|
2143 |
if (event->defaultHandled())
|
|
2144 |
return;
|
|
2145 |
if (event->charCode() == ' ')
|
|
2146 |
defaultSpaceEventHandler(event);
|
|
2147 |
}
|
|
2148 |
}
|
|
2149 |
|
|
2150 |
#if ENABLE(DRAG_SUPPORT)
|
|
2151 |
bool EventHandler::dragHysteresisExceeded(const FloatPoint& floatDragViewportLocation) const
|
|
2152 |
{
|
|
2153 |
IntPoint dragViewportLocation((int)floatDragViewportLocation.x(), (int)floatDragViewportLocation.y());
|
|
2154 |
return dragHysteresisExceeded(dragViewportLocation);
|
|
2155 |
}
|
|
2156 |
|
|
2157 |
bool EventHandler::dragHysteresisExceeded(const IntPoint& dragViewportLocation) const
|
|
2158 |
{
|
|
2159 |
FrameView* view = m_frame->view();
|
|
2160 |
if (!view)
|
|
2161 |
return false;
|
|
2162 |
IntPoint dragLocation = view->windowToContents(dragViewportLocation);
|
|
2163 |
IntSize delta = dragLocation - m_mouseDownPos;
|
|
2164 |
|
|
2165 |
int threshold = GeneralDragHysteresis;
|
|
2166 |
if (dragState().m_dragSrcIsImage)
|
|
2167 |
threshold = ImageDragHysteresis;
|
|
2168 |
else if (dragState().m_dragSrcIsLink)
|
|
2169 |
threshold = LinkDragHysteresis;
|
|
2170 |
else if (dragState().m_dragSrcInSelection)
|
|
2171 |
threshold = TextDragHysteresis;
|
|
2172 |
|
|
2173 |
return abs(delta.width()) >= threshold || abs(delta.height()) >= threshold;
|
|
2174 |
}
|
|
2175 |
|
|
2176 |
void EventHandler::freeClipboard()
|
|
2177 |
{
|
|
2178 |
if (dragState().m_dragClipboard)
|
|
2179 |
dragState().m_dragClipboard->setAccessPolicy(ClipboardNumb);
|
|
2180 |
}
|
|
2181 |
|
|
2182 |
bool EventHandler::shouldDragAutoNode(Node* node, const IntPoint& point) const
|
|
2183 |
{
|
|
2184 |
if (!node || !m_frame->view())
|
|
2185 |
return false;
|
|
2186 |
Page* page = m_frame->page();
|
|
2187 |
return page && page->dragController()->mayStartDragAtEventLocation(m_frame, point);
|
|
2188 |
}
|
|
2189 |
|
|
2190 |
void EventHandler::dragSourceMovedTo(const PlatformMouseEvent& event)
|
|
2191 |
{
|
|
2192 |
if (dragState().m_dragSrc && dragState().m_dragSrcMayBeDHTML)
|
|
2193 |
// for now we don't care if event handler cancels default behavior, since there is none
|
|
2194 |
dispatchDragSrcEvent(eventNames().dragEvent, event);
|
|
2195 |
}
|
|
2196 |
|
|
2197 |
void EventHandler::dragSourceEndedAt(const PlatformMouseEvent& event, DragOperation operation)
|
|
2198 |
{
|
|
2199 |
if (dragState().m_dragSrc && dragState().m_dragSrcMayBeDHTML) {
|
|
2200 |
dragState().m_dragClipboard->setDestinationOperation(operation);
|
|
2201 |
// for now we don't care if event handler cancels default behavior, since there is none
|
|
2202 |
dispatchDragSrcEvent(eventNames().dragendEvent, event);
|
|
2203 |
}
|
|
2204 |
freeClipboard();
|
|
2205 |
dragState().m_dragSrc = 0;
|
|
2206 |
// In case the drag was ended due to an escape key press we need to ensure
|
|
2207 |
// that consecutive mousemove events don't reinitiate the drag and drop.
|
|
2208 |
m_mouseDownMayStartDrag = false;
|
|
2209 |
}
|
|
2210 |
|
|
2211 |
// returns if we should continue "default processing", i.e., whether eventhandler canceled
|
|
2212 |
bool EventHandler::dispatchDragSrcEvent(const AtomicString& eventType, const PlatformMouseEvent& event)
|
|
2213 |
{
|
|
2214 |
return !dispatchDragEvent(eventType, dragState().m_dragSrc.get(), event, dragState().m_dragClipboard.get());
|
|
2215 |
}
|
|
2216 |
|
|
2217 |
bool EventHandler::handleDrag(const MouseEventWithHitTestResults& event)
|
|
2218 |
{
|
|
2219 |
if (event.event().button() != LeftButton || event.event().eventType() != MouseEventMoved) {
|
|
2220 |
// If we allowed the other side of the bridge to handle a drag
|
|
2221 |
// last time, then m_mousePressed might still be set. So we
|
|
2222 |
// clear it now to make sure the next move after a drag
|
|
2223 |
// doesn't look like a drag.
|
|
2224 |
m_mousePressed = false;
|
|
2225 |
return false;
|
|
2226 |
}
|
|
2227 |
|
|
2228 |
if (eventLoopHandleMouseDragged(event))
|
|
2229 |
return true;
|
|
2230 |
|
|
2231 |
// Careful that the drag starting logic stays in sync with eventMayStartDrag()
|
|
2232 |
|
|
2233 |
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
|
|
2234 |
allowDHTMLDrag(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA);
|
|
2235 |
if (!dragState().m_dragSrcMayBeDHTML && !dragState().m_dragSrcMayBeUA)
|
|
2236 |
m_mouseDownMayStartDrag = false; // no element is draggable
|
|
2237 |
}
|
|
2238 |
|
|
2239 |
if (m_mouseDownMayStartDrag && !dragState().m_dragSrc) {
|
|
2240 |
// try to find an element that wants to be dragged
|
|
2241 |
HitTestRequest request(HitTestRequest::ReadOnly);
|
|
2242 |
HitTestResult result(m_mouseDownPos);
|
|
2243 |
m_frame->contentRenderer()->layer()->hitTest(request, result);
|
|
2244 |
Node* node = result.innerNode();
|
|
2245 |
if (node && node->renderer())
|
|
2246 |
dragState().m_dragSrc = node->renderer()->draggableNode(dragState().m_dragSrcMayBeDHTML, dragState().m_dragSrcMayBeUA,
|
|
2247 |
m_mouseDownPos.x(), m_mouseDownPos.y(), dragState().m_dragSrcIsDHTML);
|
|
2248 |
else
|
|
2249 |
dragState().m_dragSrc = 0;
|
|
2250 |
|
|
2251 |
if (!dragState().m_dragSrc)
|
|
2252 |
m_mouseDownMayStartDrag = false; // no element is draggable
|
|
2253 |
else {
|
|
2254 |
// remember some facts about this source, while we have a HitTestResult handy
|
|
2255 |
node = result.URLElement();
|
|
2256 |
dragState().m_dragSrcIsLink = node && node->isLink();
|
|
2257 |
|
|
2258 |
node = result.innerNonSharedNode();
|
|
2259 |
dragState().m_dragSrcIsImage = node && node->renderer() && node->renderer()->isImage();
|
|
2260 |
|
|
2261 |
dragState().m_dragSrcInSelection = m_frame->selection()->contains(m_mouseDownPos);
|
|
2262 |
}
|
|
2263 |
}
|
|
2264 |
|
|
2265 |
// For drags starting in the selection, the user must wait between the mousedown and mousedrag,
|
|
2266 |
// or else we bail on the dragging stuff and allow selection to occur
|
|
2267 |
if (m_mouseDownMayStartDrag && !dragState().m_dragSrcIsImage && dragState().m_dragSrcInSelection && event.event().timestamp() - m_mouseDownTimestamp < TextDragDelay) {
|
|
2268 |
m_mouseDownMayStartDrag = false;
|
|
2269 |
dragState().m_dragSrc = 0;
|
|
2270 |
// ...but if this was the first click in the window, we don't even want to start selection
|
|
2271 |
if (eventActivatedView(event.event()))
|
|
2272 |
m_mouseDownMayStartSelect = false;
|
|
2273 |
}
|
|
2274 |
|
|
2275 |
if (!m_mouseDownMayStartDrag)
|
|
2276 |
return !mouseDownMayStartSelect() && !m_mouseDownMayStartAutoscroll;
|
|
2277 |
|
|
2278 |
// We are starting a text/image/url drag, so the cursor should be an arrow
|
|
2279 |
if (FrameView* view = m_frame->view())
|
|
2280 |
view->setCursor(pointerCursor());
|
|
2281 |
|
|
2282 |
if (!dragHysteresisExceeded(event.event().pos()))
|
|
2283 |
return true;
|
|
2284 |
|
|
2285 |
// Once we're past the hysteresis point, we don't want to treat this gesture as a click
|
|
2286 |
invalidateClick();
|
|
2287 |
|
|
2288 |
DragOperation srcOp = DragOperationNone;
|
|
2289 |
|
|
2290 |
freeClipboard(); // would only happen if we missed a dragEnd. Do it anyway, just
|
|
2291 |
// to make sure it gets numbified
|
|
2292 |
dragState().m_dragClipboard = createDraggingClipboard();
|
|
2293 |
|
|
2294 |
if (dragState().m_dragSrcMayBeDHTML) {
|
|
2295 |
// Check to see if the is a DOM based drag, if it is get the DOM specified drag
|
|
2296 |
// image and offset
|
|
2297 |
if (dragState().m_dragSrcIsDHTML) {
|
|
2298 |
if (RenderObject* renderer = dragState().m_dragSrc->renderer()) {
|
|
2299 |
// FIXME: This doesn't work correctly with transforms.
|
|
2300 |
FloatPoint absPos = renderer->localToAbsolute();
|
|
2301 |
IntSize delta = m_mouseDownPos - roundedIntPoint(absPos);
|
|
2302 |
dragState().m_dragClipboard->setDragImageElement(dragState().m_dragSrc.get(), IntPoint() + delta);
|
|
2303 |
} else {
|
|
2304 |
// The renderer has disappeared, this can happen if the onStartDrag handler has hidden
|
|
2305 |
// the element in some way. In this case we just kill the drag.
|
|
2306 |
m_mouseDownMayStartDrag = false;
|
|
2307 |
goto cleanupDrag;
|
|
2308 |
}
|
|
2309 |
}
|
|
2310 |
|
|
2311 |
m_mouseDownMayStartDrag = dispatchDragSrcEvent(eventNames().dragstartEvent, m_mouseDown)
|
|
2312 |
&& !m_frame->selection()->isInPasswordField();
|
|
2313 |
|
|
2314 |
// Invalidate clipboard here against anymore pasteboard writing for security. The drag
|
|
2315 |
// image can still be changed as we drag, but not the pasteboard data.
|
|
2316 |
dragState().m_dragClipboard->setAccessPolicy(ClipboardImageWritable);
|
|
2317 |
|
|
2318 |
if (m_mouseDownMayStartDrag) {
|
|
2319 |
// gather values from DHTML element, if it set any
|
|
2320 |
dragState().m_dragClipboard->sourceOperation(srcOp);
|
|
2321 |
|
|
2322 |
// Yuck, dragSourceMovedTo() can be called as a result of kicking off the drag with
|
|
2323 |
// dragImage! Because of that dumb reentrancy, we may think we've not started the
|
|
2324 |
// drag when that happens. So we have to assume it's started before we kick it off.
|
|
2325 |
dragState().m_dragClipboard->setDragHasStarted();
|
|
2326 |
}
|
|
2327 |
}
|
|
2328 |
|
|
2329 |
if (m_mouseDownMayStartDrag) {
|
|
2330 |
Page* page = m_frame->page();
|
|
2331 |
DragController* dragController = page ? page->dragController() : 0;
|
|
2332 |
bool startedDrag = dragController && dragController->startDrag(m_frame, dragState().m_dragClipboard.get(), srcOp, event.event(), m_mouseDownPos, dragState().m_dragSrcIsDHTML);
|
|
2333 |
if (!startedDrag && dragState().m_dragSrcMayBeDHTML) {
|
|
2334 |
// Drag was canned at the last minute - we owe m_dragSrc a DRAGEND event
|
|
2335 |
dispatchDragSrcEvent(eventNames().dragendEvent, event.event());
|
|
2336 |
m_mouseDownMayStartDrag = false;
|
|
2337 |
}
|
|
2338 |
}
|
|
2339 |
|
|
2340 |
cleanupDrag:
|
|
2341 |
if (!m_mouseDownMayStartDrag) {
|
|
2342 |
// something failed to start the drag, cleanup
|
|
2343 |
freeClipboard();
|
|
2344 |
dragState().m_dragSrc = 0;
|
|
2345 |
}
|
|
2346 |
|
|
2347 |
// No more default handling (like selection), whether we're past the hysteresis bounds or not
|
|
2348 |
return true;
|
|
2349 |
}
|
|
2350 |
#endif // ENABLE(DRAG_SUPPORT)
|
|
2351 |
|
|
2352 |
bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent, bool isLineBreak, bool isBackTab)
|
|
2353 |
{
|
|
2354 |
// Platforms should differentiate real commands like selectAll from text input in disguise (like insertNewline),
|
|
2355 |
// and avoid dispatching text input events from keydown default handlers.
|
|
2356 |
ASSERT(!underlyingEvent || !underlyingEvent->isKeyboardEvent() || static_cast<KeyboardEvent*>(underlyingEvent)->type() == eventNames().keypressEvent);
|
|
2357 |
|
|
2358 |
if (!m_frame)
|
|
2359 |
return false;
|
|
2360 |
|
|
2361 |
EventTarget* target;
|
|
2362 |
if (underlyingEvent)
|
|
2363 |
target = underlyingEvent->target();
|
|
2364 |
else
|
|
2365 |
target = eventTargetNodeForDocument(m_frame->document());
|
|
2366 |
if (!target)
|
|
2367 |
return false;
|
|
2368 |
|
|
2369 |
if (FrameView* view = m_frame->view())
|
|
2370 |
view->resetDeferredRepaintDelay();
|
|
2371 |
|
|
2372 |
RefPtr<TextEvent> event = TextEvent::create(m_frame->domWindow(), text);
|
|
2373 |
event->setUnderlyingEvent(underlyingEvent);
|
|
2374 |
event->setIsLineBreak(isLineBreak);
|
|
2375 |
event->setIsBackTab(isBackTab);
|
|
2376 |
ExceptionCode ec;
|
|
2377 |
target->dispatchEvent(event, ec);
|
|
2378 |
return event->defaultHandled();
|
|
2379 |
}
|
|
2380 |
|
|
2381 |
|
|
2382 |
#if !PLATFORM(MAC) && !PLATFORM(QT) && !PLATFORM(HAIKU)
|
|
2383 |
bool EventHandler::invertSenseOfTabsToLinks(KeyboardEvent*) const
|
|
2384 |
{
|
|
2385 |
return false;
|
|
2386 |
}
|
|
2387 |
#endif
|
|
2388 |
|
|
2389 |
bool EventHandler::tabsToLinks(KeyboardEvent* event) const
|
|
2390 |
{
|
|
2391 |
Page* page = m_frame->page();
|
|
2392 |
if (!page)
|
|
2393 |
return false;
|
|
2394 |
|
|
2395 |
if (page->chrome()->client()->tabsToLinks())
|
|
2396 |
return !invertSenseOfTabsToLinks(event);
|
|
2397 |
|
|
2398 |
return invertSenseOfTabsToLinks(event);
|
|
2399 |
}
|
|
2400 |
|
|
2401 |
void EventHandler::defaultTextInputEventHandler(TextEvent* event)
|
|
2402 |
{
|
|
2403 |
String data = event->data();
|
|
2404 |
if (data == "\n") {
|
|
2405 |
if (event->isLineBreak()) {
|
|
2406 |
if (m_frame->editor()->insertLineBreak())
|
|
2407 |
event->setDefaultHandled();
|
|
2408 |
} else {
|
|
2409 |
if (m_frame->editor()->insertParagraphSeparator())
|
|
2410 |
event->setDefaultHandled();
|
|
2411 |
}
|
|
2412 |
} else {
|
|
2413 |
if (m_frame->editor()->insertTextWithoutSendingTextEvent(data, false, event))
|
|
2414 |
event->setDefaultHandled();
|
|
2415 |
}
|
|
2416 |
}
|
|
2417 |
|
|
2418 |
#if PLATFORM(QT) || PLATFORM(MAC)
|
|
2419 |
|
|
2420 |
// These two platforms handle the space event in the platform-specific WebKit code.
|
|
2421 |
// Eventually it would be good to eliminate that and use the code here instead, but
|
|
2422 |
// the Qt version is inside an ifdef and the Mac version has some extra behavior
|
|
2423 |
// so we can't unify everything yet.
|
|
2424 |
void EventHandler::defaultSpaceEventHandler(KeyboardEvent*)
|
|
2425 |
{
|
|
2426 |
}
|
|
2427 |
|
|
2428 |
#else
|
|
2429 |
|
|
2430 |
void EventHandler::defaultSpaceEventHandler(KeyboardEvent* event)
|
|
2431 |
{
|
|
2432 |
ScrollDirection direction = event->shiftKey() ? ScrollUp : ScrollDown;
|
|
2433 |
if (scrollOverflow(direction, ScrollByPage)) {
|
|
2434 |
event->setDefaultHandled();
|
|
2435 |
return;
|
|
2436 |
}
|
|
2437 |
|
|
2438 |
FrameView* view = m_frame->view();
|
|
2439 |
if (!view)
|
|
2440 |
return;
|
|
2441 |
|
|
2442 |
if (view->scroll(direction, ScrollByPage))
|
|
2443 |
event->setDefaultHandled();
|
|
2444 |
}
|
|
2445 |
|
|
2446 |
#endif
|
|
2447 |
|
|
2448 |
void EventHandler::defaultTabEventHandler(KeyboardEvent* event)
|
|
2449 |
{
|
|
2450 |
// We should only advance focus on tabs if no special modifier keys are held down.
|
|
2451 |
if (event->ctrlKey() || event->metaKey() || event->altGraphKey())
|
|
2452 |
return;
|
|
2453 |
|
|
2454 |
Page* page = m_frame->page();
|
|
2455 |
if (!page)
|
|
2456 |
return;
|
|
2457 |
if (!page->tabKeyCyclesThroughElements())
|
|
2458 |
return;
|
|
2459 |
|
|
2460 |
FocusDirection focusDirection = event->shiftKey() ? FocusDirectionBackward : FocusDirectionForward;
|
|
2461 |
|
|
2462 |
// Tabs can be used in design mode editing.
|
|
2463 |
if (m_frame->document()->inDesignMode())
|
|
2464 |
return;
|
|
2465 |
|
|
2466 |
if (page->focusController()->advanceFocus(focusDirection, event))
|
|
2467 |
event->setDefaultHandled();
|
|
2468 |
}
|
|
2469 |
|
|
2470 |
void EventHandler::capsLockStateMayHaveChanged()
|
|
2471 |
{
|
|
2472 |
Document* d = m_frame->document();
|
|
2473 |
if (Node* node = d->focusedNode()) {
|
|
2474 |
if (RenderObject* r = node->renderer()) {
|
|
2475 |
if (r->isTextField())
|
|
2476 |
toRenderTextControlSingleLine(r)->capsLockStateMayHaveChanged();
|
|
2477 |
}
|
|
2478 |
}
|
|
2479 |
}
|
|
2480 |
|
|
2481 |
void EventHandler::sendResizeEvent()
|
|
2482 |
{
|
|
2483 |
m_frame->document()->dispatchWindowEvent(Event::create(eventNames().resizeEvent, false, false));
|
|
2484 |
}
|
|
2485 |
|
|
2486 |
void EventHandler::sendScrollEvent()
|
|
2487 |
{
|
|
2488 |
setFrameWasScrolledByUser();
|
|
2489 |
if (m_frame->view())
|
|
2490 |
m_frame->document()->dispatchEvent(Event::create(eventNames().scrollEvent, true, false));
|
|
2491 |
}
|
|
2492 |
|
|
2493 |
void EventHandler::setFrameWasScrolledByUser()
|
|
2494 |
{
|
|
2495 |
FrameView* v = m_frame->view();
|
|
2496 |
if (v)
|
|
2497 |
v->setWasScrolledByUser(true);
|
|
2498 |
}
|
|
2499 |
|
|
2500 |
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mev, Scrollbar* scrollbar)
|
|
2501 |
{
|
|
2502 |
if (!scrollbar || !scrollbar->enabled())
|
|
2503 |
return false;
|
|
2504 |
setFrameWasScrolledByUser();
|
|
2505 |
return scrollbar->mouseDown(mev.event());
|
|
2506 |
}
|
|
2507 |
|
|
2508 |
// If scrollbar (under mouse) is different from last, send a mouse exited. Set
|
|
2509 |
// last to scrollbar if setLast is true; else set last to 0.
|
|
2510 |
void EventHandler::updateLastScrollbarUnderMouse(Scrollbar* scrollbar, bool setLast)
|
|
2511 |
{
|
|
2512 |
if (m_lastScrollbarUnderMouse != scrollbar) {
|
|
2513 |
// Send mouse exited to the old scrollbar.
|
|
2514 |
if (m_lastScrollbarUnderMouse)
|
|
2515 |
m_lastScrollbarUnderMouse->mouseExited();
|
|
2516 |
m_lastScrollbarUnderMouse = setLast ? scrollbar : 0;
|
|
2517 |
}
|
|
2518 |
}
|
|
2519 |
|
|
2520 |
}
|