Changeset 182822 in webkit


Ignore:
Timestamp:
Apr 14, 2015 5:02:53 PM (9 years ago)
Author:
timothy_horton@apple.com
Message:

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.

Location:
trunk/Source/WebKit2
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r182815 r182822  
     12015-04-14  Tim Horton  <timothy_horton@apple.com>
     2
     3        Update gesture swipe shadow style
     4        https://bugs.webkit.org/show_bug.cgi?id=143616
     5        <rdar://problem/19295843>
     6
     7        Reviewed by Darin Adler.
     8
     9        * UIProcess/mac/ViewGestureController.h:
     10        * UIProcess/mac/ViewGestureControllerMac.mm:
     11        (WebKit::ViewGestureController::beginSwipeGesture):
     12        For the modern shadow style, use a layer stretched along the edge of the swiping content
     13        with the newly added PNGs as the layer contents.
     14
     15        Add a dimming layer over the lower layer of content which fades in/out
     16        during the swipe.
     17
     18        (WebKit::ViewGestureController::handleSwipeGesture):
     19        Fade the dimming layer in and out during the entire swipe.
     20        Fade the shadow layer out during the last few pixels of the swipe.
     21
     22        (WebKit::ViewGestureController::removeSwipeSnapshot):
     23        Unparent the new layers.
     24
     25        * WebKit2.xcodeproj/project.pbxproj:
     26        * Resources/SwipeShadow.png:
     27        * Resources/SwipeShadow@2x.png:
     28        Add the new resources.
     29
    1302015-04-14  Brian Weinstein  <bweinstein@apple.com>
    231
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h

    r182216 r182822  
    187187    RetainPtr<CALayer> m_swipeLayer;
    188188    RetainPtr<CALayer> m_swipeSnapshotLayer;
     189    RetainPtr<CALayer> m_swipeShadowLayer;
     190    RetainPtr<CALayer> m_swipeDimmingLayer;
    189191    Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
    190192
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

    r182245 r182822  
    4747using namespace WebCore;
    4848
     49#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
     50#define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 1
     51#else
     52#define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 0
     53#endif
     54
    4955static const double minMagnification = 1;
    5056static const double maxMagnification = 3;
     
    5965static const float smartMagnificationPanScrollThreshold = 100;
    6066
     67#if ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
    6168static const double swipeOverlayShadowOpacity = 0.66;
    6269static const double swipeOverlayShadowRadius = 3;
     70#else
     71static const double swipeOverlayShadowOpacity = 0.47;
     72static const double swipeOverlayDimmingOpacity = 0.12;
     73#endif
    6374
    6475static const CGFloat minimumHorizontalSwipeDistance = 15;
     
    565576    [m_swipeLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
    566577
     578    float deviceScaleFactor = m_webPageProxy.deviceScaleFactor();
    567579    [m_swipeSnapshotLayer setContentsGravity:kCAGravityTopLeft];
    568     [m_swipeSnapshotLayer setContentsScale:m_webPageProxy.deviceScaleFactor()];
     580    [m_swipeSnapshotLayer setContentsScale:deviceScaleFactor];
    569581    [m_swipeSnapshotLayer setAnchorPoint:CGPointZero];
    570582    [m_swipeSnapshotLayer setFrame:CGRectMake(0, 0, swipeArea.width(), swipeArea.height() - topContentInset)];
     
    577589        applyDebuggingPropertiesToSwipeViews();
    578590
     591
     592    CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
     593    if (direction == SwipeDirection::Back)
     594        [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
     595    else
     596        [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
     597
    579598    // We don't know enough about the custom views' hierarchy to apply a shadow.
    580599    if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap && m_customSwipeViews.isEmpty()) {
     600#if ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
    581601        if (direction == SwipeDirection::Back) {
    582602            float topContentInset = m_webPageProxy.topContentInset();
     
    594614            [m_swipeLayer setShadowPath:shadowPath.get()];
    595615        }
    596     }
    597 
    598     CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
    599     if (direction == SwipeDirection::Back)
    600         [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
    601     else
    602         [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
     616#else
     617        FloatRect dimmingRect(FloatPoint(), m_webPageProxy.viewSize());
     618        m_swipeDimmingLayer = adoptNS([[CALayer alloc] init]);
     619        [m_swipeDimmingLayer setName:@"Gesture Swipe Dimming Layer"];
     620        [m_swipeDimmingLayer setBackgroundColor:[NSColor blackColor].CGColor];
     621        [m_swipeDimmingLayer setOpacity:swipeOverlayDimmingOpacity];
     622        [m_swipeDimmingLayer setAnchorPoint:CGPointZero];
     623        [m_swipeDimmingLayer setFrame:dimmingRect];
     624        [m_swipeDimmingLayer setGeometryFlipped:geometryIsFlippedToRoot];
     625        [m_swipeDimmingLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
     626
     627        NSImage *shadowImage = [[NSBundle bundleForClass:[WKSwipeCancellationTracker class]] imageForResource:@"SwipeShadow"];
     628        FloatRect shadowRect(-shadowImage.size.width, topContentInset, shadowImage.size.width, m_webPageProxy.viewSize().height() - topContentInset);
     629        m_swipeShadowLayer = adoptNS([[CALayer alloc] init]);
     630        [m_swipeShadowLayer setName:@"Gesture Swipe Shadow Layer"];
     631        [m_swipeShadowLayer setBackgroundColor:[NSColor colorWithPatternImage:shadowImage].CGColor];
     632        [m_swipeShadowLayer setContentsScale:deviceScaleFactor];
     633        [m_swipeShadowLayer setOpacity:swipeOverlayShadowOpacity];
     634        [m_swipeShadowLayer setAnchorPoint:CGPointZero];
     635        [m_swipeShadowLayer setFrame:shadowRect];
     636        [m_swipeShadowLayer setGeometryFlipped:geometryIsFlippedToRoot];
     637        [m_swipeShadowLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
     638
     639        if (direction == SwipeDirection::Back)
     640            [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() above:m_swipeLayer.get()];
     641        else
     642            [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() below:m_swipeLayer.get()];
     643
     644        [snapshotLayerParent insertSublayer:m_swipeShadowLayer.get() above:m_swipeLayer.get()];
     645#endif
     646    }
    603647}
    604648
     
    617661
    618662    double swipingLayerOffset = floor(width * progress);
     663
     664#if !ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
     665    double dimmingProgress = (direction == SwipeDirection::Back) ? 1 - progress : -progress;
     666    dimmingProgress = std::min(1., std::max(dimmingProgress, 0.));
     667    [m_swipeDimmingLayer setOpacity:dimmingProgress * swipeOverlayDimmingOpacity];
     668
     669    double absoluteProgress = fabs(progress);
     670    double remainingSwipeDistance = width - fabs(absoluteProgress * width);
     671    double shadowFadeDistance = [m_swipeShadowLayer bounds].size.width;
     672    if (remainingSwipeDistance < shadowFadeDistance)
     673        [m_swipeShadowLayer setOpacity:(remainingSwipeDistance / shadowFadeDistance) * swipeOverlayShadowOpacity];
     674    else
     675        [m_swipeShadowLayer setOpacity:swipeOverlayShadowOpacity];
     676
     677    if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap)
     678        [m_swipeShadowLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Back ? 0 : width) + swipingLayerOffset, 0, 0)];
     679#endif
    619680
    620681    if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
     
    791852    m_swipeLayer = nullptr;
    792853
     854#if !ENABLE(LEGACY_SWIPE_SHADOW_STYLE)
     855    [m_swipeShadowLayer removeFromSuperlayer];
     856    m_swipeShadowLayer = nullptr;
     857
     858    [m_swipeDimmingLayer removeFromSuperlayer];
     859    m_swipeDimmingLayer = nullptr;
     860#endif
     861
    793862    m_currentSwipeLiveLayers.clear();
    794863
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r182803 r182822  
    668668                2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */; };
    669669                2DAF06D718BD1A470081CEB1 /* SmartMagnificationController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */; };
     670                2DC658351AD7237600D44508 /* SwipeShadow.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC658331AD7237600D44508 /* SwipeShadow.png */; };
     671                2DC658361AD7237600D44508 /* SwipeShadow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 2DC658341AD7237600D44508 /* SwipeShadow@2x.png */; };
    670672                2DC6D9C318C44A610043BAD4 /* WKWebViewContentProviderRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */; };
    671673                2DC6D9C418C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */; };
     
    28382840                2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SmartMagnificationController.mm; path = ios/SmartMagnificationController.mm; sourceTree = "<group>"; };
    28392841                2DAF06D818BD23BA0081CEB1 /* SmartMagnificationController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = SmartMagnificationController.messages.in; path = ios/SmartMagnificationController.messages.in; sourceTree = "<group>"; };
     2842                2DC658331AD7237600D44508 /* SwipeShadow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = SwipeShadow.png; path = Resources/SwipeShadow.png; sourceTree = "<group>"; };
     2843                2DC658341AD7237600D44508 /* SwipeShadow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "SwipeShadow@2x.png"; path = "Resources/SwipeShadow@2x.png"; sourceTree = "<group>"; };
    28402844                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewContentProviderRegistry.h; sourceTree = "<group>"; };
    28412845                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewContentProviderRegistry.mm; sourceTree = "<group>"; };
     
    43234327                                1CB75C931701E880009F809F /* DockRight.pdf */,
    43244328                                1C8AE7601992F62F00ABF6EC /* DockRightLegacy.pdf */,
     4329                                2DC658331AD7237600D44508 /* SwipeShadow.png */,
     4330                                2DC658341AD7237600D44508 /* SwipeShadow@2x.png */,
    43254331                                8DC2EF5A0486A6940098B216 /* Info.plist */,
    43264332                                089C1666FE841158C02AAC07 /* InfoPlist.strings */,
     
    89368942                                1CB75C941701E880009F809F /* DockRight.pdf in Resources */,
    89378943                                1C8AE7621992F63C00ABF6EC /* DockRightLegacy.pdf in Resources */,
     8944                                2DC658361AD7237600D44508 /* SwipeShadow@2x.png in Resources */,
    89388945                                8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */,
     8946                                2DC658351AD7237600D44508 /* SwipeShadow.png in Resources */,
    89398947                        );
    89408948                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.