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

Side by Side Diff: Source/core/editing/commands/InsertParagraphSeparatorCommand.cpp

Issue 1294543005: Move execCommand related files in core/editing/ related files into core/editing/commands/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-17T17:57:33 Created 5 years, 4 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, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2005, 2006 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/editing/InsertParagraphSeparatorCommand.h" 27 #include "core/editing/commands/InsertParagraphSeparatorCommand.h"
28 28
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/NodeTraversal.h" 31 #include "core/dom/NodeTraversal.h"
32 #include "core/dom/Text.h" 32 #include "core/dom/Text.h"
33 #include "core/editing/EditingStyle.h" 33 #include "core/editing/EditingStyle.h"
34 #include "core/editing/EditingUtilities.h" 34 #include "core/editing/EditingUtilities.h"
35 #include "core/editing/InsertLineBreakCommand.h"
36 #include "core/editing/VisibleUnits.h" 35 #include "core/editing/VisibleUnits.h"
36 #include "core/editing/commands/InsertLineBreakCommand.h"
37 #include "core/html/HTMLBRElement.h" 37 #include "core/html/HTMLBRElement.h"
38 #include "core/html/HTMLElement.h" 38 #include "core/html/HTMLElement.h"
39 #include "core/html/HTMLQuoteElement.h" 39 #include "core/html/HTMLQuoteElement.h"
40 #include "core/layout/LayoutObject.h" 40 #include "core/layout/LayoutObject.h"
41 #include "core/layout/LayoutText.h" 41 #include "core/layout/LayoutText.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 using namespace HTMLNames; 45 using namespace HTMLNames;
46 46
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 ASSERT(pos.isNotNull()); 85 ASSERT(pos.isNotNull());
86 m_style = EditingStyle::create(pos); 86 m_style = EditingStyle::create(pos);
87 m_style->mergeTypingStyle(pos.document()); 87 m_style->mergeTypingStyle(pos.document());
88 } 88 }
89 89
90 void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Element* original EnclosingBlock) 90 void InsertParagraphSeparatorCommand::applyStyleAfterInsertion(Element* original EnclosingBlock)
91 { 91 {
92 // Not only do we break out of header tags, but we also do not preserve the typing style, 92 // Not only do we break out of header tags, but we also do not preserve the typing style,
93 // in order to match other browsers. 93 // in order to match other browsers.
94 if (originalEnclosingBlock->hasTagName(h1Tag) || 94 if (originalEnclosingBlock->hasTagName(h1Tag)
95 originalEnclosingBlock->hasTagName(h2Tag) || 95 || originalEnclosingBlock->hasTagName(h2Tag)
96 originalEnclosingBlock->hasTagName(h3Tag) || 96 || originalEnclosingBlock->hasTagName(h3Tag)
97 originalEnclosingBlock->hasTagName(h4Tag) || 97 || originalEnclosingBlock->hasTagName(h4Tag)
98 originalEnclosingBlock->hasTagName(h5Tag)) 98 || originalEnclosingBlock->hasTagName(h5Tag))
99 return; 99 return;
100 100
101 if (!m_style) 101 if (!m_style)
102 return; 102 return;
103 103
104 m_style->prepareToApplyAt(endingSelection().start()); 104 m_style->prepareToApplyAt(endingSelection().start());
105 if (!m_style->isEmpty()) 105 if (!m_style->isEmpty())
106 applyStyle(m_style.get()); 106 applyStyle(m_style.get());
107 } 107 }
108 108
109 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element* enclosingBlock) const 109 bool InsertParagraphSeparatorCommand::shouldUseDefaultParagraphElement(Element* enclosingBlock) const
110 { 110 {
111 if (m_mustUseDefaultParagraphElement) 111 if (m_mustUseDefaultParagraphElement)
112 return true; 112 return true;
113 113
114 // Assumes that if there was a range selection, it was already deleted. 114 // Assumes that if there was a range selection, it was already deleted.
115 if (!isEndOfBlock(endingSelection().visibleStart())) 115 if (!isEndOfBlock(endingSelection().visibleStart()))
116 return false; 116 return false;
117 117
118 return enclosingBlock->hasTagName(h1Tag) || 118 return enclosingBlock->hasTagName(h1Tag)
119 enclosingBlock->hasTagName(h2Tag) || 119 || enclosingBlock->hasTagName(h2Tag)
120 enclosingBlock->hasTagName(h3Tag) || 120 || enclosingBlock->hasTagName(h3Tag)
121 enclosingBlock->hasTagName(h4Tag) || 121 || enclosingBlock->hasTagName(h4Tag)
122 enclosingBlock->hasTagName(h5Tag); 122 || enclosingBlock->hasTagName(h5Tag);
123 } 123 }
124 124
125 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert ionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element>>& anc estors) 125 void InsertParagraphSeparatorCommand::getAncestorsInsideBlock(const Node* insert ionNode, Element* outerBlock, WillBeHeapVector<RefPtrWillBeMember<Element>>& anc estors)
126 { 126 {
127 ancestors.clear(); 127 ancestors.clear();
128 128
129 // Build up list of ancestors elements between the insertion node and the ou ter block. 129 // Build up list of ancestors elements between the insertion node and the ou ter block.
130 if (insertionNode != outerBlock) { 130 if (insertionNode != outerBlock) {
131 for (Element* n = insertionNode->parentElement(); n && n != outerBlock; n = n->parentElement()) 131 for (Element* n = insertionNode->parentElement(); n && n != outerBlock; n = n->parentElement())
132 ancestors.append(n); 132 ancestors.append(n);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 // If the paragraph separator was inserted at the end of a paragraph, an emp ty line must be 388 // If the paragraph separator was inserted at the end of a paragraph, an emp ty line must be
389 // created. All of the nodes, starting at visiblePos, are about to be added to the new paragraph 389 // created. All of the nodes, starting at visiblePos, are about to be added to the new paragraph
390 // element. If the first node to be inserted won't be one that will hold an empty line open, add a br. 390 // element. If the first node to be inserted won't be one that will hold an empty line open, add a br.
391 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl ePos)) 391 if (isEndOfParagraph(visiblePos) && !lineBreakExistsAtVisiblePosition(visibl ePos))
392 appendNode(createBreakElement(document()).get(), blockToInsert.get()); 392 appendNode(createBreakElement(document()).get(), blockToInsert.get());
393 393
394 // Move the start node and the siblings of the start node. 394 // Move the start node and the siblings of the start node.
395 if (VisiblePosition(insertionPosition).deepEquivalent() != VisiblePosition(p ositionBeforeNode(blockToInsert.get())).deepEquivalent()) { 395 if (VisiblePosition(insertionPosition).deepEquivalent() != VisiblePosition(p ositionBeforeNode(blockToInsert.get())).deepEquivalent()) {
396 Node* n; 396 Node* n;
397 if (insertionPosition.computeContainerNode() == startBlock) 397 if (insertionPosition.computeContainerNode() == startBlock) {
398 n = insertionPosition.computeNodeAfterPosition(); 398 n = insertionPosition.computeNodeAfterPosition();
399 else { 399 } else {
400 Node* splitTo = insertionPosition.computeContainerNode(); 400 Node* splitTo = insertionPosition.computeContainerNode();
401 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode () >= caretMaxOffset(splitTo)) 401 if (splitTo->isTextNode() && insertionPosition.offsetInContainerNode () >= caretMaxOffset(splitTo))
402 splitTo = NodeTraversal::next(*splitTo, startBlock.get()); 402 splitTo = NodeTraversal::next(*splitTo, startBlock.get());
403 ASSERT(splitTo); 403 ASSERT(splitTo);
404 splitTreeToNode(splitTo, startBlock.get()); 404 splitTreeToNode(splitTo, startBlock.get());
405 405
406 for (n = startBlock->firstChild(); n; n = n->nextSibling()) { 406 for (n = startBlock->firstChild(); n; n = n->nextSibling()) {
407 VisiblePosition beforeNodePosition(positionBeforeNode(n)); 407 VisiblePosition beforeNodePosition(positionBeforeNode(n));
408 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi tion(insertionPosition), beforeNodePosition) <= 0) 408 if (!beforeNodePosition.isNull() && comparePositions(VisiblePosi tion(insertionPosition), beforeNodePosition) <= 0)
409 break; 409 break;
(...skipping 20 matching lines...) Expand all
430 } 430 }
431 431
432 DEFINE_TRACE(InsertParagraphSeparatorCommand) 432 DEFINE_TRACE(InsertParagraphSeparatorCommand)
433 { 433 {
434 visitor->trace(m_style); 434 visitor->trace(m_style);
435 CompositeEditCommand::trace(visitor); 435 CompositeEditCommand::trace(visitor);
436 } 436 }
437 437
438 438
439 } // namespace blink 439 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698