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

Unified Diff: Source/core/editing/ReplaceSelectionCommand.cpp

Issue 54803003: Have Node::lastDescendant() return a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Kill firstDescendant()! Created 7 years, 2 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 | « Source/core/editing/ReplaceSelectionCommand.h ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/ReplaceSelectionCommand.cpp
diff --git a/Source/core/editing/ReplaceSelectionCommand.cpp b/Source/core/editing/ReplaceSelectionCommand.cpp
index 92e69b6ba68d7ad5181e80a0085f619a30fbcb57..a77d2b07c3bfd0ed2fe63d031c3149190abcabaa 100644
--- a/Source/core/editing/ReplaceSelectionCommand.cpp
+++ b/Source/core/editing/ReplaceSelectionCommand.cpp
@@ -658,27 +658,27 @@ void ReplaceSelectionCommand::moveNodeOutOfAncestor(PassRefPtr<Node> prpNode, Pa
removeNode(ancestor.release());
}
-static inline bool nodeHasVisibleRenderText(Text* text)
+static inline bool nodeHasVisibleRenderText(Text& text)
{
- return text->renderer() && toRenderText(text->renderer())->renderedTextLength() > 0;
+ return text.renderer() && toRenderText(text.renderer())->renderedTextLength() > 0;
}
void ReplaceSelectionCommand::removeUnrenderedTextNodesAtEnds(InsertedNodes& insertedNodes)
{
document().updateLayoutIgnorePendingStylesheets();
- Node* lastLeafInserted = insertedNodes.lastLeafInserted();
- if (lastLeafInserted && lastLeafInserted->isTextNode() && !nodeHasVisibleRenderText(toText(lastLeafInserted))
- && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), selectTag)
- && !enclosingNodeWithTag(firstPositionInOrBeforeNode(lastLeafInserted), scriptTag)) {
- insertedNodes.willRemoveNode(lastLeafInserted);
- removeNode(lastLeafInserted);
+ Node& lastLeafInserted = insertedNodes.lastLeafInserted();
+ if (lastLeafInserted.isTextNode() && !nodeHasVisibleRenderText(toText(lastLeafInserted))
+ && !enclosingNodeWithTag(firstPositionInOrBeforeNode(&lastLeafInserted), selectTag)
+ && !enclosingNodeWithTag(firstPositionInOrBeforeNode(&lastLeafInserted), scriptTag)) {
+ insertedNodes.willRemoveNode(&lastLeafInserted);
+ removeNode(&lastLeafInserted);
}
// We don't have to make sure that firstNodeInserted isn't inside a select or script element, because
// it is a top level node in the fragment and the user can't insert into those elements.
Node* firstNodeInserted = insertedNodes.firstNodeInserted();
- if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleRenderText(toText(firstNodeInserted))) {
+ if (firstNodeInserted && firstNodeInserted->isTextNode() && !nodeHasVisibleRenderText(toText(*firstNodeInserted))) {
insertedNodes.willRemoveNode(firstNodeInserted);
removeNode(firstNodeInserted);
}
@@ -1137,7 +1137,7 @@ void ReplaceSelectionCommand::doApply()
// Setup m_startOfInsertedContent and m_endOfInsertedContent. This should be the last two lines of code that access insertedNodes.
m_startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted());
- m_endOfInsertedContent = lastPositionInOrAfterNode(insertedNodes.lastLeafInserted());
+ m_endOfInsertedContent = lastPositionInOrAfterNode(&insertedNodes.lastLeafInserted());
// Determine whether or not we should merge the end of inserted content with what's after it before we do
// the start merge so that the start merge doesn't effect our decision.
@@ -1453,7 +1453,7 @@ void ReplaceSelectionCommand::updateNodesInserted(Node *node)
if (m_startOfInsertedContent.isNull())
m_startOfInsertedContent = firstPositionInOrBeforeNode(node);
- m_endOfInsertedContent = lastPositionInOrAfterNode(node->lastDescendant());
+ m_endOfInsertedContent = lastPositionInOrAfterNode(&node->lastDescendant());
}
// During simple pastes, where we're just pasting a text node into a run of text, we insert the text node
« no previous file with comments | « Source/core/editing/ReplaceSelectionCommand.h ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698