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

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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/scoped/editing-commands.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 Position& start) {
78 // This is a position equivalent to the caret. We use |downstream()| so that
79 // |position| will be in the first node that we need to move (there are a few
80 // exceptions to this, see |doApply|).
81 const Position& position = mostForwardCaretPosition(start);
82
yosin_UTC9 2017/03/21 05:30:44 nit: We don't need to have an extra blank line her
83 return toHTMLQuoteElement(
84 highestEnclosingNodeOfType(position, isMailHTMLBlockquoteElement));
85 }
86
77 void BreakBlockquoteCommand::doApply(EditingState* editingState) { 87 void BreakBlockquoteCommand::doApply(EditingState* editingState) {
78 if (endingSelection().isNone()) 88 if (endingSelection().isNone())
79 return; 89 return;
80 90
91 if (!topBlockquoteOf(endingSelection().start()))
92 return;
93
81 // Delete the current selection. 94 // Delete the current selection.
82 if (endingSelection().isRange()) { 95 if (endingSelection().isRange()) {
83 deleteSelection(editingState, false, false); 96 deleteSelection(editingState, false, false);
84 if (editingState->isAborted()) 97 if (editingState->isAborted())
85 return; 98 return;
86 } 99 }
87 100
88 // This is a scenario that should never happen, but we want to 101 // This is a scenario that should never happen, but we want to
89 // make sure we don't dereference a null pointer below. 102 // make sure we don't dereference a null pointer below.
90 103
91 DCHECK(!endingSelection().isNone()); 104 DCHECK(!endingSelection().isNone());
92 105
93 if (endingSelection().isNone()) 106 if (endingSelection().isNone())
94 return; 107 return;
95 108
96 document().updateStyleAndLayoutIgnorePendingStylesheets(); 109 document().updateStyleAndLayoutIgnorePendingStylesheets();
97 110
98 VisiblePosition visiblePos = endingSelection().visibleStart(); 111 VisiblePosition visiblePos = endingSelection().visibleStart();
99 112
100 // pos is a position equivalent to the caret. We use downstream() so that pos 113 // 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 114 // will be in the first node that we need to move (there are a few exceptions
102 // to this, see below). 115 // to this, see below).
103 Position pos = mostForwardCaretPosition(endingSelection().start()); 116 Position pos = mostForwardCaretPosition(endingSelection().start());
104 117
105 // Find the top-most blockquote from the start. 118 // Find the top-most blockquote from the start.
106 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement( 119 HTMLQuoteElement* const topBlockquote =
107 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement)); 120 topBlockquoteOf(endingSelection().start());
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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/scoped/editing-commands.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698