[webkit-changes] cvs commit: WebCore/khtml/editing htmlediting.cpp
htmlediting.h
Timothy
thatcher at opensource.apple.com
Thu Nov 10 21:58:32 PST 2005
thatcher 05/11/10 21:58:31
Modified: . Tag: Safari-2-0-branch ChangeLog
khtml/editing Tag: Safari-2-0-branch htmlediting.cpp
htmlediting.h
Log:
Merged fix from TOT to Safari-2-0-branch
All the changes were applied to khtml/editing/htmlediting.[m|h]
None of the other files exist on the branch, they were split off later.
2005-11-09 David Harrison <harrison at apple.com>
Reviewed by Justin.
<rdar://problem/4313925> Denver Regression: Mail: "TAB+paste+insert before" actually inserts after the pasted text
- added tab span editing functions in composite_edit_command.cpp
- called them from insertText, insertLineBreak, and replaceSelection commands
- also exposed some handy tab span funcs from htmlediting.cpp
Tests added in editing/insertion and editing/pasteboard.
* khtml/editing/composite_edit_command.cpp:
(khtml::CompositeEditCommand::positionOutsideTabSpan):
(khtml::CompositeEditCommand::insertNodeAtTabSpanPosition):
* khtml/editing/composite_edit_command.h:
* khtml/editing/htmlediting.cpp:
(khtml::positionBeforeNode):
(khtml::positionAfterNode):
(khtml::tabSpanNode):
(khtml::positionBeforeTabSpan):
* khtml/editing/htmlediting.h:
* khtml/editing/insert_line_break_command.cpp:
(khtml::InsertLineBreakCommand::doApply):
* khtml/editing/insert_text_command.cpp:
(khtml::InsertTextCommand::prepareForTextInsertion):
* khtml/editing/replace_selection_command.cpp:
(khtml::ReplaceSelectionCommand::doApply):
Revision Changes Path
No revision
No revision
1.1.2.52 +35 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.1.2.51
retrieving revision 1.1.2.52
diff -u -r1.1.2.51 -r1.1.2.52
--- ChangeLog 11 Nov 2005 05:06:30 -0000 1.1.2.51
+++ ChangeLog 11 Nov 2005 05:58:23 -0000 1.1.2.52
@@ -1,6 +1,41 @@
2005-11-10 Timothy Hatcher <timothy at apple.com>
Merged fix from TOT to Safari-2-0-branch
+ All the changes were applied to khtml/editing/htmlediting.[m|h]
+ None of the other files exist on the branch, they were split off later.
+
+ 2005-11-09 David Harrison <harrison at apple.com>
+
+ Reviewed by Justin.
+
+ <rdar://problem/4313925> Denver Regression: Mail: "TAB+paste+insert before" actually inserts after the pasted text
+
+ - added tab span editing functions in composite_edit_command.cpp
+ - called them from insertText, insertLineBreak, and replaceSelection commands
+ - also exposed some handy tab span funcs from htmlediting.cpp
+
+ Tests added in editing/insertion and editing/pasteboard.
+
+ * khtml/editing/composite_edit_command.cpp:
+ (khtml::CompositeEditCommand::positionOutsideTabSpan):
+ (khtml::CompositeEditCommand::insertNodeAtTabSpanPosition):
+ * khtml/editing/composite_edit_command.h:
+ * khtml/editing/htmlediting.cpp:
+ (khtml::positionBeforeNode):
+ (khtml::positionAfterNode):
+ (khtml::tabSpanNode):
+ (khtml::positionBeforeTabSpan):
+ * khtml/editing/htmlediting.h:
+ * khtml/editing/insert_line_break_command.cpp:
+ (khtml::InsertLineBreakCommand::doApply):
+ * khtml/editing/insert_text_command.cpp:
+ (khtml::InsertTextCommand::prepareForTextInsertion):
+ * khtml/editing/replace_selection_command.cpp:
+ (khtml::ReplaceSelectionCommand::doApply):
+
+2005-11-10 Timothy Hatcher <timothy at apple.com>
+
+ Merged fix from TOT to Safari-2-0-branch
2005-11-02 Vicki Murley <vicki at apple.com>
No revision
No revision
1.228.8.11 +45 -36 WebCore/khtml/editing/htmlediting.cpp
Index: htmlediting.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/htmlediting.cpp,v
retrieving revision 1.228.8.10
retrieving revision 1.228.8.11
diff -u -r1.228.8.10 -r1.228.8.11
--- htmlediting.cpp 27 Aug 2005 17:10:26 -0000 1.228.8.10
+++ htmlediting.cpp 11 Nov 2005 05:58:29 -0000 1.228.8.11
@@ -953,6 +953,29 @@
applyCommandToComposite(insertCommand);
}
+Position CompositeEditCommand::positionOutsideTabSpan(const Position& pos)
+{
+ ASSERT(isTabSpanTextNode(pos.node()));
+
+ NodeImpl *tabSpan = tabSpanNode(pos.node());
+
+ if (pos.offset() <= pos.node()->caretMinOffset())
+ return positionBeforeNode(tabSpan);
+
+ if (pos.offset() >= pos.node()->caretMaxOffset())
+ return positionAfterNode(tabSpan);
+
+ splitTextNodeContainingElement(static_cast<TextImpl *>(pos.node()), pos.offset());
+ return positionBeforeNode(tabSpan);
+}
+
+void CompositeEditCommand::insertNodeAtTabSpanPosition(NodeImpl *node, const Position& pos)
+{
+ // insert node before, after, or at split of tab span
+ Position insertPos = positionOutsideTabSpan(pos);
+ insertNodeAt(node, insertPos.node(), insertPos.offset());
+}
+
void CompositeEditCommand::deleteSelection(bool smartDelete, bool mergeBlocksAfterDelete)
{
if (endingSelection().isRange()) {
@@ -1321,7 +1344,7 @@
return false;
}
-static Position positionBeforeNode(NodeImpl *node)
+Position positionBeforeNode(const NodeImpl *node)
{
return Position(node->parentNode(), node->nodeIndex());
}
@@ -1371,7 +1394,7 @@
return false;
}
-static Position positionAfterNode(NodeImpl *node)
+Position positionAfterNode(const NodeImpl *node)
{
return Position(node->parentNode(), node->nodeIndex() + 1);
}
@@ -3350,11 +3373,10 @@
pos = positionOutsideContainingSpecialElement(pos);
- bool atStart = pos.offset() <= pos.node()->caretMinOffset();
- bool atEnd = pos.offset() >= pos.node()->caretMaxOffset();
- bool atEndOfBlock = isLastVisiblePositionInBlock(VisiblePosition(pos, selection.startAffinity()));
-
- if (atEndOfBlock) {
+ if (isTabSpanTextNode(pos.node())) {
+ insertNodeAtTabSpanPosition(nodeToInsert, pos);
+ setEndingSelection(Position(nodeToInsert->traverseNextNode(), 0), DOWNSTREAM);
+ } else if (isEndOfBlock(VisiblePosition(pos, selection.startAffinity()))) {
LOG(Editing, "input newline case 1");
// Check for a trailing BR. If there isn't one, we'll need to insert an "extra" one.
// This makes the "real" BR we want to insert appear in the rendering without any
@@ -3363,14 +3385,12 @@
if (pos.node()->id() == ID_BR && pos.offset() == 0) {
// Already placed in a trailing BR. Insert "real" BR before it and leave the selection alone.
insertNodeBefore(nodeToInsert, pos.node());
- }
- else {
+ } else {
NodeImpl *next = pos.node()->traverseNextNode();
bool hasTrailingBR = next && next->id() == ID_BR && pos.node()->enclosingBlockFlowElement() == next->enclosingBlockFlowElement();
insertNodeAfterPosition(nodeToInsert, pos);
- if (hasTrailingBR) {
+ if (hasTrailingBR)
setEndingSelection(Selection(Position(next, 0), DOWNSTREAM));
- }
else if (!document()->inStrictMode()) {
// Insert an "extra" BR at the end of the block.
ElementImpl *extraBreakNode = createBreakElement(document());
@@ -3379,22 +3399,20 @@
}
}
}
- else if (atStart) {
+ else if (pos.offset() <= pos.node()->caretMinOffset()) {
LOG(Editing, "input newline case 2");
// Insert node before downstream position, and place caret there as well.
Position endingPosition = pos.downstream(StayInBlock);
insertNodeBeforePosition(nodeToInsert, endingPosition);
setEndingSelection(endingPosition, DOWNSTREAM);
- }
- else if (atEnd) {
+ } else if (pos.offset() >= pos.node()->caretMaxOffset()) {
LOG(Editing, "input newline case 3");
// Insert BR after this node. Place caret in the position that is downstream
// of the current position, reckoned before inserting the BR in between.
Position endingPosition = pos.downstream(StayInBlock);
insertNodeAfterPosition(nodeToInsert, pos);
setEndingSelection(endingPosition, DOWNSTREAM);
- }
- else {
+ } else {
// Split a text node
LOG(Editing, "input newline case 4");
ASSERT(pos.node()->isTextNode());
@@ -3940,25 +3958,8 @@
}
if (isTabSpanTextNode(pos.node())) {
- Position tempPos = pos;
-//#ifndef COALESCE_TAB_SPANS
-#if 0
- NodeImpl *node = pos.node()->parentNode();
- if (pos.offset() > pos.node()->caretMinOffset())
- tempPos = Position(node->parentNode(), node->nodeIndex() + 1);
- else
- tempPos = Position(node->parentNode(), node->nodeIndex());
-#endif
NodeImpl *textNode = document()->createEditingTextNode("");
- NodeImpl *originalTabSpan = tempPos.node()->parent();
- if (tempPos.offset() <= tempPos.node()->caretMinOffset()) {
- insertNodeBefore(textNode, originalTabSpan);
- } else if (tempPos.offset() >= tempPos.node()->caretMaxOffset()) {
- insertNodeAfter(textNode, originalTabSpan);
- } else {
- splitTextNodeContainingElement(static_cast<TextImpl *>(tempPos.node()), tempPos.offset());
- insertNodeBefore(textNode, originalTabSpan);
- }
+ insertNodeAtTabSpanPosition(textNode, pos);
return Position(textNode, 0);
}
@@ -5002,7 +5003,10 @@
if (startAtStartOfBlock && startBlock->inDocument())
startPos = Position(startBlock, 0);
- startPos = positionOutsideContainingSpecialElement(startPos);
+ if (isTabSpanTextNode(startPos.node()))
+ startPos = positionOutsideTabSpan(startPos);
+ else
+ startPos = positionOutsideContainingSpecialElement(startPos);
KHTMLPart *part = document()->part();
if (m_matchStyle) {
@@ -6234,11 +6238,16 @@
return (node && node->parentNode() && isTabSpanNode(node->parentNode()));
}
+NodeImpl *tabSpanNode(const NodeImpl *node)
+{
+ return isTabSpanTextNode(node) ? node->parentNode() : 0;
+}
+
Position positionBeforeTabSpan(const Position& pos)
{
NodeImpl *node = pos.node();
if (isTabSpanTextNode(node))
- node = node->parent();
+ node = tabSpanNode(node);
else if (!isTabSpanNode(node))
return pos;
1.101.8.5 +7 -1 WebCore/khtml/editing/htmlediting.h
Index: htmlediting.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/htmlediting.h,v
retrieving revision 1.101.8.4
retrieving revision 1.101.8.5
diff -u -r1.101.8.4 -r1.101.8.5
--- htmlediting.h 9 Aug 2005 17:48:54 -0000 1.101.8.4
+++ htmlediting.h 11 Nov 2005 05:58:30 -0000 1.101.8.5
@@ -236,6 +236,8 @@
void removeNode(DOM::NodeImpl *removeChild);
void removeNodePreservingChildren(DOM::NodeImpl *node);
void replaceTextInNode(DOM::TextImpl *node, long offset, long count, const DOM::DOMString &replacementText);
+ DOM::Position positionOutsideTabSpan(const DOM::Position& pos);
+ void insertNodeAtTabSpanPosition(DOM::NodeImpl *node, const DOM::Position& pos);
void setNodeAttribute(DOM::ElementImpl *, int attribute, const DOM::DOMString &);
void splitTextNode(DOM::TextImpl *text, long offset);
void splitElement(DOM::ElementImpl *element, DOM::NodeImpl *atChild);
@@ -961,7 +963,10 @@
//------------------------------------------------------------------------------------------
-bool isSpecialElement(const DOM::NodeImpl *n);
+DOM::Position positionBeforeNode(const DOM::NodeImpl *node);
+DOM::Position positionAfterNode(const DOM::NodeImpl *node);
+
+bool isSpecialElement(const DOM::NodeImpl *node);
DOM::ElementImpl *floatRefdElement(DOM::ElementImpl *element);
DOM::ElementImpl *createDefaultParagraphElement(DOM::DocumentImpl *document);
@@ -972,6 +977,7 @@
bool isTabSpanNode(const DOM::NodeImpl *node);
bool isTabSpanTextNode(const DOM::NodeImpl *node);
+DOM::NodeImpl *tabSpanNode(const DOM::NodeImpl *node);
DOM::Position positionBeforeTabSpan(const DOM::Position& pos);
DOM::ElementImpl *createTabSpanElement(DOM::DocumentImpl *document, DOM::NodeImpl *tabTextNode=0);
DOM::ElementImpl *createTabSpanElement(DOM::DocumentImpl *document, QString *tabText);
More information about the webkit-changes
mailing list