Skip to content

Commit 131cc3c

Browse files
committed
WKWebView doesn’t respond to -copyFont: and -pasteFont:
https://bugs.webkit.org/show_bug.cgi?id=191379 <rdar://problem/45878659> Reviewed by Wenson Hsieh. Source/WebCore: Test: editing/execCommand/mac/copyFont-pasteFont.html * dom/DOMPasteAccess.h: Add `DOMPasteAccessCategory::Fonts` (which corresponds to `NSPasteboardNameFont` on macOS). * editing/Editor.h: * editing/Editor.cpp: (WebCore::eventNameForClipboardEvent): (WebCore::createDataTransferForClipboardEvent): (WebCore::Editor::copyFont): Added. (WebCore::Editor::pasteFont): Added. Add platform-agnostic handling for `"CopyFont"` and `"PasteFont"` editor commands. * editing/mac/EditorMac.mm: (WebCore::Editor::platformCopyFont): Added. (WebCore::Editor::platformPasteFont): Added. Mimic the logic in `-[WebHTMLView copyFont:]`/`-[WebHTMLView pasteFont:]` to be compatible with WK1 (i.e. to make it easier for clients to switch to WK2). * editing/gtk/EditorGtk.cpp: (WebCore::Editor::platformCopyFont): Added. (WebCore::Editor::platformPasteFont): Added. * editing/ios/EditorIOS.mm: (WebCore::Editor::platformCopyFont): Added. (WebCore::Editor::platformPasteFont): Added. * editing/libwpe/EditorLibWPE.cpp: (WebCore::Editor::platformCopyFont): Added. (WebCore::Editor::platformPasteFont): Added. * editing/win/EditorWin.cpp: (WebCore::Editor::platformCopyFont): Added. (WebCore::Editor::platformPasteFont): Added. Add stubs for other platforms. * editing/EditorCommand.cpp: (WebCore::executeCopyFont): Added. (WebCore::executePasteFont): Added. (WebCore::createCommandMap): Hook `"CopyFont"` and `"PasteFont"` editor commands up to `document.execCommand`. Source/WebKit: * UIProcess/API/mac/WKView.mm: * UIProcess/API/mac/WKWebViewMac.mm: Add `-copyFont:` and `-pasteFont:` methods via `WEBCORE_COMMAND`. * UIProcess/WebPageProxy.cpp: (WebKit::pasteAccessCategoryForCommand): The `PasteFont` command should be categorized as `DOMPasteAccessCategory::Fonts`. * UIProcess/Cocoa/WebViewImpl.mm: (WebKit::pasteboardNameForAccessCategory): (WebKit::pasteboardForAccessCategory): * UIProcess/mac/WebPageProxyMac.mm: (WebKit::WebPageProxy::willPerformPasteCommand): Correlate `DOMPasteAccessCategory::Fonts` with `NSPasteboardNameFont`. * UIProcess/ios/WKContentViewInteraction.mm: (pasteboardNameForAccessCategory): (pasteboardForAccessCategory): * UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::willPerformPasteCommand): Correlate `DOMPasteAccessCategory::Fonts` with `UIPasteboardNameGeneral`. LayoutTests: * editing/editing.js: (execCopyFontCommand): Added. (copyFontCommand): Added. (execPasteFontCommand): Added. (pasteFontCommand): Added. * editing/execCommand/mac/copyFont-pasteFont.html: Added. * editing/execCommand/mac/copyFont-pasteFont-expected.html: Added. * TestExpectations: * platform/mac/TestExpectations: Canonical link: https://commits.webkit.org/245122@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@286894 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9ff0352 commit 131cc3c

24 files changed

+391
-3
lines changed

LayoutTests/ChangeLog

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2021-12-10 Devin Rousso <[email protected]>
2+
3+
WKWebView doesn’t respond to -copyFont: and -pasteFont:
4+
https://bugs.webkit.org/show_bug.cgi?id=191379
5+
<rdar://problem/45878659>
6+
7+
Reviewed by Wenson Hsieh.
8+
9+
* editing/editing.js:
10+
(execCopyFontCommand): Added.
11+
(copyFontCommand): Added.
12+
(execPasteFontCommand): Added.
13+
(pasteFontCommand): Added.
14+
* editing/execCommand/mac/copyFont-pasteFont.html: Added.
15+
* editing/execCommand/mac/copyFont-pasteFont-expected.html: Added.
16+
17+
* TestExpectations:
18+
* platform/mac/TestExpectations:
19+
120
2021-12-10 Myles C. Maxfield <[email protected]>
221

322
[Cocoa] OT-SVG glyphs don't draw into canvases (because of the GPU process)

LayoutTests/TestExpectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ editing/mac [ Skip ]
2020
editing/caret/ios [ Skip ]
2121
editing/editable-region [ Skip ]
2222
editing/execCommand/ios [ Skip ]
23+
editing/execCommand/mac [ Skip ]
2324
editing/input/cocoa [ Skip ]
2425
editing/input/ios [ Skip ]
2526
editing/find [ Skip ]

LayoutTests/editing/editing.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,34 @@ function pasteCommand() {
811811

812812
//-------------------------------------------------------------------------------------------------------
813813

814+
function execCopyFontCommand() {
815+
document.execCommand("CopyFont");
816+
debugForDumpAsText("execCopyFontCommand");
817+
}
818+
function copyFontCommand() {
819+
if (commandDelay > 0) {
820+
queueCommand(execCopyFontCommand, commandCount * commandDelay);
821+
commandCount++;
822+
} else
823+
execCopyFontCommand();
824+
}
825+
826+
//-------------------------------------------------------------------------------------------------------
827+
828+
function execPasteFontCommand() {
829+
document.execCommand("PasteFont");
830+
debugForDumpAsText("execPasteFontCommand");
831+
}
832+
function pasteFontCommand() {
833+
if (commandDelay > 0) {
834+
queueCommand(execPasteFontCommand, commandCount * commandDelay);
835+
commandCount++;
836+
} else
837+
execPasteFontCommand();
838+
}
839+
840+
//-------------------------------------------------------------------------------------------------------
841+
814842
function execCreateLinkCommand(url) {
815843
document.execCommand("CreateLink", false, url);
816844
debugForDumpAsText("execCreateLinkCommand");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html>
2+
<head>
3+
<style>
4+
#copy {
5+
background-color: green;
6+
font-family: Arial;
7+
font-size: 20px;
8+
font-weight: bold;
9+
font-style: italic;
10+
color: yellow;
11+
text-shadow: black 1px 1px;
12+
vertical-align: sub;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<div id="copy">copy this</div>
18+
<div id="paste" contenteditable=""><font color="#ffff00" face="Arial"><span style="background-color: rgb(0, 128, 0); font-size: 20px; text-shadow: rgb(0, 0, 0) 1px 1px;"><b><i><sub>paste here</sub></i></b></span></font></div>
19+
</body>
20+
</html>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<html>
2+
<head>
3+
<script src=../../editing.js></script>
4+
<script>
5+
function editingTest() {
6+
let selection = window.getSelection();
7+
8+
let copyRange = document.createRange();
9+
copyRange.selectNodeContents(document.getElementById("copy"));
10+
selection.removeAllRanges();
11+
selection.addRange(copyRange);
12+
copyFontCommand();
13+
14+
let pasteRange = document.createRange();
15+
pasteRange.selectNodeContents(document.getElementById("paste"));
16+
selection.removeAllRanges();
17+
selection.addRange(pasteRange);
18+
pasteFontCommand();
19+
20+
selection.removeAllRanges();
21+
}
22+
</script>
23+
<style>
24+
#copy {
25+
background-color: green;
26+
font-family: Arial;
27+
font-size: 20px;
28+
font-weight: bold;
29+
font-style: italic;
30+
color: yellow;
31+
text-shadow: black 1px 1px;
32+
vertical-align: sub;
33+
}
34+
#paste {
35+
outline: none;
36+
}
37+
</style>
38+
</head>
39+
<body>
40+
<div id="copy">copy this</div>
41+
<div id="paste" contenteditable>paste here</div>
42+
<script>
43+
runEditingTest();
44+
</script>
45+
</body>
46+
</html>

LayoutTests/platform/mac/TestExpectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
accessibility/mac [ Pass ]
1010
compositing/scrolling/async-overflow-scrolling/mac [ Pass ]
1111
displaylists [ Pass ]
12+
editing/execCommand/mac [ Pass ]
1213
editing/input/cocoa [ Pass ]
1314
editing/mac [ Pass ]
1415
editing/pasteboard/mac [ Pass ]

Source/WebCore/ChangeLog

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,50 @@
1+
2021-12-10 Devin Rousso <[email protected]>
2+
3+
WKWebView doesn’t respond to -copyFont: and -pasteFont:
4+
https://bugs.webkit.org/show_bug.cgi?id=191379
5+
<rdar://problem/45878659>
6+
7+
Reviewed by Wenson Hsieh.
8+
9+
Test: editing/execCommand/mac/copyFont-pasteFont.html
10+
11+
* dom/DOMPasteAccess.h:
12+
Add `DOMPasteAccessCategory::Fonts` (which corresponds to `NSPasteboardNameFont` on macOS).
13+
14+
* editing/Editor.h:
15+
* editing/Editor.cpp:
16+
(WebCore::eventNameForClipboardEvent):
17+
(WebCore::createDataTransferForClipboardEvent):
18+
(WebCore::Editor::copyFont): Added.
19+
(WebCore::Editor::pasteFont): Added.
20+
Add platform-agnostic handling for `"CopyFont"` and `"PasteFont"` editor commands.
21+
22+
* editing/mac/EditorMac.mm:
23+
(WebCore::Editor::platformCopyFont): Added.
24+
(WebCore::Editor::platformPasteFont): Added.
25+
Mimic the logic in `-[WebHTMLView copyFont:]`/`-[WebHTMLView pasteFont:]` to be compatible
26+
with WK1 (i.e. to make it easier for clients to switch to WK2).
27+
28+
* editing/gtk/EditorGtk.cpp:
29+
(WebCore::Editor::platformCopyFont): Added.
30+
(WebCore::Editor::platformPasteFont): Added.
31+
* editing/ios/EditorIOS.mm:
32+
(WebCore::Editor::platformCopyFont): Added.
33+
(WebCore::Editor::platformPasteFont): Added.
34+
* editing/libwpe/EditorLibWPE.cpp:
35+
(WebCore::Editor::platformCopyFont): Added.
36+
(WebCore::Editor::platformPasteFont): Added.
37+
* editing/win/EditorWin.cpp:
38+
(WebCore::Editor::platformCopyFont): Added.
39+
(WebCore::Editor::platformPasteFont): Added.
40+
Add stubs for other platforms.
41+
42+
* editing/EditorCommand.cpp:
43+
(WebCore::executeCopyFont): Added.
44+
(WebCore::executePasteFont): Added.
45+
(WebCore::createCommandMap):
46+
Hook `"CopyFont"` and `"PasteFont"` editor commands up to `document.execCommand`.
47+
148
2021-12-10 Eric Carlson <[email protected]>
249

350
[macOS] Add new screen and window capture backend

Source/WebCore/dom/DOMPasteAccess.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace WebCore {
3131

3232
enum class DOMPasteAccessCategory : uint8_t {
3333
General,
34+
Fonts,
3435
};
3536

3637
enum class DOMPasteAccessPolicy : uint8_t {
@@ -52,7 +53,8 @@ namespace WTF {
5253
template<> struct EnumTraits<WebCore::DOMPasteAccessCategory> {
5354
using values = EnumValues<
5455
WebCore::DOMPasteAccessCategory,
55-
WebCore::DOMPasteAccessCategory::General
56+
WebCore::DOMPasteAccessCategory::General,
57+
WebCore::DOMPasteAccessCategory::Fonts
5658
>;
5759
};
5860

Source/WebCore/editing/Editor.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,10 @@ bool Editor::canEditRichly() const
372372

373373
enum class ClipboardEventKind {
374374
Copy,
375+
CopyFont,
375376
Cut,
376377
Paste,
378+
PasteFont,
377379
PasteAsPlainText,
378380
PasteAsQuotation,
379381
BeforeCopy,
@@ -385,12 +387,14 @@ static AtomString eventNameForClipboardEvent(ClipboardEventKind kind)
385387
{
386388
switch (kind) {
387389
case ClipboardEventKind::Copy:
390+
case ClipboardEventKind::CopyFont:
388391
return eventNames().copyEvent;
389392
case ClipboardEventKind::Cut:
390393
return eventNames().cutEvent;
391394
case ClipboardEventKind::Paste:
392395
case ClipboardEventKind::PasteAsPlainText:
393396
case ClipboardEventKind::PasteAsQuotation:
397+
case ClipboardEventKind::PasteFont:
394398
return eventNames().pasteEvent;
395399
case ClipboardEventKind::BeforeCopy:
396400
return eventNames().beforecopyEvent;
@@ -407,6 +411,7 @@ static Ref<DataTransfer> createDataTransferForClipboardEvent(Document& document,
407411
{
408412
switch (kind) {
409413
case ClipboardEventKind::Copy:
414+
case ClipboardEventKind::CopyFont:
410415
case ClipboardEventKind::Cut:
411416
return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::ReadWrite, makeUnique<StaticPasteboard>());
412417
case ClipboardEventKind::PasteAsPlainText:
@@ -420,6 +425,7 @@ static Ref<DataTransfer> createDataTransferForClipboardEvent(Document& document,
420425
FALLTHROUGH;
421426
case ClipboardEventKind::Paste:
422427
case ClipboardEventKind::PasteAsQuotation:
428+
case ClipboardEventKind::PasteFont:
423429
return DataTransfer::createForCopyAndPaste(document, DataTransfer::StoreMode::Readonly, Pasteboard::createForCopyAndPaste(PagePasteboardContext::create(document.pageID())));
424430
case ClipboardEventKind::BeforeCopy:
425431
case ClipboardEventKind::BeforeCut:
@@ -1404,6 +1410,21 @@ void Editor::copy(FromMenuOrKeyBinding fromMenuOrKeyBinding)
14041410
performCutOrCopy(CopyAction);
14051411
}
14061412

1413+
void Editor::copyFont(FromMenuOrKeyBinding fromMenuOrKeyBinding)
1414+
{
1415+
SetForScope<bool> copyScope { m_copyingFromMenuOrKeyBinding, fromMenuOrKeyBinding == FromMenuOrKeyBinding::Yes };
1416+
if (tryDHTMLCopy())
1417+
return; // DHTML did the whole operation
1418+
if (!canCopy()) {
1419+
SystemSoundManager::singleton().systemBeep();
1420+
return;
1421+
}
1422+
1423+
willWriteSelectionToPasteboard(selectedRange());
1424+
platformCopyFont();
1425+
didWriteSelectionToPasteboard();
1426+
}
1427+
14071428
void Editor::postTextStateChangeNotificationForCut(const String& text, const VisibleSelection& selection)
14081429
{
14091430
if (!AXObjectCache::accessibilityEnabled())
@@ -1512,6 +1533,19 @@ void Editor::pasteAsQuotation(FromMenuOrKeyBinding fromMenuOrKeyBinding)
15121533
pasteAsPlainTextWithPasteboard(*pasteboard);
15131534
}
15141535

1536+
void Editor::pasteFont(FromMenuOrKeyBinding fromMenuOrKeyBinding)
1537+
{
1538+
SetForScope<bool> pasteScope { m_pastingFromMenuOrKeyBinding, fromMenuOrKeyBinding == FromMenuOrKeyBinding::Yes };
1539+
1540+
if (!dispatchClipboardEvent(findEventTargetFromSelection(), ClipboardEventKind::PasteFont))
1541+
return;
1542+
if (!canPaste())
1543+
return;
1544+
updateMarkersForWordsAffectedByEditing(false);
1545+
ResourceCacheValidationSuppressor validationSuppressor(document().cachedResourceLoader());
1546+
platformPasteFont();
1547+
}
1548+
15151549
void Editor::quoteFragmentForPasting(DocumentFragment& fragment)
15161550
{
15171551
auto blockQuote = HTMLQuoteElement::create(blockquoteTag, document());

Source/WebCore/editing/Editor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,13 @@ class Editor {
197197
enum class FromMenuOrKeyBinding : bool { No, Yes };
198198
WEBCORE_EXPORT void cut(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
199199
WEBCORE_EXPORT void copy(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
200+
void copyFont(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
200201

201202
WEBCORE_EXPORT void paste(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
202203
void paste(Pasteboard&, FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
203204
WEBCORE_EXPORT void pasteAsPlainText(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
204205
void pasteAsQuotation(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
206+
void pasteFont(FromMenuOrKeyBinding = FromMenuOrKeyBinding::No);
205207
WEBCORE_EXPORT void performDelete();
206208

207209
WEBCORE_EXPORT void copyURL(const URL&, const String& title);
@@ -592,6 +594,9 @@ class Editor {
592594
void pasteWithPasteboard(Pasteboard*, OptionSet<PasteOption>);
593595
String plainTextFromPasteboard(const PasteboardPlainText&);
594596

597+
void platformCopyFont();
598+
void platformPasteFont();
599+
595600
void quoteFragmentForPasting(DocumentFragment&);
596601

597602
void revealSelectionAfterEditingOperation(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent);

0 commit comments

Comments
 (0)