Changeset 236445 in webkit


Ignore:
Timestamp:
Sep 24, 2018 5:17:29 PM (6 years ago)
Author:
Wenson Hsieh
Message:

Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
https://bugs.webkit.org/show_bug.cgi?id=189918
Work towards <rdar://problem/44648705>

Reviewed by Tim Horton.

Source/WebCore:

Refactors the functionality in Editor::fontAttributesForSelectionStart to not be Cocoa-only. Rename this to
fontAttributesAtSelectionStart (to be consistent with EditingStyle::styleAtSelectionStart) and move it from
EditorCocoa.mm to Editor.cpp; instead of creating and populating an NSDictionary with font attribute
information, create and populate a new FontAttributes struct that contains the same information. Cocoa clients
in WebKitLegacy may then create an NSDictionary as needed from the FontAttributes.

  • SourcesCocoa.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • editing/Editor.cpp:

(WebCore::Editor::platformFontAttributesAtSelectionStart const):

Add a hook to allow platforms to supply additional information in FontAttributes. On Cocoa, this adds a UIFont
or NSFont to FontAttributes; otherwise, this is a no-op.

(WebCore::Editor::fontAttributesAtSelectionStart const):

  • editing/Editor.h:
  • editing/FontAttributeChanges.cpp:

(WebCore::cssValueListForShadow):

  • editing/FontAttributeChanges.h:

(): Deleted.
(WebCore::FontShadow::encode const): Deleted.
(WebCore::FontShadow::decode): Deleted.

  • editing/FontAttributes.h: Added.

Introduce a new struct that contains font attribute information. May be converted into an NSDictionary for use
by Cocoa clients in WebKitLegacy and WebKit. In a future patch, this will become serializable over IPC for use
in WebKit2.

  • editing/FontShadow.h: Added.

Move FontShadow out into a separate header file, included in FontAttributeChanges.h and FontAttributes.h.

(WebCore::FontShadow::encode const):
(WebCore::FontShadow::decode):

  • editing/cocoa/EditorCocoa.mm:

Add a helper function to convert a WebCore::Color to either UIColor on iOS or NSColor when AppKit is being
used.

(WebCore::Editor::platformFontAttributesAtSelectionStart const):
(WebCore::Editor::getTextDecorationAttributesRespectingTypingStyle const): Deleted.

Remove a helper function that was only used to compute text decoration attributes in
fontAttributesForSelectionStart.

(WebCore::Editor::fontAttributesForSelectionStart const): Deleted.

  • editing/cocoa/FontAttributesCocoa.mm: Added.

(WebCore::FontAttributes::createDictionary const):

  • editing/cocoa/FontShadowCocoa.mm: Added.

(WebCore::FontShadow::createShadow const):

  • editing/cocoa/HTMLConverter.mm:

(_webKitBundle):
(HTMLConverter::_colorForElement):
(_platformColor): Deleted.

Adopt platformColor().

  • platform/graphics/cocoa/ColorCocoa.h: Added.
  • platform/graphics/cocoa/ColorCocoa.mm: Added.

(WebCore::platformColor):

  • platform/graphics/metal/GPURenderPassDescriptorMetal.mm:

Build fix due to changes in unified sources.

  • platform/mac/WebCoreNSFontManagerExtras.mm:

(WebCore::computedFontAttributeChanges):

  • platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
  • platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:

More build fixes due to changes in unified sources.

Source/WebCore/PAL:

Add +_disambiguated_due_to_CIImage_colorWithCGColor: as a UIColor SPI definition. Also, import
UIColor_Private.h directly when the Apple internal SDK is used.

  • pal/spi/ios/UIKitSPI.h:

Source/WebKitLegacy/mac:

Replace call sites of fontAttributesForSelectionStart() to fontAttributesAtSelectionStart().createDictionary().

  • WebView/WebHTMLView.mm:

(-[WebHTMLView _selectionStartFontAttributesAsRTF]):
(-[WebHTMLView _updateFontPanel]):

  • WebView/WebView.mm:

(-[WebView typingAttributes]):

Location:
trunk/Source
Files:
6 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r236443 r236445  
     12018-09-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=189918
     5        Work towards <rdar://problem/44648705>
     6
     7        Reviewed by Tim Horton.
     8
     9        Refactors the functionality in Editor::fontAttributesForSelectionStart to not be Cocoa-only. Rename this to
     10        fontAttributesAtSelectionStart (to be consistent with `EditingStyle::styleAtSelectionStart`) and move it from
     11        EditorCocoa.mm to Editor.cpp; instead of creating and populating an NSDictionary with font attribute
     12        information, create and populate a new `FontAttributes` struct that contains the same information. Cocoa clients
     13        in WebKitLegacy may then create an `NSDictionary` as needed from the `FontAttributes`.
     14
     15        * SourcesCocoa.txt:
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * editing/Editor.cpp:
     18        (WebCore::Editor::platformFontAttributesAtSelectionStart const):
     19
     20        Add a hook to allow platforms to supply additional information in FontAttributes. On Cocoa, this adds a UIFont
     21        or NSFont to FontAttributes; otherwise, this is a no-op.
     22
     23        (WebCore::Editor::fontAttributesAtSelectionStart const):
     24        * editing/Editor.h:
     25        * editing/FontAttributeChanges.cpp:
     26        (WebCore::cssValueListForShadow):
     27        * editing/FontAttributeChanges.h:
     28        (): Deleted.
     29        (WebCore::FontShadow::encode const): Deleted.
     30        (WebCore::FontShadow::decode): Deleted.
     31        * editing/FontAttributes.h: Added.
     32
     33        Introduce a new struct that contains font attribute information. May be converted into an NSDictionary for use
     34        by Cocoa clients in WebKitLegacy and WebKit. In a future patch, this will become serializable over IPC for use
     35        in WebKit2.
     36
     37        * editing/FontShadow.h: Added.
     38
     39        Move FontShadow out into a separate header file, included in `FontAttributeChanges.h` and `FontAttributes.h`.
     40
     41        (WebCore::FontShadow::encode const):
     42        (WebCore::FontShadow::decode):
     43        * editing/cocoa/EditorCocoa.mm:
     44
     45        Add a helper function to convert a WebCore::Color to either `UIColor` on iOS or `NSColor` when AppKit is being
     46        used.
     47
     48        (WebCore::Editor::platformFontAttributesAtSelectionStart const):
     49        (WebCore::Editor::getTextDecorationAttributesRespectingTypingStyle const): Deleted.
     50
     51        Remove a helper function that was only used to compute text decoration attributes in
     52        fontAttributesForSelectionStart.
     53
     54        (WebCore::Editor::fontAttributesForSelectionStart const): Deleted.
     55        * editing/cocoa/FontAttributesCocoa.mm: Added.
     56        (WebCore::FontAttributes::createDictionary const):
     57        * editing/cocoa/FontShadowCocoa.mm: Added.
     58        (WebCore::FontShadow::createShadow const):
     59        * editing/cocoa/HTMLConverter.mm:
     60        (_webKitBundle):
     61        (HTMLConverter::_colorForElement):
     62        (_platformColor): Deleted.
     63
     64        Adopt platformColor().
     65
     66        * platform/graphics/cocoa/ColorCocoa.h: Added.
     67        * platform/graphics/cocoa/ColorCocoa.mm: Added.
     68        (WebCore::platformColor):
     69        * platform/graphics/metal/GPURenderPassDescriptorMetal.mm:
     70
     71        Build fix due to changes in unified sources.
     72
     73        * platform/mac/WebCoreNSFontManagerExtras.mm:
     74        (WebCore::computedFontAttributeChanges):
     75        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
     76        * platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm:
     77
     78        More build fixes due to changes in unified sources.
     79
    1802018-09-24  Jer Noble  <jer.noble@apple.com>
    281
  • trunk/Source/WebCore/PAL/ChangeLog

    r236366 r236445  
     12018-09-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=189918
     5        Work towards <rdar://problem/44648705>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add `+_disambiguated_due_to_CIImage_colorWithCGColor:` as a UIColor SPI definition. Also, import
     10        `UIColor_Private.h` directly when the Apple internal SDK is used.
     11
     12        * pal/spi/ios/UIKitSPI.h:
     13
    1142018-09-21  Jer Noble  <jer.noble@apple.com>
    215
  • trunk/Source/WebCore/PAL/pal/spi/ios/UIKitSPI.h

    r221187 r236445  
    2828#import <UIKit/UIApplicationSceneConstants.h>
    2929#import <UIKit/UIApplication_Private.h>
     30#import <UIKit/UIColor_Private.h>
    3031#import <UIKit/UIInterface_Private.h>
    3132#import <UIKit/UIScreen_Private.h>
     
    7475+ (UIColor *)systemRedColor;
    7576+ (UIColor *)systemYellowColor;
     77
     78+ (UIColor *)_disambiguated_due_to_CIImage_colorWithCGColor:(CGColorRef)cgColor;
    7679
    7780@end
  • trunk/Source/WebCore/SourcesCocoa.txt

    r236094 r236445  
    8080editing/cocoa/EditorCocoa.mm
    8181editing/cocoa/FontAttributeChangesCocoa.mm
     82editing/cocoa/FontAttributesCocoa.mm
     83editing/cocoa/FontShadowCocoa.mm
    8284editing/cocoa/HTMLConverter.mm @no-unify
    8385editing/cocoa/WebArchiveResourceFromNSAttributedString.mm
     
    294296platform/graphics/cg/UTIRegistry.cpp
    295297
     298platform/graphics/cocoa/ColorCocoa.mm
    296299platform/graphics/cocoa/GraphicsContext3DCocoa.mm
    297300platform/graphics/cocoa/GraphicsContextCocoa.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r236429 r236445  
    48444844                F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48454845                F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4846                F48D2A6C215623B400C6752B /* FontShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A6A215623B400C6752B /* FontShadow.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4847                F48D2A7E2157182600C6752B /* FontAttributes.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A712156DC0A00C6752B /* FontAttributes.h */; settings = {ATTRIBUTES = (Private, ); }; };
     4848                F48D2AA52159740D00C6752B /* ColorCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2AA32159740D00C6752B /* ColorCocoa.h */; };
    48464849                F49786881FF45FA500E060AB /* PasteboardItemInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F49786871FF45FA500E060AB /* PasteboardItemInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48474850                F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; };
     
    1458414587                F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; };
    1458514588                F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; };
     14589                F48D2A6A215623B400C6752B /* FontShadow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontShadow.h; sourceTree = "<group>"; };
     14590                F48D2A712156DC0A00C6752B /* FontAttributes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributes.h; sourceTree = "<group>"; };
     14591                F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontAttributesCocoa.mm; sourceTree = "<group>"; };
     14592                F48D2A7A2157051E00C6752B /* FontShadowCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FontShadowCocoa.mm; sourceTree = "<group>"; };
     14593                F48D2AA32159740D00C6752B /* ColorCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorCocoa.h; sourceTree = "<group>"; };
     14594                F48D2AA42159740D00C6752B /* ColorCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ColorCocoa.mm; sourceTree = "<group>"; };
    1458614595                F49786871FF45FA500E060AB /* PasteboardItemInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteboardItemInfo.h; sourceTree = "<group>"; };
    1458714596                F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontAttributeChanges.h; sourceTree = "<group>"; };
     
    1994219951                                9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
    1994319952                                F42CEB54214031EE002DCA72 /* FontAttributeChangesCocoa.mm */,
     19953                                F48D2A752156FE5700C6752B /* FontAttributesCocoa.mm */,
     19954                                F48D2A7A2157051E00C6752B /* FontShadowCocoa.mm */,
    1994419955                                7C3E510818DF8F3500C112F7 /* HTMLConverter.h */,
    1994519956                                7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */,
     
    2024620257                                F442850B2140412500CCDA22 /* FontAttributeChanges.cpp */,
    2024720258                                F4E57EDA213F3F5F004EA98E /* FontAttributeChanges.h */,
     20259                                F48D2A712156DC0A00C6752B /* FontAttributes.h */,
     20260                                F48D2A6A215623B400C6752B /* FontShadow.h */,
    2024820261                                D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */,
    2024920262                                D05CED280A40BB2C00C5AF38 /* FormatBlockCommand.h */,
     
    2394623959                        isa = PBXGroup;
    2394723960                        children = (
     23961                                F48D2AA32159740D00C6752B /* ColorCocoa.h */,
     23962                                F48D2AA42159740D00C6752B /* ColorCocoa.mm */,
    2394823963                                1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */,
    2394923964                                C2458E611FE8979E00594759 /* FontCacheCoreText.h */,
     
    2746727482                                C330A22313EC196B0000B45B /* ColorChooser.h in Headers */,
    2746827483                                C37CDEBD149EF2030042090D /* ColorChooserClient.h in Headers */,
     27484                                F48D2AA52159740D00C6752B /* ColorCocoa.h in Headers */,
    2746927485                                3103B7DF1DB01567008BB890 /* ColorHash.h in Headers */,
    2747027486                                F55B3DB41251F12D003EF269 /* ColorInputType.h in Headers */,
     
    2806528081                                1AC2D89D1B1E291F00D52E87 /* FontAntialiasingStateSaver.h in Headers */,
    2806628082                                F4E57EDC213F3F5F004EA98E /* FontAttributeChanges.h in Headers */,
     28083                                F48D2A7E2157182600C6752B /* FontAttributes.h in Headers */,
    2806728084                                BCB92D4F1293550B00C8387F /* FontBaseline.h in Headers */,
    2806828085                                B2C3DA630D006CD600EF6F26 /* FontCache.h in Headers */,
     
    2808128098                                B2C3DA6B0D006CD600EF6F26 /* FontSelector.h in Headers */,
    2808228099                                E419041F1CC6486B00C35F5D /* FontSelectorClient.h in Headers */,
     28100                                F48D2A6C215623B400C6752B /* FontShadow.h in Headers */,
    2808328101                                4A6E9FC813C17D570046A7F8 /* FontTaggedSettings.h in Headers */,
    2808428102                                C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */,
  • trunk/Source/WebCore/editing/Editor.cpp

    r235955 r236445  
    4949#include "File.h"
    5050#include "FocusController.h"
     51#include "FontAttributes.h"
    5152#include "Frame.h"
    5253#include "FrameLoader.h"
     
    38523853}
    38533854
     3855#if !PLATFORM(COCOA)
     3856
     3857void Editor::platformFontAttributesAtSelectionStart(FontAttributes&, const RenderStyle&) const
     3858{
     3859}
     3860
     3861#endif
     3862
     3863FontAttributes Editor::fontAttributesAtSelectionStart() const
     3864{
     3865    FontAttributes attributes;
     3866    Node* nodeToRemove = nullptr;
     3867    auto* style = styleForSelectionStart(&m_frame, nodeToRemove);
     3868    if (!style) {
     3869        if (nodeToRemove)
     3870            nodeToRemove->remove();
     3871        return attributes;
     3872    }
     3873
     3874    platformFontAttributesAtSelectionStart(attributes, *style);
     3875
     3876    // FIXME: for now, always report the colors after applying -apple-color-filter. In future not all clients
     3877    // may want this, so we may have to add a setting to control it. See also editingAttributedStringFromRange().
     3878    auto backgroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
     3879    if (backgroundColor.isVisible())
     3880        attributes.backgroundColor = backgroundColor;
     3881
     3882    auto foregroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyColor);
     3883    // FIXME: isBlackColor not suitable for dark mode.
     3884    if (foregroundColor.isValid() && !Color::isBlackColor(foregroundColor))
     3885        attributes.foregroundColor = foregroundColor;
     3886
     3887    if (auto* shadowData = style->textShadow())
     3888        attributes.fontShadow = { shadowData->color(), { static_cast<float>(shadowData->x()), static_cast<float>(shadowData->y()) }, static_cast<double>(shadowData->radius()) };
     3889
     3890    switch (style->verticalAlign()) {
     3891    case VerticalAlign::Baseline:
     3892    case VerticalAlign::Bottom:
     3893    case VerticalAlign::BaselineMiddle:
     3894    case VerticalAlign::Length:
     3895    case VerticalAlign::Middle:
     3896    case VerticalAlign::TextBottom:
     3897    case VerticalAlign::TextTop:
     3898    case VerticalAlign::Top:
     3899        break;
     3900    case VerticalAlign::Sub:
     3901        attributes.subscriptOrSuperscript = SubscriptOrSuperscript::Subscript;
     3902        break;
     3903    case VerticalAlign::Super:
     3904        attributes.subscriptOrSuperscript = SubscriptOrSuperscript::Superscript;
     3905        break;
     3906    }
     3907
     3908    auto typingStyle = makeRefPtr(m_frame.selection().typingStyle());
     3909    if (typingStyle && typingStyle->style()) {
     3910        auto value = typingStyle->style()->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
     3911        if (value && value->isValueList()) {
     3912            CSSValueList& valueList = downcast<CSSValueList>(*value);
     3913            if (valueList.hasValue(CSSValuePool::singleton().createIdentifierValue(CSSValueLineThrough).ptr()))
     3914                attributes.hasStrikeThrough = true;
     3915            if (valueList.hasValue(CSSValuePool::singleton().createIdentifierValue(CSSValueUnderline).ptr()))
     3916                attributes.hasUnderline = true;
     3917        }
     3918    } else {
     3919        auto decoration = style->textDecorationsInEffect();
     3920        if (decoration & TextDecoration::LineThrough)
     3921            attributes.hasStrikeThrough = true;
     3922        if (decoration & TextDecoration::Underline)
     3923            attributes.hasUnderline = true;
     3924    }
     3925
     3926    if (nodeToRemove)
     3927        nodeToRemove->remove();
     3928
     3929    return attributes;
     3930}
     3931
    38543932#if ENABLE(ATTACHMENT_ELEMENT)
    38553933
  • trunk/Source/WebCore/editing/Editor.h

    r235955 r236445  
    8282class TextEvent;
    8383
     84struct FontAttributes;
    8485struct PasteboardPlainText;
    8586struct PasteboardURL;
     
    470471    WEBCORE_EXPORT const Font* fontForSelection(bool& hasMultipleFonts) const;
    471472    WEBCORE_EXPORT static const RenderStyle* styleForSelectionStart(Frame* , Node *&nodeToRemove);
     473    WEBCORE_EXPORT FontAttributes fontAttributesAtSelectionStart() const;
    472474
    473475#if PLATFORM(COCOA)
    474     void getTextDecorationAttributesRespectingTypingStyle(const RenderStyle&, NSMutableDictionary*) const;
    475     WEBCORE_EXPORT RetainPtr<NSDictionary> fontAttributesForSelectionStart() const;
    476476    WEBCORE_EXPORT String stringSelectionForPasteboard();
    477477    String stringSelectionForPasteboardWithImageAltText();
     
    563563    static RefPtr<SharedBuffer> dataInRTFFormat(NSAttributedString *);
    564564#endif
     565    void platformFontAttributesAtSelectionStart(FontAttributes&, const RenderStyle&) const;
    565566
    566567    void scheduleEditorUIUpdate();
  • trunk/Source/WebCore/editing/FontAttributeChanges.cpp

    r235914 r236445  
    8282static RefPtr<CSSValueList> cssValueListForShadow(const FontShadow& shadow)
    8383{
    84     if (!shadow.width && !shadow.height && !shadow.blurRadius)
     84    if (shadow.offset.isEmpty() && !shadow.blurRadius)
    8585        return nullptr;
    8686
    8787    auto list = CSSValueList::createCommaSeparated();
    8888    auto& cssValuePool = CSSValuePool::singleton();
    89     auto width = cssValuePool.createValue(shadow.width, CSSPrimitiveValue::CSS_PX);
    90     auto height = cssValuePool.createValue(shadow.height, CSSPrimitiveValue::CSS_PX);
     89    auto width = cssValuePool.createValue(shadow.offset.width(), CSSPrimitiveValue::CSS_PX);
     90    auto height = cssValuePool.createValue(shadow.offset.height(), CSSPrimitiveValue::CSS_PX);
    9191    auto blurRadius = cssValuePool.createValue(shadow.blurRadius, CSSPrimitiveValue::CSS_PX);
    9292    auto color = cssValuePool.createValue(shadow.color);
  • trunk/Source/WebCore/editing/FontAttributeChanges.h

    r235914 r236445  
    2727
    2828#include "Color.h"
     29#include "FontShadow.h"
    2930#include <wtf/EnumTraits.h>
    3031#include <wtf/Forward.h>
     
    6869    std::optional<bool> m_bold;
    6970    std::optional<bool> m_italic;
    70 };
    71 
    72 struct FontShadow {
    73     template<class Encoder> void encode(Encoder&) const;
    74     template<class Decoder> static bool decode(Decoder&, FontShadow&);
    75 
    76     Color color;
    77     double width { 0 };
    78     double height { 0 };
    79     double blurRadius { 0 };
    8071};
    8172
     
    139130
    140131template<class Encoder>
    141 void FontShadow::encode(Encoder& encoder) const
    142 {
    143     encoder << color << width << height << blurRadius;
    144 }
    145 
    146 template<class Decoder>
    147 bool FontShadow::decode(Decoder& decoder, FontShadow& shadow)
    148 {
    149     if (!decoder.decode(shadow.color))
    150         return false;
    151 
    152     if (!decoder.decode(shadow.width))
    153         return false;
    154 
    155     if (!decoder.decode(shadow.height))
    156         return false;
    157 
    158     if (!decoder.decode(shadow.blurRadius))
    159         return false;
    160 
    161     return true;
    162 }
    163 
    164 template<class Encoder>
    165132void FontAttributeChanges::encode(Encoder& encoder) const
    166133{
  • trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm

    r235955 r236445  
    3737#import "EditingStyle.h"
    3838#import "EditorClient.h"
     39#import "FontAttributes.h"
    3940#import "FontCascade.h"
    4041#import "Frame.h"
     
    5960namespace WebCore {
    6061
    61 void Editor::getTextDecorationAttributesRespectingTypingStyle(const RenderStyle& style, NSMutableDictionary* result) const
    62 {
    63     RefPtr<EditingStyle> typingStyle = m_frame.selection().typingStyle();
    64     if (typingStyle && typingStyle->style()) {
    65         RefPtr<CSSValue> value = typingStyle->style()->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);
    66         if (value && value->isValueList()) {
    67             CSSValueList& valueList = downcast<CSSValueList>(*value);
    68             if (valueList.hasValue(CSSValuePool::singleton().createIdentifierValue(CSSValueLineThrough).ptr()))
    69                 [result setObject:@(NSUnderlineStyleSingle) forKey:NSStrikethroughStyleAttributeName];
    70             if (valueList.hasValue(CSSValuePool::singleton().createIdentifierValue(CSSValueUnderline).ptr()))
    71                 [result setObject:@(NSUnderlineStyleSingle) forKey:NSUnderlineStyleAttributeName];
    72         }
    73     } else {
    74         auto decoration = style.textDecorationsInEffect();
    75         if (decoration & TextDecoration::LineThrough)
    76             [result setObject:@(NSUnderlineStyleSingle) forKey:NSStrikethroughStyleAttributeName];
    77         if (decoration & TextDecoration::Underline)
    78             [result setObject:@(NSUnderlineStyleSingle) forKey:NSUnderlineStyleAttributeName];
    79     }
    80 }
    81 
    82 RetainPtr<NSDictionary> Editor::fontAttributesForSelectionStart() const
    83 {
    84     Node* nodeToRemove;
    85     auto* style = styleForSelectionStart(&m_frame, nodeToRemove);
    86     if (!style)
    87         return nil;
    88 
    89     RetainPtr<NSMutableDictionary> attributes = adoptNS([[NSMutableDictionary alloc] init]);
    90 
    91     if (auto ctFont = style->fontCascade().primaryFont().getCTFont())
    92         [attributes setObject:(__bridge id)ctFont forKey:NSFontAttributeName];
    93 
    94     // FIXME: Why would we not want to retrieve these attributes on iOS?
    95 #if PLATFORM(MAC)
    96     // FIXME: for now, always report the colors after applying -apple-color-filter. In future not all clients
    97     // may want this, so we may have to add a setting to control it. See also editingAttributedStringFromRange().
    98     Color backgroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
    99     if (backgroundColor.isVisible())
    100         [attributes setObject:nsColor(backgroundColor) forKey:NSBackgroundColorAttributeName];
    101 
    102     Color foregroundColor = style->visitedDependentColorWithColorFilter(CSSPropertyColor);
    103     // FIXME: isBlackColor not suitable for dark mode.
    104     if (foregroundColor.isValid() && !Color::isBlackColor(foregroundColor))
    105         [attributes setObject:nsColor(foregroundColor) forKey:NSForegroundColorAttributeName];
    106 
    107     const ShadowData* shadowData = style->textShadow();
    108     if (shadowData) {
    109         RetainPtr<NSShadow> platformShadow = adoptNS([[NSShadow alloc] init]);
    110         [platformShadow setShadowOffset:NSMakeSize(shadowData->x(), shadowData->y())];
    111         [platformShadow setShadowBlurRadius:shadowData->radius()];
    112         [platformShadow setShadowColor:nsColor(shadowData->color())];
    113         [attributes setObject:platformShadow.get() forKey:NSShadowAttributeName];
    114     }
    115 
    116     int superscriptInt = 0;
    117     switch (style->verticalAlign()) {
    118     case VerticalAlign::Baseline:
    119     case VerticalAlign::Bottom:
    120     case VerticalAlign::BaselineMiddle:
    121     case VerticalAlign::Length:
    122     case VerticalAlign::Middle:
    123     case VerticalAlign::TextBottom:
    124     case VerticalAlign::TextTop:
    125     case VerticalAlign::Top:
    126         break;
    127     case VerticalAlign::Sub:
    128         superscriptInt = -1;
    129         break;
    130     case VerticalAlign::Super:
    131         superscriptInt = 1;
    132         break;
    133     }
    134     if (superscriptInt)
    135         [attributes setObject:@(superscriptInt) forKey:NSSuperscriptAttributeName];
    136 #endif
    137 
    138     getTextDecorationAttributesRespectingTypingStyle(*style, attributes.get());
    139 
    140     if (nodeToRemove)
    141         nodeToRemove->remove();
    142 
    143     return attributes;
     62void Editor::platformFontAttributesAtSelectionStart(FontAttributes& attributes, const RenderStyle& style) const
     63{
     64    if (auto ctFont = style.fontCascade().primaryFont().getCTFont())
     65        attributes.font = (__bridge id)ctFont;
    14466}
    14567
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r234348 r236445  
    3333#import "CachedImage.h"
    3434#import "CharacterData.h"
     35#import "ColorCocoa.h"
    3536#import "ColorMac.h"
    3637#import "Document.h"
     
    206207+ (UIColor *)clearColor;
    207208- (CGFloat)alphaComponent;
    208 + (UIColor *)_disambiguated_due_to_CIImage_colorWithCGColor:(CGColorRef)cgColor;
    209209@end
    210210
     
    864864    return bundle;
    865865}
    866 
    867 static inline UIColor *_platformColor(Color color)
    868 {
    869     return [getUIColorClass() _disambiguated_due_to_CIImage_colorWithCGColor:cachedCGColor(color)];
    870 }
    871 #else
    872 static inline NSColor *_platformColor(Color color)
    873 {
    874     return nsColor(color);
    875 }
    876866#endif
    877867
     
    10211011    if (!result.isValid())
    10221012        return nil;
    1023     PlatformColor *platformResult = _platformColor(result);
     1013    PlatformColor *platformResult = platformColor(result);
    10241014    if ([[PlatformColorClass clearColor] isEqual:platformResult] || ([platformResult alphaComponent] == 0.0))
    10251015        return nil;
  • trunk/Source/WebCore/platform/graphics/metal/GPURenderPassDescriptorMetal.mm

    r234258 r236445  
    3333#import "Logging.h"
    3434#import <Metal/Metal.h>
     35#import <wtf/Vector.h>
    3536
    3637namespace WebCore {
  • trunk/Source/WebCore/platform/mac/WebCoreNSFontManagerExtras.mm

    r235769 r236445  
    137137    NSShadow *convertedShadow = [convertedAttributesA objectForKey:NSShadowAttributeName];
    138138    if (convertedShadow) {
    139         auto offset = convertedShadow.shadowOffset;
    140         changes.setShadow({ colorFromNSColor(convertedShadow.shadowColor ?: NSColor.blackColor), offset.width, offset.height, convertedShadow.shadowBlurRadius });
     139        FloatSize offset { static_cast<float>(convertedShadow.shadowOffset.width), static_cast<float>(convertedShadow.shadowOffset.height) };
     140        changes.setShadow({ colorFromNSColor(convertedShadow.shadowColor ?: NSColor.blackColor), offset, convertedShadow.shadowBlurRadius });
    141141    } else if (![convertedAttributesB objectForKey:NSShadowAttributeName])
    142142        changes.setShadow({ });
  • trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.h

    r236423 r236445  
    3333
    3434using CMSampleBufferRef = struct opaqueCMSampleBuffer*;
     35using CVPixelBufferPoolRef = struct __CVPixelBufferPool*;
    3536using CVPixelBufferRef = struct __CVBuffer*;
    3637
  • trunk/Source/WebCore/platform/mediastream/mac/RealtimeIncomingVideoSourceCocoa.mm

    r236423 r236445  
    3333#include "Logging.h"
    3434#include "MediaSampleAVFObjC.h"
     35#include "RealtimeVideoUtilities.h"
    3536#include <pal/cf/CoreMediaSoftLink.h>
    3637
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r236066 r236445  
     12018-09-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Refactor Editor::fontAttributesForSelectionStart to be platform-agnostic
     4        https://bugs.webkit.org/show_bug.cgi?id=189918
     5        Work towards <rdar://problem/44648705>
     6
     7        Reviewed by Tim Horton.
     8
     9        Replace call sites of fontAttributesForSelectionStart() to fontAttributesAtSelectionStart().createDictionary().
     10
     11        * WebView/WebHTMLView.mm:
     12        (-[WebHTMLView _selectionStartFontAttributesAsRTF]):
     13        (-[WebHTMLView _updateFontPanel]):
     14        * WebView/WebView.mm:
     15        (-[WebView typingAttributes]):
     16
    1172018-09-17  Darin Adler  <darin@apple.com>
    218
  • trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

    r235935 r236445  
    9797#import <WebCore/Font.h>
    9898#import <WebCore/FontAttributeChanges.h>
     99#import <WebCore/FontAttributes.h>
    99100#import <WebCore/FontCache.h>
    100101#import <WebCore/Frame.h>
     
    50585059    Frame* coreFrame = core([self _frame]);
    50595060    auto string = adoptNS([[NSAttributedString alloc] initWithString:@"x"
    5060         attributes:coreFrame ? coreFrame->editor().fontAttributesForSelectionStart().get() : nil]);
     5061        attributes:coreFrame ? coreFrame->editor().fontAttributesAtSelectionStart().createDictionary().get() : nil]);
    50615062    return [string RTFFromRange:NSMakeRange(0, [string length]) documentAttributes:@{ }];
    50625063}
     
    57055706        if (const Font* fd = coreFrame->editor().fontForSelection(multipleFonts))
    57065707            font = (NSFont *)fd->platformData().registeredFont();
    5707         attributes = coreFrame->editor().fontAttributesForSelectionStart();
     5708        attributes = coreFrame->editor().fontAttributesAtSelectionStart().createDictionary();
    57085709    }
    57095710
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r235935 r236445  
    145145#import <WebCore/FileSystem.h>
    146146#import <WebCore/FocusController.h>
     147#import <WebCore/FontAttributes.h>
    147148#import <WebCore/FontCache.h>
    148149#import <WebCore/Frame.h>
     
    86248625- (NSDictionary *)typingAttributes
    86258626{
    8626     Frame* coreFrame = core([self _selectedOrMainFrame]);
    8627     if (coreFrame)
    8628         return coreFrame->editor().fontAttributesForSelectionStart().autorelease();
     8627    if (auto* coreFrame = core([self _selectedOrMainFrame]))
     8628        return coreFrame->editor().fontAttributesAtSelectionStart().createDictionary().autorelease();
    86298629   
    86308630    return nil;
Note: See TracChangeset for help on using the changeset viewer.