Diff
Modified: trunk/Source/WebCore/ChangeLog (287495 => 287496)
--- trunk/Source/WebCore/ChangeLog 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/ChangeLog 2021-12-31 23:33:52 UTC (rev 287496)
@@ -1,3 +1,43 @@
+2021-12-31 Wenson Hsieh <[email protected]>
+
+ Refactor some Cocoa-specific code in WebCore::FontAttributes to be platform-agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=234757
+
+ Reviewed by Darin Adler.
+
+ Replace the UIFont/NSFont currently in WebCore::FontAttributes with a WebCore::Font instead. This removes a bit
+ of platform-specific logic in an otherwise platform-agnostic class (with the exception of a couple Cocoa-
+ specific helper methods). This additionally lets us remove some platform-specific logic for computing font
+ attributes (i.e. `platformFontAttributesAtSelectionStart`) below.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * editing/Editor.cpp:
+ (WebCore::Editor::fontAttributesAtSelectionStart):
+ (WebCore::Editor::platformFontAttributesAtSelectionStart const): Deleted.
+ * editing/Editor.h:
+ * editing/FontAttributes.h:
+ (WebCore::TextList::encode const):
+ (WebCore::TextList::decode):
+
+ Drive-by fix: instead of `static_cast`-ing to a uint8_t and encoding/decoding the raw value, encode and decode
+ the ListStyleType as a normal enum instead. This also ensures that we validate the enum value upon decoding.
+
+ (WebCore::FontAttributes::encodingRequiresPlatformData const): Deleted.
+ * editing/cocoa/EditorCocoa.mm:
+ (WebCore::Editor::platformFontAttributesAtSelectionStart const): Deleted.
+ * editing/cocoa/FontAttributesCocoa.mm:
+ (WebCore::FontAttributes::createDictionary const):
+
+ Only grab the NSFont or UIFont from the WebCore::Font object once we're in this Cocoa-specific helper.
+
+ * platform/graphics/cocoa/FontCocoa.h: Added.
+
+ Moved here from CocoaFont.h in WebKit. See WebKit/ChangeLog for more details.
+
+ * rendering/style/RenderStyleConstants.h:
+
+ Add EnumTraits for ListStyleType, so that it can be encoded/decoded.
+
2021-12-31 Alan Bujtas <[email protected]>
REGRESSION (r287028): Incorrect root inline box horizontal position when text-align offset is present
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (287495 => 287496)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2021-12-31 23:33:52 UTC (rev 287496)
@@ -5511,6 +5511,7 @@
F48D2AA52159740D00C6752B /* ColorCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2AA32159740D00C6752B /* ColorCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
F49328832769041B003E20F8 /* ModalContainerTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = F49328822769041B003E20F8 /* ModalContainerTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ F4A064C8277E48C900B06A17 /* FontCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F4A064C6277E48C600B06A17 /* FontCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
F4B0018926E7F21F006EAABE /* HTMLAtomStringCache.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B0018726E7F21F006EAABE /* HTMLAtomStringCache.h */; };
F4B2A909265030BA009E7286 /* DataDetectorHighlight.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */; };
F4B422C4220C0568009E1E7D /* DOMPasteAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B422C2220C0000009E1E7D /* DOMPasteAccess.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -17742,6 +17743,7 @@
F49328822769041B003E20F8 /* ModalContainerTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ModalContainerTypes.h; sourceTree = "<group>"; };
F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; };
F49E98E421DEE6C1009AE55E /* EditAction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = EditAction.cpp; sourceTree = "<group>"; };
+ F4A064C6277E48C600B06A17 /* FontCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontCocoa.h; sourceTree = "<group>"; };
F4B0018726E7F21F006EAABE /* HTMLAtomStringCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTMLAtomStringCache.h; sourceTree = "<group>"; };
F4B0018826E7F21F006EAABE /* HTMLAtomStringCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLAtomStringCache.cpp; sourceTree = "<group>"; };
F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataDetectorHighlight.h; sourceTree = "<group>"; };
@@ -29053,6 +29055,7 @@
C2458E611FE8979E00594759 /* FontCacheCoreText.h */,
B2AFFC780D00A5C10030074D /* FontCascadeCocoa.cpp */,
1C6FD8B0250A35F100D6E920 /* FontCocoa.cpp */,
+ F4A064C6277E48C600B06A17 /* FontCocoa.h */,
1C12AC2C1EE779950079E0A0 /* FontDescriptionCocoa.cpp */,
1C12AC281EE778AE0079E0A0 /* FontFamilySpecificationCoreText.cpp */,
1C12AC291EE778AE0079E0A0 /* FontFamilySpecificationCoreText.h */,
@@ -34409,6 +34412,7 @@
B2C3DA610D006CD600EF6F26 /* FontCascade.h in Headers */,
E4E8B4F5216B956500B8834D /* FontCascadeDescription.h in Headers */,
B2C3DA680D006CD600EF6F26 /* FontCascadeFonts.h in Headers */,
+ F4A064C8277E48C900B06A17 /* FontCocoa.h in Headers */,
1C26671B26FA932F00117073 /* FontCreationContext.h in Headers */,
B2AFFC7E0D00A5C10030074D /* FontCustomPlatformData.h in Headers */,
B2C3DA660D006CD600EF6F26 /* FontDescription.h in Headers */,
@@ -34508,6 +34512,7 @@
BC53C5F50DA56B920021EB5D /* Gradient.h in Headers */,
B22279640D00BF220071B782 /* GradientAttributes.h in Headers */,
BC19CDF4277106390053F734 /* GradientColorStop.h in Headers */,
+ BC19CE2B2772BF7B0053F734 /* GradientColorStops.h in Headers */,
2D481F04146B5C6B00AA7834 /* GradientImage.h in Headers */,
BC19CDF2276FFC6D0053F734 /* GradientRendererCG.h in Headers */,
7BB680BA25BA1BE4002B8738 /* GraphicsChecksMac.h in Headers */,
@@ -37573,7 +37578,6 @@
BE913D80181EF92400DCB09E /* TrackPrivateBase.h in Headers */,
CD1F9B1C27024BC200617EB6 /* TrackPrivateBaseClient.h in Headers */,
FFAC30FE184FB145008C4F1E /* TrailingObjects.h in Headers */,
- BC19CE2B2772BF7B0053F734 /* GradientColorStops.h in Headers */,
516071321BD8308B00DBC4F2 /* TransactionOperation.h in Headers */,
CD3EEF4125799FD9006563BB /* TransferFunction.h in Headers */,
49E911C40EF86D47009D0CAF /* TransformationMatrix.h in Headers */,
Modified: trunk/Source/WebCore/editing/Editor.cpp (287495 => 287496)
--- trunk/Source/WebCore/editing/Editor.cpp 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/editing/Editor.cpp 2021-12-31 23:33:52 UTC (rev 287496)
@@ -3997,10 +3997,6 @@
#if !PLATFORM(COCOA)
-void Editor::platformFontAttributesAtSelectionStart(FontAttributes&, const RenderStyle&) const
-{
-}
-
String Editor::platformContentTypeForBlobType(const String& type) const
{
return type;
@@ -4044,6 +4040,10 @@
FontAttributes Editor::fontAttributesAtSelectionStart()
{
+ FontAttributes attributes;
+ bool hasMultipleFonts = false; // FIXME (190120): Add `hasMultipleFonts` as a member in `FontAttributes`.
+ attributes.font = fontForSelection(hasMultipleFonts);
+
RefPtr<Node> nodeToRemove;
auto nodeRemovalScope = makeScopeExit([&nodeToRemove]() {
if (nodeToRemove)
@@ -4056,9 +4056,6 @@
ScriptDisallowedScope::InMainThread scriptDisallowedScope;
- FontAttributes attributes;
- platformFontAttributesAtSelectionStart(attributes, *style);
-
// FIXME: for now, always report the colors after applying -apple-color-filter. In future not all clients
// may want this, so we may have to add a setting to control it. See also editingAttributedStringFromRange().
auto backgroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
Modified: trunk/Source/WebCore/editing/Editor.h (287495 => 287496)
--- trunk/Source/WebCore/editing/Editor.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/editing/Editor.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -631,7 +631,6 @@
static RefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *);
static RefPtr<SharedBuffer> dataInRTFFormat(NSAttributedString *);
#endif
- void platformFontAttributesAtSelectionStart(FontAttributes&, const RenderStyle&) const;
void scheduleEditorUIUpdate();
Modified: trunk/Source/WebCore/editing/FontAttributes.h (287495 => 287496)
--- trunk/Source/WebCore/editing/FontAttributes.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/editing/FontAttributes.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -25,14 +25,13 @@
#pragma once
+#include "Font.h"
#include "FontShadow.h"
#include "RenderStyleConstants.h"
#include <wtf/RetainPtr.h>
OBJC_CLASS NSDictionary;
-OBJC_CLASS NSFont;
OBJC_CLASS NSTextList;
-OBJC_CLASS UIFont;
namespace WebCore {
@@ -51,12 +50,12 @@
template<class Encoder> inline void TextList::encode(Encoder& encoder) const
{
- encoder << static_cast<uint8_t>(style) << startingItemNumber << ordered;
+ encoder << style << startingItemNumber << ordered;
}
template<class Decoder> inline std::optional<TextList> TextList::decode(Decoder& decoder)
{
- std::optional<uint8_t> style;
+ std::optional<ListStyleType> style;
decoder >> style;
if (!style)
return std::nullopt;
@@ -71,7 +70,7 @@
if (!ordered)
return std::nullopt;
- return {{ static_cast<ListStyleType>(WTFMove(*style)), WTFMove(*startingItemNumber), WTFMove(*ordered) }};
+ return { { *style, *startingItemNumber, *ordered } };
}
struct FontAttributes {
@@ -79,18 +78,10 @@
enum class HorizontalAlignment : uint8_t { Left, Center, Right, Justify, Natural };
#if PLATFORM(COCOA)
- bool encodingRequiresPlatformData() const { return true; }
-
WEBCORE_EXPORT RetainPtr<NSDictionary> createDictionary() const;
-#else
- bool encodingRequiresPlatformData() const { return false; }
#endif
-#if PLATFORM(MAC)
- RetainPtr<NSFont> font;
-#elif PLATFORM(IOS_FAMILY)
- RetainPtr<UIFont> font;
-#endif
+ RefPtr<Font> font;
Color backgroundColor;
Color foregroundColor;
FontShadow fontShadow;
Modified: trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm (287495 => 287496)
--- trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -65,12 +65,6 @@
namespace WebCore {
-void Editor::platformFontAttributesAtSelectionStart(FontAttributes& attributes, const RenderStyle& style) const
-{
- if (auto ctFont = style.fontCascade().primaryFont().getCTFont())
- attributes.font = (__bridge id)ctFont;
-}
-
static RefPtr<SharedBuffer> archivedDataForAttributedString(NSAttributedString *attributedString)
{
if (!attributedString.length)
Modified: trunk/Source/WebCore/editing/cocoa/FontAttributesCocoa.mm (287495 => 287496)
--- trunk/Source/WebCore/editing/cocoa/FontAttributesCocoa.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/editing/cocoa/FontAttributesCocoa.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -27,6 +27,7 @@
#import "FontAttributes.h"
#import "ColorCocoa.h"
+#import "FontCocoa.h"
#import <pal/spi/cocoa/NSAttributedStringSPI.h>
#import <wtf/cocoa/VectorCocoa.h>
@@ -87,8 +88,8 @@
RetainPtr<NSDictionary> FontAttributes::createDictionary() const
{
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
- if (font)
- attributes[NSFontAttributeName] = font.get();
+ if (auto cocoaFont = font ? (__bridge CocoaFont *)font->getCTFont() : nil)
+ attributes[NSFontAttributeName] = cocoaFont;
if (foregroundColor.isValid())
attributes[NSForegroundColorAttributeName] = cocoaColor(foregroundColor).get();
Copied: trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.h (from rev 287495, trunk/Source/WebKit/Platform/cocoa/CocoaFont.h) (0 => 287496)
--- trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -0,0 +1,48 @@
+/*
+* Copyright (C) 2021 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 <wtf/Compiler.h>
+
+#if USE(APPKIT)
+OBJC_CLASS NSFont;
+OBJC_CLASS NSFontDescriptor;
+#else
+OBJC_CLASS UIFont;
+OBJC_CLASS UIFontDescriptor;
+#endif
+
+namespace WebCore {
+
+#if USE(APPKIT)
+using CocoaFont = NSFont;
+using CocoaFontDescriptor = NSFontDescriptor;
+#else
+using CocoaFont = UIFont;
+using CocoaFontDescriptor = UIFontDescriptor;
+#endif
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/style/RenderStyleConstants.h (287495 => 287496)
--- trunk/Source/WebCore/rendering/style/RenderStyleConstants.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebCore/rendering/style/RenderStyleConstants.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -1360,4 +1360,107 @@
WebCore::ScrollSnapStop::Always
>;
};
+
+template<> struct EnumTraits<WebCore::ListStyleType> {
+ using values = EnumValues<
+ WebCore::ListStyleType,
+ WebCore::ListStyleType::Disc,
+ WebCore::ListStyleType::Circle,
+ WebCore::ListStyleType::Square,
+ WebCore::ListStyleType::Decimal,
+ WebCore::ListStyleType::DecimalLeadingZero,
+ WebCore::ListStyleType::ArabicIndic,
+ WebCore::ListStyleType::Binary,
+ WebCore::ListStyleType::Bengali,
+ WebCore::ListStyleType::Cambodian,
+ WebCore::ListStyleType::Khmer,
+ WebCore::ListStyleType::Devanagari,
+ WebCore::ListStyleType::Gujarati,
+ WebCore::ListStyleType::Gurmukhi,
+ WebCore::ListStyleType::Kannada,
+ WebCore::ListStyleType::LowerHexadecimal,
+ WebCore::ListStyleType::Lao,
+ WebCore::ListStyleType::Malayalam,
+ WebCore::ListStyleType::Mongolian,
+ WebCore::ListStyleType::Myanmar,
+ WebCore::ListStyleType::Octal,
+ WebCore::ListStyleType::Oriya,
+ WebCore::ListStyleType::Persian,
+ WebCore::ListStyleType::Urdu,
+ WebCore::ListStyleType::Telugu,
+ WebCore::ListStyleType::Tibetan,
+ WebCore::ListStyleType::Thai,
+ WebCore::ListStyleType::UpperHexadecimal,
+ WebCore::ListStyleType::LowerRoman,
+ WebCore::ListStyleType::UpperRoman,
+ WebCore::ListStyleType::LowerGreek,
+ WebCore::ListStyleType::LowerAlpha,
+ WebCore::ListStyleType::LowerLatin,
+ WebCore::ListStyleType::UpperAlpha,
+ WebCore::ListStyleType::UpperLatin,
+ WebCore::ListStyleType::Afar,
+ WebCore::ListStyleType::EthiopicHalehameAaEt,
+ WebCore::ListStyleType::EthiopicHalehameAaEr,
+ WebCore::ListStyleType::Amharic,
+ WebCore::ListStyleType::EthiopicHalehameAmEt,
+ WebCore::ListStyleType::AmharicAbegede,
+ WebCore::ListStyleType::EthiopicAbegedeAmEt,
+ WebCore::ListStyleType::CJKEarthlyBranch,
+ WebCore::ListStyleType::CJKHeavenlyStem,
+ WebCore::ListStyleType::Ethiopic,
+ WebCore::ListStyleType::EthiopicHalehameGez,
+ WebCore::ListStyleType::EthiopicAbegede,
+ WebCore::ListStyleType::EthiopicAbegedeGez,
+ WebCore::ListStyleType::HangulConsonant,
+ WebCore::ListStyleType::Hangul,
+ WebCore::ListStyleType::LowerNorwegian,
+ WebCore::ListStyleType::Oromo,
+ WebCore::ListStyleType::EthiopicHalehameOmEt,
+ WebCore::ListStyleType::Sidama,
+ WebCore::ListStyleType::EthiopicHalehameSidEt,
+ WebCore::ListStyleType::Somali,
+ WebCore::ListStyleType::EthiopicHalehameSoEt,
+ WebCore::ListStyleType::Tigre,
+ WebCore::ListStyleType::EthiopicHalehameTig,
+ WebCore::ListStyleType::TigrinyaEr,
+ WebCore::ListStyleType::EthiopicHalehameTiEr,
+ WebCore::ListStyleType::TigrinyaErAbegede,
+ WebCore::ListStyleType::EthiopicAbegedeTiEr,
+ WebCore::ListStyleType::TigrinyaEt,
+ WebCore::ListStyleType::EthiopicHalehameTiEt,
+ WebCore::ListStyleType::TigrinyaEtAbegede,
+ WebCore::ListStyleType::EthiopicAbegedeTiEt,
+ WebCore::ListStyleType::UpperGreek,
+ WebCore::ListStyleType::UpperNorwegian,
+ WebCore::ListStyleType::Asterisks,
+ WebCore::ListStyleType::Footnotes,
+ WebCore::ListStyleType::Hebrew,
+ WebCore::ListStyleType::Armenian,
+ WebCore::ListStyleType::LowerArmenian,
+ WebCore::ListStyleType::UpperArmenian,
+ WebCore::ListStyleType::Georgian,
+ WebCore::ListStyleType::CJKIdeographic,
+ WebCore::ListStyleType::Hiragana,
+ WebCore::ListStyleType::Katakana,
+ WebCore::ListStyleType::HiraganaIroha,
+ WebCore::ListStyleType::KatakanaIroha,
+ WebCore::ListStyleType::CJKDecimal,
+ WebCore::ListStyleType::Tamil,
+ WebCore::ListStyleType::DisclosureOpen,
+ WebCore::ListStyleType::DisclosureClosed,
+ WebCore::ListStyleType::JapaneseInformal,
+ WebCore::ListStyleType::JapaneseFormal,
+ WebCore::ListStyleType::KoreanHangulFormal,
+ WebCore::ListStyleType::KoreanHanjaInformal,
+ WebCore::ListStyleType::KoreanHanjaFormal,
+ WebCore::ListStyleType::SimplifiedChineseInformal,
+ WebCore::ListStyleType::SimplifiedChineseFormal,
+ WebCore::ListStyleType::TraditionalChineseInformal,
+ WebCore::ListStyleType::TraditionalChineseFormal,
+ WebCore::ListStyleType::EthiopicNumeric,
+ WebCore::ListStyleType::String,
+ WebCore::ListStyleType::None
+ >;
+};
+
}
Modified: trunk/Source/WebKit/ChangeLog (287495 => 287496)
--- trunk/Source/WebKit/ChangeLog 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/ChangeLog 2021-12-31 23:33:52 UTC (rev 287496)
@@ -1,3 +1,58 @@
+2021-12-31 Wenson Hsieh <[email protected]>
+
+ Refactor some Cocoa-specific code in WebCore::FontAttributes to be platform-agnostic
+ https://bugs.webkit.org/show_bug.cgi?id=234757
+
+ See comments below (as well as WebCore/ChangeLog) for more details.
+
+ Reviewed by Darin Adler.
+
+ * Platform/cocoa/CocoaFont.h: Removed.
+
+ Move this file into WebCore, as `FontCocoa.h`.
+
+ * Shared/Cocoa/ArgumentCodersCocoa.mm:
+ * Shared/Cocoa/CoreTextHelpers.h:
+ * Shared/Cocoa/CoreTextHelpers.mm:
+
+ Adjust a few places that currently import CocoaFont.h to import WebCore/FontCocoa.h instead. Additonally, change
+ CocoaFont to WebCore::CocoaFont where necessary.
+
+ * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+ (IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData): Deleted.
+ (IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData): Deleted.
+
+ Remove platform-specific FontAttributes encoding/decoding logic. This is no longer needed, since we just
+ propagate a Font instead of an NSFont or UIFont.
+
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<RefPtr<Font>>::encode):
+ (IPC::ArgumentCoder<RefPtr<Font>>::decode):
+
+ Add argument coders for `RefPtr<Font>` that encode the font only if it's non-null.
+
+ (IPC::ArgumentCoder<FontAttributes>::encode):
+ (IPC::ArgumentCoder<FontAttributes>::decode):
+
+ Remove the calls to `encodePlatformData/decodePlatformData`, and instead encode the `RefPtr<WebCore::Font>`.
+
+ * Shared/WebCoreArgumentCoders.h:
+ * Shared/playstation/WebCoreArgumentCodersPlayStation.cpp:
+ (IPC::ArgumentCoder<FontAttributes>::encodePlatformData): Deleted.
+ (IPC::ArgumentCoder<FontAttributes>::decodePlatformData): Deleted.
+ * Shared/soup/WebCoreArgumentCodersSoup.cpp:
+ (IPC::ArgumentCoder<FontAttributes>::encodePlatformData): Deleted.
+ (IPC::ArgumentCoder<FontAttributes>::decodePlatformData): Deleted.
+ * Shared/win/WebCoreArgumentCodersWin.cpp:
+ (IPC::ArgumentCoder<FontAttributes>::encodePlatformData): Deleted.
+ (IPC::ArgumentCoder<FontAttributes>::decodePlatformData): Deleted.
+
+ Remove some method stubs that are now unnecessary.
+
+ * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+ (fontOfSize):
+ * WebKit.xcodeproj/project.pbxproj:
+
2021-12-26 Sam Weinig <[email protected]>
Replace WebKit/CocoaColor.h with WebCore/ColorCocoa.h, not confusing at all
Deleted: trunk/Source/WebKit/Platform/cocoa/CocoaFont.h (287495 => 287496)
--- trunk/Source/WebKit/Platform/cocoa/CocoaFont.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Platform/cocoa/CocoaFont.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -1,40 +0,0 @@
-/*
-* Copyright (C) 2020 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 <wtf/Compiler.h>
-
-#if USE(APPKIT)
-OBJC_CLASS NSFont;
-OBJC_CLASS NSFontDescriptor;
-using CocoaFont = NSFont;
-using CocoaFontDescriptor = NSFontDescriptor;
-#else
-OBJC_CLASS UIFont;
-OBJC_CLASS UIFontDescriptor;
-using CocoaFont = UIFont;
-using CocoaFontDescriptor = UIFontDescriptor;
-#endif
Modified: trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm (287495 => 287496)
--- trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -29,11 +29,11 @@
#if PLATFORM(COCOA)
#import "ArgumentCodersCF.h"
-#import "CocoaFont.h"
#import "CoreTextHelpers.h"
#import <CoreText/CTFont.h>
#import <CoreText/CTFontDescriptor.h>
#import <WebCore/ColorCocoa.h>
+#import <WebCore/FontCocoa.h>
#import <wtf/BlockObjCExceptions.h>
#import <wtf/HashSet.h>
#import <wtf/cf/CFURLExtras.h>
Modified: trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h (287495 => 287496)
--- trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -25,7 +25,7 @@
#pragma once
-#import "CocoaFont.h"
+#import <WebCore/FontCocoa.h>
#import <wtf/RetainPtr.h>
#if USE(APPKIT)
@@ -36,6 +36,6 @@
namespace WebKit {
-CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size);
+WebCore::CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size);
}
Modified: trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm (287495 => 287496)
--- trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -31,12 +31,12 @@
namespace WebKit {
-CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size)
+WebCore::CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
- auto descriptor = [CocoaFontDescriptor fontDescriptorWithFontAttributes:attributes];
- return [CocoaFont fontWithDescriptor:descriptor size:size];
+ auto descriptor = [WebCore::CocoaFontDescriptor fontDescriptorWithFontAttributes:attributes];
+ return [WebCore::CocoaFont fontWithDescriptor:descriptor size:size];
END_BLOCK_OBJC_EXCEPTIONS
Modified: trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm (287495 => 287496)
--- trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -440,18 +440,6 @@
return true;
}
-void ArgumentCoder<WebCore::FontAttributes>::encodePlatformData(Encoder& encoder, const WebCore::FontAttributes& attributes)
-{
- encoder << attributes.font;
-}
-
-std::optional<WebCore::FontAttributes> ArgumentCoder<WebCore::FontAttributes>::decodePlatformData(Decoder& decoder, WebCore::FontAttributes& attributes)
-{
- if (!IPC::decode(decoder, attributes.font))
- return std::nullopt;
- return attributes;
-}
-
void ArgumentCoder<Ref<WebCore::Font>>::encodePlatformData(Encoder& encoder, const Ref<WebCore::Font>& font)
{
const auto& platformData = font->platformData();
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (287495 => 287496)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2021-12-31 23:33:52 UTC (rev 287496)
@@ -1071,6 +1071,31 @@
return decodeImage(decoder, image);
}
+void ArgumentCoder<RefPtr<Font>>::encode(Encoder& encoder, const RefPtr<Font>& font)
+{
+ encoder << !!font;
+ if (font)
+ encoder << Ref { *font };
+}
+
+std::optional<RefPtr<Font>> ArgumentCoder<RefPtr<Font>>::decode(Decoder& decoder)
+{
+ std::optional<bool> hasFont;
+ decoder >> hasFont;
+ if (!hasFont)
+ return std::nullopt;
+
+ if (!hasFont.value())
+ return std::make_optional(nullptr);
+
+ std::optional<Ref<Font>> font;
+ decoder >> font;
+ if (!font)
+ return std::nullopt;
+
+ return { WTFMove(*font) };
+}
+
void ArgumentCoder<Ref<Font>>::encode(Encoder& encoder, const Ref<WebCore::Font>& font)
{
encoder << font->origin();
@@ -2910,12 +2935,7 @@
encoder << attributes.backgroundColor << attributes.foregroundColor << attributes.fontShadow << attributes.hasUnderline << attributes.hasStrikeThrough << attributes.textLists;
encoder << attributes.horizontalAlignment;
encoder << attributes.subscriptOrSuperscript;
-
- if (attributes.encodingRequiresPlatformData()) {
- encoder << true;
- encodePlatformData(encoder, attributes);
- return;
- }
+ encoder << attributes.font;
}
std::optional<FontAttributes> ArgumentCoder<FontAttributes>::decode(Decoder& decoder)
@@ -2946,12 +2966,13 @@
if (!decoder.decode(attributes.subscriptOrSuperscript))
return std::nullopt;
- bool hasPlatformData;
- if (!decoder.decode(hasPlatformData))
+ std::optional<RefPtr<Font>> font;
+ decoder >> font;
+ if (!font)
return std::nullopt;
- if (hasPlatformData)
- return decodePlatformData(decoder, attributes);
+ attributes.font = WTFMove(*font);
+
return attributes;
}
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (287495 => 287496)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h 2021-12-31 23:33:52 UTC (rev 287496)
@@ -392,6 +392,11 @@
static WARN_UNUSED_RETURN bool decode(Decoder&, WebCore::Cursor&);
};
+template<> struct ArgumentCoder<RefPtr<WebCore::Font>> {
+ static void encode(Encoder&, const RefPtr<WebCore::Font>&);
+ static std::optional<RefPtr<WebCore::Font>> decode(Decoder&);
+};
+
template<> struct ArgumentCoder<Ref<WebCore::Font>> {
static void encode(Encoder&, const Ref<WebCore::Font>&);
static std::optional<Ref<WebCore::Font>> decode(Decoder&);
@@ -730,8 +735,6 @@
template<> struct ArgumentCoder<WebCore::FontAttributes> {
static void encode(Encoder&, const WebCore::FontAttributes&);
static std::optional<WebCore::FontAttributes> decode(Decoder&);
- static void encodePlatformData(Encoder&, const WebCore::FontAttributes&);
- static std::optional<WebCore::FontAttributes> decodePlatformData(Decoder&, WebCore::FontAttributes&);
};
#if ENABLE(ATTACHMENT_ELEMENT)
Modified: trunk/Source/WebKit/Shared/playstation/WebCoreArgumentCodersPlayStation.cpp (287495 => 287496)
--- trunk/Source/WebKit/Shared/playstation/WebCoreArgumentCodersPlayStation.cpp 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/playstation/WebCoreArgumentCodersPlayStation.cpp 2021-12-31 23:33:52 UTC (rev 287496)
@@ -27,23 +27,11 @@
#include "WebCoreArgumentCoders.h"
#include <WebCore/Font.h>
-#include <WebCore/FontAttributes.h>
namespace IPC {
using namespace WebCore;
-void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
-{
- ASSERT_NOT_REACHED();
-}
-
-std::optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
-{
- ASSERT_NOT_REACHED();
- return std::nullopt;
-}
-
void ArgumentCoder<Ref<Font>>::encodePlatformData(Encoder& encoder, const Ref<Font>& font)
{
ASSERT_NOT_REACHED();
Modified: trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp (287495 => 287496)
--- trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/soup/WebCoreArgumentCodersSoup.cpp 2021-12-31 23:33:52 UTC (rev 287496)
@@ -36,7 +36,6 @@
#include <WebCore/Credential.h>
#include <WebCore/DictionaryPopupInfo.h>
#include <WebCore/Font.h>
-#include <WebCore/FontAttributes.h>
#include <WebCore/ResourceError.h>
#include <WebCore/ResourceRequest.h>
#include <WebCore/ResourceResponse.h>
@@ -214,17 +213,6 @@
return true;
}
-void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
-{
- ASSERT_NOT_REACHED();
-}
-
-std::optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
-{
- ASSERT_NOT_REACHED();
- return std::nullopt;
-}
-
void ArgumentCoder<DictionaryPopupInfo>::encodePlatformData(Encoder&, const DictionaryPopupInfo&)
{
ASSERT_NOT_REACHED();
Modified: trunk/Source/WebKit/Shared/win/WebCoreArgumentCodersWin.cpp (287495 => 287496)
--- trunk/Source/WebKit/Shared/win/WebCoreArgumentCodersWin.cpp 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/Shared/win/WebCoreArgumentCodersWin.cpp 2021-12-31 23:33:52 UTC (rev 287496)
@@ -27,7 +27,6 @@
#include "WebCoreArgumentCoders.h"
#include <WebCore/Font.h>
-#include <WebCore/FontAttributes.h>
#include <WebCore/FontCache.h>
#include <WebCore/FontCustomPlatformData.h>
#include <WebCore/FontDescription.h>
@@ -37,17 +36,6 @@
using namespace WebCore;
-void ArgumentCoder<FontAttributes>::encodePlatformData(Encoder&, const FontAttributes&)
-{
- ASSERT_NOT_REACHED();
-}
-
-std::optional<FontAttributes> ArgumentCoder<FontAttributes>::decodePlatformData(Decoder&, FontAttributes&)
-{
- ASSERT_NOT_REACHED();
- return std::nullopt;
-}
-
template<> struct ArgumentCoder<LOGFONT> {
static void encode(Encoder& encoder, const LOGFONT& logFont)
{
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm (287495 => 287496)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm 2021-12-31 23:33:52 UTC (rev 287496)
@@ -26,9 +26,9 @@
#import "config.h"
#import "WKSafeBrowsingWarning.h"
-#import "CocoaFont.h"
#import "PageClient.h"
#import "SafeBrowsingWarning.h"
+#import <WebCore/FontCocoa.h>
#import <WebCore/LocalizedStrings.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <wtf/URL.h>
@@ -78,7 +78,7 @@
Body
};
-static CocoaFont *fontOfSize(WarningTextSize size)
+static WebCore::CocoaFont *fontOfSize(WarningTextSize size)
{
#if PLATFORM(MAC)
switch (size) {
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (287495 => 287496)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-12-31 20:08:22 UTC (rev 287495)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2021-12-31 23:33:52 UTC (rev 287496)
@@ -6446,7 +6446,6 @@
F4EB4AFC269CD23600D297AE /* OSStateSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSStateSPI.h; sourceTree = "<group>"; };
F4F59AD32065A5C9006CAA46 /* WKSelectMenuListViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKSelectMenuListViewController.mm; path = ios/forms/WKSelectMenuListViewController.mm; sourceTree = "<group>"; };
F4F59AD42065A5CA006CAA46 /* WKSelectMenuListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKSelectMenuListViewController.h; path = ios/forms/WKSelectMenuListViewController.h; sourceTree = "<group>"; };
- F4FE0A3C24635667002631E1 /* CocoaFont.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CocoaFont.h; sourceTree = "<group>"; };
F6113E24126CE1820057D0A7 /* APIUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIUserContentURLPattern.h; sourceTree = "<group>"; };
F6113E26126CE19B0057D0A7 /* WKUserContentURLPattern.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKUserContentURLPattern.cpp; sourceTree = "<group>"; };
F6113E27126CE19B0057D0A7 /* WKUserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKUserContentURLPattern.h; sourceTree = "<group>"; };
@@ -9167,7 +9166,6 @@
4450AEBE1DC3FAAC009943F2 /* cocoa */ = {
isa = PBXGroup;
children = (
- F4FE0A3C24635667002631E1 /* CocoaFont.h */,
4482734624528F6000A95493 /* CocoaImage.h */,
BCE0937614FB128B001138D9 /* LayerHostingContext.h */,
BCE0937514FB128B001138D9 /* LayerHostingContext.mm */,