Pasteboard data's RTF data doesn't always include URLs via NSLinkAttributeName.
authorenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Mar 2011 18:47:45 +0000 (18:47 +0000)
committerenrica@apple.com <enrica@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Mar 2011 18:47:45 +0000 (18:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=57107
<rdar://problem/9084267>

Reviewed by Oliver Hunt.

If the selection is at the beginning of content inside an anchor tag
we move the selection start to include the anchor.

* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeSelection): Modified to change the selection
start according to the new rule.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/PasteboardMac.mm

index c525eef..73def02 100644 (file)
@@ -1,3 +1,18 @@
+2011-03-25  Enrica Casucci  <enrica@apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        Pasteboard data's RTF data doesn't always include URLs via NSLinkAttributeName.
+        https://bugs.webkit.org/show_bug.cgi?id=57107
+        <rdar://problem/9084267>
+
+        If the selection is at the beginning of content inside an anchor tag
+        we move the selection start to include the anchor.
+        
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writeSelection): Modified to change the selection
+        start according to the new rule.
+
 2011-03-25  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index bcd7801..da06606 100644 (file)
@@ -41,6 +41,7 @@
 #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
 #import "HTMLConverter.h"
 #endif
+#import "htmlediting.h"
 #import "HTMLNames.h"
 #import "Image.h"
 #import "KURL.h"
@@ -147,6 +148,17 @@ void Pasteboard::writeSelection(NSPasteboard* pasteboard, NSArray* pasteboardTyp
         Pasteboard::generalPasteboard(); // Initializes pasteboard types.
     ASSERT(selectedRange);
     
+    // If the selection is at the beginning of content inside an anchor tag
+    // we move the selection start to include the anchor.
+    // This way the attributed string will contain the url attribute as well.
+    // See <rdar://problem/9084267>.
+    ExceptionCode ec;
+    Node* commonAncestor = selectedRange->commonAncestorContainer(ec);
+    ASSERT(commonAncestor);
+    Node* enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(commonAncestor), HTMLNames::aTag);
+    if (enclosingAnchor && comparePositions(firstPositionInOrBeforeNode(selectedRange->startPosition().anchorNode()), selectedRange->startPosition()) >= 0)
+        selectedRange->setStart(enclosingAnchor, 0, ec);
+
     // Using different API for WebKit and WebKit2.
     NSAttributedString *attributedString = nil;
     if (frame->view()->platformWidget())