Diff
Modified: trunk/Source/WebCore/ChangeLog (242830 => 242831)
--- trunk/Source/WebCore/ChangeLog 2019-03-12 22:35:36 UTC (rev 242830)
+++ trunk/Source/WebCore/ChangeLog 2019-03-12 22:42:49 UTC (rev 242831)
@@ -1,3 +1,18 @@
+2019-03-12 Timothy Hatcher <[email protected]>
+
+ 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.
+
+ * editing/cocoa/HTMLConverter.h:
+ * editing/cocoa/HTMLConverter.mm:
+ (HTMLConverter::convert):
+ (WebCore::attributedStringFromRange):
+ (WebCore::attributedStringFromSelection):
+ (WebCore::attributedStringBetweenStartAndEnd):
+
2019-03-12 Antti Koivisto <[email protected]>
Compositing layer that renders two positioned elements should not hit test
Modified: trunk/Source/WebCore/PAL/ChangeLog (242830 => 242831)
--- trunk/Source/WebCore/PAL/ChangeLog 2019-03-12 22:35:36 UTC (rev 242830)
+++ trunk/Source/WebCore/PAL/ChangeLog 2019-03-12 22:42:49 UTC (rev 242831)
@@ -1,3 +1,14 @@
+2019-03-12 Timothy Hatcher <[email protected]>
+
+ 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.
+
+ * pal/spi/cocoa/NSAttributedStringSPI.h:
+ (NSBackgroundColorDocumentAttribute): Added.
+
2019-03-12 Jennifer Moore <[email protected]>
Check whether to launch a default action instead of action sheet
Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h (242830 => 242831)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h 2019-03-12 22:35:36 UTC (rev 242830)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/NSAttributedStringSPI.h 2019-03-12 22:42:49 UTC (rev 242831)
@@ -91,6 +91,8 @@
#define NSConvertedDocumentAttribute getNSConvertedDocumentAttribute()
SOFT_LINK_CONSTANT(UIFoundation, NSCocoaVersionDocumentAttribute, NSString *)
#define NSCocoaVersionDocumentAttribute getNSCocoaVersionDocumentAttribute()
+SOFT_LINK_CONSTANT(UIFoundation, NSBackgroundColorDocumentAttribute, NSString *)
+#define NSBackgroundColorDocumentAttribute getNSBackgroundColorDocumentAttribute()
// We don't softlink NSSuperscriptAttributeName because UIFoundation stopped exporting it.
// This attribute is being deprecated at the API level, but internally UIFoundation
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.h (242830 => 242831)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.h 2019-03-12 22:35:36 UTC (rev 242830)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.h 2019-03-12 22:42:49 UTC (rev 242831)
@@ -35,12 +35,12 @@
enum class IncludeImagesInAttributedString { Yes, No };
-NSAttributedString *attributedStringFromSelection(const VisibleSelection&);
+NSAttributedString *attributedStringFromSelection(const VisibleSelection&, NSDictionary** documentAttributes = nullptr);
// For testing purpose only
-WEBCORE_EXPORT NSAttributedString *attributedStringBetweenStartAndEnd(const Position&, const Position&);
+WEBCORE_EXPORT NSAttributedString *attributedStringBetweenStartAndEnd(const Position&, const Position&, NSDictionary** documentAttributes = nullptr);
-WEBCORE_EXPORT NSAttributedString *attributedStringFromRange(Range&);
+WEBCORE_EXPORT NSAttributedString *attributedStringFromRange(Range&, NSDictionary** documentAttributes = nullptr);
#if !PLATFORM(IOS_FAMILY)
WEBCORE_EXPORT NSAttributedString *editingAttributedStringFromRange(Range&, IncludeImagesInAttributedString = IncludeImagesInAttributedString::Yes);
#endif
Modified: trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm (242830 => 242831)
--- trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2019-03-12 22:35:36 UTC (rev 242830)
+++ trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm 2019-03-12 22:42:49 UTC (rev 242831)
@@ -276,9 +276,9 @@
public:
HTMLConverter(const Position&, const Position&);
~HTMLConverter();
-
- NSAttributedString* convert();
-
+
+ NSAttributedString* convert(NSDictionary** documentAttributes = nullptr);
+
private:
Position m_start;
Position m_end;
@@ -396,7 +396,7 @@
[_writingDirectionArray release];
}
-NSAttributedString *HTMLConverter::convert()
+NSAttributedString *HTMLConverter::convert(NSDictionary** documentAttributes)
{
if (comparePositions(m_start, m_end) > 0)
return nil;
@@ -408,11 +408,20 @@
if (!m_dataSource)
return nil;
+ Document& document = commonAncestorContainer->document();
+ if (auto* body = document.bodyOrFrameset()) {
+ if (PlatformColor *backgroundColor = _colorForElement(*body, CSSPropertyBackgroundColor))
+ [_documentAttrs setObject:backgroundColor forKey:NSBackgroundColorDocumentAttribute];
+ }
+
_domRangeStartIndex = 0;
_traverseNode(*commonAncestorContainer, 0, false /* embedded */);
if (_domRangeStartIndex > 0 && _domRangeStartIndex <= [_attrStr length])
[_attrStr deleteCharactersInRange:NSMakeRange(0, _domRangeStartIndex)];
+ if (documentAttributes)
+ *documentAttributes = [[_documentAttrs retain] autorelease];
+
return [[_attrStr retain] autorelease];
}
@@ -2375,23 +2384,23 @@
#endif
namespace WebCore {
-
+
// This function supports more HTML features than the editing variant below, such as tables.
-NSAttributedString *attributedStringFromRange(Range& range)
+NSAttributedString *attributedStringFromRange(Range& range, NSDictionary** documentAttributes)
{
- return HTMLConverter { range.startPosition(), range.endPosition() }.convert();
+ return HTMLConverter { range.startPosition(), range.endPosition() }.convert(documentAttributes);
}
-NSAttributedString *attributedStringFromSelection(const VisibleSelection& selection)
+NSAttributedString *attributedStringFromSelection(const VisibleSelection& selection, NSDictionary** documentAttributes)
{
- return attributedStringBetweenStartAndEnd(selection.start(), selection.end());
+ return attributedStringBetweenStartAndEnd(selection.start(), selection.end(), documentAttributes);
}
-NSAttributedString *attributedStringBetweenStartAndEnd(const Position& start, const Position& end)
+NSAttributedString *attributedStringBetweenStartAndEnd(const Position& start, const Position& end, NSDictionary** documentAttributes)
{
- return HTMLConverter { start, end }.convert();
+ return HTMLConverter { start, end }.convert(documentAttributes);
}
-
+
#if !PLATFORM(IOS_FAMILY)
// This function uses TextIterator, which makes offsets in its result compatible with HTML editing.