Title: [214111] trunk/Source
Revision
214111
Author
[email protected]
Date
2017-03-17 12:30:43 -0700 (Fri, 17 Mar 2017)

Log Message

[WK1] Support animated transitions when performing a data interaction operation
https://bugs.webkit.org/show_bug.cgi?id=169805
<rdar://problem/31045767>

Reviewed by Beth Dakin and Megan Gardner.

Source/WebCore:

When performing a snapshot excluding the current selection, use ScrollableArea::visibleContentRect to compute
the visible content rect rather than FrameView::visualViewportRect. In WebKit1, the latter will return the
entire content view's bounds.

* page/TextIndicator.cpp:
(WebCore::takeSnapshots):

Source/WebKit/mac:

Adds WebKit1 support for animated transitions when performing a data interaction operation. See per-method changes
for more details.

* DOM/DOMElement.h:
* DOM/DOMElement.mm:
(-[DOMElement boundsInRootViewSpace]):

Introduce -[DOMElement boundsInRootViewSpace], which returns the bounds of the element in root view coordinates.

* WebCoreSupport/WebDragClient.h:
(): Deleted.
* WebCoreSupport/WebDragClient.mm:
(WebDragClient::didConcludeEditDrag):

Add boilerplate plumbing.

* WebView/WebView.mm:
(-[WebUITextIndicatorData initWithImage:textIndicatorData:scale:]):

Add contentImageWithoutSelection and contentImageWithoutSelectionRectInRootViewCoordinates to WebUITextIndicatorData.

(floatRectsForCGRectArray):
(-[WebView _createImageWithPlatterForImage:boundingRect:contentScaleFactor:clippingRects:]):

Introduces a SPI helper method in WebView that clients can use to generate an image of a text platter given an
image of some text, as well as clipping rects to apply to the image.

(-[WebView _dataOperationTextIndicator]):

Add SPI to fetch the text indicator used to drive animations for the current data operation.

(-[WebView _didConcludeEditDataInteraction]):
* WebView/WebViewData.h:
* WebView/WebViewInternal.h:
* WebView/WebViewPrivate.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (214110 => 214111)


--- trunk/Source/WebCore/ChangeLog	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebCore/ChangeLog	2017-03-17 19:30:43 UTC (rev 214111)
@@ -1,3 +1,18 @@
+2017-03-17  Wenson Hsieh  <[email protected]>
+
+        [WK1] Support animated transitions when performing a data interaction operation
+        https://bugs.webkit.org/show_bug.cgi?id=169805
+        <rdar://problem/31045767>
+
+        Reviewed by Beth Dakin and Megan Gardner.
+
+        When performing a snapshot excluding the current selection, use ScrollableArea::visibleContentRect to compute
+        the visible content rect rather than FrameView::visualViewportRect. In WebKit1, the latter will return the
+        entire content view's bounds.
+
+        * page/TextIndicator.cpp:
+        (WebCore::takeSnapshots):
+
 2017-03-17  Dave Hyatt  <[email protected]>
 
         Initial letter does not paginate properly.

Modified: trunk/Source/WebCore/page/TextIndicator.cpp (214110 => 214111)


--- trunk/Source/WebCore/page/TextIndicator.cpp	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebCore/page/TextIndicator.cpp	2017-03-17 19:30:43 UTC (rev 214111)
@@ -175,7 +175,7 @@
 
     if (data.options & TextIndicatorOptionIncludeSnapshotOfAllVisibleContentWithoutSelection) {
         float snapshotScaleFactor;
-        auto snapshotRect = enclosingIntRect(frame.view()->visualViewportRect());
+        auto snapshotRect = frame.view()->visibleContentRect();
         data.contentImageWithoutSelection = takeSnapshot(frame, snapshotRect, SnapshotOptionsPaintEverythingExcludingSelection, snapshotScaleFactor, { });
         data.contentImageWithoutSelectionRectInRootViewCoordinates = frame.view()->contentsToRootView(snapshotRect);
     }

Modified: trunk/Source/WebKit/mac/ChangeLog (214110 => 214111)


--- trunk/Source/WebKit/mac/ChangeLog	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/ChangeLog	2017-03-17 19:30:43 UTC (rev 214111)
@@ -1,3 +1,47 @@
+2017-03-17  Wenson Hsieh  <[email protected]>
+
+        [WK1] Support animated transitions when performing a data interaction operation
+        https://bugs.webkit.org/show_bug.cgi?id=169805
+        <rdar://problem/31045767>
+
+        Reviewed by Beth Dakin and Megan Gardner.
+
+        Adds WebKit1 support for animated transitions when performing a data interaction operation. See per-method changes
+        for more details.
+
+        * DOM/DOMElement.h:
+        * DOM/DOMElement.mm:
+        (-[DOMElement boundsInRootViewSpace]):
+
+        Introduce -[DOMElement boundsInRootViewSpace], which returns the bounds of the element in root view coordinates.
+
+        * WebCoreSupport/WebDragClient.h:
+        (): Deleted.
+        * WebCoreSupport/WebDragClient.mm:
+        (WebDragClient::didConcludeEditDrag):
+
+        Add boilerplate plumbing.
+
+        * WebView/WebView.mm:
+        (-[WebUITextIndicatorData initWithImage:textIndicatorData:scale:]):
+
+        Add contentImageWithoutSelection and contentImageWithoutSelectionRectInRootViewCoordinates to WebUITextIndicatorData.
+
+        (floatRectsForCGRectArray):
+        (-[WebView _createImageWithPlatterForImage:boundingRect:contentScaleFactor:clippingRects:]):
+
+        Introduces a SPI helper method in WebView that clients can use to generate an image of a text platter given an
+        image of some text, as well as clipping rects to apply to the image.
+
+        (-[WebView _dataOperationTextIndicator]):
+
+        Add SPI to fetch the text indicator used to drive animations for the current data operation.
+
+        (-[WebView _didConcludeEditDataInteraction]):
+        * WebView/WebViewData.h:
+        * WebView/WebViewInternal.h:
+        * WebView/WebViewPrivate.h:
+
 2017-03-16  Simon Fraser  <[email protected]>
 
         Improve the system tracing points

Modified: trunk/Source/WebKit/mac/DOM/DOMElement.h (214110 => 214111)


--- trunk/Source/WebKit/mac/DOM/DOMElement.h	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/DOM/DOMElement.h	2017-03-17 19:30:43 UTC (rev 214111)
@@ -25,6 +25,10 @@
 
 #import <WebKitLegacy/DOMNode.h>
 
+#if TARGET_OS_IPHONE
+#import <CoreGraphics/CoreGraphics.h>
+#endif
+
 @class DOMAttr;
 @class DOMCSSStyleDeclaration;
 @class DOMElement;
@@ -62,6 +66,10 @@
 @property (readonly, strong) DOMElement *lastElementChild WEBKIT_AVAILABLE_MAC(10_6);
 @property (readonly) unsigned childElementCount WEBKIT_AVAILABLE_MAC(10_6);
 
+#if TARGET_OS_IPHONE
+@property (readonly) CGRect boundsInRootViewSpace;
+#endif
+
 - (NSString *)getAttribute:(NSString *)name;
 - (void)setAttribute:(NSString *)name value:(NSString *)value WEBKIT_AVAILABLE_MAC(10_5);
 - (void)removeAttribute:(NSString *)name;

Modified: trunk/Source/WebKit/mac/DOM/DOMElement.mm (214110 => 214111)


--- trunk/Source/WebKit/mac/DOM/DOMElement.mm	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/DOM/DOMElement.mm	2017-03-17 19:30:43 UTC (rev 214111)
@@ -269,6 +269,15 @@
     return unwrap(*self).childElementCount();
 }
 
+#if PLATFORM(IOS)
+- (CGRect)boundsInRootViewSpace
+{
+    WebCore::JSMainThreadNullState state;
+    auto bounds = unwrap(*self).boundsInRootViewSpace();
+    return CGRectMake(bounds.x(), bounds.y(), bounds.width(), bounds.height());
+}
+#endif
+
 - (NSString *)getAttribute:(NSString *)name
 {
     WebCore::JSMainThreadNullState state;

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h (214110 => 214111)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.h	2017-03-17 19:30:43 UTC (rev 214111)
@@ -48,7 +48,7 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
     void declareAndWriteAttachment(const String& pasteboardName, WebCore::Element&, const WebCore::URL&, const String& path, WebCore::Frame*) override;
 #endif
-    void didConcludeEditDrag() override { }
+    void didConcludeEditDrag() override;
 private:
     WebView* m_webView;
 };

Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm (214110 => 214111)


--- trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebDragClient.mm	2017-03-17 19:30:43 UTC (rev 214111)
@@ -76,6 +76,10 @@
     return false;
 }
 
+void WebDragClient::didConcludeEditDrag()
+{
+}
+
 static WebHTMLView *getTopHTMLView(Frame* frame)
 {
     ASSERT(frame);
@@ -185,6 +189,11 @@
 {
     return false;
 }
+
+void WebDragClient::didConcludeEditDrag()
+{
+}
+
 WebCore::DragDestinationAction WebDragClient::actionMaskForDrag(const WebCore::DragData&)
 {
     return DragDestinationActionNone;

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (214110 => 214111)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2017-03-17 19:30:43 UTC (rev 214111)
@@ -176,6 +176,7 @@
 #import <WebCore/PageCache.h>
 #import <WebCore/PageConfiguration.h>
 #import <WebCore/PageGroup.h>
+#import <WebCore/PathUtilities.h>
 #import <WebCore/PlatformEventFactoryMac.h>
 #import <WebCore/ProgressTracker.h>
 #import <WebCore/RenderView.h>
@@ -320,9 +321,17 @@
 #endif
 
 #if ENABLE(DATA_INTERACTION)
+#import <UIKit/UIBezierPath.h>
+#import <UIKit/UIColor.h>
 #import <UIKit/UIImage.h>
 SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK_CLASS(UIKit, UIBezierPath)
+SOFT_LINK_CLASS(UIKit, UIColor)
 SOFT_LINK_CLASS(UIKit, UIImage)
+SOFT_LINK(UIKit, UIGraphicsBeginImageContextWithOptions, void, (CGSize size, BOOL opaque, CGFloat scale), (size, opaque, scale))
+SOFT_LINK(UIKit, UIGraphicsGetCurrentContext, CGContextRef, (void), ())
+SOFT_LINK(UIKit, UIGraphicsGetImageFromCurrentImageContext, UIImage *, (void), ())
+SOFT_LINK(UIKit, UIGraphicsEndImageContext, void, (void), ())
 #endif
 
 #if HAVE(TOUCH_BAR) && ENABLE(WEB_PLAYBACK_CONTROLS_MANAGER)
@@ -626,6 +635,8 @@
 @synthesize textBoundingRectInRootViewCoordinates=_textBoundingRectInRootViewCoordinates;
 @synthesize textRectsInBoundingRectCoordinates=_textRectsInBoundingRectCoordinates;
 @synthesize contentImageWithHighlight=_contentImageWithHighlight;
+@synthesize contentImageWithoutSelection=_contentImageWithoutSelection;
+@synthesize contentImageWithoutSelectionRectInRootViewCoordinates=_contentImageWithoutSelectionRectInRootViewCoordinates;
 @synthesize contentImage=_contentImage;
 
 @end
@@ -632,7 +643,7 @@
 
 @implementation WebUITextIndicatorData (WebUITextIndicatorInternal)
 
-- (WebUITextIndicatorData *)initWithImage:(CGImageRef)image textIndicatorData:(WebCore::TextIndicatorData &)indicatorData scale:(CGFloat)scale
+- (WebUITextIndicatorData *)initWithImage:(CGImageRef)image textIndicatorData:(const TextIndicatorData&)indicatorData scale:(CGFloat)scale
 {
     if (!(self = [super init]))
         return nil;
@@ -649,8 +660,16 @@
     if (indicatorData.contentImageWithHighlight)
         _contentImageWithHighlight = [[[getUIImageClass() alloc] initWithCGImage:indicatorData.contentImageWithHighlight.get()->nativeImage().get() scale:scale orientation:UIImageOrientationDownMirrored] retain];
     if (indicatorData.contentImage)
-        _contentImage = [[[getUIImageClass() alloc] initWithCGImage:indicatorData.contentImage.get()->nativeImage().get() scale:scale orientation:UIImageOrientationDownMirrored] retain];
-    
+        _contentImage = [[[getUIImageClass() alloc] initWithCGImage:indicatorData.contentImage.get()->nativeImage().get() scale:scale orientation:UIImageOrientationUp] retain];
+
+    if (indicatorData.contentImageWithoutSelection) {
+        auto nativeImage = indicatorData.contentImageWithoutSelection.get()->nativeImage();
+        if (nativeImage) {
+            _contentImageWithoutSelection = [[[getUIImageClass() alloc] initWithCGImage:nativeImage.get() scale:scale orientation:UIImageOrientationUp] retain];
+            _contentImageWithoutSelectionRectInRootViewCoordinates = indicatorData.contentImageWithoutSelectionRectInRootViewCoordinates;
+        }
+    }
+
     return self;
 }
 
@@ -669,6 +688,7 @@
     [_dataInteractionImage release];
     [_textRectsInBoundingRectCoordinates release];
     [_contentImageWithHighlight release];
+    [_contentImageWithoutSelection release];
     [_contentImage release];
     
     [super dealloc];
@@ -1795,11 +1815,62 @@
         _private->textIndicatorData = [[[WebUITextIndicatorData alloc] initWithImage:image scale:_private->page->deviceScaleFactor()] retain];
 }
 
+- (WebUITextIndicatorData *)_dataOperationTextIndicator
+{
+    return _private->dataOperationTextIndicator.get();
+}
+
 - (WebUITextIndicatorData *)_getDataInteractionData
 {
     return _private->textIndicatorData;
 }
 
+static Vector<FloatRect> floatRectsForCGRectArray(NSArray<NSValue *> *rectValues)
+{
+    Vector<FloatRect> rects;
+    for (NSValue *rectValue in rectValues)
+        rects.append(rectValue.CGRectValue);
+    return rects;
+}
+
+- (UIImage *)_createImageWithPlatterForImage:(UIImage *)image boundingRect:(CGRect)boundingRect contentScaleFactor:(CGFloat)contentScaleFactor clippingRects:(NSArray<NSValue *> *)clippingRects
+{
+    if (!_private->page)
+        return nil;
+
+    if (!image)
+        return nil;
+
+    CGFloat imageScaleFactor = contentScaleFactor / _private->page->deviceScaleFactor();
+    CGRect imagePaintBounds = CGRectMake(0, 0, CGRectGetWidth(boundingRect) * imageScaleFactor, CGRectGetHeight(boundingRect) * imageScaleFactor);
+    UIGraphicsBeginImageContextWithOptions(imagePaintBounds.size, NO, _private->page->deviceScaleFactor());
+    CGContextRef newContext = UIGraphicsGetCurrentContext();
+
+    auto scaledClippingRects = floatRectsForCGRectArray(clippingRects);
+    for (auto& textBoundingRect : scaledClippingRects)
+        textBoundingRect.scale(imageScaleFactor);
+
+    if (!scaledClippingRects.isEmpty()) {
+        auto webcorePath = PathUtilities::pathWithShrinkWrappedRects(scaledClippingRects, 6 * imageScaleFactor);
+        [[getUIBezierPathClass() bezierPathWithCGPath:webcorePath.ensurePlatformPath()] addClip];
+    }
+
+    // FIXME: This should match the background color of the text, or if the background cannot be captured as a single color, we should fall back
+    // to a default representation, e.g. black text on a white background.
+    CGContextSetFillColorWithColor(newContext, [[getUIColorClass() whiteColor] CGColor]);
+    for (auto textBoundingRect : scaledClippingRects)
+        CGContextFillRect(newContext, textBoundingRect);
+
+    CGContextTranslateCTM(newContext, 0, CGRectGetHeight(imagePaintBounds));
+    CGContextScaleCTM(newContext, 1, -1);
+    CGContextDrawImage(newContext, imagePaintBounds, image.CGImage);
+
+    UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
+    UIGraphicsEndImageContext();
+
+    return [previewImage retain];
+}
+
 #if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WebViewAdditions.mm>)
 #include <WebKitAdditions/WebViewAdditions.mm>
 #endif
@@ -1834,6 +1905,19 @@
 - (void)_endedDataInteraction:(CGPoint)clientPosition global:(CGPoint)globalPosition
 {
 }
+
+- (WebUITextIndicatorData *)_dataOperationTextIndicator
+{
+    return nil;
+}
+
+#if PLATFORM(IOS)
+- (UIImage *)_createImageWithPlatterForImage:(UIImage *)image boundingRect:(CGRect)boundingRect contentScaleFactor:(CGFloat)contentScaleFactor clippingRects:(NSArray<NSValue *> *)clippingRects
+{
+    return nil;
+}
+#endif
+
 #endif // ENABLE(DATA_INTERACTION) && defined(__cplusplus)
 
 static NSMutableSet *knownPluginMIMETypes()

Modified: trunk/Source/WebKit/mac/WebView/WebViewData.h (214110 => 214111)


--- trunk/Source/WebKit/mac/WebView/WebViewData.h	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebView/WebViewData.h	2017-03-17 19:30:43 UTC (rev 214111)
@@ -288,6 +288,7 @@
     
 #if ENABLE(DATA_INTERACTION)
     WebUITextIndicatorData *textIndicatorData;
+    RetainPtr<WebUITextIndicatorData> dataOperationTextIndicator;
 #endif
 
 

Modified: trunk/Source/WebKit/mac/WebView/WebViewInternal.h (214110 => 214111)


--- trunk/Source/WebKit/mac/WebView/WebViewInternal.h	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebView/WebViewInternal.h	2017-03-17 19:30:43 UTC (rev 214111)
@@ -92,7 +92,7 @@
 
 #if ENABLE(DATA_INTERACTION) && defined(__cplusplus)
 @interface WebUITextIndicatorData (WebUITextIndicatorInternal)
-- (WebUITextIndicatorData *)initWithImage:(CGImageRef)image textIndicatorData:(WebCore::TextIndicatorData&)indicatorData scale:(CGFloat)scale;
+- (WebUITextIndicatorData *)initWithImage:(CGImageRef)image textIndicatorData:(const WebCore::TextIndicatorData&)indicatorData scale:(CGFloat)scale;
 - (WebUITextIndicatorData *)initWithImage:(CGImageRef)image scale:(CGFloat)scale;
 @end
 #endif
@@ -258,6 +258,7 @@
 
 #if ENABLE(DATA_INTERACTION) && defined(__cplusplus)
 - (void)_setDataInteractionData:(CGImageRef)image textIndicator:(std::optional<WebCore::TextIndicatorData>)textIndicator atClientPosition:(CGPoint)clientPosition anchorPoint:(CGPoint)anchorPoint action:(uint64_t)action;
+- (void)_didConcludeEditDataInteraction;
 #endif
 
 - (void)_preferencesChanged:(WebPreferences *)preferences;

Modified: trunk/Source/WebKit/mac/WebView/WebViewPrivate.h (214110 => 214111)


--- trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2017-03-17 18:54:47 UTC (rev 214110)
+++ trunk/Source/WebKit/mac/WebView/WebViewPrivate.h	2017-03-17 19:30:43 UTC (rev 214111)
@@ -191,7 +191,8 @@
 @property (nonatomic, assign) CGFloat contentImageScaleFactor;
 @property (nonatomic, retain) UIImage *contentImageWithHighlight;
 @property (nonatomic, retain) UIImage *contentImage;
-
+@property (nonatomic, retain) UIImage *contentImageWithoutSelection;
+@property (nonatomic, assign) CGRect contentImageWithoutSelectionRectInRootViewCoordinates;
 @end
 
 #if !TARGET_OS_IPHONE
@@ -467,6 +468,7 @@
 
 - (BOOL)_requestStartDataInteraction:(CGPoint)clientPosition globalPosition:(CGPoint)globalPosition;
 - (WebUITextIndicatorData *)_getDataInteractionData;
+@property (nonatomic, readonly, strong, getter=_dataOperationTextIndicator) WebUITextIndicatorData *dataOperationTextIndicator;
 - (uint64_t)_enteredDataInteraction:(id)dataInteraction client:(CGPoint)clientPosition global:(CGPoint)globalPosition operation:(uint64_t)operation;
 - (uint64_t)_updatedDataInteraction:(id)dataInteraction client:(CGPoint)clientPosition global:(CGPoint)globalPosition operation:(uint64_t)operation;
 - (void)_exitedDataInteraction:(id)dataInteraction client:(CGPoint)clientPosition global:(CGPoint)globalPosition operation:(uint64_t)operation;
@@ -474,6 +476,7 @@
 - (void)_endedDataInteraction:(CGPoint)clientPosition global:(CGPoint)clientPosition;
 
 #if TARGET_OS_IPHONE
+- (UIImage *)_createImageWithPlatterForImage:(UIImage *)image boundingRect:(CGRect)boundingRect contentScaleFactor:(CGFloat)contentScaleFactor clippingRects:(NSArray<NSValue *> *)clippingRects;
 // Deprecated. Use -[WebDataSource _quickLookContent] instead.
 - (NSDictionary *)quickLookContentForURL:(NSURL *)url;
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to