Diff
Modified: trunk/Source/WebKit/mac/ChangeLog (93314 => 93315)
--- trunk/Source/WebKit/mac/ChangeLog 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Source/WebKit/mac/ChangeLog 2011-08-18 16:43:53 UTC (rev 93315)
@@ -1,3 +1,17 @@
+2011-08-18 Adam Roben <[email protected]>
+
+ Update the device scale factor when the WebView's window changes
+
+ Fixes <http://webkit.org/b/66412> <rdar://problem/9971958> WebKit doesn't react when a
+ WebView is moved between windows with different backing scale factors
+
+ Reviewed by Anders Carlsson.
+
+ * WebView/WebView.mm:
+ (-[WebView viewDidMoveToWindow]): Call setDeviceScaleFactor because our new window (or no
+ window at all) might have a different backing scale factor than the previous one.
+ (-[WebView _deviceScaleFactor]): Moved to the WebFileInternal category.
+
2011-08-17 Adam Roben <[email protected]>
Make WebCore keep track of the current device scale factor
Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (93314 => 93315)
--- trunk/Source/WebKit/mac/WebView/WebView.mm 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm 2011-08-18 16:43:53 UTC (rev 93315)
@@ -375,6 +375,7 @@
@end
@interface WebView (WebFileInternal)
+- (float)_deviceScaleFactor;
- (BOOL)_isLoading;
- (WebFrameView *)_frameViewAtWindowPoint:(NSPoint)point;
- (WebFrame *)_focusedFrame;
@@ -3353,6 +3354,8 @@
_private->page->didMoveOnscreen();
}
+ _private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
+
[self _updateActiveState];
}
@@ -3382,20 +3385,6 @@
[self close];
}
-- (float)_deviceScaleFactor
-{
- NSWindow *window = [self window];
-#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
- if (window)
- return [window backingScaleFactor];
- return [[NSScreen mainScreen] backingScaleFactor];
-#else
- if (window)
- return [window userSpaceScaleFactor];
- return [[NSScreen mainScreen] userSpaceScaleFactor];
-#endif
-}
-
- (void)_windowDidChangeResolution:(NSNotification *)notification
{
_private->page->setDeviceScaleFactor([self _deviceScaleFactor]);
@@ -5522,6 +5511,20 @@
@implementation WebView (WebFileInternal)
+- (float)_deviceScaleFactor
+{
+ NSWindow *window = [self window];
+#if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
+ if (window)
+ return [window backingScaleFactor];
+ return [[NSScreen mainScreen] backingScaleFactor];
+#else
+ if (window)
+ return [window userSpaceScaleFactor];
+ return [[NSScreen mainScreen] userSpaceScaleFactor];
+#endif
+}
+
static inline uint64_t roundUpToPowerOf2(uint64_t num)
{
return powf(2.0, ceilf(log2f(num)));
Modified: trunk/Source/WebKit2/ChangeLog (93314 => 93315)
--- trunk/Source/WebKit2/ChangeLog 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Source/WebKit2/ChangeLog 2011-08-18 16:43:53 UTC (rev 93315)
@@ -1,5 +1,19 @@
2011-08-18 Adam Roben <[email protected]>
+ Update the device scale factor when the WKView's window changes
+
+ Fixes <http://webkit.org/b/66412> <rdar://problem/9971958> WebKit doesn't react when a
+ WebView is moved between windows with different backing scale factors
+
+ Reviewed by Anders Carlsson.
+
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView viewDidMoveToWindow]): Call setDeviceScaleFactor because our new window (or no
+ window at all) might have a different backing scale factor than the previous one.
+ (-[WKView _deviceScaleFactor]): Moved to the new FileInternal category.
+
+2011-08-18 Adam Roben <[email protected]>
+
Make WebPageProxy keep track of the current device scale factor
The device scale factor is no longer considered part of WebPageProxy's "view state". It now
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (93314 => 93315)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2011-08-18 16:43:53 UTC (rev 93315)
@@ -109,6 +109,10 @@
Vector<KeypressCommand>* commands;
};
+@interface WKView (FileInternal)
+- (float)_deviceScaleFactor;
+@end
+
@interface WKViewData : NSObject {
@public
OwnPtr<PageClientImpl> _pageClient;
@@ -1791,6 +1795,8 @@
WKHideWordDefinitionWindow();
#endif
}
+
+ _data->_page->setDeviceScaleFactor([self _deviceScaleFactor]);
}
- (void)_windowDidBecomeKey:(NSNotification *)notification
@@ -1836,20 +1842,6 @@
_data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
}
-- (float)_deviceScaleFactor
-{
- NSWindow *window = [self window];
-#if !defined(BUILDING_ON_SNOW_LEOPARD)
- if (window)
- return [window backingScaleFactor];
- return [[NSScreen mainScreen] backingScaleFactor];
-#else
- if (window)
- return [window userSpaceScaleFactor];
- return [[NSScreen mainScreen] userSpaceScaleFactor];
-#endif
-}
-
- (void)_windowDidChangeResolution:(NSNotification *)notification
{
_data->_page->setDeviceScaleFactor([self _deviceScaleFactor]);
@@ -2599,3 +2591,21 @@
}
@end
+
+@implementation WKView (FileInternal)
+
+- (float)_deviceScaleFactor
+{
+ NSWindow *window = [self window];
+#if !defined(BUILDING_ON_SNOW_LEOPARD)
+ if (window)
+ return [window backingScaleFactor];
+ return [[NSScreen mainScreen] backingScaleFactor];
+#else
+ if (window)
+ return [window userSpaceScaleFactor];
+ return [[NSScreen mainScreen] userSpaceScaleFactor];
+#endif
+}
+
+@end
Modified: trunk/Tools/ChangeLog (93314 => 93315)
--- trunk/Tools/ChangeLog 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Tools/ChangeLog 2011-08-18 16:43:53 UTC (rev 93315)
@@ -1,3 +1,53 @@
+2011-08-18 Adam Roben <[email protected]>
+
+ Test that WebKit updates style when a WebView is moved between differently-scaled windows
+
+ Test for <http://webkit.org/b/66412> <rdar://problem/9971958> WebKit doesn't react when a
+ WebView is moved between windows with different backing scale factors
+
+ Reviewed by Anders Carlsson.
+
+ * TestWebKitAPI/_javascript_Test.cpp:
+ (TestWebKitAPI::runJSTest): Moved a little bit of code from here...
+ (TestWebKitAPI::compareJSResult): ...to here. Also made the error message more similar to
+ gtest's built-in error messages.
+
+ * TestWebKitAPI/_javascript_Test.h: Added overloads of runJSTest that take a WebView * and
+ WKView * for convenience on Mac. Added compareJSResult helper function for implementing
+ those overloads.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Added new files.
+
+ * TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm: Added.
+ (-[FrameLoadDelegate initWithDidFinishLoadBoolean:]): Simple initializer.
+ (-[FrameLoadDelegate webView:didFinishLoadForFrame:]): Record that the load finished.
+ (TestWebKitAPI::didFinishLoadForFrame): Record that the load finished.
+ (TestWebKitAPI::setPageLoaderClient): Set up the client.
+ (TestWebKitAPI::DynamicDeviceScaleFactor::DynamicDeviceScaleFactor): Simple constructor.
+ (TestWebKitAPI::DynamicDeviceScaleFactor::createWindow): Creates a
+ SyntheticBackingScaleFactorWindow and returns it.
+ (TestWebKitAPI::DynamicDeviceScaleFactor::runTest): Loads devicePixelRatio.html and checks
+ that WebKit uses the correct scale factor when the WebView is not in a window, is put in a
+ window, is moved to a differently-scaled window, and is taken out of the window.
+ (TestWebKitAPI::DynamicDeviceScaleFactor::loadURL): Helper function with overloads for
+ WebKit1 and WebKit2.
+ (TestWebKitAPI::TEST_F): Runs the test, with overloads for WebKit1 and WebKit2.
+
+ * TestWebKitAPI/Tests/mac/devicePixelRatio.html: Added.
+
+ * TestWebKitAPI/mac/_javascript_TestMac.mm: Added.
+ (TestWebKitAPI::runJSTest): Fairly simple overloads for WebView * and WKView *.
+
+ * TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.h: Added.
+ * TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.m: Added.
+ (-[SyntheticBackingScaleFactorWindow initWithContentRect:styleMask:backing:defer:]): Simple
+ initializer.
+ (-[SyntheticBackingScaleFactorWindow setBackingScaleFactor:]): Simple setter.
+
+ (-[SyntheticBackingScaleFactorWindow backingScaleFactor]):
+ (-[SyntheticBackingScaleFactorWindow userSpaceScaleFactor]):
+ Overrides of NSWindow methods that WebKit uses to determine the device scale factor.
+
2011-08-18 Dmitry Lomov <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=66425
Modified: trunk/Tools/TestWebKitAPI/_javascript_Test.cpp (93314 => 93315)
--- trunk/Tools/TestWebKitAPI/_javascript_Test.cpp 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Tools/TestWebKitAPI/_javascript_Test.cpp 2011-08-18 16:43:53 UTC (rev 93315)
@@ -70,14 +70,22 @@
WKPageRunJavaScriptInMainFrame(page, Util::toWK(script).get(), &context, _javascript_Callback);
Util::run(&context.didFinish);
- if (JSStringIsEqualToUTF8CString(context.actualString.get(), expectedResult))
- return ::testing::AssertionSuccess();
-
size_t bufferSize = JSStringGetMaximumUTF8CStringSize(context.actualString.get());
OwnArrayPtr<char> buffer = adoptArrayPtr(new char[bufferSize]);
JSStringGetUTF8CString(context.actualString.get(), buffer.get(), bufferSize);
+
+ return compareJSResult(script, buffer.get(), expectedResult);
+}
+
+::testing::AssertionResult compareJSResult(const char* script, const char* actualResult, const char* expectedResult)
+{
+ if (!strcmp(actualResult, expectedResult))
+ return ::testing::AssertionSuccess();
- return ::testing::AssertionFailure() << script << " should be " << expectedResult << " but is " << buffer.get();
+ return ::testing::AssertionFailure()
+ << "JS _expression_: " << script << "\n"
+ << " Actual: " << actualResult << "\n"
+ << " Expected: " << expectedResult;
}
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/_javascript_Test.h (93314 => 93315)
--- trunk/Tools/TestWebKitAPI/_javascript_Test.h 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Tools/TestWebKitAPI/_javascript_Test.h 2011-08-18 16:43:53 UTC (rev 93315)
@@ -24,7 +24,18 @@
*/
#include <gtest/gtest.h>
+#include <wtf/Platform.h>
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+@class WKView;
+@class WebView;
+#else
+class WKView;
+class WebView;
+#endif
+#endif
+
namespace TestWebKitAPI {
// These macros execute |script| in the page and wait until it has run, then compare its return
@@ -34,5 +45,11 @@
#define EXPECT_JS_TRUE(page, script) EXPECT_JS_EQ(page, script, "true")
::testing::AssertionResult runJSTest(const char* pageExpr, const char* scriptExpr, const char* expectedResultExpr, WKPageRef, const char* script, const char* expectedResult);
+::testing::AssertionResult compareJSResult(const char* script, const char* actualResult, const char* expectedResult);
+#if PLATFORM(MAC)
+::testing::AssertionResult runJSTest(const char* webViewExpr, const char* scriptExpr, const char* expectedResultExpr, WebView *, const char* script, const char* expectedResult);
+::testing::AssertionResult runJSTest(const char* viewExpr, const char* scriptExpr, const char* expectedResultExpr, WKView *, const char* script, const char* expectedResult);
+#endif
+
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (93314 => 93315)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-08-18 16:43:14 UTC (rev 93314)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-08-18 16:43:53 UTC (rev 93315)
@@ -60,6 +60,11 @@
C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */; };
C02B7854126613AE0026BF0F /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C02B7853126613AE0026BF0F /* Carbon.framework */; };
C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C045F9441385C2E900C0F3CD /* DownloadDecideDestinationCrash.cpp */; };
+ C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */; };
+ C07E6CB213FD73930038B22B /* devicePixelRatio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C07E6CB113FD738A0038B22B /* devicePixelRatio.html */; };
+ C081224213FC172400DC39AE /* _javascript_TestMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = C081224013FC172400DC39AE /* _javascript_TestMac.mm */; };
+ C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */; };
+ C081224913FC1B0300DC39AE /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; };
C0ADBE7C12FCA4D000D2C129 /* _javascript_Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE7A12FCA4D000D2C129 /* _javascript_Test.cpp */; };
C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */; };
C0ADBE9612FCA79B00D2C129 /* simple-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C0ADBE8412FCA6B600D2C129 /* simple-form.html */; };
@@ -96,6 +101,7 @@
dstSubfolderSpec = 7;
files = (
1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
+ C07E6CB213FD73930038B22B /* devicePixelRatio.html in Copy Resources */,
33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */,
BCBD3737125ABBEB00D2C29F /* icon.png in Copy Resources */,
1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */,
@@ -174,6 +180,12 @@
C02B7882126615410026BF0F /* spacebar-scrolling.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "spacebar-scrolling.html"; sourceTree = "<group>"; };
C045F9441385C2E900C0F3CD /* DownloadDecideDestinationCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DownloadDecideDestinationCrash.cpp; sourceTree = "<group>"; };
C045F9461385C2F800C0F3CD /* 18-characters.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "18-characters.html"; sourceTree = "<group>"; };
+ C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DynamicDeviceScaleFactor.mm; sourceTree = "<group>"; };
+ C07E6CB113FD738A0038B22B /* devicePixelRatio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = devicePixelRatio.html; sourceTree = "<group>"; };
+ C081224013FC172400DC39AE /* _javascript_TestMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _javascript_TestMac.mm; sourceTree = "<group>"; };
+ C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SyntheticBackingScaleFactorWindow.h; sourceTree = "<group>"; };
+ C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SyntheticBackingScaleFactorWindow.m; sourceTree = "<group>"; };
+ C081224813FC1B0300DC39AE /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C0ADBE7A12FCA4D000D2C129 /* _javascript_Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = _javascript_Test.cpp; sourceTree = "<group>"; };
C0ADBE7B12FCA4D000D2C129 /* _javascript_Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _javascript_Test.h; sourceTree = "<group>"; };
C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RestoreSessionStateContainingFormData.cpp; sourceTree = "<group>"; };
@@ -190,6 +202,7 @@
buildActionMask = 2147483647;
files = (
BCB9E9F111235BDE00A137E0 /* Cocoa.framework in Frameworks */,
+ C081224913FC1B0300DC39AE /* WebKit.framework in Frameworks */,
BCA61DB511700EFD00460D1E /* WebKit2.framework in Frameworks */,
BC90964E1255620C00083756 /* _javascript_Core.framework in Frameworks */,
C02B7854126613AE0026BF0F /* Carbon.framework in Frameworks */,
@@ -246,6 +259,7 @@
F3FC3EE213678B7300126A65 /* libgtest.a */,
BCB9E9F011235BDE00A137E0 /* Cocoa.framework */,
BC90964D1255620C00083756 /* _javascript_Core.framework */,
+ C081224813FC1B0300DC39AE /* WebKit.framework */,
BCA61DB411700EFD00460D1E /* WebKit2.framework */,
C02B7853126613AE0026BF0F /* Carbon.framework */,
);
@@ -352,9 +366,12 @@
isa = PBXGroup;
children = (
1AEDE22413E5E7A000E62FE8 /* InjectedBundleControllerMac.mm */,
+ C081224013FC172400DC39AE /* _javascript_TestMac.mm */,
BC131A9A1171316900B69727 /* main.mm */,
BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */,
BC90955C125548AA00083756 /* PlatformWebViewMac.mm */,
+ C081224313FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.h */,
+ C081224413FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m */,
);
path = mac;
sourceTree = "<group>";
@@ -362,12 +379,30 @@
BCB9EB66112366D800A137E0 /* Tests */ = {
isa = PBXGroup;
children = (
+ C07E6CAD13FD67650038B22B /* mac */,
BC9096411255616000083756 /* WebKit2 */,
BC9096461255618900083756 /* WTF */,
);
path = Tests;
sourceTree = "<group>";
};
+ C07E6CAD13FD67650038B22B /* mac */ = {
+ isa = PBXGroup;
+ children = (
+ C07E6CB013FD737C0038B22B /* Resources */,
+ C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
+ );
+ path = mac;
+ sourceTree = "<group>";
+ };
+ C07E6CB013FD737C0038B22B /* Resources */ = {
+ isa = PBXGroup;
+ children = (
+ C07E6CB113FD738A0038B22B /* devicePixelRatio.html */,
+ );
+ name = Resources;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -480,6 +515,9 @@
C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */,
C01363C813C3997300EF3964 /* StringOperators.cpp in Sources */,
+ C081224213FC172400DC39AE /* _javascript_TestMac.mm in Sources */,
+ C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */,
+ C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm (0 => 93315)
--- trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/DynamicDeviceScaleFactor.mm 2011-08-18 16:43:53 UTC (rev 93315)
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "Test.h"
+
+#include "_javascript_Test.h"
+#include "PlatformUtilities.h"
+#include "SyntheticBackingScaleFactorWindow.h"
+#include <WebKit/WebFrame.h>
+#include <WebKit/WebView.h>
+#include <WebKit2/WKURLCF.h>
+#include <wtf/RetainPtr.h>
+
+@interface FrameLoadDelegate : NSObject {
+ bool* _didFinishLoad;
+}
+
+- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad;
+
+@end
+
+@implementation FrameLoadDelegate
+
+- (id)initWithDidFinishLoadBoolean:(bool*)didFinishLoad
+{
+ self = [super init];
+ if (!self)
+ return nil;
+
+ _didFinishLoad = didFinishLoad;
+ return self;
+}
+
+- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame
+{
+ *_didFinishLoad = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void* context)
+{
+ *static_cast<bool*>(const_cast<void*>(context)) = true;
+}
+
+static void setPageLoaderClient(WKPageRef page, bool* didFinishLoad)
+{
+ WKPageLoaderClient loaderClient;
+ memset(&loaderClient, 0, sizeof(loaderClient));
+ loaderClient.version = 0;
+ loaderClient.clientInfo = didFinishLoad;
+ loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+ WKPageSetPageLoaderClient(page, &loaderClient);
+}
+
+class DynamicDeviceScaleFactor : public ::testing::Test {
+public:
+ DynamicDeviceScaleFactor();
+
+ template <typename View> void runTest(View);
+
+ bool didFinishLoad;
+ NSRect viewFrame;
+
+private:
+ RetainPtr<SyntheticBackingScaleFactorWindow> createWindow();
+
+ void loadURL(WebView *, NSURL *);
+ void loadURL(WKView *, NSURL *);
+};
+
+DynamicDeviceScaleFactor::DynamicDeviceScaleFactor()
+ : didFinishLoad(false)
+ , viewFrame(NSMakeRect(0, 0, 800, 600))
+{
+}
+
+RetainPtr<SyntheticBackingScaleFactorWindow> DynamicDeviceScaleFactor::createWindow()
+{
+ RetainPtr<SyntheticBackingScaleFactorWindow> window(AdoptNS, [[SyntheticBackingScaleFactorWindow alloc] initWithContentRect:viewFrame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES]);
+ [window.get() setReleasedWhenClosed:NO];
+ return window;
+}
+
+template <typename View>
+void DynamicDeviceScaleFactor::runTest(View view)
+{
+ EXPECT_FALSE(didFinishLoad);
+ loadURL(view, [[NSBundle mainBundle] URLForResource:@"devicePixelRatio" withExtension:@"html"]);
+ Util::run(&didFinishLoad);
+ didFinishLoad = false;
+
+ EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
+ EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
+
+ RetainPtr<SyntheticBackingScaleFactorWindow> window1 = createWindow();
+ [window1.get() setBackingScaleFactor:3];
+
+ [[window1.get() contentView] addSubview:view];
+ EXPECT_JS_EQ(view, "window.devicePixelRatio", "3");
+ EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "3");
+
+ RetainPtr<SyntheticBackingScaleFactorWindow> window2 = createWindow();
+ [window2.get() setBackingScaleFactor:4];
+
+ [[window2.get() contentView] addSubview:view];
+ EXPECT_JS_EQ(view, "window.devicePixelRatio", "4");
+ EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "4");
+
+ [view removeFromSuperview];
+ EXPECT_JS_EQ(view, "window.devicePixelRatio", "1");
+ EXPECT_JS_EQ(view, "devicePixelRatioFromStyle()", "1");
+}
+
+void DynamicDeviceScaleFactor::loadURL(WebView *webView, NSURL *url)
+{
+ [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
+}
+
+void DynamicDeviceScaleFactor::loadURL(WKView *view, NSURL *url)
+{
+ WKPageLoadURL([view pageRef], adoptWK(WKURLCreateWithCFURL((CFURLRef)url)).get());
+}
+
+TEST_F(DynamicDeviceScaleFactor, WebKit)
+{
+ RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:viewFrame]);
+ RetainPtr<FrameLoadDelegate> delegate(AdoptNS, [[FrameLoadDelegate alloc] initWithDidFinishLoadBoolean:&didFinishLoad]);
+ [webView.get() setFrameLoadDelegate:delegate.get()];
+
+ runTest(webView.get());
+}
+
+TEST_F(DynamicDeviceScaleFactor, WebKit2)
+{
+ WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate());
+ RetainPtr<WKView> view(AdoptNS, [[WKView alloc] initWithFrame:viewFrame contextRef:context.get()]);
+ setPageLoaderClient([view.get() pageRef], &didFinishLoad);
+
+ runTest(view.get());
+}
+
+} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/Tests/mac/devicePixelRatio.html (0 => 93315)
--- trunk/Tools/TestWebKitAPI/Tests/mac/devicePixelRatio.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/devicePixelRatio.html 2011-08-18 16:43:53 UTC (rev 93315)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<style>
+ #detector { width: 5px; }
+ @media (-webkit-device-pixel-ratio:1) { #detector { width: 10px; } }
+ @media (-webkit-device-pixel-ratio:3) { #detector { width: 30px; } }
+ @media (-webkit-device-pixel-ratio:4) { #detector { width: 40px; } }
+</style>
+<script>
+ function devicePixelRatioFromStyle() {
+ var width = getComputedStyle(document.getElementById("detector")).width;
+ switch (width) {
+ case "10px":
+ return 1;
+ case "30px":
+ return 3;
+ case "40px":
+ return 4;
+ default:
+ return "unknown width: " + width;
+ }
+ }
+</script>
+<div id="detector"></div>
Copied: trunk/Tools/TestWebKitAPI/mac/_javascript_TestMac.mm (from rev 93314, trunk/Tools/TestWebKitAPI/_javascript_Test.h) (0 => 93315)
--- trunk/Tools/TestWebKitAPI/mac/_javascript_TestMac.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/_javascript_TestMac.mm 2011-08-18 16:43:53 UTC (rev 93315)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "_javascript_Test.h"
+
+#include <WebKit/WebView.h>
+
+namespace TestWebKitAPI {
+
+::testing::AssertionResult runJSTest(const char*, const char*, const char*, WebView *webView, const char* script, const char* expectedResult)
+{
+ NSString *actualResult = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithUTF8String:script]];
+ return compareJSResult(script, [actualResult UTF8String], expectedResult);
+}
+
+::testing::AssertionResult runJSTest(const char* viewExpr, const char* scriptExpr, const char* expectedResultExpr, WKView *view, const char* script, const char* expectedResult)
+{
+ return runJSTest(viewExpr, scriptExpr, expectedResultExpr, [view pageRef], script, expectedResult);
+}
+
+} // namespace TestWebKitAPI
Copied: trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.h (from rev 93314, trunk/Tools/TestWebKitAPI/_javascript_Test.h) (0 => 93315)
--- trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.h (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.h 2011-08-18 16:43:53 UTC (rev 93315)
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+@interface SyntheticBackingScaleFactorWindow : NSWindow {
+ CGFloat _backingScaleFactor;
+}
+- (void)setBackingScaleFactor:(CGFloat)scaleFactor;
+@end
Copied: trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.m (from rev 93314, trunk/Tools/TestWebKitAPI/_javascript_Test.h) (0 => 93315)
--- trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.m (rev 0)
+++ trunk/Tools/TestWebKitAPI/mac/SyntheticBackingScaleFactorWindow.m 2011-08-18 16:43:53 UTC (rev 93315)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SyntheticBackingScaleFactorWindow.h"
+
+@implementation SyntheticBackingScaleFactorWindow
+
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
+{
+ self = [super initWithContentRect:contentRect styleMask:windowStyle backing:bufferingType defer:deferCreation];
+ if (!self)
+ return nil;
+
+ _backingScaleFactor = 1;
+ return self;
+}
+
+- (void)setBackingScaleFactor:(CGFloat)scaleFactor
+{
+ _backingScaleFactor = scaleFactor;
+}
+
+- (CGFloat)backingScaleFactor
+{
+ return _backingScaleFactor;
+}
+
+- (CGFloat)userSpaceScaleFactor
+{
+ return _backingScaleFactor;
+}
+
+@end