Changeset 251086 in webkit


Ignore:
Timestamp:
Oct 14, 2019 12:42:50 PM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[Cocoa] REGRESSION (r245672): Contenteditable with optical sizing freezes Safari
https://bugs.webkit.org/show_bug.cgi?id=202262

Reviewed by Tim Horton.

Source/WebKit:

r250640 didn't go far enough. We need to apply the same fix everywhere [NSFontDescriptor fontDescriptorWithFontAttributes:] is called.

  • Shared/Cocoa/ArgumentCodersCocoa.mm:

(IPC::decodeFontInternal):

  • Shared/Cocoa/CoreTextHelpers.h: Added.
  • Shared/Cocoa/CoreTextHelpers.mm: Added.

(fontDescriptorWithFontAttributes):

  • SourcesCocoa.txt:
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::updateFontManagerIfNeeded):

  • UIProcess/mac/WebPopupMenuProxyMac.mm:

(WebKit::WebPopupMenuProxyMac::showPopupMenu):

  • WebKit.xcodeproj/project.pbxproj:

LayoutTests:

  • fast/forms/contenteditable-font-optical-size-expected.txt: Added.
  • fast/forms/contenteditable-font-optical-size.html: Added.
Location:
trunk
Files:
2 added
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r251084 r251086  
     12019-10-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] REGRESSION (r245672): Contenteditable with optical sizing freezes Safari
     4        https://bugs.webkit.org/show_bug.cgi?id=202262
     5
     6        Reviewed by Tim Horton.
     7
     8        * fast/forms/contenteditable-font-optical-size-expected.txt: Added.
     9        * fast/forms/contenteditable-font-optical-size.html: Added.
     10
    1112019-10-14  Russell Epstein  <russell_e@apple.com>
    212
  • trunk/Source/WebKit/ChangeLog

    r251074 r251086  
     12019-10-14  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] REGRESSION (r245672): Contenteditable with optical sizing freezes Safari
     4        https://bugs.webkit.org/show_bug.cgi?id=202262
     5
     6        Reviewed by Tim Horton.
     7
     8        r250640 didn't go far enough. We need to apply the same fix everywhere [NSFontDescriptor fontDescriptorWithFontAttributes:] is called.
     9
     10        * Shared/Cocoa/ArgumentCodersCocoa.mm:
     11        (IPC::decodeFontInternal):
     12        * Shared/Cocoa/CoreTextHelpers.h: Added.
     13        * Shared/Cocoa/CoreTextHelpers.mm: Added.
     14        (fontDescriptorWithFontAttributes):
     15        * SourcesCocoa.txt:
     16        * UIProcess/Cocoa/WebViewImpl.mm:
     17        (WebKit::WebViewImpl::updateFontManagerIfNeeded):
     18        * UIProcess/mac/WebPopupMenuProxyMac.mm:
     19        (WebKit::WebPopupMenuProxyMac::showPopupMenu):
     20        * WebKit.xcodeproj/project.pbxproj:
     21
    1222019-10-14  Truitt Savell  <tsavell@apple.com>
    223
  • trunk/Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm

    r246726 r251086  
    3030
    3131#import "ArgumentCodersCF.h"
     32#import "CoreTextHelpers.h"
    3233#import <CoreText/CTFont.h>
    3334#import <CoreText/CTFontDescriptor.h>
    3435#import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
     36#import <wtf/BlockObjCExceptions.h>
    3537#import <wtf/HashSet.h>
    3638
     
    329331        return WTF::nullopt;
    330332
    331     PlatformFontDescriptor *fontDescriptor = [PlatformFontDescriptor fontDescriptorWithFontAttributes:fontAttributes.get()];
     333    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     334
     335    PlatformFontDescriptor *fontDescriptor = WebKit::fontDescriptorWithFontAttributes(fontAttributes.get());
    332336    return { [PlatformFont fontWithDescriptor:fontDescriptor size:0] };
     337
     338    END_BLOCK_OBJC_EXCEPTIONS
     339
     340    return { };
    333341}
    334342
  • trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.h

    r251085 r251086  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2019 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 "WebAutocorrectionData.h"
     26#pragma once
    2827
    29 #if PLATFORM(IOS_FAMILY)
     28#if USE(APPKIT)
     29#import <AppKit/AppKit.h>
     30#else
     31#import <UIKit/UIKit.h>
     32#endif
    3033
    31 #import "ArgumentCodersCocoa.h"
    32 #import "Decoder.h"
    33 #import "Encoder.h"
    34 #import "WebCoreArgumentCoders.h"
    35 #import <WebCore/FloatRect.h>
     34#import <wtf/RetainPtr.h>
    3635
    3736namespace WebKit {
    38 using namespace WebCore;
    3937
    40 void WebAutocorrectionData::encode(IPC::Encoder& encoder) const
    41 {
    42     encoder << textRects;
    43     IPC::encode(encoder, font.get());
     38#if USE(APPKIT)
     39using PlatformFontDescriptor = NSFontDescriptor;
     40#else
     41using PlatformFontDescriptor = UIFontDescriptor;
     42#endif
     43
     44PlatformFontDescriptor *fontDescriptorWithFontAttributes(NSDictionary *attributes);
     45
    4446}
    45 
    46 Optional<WebAutocorrectionData> WebAutocorrectionData::decode(IPC::Decoder& decoder)
    47 {
    48     Optional<Vector<FloatRect>> textRects;
    49     decoder >> textRects;
    50     if (!textRects)
    51         return WTF::nullopt;
    52 
    53     RetainPtr<UIFont> font;
    54     if (!IPC::decode(decoder, font, @[ UIFont.class ]))
    55         return WTF::nullopt;
    56 
    57     return {{ *textRects, font }};
    58 }
    59 
    60 } // namespace WebKit
    61 
    62 #endif // PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/Shared/Cocoa/CoreTextHelpers.mm

    r251085 r251086  
    2525
    2626#import "config.h"
    27 #import "WebAutocorrectionData.h"
     27#import "CoreTextHelpers.h"
    2828
    29 #if PLATFORM(IOS_FAMILY)
    30 
    31 #import "ArgumentCodersCocoa.h"
    32 #import "Decoder.h"
    33 #import "Encoder.h"
    34 #import "WebCoreArgumentCoders.h"
    35 #import <WebCore/FloatRect.h>
     29#import <pal/spi/cocoa/CoreTextSPI.h>
     30#import <wtf/BlockObjCExceptions.h>
    3631
    3732namespace WebKit {
    38 using namespace WebCore;
    3933
    40 void WebAutocorrectionData::encode(IPC::Encoder& encoder) const
     34PlatformFontDescriptor *fontDescriptorWithFontAttributes(NSDictionary *attributes)
    4135{
    42     encoder << textRects;
    43     IPC::encode(encoder, font.get());
     36    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     37
     38#if HAVE(NSFONT_WITH_OPTICAL_SIZING_BUG)
     39    auto mutableDictionary = adoptNS([attributes mutableCopy]);
     40    if (id opticalSizeAttribute = [mutableDictionary objectForKey:(__bridge NSString *)kCTFontOpticalSizeAttribute]) {
     41        if ([opticalSizeAttribute isKindOfClass:[NSString class]]) {
     42            [mutableDictionary removeObjectForKey:(__bridge NSString *)kCTFontOpticalSizeAttribute];
     43            if (NSNumber *size = [mutableDictionary objectForKey:(__bridge NSString *)kCTFontSizeAttribute])
     44                [mutableDictionary setObject:size forKey:(__bridge NSString *)kCTFontOpticalSizeAttribute];
     45        }
     46    }
     47    return [PlatformFontDescriptor fontDescriptorWithFontAttributes:mutableDictionary.get()];
     48#else
     49    return [PlatformFontDescriptor fontDescriptorWithFontAttributes:attributes];
     50#endif
     51
     52    END_BLOCK_OBJC_EXCEPTIONS
     53
     54    return nil;
    4455}
    4556
    46 Optional<WebAutocorrectionData> WebAutocorrectionData::decode(IPC::Decoder& decoder)
    47 {
    48     Optional<Vector<FloatRect>> textRects;
    49     decoder >> textRects;
    50     if (!textRects)
    51         return WTF::nullopt;
    52 
    53     RetainPtr<UIFont> font;
    54     if (!IPC::decode(decoder, font, @[ UIFont.class ]))
    55         return WTF::nullopt;
    56 
    57     return {{ *textRects, font }};
    5857}
    59 
    60 } // namespace WebKit
    61 
    62 #endif // PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/Shared/ios/WebAutocorrectionData.mm

    r245998 r251086  
    3333#import "Encoder.h"
    3434#import "WebCoreArgumentCoders.h"
     35#import <UIKit/UIKit.h>
    3536#import <WebCore/FloatRect.h>
    3637
  • trunk/Source/WebKit/SourcesCocoa.txt

    r250729 r251086  
    143143Shared/Cocoa/AuxiliaryProcessCocoa.mm
    144144Shared/Cocoa/CompletionHandlerCallChecker.mm
     145Shared/Cocoa/CoreTextHelpers.mm
    145146Shared/Cocoa/DataDetectionResult.mm
    146147Shared/Cocoa/InsertTextOptions.cpp
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r250973 r251086  
    3535#import "AttributedString.h"
    3636#import "ColorSpaceData.h"
     37#import "CoreTextHelpers.h"
    3738#import "FontInfo.h"
    3839#import "FullscreenClient.h"
     
    118119#import <pal/spi/mac/NSWindowSPI.h>
    119120#import <sys/stat.h>
     121#import <wtf/BlockObjCExceptions.h>
    120122#import <wtf/FileSystem.h>
    121123#import <wtf/NeverDestroyed.h>
     
    11201122        ASSERT_NOT_REACHED();
    11211123    }
    1122    
     1124
    11231125    return nsTextAlignment;
    11241126}
     
    16001602
    16011603    m_page->activityStateDidChange(WebCore::ActivityState::IsFocused);
    1602    
     1604
    16031605    m_inResignFirstResponder = false;
    1604    
     1606
    16051607    return true;
    16061608}
     
    17491751            accessibilityPosition = [[weakThis->m_view accessibilityAttributeValue:NSAccessibilityPositionAttribute] pointValue];
    17501752            ALLOW_DEPRECATED_DECLARATIONS_END
    1751        
     1753
    17521754        weakThis->m_page->windowAndViewFramesChanged(viewFrameInWindowCoordinates, accessibilityPosition);
    17531755    });
     
    23222324    ColorSpaceData colorSpaceData;
    23232325    colorSpaceData.cgColorSpace = [m_colorSpace CGColorSpace];
    2324    
     2326
    23252327    return colorSpaceData;
    23262328}
     
    25692571        [[WKTextInputWindowController sharedTextInputWindowController] unmarkText];
    25702572    }
    2571    
     2573
    25722574    // This will force the current input context to be updated to its correct value.
    25732575    [NSApp updateWindows];
     
    28192821    if (_shareSheet)
    28202822        [_shareSheet dismiss];
    2821    
     2823
    28222824    ASSERT([view respondsToSelector:@selector(shareSheetDidDismiss:)]);
    28232825    _shareSheet = adoptNS([[WKShareSheet alloc] initWithView:view]);
    28242826    [_shareSheet setDelegate:view];
    2825    
     2827
    28262828    [_shareSheet presentWithParameters:data inRect:WTF::nullopt completionHandler:WTFMove(completionHandler)];
    28272829}
    2828    
     2830
    28292831void WebViewImpl::shareSheetDidDismiss(WKShareSheet *shareSheet)
    28302832{
    28312833    ASSERT(_shareSheet == shareSheet);
    2832    
     2834
    28332835    [_shareSheet setDelegate:nil];
    28342836    _shareSheet = nil;
     
    28542856            return;
    28552857
     2858        BEGIN_BLOCK_OBJC_EXCEPTIONS;
     2859
    28562860        NSDictionary *attributeDictionary = (__bridge NSDictionary *)fontInfo.fontAttributeDictionary.get();
    28572861        if (!attributeDictionary)
    28582862            return;
    28592863
    2860         NSFontDescriptor *descriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:attributeDictionary];
     2864        PlatformFontDescriptor *descriptor = fontDescriptorWithFontAttributes(attributeDictionary);
    28612865        if (!descriptor)
    28622866            return;
     
    28672871
    28682872        [NSFontManager.sharedFontManager setSelectedFont:font isMultiple:selectionHasMultipleFonts];
     2873
     2874        END_BLOCK_OBJC_EXCEPTIONS
    28692875    });
    28702876}
     
    32393245    if (static_cast<bool>(flag) == TextChecker::state().isAutomaticTextReplacementEnabled)
    32403246        return;
    3241    
     3247
    32423248    TextChecker::setAutomaticTextReplacementEnabled(flag);
    32433249    m_page->process().updateTextCheckerState();
     
    36623668            if ([attribute isEqualToString:NSAccessibilityEnabledAttribute])
    36633669                return @YES;
    3664    
     3670
    36653671    if ([attribute isEqualToString:@"AXConvertRelativeFrame"]) {
    36663672        if ([parameter isKindOfClass:[NSValue class]]) {
     
    36693675        }
    36703676    }
    3671    
     3677
    36723678    return [m_view _web_superAccessibilityAttributeValue:attribute];
    36733679}
     
    37813787    if (!oldToolTip.isNull())
    37823788        sendToolTipMouseExited();
    3783    
     3789
    37843790    if (!newToolTip.isEmpty()) {
    37853791        // See radar 3500217 for why we remove all tooltips rather than just the single one we created.
     
    39723978
    39733979    if (![types containsObject:PasteboardTypes::WebArchivePboardType] && [types containsObject:WebCore::legacyFilesPromisePasteboardType()]) {
    3974        
     3980
    39753981        // FIXME: legacyFilesPromisePasteboardType() contains UTIs, not path names. Also, it's not
    39763982        // guaranteed that the count of UTIs equals the count of files, since some clients only write
     
    40264032            return false;
    40274033        }
    4028        
     4034
    40294035        Vector<String> fileNames;
    4030        
     4036
    40314037        for (NSString *file in files)
    40324038            fileNames.append(file);
     
    42494255    NSString *filename = filenameByFixingIllegalCharacters([path lastPathComponent]);
    42504256    path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
    4251    
     4257
    42524258    if (fileExists(path)) {
    42534259        // Don't overwrite existing file by appending "-n", "-n.ext" or "-n.ext.ext" to the filename.
     
    42564262        NSString *lastPathComponent = [path lastPathComponent];
    42574263        NSRange periodRange = [lastPathComponent rangeOfString:@"."];
    4258        
     4264
    42594265        if (periodRange.location == NSNotFound) {
    42604266            pathWithoutExtensions = path;
     
    42644270            pathWithoutExtensions = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:lastPathComponent];
    42654271        }
    4266        
     4272
    42674273        for (unsigned i = 1; ; i++) {
    42684274            NSString *pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtensions, i];
     
    42724278        }
    42734279    }
    4274    
     4280
    42754281    return path;
    42764282}
     
    42804286    RetainPtr<NSFileWrapper> wrapper;
    42814287    RetainPtr<NSData> data;
    4282    
     4288
    42834289    if (m_promisedImage) {
    42844290        data = m_promisedImage->data()->createNSData();
     
    42864292    } else
    42874293        wrapper = adoptNS([[NSFileWrapper alloc] initWithURL:[NSURL URLWithString:m_promisedURL] options:NSFileWrapperReadingImmediate error:nil]);
    4288    
     4294
    42894295    if (wrapper)
    42904296        [wrapper setPreferredFilename:m_promisedFilename];
     
    42934299        return nil;
    42944300    }
    4295    
     4301
    42964302    // FIXME: Report an error if we fail to create a file.
    42974303    NSString *path = [[dropDestination path] stringByAppendingPathComponent:[wrapper preferredFilename]];
     
    43024308    if (!m_promisedURL.isEmpty())
    43034309        FileSystem::setMetadataURL(String(path), m_promisedURL);
    4304    
     4310
    43054311    return [NSArray arrayWithObject:[path lastPathComponent]];
    43064312}
     
    44994505
    45004506    gestureController.setShouldIgnorePinnedState(wasIgnoringPinnedState);
    4501    
     4507
    45024508    return handledEvent;
    45034509}
     
    46424648    [NSApp _setCurrentEvent:event];
    46434649    [NSApp sendEvent:event];
    4644    
     4650
    46454651    m_keyDownEventBeingResent = nullptr;
    46464652}
     
    46874693            result.append(WebCore::CompositionUnderline(range.location, NSMaxRange(range), compositionUnderlineColor, color, style.intValue > 1));
    46884694        }
    4689        
     4695
    46904696        i = range.location + range.length;
    46914697    }
     
    51075113        return YES;
    51085114    }
    5109    
     5115
    51105116    return [m_view _web_superPerformKeyEquivalent:event];
    51115117}
     
    53175323    NSRect eventScreenPosition = [[m_view window] convertRectToScreen:NSMakeRect(event.locationInWindow.x, event.locationInWindow.y, 0, 0)];
    53185324    NSInteger eventWindowNumber = [NSWindow windowNumberAtPoint:eventScreenPosition.origin belowWindowWithWindowNumber:0];
    5319        
     5325
    53205326    return [m_view window].windowNumber != eventWindowNumber;
    53215327}
     
    53575363    return m_gestureController->completeSimulatedSwipeInDirectionForTesting(ViewGestureController::SwipeDirection::Back);
    53585364}
    5359    
     5365
    53605366void WebViewImpl::setUseSystemAppearance(bool useSystemAppearance)
    53615367{
  • trunk/Source/WebKit/UIProcess/mac/WebPopupMenuProxyMac.mm

    r250640 r251086  
    2929#if USE(APPKIT)
    3030
     31#import "CoreTextHelpers.h"
    3132#import "NativeWebMouseEvent.h"
    3233#import "PageClientImplMac.h"
     
    3435#import "StringUtilities.h"
    3536#import "WebPopupItem.h"
    36 #import <pal/spi/cocoa/CoreTextSPI.h>
    3737#import <pal/system/mac/PopupMenu.h>
    3838#import <wtf/BlockObjCExceptions.h>
     
    107107
    108108    if (data.fontInfo.fontAttributeDictionary) {
    109         RetainPtr<NSMutableDictionary> mutableDictionary = adoptNS([(__bridge NSDictionary *)data.fontInfo.fontAttributeDictionary.get() mutableCopy]);
    110 #if HAVE(NSFONT_WITH_OPTICAL_SIZING_BUG)
    111         if (id opticalSizeAttribute = [mutableDictionary objectForKey:(__bridge NSString *)kCTFontOpticalSizeAttribute]) {
    112             if ([opticalSizeAttribute isKindOfClass:[NSString class]]) {
    113                 [mutableDictionary removeObjectForKey:(__bridge NSString *)kCTFontOpticalSizeAttribute];
    114                 if (NSNumber *size = [mutableDictionary objectForKey:(__bridge NSString *)kCTFontSizeAttribute])
    115                     [mutableDictionary setObject:size forKey:(__bridge NSString *)kCTFontOpticalSizeAttribute];
    116             }
    117         }
    118 #endif
    119         NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:mutableDictionary.get()];
     109        PlatformFontDescriptor *fontDescriptor = fontDescriptorWithFontAttributes(static_cast<NSDictionary *>(data.fontInfo.fontAttributeDictionary.get()));
    120110        font = [NSFont fontWithDescriptor:fontDescriptor size:((pageScaleFactor != 1) ? [fontDescriptor pointSize] * pageScaleFactor : 0)];
    121111    } else
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r251022 r251086  
    24752475                1C20935F22318CB000026A39 /* NSAttributedString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSAttributedString.mm; sourceTree = "<group>"; };
    24762476                1C2184012233872800BAC700 /* NSAttributedStringPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSAttributedStringPrivate.h; sourceTree = "<group>"; };
     2477                1C739E852347BCF600C621EC /* CoreTextHelpers.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CoreTextHelpers.mm; sourceTree = "<group>"; };
     2478                1C739E872347BD0F00C621EC /* CoreTextHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CoreTextHelpers.h; sourceTree = "<group>"; };
    24772479                1C77C1951288A872006A742F /* WebInspectorProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebInspectorProxy.messages.in; sourceTree = "<group>"; };
    24782480                1C891D6219B124FF00BA79DD /* WebInspectorUI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebInspectorUI.cpp; sourceTree = "<group>"; };
     
    65196521                                37BEC4DF19491486008B4286 /* CompletionHandlerCallChecker.h */,
    65206522                                37BEC4DE19491486008B4286 /* CompletionHandlerCallChecker.mm */,
     6523                                1C739E872347BD0F00C621EC /* CoreTextHelpers.h */,
     6524                                1C739E852347BCF600C621EC /* CoreTextHelpers.mm */,
    65216525                                C55F916C1C595E440029E92D /* DataDetectionResult.h */,
    65226526                                C55F916D1C595E440029E92D /* DataDetectionResult.mm */,
Note: See TracChangeset for help on using the changeset viewer.