OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/DevToolsEmulator.h" | 5 #include "web/DevToolsEmulator.h" |
6 | 6 |
7 #include "core/frame/FrameHost.h" | 7 #include "core/frame/FrameHost.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 if (!page) | 489 if (!page) |
490 return false; | 490 return false; |
491 | 491 |
492 // FIXME: This workaround is required for touch emulation on Mac, where | 492 // FIXME: This workaround is required for touch emulation on Mac, where |
493 // compositor-side pinch handling is not enabled. See http://crbug.com/138003. | 493 // compositor-side pinch handling is not enabled. See http://crbug.com/138003. |
494 bool isPinch = inputEvent.type == WebInputEvent::GesturePinchBegin || | 494 bool isPinch = inputEvent.type == WebInputEvent::GesturePinchBegin || |
495 inputEvent.type == WebInputEvent::GesturePinchUpdate || | 495 inputEvent.type == WebInputEvent::GesturePinchUpdate || |
496 inputEvent.type == WebInputEvent::GesturePinchEnd; | 496 inputEvent.type == WebInputEvent::GesturePinchEnd; |
497 if (isPinch && m_touchEventEmulationEnabled) { | 497 if (isPinch && m_touchEventEmulationEnabled) { |
498 FrameView* frameView = page->deprecatedLocalMainFrame()->view(); | 498 FrameView* frameView = page->deprecatedLocalMainFrame()->view(); |
499 PlatformGestureEventBuilder gestureEvent( | 499 WebGestureEvent scaledEvent = ScaleWebGestureEvent( |
500 frameView, static_cast<const WebGestureEvent&>(inputEvent)); | 500 frameView, static_cast<const WebGestureEvent&>(inputEvent)); |
501 float pageScaleFactor = page->pageScaleFactor(); | 501 float pageScaleFactor = page->pageScaleFactor(); |
502 if (gestureEvent.type() == PlatformEvent::GesturePinchBegin) { | 502 if (scaledEvent.type == WebInputEvent::GesturePinchBegin) { |
503 m_lastPinchAnchorCss = wrapUnique(new IntPoint(roundedIntPoint( | 503 WebFloatPoint gesturePosition = scaledEvent.positionInRootFrame(); |
504 gestureEvent.position() + frameView->scrollOffset()))); | 504 m_lastPinchAnchorCss = wrapUnique(new IntPoint( |
505 m_lastPinchAnchorDip = wrapUnique(new IntPoint(gestureEvent.position())); | 505 roundedIntPoint(gesturePosition + frameView->scrollOffset()))); |
| 506 m_lastPinchAnchorDip = |
| 507 wrapUnique(new IntPoint(flooredIntPoint(gesturePosition))); |
506 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); | 508 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); |
507 } | 509 } |
508 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && | 510 if (scaledEvent.type == WebInputEvent::GesturePinchUpdate && |
509 m_lastPinchAnchorCss) { | 511 m_lastPinchAnchorCss) { |
510 float newPageScaleFactor = pageScaleFactor * gestureEvent.scale(); | 512 float newPageScaleFactor = pageScaleFactor * scaledEvent.pinchScale(); |
511 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); | 513 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); |
512 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); | 514 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); |
513 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); | 515 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); |
514 m_webViewImpl->mainFrame()->setScrollOffset( | 516 m_webViewImpl->mainFrame()->setScrollOffset( |
515 toIntSize(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss))); | 517 toIntSize(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss))); |
516 } | 518 } |
517 if (gestureEvent.type() == PlatformEvent::GesturePinchEnd) { | 519 if (scaledEvent.type == WebInputEvent::GesturePinchEnd) { |
518 m_lastPinchAnchorCss.reset(); | 520 m_lastPinchAnchorCss.reset(); |
519 m_lastPinchAnchorDip.reset(); | 521 m_lastPinchAnchorDip.reset(); |
520 } | 522 } |
521 return true; | 523 return true; |
522 } | 524 } |
523 | 525 |
524 return false; | 526 return false; |
525 } | 527 } |
526 | 528 |
527 } // namespace blink | 529 } // namespace blink |
OLD | NEW |