author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 0 | 1918ee327afb |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (C) 2007, 2009 Apple Inc. All rights reserved. |
|
3 |
* |
|
4 |
* Redistribution and use in source and binary forms, with or without |
|
5 |
* modification, are permitted provided that the following conditions |
|
6 |
* are met: |
|
7 |
* 1. Redistributions of source code must retain the above copyright |
|
8 |
* notice, this list of conditions and the following disclaimer. |
|
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
|
10 |
* notice, this list of conditions and the following disclaimer in the |
|
11 |
* documentation and/or other materials provided with the distribution. |
|
12 |
* |
|
13 |
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 |
*/ |
|
25 |
||
26 |
#include "config.h" |
|
27 |
#include "DragController.h" |
|
28 |
||
29 |
#if ENABLE(DRAG_SUPPORT) |
|
30 |
#include "CSSStyleDeclaration.h" |
|
31 |
#include "Clipboard.h" |
|
32 |
#include "ClipboardAccessPolicy.h" |
|
33 |
#include "DocLoader.h" |
|
34 |
#include "Document.h" |
|
35 |
#include "DocumentFragment.h" |
|
36 |
#include "DragActions.h" |
|
37 |
#include "DragClient.h" |
|
38 |
#include "DragData.h" |
|
39 |
#include "Editor.h" |
|
40 |
#include "EditorClient.h" |
|
41 |
#include "Element.h" |
|
42 |
#include "EventHandler.h" |
|
43 |
#include "FloatRect.h" |
|
44 |
#include "Frame.h" |
|
45 |
#include "FrameLoader.h" |
|
46 |
#include "FrameView.h" |
|
47 |
#include "HTMLAnchorElement.h" |
|
48 |
#include "HTMLInputElement.h" |
|
49 |
#include "HTMLNames.h" |
|
50 |
#include "HitTestRequest.h" |
|
51 |
#include "HitTestResult.h" |
|
52 |
#include "Image.h" |
|
53 |
#include "MoveSelectionCommand.h" |
|
54 |
#include "Node.h" |
|
55 |
#include "Page.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
56 |
#include "PlatformKeyboardEvent.h" |
0 | 57 |
#include "RenderFileUploadControl.h" |
58 |
#include "RenderImage.h" |
|
59 |
#include "RenderView.h" |
|
60 |
#include "ReplaceSelectionCommand.h" |
|
61 |
#include "ResourceRequest.h" |
|
62 |
#include "SelectionController.h" |
|
63 |
#include "Settings.h" |
|
64 |
#include "Text.h" |
|
65 |
#include "htmlediting.h" |
|
66 |
#include "markup.h" |
|
67 |
#include <wtf/CurrentTime.h> |
|
68 |
#include <wtf/RefPtr.h> |
|
69 |
||
70 |
namespace WebCore { |
|
71 |
||
72 |
static PlatformMouseEvent createMouseEvent(DragData* dragData) |
|
73 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
bool shiftKey, ctrlKey, altKey, metaKey; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
shiftKey = ctrlKey = altKey = metaKey = false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
PlatformKeyboardEvent::getCurrentModifierState(shiftKey, ctrlKey, altKey, metaKey); |
0 | 77 |
return PlatformMouseEvent(dragData->clientPosition(), dragData->globalPosition(), |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
LeftButton, MouseEventMoved, 0, shiftKey, ctrlKey, altKey, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
metaKey, currentTime()); |
0 | 80 |
} |
81 |
||
82 |
DragController::DragController(Page* page, DragClient* client) |
|
83 |
: m_page(page) |
|
84 |
, m_client(client) |
|
85 |
, m_documentUnderMouse(0) |
|
86 |
, m_dragInitiator(0) |
|
87 |
, m_dragDestinationAction(DragDestinationActionNone) |
|
88 |
, m_dragSourceAction(DragSourceActionNone) |
|
89 |
, m_didInitiateDrag(false) |
|
90 |
, m_isHandlingDrag(false) |
|
91 |
, m_sourceDragOperation(DragOperationNone) |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
DragController::~DragController() |
|
96 |
{ |
|
97 |
m_client->dragControllerDestroyed(); |
|
98 |
} |
|
99 |
||
100 |
static PassRefPtr<DocumentFragment> documentFragmentFromDragData(DragData* dragData, RefPtr<Range> context, |
|
101 |
bool allowPlainText, bool& chosePlainText) |
|
102 |
{ |
|
103 |
ASSERT(dragData); |
|
104 |
chosePlainText = false; |
|
105 |
||
106 |
Document* document = context->ownerDocument(); |
|
107 |
ASSERT(document); |
|
108 |
if (document && dragData->containsCompatibleContent()) { |
|
109 |
if (PassRefPtr<DocumentFragment> fragment = dragData->asFragment(document)) |
|
110 |
return fragment; |
|
111 |
||
112 |
if (dragData->containsURL()) { |
|
113 |
String title; |
|
114 |
String url = dragData->asURL(&title); |
|
115 |
if (!url.isEmpty()) { |
|
116 |
RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(document); |
|
117 |
anchor->setHref(url); |
|
118 |
ExceptionCode ec; |
|
119 |
RefPtr<Node> anchorText = document->createTextNode(title); |
|
120 |
anchor->appendChild(anchorText, ec); |
|
121 |
RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); |
|
122 |
fragment->appendChild(anchor, ec); |
|
123 |
return fragment.get(); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
if (allowPlainText && dragData->containsPlainText()) { |
|
128 |
chosePlainText = true; |
|
129 |
return createFragmentFromText(context.get(), dragData->asPlainText()).get(); |
|
130 |
} |
|
131 |
||
132 |
return 0; |
|
133 |
} |
|
134 |
||
135 |
bool DragController::dragIsMove(SelectionController* selection) |
|
136 |
{ |
|
137 |
return m_documentUnderMouse == m_dragInitiator && selection->isContentEditable() && !isCopyKeyDown(); |
|
138 |
} |
|
139 |
||
140 |
// FIXME: This method is poorly named. We're just clearing the selection from the document this drag is exiting. |
|
141 |
void DragController::cancelDrag() |
|
142 |
{ |
|
143 |
m_page->dragCaretController()->clear(); |
|
144 |
} |
|
145 |
||
146 |
void DragController::dragEnded() |
|
147 |
{ |
|
148 |
m_dragInitiator = 0; |
|
149 |
m_didInitiateDrag = false; |
|
150 |
m_page->dragCaretController()->clear(); |
|
151 |
} |
|
152 |
||
153 |
DragOperation DragController::dragEntered(DragData* dragData) |
|
154 |
{ |
|
155 |
return dragEnteredOrUpdated(dragData); |
|
156 |
} |
|
157 |
||
158 |
void DragController::dragExited(DragData* dragData) |
|
159 |
{ |
|
160 |
ASSERT(dragData); |
|
161 |
Frame* mainFrame = m_page->mainFrame(); |
|
162 |
||
163 |
if (RefPtr<FrameView> v = mainFrame->view()) { |
|
164 |
ClipboardAccessPolicy policy = (!m_documentUnderMouse || m_documentUnderMouse->securityOrigin()->isLocal()) ? ClipboardReadable : ClipboardTypesReadable; |
|
165 |
RefPtr<Clipboard> clipboard = dragData->createClipboard(policy); |
|
166 |
clipboard->setSourceOperation(dragData->draggingSourceOperationMask()); |
|
167 |
mainFrame->eventHandler()->cancelDragAndDrop(createMouseEvent(dragData), clipboard.get()); |
|
168 |
clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security |
|
169 |
} |
|
170 |
mouseMovedIntoDocument(0); |
|
171 |
} |
|
172 |
||
173 |
DragOperation DragController::dragUpdated(DragData* dragData) |
|
174 |
{ |
|
175 |
return dragEnteredOrUpdated(dragData); |
|
176 |
} |
|
177 |
||
178 |
bool DragController::performDrag(DragData* dragData) |
|
179 |
{ |
|
180 |
ASSERT(dragData); |
|
181 |
m_documentUnderMouse = m_page->mainFrame()->documentAtPoint(dragData->clientPosition()); |
|
182 |
if (m_isHandlingDrag) { |
|
183 |
ASSERT(m_dragDestinationAction & DragDestinationActionDHTML); |
|
184 |
m_client->willPerformDragDestinationAction(DragDestinationActionDHTML, dragData); |
|
185 |
RefPtr<Frame> mainFrame = m_page->mainFrame(); |
|
186 |
if (mainFrame->view()) { |
|
187 |
// Sending an event can result in the destruction of the view and part. |
|
188 |
RefPtr<Clipboard> clipboard = dragData->createClipboard(ClipboardReadable); |
|
189 |
clipboard->setSourceOperation(dragData->draggingSourceOperationMask()); |
|
190 |
mainFrame->eventHandler()->performDragAndDrop(createMouseEvent(dragData), clipboard.get()); |
|
191 |
clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security |
|
192 |
} |
|
193 |
m_documentUnderMouse = 0; |
|
194 |
return true; |
|
195 |
} |
|
196 |
||
197 |
if ((m_dragDestinationAction & DragDestinationActionEdit) && concludeEditDrag(dragData)) { |
|
198 |
m_documentUnderMouse = 0; |
|
199 |
return true; |
|
200 |
} |
|
201 |
||
202 |
m_documentUnderMouse = 0; |
|
203 |
||
204 |
if (operationForLoad(dragData) == DragOperationNone) |
|
205 |
return false; |
|
206 |
||
207 |
m_client->willPerformDragDestinationAction(DragDestinationActionLoad, dragData); |
|
208 |
m_page->mainFrame()->loader()->load(ResourceRequest(dragData->asURL()), false); |
|
209 |
return true; |
|
210 |
} |
|
211 |
||
212 |
void DragController::mouseMovedIntoDocument(Document* newDocument) |
|
213 |
{ |
|
214 |
if (m_documentUnderMouse == newDocument) |
|
215 |
return; |
|
216 |
||
217 |
// If we were over another document clear the selection |
|
218 |
if (m_documentUnderMouse) |
|
219 |
cancelDrag(); |
|
220 |
m_documentUnderMouse = newDocument; |
|
221 |
} |
|
222 |
||
223 |
DragOperation DragController::dragEnteredOrUpdated(DragData* dragData) |
|
224 |
{ |
|
225 |
ASSERT(dragData); |
|
226 |
ASSERT(m_page->mainFrame()); // It is not possible in Mac WebKit to have a Page without a mainFrame() |
|
227 |
mouseMovedIntoDocument(m_page->mainFrame()->documentAtPoint(dragData->clientPosition())); |
|
228 |
||
229 |
m_dragDestinationAction = m_client->actionMaskForDrag(dragData); |
|
230 |
if (m_dragDestinationAction == DragDestinationActionNone) { |
|
231 |
cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(0)? |
|
232 |
return DragOperationNone; |
|
233 |
} |
|
234 |
||
235 |
DragOperation operation = DragOperationNone; |
|
236 |
bool handledByDocument = tryDocumentDrag(dragData, m_dragDestinationAction, operation); |
|
237 |
if (!handledByDocument && (m_dragDestinationAction & DragDestinationActionLoad)) |
|
238 |
return operationForLoad(dragData); |
|
239 |
return operation; |
|
240 |
} |
|
241 |
||
242 |
static HTMLInputElement* asFileInput(Node* node) |
|
243 |
{ |
|
244 |
ASSERT(node); |
|
245 |
||
246 |
// The button for a FILE input is a sub element with no set input type |
|
247 |
// In order to get around this problem we assume any non-FILE input element |
|
248 |
// is this internal button, and try querying the shadow parent node. |
|
249 |
if (node->hasTagName(HTMLNames::inputTag) && node->isShadowNode() && static_cast<HTMLInputElement*>(node)->inputType() != HTMLInputElement::FILE) |
|
250 |
node = node->shadowParentNode(); |
|
251 |
||
252 |
if (!node || !node->hasTagName(HTMLNames::inputTag)) |
|
253 |
return 0; |
|
254 |
||
255 |
HTMLInputElement* inputElem = static_cast<HTMLInputElement*>(node); |
|
256 |
if (inputElem->inputType() == HTMLInputElement::FILE) |
|
257 |
return inputElem; |
|
258 |
||
259 |
return 0; |
|
260 |
} |
|
261 |
||
262 |
static Element* elementUnderMouse(Document* documentUnderMouse, const IntPoint& p) |
|
263 |
{ |
|
264 |
float zoomFactor = documentUnderMouse->frame()->pageZoomFactor(); |
|
265 |
IntPoint point = roundedIntPoint(FloatPoint(p.x() * zoomFactor, p.y() * zoomFactor)); |
|
266 |
||
267 |
HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active); |
|
268 |
HitTestResult result(point); |
|
269 |
documentUnderMouse->renderView()->layer()->hitTest(request, result); |
|
270 |
||
271 |
Node* n = result.innerNode(); |
|
272 |
while (n && !n->isElementNode()) |
|
273 |
n = n->parentNode(); |
|
274 |
if (n) |
|
275 |
n = n->shadowAncestorNode(); |
|
276 |
||
277 |
ASSERT(n); |
|
278 |
return static_cast<Element*>(n); |
|
279 |
} |
|
280 |
||
281 |
bool DragController::tryDocumentDrag(DragData* dragData, DragDestinationAction actionMask, DragOperation& operation) |
|
282 |
{ |
|
283 |
ASSERT(dragData); |
|
284 |
||
285 |
if (!m_documentUnderMouse) |
|
286 |
return false; |
|
287 |
||
288 |
m_isHandlingDrag = false; |
|
289 |
if (actionMask & DragDestinationActionDHTML) { |
|
290 |
m_isHandlingDrag = tryDHTMLDrag(dragData, operation); |
|
291 |
// Do not continue if m_documentUnderMouse has been reset by tryDHTMLDrag. |
|
292 |
// tryDHTMLDrag fires dragenter event. The event listener that listens |
|
293 |
// to this event may create a nested message loop (open a modal dialog), |
|
294 |
// which could process dragleave event and reset m_documentUnderMouse in |
|
295 |
// dragExited. |
|
296 |
if (!m_documentUnderMouse) |
|
297 |
return false; |
|
298 |
} |
|
299 |
||
300 |
// It's unclear why this check is after tryDHTMLDrag. |
|
301 |
// We send drag events in tryDHTMLDrag and that may be the reason. |
|
302 |
RefPtr<FrameView> frameView = m_documentUnderMouse->view(); |
|
303 |
if (!frameView) |
|
304 |
return false; |
|
305 |
||
306 |
if (m_isHandlingDrag) { |
|
307 |
m_page->dragCaretController()->clear(); |
|
308 |
return true; |
|
309 |
} else if ((actionMask & DragDestinationActionEdit) && canProcessDrag(dragData)) { |
|
310 |
if (dragData->containsColor()) { |
|
311 |
operation = DragOperationGeneric; |
|
312 |
return true; |
|
313 |
} |
|
314 |
||
315 |
IntPoint point = frameView->windowToContents(dragData->clientPosition()); |
|
316 |
Element* element = elementUnderMouse(m_documentUnderMouse, point); |
|
317 |
if (!asFileInput(element)) { |
|
318 |
VisibleSelection dragCaret = m_documentUnderMouse->frame()->visiblePositionForPoint(point); |
|
319 |
m_page->dragCaretController()->setSelection(dragCaret); |
|
320 |
} |
|
321 |
||
322 |
Frame* innerFrame = element->document()->frame(); |
|
323 |
operation = dragIsMove(innerFrame->selection()) ? DragOperationMove : DragOperationCopy; |
|
324 |
return true; |
|
325 |
} |
|
326 |
// If we're not over an editable region, make sure we're clearing any prior drag cursor. |
|
327 |
m_page->dragCaretController()->clear(); |
|
328 |
return false; |
|
329 |
} |
|
330 |
||
331 |
DragSourceAction DragController::delegateDragSourceAction(const IntPoint& windowPoint) |
|
332 |
{ |
|
333 |
m_dragSourceAction = m_client->dragSourceActionMaskForPoint(windowPoint); |
|
334 |
return m_dragSourceAction; |
|
335 |
} |
|
336 |
||
337 |
DragOperation DragController::operationForLoad(DragData* dragData) |
|
338 |
{ |
|
339 |
ASSERT(dragData); |
|
340 |
Document* doc = m_page->mainFrame()->documentAtPoint(dragData->clientPosition()); |
|
341 |
if (doc && (m_didInitiateDrag || doc->isPluginDocument() || (doc->frame() && doc->frame()->editor()->clientIsEditable()))) |
|
342 |
return DragOperationNone; |
|
343 |
return dragOperation(dragData); |
|
344 |
} |
|
345 |
||
346 |
static bool setSelectionToDragCaret(Frame* frame, VisibleSelection& dragCaret, RefPtr<Range>& range, const IntPoint& point) |
|
347 |
{ |
|
348 |
frame->selection()->setSelection(dragCaret); |
|
349 |
if (frame->selection()->isNone()) { |
|
350 |
dragCaret = frame->visiblePositionForPoint(point); |
|
351 |
frame->selection()->setSelection(dragCaret); |
|
352 |
range = dragCaret.toNormalizedRange(); |
|
353 |
} |
|
354 |
return !frame->selection()->isNone() && frame->selection()->isContentEditable(); |
|
355 |
} |
|
356 |
||
357 |
bool DragController::concludeEditDrag(DragData* dragData) |
|
358 |
{ |
|
359 |
ASSERT(dragData); |
|
360 |
ASSERT(!m_isHandlingDrag); |
|
361 |
||
362 |
if (!m_documentUnderMouse) |
|
363 |
return false; |
|
364 |
||
365 |
IntPoint point = m_documentUnderMouse->view()->windowToContents(dragData->clientPosition()); |
|
366 |
Element* element = elementUnderMouse(m_documentUnderMouse, point); |
|
367 |
Frame* innerFrame = element->ownerDocument()->frame(); |
|
368 |
ASSERT(innerFrame); |
|
369 |
||
370 |
if (dragData->containsColor()) { |
|
371 |
Color color = dragData->asColor(); |
|
372 |
if (!color.isValid()) |
|
373 |
return false; |
|
374 |
if (!innerFrame) |
|
375 |
return false; |
|
376 |
RefPtr<Range> innerRange = innerFrame->selection()->toNormalizedRange(); |
|
377 |
RefPtr<CSSStyleDeclaration> style = m_documentUnderMouse->createCSSStyleDeclaration(); |
|
378 |
ExceptionCode ec; |
|
379 |
style->setProperty("color", color.name(), ec); |
|
380 |
if (!innerFrame->editor()->shouldApplyStyle(style.get(), innerRange.get())) |
|
381 |
return false; |
|
382 |
m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); |
|
383 |
innerFrame->editor()->applyStyle(style.get(), EditActionSetColor); |
|
384 |
return true; |
|
385 |
} |
|
386 |
||
387 |
if (!m_page->dragController()->canProcessDrag(dragData)) { |
|
388 |
m_page->dragCaretController()->clear(); |
|
389 |
return false; |
|
390 |
} |
|
391 |
||
392 |
if (HTMLInputElement* fileInput = asFileInput(element)) { |
|
393 |
if (!fileInput->isEnabledFormControl()) |
|
394 |
return false; |
|
395 |
||
396 |
if (!dragData->containsFiles()) |
|
397 |
return false; |
|
398 |
||
399 |
Vector<String> filenames; |
|
400 |
dragData->asFilenames(filenames); |
|
401 |
if (filenames.isEmpty()) |
|
402 |
return false; |
|
403 |
||
404 |
// Ugly. For security none of the APIs available to us can set the input value |
|
405 |
// on file inputs. Even forcing a change in HTMLInputElement doesn't work as |
|
406 |
// RenderFileUploadControl clears the file when doing updateFromElement(). |
|
407 |
RenderFileUploadControl* renderer = toRenderFileUploadControl(fileInput->renderer()); |
|
408 |
if (!renderer) |
|
409 |
return false; |
|
410 |
||
411 |
renderer->receiveDroppedFiles(filenames); |
|
412 |
return true; |
|
413 |
} |
|
414 |
||
415 |
VisibleSelection dragCaret(m_page->dragCaretController()->selection()); |
|
416 |
m_page->dragCaretController()->clear(); |
|
417 |
RefPtr<Range> range = dragCaret.toNormalizedRange(); |
|
418 |
||
419 |
// For range to be null a WebKit client must have done something bad while |
|
420 |
// manually controlling drag behaviour |
|
421 |
if (!range) |
|
422 |
return false; |
|
423 |
DocLoader* loader = range->ownerDocument()->docLoader(); |
|
424 |
loader->setAllowStaleResources(true); |
|
425 |
if (dragIsMove(innerFrame->selection()) || dragCaret.isContentRichlyEditable()) { |
|
426 |
bool chosePlainText = false; |
|
427 |
RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, range, true, chosePlainText); |
|
428 |
if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped)) { |
|
429 |
loader->setAllowStaleResources(false); |
|
430 |
return false; |
|
431 |
} |
|
432 |
||
433 |
m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); |
|
434 |
if (dragIsMove(innerFrame->selection())) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
435 |
// NSTextView behavior is to always smart delete on moving a selection, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
436 |
// but only to smart insert if the selection granularity is word granularity. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
bool smartDelete = innerFrame->editor()->smartInsertDeleteEnabled(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
438 |
bool smartInsert = smartDelete && innerFrame->selectionGranularity() == WordGranularity && dragData->canSmartReplace(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
439 |
applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete)); |
0 | 440 |
} else { |
441 |
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) |
|
442 |
applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, fragment, true, dragData->canSmartReplace(), chosePlainText)); |
|
443 |
} |
|
444 |
} else { |
|
445 |
String text = dragData->asPlainText(); |
|
446 |
if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped)) { |
|
447 |
loader->setAllowStaleResources(false); |
|
448 |
return false; |
|
449 |
} |
|
450 |
||
451 |
m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData); |
|
452 |
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) |
|
453 |
applyCommand(ReplaceSelectionCommand::create(m_documentUnderMouse, createFragmentFromText(range.get(), text), true, false, true)); |
|
454 |
} |
|
455 |
loader->setAllowStaleResources(false); |
|
456 |
||
457 |
return true; |
|
458 |
} |
|
459 |
||
460 |
bool DragController::canProcessDrag(DragData* dragData) |
|
461 |
{ |
|
462 |
ASSERT(dragData); |
|
463 |
||
464 |
if (!dragData->containsCompatibleContent()) |
|
465 |
return false; |
|
466 |
||
467 |
IntPoint point = m_page->mainFrame()->view()->windowToContents(dragData->clientPosition()); |
|
468 |
HitTestResult result = HitTestResult(point); |
|
469 |
if (!m_page->mainFrame()->contentRenderer()) |
|
470 |
return false; |
|
471 |
||
472 |
result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, true); |
|
473 |
||
474 |
if (!result.innerNonSharedNode()) |
|
475 |
return false; |
|
476 |
||
477 |
if (dragData->containsFiles() && asFileInput(result.innerNonSharedNode())) |
|
478 |
return true; |
|
479 |
||
480 |
if (!result.innerNonSharedNode()->isContentEditable()) |
|
481 |
return false; |
|
482 |
||
483 |
if (m_didInitiateDrag && m_documentUnderMouse == m_dragInitiator && result.isSelected()) |
|
484 |
return false; |
|
485 |
||
486 |
return true; |
|
487 |
} |
|
488 |
||
489 |
static DragOperation defaultOperationForDrag(DragOperation srcOpMask) |
|
490 |
{ |
|
491 |
// This is designed to match IE's operation fallback for the case where |
|
492 |
// the page calls preventDefault() in a drag event but doesn't set dropEffect. |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
493 |
if (srcOpMask == DragOperationEvery) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
return DragOperationCopy; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
if (srcOpMask == DragOperationNone) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
496 |
return DragOperationNone; |
0 | 497 |
if (srcOpMask & DragOperationMove || srcOpMask & DragOperationGeneric) |
498 |
return DragOperationMove; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
if (srcOpMask & DragOperationCopy) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
return DragOperationCopy; |
0 | 501 |
if (srcOpMask & DragOperationLink) |
502 |
return DragOperationLink; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
|
0 | 504 |
// FIXME: Does IE really return "generic" even if no operations were allowed by the source? |
505 |
return DragOperationGeneric; |
|
506 |
} |
|
507 |
||
508 |
bool DragController::tryDHTMLDrag(DragData* dragData, DragOperation& operation) |
|
509 |
{ |
|
510 |
ASSERT(dragData); |
|
511 |
ASSERT(m_documentUnderMouse); |
|
512 |
RefPtr<Frame> mainFrame = m_page->mainFrame(); |
|
513 |
RefPtr<FrameView> viewProtector = mainFrame->view(); |
|
514 |
if (!viewProtector) |
|
515 |
return false; |
|
516 |
||
517 |
ClipboardAccessPolicy policy = m_documentUnderMouse->securityOrigin()->isLocal() ? ClipboardReadable : ClipboardTypesReadable; |
|
518 |
RefPtr<Clipboard> clipboard = dragData->createClipboard(policy); |
|
519 |
DragOperation srcOpMask = dragData->draggingSourceOperationMask(); |
|
520 |
clipboard->setSourceOperation(srcOpMask); |
|
521 |
||
522 |
PlatformMouseEvent event = createMouseEvent(dragData); |
|
523 |
if (!mainFrame->eventHandler()->updateDragAndDrop(event, clipboard.get())) { |
|
524 |
clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security |
|
525 |
return false; |
|
526 |
} |
|
527 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
528 |
operation = clipboard->destinationOperation(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
if (clipboard->dropEffectIsUninitialized()) |
0 | 530 |
operation = defaultOperationForDrag(srcOpMask); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
else if (!(srcOpMask & operation)) { |
0 | 532 |
// The element picked an operation which is not supported by the source |
533 |
operation = DragOperationNone; |
|
534 |
} |
|
535 |
||
536 |
clipboard->setAccessPolicy(ClipboardNumb); // invalidate clipboard here for security |
|
537 |
return true; |
|
538 |
} |
|
539 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
bool DragController::mayStartDragAtEventLocation(const Frame* frame, const IntPoint& framePos, Node* node) |
0 | 541 |
{ |
542 |
ASSERT(frame); |
|
543 |
ASSERT(frame->settings()); |
|
544 |
||
545 |
if (!frame->view() || !frame->contentRenderer()) |
|
546 |
return false; |
|
547 |
||
548 |
HitTestResult mouseDownTarget = HitTestResult(framePos); |
|
549 |
||
550 |
mouseDownTarget = frame->eventHandler()->hitTestResultAtPoint(framePos, true); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
if (node) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
mouseDownTarget.setInnerNonSharedNode(node); |
0 | 553 |
|
554 |
if (mouseDownTarget.image() |
|
555 |
&& !mouseDownTarget.absoluteImageURL().isEmpty() |
|
556 |
&& frame->settings()->loadsImagesAutomatically() |
|
557 |
&& m_dragSourceAction & DragSourceActionImage) |
|
558 |
return true; |
|
559 |
||
560 |
if (!mouseDownTarget.absoluteLinkURL().isEmpty() |
|
561 |
&& m_dragSourceAction & DragSourceActionLink |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
562 |
&& mouseDownTarget.isLiveLink() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
&& mouseDownTarget.URLElement()->renderer() && mouseDownTarget.URLElement()->renderer()->style()->userDrag() != DRAG_NONE) |
0 | 564 |
return true; |
565 |
||
566 |
if (mouseDownTarget.isSelected() |
|
567 |
&& m_dragSourceAction & DragSourceActionSelection) |
|
568 |
return true; |
|
569 |
||
570 |
return false; |
|
571 |
} |
|
572 |
||
573 |
static CachedImage* getCachedImage(Element* element) |
|
574 |
{ |
|
575 |
ASSERT(element); |
|
576 |
RenderObject* renderer = element->renderer(); |
|
577 |
if (!renderer || !renderer->isImage()) |
|
578 |
return 0; |
|
579 |
RenderImage* image = toRenderImage(renderer); |
|
580 |
return image->cachedImage(); |
|
581 |
} |
|
582 |
||
583 |
static Image* getImage(Element* element) |
|
584 |
{ |
|
585 |
ASSERT(element); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
586 |
CachedImage* cachedImage = getCachedImage(element); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
587 |
return (cachedImage && !cachedImage->errorOccurred()) ? |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
588 |
cachedImage->image() : 0; |
0 | 589 |
} |
590 |
||
591 |
static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label) |
|
592 |
{ |
|
593 |
RefPtr<Range> range = src->document()->createRange(); |
|
594 |
ExceptionCode ec = 0; |
|
595 |
range->selectNode(node, ec); |
|
596 |
ASSERT(!ec); |
|
597 |
src->selection()->setSelection(VisibleSelection(range.get(), DOWNSTREAM)); |
|
598 |
clipboard->declareAndWriteDragImage(node, !linkURL.isEmpty() ? linkURL : imageURL, label, src); |
|
599 |
} |
|
600 |
||
601 |
static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const IntPoint& dragOrigin, const IntPoint& dragImageOffset, bool isLinkImage) |
|
602 |
{ |
|
603 |
// dragImageOffset is the cursor position relative to the lower-left corner of the image. |
|
604 |
#if PLATFORM(MAC) |
|
605 |
// We add in the Y dimension because we are a flipped view, so adding moves the image down. |
|
606 |
const int yOffset = dragImageOffset.y(); |
|
607 |
#else |
|
608 |
const int yOffset = -dragImageOffset.y(); |
|
609 |
#endif |
|
610 |
||
611 |
if (isLinkImage) |
|
612 |
return IntPoint(mouseDraggedPoint.x() - dragImageOffset.x(), mouseDraggedPoint.y() + yOffset); |
|
613 |
||
614 |
return IntPoint(dragOrigin.x() - dragImageOffset.x(), dragOrigin.y() + yOffset); |
|
615 |
} |
|
616 |
||
617 |
static IntPoint dragLocForSelectionDrag(Frame* src) |
|
618 |
{ |
|
619 |
IntRect draggingRect = enclosingIntRect(src->selectionBounds()); |
|
620 |
int xpos = draggingRect.right(); |
|
621 |
xpos = draggingRect.x() < xpos ? draggingRect.x() : xpos; |
|
622 |
int ypos = draggingRect.bottom(); |
|
623 |
#if PLATFORM(MAC) |
|
624 |
// Deal with flipped coordinates on Mac |
|
625 |
ypos = draggingRect.y() > ypos ? draggingRect.y() : ypos; |
|
626 |
#else |
|
627 |
ypos = draggingRect.y() < ypos ? draggingRect.y() : ypos; |
|
628 |
#endif |
|
629 |
return IntPoint(xpos, ypos); |
|
630 |
} |
|
631 |
||
632 |
bool DragController::startDrag(Frame* src, Clipboard* clipboard, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag) |
|
633 |
{ |
|
634 |
ASSERT(src); |
|
635 |
ASSERT(clipboard); |
|
636 |
||
637 |
if (!src->view() || !src->contentRenderer()) |
|
638 |
return false; |
|
639 |
||
640 |
HitTestResult dragSource = HitTestResult(dragOrigin); |
|
641 |
dragSource = src->eventHandler()->hitTestResultAtPoint(dragOrigin, true); |
|
642 |
KURL linkURL = dragSource.absoluteLinkURL(); |
|
643 |
KURL imageURL = dragSource.absoluteImageURL(); |
|
644 |
bool isSelected = dragSource.isSelected(); |
|
645 |
||
646 |
IntPoint mouseDraggedPoint = src->view()->windowToContents(dragEvent.pos()); |
|
647 |
||
648 |
m_draggingImageURL = KURL(); |
|
649 |
m_sourceDragOperation = srcOp; |
|
650 |
||
651 |
DragImageRef dragImage = 0; |
|
652 |
IntPoint dragLoc(0, 0); |
|
653 |
IntPoint dragImageOffset(0, 0); |
|
654 |
||
655 |
if (isDHTMLDrag) |
|
656 |
dragImage = clipboard->createDragImage(dragImageOffset); |
|
657 |
else { |
|
658 |
// This drag operation is not a DHTML drag and may go outside the WebView. |
|
659 |
// We provide a default set of allowed drag operations that follows from: |
|
660 |
// http://trac.webkit.org/browser/trunk/WebKit/mac/WebView/WebHTMLView.mm?rev=48526#L3430 |
|
661 |
m_sourceDragOperation = (DragOperation)(DragOperationGeneric | DragOperationCopy); |
|
662 |
} |
|
663 |
||
664 |
// We allow DHTML/JS to set the drag image, even if its a link, image or text we're dragging. |
|
665 |
// This is in the spirit of the IE API, which allows overriding of pasteboard data and DragOp. |
|
666 |
if (dragImage) { |
|
667 |
dragLoc = dragLocForDHTMLDrag(mouseDraggedPoint, dragOrigin, dragImageOffset, !linkURL.isEmpty()); |
|
668 |
m_dragOffset = dragImageOffset; |
|
669 |
} |
|
670 |
||
671 |
bool startedDrag = true; // optimism - we almost always manage to start the drag |
|
672 |
||
673 |
Node* node = dragSource.innerNonSharedNode(); |
|
674 |
||
675 |
Image* image = getImage(static_cast<Element*>(node)); |
|
676 |
if (!imageURL.isEmpty() && node && node->isElementNode() && image |
|
677 |
&& (m_dragSourceAction & DragSourceActionImage)) { |
|
678 |
// We shouldn't be starting a drag for an image that can't provide an extension. |
|
679 |
// This is an early detection for problems encountered later upon drop. |
|
680 |
ASSERT(!image->filenameExtension().isEmpty()); |
|
681 |
Element* element = static_cast<Element*>(node); |
|
682 |
if (!clipboard->hasData()) { |
|
683 |
m_draggingImageURL = imageURL; |
|
684 |
prepareClipboardForImageDrag(src, clipboard, element, linkURL, imageURL, dragSource.altDisplayString()); |
|
685 |
} |
|
686 |
||
687 |
m_client->willPerformDragSourceAction(DragSourceActionImage, dragOrigin, clipboard); |
|
688 |
||
689 |
if (!dragImage) { |
|
690 |
IntRect imageRect = dragSource.imageRect(); |
|
691 |
imageRect.setLocation(m_page->mainFrame()->view()->windowToContents(src->view()->contentsToWindow(imageRect.location()))); |
|
692 |
doImageDrag(element, dragOrigin, dragSource.imageRect(), clipboard, src, m_dragOffset); |
|
693 |
} else |
|
694 |
// DHTML defined drag image |
|
695 |
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); |
|
696 |
||
697 |
} else if (!linkURL.isEmpty() && (m_dragSourceAction & DragSourceActionLink)) { |
|
698 |
if (!clipboard->hasData()) |
|
699 |
// Simplify whitespace so the title put on the clipboard resembles what the user sees |
|
700 |
// on the web page. This includes replacing newlines with spaces. |
|
701 |
clipboard->writeURL(linkURL, dragSource.textContent().simplifyWhiteSpace(), src); |
|
702 |
||
703 |
if (src->selection()->isCaret() && src->selection()->isContentEditable()) { |
|
704 |
// a user can initiate a drag on a link without having any text |
|
705 |
// selected. In this case, we should expand the selection to |
|
706 |
// the enclosing anchor element |
|
707 |
Position pos = src->selection()->base(); |
|
708 |
Node* node = enclosingAnchorElement(pos); |
|
709 |
if (node) |
|
710 |
src->selection()->setSelection(VisibleSelection::selectionFromContentsOfNode(node)); |
|
711 |
} |
|
712 |
||
713 |
m_client->willPerformDragSourceAction(DragSourceActionLink, dragOrigin, clipboard); |
|
714 |
if (!dragImage) { |
|
715 |
dragImage = m_client->createDragImageForLink(linkURL, dragSource.textContent(), src); |
|
716 |
IntSize size = dragImageSize(dragImage); |
|
717 |
m_dragOffset = IntPoint(-size.width() / 2, -LinkDragBorderInset); |
|
718 |
dragLoc = IntPoint(mouseDraggedPoint.x() + m_dragOffset.x(), mouseDraggedPoint.y() + m_dragOffset.y()); |
|
719 |
} |
|
720 |
doSystemDrag(dragImage, dragLoc, mouseDraggedPoint, clipboard, src, true); |
|
721 |
} else if (isSelected && (m_dragSourceAction & DragSourceActionSelection)) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
if (!clipboard->hasData()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
if (isNodeInTextFormControl(src->selection()->start().node())) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
clipboard->writePlainText(src->selectedText()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
RefPtr<Range> selectionRange = src->selection()->toNormalizedRange(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
ASSERT(selectionRange); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
clipboard->writeRange(selectionRange.get(), src); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
} |
0 | 732 |
m_client->willPerformDragSourceAction(DragSourceActionSelection, dragOrigin, clipboard); |
733 |
if (!dragImage) { |
|
734 |
dragImage = createDragImageForSelection(src); |
|
735 |
dragLoc = dragLocForSelectionDrag(src); |
|
736 |
m_dragOffset = IntPoint((int)(dragOrigin.x() - dragLoc.x()), (int)(dragOrigin.y() - dragLoc.y())); |
|
737 |
} |
|
738 |
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); |
|
739 |
} else if (isDHTMLDrag) { |
|
740 |
ASSERT(m_dragSourceAction & DragSourceActionDHTML); |
|
741 |
m_client->willPerformDragSourceAction(DragSourceActionDHTML, dragOrigin, clipboard); |
|
742 |
doSystemDrag(dragImage, dragLoc, dragOrigin, clipboard, src, false); |
|
743 |
} else { |
|
744 |
// Only way I know to get here is if to get here is if the original element clicked on in the mousedown is no longer |
|
745 |
// under the mousedown point, so linkURL, imageURL and isSelected are all false/empty. |
|
746 |
startedDrag = false; |
|
747 |
} |
|
748 |
||
749 |
if (dragImage) |
|
750 |
deleteDragImage(dragImage); |
|
751 |
return startedDrag; |
|
752 |
} |
|
753 |
||
754 |
void DragController::doImageDrag(Element* element, const IntPoint& dragOrigin, const IntRect& rect, Clipboard* clipboard, Frame* frame, IntPoint& dragImageOffset) |
|
755 |
{ |
|
756 |
IntPoint mouseDownPoint = dragOrigin; |
|
757 |
DragImageRef dragImage; |
|
758 |
IntPoint origin; |
|
759 |
||
760 |
Image* image = getImage(element); |
|
761 |
if (image && image->size().height() * image->size().width() <= MaxOriginalImageArea |
|
762 |
&& (dragImage = createDragImageFromImage(image))) { |
|
763 |
IntSize originalSize = rect.size(); |
|
764 |
origin = rect.location(); |
|
765 |
||
766 |
dragImage = fitDragImageToMaxSize(dragImage, rect.size(), maxDragImageSize()); |
|
767 |
dragImage = dissolveDragImageToFraction(dragImage, DragImageAlpha); |
|
768 |
IntSize newSize = dragImageSize(dragImage); |
|
769 |
||
770 |
// Properly orient the drag image and orient it differently if it's smaller than the original |
|
771 |
float scale = newSize.width() / (float)originalSize.width(); |
|
772 |
float dx = origin.x() - mouseDownPoint.x(); |
|
773 |
dx *= scale; |
|
774 |
origin.setX((int)(dx + 0.5)); |
|
775 |
#if PLATFORM(MAC) |
|
776 |
//Compensate for accursed flipped coordinates in cocoa |
|
777 |
origin.setY(origin.y() + originalSize.height()); |
|
778 |
#endif |
|
779 |
float dy = origin.y() - mouseDownPoint.y(); |
|
780 |
dy *= scale; |
|
781 |
origin.setY((int)(dy + 0.5)); |
|
782 |
} else { |
|
783 |
dragImage = createDragImageIconForCachedImage(getCachedImage(element)); |
|
784 |
if (dragImage) |
|
785 |
origin = IntPoint(DragIconRightInset - dragImageSize(dragImage).width(), DragIconBottomInset); |
|
786 |
} |
|
787 |
||
788 |
dragImageOffset.setX(mouseDownPoint.x() + origin.x()); |
|
789 |
dragImageOffset.setY(mouseDownPoint.y() + origin.y()); |
|
790 |
doSystemDrag(dragImage, dragImageOffset, dragOrigin, clipboard, frame, false); |
|
791 |
||
792 |
deleteDragImage(dragImage); |
|
793 |
} |
|
794 |
||
795 |
void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, const IntPoint& eventPos, Clipboard* clipboard, Frame* frame, bool forLink) |
|
796 |
{ |
|
797 |
m_didInitiateDrag = true; |
|
798 |
m_dragInitiator = frame->document(); |
|
799 |
// Protect this frame and view, as a load may occur mid drag and attempt to unload this frame |
|
800 |
RefPtr<Frame> frameProtector = m_page->mainFrame(); |
|
801 |
RefPtr<FrameView> viewProtector = frameProtector->view(); |
|
802 |
m_client->startDrag(image, viewProtector->windowToContents(frame->view()->contentsToWindow(dragLoc)), |
|
803 |
viewProtector->windowToContents(frame->view()->contentsToWindow(eventPos)), clipboard, frameProtector.get(), forLink); |
|
804 |
||
805 |
cleanupAfterSystemDrag(); |
|
806 |
} |
|
807 |
||
808 |
// Manual drag caret manipulation |
|
809 |
void DragController::placeDragCaret(const IntPoint& windowPoint) |
|
810 |
{ |
|
811 |
mouseMovedIntoDocument(m_page->mainFrame()->documentAtPoint(windowPoint)); |
|
812 |
if (!m_documentUnderMouse) |
|
813 |
return; |
|
814 |
Frame* frame = m_documentUnderMouse->frame(); |
|
815 |
FrameView* frameView = frame->view(); |
|
816 |
if (!frameView) |
|
817 |
return; |
|
818 |
IntPoint framePoint = frameView->windowToContents(windowPoint); |
|
819 |
VisibleSelection dragCaret(frame->visiblePositionForPoint(framePoint)); |
|
820 |
m_page->dragCaretController()->setSelection(dragCaret); |
|
821 |
} |
|
822 |
||
823 |
} // namespace WebCore |
|
824 |
||
825 |
#endif // ENABLE(DRAG_SUPPORT) |