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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 if (!element.hasAttributes()) 315 if (!element.hasAttributes())
316 return true; 316 return true;
317 317
318 return false; 318 return false;
319 } 319 }
320 320
321 void CompositeEditCommand::insertNodeBefore(Node* insertChild, Node* refChild, E ditingState* editingState, ShouldAssumeContentIsAlwaysEditable shouldAssumeConte ntIsAlwaysEditable) 321 void CompositeEditCommand::insertNodeBefore(Node* insertChild, Node* refChild, E ditingState* editingState, ShouldAssumeContentIsAlwaysEditable shouldAssumeConte ntIsAlwaysEditable)
322 { 322 {
323 DCHECK_NE(document().body(), refChild); 323 DCHECK_NE(document().body(), refChild);
324 ABORT_EDITING_COMMAND_IF(!refChild->parentNode()->hasEditableStyle() && refC hild->parentNode()->inActiveDocument()); 324 ABORT_EDITING_COMMAND_IF(!hasEditableStyle(*refChild->parentNode()) && refCh ild->parentNode()->inActiveDocument());
325 applyCommandToComposite(InsertNodeBeforeCommand::create(insertChild, refChil d, shouldAssumeContentIsAlwaysEditable), editingState); 325 applyCommandToComposite(InsertNodeBeforeCommand::create(insertChild, refChil d, shouldAssumeContentIsAlwaysEditable), editingState);
326 } 326 }
327 327
328 void CompositeEditCommand::insertNodeAfter(Node* insertChild, Node* refChild, Ed itingState* editingState) 328 void CompositeEditCommand::insertNodeAfter(Node* insertChild, Node* refChild, Ed itingState* editingState)
329 { 329 {
330 DCHECK(insertChild); 330 DCHECK(insertChild);
331 DCHECK(refChild); 331 DCHECK(refChild);
332 DCHECK_NE(document().body(), refChild); 332 DCHECK_NE(document().body(), refChild);
333 ContainerNode* parent = refChild->parentNode(); 333 ContainerNode* parent = refChild->parentNode();
334 DCHECK(parent); 334 DCHECK(parent);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // of an OBJECT element, the ASSERT below may fire since the return 379 // of an OBJECT element, the ASSERT below may fire since the return
380 // value of canHaveChildrenForEditing is not reliable until the layout 380 // value of canHaveChildrenForEditing is not reliable until the layout
381 // object of the OBJECT is created. Hence we ignore this check for OBJECTs. 381 // object of the OBJECT is created. Hence we ignore this check for OBJECTs.
382 // TODO(yosin): We should move following |ABORT_EDITING_COMMAND_IF|s to 382 // TODO(yosin): We should move following |ABORT_EDITING_COMMAND_IF|s to
383 // |AppendNodeCommand|. 383 // |AppendNodeCommand|.
384 // TODO(yosin): We should get rid of |canHaveChildrenForEditing()|, since 384 // TODO(yosin): We should get rid of |canHaveChildrenForEditing()|, since
385 // |cloneParagraphUnderNewElement()| attempt to clone non-well-formed HTML, 385 // |cloneParagraphUnderNewElement()| attempt to clone non-well-formed HTML,
386 // produced by JavaScript. 386 // produced by JavaScript.
387 ABORT_EDITING_COMMAND_IF(!canHaveChildrenForEditing(parent) 387 ABORT_EDITING_COMMAND_IF(!canHaveChildrenForEditing(parent)
388 && !(parent->isElementNode() && toElement(parent)->tagQName() == objectT ag)); 388 && !(parent->isElementNode() && toElement(parent)->tagQName() == objectT ag));
389 ABORT_EDITING_COMMAND_IF(!parent->hasEditableStyle() && parent->inActiveDocu ment()); 389 ABORT_EDITING_COMMAND_IF(!hasEditableStyle(*parent) && parent->inActiveDocum ent());
390 applyCommandToComposite(AppendNodeCommand::create(parent, node), editingStat e); 390 applyCommandToComposite(AppendNodeCommand::create(parent, node), editingStat e);
391 } 391 }
392 392
393 void CompositeEditCommand::removeChildrenInRange(Node* node, unsigned from, unsi gned to, EditingState* editingState) 393 void CompositeEditCommand::removeChildrenInRange(Node* node, unsigned from, unsi gned to, EditingState* editingState)
394 { 394 {
395 HeapVector<Member<Node>> children; 395 HeapVector<Member<Node>> children;
396 Node* child = NodeTraversal::childAt(*node, from); 396 Node* child = NodeTraversal::childAt(*node, from);
397 for (unsigned i = from; child && i < to; i++, child = child->nextSibling()) 397 for (unsigned i = from; child && i < to; i++, child = child->nextSibling())
398 children.append(child); 398 children.append(child);
399 399
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 652 }
653 653
654 bool CompositeEditCommand::shouldRebalanceLeadingWhitespaceFor(const String& tex t) const 654 bool CompositeEditCommand::shouldRebalanceLeadingWhitespaceFor(const String& tex t) const
655 { 655 {
656 return containsOnlyWhitespace(text); 656 return containsOnlyWhitespace(text);
657 } 657 }
658 658
659 bool CompositeEditCommand::canRebalance(const Position& position) const 659 bool CompositeEditCommand::canRebalance(const Position& position) const
660 { 660 {
661 Node* node = position.computeContainerNode(); 661 Node* node = position.computeContainerNode();
662 if (!position.isOffsetInAnchor() || !node || !node->isTextNode() || !node->l ayoutObjectIsRichlyEditable()) 662 if (!position.isOffsetInAnchor() || !node || !node->isTextNode() || !layoutO bjectIsRichlyEditable(*node))
663 return false; 663 return false;
664 664
665 Text* textNode = toText(node); 665 Text* textNode = toText(node);
666 if (textNode->length() == 0) 666 if (textNode->length() == 0)
667 return false; 667 return false;
668 668
669 LayoutText* layoutText = textNode->layoutObject(); 669 LayoutText* layoutText = textNode->layoutObject();
670 if (layoutText && !layoutText->style()->collapseWhiteSpace()) 670 if (layoutText && !layoutText->style()->collapseWhiteSpace())
671 return false; 671 return false;
672 672
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 if (!emptyListItem) 1395 if (!emptyListItem)
1396 return false; 1396 return false;
1397 1397
1398 EditingStyle* style = EditingStyle::create(endingSelection().start()); 1398 EditingStyle* style = EditingStyle::create(endingSelection().start());
1399 style->mergeTypingStyle(&document()); 1399 style->mergeTypingStyle(&document());
1400 1400
1401 ContainerNode* listNode = emptyListItem->parentNode(); 1401 ContainerNode* listNode = emptyListItem->parentNode();
1402 // FIXME: Can't we do something better when the immediate parent wasn't a li st node? 1402 // FIXME: Can't we do something better when the immediate parent wasn't a li st node?
1403 if (!listNode 1403 if (!listNode
1404 || (!isHTMLUListElement(*listNode) && !isHTMLOListElement(*listNode)) 1404 || (!isHTMLUListElement(*listNode) && !isHTMLOListElement(*listNode))
1405 || !listNode->hasEditableStyle() 1405 || !hasEditableStyle(*listNode)
1406 || listNode == rootEditableElement(*emptyListItem)) 1406 || listNode == rootEditableElement(*emptyListItem))
1407 return false; 1407 return false;
1408 1408
1409 HTMLElement* newBlock = nullptr; 1409 HTMLElement* newBlock = nullptr;
1410 if (ContainerNode* blockEnclosingList = listNode->parentNode()) { 1410 if (ContainerNode* blockEnclosingList = listNode->parentNode()) {
1411 if (isHTMLLIElement(*blockEnclosingList)) { // listNode is inside anothe r list item 1411 if (isHTMLLIElement(*blockEnclosingList)) { // listNode is inside anothe r list item
1412 if (visiblePositionAfterNode(*blockEnclosingList).deepEquivalent() = = visiblePositionAfterNode(*listNode).deepEquivalent()) { 1412 if (visiblePositionAfterNode(*blockEnclosingList).deepEquivalent() = = visiblePositionAfterNode(*listNode).deepEquivalent()) {
1413 // If listNode appears at the end of the outer list item, then m ove listNode outside of this list item 1413 // If listNode appears at the end of the outer list item, then m ove listNode outside of this list item
1414 // e.g. <ul><li>hello <ul><li><br></li></ul> </li></ul> should b ecome <ul><li>hello</li> <ul><li><br></li></ul> </ul> after this section 1414 // e.g. <ul><li>hello <ul><li><br></li></ul> </li></ul> should b ecome <ul><li>hello</li> <ul><li><br></li></ul> </ul> after this section
1415 // If listNode does NOT appear at the end, then we should consid er it as a regular paragraph. 1415 // If listNode does NOT appear at the end, then we should consid er it as a regular paragraph.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 } 1628 }
1629 1629
1630 DEFINE_TRACE(CompositeEditCommand) 1630 DEFINE_TRACE(CompositeEditCommand)
1631 { 1631 {
1632 visitor->trace(m_commands); 1632 visitor->trace(m_commands);
1633 visitor->trace(m_composition); 1633 visitor->trace(m_composition);
1634 EditCommand::trace(visitor); 1634 EditCommand::trace(visitor);
1635 } 1635 }
1636 1636
1637 } // namespace blink 1637 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698