OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #include "core/loader/FrameLoadRequest.h" | 50 #include "core/loader/FrameLoadRequest.h" |
51 #include "core/page/Page.h" | 51 #include "core/page/Page.h" |
52 #include "core/page/ScopedPageLoadDeferrer.h" | 52 #include "core/page/ScopedPageLoadDeferrer.h" |
53 #include "core/paint/PaintLayer.h" | 53 #include "core/paint/PaintLayer.h" |
54 #include "core/paint/PaintLayerPainter.h" | 54 #include "core/paint/PaintLayerPainter.h" |
55 #include "core/timing/DOMWindowPerformance.h" | 55 #include "core/timing/DOMWindowPerformance.h" |
56 #include "core/timing/Performance.h" | 56 #include "core/timing/Performance.h" |
57 #include "core/timing/PerformanceCompositeTiming.h" | 57 #include "core/timing/PerformanceCompositeTiming.h" |
58 #include "platform/KeyboardCodes.h" | 58 #include "platform/KeyboardCodes.h" |
59 #include "platform/UserGestureIndicator.h" | 59 #include "platform/UserGestureIndicator.h" |
| 60 #include "platform/geometry/IntRect.h" |
60 #include "platform/geometry/IntSize.h" | 61 #include "platform/geometry/IntSize.h" |
61 #include "platform/graphics/Color.h" | 62 #include "platform/graphics/Color.h" |
62 #include "platform/graphics/GraphicsContext.h" | 63 #include "platform/graphics/GraphicsContext.h" |
63 #include "platform/graphics/paint/SkPictureBuilder.h" | 64 #include "platform/graphics/paint/SkPictureBuilder.h" |
| 65 #include "platform/scroll/ScrollTypes.h" |
64 #include "platform/testing/URLTestHelpers.h" | 66 #include "platform/testing/URLTestHelpers.h" |
65 #include "platform/testing/UnitTestHelpers.h" | 67 #include "platform/testing/UnitTestHelpers.h" |
66 #include "public/platform/Platform.h" | 68 #include "public/platform/Platform.h" |
67 #include "public/platform/WebDisplayMode.h" | 69 #include "public/platform/WebDisplayMode.h" |
68 #include "public/platform/WebDragData.h" | 70 #include "public/platform/WebDragData.h" |
69 #include "public/platform/WebDragOperation.h" | 71 #include "public/platform/WebDragOperation.h" |
| 72 #include "public/platform/WebFloatRect.h" |
70 #include "public/platform/WebMockClipboard.h" | 73 #include "public/platform/WebMockClipboard.h" |
71 #include "public/platform/WebSize.h" | 74 #include "public/platform/WebSize.h" |
72 #include "public/platform/WebThread.h" | 75 #include "public/platform/WebThread.h" |
73 #include "public/platform/WebURLLoaderMockFactory.h" | 76 #include "public/platform/WebURLLoaderMockFactory.h" |
74 #include "public/web/WebAutofillClient.h" | 77 #include "public/web/WebAutofillClient.h" |
75 #include "public/web/WebCache.h" | 78 #include "public/web/WebCache.h" |
76 #include "public/web/WebDateTimeChooserCompletion.h" | 79 #include "public/web/WebDateTimeChooserCompletion.h" |
77 #include "public/web/WebDeviceEmulationParams.h" | 80 #include "public/web/WebDeviceEmulationParams.h" |
78 #include "public/web/WebDocument.h" | 81 #include "public/web/WebDocument.h" |
79 #include "public/web/WebElement.h" | 82 #include "public/web/WebElement.h" |
80 #include "public/web/WebFrame.h" | 83 #include "public/web/WebFrame.h" |
81 #include "public/web/WebFrameClient.h" | 84 #include "public/web/WebFrameClient.h" |
82 #include "public/web/WebFrameContentDumper.h" | 85 #include "public/web/WebFrameContentDumper.h" |
83 #include "public/web/WebHitTestResult.h" | 86 #include "public/web/WebHitTestResult.h" |
84 #include "public/web/WebInputEvent.h" | 87 #include "public/web/WebInputEvent.h" |
85 #include "public/web/WebScriptSource.h" | 88 #include "public/web/WebScriptSource.h" |
86 #include "public/web/WebSettings.h" | 89 #include "public/web/WebSettings.h" |
87 #include "public/web/WebTreeScopeType.h" | 90 #include "public/web/WebTreeScopeType.h" |
88 #include "public/web/WebViewClient.h" | 91 #include "public/web/WebViewClient.h" |
89 #include "public/web/WebWidget.h" | 92 #include "public/web/WebWidget.h" |
90 #include "public/web/WebWidgetClient.h" | 93 #include "public/web/WebWidgetClient.h" |
91 #include "testing/gtest/include/gtest/gtest.h" | 94 #include "testing/gtest/include/gtest/gtest.h" |
92 #include "third_party/skia/include/core/SkBitmap.h" | 95 #include "third_party/skia/include/core/SkBitmap.h" |
93 #include "third_party/skia/include/core/SkCanvas.h" | 96 #include "third_party/skia/include/core/SkCanvas.h" |
| 97 #include "web/DevToolsEmulator.h" |
94 #include "web/WebLocalFrameImpl.h" | 98 #include "web/WebLocalFrameImpl.h" |
95 #include "web/WebSettingsImpl.h" | 99 #include "web/WebSettingsImpl.h" |
96 #include "web/WebViewImpl.h" | 100 #include "web/WebViewImpl.h" |
97 #include "web/tests/FrameTestHelpers.h" | 101 #include "web/tests/FrameTestHelpers.h" |
98 #include "wtf/PtrUtil.h" | 102 #include "wtf/PtrUtil.h" |
99 #include <memory> | 103 #include <memory> |
100 | 104 |
101 #if OS(MACOSX) | 105 #if OS(MACOSX) |
102 #include "public/web/mac/WebSubstringUtil.h" | 106 #include "public/web/mac/WebSubstringUtil.h" |
103 #endif | 107 #endif |
(...skipping 3175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3279 ScopedPageLoadDeferrer deferrer2; | 3283 ScopedPageLoadDeferrer deferrer2; |
3280 EXPECT_TRUE(webView->page()->defersLoading()); | 3284 EXPECT_TRUE(webView->page()->defersLoading()); |
3281 } | 3285 } |
3282 | 3286 |
3283 EXPECT_TRUE(webView->page()->defersLoading()); | 3287 EXPECT_TRUE(webView->page()->defersLoading()); |
3284 } | 3288 } |
3285 | 3289 |
3286 EXPECT_FALSE(webView->page()->defersLoading()); | 3290 EXPECT_FALSE(webView->page()->defersLoading()); |
3287 } | 3291 } |
3288 | 3292 |
| 3293 TEST_F(WebViewTest, SetAndClearVisualTransformOverride) |
| 3294 { |
| 3295 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3296 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3297 webViewImpl->resize(WebSize(100, 150)); |
| 3298 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| 3299 VisualViewport* visualViewport = &webViewImpl->page()->frameHost().visualVie
wport(); |
| 3300 |
| 3301 TransformationMatrix expectedMatrix; |
| 3302 expectedMatrix.makeIdentity(); |
| 3303 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3304 EXPECT_EQ(IntRect(0, 0, 100, 150), frameView->visibleContentRectForPainting(
)); |
| 3305 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); |
| 3306 |
| 3307 // Override applies transform, sets visibleContentRect, and disables |
| 3308 // visual viewport clipping. |
| 3309 webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(50,
55, 100, 110), 2.f); |
| 3310 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55); |
| 3311 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3312 EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPaintin
g()); |
| 3313 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); |
| 3314 |
| 3315 // Setting new override discards previous one. |
| 3316 webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(5.4
f, 10.5f, 50.4f, 55.5f), 1.5); |
| 3317 expectedMatrix.makeIdentity().scale(1.5f).translate(-5.4f, -10.5f); |
| 3318 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3319 EXPECT_EQ(IntRect(5, 10, 51, 56), frameView->visibleContentRectForPainting()
); |
| 3320 EXPECT_FALSE(visualViewport->containerLayer()->masksToBounds()); |
| 3321 |
| 3322 // Clearing override restores original transform, visibleContentRect and |
| 3323 // visual viewport clipping. |
| 3324 webViewImpl->devToolsEmulator()->clearVisualTransformOverride(); |
| 3325 expectedMatrix.makeIdentity(); |
| 3326 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3327 EXPECT_EQ(IntRect(0, 0, 100, 150), frameView->visibleContentRectForPainting(
)); |
| 3328 EXPECT_TRUE(visualViewport->containerLayer()->masksToBounds()); |
| 3329 } |
| 3330 |
| 3331 TEST_F(WebViewTest, VisualTransformOverrideIntegratesDeviceMetricsOffsetAndScale
) |
| 3332 { |
| 3333 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3334 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3335 webViewImpl->resize(WebSize(100, 150)); |
| 3336 |
| 3337 TransformationMatrix expectedMatrix; |
| 3338 expectedMatrix.makeIdentity(); |
| 3339 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3340 |
| 3341 WebDeviceEmulationParams emulationParams; |
| 3342 emulationParams.offset = WebFloatPoint(50, 50); |
| 3343 emulationParams.scale = 2.f; |
| 3344 webViewImpl->enableDeviceEmulation(emulationParams); |
| 3345 expectedMatrix.makeIdentity().translate(50, 50).scale(2.f); |
| 3346 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3347 |
| 3348 // Device metrics offset and scale are applied before visual transform. |
| 3349 webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(5,
10, 100, 110), 1.5f); |
| 3350 expectedMatrix.makeIdentity().scale(1.5f).translate(-5, -10).translate(50, 5
0).scale(2.f); |
| 3351 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3352 } |
| 3353 |
| 3354 TEST_F(WebViewTest, VisualTransformOverrideAdaptsToScaleAndScroll) |
| 3355 { |
| 3356 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("200-by-300.html")); |
| 3357 WebViewImpl* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + "20
0-by-300.html"); |
| 3358 webViewImpl->resize(WebSize(100, 150)); |
| 3359 FrameView* frameView = webViewImpl->mainFrameImpl()->frame()->view(); |
| 3360 |
| 3361 TransformationMatrix expectedMatrix; |
| 3362 expectedMatrix.makeIdentity(); |
| 3363 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3364 |
| 3365 // Initial transform takes current page scale and scroll position into |
| 3366 // account. |
| 3367 webViewImpl->setPageScaleFactor(1.5f); |
| 3368 frameView->setScrollPosition(DoublePoint(100, 150), ProgrammaticScroll, Scro
llBehaviorInstant); |
| 3369 webViewImpl->devToolsEmulator()->setVisualTransformOverride(WebFloatRect(50,
55, 100, 110), 2.f); |
| 3370 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(100,
150).scale(1. / 1.5f); |
| 3371 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3372 // Scroll and scale are irrelevant for visibleContentRect. |
| 3373 EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPaintin
g()); |
| 3374 |
| 3375 // Transform adapts to scroll changes. |
| 3376 frameView->setScrollPosition(DoublePoint(50, 55), ProgrammaticScroll, Scroll
BehaviorInstant); |
| 3377 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5
5).scale(1. / 1.5f); |
| 3378 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3379 // visibleContentRect doesn't change. |
| 3380 EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPaintin
g()); |
| 3381 |
| 3382 // Transform adapts to page scale changes. |
| 3383 webViewImpl->setPageScaleFactor(2.f); |
| 3384 expectedMatrix.makeIdentity().scale(2.f).translate(-50, -55).translate(50, 5
5).scale(1. / 2.f); |
| 3385 EXPECT_EQ(expectedMatrix, webViewImpl->getRootLayerTransformForTesting()); |
| 3386 // visibleContentRect doesn't change. |
| 3387 EXPECT_EQ(IntRect(50, 55, 100, 110), frameView->visibleContentRectForPaintin
g()); |
| 3388 } |
| 3389 |
3289 } // namespace blink | 3390 } // namespace blink |
OLD | NEW |