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

Unified Diff: third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp

Issue 2397963002: Reflow comments in //third_party/WebKit/Source/core/editing/commands (Closed)
Patch Set: . Created 4 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
Index: third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp b/third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp
index 90f02994e35c22396d9cb7ab6143075eae3d2324..efb288167a272d9dbd3ffd46abafc98976fe867f 100644
--- a/third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp
@@ -43,14 +43,14 @@ namespace blink {
using namespace HTMLNames;
-// When inserting a new line, we want to avoid nesting empty divs if we can. Otherwise, when
-// pasting, it's easy to have each new line be a div deeper than the previous. E.g., in the case
-// below, we want to insert at ^ instead of |.
+// When inserting a new line, we want to avoid nesting empty divs if we can.
+// Otherwise, when pasting, it's easy to have each new line be a div deeper than
+// the previous. E.g., in the case below, we want to insert at ^ instead of |.
// <div>foo<div>bar</div>|</div>^
static Element* highestVisuallyEquivalentDivBelowRoot(Element* startBlock) {
Element* curBlock = startBlock;
- // We don't want to return a root node (if it happens to be a div, e.g., in a document fragment) because there are no
- // siblings for us to append to.
+ // We don't want to return a root node (if it happens to be a div, e.g., in a
+ // document fragment) because there are no siblings for us to append to.
while (!curBlock->nextSibling() &&
isHTMLDivElement(*curBlock->parentElement()) &&
curBlock->parentElement()->parentElement()) {
@@ -75,9 +75,10 @@ bool InsertParagraphSeparatorCommand::preservesTypingStyle() const {
void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(
const Position& pos) {
- // It is only important to set a style to apply later if we're at the boundaries of
- // a paragraph. Otherwise, content that is moved as part of the work of the command
- // will lend their styles to the new paragraph without any extra work needed.
+ // It is only important to set a style to apply later if we're at the
+ // boundaries of a paragraph. Otherwise, content that is moved as part of the
+ // work of the command will lend their styles to the new paragraph without any
+ // extra work needed.
VisiblePosition visiblePos =
createVisiblePositionDeprecated(pos, VP_DEFAULT_AFFINITY);
if (!isStartOfParagraphDeprecated(visiblePos) &&
@@ -92,8 +93,8 @@ void InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion(
void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(
Element* originalEnclosingBlock,
EditingState* editingState) {
- // Not only do we break out of header tags, but we also do not preserve the typing style,
- // in order to match other browsers.
+ // Not only do we break out of header tags, but we also do not preserve the
+ // typing style, in order to match other browsers.
if (originalEnclosingBlock->hasTagName(h1Tag) ||
originalEnclosingBlock->hasTagName(h2Tag) ||
originalEnclosingBlock->hasTagName(h3Tag) ||
@@ -131,7 +132,8 @@ void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(
HeapVector<Member<Element>>& ancestors) {
ancestors.clear();
- // Build up list of ancestors elements between the insertion node and the outer block.
+ // Build up list of ancestors elements between the insertion node and the
+ // outer block.
if (insertionNode != outerBlock) {
for (Element* n = insertionNode->parentElement(); n && n != outerBlock;
n = n->parentElement())
@@ -147,7 +149,8 @@ Element* InsertParagraphSeparatorCommand::cloneHierarchyUnderNewBlock(
Element* parent = blockToInsert;
for (size_t i = ancestors.size(); i != 0; --i) {
Element* child = ancestors[i - 1]->cloneElementWithoutChildren();
- // It should always be okay to remove id from the cloned elements, since the originals are not deleted.
+ // It should always be okay to remove id from the cloned elements, since the
+ // originals are not deleted.
child->removeAttribute(idAttr);
appendNode(child, parent, editingState);
if (editingState->isAborted())
@@ -176,7 +179,8 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
affinity = endingSelection().affinity();
}
- // FIXME: The parentAnchoredEquivalent conversion needs to be moved into enclosingBlock.
+ // FIXME: The parentAnchoredEquivalent conversion needs to be moved into
+ // enclosingBlock.
Element* startBlock = enclosingBlock(
insertionPosition.parentAnchoredEquivalent().computeContainerNode());
Node* listChildNode = enclosingListChild(
@@ -188,7 +192,9 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
createVisiblePositionDeprecated(insertionPosition).deepEquivalent();
if (!startBlock || !startBlock->nonShadowBoundaryParentNode() ||
isTableCell(startBlock) || isHTMLFormElement(*startBlock)
- // FIXME: If the node is hidden, we don't have a canonical position so we will do the wrong thing for tables and <hr>. https://bugs.webkit.org/show_bug.cgi?id=40342
+ // FIXME: If the node is hidden, we don't have a canonical position so we
+ // will do the wrong thing for tables and <hr>.
+ // https://bugs.webkit.org/show_bug.cgi?id=40342
|| (!canonicalPos.isNull() &&
isDisplayInsideTable(canonicalPos.anchorNode())) ||
(!canonicalPos.isNull() && isHTMLHRElement(*canonicalPos.anchorNode()))) {
@@ -263,8 +269,10 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
if (editingState->isAborted())
return;
} else {
- // We can get here if we pasted a copied portion of a blockquote with a newline at the end and are trying to paste it
- // into an unquoted area. We then don't want the newline within the blockquote or else it will also be quoted.
+ // We can get here if we pasted a copied portion of a blockquote with a
+ // newline at the end and are trying to paste it into an unquoted area. We
+ // then don't want the newline within the blockquote or else it will also
+ // be quoted.
if (m_pasteBlockquoteIntoUnquotedArea) {
if (HTMLQuoteElement* highestBlockquote =
toHTMLQuoteElement(highestEnclosingNodeOfType(
@@ -279,8 +287,9 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
return;
insertNodeAfter(listChildToInsert, listChild, editingState);
} else {
- // Most of the time we want to stay at the nesting level of the startBlock (e.g., when nesting within lists). However,
- // for div nodes, this can result in nested div tags that are hard to break out of.
+ // Most of the time we want to stay at the nesting level of the
+ // startBlock (e.g., when nesting within lists). However, for div nodes,
+ // this can result in nested div tags that are hard to break out of.
Element* siblingElement = startBlock;
if (isHTMLDivElement(*blockToInsert))
siblingElement = highestVisuallyEquivalentDivBelowRoot(startBlock);
@@ -312,8 +321,9 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
}
//---------------------------------------------------------------------
- // Handle case when position is in the first visible position in its block, and
- // similar case where previous position is in another, presumeably nested, block.
+ // Handle case when position is in the first visible position in its block,
+ // and similar case where previous position is in another, presumeably nested,
+ // block.
if (isFirstInBlock ||
!inSameBlock(visiblePos, previousPositionOf(visiblePos))) {
Node* refNode = nullptr;
@@ -332,7 +342,8 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
refNode = startBlock;
}
} else if (isFirstInBlock && nestNewBlock) {
- // startBlock should always have children, otherwise isLastInBlock would be true and it's handled above.
+ // startBlock should always have children, otherwise isLastInBlock would
+ // be true and it's handled above.
DCHECK(startBlock->hasChildren());
refNode = startBlock->firstChild();
} else if (insertionPosition.anchorNode() == startBlock && nestNewBlock) {
@@ -404,14 +415,16 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
// style of the upstream position.
insertionPosition = mostForwardCaretPosition(insertionPosition);
- // At this point, the insertionPosition's node could be a container, and we want to make sure we include
- // all of the correct nodes when building the ancestor list. So this needs to be the deepest representation of the position
- // before we walk the DOM tree.
+ // At this point, the insertionPosition's node could be a container, and we
+ // want to make sure we include all of the correct nodes when building the
+ // ancestor list. So this needs to be the deepest representation of the
+ // position before we walk the DOM tree.
insertionPosition = positionOutsideTabSpan(
createVisiblePositionDeprecated(insertionPosition).deepEquivalent());
- // If the returned position lies either at the end or at the start of an element that is ignored by editing
- // we should move to its upstream or downstream position.
+ // If the returned position lies either at the end or at the start of an
+ // element that is ignored by editing we should move to its upstream or
+ // downstream position.
if (editingIgnoresContent(insertionPosition.anchorNode())) {
if (insertionPosition.atLastEditingPositionForNode())
insertionPosition = mostForwardCaretPosition(insertionPosition);
@@ -420,11 +433,13 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
}
// Make sure we do not cause a rendered space to become unrendered.
- // FIXME: We need the affinity for pos, but mostForwardCaretPosition does not give it
+ // FIXME: We need the affinity for pos, but mostForwardCaretPosition does not
+ // give it
Position leadingWhitespace =
leadingWhitespacePosition(insertionPosition, VP_DEFAULT_AFFINITY);
- // FIXME: leadingWhitespacePosition is returning the position before preserved newlines for positions
- // after the preserved newline, causing the newline to be turned into a nbsp.
+ // FIXME: leadingWhitespacePosition is returning the position before preserved
+ // newlines for positions after the preserved newline, causing the newline to
+ // be turned into a nbsp.
if (leadingWhitespace.isNotNull() &&
leadingWhitespace.anchorNode()->isTextNode()) {
Text* textNode = toText(leadingWhitespace.anchorNode());
@@ -472,9 +487,10 @@ void InsertParagraphSeparatorCommand::doApply(EditingState* editingState) {
document().updateStyleAndLayoutIgnorePendingStylesheets();
- // If the paragraph separator was inserted at the end of a paragraph, an empty line must be
- // created. All of the nodes, starting at visiblePos, are about to be added to the new paragraph
- // element. If the first node to be inserted won't be one that will hold an empty line open, add a br.
+ // If the paragraph separator was inserted at the end of a paragraph, an empty
+ // line must be created. All of the nodes, starting at visiblePos, are about
+ // to be added to the new paragraph element. If the first node to be inserted
+ // won't be one that will hold an empty line open, add a br.
if (isEndOfParagraphDeprecated(visiblePos) &&
!lineBreakExistsAtVisiblePosition(visiblePos)) {
appendNode(HTMLBRElement::create(document()), blockToInsert, editingState);

Powered by Google App Engine
This is Rietveld 408576698