| 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 "config.h" | 5 #include "config.h" |
| 6 #include "web/DevToolsEmulator.h" | 6 #include "web/DevToolsEmulator.h" |
| 7 | 7 |
| 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/page/Page.h" | 10 #include "core/page/Page.h" |
| 11 #include "platform/RuntimeEnabledFeatures.h" | 11 #include "platform/RuntimeEnabledFeatures.h" |
| 12 #include "public/web/WebDevToolsAgentClient.h" | |
| 13 #include "public/web/WebDeviceEmulationParams.h" | 12 #include "public/web/WebDeviceEmulationParams.h" |
| 14 #include "web/WebDevToolsAgentImpl.h" | 13 #include "web/WebDevToolsAgentImpl.h" |
| 15 #include "web/WebInputEventConversion.h" | 14 #include "web/WebInputEventConversion.h" |
| 16 #include "web/WebLocalFrameImpl.h" | 15 #include "web/WebLocalFrameImpl.h" |
| 17 #include "web/WebSettingsImpl.h" | 16 #include "web/WebSettingsImpl.h" |
| 18 #include "web/WebViewImpl.h" | 17 #include "web/WebViewImpl.h" |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS
caleFactor) | 21 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS
caleFactor) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 43 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / (kWidthForMax
FSM - kWidthForMinFSM); | 42 float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / (kWidthForMax
FSM - kWidthForMinFSM); |
| 44 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; | 43 return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 45 } | 44 } |
| 46 | 45 |
| 47 } // namespace | 46 } // namespace |
| 48 | 47 |
| 49 namespace blink { | 48 namespace blink { |
| 50 | 49 |
| 51 DevToolsEmulator::DevToolsEmulator(WebViewImpl* webViewImpl) | 50 DevToolsEmulator::DevToolsEmulator(WebViewImpl* webViewImpl) |
| 52 : m_webViewImpl(webViewImpl) | 51 : m_webViewImpl(webViewImpl) |
| 53 , m_devToolsAgent(nullptr) | |
| 54 , m_deviceMetricsEnabled(false) | 52 , m_deviceMetricsEnabled(false) |
| 55 , m_emulateMobileEnabled(false) | 53 , m_emulateMobileEnabled(false) |
| 56 , m_originalViewportEnabled(false) | 54 , m_originalViewportEnabled(false) |
| 57 , m_isOverlayScrollbarsEnabled(false) | 55 , m_isOverlayScrollbarsEnabled(false) |
| 58 , m_originalDefaultMinimumPageScaleFactor(0) | 56 , m_originalDefaultMinimumPageScaleFactor(0) |
| 59 , m_originalDefaultMaximumPageScaleFactor(0) | 57 , m_originalDefaultMaximumPageScaleFactor(0) |
| 60 , m_embedderTextAutosizingEnabled(webViewImpl->page()->settings().textAutosi
zingEnabled()) | 58 , m_embedderTextAutosizingEnabled(webViewImpl->page()->settings().textAutosi
zingEnabled()) |
| 61 , m_embedderDeviceScaleAdjustment(webViewImpl->page()->settings().deviceScal
eAdjustment()) | 59 , m_embedderDeviceScaleAdjustment(webViewImpl->page()->settings().deviceScal
eAdjustment()) |
| 62 , m_embedderPreferCompositingToLCDTextEnabled(webViewImpl->page()->settings(
).preferCompositingToLCDTextEnabled()) | 60 , m_embedderPreferCompositingToLCDTextEnabled(webViewImpl->page()->settings(
).preferCompositingToLCDTextEnabled()) |
| 63 , m_embedderUseMobileViewport(webViewImpl->page()->settings().useMobileViewp
ortStyle()) | 61 , m_embedderUseMobileViewport(webViewImpl->page()->settings().useMobileViewp
ortStyle()) |
| 64 , m_touchEventEmulationEnabled(false) | 62 , m_touchEventEmulationEnabled(false) |
| 65 , m_originalTouchEnabled(false) | 63 , m_originalTouchEnabled(false) |
| 66 , m_originalDeviceSupportsMouse(false) | 64 , m_originalDeviceSupportsMouse(false) |
| 67 , m_originalDeviceSupportsTouch(false) | 65 , m_originalDeviceSupportsTouch(false) |
| 68 , m_originalMaxTouchPoints(0) | 66 , m_originalMaxTouchPoints(0) |
| 69 , m_ignoreSetOverrides(false) | |
| 70 { | 67 { |
| 71 } | 68 } |
| 72 | 69 |
| 73 DevToolsEmulator::~DevToolsEmulator() | 70 DevToolsEmulator::~DevToolsEmulator() |
| 74 { | 71 { |
| 75 } | 72 } |
| 76 | 73 |
| 77 void DevToolsEmulator::setDevToolsAgent(WebDevToolsAgentImpl* agent) | |
| 78 { | |
| 79 m_devToolsAgent = agent; | |
| 80 } | |
| 81 | |
| 82 void DevToolsEmulator::setTextAutosizingEnabled(bool enabled) | 74 void DevToolsEmulator::setTextAutosizingEnabled(bool enabled) |
| 83 { | 75 { |
| 84 m_embedderTextAutosizingEnabled = enabled; | 76 m_embedderTextAutosizingEnabled = enabled; |
| 85 bool emulateMobileEnabled = m_deviceMetricsEnabled && m_emulateMobileEnabled
; | 77 bool emulateMobileEnabled = m_deviceMetricsEnabled && m_emulateMobileEnabled
; |
| 86 if (!emulateMobileEnabled) | 78 if (!emulateMobileEnabled) |
| 87 m_webViewImpl->page()->settings().setTextAutosizingEnabled(enabled); | 79 m_webViewImpl->page()->settings().setTextAutosizingEnabled(enabled); |
| 88 } | 80 } |
| 89 | 81 |
| 90 void DevToolsEmulator::setDeviceScaleAdjustment(float deviceScaleAdjustment) | 82 void DevToolsEmulator::setDeviceScaleAdjustment(float deviceScaleAdjustment) |
| 91 { | 83 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 104 } | 96 } |
| 105 | 97 |
| 106 void DevToolsEmulator::setUseMobileViewportStyle(bool enabled) | 98 void DevToolsEmulator::setUseMobileViewportStyle(bool enabled) |
| 107 { | 99 { |
| 108 m_embedderUseMobileViewport = enabled; | 100 m_embedderUseMobileViewport = enabled; |
| 109 bool emulateMobileEnabled = m_deviceMetricsEnabled && m_emulateMobileEnabled
; | 101 bool emulateMobileEnabled = m_deviceMetricsEnabled && m_emulateMobileEnabled
; |
| 110 if (!emulateMobileEnabled) | 102 if (!emulateMobileEnabled) |
| 111 m_webViewImpl->page()->settings().setUseMobileViewportStyle(enabled); | 103 m_webViewImpl->page()->settings().setUseMobileViewportStyle(enabled); |
| 112 } | 104 } |
| 113 | 105 |
| 114 void DevToolsEmulator::setDeviceMetricsOverride(int width, int height, float dev
iceScaleFactor, bool mobile, bool fitWindow, float scale, float offsetX, float o
ffsetY) | |
| 115 { | |
| 116 if (m_ignoreSetOverrides) | |
| 117 return; | |
| 118 WebDeviceEmulationParams params; | |
| 119 params.screenPosition = mobile ? WebDeviceEmulationParams::Mobile : WebDevic
eEmulationParams::Desktop; | |
| 120 params.deviceScaleFactor = deviceScaleFactor; | |
| 121 params.viewSize = WebSize(width, height); | |
| 122 params.fitToView = fitWindow; | |
| 123 params.scale = scale; | |
| 124 params.offset = WebFloatPoint(offsetX, offsetY); | |
| 125 | |
| 126 enableDeviceEmulationInner(params); | |
| 127 ASSERT(m_devToolsAgent); | |
| 128 m_devToolsAgent->client()->enableDeviceEmulation(params); | |
| 129 | |
| 130 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { | |
| 131 document->styleResolverChanged(); | |
| 132 document->mediaQueryAffectingValueChanged(); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void DevToolsEmulator::enableDeviceEmulation(const WebDeviceEmulationParams& par
ams) | 106 void DevToolsEmulator::enableDeviceEmulation(const WebDeviceEmulationParams& par
ams) |
| 137 { | 107 { |
| 138 m_ignoreSetOverrides = true; | |
| 139 enableDeviceEmulationInner(params); | |
| 140 m_webViewImpl->setCompositorDeviceScaleFactorOverride(params.deviceScaleFact
or); | |
| 141 m_webViewImpl->setRootLayerTransform(WebSize(params.offset.x, params.offset.
y), params.scale); | |
| 142 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { | |
| 143 document->styleResolverChanged(); | |
| 144 document->mediaQueryAffectingValueChanged(); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 void DevToolsEmulator::enableDeviceEmulationInner(const WebDeviceEmulationParams
& params) | |
| 149 { | |
| 150 if (!m_deviceMetricsEnabled) { | 108 if (!m_deviceMetricsEnabled) { |
| 151 m_deviceMetricsEnabled = true; | 109 m_deviceMetricsEnabled = true; |
| 152 m_webViewImpl->setBackgroundColorOverride(Color::darkGray); | 110 m_webViewImpl->setBackgroundColorOverride(Color::darkGray); |
| 153 m_webViewImpl->updateShowFPSCounterAndContinuousPainting(); | 111 m_webViewImpl->updateShowFPSCounterAndContinuousPainting(); |
| 154 if (m_devToolsAgent) | 112 if (WebDevToolsAgentImpl* devToolsAgent = m_webViewImpl->devToolsAgentIm
pl()) |
| 155 m_devToolsAgent->pageAgent()->setViewportNotificationsEnabled(true); | 113 devToolsAgent->pageAgent()->setViewportNotificationsEnabled(true); |
| 156 } | 114 } |
| 157 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(calculateDeviceSc
aleAdjustment(params.viewSize.width, params.viewSize.height, params.deviceScaleF
actor)); | 115 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(calculateDeviceSc
aleAdjustment(params.viewSize.width, params.viewSize.height, params.deviceScaleF
actor)); |
| 158 | 116 |
| 159 if (params.screenPosition == WebDeviceEmulationParams::Mobile) | 117 if (params.screenPosition == WebDeviceEmulationParams::Mobile) |
| 160 enableMobileEmulation(); | 118 enableMobileEmulation(); |
| 161 else | 119 else |
| 162 disableMobileEmulation(); | 120 disableMobileEmulation(); |
| 163 } | |
| 164 | 121 |
| 165 void DevToolsEmulator::clearDeviceMetricsOverride() | 122 m_webViewImpl->setCompositorDeviceScaleFactorOverride(params.deviceScaleFact
or); |
| 166 { | 123 m_webViewImpl->setRootLayerTransform(WebSize(params.offset.x, params.offset.
y), params.scale); |
| 167 if (m_ignoreSetOverrides) | |
| 168 return; | |
| 169 if (!m_deviceMetricsEnabled) | |
| 170 return; | |
| 171 | |
| 172 disableDeviceEmulationInner(); | |
| 173 ASSERT(m_devToolsAgent); | |
| 174 m_devToolsAgent->client()->disableDeviceEmulation(); | |
| 175 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { | 124 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { |
| 176 document->styleResolverChanged(); | 125 document->styleResolverChanged(); |
| 177 document->mediaQueryAffectingValueChanged(); | 126 document->mediaQueryAffectingValueChanged(); |
| 178 } | 127 } |
| 179 } | 128 } |
| 180 | 129 |
| 181 void DevToolsEmulator::disableDeviceEmulation() | 130 void DevToolsEmulator::disableDeviceEmulation() |
| 182 { | 131 { |
| 183 m_ignoreSetOverrides = true; | 132 if (!m_deviceMetricsEnabled) |
| 184 disableDeviceEmulationInner(); | 133 return; |
| 134 |
| 135 m_deviceMetricsEnabled = false; |
| 136 m_webViewImpl->setBackgroundColorOverride(Color::transparent); |
| 137 m_webViewImpl->updateShowFPSCounterAndContinuousPainting(); |
| 138 if (WebDevToolsAgentImpl* devToolsAgent = m_webViewImpl->devToolsAgentImpl()
) |
| 139 devToolsAgent->pageAgent()->setViewportNotificationsEnabled(false); |
| 140 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(m_embedderDeviceS
caleAdjustment); |
| 141 disableMobileEmulation(); |
| 185 m_webViewImpl->setCompositorDeviceScaleFactorOverride(0.f); | 142 m_webViewImpl->setCompositorDeviceScaleFactorOverride(0.f); |
| 186 m_webViewImpl->setRootLayerTransform(WebSize(0.f, 0.f), 1.f); | 143 m_webViewImpl->setRootLayerTransform(WebSize(0.f, 0.f), 1.f); |
| 187 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { | 144 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->document()
) { |
| 188 document->styleResolverChanged(); | 145 document->styleResolverChanged(); |
| 189 document->mediaQueryAffectingValueChanged(); | 146 document->mediaQueryAffectingValueChanged(); |
| 190 } | 147 } |
| 191 } | 148 } |
| 192 | 149 |
| 193 void DevToolsEmulator::disableDeviceEmulationInner() | |
| 194 { | |
| 195 if (m_deviceMetricsEnabled) { | |
| 196 m_deviceMetricsEnabled = false; | |
| 197 m_webViewImpl->setBackgroundColorOverride(Color::transparent); | |
| 198 m_webViewImpl->updateShowFPSCounterAndContinuousPainting(); | |
| 199 if (m_devToolsAgent) | |
| 200 m_devToolsAgent->pageAgent()->setViewportNotificationsEnabled(false)
; | |
| 201 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(m_embedderDev
iceScaleAdjustment); | |
| 202 disableMobileEmulation(); | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 void DevToolsEmulator::enableMobileEmulation() | 150 void DevToolsEmulator::enableMobileEmulation() |
| 207 { | 151 { |
| 208 if (m_emulateMobileEnabled) | 152 if (m_emulateMobileEnabled) |
| 209 return; | 153 return; |
| 210 m_emulateMobileEnabled = true; | 154 m_emulateMobileEnabled = true; |
| 211 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab
led(); | 155 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab
led(); |
| 212 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | 156 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); |
| 213 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled(); | 157 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled(); |
| 214 RuntimeEnabledFeatures::setCSSViewportEnabled(true); | 158 RuntimeEnabledFeatures::setCSSViewportEnabled(true); |
| 215 m_webViewImpl->enableViewport(); | 159 m_webViewImpl->enableViewport(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 m_lastPinchAnchorCss.clear(); | 236 m_lastPinchAnchorCss.clear(); |
| 293 m_lastPinchAnchorDip.clear(); | 237 m_lastPinchAnchorDip.clear(); |
| 294 } | 238 } |
| 295 return true; | 239 return true; |
| 296 } | 240 } |
| 297 | 241 |
| 298 return false; | 242 return false; |
| 299 } | 243 } |
| 300 | 244 |
| 301 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |