WebKit Bugzilla
Attachment 348892 Details for
Bug 189295
: [macOS] Cannot change font size at selection until font panel is shown
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
bug-189295-20180904213356.patch (text/plain), 63.77 KB, created by
Wenson Hsieh
on 2018-09-04 21:33:57 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-09-04 21:33:57 PDT
Size:
63.77 KB
patch
obsolete
>Subversion Revision: 235579 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 7de7e235a48bda373f93e195782d7c7829e12dbb..4e44a2989c262456190904e37803dbb51fda141b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,26 @@ >+2018-09-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [macOS] Cannot change font size at selection until font panel is shown >+ https://bugs.webkit.org/show_bug.cgi?id=189295 >+ <rdar://problem/35593389> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * SourcesCocoa.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * editing/Editor.h: >+ * editing/FontAttributeChanges.h: Added. >+ (WebCore::FontChanges::encode const): >+ (WebCore::FontChanges::decode): >+ * editing/mac/EditorMac.mm: >+ (WebCore::Editor::applyFontStyles): >+ * platform/mac/WebCoreNSFontManagerExtras.h: Added. >+ * platform/mac/WebCoreNSFontManagerExtras.mm: Added. >+ (WebCore::firstFontConversionSpecimen): >+ (WebCore::secondFontConversionSpecimen): >+ (WebCore::computedFontChanges): >+ (WebCore::computedFontAttributeChanges): >+ > 2018-08-31 Youenn Fablet <youenn@apple.com> > > Move stats gathering out of LibWebRTCMediaEndpoint >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index fc03a5651c260cacf00093a99c5a2ac8f0c75343..3200ca92dc96f2b5faf74792a8ab561a1f08b132 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,33 @@ >+2018-09-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [macOS] Cannot change font size at selection until font panel is shown >+ https://bugs.webkit.org/show_bug.cgi?id=189295 >+ <rdar://problem/35593389> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Scripts/webkit/messages.py: >+ * UIProcess/API/Cocoa/WKWebView.mm: >+ (-[WKWebView changeFont:]): >+ * UIProcess/API/mac/WKView.mm: >+ (-[WKView changeFont:]): >+ * UIProcess/Cocoa/WebViewImpl.h: >+ * UIProcess/Cocoa/WebViewImpl.mm: >+ (WebKit::WebViewImpl::changeFontFromFontManager): >+ (WebKit::WebViewImpl::changeFontFromFontPanel): Deleted. >+ * UIProcess/WebPageProxy.h: >+ * UIProcess/mac/WebPageProxyMac.mm: >+ (WebKit::WebPageProxy::changeFont): >+ (WebKit::WebPageProxy::setFont): Deleted. >+ * WebKit.xcodeproj/project.pbxproj: >+ * WebProcess/WebPage/WebPage.h: >+ * WebProcess/WebPage/WebPage.messages.in: >+ * WebProcess/WebPage/mac/WebPageMac.mm: >+ (WebKit::nameAndSizeOfFont): >+ (WebKit::WebPage::fontAtSelection): >+ (WebKit::WebPage::changeFont): >+ (WebKit::WebPage::setFont): Deleted. >+ > 2018-08-31 John Wilander <wilander@apple.com> > > Storage Access API: Maintain access through same-site navigations >diff --git a/Source/WebKitLegacy/mac/ChangeLog b/Source/WebKitLegacy/mac/ChangeLog >index 9b1d5790768eaa0aad71861cd65f77d4e482a285..87e0213229623bfa1ffc9bcf4126eaca7a602a89 100644 >--- a/Source/WebKitLegacy/mac/ChangeLog >+++ b/Source/WebKitLegacy/mac/ChangeLog >@@ -1,3 +1,19 @@ >+2018-09-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [macOS] Cannot change font size at selection until font panel is shown >+ https://bugs.webkit.org/show_bug.cgi?id=189295 >+ <rdar://problem/35593389> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * WebView/WebHTMLView.mm: >+ (-[WebHTMLView _shadowAsString:]): >+ (-[WebHTMLView _shadowAsStringWithOffset:color:blurRadius:]): >+ (-[WebHTMLView _addFontChanges:toStyle:]): >+ (-[WebHTMLView _styleFromFontManagerOperation]): >+ (-[WebHTMLView _styleForAttributeChange:]): >+ (-[WebHTMLView _addToStyle:fontA:fontB:]): Deleted. >+ > 2018-08-31 Chris Dumez <cdumez@apple.com> > > Assertion hit in ~CompletionHandler() from ~WebFrame() >diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt >index 498208119f26f8a5b0f967f4a912a84797ec9497..1237151821503b2d9608266c21b59417b509ef5e 100644 >--- a/Source/WebCore/SourcesCocoa.txt >+++ b/Source/WebCore/SourcesCocoa.txt >@@ -462,6 +462,7 @@ platform/mac/VideoFullscreenInterfaceMac.mm > platform/mac/WebCoreFullScreenPlaceholderView.mm > platform/mac/WebCoreFullScreenWarningView.mm > platform/mac/WebCoreFullScreenWindow.mm >+platform/mac/WebCoreNSFontManagerExtras.mm > platform/mac/WebCoreNSURLExtras.mm > platform/mac/WebCoreObjCExtras.mm > platform/mac/WebGLBlacklist.mm >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 71cec8cb1140f538e914b05badac66dd754ecc5e..cf3333069c4c8a193ae04913e18df2a5e8531c2a 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -4823,6 +4823,8 @@ > F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; }; > F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; }; > F4BFB9861E1DDF9B00862C24 /* EditingHistoryUtil.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */; }; >+ F4E57EDC213F3F5F004EA98E /* FontAttributeChanges.h in Headers */ = {isa = PBXBuildFile; fileRef = F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ F4E57EE1213F434A004EA98E /* WebCoreNSFontManagerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; }; > F50664F8157F52DC00AC226F /* FormController.h in Headers */ = {isa = PBXBuildFile; fileRef = F50664F6157F52DC00AC226F /* FormController.h */; }; > F513A3EA15FF4841001526DB /* ValidationMessageClient.h in Headers */ = {isa = PBXBuildFile; fileRef = F513A3E915FF4841001526DB /* ValidationMessageClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; > F544F78915CFB2A800AF33A8 /* PlatformLocale.h in Headers */ = {isa = PBXBuildFile; fileRef = F544F78715CFB2A800AF33A8 /* PlatformLocale.h */; }; >@@ -14486,6 +14488,9 @@ > F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; }; > F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; }; > F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; }; >+ F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; }; >+ F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebCoreNSFontManagerExtras.h; sourceTree = "<group>"; }; >+ F4E57EE0213F434A004EA98E /* WebCoreNSFontManagerExtras.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreNSFontManagerExtras.mm; sourceTree = "<group>"; }; > F50664F5157F52DC00AC226F /* FormController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormController.cpp; sourceTree = "<group>"; }; > F50664F6157F52DC00AC226F /* FormController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormController.h; sourceTree = "<group>"; }; > F513A3E915FF4841001526DB /* ValidationMessageClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ValidationMessageClient.h; sourceTree = "<group>"; }; >@@ -19136,6 +19141,8 @@ > CDC69DD51632026C007C38DF /* WebCoreFullScreenWarningView.mm */, > CD127DEA14F3097900E84779 /* WebCoreFullScreenWindow.h */, > CD127DEB14F3097900E84779 /* WebCoreFullScreenWindow.mm */, >+ F4E57EDF213F434A004EA98E /* WebCoreNSFontManagerExtras.h */, >+ F4E57EE0213F434A004EA98E /* WebCoreNSFontManagerExtras.mm */, > C5B4C24B1509236C00A6EF37 /* WebCoreNSURLExtras.h */, > C5B4C24C1509236C00A6EF37 /* WebCoreNSURLExtras.mm */, > DD05FE0B0B8BA3C6009ACDFE /* WebCoreObjCExtras.h */, >@@ -20096,6 +20103,7 @@ > 4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */, > 93FDAFC90B11307400E2746F /* EditorInsertAction.h */, > 372C00D8129619F8005C9575 /* FindOptions.h */, >+ F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */, > D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */, > D05CED280A40BB2C00C5AF38 /* FormatBlockCommand.h */, > 93309DBE099E64910056E581 /* FrameSelection.cpp */, >@@ -27882,6 +27890,7 @@ > B6D9D23514EABD260090D75E /* FocusEvent.h in Headers */, > B2C3DA650D006CD600EF6F26 /* Font.h in Headers */, > 1AC2D89D1B1E291F00D52E87 /* FontAntialiasingStateSaver.h in Headers */, >+ F4E57EDC213F3F5F004EA98E /* FontAttributeChanges.h in Headers */, > BCB92D4F1293550B00C8387F /* FontBaseline.h in Headers */, > B2C3DA630D006CD600EF6F26 /* FontCache.h in Headers */, > C2458E631FE897B000594759 /* FontCacheCoreText.h in Headers */, >@@ -30790,6 +30799,7 @@ > 93F199BB08245E59001E9ABC /* WebCoreKeyboardUIMode.h in Headers */, > 3140379B124BEA7F00AF40E4 /* WebCoreMotionManager.h in Headers */, > CDC979F51C498C0900DB50D4 /* WebCoreNSErrorExtras.h in Headers */, >+ F4E57EE1213F434A004EA98E /* WebCoreNSFontManagerExtras.h in Headers */, > C5B4C24D1509236C00A6EF37 /* WebCoreNSURLExtras.h in Headers */, > CD225C0C1C46FBF400140761 /* WebCoreNSURLSession.h in Headers */, > DD05FE0D0B8BA3C6009ACDFE /* WebCoreObjCExtras.h in Headers */, >@@ -31412,6 +31422,7 @@ > 5CDD83641E4325A000621E92 /* LibWebRTCDataChannelHandler.cpp in Sources */, > 417612AF1E3A994000C3D81D /* LibWebRTCMediaEndpoint.cpp in Sources */, > 417612B11E3A994000C3D81D /* LibWebRTCPeerConnectionBackend.cpp in Sources */, >+ 41D28D0D2139E05800F4206F /* LibWebRTCStatsCollector.cpp in Sources */, > 9759E93E14EF1CF80026A2DD /* LoadableTextTrack.cpp in Sources */, > 445775EA2047303C008DCE5D /* LocalDefaultSystemAppearance.mm in Sources */, > FABE72FE1059C21100D999DD /* MathMLNames.cpp in Sources */, >@@ -31779,7 +31790,6 @@ > DECA7E651F9EBD8300E3B661 /* UnifiedSource234.cpp in Sources */, > DECA7E661F9EBD8300E3B661 /* UnifiedSource235.cpp in Sources */, > DECA7E671F9EBD8300E3B661 /* UnifiedSource236.cpp in Sources */, >- 41D28D0D2139E05800F4206F /* LibWebRTCStatsCollector.cpp in Sources */, > DECA7E681F9EBD8300E3B661 /* UnifiedSource237.cpp in Sources */, > DECA7E691F9EBD8300E3B661 /* UnifiedSource238.cpp in Sources */, > DECA7E6A1F9EBD8300E3B661 /* UnifiedSource239.cpp in Sources */, >diff --git a/Source/WebCore/editing/Editor.h b/Source/WebCore/editing/Editor.h >index 3d63ce14511745b94904df98039dff8e61d7c784..7b9a7cc6f30f26c03169a417055c211c2370c3ae 100644 >--- a/Source/WebCore/editing/Editor.h >+++ b/Source/WebCore/editing/Editor.h >@@ -474,7 +474,7 @@ public: > WEBCORE_EXPORT void readSelectionFromPasteboard(const String& pasteboardName, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote); > WEBCORE_EXPORT void replaceNodeFromPasteboard(Node*, const String& pasteboardName); > WEBCORE_EXPORT RefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName); >- WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits); >+ WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, std::optional<double>&& fontSize, std::optional<bool>&& bold, std::optional<bool>&& italic); > #endif // !PLATFORM(IOS) > WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote); > #endif >diff --git a/Source/WebCore/editing/FontAttributeChanges.h b/Source/WebCore/editing/FontAttributeChanges.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d06a73cafed10950ae7b550b28448638de45d88d >--- /dev/null >+++ b/Source/WebCore/editing/FontAttributeChanges.h >@@ -0,0 +1,95 @@ >+/* >+ * 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 >+ >+#include "Color.h" >+#include "RenderStyleConstants.h" >+#include <wtf/Optional.h> >+ >+namespace WebCore { >+ >+struct FontChanges { >+ template<class Encoder> void encode(Encoder&) const; >+ template<class Decoder> static bool decode(Decoder&, FontChanges&); >+ >+ String fontName; >+ String fontFamily; >+ std::optional<double> fontSize; >+ std::optional<double> fontSizeDelta; >+ std::optional<bool> bold; >+ std::optional<bool> italic; >+}; >+ >+struct FontShadow { >+ Color color; >+ double width { 0 }; >+ double height { 0 }; >+ double blurRadius { 0 }; >+}; >+ >+struct FontAttributeChanges { >+ VerticalAlign verticalAlign; >+ std::optional<Color> backgroundColor; >+ std::optional<Color> foregroundColor; >+ std::optional<FontShadow> shadow; >+ std::optional<bool> strikeThrough; >+ std::optional<bool> underline; >+ FontChanges fontChanges; >+}; >+ >+template<class Encoder> >+void FontChanges::encode(Encoder& encoder) const >+{ >+ ASSERT(!fontSize || !fontSizeDelta); >+ encoder << fontName << fontFamily << fontSize << fontSizeDelta << bold << italic; >+} >+ >+template<class Decoder> >+bool FontChanges::decode(Decoder& decoder, FontChanges& changes) >+{ >+ if (!decoder.decode(changes.fontName)) >+ return false; >+ >+ if (!decoder.decode(changes.fontFamily)) >+ return false; >+ >+ if (!decoder.decode(changes.fontSize)) >+ return false; >+ >+ if (!decoder.decode(changes.fontSizeDelta)) >+ return false; >+ >+ if (!decoder.decode(changes.bold)) >+ return false; >+ >+ if (!decoder.decode(changes.italic)) >+ return false; >+ >+ ASSERT(!changes.fontSize || !changes.fontSizeDelta); >+ return true; >+} >+ >+} // namespace WebCore >diff --git a/Source/WebCore/editing/mac/EditorMac.mm b/Source/WebCore/editing/mac/EditorMac.mm >index cf289bf70e400036767808d1a1699f68237aac00..cce3b2a4e6dd79d57aa6f0b97b88c8a398aab42f 100644 >--- a/Source/WebCore/editing/mac/EditorMac.mm >+++ b/Source/WebCore/editing/mac/EditorMac.mm >@@ -289,14 +289,18 @@ RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard > return WTFMove(reader.fragment); > } > >-void Editor::applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits) >+void Editor::applyFontStyles(const String& fontFamily, std::optional<double>&& fontSize, std::optional<bool>&& bold, std::optional<bool>&& italic) > { > auto& cssValuePool = CSSValuePool::singleton(); >- Ref<MutableStyleProperties> style = MutableStyleProperties::create(); >- style->setProperty(CSSPropertyFontFamily, cssValuePool.createFontFamilyValue(fontFamily)); >- style->setProperty(CSSPropertyFontStyle, (fontTraits & NSFontItalicTrait) ? CSSValueItalic : CSSValueNormal); >- style->setProperty(CSSPropertyFontWeight, (fontTraits & NSFontBoldTrait) ? CSSValueBold : CSSValueNormal); >- style->setProperty(CSSPropertyFontSize, cssValuePool.createValue(fontSize, CSSPrimitiveValue::CSS_PX)); >+ auto style = MutableStyleProperties::create(); >+ if (!!fontFamily) >+ style->setProperty(CSSPropertyFontFamily, cssValuePool.createFontFamilyValue(fontFamily)); >+ if (italic.has_value()) >+ style->setProperty(CSSPropertyFontStyle, *italic ? CSSValueItalic : CSSValueNormal); >+ if (bold.has_value()) >+ style->setProperty(CSSPropertyFontWeight, *bold ? CSSValueBold : CSSValueNormal); >+ if (fontSize.has_value()) >+ style->setProperty(CSSPropertyFontSize, cssValuePool.createValue(*fontSize, CSSPrimitiveValue::CSS_PX)); > applyStyleToSelection(style.ptr(), EditActionSetFont); > } > >diff --git a/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.h b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.h >new file mode 100644 >index 0000000000000000000000000000000000000000..a565c5e4732ca4ebb434c1ebcedc0fd34e106137 >--- /dev/null >+++ b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.h >@@ -0,0 +1,42 @@ >+/* >+ * 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) >+ >+OBJC_CLASS NSFontManager; >+ >+namespace WebCore { >+ >+struct FontAttributeChanges; >+struct FontChanges; >+ >+WEBCORE_EXPORT FontChanges computedFontChanges(NSFontManager *); >+WEBCORE_EXPORT FontAttributeChanges computedFontAttributeChanges(NSFontManager *, id attributeConverter); >+ >+} // namespace WebCore >+ >+#endif >diff --git a/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..1293b886c95b9c7adb83d15fa2e6350a5b950e06 >--- /dev/null >+++ b/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm >@@ -0,0 +1,167 @@ >+/* >+ * 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. >+ */ >+ >+#import "config.h" >+#import "WebCoreNSFontManagerExtras.h" >+ >+#if PLATFORM(MAC) >+ >+#import "ColorMac.h" >+#import "FontAttributeChanges.h" >+#import <AppKit/NSFontManager.h> >+ >+namespace WebCore { >+ >+static NSFont *firstFontConversionSpecimen(NSFontManager *fontManager) >+{ >+ const double standardWeight = 5.; >+ return [fontManager fontWithFamily:@"Helvetica" traits:0 weight:standardWeight size:10.]; >+} >+ >+static NSFont *secondFontConversionSpecimen(NSFontManager *fontManager) >+{ >+ const double standardBoldWeight = 9.; >+ return [fontManager fontWithFamily:@"Times" traits:NSFontItalicTrait weight:standardBoldWeight size:12.]; >+} >+ >+static FontChanges computedFontChanges(NSFontManager *fontManager, NSFont *originalFontA, NSFont *convertedFontA, NSFont *convertedFontB) >+{ >+ if (!convertedFontA || !convertedFontB) >+ return { }; >+ >+ // Since there's still no way to directly ask NSFontManager what style change it's going >+ // to do we instead pass two "specimen" fonts to it and let it change them. We then deduce >+ // what style change it was doing by looking at what happened to each of the two fonts. >+ // So if it was making the text bold, both fonts will be bold after the fact. >+ // This logic was originally from WebHTMLView, and is now in WebCore so that it is shared >+ // between WebKitLegacy and WebKit. >+ const double minimumBoldWeight = 7.; >+ >+ NSString *convertedFamilyNameA = convertedFontA.familyName; >+ NSString *convertedFamilyNameB = convertedFontB.familyName; >+ >+ auto convertedPointSizeA = convertedFontA.pointSize; >+ auto convertedPointSizeB = convertedFontB.pointSize; >+ >+ auto convertedFontWeightA = [fontManager weightOfFont:convertedFontA]; >+ auto convertedFontWeightB = [fontManager weightOfFont:convertedFontB]; >+ >+ bool convertedFontAIsItalic = !!([fontManager traitsOfFont:convertedFontA] & NSItalicFontMask); >+ bool convertedFontBIsItalic = !!([fontManager traitsOfFont:convertedFontB] & NSItalicFontMask); >+ >+ bool convertedFontAIsBold = convertedFontWeightA > minimumBoldWeight; >+ >+ FontChanges changes; >+ if ([convertedFamilyNameA isEqualToString:convertedFamilyNameB]) { >+ changes.fontName = convertedFontA.fontName; >+ changes.fontFamily = convertedFamilyNameA; >+ } >+ >+ int originalPointSizeA = originalFontA.pointSize; >+ if (convertedPointSizeA == convertedPointSizeB) >+ changes.fontSize = convertedPointSizeA; >+ else if (convertedPointSizeA < originalPointSizeA) >+ changes.fontSizeDelta = -1; >+ else if (convertedPointSizeA > originalPointSizeA) >+ changes.fontSizeDelta = 1; >+ >+ if (convertedFontWeightA == convertedFontWeightB) >+ changes.bold = convertedFontAIsBold; >+ >+ if (convertedFontAIsItalic == convertedFontBIsItalic) >+ changes.italic = convertedFontAIsItalic; >+ >+ return changes; >+} >+ >+FontChanges computedFontChanges(NSFontManager *fontManager) >+{ >+ NSFont *originalFontA = firstFontConversionSpecimen(fontManager); >+ return computedFontChanges(fontManager, originalFontA, [fontManager convertFont:originalFontA], [fontManager convertFont:secondFontConversionSpecimen(fontManager)]); >+} >+ >+FontAttributeChanges computedFontAttributeChanges(NSFontManager *fontManager, id attributeConverter) >+{ >+ FontAttributeChanges changes; >+ >+ auto shadow = adoptNS([[NSShadow alloc] init]); >+ [shadow setShadowOffset:NSMakeSize(1, 1)]; >+ >+ NSFont *originalFontA = firstFontConversionSpecimen(fontManager); >+ NSDictionary *originalAttributesA = @{ NSFontAttributeName : originalFontA }; >+ NSDictionary *originalAttributesB = @{ >+ NSBackgroundColorAttributeName : NSColor.blackColor, >+ NSFontAttributeName : secondFontConversionSpecimen(fontManager), >+ NSForegroundColorAttributeName : NSColor.whiteColor, >+ NSShadowAttributeName : shadow.get(), >+ NSStrikethroughStyleAttributeName : @(NSUnderlineStyleSingle), >+ NSSuperscriptAttributeName : @1, >+ NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle) >+ }; >+ >+ NSDictionary *convertedAttributesA = [attributeConverter convertAttributes:originalAttributesA]; >+ NSDictionary *convertedAttributesB = [attributeConverter convertAttributes:originalAttributesB]; >+ >+ NSColor *convertedBackgroundColorA = [convertedAttributesA objectForKey:NSBackgroundColorAttributeName]; >+ if (convertedBackgroundColorA == [convertedAttributesB objectForKey:NSBackgroundColorAttributeName]) >+ changes.backgroundColor = colorFromNSColor(convertedBackgroundColorA); >+ >+ changes.fontChanges = computedFontChanges(fontManager, originalFontA, [convertedAttributesA objectForKey:NSFontAttributeName], [convertedAttributesB objectForKey:NSFontAttributeName]); >+ >+ NSColor *convertedForegroundColorA = [convertedAttributesA objectForKey:NSForegroundColorAttributeName]; >+ if (convertedForegroundColorA == [convertedAttributesB objectForKey:NSForegroundColorAttributeName]) >+ changes.backgroundColor = colorFromNSColor(convertedForegroundColorA ?: NSColor.blackColor); >+ >+ NSShadow *convertedShadow = [convertedAttributesA objectForKey:NSShadowAttributeName]; >+ if (convertedShadow) { >+ auto offset = convertedShadow.shadowOffset; >+ changes.shadow = {{ colorFromNSColor(convertedShadow.shadowColor ?: NSColor.blackColor), offset.width, offset.height, convertedShadow.shadowBlurRadius }}; >+ } else if (![convertedAttributesB objectForKey:NSShadowAttributeName]) >+ changes.shadow = {{ }}; >+ >+ int convertedSuperscriptA = [[convertedAttributesA objectForKey:NSSuperscriptAttributeName] intValue]; >+ if (convertedSuperscriptA == [[convertedAttributesB objectForKey:NSSuperscriptAttributeName] intValue]) { >+ if (convertedSuperscriptA > 0) >+ changes.verticalAlign = VerticalAlign::Super; >+ else if (convertedSuperscriptA < 0) >+ changes.verticalAlign = VerticalAlign::Sub; >+ else >+ changes.verticalAlign = VerticalAlign::Baseline; >+ } >+ >+ int convertedStrikeThroughA = [[convertedAttributesA objectForKey:NSStrikethroughStyleAttributeName] intValue]; >+ if (convertedStrikeThroughA == [[convertedAttributesB objectForKey:NSStrikethroughStyleAttributeName] intValue]) >+ changes.strikeThrough = convertedStrikeThroughA != NSUnderlineStyleNone; >+ >+ int convertedUnderlineA = [[convertedAttributesA objectForKey:NSUnderlineStyleAttributeName] intValue]; >+ if (convertedUnderlineA == [[convertedAttributesB objectForKey:NSUnderlineStyleAttributeName] intValue]) >+ changes.underline = convertedUnderlineA != NSUnderlineStyleNone; >+ >+ return changes; >+} >+ >+} // namespace WebCore >+ >+#endif // PLATFORM(MAC) >diff --git a/Source/WebKit/Scripts/webkit/messages.py b/Source/WebKit/Scripts/webkit/messages.py >index 9ac3728401ac361fc8b618184cc78567cbfe61dd..fc5846955d35e1a41bf19aae7d678c8aa12e1541 100644 >--- a/Source/WebKit/Scripts/webkit/messages.py >+++ b/Source/WebKit/Scripts/webkit/messages.py >@@ -381,6 +381,7 @@ def headers_for_type(type): > 'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'], > 'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'], > 'WebCore::ShareDataWithParsedURL': ['<WebCore/ShareData.h>'], >+ 'WebCore::FontChanges': ['<WebCore/FontAttributeChanges.h>'], > 'WebCore::FrameLoadType': ['<WebCore/FrameLoaderTypes.h>'], > 'WebCore::GrammarDetail': ['<WebCore/TextCheckerClient.h>'], > 'WebCore::HasInsecureContent': ['<WebCore/FrameLoaderTypes.h>'], >diff --git a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >index 6fff3a0916766c31376c59f3896c1242cef9bd33..1c2217272a0aa036dcbce59d1fa6ca38810fa882 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm >@@ -3349,7 +3349,7 @@ WEBCORE_COMMAND(yankAndSelect) > > - (void)changeFont:(id)sender > { >- _impl->changeFontFromFontPanel(); >+ _impl->changeFontFromFontManager(); > } > > - (IBAction)startSpeaking:(id)sender >diff --git a/Source/WebKit/UIProcess/API/mac/WKView.mm b/Source/WebKit/UIProcess/API/mac/WKView.mm >index bc5de2b59f2f4c21ae54b60a3433dc84da2d50e4..fe97010375507b7d71119a4dafb0d528a72e4976 100644 >--- a/Source/WebKit/UIProcess/API/mac/WKView.mm >+++ b/Source/WebKit/UIProcess/API/mac/WKView.mm >@@ -316,7 +316,7 @@ WEBCORE_COMMAND(yankAndSelect) > > - (void)changeFont:(id)sender > { >- _data->_impl->changeFontFromFontPanel(); >+ _data->_impl->changeFontFromFontManager(); > } > > /* >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >index e54dd00140584fc1e19148a22e78fc2fe0b09742..c9f3b895c7ba8e77f0da639fad2eb971bf7347dd 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h >@@ -315,7 +315,7 @@ public: > void selectionDidChange(); > void didBecomeEditable(); > void updateFontPanelIfNeeded(); >- void changeFontFromFontPanel(); >+ void changeFontFromFontManager(); > bool validateUserInterfaceItem(id <NSValidatedUserInterfaceItem>); > void setEditableElementIsFocused(bool); > >diff --git a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >index de48e0f8a895eb82c17b4f8753c63e1521688e5a..405ac9ea95bdb4ef5bed9f840b2d94b58c3c5726 100644 >--- a/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >+++ b/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm >@@ -80,6 +80,7 @@ > #import <WebCore/DragItem.h> > #import <WebCore/Editor.h> > #import <WebCore/FileSystem.h> >+#import <WebCore/FontAttributeChanges.h> > #import <WebCore/KeypressCommand.h> > #import <WebCore/LegacyNSPasteboardTypes.h> > #import <WebCore/LoaderNSURLExtras.h> >@@ -92,6 +93,7 @@ > #import <WebCore/WebCoreCALayerExtras.h> > #import <WebCore/WebCoreFullScreenPlaceholderView.h> > #import <WebCore/WebCoreFullScreenWindow.h> >+#import <WebCore/WebCoreNSFontManagerExtras.h> > #import <WebCore/WebPlaybackControlsManager.h> > #import <pal/spi/cg/CoreGraphicsSPI.h> > #import <pal/spi/cocoa/AVKitSPI.h> >@@ -2732,13 +2734,14 @@ void WebViewImpl::updateFontPanelIfNeeded() > } > } > >-void WebViewImpl::changeFontFromFontPanel() >+void WebViewImpl::changeFontFromFontManager() > { >- NSFontManager *fontManager = [NSFontManager sharedFontManager]; >- NSFont *font = [fontManager convertFont:fontManager.selectedFont]; >- if (!font) >+ auto& editorState = m_page->editorState(); >+ if (!editorState.isContentEditable || editorState.selectionIsNone) > return; >- m_page->setFont(font.familyName, font.pointSize, font.fontDescriptor.symbolicTraits); >+ >+ m_page->changeFont(WebCore::computedFontChanges([NSFontManager sharedFontManager])); >+ updateFontPanelIfNeeded(); > } > > static NSMenuItem *menuItem(id <NSValidatedUserInterfaceItem> item) >diff --git a/Source/WebKit/UIProcess/WebPageProxy.h b/Source/WebKit/UIProcess/WebPageProxy.h >index 452814bc25fd2dd009b0dcdb1ebd2ffe5451d18e..0f8202e8981a047d682878baa1989b03bdbe519f 100644 >--- a/Source/WebKit/UIProcess/WebPageProxy.h >+++ b/Source/WebKit/UIProcess/WebPageProxy.h >@@ -184,6 +184,7 @@ struct DataListSuggestionInformation; > struct DictionaryPopupInfo; > struct ExceptionDetails; > struct FileChooserSettings; >+struct FontChanges; > struct GlobalWindowIdentifier; > struct MediaStreamRequest; > struct SecurityOriginData; >@@ -680,7 +681,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 setFont(const String& fontFamily, double fontSize, uint64_t fontTraits); >+ void changeFont(WebCore::FontChanges&&); > void fontAtSelection(WTF::Function<void (const String&, double, bool, CallbackBase::Error)>&&); > > void startWindowDrag(); >diff --git a/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm b/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >index d30afc809394427c2ec10cc8b0651daadbe20a73..1446ae0d12f135bcd2fa25387a0fbbaa979dd33b 100644 >--- a/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >+++ b/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm >@@ -50,6 +50,7 @@ > #import <WebCore/DictationAlternative.h> > #import <WebCore/DictionaryLookup.h> > #import <WebCore/DragItem.h> >+#import <WebCore/FontAttributeChanges.h> > #import <WebCore/GraphicsLayer.h> > #import <WebCore/LegacyNSPasteboardTypes.h> > #import <WebCore/RuntimeApplicationChecks.h> >@@ -626,12 +627,12 @@ bool WebPageProxy::appleMailLinesClampEnabled() > return MacApplication::isAppleMail(); > } > >-void WebPageProxy::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits) >+void WebPageProxy::changeFont(WebCore::FontChanges&& changes) > { > if (!isValid()) > return; > >- process().send(Messages::WebPage::SetFont(fontFamily, fontSize, fontTraits), m_pageID); >+ process().send(Messages::WebPage::ChangeFont(WTFMove(changes)), m_pageID); > } > > void WebPageProxy::editorStateChanged(const EditorState& editorState) >diff --git a/Source/WebKit/WebKit.xcodeproj/project.pbxproj b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >index d3f8b9ea9b9237b05160e572a6e850ce364597d2..552c631402c70cb7706cdd786e5fa6ab0ed440b9 100644 >--- a/Source/WebKit/WebKit.xcodeproj/project.pbxproj >+++ b/Source/WebKit/WebKit.xcodeproj/project.pbxproj >@@ -11411,7 +11411,6 @@ > BC407603124FF0270068F20A /* WKSerializedScriptValue.cpp in Sources */, > 1ADE46B21954EC61000F7985 /* WKSessionStateRef.cpp in Sources */, > 1DB01944211CF005009FB3E8 /* WKShareSheet.mm in Sources */, >- 513E462E1AD837560016234A /* WKSharingServicePickerDelegate.mm in Sources */, > 93F549B61E3174DA000E7239 /* WKSnapshotConfiguration.mm in Sources */, > BC407605124FF0270068F20A /* WKString.cpp in Sources */, > BC407619124FF0370068F20A /* WKStringCF.mm in Sources */, >diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.h b/Source/WebKit/WebProcess/WebPage/WebPage.h >index 78fbf56654e74449e208a7d85a5ee8c84a090358..0a6fd1a7b17100b011412beabd4b79c8ec9c2b4f 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.h >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.h >@@ -166,6 +166,7 @@ enum class TextIndicatorPresentationTransition : uint8_t; > struct BackForwardItemIdentifier; > struct CompositionUnderline; > struct DictationAlternative; >+struct FontChanges; > struct GlobalFrameIdentifier; > struct GlobalWindowIdentifier; > struct Highlight; >@@ -1361,7 +1362,7 @@ private: > void immediateActionDidUpdate(); > void immediateActionDidCancel(); > void immediateActionDidComplete(); >- void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits); >+ void changeFont(WebCore::FontChanges&&); > > 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 8c411453a2e1e3c3231974b7ed1cd56fd179ce6b..8657d38bff1c7bab9036077e9b67bd5395b4662b 100644 >--- a/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >+++ b/Source/WebKit/WebProcess/WebPage/WebPage.messages.in >@@ -190,7 +190,7 @@ messages -> WebPage LegacyReceiver { > > #if PLATFORM(MAC) > PerformDictionaryLookupOfCurrentSelection() >- SetFont(String fontFamily, double fontSize, uint64_t fontTraits) >+ ChangeFont(struct WebCore::FontChanges 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 da7c98f68c48189073dbea474871ff2cab6a581a..657472c95ffe7fe127de9733cbacbdd2879faf44 100644 >--- a/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm >+++ b/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm >@@ -63,6 +63,8 @@ > #import <WebCore/Editor.h> > #import <WebCore/EventHandler.h> > #import <WebCore/FocusController.h> >+#import <WebCore/FontAttributeChanges.h> >+#import <WebCore/FontCache.h> > #import <WebCore/Frame.h> > #import <WebCore/FrameLoader.h> > #import <WebCore/FrameView.h> >@@ -371,21 +373,25 @@ void WebPage::attributedSubstringForCharacterRangeAsync(const EditingRange& edit > send(Messages::WebPageProxy::AttributedStringForCharacterRangeCallback(result, rangeToSend, callbackID)); > } > >+static bool nameAndSizeOfFont(const WebCore::Font& font, String& fontName, double& fontSize) >+{ >+ if (auto ctFont = font.getCTFont()) { >+ fontName = adoptCF(CTFontCopyPostScriptName(ctFont)).get(); >+ fontSize = CTFontGetSize(ctFont); >+ return true; >+ } >+ return false; >+} >+ > void WebPage::fontAtSelection(CallbackID callbackID) > { > String fontName; > double fontSize = 0; > bool selectionHasMultipleFonts = false; > Frame& frame = m_page->focusController().focusedOrMainFrame(); >- >- if (!frame.selection().selection().isNone()) { >- if (auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts)) { >- if (auto ctFont = font->getCTFont()) { >- fontName = adoptCF(CTFontCopyPostScriptName(ctFont)).get(); >- fontSize = CTFontGetSize(ctFont); >- } >- } >- } >+ if (auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts)) >+ nameAndSizeOfFont(*font, fontName, fontSize); >+ > send(Messages::WebPageProxy::FontAtSelectionCallback(fontName, fontSize, selectionHasMultipleFonts, callbackID)); > } > >@@ -1114,10 +1120,47 @@ void WebPage::dataDetectorsDidHideUI(PageOverlay::PageOverlayID overlayID) > } > } > >-void WebPage::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits) >+void WebPage::changeFont(WebCore::FontChanges&& changes) > { >- Frame& frame = m_page->focusController().focusedOrMainFrame(); >- frame.editor().applyFontStyles(fontFamily, fontSize, fontTraits); >+ auto& frame = m_page->focusController().focusedOrMainFrame(); >+ if (!frame.selection().selection().isContentEditable()) >+ return; >+ >+ std::optional<double> newSize; >+ if (changes.fontSize.has_value()) >+ newSize = changes.fontSize; >+ else if (changes.fontSizeDelta.has_value()) { >+ bool hasMultipleFonts = false; >+ auto* font = frame.editor().fontForSelection(hasMultipleFonts); >+ if (!font) { >+ ASSERT_NOT_REACHED(); >+ return; >+ } >+ double currentFontSize = 0; >+ String currentFontFamilyName; >+ if (!nameAndSizeOfFont(*font, currentFontFamilyName, currentFontSize)) { >+ ASSERT_NOT_REACHED(); >+ return; >+ } >+ newSize = currentFontSize + *changes.fontSizeDelta; >+ } >+ String familyNameForCSS; >+ if (!!changes.fontFamily) { >+ auto selectedFontName = changes.fontName.createCFString(); >+ RetainPtr<CFStringRef> fontNameFromFamily; >+ >+ FontDescription fontDescription; >+ fontDescription.setIsItalic(changes.italic.value_or(false)); >+ fontDescription.setWeight(FontSelectionValue { changes.bold.value_or(false) ? 900 : 500 }); >+ if (auto font = FontCache::singleton().fontForFamily(fontDescription, changes.fontFamily)) >+ fontNameFromFamily = adoptCF(CTFontCopyPostScriptName(font->getCTFont())); >+ >+ if (fontNameFromFamily && CFStringCompare(selectedFontName.get(), fontNameFromFamily.get(), 0) == kCFCompareEqualTo) >+ familyNameForCSS = changes.fontFamily; >+ else >+ familyNameForCSS = changes.fontName; >+ } >+ frame.editor().applyFontStyles(WTFMove(familyNameForCSS), WTFMove(newSize), WTFMove(changes.bold), WTFMove(changes.italic)); > } > > #if ENABLE(WIRELESS_PLAYBACK_TARGET) && !PLATFORM(IOS) >diff --git a/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm b/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm >index 6a7b140bd85d3f13de41c6dbfe52a3c448d45253..7b98bb85bb975e7e17f421cdc182ff23785f015d 100644 >--- a/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm >+++ b/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm >@@ -95,6 +95,7 @@ > #import <WebCore/FloatRect.h> > #import <WebCore/FocusController.h> > #import <WebCore/Font.h> >+#import <WebCore/FontAttributeChanges.h> > #import <WebCore/FontCache.h> > #import <WebCore/Frame.h> > #import <WebCore/FrameLoader.h> >@@ -123,6 +124,7 @@ > #import <WebCore/TextAlternativeWithRange.h> > #import <WebCore/TextIndicator.h> > #import <WebCore/TextUndoInsertionMarkupMac.h> >+#import <WebCore/WebCoreNSFontManagerExtras.h> > #import <WebCore/WebCoreObjCExtras.h> > #import <WebCore/WebNSAttributedStringExtras.h> > #import <WebCore/markup.h> >@@ -5128,13 +5130,19 @@ static RefPtr<KeyboardEvent> currentKeyboardEvent(Frame* coreFrame) > > - (NSString *)_shadowAsString:(NSShadow *)shadow > { >- if (shadow == nil) >+ if (!shadow) > return @"none"; >- NSSize offset = [shadow shadowOffset]; >- float blurRadius = [shadow shadowBlurRadius]; >- if (offset.width == 0 && offset.height == 0 && blurRadius == 0) >+ >+ return [self _shadowAsStringWithOffset:shadow.shadowOffset color:shadow.shadowColor blurRadius:shadow.shadowBlurRadius]; >+} >+ >+- (NSString *)_shadowAsStringWithOffset:(const NSSize&)shadowOffset color:(NSColor *)shadowColor blurRadius:(double)shadowBlurRadius >+{ >+ NSSize offset = shadowOffset; >+ float blurRadius = shadowBlurRadius; >+ if (!offset.width && !offset.height && !blurRadius) > return @"none"; >- NSColor *color = [shadow shadowColor]; >+ NSColor *color = shadowColor; > if (color == nil) > return @"none"; > // FIXME: Handle non-integral values here? >@@ -5327,78 +5335,44 @@ static RetainPtr<CFStringRef> fontNameForDescription(NSString *familyName, BOOL > return adoptCF(CTFontCopyPostScriptName(font->getCTFont())); > } > >-- (void)_addToStyle:(DOMCSSStyleDeclaration *)style fontA:(NSFont *)a fontB:(NSFont *)b >+- (void)_addFontChanges:(const FontChanges&)changes toStyle:(DOMCSSStyleDeclaration *)style > { >- // Since there's no way to directly ask NSFontManager what style change it's going to do >- // we instead pass two "specimen" fonts to it and let it change them. We then deduce what >- // style change it was doing by looking at what happened to each of the two fonts. >- // So if it was making the text bold, both fonts will be bold after the fact. >- >- if (a == nil || b == nil) >- return; >- >- NSFontManager *fm = [NSFontManager sharedFontManager]; >- >- NSFont *oa = [self _originalFontA]; >- >- NSString *aFamilyName = [a familyName]; >- NSString *bFamilyName = [b familyName]; >- >- int aPointSize = (int)[a pointSize]; >- int bPointSize = (int)[b pointSize]; >- >- int aWeight = [fm weightOfFont:a]; >- int bWeight = [fm weightOfFont:b]; >- >- BOOL aIsItalic = ([fm traitsOfFont:a] & NSItalicFontMask) != 0; >- BOOL bIsItalic = ([fm traitsOfFont:b] & NSItalicFontMask) != 0; >- >- BOOL aIsBold = aWeight > MIN_BOLD_WEIGHT; >- >- if ([aFamilyName isEqualToString:bFamilyName]) { >- NSString *familyNameForCSS = aFamilyName; >+ if (!!changes.fontFamily) { >+ NSString *familyNameForCSS = changes.fontFamily; > > // The family name may not be specific enough to get us the font specified. > // In some cases, the only way to get exactly what we are looking for is to use > // the Postscript name. > // If we don't find a font with the same Postscript name, then we'll have to use the > // Postscript name to make the CSS specific enough. >- auto fontName = fontNameForDescription(aFamilyName, aIsItalic, aIsBold); >- auto aName = [a fontName]; >- if (!fontName || !aName || !CFEqual(fontName.get(), static_cast<CFStringRef>(aName))) >- familyNameForCSS = aName; >+ auto fontNameFromFamily = fontNameForDescription(changes.fontFamily, changes.italic.has_value() && *changes.italic, changes.bold.has_value() && *changes.bold); >+ auto fontNameFromFont = changes.fontName.createCFString(); >+ if (!fontNameFromFamily || !fontNameFromFont || !CFEqual(fontNameFromFamily.get(), static_cast<CFStringRef>(fontNameFromFont.get()))) >+ familyNameForCSS = (__bridge NSString *)fontNameFromFont.get(); > > // FIXME: Need more sophisticated escaping code if we want to handle family names > // with characters like single quote or backslash in their names. >- [style setFontFamily:[NSString stringWithFormat:@"'%@'", familyNameForCSS]]; >+ style.fontFamily = [NSString stringWithFormat:@"'%@'", familyNameForCSS]; > } > >- int soa = (int)[oa pointSize]; >- if (aPointSize == bPointSize) >- [style setFontSize:[NSString stringWithFormat:@"%dpx", aPointSize]]; >- else if (aPointSize < soa) >- [style _setFontSizeDelta:@"-1px"]; >- else if (aPointSize > soa) >- [style _setFontSizeDelta:@"1px"]; >+ if (auto& fontSize = changes.fontSize) >+ style.fontSize = [NSString stringWithFormat:@"%.0fpx", *fontSize]; >+ >+ if (auto& fontSizeDelta = changes.fontSizeDelta) >+ [style _setFontSizeDelta:[NSString stringWithFormat:@"%.0fpx", *fontSizeDelta]]; > > // FIXME: Map to the entire range of CSS weight values. >- if (aWeight == bWeight) >- [style setFontWeight:aIsBold ? @"bold" : @"normal"]; >+ if (auto& bold = changes.bold) >+ style.fontWeight = *bold ? @"bold" : @"normal"; > >- if (aIsItalic == bIsItalic) >- [style setFontStyle:aIsItalic ? @"italic" : @"normal"]; >+ if (auto& italic = changes.italic) >+ style.fontStyle = *italic ? @"italic" : @"normal"; > } > > - (DOMCSSStyleDeclaration *)_styleFromFontManagerOperation > { > DOMCSSStyleDeclaration *style = [self _emptyStyle]; >- >- NSFontManager *fm = [NSFontManager sharedFontManager]; >- >- NSFont *oa = [self _originalFontA]; >- NSFont *ob = [self _originalFontB]; >- [self _addToStyle:style fontA:[fm convertFont:oa] fontB:[fm convertFont:ob]]; >- >+ [self _addFontChanges:WebCore::computedFontChanges(NSFontManager.sharedFontManager) toStyle:style]; > return style; > } > >@@ -5413,73 +5387,33 @@ static RetainPtr<CFStringRef> fontNameForDescription(NSString *familyName, BOOL > { > DOMCSSStyleDeclaration *style = [self _emptyStyle]; > >- auto shadow = adoptNS([[NSShadow alloc] init]); >- [shadow setShadowOffset:NSMakeSize(1, 1)]; >- >- NSDictionary *oa = [NSDictionary dictionaryWithObjectsAndKeys: >- [self _originalFontA], NSFontAttributeName, >- nil]; >- NSDictionary *ob = [NSDictionary dictionaryWithObjectsAndKeys: >- [NSColor blackColor], NSBackgroundColorAttributeName, >- [self _originalFontB], NSFontAttributeName, >- [NSColor whiteColor], NSForegroundColorAttributeName, >- shadow.get(), NSShadowAttributeName, >- [NSNumber numberWithInt:NSUnderlineStyleSingle], NSStrikethroughStyleAttributeName, >- [NSNumber numberWithInt:1], NSSuperscriptAttributeName, >- [NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, >- nil]; >+ auto changes = WebCore::computedFontAttributeChanges(NSFontManager.sharedFontManager, sender); > >- NSDictionary *a = [sender convertAttributes:oa]; >- NSDictionary *b = [sender convertAttributes:ob]; >+ if (auto& backgroundColor = changes.backgroundColor) >+ style.backgroundColor = [self _colorAsString:nsColor(*backgroundColor)]; > >- NSColor *ca = [a objectForKey:NSBackgroundColorAttributeName]; >- NSColor *cb = [b objectForKey:NSBackgroundColorAttributeName]; >- if (ca == cb) { >- [style setBackgroundColor:[self _colorAsString:ca]]; >- } >+ if (auto& foregroundColor = changes.foregroundColor) >+ style.color = [self _colorAsString:nsColor(*foregroundColor)]; > >- [self _addToStyle:style fontA:[a objectForKey:NSFontAttributeName] fontB:[b objectForKey:NSFontAttributeName]]; >+ if (auto& shadow = changes.shadow) >+ style.textShadow = [self _shadowAsStringWithOffset:NSMakeSize(shadow->width, shadow->height) color:nsColor(shadow->color) blurRadius:shadow->blurRadius]; > >- ca = [a objectForKey:NSForegroundColorAttributeName]; >- cb = [b objectForKey:NSForegroundColorAttributeName]; >- if (ca == cb) { >- if (!ca) >- ca = [NSColor blackColor]; >- [style setColor:[self _colorAsString:ca]]; >- } >+ if (changes.verticalAlign == VerticalAlign::Super) >+ style.verticalAlign = @"super"; >+ else if (changes.verticalAlign == VerticalAlign::Sub) >+ style.verticalAlign = @"sub"; >+ else if (changes.verticalAlign == VerticalAlign::Baseline) >+ style.verticalAlign = @"baseline"; > >- NSShadow *sha = [a objectForKey:NSShadowAttributeName]; >- if (sha) >- [style setTextShadow:[self _shadowAsString:sha]]; >- else if ([b objectForKey:NSShadowAttributeName] == nil) >- [style setTextShadow:@"none"]; >+ [self _addFontChanges:changes.fontChanges toStyle:style]; > >- int sa = [[a objectForKey:NSSuperscriptAttributeName] intValue]; >- int sb = [[b objectForKey:NSSuperscriptAttributeName] intValue]; >- if (sa == sb) { >- if (sa > 0) >- [style setVerticalAlign:@"super"]; >- else if (sa < 0) >- [style setVerticalAlign:@"sub"]; >- else >- [style setVerticalAlign:@"baseline"]; >- } >- > auto editingStyle = EditingStyle::create(core(style)); > >- int strikeThroughA = [[a objectForKey:NSStrikethroughStyleAttributeName] intValue]; >- int strikeThroughB = [[b objectForKey:NSStrikethroughStyleAttributeName] intValue]; >- if (strikeThroughA == strikeThroughB) { >- bool shouldRemoveStrikeThrough = strikeThroughA == NSUnderlineStyleNone; >- editingStyle->setStrikeThroughChange(shouldRemoveStrikeThrough ? TextDecorationChange::Remove : TextDecorationChange::Add); >- } >+ if (auto& strikeThrough = changes.strikeThrough) >+ editingStyle->setStrikeThroughChange(*strikeThrough ? TextDecorationChange::Add : TextDecorationChange::Remove); > >- int ua = [[a objectForKey:NSUnderlineStyleAttributeName] intValue]; >- int ub = [[b objectForKey:NSUnderlineStyleAttributeName] intValue]; >- if (ua == ub) { >- bool shouldRemoveUnderline = ua == NSUnderlineStyleNone; >- editingStyle->setUnderlineChange(shouldRemoveUnderline ? TextDecorationChange::Remove : TextDecorationChange::Add); >- } >+ if (auto& underline = changes.underline) >+ editingStyle->setUnderlineChange(*underline ? TextDecorationChange::Add : TextDecorationChange::Remove); > > return editingStyle; > } >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 7d898d414ce68f81a23e3bd2156f75d3e230e938..f4726d01c2d88c544edecf907270f04b13e816f7 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,21 @@ >+2018-09-04 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [macOS] Cannot change font size at selection until font panel is shown >+ https://bugs.webkit.org/show_bug.cgi?id=189295 >+ <rdar://problem/35593389> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/mac/FontManagerTests.mm: Added. >+ (-[TestWKWebView selectedText]): >+ (-[TestWKWebView selectNextWord]): >+ (-[TestWKWebView stylePropertyAtSelectionStart:]): >+ (-[TestWKWebView stylePropertyAtSelectionEnd:]): >+ (webViewForFontManagerTesting): >+ (menuItemCellForFontAction): >+ (TestWebKitAPI::TEST): >+ > 2018-08-31 Aditya Keerthi <akeerthi@apple.com> > > Unreviewed, add an alternate email for Aditya Keerthi. >diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >index cc640c5874cc6d4a57a80878e0a450db2f5aac9e..d93450202cb323bc7fd8113b765971239f256751 100644 >--- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >+++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >@@ -806,6 +806,7 @@ > F4517B672054C49500C26721 /* TestWKWebViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4517B662054C49500C26721 /* TestWKWebViewController.mm */; }; > F4517B7F2055101B00C26721 /* ClassMethodSwizzler.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4517B692054E0AC00C26721 /* ClassMethodSwizzler.mm */; }; > F4538EF71E8473E600B5C953 /* large-red-square.png in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4538EF01E846B4100B5C953 /* large-red-square.png */; }; >+ F456AB1C213EDBA300CB2CEF /* FontManagerTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F456AB1B213EDBA300CB2CEF /* FontManagerTests.mm */; }; > F457A9B8202D5CDC00F7E9D5 /* PasteMixedContent.mm in Sources */ = {isa = PBXBuildFile; fileRef = F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */; }; > F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F457A9B3202D535300F7E9D5 /* DataTransfer.html */; }; > F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F45B63FA1F197F33009D38B9 /* image-map.html */; }; >@@ -2050,6 +2051,7 @@ > F4517B682054E0AC00C26721 /* ClassMethodSwizzler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ClassMethodSwizzler.h; sourceTree = "<group>"; }; > F4517B692054E0AC00C26721 /* ClassMethodSwizzler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ClassMethodSwizzler.mm; sourceTree = "<group>"; }; > F4538EF01E846B4100B5C953 /* large-red-square.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "large-red-square.png"; sourceTree = "<group>"; }; >+ F456AB1B213EDBA300CB2CEF /* FontManagerTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontManagerTests.mm; sourceTree = "<group>"; }; > F457A9B3202D535300F7E9D5 /* DataTransfer.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DataTransfer.html; sourceTree = "<group>"; }; > F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteMixedContent.mm; sourceTree = "<group>"; }; > F45B63FA1F197F33009D38B9 /* image-map.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "image-map.html"; sourceTree = "<group>"; }; >@@ -3207,6 +3209,7 @@ > 4BB4160316815F9100824238 /* ElementAtPointInWebFrame.mm */, > 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */, > C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */, >+ F456AB1B213EDBA300CB2CEF /* FontManagerTests.mm */, > 1A7E8B33181208DE00AEB74A /* FragmentNavigation.mm */, > CDBFCC431A9FF44800A7B691 /* FullscreenZoomInitialFrame.mm */, > 9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */, >@@ -3774,6 +3777,7 @@ > 7A909A7F1D877480007E10F8 /* FloatRect.cpp in Sources */, > 7A909A801D877480007E10F8 /* FloatSize.cpp in Sources */, > 1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */, >+ F456AB1C213EDBA300CB2CEF /* FontManagerTests.mm in Sources */, > 7CCE7EF51A411AE600447C4C /* ForceRepaint.cpp in Sources */, > 7CCE7EC01A411A7E00447C4C /* FragmentNavigation.mm in Sources */, > 376C8C061D6E197C007D2BB9 /* FrameHandle.cpp in Sources */, >diff --git a/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm b/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..7616dd5e66d95f48c0a18b908d5459962ae38c11 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm >@@ -0,0 +1,183 @@ >+/* >+ * 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. >+ */ >+ >+#import "config.h" >+ >+#if PLATFORM(MAC) >+ >+#import "PlatformUtilities.h" >+#import "TestWKWebView.h" >+#import <WebKit/WKWebViewPrivate.h> >+ >+@interface TestWKWebView (FontManagerTests) >+ >+@property (nonatomic, readonly) NSString *selectedText; >+ >+- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName; >+- (NSString *)stylePropertyAtSelectionEnd:(NSString *)propertyName; >+- (void)selectNextWord; >+ >+@end >+ >+@implementation TestWKWebView (FontManagerTests) >+ >+- (NSString *)selectedText >+{ >+ return [self stringByEvaluatingJavaScript:@"getSelection().toString()"]; >+} >+ >+- (void)selectNextWord >+{ >+ [self moveRight:nil]; >+ [self moveRight:nil]; >+ [self selectWord:nil]; >+} >+ >+- (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName >+{ >+ NSString *script = [NSString stringWithFormat:@"getComputedStyle(getSelection().getRangeAt(0).startContainer.parentElement)['%@']", propertyName]; >+ return [self stringByEvaluatingJavaScript:script]; >+} >+ >+- (NSString *)stylePropertyAtSelectionEnd:(NSString *)propertyName >+{ >+ NSString *script = [NSString stringWithFormat:@"getComputedStyle(getSelection().getRangeAt(0).endContainer.parentElement)['%@']", propertyName]; >+ return [self stringByEvaluatingJavaScript:script]; >+} >+ >+@end >+ >+static RetainPtr<TestWKWebView> webViewForFontManagerTesting(NSFontManager *fontManager) >+{ >+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]); >+ [webView synchronouslyLoadHTMLString:@"<body contenteditable><span id='foo'>foo</span> <span id='bar'>bar</span> <span id='baz'>baz</span></body>"]; >+ [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; >+ fontManager.target = webView.get(); >+ return webView; >+} >+ >+static RetainPtr<NSMenuItemCell> menuItemCellForFontAction(NSFontAction action) >+{ >+ auto menuItem = adoptNS([[NSMenuItem alloc] init]); >+ auto menuItemCell = adoptNS([[NSMenuItemCell alloc] init]); >+ [menuItemCell setMenuItem:menuItem.get()]; >+ [menuItemCell setTag:action]; >+ return menuItemCell; >+} >+ >+namespace TestWebKitAPI { >+ >+TEST(FontManagerTests, ChangeFontSizeWithMenuItems) >+{ >+ NSFontManager *fontManager = [NSFontManager sharedFontManager]; >+ auto webView = webViewForFontManagerTesting(fontManager); >+ >+ auto sizeIncreaseMenuItemCell = menuItemCellForFontAction(NSSizeUpFontAction); >+ auto sizeDecreaseMenuItemCell = menuItemCellForFontAction(NSSizeDownFontAction); >+ >+ // Select "foo" and increase font size. >+ [webView selectWord:nil]; >+ [fontManager modifyFont:sizeIncreaseMenuItemCell.get()]; >+ [fontManager modifyFont:sizeIncreaseMenuItemCell.get()]; >+ >+ // Now select "baz" and decrease font size. >+ [webView moveToEndOfParagraph:nil]; >+ [webView selectWord:nil]; >+ [fontManager modifyFont:sizeDecreaseMenuItemCell.get()]; >+ [fontManager modifyFont:sizeDecreaseMenuItemCell.get()]; >+ >+ // Lastly, select just the "r" in "bar" and increase font size. >+ [webView evaluateJavaScript:@"getSelection().setBaseAndExtent(bar.childNodes[0], 2, bar.childNodes[0], 3)" completionHandler:nil]; >+ [fontManager modifyFont:sizeIncreaseMenuItemCell.get()]; >+ >+ [webView moveToBeginningOfParagraph:nil]; >+ [webView selectWord:nil]; >+ EXPECT_WK_STREQ(@"foo", [webView selectedText]); >+ EXPECT_WK_STREQ(@"18px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ(@"18px", [webView stylePropertyAtSelectionEnd:@"font-size"]); >+ >+ [webView selectNextWord]; >+ EXPECT_WK_STREQ(@"bar", [webView selectedText]); >+ EXPECT_WK_STREQ(@"16px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ(@"17px", [webView stylePropertyAtSelectionEnd:@"font-size"]); >+ >+ [webView selectNextWord]; >+ EXPECT_WK_STREQ(@"baz", [webView selectedText]); >+ EXPECT_WK_STREQ(@"14px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ(@"14px", [webView stylePropertyAtSelectionEnd:@"font-size"]); >+} >+ >+TEST(FontManagerTests, ChangeFontWithPanel) >+{ >+ NSFontManager *fontManager = [NSFontManager sharedFontManager]; >+ auto webView = webViewForFontManagerTesting(fontManager); >+ >+ NSFontPanel *fontPanel = [fontManager fontPanel:YES]; >+ [fontPanel setIsVisible:YES]; >+ >+ NSFont *largeHelveticaFont = [NSFont fontWithName:@"Helvetica" size:20]; >+ [fontPanel setPanelFont:largeHelveticaFont isMultiple:NO]; >+ [webView selectWord:nil]; >+ [fontManager modifyFontViaPanel:fontPanel]; >+ EXPECT_WK_STREQ("foo", [webView selectedText]); >+ EXPECT_WK_STREQ("Helvetica", [webView stylePropertyAtSelectionStart:@"font-family"]); >+ EXPECT_WK_STREQ("20px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-weight"]); >+ EXPECT_EQ(largeHelveticaFont, fontManager.selectedFont); >+ >+ NSFont *smallBoldTimesFont = [fontManager fontWithFamily:@"Times New Roman" traits:NSBoldFontMask weight:NSFontWeightBold size:10]; >+ [fontPanel setPanelFont:smallBoldTimesFont isMultiple:NO]; >+ [webView selectNextWord]; >+ [fontManager modifyFontViaPanel:fontPanel]; >+ EXPECT_WK_STREQ("bar", [webView selectedText]); >+ EXPECT_WK_STREQ("\"Times New Roman\"", [webView stylePropertyAtSelectionStart:@"font-family"]); >+ EXPECT_WK_STREQ("10px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]); >+ EXPECT_EQ(smallBoldTimesFont, fontManager.selectedFont); >+ >+ NSFont *boldItalicArialFont = [fontManager fontWithFamily:@"Arial" traits:NSBoldFontMask | NSItalicFontMask weight:NSFontWeightBold size:14]; >+ [fontPanel setPanelFont:boldItalicArialFont isMultiple:NO]; >+ [webView selectNextWord]; >+ [fontManager modifyFontViaPanel:fontPanel]; >+ EXPECT_WK_STREQ("baz", [webView selectedText]); >+ EXPECT_WK_STREQ("Arial", [webView stylePropertyAtSelectionStart:@"font-family"]); >+ EXPECT_WK_STREQ("14px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]); >+ EXPECT_EQ(boldItalicArialFont, fontManager.selectedFont); >+ >+ NSFont *largeItalicUltralightAvenirFont = [fontManager fontWithFamily:@"Avenir" traits:NSItalicFontMask weight:NSFontWeightLight size:24]; >+ [fontPanel setPanelFont:largeItalicUltralightAvenirFont isMultiple:NO]; >+ [webView selectAll:nil]; >+ [fontManager modifyFontViaPanel:fontPanel]; >+ EXPECT_WK_STREQ("foo bar baz", [webView selectedText]); >+ EXPECT_WK_STREQ("Avenir-LightOblique", [webView stylePropertyAtSelectionStart:@"font-family"]); >+ EXPECT_WK_STREQ("24px", [webView stylePropertyAtSelectionStart:@"font-size"]); >+ EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-weight"]); >+ EXPECT_EQ(largeItalicUltralightAvenirFont, fontManager.selectedFont); >+} >+ >+} // namespace TestWebKitAPI >+ >+#endif // PLATFORM(MAC)
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 189295
:
348892
|
348947
|
348981
|
348984
|
348986
|
348989
|
348995
|
349029
|
349050