<https://webkit.org/b/119806> [Mac] Add a way to easily test attributed string generation
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Aug 2013 03:04:07 +0000 (03:04 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Aug 2013 03:04:07 +0000 (03:04 +0000)
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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/platform/mac/editing/attributed-string/anchor-element-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/anchor-element.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/basic-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/basic.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-size-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-size.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-style-variant-effect.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-weight-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/font-weight.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/letter-spacing-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/letter-spacing.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/resources/dump-attributed-string.js [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/text-decorations-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/text-decorations.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/vertical-align-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/attributed-string/vertical-align.html [new file with mode: 0644]
Tools/ChangeLog
Tools/DumpRenderTree/mac/TextInputController.m

index 861a173f4efbcfab7d48f9a6ecadd3796004e9fb..84feea17a4222a715b8dcd154a5abd6f213310b8 100644 (file)
@@ -1,3 +1,33 @@
+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
index 7977a0552cd19512d4e47bad96cd59e9fc679c08..29294031a78edcb8f5aeebc79fcd1f01baf6b33b 100644 (file)
@@ -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 (file)
index 0000000..d408dd8
--- /dev/null
@@ -0,0 +1,31 @@
+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.
+
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 (file)
index 0000000..ae445ff
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<a href="https://webkit.org/">webkit.org</a>
+</body>
+</html>
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 (file)
index 0000000..1c4cad0
--- /dev/null
@@ -0,0 +1,61 @@
+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.
+
diff --git a/LayoutTests/platform/mac/editing/attributed-string/basic.html b/LayoutTests/platform/mac/editing/attributed-string/basic.html
new file mode 100644 (file)
index 0000000..f2f8e90
--- /dev/null
@@ -0,0 +1,10 @@
+<!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>
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 (file)
index 0000000..0d2859c
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..ec88839
--- /dev/null
@@ -0,0 +1,18 @@
+<!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>
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 (file)
index 0000000..aa80d40
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..81b1880
--- /dev/null
@@ -0,0 +1,13 @@
+<!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>
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 (file)
index 0000000..1973389
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..95ff836
--- /dev/null
@@ -0,0 +1,18 @@
+<!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>
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 (file)
index 0000000..51218e4
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..f71185a
--- /dev/null
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="resources/dump-attributed-string.js"></script>
+</head>
+<body>
+<span style="letter-spacing: 3pt">3pt</span>
+</body>
+</html>
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 (file)
index 0000000..8a033a6
--- /dev/null
@@ -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 (file)
index 0000000..2739e62
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..170e919
--- /dev/null
@@ -0,0 +1,11 @@
+<!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>
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 (file)
index 0000000..09313f6
--- /dev/null
@@ -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.
+
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 (file)
index 0000000..ad998ba
--- /dev/null
@@ -0,0 +1,13 @@
+<!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>
index 4fb82bb424d23def851c6034fc3d20bd72939d7f..342a5368bb4c287a372a16252215700a113cd82f 100644 (file)
@@ -1,3 +1,29 @@
+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
index 91dbd84a1a966ba9d4e4ffd69c8c40fe920b56e3..7edfed70227c52e7153421f8aa32d35dfbbaf899 100644 (file)
@@ -54,6 +54,7 @@
 
 @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];