| 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 = TransformWebGestureEvent( |
| 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 = WTF::wrapUnique(new IntPoint(roundedIntPoint( | 503 WebFloatPoint gesturePosition = scaledEvent.positionInRootFrame(); |
| 504 gestureEvent.position() + frameView->getScrollOffset()))); | 504 m_lastPinchAnchorCss = WTF::wrapUnique(new IntPoint( |
| 505 roundedIntPoint(gesturePosition + frameView->getScrollOffset()))); |
| 505 m_lastPinchAnchorDip = | 506 m_lastPinchAnchorDip = |
| 506 WTF::wrapUnique(new IntPoint(gestureEvent.position())); | 507 WTF::wrapUnique(new IntPoint(flooredIntPoint(gesturePosition))); |
| 507 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); | 508 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); |
| 508 } | 509 } |
| 509 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && | 510 if (scaledEvent.type == WebInputEvent::GesturePinchUpdate && |
| 510 m_lastPinchAnchorCss) { | 511 m_lastPinchAnchorCss) { |
| 511 float newPageScaleFactor = pageScaleFactor * gestureEvent.scale(); | 512 float newPageScaleFactor = pageScaleFactor * scaledEvent.pinchScale(); |
| 512 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); | 513 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); |
| 513 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); | 514 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); |
| 514 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); | 515 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); |
| 515 m_webViewImpl->mainFrame()->setScrollOffset( | 516 m_webViewImpl->mainFrame()->setScrollOffset( |
| 516 toIntSize(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss))); | 517 toIntSize(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss))); |
| 517 } | 518 } |
| 518 if (gestureEvent.type() == PlatformEvent::GesturePinchEnd) { | 519 if (scaledEvent.type == WebInputEvent::GesturePinchEnd) { |
| 519 m_lastPinchAnchorCss.reset(); | 520 m_lastPinchAnchorCss.reset(); |
| 520 m_lastPinchAnchorDip.reset(); | 521 m_lastPinchAnchorDip.reset(); |
| 521 } | 522 } |
| 522 return true; | 523 return true; |
| 523 } | 524 } |
| 524 | 525 |
| 525 return false; | 526 return false; |
| 526 } | 527 } |
| 527 | 528 |
| 528 } // namespace blink | 529 } // namespace blink |
| OLD | NEW |