Source/WebCore:
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 19:30:02 +0000 (19:30 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 19:30:02 +0000 (19:30 +0000)
[Win] Implement High DPI support features
https://bugs.webkit.org/show_bug.cgi?id=146335
<rdar://problem/21558269>

Reviewed by Alex Christensen.

* platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
(WebCore::PlatformCALayerWinInternal::drawTile): Don't translate the CGContext to the position
of the CACFLayerRef; the underlying context is already in the right position.
* platform/win/PlatformMouseEventWin.cpp: Update class to adjust mouse
event coordinates based on scaling factor.
(WebCore::deviceScaleFactor):
(WebCore::positionForEvent):
* platform/win/ScrollbarThemeWin.cpp:
(WebCore::scrollbarThicknessInPixels):
(WebCore::ScrollbarThemeWin::scrollbarThickness):
(WebCore::ScrollbarThemeWin::themeChanged):
* platform/win/WheelEventWin.cpp: Update class to adjust wheel event
coordinates based on scaling factor.
(WebCore::deviceScaleFactor):
(WebCore::positionForEvent):
(WebCore::globalPositionForEvent):
(WebCore::PlatformWheelEvent::PlatformWheelEvent):

Source/WebKit/win:
[Win] Implement High DPI support features
https://bugs.webkit.org/show_bug.cgi?id=146335
<rdar://problem/21558269>

Reviewed by Alex Christensen.

* WebCoreSupport/WebFrameLoaderClient.cpp:
(WebFrameLoaderClient::transitionToCommittedForNewPage): Size
page for current device scale factor.
* WebFrame.cpp:
(WebFrame::paintDocumentRectToContext): Account for device scale factor.
(WebFrame::paintScrollViewRectToContextAtPoint): Ditto.
* WebView.cpp:
(WebView::repaint): Adjust paint rect for device scale factor.
(WebView::scrollBackingStore): Adjust coordinates for scale factor.
(WebView::sizeChanged): Ditto.
(WebView::updateBackingStore): Ditto.
(WebView::paint): Ditto.
(WebView::paintIntoBackingStore): Ditto.
(WebView::handleContextMenuEvent): Ditto.
(WebView::gestureNotify): Ditto.
(WebView::gesture): Ditto.
(WebView::initializeToolTipWindow): Adjust max tool tip width
for device scale factor.
(WebView::selectionRect): Adjust coordinates for scale factor.
(WebView::elementAtPoint): Ditto.
(WebView::scrollOffset): Ditto.
(WebView::scrollBy): Ditto.
(WebView::visibleContentRect): Ditto.
(WebView::paintContents): Ditto.
* WebView.h:

Tools:
[Win] Implement proper High DPI support features
https://bugs.webkit.org/show_bug.cgi?id=146335
<rdar://problem/21558269>

Reviewed by Alex Christensen.

Update WinLauncher to take device scaling factor into account.

* WinLauncher/Common.cpp:
(resizeSubViews): Make sure toolbars and URL bar are properly sized and using
a valid font.
(computeFullDesktopFrame): Handle high DPI desktops.
(WndProc): Make comments more precise.
* WinLauncher/WinLauncher.cpp:
(WinLauncher::init): Determine device scale factor at launch.
(WinLauncher::updateDeviceScaleFactor): Added.
* WinLauncher/WinLauncher.h:
* WinLauncher/WinLauncherWebHost.h: Use C++11 initialization.
* WinLauncher/WinMain.cpp: Size interface based on scaling factor.
(wWinMain): Ditto.
* win/DLLLauncher/DLLLauncherMain.cpp:
(wWinMain): Tell Windows we understand high DPI.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187245 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp
Source/WebCore/platform/win/GDIUtilities.cpp [new file with mode: 0644]
Source/WebCore/platform/win/GDIUtilities.h [new file with mode: 0644]
Source/WebCore/platform/win/PlatformMouseEventWin.cpp
Source/WebCore/platform/win/ScrollbarThemeWin.cpp
Source/WebCore/platform/win/WheelEventWin.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit/win/WebFrame.cpp
Source/WebKit/win/WebPreferences.cpp
Source/WebKit/win/WebView.cpp
Source/WebKit/win/WebView.h
Tools/ChangeLog
Tools/WinLauncher/Common.cpp
Tools/WinLauncher/WinLauncher.cpp
Tools/WinLauncher/WinLauncher.h
Tools/WinLauncher/WinLauncherWebHost.h
Tools/WinLauncher/WinMain.cpp
Tools/win/DLLLauncher/DLLLauncherMain.cpp

index 0c2f3b8..a1f9c0d 100644 (file)
@@ -1,3 +1,29 @@
+2015-07-23  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Implement High DPI support features
+        https://bugs.webkit.org/show_bug.cgi?id=146335
+        <rdar://problem/21558269>
+
+        Reviewed by Alex Christensen.
+
+        * platform/graphics/ca/win/PlatformCALayerWinInternal.cpp:
+        (WebCore::PlatformCALayerWinInternal::drawTile): Don't translate the CGContext to the position
+        of the CACFLayerRef; the underlying context is already in the right position.
+        * platform/win/PlatformMouseEventWin.cpp: Update class to adjust mouse
+        event coordinates based on scaling factor.
+        (WebCore::deviceScaleFactor):
+        (WebCore::positionForEvent):
+        * platform/win/ScrollbarThemeWin.cpp:
+        (WebCore::scrollbarThicknessInPixels):
+        (WebCore::ScrollbarThemeWin::scrollbarThickness):
+        (WebCore::ScrollbarThemeWin::themeChanged):
+        * platform/win/WheelEventWin.cpp: Update class to adjust wheel event
+        coordinates based on scaling factor.
+        (WebCore::deviceScaleFactor):
+        (WebCore::positionForEvent):
+        (WebCore::globalPositionForEvent):
+        (WebCore::PlatformWheelEvent::PlatformWheelEvent):
+
 2015-07-23  Myles C. Maxfield  <mmaxfield@apple.com>
 
         REGRESSION(r182236): Justified Arabic text does not expand
index bca734b..1cb1e57 100644 (file)
     <ClCompile Include="..\platform\win\EventLoopWin.cpp" />
     <ClCompile Include="..\platform\win\FileSystemWin.cpp" />
     <ClCompile Include="..\platform\win\GDIObjectCounter.cpp" />
+    <ClCompile Include="..\platform\win\GDIUtilities.cpp" />
     <ClCompile Include="..\platform\win\ImportedFunctionsEnumerator.cpp" />
     <ClCompile Include="..\platform\win\ImportedModulesEnumerator.cpp" />
     <ClCompile Include="..\platform\win\KeyEventWin.cpp" />
     <ClInclude Include="..\platform\win\DefWndProcWindowClass.h" />
     <ClInclude Include="..\platform\win\DelayLoadedModulesEnumerator.h" />
     <ClInclude Include="..\platform\win\GDIObjectCounter.h" />
+    <ClInclude Include="..\platform\win\GDIUtilities.h" />
     <ClInclude Include="..\platform\win\HWndDC.h" />
     <ClInclude Include="..\platform\win\ImportedFunctionsEnumerator.h" />
     <ClInclude Include="..\platform\win\ImportedModulesEnumerator.h" />
index db1629e..834eeb8 100644 (file)
     <ClCompile Include="..\platform\graphics\PathUtilities.cpp">
       <Filter>platform\graphics</Filter>
     </ClCompile>
+    <ClCompile Include="..\platform\win\GDIUtilities.cpp">
+      <Filter>platform\graphics\win</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\Modules\geolocation\Coordinates.h">
     <ClInclude Include="..\platform\graphics\PathUtilities.h">
       <Filter>platform\graphics</Filter>
     </ClInclude>
+    <ClInclude Include="..\platform\win\GDIUtilities.h">
+      <Filter>platform\graphics\win</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\css\CSSGrammar.y.in">
index 7c5c0ce..5761392 100644 (file)
@@ -512,9 +512,6 @@ void PlatformCALayerWinInternal::drawTile(CACFLayerRef tile, CGContextRef contex
 
     CGContextSaveGState(context);
 
-    // Transform context to be at the origin of the parent layer
-    CGContextTranslateCTM(context, -tilePosition.x, -tilePosition.y);
-
     // Set the context clipping rectangle to the current tile
     CGContextClipToRect(context, CGRectMake(tilePosition.x, tilePosition.y, tileBounds.size.width, tileBounds.size.height));
 
diff --git a/Source/WebCore/platform/win/GDIUtilities.cpp b/Source/WebCore/platform/win/GDIUtilities.cpp
new file mode 100644 (file)
index 0000000..f1606b0
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+* Copyright (C) 2015 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. ``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
+* 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 "config.h"
+#include "GDIUtilities.h"
+
+#include "HWndDC.h"
+
+namespace WebCore {
+
+float deviceScaleFactorForWindow(HWND window)
+{
+    HWndDC dc(window);
+    return ::GetDeviceCaps(dc, LOGPIXELSX) / 96.0f;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/win/GDIUtilities.h b/Source/WebCore/platform/win/GDIUtilities.h
new file mode 100644 (file)
index 0000000..29b90e8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+* Copyright (C) 2015 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. ``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
+* 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.
+*/
+
+#ifndef GDIUtilties_h
+#define GDIUtilties_h
+
+#include <windows.h>
+
+namespace WebCore {
+
+WEBCORE_EXPORT float deviceScaleFactorForWindow(HWND);
+
+} // namespace WebCore
+
+#endif // GDIUtilties_h
index f195302..b60bc56 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006, 2007, 2015 Apple Inc.  All rights reserved.
  * Copyright (C) 2007-2008 Torch Mobile Inc.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "config.h"
 #include "PlatformMouseEvent.h"
 
+#include "GDIUtilities.h"
+#include "HWndDC.h"
 #include <wtf/Assertions.h>
 #include <wtf/CurrentTime.h>
+#include <wtf/MathExtras.h>
 #include <windows.h>
 #include <windowsx.h>
 
@@ -38,7 +41,9 @@ namespace WebCore {
 
 static IntPoint positionForEvent(HWND hWnd, LPARAM lParam)
 {
-    POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
+    IntPoint point(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+    float inverseScaleFactor = 1.0f / deviceScaleFactorForWindow(hWnd);
+    point.scale(inverseScaleFactor, inverseScaleFactor);
     return point;
 }
 
index 38990d6..c654ab1 100644 (file)
@@ -26,7 +26,9 @@
 #include "config.h"
 #include "ScrollbarThemeWin.h"
 
+#include "GDIUtilities.h"
 #include "GraphicsContext.h"
+#include "HWndDC.h"
 #include "LocalWindowsContext.h"
 #include "PlatformMouseEvent.h"
 #include "Scrollbar.h"
@@ -107,14 +109,18 @@ ScrollbarThemeWin::~ScrollbarThemeWin()
 {
 }
 
-int ScrollbarThemeWin::scrollbarThickness(ScrollbarControlSize)
+static int scrollbarThicknessInPixels()
 {
-    static int thickness;
-    if (!thickness)
-        thickness = ::GetSystemMetrics(SM_CXVSCROLL);
+    static int thickness = ::GetSystemMetrics(SM_CXVSCROLL);
     return thickness;
 }
 
+int ScrollbarThemeWin::scrollbarThickness(ScrollbarControlSize)
+{
+    float inverseScaleFactor = 1.0f / deviceScaleFactorForWindow(0);
+    return clampTo<int>(inverseScaleFactor * scrollbarThicknessInPixels());
+}
+
 void ScrollbarThemeWin::themeChanged()
 {
     if (!scrollbarTheme)
index cd2c47b..9ef248b 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "FloatPoint.h"
 #include "FloatSize.h"
+#include "GDIUtilities.h"
+#include "HWndDC.h"
 #include <windows.h>
 #include <windowsx.h>
 
@@ -40,13 +42,18 @@ static IntPoint positionForEvent(HWND hWnd, LPARAM lParam)
 {
     POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
     ScreenToClient(hWnd, &point);
-    return point;
+    IntPoint logicalPoint(point);
+    float inverseScaleFactor = 1.0f / deviceScaleFactorForWindow(hWnd);
+    logicalPoint.scale(inverseScaleFactor, inverseScaleFactor);
+    return logicalPoint;
 }
 
 static IntPoint globalPositionForEvent(HWND hWnd, LPARAM lParam)
 {
-    POINT point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
-    return point;
+    IntPoint logicalPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+    float inverseScaleFactor = 1.0f / deviceScaleFactorForWindow(hWnd);
+    logicalPoint.scale(inverseScaleFactor, inverseScaleFactor);
+    return logicalPoint;
 }
 
 static int horizontalScrollChars()
@@ -77,11 +84,14 @@ PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, const FloatSize& delta, const
 
     // Global Position is just x, y location of event
     POINT point = {location.x(), location.y()};
+    float inverseScaleFactor = 1.0f / deviceScaleFactorForWindow(hWnd);
     m_globalPosition = point;
+    m_globalPosition.scale(inverseScaleFactor, inverseScaleFactor);
 
     // Position needs to be translated to our client
     ScreenToClient(hWnd, &point);
     m_position = point;
+    m_position.scale(inverseScaleFactor, inverseScaleFactor);
 }
 
 PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam, bool isMouseHWheel)
@@ -90,6 +100,8 @@ PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam,
     , m_globalPosition(globalPositionForEvent(hWnd, lParam))
     , m_directionInvertedFromDevice(false)
 {
+    float scaleFactor = deviceScaleFactorForWindow(hWnd);
+
     // How many pixels should we scroll per line?  Gecko uses the height of the
     // current line, which means scroll distance changes as you go through the
     // page or go to different pages.  IE 7 is ~50 px/line, although the value
@@ -97,8 +109,8 @@ PlatformWheelEvent::PlatformWheelEvent(HWND hWnd, WPARAM wParam, LPARAM lParam,
     // smoothing algorithm on scrolling, it can get away with slightly larger
     // scroll values without feeling jerky.  Here we use 100 px per three lines
     // (the default scroll amount on Windows is three lines per wheel tick).
-    static const float cScrollbarPixelsPerLine = 100.0f / 3.0f;
-    float delta = GET_WHEEL_DELTA_WPARAM(wParam) / static_cast<float>(WHEEL_DELTA);
+    static const float cScrollbarPixelsPerLine = scaleFactor * 100.0f / 3.0f;
+    float delta = GET_WHEEL_DELTA_WPARAM(wParam) / (scaleFactor * static_cast<float>(WHEEL_DELTA));
     if (isMouseHWheel) {
         // Windows is <-- -/+ -->, WebKit wants <-- +/- -->, so we negate
         // |delta| after saving the original value on the wheel tick member.
index 1349dea..258318f 100644 (file)
@@ -1,3 +1,37 @@
+2015-07-23  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Implement High DPI support features
+        https://bugs.webkit.org/show_bug.cgi?id=146335
+        <rdar://problem/21558269>
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebFrameLoaderClient::transitionToCommittedForNewPage): Size
+        page for current device scale factor.
+        * WebFrame.cpp:
+        (WebFrame::paintDocumentRectToContext): Account for device scale factor.
+        (WebFrame::paintScrollViewRectToContextAtPoint): Ditto.
+        * WebView.cpp:
+        (WebView::repaint): Adjust paint rect for device scale factor.
+        (WebView::scrollBackingStore): Adjust coordinates for scale factor.
+        (WebView::sizeChanged): Ditto.
+        (WebView::updateBackingStore): Ditto.
+        (WebView::paint): Ditto.
+        (WebView::paintIntoBackingStore): Ditto.
+        (WebView::handleContextMenuEvent): Ditto.
+        (WebView::gestureNotify): Ditto.
+        (WebView::gesture): Ditto.
+        (WebView::initializeToolTipWindow): Adjust max tool tip width
+        for device scale factor.
+        (WebView::selectionRect): Adjust coordinates for scale factor.
+        (WebView::elementAtPoint): Ditto.
+        (WebView::scrollOffset): Ditto.
+        (WebView::scrollBy): Ditto.
+        (WebView::visibleContentRect): Ditto.
+        (WebView::paintContents): Ditto.
+        * WebView.h:
+
 2015-07-23  Sungmann Cho  <sungmann.cho@navercorp.com>
 
         [Win] Fix typos in PluginViewWin.cpp: kWebPluginViewdowClassName -> kWebPluginViewClassName
index d66c846..a8253d3 100644 (file)
@@ -1017,11 +1017,13 @@ void WebFrameLoaderClient::transitionToCommittedForNewPage()
 {
     WebView* view = m_webFrame->webView();
 
-    RECT rect;
-    view->frameRect(&rect);
+    RECT pixelRect;
+    view->frameRect(&pixelRect);
     bool transparent = view->transparent();
     Color backgroundColor = transparent ? Color::transparent : Color::white;
-    core(m_webFrame)->createView(IntRect(rect).size(), backgroundColor, transparent);
+    IntRect logicalFrame(pixelRect);
+    logicalFrame.scale(1.0f / view->deviceScaleFactor());
+    core(m_webFrame)->createView(logicalFrame.size(), backgroundColor, transparent);
 }
 
 void WebFrameLoaderClient::didSaveToPageCache()
index 9c7ba2c..903ccb6 100644 (file)
@@ -336,6 +336,8 @@ HRESULT WebFrame::paintDocumentRectToContext(RECT rect, HDC deviceContext)
     dirtyRect.setHeight(height);
     gc.clip(dirtyRect);
     gc.translate(-rect.left, -rect.top);
+    float scaleFactor = webView()->deviceScaleFactor();
+    gc.scale(WebCore::FloatSize(scaleFactor, scaleFactor));
     view->paintContents(&gc, rect);
     gc.restore();
 
@@ -360,6 +362,8 @@ HRESULT WebFrame::paintScrollViewRectToContextAtPoint(RECT rect, POINT pt, HDC d
     gc.save();
     IntRect dirtyRect(rect);
     dirtyRect.move(-pt.x, -pt.y);
+    float scaleFactor = webView()->deviceScaleFactor();
+    gc.scale(WebCore::FloatSize(scaleFactor, scaleFactor));
     view->paint(&gc, dirtyRect);
     gc.restore();
 
index c9355d7..b913031 100644 (file)
@@ -194,7 +194,7 @@ void WebPreferences::initializeDefaultSettings()
 
     CFMutableDictionaryRef defaults = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 
-    CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Segoe UI"));
+    CFDictionaryAddValue(defaults, CFSTR(WebKitStandardFontPreferenceKey), CFSTR("Times New Roman"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitFixedFontPreferenceKey), CFSTR("Courier New"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitSerifFontPreferenceKey), CFSTR("Times New Roman"));
     CFDictionaryAddValue(defaults, CFSTR(WebKitSansSerifFontPreferenceKey), CFSTR("Arial"));
index a332c03..b4fb9b0 100644 (file)
 #include <WebCore/FrameWin.h>
 #include <WebCore/FullScreenController.h>
 #include <WebCore/GDIObjectCounter.h>
+#include <WebCore/GDIUtilities.h>
 #include <WebCore/GeolocationController.h>
 #include <WebCore/GeolocationError.h>
 #include <WebCore/GraphicsContext.h>
@@ -364,6 +365,7 @@ const LPCWSTR kWebViewWindowClassName = L"WebViewWindowClass";
 
 const int WM_XP_THEMECHANGED = 0x031A;
 const int WM_VISTA_MOUSEHWHEEL = 0x020E;
+const int WM_DPICHANGED = 0x02E0;
 
 static const int maxToolTipWidth = 250;
 
@@ -822,8 +824,11 @@ HRESULT STDMETHODCALLTYPE WebView::close()
     return S_OK;
 }
 
-void WebView::repaint(const WebCore::IntRect& windowRect, bool contentChanged, bool immediate, bool repaintContentOnly)
+void WebView::repaint(const WebCore::IntRect& logicalWindowRect, bool contentChanged, bool immediate, bool repaintContentOnly)
 {
+    WebCore::IntRect windowRect(logicalWindowRect);
+    windowRect.scale(deviceScaleFactor());
+
     if (isAcceleratedCompositing()) {
         // The contentChanged, immediate, and repaintContentOnly parameters are all based on a non-
         // compositing painting/scrolling model.
@@ -921,10 +926,19 @@ void WebView::addToDirtyRegion(GDIObject<HRGN> newRegion)
         m_uiDelegatePrivate->webViewDidInvalidate(this);
 }
 
-void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect)
+void WebView::scrollBackingStore(FrameView* frameView, int logicalDx, int logicalDy, const IntRect& logicalScrollViewRect, const IntRect& logicalClipRect)
 {
     m_needsDisplay = true;
 
+    // Dimensions passed to us from WebCore are in logical units. We must convert to pixels:
+    float scaleFactor = deviceScaleFactor();
+    int dx = clampTo<int>(scaleFactor * logicalDx);
+    int dy = clampTo<int>(scaleFactor * logicalDy);
+    IntRect scrollViewRect(logicalScrollViewRect);
+    scrollViewRect.scale(scaleFactor);
+    IntRect clipRect(logicalClipRect);
+    clipRect.scale(scaleFactor);
+
     if (isAcceleratedCompositing()) {
         // FIXME: We should be doing something smarter here, like moving tiles around and painting
         // any newly-exposed tiles. <http://webkit.org/b/52714>
@@ -953,7 +967,7 @@ void WebView::scrollBackingStore(FrameView* frameView, int dx, int dy, const Int
     HWndDC windowDC(m_viewWindow);
     auto bitmapDC = adoptGDIObject(::CreateCompatibleDC(windowDC));
     HGDIOBJ oldBitmap = ::SelectObject(bitmapDC.get(), m_backingStoreBitmap->get());
-    
+
     // Scroll the bitmap.
     RECT scrollRectWin(scrollViewRect);
     RECT clipRectWin(clipRect);
@@ -983,8 +997,11 @@ void WebView::sizeChanged(const IntSize& newSize)
 
     deleteBackingStore();
 
-    if (Frame* coreFrame = core(topLevelFrame()))
-        coreFrame->view()->resize(newSize);
+    if (Frame* coreFrame = core(topLevelFrame())) {
+        IntSize logicalSize = newSize;
+        logicalSize.scale(1.0f / deviceScaleFactor());
+        coreFrame->view()->resize(logicalSize);
+    }
 
 #if USE(CA)
     if (m_layerTreeHost)
@@ -1000,6 +1017,16 @@ void WebView::sizeChanged(const IntSize& newSize)
 #endif
 }
 
+bool WebView::dpiChanged(float, const WebCore::IntSize& newSize)
+{
+    if (!IsProcessDPIAware())
+        return false;
+
+    sizeChanged(newSize);
+
+    return true;
+}
+
 // This emulates the Mac smarts for painting rects intelligently.  This is very
 // important for us, since we double buffer based off dirty rects.
 static void getUpdateRects(HRGN region, const IntRect& dirtyRect, Vector<IntRect>& rects)
@@ -1212,7 +1239,7 @@ void WebView::paint(HDC dc, LPARAM options)
         deleteBackingStoreSoon();
 }
 
-void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const IntRect& dirtyRect, WindowsToPaint windowsToPaint)
+void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const IntRect& dirtyRectPixels, WindowsToPaint windowsToPaint)
 {
     // FIXME: This function should never be called in accelerated compositing mode, and we should
     // assert as such. But currently it *is* sometimes called, so we can't assert yet. See
@@ -1224,7 +1251,7 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
     // but it was being hit during our layout tests, and is being investigated in
     // http://webkit.org/b/29350.
 
-    RECT rect = dirtyRect;
+    RECT rect = dirtyRectPixels;
 
 #if FLASH_BACKING_STORE_REDRAW
     {
@@ -1233,15 +1260,21 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
         FillRect(dc, &rect, yellowBrush.get());
         GdiFlush();
         Sleep(50);
-        paintIntoWindow(bitmapDC, dc, dirtyRect);
+        paintIntoWindow(bitmapDC, dc, dirtyRectPixels);
     }
 #endif
 
+    float scaleFactor = deviceScaleFactor();
+    float inverseScaleFactor = 1.0f / scaleFactor;
+
+    IntRect logicalDirtyRect = dirtyRectPixels;
+    logicalDirtyRect.scale(inverseScaleFactor);
+
     GraphicsContext gc(bitmapDC, m_transparent);
     gc.setShouldIncludeChildWindows(windowsToPaint == PaintWebViewAndChildren);
     gc.save();
     if (m_transparent)
-        gc.clearRect(dirtyRect);
+        gc.clearRect(logicalDirtyRect);
     else
         FillRect(bitmapDC, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
 
@@ -1250,15 +1283,18 @@ void WebView::paintIntoBackingStore(FrameView* frameView, HDC bitmapDC, const In
         uiPrivate->drawBackground(this, bitmapDC, &rect);
 
     if (frameView && frameView->frame().contentRenderer()) {
-        gc.clip(dirtyRect);
-        frameView->paint(&gc, dirtyRect);
+        gc.save();
+        gc.scale(FloatSize(scaleFactor, scaleFactor));
+        gc.clip(logicalDirtyRect);
+        frameView->paint(&gc, logicalDirtyRect);
+        gc.restore();
         if (m_shouldInvertColors)
-            gc.fillRect(dirtyRect, Color::white, ColorSpaceDeviceRGB, CompositeDifference);
+            gc.fillRect(logicalDirtyRect, Color::white, ColorSpaceDeviceRGB, CompositeDifference);
     }
     gc.restore();
 }
 
-void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRect)
+void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRectPixels)
 {
     // FIXME: This function should never be called in accelerated compositing mode, and we should
     // assert as such. But currently it *is* sometimes called, so we can't assert yet. See
@@ -1267,7 +1303,7 @@ void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRe
     LOCAL_GDI_COUNTER(0, __FUNCTION__);
 #if FLASH_WINDOW_REDRAW
     auto greenBrush = adoptGDIObject(::CreateSolidBrush(RGB(0, 255, 0)));
-    RECT rect = dirtyRect;
+    RECT rect = dirtyRectPixels;
     FillRect(windowDC, &rect, greenBrush.get());
     GdiFlush();
     Sleep(50);
@@ -1275,8 +1311,8 @@ void WebView::paintIntoWindow(HDC bitmapDC, HDC windowDC, const IntRect& dirtyRe
 
     // Blit the dirty rect from the backing store into the same position
     // in the destination DC.
-    BitBlt(windowDC, dirtyRect.x(), dirtyRect.y(), dirtyRect.width(), dirtyRect.height(), bitmapDC,
-           dirtyRect.x(), dirtyRect.y(), SRCCOPY);
+    BitBlt(windowDC, dirtyRectPixels.x(), dirtyRectPixels.y(), dirtyRectPixels.width(), dirtyRectPixels.height(), bitmapDC,
+        dirtyRectPixels.x(), dirtyRectPixels.y(), SRCCOPY);
 
     m_needsDisplay = false;
 }
@@ -1423,9 +1459,15 @@ bool WebView::handleContextMenuEvent(WPARAM wParam, LPARAM lParam)
 
     lParam = MAKELPARAM(coords.x, coords.y);
 
+    // Convert coordinates to logical pixels
+    float scaleFactor = deviceScaleFactor();
+    float inverseScaleFactor = 1.0f / scaleFactor;
+    IntPoint logicalCoords(coords);
+    logicalCoords.scale(inverseScaleFactor, inverseScaleFactor);
+
     m_page->contextMenuController().clearContextMenu();
 
-    IntPoint documentPoint(m_page->mainFrame().view()->windowToContents(coords));
+    IntPoint documentPoint(m_page->mainFrame().view()->windowToContents(logicalCoords));
     HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(documentPoint);
     Frame* targetFrame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
 
@@ -1450,9 +1492,11 @@ bool WebView::handleContextMenuEvent(WPARAM wParam, LPARAM lParam)
     if (!view)
         return false;
 
-    POINT point(view->contentsToWindow(contextMenuController.hitTestResult().roundedPointInInnerNodeFrame()));
+    IntPoint logicalPoint = view->contentsToWindow(contextMenuController.hitTestResult().roundedPointInInnerNodeFrame());
+    logicalPoint.scale(scaleFactor, scaleFactor);
 
     // Translate the point to screen coordinates
+    POINT point = logicalPoint;
     if (!::ClientToScreen(m_viewWindow, &point))
         return false;
 
@@ -1645,6 +1689,12 @@ bool WebView::gestureNotify(WPARAM wParam, LPARAM lParam)
 
     bool hitScrollbar = false;
     POINT gestureBeginPoint = {gn->ptsLocation.x, gn->ptsLocation.y};
+
+    float scaleFactor = deviceScaleFactor();
+    float inverseScaleFactor = 1.0f / scaleFactor;
+    IntPoint logicalGestureBeginPoint(gestureBeginPoint);
+    logicalGestureBeginPoint.scale(inverseScaleFactor, inverseScaleFactor);
+
     HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::DisallowShadowContent);
     for (Frame* childFrame = &m_page->mainFrame(); childFrame; childFrame = EventHandler::subframeForTargetNode(m_gestureTargetNode.get())) {
         FrameView* frameView = childFrame->view();
@@ -1657,7 +1707,7 @@ bool WebView::gestureNotify(WPARAM wParam, LPARAM lParam)
         if (!layer)
             break;
 
-        HitTestResult result(frameView->screenToContents(gestureBeginPoint));
+        HitTestResult result(frameView->screenToContents(logicalGestureBeginPoint));
         layer->hitTest(request, result);
         m_gestureTargetNode = result.innerNode();
 
@@ -1762,13 +1812,15 @@ bool WebView::gesture(WPARAM wParam, LPARAM lParam)
         }
 
         ScrollableArea* scrolledArea = 0;
+        float scaleFactor = deviceScaleFactor();
+        IntSize logicalScrollDelta(-deltaX * scaleFactor, -deltaY * scaleFactor);
 
         if (!m_gestureTargetNode || !m_gestureTargetNode->renderer()) {
             // We might directly hit the document without hitting any nodes
-            coreFrame->view()->scrollBy(IntSize(-deltaX, -deltaY));
+            coreFrame->view()->scrollBy(logicalScrollDelta);
             scrolledArea = coreFrame->view();
         } else
-            m_gestureTargetNode->renderer()->enclosingLayer()->enclosingScrollableLayer()->scrollByRecursively(IntSize(-deltaX, -deltaY), WebCore::RenderLayer::ScrollOffsetClamped, &scrolledArea);
+            m_gestureTargetNode->renderer()->enclosingLayer()->enclosingScrollableLayer()->scrollByRecursively(logicalScrollDelta, WebCore::RenderLayer::ScrollOffsetClamped, &scrolledArea);
 
         if (!(UpdatePanningFeedbackPtr() && BeginPanningFeedbackPtr() && EndPanningFeedbackPtr())) {
             CloseGestureInfoHandlePtr()(gestureHandle);
@@ -2207,7 +2259,11 @@ void WebView::setShouldInvertColors(bool shouldInvertColors)
 
     RECT windowRect = {0};
     frameRect(&windowRect);
-    repaint(windowRect, true, true);
+
+    // repaint expects logical pixels, so rescale here.
+    IntRect logicalRect(windowRect);
+    logicalRect.scale(1.0f / deviceScaleFactor());
+    repaint(logicalRect, true, true);
 }
 
 bool WebView::registerWebViewWindowClass()
@@ -2350,6 +2406,9 @@ LRESULT CALLBACK WebView::WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam,
             if (lParam != 0)
                 webView->sizeChanged(IntSize(LOWORD(lParam), HIWORD(lParam)));
             break;
+        case WM_DPICHANGED:
+            webView->dpiChanged(LOWORD(wParam), IntSize(LOWORD(lParam), HIWORD(lParam)));
+            break;
         case WM_SHOWWINDOW:
             lResult = DefWindowProc(hWnd, message, wParam, lParam);
             if (wParam == 0) {
@@ -2917,7 +2976,7 @@ void WebView::initializeToolTipWindow()
     info.uId = reinterpret_cast<UINT_PTR>(m_viewWindow);
 
     ::SendMessage(m_toolTipHwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&info));
-    ::SendMessage(m_toolTipHwnd, TTM_SETMAXTIPWIDTH, 0, maxToolTipWidth);
+    ::SendMessage(m_toolTipHwnd, TTM_SETMAXTIPWIDTH, 0, clampTo<int>(maxToolTipWidth * deviceScaleFactor()));
 
     ::SetWindowPos(m_toolTipHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 }
@@ -3688,17 +3747,19 @@ HRESULT STDMETHODCALLTYPE WebView::generateSelectionImage(BOOL forceWhiteText, H
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebView::selectionRect(RECT* rc)
+HRESULT WebView::selectionRect(RECT* rc)
 {
     WebCore::Frame& frame = m_page->focusController().focusedOrMainFrame();
 
     IntRect ir = enclosingIntRect(frame.selection().selectionBounds());
     ir = frame.view()->convertToContainingWindow(ir);
     ir.move(-frame.view()->scrollOffset().width(), -frame.view()->scrollOffset().height());
-    rc->left = ir.x();
-    rc->top = ir.y();
-    rc->bottom = rc->top + ir.height();
-    rc->right = rc->left + ir.width();
+
+    float scaleFactor = deviceScaleFactor();
+    rc->left = ir.x() * scaleFactor;
+    rc->top = ir.y() * scaleFactor;
+    rc->bottom = rc->top + ir.height() * scaleFactor;
+    rc->right = rc->left + ir.width() * scaleFactor;
 
     return S_OK;
 }
@@ -3775,9 +3836,7 @@ HRESULT STDMETHODCALLTYPE WebView::isLoading(
     return S_OK;
 }
     
-HRESULT STDMETHODCALLTYPE WebView::elementAtPoint( 
-        /* [in] */ LPPOINT point,
-        /* [retval][out] */ IPropertyBag** elementDictionary)
+HRESULT WebView::elementAtPoint(LPPOINT point, IPropertyBag** elementDictionary)
 {
     if (!elementDictionary) {
         ASSERT_NOT_REACHED();
@@ -3791,6 +3850,8 @@ HRESULT STDMETHODCALLTYPE WebView::elementAtPoint(
         return E_FAIL;
 
     IntPoint webCorePoint = IntPoint(point->x, point->y);
+    float inverseScaleFactor = 1.0f / deviceScaleFactor();
+    webCorePoint.scale(inverseScaleFactor, inverseScaleFactor);
     HitTestResult result = HitTestResult(webCorePoint);
     if (frame->contentRenderer())
         result = frame->eventHandler().hitTestResultAtPoint(webCorePoint);
@@ -5307,32 +5368,37 @@ HRESULT STDMETHODCALLTYPE WebView::frameLoadDelegatePrivate(
     return m_frameLoadDelegatePrivate.copyRefTo(d);
 }
 
-HRESULT STDMETHODCALLTYPE WebView::scrollOffset( 
-    /* [retval][out] */ LPPOINT offset)
+HRESULT WebView::scrollOffset(LPPOINT offset)
 {
     if (!offset)
         return E_POINTER;
     IntSize offsetIntSize = m_page->mainFrame().view()->scrollOffset();
+
+    offsetIntSize.scale(deviceScaleFactor());
+
     offset->x = offsetIntSize.width();
     offset->y = offsetIntSize.height();
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebView::scrollBy( 
-    /* [in] */ LPPOINT offset)
+HRESULT WebView::scrollBy(LPPOINT offset)
 {
     if (!offset)
         return E_POINTER;
-    m_page->mainFrame().view()->scrollBy(IntSize(offset->x, offset->y));
+
+    IntSize scrollDelta(offset->x, offset->y);
+    scrollDelta.scale(1.0f / deviceScaleFactor());
+    m_page->mainFrame().view()->scrollBy(scrollDelta);
     return S_OK;
 }
 
-HRESULT STDMETHODCALLTYPE WebView::visibleContentRect( 
-    /* [retval][out] */ LPRECT rect)
+HRESULT WebView::visibleContentRect(LPRECT rect)
 {
     if (!rect)
         return E_POINTER;
+
     FloatRect visibleContent = m_page->mainFrame().view()->visibleContentRect();
+    visibleContent.scale(deviceScaleFactor());
     rect->left = (LONG) visibleContent.x();
     rect->top = (LONG) visibleContent.y();
     rect->right = (LONG) visibleContent.maxX();
@@ -5687,6 +5753,8 @@ void WebView::prepareCandidateWindow(Frame* targetFrame, HIMC hInputContext)
         caret = targetFrame->editor().firstRectForRange(tempRange.get());
     }
     caret = targetFrame->view()->contentsToWindow(caret);
+    caret.scale(deviceScaleFactor());
+
     CANDIDATEFORM form;
     form.dwIndex = 0;
     form.dwStyle = CFS_EXCLUDE;
@@ -5946,6 +6014,7 @@ LRESULT WebView::onIMERequestCharPosition(Frame* targetFrame, IMECHARPOSITION* c
         caret = targetFrame->editor().firstRectForRange(tempRange.get());
     }
     caret = targetFrame->view()->contentsToWindow(caret);
+    caret.scale(deviceScaleFactor());
     charPos->pt.x = caret.x();
     charPos->pt.y = caret.y();
     ::ClientToScreen(m_viewWindow, &charPos->pt);
@@ -6623,7 +6692,6 @@ void WebView::setAcceleratedCompositing(bool accelerated)
             ::GetClientRect(m_viewWindow, &clientRect);
             m_backingLayer->setSize(IntRect(clientRect).size());
             m_backingLayer->setNeedsDisplay();
-
             m_layerTreeHost->setRootChildLayer(PlatformCALayer::platformCALayer(m_backingLayer->platformLayer()));
 
             // We aren't going to be using our backing store while we're in accelerated compositing
@@ -6772,15 +6840,22 @@ void WebView::notifyFlushRequired(const GraphicsLayer*)
     flushPendingGraphicsLayerChangesSoon();
 }
 
-void WebView::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& inClip)
+void WebView::paintContents(const GraphicsLayer*, GraphicsContext& context, GraphicsLayerPaintingPhase, const FloatRect& inClipPixels)
 {
     Frame* frame = core(m_mainFrame);
     if (!frame)
         return;
 
+    float scaleFactor = deviceScaleFactor();
+    float inverseScaleFactor = 1.0f / scaleFactor;
+
+    FloatRect logicalClip = inClipPixels;
+    logicalClip.scale(inverseScaleFactor);
+
     context.save();
-    context.clip(inClip);
-    frame->view()->paint(&context, enclosingIntRect(inClip));
+    context.scale(FloatSize(scaleFactor, scaleFactor));
+    context.clip(logicalClip);
+    frame->view()->paint(&context, enclosingIntRect(logicalClip));
     context.restore();
 }
 
@@ -7123,6 +7198,8 @@ HRESULT STDMETHODCALLTYPE WebView::firstRectForCharacterRangeForTesting(
     IntRect rect = frame.editor().firstRectForRange(range.get());
     resultIntRect = frame.view()->contentsToWindow(rect);
 
+    resultIntRect.scale(deviceScaleFactor());
+
     resultRect->left = resultIntRect.x();
     resultRect->top = resultIntRect.y();
     resultRect->right = resultIntRect.x() + resultIntRect.width();
@@ -7174,12 +7251,6 @@ HRESULT WebView::dispatchPendingLoadRequests()
     return S_OK;
 }
 
-static float scaleFactorFromWindow(HWND window)
-{
-    HWndDC dc(window);
-    return ::GetDeviceCaps(dc, LOGPIXELSX) / 96.0f;
-}
-
 float WebView::deviceScaleFactor() const
 {
     if (m_customDeviceScaleFactor)
@@ -7188,12 +7259,12 @@ float WebView::deviceScaleFactor() const
     // FIXME(146335): Should check for Windows 8.1 High DPI Features here first.
 
     if (m_viewWindow)
-        return scaleFactorFromWindow(m_viewWindow);
+        return WebCore::deviceScaleFactorForWindow(m_viewWindow);
 
     if (m_hostWindow)
-        return scaleFactorFromWindow(m_hostWindow);
+        return WebCore::deviceScaleFactorForWindow(m_hostWindow);
 
-    return scaleFactorFromWindow(0);
+    return WebCore::deviceScaleFactorForWindow(nullptr);
 }
 
 HRESULT WebView::setCustomBackingScaleFactor(double customScaleFactor)
index c642d6e..95d7430 100644 (file)
@@ -988,6 +988,9 @@ public:
     /* [out, retval] */ RECT* resultRect);
 
     HRESULT STDMETHODCALLTYPE selectedRangeForTesting(/* [out] */ UINT* location, /* [out] */ UINT* length);
+
+    float deviceScaleFactor() const;
+
 private:
     void setZoomMultiplier(float multiplier, bool isTextOnly);
     float zoomMultiplier(bool isTextOnly);
@@ -1000,6 +1003,7 @@ private:
     bool active();
 
     void sizeChanged(const WebCore::IntSize&);
+    bool dpiChanged(float, const WebCore::IntSize&);
 
     enum WindowsToPaint { PaintWebViewOnly, PaintWebViewAndChildren };
     void paintIntoBackingStore(WebCore::FrameView*, HDC bitmapDC, const WebCore::IntRect& dirtyRect, WindowsToPaint);
@@ -1026,8 +1030,6 @@ private:
     bool m_shouldInvertColors;
     void setShouldInvertColors(bool);
 
-    float deviceScaleFactor() const;
-
 protected:
     static bool registerWebViewWindowClass();
     static LRESULT CALLBACK WebViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
index 8c04aa2..c529841 100644 (file)
@@ -1,3 +1,28 @@
+2015-07-23  Brent Fulgham  <bfulgham@apple.com>
+
+        [Win] Implement proper High DPI support features
+        https://bugs.webkit.org/show_bug.cgi?id=146335
+        <rdar://problem/21558269>
+
+        Reviewed by Alex Christensen.
+
+        Update WinLauncher to take device scaling factor into account.
+
+        * WinLauncher/Common.cpp:
+        (resizeSubViews): Make sure toolbars and URL bar are properly sized and using
+        a valid font.
+        (computeFullDesktopFrame): Handle high DPI desktops.
+        (WndProc): Make comments more precise.
+        * WinLauncher/WinLauncher.cpp:
+        (WinLauncher::init): Determine device scale factor at launch.
+        (WinLauncher::updateDeviceScaleFactor): Added.
+        * WinLauncher/WinLauncher.h:
+        * WinLauncher/WinLauncherWebHost.h: Use C++11 initialization.
+        * WinLauncher/WinMain.cpp: Size interface based on scaling factor.
+        (wWinMain): Ditto.
+        * win/DLLLauncher/DLLLauncherMain.cpp:
+        (wWinMain): Tell Windows we understand high DPI.
+
 2015-07-23  Alex Christensen  <achristensen@webkit.org>
 
         [Win] Unreviewed build fix after r187169.
index b8657c7..3144925 100644 (file)
 
 static const int maxHistorySize = 10;
 
+#ifndef WM_DPICHANGED
+#define WM_DPICHANGED 0x02E0
+#endif
+
 typedef _com_ptr_t<_com_IIID<IWebFrame, &__uuidof(IWebFrame)>> IWebFramePtr;
 typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
 
@@ -72,6 +76,7 @@ typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequ
 HINSTANCE hInst;
 HWND hMainWnd;
 HWND hURLBarWnd;
+HGDIOBJ hURLFont;
 HWND hBackButtonWnd;
 HWND hForwardButtonWnd;
 HWND hCacheWnd;
@@ -101,17 +106,29 @@ INT_PTR CALLBACK Caches(HWND, UINT, WPARAM, LPARAM);
 static void loadURL(BSTR urlBStr);
 static void updateStatistics(HWND hDlg);
 
+namespace WebCore {
+float deviceScaleFactorForWindow(HWND);
+}
+
 static void resizeSubViews()
 {
     if (gWinLauncher->usesLayeredWebView() || !gViewWindow)
         return;
 
+    float scaleFactor = WebCore::deviceScaleFactorForWindow(gViewWindow);
+
     RECT rcClient;
     GetClientRect(hMainWnd, &rcClient);
-    MoveWindow(hBackButtonWnd, 0, 0, CONTROLBUTTON_WIDTH, URLBAR_HEIGHT, TRUE);
-    MoveWindow(hForwardButtonWnd, CONTROLBUTTON_WIDTH, 0, CONTROLBUTTON_WIDTH, URLBAR_HEIGHT, TRUE);
-    MoveWindow(hURLBarWnd, CONTROLBUTTON_WIDTH * 2, 0, rcClient.right, URLBAR_HEIGHT, TRUE);
-    MoveWindow(gViewWindow, 0, URLBAR_HEIGHT, rcClient.right, rcClient.bottom - URLBAR_HEIGHT, TRUE);
+
+    int height = scaleFactor * URLBAR_HEIGHT;
+    int width = scaleFactor * CONTROLBUTTON_WIDTH;
+
+    MoveWindow(hBackButtonWnd, 0, 0, width, height, TRUE);
+    MoveWindow(hForwardButtonWnd, width, 0, width, height, TRUE);
+    MoveWindow(hURLBarWnd, width * 2, 0, rcClient.right, height, TRUE);
+    MoveWindow(gViewWindow, 0, height, rcClient.right, rcClient.bottom - height, TRUE);
+
+    ::SendMessage(hURLBarWnd, static_cast<UINT>(WM_SETFONT), reinterpret_cast<WPARAM>(gWinLauncher->urlBarFont()), TRUE);
 }
 
 static void subclassForLayeredWindow()
@@ -132,10 +149,12 @@ static void computeFullDesktopFrame()
     if (!::SystemParametersInfo(SPI_GETWORKAREA, 0, static_cast<void*>(&desktop), 0))
         return;
 
+    float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
+
     s_windowPosition.x = 0;
     s_windowPosition.y = 0;
-    s_windowSize.cx = desktop.right - desktop.left;
-    s_windowSize.cy = desktop.bottom - desktop.top;
+    s_windowSize.cx = scaleFactor * (desktop.right - desktop.left);
+    s_windowSize.cy = scaleFactor * (desktop.bottom - desktop.top);
 }
 
 BOOL WINAPI DllMain(HINSTANCE dllInstance, DWORD reason, LPVOID)
@@ -421,13 +440,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
             // For testing our transparent window, we need a region to use as a handle for
             // dragging. The right way to do this would be to query the web view to see what's
             // under the mouse. However, for testing purposes we just use an arbitrary
-            // 30 pixel band at the top of the view as an arbitrary gripping location.
+            // 30 logical pixel band at the top of the view as an arbitrary gripping location.
             //
             // When we are within this bad, return HT_CAPTION to tell Windows we want to
             // treat this region as if it were the title bar on a normal window.
             int y = HIWORD(lParam);
-
-            if ((y > window.top) && (y < window.top + dragBarHeight))
+            float scaledDragBarHeightFactor = dragBarHeight * gWinLauncher->deviceScaleFactor();
+            if ((y > window.top) && (y < window.top + scaledDragBarHeightFactor))
                 return HTCAPTION;
         }
         return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
@@ -519,6 +538,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         resizeSubViews();
         break;
+    case WM_DPICHANGED:
+        if (gWinLauncher)
+            gWinLauncher->updateDeviceScaleFactor();
+        return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     default:
         return CallWindowProc(parentProc, hWnd, message, wParam, lParam);
     }
index 413a399..3990740 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2008, 2013, 2014 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006, 2008, 2013-2015 Apple Inc.  All rights reserved.
  * Copyright (C) 2009, 2011 Brent Fulgham.  All rights reserved.
  * Copyright (C) 2009, 2010, 2011 Appcelerator, Inc. All rights reserved.
  * Copyright (C) 2013 Alex Christensen. All rights reserved.
 #include <string>
 #include <vector>
 
+namespace WebCore {
+float deviceScaleFactorForWindow(HWND);
+}
+
 static const int maxHistorySize = 10;
 
 typedef _com_ptr_t<_com_IIID<IWebMutableURLRequest, &__uuidof(IWebMutableURLRequest)>> IWebMutableURLRequestPtr;
@@ -61,6 +65,8 @@ WinLauncher::WinLauncher(HWND mainWnd, HWND urlBarWnd, bool useLayeredWebView, b
 
 HRESULT WinLauncher::init()
 {
+    updateDeviceScaleFactor();
+
     HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView, reinterpret_cast<void**>(&m_webView.GetInterfacePtr()));
     if (FAILED(hr))
         return hr;
@@ -478,3 +484,19 @@ void WinLauncher::zoomOut()
 
     webActions->zoomPageOut(nullptr);
 }
+
+void WinLauncher::generateFontForScaleFactor(float scaleFactor)
+{
+    if (m_hURLBarFont)
+        ::DeleteObject(m_hURLBarFont);
+
+    m_hURLBarFont = ::CreateFont(scaleFactor * 18, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
+        OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, L"Times New Roman");
+}
+
+
+void WinLauncher::updateDeviceScaleFactor()
+{
+    m_deviceScaleFactor = WebCore::deviceScaleFactorForWindow(m_hMainWnd);
+    generateFontForScaleFactor(m_deviceScaleFactor);
+}
index 5ac348e..1d55804 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc.  All rights reserved.
+ * Copyright (C) 2014-2015 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -90,7 +90,14 @@ public:
     void zoomIn();
     void zoomOut();
 
+    float deviceScaleFactor() { return m_deviceScaleFactor; }
+    void updateDeviceScaleFactor();
+
+    HGDIOBJ urlBarFont() { return m_hURLBarFont; }
+
 private:
+    void generateFontForScaleFactor(float);
+
     std::vector<IWebHistoryItemPtr> m_historyItems;
 
     std::unique_ptr<PageLoadTestClient> m_pageLoadTestClient;
@@ -112,8 +119,10 @@ private:
     IWebCoreStatisticsPtr m_statistics;
     IWebCachePtr m_webCache;
 
-    HWND m_hMainWnd;
-    HWND m_hURLBarWnd;
+    HWND m_hMainWnd { nullptr };
+    HWND m_hURLBarWnd { nullptr };
+    HGDIOBJ m_hURLBarFont { nullptr };
 
+    float m_deviceScaleFactor { 1.0f };
     bool m_useLayeredWebView;
 };
index 856fb10..b83dc2c 100644 (file)
@@ -76,7 +76,9 @@ protected:
     HRESULT updateAddressBar(IWebView&);
 
 private:
-    HWND m_hURLBarWnd;
-    ULONG m_refCount;
-    WinLauncher* m_client;
+    HWND m_hURLBarWnd { 0 };
+    HGDIOBJ m_URLBarFont { 0 };
+    HGDIOBJ m_oldFont { 0 };
+    ULONG m_refCount { 0 };
+    WinLauncher* m_client { nullptr };
 };
index ecd94bd..d19a458 100644 (file)
 #include "WinLauncherWebHost.h"
 #include "Common.cpp"
 
+namespace WebCore {
+float deviceScaleFactorForWindow(HWND);
+}
+
 int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int nCmdShow)
 {
 #ifdef _CRTDBG_MAP_ALLOC
@@ -65,10 +69,12 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int nCmdShow)
     // Init COM
     OleInitialize(nullptr);
 
+    float scaleFactor = WebCore::deviceScaleFactorForWindow(nullptr);
+
     if (usesLayeredWebView) {
         hURLBarWnd = CreateWindow(L"EDIT", L"Type URL Here",
             WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, 
-            s_windowPosition.x, s_windowPosition.y + s_windowSize.cy, s_windowSize.cx, URLBAR_HEIGHT,
+            scaleFactor * s_windowPosition.x, scaleFactor * (s_windowPosition.y + s_windowSize.cy), scaleFactor * s_windowSize.cx, scaleFactor * URLBAR_HEIGHT,
             0, 0, hInst, 0);
     } else {
         hMainWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
@@ -78,8 +84,8 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int nCmdShow)
             return FALSE;
 
         hBackButtonWnd = CreateWindow(L"BUTTON", L"<", WS_CHILD | WS_VISIBLE  | BS_TEXT, 0, 0, 0, 0, hMainWnd, 0, hInst, 0);
-        hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE  | BS_TEXT, CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0);
-        hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, CONTROLBUTTON_WIDTH * 2, 0, 0, 0, hMainWnd, 0, hInst, 0);
+        hForwardButtonWnd = CreateWindow(L"BUTTON", L">", WS_CHILD | WS_VISIBLE | BS_TEXT, scaleFactor * CONTROLBUTTON_WIDTH, 0, 0, 0, hMainWnd, 0, hInst, 0);
+        hURLBarWnd = CreateWindow(L"EDIT", 0, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | ES_AUTOVSCROLL, scaleFactor * CONTROLBUTTON_WIDTH * 2, 0, 0, 0, hMainWnd, 0, hInst, 0);
 
         ShowWindow(hMainWnd, nCmdShow);
         UpdateWindow(hMainWnd);
@@ -93,7 +99,11 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int nCmdShow)
 
     SetFocus(hURLBarWnd);
 
-    RECT clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy };
+    RECT clientRect;
+    ::GetClientRect(hMainWnd, &clientRect);
+
+    if (usesLayeredWebView)
+        clientRect = { s_windowPosition.x, s_windowPosition.y, s_windowPosition.x + s_windowSize.cx, s_windowPosition.y + s_windowSize.cy };
 
     WinLauncherWebHost* webHost = nullptr;
 
index 9fc2d21..2a08001 100644 (file)
@@ -193,6 +193,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpstrCm
     _set_FMA3_enable(0);
 #endif
 
+    BOOL didIt = SetProcessDPIAware();
+    _ASSERT(didIt);
+
 #ifdef _CRTDBG_MAP_ALLOC
     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);