Diff
Modified: trunk/Source/WebKit/ChangeLog (261258 => 261259)
--- trunk/Source/WebKit/ChangeLog 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/ChangeLog 2020-05-06 23:50:19 UTC (rev 261259)
@@ -1,3 +1,43 @@
+2020-05-06 Wenson Hsieh <[email protected]>
+
+ Use CocoaColor in more places instead of platform defines
+ https://bugs.webkit.org/show_bug.cgi?id=211527
+
+ Reviewed by Darin Adler and Tim Horton.
+
+ Use CocoaColor (added in r261247) in more places, and also introduce `CocoaFont.h` and use it to simplify some
+ existing code that uses platform ifdefs for UIFont, NSFont, UIFontDescriptor and NSFontDescriptor.
+
+ No change in behavior.
+
+ * Platform/cocoa/CocoaColor.h:
+ * Platform/cocoa/CocoaFont.h: Copied from Source/WebKit/Platform/cocoa/CocoaColor.h.
+ * Platform/cocoa/CocoaImage.h:
+
+ Change `@class`es to `OBJC_CLASS`, so that this header can be safely imported in C++ code.
+
+ * Shared/Cocoa/ArgumentCodersCocoa.mm:
+ (IPC::typeFromObject):
+ (IPC::isSerializableValue):
+ (IPC::encodeFontInternal):
+ (IPC::encodeObject):
+ (IPC::platformColorClass): Deleted.
+ (IPC::platformFontClass): Deleted.
+ * Shared/Cocoa/CoreTextHelpers.h:
+ * Shared/Cocoa/CoreTextHelpers.mm:
+ (WebKit::fontWithAttributes):
+ * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+ * UIProcess/Cocoa/WKSafeBrowsingWarning.h:
+ * UIProcess/Cocoa/WKSafeBrowsingWarning.mm:
+ (fontOfSize):
+ (colorForItem):
+ (-[WKSafeBrowsingBox setSafeBrowsingBackgroundColor:]):
+ (-[WKSafeBrowsingWarning showDetailsClicked]):
+ (-[WKSafeBrowsingTextView initWithAttributedString:forWarning:]):
+ * UIProcess/Cocoa/WebViewImpl.mm:
+ (WebKit::WebViewImpl::updateFontManagerIfNeeded):
+ * WebKit.xcodeproj/project.pbxproj:
+
2020-05-06 Alex Christensen <[email protected]>
Reduce IPC overhead for message receiver name and message name to 2 bytes
Modified: trunk/Source/WebKit/Platform/cocoa/CocoaColor.h (261258 => 261259)
--- trunk/Source/WebKit/Platform/cocoa/CocoaColor.h 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Platform/cocoa/CocoaColor.h 2020-05-06 23:50:19 UTC (rev 261259)
@@ -25,10 +25,12 @@
#pragma once
+#include <wtf/Compiler.h>
+
#if USE(APPKIT)
-@class NSColor;
+OBJC_CLASS NSColor;
using CocoaColor = NSColor;
#else
-@class UIColor;
+OBJC_CLASS UIColor;
using CocoaColor = UIColor;
#endif
Copied: trunk/Source/WebKit/Platform/cocoa/CocoaFont.h (from rev 261258, trunk/Source/WebKit/Platform/cocoa/CocoaColor.h) (0 => 261259)
--- trunk/Source/WebKit/Platform/cocoa/CocoaFont.h (rev 0)
+++ trunk/Source/WebKit/Platform/cocoa/CocoaFont.h 2020-05-06 23:50:19 UTC (rev 261259)
@@ -0,0 +1,40 @@
+/*
+* 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/Platform/cocoa/CocoaImage.h (261258 => 261259)
--- trunk/Source/WebKit/Platform/cocoa/CocoaImage.h 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Platform/cocoa/CocoaImage.h 2020-05-06 23:50:19 UTC (rev 261259)
@@ -23,10 +23,12 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <wtf/Compiler.h>
+
#if USE(APPKIT)
-@class NSImage;
+OBJC_CLASS NSImage;
using CocoaImage = NSImage;
#else
-@class UIImage;
+OBJC_CLASS UIImage;
using CocoaImage = UIImage;
#endif
Modified: trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm (261258 => 261259)
--- trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm 2020-05-06 23:50:19 UTC (rev 261259)
@@ -29,6 +29,8 @@
#if PLATFORM(COCOA)
#import "ArgumentCodersCF.h"
+#import "CocoaColor.h"
+#import "CocoaFont.h"
#import "CoreTextHelpers.h"
#import <CoreText/CTFont.h>
#import <CoreText/CTFontDescriptor.h>
@@ -47,14 +49,6 @@
#import <UIKit/UIFontDescriptor.h>
#endif
-#if USE(APPKIT)
-using PlatformColor = NSColor;
-using PlatformFont = NSFont;
-#else
-using PlatformColor = UIColor;
-using PlatformFont = UIFont;
-#endif
-
#if HAVE(NSFONT_WITH_OPTICAL_SIZING_BUG)
@interface WKSecureCodingFontAttributeNormalizer : NSObject <NSKeyedArchiverDelegate>
@@ -99,34 +93,6 @@
#pragma mark - Helpers
-static Class platformColorClass()
-{
- static Class colorClass;
- static std::once_flag flag;
- std::call_once(flag, [] {
-#if USE(APPKIT)
- colorClass = NSClassFromString(@"NSColor");
-#else
- colorClass = NSClassFromString(@"UIColor");
-#endif
- });
- return colorClass;
-}
-
-static Class platformFontClass()
-{
- static Class fontClass;
- static std::once_flag flag;
- std::call_once(flag, [] {
-#if USE(APPKIT)
- fontClass = NSClassFromString(@"NSFont");
-#else
- fontClass = NSClassFromString(@"UIFont");
-#endif
- });
- return fontClass;
-}
-
static NSType typeFromObject(id object)
{
ASSERT(object);
@@ -134,7 +100,7 @@
// Specific classes handled.
if ([object isKindOfClass:[NSArray class]])
return NSType::Array;
- if ([object isKindOfClass:platformColorClass()])
+ if ([object isKindOfClass:[CocoaColor class]])
return NSType::Color;
if ([object isKindOfClass:[NSData class]])
return NSType::Data;
@@ -142,7 +108,7 @@
return NSType::Date;
if ([object isKindOfClass:[NSDictionary class]])
return NSType::Dictionary;
- if ([object isKindOfClass:platformFontClass()])
+ if ([object isKindOfClass:[CocoaFont class]])
return NSType::Font;
if ([object isKindOfClass:[NSNumber class]])
return NSType::Number;
@@ -168,7 +134,7 @@
static inline bool isSerializableValue(id value)
{
- if ([value isKindOfClass:[PlatformFont class]])
+ if ([value isKindOfClass:[CocoaFont class]])
return isSerializableFont((__bridge CTFontRef)value);
return typeFromObject(value) != NSType::Unknown;
}
@@ -339,7 +305,7 @@
#pragma mark - NSFont / UIFont
-static inline void encodeFontInternal(Encoder& encoder, PlatformFont *font)
+static inline void encodeFontInternal(Encoder& encoder, CocoaFont *font)
{
encode(encoder, font.fontDescriptor.fontAttributes);
}
@@ -465,13 +431,13 @@
encodeArrayInternal(encoder, static_cast<NSArray *>(object));
return;
case NSType::Color:
- encodeColorInternal(encoder, static_cast<PlatformColor *>(object));
+ encodeColorInternal(encoder, static_cast<CocoaColor *>(object));
return;
case NSType::Dictionary:
encodeDictionaryInternal(encoder, static_cast<NSDictionary *>(object));
return;
case NSType::Font:
- encodeFontInternal(encoder, static_cast<PlatformFont *>(object));
+ encodeFontInternal(encoder, static_cast<CocoaFont *>(object));
return;
case NSType::Number:
encodeNumberInternal(encoder, static_cast<NSNumber *>(object));
Modified: trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h (261258 => 261259)
--- trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h 2020-05-06 23:50:19 UTC (rev 261259)
@@ -25,6 +25,9 @@
#pragma once
+#import "CocoaFont.h"
+#import <wtf/RetainPtr.h>
+
#if USE(APPKIT)
#import <AppKit/AppKit.h>
#else
@@ -31,16 +34,8 @@
#import <UIKit/UIKit.h>
#endif
-#import <wtf/RetainPtr.h>
-
namespace WebKit {
-#if USE(APPKIT)
-using PlatformFont = NSFont;
-#else
-using PlatformFont = UIFont;
-#endif
+CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size);
-PlatformFont *fontWithAttributes(NSDictionary *attributes, CGFloat size);
-
}
Modified: trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm (261258 => 261259)
--- trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm 2020-05-06 23:50:19 UTC (rev 261259)
@@ -29,15 +29,9 @@
#import <pal/spi/cocoa/CoreTextSPI.h>
#import <wtf/BlockObjCExceptions.h>
-#if USE(APPKIT)
-using PlatformFontDescriptor = NSFontDescriptor;
-#else
-using PlatformFontDescriptor = UIFontDescriptor;
-#endif
-
namespace WebKit {
-PlatformFont *fontWithAttributes(NSDictionary *attributes, CGFloat size)
+CocoaFont *fontWithAttributes(NSDictionary *attributes, CGFloat size)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -51,12 +45,12 @@
}
}
- auto descriptor = [PlatformFontDescriptor fontDescriptorWithFontAttributes:mutableDictionary.get()];
+ auto descriptor = [CocoaFontDescriptor fontDescriptorWithFontAttributes:mutableDictionary.get()];
#else
- auto descriptor = [PlatformFontDescriptor fontDescriptorWithFontAttributes:attributes];
+ auto descriptor = [CocoaFontDescriptor fontDescriptorWithFontAttributes:attributes];
#endif
- return [PlatformFont fontWithDescriptor:descriptor size:size];
+ return [CocoaFont fontWithDescriptor:descriptor size:size];
END_BLOCK_OBJC_EXCEPTIONS
Modified: trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm (261258 => 261259)
--- trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm 2020-05-06 23:50:19 UTC (rev 261259)
@@ -27,6 +27,7 @@
#import "WebCoreArgumentCoders.h"
#import "ArgumentCodersCocoa.h"
+#import "CocoaFont.h"
#import <WebCore/AttributedString.h>
#import <WebCore/DictionaryPopupInfo.h>
#import <WebCore/Font.h>
@@ -525,12 +526,6 @@
return attributes;
}
-#if PLATFORM(IOS_FAMILY)
-#define CocoaFont UIFont
-#else
-#define CocoaFont NSFont
-#endif
-
void ArgumentCoder<FontHandle>::encodePlatformData(Encoder& encoder, const FontHandle& handle)
{
auto ctFont = handle.font && !handle.font->fontFaceData() ? handle.font->getCTFont() : nil;
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h (261258 => 261259)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h 2020-05-06 23:50:19 UTC (rev 261259)
@@ -23,6 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#import "CocoaColor.h"
#import "WKFoundation.h"
#import <wtf/CompletionHandler.h>
#import <wtf/RefPtr.h>
@@ -45,20 +46,18 @@
#if PLATFORM(MAC)
using ViewType = NSView;
using RectType = NSRect;
-using ColorType = NSColor;
#else
using ViewType = UIView;
using RectType = CGRect;
-using ColorType = UIColor;
#endif
@interface WKSafeBrowsingBox : ViewType {
@package
#if PLATFORM(MAC)
- RetainPtr<ColorType> _backgroundColor;
+ RetainPtr<CocoaColor> _backgroundColor;
#endif
}
-- (void)setSafeBrowsingBackgroundColor:(ColorType *)color;
+- (void)setSafeBrowsingBackgroundColor:(CocoaColor *)color;
@end
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm (261258 => 261259)
--- trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm 2020-05-06 23:50:19 UTC (rev 261259)
@@ -26,6 +26,7 @@
#import "config.h"
#import "WKSafeBrowsingWarning.h"
+#import "CocoaFont.h"
#import "PageClient.h"
#import "SafeBrowsingWarning.h"
#import <WebCore/LocalizedStrings.h>
@@ -50,13 +51,11 @@
#endif
#if PLATFORM(MAC)
-using FontType = NSFont;
using TextViewType = NSTextView;
using ButtonType = NSButton;
using AlignmentType = NSLayoutAttribute;
using SizeType = NSSize;
#else
-using FontType = UIFont;
using TextViewType = UITextView;
using ButtonType = UIButton;
using AlignmentType = UIStackViewAlignment;
@@ -78,7 +77,7 @@
Body
};
-static FontType *fontOfSize(WarningTextSize size)
+static CocoaFont *fontOfSize(WarningTextSize size)
{
#if PLATFORM(MAC)
switch (size) {
@@ -103,12 +102,12 @@
#endif
}
-static ColorType *colorForItem(WarningItem item, ViewType *warning)
+static CocoaColor *colorForItem(WarningItem item, ViewType *warning)
{
ASSERT([warning isKindOfClass:[WKSafeBrowsingWarning class]]);
#if PLATFORM(MAC)
- auto colorNamed = [] (NSString *name) -> ColorType* {
+ auto colorNamed = [] (NSString *name) -> CocoaColor * {
#if HAVE(SAFE_BROWSING)
return [NSColor colorNamed:name bundle:[NSBundle bundleWithIdentifier:@"com.apple.WebKit"]];
#else
@@ -261,7 +260,7 @@
@implementation WKSafeBrowsingBox
-- (void)setSafeBrowsingBackgroundColor:(ColorType *)color
+- (void)setSafeBrowsingBackgroundColor:(CocoaColor *)color
{
#if PLATFORM(MAC)
_backgroundColor = color;
@@ -435,7 +434,7 @@
#endif
WKSafeBrowsingBox *line = [[WKSafeBrowsingBox new] autorelease];
- [line setSafeBrowsingBackgroundColor:[ColorType lightGrayColor]];
+ [line setSafeBrowsingBackgroundColor:[CocoaColor lightGrayColor]];
for (ViewType *view in @[details, bottom, line])
view.translatesAutoresizingMaskIntoConstraints = NO;
@@ -570,7 +569,7 @@
self->_warning = warning;
self.delegate = warning;
- ColorType *foregroundColor = colorForItem(WarningItem::MessageText, warning);
+ CocoaColor *foregroundColor = colorForItem(WarningItem::MessageText, warning);
NSMutableAttributedString *string = [[attributedString mutableCopy] autorelease];
[string addAttributes:@{ NSForegroundColorAttributeName : foregroundColor } range:NSMakeRange(0, string.length)];
[self setBackgroundColor:colorForItem(WarningItem::BoxBackground, warning)];
Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (261258 => 261259)
--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm 2020-05-06 23:50:19 UTC (rev 261259)
@@ -2889,7 +2889,7 @@
if (!attributeDictionary)
return;
- PlatformFont *font = fontWithAttributes(attributeDictionary, fontSize);
+ auto font = fontWithAttributes(attributeDictionary, fontSize);
if (!font)
return;
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (261258 => 261259)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2020-05-06 23:16:14 UTC (rev 261258)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2020-05-06 23:50:19 UTC (rev 261259)
@@ -5374,6 +5374,7 @@
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>"; };
F4FE0A3A24632B10002631E1 /* CocoaColor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CocoaColor.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>"; };
@@ -7687,6 +7688,7 @@
isa = PBXGroup;
children = (
F4FE0A3A24632B10002631E1 /* CocoaColor.h */,
+ F4FE0A3C24635667002631E1 /* CocoaFont.h */,
4482734624528F6000A95493 /* CocoaImage.h */,
BCE0937614FB128B001138D9 /* LayerHostingContext.h */,
BCE0937514FB128B001138D9 /* LayerHostingContext.mm */,