Title: [151877] trunk/Source
Revision
151877
Author
[email protected]
Date
2013-06-22 12:41:31 -0700 (Sat, 22 Jun 2013)

Log Message

screen.availWidth always returns width of primary display
https://bugs.webkit.org/show_bug.cgi?id=117863

Source/WebCore:

Reviewed by Geoffrey Garen.

In WebKit2, Widgets have no platformWidget, so trying to get to the
NSScreen via the platform widget's window never succeeded, and we always
fell back on getting info for the main display.

However, we were already pushing the WKView's displayID down to the
WebProcess for the requestAnimationFrame infrastructure, so use that.

Add a virtual function on Widget windowDisplayID(), that is overridden
in FrameView to return the PlatformDisplayID which Page has.

Fix PlatformScreenMac to fall back to Widget::windowDisplayID() when it fails
to get an NSWindow from the Widget.

Add a utility category on NSScreen to get an NSScreen's displayID, and to
find an NSScreen given a displayID.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* page/FrameView.cpp:
(WebCore::FrameView::windowDisplayID):
* page/FrameView.h:
* platform/Widget.cpp:
(WebCore::Widget::windowDisplayID):
* platform/Widget.h:
* platform/mac/PlatformScreenMac.h: Added.
* platform/mac/PlatformScreenMac.mm:
(+[NSScreen screenForDislayID:]):
(-[NSScreen displayID]):
(WebCore::screenRect):
(WebCore::screenAvailableRect):
* platform/mac/WidgetMac.mm:
(WebCore::Widget::windowDisplayID):

Source/WebKit2:

Reviewed by Geoffrey Garen.

In WebKit2, Widgets have no platformWidget, so trying to get to the
NSScreen via the platform widget's window never succeeded, and we always
fell back on getting info for the main display.

However, we were already pushing the WKView's displayID down to the
WebProcess for the requestAnimationFrame infrastructure, so use that.

The WebProcess would not receive a displayID for a WKView until the window
was activated; fix by calling -doWindowDidChangeScreen when the view
moves to a window, rather than doing it from -_windowDidBecomeKey:.

* UIProcess/API/mac/WKView.mm:
(-[WKView viewDidMoveToWindow]):
(-[WKView _windowDidBecomeKey:]):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (151876 => 151877)


--- trunk/Source/WebCore/ChangeLog	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/ChangeLog	2013-06-22 19:41:31 UTC (rev 151877)
@@ -1,3 +1,43 @@
+2013-06-22  Simon Fraser  <[email protected]>
+
+        screen.availWidth always returns width of primary display
+        https://bugs.webkit.org/show_bug.cgi?id=117863
+
+        Reviewed by Geoffrey Garen.
+
+        In WebKit2, Widgets have no platformWidget, so trying to get to the
+        NSScreen via the platform widget's window never succeeded, and we always
+        fell back on getting info for the main display.
+
+        However, we were already pushing the WKView's displayID down to the
+        WebProcess for the requestAnimationFrame infrastructure, so use that.
+
+        Add a virtual function on Widget windowDisplayID(), that is overridden
+        in FrameView to return the PlatformDisplayID which Page has.
+
+        Fix PlatformScreenMac to fall back to Widget::windowDisplayID() when it fails
+        to get an NSWindow from the Widget.
+
+        Add a utility category on NSScreen to get an NSScreen's displayID, and to
+        find an NSScreen given a displayID.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::windowDisplayID):
+        * page/FrameView.h:
+        * platform/Widget.cpp:
+        (WebCore::Widget::windowDisplayID):
+        * platform/Widget.h:
+        * platform/mac/PlatformScreenMac.h: Added.
+        * platform/mac/PlatformScreenMac.mm:
+        (+[NSScreen screenForDislayID:]):
+        (-[NSScreen displayID]):
+        (WebCore::screenRect):
+        (WebCore::screenAvailableRect):
+        * platform/mac/WidgetMac.mm:
+        (WebCore::Widget::windowDisplayID):
+
 2013-06-21  Geoffrey Garen  <[email protected]>
 
         Crashes due to NULL dereference beneath WebCore::StyleResolver::loadPendingSVGDocuments and related functions

Modified: trunk/Source/WebCore/WebCore.exp.in (151876 => 151877)


--- trunk/Source/WebCore/WebCore.exp.in	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-06-22 19:41:31 UTC (rev 151877)
@@ -1011,6 +1011,7 @@
 __ZN7WebCore6Widget8setFocusEb
 __ZN7WebCore6Widget9setParentEPNS_10ScrollViewE
 __ZN7WebCore6WidgetD2Ev
+__ZNK7WebCore6Widget15windowDisplayIDEv
 __ZN7WebCore6toInt8EPN3JSC9ExecStateENS0_7JSValueENS_30IntegerConversionConfigurationE
 __ZN7WebCore6toNodeEN3JSC7JSValueE
 __ZN7WebCore7Element12setAttributeERKN3WTF12AtomicStringES4_Ri

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (151876 => 151877)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-06-22 19:41:31 UTC (rev 151877)
@@ -251,6 +251,7 @@
 		0F13164016ED0CDE0035CC04 /* PlatformCAFiltersMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F13163F16ED0CDE0035CC04 /* PlatformCAFiltersMac.mm */; };
 		0F15DA8A0F3AAEE70000CE47 /* AnimationControllerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F15DA890F3AAEE70000CE47 /* AnimationControllerPrivate.h */; };
 		0F29C16E1300C2E2002D794E /* AccessibilityAllInOne.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F29C16D1300C2E2002D794E /* AccessibilityAllInOne.cpp */; };
+		0F2C98EB1774084C00C1BBBA /* PlatformScreenMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F2C98EA1774084C00C1BBBA /* PlatformScreenMac.h */; };
 		0F3DD44F12F5EA1B000D9190 /* ShadowBlur.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */; };
 		0F3DD45012F5EA1B000D9190 /* ShadowBlur.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */; };
 		0F3F0E59157030C3006DA57F /* RenderGeometryMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F3F0E57157030C3006DA57F /* RenderGeometryMap.cpp */; };
@@ -6473,6 +6474,7 @@
 		0F13163F16ED0CDE0035CC04 /* PlatformCAFiltersMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformCAFiltersMac.mm; path = ca/mac/PlatformCAFiltersMac.mm; sourceTree = "<group>"; };
 		0F15DA890F3AAEE70000CE47 /* AnimationControllerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnimationControllerPrivate.h; path = animation/AnimationControllerPrivate.h; sourceTree = "<group>"; };
 		0F29C16D1300C2E2002D794E /* AccessibilityAllInOne.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityAllInOne.cpp; sourceTree = "<group>"; };
+		0F2C98EA1774084C00C1BBBA /* PlatformScreenMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformScreenMac.h; sourceTree = "<group>"; };
 		0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowBlur.cpp; sourceTree = "<group>"; };
 		0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowBlur.h; sourceTree = "<group>"; };
 		0F3F0E57157030C3006DA57F /* RenderGeometryMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderGeometryMap.cpp; sourceTree = "<group>"; };
@@ -14592,6 +14594,7 @@
 				BCAA486E14A052530088FAC4 /* PlatformEventFactoryMac.h */,
 				BCAA486D14A052530088FAC4 /* PlatformEventFactoryMac.mm */,
 				C5F765BA14E1ECF4006C899B /* PlatformPasteboardMac.mm */,
+				0F2C98EA1774084C00C1BBBA /* PlatformScreenMac.h */,
 				BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */,
 				29E4D8E016B0959800C84704 /* PlatformSpeechSynthesizerMac.mm */,
 				0081FEFE16B0A2B6008AAA7A /* PublicSuffixMac.mm */,
@@ -20905,6 +20908,7 @@
 				A409C985116D0DDD007197BD /* AccessibilityProgressIndicator.h in Headers */,
 				29A812390FBB9C1D00510293 /* AccessibilityRenderObject.h in Headers */,
 				93C4F6EB1108F9A50099D0DB /* AccessibilityScrollbar.h in Headers */,
+				0F2C98EB1774084C00C1BBBA /* PlatformScreenMac.h in Headers */,
 				29489FC712C00F0300D83F0F /* AccessibilityScrollView.h in Headers */,
 				0709FC4E1025DEE30059CDBA /* AccessibilitySlider.h in Headers */,
 				29D7BCFA1444AF7D0070619C /* AccessibilitySpinButton.h in Headers */,

Modified: trunk/Source/WebCore/page/FrameView.cpp (151876 => 151877)


--- trunk/Source/WebCore/page/FrameView.cpp	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/page/FrameView.cpp	2013-06-22 19:41:31 UTC (rev 151877)
@@ -3975,6 +3975,14 @@
     return parentPoint;
 }
 
+PlatformDisplayID FrameView::windowDisplayID() const
+{
+    if (Page* page = m_frame->page())
+        return page->displayID();
+    
+    return Widget::windowDisplayID();
+}
+
 // Normal delay
 void FrameView::setRepaintThrottlingDeferredRepaintDelay(double p)
 {

Modified: trunk/Source/WebCore/page/FrameView.h (151876 => 151877)


--- trunk/Source/WebCore/page/FrameView.h	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/page/FrameView.h	2013-06-22 19:41:31 UTC (rev 151877)
@@ -482,6 +482,8 @@
     virtual IntPoint convertToContainingView(const IntPoint&) const OVERRIDE;
     virtual IntPoint convertFromContainingView(const IntPoint&) const OVERRIDE;
 
+    virtual PlatformDisplayID windowDisplayID() const OVERRIDE;
+
     // ScrollableArea interface
     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE;
     virtual void getTickmarks(Vector<IntRect>&) const OVERRIDE;

Modified: trunk/Source/WebCore/platform/Widget.cpp (151876 => 151877)


--- trunk/Source/WebCore/platform/Widget.cpp	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/platform/Widget.cpp	2013-06-22 19:41:31 UTC (rev 151877)
@@ -161,6 +161,11 @@
 {
     return point;
 }
+
+PlatformDisplayID Widget::windowDisplayID() const
+{
+    return 0;
+}
 #endif
 
 IntRect Widget::convertToContainingView(const IntRect& localRect) const

Modified: trunk/Source/WebCore/platform/Widget.h (151876 => 151877)


--- trunk/Source/WebCore/platform/Widget.h	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/platform/Widget.h	2013-06-22 19:41:31 UTC (rev 151877)
@@ -28,6 +28,7 @@
 #define Widget_h
 
 #include "IntRect.h"
+#include "PlatformScreen.h"
 #include <wtf/Forward.h>
 #include <wtf/RefCounted.h>
 
@@ -224,6 +225,9 @@
     virtual IntRect convertFromContainingView(const IntRect&) const;
     virtual IntPoint convertToContainingView(const IntPoint&) const;
     virtual IntPoint convertFromContainingView(const IntPoint&) const;
+    
+    // Return the displayID of the screen that this widget's window is primarily on.
+    virtual PlatformDisplayID windowDisplayID() const;
 
 private:
     void init(PlatformWidget); // Must be called by all Widget constructors to initialize cross-platform data.

Added: trunk/Source/WebCore/platform/mac/PlatformScreenMac.h (0 => 151877)


--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.h	2013-06-22 19:41:31 UTC (rev 151877)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#ifndef PlatformScreenMac_h
+#define PlatformScreenMac_h
+
+#include "PlatformScreen.h"
+
+@interface NSScreen(WebCoreNSScreenUtilities)
+
++ (NSScreen *)screenForDislayID:(PlatformDisplayID)displayID;
+- (PlatformDisplayID)displayID;
+
+@end
+
+
+#endif // PlatformScreenMac_h

Modified: trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm (151876 => 151877)


--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm	2013-06-22 19:41:31 UTC (rev 151877)
@@ -32,6 +32,22 @@
 #import "Widget.h"
 #import "NotImplemented.h"
 
+@implementation NSScreen(WebCoreNSScreenUtilities)
++ (NSScreen *)screenForDislayID:(PlatformDisplayID)displayID
+{
+    for (NSScreen *screen in [NSScreen screens]) {
+        if ([screen displayID] == displayID)
+            return screen;
+    }
+    return nil;
+}
+
+- (PlatformDisplayID)displayID
+{
+    return (PlatformDisplayID)[[[self deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
+}
+@end
+
 namespace WebCore {
 
 int screenDepth(Widget*)
@@ -52,16 +68,32 @@
 // These functions scale between screen and page coordinates because _javascript_/DOM operations 
 // assume that the screen and the page share the same coordinate system.
 
+static NSScreen *screenForWidget(Widget* widget, NSWindow *window)
+{
+    // Widget is in an NSWindow, use its screen.
+    if (window)
+        return screenForWindow(window);
+    
+    // Didn't get an NSWindow; probably WebKit2. Try using the Widget's display ID.
+    if (NSScreen *screen = [NSScreen screenForDislayID:widget->windowDisplayID()])
+        return screen;
+    
+    // Widget's window is offscreen, or no screens. Fall back to the first screen if available.
+    return screenForWindow(nil);
+}
+
 FloatRect screenRect(Widget* widget)
 {
     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
-    return toUserSpace([screenForWindow(window) frame], window);
+    NSScreen *screen = screenForWidget(widget, window);
+    return toUserSpace([screen frame], window);
 }
 
 FloatRect screenAvailableRect(Widget* widget)
 {
     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
-    return toUserSpace([screenForWindow(window) visibleFrame], window);
+    NSScreen *screen = screenForWidget(widget, window);
+    return toUserSpace([screen visibleFrame], window);
 }
 
 void screenColorProfile(ColorProfile&)

Modified: trunk/Source/WebCore/platform/mac/WidgetMac.mm (151876 => 151877)


--- trunk/Source/WebCore/platform/mac/WidgetMac.mm	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebCore/platform/mac/WidgetMac.mm	2013-06-22 19:41:31 UTC (rev 151877)
@@ -37,6 +37,7 @@
 #import "NotImplemented.h"
 #import "Page.h"
 #import "PlatformMouseEvent.h"
+#import "PlatformScreenMac.h"
 #import "ScrollView.h"
 #import "WebCoreFrameView.h"
 #import "WebCoreView.h"
@@ -355,4 +356,9 @@
     m_data->previousVisibleRect = NSZeroRect;
 }
 
+PlatformDisplayID Widget::windowDisplayID() const
+{
+    return [[[platformWidget() window] screen] displayID];
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (151876 => 151877)


--- trunk/Source/WebKit2/ChangeLog	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebKit2/ChangeLog	2013-06-22 19:41:31 UTC (rev 151877)
@@ -1,3 +1,25 @@
+2013-06-22  Simon Fraser  <[email protected]>
+
+        screen.availWidth always returns width of primary display
+        https://bugs.webkit.org/show_bug.cgi?id=117863
+
+        Reviewed by Geoffrey Garen.
+    
+        In WebKit2, Widgets have no platformWidget, so trying to get to the
+        NSScreen via the platform widget's window never succeeded, and we always
+        fell back on getting info for the main display.
+
+        However, we were already pushing the WKView's displayID down to the
+        WebProcess for the requestAnimationFrame infrastructure, so use that.
+        
+        The WebProcess would not receive a displayID for a WKView until the window
+        was activated; fix by calling -doWindowDidChangeScreen when the view
+        moves to a window, rather than doing it from -_windowDidBecomeKey:.
+        
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView _windowDidBecomeKey:]):
+
 2013-06-21  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Do not try to load videos in unit tests

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (151876 => 151877)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2013-06-22 05:56:14 UTC (rev 151876)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2013-06-22 19:41:31 UTC (rev 151877)
@@ -1981,6 +1981,7 @@
     // update the active state.
     if ([self window]) {
         _data->_windowHasValidBackingStore = NO;
+        [self doWindowDidChangeScreen];
         [self _updateWindowVisibility];
         _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
 
@@ -2037,9 +2038,6 @@
         [self _updateSecureInputState];
         _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
     }
-
-    // Send a change screen to make sure the initial displayID is set
-    [self doWindowDidChangeScreen];
 }
 
 - (void)_windowDidChangeScreen:(NSNotification *)notification
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to