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 "core/frame/WebFrameWidgetBase.h" | 5 #include "core/frame/WebFrameWidgetBase.h" |
| 6 | 6 |
| 7 #include "core/dom/DocumentUserGestureToken.h" | 7 #include "core/dom/DocumentUserGestureToken.h" |
| 8 #include "core/events/WebInputEventConversion.h" | 8 #include "core/events/WebInputEventConversion.h" |
| 9 #include "core/exported/WebViewBase.h" | 9 #include "core/exported/WebViewBase.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/frame/VisualViewport.h" | 11 #include "core/frame/VisualViewport.h" |
| 12 #include "core/frame/WebLocalFrameBase.h" | 12 #include "core/frame/WebLocalFrameBase.h" |
| 13 #include "core/input/EventHandler.h" | 13 #include "core/input/EventHandler.h" |
| 14 #include "core/page/DragActions.h" | 14 #include "core/page/DragActions.h" |
| 15 #include "core/page/DragController.h" | 15 #include "core/page/DragController.h" |
| 16 #include "core/page/DragData.h" | 16 #include "core/page/DragData.h" |
| 17 #include "core/page/DragSession.h" | 17 #include "core/page/DragSession.h" |
| 18 #include "core/page/FocusController.h" | |
| 18 #include "core/page/Page.h" | 19 #include "core/page/Page.h" |
| 19 #include "core/page/PointerLockController.h" | 20 #include "core/page/PointerLockController.h" |
| 20 #include "platform/UserGestureIndicator.h" | 21 #include "platform/UserGestureIndicator.h" |
| 21 #include "public/web/WebWidgetClient.h" | 22 #include "public/web/WebWidgetClient.h" |
| 22 | 23 |
| 23 namespace blink { | 24 namespace blink { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Helper to get LocalFrame* from WebLocalFrame*. | 28 // Helper to get LocalFrame* from WebLocalFrame*. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 WebViewBase* WebFrameWidgetBase::View() const { | 229 WebViewBase* WebFrameWidgetBase::View() const { |
| 229 return ToWebLocalFrameBase(LocalRoot())->ViewImpl(); | 230 return ToWebLocalFrameBase(LocalRoot())->ViewImpl(); |
| 230 } | 231 } |
| 231 | 232 |
| 232 Page* WebFrameWidgetBase::GetPage() const { | 233 Page* WebFrameWidgetBase::GetPage() const { |
| 233 return View()->GetPage(); | 234 return View()->GetPage(); |
| 234 } | 235 } |
| 235 | 236 |
| 236 void WebFrameWidgetBase::DidAcquirePointerLock() { | 237 void WebFrameWidgetBase::DidAcquirePointerLock() { |
| 237 GetPage()->GetPointerLockController().DidAcquirePointerLock(); | 238 GetPage()->GetPointerLockController().DidAcquirePointerLock(); |
| 239 | |
| 240 LocalFrame* focusedFrame = FocusedLocalFrameInWidget(); | |
| 241 if (focusedFrame) { | |
| 242 focusedFrame->GetEventHandler().ReleaseMousePointerCapture(); | |
| 243 } | |
| 238 } | 244 } |
| 239 | 245 |
| 240 void WebFrameWidgetBase::DidNotAcquirePointerLock() { | 246 void WebFrameWidgetBase::DidNotAcquirePointerLock() { |
| 241 GetPage()->GetPointerLockController().DidNotAcquirePointerLock(); | 247 GetPage()->GetPointerLockController().DidNotAcquirePointerLock(); |
| 242 } | 248 } |
| 243 | 249 |
| 244 void WebFrameWidgetBase::DidLosePointerLock() { | 250 void WebFrameWidgetBase::DidLosePointerLock() { |
| 245 pointer_lock_gesture_token_.Clear(); | 251 pointer_lock_gesture_token_.Clear(); |
| 246 GetPage()->GetPointerLockController().DidLosePointerLock(); | 252 GetPage()->GetPointerLockController().DidLosePointerLock(); |
| 247 } | 253 } |
| 248 | 254 |
| 249 void WebFrameWidgetBase::PointerLockMouseEvent(const WebInputEvent& event) { | 255 // TODO(665924): Remove direct dispatches of mouse events from |
| 256 // PointerLockController, instead passing them through EventHandler. | |
| 257 void WebFrameWidgetBase::PointerLockMouseEvent( | |
|
scheib
2017/05/26 05:44:12
NOTE: I'm not familiar enough with this code, and
| |
| 258 const WebCoalescedInputEvent& coalesced_event) { | |
|
Navid Zolghadr
2017/05/25 16:59:15
I love the idea that you changed this to WebCoales
lanwei
2017/05/29 18:30:07
Done.
| |
| 259 const WebInputEvent& input_event = coalesced_event.Event(); | |
| 260 const WebMouseEvent& mouse_event = | |
| 261 static_cast<const WebMouseEvent&>(input_event); | |
| 262 WebMouseEvent transformed_event = TransformWebMouseEvent( | |
| 263 ToWebLocalFrameBase(LocalRoot())->GetFrameView(), mouse_event); | |
| 264 | |
| 265 LocalFrame* focusedFrame = FocusedLocalFrameInWidget(); | |
| 266 if (focusedFrame) { | |
| 267 Vector<WebMouseEvent> transformed_coalesced_events = | |
| 268 TransformWebMouseEventVector( | |
| 269 ToWebLocalFrameBase(LocalRoot())->GetFrameView(), | |
| 270 coalesced_event.GetCoalescedEventsPointers()); | |
| 271 focusedFrame->GetEventHandler().ProcessPendingPointerCapture( | |
| 272 transformed_event, transformed_coalesced_events); | |
| 273 } | |
| 274 | |
| 250 std::unique_ptr<UserGestureIndicator> gesture_indicator; | 275 std::unique_ptr<UserGestureIndicator> gesture_indicator; |
| 251 AtomicString event_type; | 276 AtomicString event_type; |
| 252 switch (event.GetType()) { | 277 switch (input_event.GetType()) { |
| 253 case WebInputEvent::kMouseDown: | 278 case WebInputEvent::kMouseDown: |
| 254 event_type = EventTypeNames::mousedown; | 279 event_type = EventTypeNames::mousedown; |
| 255 if (!GetPage() || !GetPage()->GetPointerLockController().GetElement()) | 280 if (!GetPage() || !GetPage()->GetPointerLockController().GetElement()) |
| 256 break; | 281 break; |
| 257 gesture_indicator = WTF::WrapUnique(new UserGestureIndicator( | 282 gesture_indicator = WTF::WrapUnique(new UserGestureIndicator( |
| 258 DocumentUserGestureToken::Create(&GetPage() | 283 DocumentUserGestureToken::Create(&GetPage() |
| 259 ->GetPointerLockController() | 284 ->GetPointerLockController() |
| 260 .GetElement() | 285 .GetElement() |
| 261 ->GetDocument(), | 286 ->GetDocument(), |
| 262 UserGestureToken::kNewGesture))); | 287 UserGestureToken::kNewGesture))); |
| 263 pointer_lock_gesture_token_ = gesture_indicator->CurrentToken(); | 288 pointer_lock_gesture_token_ = gesture_indicator->CurrentToken(); |
| 264 break; | 289 break; |
| 265 case WebInputEvent::kMouseUp: | 290 case WebInputEvent::kMouseUp: |
| 266 event_type = EventTypeNames::mouseup; | 291 event_type = EventTypeNames::mouseup; |
| 267 gesture_indicator = WTF::WrapUnique( | 292 gesture_indicator = WTF::WrapUnique( |
| 268 new UserGestureIndicator(pointer_lock_gesture_token_.Release())); | 293 new UserGestureIndicator(pointer_lock_gesture_token_.Release())); |
| 269 break; | 294 break; |
| 270 case WebInputEvent::kMouseMove: | 295 case WebInputEvent::kMouseMove: |
| 271 event_type = EventTypeNames::mousemove; | 296 event_type = EventTypeNames::mousemove; |
| 272 break; | 297 break; |
| 273 default: | 298 default: |
| 274 NOTREACHED(); | 299 NOTREACHED(); |
| 275 } | 300 } |
| 276 | 301 |
| 277 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); | |
| 278 | |
| 279 if (GetPage()) { | 302 if (GetPage()) { |
| 280 WebMouseEvent transformed_event = TransformWebMouseEvent( | |
| 281 ToWebLocalFrameBase(LocalRoot())->GetFrameView(), mouse_event); | |
| 282 GetPage()->GetPointerLockController().DispatchLockedMouseEvent( | 303 GetPage()->GetPointerLockController().DispatchLockedMouseEvent( |
| 283 transformed_event, event_type); | 304 transformed_event, event_type); |
| 284 } | 305 } |
| 285 } | 306 } |
| 286 | 307 |
| 308 LocalFrame* WebFrameWidgetBase::FocusedLocalFrameInWidget() const { | |
| 309 LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame(); | |
| 310 return (frame && frame->LocalFrameRoot() == ToCoreFrame(LocalRoot())) | |
| 311 ? frame | |
| 312 : nullptr; | |
| 313 } | |
| 314 | |
| 287 } // namespace blink | 315 } // namespace blink |
| OLD | NEW |