Title: [187686] trunk/Source/WebCore
Revision
187686
Author
timothy_hor...@apple.com
Date
2015-07-31 15:34:23 -0700 (Fri, 31 Jul 2015)

Log Message

[iOS] DOMNode preview snapshot rects are wrong for user-select: none links
https://bugs.webkit.org/show_bug.cgi?id=147513
<rdar://problem/22083354>

Reviewed by Simon Fraser.

* bindings/objc/DOM.mm:
(-[DOMNode getPreviewSnapshotImage:andRects:]):
Use the same code as WebKit2 to compute the fallback rect (if TextIndicator fails),
asking the RenderObject (or RenderImage) for its bounding box instead of using the
(often wrong) Range bounding rect.

Make sure to use the fallback rect *any* time TextIndicator fails (before
we would return no rects at all if TextIndicator::createWithRange returned null,
and the fallback rect if it returned with an empty image).

Inverse-page-scale the margin, to match the appearance in WebKit2.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (187685 => 187686)


--- trunk/Source/WebCore/ChangeLog	2015-07-31 22:24:56 UTC (rev 187685)
+++ trunk/Source/WebCore/ChangeLog	2015-07-31 22:34:23 UTC (rev 187686)
@@ -1,3 +1,23 @@
+2015-07-31  Tim Horton  <timothy_hor...@apple.com>
+
+        [iOS] DOMNode preview snapshot rects are wrong for user-select: none links
+        https://bugs.webkit.org/show_bug.cgi?id=147513
+        <rdar://problem/22083354>
+
+        Reviewed by Simon Fraser.
+
+        * bindings/objc/DOM.mm:
+        (-[DOMNode getPreviewSnapshotImage:andRects:]):
+        Use the same code as WebKit2 to compute the fallback rect (if TextIndicator fails),
+        asking the RenderObject (or RenderImage) for its bounding box instead of using the
+        (often wrong) Range bounding rect.
+
+        Make sure to use the fallback rect *any* time TextIndicator fails (before
+        we would return no rects at all if TextIndicator::createWithRange returned null,
+        and the fallback rect if it returned with an empty image).
+
+        Inverse-page-scale the margin, to match the appearance in WebKit2.
+
 2015-07-31  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [SVG -> OTF Converter] Crash when converting Arabic fonts

Modified: trunk/Source/WebCore/bindings/objc/DOM.mm (187685 => 187686)


--- trunk/Source/WebCore/bindings/objc/DOM.mm	2015-07-31 22:24:56 UTC (rev 187685)
+++ trunk/Source/WebCore/bindings/objc/DOM.mm	2015-07-31 22:34:23 UTC (rev 187686)
@@ -595,28 +595,39 @@
 
     Ref<Range> range = rangeOfContents(*coreNode);
 
-    const float margin = 4;
+    const float margin = 4 / coreNode->document().page()->pageScaleFactor();
     RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, TextIndicatorPresentationTransition::None, margin);
 
-    if (!textIndicator)
-        return;
+    if (textIndicator) {
+        if (Image* image = textIndicator->contentImage())
+            *cgImage = (CGImageRef)CFAutorelease(CGImageRetain(image->getCGImageRef()));
+    }
 
-    if (Image* image = textIndicator->contentImage())
-        *cgImage = (CGImageRef)CFAutorelease(CGImageRetain(image->getCGImageRef()));
-
     RetainPtr<NSMutableArray> rectArray = adoptNS([[NSMutableArray alloc] init]);
 
-    if (*cgImage) {
-        FloatPoint origin = textIndicator->textBoundingRectInRootViewCoordinates().location();
-        for (const FloatRect& rect : textIndicator->textRectsInBoundingRectCoordinates()) {
-            CGRect cgRect = rect;
-            cgRect.origin.x += origin.x();
-            cgRect.origin.y += origin.y();
-            cgRect = coreNode->document().frame()->view()->contentsToWindow(enclosingIntRect(cgRect));
+    if (!*cgImage) {
+        if (RenderObject* renderer = coreNode->renderer()) {
+            FloatRect boundingBox;
+            if (renderer->isRenderImage())
+                boundingBox = downcast<RenderImage>(*renderer).absoluteContentQuad().enclosingBoundingBox();
+            else
+                boundingBox = renderer->absoluteBoundingBoxRect();
+
+            boundingBox.inflate(margin);
+
+            CGRect cgRect = coreNode->document().frame()->view()->contentsToWindow(enclosingIntRect(boundingBox));
             [rectArray addObject:[NSValue value:&cgRect withObjCType:@encode(CGRect)]];
+
+            *rects = rectArray.autorelease();
         }
-    } else {
-        CGRect cgRect = CGRectInset(range->boundingRect(), -margin, -margin);
+        return;
+    }
+
+    FloatPoint origin = textIndicator->textBoundingRectInRootViewCoordinates().location();
+    for (const FloatRect& rect : textIndicator->textRectsInBoundingRectCoordinates()) {
+        CGRect cgRect = rect;
+        cgRect.origin.x += origin.x();
+        cgRect.origin.y += origin.y();
         cgRect = coreNode->document().frame()->view()->contentsToWindow(enclosingIntRect(cgRect));
         [rectArray addObject:[NSValue value:&cgRect withObjCType:@encode(CGRect)]];
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to