Title: [154803] trunk
Revision
154803
Author
[email protected]
Date
2013-08-28 20:04:07 -0700 (Wed, 28 Aug 2013)

Log Message

<https://webkit.org/b/119806> [Mac] Add a way to easily test attributed string generation

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (154802 => 154803)


--- trunk/LayoutTests/ChangeLog	2013-08-29 02:33:42 UTC (rev 154802)
+++ trunk/LayoutTests/ChangeLog	2013-08-29 03:04:07 UTC (rev 154803)
@@ -1,3 +1,33 @@
+2013-08-16  Ryosuke Niwa  <[email protected]>
+
+        <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  <[email protected]>
 
         Expand classList test to cover exception in toString

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,31 @@
+Input:
+<a href=""
+
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/anchor-element.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<a href=""
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,61 @@
+Input:
+hello <b style="background-color:blue; color:white;">world</b> <a href=""
+<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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/basic.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/basic.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/basic.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+hello <b style="background-color:blue; color:white;">world</b> <a href=""
+<span style="background-color:yellow;">this is a <u><i>t</i>est</u> of <em>attributed</em> string.</span>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,69 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-size.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-size.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-size.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,36 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,53 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/font-weight.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,29 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<span style="letter-spacing: 3pt">3pt</span>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js	2013-08-29 03:04:07 UTC (rev 154803)
@@ -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();
+    }
+})();

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,36 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/text-decorations.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<u>underline</u>
+<strike>strike</strike>
+<span style="text-decoration: underline line-though">underline and strike</span>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,48 @@
+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.
+

Added: trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html (0 => 154803)


--- trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/attributed-string/vertical-align.html	2013-08-29 03:04:07 UTC (rev 154803)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</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>

Modified: trunk/LayoutTests/platform/mac-wk2/TestExpectations (154802 => 154803)


--- trunk/LayoutTests/platform/mac-wk2/TestExpectations	2013-08-29 02:33:42 UTC (rev 154802)
+++ trunk/LayoutTests/platform/mac-wk2/TestExpectations	2013-08-29 03:04:07 UTC (rev 154803)
@@ -195,6 +195,7 @@
 # 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

Modified: trunk/Tools/ChangeLog (154802 => 154803)


--- trunk/Tools/ChangeLog	2013-08-29 02:33:42 UTC (rev 154802)
+++ trunk/Tools/ChangeLog	2013-08-29 03:04:07 UTC (rev 154803)
@@ -1,3 +1,29 @@
+2013-08-16  Ryosuke Niwa  <[email protected]>
+
+        <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  <[email protected]>
 
         [GTK] accessibility/menu-list-sends-change-notification.html has incorrect expected results

Modified: trunk/Tools/DumpRenderTree/mac/TextInputController.m (154802 => 154803)


--- trunk/Tools/DumpRenderTree/mac/TextInputController.m	2013-08-29 02:33:42 UTC (rev 154802)
+++ trunk/Tools/DumpRenderTree/mac/TextInputController.m	2013-08-29 03:04:07 UTC (rev 154803)
@@ -54,6 +54,7 @@
 
 @interface WebHTMLView (WebKitSecretsTextInputControllerIsAwareOf)
 - (WebFrame *)_frame;
+- (NSAttributedString *)_attributeStringFromDOMRange:(DOMRange *)range;
 @end
 
 @implementation WebHTMLView (DumpRenderTreeInputMethodHandler)
@@ -66,12 +67,51 @@
 }
 @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 @@
 {
     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 @@
     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 @@
             || 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 @@
         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 @@
     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];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to