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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameWidgetBase.cpp

Issue 2517653003: Drag-and-drop across OOPIFs. (Closed)
Patch Set: Created 4 years, 1 month 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/WebFrameWidgetBase.h" 5 #include "web/WebFrameWidgetBase.h"
6 6
7 #include "core/frame/FrameHost.h" 7 #include "core/frame/FrameHost.h"
8 #include "core/frame/VisualViewport.h" 8 #include "core/frame/VisualViewport.h"
9 #include "core/input/EventHandler.h" 9 #include "core/input/EventHandler.h"
10 #include "core/page/DragActions.h" 10 #include "core/page/DragActions.h"
11 #include "core/page/DragController.h" 11 #include "core/page/DragController.h"
12 #include "core/page/DragData.h" 12 #include "core/page/DragData.h"
13 #include "core/page/DragSession.h" 13 #include "core/page/DragSession.h"
14 #include "core/page/Page.h" 14 #include "core/page/Page.h"
15 #include "public/web/WebAutofillClient.h" 15 #include "public/web/WebAutofillClient.h"
16 #include "public/web/WebDocument.h" 16 #include "public/web/WebDocument.h"
17 #include "public/web/WebWidgetClient.h"
17 #include "web/WebLocalFrameImpl.h" 18 #include "web/WebLocalFrameImpl.h"
18 #include "web/WebViewImpl.h" 19 #include "web/WebViewImpl.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
23 namespace {
24
25 // Helper to get LocalFrame* from WebLocalFrame*.
26 // TODO(dcheng): This should be moved into WebLocalFrame.
27 LocalFrame* toCoreFrame(WebLocalFrame* frame) {
28 return toWebLocalFrameImpl(frame)->frame();
29 }
30
31 } // namespace
32
33 // Ensure that the WebDragOperation enum values stay in sync with the original
34 // DragOperation constants.
35 #define STATIC_ASSERT_ENUM(a, b) \
36 static_assert(static_cast<int>(a) == static_cast<int>(b), \
37 "mismatching enum : " #a)
38 STATIC_ASSERT_ENUM(DragOperationNone, WebDragOperationNone);
39 STATIC_ASSERT_ENUM(DragOperationCopy, WebDragOperationCopy);
40 STATIC_ASSERT_ENUM(DragOperationLink, WebDragOperationLink);
41 STATIC_ASSERT_ENUM(DragOperationGeneric, WebDragOperationGeneric);
42 STATIC_ASSERT_ENUM(DragOperationPrivate, WebDragOperationPrivate);
43 STATIC_ASSERT_ENUM(DragOperationMove, WebDragOperationMove);
44 STATIC_ASSERT_ENUM(DragOperationDelete, WebDragOperationDelete);
45 STATIC_ASSERT_ENUM(DragOperationEvery, WebDragOperationEvery);
46
22 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter( 47 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter(
23 const WebDragData& webDragData, 48 const WebDragData& webDragData,
24 const WebPoint& pointInViewport, 49 const WebPoint& pointInViewport,
25 const WebPoint& screenPoint, 50 const WebPoint& screenPoint,
26 WebDragOperationsMask operationsAllowed, 51 WebDragOperationsMask operationsAllowed,
27 int modifiers) { 52 int modifiers) {
28 DCHECK(!m_currentDragData); 53 DCHECK(!m_currentDragData);
29 54
30 m_currentDragData = DataObject::create(webDragData); 55 m_currentDragData = DataObject::create(webDragData);
31 m_operationsAllowed = operationsAllowed; 56 m_operationsAllowed = operationsAllowed;
(...skipping 12 matching lines...) Expand all
44 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver, 69 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver,
45 modifiers); 70 modifiers);
46 } 71 }
47 72
48 void WebFrameWidgetBase::dragTargetDragLeave() { 73 void WebFrameWidgetBase::dragTargetDragLeave() {
49 DCHECK(m_currentDragData); 74 DCHECK(m_currentDragData);
50 75
51 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(), 76 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(),
52 static_cast<DragOperation>(m_operationsAllowed)); 77 static_cast<DragOperation>(m_operationsAllowed));
53 78
54 page()->dragController().dragExited(&dragData); 79 page()->dragController().dragExited(&dragData, *toCoreFrame(localRoot()));
55 80
56 // FIXME: why is the drag scroll timer not stopped here? 81 // FIXME: why is the drag scroll timer not stopped here?
57 82
58 m_dragOperation = WebDragOperationNone; 83 m_dragOperation = WebDragOperationNone;
59 m_currentDragData = nullptr; 84 m_currentDragData = nullptr;
60 } 85 }
61 86
62 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, 87 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData,
63 const WebPoint& pointInViewport, 88 const WebPoint& pointInViewport,
64 const WebPoint& screenPoint, 89 const WebPoint& screenPoint,
(...skipping 14 matching lines...) Expand all
79 if (m_dragOperation == WebDragOperationNone) { 104 if (m_dragOperation == WebDragOperationNone) {
80 // IPC RACE CONDITION: do not allow this drop. 105 // IPC RACE CONDITION: do not allow this drop.
81 dragTargetDragLeave(); 106 dragTargetDragLeave();
82 return; 107 return;
83 } 108 }
84 109
85 m_currentDragData->setModifiers(modifiers); 110 m_currentDragData->setModifiers(modifiers);
86 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, 111 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint,
87 static_cast<DragOperation>(m_operationsAllowed)); 112 static_cast<DragOperation>(m_operationsAllowed));
88 113
89 page()->dragController().performDrag(&dragData); 114 page()->dragController().performDrag(&dragData, *toCoreFrame(localRoot()));
90 115
91 m_dragOperation = WebDragOperationNone; 116 m_dragOperation = WebDragOperationNone;
92 m_currentDragData = nullptr; 117 m_currentDragData = nullptr;
93 } 118 }
94 119
95 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, 120 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport,
96 const WebPoint& screenPoint, 121 const WebPoint& screenPoint,
97 WebDragOperation operation) { 122 WebDragOperation operation) {
98 WebPoint pointInRootFrame( 123 WebPoint pointInRootFrame(
99 page()->frameHost().visualViewport().viewportToRootFrame( 124 page()->frameHost().visualViewport().viewportToRootFrame(
100 pointInViewport)); 125 pointInViewport));
101 PlatformMouseEvent pme( 126 PlatformMouseEvent pme(
102 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, 127 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left,
103 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, 128 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers,
104 PlatformMouseEvent::RealOrIndistinguishable, 129 PlatformMouseEvent::RealOrIndistinguishable,
105 WTF::monotonicallyIncreasingTime()); 130 WTF::monotonicallyIncreasingTime());
106 page()->deprecatedLocalMainFrame()->eventHandler().dragSourceEndedAt( 131 toCoreFrame(localRoot())
107 pme, static_cast<DragOperation>(operation)); 132 ->eventHandler()
133 .dragSourceEndedAt(pme, static_cast<DragOperation>(operation));
108 } 134 }
109 135
110 void WebFrameWidgetBase::dragSourceSystemDragEnded() { 136 void WebFrameWidgetBase::dragSourceSystemDragEnded() {
111 // It's possible for us to get this callback while not doing a drag if it's 137 // It's possible for us to get this callback while not doing a drag if it's
112 // from a previous page that got unloaded. 138 // from a previous page that got unloaded.
113 if (view()->doingDragAndDrop()) { 139 if (m_doingDragAndDrop) {
114 page()->dragController().dragEnded(); 140 page()->dragController().dragEnded();
115 view()->setDoingDragAndDrop(false); 141 m_doingDragAndDrop = false;
116 } 142 }
117 } 143 }
118 144
145 void WebFrameWidgetBase::startDragging(WebReferrerPolicy policy,
146 const WebDragData& data,
147 WebDragOperationsMask mask,
148 const WebImage& dragImage,
149 const WebPoint& dragImageOffset) {
150 m_doingDragAndDrop = true;
151 client()->startDragging(policy, data, mask, dragImage, dragImageOffset);
152 }
153
119 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( 154 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver(
120 const WebPoint& pointInViewport, 155 const WebPoint& pointInViewport,
121 const WebPoint& screenPoint, 156 const WebPoint& screenPoint,
122 DragAction dragAction, 157 DragAction dragAction,
123 int modifiers) { 158 int modifiers) {
124 DCHECK(m_currentDragData); 159 DCHECK(m_currentDragData);
125 160
126 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); 161 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport));
127 162
128 m_currentDragData->setModifiers(modifiers); 163 m_currentDragData->setModifiers(modifiers);
129 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, 164 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint,
130 static_cast<DragOperation>(m_operationsAllowed)); 165 static_cast<DragOperation>(m_operationsAllowed));
131 166
132 DragSession dragSession; 167 DragSession dragSession;
133 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData); 168 dragSession = page()->dragController().dragEnteredOrUpdated(
169 &dragData, *toCoreFrame(localRoot()));
134 170
135 DragOperation dropEffect = dragSession.operation; 171 DragOperation dropEffect = dragSession.operation;
136 172
137 // Mask the drop effect operation against the drag source's allowed 173 // Mask the drop effect operation against the drag source's allowed
138 // operations. 174 // operations.
139 if (!(dropEffect & dragData.draggingSourceOperationMask())) 175 if (!(dropEffect & dragData.draggingSourceOperationMask()))
140 dropEffect = DragOperationNone; 176 dropEffect = DragOperationNone;
141 177
142 m_dragOperation = static_cast<WebDragOperation>(dropEffect); 178 m_dragOperation = static_cast<WebDragOperation>(dropEffect);
143 179
144 return m_dragOperation; 180 return m_dragOperation;
145 } 181 }
146 182
147 WebPoint WebFrameWidgetBase::viewportToRootFrame( 183 WebPoint WebFrameWidgetBase::viewportToRootFrame(
148 const WebPoint& pointInViewport) const { 184 const WebPoint& pointInViewport) const {
149 return page()->frameHost().visualViewport().viewportToRootFrame( 185 return page()->frameHost().visualViewport().viewportToRootFrame(
150 pointInViewport); 186 pointInViewport);
151 } 187 }
152 188
153 WebViewImpl* WebFrameWidgetBase::view() const { 189 WebViewImpl* WebFrameWidgetBase::view() const {
154 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl(); 190 return toWebLocalFrameImpl(localRoot())->viewImpl();
155 } 191 }
156 192
157 Page* WebFrameWidgetBase::page() const { 193 Page* WebFrameWidgetBase::page() const {
158 return view()->page(); 194 return view()->page();
159 } 195 }
160 196
161 } // namespace blink 197 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebFrameWidgetBase.h ('k') | third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698