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

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

Issue 2171493003: [Editing][DOM][CodeHealth] Make Node::hasEditableStyle global functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 Element* shadowAncestorElement; 166 Element* shadowAncestorElement;
167 if (editableRoot->isInShadowTree()) 167 if (editableRoot->isInShadowTree())
168 shadowAncestorElement = editableRoot->shadowHost(); 168 shadowAncestorElement = editableRoot->shadowHost();
169 else 169 else
170 shadowAncestorElement = editableRoot; 170 shadowAncestorElement = editableRoot;
171 171
172 if (!editableRoot->getAttributeEventListener(EventTypeNames::webkitBeforeTex tInserted) 172 if (!editableRoot->getAttributeEventListener(EventTypeNames::webkitBeforeTex tInserted)
173 // FIXME: Remove these checks once textareas and textfields actually reg ister an event handler. 173 // FIXME: Remove these checks once textareas and textfields actually reg ister an event handler.
174 && !(shadowAncestorElement && shadowAncestorElement->layoutObject() && s hadowAncestorElement->layoutObject()->isTextControl()) 174 && !(shadowAncestorElement && shadowAncestorElement->layoutObject() && s hadowAncestorElement->layoutObject()->isTextControl())
175 && editableRoot->layoutObjectIsRichlyEditable()) { 175 && layoutObjectIsRichlyEditable(*editableRoot)) {
176 removeInterchangeNodes(m_fragment.get()); 176 removeInterchangeNodes(m_fragment.get());
177 return; 177 return;
178 } 178 }
179 179
180 if (!editableRoot->layoutObjectIsRichlyEditable()) { 180 if (!layoutObjectIsRichlyEditable(*editableRoot)) {
181 bool isPlainText = true; 181 bool isPlainText = true;
182 for (Node& node : NodeTraversal::childrenOf(*m_fragment)) { 182 for (Node& node : NodeTraversal::childrenOf(*m_fragment)) {
183 if (isInterchangeHTMLBRElement(&node) && &node == m_fragment->lastCh ild()) 183 if (isInterchangeHTMLBRElement(&node) && &node == m_fragment->lastCh ild())
184 continue; 184 continue;
185 if (!node.isTextNode()) { 185 if (!node.isTextNode()) {
186 isPlainText = false; 186 isPlainText = false;
187 break; 187 break;
188 } 188 }
189 } 189 }
190 // We don't need TestRendering for plain-text editing + plain-text inser tion. 190 // We don't need TestRendering for plain-text editing + plain-text inser tion.
(...skipping 19 matching lines...) Expand all
210 const EphemeralRange range = VisibleSelection::selectionFromContentsOfNode(h older).toNormalizedEphemeralRange(); 210 const EphemeralRange range = VisibleSelection::selectionFromContentsOfNode(h older).toNormalizedEphemeralRange();
211 String text = plainText(range, static_cast<TextIteratorBehavior>(TextIterato rEmitsOriginalText | TextIteratorIgnoresStyleVisibility)); 211 String text = plainText(range, static_cast<TextIteratorBehavior>(TextIterato rEmitsOriginalText | TextIteratorIgnoresStyleVisibility));
212 212
213 removeInterchangeNodes(holder); 213 removeInterchangeNodes(holder);
214 removeUnrenderedNodes(holder); 214 removeUnrenderedNodes(holder);
215 restoreAndRemoveTestRenderingNodesToFragment(holder); 215 restoreAndRemoveTestRenderingNodesToFragment(holder);
216 216
217 // Give the root a chance to change the text. 217 // Give the root a chance to change the text.
218 BeforeTextInsertedEvent* evt = BeforeTextInsertedEvent::create(text); 218 BeforeTextInsertedEvent* evt = BeforeTextInsertedEvent::create(text);
219 editableRoot->dispatchEvent(evt); 219 editableRoot->dispatchEvent(evt);
220 if (text != evt->text() || !editableRoot->layoutObjectIsRichlyEditable()) { 220 if (text != evt->text() || !layoutObjectIsRichlyEditable(*editableRoot)) {
221 restoreAndRemoveTestRenderingNodesToFragment(holder); 221 restoreAndRemoveTestRenderingNodesToFragment(holder);
222 222
223 m_fragment = createFragmentFromText(selection.toNormalizedEphemeralRange (), evt->text()); 223 m_fragment = createFragmentFromText(selection.toNormalizedEphemeralRange (), evt->text());
224 if (!m_fragment->hasChildren()) 224 if (!m_fragment->hasChildren())
225 return; 225 return;
226 226
227 holder = insertFragmentForTestRendering(editableRoot); 227 holder = insertFragmentForTestRendering(editableRoot);
228 removeInterchangeNodes(holder); 228 removeInterchangeNodes(holder);
229 removeUnrenderedNodes(holder); 229 removeUnrenderedNodes(holder);
230 restoreAndRemoveTestRenderingNodesToFragment(holder); 230 restoreAndRemoveTestRenderingNodesToFragment(holder);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 if (element->parentNode() && isNonTableCellHTMLBlockElement(element) && areIdenticalElements(*element, *element->parentNode()) 574 if (element->parentNode() && isNonTableCellHTMLBlockElement(element) && areIdenticalElements(*element, *element->parentNode())
575 && VisiblePosition::firstPositionInNode(element->parentNode()).deepE quivalent() == VisiblePosition::firstPositionInNode(element).deepEquivalent() 575 && VisiblePosition::firstPositionInNode(element->parentNode()).deepE quivalent() == VisiblePosition::firstPositionInNode(element).deepEquivalent()
576 && VisiblePosition::lastPositionInNode(element->parentNode()).deepEq uivalent() == VisiblePosition::lastPositionInNode(element).deepEquivalent()) { 576 && VisiblePosition::lastPositionInNode(element->parentNode()).deepEq uivalent() == VisiblePosition::lastPositionInNode(element).deepEquivalent()) {
577 insertedNodes.willRemoveNodePreservingChildren(*element); 577 insertedNodes.willRemoveNodePreservingChildren(*element);
578 removeNodePreservingChildren(element, editingState); 578 removeNodePreservingChildren(element, editingState);
579 if (editingState->isAborted()) 579 if (editingState->isAborted())
580 return; 580 return;
581 continue; 581 continue;
582 } 582 }
583 583
584 if (element->parentNode() && element->parentNode()->layoutObjectIsRichly Editable()) 584 if (element->parentNode() && layoutObjectIsRichlyEditable(*element->pare ntNode()))
585 removeElementAttribute(element, contenteditableAttr); 585 removeElementAttribute(element, contenteditableAttr);
586 586
587 // WebKit used to not add display: inline and float: none on copy. 587 // WebKit used to not add display: inline and float: none on copy.
588 // Keep this code around for backward compatibility 588 // Keep this code around for backward compatibility
589 if (isLegacyAppleHTMLSpanElement(element)) { 589 if (isLegacyAppleHTMLSpanElement(element)) {
590 if (!element->hasChildren()) { 590 if (!element->hasChildren()) {
591 insertedNodes.willRemoveNodePreservingChildren(*element); 591 insertedNodes.willRemoveNodePreservingChildren(*element);
592 removeNodePreservingChildren(element, editingState); 592 removeNodePreservingChildren(element, editingState);
593 if (editingState->isAborted()) 593 if (editingState->isAborted())
594 return; 594 return;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 moveElementOutOfAncestor(&element, headerElement, editingState); 694 moveElementOutOfAncestor(&element, headerElement, editingState);
695 if (editingState->isAborted()) 695 if (editingState->isAborted())
696 return; 696 return;
697 } 697 }
698 } 698 }
699 } 699 }
700 } 700 }
701 701
702 void ReplaceSelectionCommand::moveElementOutOfAncestor(Element* element, Element * ancestor, EditingState* editingState) 702 void ReplaceSelectionCommand::moveElementOutOfAncestor(Element* element, Element * ancestor, EditingState* editingState)
703 { 703 {
704 if (!ancestor->parentNode()->hasEditableStyle()) 704 if (!hasEditableStyle(*ancestor->parentNode()))
705 return; 705 return;
706 706
707 VisiblePosition positionAtEndOfNode = createVisiblePosition(lastPositionInOr AfterNode(element)); 707 VisiblePosition positionAtEndOfNode = createVisiblePosition(lastPositionInOr AfterNode(element));
708 VisiblePosition lastPositionInParagraph = VisiblePosition::lastPositionInNod e(ancestor); 708 VisiblePosition lastPositionInParagraph = VisiblePosition::lastPositionInNod e(ancestor);
709 if (positionAtEndOfNode.deepEquivalent() == lastPositionInParagraph.deepEqui valent()) { 709 if (positionAtEndOfNode.deepEquivalent() == lastPositionInParagraph.deepEqui valent()) {
710 removeNode(element, editingState); 710 removeNode(element, editingState);
711 if (editingState->isAborted()) 711 if (editingState->isAborted())
712 return; 712 return;
713 if (ancestor->nextSibling()) 713 if (ancestor->nextSibling())
714 insertNodeBefore(element, ancestor->nextSibling(), editingState); 714 insertNodeBefore(element, ancestor->nextSibling(), editingState);
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 1220
1221 InsertedNodes insertedNodes; 1221 InsertedNodes insertedNodes;
1222 Node* refNode = fragment.firstChild(); 1222 Node* refNode = fragment.firstChild();
1223 DCHECK(refNode); 1223 DCHECK(refNode);
1224 Node* node = refNode->nextSibling(); 1224 Node* node = refNode->nextSibling();
1225 1225
1226 fragment.removeNode(refNode); 1226 fragment.removeNode(refNode);
1227 1227
1228 Element* blockStart = enclosingBlock(insertionPos.anchorNode()); 1228 Element* blockStart = enclosingBlock(insertionPos.anchorNode());
1229 if ((isHTMLListElement(refNode) || (isLegacyAppleHTMLSpanElement(refNode) && isHTMLListElement(refNode->firstChild()))) 1229 if ((isHTMLListElement(refNode) || (isLegacyAppleHTMLSpanElement(refNode) && isHTMLListElement(refNode->firstChild())))
1230 && blockStart && blockStart->layoutObject()->isListItem() && blockStart- >parentNode()->hasEditableStyle()) { 1230 && blockStart && blockStart->layoutObject()->isListItem() && hasEditable Style(*blockStart->parentNode())) {
1231 refNode = insertAsListItems(toHTMLElement(refNode), blockStart, insertio nPos, insertedNodes, editingState); 1231 refNode = insertAsListItems(toHTMLElement(refNode), blockStart, insertio nPos, insertedNodes, editingState);
1232 if (editingState->isAborted()) 1232 if (editingState->isAborted())
1233 return; 1233 return;
1234 } else { 1234 } else {
1235 insertNodeAt(refNode, insertionPos, editingState); 1235 insertNodeAt(refNode, insertionPos, editingState);
1236 if (editingState->isAborted()) 1236 if (editingState->isAborted())
1237 return; 1237 return;
1238 insertedNodes.respondToNodeInsertion(*refNode); 1238 insertedNodes.respondToNodeInsertion(*refNode);
1239 } 1239 }
1240 1240
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 visitor->trace(m_startOfInsertedContent); 1755 visitor->trace(m_startOfInsertedContent);
1756 visitor->trace(m_endOfInsertedContent); 1756 visitor->trace(m_endOfInsertedContent);
1757 visitor->trace(m_insertionStyle); 1757 visitor->trace(m_insertionStyle);
1758 visitor->trace(m_documentFragment); 1758 visitor->trace(m_documentFragment);
1759 visitor->trace(m_startOfInsertedRange); 1759 visitor->trace(m_startOfInsertedRange);
1760 visitor->trace(m_endOfInsertedRange); 1760 visitor->trace(m_endOfInsertedRange);
1761 CompositeEditCommand::trace(visitor); 1761 CompositeEditCommand::trace(visitor);
1762 } 1762 }
1763 1763
1764 } // namespace blink 1764 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698