Bug 189918 - Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
Summary: Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Wenson Hsieh
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-09-24 09:18 PDT by Wenson Hsieh
Modified: 2018-09-24 20:16 PDT (History)
6 users (show)

See Also:


Attachments
Patch (37.04 KB, patch)
2018-09-24 09:37 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Rebase on trunk (36.81 KB, patch)
2018-09-24 10:17 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Fix 32-bit macOS build (36.82 KB, patch)
2018-09-24 10:42 PDT, Wenson Hsieh
thorton: review+
Details | Formatted Diff | Diff
Patch for EWS (49.46 KB, patch)
2018-09-24 14:11 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch for EWS #2 (51.19 KB, patch)
2018-09-24 14:48 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch for EWS #2.1 (50.93 KB, patch)
2018-09-24 14:49 PDT, Wenson Hsieh
no flags Details | Formatted Diff | Diff
Patch for EWS #2.1 (rebase on trunk) (49.02 KB, patch)
2018-09-24 14:54 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 2018-09-24 09:18:35 PDT
Work towards <rdar://problem/44648705>
Comment 1 Wenson Hsieh 2018-09-24 09:37:41 PDT
Created attachment 350646 [details]
Patch
Comment 2 Wenson Hsieh 2018-09-24 10:17:20 PDT
Created attachment 350651 [details]
Rebase on trunk
Comment 3 Wenson Hsieh 2018-09-24 10:42:39 PDT
Created attachment 350653 [details]
Fix 32-bit macOS build
Comment 4 Tim Horton 2018-09-24 11:52:10 PDT
Comment on attachment 350653 [details]
Fix 32-bit macOS build

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

> Source/WebCore/editing/Editor.cpp:3895
> +    if (verticalAlign == VerticalAlign::Sub)
> +        attributes.subscriptOrSuperscript = SubscriptOrSuperscript::Subscript;
> +
> +    if (verticalAlign == VerticalAlign::Super)
> +        attributes.subscriptOrSuperscript = SubscriptOrSuperscript::Superscript;

Should this be a switch? Or do we elsewhere have a function that translates between the two?

(coming back to this, we don't, because it's new)

> Source/WebCore/editing/FontAttributes.h:39
> +#if PLATFORM(COCOA)
> +OBJC_CLASS NSDictionary;
> +#endif
> +
> +#if PLATFORM(MAC)
> +OBJC_CLASS NSFont;
> +#elif PLATFORM(IOS)
> +OBJC_CLASS UIFont;
> +#endif

None of these #ifs are really necessary.

> Source/WebCore/editing/FontShadow.h:47
> +    double width { 0 };
> +    double height { 0 };

FloatSize offset; ?

> Source/WebCore/editing/cocoa/FontAttributesCocoa.mm:54
> +        [attributes setObject:font.get() forKey:NSFontAttributeName];

Modern dictionary syntax?

> Source/WebCore/editing/cocoa/FontShadowCocoa.mm:42
> +    [shadow setShadowColor:nsColor(color)];

Wouldn't it be nice if you had your platformColor thing here. I feel like we must have something similar somewhere.
Comment 5 Wenson Hsieh 2018-09-24 12:33:15 PDT
Comment on attachment 350653 [details]
Fix 32-bit macOS build

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

>> Source/WebCore/editing/Editor.cpp:3895
>> +        attributes.subscriptOrSuperscript = SubscriptOrSuperscript::Superscript;
> 
> Should this be a switch? Or do we elsewhere have a function that translates between the two?
> 
> (coming back to this, we don't, because it's new)

Interestingly enough, it was a switch before the move! I made this just use if statements instead because I thought it make it clearer that it's just these two alignment types that make their way into FontAttributes — I'll turn this back into a switch statement.

>> Source/WebCore/editing/FontAttributes.h:39
>> +#endif
> 
> None of these #ifs are really necessary.

Good point — removed.

>> Source/WebCore/editing/FontShadow.h:47
>> +    double height { 0 };
> 
> FloatSize offset; ?

👍

>> Source/WebCore/editing/cocoa/FontAttributesCocoa.mm:54
>> +        [attributes setObject:font.get() forKey:NSFontAttributeName];
> 
> Modern dictionary syntax?

👍

(Also, I made attributes a NSMutableDictionary * instead of a RetainPtr<NSMutableDictionary>, since RetainPtr doesn't support operator[])

>> Source/WebCore/editing/cocoa/FontShadowCocoa.mm:42
>> +    [shadow setShadowColor:nsColor(color)];
> 
> Wouldn't it be nice if you had your platformColor thing here. I feel like we must have something similar somewhere.

Now that you mention it, HTMLConverter does a similar dance, but uses _disambiguated_due_to_CIImage_colorWithCGColor instead (which behaves identically to colorWithCGColor, and as its name suggests, seems to exist to avoid a name conflict with CIColor). Funny enough, the helper there is also called "_platformColor".

I think we should abstract this out into a separate helper so we can use it from these call sites, but I'm not sure where to put it. Perhaps a new ColorCocoa.h?
Comment 6 Wenson Hsieh 2018-09-24 14:11:08 PDT
Created attachment 350681 [details]
Patch for EWS
Comment 7 Wenson Hsieh 2018-09-24 14:48:11 PDT
Created attachment 350692 [details]
Patch for EWS #2
Comment 8 Wenson Hsieh 2018-09-24 14:49:41 PDT
Created attachment 350693 [details]
Patch for EWS #2.1
Comment 9 Wenson Hsieh 2018-09-24 14:54:26 PDT
Created attachment 350697 [details]
Patch for EWS #2.1 (rebase on trunk)
Comment 10 WebKit Commit Bot 2018-09-24 17:17:36 PDT
Comment on attachment 350697 [details]
Patch for EWS #2.1 (rebase on trunk)

Clearing flags on attachment: 350697

Committed r236445: <https://trac.webkit.org/changeset/236445>