Changeset 238050 in webkit
- Timestamp:
- Nov 9, 2018 12:16:32 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r238049 r238050 1 2018-11-09 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists 4 https://bugs.webkit.org/show_bug.cgi?id=191410 5 <rdar://problem/45898610> 6 7 Reviewed by Dean Jackson. 8 9 Prefixes a few iOS-only SPI methods declared on WKWebView in r236867 with underscores, and also exposes some 10 more cross-platform Cocoa editing SPI. Once the unprefixed SPI methods are no longer used by internal clients, 11 these will need to be removed (see followup bug: webkit.org/b/191450). See below for more details. 12 13 Covered by new and existing API tests in WKWebViewEditActions. 14 15 * UIProcess/API/Cocoa/WKWebView.mm: 16 17 Hoist the definition (and undefinition) of `FORWARD_ACTION_TO_WKCONTENTVIEW` to encompass both the WKWebView 18 implementation and the WKWebView (WKPrivate) implementation. This allows us to use this macro when implementing 19 SPI methods in the WKPrivate category, as well as methods that are part of the main WKWebView implementation. 20 21 (-[WKWebView canPerformAction:withSender:]): 22 (-[WKWebView targetForAction:withSender:]): 23 24 Add forwarding for the new editing commands in -canPerformAction: and -targetForAction:. 25 26 (-[WKWebView _toggleStrikeThrough:]): 27 (-[WKWebView _increaseListLevel:]): 28 (-[WKWebView _decreaseListLevel:]): 29 (-[WKWebView _changeListType:]): 30 (-[WKWebView _setFont:sender:]): 31 (-[WKWebView _setFontSize:sender:]): 32 (-[WKWebView _setTextColor:sender:]): 33 34 Add definitions for the new editing methods on WKWebView, using macros (`WEBCORE_PRIVATE_COMMAND` on macOS and 35 `FORWARD_ACTION_TO_WKCONTENTVIEW` on iOS) to help reduce the code duplication. 36 37 (-[WKWebView _pasteAsQuotation:]): Deleted. 38 39 Remove this method definition, which is now replaced by macros on iOS and macOS. 40 41 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 42 43 Introduce the new SPI to WKWebView (WKPrivate), and add FIXMEs to remove old, unprefixed variants of the SPI. 44 45 * UIProcess/WebPageProxy.cpp: 46 (WebKit::WebPageProxy::increaseListLevel): 47 (WebKit::WebPageProxy::decreaseListLevel): 48 (WebKit::WebPageProxy::changeListType): 49 50 Add plumbing for these list editing commands. 51 52 * UIProcess/WebPageProxy.h: 53 * UIProcess/ios/WKContentViewInteraction.h: 54 * UIProcess/ios/WKContentViewInteraction.mm: 55 (-[WKContentView _increaseListLevelForWebView:]): 56 (-[WKContentView _decreaseListLevelForWebView:]): 57 (-[WKContentView _changeListTypeForWebView:]): 58 (-[WKContentView _toggleStrikeThroughForWebView:]): 59 (-[WKContentView _setFontForWebView:sender:]): 60 (-[WKContentView _setFontSizeForWebView:sender:]): 61 (-[WKContentView _setTextColorForWebView:sender:]): 62 (-[WKContentView toggleStrikeThroughForWebView:]): 63 (-[WKContentView setFontForWebView:sender:]): 64 (-[WKContentView setFontSizeForWebView:sender:]): 65 (-[WKContentView setTextColorForWebView:sender:]): 66 (-[WKContentView canPerformActionForWebView:withSender:]): 67 68 Check for the new action selectors here, and additionally add validation for `_pasteAsQuotation:`. Let the 69 unprefixed versions of these methods simply call the prefixed versions (these method implementations will be 70 removed in a followup once doing so would not affect any clients of WebKit). 71 72 * WebKit.xcodeproj/project.pbxproj: 73 * WebProcess/WebPage/WebPage.cpp: 74 (WebKit::WebPage::increaseListLevel): 75 (WebKit::WebPage::decreaseListLevel): 76 (WebKit::WebPage::changeListType): 77 * WebProcess/WebPage/WebPage.h: 78 * WebProcess/WebPage/WebPage.messages.in: 79 80 Add stubs for several list editing commands that are yet to be hooked up to WebCore. These will be implemented 81 in a future patch. 82 1 83 2018-11-09 Antti Koivisto <antti@apple.com> 2 84 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r238049 r238050 258 258 #endif 259 259 260 #define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \ 261 - (void)_action:(id)sender \ 262 { \ 263 if (self.usesStandardContentView) \ 264 [_contentView _action ## ForWebView:sender]; \ 265 } 266 260 267 @implementation WKWebView { 261 268 std::unique_ptr<WebKit::NavigationState> _navigationState; … … 1385 1392 } 1386 1393 1387 #define FORWARD_ACTION_TO_WKCONTENTVIEW(_action) \1388 - (void)_action:(id)sender \1389 { \1390 if (self.usesStandardContentView) \1391 [_contentView _action ## ForWebView:sender]; \1392 }1393 1394 1394 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW) 1395 1396 #undef FORWARD_ACTION_TO_WKCONTENTVIEW1397 1395 1398 1396 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender … … 1403 1401 1404 1402 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW) 1405 1406 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_pasteAsQuotation) 1403 FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW) 1404 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setTextColor:sender) 1405 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setFontSize:sender) 1406 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(setFont:sender) 1407 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setTextColor:sender) 1408 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFontSize:sender) 1409 FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW(_setFont:sender) 1407 1410 1408 1411 #undef FORWARD_CANPERFORMACTION_TO_WKCONTENTVIEW 1409 1410 if (action == @selector(setTextColor:sender:) || action == @selector(setFontSize:sender:) || action == @selector(setFont:sender:))1411 return self.usesStandardContentView && [_contentView canPerformActionForWebView:action withSender:sender];1412 1412 1413 1413 return [super canPerformAction:action withSender:sender]; … … 1421 1421 1422 1422 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW) 1423 1424 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_pasteAsQuotation) 1423 FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW) 1424 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setTextColor:sender) 1425 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setFontSize:sender) 1426 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(setFont:sender) 1427 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setTextColor:sender) 1428 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFontSize:sender) 1429 FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_setFont:sender) 1425 1430 1426 1431 #undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW … … 4293 4298 @implementation WKWebView (WKPrivate) 4294 4299 4300 #if PLATFORM(MAC) 4301 4302 #define WEBCORE_PRIVATE_COMMAND(command) - (void)_##command:(id)sender { _page->executeEditCommand(#command ## _s); } 4303 4304 WEBCORE_PRIVATE_COMMAND(alignCenter) 4305 WEBCORE_PRIVATE_COMMAND(alignJustified) 4306 WEBCORE_PRIVATE_COMMAND(alignLeft) 4307 WEBCORE_PRIVATE_COMMAND(alignRight) 4308 WEBCORE_PRIVATE_COMMAND(insertOrderedList) 4309 WEBCORE_PRIVATE_COMMAND(insertUnorderedList) 4310 WEBCORE_PRIVATE_COMMAND(insertNestedOrderedList) 4311 WEBCORE_PRIVATE_COMMAND(insertNestedUnorderedList) 4312 WEBCORE_PRIVATE_COMMAND(indent) 4313 WEBCORE_PRIVATE_COMMAND(outdent) 4314 WEBCORE_PRIVATE_COMMAND(pasteAsQuotation); 4315 4316 #undef WEBCORE_PRIVATE_COMMAND 4317 4318 - (void)_toggleStrikeThrough:(id)sender 4319 { 4320 _page->executeEditCommand("strikethrough"_s); 4321 } 4322 4323 - (void)_increaseListLevel:(id)sender 4324 { 4325 _page->increaseListLevel(); 4326 } 4327 4328 - (void)_decreaseListLevel:(id)sender 4329 { 4330 _page->decreaseListLevel(); 4331 } 4332 4333 - (void)_changeListType:(id)sender 4334 { 4335 _page->changeListType(); 4336 } 4337 4338 #endif // PLATFORM(MAC) 4339 4340 #if PLATFORM(IOS_FAMILY) 4341 4342 FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW) 4343 4344 - (void)_setFont:(UIFont *)font sender:(id)sender 4345 { 4346 if (self.usesStandardContentView) 4347 [_contentView setFontForWebView:font sender:sender]; 4348 } 4349 4350 - (void)_setFontSize:(CGFloat)fontSize sender:(id)sender 4351 { 4352 if (self.usesStandardContentView) 4353 [_contentView setFontSizeForWebView:fontSize sender:sender]; 4354 } 4355 4356 - (void)_setTextColor:(UIColor *)color sender:(id)sender 4357 { 4358 if (self.usesStandardContentView) 4359 [_contentView setTextColorForWebView:color sender:sender]; 4360 } 4361 4362 #endif // PLATFORM(IOS_FAMILY) 4363 4295 4364 - (BOOL)_isEditable 4296 4365 { … … 4637 4706 #endif 4638 4707 return nil; 4639 }4640 4641 - (void)_pasteAsQuotation:(id)sender4642 {4643 #if PLATFORM(MAC)4644 _impl->executeEditCommandForSelector(_cmd);4645 #else4646 if (self.usesStandardContentView)4647 [_contentView _pasteAsQuotationForWebView:sender];4648 #endif4649 4708 } 4650 4709 … … 6027 6086 @end 6028 6087 6088 #undef FORWARD_ACTION_TO_WKCONTENTVIEW 6029 6089 6030 6090 @implementation WKWebView (WKTesting) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r237885 r238050 187 187 - (_WKAttachment *)_attachmentForIdentifier:(NSString *)identifier WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 188 188 189 + (BOOL)_handlesSafeBrowsing WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 190 191 - (IBAction)_alignCenter:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 192 - (IBAction)_alignJustified:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 193 - (IBAction)_alignLeft:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 194 - (IBAction)_alignRight:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 195 - (IBAction)_indent:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 196 - (IBAction)_outdent:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 197 - (IBAction)_toggleStrikeThrough:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 198 - (IBAction)_insertOrderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 199 - (IBAction)_insertUnorderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 200 - (IBAction)_insertNestedOrderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 201 - (IBAction)_insertNestedUnorderedList:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 202 - (IBAction)_increaseListLevel:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 203 - (IBAction)_decreaseListLevel:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 204 - (IBAction)_changeListType:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 189 205 - (IBAction)_pasteAsQuotation:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); 190 206 191 + (BOOL)_handlesSafeBrowsing WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));192 193 207 #if TARGET_OS_IPHONE 208 209 - (void)_setFont:(UIFont *)font sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 210 - (void)_setFontSize:(CGFloat)fontSize sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 211 - (void)_setTextColor:(UIColor *)color sender:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 212 194 213 // DERECATED: The setters of the three following function are deprecated, please use overrideLayoutParameters. 195 214 // Define the smallest size a page take with a regular viewport. … … 372 391 373 392 @interface WKWebView () <UIResponderStandardEditActions> 393 // FIXME: Remove these once internal clients have moved to the underscore-prefixed versions. 374 394 - (void)alignCenter:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); 375 395 - (void)alignJustified:(id)sender WK_API_AVAILABLE(ios(WK_IOS_TBA)); -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r238049 r238050 1757 1757 } 1758 1758 1759 void WebPageProxy::increaseListLevel() 1760 { 1761 if (isValid()) 1762 m_process->send(Messages::WebPage::IncreaseListLevel(), m_pageID); 1763 } 1764 1765 void WebPageProxy::decreaseListLevel() 1766 { 1767 if (isValid()) 1768 m_process->send(Messages::WebPage::DecreaseListLevel(), m_pageID); 1769 } 1770 1771 void WebPageProxy::changeListType() 1772 { 1773 if (isValid()) 1774 m_process->send(Messages::WebPage::ChangeListType(), m_pageID); 1775 } 1776 1759 1777 void WebPageProxy::updateFontAttributesAfterEditorStateChange() 1760 1778 { -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r238049 r238050 546 546 bool isContentEditable() const { return m_editorState.isContentEditable; } 547 547 548 void increaseListLevel(); 549 void decreaseListLevel(); 550 void changeListType(); 551 548 552 std::optional<WebCore::FontAttributes> cachedFontAttributesAtSelectionStart() const { return m_cachedFontAttributesAtSelectionStart; } 549 553 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r237924 r238050 135 135 M(alignJustified) 136 136 137 #define FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(M) \ 138 M(_alignCenter) \ 139 M(_alignJustified) \ 140 M(_alignLeft) \ 141 M(_alignRight) \ 142 M(_indent) \ 143 M(_outdent) \ 144 M(_toggleStrikeThrough) \ 145 M(_insertOrderedList) \ 146 M(_insertUnorderedList) \ 147 M(_insertNestedOrderedList) \ 148 M(_insertNestedUnorderedList) \ 149 M(_increaseListLevel) \ 150 M(_decreaseListLevel) \ 151 M(_changeListType) \ 152 M(_pasteAsQuotation) 153 137 154 namespace WebKit { 138 155 … … 340 357 - (void)_action ## ForWebView:(id)sender; 341 358 FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW) 342 DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_pasteAsQuotation)359 FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW) 343 360 #undef DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW 344 361 -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r238047 r238050 2195 2195 2196 2196 FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW) 2197 2198 FORWARD_ACTION_TO_WKWEBVIEW(_pasteAsQuotation) 2197 FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW) 2199 2198 2200 2199 #undef FORWARD_ACTION_TO_WKWEBVIEW … … 2286 2285 } 2287 2286 2288 #define WEBCORE_COMMAND_FOR_WEBVIEW(command) - (void)command ## ForWebView:(id)sender { _page->executeEditCommand(#command ## _s); } 2289 2287 #define WEBCORE_COMMAND_FOR_WEBVIEW(command) \ 2288 - (void)_ ## command ## ForWebView:(id)sender { _page->executeEditCommand(#command ## _s); } \ 2289 - (void)command ## ForWebView:(id)sender { [self _ ## command ## ForWebView:sender]; } 2290 2290 WEBCORE_COMMAND_FOR_WEBVIEW(insertOrderedList); 2291 2291 WEBCORE_COMMAND_FOR_WEBVIEW(insertUnorderedList); 2292 WEBCORE_COMMAND_FOR_WEBVIEW(insertNestedOrderedList); 2293 WEBCORE_COMMAND_FOR_WEBVIEW(insertNestedUnorderedList); 2292 2294 WEBCORE_COMMAND_FOR_WEBVIEW(indent); 2293 2295 WEBCORE_COMMAND_FOR_WEBVIEW(outdent); … … 2296 2298 WEBCORE_COMMAND_FOR_WEBVIEW(alignCenter); 2297 2299 WEBCORE_COMMAND_FOR_WEBVIEW(alignJustified); 2298 2299 - (void)toggleStrikeThroughForWebView:(id)sender 2300 #undef WEBCORE_COMMAND_FOR_WEBVIEW 2301 2302 - (void)_increaseListLevelForWebView:(id)sender 2303 { 2304 _page->increaseListLevel(); 2305 } 2306 2307 - (void)_decreaseListLevelForWebView:(id)sender 2308 { 2309 _page->decreaseListLevel(); 2310 } 2311 2312 - (void)_changeListTypeForWebView:(id)sender 2313 { 2314 _page->changeListType(); 2315 } 2316 2317 - (void)_toggleStrikeThroughForWebView:(id)sender 2300 2318 { 2301 2319 _page->executeEditCommand("StrikeThrough"_s); … … 2312 2330 } 2313 2331 2314 - (void) setFontForWebView:(UIFont *)font sender:(id)sender2332 - (void)_setFontForWebView:(UIFont *)font sender:(id)sender 2315 2333 { 2316 2334 WebCore::FontChanges changes; … … 2323 2341 } 2324 2342 2325 - (void) setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender2343 - (void)_setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender 2326 2344 { 2327 2345 WebCore::FontChanges changes; … … 2330 2348 } 2331 2349 2350 - (void)_setTextColorForWebView:(UIColor *)color sender:(id)sender 2351 { 2352 _page->executeEditCommand("ForeColor"_s, WebCore::Color(color.CGColor).serialized()); 2353 } 2354 2355 - (void)toggleStrikeThroughForWebView:(id)sender 2356 { 2357 [self _toggleStrikeThroughForWebView:sender]; 2358 } 2359 2360 - (void)setFontForWebView:(UIFont *)font sender:(id)sender 2361 { 2362 [self _setFontForWebView:font sender:sender]; 2363 } 2364 2365 - (void)setFontSizeForWebView:(CGFloat)fontSize sender:(id)sender 2366 { 2367 [self _setFontSizeForWebView:fontSize sender:sender]; 2368 } 2369 2332 2370 - (void)setTextColorForWebView:(UIColor *)color sender:(id)sender 2333 2371 { 2334 _page->executeEditCommand("ForeColor"_s, WebCore::Color(color.CGColor).serialized()); 2335 } 2336 2337 #undef WEBCORE_COMMAND_FOR_WEBVIEW 2372 [self _setTextColorForWebView:color sender:sender]; 2373 } 2338 2374 2339 2375 - (NSDictionary *)textStylingAtPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction … … 2393 2429 if (_showingTextStyleOptions) 2394 2430 return (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:)); 2395 if (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:) || action == @selector(toggleStrikeThrough:) 2396 || action == @selector(insertOrderedList:) || action == @selector(insertUnorderedList:) || action == @selector(indent:) || action == @selector(outdent:) 2431 // FIXME: Some of the following checks should be removed once internal clients move to the underscore-prefixed versions. 2432 if (action == @selector(toggleBoldface:) || action == @selector(toggleItalics:) || action == @selector(toggleUnderline:) || action == @selector(_toggleStrikeThrough:) 2433 || action == @selector(_alignLeft:) || action == @selector(_alignRight:) || action == @selector(_alignCenter:) || action == @selector(_alignJustified:) 2434 || action == @selector(_setTextColor:sender:) || action == @selector(_setFont:sender:) || action == @selector(_setFontSize:sender:) 2435 || action == @selector(_insertOrderedList:) || action == @selector(_insertUnorderedList:) || action == @selector(_insertNestedOrderedList:) || action == @selector(_insertNestedUnorderedList:) 2436 || action == @selector(_increaseListLevel:) || action == @selector(_decreaseListLevel:) || action == @selector(_changeListType:) || action == @selector(_indent:) || action == @selector(_outdent:) 2437 || action == @selector(increaseSize:) || action == @selector(decreaseSize:) 2438 || action == @selector(toggleStrikeThrough:) || action == @selector(insertOrderedList:) || action == @selector(insertUnorderedList:) || action == @selector(indent:) || action == @selector(outdent:) 2397 2439 || action == @selector(alignLeft:) || action == @selector(alignRight:) || action == @selector(alignCenter:) || action == @selector(alignJustified:) 2398 || action == @selector(increaseSize:) || action == @selector(decreaseSize:) || action == @selector(setTextColor:sender:) 2399 || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)) { 2440 || action == @selector(setTextColor:sender:) || action == @selector(setFont:sender:) || action == @selector(setFontSize:sender:)) { 2400 2441 // FIXME: This should be more nuanced in the future, rather than returning YES for all richly editable areas. For instance, outdent: should be disabled when the selection is already 2401 2442 // at the outermost indentation level. … … 2405 2446 return !editorState.isInPasswordField && editorState.isContentEditable && editorState.selectionIsRange; 2406 2447 2407 if (action == @selector(paste:) ) {2448 if (action == @selector(paste:) || action == @selector(_pasteAsQuotation:)) { 2408 2449 if (editorState.selectionIsNone || !editorState.isContentEditable) 2409 2450 return NO; -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r238049 r238050 1151 1151 } 1152 1152 1153 void WebPage::increaseListLevel() 1154 { 1155 // FIXME: Not implemented. 1156 } 1157 1158 void WebPage::decreaseListLevel() 1159 { 1160 // FIXME: Not implemented. 1161 } 1162 1163 void WebPage::changeListType() 1164 { 1165 // FIXME: Not implemented. 1166 } 1167 1153 1168 bool WebPage::isEditingCommandEnabled(const String& commandName) 1154 1169 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r238049 r238050 1187 1187 void setEditable(bool); 1188 1188 1189 void increaseListLevel(); 1190 void decreaseListLevel(); 1191 void changeListType(); 1192 1189 1193 void setNeedsFontAttributes(bool); 1190 1194 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r238049 r238050 213 213 ExecuteEditCommand(String name, String argument) 214 214 215 IncreaseListLevel() 216 DecreaseListLevel() 217 ChangeListType() 218 215 219 SetNeedsFontAttributes(bool needsFontAttributes) 216 220 -
trunk/Tools/ChangeLog
r238025 r238050 1 2018-11-09 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [Cocoa] Introduce WKWebView SPI to insert nested ordered and unordered lists 4 https://bugs.webkit.org/show_bug.cgi?id=191410 5 <rdar://problem/45898610> 6 7 Reviewed by Dean Jackson. 8 9 Move WKWebViewEditActions from iOS to WebKitCocoa, and enable the relevant WKWebViewEditActions tests on macOS. 10 Additionally, add new API tests to verify that `-_pasteAsQuotation:` and `-_insertNested(Un)OrderedList:` are 11 hooked up to their respective editing commands. 12 13 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 14 * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm: Renamed from Tools/TestWebKitAPI/Tests/ios/WKWebViewEditActions.mm. 15 (-[TestWKWebView querySelectorExists:]): 16 (-[TestWKWebView insertString:]): 17 18 Add a helper method to insert a piece of text. This abstracts platform differences between iOS and macOS, by 19 invoking the WKWebView directly on macOS and calling on the content view on iOS. 20 21 (TestWebKitAPI::webViewForEditActionTesting): 22 (TestWebKitAPI::TEST): 23 1 24 2018-11-09 Philippe Normand <pnormand@igalia.com> 2 25 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r238015 r238050 847 847 F46A095B1ED8A6E600D4AA55 /* gif-and-file-input.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */; }; 848 848 F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; }; 849 F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */; }; 849 850 F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; }; 850 851 F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */; }; … … 879 880 F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */; }; 880 881 F4FA91831E61857B007B8C1D /* double-click-does-not-select-trailing-space.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */; }; 881 F4FB682521643EFC0034607A /* WKWebViewEditActions.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */; };882 882 F4FC077720F013B600CA043C /* significant-text-milestone.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4FC077620F0108100CA043C /* significant-text-milestone.html */; }; 883 883 F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; }; … … 2132 2132 F47D30EB1ED28619000482E1 /* apple.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = apple.gif; sourceTree = "<group>"; }; 2133 2133 F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "gif-and-file-input.html"; sourceTree = "<group>"; }; 2134 F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; }; 2134 2135 F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; }; 2135 2136 F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "DataTransfer-setDragImage.html"; sourceTree = "<group>"; }; … … 2167 2168 F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewMacEditingTests.mm; sourceTree = "<group>"; }; 2168 2169 F4FA91821E618566007B8C1D /* double-click-does-not-select-trailing-space.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "double-click-does-not-select-trailing-space.html"; path = "Tests/WebKitCocoa/double-click-does-not-select-trailing-space.html"; sourceTree = SOURCE_ROOT; }; 2169 F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewEditActions.mm; sourceTree = "<group>"; };2170 2170 F4FC077620F0108100CA043C /* significant-text-milestone.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "significant-text-milestone.html"; sourceTree = "<group>"; }; 2171 2171 F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; }; … … 2515 2515 46E66A8F1F0D75590026D83C /* WKWebViewDiagnosticLogging.mm */, 2516 2516 2DB647871F4161F70051A89E /* WKWebViewDoesNotLogDuringInitialization.mm */, 2517 F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */, 2517 2518 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */, 2518 2519 D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */, … … 2633 2634 F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */, 2634 2635 514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */, 2635 F4FB682421643EFC0034607A /* WKWebViewEditActions.mm */,2636 2636 ); 2637 2637 path = ios; … … 4176 4176 46E66A901F0D75590026D83C /* WKWebViewDiagnosticLogging.mm in Sources */, 4177 4177 2DB647881F4163D60051A89E /* WKWebViewDoesNotLogDuringInitialization.mm in Sources */, 4178 F4 FB682521643EFC0034607A/* WKWebViewEditActions.mm in Sources */,4178 F4811E5921940BDE00A5E0FD /* WKWebViewEditActions.mm in Sources */, 4179 4179 0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */, 4180 4180 D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm
r238049 r238050 26 26 #import "config.h" 27 27 28 #if PLATFORM(IOS_FAMILY) &&WK_API_ENABLED28 #if WK_API_ENABLED 29 29 30 30 #import "PlatformUtilities.h" 31 31 #import "TestWKWebView.h" 32 #import <WebKit/WKWebViewPrivate.h> 33 34 #if PLATFORM(IOS_FAMILY) 32 35 #import "UIKitSPI.h" 33 36 #import <UIKit/UIFontDescriptor.h> 34 # import <WebKit/WKWebViewPrivate.h>37 #endif 35 38 36 39 @interface TestWKWebView (EditActionTesting) 37 40 - (BOOL)querySelectorExists:(NSString *)querySelector; 41 - (void)insertString:(NSString *)string; 38 42 @end 39 43 … … 43 47 { 44 48 return [[self objectByEvaluatingJavaScript:[NSString stringWithFormat:@"!!document.querySelector(`%@`)", querySelector]] boolValue]; 49 } 50 51 - (void)insertString:(NSString *)string 52 { 53 #if PLATFORM(IOS_FAMILY) 54 [[self textInputContentView] insertText:string]; 55 #else 56 [self insertText:string]; 57 #endif 45 58 } 46 59 … … 58 71 } 59 72 73 TEST(WKWebViewEditActions, NestedListInsertion) 74 { 75 auto webView = webViewForEditActionTesting(); 76 77 [webView _insertNestedOrderedList:nil]; 78 EXPECT_TRUE([webView querySelectorExists:@"ol"]); 79 EXPECT_TRUE([webView querySelectorExists:@"ol > li"]); 80 81 [webView _insertNestedOrderedList:nil]; 82 EXPECT_TRUE([webView querySelectorExists:@"ol > ol"]); 83 EXPECT_TRUE([webView querySelectorExists:@"ol > ol > li"]); 84 85 [webView _insertNestedUnorderedList:nil]; 86 EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul"]); 87 EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > li"]); 88 89 [webView _insertNestedUnorderedList:nil]; 90 EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > ul"]); 91 EXPECT_TRUE([webView querySelectorExists:@"ol > ol > ul > ul > li"]); 92 } 93 60 94 TEST(WKWebViewEditActions, ListInsertion) 61 95 { 62 96 auto webView = webViewForEditActionTesting(); 63 97 64 [webView insertOrderedList:nil];98 [webView _insertOrderedList:nil]; 65 99 EXPECT_TRUE([webView querySelectorExists:@"ol"]); 66 [webView insertOrderedList:nil];100 [webView _insertOrderedList:nil]; 67 101 EXPECT_FALSE([webView querySelectorExists:@"ol"]); 68 102 69 [webView insertUnorderedList:nil];103 [webView _insertUnorderedList:nil]; 70 104 EXPECT_TRUE([webView querySelectorExists:@"ul"]); 71 [webView insertUnorderedList:nil];105 [webView _insertUnorderedList:nil]; 72 106 EXPECT_FALSE([webView querySelectorExists:@"ul"]); 73 107 } … … 77 111 auto webView = webViewForEditActionTesting(); 78 112 79 [webView indent:nil];113 [webView _indent:nil]; 80 114 EXPECT_TRUE([webView querySelectorExists:@"blockquote"]); 81 [webView indent:nil];115 [webView _indent:nil]; 82 116 EXPECT_TRUE([webView querySelectorExists:@"blockquote > blockquote"]); 83 117 84 [webView outdent:nil];118 [webView _outdent:nil]; 85 119 EXPECT_TRUE([webView querySelectorExists:@"blockquote"]); 86 [webView outdent:nil];120 [webView _outdent:nil]; 87 121 EXPECT_FALSE([webView querySelectorExists:@"blockquote"]); 88 122 } … … 92 126 auto webView = webViewForEditActionTesting(); 93 127 auto runTest = [webView] { 94 [webView alignCenter:nil];128 [webView _alignCenter:nil]; 95 129 EXPECT_WK_STREQ("center", [webView stylePropertyAtSelectionStart:@"text-align"]); 96 [webView alignLeft:nil];130 [webView _alignLeft:nil]; 97 131 EXPECT_WK_STREQ("left", [webView stylePropertyAtSelectionStart:@"text-align"]); 98 [webView alignRight:nil];132 [webView _alignRight:nil]; 99 133 EXPECT_WK_STREQ("right", [webView stylePropertyAtSelectionStart:@"text-align"]); 100 [webView alignJustified:nil];134 [webView _alignJustified:nil]; 101 135 EXPECT_WK_STREQ("justify", [webView stylePropertyAtSelectionStart:@"text-align"]); 102 136 }; … … 113 147 auto webView = webViewForEditActionTesting(); 114 148 [webView selectAll:nil]; 115 [webView toggleStrikeThrough:nil];149 [webView _toggleStrikeThrough:nil]; 116 150 EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]); 117 151 EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]); 118 152 119 [webView toggleStrikeThrough:nil];153 [webView _toggleStrikeThrough:nil]; 120 154 EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]); 121 155 EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]); 122 156 123 157 [webView collapseToEnd]; 124 [webView toggleStrikeThrough:nil];125 [ [webView textInputContentView] insertText:@"Hello"];158 [webView _toggleStrikeThrough:nil]; 159 [webView insertString:@"Hello"]; 126 160 EXPECT_WK_STREQ("line-through", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]); 127 161 128 [webView toggleStrikeThrough:nil];129 [ [webView textInputContentView] insertText:@"Hello"];162 [webView _toggleStrikeThrough:nil]; 163 [webView insertString:@"Hello"]; 130 164 EXPECT_WK_STREQ("none", [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]); 131 165 } 166 167 TEST(WKWebViewEditActions, PasteAsQuotation) 168 { 169 auto webView = webViewForEditActionTesting(); 170 [webView selectAll:nil]; 171 [webView _executeEditCommand:@"cut" argument:nil completion:nil]; 172 [webView _pasteAsQuotation:nil]; 173 EXPECT_TRUE([webView querySelectorExists:@"blockquote"]); 174 } 175 176 #if PLATFORM(IOS_FAMILY) 132 177 133 178 TEST(WKWebViewEditActions, ChangeFontSize) … … 147 192 EXPECT_EQ(16, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]); 148 193 149 [webView setFontSize:20 sender:nil];194 [webView _setFontSize:20 sender:nil]; 150 195 EXPECT_EQ(20, [[webView stylePropertyAtSelectionStart:@"font-size"] floatValue]); 151 196 } … … 156 201 [webView selectAll:nil]; 157 202 158 [webView setTextColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1] sender:nil];203 [webView _setTextColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1] sender:nil]; 159 204 EXPECT_WK_STREQ("rgb(255, 0, 0)", [webView stylePropertyAtSelectionStart:@"color"]); 160 205 EXPECT_TRUE([webView querySelectorExists:@"font"]); 161 206 162 [webView setTextColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.2] sender:nil];207 [webView _setTextColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0.2] sender:nil]; 163 208 EXPECT_WK_STREQ("rgba(0, 255, 0, 0.2)", [webView stylePropertyAtSelectionStart:@"color"]); 164 209 EXPECT_FALSE([webView querySelectorExists:@"font"]); … … 171 216 172 217 UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{ UIFontDescriptorFamilyAttribute: @"Helvetica" }]; 173 [webView setFont:[UIFont fontWithDescriptor:fontDescriptor size:24] sender:nil];218 [webView _setFont:[UIFont fontWithDescriptor:fontDescriptor size:24] sender:nil]; 174 219 EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]); 175 220 EXPECT_WK_STREQ("24px", [webView stylePropertyAtSelectionStart:@"font-size"]); … … 177 222 EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]); 178 223 179 [webView setFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12] sender:nil];224 [webView _setFont:[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12] sender:nil]; 180 225 EXPECT_WK_STREQ("\"Times New Roman\"", [webView stylePropertyAtSelectionStart:@"font-family"]); 181 226 EXPECT_WK_STREQ("12px", [webView stylePropertyAtSelectionStart:@"font-size"]); … … 184 229 185 230 fontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic | UIFontDescriptorTraitBold]; 186 [webView setFont:[UIFont fontWithDescriptor:fontDescriptor size:20] sender:nil];231 [webView _setFont:[UIFont fontWithDescriptor:fontDescriptor size:20] sender:nil]; 187 232 EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]); 188 233 EXPECT_WK_STREQ("20px", [webView stylePropertyAtSelectionStart:@"font-size"]); … … 191 236 } 192 237 238 #endif // PLATFORM(IOS_FAMILY) 239 193 240 } // namespace TestWebKitAPI 194 241 195 #endif // PLATFORM(IOS_FAMILY) &&WK_API_ENABLED242 #endif // WK_API_ENABLED
Note: See TracChangeset
for help on using the changeset viewer.