⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286630 in webkit


Ignore:
Timestamp:
Dec 7, 2021, 4:40:21 PM (5 years ago)
Author:
Devin Rousso
Message:

Add helper methods to WebCore::FontShadow for serializing to CSS and converting to NSShadow
https://bugs.webkit.org/show_bug.cgi?id=233938

Source/WebCore:

Implementing -pasteFont: <https://webkit.org/b/191379> requires that we convert native
font attribute data into objects understandable by WebCore, one of which is a NSShadow.
These helpers will make it easier to parse the NSShadow and convert it to a CSS value that
we will use to override the selection's CSS text-shadow.

No change in behavior.

Reviewed by Wenson Hsieh.

Tests: FontShadow.InvalidColor

FontShadow.NoOffsetOrBlurRadius
FontShadow.NoOffset
FontShadow.NegativeOffset
FontShadow.NoBlurRadius
FontShadow.NegativeBlurRadius
FontShadow.AllNegative

  • editing/FontShadow.h:
  • editing/FontShadow.cpp: Added.

(WebCore::serializationForCSS):

  • editing/cocoa/FontShadowCocoa.mm:

(WebCore::fontShadowFromNSShadow): Added.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:

Tools:

Reviewed by Wenson Hsieh.

  • TestWebKitAPI/Tests/WebCore/FontShadowTests.cpp: Added.

(TestWebKitAPI::TEST.FontShadow.InvalidColor):
(TestWebKitAPI::TEST.FontShadow.NoOffsetOrBlurRadius):
(TestWebKitAPI::TEST.FontShadow.NoOffset):
(TestWebKitAPI::TEST.FontShadow.NegativeOffset):
(TestWebKitAPI::TEST.FontShadow.NoBlurRadius):
(TestWebKitAPI::TEST.FontShadow.NegativeBlurRadius):
(TestWebKitAPI::TEST.FontShadow.AllNegative):

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
Location:
trunk
Files:
1 added
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286628 r286630  
     12021-12-07  Devin Rousso  <drousso@apple.com>
     2
     3        Add helper methods to `WebCore::FontShadow` for serializing to CSS and converting to `NSShadow`
     4        https://bugs.webkit.org/show_bug.cgi?id=233938
     5
     6        Implementing `-pasteFont:` <https://webkit.org/b/191379> requires that we convert native
     7        font attribute data into objects understandable by WebCore, one of which is a `NSShadow`.
     8        These helpers will make it easier to parse the `NSShadow` and convert it to a CSS value that
     9        we will use to override the selection's CSS `text-shadow`.
     10
     11        No change in behavior.
     12
     13        Reviewed by Wenson Hsieh.
     14
     15        Tests: FontShadow.InvalidColor
     16               FontShadow.NoOffsetOrBlurRadius
     17               FontShadow.NoOffset
     18               FontShadow.NegativeOffset
     19               FontShadow.NoBlurRadius
     20               FontShadow.NegativeBlurRadius
     21               FontShadow.AllNegative
     22
     23        * editing/FontShadow.h:
     24        * editing/FontShadow.cpp: Added.
     25        (WebCore::serializationForCSS):
     26        * editing/cocoa/FontShadowCocoa.mm:
     27        (WebCore::fontShadowFromNSShadow): Added.
     28
     29        * Sources.txt:
     30        * WebCore.xcodeproj/project.pbxproj:
     31
    1322021-12-07  Yoshiaki Jitsukawa  <yoshiaki.jitsukawa@sony.com>
    233
  • trunk/Source/WebCore/Sources.txt

    r286596 r286630  
    10971097editing/EditorCommand.cpp
    10981098editing/FontAttributeChanges.cpp
     1099editing/FontShadow.cpp
    10991100editing/FormatBlockCommand.cpp
    11001101editing/FrameSelection.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r286596 r286630  
    1766217662                F48B7D5225C341E6009E75DD /* TextRecognitionResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextRecognitionResult.h; sourceTree = "<group>"; };
    1766317663                F48D2A6A215623B400C6752B /* FontShadow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontShadow.h; sourceTree = "<group>"; };
     17664                F48D2A6A215623B400C6752C /* FontShadow.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontShadow.cpp; sourceTree = "<group>"; };
    1766417665                F48D2A712156DC0A00C6752B /* FontAttributes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributes.h; sourceTree = "<group>"; };
    1766517666                F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontAttributesCocoa.mm; sourceTree = "<group>"; };
     
    2503425035                                F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */,
    2503525036                                F48D2A712156DC0A00C6752B /* FontAttributes.h */,
     25037                                F48D2A6A215623B400C6752C /* FontShadow.cpp */,
    2503625038                                F48D2A6A215623B400C6752B /* FontShadow.h */,
    2503725039                                D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */,
     
    3351633518                                3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,
    3351733519                                F55B3DB41251F12D003EF269 /* ColorInputType.h in Headers */,
     33520                                BC3A00C82754496D0047C0E5 /* ColorInterpolation.h in Headers */,
    3351833521                                BC4A23EC25EC160200AAC630 /* ColorLuminance.h in Headers */,
    3351933522                                EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
    3352033523                                7CAC6AE9247F082F00E61D59 /* ColorMatrix.h in Headers */,
    3352133524                                BC10137C25C3624B00DC773C /* ColorModels.h in Headers */,
     33525                                BCB2F88E275BEE58007231BF /* ColorNormalization.h in Headers */,
    3352233526                                7CD1E69324ABF6240089C419 /* ColorSerialization.h in Headers */,
    3352333527                                9382DF5810A8D5C900925652 /* ColorSpace.h in Headers */,
     
    3624536249                                1DBC1B562347B3D200B901AF /* PictureInPictureObserver.h in Headers */,
    3624636250                                1D2C82B7236A3F6A0055D6C5 /* PictureInPictureSupport.h in Headers */,
    36247                                 BC3A00C82754496D0047C0E5 /* ColorInterpolation.h in Headers */,
    3624836251                                1D2F8E062344752300993B68 /* PictureInPictureWindow.h in Headers */,
    3624936252                                5758597C23A1FCF300C74572 /* Pin.h in Headers */,
     
    3667036673                                078E092017D14D1C00420AA1 /* RTCDTMFSender.h in Headers */,
    3667136674                                078E092117D14D1C00420AA1 /* RTCDTMFToneChangeEvent.h in Headers */,
    36672                                 BCB2F88E275BEE58007231BF /* ColorNormalization.h in Headers */,
    3667336675                                41E6D71B26EA1A4600B765D6 /* RTCError.h in Headers */,
    3667436676                                41AB979526E75A2E007C0FE6 /* RTCErrorDetailType.h in Headers */,
  • trunk/Source/WebCore/editing/FontShadow.cpp

    r286629 r286630  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "config.h"
    27 #import "FontShadow.h"
     26#include "config.h"
     27#include "FontShadow.h"
    2828
    29 #import "ColorCocoa.h"
    30 #import "ColorMac.h"
    31 
    32 #if PLATFORM(IOS_FAMILY)
    33 #import <pal/ios/UIKitSoftLink.h>
    34 #endif
     29#include "ColorSerialization.h"
     30#include <wtf/text/StringBuilder.h>
    3531
    3632namespace WebCore {
    3733
    38 RetainPtr<NSShadow> FontShadow::createShadow() const
     34String serializationForCSS(const FontShadow& shadow)
    3935{
    40 #if USE(APPKIT)
    41     auto shadow = adoptNS([NSShadow new]);
    42 #elif PLATFORM(IOS_FAMILY)
    43     auto shadow = adoptNS([PAL::getNSShadowClass() new]);
    44 #endif
    45     [shadow setShadowColor:cocoaColor(color).get()];
    46     [shadow setShadowOffset:offset];
    47     [shadow setShadowBlurRadius:blurRadius];
    48     return shadow;
     36    if (shadow.offset.isZero() && !shadow.blurRadius)
     37        return "none"_s;
     38
     39    if (!shadow.color.isValid())
     40        return "none"_s;
     41
     42    StringBuilder builder;
     43    builder.append(shadow.offset.width(), "px ");
     44    builder.append(shadow.offset.height(), "px ");
     45    builder.append(serializationForCSS(shadow.color));
     46    if (shadow.blurRadius)
     47        builder.append(" ", shadow.blurRadius, "px");
     48    return builder.toString();
    4949}
    5050
    51 }
     51} // namespace WebCore
  • trunk/Source/WebCore/editing/FontShadow.h

    r260078 r286630  
    2929#include "FloatSize.h"
    3030#include <wtf/RetainPtr.h>
     31#include <wtf/text/WTFString.h>
    3132
    3233#if PLATFORM(COCOA)
     
    7071}
    7172
     73#if PLATFORM(COCOA)
     74WEBCORE_EXPORT FontShadow fontShadowFromNSShadow(NSShadow *);
     75#endif
     76
     77WEBCORE_EXPORT String serializationForCSS(const FontShadow&);
     78
    7279} // namespace WebCore
  • trunk/Source/WebCore/editing/cocoa/FontShadowCocoa.mm

    r284630 r286630  
    4949}
    5050
     51FontShadow fontShadowFromNSShadow(NSShadow *shadow)
     52{
     53    return {
     54        colorFromCocoaColor(shadow.shadowColor),
     55        FloatSize(shadow.shadowOffset),
     56        shadow.shadowBlurRadius,
     57    };
    5158}
     59
     60}
  • trunk/Tools/ChangeLog

    r286629 r286630  
     12021-12-07  Devin Rousso  <drousso@apple.com>
     2
     3        Add helper methods to `WebCore::FontShadow` for serializing to CSS and converting to `NSShadow`
     4        https://bugs.webkit.org/show_bug.cgi?id=233938
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/Tests/WebCore/FontShadowTests.cpp: Added.
     9        (TestWebKitAPI::TEST.FontShadow.InvalidColor):
     10        (TestWebKitAPI::TEST.FontShadow.NoOffsetOrBlurRadius):
     11        (TestWebKitAPI::TEST.FontShadow.NoOffset):
     12        (TestWebKitAPI::TEST.FontShadow.NegativeOffset):
     13        (TestWebKitAPI::TEST.FontShadow.NoBlurRadius):
     14        (TestWebKitAPI::TEST.FontShadow.NegativeBlurRadius):
     15        (TestWebKitAPI::TEST.FontShadow.AllNegative):
     16
     17        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     18
    1192021-12-07  Jonathan Bedard  <jbedard@apple.com>
    220
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r286458 r286630  
    765765                952F7167270BD9CB00D00DCC /* CSSViewportUnits.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 952F7166270BD99700D00DCC /* CSSViewportUnits.html */; };
    766766                952F7167270BD9CB00D00DCD /* CSSViewportUnits.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = 952F7166270BD99700D00DCD /* CSSViewportUnits.svg */; };
     767                95C52729275F35E100DA7E40 /* FontShadowTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95C52728275F35E100DA7E40 /* FontShadowTests.cpp */; };
    767768                996EDCCB270E70D7006DF175 /* InspectorExtension-basic-page.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 996EDCCA270E70AB006DF175 /* InspectorExtension-basic-page.html */; };
    768769                9984FACE1CFFB090008D198C /* editable-body.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9984FACD1CFFB038008D198C /* editable-body.html */; };
     
    25162517                95A524942581A10D00461FE9 /* WKWebViewThemeColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewThemeColor.mm; sourceTree = "<group>"; };
    25172518                95B6B3B6251EBF2F00FC4382 /* MediaDocument.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaDocument.mm; sourceTree = "<group>"; };
     2519                95C52728275F35E100DA7E40 /* FontShadowTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontShadowTests.cpp; sourceTree = "<group>"; };
    25182520                996EDCCA270E70AB006DF175 /* InspectorExtension-basic-page.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "InspectorExtension-basic-page.html"; sourceTree = "<group>"; };
    25192521                9984FACA1CFFAEEE008D198C /* WKWebViewTextInput.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewTextInput.mm; sourceTree = "<group>"; };
     
    36863688                                7A909A711D877475007E10F8 /* FloatRectTests.cpp */,
    36873689                                7A909A721D877475007E10F8 /* FloatSizeTests.cpp */,
     3690                                95C52728275F35E100DA7E40 /* FontShadowTests.cpp */,
    36883691                                8E4A85361E1D1AA100F53B0F /* GridPosition.cpp */,
    36893692                                83B88A331C80056D00BB2418 /* HTMLParserIdioms.cpp */,
     
    54755478                                F456AB1C213EDBA300CB2CEF /* FontManagerTests.mm in Sources */,
    54765479                                1C81802725FB09E200608B3E /* FontRegistrySandboxCheck.mm in Sources */,
     5480                                95C52729275F35E100DA7E40 /* FontShadowTests.cpp in Sources */,
    54775481                                1CF59AE321E68932006E37EC /* ForceLightAppearanceInBundle.mm in Sources */,
    54785482                                7CCE7EF51A411AE600447C4C /* ForceRepaint.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.