Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; |
| 85 | |
| 86 page()->dragController().dragEnded(); | |
| 87 m_doingDragAndDrop = false; | |
| 60 } | 88 } |
| 61 | 89 |
| 62 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, | 90 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, |
| 63 const WebPoint& pointInViewport, | 91 const WebPoint& pointInViewport, |
| 64 const WebPoint& screenPoint, | 92 const WebPoint& screenPoint, |
| 65 int modifiers) { | 93 int modifiers) { |
| 66 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | 94 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); |
| 67 | 95 |
| 68 DCHECK(m_currentDragData); | 96 DCHECK(m_currentDragData); |
| 69 m_currentDragData = DataObject::create(webDragData); | 97 m_currentDragData = DataObject::create(webDragData); |
| 70 WebViewImpl::UserGestureNotifier notifier(view()); | 98 WebViewImpl::UserGestureNotifier notifier(view()); |
| 71 | 99 |
| 72 // If this webview transitions from the "drop accepting" state to the "not | 100 // If this webview transitions from the "drop accepting" state to the "not |
| 73 // accepting" state, then our IPC message reply indicating that may be in- | 101 // accepting" state, then our IPC message reply indicating that may be in- |
| 74 // flight, or else delayed by javascript processing in this webview. If a | 102 // flight, or else delayed by javascript processing in this webview. If a |
| 75 // drop happens before our IPC reply has reached the browser process, then | 103 // drop happens before our IPC reply has reached the browser process, then |
| 76 // the browser forwards the drop to this webview. So only allow a drop to | 104 // the browser forwards the drop to this webview. So only allow a drop to |
| 77 // proceed if our webview m_dragOperation state is not DragOperationNone. | 105 // proceed if our webview m_dragOperation state is not DragOperationNone. |
| 78 | 106 |
| 79 if (m_dragOperation == WebDragOperationNone) { | 107 if (m_dragOperation == WebDragOperationNone) { |
| 80 // IPC RACE CONDITION: do not allow this drop. | 108 // IPC RACE CONDITION: do not allow this drop. |
| 81 dragTargetDragLeave(); | 109 dragTargetDragLeave(); |
| 82 return; | 110 return; |
| 83 } | 111 } |
| 84 | 112 |
| 85 m_currentDragData->setModifiers(modifiers); | 113 m_currentDragData->setModifiers(modifiers); |
| 86 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | 114 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, |
| 87 static_cast<DragOperation>(m_operationsAllowed)); | 115 static_cast<DragOperation>(m_operationsAllowed)); |
| 88 | 116 |
| 89 page()->dragController().performDrag(&dragData); | 117 page()->dragController().performDrag(&dragData, *toCoreFrame(localRoot())); |
| 90 | 118 |
| 91 m_dragOperation = WebDragOperationNone; | 119 m_dragOperation = WebDragOperationNone; |
| 92 m_currentDragData = nullptr; | 120 m_currentDragData = nullptr; |
| 121 | |
| 122 page()->dragController().dragEnded(); | |
|
dcheng
2016/11/17 21:58:13
I'm having trouble understanding why the dragEnded
paulmeyer
2016/11/18 01:25:54
Okay, I was able to remove this.
| |
| 123 m_doingDragAndDrop = false; | |
| 93 } | 124 } |
| 94 | 125 |
| 95 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, | 126 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, |
| 96 const WebPoint& screenPoint, | 127 const WebPoint& screenPoint, |
| 97 WebDragOperation operation) { | 128 WebDragOperation operation) { |
| 98 WebPoint pointInRootFrame( | 129 WebPoint pointInRootFrame( |
| 99 page()->frameHost().visualViewport().viewportToRootFrame( | 130 page()->frameHost().visualViewport().viewportToRootFrame( |
| 100 pointInViewport)); | 131 pointInViewport)); |
| 101 PlatformMouseEvent pme( | 132 PlatformMouseEvent pme( |
| 102 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, | 133 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, |
| 103 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, | 134 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, |
| 104 PlatformMouseEvent::RealOrIndistinguishable, | 135 PlatformMouseEvent::RealOrIndistinguishable, |
| 105 WTF::monotonicallyIncreasingTime()); | 136 WTF::monotonicallyIncreasingTime()); |
| 106 page()->deprecatedLocalMainFrame()->eventHandler().dragSourceEndedAt( | 137 toCoreFrame(localRoot()) |
| 107 pme, static_cast<DragOperation>(operation)); | 138 ->eventHandler() |
| 139 .dragSourceEndedAt(pme, static_cast<DragOperation>(operation)); | |
| 108 } | 140 } |
| 109 | 141 |
| 110 void WebFrameWidgetBase::dragSourceSystemDragEnded() { | 142 void WebFrameWidgetBase::dragSourceSystemDragEnded() { |
| 111 // It's possible for us to get this callback while not doing a drag if it's | 143 // 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. | 144 // from a previous page that got unloaded. |
| 113 if (view()->doingDragAndDrop()) { | 145 if (m_doingDragAndDrop) { |
| 114 page()->dragController().dragEnded(); | 146 page()->dragController().dragEnded(); |
| 115 view()->setDoingDragAndDrop(false); | 147 m_doingDragAndDrop = false; |
| 116 } | 148 } |
| 117 } | 149 } |
| 118 | 150 |
| 151 void WebFrameWidgetBase::startDragging(WebReferrerPolicy policy, | |
| 152 const WebDragData& data, | |
| 153 WebDragOperationsMask mask, | |
| 154 const WebImage& dragImage, | |
| 155 const WebPoint& dragImageOffset) { | |
| 156 m_doingDragAndDrop = true; | |
| 157 client()->startDragging(policy, data, mask, dragImage, dragImageOffset); | |
| 158 } | |
| 159 | |
| 119 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( | 160 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( |
| 120 const WebPoint& pointInViewport, | 161 const WebPoint& pointInViewport, |
| 121 const WebPoint& screenPoint, | 162 const WebPoint& screenPoint, |
| 122 DragAction dragAction, | 163 DragAction dragAction, |
| 123 int modifiers) { | 164 int modifiers) { |
| 124 DCHECK(m_currentDragData); | 165 DCHECK(m_currentDragData); |
| 125 | 166 |
| 126 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | 167 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); |
| 127 | 168 |
| 169 m_doingDragAndDrop = true; | |
| 128 m_currentDragData->setModifiers(modifiers); | 170 m_currentDragData->setModifiers(modifiers); |
| 129 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | 171 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, |
| 130 static_cast<DragOperation>(m_operationsAllowed)); | 172 static_cast<DragOperation>(m_operationsAllowed)); |
| 131 | 173 |
| 132 DragSession dragSession; | 174 DragSession dragSession; |
| 133 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData); | 175 dragSession = page()->dragController().dragEnteredOrUpdated( |
| 176 &dragData, *toCoreFrame(localRoot())); | |
| 134 | 177 |
| 135 DragOperation dropEffect = dragSession.operation; | 178 DragOperation dropEffect = dragSession.operation; |
| 136 | 179 |
| 137 // Mask the drop effect operation against the drag source's allowed | 180 // Mask the drop effect operation against the drag source's allowed |
| 138 // operations. | 181 // operations. |
| 139 if (!(dropEffect & dragData.draggingSourceOperationMask())) | 182 if (!(dropEffect & dragData.draggingSourceOperationMask())) |
| 140 dropEffect = DragOperationNone; | 183 dropEffect = DragOperationNone; |
| 141 | 184 |
| 142 m_dragOperation = static_cast<WebDragOperation>(dropEffect); | 185 m_dragOperation = static_cast<WebDragOperation>(dropEffect); |
| 143 | 186 |
| 144 return m_dragOperation; | 187 return m_dragOperation; |
| 145 } | 188 } |
| 146 | 189 |
| 147 WebPoint WebFrameWidgetBase::viewportToRootFrame( | 190 WebPoint WebFrameWidgetBase::viewportToRootFrame( |
| 148 const WebPoint& pointInViewport) const { | 191 const WebPoint& pointInViewport) const { |
| 149 return page()->frameHost().visualViewport().viewportToRootFrame( | 192 return page()->frameHost().visualViewport().viewportToRootFrame( |
| 150 pointInViewport); | 193 pointInViewport); |
| 151 } | 194 } |
| 152 | 195 |
| 153 WebViewImpl* WebFrameWidgetBase::view() const { | 196 WebViewImpl* WebFrameWidgetBase::view() const { |
| 154 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl(); | 197 return toWebLocalFrameImpl(localRoot())->viewImpl(); |
| 155 } | 198 } |
| 156 | 199 |
| 157 Page* WebFrameWidgetBase::page() const { | 200 Page* WebFrameWidgetBase::page() const { |
| 158 return view()->page(); | 201 return view()->page(); |
| 159 } | 202 } |
| 160 | 203 |
| 161 } // namespace blink | 204 } // namespace blink |
| OLD | NEW |