Changeset 166145 in webkit


Ignore:
Timestamp:
Mar 23, 2014 2:41:17 PM (10 years ago)
Author:
weinig@apple.com
Message:

Simplify the HTMLConverter interface (Part 2)
https://bugs.webkit.org/show_bug.cgi?id=130654

Reviewed by Darin Adler.

../WebCore:

Switch HTMLConverter from using an Objective-C interface to C functions.

  • WebCore.exp.in:
  • editing/ios/EditorIOS.mm:

(WebCore::Editor::writeSelectionToPasteboard):

  • editing/mac/EditorMac.mm:

(WebCore::Editor::dataSelectionForPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):

  • platform/ios/PasteboardIOS.mm:
  • platform/mac/HTMLConverter.h:
  • platform/mac/HTMLConverter.mm:

(WebCore::attributedStringFromRange):
(WebCore::editingAttributedStringFromRange):

  • platform/mac/PasteboardMac.mm:

../WebKit/mac:

  • WebView/WebHTMLRepresentation.mm:

(-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):

  • WebView/WebHTMLView.mm:

(-[WebHTMLView attributedSubstringFromRange:]):
(-[WebHTMLView attributedString]):
(-[WebHTMLView selectedAttributedString]):

../WebKit2:

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::performDictionaryLookupForRange):

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::getAttributedSubstringFromRange):
(WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
(WebKit::WebPage::performDictionaryLookupAtLocation):
(WebKit::WebPage::performDictionaryLookupForSelection):
(WebKit::WebPage::performDictionaryLookupForRange):

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r166144 r166145  
     12014-03-23  Sam Weinig  <sam@webkit.org>
     2
     3        Simplify the HTMLConverter interface (Part 2)
     4        https://bugs.webkit.org/show_bug.cgi?id=130654
     5
     6        Reviewed by Darin Adler.
     7
     8        Switch HTMLConverter from using an Objective-C interface to C functions.
     9
     10        * WebCore.exp.in:
     11        * editing/ios/EditorIOS.mm:
     12        (WebCore::Editor::writeSelectionToPasteboard):
     13        * editing/mac/EditorMac.mm:
     14        (WebCore::Editor::dataSelectionForPasteboard):
     15        (WebCore::Editor::writeSelectionToPasteboard):
     16        * platform/ios/PasteboardIOS.mm:
     17        * platform/mac/HTMLConverter.h:
     18        * platform/mac/HTMLConverter.mm:
     19        (WebCore::attributedStringFromRange):
     20        (WebCore::editingAttributedStringFromRange):
     21        * platform/mac/PasteboardMac.mm:
     22
    1232014-03-23  Darin Adler  <darin@apple.com>
    224
  • trunk/Source/WebCore/WebCore.exp.in

    r166110 r166145  
    21102110.objc_class_name_WebCoreFullScreenWindow
    21112111.objc_class_name_WebFontCache
    2112 .objc_class_name_WebHTMLConverter
    21132112.objc_class_name_WebWindowFadeAnimation
    21142113.objc_class_name_WebWindowScaleAnimation
     
    21962195__ZN7WebCore32contextMenuItemTagInspectElementEv
    21972196__ZN7WebCore32contextMenuItemTagSmartCopyPasteEv
     2197__ZN7WebCore32editingAttributedStringFromRangeERNS_5RangeE
    21982198__ZN7WebCore32useBlockedPlugInContextMenuTitleEv
    21992199__ZN7WebCore33contextMenuItemTagTextReplacementEv
  • trunk/Source/WebCore/editing/ios/EditorIOS.mm

    r166143 r166145  
    298298}
    299299
    300 // FIXME: the following fuctions should be shared between Mac and iOS.
    301 static NSAttributedString *attributedStringForRange(Range& range)
    302 {
    303     return [WebHTMLConverter attributedStringFromRange:&range];
    304 }
    305 
    306300static PassRefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *string)
    307301{
     
    331325void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
    332326{
    333     NSAttributedString *attributedString = attributedStringForRange(*selectedRange());
     327    NSAttributedString *attributedString = attributedStringFromRange(selectedRange());
    334328
    335329    PasteboardWebContent content;
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r166143 r166145  
    304304    return range;
    305305}
    306 
    307 static NSAttributedString *attributedStringForRange(Range& range)
    308 {
    309     return [WebHTMLConverter attributedStringFromRange:&range];
    310 }
    311 
     306   
    312307static PassRefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *string)
    313308{
     
    336331
    337332    if (pasteboardType == String(NSRTFDPboardType))
    338        return dataInRTFDFormat(attributedStringForRange(*adjustedSelectionRange()));
     333       return dataInRTFDFormat(attributedStringFromRange(*adjustedSelectionRange()));
    339334
    340335    if (pasteboardType == String(NSRTFPboardType)) {
    341         NSAttributedString* attributedString = attributedStringForRange(*adjustedSelectionRange());
     336        NSAttributedString* attributedString = attributedStringFromRange(*adjustedSelectionRange());
    342337        // FIXME: Why is this attachment character stripping needed here, but not needed in writeSelectionToPasteboard?
    343338        if ([attributedString containsAttachments])
     
    351346void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
    352347{
    353     NSAttributedString *attributedString = attributedStringForRange(*selectedRange());
     348    NSAttributedString *attributedString = attributedStringFromRange(*selectedRange());
    354349
    355350    PasteboardWebContent content;
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r162997 r166145  
    3636#import "FrameLoader.h"
    3737#import "FrameLoaderClient.h"
    38 #import "HTMLConverter.h"
    3938#import "HTMLElement.h"
    4039#import "HTMLNames.h"
  • trunk/Source/WebCore/platform/mac/HTMLConverter.h

    r166143 r166145  
    2424 */
    2525
    26 @class DOMDocument;
    27 @class DOMRange;
     26#ifndef HTMLConverter_h
     27#define HTMLConverter_h
     28
     29OBJC_CLASS NSAttributedString;
    2830
    2931namespace WebCore {
    30     class DocumentLoader;
    31     class Range;
     32   
     33class Range;
     34   
     35NSAttributedString *attributedStringFromRange(Range&);
     36#if !PLATFORM(IOS)
     37NSAttributedString *editingAttributedStringFromRange(Range&);
     38#endif
     39
    3240}
    3341
    34 class HTMLConverterCaches;
    35 
    36 @interface WebHTMLConverter : NSObject {
    37     NSMutableAttributedString *_attrStr;
    38     NSMutableDictionary *_documentAttrs;
    39     NSURL *_baseURL;
    40     DOMDocument *_document;
    41     DOMRange *_domRange;
    42     NSMutableArray *_domStartAncestors;
    43     WebCore::DocumentLoader *_dataSource;
    44     NSString *_standardFontFamily;
    45     CGFloat _textSizeMultiplier;
    46     CGFloat _webViewTextSizeMultiplier;
    47     CGFloat _defaultTabInterval;
    48     CGFloat _defaultFontSize;
    49     CGFloat _minimumFontSize;
    50     NSMutableArray *_textLists;
    51     NSMutableArray *_textBlocks;
    52     NSMutableArray *_textTables;
    53     NSMutableDictionary *_textTableFooters;
    54     NSMutableArray *_textTableSpacings;
    55     NSMutableArray *_textTablePaddings;
    56     NSMutableArray *_textTableRows;
    57     NSMutableArray *_textTableRowArrays;
    58     NSMutableArray *_textTableRowBackgroundColors;
    59     NSMutableDictionary *_colorsForNodes;
    60     NSMutableDictionary *_attributesForElements;
    61     NSMutableDictionary *_fontCache;
    62     NSMutableArray *_writingDirectionArray;
    63     NSUInteger _domRangeStartIndex;
    64     NSInteger _indexingLimit;
    65     NSUInteger _thumbnailLimit;
    66     NSInteger _errorCode;
    67     NSInteger _quoteLevel;
    68 
    69     std::unique_ptr<HTMLConverterCaches> _caches;
    70 
    71     struct {
    72         unsigned int isSoft:1;
    73         unsigned int reachedStart:1;
    74         unsigned int reachedEnd:1;
    75         unsigned int isIndexing:1;
    76         unsigned int isTesting:1;
    77         unsigned int hasTrailingNewline:1;
    78         unsigned int pad:26;
    79     } _flags;
    80 }
    81 
    82 
    83 + (NSAttributedString *)attributedStringFromRange:(WebCore::Range*)range;
    84 #if !PLATFORM(IOS)
    85 + (NSAttributedString *)editingAttributedStringFromRange:(WebCore::Range*)range;
    86 #endif
    87 @end
    88 
     42#endif // HTMLConverter_h
  • trunk/Source/WebCore/platform/mac/HTMLConverter.mm

    r166143 r166145  
    427427@interface NSObject(WebMessageDocumentSimulation)
    428428+ (void)document:(NSObject **)outDocument attachment:(NSTextAttachment **)outAttachment forURL:(NSURL *)url;
     429@end
     430
     431@interface WebHTMLConverter : NSObject {
     432    NSMutableAttributedString *_attrStr;
     433    NSMutableDictionary *_documentAttrs;
     434    NSURL *_baseURL;
     435    DOMDocument *_document;
     436    DOMRange *_domRange;
     437    NSMutableArray *_domStartAncestors;
     438    WebCore::DocumentLoader *_dataSource;
     439    NSString *_standardFontFamily;
     440    CGFloat _textSizeMultiplier;
     441    CGFloat _webViewTextSizeMultiplier;
     442    CGFloat _defaultTabInterval;
     443    CGFloat _defaultFontSize;
     444    CGFloat _minimumFontSize;
     445    NSMutableArray *_textLists;
     446    NSMutableArray *_textBlocks;
     447    NSMutableArray *_textTables;
     448    NSMutableDictionary *_textTableFooters;
     449    NSMutableArray *_textTableSpacings;
     450    NSMutableArray *_textTablePaddings;
     451    NSMutableArray *_textTableRows;
     452    NSMutableArray *_textTableRowArrays;
     453    NSMutableArray *_textTableRowBackgroundColors;
     454    NSMutableDictionary *_colorsForNodes;
     455    NSMutableDictionary *_attributesForElements;
     456    NSMutableDictionary *_fontCache;
     457    NSMutableArray *_writingDirectionArray;
     458    NSUInteger _domRangeStartIndex;
     459    NSInteger _indexingLimit;
     460    NSUInteger _thumbnailLimit;
     461    NSInteger _errorCode;
     462    NSInteger _quoteLevel;
     463
     464    std::unique_ptr<HTMLConverterCaches> _caches;
     465
     466    struct {
     467        unsigned int isSoft:1;
     468        unsigned int reachedStart:1;
     469        unsigned int reachedEnd:1;
     470        unsigned int isIndexing:1;
     471        unsigned int isTesting:1;
     472        unsigned int hasTrailingNewline:1;
     473        unsigned int pad:26;
     474    } _flags;
     475}
     476
     477+ (NSAttributedString *)attributedStringFromRange:(Range*)range;
     478#if !PLATFORM(IOS)
     479+ (NSAttributedString *)editingAttributedStringFromRange:(Range*)range;
     480#endif
    429481@end
    430482
     
    25792631
    25802632#endif
     2633
     2634namespace WebCore {
     2635   
     2636NSAttributedString *attributedStringFromRange(Range& range)
     2637{
     2638    return [WebHTMLConverter attributedStringFromRange:&range];
     2639}
     2640   
     2641#if !PLATFORM(IOS)
     2642NSAttributedString *editingAttributedStringFromRange(Range& range)
     2643{
     2644    return [WebHTMLConverter editingAttributedStringFromRange:&range];
     2645}
     2646#endif
     2647   
     2648}
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r165676 r166145  
    4242#import "HitTestResult.h"
    4343#import "HTMLAnchorElement.h"
    44 #import "HTMLConverter.h"
    4544#import "htmlediting.h"
    4645#import "HTMLNames.h"
  • trunk/Source/WebKit/mac/ChangeLog

    r166144 r166145  
     12014-03-23  Sam Weinig  <sam@webkit.org>
     2
     3        Simplify the HTMLConverter interface (Part 2)
     4        https://bugs.webkit.org/show_bug.cgi?id=130654
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebView/WebHTMLRepresentation.mm:
     9        (-[WebHTMLRepresentation attributedStringFrom:startOffset:to:endOffset:]):
     10        * WebView/WebHTMLView.mm:
     11        (-[WebHTMLView attributedSubstringFromRange:]):
     12        (-[WebHTMLView attributedString]):
     13        (-[WebHTMLView selectedAttributedString]):
     14
    1152014-03-23  Darin Adler  <darin@apple.com>
    216
  • trunk/Source/WebKit/mac/WebView/WebHTMLRepresentation.mm

    r166047 r166145  
    278278- (NSAttributedString *)attributedStringFrom:(DOMNode *)startNode startOffset:(int)startOffset to:(DOMNode *)endNode endOffset:(int)endOffset
    279279{
    280     return [WebHTMLConverter editingAttributedStringFromRange:Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset).get()];
     280    return editingAttributedStringFromRange(*Range::create(core(startNode)->document(), core(startNode), startOffset, core(endNode), endOffset).get());
    281281}
    282282#endif
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r165676 r166145  
    61716171    }
    61726172
    6173     NSAttributedString *result = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
    6174    
    6175     // [WebHTMLConverter editingAttributedStringFromRange:]  insists on inserting a trailing
     6173    NSAttributedString *result = editingAttributedStringFromRange(*range);
     6174   
     6175    // WebCore::editingAttributedStringFromRange() insists on inserting a trailing
    61766176    // whitespace at the end of the string which breaks the ATOK input method.  <rdar://problem/5400551>
    61776177    // To work around this we truncate the resultant string to the correct length.
     
    66436643    if (!attributedString) {
    66446644        Document* coreDocument = core(document);
    6645         attributedString = [WebHTMLConverter editingAttributedStringFromRange:Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->childNodeCount()).get()];
     6645        attributedString = editingAttributedStringFromRange(*Range::create(*coreDocument, coreDocument, 0, coreDocument, coreDocument->childNodeCount()).get());
    66466646    }
    66476647    return attributedString;
     
    66626662        if (coreFrame) {
    66636663            RefPtr<Range> range = coreFrame->selection().selection().toNormalizedRange();
    6664             attributedString = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
     6664            if (range)
     6665                attributedString = editingAttributedStringFromRange(*range);
     6666            else
     6667                attributedString = [[[NSAttributedString alloc] init] autorelease];
    66656668        }
    66666669    }
  • trunk/Source/WebKit2/ChangeLog

    r166140 r166145  
     12014-03-23  Sam Weinig  <sam@webkit.org>
     2
     3        Simplify the HTMLConverter interface (Part 2)
     4        https://bugs.webkit.org/show_bug.cgi?id=130654
     5
     6        Reviewed by Darin Adler.
     7
     8        * WebProcess/WebPage/WebPage.h:
     9        * WebProcess/WebPage/ios/WebPageIOS.mm:
     10        (WebKit::WebPage::performDictionaryLookupForRange):
     11        * WebProcess/WebPage/mac/WebPageMac.mm:
     12        (WebKit::WebPage::getAttributedSubstringFromRange):
     13        (WebKit::WebPage::attributedSubstringForCharacterRangeAsync):
     14        (WebKit::WebPage::performDictionaryLookupAtLocation):
     15        (WebKit::WebPage::performDictionaryLookupForSelection):
     16        (WebKit::WebPage::performDictionaryLookupForRange):
     17
    1182014-03-23  David Kilzer  <ddkilzer@apple.com>
    219
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r166017 r166145  
    883883#if PLATFORM(COCOA)
    884884    void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
    885     void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range*, NSDictionary *options);
     885    void performDictionaryLookupForRange(WebCore::Frame*, WebCore::Range&, NSDictionary *options);
    886886
    887887    void windowAndViewFramesChanged(const WebCore::FloatRect& windowFrameInScreenCoordinates, const WebCore::FloatRect& windowFrameInUnflippedScreenCoordinates, const WebCore::FloatRect& viewFrameInWindowCoordinates, const WebCore::FloatPoint& accessibilityViewCoordinates);
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r166110 r166145  
    172172}
    173173
    174 void WebPage::performDictionaryLookupForRange(Frame*, Range*, NSDictionary *)
     174void WebPage::performDictionaryLookupForRange(Frame*, Range&, NSDictionary *)
    175175{
    176176    notImplemented();
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r166002 r166145  
    348348        return;
    349349
    350     result.string = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
     350    result.string = editingAttributedStringFromRange(*range);
    351351    NSAttributedString* attributedString = result.string.get();
    352352   
    353     // [WebHTMLConverter editingAttributedStringFromRange:] insists on inserting a trailing
     353    // WebCore::editingAttributedStringFromRange() insists on inserting a trailing
    354354    // whitespace at the end of the string which breaks the ATOK input method.  <rdar://problem/5400551>
    355355    // To work around this we truncate the resultant string to the correct length.
     
    442442    }
    443443
    444     result.string = [WebHTMLConverter editingAttributedStringFromRange:range.get()];
     444    result.string = editingAttributedStringFromRange(*range);
    445445    NSAttributedString* attributedString = result.string.get();
    446446   
    447     // [WebHTMLConverter editingAttributedStringFromRange:] insists on inserting a trailing
     447    // WebCore::editingAttributedStringFromRange() insists on inserting a trailing
    448448    // whitespace at the end of the string which breaks the ATOK input method.  <rdar://problem/5400551>
    449449    // To work around this we truncate the resultant string to the correct length.
     
    553553        return;
    554554
    555     performDictionaryLookupForRange(frame, finalRange.get(), options);
     555    performDictionaryLookupForRange(frame, *finalRange, options);
    556556}
    557557
     
    580580    WKExtractWordDefinitionTokenRangeFromContextualString(fullPlainTextString, rangeToPass, &options);
    581581
    582     performDictionaryLookupForRange(frame, selectedRange.get(), options);
    583 }
    584 
    585 void WebPage::performDictionaryLookupForRange(Frame* frame, Range* range, NSDictionary *options)
    586 {
    587     if (range->text().stripWhiteSpace().isEmpty())
    588         return;
    589    
    590     RenderObject* renderer = range->startContainer()->renderer();
     582    performDictionaryLookupForRange(frame, *selectedRange, options);
     583}
     584
     585void WebPage::performDictionaryLookupForRange(Frame* frame, Range& range, NSDictionary *options)
     586{
     587    if (range.text().stripWhiteSpace().isEmpty())
     588        return;
     589   
     590    RenderObject* renderer = range.startContainer()->renderer();
    591591    const RenderStyle& style = renderer->style();
    592592
    593593    Vector<FloatQuad> quads;
    594     range->textQuads(quads);
     594    range.textQuads(quads);
    595595    if (quads.isEmpty())
    596596        return;
     
    602602    dictionaryPopupInfo.options = (CFDictionaryRef)options;
    603603
    604     NSAttributedString *nsAttributedString = [WebHTMLConverter editingAttributedStringFromRange:range];
     604    NSAttributedString *nsAttributedString = editingAttributedStringFromRange(range);
    605605
    606606    RetainPtr<NSMutableAttributedString> scaledNSAttributedString = adoptNS([[NSMutableAttributedString alloc] initWithString:[nsAttributedString string]]);
Note: See TracChangeset for help on using the changeset viewer.