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 "platform/geometry/FloatRect.h" | |
14 #include "public/platform/WebLayerTreeView.h" | 15 #include "public/platform/WebLayerTreeView.h" |
15 #include "web/WebInputEventConversion.h" | 16 #include "web/WebInputEventConversion.h" |
16 #include "web/WebLocalFrameImpl.h" | 17 #include "web/WebLocalFrameImpl.h" |
17 #include "web/WebSettingsImpl.h" | 18 #include "web/WebSettingsImpl.h" |
18 #include "web/WebViewImpl.h" | 19 #include "web/WebViewImpl.h" |
19 #include "wtf/PtrUtil.h" | 20 #include "wtf/PtrUtil.h" |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS caleFactor) | 24 static float calculateDeviceScaleAdjustment(int width, int height, float deviceS caleFactor) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 } | 213 } |
213 | 214 |
214 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(calculateDeviceSc aleAdjustment(params.viewSize.width, params.viewSize.height, params.deviceScaleF actor)); | 215 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(calculateDeviceSc aleAdjustment(params.viewSize.width, params.viewSize.height, params.deviceScaleF actor)); |
215 | 216 |
216 if (params.screenPosition == WebDeviceEmulationParams::Mobile) | 217 if (params.screenPosition == WebDeviceEmulationParams::Mobile) |
217 enableMobileEmulation(); | 218 enableMobileEmulation(); |
218 else | 219 else |
219 disableMobileEmulation(); | 220 disableMobileEmulation(); |
220 | 221 |
221 m_webViewImpl->setCompositorDeviceScaleFactorOverride(params.deviceScaleFact or); | 222 m_webViewImpl->setCompositorDeviceScaleFactorOverride(params.deviceScaleFact or); |
222 m_webViewImpl->setRootLayerTransform(WebSize(params.offset.x, params.offset. y), params.scale); | 223 updateRootLayerTransform(); |
223 // TODO(dgozman): mainFrameImpl() is null when it's remote. Figure out how | 224 // TODO(dgozman): mainFrameImpl() is null when it's remote. Figure out how |
224 // we end up with enabling emulation in this case. | 225 // we end up with enabling emulation in this case. |
225 if (m_webViewImpl->mainFrameImpl()) { | 226 if (m_webViewImpl->mainFrameImpl()) { |
226 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->docume nt()) | 227 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->docume nt()) |
227 document->mediaQueryAffectingValueChanged(); | 228 document->mediaQueryAffectingValueChanged(); |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 void DevToolsEmulator::disableDeviceEmulation() | 232 void DevToolsEmulator::disableDeviceEmulation() |
232 { | 233 { |
233 if (!m_deviceMetricsEnabled) | 234 if (!m_deviceMetricsEnabled) |
234 return; | 235 return; |
235 | 236 |
236 m_deviceMetricsEnabled = false; | 237 m_deviceMetricsEnabled = false; |
237 m_webViewImpl->setBackgroundColorOverride(Color::transparent); | 238 m_webViewImpl->setBackgroundColorOverride(Color::transparent); |
238 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(m_embedderDeviceS caleAdjustment); | 239 m_webViewImpl->page()->settings().setDeviceScaleAdjustment(m_embedderDeviceS caleAdjustment); |
239 disableMobileEmulation(); | 240 disableMobileEmulation(); |
240 m_webViewImpl->setCompositorDeviceScaleFactorOverride(0.f); | 241 m_webViewImpl->setCompositorDeviceScaleFactorOverride(0.f); |
241 m_webViewImpl->setRootLayerTransform(WebSize(0.f, 0.f), 1.f); | |
242 m_webViewImpl->setPageScaleFactor(1.f); | 242 m_webViewImpl->setPageScaleFactor(1.f); |
243 updateRootLayerTransform(); | |
243 // mainFrameImpl() could be null during cleanup or remote <-> local swap. | 244 // mainFrameImpl() could be null during cleanup or remote <-> local swap. |
244 if (m_webViewImpl->mainFrameImpl()) { | 245 if (m_webViewImpl->mainFrameImpl()) { |
245 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->docume nt()) | 246 if (Document* document = m_webViewImpl->mainFrameImpl()->frame()->docume nt()) |
246 document->mediaQueryAffectingValueChanged(); | 247 document->mediaQueryAffectingValueChanged(); |
247 } | 248 } |
248 } | 249 } |
249 | 250 |
250 bool DevToolsEmulator::resizeIsDeviceSizeChange() | 251 bool DevToolsEmulator::resizeIsDeviceSizeChange() |
251 { | 252 { |
252 return m_deviceMetricsEnabled && m_emulateMobileEnabled; | 253 return m_deviceMetricsEnabled && m_emulateMobileEnabled; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 m_webViewImpl->setZoomFactorOverride(0); | 313 m_webViewImpl->setZoomFactorOverride(0); |
313 m_emulateMobileEnabled = false; | 314 m_emulateMobileEnabled = false; |
314 m_webViewImpl->setDefaultPageScaleLimits( | 315 m_webViewImpl->setDefaultPageScaleLimits( |
315 m_originalDefaultMinimumPageScaleFactor, | 316 m_originalDefaultMinimumPageScaleFactor, |
316 m_originalDefaultMaximumPageScaleFactor); | 317 m_originalDefaultMaximumPageScaleFactor); |
317 // mainFrameImpl() could be null during cleanup or remote <-> local swap. | 318 // mainFrameImpl() could be null during cleanup or remote <-> local swap. |
318 if (m_webViewImpl->mainFrameImpl()) | 319 if (m_webViewImpl->mainFrameImpl()) |
319 m_webViewImpl->mainFrameImpl()->frameView()->layout(); | 320 m_webViewImpl->mainFrameImpl()->frameView()->layout(); |
320 } | 321 } |
321 | 322 |
323 void DevToolsEmulator::setVisualTransformOverride(const WebFloatRect& area, floa t scale) | |
324 { | |
325 if (!m_visualTransformOverride) | |
326 m_visualTransformOverride = VisualTransformOverride(); | |
327 | |
328 m_visualTransformOverride->area = area; | |
329 m_visualTransformOverride->scale = scale; | |
330 | |
331 // Ensure that all content inside the area is painted. | |
332 if (m_webViewImpl->mainFrameImpl()) | |
333 m_webViewImpl->mainFrameImpl()->frameView()->setVisibleContentRectForPai nting(enclosingIntRect(area)); | |
chrishtr
2016/08/12 20:56:22
Why can't this be accomplished by changing the wid
Eric Seckler
2016/08/12 21:37:53
I don't think width&height would suffice, since we
chrishtr
2016/08/12 21:41:36
Why would you want it to be different than the cur
Eric Seckler
2016/08/12 21:55:36
We want to record+render only the screenshot area,
chrishtr
2016/08/12 22:03:43
Is the objection to scrolling to the desired area
Eric Seckler
2016/08/12 22:15:46
Correct. Javascript can listen for scroll events a
| |
334 | |
335 // Disable clipping on the visual viewport layer, to ensure the whole area i s painted. | |
336 GraphicsLayer* containerLayer = m_webViewImpl->page()->frameHost().visualVie wport().containerLayer(); | |
337 if (containerLayer) { | |
338 m_visualTransformOverride->originalVisualViewportMasking = containerLaye r->masksToBounds(); | |
339 containerLayer->setMasksToBounds(false); | |
340 } | |
341 | |
342 // Move the correct (scaled) content area to show in the top left of the | |
343 // CompositorFrame via the root transform. | |
344 updateRootLayerTransform(); | |
345 } | |
346 | |
347 void DevToolsEmulator::clearVisualTransformOverride() | |
348 { | |
349 if (!m_visualTransformOverride) | |
350 return; | |
351 | |
352 bool originalMasking = m_visualTransformOverride->originalVisualViewportMask ing; | |
353 m_visualTransformOverride = WTF::nullopt; | |
354 | |
355 // Restore original state. | |
356 if (m_webViewImpl->mainFrameImpl()) | |
357 m_webViewImpl->mainFrameImpl()->frameView()->resetVisibleContentRectForP ainting(); | |
358 GraphicsLayer* containerLayer = m_webViewImpl->page()->frameHost().visualVie wport().containerLayer(); | |
359 if (containerLayer) | |
360 containerLayer->setMasksToBounds(originalMasking); | |
361 updateRootLayerTransform(); | |
362 } | |
363 | |
364 void DevToolsEmulator::mainFrameScrollOrScaleChanged() | |
365 { | |
366 // Visual transform override has to take current page scale and scroll | |
367 // offset into account. Update the transform if override is active. | |
368 if (m_visualTransformOverride) | |
369 updateRootLayerTransform(); | |
370 } | |
371 | |
372 void DevToolsEmulator::applyDeviceEmulationTransform(TransformationMatrix* trans form) | |
373 { | |
374 if (m_deviceMetricsEnabled) { | |
375 WebSize offset(m_emulationParams.offset.x, m_emulationParams.offset.y); | |
376 // Scale first, so that translation is unaffected. | |
377 transform->translate(offset.width, offset.height); | |
378 transform->scale(m_emulationParams.scale); | |
379 if (m_webViewImpl->mainFrameImpl()) | |
380 m_webViewImpl->mainFrameImpl()->setInputEventsTransformForEmulation( offset, m_emulationParams.scale); | |
381 } else { | |
382 if (m_webViewImpl->mainFrameImpl()) | |
383 m_webViewImpl->mainFrameImpl()->setInputEventsTransformForEmulation( WebSize(0, 0), 1.0); | |
384 } | |
385 } | |
386 | |
387 void DevToolsEmulator::applyVisualTransformOverride(TransformationMatrix* transf orm) | |
388 { | |
389 if (!m_visualTransformOverride) | |
390 return; | |
391 | |
392 // Transform operations follow in reverse application. | |
393 // Last, scale positioned area according to override. | |
394 transform->scale(m_visualTransformOverride->scale); | |
395 | |
396 // Translate while taking into account current scroll offset. | |
397 WebSize scrollOffset = m_webViewImpl->mainFrame()->scrollOffset(); | |
398 WebFloatPoint visualOffset = m_webViewImpl->visualViewportOffset(); | |
399 float scrollX = scrollOffset.width + visualOffset.x; | |
400 float scrollY = scrollOffset.height + visualOffset.y; | |
401 transform->translate( | |
402 -m_visualTransformOverride->area.x + scrollX, | |
403 -m_visualTransformOverride->area.y + scrollY); | |
404 | |
405 // First, reverse page scale, so we don't have to take it into account for | |
406 // calculation of the translation. | |
407 transform->scale(1. / m_webViewImpl->pageScaleFactor()); | |
408 } | |
409 | |
410 void DevToolsEmulator::updateRootLayerTransform() | |
411 { | |
412 TransformationMatrix transform; | |
413 | |
414 // Apply device emulation transform first, so that it is affected by the | |
415 // visual transform override. | |
416 applyVisualTransformOverride(&transform); | |
417 applyDeviceEmulationTransform(&transform); | |
418 | |
419 m_webViewImpl->setRootLayerTransform(transform); | |
420 } | |
421 | |
322 void DevToolsEmulator::setTouchEventEmulationEnabled(bool enabled) | 422 void DevToolsEmulator::setTouchEventEmulationEnabled(bool enabled) |
323 { | 423 { |
324 if (m_touchEventEmulationEnabled == enabled) | 424 if (m_touchEventEmulationEnabled == enabled) |
325 return; | 425 return; |
326 if (!m_touchEventEmulationEnabled) { | 426 if (!m_touchEventEmulationEnabled) { |
327 m_originalTouchEnabled = RuntimeEnabledFeatures::touchEnabled(); | 427 m_originalTouchEnabled = RuntimeEnabledFeatures::touchEnabled(); |
328 m_originalDeviceSupportsMouse = m_webViewImpl->page()->settings().device SupportsMouse(); | 428 m_originalDeviceSupportsMouse = m_webViewImpl->page()->settings().device SupportsMouse(); |
329 m_originalDeviceSupportsTouch = m_webViewImpl->page()->settings().device SupportsTouch(); | 429 m_originalDeviceSupportsTouch = m_webViewImpl->page()->settings().device SupportsTouch(); |
330 m_originalMaxTouchPoints = m_webViewImpl->page()->settings().maxTouchPoi nts(); | 430 m_originalMaxTouchPoints = m_webViewImpl->page()->settings().maxTouchPoi nts(); |
331 } | 431 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 m_lastPinchAnchorCss.reset(); | 482 m_lastPinchAnchorCss.reset(); |
383 m_lastPinchAnchorDip.reset(); | 483 m_lastPinchAnchorDip.reset(); |
384 } | 484 } |
385 return true; | 485 return true; |
386 } | 486 } |
387 | 487 |
388 return false; | 488 return false; |
389 } | 489 } |
390 | 490 |
391 } // namespace blink | 491 } // namespace blink |
OLD | NEW |