[macOS] [WK2] Support changing attributes for selected text (text shadow, underline...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 00:05:31 +0000 (00:05 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 00:05:31 +0000 (00:05 +0000)
commit99d775724563711251752d3b6fdb45f812074fb7
tree726aa255d7c07dcd9c0bd6341db3a090e393f5a8
parentefd16c7fd242fe5792f114e18d59612070022f70
[macOS] [WK2] Support changing attributes for selected text (text shadow, underline, strike-through)
https://bugs.webkit.org/show_bug.cgi?id=189356
<rdar://problem/44185674>

Reviewed by Tim Horton.

Source/WebCore:

Add support for encoding and decoding FontAttributeChanges, so that we can send FontAttributeChanges over IPC in
WebKit2. Also change m_verticalAlign to a new VerticalAlignChange enum type, so that it's no longer tied to the
CSS property values of "vertical-align", and can be encoded/decoded separately from VerticalAlign in
RenderStyleConstants.

Test: FontManagerTests.ChangeAttributesWithFontEffectsBox

* editing/FontAttributeChanges.cpp:
(WebCore::FontAttributeChanges::createEditingStyle const):
* editing/FontAttributeChanges.h:
(WebCore::FontAttributeChanges::setVerticalAlign):
(WebCore::FontShadow::encode const):
(WebCore::FontShadow::decode):
(WebCore::FontAttributeChanges::encode const):
(WebCore::FontAttributeChanges::decode):
* platform/mac/WebCoreNSFontManagerExtras.mm:
(WebCore::computedFontAttributeChanges):

Source/WebKit:

Implement -[WKWebView changeAttributes:], so that WKWebView can carry out more types of font style changes via
NSFontPanel. This patch makes it possible to (1) change text shadow, (2) add or remove strike-through, and (3)
add or remove underlines from selected text using the font panel.

This builds on the mechanisms introduced in r235748 to compute font attribute changes in the UI process and
propagate this information to the web process, where we're able to create and apply an EditingStyle to the
current selection.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView changeAttributes:]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::changeFontAttributesFromSender):
* UIProcess/WebPageProxy.h:
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::changeFontAttributes):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Add boilerplate IPC support.

* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::changeFontAttributes):

Tools:

Adds a new API test to verify that some font attributes (text shadow, underline, and strike-through) can be
added and removed using NSFontPanel.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/FontManagerTests.mm:

Add the new API test.

(TestWebKitAPI::TEST):
* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/mac/NSFontPanelTesting.h: Added.
* TestWebKitAPI/mac/NSFontPanelTesting.mm: Added.

Introduce a new file that extends NSFontPanel with some additional testing functionality. This includes the
ability to interact with the text shadow toggle button, choose the text shadow blur radius and opacity, and
change underline and strike-through styles.

(findSubviewOfClass):
(findMenuItemWithTitle):
(-[NSFontPanel fontEffectsBox]):

NSFontEffectsBox (an internal AppKit class) is the sender in the case where -changeAttributes: is invoked
through interaction with the font panel. To simulate this for testing, grab this font effects box and pass it
directory to -changeAttributes:.

(-[NSFontPanel chooseUnderlineMenuItemWithTitle:]):
(-[NSFontPanel chooseStrikeThroughMenuItemWithTitle:]):

The supported values for these menu items are "none" and "single", which adds a single underline or
strike-through to selected text. We grab these menu items by asking for the font panel's NSToolbar, and finding
the relevant menu items via toolbar item identifiers.

(-[NSFontPanel _didChangeAttributes]):
(-[NSFontPanel shadowBlurSlider]):
(-[NSFontPanel shadowOpacitySlider]):
(-[NSFontPanel shadowToggleButton]):
(-[NSFontPanel toggleShadow]):
(-[NSFontPanel shadowOpacity]):
(-[NSFontPanel setShadowOpacity:]):
(-[NSFontPanel shadowBlur]):
(-[NSFontPanel setShadowBlur:]):
(-[NSFontPanel _toolbarItemWithIdentifier:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235769 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/FontAttributeChanges.cpp
Source/WebCore/editing/FontAttributeChanges.h
Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/mac/WebPageProxyMac.mm
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/mac/NSFontPanelTesting.h [new file with mode: 0644]
Tools/TestWebKitAPI/mac/NSFontPanelTesting.mm [new file with mode: 0644]