Update gesture swipe shadow style
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Apr 2015 00:02:53 +0000 (00:02 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Apr 2015 00:02:53 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143616
<rdar://problem/19295843>

Reviewed by Darin Adler.

* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::beginSwipeGesture):
For the modern shadow style, use a layer stretched along the edge of the swiping content
with the newly added PNGs as the layer contents.

Add a dimming layer over the lower layer of content which fades in/out
during the swipe.

(WebKit::ViewGestureController::handleSwipeGesture):
Fade the dimming layer in and out during the entire swipe.
Fade the shadow layer out during the last few pixels of the swipe.

(WebKit::ViewGestureController::removeSwipeSnapshot):
Unparent the new layers.

* WebKit2.xcodeproj/project.pbxproj:
* Resources/SwipeShadow.png:
* Resources/SwipeShadow@2x.png:
Add the new resources.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Resources/SwipeShadow.png [new file with mode: 0644]
Source/WebKit2/Resources/SwipeShadow@2x.png [new file with mode: 0644]
Source/WebKit2/UIProcess/mac/ViewGestureController.h
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

index 066d67a..7d8fdfa 100644 (file)
@@ -1,3 +1,32 @@
+2015-04-14  Tim Horton  <timothy_horton@apple.com>
+
+        Update gesture swipe shadow style
+        https://bugs.webkit.org/show_bug.cgi?id=143616
+        <rdar://problem/19295843>
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        For the modern shadow style, use a layer stretched along the edge of the swiping content
+        with the newly added PNGs as the layer contents.
+
+        Add a dimming layer over the lower layer of content which fades in/out
+        during the swipe.
+
+        (WebKit::ViewGestureController::handleSwipeGesture):
+        Fade the dimming layer in and out during the entire swipe.
+        Fade the shadow layer out during the last few pixels of the swipe.
+
+        (WebKit::ViewGestureController::removeSwipeSnapshot):
+        Unparent the new layers.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        * Resources/SwipeShadow.png:
+        * Resources/SwipeShadow@2x.png:
+        Add the new resources.
+
 2015-04-14  Brian Weinstein  <bweinstein@apple.com>
 
         Add SPI to clear HSTS hosts added since a date.
diff --git a/Source/WebKit2/Resources/SwipeShadow.png b/Source/WebKit2/Resources/SwipeShadow.png
new file mode 100644 (file)
index 0000000..5469203
Binary files /dev/null and b/Source/WebKit2/Resources/SwipeShadow.png differ
diff --git a/Source/WebKit2/Resources/SwipeShadow@2x.png b/Source/WebKit2/Resources/SwipeShadow@2x.png
new file mode 100644 (file)
index 0000000..f958f2a
Binary files /dev/null and b/Source/WebKit2/Resources/SwipeShadow@2x.png differ
index e289bc0..307249f 100644 (file)
@@ -186,6 +186,8 @@ private:
     RetainPtr<WKSwipeCancellationTracker> m_swipeCancellationTracker;
     RetainPtr<CALayer> m_swipeLayer;
     RetainPtr<CALayer> m_swipeSnapshotLayer;
+    RetainPtr<CALayer> m_swipeShadowLayer;
+    RetainPtr<CALayer> m_swipeDimmingLayer;
     Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
 
     SwipeTransitionStyle m_swipeTransitionStyle { SwipeTransitionStyle::Overlap };
index 5546e51..a8a6f49 100644 (file)
 
 using namespace WebCore;
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
+#define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 1
+#else
+#define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 0
+#endif
+
 static const double minMagnification = 1;
 static const double maxMagnification = 3;
 
@@ -58,8 +64,13 @@ static const double zoomOutResistance = 0.10;
 static const float smartMagnificationElementPadding = 0.05;
 static const float smartMagnificationPanScrollThreshold = 100;
 
+#if ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
 static const double swipeOverlayShadowOpacity = 0.66;
 static const double swipeOverlayShadowRadius = 3;
+#else
+static const double swipeOverlayShadowOpacity = 0.47;
+static const double swipeOverlayDimmingOpacity = 0.12;
+#endif
 
 static const CGFloat minimumHorizontalSwipeDistance = 15;
 static const float minimumScrollEventRatioForSwipe = 0.5;
@@ -564,8 +575,9 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
     [m_swipeLayer setGeometryFlipped:geometryIsFlippedToRoot];
     [m_swipeLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
 
+    float deviceScaleFactor = m_webPageProxy.deviceScaleFactor();
     [m_swipeSnapshotLayer setContentsGravity:kCAGravityTopLeft];
-    [m_swipeSnapshotLayer setContentsScale:m_webPageProxy.deviceScaleFactor()];
+    [m_swipeSnapshotLayer setContentsScale:deviceScaleFactor];
     [m_swipeSnapshotLayer setAnchorPoint:CGPointZero];
     [m_swipeSnapshotLayer setFrame:CGRectMake(0, 0, swipeArea.width(), swipeArea.height() - topContentInset)];
     [m_swipeSnapshotLayer setName:@"Gesture Swipe Snapshot Layer"];
@@ -576,8 +588,16 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
     if (m_webPageProxy.preferences().viewGestureDebuggingEnabled())
         applyDebuggingPropertiesToSwipeViews();
 
+
+    CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
+    if (direction == SwipeDirection::Back)
+        [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
+    else
+        [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
+
     // We don't know enough about the custom views' hierarchy to apply a shadow.
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap && m_customSwipeViews.isEmpty()) {
+#if ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
         if (direction == SwipeDirection::Back) {
             float topContentInset = m_webPageProxy.topContentInset();
             FloatRect shadowRect(FloatPoint(0, topContentInset), m_webPageProxy.viewSize() - FloatSize(0, topContentInset));
@@ -593,13 +613,37 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
             [m_swipeLayer setShadowRadius:swipeOverlayShadowRadius];
             [m_swipeLayer setShadowPath:shadowPath.get()];
         }
+#else
+        FloatRect dimmingRect(FloatPoint(), m_webPageProxy.viewSize());
+        m_swipeDimmingLayer = adoptNS([[CALayer alloc] init]);
+        [m_swipeDimmingLayer setName:@"Gesture Swipe Dimming Layer"];
+        [m_swipeDimmingLayer setBackgroundColor:[NSColor blackColor].CGColor];
+        [m_swipeDimmingLayer setOpacity:swipeOverlayDimmingOpacity];
+        [m_swipeDimmingLayer setAnchorPoint:CGPointZero];
+        [m_swipeDimmingLayer setFrame:dimmingRect];
+        [m_swipeDimmingLayer setGeometryFlipped:geometryIsFlippedToRoot];
+        [m_swipeDimmingLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
+
+        NSImage *shadowImage = [[NSBundle bundleForClass:[WKSwipeCancellationTracker class]] imageForResource:@"SwipeShadow"];
+        FloatRect shadowRect(-shadowImage.size.width, topContentInset, shadowImage.size.width, m_webPageProxy.viewSize().height() - topContentInset);
+        m_swipeShadowLayer = adoptNS([[CALayer alloc] init]);
+        [m_swipeShadowLayer setName:@"Gesture Swipe Shadow Layer"];
+        [m_swipeShadowLayer setBackgroundColor:[NSColor colorWithPatternImage:shadowImage].CGColor];
+        [m_swipeShadowLayer setContentsScale:deviceScaleFactor];
+        [m_swipeShadowLayer setOpacity:swipeOverlayShadowOpacity];
+        [m_swipeShadowLayer setAnchorPoint:CGPointZero];
+        [m_swipeShadowLayer setFrame:shadowRect];
+        [m_swipeShadowLayer setGeometryFlipped:geometryIsFlippedToRoot];
+        [m_swipeShadowLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
+
+        if (direction == SwipeDirection::Back)
+            [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() above:m_swipeLayer.get()];
+        else
+            [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() below:m_swipeLayer.get()];
+
+        [snapshotLayerParent insertSublayer:m_swipeShadowLayer.get() above:m_swipeLayer.get()];
+#endif
     }
-
-    CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
-    if (direction == SwipeDirection::Back)
-        [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
-    else
-        [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
 }
 
 void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection direction)
@@ -617,6 +661,23 @@ void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetIte
 
     double swipingLayerOffset = floor(width * progress);
 
+#if !ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
+    double dimmingProgress = (direction == SwipeDirection::Back) ? 1 - progress : -progress;
+    dimmingProgress = std::min(1., std::max(dimmingProgress, 0.));
+    [m_swipeDimmingLayer setOpacity:dimmingProgress * swipeOverlayDimmingOpacity];
+
+    double absoluteProgress = fabs(progress);
+    double remainingSwipeDistance = width - fabs(absoluteProgress * width);
+    double shadowFadeDistance = [m_swipeShadowLayer bounds].size.width;
+    if (remainingSwipeDistance < shadowFadeDistance)
+        [m_swipeShadowLayer setOpacity:(remainingSwipeDistance / shadowFadeDistance) * swipeOverlayShadowOpacity];
+    else
+        [m_swipeShadowLayer setOpacity:swipeOverlayShadowOpacity];
+
+    if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap)
+        [m_swipeShadowLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Back ? 0 : width) + swipingLayerOffset, 0, 0)];
+#endif
+
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
         if (direction == SwipeDirection::Forward) {
             [m_swipeLayer setTransform:CATransform3DMakeTranslation(width + swipingLayerOffset, 0, 0)];
@@ -790,6 +851,14 @@ void ViewGestureController::removeSwipeSnapshot()
     [m_swipeLayer removeFromSuperlayer];
     m_swipeLayer = nullptr;
 
+#if !ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
+    [m_swipeShadowLayer removeFromSuperlayer];
+    m_swipeShadowLayer = nullptr;
+
+    [m_swipeDimmingLayer removeFromSuperlayer];
+    m_swipeDimmingLayer = nullptr;
+#endif
+
     m_currentSwipeLiveLayers.clear();
 
     m_activeGestureType = ViewGestureType::None;
index 4744a4c..8e5b75f 100644 (file)
                2DACE64E18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DACE64D18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h */; };
                2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */; };
                2DAF06D718BD1A470081CEB1 /* SmartMagnificationController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */; };
+               2DC658351AD7237600D44508 /* SwipeShadow.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC658331AD7237600D44508 /* SwipeShadow.png */; };
+               2DC658361AD7237600D44508 /* SwipeShadow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC658341AD7237600D44508 /* SwipeShadow@2x.png */; };
                2DC6D9C318C44A610043BAD4 /* WKWebViewContentProviderRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */; };
                2DC6D9C418C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */; };
                2DD12A081A8177F3002C74E6 /* WKPageRenderingProgressEvents.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD12A071A8177F3002C74E6 /* WKPageRenderingProgressEvents.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmartMagnificationController.h; path = ios/SmartMagnificationController.h; sourceTree = "<group>"; };
                2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SmartMagnificationController.mm; path = ios/SmartMagnificationController.mm; sourceTree = "<group>"; };
                2DAF06D818BD23BA0081CEB1 /* SmartMagnificationController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = SmartMagnificationController.messages.in; path = ios/SmartMagnificationController.messages.in; sourceTree = "<group>"; };
+               2DC658331AD7237600D44508 /* SwipeShadow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = SwipeShadow.png; path = Resources/SwipeShadow.png; sourceTree = "<group>"; };
+               2DC658341AD7237600D44508 /* SwipeShadow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "SwipeShadow@2x.png"; path = "Resources/SwipeShadow@2x.png"; sourceTree = "<group>"; };
                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewContentProviderRegistry.h; sourceTree = "<group>"; };
                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewContentProviderRegistry.mm; sourceTree = "<group>"; };
                2DD12A071A8177F3002C74E6 /* WKPageRenderingProgressEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPageRenderingProgressEvents.h; sourceTree = "<group>"; };
                                1C8AE75F1992F62F00ABF6EC /* DockBottomLegacy.pdf */,
                                1CB75C931701E880009F809F /* DockRight.pdf */,
                                1C8AE7601992F62F00ABF6EC /* DockRightLegacy.pdf */,
+                               2DC658331AD7237600D44508 /* SwipeShadow.png */,
+                               2DC658341AD7237600D44508 /* SwipeShadow@2x.png */,
                                8DC2EF5A0486A6940098B216 /* Info.plist */,
                                089C1666FE841158C02AAC07 /* InfoPlist.strings */,
                                E1D26A4C1759634E0095BFD1 /* WebContentProcess.xib */,
                                1C8AE7611992F63A00ABF6EC /* DockBottomLegacy.pdf in Resources */,
                                1CB75C941701E880009F809F /* DockRight.pdf in Resources */,
                                1C8AE7621992F63C00ABF6EC /* DockRightLegacy.pdf in Resources */,
+                               2DC658361AD7237600D44508 /* SwipeShadow@2x.png in Resources */,
                                8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */,
+                               2DC658351AD7237600D44508 /* SwipeShadow.png in Resources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };