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
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
--- /dev/null
+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}
--- /dev/null
+<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>
+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
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);
// 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;
}
{
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.
#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"
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
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