Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Unified Diff: Source/WebCore/editing/ApplyStyleCommand.cpp

Issue 10422003: Merge 116669 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1132/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/editing/style/apply-style-join-child-text-nodes-crash-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/editing/ApplyStyleCommand.cpp
===================================================================
--- Source/WebCore/editing/ApplyStyleCommand.cpp (revision 118024)
+++ Source/WebCore/editing/ApplyStyleCommand.cpp (working copy)
@@ -320,12 +320,19 @@
start = startPosition();
end = endPosition();
}
+
+ if (start.isNull() || end.isNull())
+ return;
+
if (end.deprecatedNode()->isTextNode() && start.deprecatedNode()->parentNode() != end.deprecatedNode()->parentNode()) {
joinChildTextNodes(end.deprecatedNode()->parentNode(), start, end);
start = startPosition();
end = endPosition();
}
+ if (start.isNull() || end.isNull())
+ return;
+
// Split the start text nodes if needed to apply style.
if (isValidCaretPositionInTextNode(start)) {
splitTextAtStart(start, end);
@@ -542,6 +549,10 @@
// adjust to the positions we want to use for applying style
Position start = startPosition();
Position end = endPosition();
+
+ if (start.isNull() || end.isNull())
+ return;
+
if (comparePositions(end, start) < 0) {
Position swap = start;
start = end;
@@ -1427,26 +1438,31 @@
Position newStart = start;
Position newEnd = end;
- Node* child = node->firstChild();
- while (child) {
- Node* next = child->nextSibling();
- if (child->isTextNode() && next && next->isTextNode()) {
- Text* childText = toText(child);
- Text* nextText = toText(next);
- if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
- newStart = Position(childText, childText->length() + start.offsetInContainerNode());
- if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == end.containerNode())
- newEnd = Position(childText, childText->length() + end.offsetInContainerNode());
- String textToMove = nextText->data();
- insertTextIntoNode(childText, childText->length(), textToMove);
- removeNode(next);
- // don't move child node pointer. it may want to merge with more text nodes.
- }
- else {
- child = child->nextSibling();
- }
+ Vector<RefPtr<Text> > textNodes;
+ for (Node* curr = node->firstChild(); curr; curr = curr->nextSibling()) {
+ if (!curr->isTextNode())
+ continue;
+
+ textNodes.append(toText(curr));
}
+ for (size_t i = 0; i < textNodes.size(); ++i) {
+ Text* childText = textNodes[i].get();
+ Node* next = childText->nextSibling();
+ if (!next || !next->isTextNode())
+ continue;
+
+ Text* nextText = toText(next);
+ if (start.anchorType() == Position::PositionIsOffsetInAnchor && next == start.containerNode())
+ newStart = Position(childText, childText->length() + start.offsetInContainerNode());
+ if (end.anchorType() == Position::PositionIsOffsetInAnchor && next == end.containerNode())
+ newEnd = Position(childText, childText->length() + end.offsetInContainerNode());
+ String textToMove = nextText->data();
+ insertTextIntoNode(childText, childText->length(), textToMove);
+ removeNode(next);
+ // don't move child node pointer. it may want to merge with more text nodes.
+ }
+
updateStartEnd(newStart, newEnd);
}
« no previous file with comments | « LayoutTests/editing/style/apply-style-join-child-text-nodes-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698