Reviewed by Darin
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jan 2005 18:47:43 +0000 (18:47 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Jan 2005 18:47:43 +0000 (18:47 +0000)
        Fix for this bug:

        <rdar://problem/3907005> Applying block styles to a line of text can unexpectedly affect other lines

        * khtml/editing/htmlediting.cpp:
        (khtml::CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary): New function which moves "paragraphs"
        to their own blocks if needed so that a block style can be applied.
        (khtml::CompositeEditCommand::isMailBlockquote): Moved this function to base class so it can be used more generally.
        (khtml::ApplyStyleCommand::applyBlockStyle): Pass a node instead of a block to addBlockStyleIfNeeded().
        (khtml::ApplyStyleCommand::addBlockStyleIfNeeded): Now accepts a node instead of a block for styling.
        This function also now calls moveParagraphContentsToNewBlockIfNecessary() to make sure that only the current
        paragraph is styled.
        (khtml::SetNodeAttributeCommand::doUnapply): Should not assert on undo if old value of attribute was null.
        Should remove attributue instead.
        * khtml/editing/htmlediting.h: Touch function declarations accordingly.
        * layout-tests/editing/style/create-block-for-style-001-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-001.html: Added.
        * layout-tests/editing/style/create-block-for-style-002-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-002.html: Added.
        * layout-tests/editing/style/create-block-for-style-003-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-003.html: Added.
        * layout-tests/editing/style/create-block-for-style-004-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-004.html: Added.
        * layout-tests/editing/style/create-block-for-style-005-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-005.html: Added.
        * layout-tests/editing/style/create-block-for-style-006-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-006.html: Added.
        * layout-tests/editing/style/create-block-for-style-007-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-007.html: Added.
        * layout-tests/editing/style/create-block-for-style-008-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-008.html: Added.
        * layout-tests/editing/style/create-block-for-style-009-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-009.html: Added.
        * layout-tests/editing/style/create-block-for-style-010-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-010.html: Added.
        * layout-tests/editing/style/create-block-for-style-011-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-011.html: Added.
        * layout-tests/editing/style/create-block-for-style-012-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-012.html: Added.
        * layout-tests/editing/style/create-block-for-style-013-expected.txt: Added.
        * layout-tests/editing/style/create-block-for-style-013.html: Added.

        Unrelated updates to these expected results.
        * layout-tests/editing/inserting/insert-div-007-expected.txt
        * layout-tests/editing/pasteboard/paste-text-013-expected.txt

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

31 files changed:
LayoutTests/editing/inserting/insert-div-007-expected.txt
LayoutTests/editing/pasteboard/paste-text-013-expected.txt
LayoutTests/editing/style/create-block-for-style-001-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-001.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-002-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-002.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-003-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-003.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-004-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-004.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-005-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-005.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-006-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-006.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-007-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-007.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-008-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-008.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-009-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-009.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-010-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-010.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-011-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-011.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-012-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-012.html [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-013-expected.txt [new file with mode: 0644]
LayoutTests/editing/style/create-block-for-style-013.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/htmlediting.h

index 6f3a5ce..247e925 100644 (file)
@@ -10,6 +10,6 @@ layer at (0,0) size 800x600
         RenderText {TEXT} at (14,14) size 37x28
           text run at (14,14) width 37: " bar"
 selection is CARET:
-start:      position 1 of child 1 {TEXT} of child 2 {DIV} of root {BODY}
-upstream:   position 1 of child 1 {TEXT} of child 2 {DIV} of root {BODY}
-downstream: position 1 of child 1 {TEXT} of child 2 {DIV} of root {BODY}
+start:      position 0 of child 1 {TEXT} of child 2 {DIV} of root {BODY}
+upstream:   position 0 of child 2 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 2 {DIV} of root {BODY}
index 458f96c..97bd3bc 100644 (file)
@@ -19,15 +19,17 @@ layer at (0,0) size 800x600
           RenderBlock {BLOCKQUOTE} at (40,0) size 676x28
             RenderText {TEXT} at (0,0) size 32x28
               text run at (0,0) width 32: "foo"
-      RenderBlock {DIV} at (0,182) size 784x132 [border: (2px solid #FF0000)]
+      RenderBlock {DIV} at (0,182) size 784x184 [border: (2px solid #FF0000)]
         RenderBlock (anonymous) at (14,14) size 756x28
           RenderText {TEXT} at (0,0) size 12x28
             text run at (0,0) width 12: "x"
-        RenderBlock {DIV} at (14,66) size 756x28
+        RenderBlock {DIV} at (14,66) size 756x80
           RenderBlock {BLOCKQUOTE} at (40,0) size 676x28
             RenderText {TEXT} at (0,0) size 32x28
               text run at (0,0) width 32: "foo"
+          RenderBlock {BLOCKQUOTE} at (40,52) size 676x28
+            RenderBR {BR} at (0,0) size 0x28
 selection is CARET:
-start:      position 3 of child 1 {TEXT} of child 1 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
-upstream:   position 3 of child 1 {TEXT} of child 1 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
-downstream: position 3 of child 1 {TEXT} of child 1 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
+start:      position 0 of child 1 {BR} of child 2 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
+upstream:   position 0 of child 2 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
+downstream: position 0 of child 1 {BR} of child 2 {BLOCKQUOTE} of child 2 {DIV} of child 8 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/style/create-block-for-style-001-expected.txt b/LayoutTests/editing/style/create-block-for-style-001-expected.txt
new file mode 100644 (file)
index 0000000..b03110e
--- /dev/null
@@ -0,0 +1,24 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 721x56
+          text run at (14,14) width 721: "Should see \"foo\" centered in its own red box, followed by left-aligned two"
+          text run at (14,42) width 424: "lines, \"bar\" and \"baz\", in their own red box."
+      RenderBlock {DIV} at (0,108) size 784x140
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 32x28
+            text run at (376,14) width 32: "foo"
+          RenderBR {BR} at (0,0) size 0x0
+        RenderBlock {DIV} at (0,56) size 784x84 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (14,14) size 31x28
+            text run at (14,14) width 31: "bar"
+          RenderBR {BR} at (0,0) size 0x0
+          RenderText {TEXT} at (14,42) size 34x28
+            text run at (14,42) width 34: "baz"
+selection is CARET:
+start:      position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-001.html b/LayoutTests/editing/style/create-block-for-style-001.html
new file mode 100644 (file)
index 0000000..f14b3e7
--- /dev/null
@@ -0,0 +1,46 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "foo" centered in its own red box, followed by left-aligned two lines, "bar" and "baz", in their own red box.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo<br>bar<br>baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-002-expected.txt b/LayoutTests/editing/style/create-block-for-style-002-expected.txt
new file mode 100644 (file)
index 0000000..3035ec1
--- /dev/null
@@ -0,0 +1,26 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 723x56
+          text run at (14,14) width 723: "Should see \"bar\" centered in its own red box, with a left-aligned \"foo\" line"
+          text run at (14,42) width 409: "above and a left-aligned \"baz\" line below."
+      RenderBlock {DIV} at (0,108) size 784x140
+        RenderBlock {DIV} at (0,0) size 784x140 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+            RenderBR {BR} at (0,0) size 0x0
+          RenderBlock {DIV} at (14,42) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (362,14) size 31x28
+              text run at (362,14) width 31: "bar"
+            RenderBR {BR} at (0,0) size 0x0
+          RenderBlock (anonymous) at (14,98) size 756x28
+            RenderText {TEXT} at (0,0) size 34x28
+              text run at (0,0) width 34: "baz"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 3 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-002.html b/LayoutTests/editing/style/create-block-for-style-002.html
new file mode 100644 (file)
index 0000000..6a71522
--- /dev/null
@@ -0,0 +1,47 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "bar" centered in its own red box, with a left-aligned "foo" line above and a left-aligned "baz" line below.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo<br>bar<br>baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-003-expected.txt b/LayoutTests/editing/style/create-block-for-style-003-expected.txt
new file mode 100644 (file)
index 0000000..f200a15
--- /dev/null
@@ -0,0 +1,25 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 719x56
+          text run at (14,14) width 719: "Should see \"baz\" centered in its own red box, with a two left-aligned lines"
+          text run at (14,42) width 226: "above, \"foo\" and \"bar\"."
+      RenderBlock {DIV} at (0,108) size 784x140
+        RenderBlock {DIV} at (0,0) size 784x140 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x56
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+            RenderBR {BR} at (0,0) size 0x0
+            RenderText {TEXT} at (0,28) size 31x28
+              text run at (0,28) width 31: "bar"
+            RenderBR {BR} at (0,0) size 0x0
+          RenderBlock {DIV} at (14,70) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (361,14) size 34x28
+              text run at (361,14) width 34: "baz"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 5 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 5 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 5 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-003.html b/LayoutTests/editing/style/create-block-for-style-003.html
new file mode 100644 (file)
index 0000000..7ec2d8d
--- /dev/null
@@ -0,0 +1,48 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "baz" centered in its own red box, with a two left-aligned lines above, "foo" and "bar".
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo<br>bar<br>baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-004-expected.txt b/LayoutTests/editing/style/create-block-for-style-004-expected.txt
new file mode 100644 (file)
index 0000000..7db6e3f
--- /dev/null
@@ -0,0 +1,26 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 725x56
+          text run at (14,14) width 725: "Should see \"foo\" and \"baz\" centered in their own red boxes. The \"bar\" line"
+          text run at (14,42) width 225: "should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 32x28
+            text run at (376,14) width 32: "foo"
+          RenderBR {BR} at (0,0) size 0x0
+        RenderBlock {DIV} at (0,56) size 784x112 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 31x28
+              text run at (0,0) width 31: "bar"
+            RenderBR {BR} at (0,0) size 0x0
+          RenderBlock {DIV} at (14,42) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (361,14) size 34x28
+              text run at (361,14) width 34: "baz"
+selection is CARET:
+start:      position 3 of child 1 {TEXT} of child 3 {DIV} of child 2 {DIV} of root {DIV}
+upstream:   position 3 of child 1 {TEXT} of child 3 {DIV} of child 2 {DIV} of root {DIV}
+downstream: position 4 of child 1 {TEXT} of child 3 {DIV} of child 2 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-004.html b/LayoutTests/editing/style/create-block-for-style-004.html
new file mode 100644 (file)
index 0000000..823da9a
--- /dev/null
@@ -0,0 +1,49 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    justifyCenterCommand();
+    moveSelectionForwardByLineCommand();
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "foo" and "baz" centered in their own red boxes. The "bar" line should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo<br>bar<br>baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-005-expected.txt b/LayoutTests/editing/style/create-block-for-style-005-expected.txt
new file mode 100644 (file)
index 0000000..d082c03
--- /dev/null
@@ -0,0 +1,26 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 725x56
+          text run at (14,14) width 725: "Should see \"foo\" and \"bar\" centered in their own red boxes. The \"baz\" line"
+          text run at (14,42) width 448: "should be in its own red box, but not centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 32x28
+            text run at (376,14) width 32: "foo"
+        RenderBlock {DIV} at (0,56) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 31x28
+            text run at (376,14) width 31: "bar"
+        RenderBlock {DIV} at (0,112) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (14,14) size 34x28
+            text run at (14,14) width 34: "baz"
+selection is RANGE:
+start:      position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+end:        position 1 of child 1 {TEXT} of child 3 {DIV} of root {DIV}
+upstream:   position 1 of child 1 {TEXT} of child 3 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 3 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-005.html b/LayoutTests/editing/style/create-block-for-style-005.html
new file mode 100644 (file)
index 0000000..670f5b9
--- /dev/null
@@ -0,0 +1,54 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();
+    extendSelectionForwardByCharacterCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "foo" and "bar" centered in their own red boxes. The "baz" line should be in its own red box, but not centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+</div>
+<div class="editing">
+bar
+</div>
+<div class="editing">
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-006-expected.txt b/LayoutTests/editing/style/create-block-for-style-006-expected.txt
new file mode 100644 (file)
index 0000000..1d81f7a
--- /dev/null
@@ -0,0 +1,26 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 725x56
+          text run at (14,14) width 725: "Should see \"bar\" and \"baz\" centered in their own red boxes. The \"foo\" line"
+          text run at (14,42) width 448: "should be in its own red box, but not centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (14,14) size 32x28
+            text run at (14,14) width 32: "foo"
+        RenderBlock {DIV} at (0,56) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 31x28
+            text run at (376,14) width 31: "bar"
+        RenderBlock {DIV} at (0,112) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (375,14) size 34x28
+            text run at (375,14) width 34: "baz"
+selection is RANGE:
+start:      position 0 of child 1 {TEXT} of child 3 {DIV} of root {DIV}
+upstream:   position 0 of child 3 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 3 {DIV} of root {DIV}
+end:        position 1 of child 1 {TEXT} of child 5 {DIV} of root {DIV}
+upstream:   position 1 of child 1 {TEXT} of child 5 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 5 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-006.html b/LayoutTests/editing/style/create-block-for-style-006.html
new file mode 100644 (file)
index 0000000..e2bf8e1
--- /dev/null
@@ -0,0 +1,55 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    extendSelectionForwardByLineCommand();
+    extendSelectionForwardByCharacterCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "bar" and "baz" centered in their own red boxes. The "foo" line should be in its own red box, but not centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+</div>
+<div class="editing">
+bar
+</div>
+<div class="editing">
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-007-expected.txt b/LayoutTests/editing/style/create-block-for-style-007-expected.txt
new file mode 100644 (file)
index 0000000..4c47fb5
--- /dev/null
@@ -0,0 +1,25 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 692x56
+          text run at (14,14) width 692: "Should see \"foo\" centered in its own red box. The \"bar\" and \"baz\" lines"
+          text run at (14,42) width 225: "should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 32x28
+            text run at (376,14) width 32: "foo"
+        RenderBlock {DIV} at (0,56) size 784x112 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x0
+          RenderBlock {DIV} at (14,14) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (14,14) size 31x28
+              text run at (14,14) width 31: "bar"
+          RenderBlock (anonymous) at (14,70) size 756x28
+            RenderText {TEXT} at (0,0) size 34x28
+              text run at (0,0) width 34: "baz"
+selection is CARET:
+start:      position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-007.html b/LayoutTests/editing/style/create-block-for-style-007.html
new file mode 100644 (file)
index 0000000..3eaf5ad
--- /dev/null
@@ -0,0 +1,50 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "foo" centered in its own red box. The "bar" and "baz" lines should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+</div>
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-008-expected.txt b/LayoutTests/editing/style/create-block-for-style-008-expected.txt
new file mode 100644 (file)
index 0000000..b835bd6
--- /dev/null
@@ -0,0 +1,24 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 692x56
+          text run at (14,14) width 692: "Should see \"bar\" centered in its own red box. The \"foo\" and \"baz\" lines"
+          text run at (14,42) width 225: "should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x140
+        RenderBlock {DIV} at (0,0) size 784x140 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+          RenderBlock {DIV} at (14,42) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (362,14) size 31x28
+              text run at (362,14) width 31: "bar"
+          RenderBlock (anonymous) at (14,98) size 756x28
+            RenderText {TEXT} at (0,0) size 34x28
+              text run at (0,0) width 34: "baz"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 2 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 2 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 2 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-008.html b/LayoutTests/editing/style/create-block-for-style-008.html
new file mode 100644 (file)
index 0000000..db66dd6
--- /dev/null
@@ -0,0 +1,51 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "bar" centered in its own red box. The "foo" and "baz" lines should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+</div>
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-009-expected.txt b/LayoutTests/editing/style/create-block-for-style-009-expected.txt
new file mode 100644 (file)
index 0000000..d6d5c5a
--- /dev/null
@@ -0,0 +1,25 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 749x56
+          text run at (14,14) width 749: "Should see \"baz\" centered in its own red box inside the box containing \"foo\"."
+          text run at (14,42) width 477: "The \"foo\" and \"bar\" lines should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x168 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+          RenderBlock {DIV} at (14,42) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (14,14) size 31x28
+              text run at (14,14) width 31: "bar"
+          RenderBlock (anonymous) at (14,98) size 756x0
+          RenderBlock {DIV} at (14,98) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (361,14) size 34x28
+              text run at (361,14) width 34: "baz"
+selection is CARET:
+start:      position 2 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 2 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 2 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-009.html b/LayoutTests/editing/style/create-block-for-style-009.html
new file mode 100644 (file)
index 0000000..e1638f4
--- /dev/null
@@ -0,0 +1,52 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see "baz" centered in its own red box inside the box containing "foo". The "foo" and "bar" lines should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+</div>
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-010-expected.txt b/LayoutTests/editing/style/create-block-for-style-010-expected.txt
new file mode 100644 (file)
index 0000000..5ac2cbb
--- /dev/null
@@ -0,0 +1,28 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 713x56
+          text run at (14,14) width 713: "Should see the \"foo\" and \"baz\" lines centered in their own red boxes. The"
+          text run at (14,42) width 328: "\"baz\" line should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (376,14) size 32x28
+            text run at (376,14) width 32: "foo"
+        RenderBlock {DIV} at (0,56) size 784x112 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x0
+          RenderBlock {DIV} at (14,14) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (362,14) size 31x28
+              text run at (362,14) width 31: "bar"
+          RenderBlock (anonymous) at (14,70) size 756x28
+            RenderText {TEXT} at (0,0) size 34x28
+              text run at (0,0) width 34: "baz"
+selection is RANGE:
+start:      position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 1 {DIV} of root {DIV}
+end:        position 1 of child 1 {TEXT} of child 1 {DIV} of child 2 {DIV} of root {DIV}
+upstream:   position 1 of child 1 {TEXT} of child 1 {DIV} of child 2 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 1 {DIV} of child 2 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-010.html b/LayoutTests/editing/style/create-block-for-style-010.html
new file mode 100644 (file)
index 0000000..f014e8f
--- /dev/null
@@ -0,0 +1,52 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();
+    extendSelectionForwardByCharacterCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see the "foo" and "baz" lines centered in their own red boxes. The "baz" line should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+</div>
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-011-expected.txt b/LayoutTests/editing/style/create-block-for-style-011-expected.txt
new file mode 100644 (file)
index 0000000..8152685
--- /dev/null
@@ -0,0 +1,28 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 712x56
+          text run at (14,14) width 712: "Should see the \"bar\" and \"baz\" lines centered in their own red boxes. The"
+          text run at (14,42) width 326: "\"foo\" line should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x168 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+          RenderBlock {DIV} at (14,42) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (362,14) size 31x28
+              text run at (362,14) width 31: "bar"
+          RenderBlock (anonymous) at (14,98) size 756x0
+          RenderBlock {DIV} at (14,98) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (361,14) size 34x28
+              text run at (361,14) width 34: "baz"
+selection is RANGE:
+start:      position 0 of child 1 {TEXT} of child 2 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 2 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 2 {DIV} of child 1 {DIV} of root {DIV}
+end:        position 3 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 3 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 3 of child 1 {TEXT} of child 3 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-011.html b/LayoutTests/editing/style/create-block-for-style-011.html
new file mode 100644 (file)
index 0000000..c64dd79
--- /dev/null
@@ -0,0 +1,53 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    extendSelectionForwardByLineCommand();
+    extendSelectionForwardByCharacterCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see the "bar" and "baz" lines centered in their own red boxes. The "foo" line should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+</div>
+baz
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-012-expected.txt b/LayoutTests/editing/style/create-block-for-style-012-expected.txt
new file mode 100644 (file)
index 0000000..1326d54
--- /dev/null
@@ -0,0 +1,29 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 712x56
+          text run at (14,14) width 712: "Should see the \"bar\" and \"baz\" lines centered in their own red boxes. The"
+          text run at (14,42) width 326: "\"foo\" line should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x196
+        RenderBlock {DIV} at (0,0) size 784x56 [border: (2px solid #FF0000)]
+          RenderText {TEXT} at (14,14) size 32x28
+            text run at (14,14) width 32: "foo"
+        RenderBlock {DIV} at (0,56) size 784x140 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x0
+          RenderBlock {DIV} at (14,14) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (359,14) size 37x28
+              text run at (359,14) width 37: "bar "
+            RenderBR {BR} at (0,0) size 0x0
+          RenderBlock {DIV} at (14,70) size 756x56 [border: (2px solid #FF0000)]
+            RenderText {TEXT} at (361,14) size 34x28
+              text run at (361,14) width 34: "baz"
+selection is RANGE:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of child 2 {DIV} of root {DIV}
+upstream:   position 0 of child 1 {DIV} of child 2 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of child 2 {DIV} of root {DIV}
+end:        position 1 of child 1 {TEXT} of child 2 {DIV} of child 2 {DIV} of root {DIV}
+upstream:   position 1 of child 1 {TEXT} of child 2 {DIV} of child 2 {DIV} of root {DIV}
+downstream: position 1 of child 1 {TEXT} of child 2 {DIV} of child 2 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-012.html b/LayoutTests/editing/style/create-block-for-style-012.html
new file mode 100644 (file)
index 0000000..4e9fdad
--- /dev/null
@@ -0,0 +1,53 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    extendSelectionForwardByLineCommand();
+    extendSelectionForwardByCharacterCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see the "bar" and "baz" lines centered in their own red boxes. The "foo" line should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+<br>baz
+</div>
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/style/create-block-for-style-013-expected.txt b/LayoutTests/editing/style/create-block-for-style-013-expected.txt
new file mode 100644 (file)
index 0000000..4ac6e6b
--- /dev/null
@@ -0,0 +1,26 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x84 [border: (2px solid #0000FF)]
+        RenderText {TEXT} at (14,14) size 717x56
+          text run at (14,14) width 717: "Should see the \"baz\" line centered in its red box inside the box containing"
+          text run at (14,42) width 540: "\"bar\". The \"foo\" and \"bar\" lines should not be centered."
+      RenderBlock {DIV} at (0,108) size 784x168
+        RenderBlock {DIV} at (0,0) size 784x168 [border: (2px solid #FF0000)]
+          RenderBlock (anonymous) at (14,14) size 756x28
+            RenderText {TEXT} at (0,0) size 32x28
+              text run at (0,0) width 32: "foo"
+          RenderBlock {DIV} at (14,42) size 756x112 [border: (2px solid #FF0000)]
+            RenderBlock (anonymous) at (14,14) size 728x28
+              RenderText {TEXT} at (0,0) size 37x28
+                text run at (0,0) width 37: "bar "
+              RenderBR {BR} at (0,0) size 0x0
+            RenderBlock {DIV} at (14,42) size 728x56 [border: (2px solid #FF0000)]
+              RenderText {TEXT} at (347,14) size 34x28
+                text run at (347,14) width 34: "baz"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 3 {DIV} of child 2 {DIV} of child 1 {DIV} of root {DIV}
+upstream:   position 0 of child 3 {DIV} of child 2 {DIV} of child 1 {DIV} of root {DIV}
+downstream: position 0 of child 1 {TEXT} of child 3 {DIV} of child 2 {DIV} of child 1 {DIV} of root {DIV}
diff --git a/LayoutTests/editing/style/create-block-for-style-013.html b/LayoutTests/editing/style/create-block-for-style-013.html
new file mode 100644 (file)
index 0000000..6e0e718
--- /dev/null
@@ -0,0 +1,52 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    border: 2px solid red; 
+    padding: 12px; 
+    font-size: 24px; 
+}
+.explanation { 
+    border: 2px solid blue; 
+    padding: 12px; 
+    font-size: 24px; 
+    margin-bottom: 24px;
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();
+    moveSelectionForwardByLineCommand();
+    justifyCenterCommand();
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable>
+
+<div class="explanation">
+Should see the "baz" line centered in its red box inside the box containing "bar". The "foo" and "bar" lines should not be centered.
+</div>
+
+<div id="root" style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space;">
+<div id="test" class="editing">
+foo
+<div class="editing">
+bar
+<br>baz
+</div>
+</div>
+</div>
+
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index c397ad7..9633d22 100644 (file)
@@ -1,3 +1,53 @@
+2005-01-10  Ken Kocienda  <kocienda@apple.com>
+
+        Reviewed by Darin
+
+        Fix for this bug:
+        
+        <rdar://problem/3907005> Applying block styles to a line of text can unexpectedly affect other lines
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary): New function which moves "paragraphs"
+        to their own blocks if needed so that a block style can be applied.
+        (khtml::CompositeEditCommand::isMailBlockquote): Moved this function to base class so it can be used more generally.
+        (khtml::ApplyStyleCommand::applyBlockStyle): Pass a node instead of a block to addBlockStyleIfNeeded().
+        (khtml::ApplyStyleCommand::addBlockStyleIfNeeded): Now accepts a node instead of a block for styling.
+        This function also now calls moveParagraphContentsToNewBlockIfNecessary() to make sure that only the current
+        paragraph is styled.
+        (khtml::SetNodeAttributeCommand::doUnapply): Should not assert on undo if old value of attribute was null.
+        Should remove attributue instead.
+        * khtml/editing/htmlediting.h: Touch function declarations accordingly.
+        * layout-tests/editing/style/create-block-for-style-001-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-001.html: Added.
+        * layout-tests/editing/style/create-block-for-style-002-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-002.html: Added.
+        * layout-tests/editing/style/create-block-for-style-003-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-003.html: Added.
+        * layout-tests/editing/style/create-block-for-style-004-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-004.html: Added.
+        * layout-tests/editing/style/create-block-for-style-005-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-005.html: Added.
+        * layout-tests/editing/style/create-block-for-style-006-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-006.html: Added.
+        * layout-tests/editing/style/create-block-for-style-007-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-007.html: Added.
+        * layout-tests/editing/style/create-block-for-style-008-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-008.html: Added.
+        * layout-tests/editing/style/create-block-for-style-009-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-009.html: Added.
+        * layout-tests/editing/style/create-block-for-style-010-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-010.html: Added.
+        * layout-tests/editing/style/create-block-for-style-011-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-011.html: Added.
+        * layout-tests/editing/style/create-block-for-style-012-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-012.html: Added.
+        * layout-tests/editing/style/create-block-for-style-013-expected.txt: Added.
+        * layout-tests/editing/style/create-block-for-style-013.html: Added.
+
+        Unrelated updates to these expected results.
+        * layout-tests/editing/inserting/insert-div-007-expected.txt
+        * layout-tests/editing/pasteboard/paste-text-013-expected.txt
+
 2005-01-10  Chris Blumenberg  <cblu@apple.com>
 
        Fixed: <rdar://problem/3936844> Mail: Messages with rich text do not print
index 498a246..646fe6b 100644 (file)
@@ -975,6 +975,90 @@ bool CompositeEditCommand::removeBlockPlaceholderIfNeeded(NodeImpl *node)
     return false;
 }
 
+void CompositeEditCommand::moveParagraphContentsToNewBlockIfNecessary(const Position &pos)
+{
+    if (pos.isNull())
+        return;
+        
+    VisiblePosition visiblePos(pos);
+    VisiblePosition visibleParagraphStart(startOfParagraph(visiblePos));
+    VisiblePosition visibleParagraphEnd(endOfParagraph(visiblePos, IncludeLineBreak));
+    Position paragraphStart = visibleParagraphStart.deepEquivalent().upstream(StayInBlock);
+    Position paragraphEnd = visibleParagraphEnd.deepEquivalent().upstream(StayInBlock);
+    Position beforeParagraphStart = paragraphStart.upstream(DoNotStayInBlock);
+    
+    // Perform some checks to see if we need to perform work in this function.
+    if (paragraphStart.node()->isBlockFlow()) {
+        if (paragraphEnd.node()->isBlockFlow()) {
+            if (!paragraphEnd.node()->isAncestor(paragraphStart.node())) {
+                // If the paragraph end is a descendant of paragraph start, then we need to run
+                // the rest of this function. If not, we can bail here.
+                return;
+            }
+        }
+        else if (paragraphEnd.node()->enclosingBlockFlowElement() != paragraphStart.node()) {
+            // The paragraph end is in another block that is an ancestor of the paragraph start.
+            // We can bail as we have a full block to work with.
+            ASSERT(paragraphStart.node()->isAncestor(paragraphEnd.node()->enclosingBlockFlowElement()));
+            return;
+        }
+        else if (visibleParagraphEnd.next().isNull()) {
+            // At the end of the document. We can bail here as well.
+            return;
+        }
+    }
+    
+    // Create the block to insert. Most times, this will be a shallow clone of the block containing
+    // the start of the selection (the start block), except for two cases:
+    //    1) When the start block is a body element.
+    //    2) When the start block is a mail blockquote and we are not in a position to insert
+    //       the new block as a peer of the start block. This prevents creating an unwanted 
+    //       additional level of quoting.
+    NodeImpl *startBlock = paragraphStart.node()->enclosingBlockFlowElement();
+    NodeImpl *newBlock = 0;
+    if (startBlock->id() == ID_BODY || (isMailBlockquote(startBlock) && paragraphStart.node() != startBlock))
+        newBlock = createDefaultParagraphElement(document());
+    else
+        newBlock = startBlock->cloneNode(false);
+
+    NodeImpl *moveNode = paragraphStart.node();
+    if (paragraphStart.offset() >= paragraphStart.node()->caretMaxOffset())
+        moveNode = moveNode->traverseNextNode();
+    NodeImpl *endNode = paragraphEnd.node();
+    while (moveNode && !moveNode->isBlockFlow()) {
+        NodeImpl *next = moveNode->traverseNextNode();
+        removeNode(moveNode);
+        appendNode(moveNode, newBlock);
+        if (moveNode == endNode)
+            break;
+        moveNode = next;
+    }
+
+    if (paragraphStart.node()->id() == ID_BODY) {
+        insertNodeAt(newBlock, paragraphStart.node(), 0);
+    }
+    else if (paragraphStart.node()->id() == ID_BR) {
+        insertNodeAfter(newBlock, paragraphStart.node());
+    }
+    else if (paragraphStart.node()->isBlockFlow()) {
+        insertNodeBefore(newBlock, paragraphStart.node());
+    }
+    else if (beforeParagraphStart.node()->enclosingBlockFlowElement()->id() != ID_BODY) {
+        insertNodeAfter(newBlock, beforeParagraphStart.node()->enclosingBlockFlowElement());
+    }
+    else {
+        insertNodeAfter(newBlock, beforeParagraphStart.node());
+    }
+}
+
+bool CompositeEditCommand::isMailBlockquote(const NodeImpl *node) const
+{
+    if (!node || !node->renderer() || !node->isElementNode() && node->id() != ID_BLOCKQUOTE)
+        return false;
+        
+    return static_cast<const ElementImpl *>(node)->getAttribute("type") == "cite";
+}
+
 //==========================================================================================
 // Concrete commands
 //------------------------------------------------------------------------------------------
@@ -1089,10 +1173,12 @@ void ApplyStyleCommand::applyBlockStyle(CSSMutableStyleDeclarationImpl *style)
     // apply specified styles to the block flow elements in the selected range
     prevBlock = 0;
     for (NodeImpl *node = start.node(); node != beyondEnd; node = node->traverseNextNode()) {
-        NodeImpl *block = node->enclosingBlockFlowElement();
-        if (block != prevBlock && block->isHTMLElement()) {
-            addBlockStyleIfNeeded(style, static_cast<HTMLElementImpl *>(block));
-            prevBlock = block;
+        if (node->renderer()) {
+            NodeImpl *block = node->enclosingBlockFlowElement();
+            if (block != prevBlock) {
+                addBlockStyleIfNeeded(style, node);
+                prevBlock = block;
+            }
         }
     }
 }
@@ -1321,17 +1407,26 @@ void ApplyStyleCommand::surroundNodeRangeWithElement(NodeImpl *startNode, NodeIm
     }
 }
 
-void ApplyStyleCommand::addBlockStyleIfNeeded(CSSMutableStyleDeclarationImpl *style, HTMLElementImpl *block)
+void ApplyStyleCommand::addBlockStyleIfNeeded(CSSMutableStyleDeclarationImpl *style, NodeImpl *node)
 {
     // Do not check for legacy styles here. Those styles, like <B> and <I>, only apply for
     // inline content.
+    if (!node)
+        return;
+    
+    HTMLElementImpl *block = static_cast<HTMLElementImpl *>(node->enclosingBlockFlowElement());
+    if (!block)
+        return;
+        
     StyleChange styleChange(style, Position(block, 0), StyleChange::DoNotUseLegacyHTMLStyles);
     if (styleChange.cssStyle().length() > 0) {
+        moveParagraphContentsToNewBlockIfNecessary(Position(node, 0));
+        block = static_cast<HTMLElementImpl *>(node->enclosingBlockFlowElement());
         DOMString cssText = styleChange.cssStyle();
         CSSMutableStyleDeclarationImpl *decl = block->inlineStyleDecl();
         if (decl)
             cssText += decl->cssText();
-        block->setAttribute(ATTR_STYLE, cssText);
+        setNodeAttribute(block, ATTR_STYLE, cssText);
     }
 }
 
@@ -2474,14 +2569,6 @@ InsertParagraphSeparatorInQuotedContentCommand::~InsertParagraphSeparatorInQuote
         m_breakNode->deref();
 }
 
-bool InsertParagraphSeparatorInQuotedContentCommand::isMailBlockquote(const NodeImpl *node) const
-{
-    if (!node || !node->renderer() || !node->isElementNode() && node->id() != ID_BLOCKQUOTE)
-        return false;
-        
-    return static_cast<const ElementImpl *>(node)->getAttribute("type") == "cite";
-}
-
 void InsertParagraphSeparatorInQuotedContentCommand::doApply()
 {
     Selection selection = endingSelection();
@@ -3744,10 +3831,12 @@ void SetNodeAttributeCommand::doApply()
 void SetNodeAttributeCommand::doUnapply()
 {
     ASSERT(m_element);
-    ASSERT(!m_oldValue.isNull());
 
     int exceptionCode = 0;
-    m_element->setAttribute(m_attribute, m_oldValue.implementation(), exceptionCode);
+    if (m_oldValue.isNull())
+        m_element->removeAttribute(m_attribute, exceptionCode);
+    else
+        m_element->setAttribute(m_attribute, m_oldValue.implementation(), exceptionCode);
     ASSERT(exceptionCode == 0);
 }
 
index fb6e9ea..f79b42d 100644 (file)
@@ -220,6 +220,10 @@ protected:
     void insertBlockPlaceholderIfNeeded(DOM::NodeImpl *);
     bool removeBlockPlaceholderIfNeeded(DOM::NodeImpl *);
 
+    void moveParagraphContentsToNewBlockIfNecessary(const DOM::Position &);
+
+    bool isMailBlockquote(const DOM::NodeImpl *) const;
+
     QValueList<EditCommandPtr> m_cmds;
 };
 
@@ -271,7 +275,7 @@ private:
     // style-application helpers
     void applyBlockStyle(DOM::CSSMutableStyleDeclarationImpl *);
     void applyInlineStyle(DOM::CSSMutableStyleDeclarationImpl *);
-    void addBlockStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::HTMLElementImpl *);
+    void addBlockStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::NodeImpl *);
     void addInlineStyleIfNeeded(DOM::CSSMutableStyleDeclarationImpl *, DOM::NodeImpl *start, DOM::NodeImpl *end);
     bool splitTextAtStartIfNeeded(const DOM::Position &start, const DOM::Position &end);
     DOM::NodeImpl *splitTextAtEndIfNeeded(const DOM::Position &start, const DOM::Position &end);
@@ -445,8 +449,6 @@ public:
     virtual void doApply();
     
 private:
-    bool isMailBlockquote(const DOM::NodeImpl *) const;
-
     QPtrList<DOM::NodeImpl> ancestors;
     QPtrList<DOM::NodeImpl> clonedNodes;
     DOM::ElementImpl *m_breakNode;