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 // Ensure that the WebDragOperation enum values stay in sync with the original | |
| 24 // DragOperation constants. | |
| 25 #define STATIC_ASSERT_ENUM(a, b) \ | |
| 26 static_assert(static_cast<int>(a) == static_cast<int>(b), \ | |
| 27 "mismatching enum : " #a) | |
| 28 STATIC_ASSERT_ENUM(DragOperationNone, WebDragOperationNone); | |
| 29 STATIC_ASSERT_ENUM(DragOperationCopy, WebDragOperationCopy); | |
| 30 STATIC_ASSERT_ENUM(DragOperationLink, WebDragOperationLink); | |
| 31 STATIC_ASSERT_ENUM(DragOperationGeneric, WebDragOperationGeneric); | |
| 32 STATIC_ASSERT_ENUM(DragOperationPrivate, WebDragOperationPrivate); | |
| 33 STATIC_ASSERT_ENUM(DragOperationMove, WebDragOperationMove); | |
| 34 STATIC_ASSERT_ENUM(DragOperationDelete, WebDragOperationDelete); | |
| 35 STATIC_ASSERT_ENUM(DragOperationEvery, WebDragOperationEvery); | |
| 36 | |
| 22 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter( | 37 WebDragOperation WebFrameWidgetBase::dragTargetDragEnter( |
| 23 const WebDragData& webDragData, | 38 const WebDragData& webDragData, |
| 24 const WebPoint& pointInViewport, | 39 const WebPoint& pointInViewport, |
| 25 const WebPoint& screenPoint, | 40 const WebPoint& screenPoint, |
| 26 WebDragOperationsMask operationsAllowed, | 41 WebDragOperationsMask operationsAllowed, |
| 27 int modifiers) { | 42 int modifiers) { |
| 28 DCHECK(!m_currentDragData); | 43 // TODO(paulmeyer): DragEnter is received twice when starting a drag in an |
| 44 // OOPIF, which results in |m_currentDragData| being set twice. Once this is | |
| 45 // corrected, "DCHECK(!m_currentDragData);" should be added here. | |
|
dcheng
2016/11/17 20:30:29
What's causing this to be called twice?
paulmeyer
2016/11/17 21:14:45
Sorry, that's not true anymore. This TODO was in h
| |
| 29 | 46 |
| 30 m_currentDragData = DataObject::create(webDragData); | 47 m_currentDragData = DataObject::create(webDragData); |
| 31 m_operationsAllowed = operationsAllowed; | 48 m_operationsAllowed = operationsAllowed; |
| 32 | 49 |
| 33 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragEnter, | 50 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragEnter, |
| 34 modifiers); | 51 modifiers); |
| 35 } | 52 } |
| 36 | 53 |
| 37 WebDragOperation WebFrameWidgetBase::dragTargetDragOver( | 54 WebDragOperation WebFrameWidgetBase::dragTargetDragOver( |
| 38 const WebPoint& pointInViewport, | 55 const WebPoint& pointInViewport, |
| 39 const WebPoint& screenPoint, | 56 const WebPoint& screenPoint, |
| 40 WebDragOperationsMask operationsAllowed, | 57 WebDragOperationsMask operationsAllowed, |
| 41 int modifiers) { | 58 int modifiers) { |
| 42 m_operationsAllowed = operationsAllowed; | 59 m_operationsAllowed = operationsAllowed; |
| 43 | 60 |
| 44 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver, | 61 return dragTargetDragEnterOrOver(pointInViewport, screenPoint, DragOver, |
| 45 modifiers); | 62 modifiers); |
| 46 } | 63 } |
| 47 | 64 |
| 48 void WebFrameWidgetBase::dragTargetDragLeave() { | 65 void WebFrameWidgetBase::dragTargetDragLeave() { |
| 49 DCHECK(m_currentDragData); | 66 DCHECK(m_currentDragData); |
| 50 | 67 |
| 51 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(), | 68 DragData dragData(m_currentDragData.get(), IntPoint(), IntPoint(), |
| 52 static_cast<DragOperation>(m_operationsAllowed)); | 69 static_cast<DragOperation>(m_operationsAllowed)); |
| 53 | 70 |
| 54 page()->dragController().dragExited(&dragData); | 71 page()->dragController().dragExited(&dragData, *localFrameRoot()); |
| 55 | 72 |
| 56 // FIXME: why is the drag scroll timer not stopped here? | 73 // FIXME: why is the drag scroll timer not stopped here? |
| 57 | 74 |
| 58 m_dragOperation = WebDragOperationNone; | 75 m_dragOperation = WebDragOperationNone; |
| 59 m_currentDragData = nullptr; | 76 m_currentDragData = nullptr; |
| 77 | |
| 78 page()->dragController().dragEnded(); | |
| 79 m_doingDragAndDrop = false; | |
| 60 } | 80 } |
| 61 | 81 |
| 62 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, | 82 void WebFrameWidgetBase::dragTargetDrop(const WebDragData& webDragData, |
| 63 const WebPoint& pointInViewport, | 83 const WebPoint& pointInViewport, |
| 64 const WebPoint& screenPoint, | 84 const WebPoint& screenPoint, |
| 65 int modifiers) { | 85 int modifiers) { |
| 66 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | 86 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); |
| 67 | 87 |
| 68 DCHECK(m_currentDragData); | 88 DCHECK(m_currentDragData); |
| 69 m_currentDragData = DataObject::create(webDragData); | 89 m_currentDragData = DataObject::create(webDragData); |
| 70 WebViewImpl::UserGestureNotifier notifier(view()); | 90 WebViewImpl::UserGestureNotifier notifier(view()); |
| 71 | 91 |
| 72 // If this webview transitions from the "drop accepting" state to the "not | 92 // 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- | 93 // 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 | 94 // 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 | 95 // 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 | 96 // 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. | 97 // proceed if our webview m_dragOperation state is not DragOperationNone. |
| 78 | 98 |
| 79 if (m_dragOperation == WebDragOperationNone) { | 99 if (m_dragOperation == WebDragOperationNone) { |
| 80 // IPC RACE CONDITION: do not allow this drop. | 100 // IPC RACE CONDITION: do not allow this drop. |
| 81 dragTargetDragLeave(); | 101 dragTargetDragLeave(); |
| 82 return; | 102 return; |
| 83 } | 103 } |
| 84 | 104 |
| 85 m_currentDragData->setModifiers(modifiers); | 105 m_currentDragData->setModifiers(modifiers); |
| 86 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | 106 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, |
| 87 static_cast<DragOperation>(m_operationsAllowed)); | 107 static_cast<DragOperation>(m_operationsAllowed)); |
| 88 | 108 |
| 89 page()->dragController().performDrag(&dragData); | 109 page()->dragController().performDrag(&dragData, *localFrameRoot()); |
| 90 | 110 |
| 91 m_dragOperation = WebDragOperationNone; | 111 m_dragOperation = WebDragOperationNone; |
| 92 m_currentDragData = nullptr; | 112 m_currentDragData = nullptr; |
| 113 | |
| 114 page()->dragController().dragEnded(); | |
| 115 m_doingDragAndDrop = false; | |
| 93 } | 116 } |
| 94 | 117 |
| 95 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, | 118 void WebFrameWidgetBase::dragSourceEndedAt(const WebPoint& pointInViewport, |
| 96 const WebPoint& screenPoint, | 119 const WebPoint& screenPoint, |
| 97 WebDragOperation operation) { | 120 WebDragOperation operation) { |
| 98 WebPoint pointInRootFrame( | 121 WebPoint pointInRootFrame( |
| 99 page()->frameHost().visualViewport().viewportToRootFrame( | 122 page()->frameHost().visualViewport().viewportToRootFrame( |
| 100 pointInViewport)); | 123 pointInViewport)); |
| 101 PlatformMouseEvent pme( | 124 PlatformMouseEvent pme( |
| 102 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, | 125 pointInRootFrame, screenPoint, WebPointerProperties::Button::Left, |
| 103 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, | 126 PlatformEvent::MouseMoved, 0, PlatformEvent::NoModifiers, |
| 104 PlatformMouseEvent::RealOrIndistinguishable, | 127 PlatformMouseEvent::RealOrIndistinguishable, |
| 105 WTF::monotonicallyIncreasingTime()); | 128 WTF::monotonicallyIncreasingTime()); |
| 106 page()->deprecatedLocalMainFrame()->eventHandler().dragSourceEndedAt( | 129 localFrameRoot()->eventHandler().dragSourceEndedAt( |
| 107 pme, static_cast<DragOperation>(operation)); | 130 pme, static_cast<DragOperation>(operation)); |
| 108 } | 131 } |
| 109 | 132 |
| 110 void WebFrameWidgetBase::dragSourceSystemDragEnded() { | 133 void WebFrameWidgetBase::dragSourceSystemDragEnded() { |
| 111 // It's possible for us to get this callback while not doing a drag if it's | 134 // 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. | 135 // from a previous page that got unloaded. |
| 113 if (view()->doingDragAndDrop()) { | 136 if (m_doingDragAndDrop) { |
| 114 page()->dragController().dragEnded(); | 137 page()->dragController().dragEnded(); |
| 115 view()->setDoingDragAndDrop(false); | 138 m_doingDragAndDrop = false; |
| 116 } | 139 } |
| 117 } | 140 } |
| 118 | 141 |
| 142 void WebFrameWidgetBase::startDragging(WebReferrerPolicy policy, | |
| 143 const WebDragData& data, | |
| 144 WebDragOperationsMask mask, | |
| 145 const WebImage& dragImage, | |
| 146 const WebPoint& dragImageOffset) { | |
| 147 m_doingDragAndDrop = true; | |
| 148 client()->startDragging(policy, data, mask, dragImage, dragImageOffset); | |
| 149 } | |
| 150 | |
| 119 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( | 151 WebDragOperation WebFrameWidgetBase::dragTargetDragEnterOrOver( |
| 120 const WebPoint& pointInViewport, | 152 const WebPoint& pointInViewport, |
| 121 const WebPoint& screenPoint, | 153 const WebPoint& screenPoint, |
| 122 DragAction dragAction, | 154 DragAction dragAction, |
| 123 int modifiers) { | 155 int modifiers) { |
| 124 DCHECK(m_currentDragData); | 156 DCHECK(m_currentDragData); |
| 125 | 157 |
| 126 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); | 158 WebPoint pointInRootFrame(viewportToRootFrame(pointInViewport)); |
| 127 | 159 |
| 160 m_doingDragAndDrop = true; | |
| 128 m_currentDragData->setModifiers(modifiers); | 161 m_currentDragData->setModifiers(modifiers); |
| 129 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, | 162 DragData dragData(m_currentDragData.get(), pointInRootFrame, screenPoint, |
| 130 static_cast<DragOperation>(m_operationsAllowed)); | 163 static_cast<DragOperation>(m_operationsAllowed)); |
| 131 | 164 |
| 132 DragSession dragSession; | 165 DragSession dragSession; |
| 133 dragSession = page()->dragController().dragEnteredOrUpdated(&dragData); | 166 dragSession = page()->dragController().dragEnteredOrUpdated( |
| 167 &dragData, *localFrameRoot()); | |
| 134 | 168 |
| 135 DragOperation dropEffect = dragSession.operation; | 169 DragOperation dropEffect = dragSession.operation; |
| 136 | 170 |
| 137 // Mask the drop effect operation against the drag source's allowed | 171 // Mask the drop effect operation against the drag source's allowed |
| 138 // operations. | 172 // operations. |
| 139 if (!(dropEffect & dragData.draggingSourceOperationMask())) | 173 if (!(dropEffect & dragData.draggingSourceOperationMask())) |
| 140 dropEffect = DragOperationNone; | 174 dropEffect = DragOperationNone; |
| 141 | 175 |
| 142 m_dragOperation = static_cast<WebDragOperation>(dropEffect); | 176 m_dragOperation = static_cast<WebDragOperation>(dropEffect); |
| 143 | 177 |
| 144 return m_dragOperation; | 178 return m_dragOperation; |
| 145 } | 179 } |
| 146 | 180 |
| 147 WebPoint WebFrameWidgetBase::viewportToRootFrame( | 181 WebPoint WebFrameWidgetBase::viewportToRootFrame( |
| 148 const WebPoint& pointInViewport) const { | 182 const WebPoint& pointInViewport) const { |
| 149 return page()->frameHost().visualViewport().viewportToRootFrame( | 183 return page()->frameHost().visualViewport().viewportToRootFrame( |
| 150 pointInViewport); | 184 pointInViewport); |
| 151 } | 185 } |
| 152 | 186 |
| 187 LocalFrame* WebFrameWidgetBase::localFrameRoot() const { | |
| 188 return toWebLocalFrameImpl(localRoot())->frame(); | |
|
dcheng
2016/11/17 20:30:29
Nit: the naming here is a bit confusing, we hvae b
paulmeyer
2016/11/17 21:14:45
I had named it in line with the function with the
| |
| 189 } | |
| 190 | |
| 153 WebViewImpl* WebFrameWidgetBase::view() const { | 191 WebViewImpl* WebFrameWidgetBase::view() const { |
| 154 return static_cast<WebLocalFrameImpl*>(localRoot())->viewImpl(); | 192 return toWebLocalFrameImpl(localRoot())->viewImpl(); |
| 155 } | 193 } |
| 156 | 194 |
| 157 Page* WebFrameWidgetBase::page() const { | 195 Page* WebFrameWidgetBase::page() const { |
| 158 return view()->page(); | 196 return view()->page(); |
| 159 } | 197 } |
| 160 | 198 |
| 161 } // namespace blink | 199 } // namespace blink |
| OLD | NEW |