Make TextInputController.legacyAttributedString take DOM nodes and offsets
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2018 03:54:13 +0000 (03:54 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Dec 2018 03:54:13 +0000 (03:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192653

Reviewed by Wenson Hsieh.

Source/WebCore:

No new tests since there should be no observable behavioral change other than
TextInputController API in DumpRenderTree.

* editing/cocoa/HTMLConverter.h:
* editing/cocoa/HTMLConverter.mm:
(WebCore::attributedStringFromSelection):
(WebCore::attributedStringBetweenStartAndEnd): Added.

Source/WebKitLegacy/mac:

* WebView/WebHTMLView.mm:
(-[WebHTMLView _legacyAttributedStringFrom:offset:to:offset:]):

Tools:

Updated TextInputController.legacyAttributedString to take DOM nodes and offsets instead of
a DOM Range object in preparation to add layout tests for HTMLConverter which crosses
shadow boundaries.

* DumpRenderTree/mac/TextInputControllerMac.m:
(+[TextInputController isSelectorExcludedFromWebScript:]): Updated the selector signature.
(+[TextInputController webScriptNameForSelector:]): Ditto.
(-[TextInputController legacyAttributedString:offset:to:offset:]): Made this function take
start node and offset then end node and offset pairs.

LayoutTests:

Updated the tests per API change.

* editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html:
* editing/mac/attributed-string/resources/dump-attributed-string.js:
(dumpAttributedString):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239149 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html
LayoutTests/editing/mac/attributed-string/resources/dump-attributed-string.js
Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/HTMLConverter.h
Source/WebCore/editing/cocoa/HTMLConverter.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Tools/ChangeLog
Tools/DumpRenderTree/mac/TextInputControllerMac.m

index a09c3a8..d0a675c 100644 (file)
@@ -1,3 +1,16 @@
+2018-12-12  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Make TextInputController.legacyAttributedString take DOM nodes and offsets
+        https://bugs.webkit.org/show_bug.cgi?id=192653
+
+        Reviewed by Wenson Hsieh.
+
+        Updated the tests per API change.
+
+        * editing/mac/attributed-string/attribute-string-for-copy-with-color-filter.html:
+        * editing/mac/attributed-string/resources/dump-attributed-string.js:
+        (dumpAttributedString):
+
 2018-12-12  Simon Fraser  <simon.fraser@apple.com>
 
         REGRESSION (r238357): Pins on Yelp map disappear
index a7b574d..6e204a8 100644 (file)
         var target = document.getElementById("target");
         target.focus();
 
-        const range = new Range;
-        range.setStart(target.firstChild, 2);
-        range.setEnd(target.firstChild, 4);
-
-        var attributedString = textInputController.legacyAttributedString(range);
+        var attributedString = textInputController.legacyAttributedString(target.firstChild, 2, target.firstChild, 4);
         var serializedString = serializeAttributedString(attributedString);
         log(serializedString);
 
index 4898520..e556011 100644 (file)
@@ -15,7 +15,8 @@ var shouldAutoDump = true;
         range.selectNodeContents(container);
 
         var pre = document.createElement('pre');
-        pre.textContent = 'Input:\n' + container.innerHTML.trim() + '\n\nOutput:\n' + serializeAttributedString(textInputController.legacyAttributedString(range));
+        var result = serializeAttributedString(textInputController.legacyAttributedString(container, 0, container, container.childNodes.length));
+        pre.textContent = 'Input:\n' + container.innerHTML.trim() + '\n\nOutput:\n' + result;
 
         body.innerHTML = '';
         body.appendChild(pre);
index d451b6c..1056f21 100644 (file)
@@ -1,3 +1,18 @@
+2018-12-13  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Make TextInputController.legacyAttributedString take DOM nodes and offsets
+        https://bugs.webkit.org/show_bug.cgi?id=192653
+
+        Reviewed by Wenson Hsieh.
+
+        No new tests since there should be no observable behavioral change other than
+        TextInputController API in DumpRenderTree.
+
+        * editing/cocoa/HTMLConverter.h:
+        * editing/cocoa/HTMLConverter.mm:
+        (WebCore::attributedStringFromSelection):
+        (WebCore::attributedStringBetweenStartAndEnd): Added.
+
 2018-12-12  Ryosuke Niwa  <rniwa@webkit.org>
 
         Fix macOS builds after r239145.
index f05c9a0..2d55a43 100644 (file)
 OBJC_CLASS NSAttributedString;
 
 namespace WebCore {
-    
+
+class Position;
 class Range;
 class VisibleSelection;
 
 enum class IncludeImagesInAttributedString { Yes, No };
 
 NSAttributedString *attributedStringFromSelection(const VisibleSelection&);
+
+// For testing purpose only
+WEBCORE_EXPORT NSAttributedString *attributedStringBetweenStartAndEnd(const Position&, const Position&);
+
 WEBCORE_EXPORT NSAttributedString *attributedStringFromRange(Range&);
 #if !PLATFORM(IOS_FAMILY)
 WEBCORE_EXPORT NSAttributedString *editingAttributedStringFromRange(Range&, IncludeImagesInAttributedString = IncludeImagesInAttributedString::Yes);
index b7698c4..d3b9d76 100644 (file)
@@ -2467,7 +2467,12 @@ NSAttributedString *attributedStringFromSelection(const VisibleSelection& select
 {
     auto range = selection.toNormalizedRange();
     ASSERT(range);
-    return HTMLConverter { range->startPosition(), range->endPosition() }.convert();
+    return attributedStringBetweenStartAndEnd(range->startPosition(), range->endPosition());
+}
+
+NSAttributedString *attributedStringBetweenStartAndEnd(const Position& start, const Position& end)
+{
+    return HTMLConverter { start, end }.convert();
 }
     
 #if !PLATFORM(IOS_FAMILY)
index 3b69319..3570259 100644 (file)
@@ -1,3 +1,13 @@
+2018-12-12  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Make TextInputController.legacyAttributedString take DOM nodes and offsets
+        https://bugs.webkit.org/show_bug.cgi?id=192653
+
+        Reviewed by Wenson Hsieh.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _legacyAttributedStringFrom:offset:to:offset:]):
+
 2018-12-11  Justin Michaud  <justin_michaud@apple.com>
 
         Implement feature flag for CSS Typed OM
index f05c7be..9c3c2bb 100644 (file)
@@ -7032,6 +7032,13 @@ static CGImageRef selectionImage(Frame* frame, bool forceBlackText)
     return attributedString;
 }
 
+- (NSAttributedString *)_legacyAttributedStringFrom:(DOMNode*)startContainer offset:(int)startOffset to:(DOMNode*)endContainer offset:(int)endOffset
+{
+    return attributedStringBetweenStartAndEnd(
+        Position { core(startContainer), startOffset, Position::PositionIsOffsetInAnchor },
+        Position { core(endContainer), endOffset, Position::PositionIsOffsetInAnchor });
+}
+
 - (NSAttributedString *)attributedString
 {
     DOMDocument *document = [[self _frame] DOMDocument];
index b10696e..7da31ab 100644 (file)
@@ -1,3 +1,20 @@
+2018-12-12  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Make TextInputController.legacyAttributedString take DOM nodes and offsets
+        https://bugs.webkit.org/show_bug.cgi?id=192653
+
+        Reviewed by Wenson Hsieh.
+
+        Updated TextInputController.legacyAttributedString to take DOM nodes and offsets instead of
+        a DOM Range object in preparation to add layout tests for HTMLConverter which crosses
+        shadow boundaries.
+
+        * DumpRenderTree/mac/TextInputControllerMac.m:
+        (+[TextInputController isSelectorExcludedFromWebScript:]): Updated the selector signature.
+        (+[TextInputController webScriptNameForSelector:]): Ditto.
+        (-[TextInputController legacyAttributedString:offset:to:offset:]): Made this function take
+        start node and offset then end node and offset pairs.
+
 2018-12-12  Alex Christensen  <achristensen@webkit.org>
 
         Implement safe browsing in WebKit on WatchOS
index 440f40b..227c963 100644 (file)
@@ -64,6 +64,7 @@ NSString *NSTextInsertionUndoableAttributeName;
 @interface WebHTMLView (WebKitSecretsTextInputControllerIsAwareOf)
 - (WebFrame *)_frame;
 - (NSAttributedString *)_attributedStringFromDOMRange:(DOMRange *)range;
+- (NSAttributedString *)_legacyAttributedStringFrom:(DOMNode*)startContainer offset:(int)startOffset to:(DOMNode*)endContainer offset:(int)endOffset;
 @end
 
 @implementation WebHTMLView (DumpRenderTreeInputMethodHandler)
@@ -230,7 +231,7 @@ NSString *NSTextInsertionUndoableAttributeName;
         || aSelector == @selector(conversationIdentifier)
         || aSelector == @selector(substringFrom:length:)
         || aSelector == @selector(attributedSubstringFrom:length:)
-        || aSelector == @selector(legacyAttributedString:)
+        || aSelector == @selector(legacyAttributedString:offset:to:offset:)
         || aSelector == @selector(markedRange)
         || aSelector == @selector(selectedRange)
         || aSelector == @selector(firstRectForCharactersFrom:length:)
@@ -257,7 +258,7 @@ NSString *NSTextInsertionUndoableAttributeName;
         return @"substringFromRange";
     if (aSelector == @selector(attributedSubstringFrom:length:))
         return @"attributedSubstringFromRange";
-    if (aSelector == @selector(legacyAttributedString:))
+    if (aSelector == @selector(legacyAttributedString:offset:to:offset:))
         return @"legacyAttributedString";
     if (aSelector == @selector(firstRectForCharactersFrom:length:))
         return @"firstRectForCharacterRange";
@@ -372,15 +373,13 @@ NSString *NSTextInsertionUndoableAttributeName;
     return ret;
 }
 
-- (NSMutableAttributedString *)legacyAttributedString:(DOMRange*)range
+- (NSAttributedString *)legacyAttributedString:(DOMNode*)startContainer offset:(int)startOffset to:(DOMNode*)endContainer offset:(int)endOffset
 {
-    NSMutableAttributedString *string = [[[NSMutableAttributedString alloc] init] autorelease];
     id documentView = [[[webView mainFrame] frameView] documentView];
     if (![documentView isKindOfClass:[WebHTMLView class]])
-        return string;
+        return nil;
 
-    [string setAttributedString:[(WebHTMLView *)documentView _attributedStringFromDOMRange:range]];
-    return string;
+    return [(WebHTMLView *)documentView _legacyAttributedStringFrom:startContainer offset:startOffset to:endContainer offset:endOffset];
 }
 
 - (NSArray *)markedRange