Modified: branches/safari-538.34-branch/Source/WebCore/ChangeLog (168658 => 168659)
--- branches/safari-538.34-branch/Source/WebCore/ChangeLog 2014-05-13 00:05:55 UTC (rev 168658)
+++ branches/safari-538.34-branch/Source/WebCore/ChangeLog 2014-05-13 00:11:19 UTC (rev 168659)
@@ -1,5 +1,20 @@
2014-04-17 Lucas Forschler <lforsch...@apple.com>
+ Merge r168658
+
+ 2014-05-12 Brady Eidson <beid...@apple.com>
+
+ Followup to "Teach Editor to support more direct replacement of a Node"
+ <rdar://problem/16817952> and https://bugs.webkit.org/show_bug.cgi?id=132834
+
+ Pair programmed and pair reviewed by Brady Eidson and Darin Adler.
+
+ * editing/mac/EditorMac.mm:
+ (WebCore::maybeCopyNodeAttributesToFragment):
+ (WebCore::Editor::replaceNodeFromPasteboard):
+
+2014-04-17 Lucas Forschler <lforsch...@apple.com>
+
Merge r168650
2014-05-12 Brady Eidson <beid...@apple.com>
Modified: branches/safari-538.34-branch/Source/WebCore/editing/mac/EditorMac.mm (168658 => 168659)
--- branches/safari-538.34-branch/Source/WebCore/editing/mac/EditorMac.mm 2014-05-13 00:05:55 UTC (rev 168658)
+++ branches/safari-538.34-branch/Source/WebCore/editing/mac/EditorMac.mm 2014-05-13 00:11:19 UTC (rev 168659)
@@ -265,21 +265,21 @@
pasteAsPlainTextWithPasteboard(pasteboard);
}
-static void maybeCopyNodeAttributesToFragment(Node* node, DocumentFragment* fragment)
+static void maybeCopyNodeAttributesToFragment(const Node& node, DocumentFragment& fragment)
{
// This is only supported for single-Node fragments.
- Node* firstChild = fragment->firstChild();
- if (firstChild != fragment->lastChild())
+ Node* firstChild = fragment.firstChild();
+ if (!firstChild || firstChild != fragment.lastChild())
return;
// And only supported for HTML elements.
- if (!node->isHTMLElement() || !firstChild->isHTMLElement())
+ if (!node.isHTMLElement() || !firstChild->isHTMLElement())
return;
// And only if the source Element and destination Element have the same HTML tag name.
- const Element& oldElement = toHTMLElement(*node);
- Element& newElement = toHTMLElement(*firstChild);
- if (!oldElement.hasTagName(newElement.tagQName()))
+ const HTMLElement& oldElement = toHTMLElement(node);
+ HTMLElement& newElement = toHTMLElement(*firstChild);
+ if (oldElement.localName() != newElement.localName())
return;
for (const Attribute& attribute : oldElement.attributesIterator()) {
@@ -310,13 +310,12 @@
client()->setInsertionPasteboard(NSGeneralPboard);
bool chosePlainText;
- RefPtr<DocumentFragment> fragment = webContentFromPasteboard(pasteboard, *range, true, chosePlainText);
+ if (RefPtr<DocumentFragment> fragment = webContentFromPasteboard(pasteboard, *range, true, chosePlainText)) {
+ maybeCopyNodeAttributesToFragment(*node, *fragment);
+ if (shouldInsertFragment(fragment, range, EditorInsertActionPasted))
+ pasteAsFragment(fragment.release(), canSmartReplaceWithPasteboard(pasteboard), false, MailBlockquoteHandling::IgnoreBlockquote);
+ }
- maybeCopyNodeAttributesToFragment(node, fragment.get());
-
- if (fragment && shouldInsertFragment(fragment, range, EditorInsertActionPasted))
- pasteAsFragment(fragment, canSmartReplaceWithPasteboard(pasteboard), false, MailBlockquoteHandling::IgnoreBlockquote);
-
client()->setInsertionPasteboard(String());
}