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

Side by Side Diff: third_party/WebKit/Source/core/page/DragController.cpp

Issue 1888773003: Merge DragClientImpl into core. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing file. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Google Inc. 3 * Copyright (C) 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "core/fetch/ResourceFetcher.h" 48 #include "core/fetch/ResourceFetcher.h"
49 #include "core/frame/FrameHost.h" 49 #include "core/frame/FrameHost.h"
50 #include "core/frame/FrameView.h" 50 #include "core/frame/FrameView.h"
51 #include "core/frame/LocalFrame.h" 51 #include "core/frame/LocalFrame.h"
52 #include "core/frame/Settings.h" 52 #include "core/frame/Settings.h"
53 #include "core/html/HTMLAnchorElement.h" 53 #include "core/html/HTMLAnchorElement.h"
54 #include "core/html/HTMLFormElement.h" 54 #include "core/html/HTMLFormElement.h"
55 #include "core/html/HTMLInputElement.h" 55 #include "core/html/HTMLInputElement.h"
56 #include "core/html/HTMLPlugInElement.h" 56 #include "core/html/HTMLPlugInElement.h"
57 #include "core/input/EventHandler.h" 57 #include "core/input/EventHandler.h"
58 #include "core/layout/HitTestRequest.h"
59 #include "core/layout/HitTestResult.h"
60 #include "core/layout/LayoutImage.h"
58 #include "core/layout/LayoutTheme.h" 61 #include "core/layout/LayoutTheme.h"
59 #include "core/layout/LayoutView.h" 62 #include "core/layout/LayoutView.h"
60 #include "core/loader/FrameLoadRequest.h" 63 #include "core/loader/FrameLoadRequest.h"
61 #include "core/loader/FrameLoader.h" 64 #include "core/loader/FrameLoader.h"
62 #include "core/page/ChromeClient.h" 65 #include "core/page/ChromeClient.h"
63 #include "core/page/DragClient.h"
64 #include "core/page/DragData.h" 66 #include "core/page/DragData.h"
65 #include "core/page/DragSession.h" 67 #include "core/page/DragSession.h"
66 #include "core/page/DragState.h" 68 #include "core/page/DragState.h"
67 #include "core/page/Page.h" 69 #include "core/page/Page.h"
68 #include "core/layout/HitTestRequest.h"
69 #include "core/layout/HitTestResult.h"
70 #include "core/layout/LayoutImage.h"
71 #include "platform/DragImage.h" 70 #include "platform/DragImage.h"
72 #include "platform/geometry/IntRect.h" 71 #include "platform/geometry/IntRect.h"
72 #include "platform/geometry/IntSize.h"
73 #include "platform/graphics/BitmapImage.h" 73 #include "platform/graphics/BitmapImage.h"
74 #include "platform/graphics/Image.h" 74 #include "platform/graphics/Image.h"
75 #include "platform/graphics/ImageOrientation.h" 75 #include "platform/graphics/ImageOrientation.h"
76 #include "platform/network/ResourceRequest.h" 76 #include "platform/network/ResourceRequest.h"
77 #include "platform/weborigin/SecurityOrigin.h" 77 #include "platform/weborigin/SecurityOrigin.h"
78 #include "public/platform/WebCommon.h"
79 #include "public/platform/WebDragData.h"
80 #include "public/platform/WebDragOperation.h"
81 #include "public/platform/WebImage.h"
82 #include "public/platform/WebPoint.h"
78 #include "public/platform/WebScreenInfo.h" 83 #include "public/platform/WebScreenInfo.h"
84 #include "wtf/Assertions.h"
79 #include "wtf/CurrentTime.h" 85 #include "wtf/CurrentTime.h"
80 #include "wtf/OwnPtr.h" 86 #include "wtf/OwnPtr.h"
81 #include "wtf/PassOwnPtr.h" 87 #include "wtf/PassOwnPtr.h"
82 #include "wtf/RefPtr.h" 88 #include "wtf/RefPtr.h"
83 89
84 #if OS(WIN) 90 #if OS(WIN)
85 #include <windows.h> 91 #include <windows.h>
86 #endif 92 #endif
87 93
88 namespace blink { 94 namespace blink {
(...skipping 28 matching lines...) Expand all
117 LeftButton, PlatformEvent::MouseMoved, 0, 123 LeftButton, PlatformEvent::MouseMoved, 0,
118 static_cast<PlatformEvent::Modifiers>(dragData->modifiers()), 124 static_cast<PlatformEvent::Modifiers>(dragData->modifiers()),
119 PlatformMouseEvent::RealOrIndistinguishable, monotonicallyIncreasingTime ()); 125 PlatformMouseEvent::RealOrIndistinguishable, monotonicallyIncreasingTime ());
120 } 126 }
121 127
122 static DataTransfer* createDraggingDataTransfer(DataTransferAccessPolicy policy, DragData* dragData) 128 static DataTransfer* createDraggingDataTransfer(DataTransferAccessPolicy policy, DragData* dragData)
123 { 129 {
124 return DataTransfer::create(DataTransfer::DragAndDrop, policy, dragData->pla tformData()); 130 return DataTransfer::create(DataTransfer::DragAndDrop, policy, dragData->pla tformData());
125 } 131 }
126 132
127 DragController::DragController(Page* page, DragClient* client) 133 DragController::DragController(Page* page)
128 : m_page(page) 134 : m_page(page)
129 , m_client(client)
130 , m_documentUnderMouse(nullptr) 135 , m_documentUnderMouse(nullptr)
131 , m_dragInitiator(nullptr) 136 , m_dragInitiator(nullptr)
132 , m_fileInputElementUnderMouse(nullptr) 137 , m_fileInputElementUnderMouse(nullptr)
133 , m_documentIsHandlingDrag(false) 138 , m_documentIsHandlingDrag(false)
134 , m_dragDestinationAction(DragDestinationActionNone) 139 , m_dragDestinationAction(DragDestinationActionNone)
135 , m_didInitiateDrag(false) 140 , m_didInitiateDrag(false)
136 { 141 {
137 ASSERT(m_client);
138 } 142 }
139 143
140 DragController::~DragController() 144 DragController::~DragController()
141 { 145 {
142 } 146 }
143 147
144 DragController* DragController::create(Page* page, DragClient* client) 148 DragController* DragController::create(Page* page)
145 { 149 {
146 return new DragController(page, client); 150 return new DragController(page);
147 } 151 }
148 152
149 static DocumentFragment* documentFragmentFromDragData(DragData* dragData, LocalF rame* frame, Range* context, bool allowPlainText, bool& chosePlainText) 153 static DocumentFragment* documentFragmentFromDragData(DragData* dragData, LocalF rame* frame, Range* context, bool allowPlainText, bool& chosePlainText)
150 { 154 {
151 ASSERT(dragData); 155 ASSERT(dragData);
152 chosePlainText = false; 156 chosePlainText = false;
153 157
154 Document& document = context->ownerDocument(); 158 Document& document = context->ownerDocument();
155 if (dragData->containsCompatibleContent()) { 159 if (dragData->containsCompatibleContent()) {
156 if (DocumentFragment* fragment = dragData->asFragment(frame)) 160 if (DocumentFragment* fragment = dragData->asFragment(frame))
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 cancelDrag(); 290 cancelDrag();
287 m_documentUnderMouse = newDocument; 291 m_documentUnderMouse = newDocument;
288 } 292 }
289 293
290 DragSession DragController::dragEnteredOrUpdated(DragData* dragData) 294 DragSession DragController::dragEnteredOrUpdated(DragData* dragData)
291 { 295 {
292 ASSERT(dragData); 296 ASSERT(dragData);
293 ASSERT(m_page->mainFrame()); 297 ASSERT(m_page->mainFrame());
294 mouseMovedIntoDocument(m_page->deprecatedLocalMainFrame()->documentAtPoint(d ragData->clientPosition())); 298 mouseMovedIntoDocument(m_page->deprecatedLocalMainFrame()->documentAtPoint(d ragData->clientPosition()));
295 299
296 m_dragDestinationAction = m_client->actionMaskForDrag(dragData); 300 // TODO(esprehn): Replace acceptsLoadDrops with a Setting used in core.
301 m_dragDestinationAction = m_page->chromeClient().acceptsLoadDrops()
302 ? DragDestinationActionAny
303 : static_cast<DragDestinationAction>(DragDestinationActionDHTML | DragDe stinationActionEdit);
297 if (m_dragDestinationAction == DragDestinationActionNone) { 304 if (m_dragDestinationAction == DragDestinationActionNone) {
298 cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(0)? 305 cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(0)?
299 return DragSession(); 306 return DragSession();
300 } 307 }
301 308
302 DragSession dragSession; 309 DragSession dragSession;
303 m_documentIsHandlingDrag = tryDocumentDrag(dragData, m_dragDestinationAction , dragSession); 310 m_documentIsHandlingDrag = tryDocumentDrag(dragData, m_dragDestinationAction , dragSession);
304 if (!m_documentIsHandlingDrag && (m_dragDestinationAction & DragDestinationA ctionLoad)) 311 if (!m_documentIsHandlingDrag && (m_dragDestinationAction & DragDestinationA ctionLoad))
305 dragSession.operation = operationForLoad(dragData); 312 dragSession.operation = operationForLoad(dragData);
306 return dragSession; 313 return dragSession;
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 } else if (state.m_dragType == DragSourceActionDHTML) { 933 } else if (state.m_dragType == DragSourceActionDHTML) {
927 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false); 934 doSystemDrag(dragImage.get(), dragLocation, dragOrigin, dataTransfer, sr c, false);
928 } else { 935 } else {
929 ASSERT_NOT_REACHED(); 936 ASSERT_NOT_REACHED();
930 return false; 937 return false;
931 } 938 }
932 939
933 return true; 940 return true;
934 } 941 }
935 942
943 // TODO(esprehn): forLink is dead code, what was it for?
936 void DragController::doSystemDrag(DragImage* image, const IntPoint& dragLocation , const IntPoint& eventPos, DataTransfer* dataTransfer, LocalFrame* frame, bool forLink) 944 void DragController::doSystemDrag(DragImage* image, const IntPoint& dragLocation , const IntPoint& eventPos, DataTransfer* dataTransfer, LocalFrame* frame, bool forLink)
937 { 945 {
938 // TODO(dcheng): Drag and drop is not yet supported for OOPI. 946 // TODO(dcheng): Drag and drop is not yet supported for OOPI.
939 if (m_page->mainFrame()->isRemoteFrame()) 947 if (m_page->mainFrame()->isRemoteFrame())
940 return; 948 return;
941 m_didInitiateDrag = true; 949 m_didInitiateDrag = true;
942 m_dragInitiator = frame->document(); 950 m_dragInitiator = frame->document();
943 // Protect this frame and view, as a load may occur mid drag and attempt to unload this frame 951
944 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame(); 952 LocalFrame* mainFrame = m_page->deprecatedLocalMainFrame();
945 FrameView* mainFrameView = mainFrame->view(); 953 FrameView* mainFrameView = mainFrame->view();
954 IntPoint adjustedDragLocation = mainFrameView->rootFrameToContents(frame->vi ew()->contentsToRootFrame(dragLocation));
955 IntPoint adjustedEventPos = mainFrameView->rootFrameToContents(frame->view() ->contentsToRootFrame(eventPos));
956 WebDragData dragData = dataTransfer->dataObject()->toWebDragData();
957 WebDragOperationsMask dragOperationMask = static_cast<WebDragOperationsMask> (dataTransfer->sourceOperation());
958 IntSize offsetSize(adjustedEventPos - adjustedDragLocation);
959 WebPoint offsetPoint(offsetSize.width(), offsetSize.height());
960 WebImage dragImage;
946 961
947 m_client->startDrag(image, mainFrameView->rootFrameToContents(frame->view()- >contentsToRootFrame(dragLocation)), 962 if (image) {
948 mainFrameView->rootFrameToContents(frame->view()->contentsToRootFrame(ev entPos)), dataTransfer, frame, forLink); 963 float resolutionScale = image->resolutionScale();
949 // DragClient::startDrag can cause our Page to dispear, deallocating |this|. 964 float deviceScaleFactor = m_page->chromeClient().screenInfo().deviceScal eFactor;
950 if (!frame->page()) 965 if (deviceScaleFactor != resolutionScale) {
951 return; 966 DCHECK_GT(resolutionScale, 0);
967 float scale = deviceScaleFactor / resolutionScale;
968 image->scale(scale, scale);
969 }
970 dragImage = image->bitmap();
971 }
952 972
953 cleanupAfterSystemDrag(); 973 m_page->chromeClient().startDragging(frame, dragData, dragOperationMask, dra gImage, offsetPoint);
954 } 974 }
955 975
956 DragOperation DragController::dragOperation(DragData* dragData) 976 DragOperation DragController::dragOperation(DragData* dragData)
957 { 977 {
958 // FIXME: To match the MacOS behaviour we should return DragOperationNone 978 // FIXME: To match the MacOS behaviour we should return DragOperationNone
959 // if we are a modal window, we are the drag source, or the window is an 979 // if we are a modal window, we are the drag source, or the window is an
960 // attached sheet If this can be determined from within WebCore 980 // attached sheet If this can be determined from within WebCore
961 // operationForDrag can be pulled into WebCore itself 981 // operationForDrag can be pulled into WebCore itself
962 ASSERT(dragData); 982 ASSERT(dragData);
963 return dragData->containsURL() && !m_didInitiateDrag ? DragOperationCopy : D ragOperationNone; 983 return dragData->containsURL() && !m_didInitiateDrag ? DragOperationCopy : D ragOperationNone;
964 } 984 }
965 985
966 bool DragController::isCopyKeyDown(DragData* dragData) 986 bool DragController::isCopyKeyDown(DragData* dragData)
967 { 987 {
968 int modifiers = dragData->modifiers(); 988 int modifiers = dragData->modifiers();
969 989
970 #if OS(MACOSX) 990 #if OS(MACOSX)
971 return modifiers & PlatformEvent::AltKey; 991 return modifiers & PlatformEvent::AltKey;
972 #else 992 #else
973 return modifiers & PlatformEvent::CtrlKey; 993 return modifiers & PlatformEvent::CtrlKey;
974 #endif 994 #endif
975 } 995 }
976 996
977 void DragController::cleanupAfterSystemDrag()
978 {
979 }
980
981 DEFINE_TRACE(DragController) 997 DEFINE_TRACE(DragController)
982 { 998 {
983 visitor->trace(m_page); 999 visitor->trace(m_page);
984 visitor->trace(m_documentUnderMouse); 1000 visitor->trace(m_documentUnderMouse);
985 visitor->trace(m_dragInitiator); 1001 visitor->trace(m_dragInitiator);
986 visitor->trace(m_fileInputElementUnderMouse); 1002 visitor->trace(m_fileInputElementUnderMouse);
987 } 1003 }
988 1004
989 } // namespace blink 1005 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698