Changeset 242831 in webkit


Ignore:
Timestamp:
Mar 12, 2019 3:42:49 PM (5 years ago)
Author:
timothy@apple.com
Message:

Expose document attributes and body background color through HTMLConverter.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Tim Horton.

Source/WebCore:

  • editing/cocoa/HTMLConverter.h:
  • editing/cocoa/HTMLConverter.mm:

(HTMLConverter::convert):
(WebCore::attributedStringFromRange):
(WebCore::attributedStringFromSelection):
(WebCore::attributedStringBetweenStartAndEnd):

Source/WebCore/PAL:

  • pal/spi/cocoa/NSAttributedStringSPI.h:

(NSBackgroundColorDocumentAttribute): Added.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242830 r242831  
     12019-03-12  Timothy Hatcher  <timothy@apple.com>
     2
     3        Expose document attributes and body background color through HTMLConverter.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Tim Horton.
     8
     9        * editing/cocoa/HTMLConverter.h:
     10        * editing/cocoa/HTMLConverter.mm:
     11        (HTMLConverter::convert):
     12        (WebCore::attributedStringFromRange):
     13        (WebCore::attributedStringFromSelection):
     14        (WebCore::attributedStringBetweenStartAndEnd):
     15
    1162019-03-12  Antti Koivisto  <antti@apple.com>
    217
  • trunk/Source/WebCore/PAL/ChangeLog

    r242801 r242831  
     12019-03-12  Timothy Hatcher  <timothy@apple.com>
     2
     3        Expose document attributes and body background color through HTMLConverter.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Tim Horton.
     8
     9        * pal/spi/cocoa/NSAttributedStringSPI.h:
     10        (NSBackgroundColorDocumentAttribute): Added.
     11
    1122019-03-12  Jennifer Moore  <jennifer.moore@apple.com>
    213
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h

    r237266 r242831  
    9292SOFT_LINK_CONSTANT(UIFoundation, NSCocoaVersionDocumentAttribute, NSString *)
    9393#define NSCocoaVersionDocumentAttribute getNSCocoaVersionDocumentAttribute()
     94SOFT_LINK_CONSTANT(UIFoundation, NSBackgroundColorDocumentAttribute, NSString *)
     95#define NSBackgroundColorDocumentAttribute getNSBackgroundColorDocumentAttribute()
    9496
    9597// We don't softlink NSSuperscriptAttributeName because UIFoundation stopped exporting it.
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.h

    r239149 r242831  
    3636enum class IncludeImagesInAttributedString { Yes, No };
    3737
    38 NSAttributedString *attributedStringFromSelection(const VisibleSelection&);
     38NSAttributedString *attributedStringFromSelection(const VisibleSelection&, NSDictionary** documentAttributes = nullptr);
    3939
    4040// For testing purpose only
    41 WEBCORE_EXPORT NSAttributedString *attributedStringBetweenStartAndEnd(const Position&, const Position&);
     41WEBCORE_EXPORT NSAttributedString *attributedStringBetweenStartAndEnd(const Position&, const Position&, NSDictionary** documentAttributes = nullptr);
    4242
    43 WEBCORE_EXPORT NSAttributedString *attributedStringFromRange(Range&);
     43WEBCORE_EXPORT NSAttributedString *attributedStringFromRange(Range&, NSDictionary** documentAttributes = nullptr);
    4444#if !PLATFORM(IOS_FAMILY)
    4545WEBCORE_EXPORT NSAttributedString *editingAttributedStringFromRange(Range&, IncludeImagesInAttributedString = IncludeImagesInAttributedString::Yes);
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r241183 r242831  
    277277    HTMLConverter(const Position&, const Position&);
    278278    ~HTMLConverter();
    279    
    280     NSAttributedString* convert();
    281    
     279
     280    NSAttributedString* convert(NSDictionary** documentAttributes = nullptr);
     281
    282282private:
    283283    Position m_start;
     
    397397}
    398398
    399 NSAttributedString *HTMLConverter::convert()
     399NSAttributedString *HTMLConverter::convert(NSDictionary** documentAttributes)
    400400{
    401401    if (comparePositions(m_start, m_end) > 0)
     
    408408    if (!m_dataSource)
    409409        return nil;
     410
     411    Document& document = commonAncestorContainer->document();
     412    if (auto* body = document.bodyOrFrameset()) {
     413        if (PlatformColor *backgroundColor = _colorForElement(*body, CSSPropertyBackgroundColor))
     414            [_documentAttrs setObject:backgroundColor forKey:NSBackgroundColorDocumentAttribute];
     415    }
    410416
    411417    _domRangeStartIndex = 0;
     
    413419    if (_domRangeStartIndex > 0 && _domRangeStartIndex <= [_attrStr length])
    414420        [_attrStr deleteCharactersInRange:NSMakeRange(0, _domRangeStartIndex)];
     421
     422    if (documentAttributes)
     423        *documentAttributes = [[_documentAttrs retain] autorelease];
    415424
    416425    return [[_attrStr retain] autorelease];
     
    23762385
    23772386namespace WebCore {
    2378    
     2387
    23792388// This function supports more HTML features than the editing variant below, such as tables.
    2380 NSAttributedString *attributedStringFromRange(Range& range)
    2381 {
    2382     return HTMLConverter { range.startPosition(), range.endPosition() }.convert();
    2383 }
    2384 
    2385 NSAttributedString *attributedStringFromSelection(const VisibleSelection& selection)
    2386 {
    2387     return attributedStringBetweenStartAndEnd(selection.start(), selection.end());
    2388 }
    2389 
    2390 NSAttributedString *attributedStringBetweenStartAndEnd(const Position& start, const Position& end)
    2391 {
    2392     return HTMLConverter { start, end }.convert();
    2393 }
    2394    
     2389NSAttributedString *attributedStringFromRange(Range& range, NSDictionary** documentAttributes)
     2390{
     2391    return HTMLConverter { range.startPosition(), range.endPosition() }.convert(documentAttributes);
     2392}
     2393
     2394NSAttributedString *attributedStringFromSelection(const VisibleSelection& selection, NSDictionary** documentAttributes)
     2395{
     2396    return attributedStringBetweenStartAndEnd(selection.start(), selection.end(), documentAttributes);
     2397}
     2398
     2399NSAttributedString *attributedStringBetweenStartAndEnd(const Position& start, const Position& end, NSDictionary** documentAttributes)
     2400{
     2401    return HTMLConverter { start, end }.convert(documentAttributes);
     2402}
     2403
    23952404#if !PLATFORM(IOS_FAMILY)
    23962405
Note: See TracChangeset for help on using the changeset viewer.