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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/BreakBlockquoteCommand.cpp

Issue 2750533007: Let insertNewLineInQuotedContent not do anything out of a quote element (Closed)
Patch Set: update Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 VisiblePosition next = nextPositionOf(visiblePosition); 67 VisiblePosition next = nextPositionOf(visiblePosition);
68 return next.isNull() || 68 return next.isNull() ||
69 !next.deepEquivalent().anchorNode()->isDescendantOf(node); 69 !next.deepEquivalent().anchorNode()->isDescendantOf(node);
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 BreakBlockquoteCommand::BreakBlockquoteCommand(Document& document) 74 BreakBlockquoteCommand::BreakBlockquoteCommand(Document& document)
75 : CompositeEditCommand(document) {} 75 : CompositeEditCommand(document) {}
76 76
77 static HTMLQuoteElement* topBlockquoteOf(const VisibleSelection& selection) {
yosin_UTC9 2017/03/17 09:27:02 Please use |Position| as parameter to reduce usage
yoichio 2017/03/21 03:48:07 Done.
78 // pos is a position equivalent to the caret. We use downstream() so that pos
yosin_UTC9 2017/03/17 09:27:02 nit: s/pos/|pos|/ nit: s/downstream()/|downstream(
yoichio 2017/03/21 03:48:07 Done.
79 // will be in the first node that we need to move (there are a few exceptions
80 // to this, see below).
81 const Position pos = mostForwardCaretPosition(selection.start());
yosin_UTC9 2017/03/17 09:27:02 nit: s/pos/position/ Blink doesn't want to use abb
yoichio 2017/03/21 03:48:07 Done.
82
83 // Find the top-most blockquote from the start.
yosin_UTC9 2017/03/17 09:27:02 not need to have a comment. The statement explains
yoichio 2017/03/21 03:48:07 Done.
84 return toHTMLQuoteElement(
85 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement));
86 }
87
77 void BreakBlockquoteCommand::doApply(EditingState* editingState) { 88 void BreakBlockquoteCommand::doApply(EditingState* editingState) {
78 if (endingSelection().isNone()) 89 if (endingSelection().isNone())
79 return; 90 return;
80 91
92 if (!topBlockquoteOf(endingSelection()))
93 return;
94
81 // Delete the current selection. 95 // Delete the current selection.
82 if (endingSelection().isRange()) { 96 if (endingSelection().isRange()) {
83 deleteSelection(editingState, false, false); 97 deleteSelection(editingState, false, false);
84 if (editingState->isAborted()) 98 if (editingState->isAborted())
85 return; 99 return;
86 } 100 }
87 101
88 // This is a scenario that should never happen, but we want to 102 // This is a scenario that should never happen, but we want to
89 // make sure we don't dereference a null pointer below. 103 // make sure we don't dereference a null pointer below.
90 104
91 DCHECK(!endingSelection().isNone()); 105 DCHECK(!endingSelection().isNone());
92 106
93 if (endingSelection().isNone()) 107 if (endingSelection().isNone())
94 return; 108 return;
95 109
96 document().updateStyleAndLayoutIgnorePendingStylesheets(); 110 document().updateStyleAndLayoutIgnorePendingStylesheets();
97 111
98 VisiblePosition visiblePos = endingSelection().visibleStart(); 112 VisiblePosition visiblePos = endingSelection().visibleStart();
99 113
100 // pos is a position equivalent to the caret. We use downstream() so that pos 114 // pos is a position equivalent to the caret. We use downstream() so that pos
101 // will be in the first node that we need to move (there are a few exceptions 115 // will be in the first node that we need to move (there are a few exceptions
102 // to this, see below). 116 // to this, see below).
103 Position pos = mostForwardCaretPosition(endingSelection().start()); 117 Position pos = mostForwardCaretPosition(endingSelection().start());
104 118
105 // Find the top-most blockquote from the start. 119 // Find the top-most blockquote from the start.
106 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement( 120 HTMLQuoteElement* const topBlockquote = topBlockquoteOf(endingSelection());
yosin_UTC9 2017/03/17 09:27:02 Can we use result of |topBlockquoteOf()| at L92 he
yoichio 2017/03/21 03:48:07 No, deletingSelection on L97 changes the result.
107 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement));
108 if (!topBlockquote || !topBlockquote->parentNode()) 121 if (!topBlockquote || !topBlockquote->parentNode())
109 return; 122 return;
110 123
111 HTMLBRElement* breakElement = HTMLBRElement::create(document()); 124 HTMLBRElement* breakElement = HTMLBRElement::create(document());
112 125
113 bool isLastVisPosInNode = 126 bool isLastVisPosInNode =
114 isLastVisiblePositionInNode(visiblePos, topBlockquote); 127 isLastVisiblePositionInNode(visiblePos, topBlockquote);
115 128
116 // If the position is at the beginning of the top quoted content, we don't 129 // If the position is at the beginning of the top quoted content, we don't
117 // need to break the quote. Instead, insert the break before the blockquote, 130 // need to break the quote. Instead, insert the break before the blockquote,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 281
269 // Put the selection right before the break. 282 // Put the selection right before the break.
270 setEndingSelection(SelectionInDOMTree::Builder() 283 setEndingSelection(SelectionInDOMTree::Builder()
271 .collapse(Position::beforeNode(breakElement)) 284 .collapse(Position::beforeNode(breakElement))
272 .setIsDirectional(endingSelection().isDirectional()) 285 .setIsDirectional(endingSelection().isDirectional())
273 .build()); 286 .build());
274 rebalanceWhitespace(); 287 rebalanceWhitespace();
275 } 288 }
276 289
277 } // namespace blink 290 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698