[webkit-changes] cvs commit: WebCore/khtml/editing
replace_selection_command.cpp replace_selection_command.h
David
harrison at opensource.apple.com
Mon Dec 12 17:29:00 PST 2005
harrison 05/12/12 17:28:59
Modified: . ChangeLog
khtml/editing replace_selection_command.cpp
replace_selection_command.h
Log:
Reviewed by Justin.
<rdar://problem/4027704> Paste of HTML list content can break list structure by dropping empty list items
Fixed by having ReplaceSelectionCommand remove empty nodes just
from the ancestors of the node(s) moved by mergeStart, rather
than scanning the whole fragment.
Layout tests added:
editing/pasteboard/paste-table-001.html
editing/pasteboard/paste-list-001.html
* khtml/editing/replace_selection_command.cpp:
(khtml::ReplaceSelectionCommand::isProbablyTableStructureNode):
(khtml::ReplaceSelectionCommand::pruneEmptyNodes):
Removed no longer needed functions.
(khtml::ReplaceSelectionCommand::doApply):
Remove ancestor nodes emptied by mergeStart.
Do that instead of calling pruneEmptyNodes().
* khtml/editing/replace_selection_command.h:
(khtml::ReplacementFragment::desiredStyles):
Removed pruneEmptyNodes().
Revision Changes Path
1.517 +27 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.516
retrieving revision 1.517
diff -u -r1.516 -r1.517
--- ChangeLog 12 Dec 2005 22:22:18 -0000 1.516
+++ ChangeLog 13 Dec 2005 01:28:50 -0000 1.517
@@ -1,3 +1,30 @@
+2005-12-12 David Harrison <harrison at apple.com>
+
+ Reviewed by Justin.
+
+ <rdar://problem/4027704> Paste of HTML list content can break list structure by dropping empty list items
+
+ Fixed by having ReplaceSelectionCommand remove empty nodes just
+ from the ancestors of the node(s) moved by mergeStart, rather
+ than scanning the whole fragment.
+
+ Layout tests added:
+ editing/pasteboard/paste-table-001.html
+ editing/pasteboard/paste-list-001.html
+
+ * khtml/editing/replace_selection_command.cpp:
+ (khtml::ReplaceSelectionCommand::isProbablyTableStructureNode):
+ (khtml::ReplaceSelectionCommand::pruneEmptyNodes):
+ Removed no longer needed functions.
+
+ (khtml::ReplaceSelectionCommand::doApply):
+ Remove ancestor nodes emptied by mergeStart.
+ Do that instead of calling pruneEmptyNodes().
+
+ * khtml/editing/replace_selection_command.h:
+ (khtml::ReplacementFragment::desiredStyles):
+ Removed pruneEmptyNodes().
+
2005-12-12 Timothy Hatcher <timothy at apple.com>
Reviewed by Dave Hyatt.
1.20 +8 -34 WebCore/khtml/editing/replace_selection_command.cpp
Index: replace_selection_command.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/replace_selection_command.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- replace_selection_command.cpp 21 Nov 2005 01:20:05 -0000 1.19
+++ replace_selection_command.cpp 13 Dec 2005 01:28:58 -0000 1.20
@@ -191,36 +191,6 @@
return node;
}
-static bool isProbablyTableStructureNode(const NodeImpl *node)
-{
- if (!node)
- return false;
-
- return (node->hasTagName(tableTag) || node->hasTagName(tbodyTag) || node->hasTagName(tdTag) ||
- node->hasTagName(tfootTag) || node->hasTagName(theadTag) || node->hasTagName(trTag));
-}
-
-void ReplacementFragment::pruneEmptyNodes()
-{
- bool run = true;
- while (run) {
- run = false;
- NodeImpl *node = m_fragment->firstChild();
- while (node) {
- if ((node->isTextNode() && static_cast<TextImpl *>(node)->length() == 0) ||
- (isProbablyBlock(node) && !isProbablyTableStructureNode(node) && node->childNodeCount() == 0)) {
- NodeImpl *next = node->traverseNextSibling();
- removeNode(node);
- node = next;
- run = true;
- }
- else {
- node = node->traverseNextNode();
- }
- }
- }
-}
-
bool ReplacementFragment::isInterchangeNewlineNode(const NodeImpl *node)
{
static DOMString interchangeNewlineClassString(AppleInterchangeNewline);
@@ -778,6 +748,7 @@
if (mergeStart && !isFirstVisiblePositionInSpecialElementInFragment(Position(m_fragment.mergeStartNode(), 0))) {
NodeImpl *refNode = m_fragment.mergeStartNode();
if (refNode) {
+ NodeImpl *parent = refNode->parentNode();
NodeImpl *node = refNode->nextSibling();
insertNodeAtAndUpdateNodesInserted(refNode, startPos.node(), startPos.offset());
while (node && !isProbablyBlock(node)) {
@@ -786,6 +757,13 @@
refNode = node;
node = next;
}
+
+ // remove any ancestors we emptied, except the root itself which cannot be removed
+ while (parent && parent->parentNode() && parent->childNodeCount() == 0) {
+ NodeImpl *nextParent = parent->parentNode();
+ removeNode(parent);
+ parent = nextParent;
+ }
}
// update insertion point to be at the end of the last block inserted
@@ -794,10 +772,6 @@
insertionPos = Position(m_lastNodeInserted, m_lastNodeInserted->caretMaxOffset());
}
}
-
- // prune empty nodes from fragment
- // NOTE: why was this not done earlier, before the mergeStart?
- m_fragment.pruneEmptyNodes();
// step 2 : merge everything remaining in the fragment
if (m_fragment.firstChild()) {
1.3 +0 -2 WebCore/khtml/editing/replace_selection_command.h
Index: replace_selection_command.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/replace_selection_command.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- replace_selection_command.h 16 Sep 2005 22:42:07 -0000 1.2
+++ replace_selection_command.h 13 Dec 2005 01:28:59 -0000 1.3
@@ -68,8 +68,6 @@
DOM::NodeImpl *mergeStartNode() const;
const QValueList<NodeDesiredStyle> &desiredStyles() { return m_styles; }
-
- void pruneEmptyNodes();
EFragmentType type() const { return m_type; }
bool isEmpty() const { return m_type == EmptyFragment; }
More information about the webkit-changes
mailing list