diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 861a173f4efbcfab7d48f9a6ecadd3796004e9fb..84feea17a4222a715b8dcd154a5abd6f213310b8 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,33 @@ +2013-08-16 Ryosuke Niwa + + [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 Expand classList test to cover exception in toString diff --git a/LayoutTests/platform/mac-wk2/TestExpectations b/LayoutTests/platform/mac-wk2/TestExpectations index 7977a0552cd19512d4e47bad96cd59e9fc679c08..29294031a78edcb8f5aeebc79fcd1f01baf6b33b 100644 --- a/LayoutTests/platform/mac-wk2/TestExpectations +++ b/LayoutTests/platform/mac-wk2/TestExpectations @@ -195,6 +195,7 @@ storage/websql/transaction-error-callback-isolated-world.html # 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 diff --git a/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d408dd89b65c5cd2dae2422dcb50477d44483820 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt @@ -0,0 +1,31 @@ +Input: +webkit.org + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html b/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html new file mode 100644 index 0000000000000000000000000000000000000000..ae445ffc6a6427baf45a302a5ed57ae944df0f6c --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html @@ -0,0 +1,9 @@ + + + + + + +webkit.org + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c4cad066fb68fa5c428142c749b515fe9d6991d --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt @@ -0,0 +1,61 @@ +Input: +hello world WebKit.
+this is a test of attributed string. + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/basic.html b/LayoutTests/platform/mac/editing/attributed-string/basic.html new file mode 100644 index 0000000000000000000000000000000000000000..f2f8e9093a33f7bb4359d6eb9e52b0ac9529d8f4 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/basic.html @@ -0,0 +1,10 @@ + + + + + + +hello world WebKit.
+this is a test of attributed string. + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0d2859cd021d3cf424ef48278999bd97e4af22ee --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt @@ -0,0 +1,69 @@ +Input: +small element +xx-small +x-small +small +normal +large +x-large +xx-large +5pt +15pt + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-size.html b/LayoutTests/platform/mac/editing/attributed-string/font-size.html new file mode 100644 index 0000000000000000000000000000000000000000..ec888399832025f722e2b0a2668c979dc8a5c493 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-size.html @@ -0,0 +1,18 @@ + + + + + + +small element +xx-small +x-small +small +normal +large +x-large +xx-large +5pt +15pt + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa80d404cc8beba5743b37137f97b8989bb318aa --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt @@ -0,0 +1,36 @@ +Input: +italic +oblique +small-caps +outline +emboss + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html b/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html new file mode 100644 index 0000000000000000000000000000000000000000..81b18800017670105ae09ee16a857c8120b6e1a0 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html @@ -0,0 +1,13 @@ + + + + + + +italic +oblique +small-caps +outline +emboss + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..1973389ee36ff512f4021d62145e589d660c99bf --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt @@ -0,0 +1,53 @@ +Input: +bold +font weight 100 +font weight 200 +font weight 300 +font weight 400 +font weight 500 +font weight 600 +font weight 700 +font weight 800 +font weight 900 + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/font-weight.html b/LayoutTests/platform/mac/editing/attributed-string/font-weight.html new file mode 100644 index 0000000000000000000000000000000000000000..95ff836764ae2243517971a94dc88f0da038f3f7 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/font-weight.html @@ -0,0 +1,18 @@ + + + + + + +bold +font weight 100 +font weight 200 +font weight 300 +font weight 400 +font weight 500 +font weight 600 +font weight 700 +font weight 800 +font weight 900 + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..51218e4aa23851582413c98ed725f175c2c74e9e --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt @@ -0,0 +1,29 @@ +Input: +3pt + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html b/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html new file mode 100644 index 0000000000000000000000000000000000000000..f71185a08e7fcbe032d4808a33b5d25953cde1dc --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html @@ -0,0 +1,9 @@ + + + + + + +3pt + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js b/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js new file mode 100644 index 0000000000000000000000000000000000000000..8a033a6decb6c250eedbd601287dd2b7b1f771b1 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js @@ -0,0 +1,132 @@ +(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(); + } +})(); diff --git a/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..2739e62cd02841bca1f043f6712186b24dafcb2c --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt @@ -0,0 +1,36 @@ +Input: +underline +strike +underline and strike + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html b/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html new file mode 100644 index 0000000000000000000000000000000000000000..170e91962fe67d31b1720f998088c0f1c14fa1fc --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html @@ -0,0 +1,11 @@ + + + + + + +underline +strike +underline and strike + + diff --git a/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt b/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..09313f6f624ba308eac00c4a146b217c04305892 --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt @@ -0,0 +1,48 @@ +Input: +sup element +sub element +vertical align super +vertical align sub +vertical align 50% + +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. + diff --git a/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html b/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html new file mode 100644 index 0000000000000000000000000000000000000000..ad998bac53321938a9b447b43b8fea55403ae8bb --- /dev/null +++ b/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html @@ -0,0 +1,13 @@ + + + + + + +sup element +sub element +vertical align super +vertical align sub +vertical align 50% + + diff --git a/Tools/ChangeLog b/Tools/ChangeLog index 4fb82bb424d23def851c6034fc3d20bd72939d7f..342a5368bb4c287a372a16252215700a113cd82f 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,29 @@ +2013-08-16 Ryosuke Niwa + + [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 [GTK] accessibility/menu-list-sends-change-notification.html has incorrect expected results diff --git a/Tools/DumpRenderTree/mac/TextInputController.m b/Tools/DumpRenderTree/mac/TextInputController.m index 91dbd84a1a966ba9d4e4ffd69c8c40fe920b56e3..7edfed70227c52e7153421f8aa32d35dfbbaf899 100644 --- a/Tools/DumpRenderTree/mac/TextInputController.m +++ b/Tools/DumpRenderTree/mac/TextInputController.m @@ -54,6 +54,7 @@ - (void)interpretKeyEvents:(NSArray *)eventArray; @interface WebHTMLView (WebKitSecretsTextInputControllerIsAwareOf) - (WebFrame *)_frame; +- (NSAttributedString *)_attributeStringFromDOMRange:(DOMRange *)range; @end @implementation WebHTMLView (DumpRenderTreeInputMethodHandler) @@ -66,12 +67,51 @@ - (void)interpretKeyEvents:(NSArray *)eventArray } @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:) @@ -88,6 +128,8 @@ + (NSString *)webScriptNameForSelector:(SEL)aSelector { if (aSelector == @selector(getLength)) return @"length"; + if (aSelector == @selector(ranges)) + return @"ranges"; if (aSelector == @selector(attributeNamesAtIndex:)) return @"getAttributeNamesAtIndex"; if (aSelector == @selector(valueOfAttribute:atIndex:)) @@ -113,6 +155,17 @@ - (int)getLength 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]; @@ -168,6 +221,7 @@ + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector || aSelector == @selector(conversationIdentifier) || aSelector == @selector(substringFrom:length:) || aSelector == @selector(attributedSubstringFrom:length:) + || aSelector == @selector(legacyAttributedString:) || aSelector == @selector(markedRange) || aSelector == @selector(selectedRange) || aSelector == @selector(firstRectForCharactersFrom:length:) @@ -192,6 +246,8 @@ + (NSString *)webScriptNameForSelector:(SEL)aSelector 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:)) @@ -303,6 +359,17 @@ - (NSMutableAttributedString *)attributedSubstringFrom:(int)from length:(int)len 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 *textInput = [self textInput];