Reviewed by Darin Adler.
Tools:
Add textInputController.legacyAttributedString to retrieve the attributed string for copy & paste.
We can't use textInputController.attributedSubstringFromRange as it uses WebHTMLConverter's static
editingAttributedStringFromRange function, which doesn't implement the full converter at the moment.
Also NSMutableAttributedString.ranges and WebNSRange so that JavaScript can get a list of all
ranges in a given attributed string.
* DumpRenderTree/mac/TextInputController.m:
(-[WebNSRange initWithNSRange:]):
(-[WebNSRange location]):
(-[WebNSRange length]):
(+[WebNSRange isSelectorExcludedFromWebScript:]):
(+[NSMutableAttributedString isSelectorExcludedFromWebScript:]):
(+[NSMutableAttributedString webScriptNameForSelector:]):
(-[NSMutableAttributedString ranges]): Added.
(+[TextInputController isSelectorExcludedFromWebScript:]):
(+[TextInputController webScriptNameForSelector:]):
(-[TextInputController legacyAttributedString:]):
LayoutTests:
Add basic tests for textInputController.legacyAttributedString.
* platform/mac-wk2/TestExpectations:
* platform/mac/editing/attributed-string: Added.
* platform/mac/editing/attributed-string/anchor-element-expected.txt: Added.
* platform/mac/editing/attributed-string/anchor-element.html: Added.
* platform/mac/editing/attributed-string/basic-expected.txt: Added.
* platform/mac/editing/attributed-string/basic.html: Added.
* platform/mac/editing/attributed-string/font-size-expected.txt: Added.
* platform/mac/editing/attributed-string/font-size.html: Added.
* platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt: Added.
* platform/mac/editing/attributed-string/font-style-variant-effect.html: Added.
* platform/mac/editing/attributed-string/font-weight-expected.txt: Added.
* platform/mac/editing/attributed-string/font-weight.html: Added.
* platform/mac/editing/attributed-string/letter-spacing-expected.txt: Added.
* platform/mac/editing/attributed-string/letter-spacing.html: Added.
* platform/mac/editing/attributed-string/resources: Added.
* platform/mac/editing/attributed-string/resources/dump-attributed-string.js: Added.
(.):
* platform/mac/editing/attributed-string/text-decorations-expected.txt: Added.
* platform/mac/editing/attributed-string/text-decorations.html: Added.
* platform/mac/editing/attributed-string/vertical-align-expected.txt: Added.
* platform/mac/editing/attributed-string/vertical-align.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154803
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2013-08-16 Ryosuke Niwa <rniwa@webkit.org>
+
+ <https://webkit.org/b/119806> [Mac] Add a way to easily test attributed string generation
+
+ Reviewed by Darin Adler.
+
+ Add basic tests for textInputController.legacyAttributedString.
+
+ * platform/mac-wk2/TestExpectations:
+ * platform/mac/editing/attributed-string: Added.
+ * platform/mac/editing/attributed-string/anchor-element-expected.txt: Added.
+ * platform/mac/editing/attributed-string/anchor-element.html: Added.
+ * platform/mac/editing/attributed-string/basic-expected.txt: Added.
+ * platform/mac/editing/attributed-string/basic.html: Added.
+ * platform/mac/editing/attributed-string/font-size-expected.txt: Added.
+ * platform/mac/editing/attributed-string/font-size.html: Added.
+ * platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt: Added.
+ * platform/mac/editing/attributed-string/font-style-variant-effect.html: Added.
+ * platform/mac/editing/attributed-string/font-weight-expected.txt: Added.
+ * platform/mac/editing/attributed-string/font-weight.html: Added.
+ * platform/mac/editing/attributed-string/letter-spacing-expected.txt: Added.
+ * platform/mac/editing/attributed-string/letter-spacing.html: Added.
+ * platform/mac/editing/attributed-string/resources: Added.
+ * platform/mac/editing/attributed-string/resources/dump-attributed-string.js: Added.
+ (.):
+ * platform/mac/editing/attributed-string/text-decorations-expected.txt: Added.
+ * platform/mac/editing/attributed-string/text-decorations.html: Added.
+ * platform/mac/editing/attributed-string/vertical-align-expected.txt: Added.
+ * platform/mac/editing/attributed-string/vertical-align.html: Added.
+
2013-08-28 Ryosuke Niwa <rniwa@webkit.org>
Expand classList test to cover exception in toString
# https://bugs.webkit.org/show_bug.cgi?id=89401
platform/mac/editing/input/insert-dictated-text.html
platform/mac/editing/input/edit-dictated-text-with-alternative.html
+platform/mac/editing/attributed-string/
# https://bugs.webkit.org/show_bug.cgi?id=89199
editing/spelling/grammar-edit-word.html
--- /dev/null
+Input:
+<a href="https://webkit.org/">webkit.org</a>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[webkit.org]
+ NSColor: #0000ee (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+ NSLink: https://webkit.org/
+ NSUnderline: true
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<a href="https://webkit.org/">webkit.org</a>
+</body>
+</html>
--- /dev/null
+Input:
+hello <b style="background-color:blue; color:white;">world</b> <a href="https://webkit.org/">WebKit</a>.<br>
+<span style="background-color:yellow;">this is a <u><i>t</i>est</u> of <em>attributed</em> string.</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[hello ]
+ NSFont: Times-Roman 16.00 pt.
+[world]
+ NSBackgroundColor: #0000ff (NSDeviceRGBColorSpace)
+ NSColor: #ffffff (NSDeviceRGBColorSpace)
+ NSFont: Times-Bold 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[WebKit]
+ NSColor: #0000ee (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+ NSLink: https://webkit.org/
+ NSUnderline: true
+[.\n]
+ NSFont: Times-Roman 16.00 pt.
+[this is a ]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+[t]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Italic 16.00 pt.
+[est]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+ NSUnderline: true
+[ of ]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+[attributed]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Italic 16.00 pt.
+[ string.]
+ NSBackgroundColor: #ffff00 (NSDeviceRGBColorSpace)
+ NSFont: Times-Roman 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+hello <b style="background-color:blue; color:white;">world</b> <a href="https://webkit.org/">WebKit</a>.<br>
+<span style="background-color:yellow;">this is a <u><i>t</i>est</u> of <em>attributed</em> string.</span>
+</body>
+</html>
--- /dev/null
+Input:
+<small>small element</small>
+<span style="font-size: xx-small">xx-small</span>
+<span style="font-size: x-small">x-small</span>
+<span style="font-size: small">small</span>
+<span style="font-size: normal">normal</span>
+<span style="font-size: large">large</span>
+<span style="font-size: x-large">x-large</span>
+<span style="font-size: xx-large">xx-large</span>
+<span style="font-size: 5pt">5pt</span>
+<span style="font-size: 15pt">15pt</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[small element]
+ NSFont: Times-Roman 13.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[xx-small]
+ NSFont: Times-Roman 9.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[x-small]
+ NSFont: Times-Roman 10.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[small]
+ NSFont: Times-Roman 13.00 pt.
+[ normal ]
+ NSFont: Times-Roman 16.00 pt.
+[large]
+ NSFont: Times-Roman 18.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[x-large]
+ NSFont: Times-Roman 24.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[xx-large]
+ NSFont: Times-Roman 32.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[5pt]
+ NSFont: Times-Roman 7.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[15pt]
+ NSFont: Times-Roman 20.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<small>small element</small>
+<span style="font-size: xx-small">xx-small</span>
+<span style="font-size: x-small">x-small</span>
+<span style="font-size: small">small</span>
+<span style="font-size: normal">normal</span>
+<span style="font-size: large">large</span>
+<span style="font-size: x-large">x-large</span>
+<span style="font-size: xx-large">xx-large</span>
+<span style="font-size: 5pt">5pt</span>
+<span style="font-size: 15pt">15pt</span>
+</body>
+</html>
--- /dev/null
+Input:
+<i>italic</i>
+<span style="font-style: oblique">oblique</span>
+<span style="font-variant: small-caps">small-caps</span>
+<span style="font-effect: outline">outline</span>
+<span style="font-effect: emboss">emboss</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[italic]
+ NSFont: Times-Italic 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[oblique]
+ NSFont: Times-Italic 16.00 pt.
+[ small-caps outline emboss ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<i>italic</i>
+<span style="font-style: oblique">oblique</span>
+<span style="font-variant: small-caps">small-caps</span>
+<span style="font-effect: outline">outline</span>
+<span style="font-effect: emboss">emboss</span>
+</body>
+</html>
--- /dev/null
+Input:
+<b>bold</b>
+<span style="font-weight: 100">font weight 100</span>
+<span style="font-weight: 200">font weight 200</span>
+<span style="font-weight: 300">font weight 300</span>
+<span style="font-weight: 400">font weight 400</span>
+<span style="font-weight: 500">font weight 500</span>
+<span style="font-weight: 600">font weight 600</span>
+<span style="font-weight: 700">font weight 700</span>
+<span style="font-weight: 800">font weight 800</span>
+<span style="font-weight: 900">font weight 900</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[bold]
+ NSFont: Times-Bold 16.00 pt.
+[ font weight 100 font weight 200 font weight 300 font weight 400 font weight 500 ]
+ NSFont: Times-Roman 16.00 pt.
+[font weight 600]
+ NSFont: Times-Bold 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[font weight 700]
+ NSFont: Times-Bold 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[font weight 800]
+ NSFont: Times-Bold 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[font weight 900]
+ NSFont: Times-Bold 16.00 pt.
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<b>bold</b>
+<span style="font-weight: 100">font weight 100</span>
+<span style="font-weight: 200">font weight 200</span>
+<span style="font-weight: 300">font weight 300</span>
+<span style="font-weight: 400">font weight 400</span>
+<span style="font-weight: 500">font weight 500</span>
+<span style="font-weight: 600">font weight 600</span>
+<span style="font-weight: 700">font weight 700</span>
+<span style="font-weight: 800">font weight 800</span>
+<span style="font-weight: 900">font weight 900</span>
+</body>
+</html>
--- /dev/null
+Input:
+<span style="letter-spacing: 3pt">3pt</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[3pt]
+ NSFont: Times-Roman 16.00 pt.
+ NSKern: 4pt
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<span style="letter-spacing: 3pt">3pt</span>
+</body>
+</html>
--- /dev/null
+(function () {
+ if (window.testRunner)
+ testRunner.dumpAsText();
+
+ var called = false;
+ function dumpAttributedString(container) {
+ called = true;
+
+ var body = document.body;
+ if (!container)
+ container = body;
+
+ var range = document.createRange();
+ range.selectNodeContents(container);
+
+ var pre = document.createElement('pre');
+ pre.textContent = 'Input:\n' + container.innerHTML.trim() + '\n\nOutput:\n' + serializeAttributedString(textInputController.legacyAttributedString(range));
+
+ body.innerHTML = '';
+ body.appendChild(pre);
+ }
+
+ function serializeAttributedString(attributedString) {
+ var string = attributedString.string();
+ var output = '';
+ function log(text) {
+ output += text + '\n';
+ }
+
+ var currentParagraphStyle;
+
+ attributedString.ranges().forEach(function (range) {
+ var location = range.location();
+ var length = range.length();
+
+ var attributeNames = attributedString.getAttributeNamesAtIndex(location, length).slice();
+ if (attributeNames.indexOf('NSParagraphStyle') >= 0) {
+ var value = '' + attributedString.getAttributeValueAtIndex('NSParagraphStyle', location);
+ var newParagraphStyle = value.split(', ').reduce(function (result, component) {
+ var match = component.match(/(\w+)\s+([^]+)/);
+ return (result ? result + '\n' : '') + ' ' + match[1] + ': ' + formatParagraphStyle(match[1], match[2]);
+ });
+ if (newParagraphStyle != currentParagraphStyle) {
+ log('NSParagraphStyle:');
+ log(newParagraphStyle);
+ currentParagraphStyle = newParagraphStyle;
+ }
+ }
+
+ log('[' + string.substring(location, location + length).replace('\n', '\\n') + ']');
+
+ attributeNames.sort().forEach(function (attributeName) {
+ var indentAndName = ' ' + attributeName + ':';
+ var value = '' + attributedString.getAttributeValueAtIndex(attributeName, location);
+
+ if (attributeName != 'NSParagraphStyle')
+ log(indentAndName + ' ' + formatNonParagraphAttributeValue(attributeName, value));
+ });
+ });
+
+ return output;
+ }
+
+ function formatNonParagraphAttributeValue(name, value) {
+ value = value.replace(/^"|"$/g, '');
+ switch (name) {
+ case 'NSFont':
+ return value.match(/(.+?)\s+P \[\]/)[1];
+ case 'NSColor':
+ case 'NSBackgroundColor':
+ var parsed = parseNSColorDescription(value);
+ return serializeColor(parsed.rgb, parsed.alpha) + ' (' + parsed.colorSpace + ')';
+ case 'NSUnderline':
+ case 'NSStrikethrough':
+ switch (value) {
+ case '1':
+ return 'true';
+ case '0':
+ return 'false';
+ }
+ return value;
+ case 'NSKern':
+ return value + 'pt';
+ }
+ return value;
+ }
+
+ function parseNSColorDescription(value) {
+ var match = value.match(/\s*(\w+)\s*([0-9\.]+)\s*([0-9\.]+)\s*([0-9\.]+)\s*([0-9\.]+)/);
+ return {
+ colorSpace: match[1],
+ rgb: match.slice(2, 5).map(function (string) { return Math.round(string * 255); }),
+ alpha: match[5],
+ };
+ }
+
+ function serializeColor(rgb, alpha) {
+ if (alpha == 1)
+ return '#' + rgb.map(function (component) {
+ var digits = component.toString(16);
+ return digits.length < 2 ? '0' + digits : digits;
+ }).join('');
+ return 'rgba(' + rgb.concat(alpha).join(', ') + ')';
+ }
+
+ function formatParagraphStyle(name, value) {
+ switch (name) {
+ case 'Alignment':
+ switch (parseInt(value)) {
+ case 0:
+ return 'left';
+ case 1:
+ return 'right';
+ case 2:
+ return 'center';
+ case 3:
+ return 'justified';
+ case 4:
+ return 'natural';
+ }
+ break;
+ case 'Tabs':
+ return value.replace('\n', '');
+ }
+ return value;
+ }
+
+ window.onload = function () {
+ (!called)
+ dumpAttributedString();
+ }
+})();
--- /dev/null
+Input:
+<u>underline</u>
+<strike>strike</strike>
+<span style="text-decoration: underline line-though">underline and strike</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[underline]
+ NSFont: Times-Roman 16.00 pt.
+ NSUnderline: true
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[strike]
+ NSFont: Times-Roman 16.00 pt.
+ NSStrikethrough: true
+[ underline and strike ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<u>underline</u>
+<strike>strike</strike>
+<span style="text-decoration: underline line-though">underline and strike</span>
+</body>
+</html>
--- /dev/null
+Input:
+<sup>sup element</sup>
+<sub>sub element</sub>
+<span style="vertical-align: super">vertical align super</span>
+<span style="vertical-align: sub">vertical align sub</span>
+<span style="vertical-align: 50%">vertical align 50%</span>
+
+Output:
+NSParagraphStyle:
+Alignment 4
+ LineSpacing: 0
+ ParagraphSpacing: 0
+ ParagraphSpacingBefore: 0
+ HeadIndent: 0
+ TailIndent: 0
+ FirstLineHeadIndent: 0
+ LineHeight: 0/0
+ LineHeightMultiple: 0
+ LineBreakMode: 0
+ Tabs: ()
+ DefaultTabInterval: 36
+ Blocks: (null)
+ Lists: (null)
+ BaseWritingDirection: 0
+ HyphenationFactor: 0
+ TighteningFactor: 0.05
+ HeaderLevel: 0
+[sup element]
+ NSFont: Times-Roman 13.00 pt.
+ NSSuperScript: 1
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[sub element]
+ NSFont: Times-Roman 13.00 pt.
+ NSSuperScript: -1
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[vertical align super]
+ NSFont: Times-Roman 16.00 pt.
+ NSSuperScript: 1
+[ ]
+ NSFont: Times-Roman 16.00 pt.
+[vertical align sub]
+ NSFont: Times-Roman 16.00 pt.
+ NSSuperScript: -1
+[ vertical align 50% ]
+ NSFont: Times-Roman 16.00 pt.
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<sup>sup element</sup>
+<sub>sub element</sub>
+<span style="vertical-align: super">vertical align super</span>
+<span style="vertical-align: sub">vertical align sub</span>
+<span style="vertical-align: 50%">vertical align 50%</span>
+</body>
+</html>
+2013-08-16 Ryosuke Niwa <rniwa@webkit.org>
+
+ <https://webkit.org/b/119806> [Mac] Add a way to easily test attributed string generation
+
+ Reviewed by Darin Adler.
+
+ Add textInputController.legacyAttributedString to retrieve the attributed string for copy & paste.
+
+ We can't use textInputController.attributedSubstringFromRange as it uses WebHTMLConverter's static
+ editingAttributedStringFromRange function, which doesn't implement the full converter at the moment.
+
+ Also NSMutableAttributedString.ranges and WebNSRange so that JavaScript can get a list of all
+ ranges in a given attributed string.
+
+ * DumpRenderTree/mac/TextInputController.m:
+ (-[WebNSRange initWithNSRange:]):
+ (-[WebNSRange location]):
+ (-[WebNSRange length]):
+ (+[WebNSRange isSelectorExcludedFromWebScript:]):
+ (+[NSMutableAttributedString isSelectorExcludedFromWebScript:]):
+ (+[NSMutableAttributedString webScriptNameForSelector:]):
+ (-[NSMutableAttributedString ranges]): Added.
+ (+[TextInputController isSelectorExcludedFromWebScript:]):
+ (+[TextInputController webScriptNameForSelector:]):
+ (-[TextInputController legacyAttributedString:]):
+
2013-08-28 Denis Nomiyama <d.nomiyama@samsung.com>
[GTK] accessibility/menu-list-sends-change-notification.html has incorrect expected results
@interface WebHTMLView (WebKitSecretsTextInputControllerIsAwareOf)
- (WebFrame *)_frame;
+- (NSAttributedString *)_attributeStringFromDOMRange:(DOMRange *)range;
@end
@implementation WebHTMLView (DumpRenderTreeInputMethodHandler)
}
@end
+@interface WebNSRange : NSObject {
+@private
+ NSRange _range;
+}
+- (id)initWithNSRange:(NSRange)range;
+- (unsigned)location;
+- (unsigned)length;
+@end
+
+@implementation WebNSRange
+
+- (id)initWithNSRange:(NSRange)range
+{
+ self = [super init];
+ if (!self)
+ return self;
+
+ _range = range;
+ return self;
+}
+
+- (unsigned)location
+{
+ return _range.location;
+}
+
+- (unsigned)length
+{
+ return _range.length;
+}
+
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector
+{
+ return !(selector == @selector(location) || selector == @selector(length));
+}
+
+@end
+
@implementation NSMutableAttributedString (TextInputController)
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
{
if (aSelector == @selector(string)
|| aSelector == @selector(getLength)
+ || aSelector == @selector(ranges)
|| aSelector == @selector(attributeNamesAtIndex:)
|| aSelector == @selector(valueOfAttribute:atIndex:)
|| aSelector == @selector(addAttribute:value:)
{
if (aSelector == @selector(getLength))
return @"length";
+ if (aSelector == @selector(ranges))
+ return @"ranges";
if (aSelector == @selector(attributeNamesAtIndex:))
return @"getAttributeNamesAtIndex";
if (aSelector == @selector(valueOfAttribute:atIndex:))
return (int)[self length];
}
+- (NSArray *)ranges
+{
+ NSMutableArray *array = [NSMutableArray array];
+ [self enumerateAttributesInRange:NSMakeRange(0, [self length]) options:0 usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
+ WebNSRange *webRange = [[WebNSRange alloc] initWithNSRange:range];
+ [array addObject:webRange];
+ [webRange release];
+ }];
+ return array;
+}
+
- (NSArray *)attributeNamesAtIndex:(int)index
{
NSDictionary *attributes = [self attributesAtIndex:(unsigned)index effectiveRange:nil];
|| aSelector == @selector(conversationIdentifier)
|| aSelector == @selector(substringFrom:length:)
|| aSelector == @selector(attributedSubstringFrom:length:)
+ || aSelector == @selector(legacyAttributedString:)
|| aSelector == @selector(markedRange)
|| aSelector == @selector(selectedRange)
|| aSelector == @selector(firstRectForCharactersFrom:length:)
return @"substringFromRange";
else if (aSelector == @selector(attributedSubstringFrom:length:))
return @"attributedSubstringFromRange";
+ else if (aSelector == @selector(legacyAttributedString:))
+ return @"legacyAttributedString";
else if (aSelector == @selector(firstRectForCharactersFrom:length:))
return @"firstRectForCharacterRange";
else if (aSelector == @selector(characterIndexForPointX:Y:))
return ret;
}
+- (NSMutableAttributedString *)legacyAttributedString:(DOMRange*)range
+{
+ NSMutableAttributedString *string = [[[NSMutableAttributedString alloc] init] autorelease];
+ id documentView = [[[webView mainFrame] frameView] documentView];
+ if (![documentView isKindOfClass:[WebHTMLView class]])
+ return string;
+
+ [string setAttributedString:[(WebHTMLView *)documentView _attributeStringFromDOMRange:range]];
+ return string;
+}
+
- (NSArray *)markedRange
{
NSObject <NSTextInput> *textInput = [self textInput];