-[DOMRange renderedImageForcingBlackText:] fails with non-user-selectable text
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jan 2012 02:14:33 +0000 (02:14 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jan 2012 02:14:33 +0000 (02:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75920

Reviewed by Darin Adler.

Source/WebCore:

Test: added to TestWebKitAPI/Tests/mac/RenderedImageFromDOMRange.mm

* page/mac/FrameMac.mm:
(WebCore::Frame::rangeImage): Removed the requirement that the start and end positions used
for setting the selection in the render tree be candidates.

Tools:

* TestWebKitAPI/Tests/mac/RenderedImageFromDOMRange.mm:
(TestWebKitAPI::TEST): Added a test for a range in a
-webkit-user-select: none; block.

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

Source/WebCore/ChangeLog
Source/WebCore/page/mac/FrameMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/mac/RenderedImageFromDOMRange.mm

index 9272b2470cd6548c7c423924e38bf49d814557a7..8386408850a44cdec829f844649636bf9ac1633d 100644 (file)
@@ -1,3 +1,16 @@
+2012-01-09  Dan Bernstein  <mitz@apple.com>
+
+        -[DOMRange renderedImageForcingBlackText:] fails with non-user-selectable text
+        https://bugs.webkit.org/show_bug.cgi?id=75920
+
+        Reviewed by Darin Adler.
+
+        Test: added to TestWebKitAPI/Tests/mac/RenderedImageFromDOMRange.mm
+
+        * page/mac/FrameMac.mm:
+        (WebCore::Frame::rangeImage): Removed the requirement that the start and end positions used
+        for setting the selection in the render tree be candidates.
+
 2012-01-06  Hajime Morrita  <morrita@chromium.org>
 
         [Refactoring] Moving between TreeScopes should be done by its own class.
index 234627858a63310004201afb4a39759ac503798b..1c835afac8b7866717788e3d6b0c8b7bc3cc9d0b 100644 (file)
@@ -113,21 +113,17 @@ NSImage *Frame::rangeImage(Range* range, bool forceBlackText) const
     if (!view)
         return nil;
 
-    VisibleSelection visibleSelection(range);
-
-    if (!visibleSelection.isRange())
-        return nil;
-
-    Position start = visibleSelection.start();
+    Position start = range->startPosition();
     Position candidate = start.downstream();
-    if (candidate.isCandidate())
+    if (candidate.deprecatedNode() && candidate.deprecatedNode()->renderer())
         start = candidate;
-    Position end = visibleSelection.end();
+
+    Position end = range->endPosition();
     candidate = end.upstream();
-    if (candidate.isCandidate())
+    if (candidate.deprecatedNode() && candidate.deprecatedNode()->renderer())
         end = candidate;
 
-    if (start.isNull() || end.isNull() || visibleSelection.visibleStart() == visibleSelection.visibleEnd())
+    if (start.isNull() || end.isNull() || start == end)
         return nil;
 
     RenderObject* savedStartRenderer;
@@ -137,7 +133,12 @@ NSImage *Frame::rangeImage(Range* range, bool forceBlackText) const
     view->getSelection(savedStartRenderer, savedStartOffset, savedEndRenderer, savedEndOffset);
 
     RenderObject* startRenderer = start.deprecatedNode()->renderer();
+    if (!startRenderer)
+        return nil;
+
     RenderObject* endRenderer = end.deprecatedNode()->renderer();
+    if (!endRenderer)
+        return nil;
 
     view->setSelection(startRenderer, start.deprecatedEditingOffset(), endRenderer, end.deprecatedEditingOffset(), RenderView::RepaintNothing);
     NSImage* result = imageFromRect(view->selectionBounds());
index e90870c4b0f54f51de6afa333759c6fc2558b82e..be4d5ea0519d6ec5d45b912494aa6eaadb20df68 100644 (file)
@@ -1,3 +1,14 @@
+2012-01-09  Dan Bernstein  <mitz@apple.com>
+
+        -[DOMRange renderedImageForcingBlackText:] fails with non-user-selectable text
+        https://bugs.webkit.org/show_bug.cgi?id=75920
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/mac/RenderedImageFromDOMRange.mm:
+        (TestWebKitAPI::TEST): Added a test for a range in a
+        -webkit-user-select: none; block.
+
 2012-01-09  Dirk Pranke  <dpranke@chromium.org>
 
         webkitpy.layout_tests.port.mock_drt_unittest.MockChromiumDRTTest has been failing on cr-win
index 4bda167983ceb5c5bb601f83ffa20fdf2c7325d3..5ad43bd25cbe0d3ae25bc3d3275bc5511092acb2 100644 (file)
@@ -58,13 +58,18 @@ TEST(WebKit1, RenderedImageFromDOMRange)
 
     DOMDocument *document = webView.get().mainFrameDocument;
     DOMRange *range = [document createRange];
-    [range selectNode:[document getElementById:@"target"]];
+    DOMNode *target = [document getElementById:@"target"];
+    [range selectNode:target];
     NSImage *actualImage = [range renderedImageForcingBlackText:YES];
 
     [webView.get() setSelectedDOMRange:range affinity:NSSelectionAffinityDownstream];
     id <WebDocumentView> documentView = webView.get().mainFrame.frameView.documentView;
     NSImage *expectedImage = [(id <WebDocumentSelection>)documentView selectionImageForcingBlackText:YES];
     EXPECT_TRUE([actualImage.TIFFRepresentation isEqual:expectedImage.TIFFRepresentation]);
+
+    [target.parentElement.style setProperty:@"-webkit-user-select" value:@"none" priority:nil];
+    NSImage *actualImageWithUserSelectNone = [range renderedImageForcingBlackText:YES];
+    EXPECT_TRUE([actualImageWithUserSelectNone.TIFFRepresentation isEqual:expectedImage.TIFFRepresentation]);
 }
 
 } // namespace TestWebKitAPI