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

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 return toHTMLQuoteElement(
83 highestEnclosingNodeOfType(position, isMailHTMLBlockquoteElement));
84 }
85
77 void BreakBlockquoteCommand::doApply(EditingState* editingState) { 86 void BreakBlockquoteCommand::doApply(EditingState* editingState) {
78 if (endingSelection().isNone()) 87 if (endingSelection().isNone())
79 return; 88 return;
80 89
90 if (!topBlockquoteOf(endingSelection().start()))
91 return;
92
81 // Delete the current selection. 93 // Delete the current selection.
82 if (endingSelection().isRange()) { 94 if (endingSelection().isRange()) {
83 deleteSelection(editingState, false, false); 95 deleteSelection(editingState, false, false);
84 if (editingState->isAborted()) 96 if (editingState->isAborted())
85 return; 97 return;
86 } 98 }
87 99
88 // This is a scenario that should never happen, but we want to 100 // This is a scenario that should never happen, but we want to
89 // make sure we don't dereference a null pointer below. 101 // make sure we don't dereference a null pointer below.
90 102
91 DCHECK(!endingSelection().isNone()); 103 DCHECK(!endingSelection().isNone());
92 104
93 if (endingSelection().isNone()) 105 if (endingSelection().isNone())
94 return; 106 return;
95 107
96 document().updateStyleAndLayoutIgnorePendingStylesheets(); 108 document().updateStyleAndLayoutIgnorePendingStylesheets();
97 109
98 VisiblePosition visiblePos = endingSelection().visibleStart(); 110 VisiblePosition visiblePos = endingSelection().visibleStart();
99 111
100 // pos is a position equivalent to the caret. We use downstream() so that pos 112 // 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 113 // will be in the first node that we need to move (there are a few exceptions
102 // to this, see below). 114 // to this, see below).
103 Position pos = mostForwardCaretPosition(endingSelection().start()); 115 Position pos = mostForwardCaretPosition(endingSelection().start());
104 116
105 // Find the top-most blockquote from the start. 117 // Find the top-most blockquote from the start.
106 HTMLQuoteElement* topBlockquote = toHTMLQuoteElement( 118 HTMLQuoteElement* const topBlockquote =
107 highestEnclosingNodeOfType(pos, isMailHTMLBlockquoteElement)); 119 topBlockquoteOf(endingSelection().start());
108 if (!topBlockquote || !topBlockquote->parentNode()) 120 if (!topBlockquote || !topBlockquote->parentNode())
109 return; 121 return;
110 122
111 HTMLBRElement* breakElement = HTMLBRElement::create(document()); 123 HTMLBRElement* breakElement = HTMLBRElement::create(document());
112 124
113 bool isLastVisPosInNode = 125 bool isLastVisPosInNode =
114 isLastVisiblePositionInNode(visiblePos, topBlockquote); 126 isLastVisiblePositionInNode(visiblePos, topBlockquote);
115 127
116 // If the position is at the beginning of the top quoted content, we don't 128 // 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, 129 // 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 280
269 // Put the selection right before the break. 281 // Put the selection right before the break.
270 setEndingSelection(SelectionInDOMTree::Builder() 282 setEndingSelection(SelectionInDOMTree::Builder()
271 .collapse(Position::beforeNode(breakElement)) 283 .collapse(Position::beforeNode(breakElement))
272 .setIsDirectional(endingSelection().isDirectional()) 284 .setIsDirectional(endingSelection().isDirectional())
273 .build()); 285 .build());
274 rebalanceWhitespace(); 286 rebalanceWhitespace();
275 } 287 }
276 288
277 } // namespace blink 289 } // 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