| 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" |
| 11 #include "core/page/Page.h" | 11 #include "core/page/Page.h" |
| 12 #include "core/style/ComputedStyle.h" | 12 #include "core/style/ComputedStyle.h" |
| 13 #include "platform/RuntimeEnabledFeatures.h" | 13 #include "platform/RuntimeEnabledFeatures.h" |
| 14 #include "public/platform/WebLayerTreeView.h" | 14 #include "public/platform/WebLayerTreeView.h" |
| 15 #include "web/WebInputEventConversion.h" | 15 #include "web/WebInputEventConversion.h" |
| 16 #include "web/WebLocalFrameImpl.h" | 16 #include "web/WebLocalFrameImpl.h" |
| 17 #include "web/WebSettingsImpl.h" | 17 #include "web/WebSettingsImpl.h" |
| 18 #include "web/WebViewImpl.h" | 18 #include "web/WebViewImpl.h" |
| 19 #include "wtf/PtrUtil.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS
caleFactor) | 23 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS
caleFactor) |
| 23 { | 24 { |
| 24 // Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for | 25 // Chromium on Android uses a device scale adjustment for fonts used in text
autosizing for |
| 25 // improved legibility. This function computes this adjusted value for text
autosizing. | 26 // improved legibility. This function computes this adjusted value for text
autosizing. |
| 26 // For a description of the Android device scale adjustment algorithm, see: | 27 // For a description of the Android device scale adjustment algorithm, see: |
| 27 // chrome/browser/chrome_content_browser_client.cc, GetDeviceScaleAdjustment
(...) | 28 // chrome/browser/chrome_content_browser_client.cc, GetDeviceScaleAdjustment
(...) |
| 28 if (!width || !height || !deviceScaleFactor) | 29 if (!width || !height || !deviceScaleFactor) |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return false; | 360 return false; |
| 360 | 361 |
| 361 // FIXME: This workaround is required for touch emulation on Mac, where | 362 // FIXME: This workaround is required for touch emulation on Mac, where |
| 362 // compositor-side pinch handling is not enabled. See http://crbug.com/13800
3. | 363 // compositor-side pinch handling is not enabled. See http://crbug.com/13800
3. |
| 363 bool isPinch = inputEvent.type == WebInputEvent::GesturePinchBegin || inputE
vent.type == WebInputEvent::GesturePinchUpdate || inputEvent.type == WebInputEve
nt::GesturePinchEnd; | 364 bool isPinch = inputEvent.type == WebInputEvent::GesturePinchBegin || inputE
vent.type == WebInputEvent::GesturePinchUpdate || inputEvent.type == WebInputEve
nt::GesturePinchEnd; |
| 364 if (isPinch && m_touchEventEmulationEnabled) { | 365 if (isPinch && m_touchEventEmulationEnabled) { |
| 365 FrameView* frameView = page->deprecatedLocalMainFrame()->view(); | 366 FrameView* frameView = page->deprecatedLocalMainFrame()->view(); |
| 366 PlatformGestureEventBuilder gestureEvent(frameView, static_cast<const We
bGestureEvent&>(inputEvent)); | 367 PlatformGestureEventBuilder gestureEvent(frameView, static_cast<const We
bGestureEvent&>(inputEvent)); |
| 367 float pageScaleFactor = page->pageScaleFactor(); | 368 float pageScaleFactor = page->pageScaleFactor(); |
| 368 if (gestureEvent.type() == PlatformEvent::GesturePinchBegin) { | 369 if (gestureEvent.type() == PlatformEvent::GesturePinchBegin) { |
| 369 m_lastPinchAnchorCss = adoptPtr(new IntPoint(frameView->scrollPositi
on() + gestureEvent.position())); | 370 m_lastPinchAnchorCss = wrapUnique(new IntPoint(frameView->scrollPosi
tion() + gestureEvent.position())); |
| 370 m_lastPinchAnchorDip = adoptPtr(new IntPoint(gestureEvent.position()
)); | 371 m_lastPinchAnchorDip = wrapUnique(new IntPoint(gestureEvent.position
())); |
| 371 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); | 372 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor); |
| 372 } | 373 } |
| 373 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && m_lastPi
nchAnchorCss) { | 374 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && m_lastPi
nchAnchorCss) { |
| 374 float newPageScaleFactor = pageScaleFactor * gestureEvent.scale(); | 375 float newPageScaleFactor = pageScaleFactor * gestureEvent.scale(); |
| 375 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); | 376 IntPoint anchorCss(*m_lastPinchAnchorDip.get()); |
| 376 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); | 377 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor); |
| 377 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); | 378 m_webViewImpl->setPageScaleFactor(newPageScaleFactor); |
| 378 m_webViewImpl->mainFrame()->setScrollOffset(toIntSize(*m_lastPinchAn
chorCss.get() - toIntSize(anchorCss))); | 379 m_webViewImpl->mainFrame()->setScrollOffset(toIntSize(*m_lastPinchAn
chorCss.get() - toIntSize(anchorCss))); |
| 379 } | 380 } |
| 380 if (gestureEvent.type() == PlatformEvent::GesturePinchEnd) { | 381 if (gestureEvent.type() == PlatformEvent::GesturePinchEnd) { |
| 381 m_lastPinchAnchorCss.reset(); | 382 m_lastPinchAnchorCss.reset(); |
| 382 m_lastPinchAnchorDip.reset(); | 383 m_lastPinchAnchorDip.reset(); |
| 383 } | 384 } |
| 384 return true; | 385 return true; |
| 385 } | 386 } |
| 386 | 387 |
| 387 return false; | 388 return false; |
| 388 } | 389 } |
| 389 | 390 |
| 390 } // namespace blink | 391 } // namespace blink |
| OLD | NEW |