Diff
Modified: trunk/LayoutTests/ChangeLog (236706 => 236707)
--- trunk/LayoutTests/ChangeLog 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/LayoutTests/ChangeLog 2018-10-02 01:59:52 UTC (rev 236707)
@@ -1,3 +1,16 @@
+2018-10-01 Ryosuke Niwa <rn...@webkit.org>
+
+ Add a new variant of serializePreservingVisualAppearance which takes VisibleSelection
+ https://bugs.webkit.org/show_bug.cgi?id=190108
+
+ Reviewed by Wenson Hsieh.
+
+ Rebaselined the test since the bug that interchange new lines are inserted in the last table cell is fixed.
+ Also updated the description in the test to reflect this change.
+
+ * editing/pasteboard/paste-table-003-expected.txt:
+ * editing/pasteboard/paste-table-003.html:
+
2018-10-01 Ryan Haddad <ryanhad...@apple.com>
Unreviewed, rebaseline tests after r236632.
Modified: trunk/LayoutTests/editing/pasteboard/paste-table-003-expected.txt (236706 => 236707)
--- trunk/LayoutTests/editing/pasteboard/paste-table-003-expected.txt 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/LayoutTests/editing/pasteboard/paste-table-003-expected.txt 2018-10-02 01:59:52 UTC (rev 236707)
@@ -5,13 +5,13 @@
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldInsertNode:#document-fragment replacingDOMRange:range from 0 of #text > DIV > DIV > BODY > HTML > #document to 9 of #text > DIV > DIV > BODY > HTML > #document givenAction:WebViewInsertActionPasted
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
-EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > BODY > HTML > #document toDOMRange:range from 2 of TD > TR > TBODY > TABLE > DIV > DIV > BODY > HTML > #document to 2 of TD > TR > TBODY > TABLE > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
+EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV > DIV > BODY > HTML > #document to 0 of DIV > DIV > BODY > HTML > #document toDOMRange:range from 3 of #text > TD > TR > TBODY > TABLE > DIV > DIV > BODY > HTML > #document to 3 of #text > TD > TR > TBODY > TABLE > DIV > DIV > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification
-This tests pasting a table to replace some text. It demonstrates two bugs: 1) selecting a table without also selecting the line break after programmatically is impossible when its followed by a div because of the way DOM positions are mapped to visible positions, 2) pasting content that ends in a table places the caret in the last table cell instead of after the table, so the interchange newline is placed in the last table cell and not after the table.
+This tests pasting a table to replace some text.
+It demonstrates a bug: selecting a table without also selecting the line break after programmatically is impossible when its followed by a div because of the way DOM positions are mapped to visible positions.
one two
one two
-
execCopyCommand: <table id="test"> <tbody><tr><td>one</td><td>two</td></tr></tbody></table> <div id="target">replaceme</div>
-execPasteCommand: <table id="test"> <tbody><tr><td>one</td><td>two</td></tr></tbody></table> <div id="target"><table id="test"><tbody><tr><td>one</td><td>two<br><br></td></tr></tbody></table></div>
+execPasteCommand: <table id="test"> <tbody><tr><td>one</td><td>two</td></tr></tbody></table> <div id="target"><table id="test"><tbody><tr><td>one</td><td>two</td></tr></tbody></table></div>
Modified: trunk/LayoutTests/editing/pasteboard/paste-table-003.html (236706 => 236707)
--- trunk/LayoutTests/editing/pasteboard/paste-table-003.html 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/LayoutTests/editing/pasteboard/paste-table-003.html 2018-10-02 01:59:52 UTC (rev 236707)
@@ -34,7 +34,9 @@
<title>Editing Test</title>
</head>
<body>
-<p>This tests pasting a table to replace some text. <b>It demonstrates two bugs: 1) selecting a table without also selecting the line break after programmatically is impossible when its followed by a div because of the way DOM positions are mapped to visible positions, 2) pasting content that ends in a table places the caret in the last table cell instead of after the table, so the interchange newline is placed in the last table cell and not after the table.</b></p>
+<p>This tests pasting a table to replace some text.<br>
+It demonstrates a bug: selecting a table without also selecting the line break after programmatically is impossible
+when its followed by a div because of the way DOM positions are mapped to visible positions.</p>
<div id="root" contenteditable>
<table id="test">
<tbody><tr><td>one</td><td>two</td></tr></tbody></table>
Modified: trunk/Source/WebCore/ChangeLog (236706 => 236707)
--- trunk/Source/WebCore/ChangeLog 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/ChangeLog 2018-10-02 01:59:52 UTC (rev 236707)
@@ -1,3 +1,30 @@
+2018-10-01 Ryosuke Niwa <rn...@webkit.org>
+
+ Add a new variant of serializePreservingVisualAppearance which takes VisibleSelection
+ https://bugs.webkit.org/show_bug.cgi?id=190108
+
+ Reviewed by Wenson Hsieh.
+
+ Added a version of serializePreservingVisualAppearance which takes VisibleSelection so that we can avoid creating
+ a range simply to get the first node and the end node of the selection later. This simple change also fixes a bug
+ demonstrated in editing/pasteboard/paste-table-003.html.
+
+ Test: editing/pasteboard/paste-table-003.html
+
+ * editing/cocoa/EditorCocoa.mm:
+ (WebCore::Editor::selectionInHTMLFormat): Adopt the new variant.
+ * editing/gtk/EditorGtk.cpp:
+ (WebCore::Editor::writeSelectionToPasteboard): Ditto.
+ * editing/markup.cpp:
+ (WebCore::serializePreservingVisualAppearance): Added.
+ * editing/markup.h:
+ * editing/wpe/EditorWPE.cpp:
+ (WebCore::Editor::writeSelectionToPasteboard): Ditto.
+ * loader/archive/cf/LegacyWebArchive.cpp:
+ (WebCore::LegacyWebArchive::createFromSelection): Ditto.
+ * platform/win/PasteboardWin.cpp:
+ (WebCore::Pasteboard::writeSelection): Ditto.
+
2018-10-01 Alex Christensen <achristen...@webkit.org>
Don't read from WebCore's bundle for IDNScriptWhiteList
Modified: trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm (236706 => 236707)
--- trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2018-10-02 01:59:52 UTC (rev 236707)
@@ -75,9 +75,7 @@
String Editor::selectionInHTMLFormat()
{
- if (auto range = selectedRange())
- return serializePreservingVisualAppearance(*range, nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
- return { };
+ return serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
}
#if ENABLE(ATTACHMENT_ELEMENT)
Modified: trunk/Source/WebCore/editing/gtk/EditorGtk.cpp (236706 => 236707)
--- trunk/Source/WebCore/editing/gtk/EditorGtk.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/editing/gtk/EditorGtk.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -146,7 +146,7 @@
PasteboardWebContent pasteboardContent;
pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
pasteboardContent.text = selectedTextForDataTransfer();
- pasteboardContent.markup = serializePreservingVisualAppearance(*selectedRange(), nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
+ pasteboardContent.markup = serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
pasteboard.write(pasteboardContent);
}
Modified: trunk/Source/WebCore/editing/markup.cpp (236706 => 236707)
--- trunk/Source/WebCore/editing/markup.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/editing/markup.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -852,6 +852,13 @@
return serializePreservingVisualAppearanceInternal(range.startPosition(), range.endPosition(), nodes, annotate, convertBlocksToInlines, urlsToReslve, MSOListMode::DoNotPreserve);
}
+String serializePreservingVisualAppearance(const VisibleSelection& selection, ResolveURLs resolveURLs, Vector<Node*>* nodes)
+{
+ return serializePreservingVisualAppearanceInternal(selection.start(), selection.end(), nodes,
+ AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, resolveURLs, MSOListMode::DoNotPreserve);
+}
+
+
static bool shouldPreserveMSOLists(const String& markup)
{
if (!markup.startsWith("<html xmlns:"))
Modified: trunk/Source/WebCore/editing/markup.h (236706 => 236707)
--- trunk/Source/WebCore/editing/markup.h 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/editing/markup.h 2018-10-02 01:59:52 UTC (rev 236707)
@@ -46,6 +46,7 @@
class Page;
class QualifiedName;
class Range;
+class VisibleSelection;
void replaceSubresourceURLs(Ref<DocumentFragment>&&, HashMap<AtomicString, AtomicString>&&);
void removeSubresourceURLAttributes(Ref<DocumentFragment>&&, WTF::Function<bool(const URL&)> shouldRemoveURL);
@@ -70,6 +71,7 @@
enum class ResolveURLs : uint8_t { No, Yes, YesExcludingLocalFileURLsForPrivacy };
enum class ConvertBlocksToInlines : uint8_t { No, Yes };
WEBCORE_EXPORT String serializePreservingVisualAppearance(const Range&, Vector<Node*>* = nullptr, AnnotateForInterchange = AnnotateForInterchange::No, ConvertBlocksToInlines = ConvertBlocksToInlines::No, ResolveURLs = ResolveURLs::No);
+String serializePreservingVisualAppearance(const VisibleSelection&, ResolveURLs = ResolveURLs::No, Vector<Node*>* = nullptr);
enum class SerializedNodes : uint8_t { SubtreeIncludingNode, SubtreesOfChildren };
enum class SerializationSyntax : uint8_t { HTML, XML };
Modified: trunk/Source/WebCore/editing/wpe/EditorWPE.cpp (236706 => 236707)
--- trunk/Source/WebCore/editing/wpe/EditorWPE.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/editing/wpe/EditorWPE.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -64,7 +64,7 @@
{
PasteboardWebContent pasteboardContent;
pasteboardContent.text = selectedTextForDataTransfer();
- pasteboardContent.markup = serializePreservingVisualAppearance(*selectedRange(), nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
+ pasteboardContent.markup = serializePreservingVisualAppearance(m_frame.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
pasteboard.write(pasteboardContent);
}
Modified: trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp (236706 => 236707)
--- trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -554,8 +554,7 @@
builder.append(documentTypeString(*document));
Vector<Node*> nodeList;
- if (auto selectionRange = frame->selection().toNormalizedRange())
- builder.append(serializePreservingVisualAppearance(*selectionRange, &nodeList, AnnotateForInterchange::Yes));
+ builder.append(serializePreservingVisualAppearance(frame->selection().selection(), ResolveURLs::No, &nodeList));
auto archive = create(builder.toString(), *frame, nodeList, nullptr);
Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (236706 => 236707)
--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -469,7 +469,8 @@
// Put CF_HTML format on the pasteboard
if (::OpenClipboard(m_owner)) {
Vector<char> data;
- markupToCFHTML(serializePreservingVisualAppearance(selectedRange, nullptr, AnnotateForInterchange::Yes),
+ // FIXME: Use ResolveURLs::YesExcludingLocalFileURLsForPrivacy.
+ markupToCFHTML(serializePreservingVisualAppearance(frame.selection().selection()),
selectedRange.startContainer().document().url().string(), data);
HGLOBAL cbData = createGlobalData(data);
if (!::SetClipboardData(HTMLClipboardFormat, cbData))
Modified: trunk/Source/WebKit/ChangeLog (236706 => 236707)
--- trunk/Source/WebKit/ChangeLog 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebKit/ChangeLog 2018-10-02 01:59:52 UTC (rev 236707)
@@ -1,3 +1,15 @@
+2018-09-30 Ryosuke Niwa <rn...@webkit.org>
+
+ Add a new variant of serializePreservingVisualAppearance which takes VisibleSelection
+ https://bugs.webkit.org/show_bug.cgi?id=190108
+
+ Reviewed by Wenson Hsieh.
+
+ Adopt the new variant which directly takes VisibleSelection.
+
+ * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+ (WebKit::WebEditorClient::updateGlobalSelection):
+
2018-10-01 Andy Estes <aes...@apple.com>
[watchOS] Adopt NSURLSessionCompanionProxyPreference
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp (236706 => 236707)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp 2018-10-02 01:37:43 UTC (rev 236706)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp 2018-10-02 01:59:52 UTC (rev 236707)
@@ -126,7 +126,7 @@
PasteboardWebContent pasteboardContent;
pasteboardContent.canSmartCopyOrDelete = false;
pasteboardContent.text = range->text();
- pasteboardContent.markup = serializePreservingVisualAppearance(*range, nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
+ pasteboardContent.markup = serializePreservingVisualAppearance(frame->selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
Pasteboard::createForGlobalSelection()->write(pasteboardContent);
}