Reviewed by Harrison
authorkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2004 22:23:23 +0000 (22:23 +0000)
committerkocienda <kocienda@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Nov 2004 22:23:23 +0000 (22:23 +0000)
        Some improvements to deleting when complete lines are selected.

        * khtml/editing/htmlediting.cpp:
        (khtml::DeleteSelectionCommand::initializePositionData): Detect when the line containing
        the end of a selection is fully selected. Turn off block merging in this case.
        (khtml::DeleteSelectionCommand::handleSpecialCaseBRDelete): Fix a bug in the check for
        whether a BR immediately followed a block. The old code could erroneously skip nodes.
        (khtml::DeleteSelectionCommand::handleGeneralDelete): Add a case for when the entire
        start block is selected. This new code will now delete this block in one call, rather
        than iterating over each child.
        * khtml/editing/visible_position.cpp:
        (khtml::visiblePositionsOnDifferentLines): New helper called in initializePositionData()
        to do the work mentioned above in the comment for that function.
        (khtml::isFirstVisiblePositionOnLine): Ditto.
        (khtml::isLastVisiblePositionOnLine): Ditto.
        * khtml/editing/visible_position.h: Add new functions.
        * layout-tests/editing/deleting/delete-line-001-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-001.html: Added.
        * layout-tests/editing/deleting/delete-line-002-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-002.html: Added.
        * layout-tests/editing/deleting/delete-line-003-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-003.html: Added.
        * layout-tests/editing/deleting/delete-line-004-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-004.html: Added.
        * layout-tests/editing/deleting/delete-line-005-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-005.html: Added.
        * layout-tests/editing/deleting/delete-line-006-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-006.html: Added.
        * layout-tests/editing/deleting/delete-line-007-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-007.html: Added.
        * layout-tests/editing/deleting/delete-line-008-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-008.html: Added.
        * layout-tests/editing/deleting/delete-line-009-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-009.html: Added.
        * layout-tests/editing/deleting/delete-line-010-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-010.html: Added.
        * layout-tests/editing/deleting/delete-line-011-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-011.html: Added.
        * layout-tests/editing/deleting/delete-line-012-expected.txt: Added.
        * layout-tests/editing/deleting/delete-line-012.html: Added.

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

28 files changed:
LayoutTests/editing/deleting/delete-line-001-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-001.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-002-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-002.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-003-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-003.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-004-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-004.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-005-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-005.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-006-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-006.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-007-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-007.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-008-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-008.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-009-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-009.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-010-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-010.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-011-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-011.html [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-012-expected.txt [new file with mode: 0644]
LayoutTests/editing/deleting/delete-line-012.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/editing/htmlediting.cpp
WebCore/khtml/editing/visible_position.cpp
WebCore/khtml/editing/visible_position.h

diff --git a/LayoutTests/editing/deleting/delete-line-001-expected.txt b/LayoutTests/editing/deleting/delete-line-001-expected.txt
new file mode 100644 (file)
index 0000000..c87a137
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 197x28
+          text run at (0,0) width 197: "in the affairs of men"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-001.html b/LayoutTests/editing/deleting/delete-line-001.html
new file mode 100644 (file)
index 0000000..b3922d4
--- /dev/null
@@ -0,0 +1,30 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-002-expected.txt b/LayoutTests/editing/deleting/delete-line-002-expected.txt
new file mode 100644 (file)
index 0000000..c87a137
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 197x28
+          text run at (0,0) width 197: "in the affairs of men"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-002.html b/LayoutTests/editing/deleting/delete-line-002.html
new file mode 100644 (file)
index 0000000..4918b24
--- /dev/null
@@ -0,0 +1,30 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div><div class="editing">in the affairs of men</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-003-expected.txt b/LayoutTests/editing/deleting/delete-line-003-expected.txt
new file mode 100644 (file)
index 0000000..ae79c34
--- /dev/null
@@ -0,0 +1,15 @@
+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 600x56
+        RenderText {TEXT} at (0,0) size 139x28
+          text run at (0,0) width 139: "There is a tide"
+        RenderBR {BR} at (0,0) size 0x0
+        RenderText {TEXT} at (0,28) size 241x28
+          text run at (0,28) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 3 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 1 of child 2 {BR} of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 3 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-003.html b/LayoutTests/editing/deleting/delete-line-003.html
new file mode 100644 (file)
index 0000000..8bf0bf8
--- /dev/null
@@ -0,0 +1,31 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men<br>Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-004-expected.txt b/LayoutTests/editing/deleting/delete-line-004-expected.txt
new file mode 100644 (file)
index 0000000..bea14af
--- /dev/null
@@ -0,0 +1,15 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 139x28
+          text run at (0,0) width 139: "There is a tide"
+      RenderBlock {DIV} at (0,28) size 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 3 {DIV} of root {BODY}
+upstream:   position 0 of child 3 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 3 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-004.html b/LayoutTests/editing/deleting/delete-line-004.html
new file mode 100644 (file)
index 0000000..3490e21
--- /dev/null
@@ -0,0 +1,33 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    moveSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div>
+<div class="editing">in the affairs of men</div>
+<div class="editing">Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-005-expected.txt b/LayoutTests/editing/deleting/delete-line-005-expected.txt
new file mode 100644 (file)
index 0000000..a893f3e
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-005.html b/LayoutTests/editing/deleting/delete-line-005.html
new file mode 100644 (file)
index 0000000..64259ca
--- /dev/null
@@ -0,0 +1,31 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men<br>Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-006-expected.txt b/LayoutTests/editing/deleting/delete-line-006-expected.txt
new file mode 100644 (file)
index 0000000..a893f3e
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-006.html b/LayoutTests/editing/deleting/delete-line-006.html
new file mode 100644 (file)
index 0000000..db56416
--- /dev/null
@@ -0,0 +1,33 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div>
+<div class="editing">in the affairs of men</div>
+<div class="editing">Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-007-expected.txt b/LayoutTests/editing/deleting/delete-line-007-expected.txt
new file mode 100644 (file)
index 0000000..a893f3e
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-007.html b/LayoutTests/editing/deleting/delete-line-007.html
new file mode 100644 (file)
index 0000000..863cddf
--- /dev/null
@@ -0,0 +1,32 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men</div>
+<div class="editing">Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-008-expected.txt b/LayoutTests/editing/deleting/delete-line-008-expected.txt
new file mode 100644 (file)
index 0000000..a893f3e
--- /dev/null
@@ -0,0 +1,12 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-008.html b/LayoutTests/editing/deleting/delete-line-008.html
new file mode 100644 (file)
index 0000000..ee28085
--- /dev/null
@@ -0,0 +1,32 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div>
+<div class="editing">in the affairs of men<br>Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-009-expected.txt b/LayoutTests/editing/deleting/delete-line-009-expected.txt
new file mode 100644 (file)
index 0000000..90c641a
--- /dev/null
@@ -0,0 +1,14 @@
+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 600x28
+        RenderBR {BR} at (0,0) size 0x28
+      RenderBlock {DIV} at (0,28) size 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {BR} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {BR} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-009.html b/LayoutTests/editing/deleting/delete-line-009.html
new file mode 100644 (file)
index 0000000..84e797c
--- /dev/null
@@ -0,0 +1,33 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();
+    extendSelectionBackwardByCharacterCommand();
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men</div>
+<div class="editing">Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-010-expected.txt b/LayoutTests/editing/deleting/delete-line-010-expected.txt
new file mode 100644 (file)
index 0000000..6187de8
--- /dev/null
@@ -0,0 +1,13 @@
+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 600x56
+        RenderBR {BR} at (0,0) size 0x28
+        RenderText {TEXT} at (0,28) size 241x28
+          text run at (0,28) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 0 of child 1 {BR} of child 1 {DIV} of root {BODY}
+upstream:   position 0 of child 1 {DIV} of root {BODY}
+downstream: position 0 of child 1 {BR} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-010.html b/LayoutTests/editing/deleting/delete-line-010.html
new file mode 100644 (file)
index 0000000..83d8d84
--- /dev/null
@@ -0,0 +1,33 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    extendSelectionForwardByLineCommand();    
+    extendSelectionForwardByLineCommand();    
+    extendSelectionBackwardByCharacterCommand();
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div>
+<div class="editing">in the affairs of men<br>Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-011-expected.txt b/LayoutTests/editing/deleting/delete-line-011-expected.txt
new file mode 100644 (file)
index 0000000..517db84
--- /dev/null
@@ -0,0 +1,15 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 96x28
+          text run at (0,0) width 96: "There is a"
+      RenderBlock {DIV} at (0,28) size 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+downstream: position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-011.html b/LayoutTests/editing/deleting/delete-line-011.html
new file mode 100644 (file)
index 0000000..025d181
--- /dev/null
@@ -0,0 +1,35 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    for (i = 0; i < 10; i++)
+        moveSelectionForwardByCharacterCommand(); 
+    extendSelectionForwardByLineCommand();    
+    for (i = 0; i < 11; i++)
+        extendSelectionForwardByCharacterCommand(); 
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide<br>in the affairs of men</div>
+<div class="editing">Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
diff --git a/LayoutTests/editing/deleting/delete-line-012-expected.txt b/LayoutTests/editing/deleting/delete-line-012-expected.txt
new file mode 100644 (file)
index 0000000..517db84
--- /dev/null
@@ -0,0 +1,15 @@
+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 600x28
+        RenderText {TEXT} at (0,0) size 96x28
+          text run at (0,0) width 96: "There is a"
+      RenderBlock {DIV} at (0,28) size 600x28
+        RenderText {TEXT} at (0,0) size 241x28
+          text run at (0,0) width 241: "Which taken at the flood"
+selection is CARET:
+start:      position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+upstream:   position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
+downstream: position 10 of child 1 {TEXT} of child 1 {DIV} of root {BODY}
diff --git a/LayoutTests/editing/deleting/delete-line-012.html b/LayoutTests/editing/deleting/delete-line-012.html
new file mode 100644 (file)
index 0000000..2084fa7
--- /dev/null
@@ -0,0 +1,35 @@
+<html> 
+<head>
+
+<style>
+.editing { 
+    font-size: 24px; 
+    width: 600px; 
+}
+</style>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+
+<script>
+
+function editingTest() {
+    for (i = 0; i < 10; i++)
+        moveSelectionForwardByCharacterCommand(); 
+    extendSelectionForwardByLineCommand();    
+    for (i = 0; i < 11; i++)
+        extendSelectionForwardByCharacterCommand(); 
+    deleteCommand(); 
+}
+
+</script>
+
+<title>Editing Test</title> 
+</head> 
+<body contenteditable id="root">
+<div id="test" class="editing">There is a tide</div>
+<div class="editing">in the affairs of men<br>Which taken at the flood</div>
+<script>
+runEditingTest();
+</script>
+
+</body>
+</html>
index 6866190..6c23a1e 100644 (file)
@@ -1,5 +1,50 @@
 2004-11-11  Ken Kocienda  <kocienda@apple.com>
 
+        Reviewed by Harrison
+
+        Some improvements to deleting when complete lines are selected.
+
+        * khtml/editing/htmlediting.cpp:
+        (khtml::DeleteSelectionCommand::initializePositionData): Detect when the line containing
+        the end of a selection is fully selected. Turn off block merging in this case.
+        (khtml::DeleteSelectionCommand::handleSpecialCaseBRDelete): Fix a bug in the check for
+        whether a BR immediately followed a block. The old code could erroneously skip nodes.
+        (khtml::DeleteSelectionCommand::handleGeneralDelete): Add a case for when the entire
+        start block is selected. This new code will now delete this block in one call, rather
+        than iterating over each child.
+        * khtml/editing/visible_position.cpp:
+        (khtml::visiblePositionsOnDifferentLines): New helper called in initializePositionData()
+        to do the work mentioned above in the comment for that function.
+        (khtml::isFirstVisiblePositionOnLine): Ditto.
+        (khtml::isLastVisiblePositionOnLine): Ditto.
+        * khtml/editing/visible_position.h: Add new functions.
+        * layout-tests/editing/deleting/delete-line-001-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-001.html: Added.
+        * layout-tests/editing/deleting/delete-line-002-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-002.html: Added.
+        * layout-tests/editing/deleting/delete-line-003-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-003.html: Added.
+        * layout-tests/editing/deleting/delete-line-004-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-004.html: Added.
+        * layout-tests/editing/deleting/delete-line-005-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-005.html: Added.
+        * layout-tests/editing/deleting/delete-line-006-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-006.html: Added.
+        * layout-tests/editing/deleting/delete-line-007-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-007.html: Added.
+        * layout-tests/editing/deleting/delete-line-008-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-008.html: Added.
+        * layout-tests/editing/deleting/delete-line-009-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-009.html: Added.
+        * layout-tests/editing/deleting/delete-line-010-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-010.html: Added.
+        * layout-tests/editing/deleting/delete-line-011-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-011.html: Added.
+        * layout-tests/editing/deleting/delete-line-012-expected.txt: Added.
+        * layout-tests/editing/deleting/delete-line-012.html: Added.
+
+2004-11-11  Ken Kocienda  <kocienda@apple.com>
+
         Reviewed by Adele
 
         * khtml/editing/htmlediting.cpp:
index d192685..d5da152 100644 (file)
@@ -1460,6 +1460,17 @@ void DeleteSelectionCommand::initializePositionData()
     m_startNode = m_upstreamStart.node();
     m_startNode->ref();
 
+    //
+    // Handle detecting if the line containing the selection end is itself fully selected.
+    // This is one of the tests that determines if block merging of content needs to be done.
+    //
+    VisiblePosition visibleEnd(end);
+    if (isFirstVisiblePositionOnLine(visibleEnd)) {
+        Position previousLineStart = previousLinePosition(visibleEnd, DOWNSTREAM, 0).deepEquivalent();
+        if (RangeImpl::compareBoundaryPoints(previousLineStart.node(), previousLineStart.offset(), m_downstreamStart.node(), m_downstreamStart.offset()) >= 0)
+            m_mergeBlocksAfterDelete = false;
+    }
+
     debugPosition("m_upstreamStart      ", m_upstreamStart);
     debugPosition("m_downstreamStart    ", m_downstreamStart);
     debugPosition("m_upstreamEnd        ", m_upstreamEnd);
@@ -1519,11 +1530,11 @@ bool DeleteSelectionCommand::handleSpecialCaseBRDelete()
 
     // Check for special-case where the selection contains only a BR right after a block ended.
     bool downstreamEndIsBR = m_downstreamEnd.node()->id() == ID_BR;
-    Position upstreamUpstreamStart = m_upstreamStart.upstream();
-    bool startIsBRAfterBlock = downstreamEndIsBR && m_downstreamEnd.node()->enclosingBlockFlowElement() != upstreamUpstreamStart.node()->enclosingBlockFlowElement();
+    Position upstreamFromBR = m_downstreamEnd.upstream();
+    bool startIsBRAfterBlock = downstreamEndIsBR && m_downstreamEnd.node()->enclosingBlockFlowElement() != upstreamFromBR.node()->enclosingBlockFlowElement();
     if (startIsBRAfterBlock) {
         removeNode(m_downstreamEnd.node());
-        m_endingPosition = upstreamUpstreamStart;
+        m_endingPosition = upstreamFromBR;
         m_mergeBlocksAfterDelete = false;
         return true;
     }
@@ -1540,7 +1551,21 @@ void DeleteSelectionCommand::handleGeneralDelete()
 {
     int startOffset = m_upstreamStart.offset();
 
-    if (startOffset >= m_startNode->caretMaxOffset()) {
+    if (startOffset == 0 && m_startNode->isBlockFlow() && m_startBlock != m_endBlock && !m_endBlock->isAncestor(m_startBlock)) {
+        // The block containing the start of the selection is completely selected. 
+        // Delete it all in one step right here.
+        ASSERT(!m_downstreamEnd.node()->isAncestor(m_startNode));
+
+        // shift the start node to the start of the next block.
+        NodeImpl *old = m_startNode;
+        m_startNode = m_startBlock->traverseNextSibling();
+        m_startNode->ref();
+        old->deref();
+        startOffset = 0;
+
+        removeFullySelectedNode(m_startBlock);
+    }
+    else if (startOffset >= m_startNode->caretMaxOffset()) {
         // Move the start node to the next node in the tree since the startOffset is equal to
         // or beyond the start node's caretMaxOffset This means there is nothing visible to delete. 
         // However, before moving on, delete any insignificant text that may be present in a text node.
index 5f92254..431cbbd 100644 (file)
@@ -26,6 +26,8 @@
 #include "visible_position.h"
 
 #include "misc/htmltags.h"
+#include "rendering/render_line.h"
+#include "rendering/render_object.h"
 #include "rendering/render_text.h"
 #include "xml/dom2_rangeimpl.h"
 #include "xml/dom_textimpl.h"
@@ -460,4 +462,39 @@ bool setEnd(Range &r, const VisiblePosition &c)
     return code == 0;
 }
 
+bool visiblePositionsOnDifferentLines(const VisiblePosition &pos1, const VisiblePosition &pos2)
+{
+    if (pos1.isNull() || pos2.isNull())
+        return false;
+    if (pos1 == pos2)
+        return false;
+    
+    Position p1 = pos1.deepEquivalent();
+    Position p2 = pos2.deepEquivalent();
+    RenderObject *r1 = p1.node()->renderer();
+    RenderObject *r2 = p2.node()->renderer();
+    InlineBox *b1 = r1 ? r1->inlineBox(p1.offset()) : 0;
+    InlineBox *b2 = r2 ? r2->inlineBox(p2.offset()) : 0;
+    return (b1 && b2 && b1->root() != b2->root());
+}
+
+bool isFirstVisiblePositionOnLine(const VisiblePosition &pos)
+{
+    if (pos.isNull())
+        return false;
+        
+    VisiblePosition previous = pos.previous();
+    return previous.isNull() || visiblePositionsOnDifferentLines(pos, previous);
+}
+
+bool isLastVisiblePositionOnLine(const VisiblePosition &pos)
+{
+    if (pos.isNull())
+        return false;
+        
+    VisiblePosition next = pos.next();
+    return next.isNull() || visiblePositionsOnDifferentLines(pos, next);
+}
+
+
 }  // namespace DOM
index b6e05a7..110dd46 100644 (file)
@@ -117,6 +117,10 @@ VisiblePosition startVisiblePosition(const DOM::RangeImpl *);
 VisiblePosition endVisiblePosition(const DOM::Range &);
 VisiblePosition endVisiblePosition(const DOM::RangeImpl *);
 
+bool visiblePositionsOnSameLine(const VisiblePosition &, const VisiblePosition &);
+bool isFirstVisiblePositionOnLine(const VisiblePosition &);
+bool isLastVisiblePositionOnLine(const VisiblePosition &);
+
 } // namespace khtml
 
 #endif // KHTML_EDITING_VISIBLE_POSITION_H