Bug 211527 - Use CocoaColor in more places instead of platform defines
Summary: Use CocoaColor in more places instead of platform defines
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: DoNotImportToRadar
Depends on:
Blocks:
 
Reported: 2020-05-06 12:46 PDT by Wenson Hsieh
Modified: 2020-05-06 16:50 PDT (History)
5 users (show)

See Also:


Attachments
Patch (17.22 KB, patch)
2020-05-06 14:54 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Fix bug title (17.22 KB, patch)
2020-05-06 14:56 PDT, Wenson Hsieh
darin: review+
Details | Formatted Diff | Diff
Patch for landing (18.67 KB, patch)
2020-05-06 15:48 PDT, Wenson Hsieh
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (18.67 KB, patch)
2020-05-06 16:26 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wenson Hsieh 2020-05-06 12:46:34 PDT
SSIA
Comment 1 Wenson Hsieh 2020-05-06 14:54:10 PDT Comment hidden (obsolete)
Comment 2 Wenson Hsieh 2020-05-06 14:56:42 PDT
Created attachment 398665 [details]
Fix bug title
Comment 3 Darin Adler 2020-05-06 15:05:48 PDT
Comment on attachment 398665 [details]
Fix bug title

View in context: https://bugs.webkit.org/attachment.cgi?id=398665&action=review

Nice clean up. This is the kind of abstraction I really like.

Not sure each of these (CocoaColor, CocoaFont/Descriptor, CocoaImage) should have its own header. Seems like they could share.

> Source/WebKit/Platform/cocoa/CocoaFont.h:29
> +@class NSFont, NSFontDescriptor;

Didn’t even know you could use commas in these! Not sure I would have.

> Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:103
> +    if ([object isKindOfClass:[CocoaColor class]])

I’m tempted in new code to write ".class" instead.

> Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:434
> +        encodeColorInternal(encoder, static_cast<CocoaColor *>(object));

Seems like for the future we need a Objective-C pointer cast that, at least in debug builds, checks the class.

> Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.h:48
>  using ViewType = NSView;
>  using RectType = NSRect;

Other candidates.

> Source/WebKit/UIProcess/Cocoa/WKSafeBrowsingWarning.mm:57
>  using TextViewType = NSTextView;
>  using ButtonType = NSButton;
>  using AlignmentType = NSLayoutAttribute;
>  using SizeType = NSSize;

Other candidates.
Comment 4 Tim Horton 2020-05-06 15:06:13 PDT
Comment on attachment 398665 [details]
Fix bug title

View in context: https://bugs.webkit.org/attachment.cgi?id=398665&action=review

> Source/WebKit/Platform/cocoa/CocoaFont.h:29
> +@class NSFont, NSFontDescriptor;

1) I know these aren't variable declarations but the multi-line thing still looks surprising.
2) Why not OBJC_CLASS in case these get included in C++ code? (which seems ... likely)
Comment 5 Wenson Hsieh 2020-05-06 15:15:15 PDT
Comment on attachment 398665 [details]
Fix bug title

View in context: https://bugs.webkit.org/attachment.cgi?id=398665&action=review

>>> Source/WebKit/Platform/cocoa/CocoaFont.h:29
>>> +@class NSFont, NSFontDescriptor;
>> 
>> Didn’t even know you could use commas in these! Not sure I would have.
> 
> 1) I know these aren't variable declarations but the multi-line thing still looks surprising.
> 2) Why not OBJC_CLASS in case these get included in C++ code? (which seems ... likely)

(1) We use it in a few public headers! (JSContext.h, WKDOMRange.h)
(2) Good point! I’ll change these to be OBJC_CLASS instead.

>> Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:103
>> +    if ([object isKindOfClass:[CocoaColor class]])
> 
> I’m tempted in new code to write ".class" instead.

👍🏻 Will make that change here, and below (CocoaFont.class).
Comment 6 Wenson Hsieh 2020-05-06 15:22:02 PDT
(In reply to Wenson Hsieh from comment #5)
> Comment on attachment 398665 [details]
> Fix bug title
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=398665&action=review
> 
> >>> Source/WebKit/Platform/cocoa/CocoaFont.h:29
> >>> +@class NSFont, NSFontDescriptor;
> >> 
> >> Didn’t even know you could use commas in these! Not sure I would have.
> > 
> > 1) I know these aren't variable declarations but the multi-line thing still looks surprising.
> > 2) Why not OBJC_CLASS in case these get included in C++ code? (which seems ... likely)
> 
> (1) We use it in a few public headers! (JSContext.h, WKDOMRange.h)
> (2) Good point! I’ll change these to be OBJC_CLASS instead.

I’m also going to change existing `@class`s in CocoaImage.h to be OBJC_CLASS as well, for consistency.

> 
> >> Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:103
> >> +    if ([object isKindOfClass:[CocoaColor class]])
> > 
> > I’m tempted in new code to write ".class" instead.
> 
> 👍🏻 Will make that change here, and below (CocoaFont.class).
Comment 7 Wenson Hsieh 2020-05-06 15:46:12 PDT
Comment on attachment 398665 [details]
Fix bug title

View in context: https://bugs.webkit.org/attachment.cgi?id=398665&action=review

>>>> Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm:103
>>>> +    if ([object isKindOfClass:[CocoaColor class]])
>>> 
>>> I’m tempted in new code to write ".class" instead.
>> 
>> 👍🏻 Will make that change here, and below (CocoaFont.class).
> 
> 

Unfortunately, I can’t make this change since CocoaColor is a “using" declaration :(

I put together this simple snippet in a standalone test case:

@class NSString;
using MyString = NSString;

static Class foo()
{
    return MyString.class;
}

…attempting to compile this results in:

/Volumes/…/foo.mm:16:12: error: expected identifier or '('
    return MyString.class;
           ^
1 error generated.
Comment 8 Wenson Hsieh 2020-05-06 15:48:19 PDT Comment hidden (obsolete)
Comment 9 EWS 2020-05-06 16:25:50 PDT Comment hidden (obsolete)
Comment 10 Wenson Hsieh 2020-05-06 16:26:56 PDT
Created attachment 398681 [details]
Patch for landing
Comment 11 EWS 2020-05-06 16:50:23 PDT
Committed r261259: <https://trac.webkit.org/changeset/261259>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 398681 [details].