WebKit Bugzilla
Attachment 349049 Details for
Bug 189356
: [macOS] [WK2] Support changing attributes for selected text (text shadow, underline, strike-through)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Blocked on webkit.org/b/189295
bug-189356-20180906114932.patch (text/plain), 33.79 KB, created by
Wenson Hsieh
on 2018-09-06 11:49:33 PDT
(
hide
)
Description:
Blocked on webkit.org/b/189295
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-09-06 11:49:33 PDT
Size:
33.79 KB
patch
obsolete
>Subversion Revision: 235715 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index bf84a2792ea50e3303f28fa483dfba8d8e1f1015..f5d391fe6576431638c0fb47337f6c1eec96a195 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,29 @@ >+2018-09-06 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ 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): >+ > 2018-09-05 Wenson Hsieh <wenson_hsieh@apple.com> > > [macOS] Cannot change font size at selection until font panel is shown >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index a16e593c1d7b301a0b4653c63e160c4660f54a88..ee59d784be006b5f18c6b80c315312453d56b013 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,35 @@ >+2018-09-06 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ 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 <webkit.org/b/189295> 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): >+ > 2018-09-05 Wenson Hsieh <wenson_hsieh@apple.com> > > [macOS] Cannot change font size at selection until font panel is shown >diff --git a/Source/WebCore/editing/FontAttributeChanges.cpp b/Source/WebCore/editing/FontAttributeChanges.cpp >index ec3f8fc6bb6b8281ce7b2c06b1824c85ac4a4069..40b3d62ab60eef5f5a9b5c767df5c06b484fc353 100644 >--- a/Source/WebCore/editing/FontAttributeChanges.cpp >+++ b/Source/WebCore/editing/FontAttributeChanges.cpp >@@ -112,14 +112,19 @@ Ref<EditingStyle> FontAttributeChanges::createEditingStyle() const > } > > if (m_verticalAlign) { >- if (*m_verticalAlign == VerticalAlign::Super) >+ switch (*m_verticalAlign) { >+ case VerticalAlignChange::Superscript: > style->setProperty(CSSPropertyVerticalAlign, CSSValueSuper); >- else if (*m_verticalAlign == VerticalAlign::Sub) >+ break; >+ case VerticalAlignChange::Subscript: > style->setProperty(CSSPropertyVerticalAlign, CSSValueSub); >- else if (*m_verticalAlign == VerticalAlign::Baseline) >+ break; >+ case VerticalAlignChange::Baseline: > style->setProperty(CSSPropertyVerticalAlign, CSSValueBaseline); >- else >+ break; >+ default: > ASSERT_NOT_REACHED(); >+ } > } > > auto editingStyle = EditingStyle::create(style.ptr()); >diff --git a/Source/WebCore/editing/FontAttributeChanges.h b/Source/WebCore/editing/FontAttributeChanges.h >index b97fde809af539cc04cdc2718c519ac4da9a2245..cb667b5c50ece005ebe094d5b1b1e8e6e1c6109f 100644 >--- a/Source/WebCore/editing/FontAttributeChanges.h >+++ b/Source/WebCore/editing/FontAttributeChanges.h >@@ -26,7 +26,7 @@ > #pragma once > > #include "Color.h" >-#include "RenderStyleConstants.h" >+#include <wtf/EnumTraits.h> > #include <wtf/Forward.h> > #include <wtf/Optional.h> > >@@ -35,6 +35,8 @@ namespace WebCore { > class EditingStyle; > class MutableStyleProperties; > >+enum class VerticalAlignChange : uint8_t { Superscript, Baseline, Subscript }; >+ > class FontChanges { > public: > template<class Encoder> void encode(Encoder&) const; >@@ -62,6 +64,9 @@ private: > }; > > struct FontShadow { >+ template<class Encoder> void encode(Encoder&) const; >+ template<class Decoder> static bool decode(Decoder&, FontShadow&); >+ > Color color; > double width { 0 }; > double height { 0 }; >@@ -70,7 +75,10 @@ struct FontShadow { > > class FontAttributeChanges { > public: >- void setVerticalAlign(VerticalAlign align) { m_verticalAlign = align; } >+ template<class Encoder> void encode(Encoder&) const; >+ template<class Decoder> static bool decode(Decoder&, FontAttributeChanges&); >+ >+ void setVerticalAlign(VerticalAlignChange align) { m_verticalAlign = align; } > void setBackgroundColor(const Color& color) { m_backgroundColor = color; } > void setForegroundColor(const Color& color) { m_foregroundColor = color; } > void setShadow(const FontShadow& shadow) { m_shadow = shadow; } >@@ -81,7 +89,7 @@ public: > WEBCORE_EXPORT Ref<EditingStyle> createEditingStyle() const; > > private: >- std::optional<VerticalAlign> m_verticalAlign; >+ std::optional<VerticalAlignChange> m_verticalAlign; > std::optional<Color> m_backgroundColor; > std::optional<Color> m_foregroundColor; > std::optional<FontShadow> m_shadow; >@@ -122,4 +130,72 @@ bool FontChanges::decode(Decoder& decoder, FontChanges& changes) > return true; > } > >+template<class Encoder> >+void FontShadow::encode(Encoder& encoder) const >+{ >+ encoder << color << width << height << blurRadius; >+} >+ >+template<class Decoder> >+bool FontShadow::decode(Decoder& decoder, FontShadow& shadow) >+{ >+ if (!decoder.decode(shadow.color)) >+ return false; >+ >+ if (!decoder.decode(shadow.width)) >+ return false; >+ >+ if (!decoder.decode(shadow.height)) >+ return false; >+ >+ if (!decoder.decode(shadow.blurRadius)) >+ return false; >+ >+ return true; >+} >+ >+template<class Encoder> >+void FontAttributeChanges::encode(Encoder& encoder) const >+{ >+ encoder << m_verticalAlign << m_backgroundColor << m_foregroundColor << m_shadow << m_strikeThrough << m_underline << m_fontChanges; >+} >+ >+template<class Decoder> >+bool FontAttributeChanges::decode(Decoder& decoder, FontAttributeChanges& changes) >+{ >+ if (!decoder.decode(changes.m_verticalAlign)) >+ return false; >+ >+ if (!decoder.decode(changes.m_backgroundColor)) >+ return false; >+ >+ if (!decoder.decode(changes.m_foregroundColor)) >+ return false; >+ >+ if (!decoder.decode(changes.m_shadow)) >+ return false; >+ >+ if (!decoder.decode(changes.m_strikeThrough)) >+ return false; >+ >+ if (!decoder.decode(changes.m_underline)) >+ return false; >+ >+ if (!decoder.decode(changes.m_fontChanges)) >+ return false; >+ >+ return true; >+} >+ > } // namespace WebCore >+ >+namespace WTF { >+template<> struct EnumTraits<WebCore::VerticalAlignChange> { >+ using values = EnumValues< >+ WebCore::VerticalAlignChange, >+ WebCore::VerticalAlignChange::Superscript, >+ WebCore::VerticalAlignChange::Baseline, >+ WebCore::VerticalAlignChange::Subscript >+ >; >+}; >+} >diff --git a/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm >index 478db4acc436445d7e83025d8b03f0244b1d845a..9275ba5f092809ebfe8c1677b3ba93f618c1055e 100644 >--- a/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm >+++ b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm >@@ -144,11 +144,11 @@ FontAttributeChanges computedFontAttributeChanges(NSFontManager *fontManager, id > int convertedSuperscriptA = [[convertedAttributesA objectForKey:NSSuperscriptAttributeName] intValue]; > if (convertedSuperscriptA == [[convertedAttributesB objectForKey:NSSuperscriptAttributeName] intValue]) { > if (convertedSuperscriptA > 0) >- changes.setVerticalAlign(VerticalAlign::Super); >+ changes.setVerticalAlign(VerticalAlignChange::Superscript); > else if (convertedSuperscriptA < 0) >- changes.setVerticalAlign(VerticalAlign::Sub); >+ changes.setVerticalAlign(VerticalAlignChange::Subscript); > else >- changes.setVerticalAlign(VerticalAlign::Baseline); >+ changes.setVerticalAlign(VerticalAlignChange::Baseline); > } > > int convertedStrikeThroughA = [[convertedAttributesA objectForKey:NSStrikethroughStyleAttributeName] intValue]; >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >index 49f5180ed33603a454c51f401a7eb754f2f67d0c..66c28ebffcd523b7045c15adb2754f42a0cd8243 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >@@ -3359,6 +3359,11 @@ WEBCORE_COMMAND(yankAndSelect) > _impl->changeFontFromFontManager(); > } > >+- (void)changeAttributes:(id)sender >+{ >+ _impl->changeFontAttributesFromSender(sender); >+} >+ > - (IBAction)startSpeaking:(id)sender > { > _impl->startSpeaking(); >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >index c9f3b895c7ba8e77f0da639fad2eb971bf7347dd..796c928d091c0a66b98b4ce2721955c4b03f32b3 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >@@ -316,6 +316,7 @@ public: > void didBecomeEditable(); > void updateFontPanelIfNeeded(); > void changeFontFromFontManager(); >+ void changeFontAttributesFromSender(id); > bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>); > void setEditableElementIsFocused(bool); > >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >index c25edf34f650abeecc529485b636a399c659d593..552d6505d2538b86c5fceee77d950ba8c25a4006 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >@@ -2734,6 +2734,16 @@ void WebViewImpl::updateFontPanelIfNeeded() > } > } > >+void WebViewImpl::changeFontAttributesFromSender(id sender) >+{ >+ auto& editorState = m_page->editorState(); >+ if (!editorState.isContentEditable || editorState.selectionIsNone) >+ return; >+ >+ m_page->changeFontAttributes(WebCore::computedFontAttributeChanges(NSFontManager.sharedFontManager, sender)); >+ updateFontPanelIfNeeded(); >+} >+ > void WebViewImpl::changeFontFromFontManager() > { > auto& editorState = m_page->editorState(); >diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h >index 380ba9efea10481db19d079a6b2415482e099047..4272e1b3e4d2f0df7a26707abf1932805d5d20bb 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.h >+++ b/Source/WebKit/UIProcess/WebPageProxy.h >@@ -162,6 +162,7 @@ class CertificateInfo; > class Cursor; > class DragData; > class FloatRect; >+class FontAttributeChanges; > class FontChanges; > class GraphicsLayer; > class IntSize; >@@ -681,6 +682,7 @@ public: > #if PLATFORM(MAC) > void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup); > void attributedSubstringForCharacterRangeAsync(const EditingRange&, WTF::Function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>&&); >+ void changeFontAttributes(WebCore::FontAttributeChanges&&); > void changeFont(WebCore::FontChanges&&); > void fontAtSelection(WTF::Function<void (const String&, double, bool, CallbackBase::Error)>&&); > >diff --git a/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm b/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >index 1446ae0d12f135bcd2fa25387a0fbbaa979dd33b..5d0cedc089fdf910629ee969025a73c0c3f85d59 100644 >--- a/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >+++ b/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >@@ -626,6 +626,14 @@ bool WebPageProxy::appleMailLinesClampEnabled() > { > return MacApplication::isAppleMail(); > } >+ >+void WebPageProxy::changeFontAttributes(WebCore::FontAttributeChanges&& changes) >+{ >+ if (!isValid()) >+ return; >+ >+ process().send(Messages::WebPage::ChangeFontAttributes(WTFMove(changes)), m_pageID); >+} > > void WebPageProxy::changeFont(WebCore::FontChanges&& changes) > { >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index fbaf780db3f8cb7669c2854e28104e2d222923ed..14499480293c5e42eaee87b75a435ee8d1fe508e 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -135,6 +135,7 @@ namespace WebCore { > class CaptureDevice; > class DocumentLoader; > class DragData; >+class FontAttributeChanges; > class FontChanges; > class Frame; > class FrameSelection; >@@ -1363,6 +1364,7 @@ private: > void immediateActionDidCancel(); > void immediateActionDidComplete(); > void changeFont(WebCore::FontChanges&&); >+ void changeFontAttributes(WebCore::FontAttributeChanges&&); > > void dataDetectorsDidPresentUI(WebCore::PageOverlay::PageOverlayID); > void dataDetectorsDidChangeUI(WebCore::PageOverlay::PageOverlayID); >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >index 70f220dd375aa95a8d210fe8e7105df21592f1c4..c34afeb1d08a9ae7d4879b4447ae2f7b82b152de 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >@@ -191,6 +191,7 @@ messages -> WebPage LegacyReceiver { > #if PLATFORM(MAC) > PerformDictionaryLookupOfCurrentSelection() > ChangeFont(WebCore::FontChanges changes) >+ ChangeFontAttributes(WebCore::FontAttributeChanges changes) > #endif > > PreferencesDidChange(struct WebKit::WebPreferencesStore store) >diff --git a/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm b/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm >index 8d20d2eff06bc46b0cfc99159c8e989f5db3f387..8e2002d4e03805195664963313713c09f3a29727 100644 >--- a/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm >+++ b/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm >@@ -1115,6 +1115,13 @@ void WebPage::dataDetectorsDidHideUI(PageOverlay::PageOverlayID overlayID) > } > } > >+void WebPage::changeFontAttributes(WebCore::FontAttributeChanges&& changes) >+{ >+ auto& frame = m_page->focusController().focusedOrMainFrame(); >+ if (frame.selection().selection().isContentEditable()) >+ frame.editor().applyStyleToSelection(changes.createEditingStyle(), EditActionChangeAttributes, Editor::ColorFilterMode::InvertColor); >+} >+ > void WebPage::changeFont(WebCore::FontChanges&& changes) > { > auto& frame = m_page->focusController().focusedOrMainFrame(); >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index ce56f341ff9938235783d49f42c629ab748f0711..60bb9f274213f9fef0b88ab70a23dfe6a347f9e8 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,54 @@ >+2018-09-06 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ 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:]): >+ > 2018-09-05 Wenson Hsieh <wenson_hsieh@apple.com> > > [macOS] Cannot change font size at selection until font panel is shown >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index 236777a8358ece327611b7ce5b652f92cc1c0379..9518152bd0a3d0c9ede20d4352c018cb79d1a10a 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -794,6 +794,7 @@ > F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; }; > F43E3BBF20DADA1E00A4E7ED /* WKScrollViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */; }; > F43E3BC120DADBC500A4E7ED /* fixed-nav-bar.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */; }; >+ F442851D2140DF2900CCDA22 /* NSFontPanelTesting.mm in Sources */ = {isa = PBXBuildFile; fileRef = F442851C2140DF2900CCDA22 /* NSFontPanelTesting.mm */; }; > F4451C761EB8FD890020C5DA /* two-paragraph-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4451C751EB8FD7C0020C5DA /* two-paragraph-contenteditable.html */; }; > F44C79FF20F9E8710014478C /* ParserYieldTokenTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C79FE20F9E8710014478C /* ParserYieldTokenTests.mm */; }; > F44C7A0020F9EEBF0014478C /* ParserYieldTokenPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = F44C79FB20F9E50C0014478C /* ParserYieldTokenPlugIn.mm */; }; >@@ -2035,6 +2036,8 @@ > F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKitCocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; }; > F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKScrollViewTests.mm; sourceTree = "<group>"; }; > F43E3BC020DADB8000A4E7ED /* fixed-nav-bar.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "fixed-nav-bar.html"; sourceTree = "<group>"; }; >+ F442851B2140DF2900CCDA22 /* NSFontPanelTesting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFontPanelTesting.h; sourceTree = "<group>"; }; >+ F442851C2140DF2900CCDA22 /* NSFontPanelTesting.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSFontPanelTesting.mm; sourceTree = "<group>"; }; > F4451C751EB8FD7C0020C5DA /* two-paragraph-contenteditable.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "two-paragraph-contenteditable.html"; sourceTree = "<group>"; }; > F44C79FB20F9E50C0014478C /* ParserYieldTokenPlugIn.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ParserYieldTokenPlugIn.mm; sourceTree = "<group>"; }; > F44C79FD20F9E8710014478C /* ParserYieldTokenTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParserYieldTokenTests.h; sourceTree = "<group>"; }; >@@ -3161,6 +3164,8 @@ > F4E0A2B72122847400AF7C7F /* TestFilePromiseReceiver.mm */, > C08587BE13FE956C001EF4E5 /* WebKitAgnosticTest.h */, > C08587BD13FE956C001EF4E5 /* WebKitAgnosticTest.mm */, >+ F442851B2140DF2900CCDA22 /* NSFontPanelTesting.h */, >+ F442851C2140DF2900CCDA22 /* NSFontPanelTesting.mm */, > ); > path = mac; > sourceTree = "<group>"; >@@ -3913,6 +3918,7 @@ > 4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */, > 41882F0321010C0D002FF288 /* ProcessPreWarming.mm in Sources */, > 518C1153205B0504001FF4AE /* ProcessSwapOnNavigation.mm in Sources */, >+ F442851D2140DF2900CCDA22 /* NSFontPanelTesting.mm in Sources */, > 7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */, > 7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */, > 7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */, >diff --git a/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm b/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm >index d15a0c35a698d1d60174737eac6293cd9c83ccd8..22bf87c6abe5b0cc03319066bb01b0ce10a718cf 100644 >--- a/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm >+++ b/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm >@@ -27,6 +27,8 @@ > > #if PLATFORM(MAC) && WK_API_ENABLED > >+#import "AppKitSPI.h" >+#import "NSFontPanelTesting.h" > #import "PlatformUtilities.h" > #import "TestWKWebView.h" > #import <WebKit/WKWebViewPrivate.h> >@@ -178,6 +180,74 @@ TEST(FontManagerTests, ChangeFontWithPanel) > EXPECT_EQ(largeItalicLightAvenirFont, fontManager.selectedFont); > } > >+TEST(FontManagerTests, ChangeAttributesWithFontEffectsBox) >+{ >+ NSFontManager *fontManager = [NSFontManager sharedFontManager]; >+ auto webView = webViewForFontManagerTesting(fontManager); >+ >+ NSFontPanel *fontPanel = [fontManager fontPanel:YES]; >+ [fontPanel setIsVisible:YES]; >+ >+ auto textDecorationsAroundSelection = [webView] { >+ NSString *decorationsAtStart = [webView stylePropertyAtSelectionStart:@"-webkit-text-decorations-in-effect"]; >+ NSString *decorationsAtEnd = [webView stylePropertyAtSelectionEnd:@"-webkit-text-decorations-in-effect"]; >+ if ([decorationsAtStart isEqualToString:decorationsAtEnd] || decorationsAtStart == decorationsAtEnd) >+ return decorationsAtStart; >+ return [NSString stringWithFormat:@"(%@, %@)", decorationsAtStart, decorationsAtEnd]; >+ }; >+ >+ auto textShadowAroundSelection = [webView] { >+ NSString *shadowAtStart = [webView stylePropertyAtSelectionStart:@"text-shadow"]; >+ NSString *shadowAtEnd = [webView stylePropertyAtSelectionEnd:@"text-shadow"]; >+ if ([shadowAtStart isEqualToString:shadowAtEnd] || shadowAtStart == shadowAtEnd) >+ return shadowAtStart; >+ return [NSString stringWithFormat:@"(%@, %@)", shadowAtStart, shadowAtEnd]; >+ }; >+ >+ [webView selectWord:nil]; >+ [fontPanel chooseUnderlineMenuItemWithTitle:@"single"]; >+ EXPECT_WK_STREQ("foo", [webView selectedText]); >+ EXPECT_WK_STREQ("underline", textDecorationsAroundSelection()); >+ >+ [fontPanel chooseUnderlineMenuItemWithTitle:@"none"]; >+ EXPECT_WK_STREQ("none", textDecorationsAroundSelection()); >+ >+ [webView selectNextWord]; >+ [fontPanel chooseStrikeThroughMenuItemWithTitle:@"single"]; >+ EXPECT_WK_STREQ("bar", [webView selectedText]); >+ EXPECT_WK_STREQ("line-through", textDecorationsAroundSelection()); >+ >+ [fontPanel chooseStrikeThroughMenuItemWithTitle:@"none"]; >+ EXPECT_WK_STREQ("none", textDecorationsAroundSelection()); >+ >+ [webView selectNextWord]; >+ fontPanel.shadowBlur = 8; >+ fontPanel.shadowOpacity = 1; >+ [fontPanel toggleShadow]; >+ EXPECT_WK_STREQ("baz", [webView selectedText]); >+ EXPECT_WK_STREQ("rgb(0, 0, 0) 0px 1px 8px", textShadowAroundSelection()); >+ >+ [fontPanel toggleShadow]; >+ EXPECT_WK_STREQ("none", textShadowAroundSelection()); >+ >+ // Now combine all three attributes together. >+ [webView selectAll:nil]; >+ fontPanel.shadowBlur = 5; >+ fontPanel.shadowOpacity = 0.2; >+ [fontPanel toggleShadow]; >+ [fontPanel chooseUnderlineMenuItemWithTitle:@"single"]; >+ [fontPanel chooseStrikeThroughMenuItemWithTitle:@"single"]; >+ EXPECT_WK_STREQ("foo bar baz", [webView selectedText]); >+ EXPECT_WK_STREQ("rgba(0, 0, 0, 0.2) 0px 1px 5px", textShadowAroundSelection()); >+ EXPECT_WK_STREQ("underline line-through", textDecorationsAroundSelection()); >+ >+ [fontPanel toggleShadow]; >+ [fontPanel chooseUnderlineMenuItemWithTitle:@"none"]; >+ [fontPanel chooseStrikeThroughMenuItemWithTitle:@"none"]; >+ EXPECT_WK_STREQ("none", textShadowAroundSelection()); >+ EXPECT_WK_STREQ("none", textDecorationsAroundSelection()); >+} >+ > } // namespace TestWebKitAPI > > #endif // PLATFORM(MAC) && WK_API_ENABLED >diff --git a/Tools/TestWebKitAPI/cocoa/TestWKWebView.h b/Tools/TestWebKitAPI/cocoa/TestWKWebView.h >index 613dfae8aa1dff764c773cfc5014e5c3e1638166..5f169d9b4d74da5713e3ea3c8185a2a72a8ad591 100644 >--- a/Tools/TestWebKitAPI/cocoa/TestWKWebView.h >+++ b/Tools/TestWebKitAPI/cocoa/TestWKWebView.h >@@ -37,6 +37,7 @@ > @interface WKWebView (AdditionalDeclarations) > #if PLATFORM(MAC) > - (void)paste:(id)sender; >+- (void)changeAttributes:(id)sender; > #endif > @end > >diff --git a/Tools/TestWebKitAPI/mac/NSFontPanelTesting.h b/Tools/TestWebKitAPI/mac/NSFontPanelTesting.h >new file mode 100644 >index 0000000000000000000000000000000000000000..0b04d48f3e985fa221da61c69da1beb286141d9b >--- /dev/null >+++ b/Tools/TestWebKitAPI/mac/NSFontPanelTesting.h >@@ -0,0 +1,43 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if PLATFORM(MAC) && WK_API_ENABLED >+ >+#import <AppKit/AppKit.h> >+ >+@interface NSFontPanel (TestWebKitAPI) >+ >+@property (nonatomic) double shadowOpacity; >+@property (nonatomic) double shadowBlur; >+ >+- (void)toggleShadow; >+- (void)chooseUnderlineMenuItemWithTitle:(NSString *)itemTitle; >+- (void)chooseStrikeThroughMenuItemWithTitle:(NSString *)itemTitle; >+ >+@end >+ >+#endif >diff --git a/Tools/TestWebKitAPI/mac/NSFontPanelTesting.mm b/Tools/TestWebKitAPI/mac/NSFontPanelTesting.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..a1c1abb10213188903149fe8ea6b0cf576fdff12 >--- /dev/null >+++ b/Tools/TestWebKitAPI/mac/NSFontPanelTesting.mm >@@ -0,0 +1,148 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "NSFontPanelTesting.h" >+ >+#if PLATFORM(MAC) && WK_API_ENABLED >+ >+#import <objc/runtime.h> >+ >+@interface NSBox (NSFontEffectsBox) >+// Invoked after a font effect (e.g. single strike-through) is chosen. >+- (void)_openEffectsButton:(id)sender; >+@end >+ >+static NSView *findSubviewOfClass(NSView *view, Class targetClass) >+{ >+ if ([view isKindOfClass:targetClass]) >+ return view; >+ >+ for (NSView *subview in view.subviews) { >+ if (NSView *targetView = findSubviewOfClass(subview, targetClass)) >+ return targetView; >+ } >+ return nil; >+} >+ >+static NSMenuItem *findMenuItemWithTitle(NSPopUpButton *button, NSString *title) >+{ >+ for (NSMenuItem *item in button.itemArray) { >+ if ([item.title.lowercaseString isEqualToString:title.lowercaseString]) >+ return item; >+ } >+ return nil; >+} >+ >+@implementation NSFontPanel (TestWebKitAPI) >+ >+- (NSBox *)fontEffectsBox >+{ >+ void* result = nullptr; >+ object_getInstanceVariable(self, "_fontEffectsBox", &result); >+ return static_cast<NSBox *>(result); >+} >+ >+- (void)chooseUnderlineMenuItemWithTitle:(NSString *)itemTitle >+{ >+ NSPopUpButton *button = (NSPopUpButton *)[self _toolbarItemWithIdentifier:@"NSFontPanelUnderlineToolbarItem"].view; >+ [button selectItem:findMenuItemWithTitle(button, itemTitle)]; >+ [self.fontEffectsBox _openEffectsButton:button]; >+ [self _didChangeAttributes]; >+} >+ >+- (void)chooseStrikeThroughMenuItemWithTitle:(NSString *)itemTitle >+{ >+ NSPopUpButton *button = (NSPopUpButton *)[self _toolbarItemWithIdentifier:@"NSFontPanelStrikethroughToolbarItem"].view; >+ [button selectItem:findMenuItemWithTitle(button, itemTitle)]; >+ [self.fontEffectsBox _openEffectsButton:button]; >+ [self _didChangeAttributes]; >+} >+ >+- (void)_didChangeAttributes >+{ >+ NSFontManager *fontManager = NSFontManager.sharedFontManager; >+ if (self == [fontManager fontPanel:NO]) >+ [fontManager.target changeAttributes:self.fontEffectsBox]; >+} >+ >+- (NSSlider *)shadowBlurSlider >+{ >+ return (NSSlider *)findSubviewOfClass([self _toolbarItemWithIdentifier:@"NSFontPanelShadowBlurToolbarItem"].view, NSSlider.class); >+} >+ >+- (NSSlider *)shadowOpacitySlider >+{ >+ return (NSSlider *)findSubviewOfClass([self _toolbarItemWithIdentifier:@"NSFontPanelShadowOpacityToolbarItem"].view, NSSlider.class); >+} >+ >+- (NSButton *)shadowToggleButton >+{ >+ return (NSButton *)[self _toolbarItemWithIdentifier:@"NSFontPanelShadowToggleToolbarItem"].view; >+} >+ >+- (void)toggleShadow >+{ >+ NSButton *shadowToggleButton = self.shadowToggleButton; >+ shadowToggleButton.state = shadowToggleButton.state == NSControlStateValueOff ? NSControlStateValueOn : NSControlStateValueOff; >+ [self _didChangeAttributes]; >+} >+ >+- (double)shadowOpacity >+{ >+ return self.shadowOpacitySlider.doubleValue; >+} >+ >+- (void)setShadowOpacity:(double)shadowOpacity >+{ >+ self.shadowOpacitySlider.doubleValue = shadowOpacity; >+ if (self.shadowToggleButton.state == NSControlStateValueOn) >+ [self _didChangeAttributes]; >+} >+ >+- (double)shadowBlur >+{ >+ return self.shadowBlurSlider.doubleValue; >+} >+ >+- (void)setShadowBlur:(double)shadowBlur >+{ >+ self.shadowBlurSlider.doubleValue = shadowBlur; >+ if (self.shadowToggleButton.state == NSControlStateValueOn) >+ [self _didChangeAttributes]; >+} >+ >+- (NSToolbarItem *)_toolbarItemWithIdentifier:(NSString *)itemIdentifier >+{ >+ for (NSToolbarItem *item in self.toolbar.items) { >+ if ([item.itemIdentifier isEqualToString:itemIdentifier]) >+ return item; >+ } >+ return nil; >+} >+ >+@end >+ >+#endif // PLATFORM(MAC) && WK_API_ENABLED
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189356
:
349049
|
349056
|
349064