OLD | NEW |
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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 return; | 355 return; |
356 insertNodeBefore(insertChild, refChild); | 356 insertNodeBefore(insertChild, refChild); |
357 } else | 357 } else |
358 insertNodeAfter(insertChild, refChild); | 358 insertNodeAfter(insertChild, refChild); |
359 } | 359 } |
360 | 360 |
361 void CompositeEditCommand::appendNode(PassRefPtrWillBeRawPtr<Node> node, PassRef
PtrWillBeRawPtr<ContainerNode> parent) | 361 void CompositeEditCommand::appendNode(PassRefPtrWillBeRawPtr<Node> node, PassRef
PtrWillBeRawPtr<ContainerNode> parent) |
362 { | 362 { |
363 // When cloneParagraphUnderNewElement() clones the fallback content | 363 // When cloneParagraphUnderNewElement() clones the fallback content |
364 // of an OBJECT element, the ASSERT below may fire since the return | 364 // of an OBJECT element, the ASSERT below may fire since the return |
365 // value of canHaveChildrenForEditing is not reliable until the render | 365 // value of canHaveChildrenForEditing is not reliable until the layout |
366 // object of the OBJECT is created. Hence we ignore this check for OBJECTs. | 366 // object of the OBJECT is created. Hence we ignore this check for OBJECTs. |
367 ASSERT(canHaveChildrenForEditing(parent.get()) | 367 ASSERT(canHaveChildrenForEditing(parent.get()) |
368 || (parent->isElementNode() && toElement(parent.get())->tagQName() == ob
jectTag)); | 368 || (parent->isElementNode() && toElement(parent.get())->tagQName() == ob
jectTag)); |
369 applyCommandToComposite(AppendNodeCommand::create(parent, node)); | 369 applyCommandToComposite(AppendNodeCommand::create(parent, node)); |
370 } | 370 } |
371 | 371 |
372 void CompositeEditCommand::removeChildrenInRange(PassRefPtrWillBeRawPtr<Node> no
de, unsigned from, unsigned to) | 372 void CompositeEditCommand::removeChildrenInRange(PassRefPtrWillBeRawPtr<Node> no
de, unsigned from, unsigned to) |
373 { | 373 { |
374 WillBeHeapVector<RefPtrWillBeMember<Node>> children; | 374 WillBeHeapVector<RefPtrWillBeMember<Node>> children; |
375 Node* child = NodeTraversal::childAt(*node, from); | 375 Node* child = NodeTraversal::childAt(*node, from); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 bool CompositeEditCommand::canRebalance(const Position& position) const | 614 bool CompositeEditCommand::canRebalance(const Position& position) const |
615 { | 615 { |
616 Node* node = position.containerNode(); | 616 Node* node = position.containerNode(); |
617 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node ||
!node->isTextNode()) | 617 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !node ||
!node->isTextNode()) |
618 return false; | 618 return false; |
619 | 619 |
620 Text* textNode = toText(node); | 620 Text* textNode = toText(node); |
621 if (textNode->length() == 0) | 621 if (textNode->length() == 0) |
622 return false; | 622 return false; |
623 | 623 |
624 LayoutText* renderer = textNode->layoutObject(); | 624 LayoutText* layoutText = textNode->layoutObject(); |
625 if (renderer && !renderer->style()->collapseWhiteSpace()) | 625 if (layoutText && !layoutText->style()->collapseWhiteSpace()) |
626 return false; | 626 return false; |
627 | 627 |
628 return true; | 628 return true; |
629 } | 629 } |
630 | 630 |
631 // FIXME: Doesn't go into text nodes that contribute adjacent text (siblings, co
usins, etc). | 631 // FIXME: Doesn't go into text nodes that contribute adjacent text (siblings, co
usins, etc). |
632 void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position) | 632 void CompositeEditCommand::rebalanceWhitespaceAt(const Position& position) |
633 { | 633 { |
634 Node* node = position.containerNode(); | 634 Node* node = position.containerNode(); |
635 if (!canRebalance(position)) | 635 if (!canRebalance(position)) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 | 683 |
684 void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& positio
n) | 684 void CompositeEditCommand::prepareWhitespaceAtPositionForSplit(Position& positio
n) |
685 { | 685 { |
686 Node* node = position.deprecatedNode(); | 686 Node* node = position.deprecatedNode(); |
687 if (!node || !node->isTextNode()) | 687 if (!node || !node->isTextNode()) |
688 return; | 688 return; |
689 Text* textNode = toText(node); | 689 Text* textNode = toText(node); |
690 | 690 |
691 if (textNode->length() == 0) | 691 if (textNode->length() == 0) |
692 return; | 692 return; |
693 LayoutText* renderer = textNode->layoutObject(); | 693 LayoutText* layoutText = textNode->layoutObject(); |
694 if (renderer && !renderer->style()->collapseWhiteSpace()) | 694 if (layoutText && !layoutText->style()->collapseWhiteSpace()) |
695 return; | 695 return; |
696 | 696 |
697 // Delete collapsed whitespace so that inserting nbsps doesn't uncollapse it
. | 697 // Delete collapsed whitespace so that inserting nbsps doesn't uncollapse it
. |
698 Position upstreamPos = position.upstream(); | 698 Position upstreamPos = position.upstream(); |
699 deleteInsignificantText(upstreamPos, position.downstream()); | 699 deleteInsignificantText(upstreamPos, position.downstream()); |
700 position = upstreamPos.downstream(); | 700 position = upstreamPos.downstream(); |
701 | 701 |
702 VisiblePosition visiblePos(position); | 702 VisiblePosition visiblePos(position); |
703 VisiblePosition previousVisiblePos(visiblePos.previous()); | 703 VisiblePosition previousVisiblePos(visiblePos.previous()); |
704 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(previousVisiblePos)
; | 704 replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(previousVisiblePos)
; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 return placeholder.release(); | 864 return placeholder.release(); |
865 } | 865 } |
866 | 866 |
867 PassRefPtrWillBeRawPtr<HTMLBRElement> CompositeEditCommand::addBlockPlaceholderI
fNeeded(Element* container) | 867 PassRefPtrWillBeRawPtr<HTMLBRElement> CompositeEditCommand::addBlockPlaceholderI
fNeeded(Element* container) |
868 { | 868 { |
869 if (!container) | 869 if (!container) |
870 return nullptr; | 870 return nullptr; |
871 | 871 |
872 document().updateLayoutIgnorePendingStylesheets(); | 872 document().updateLayoutIgnorePendingStylesheets(); |
873 | 873 |
874 LayoutObject* renderer = container->layoutObject(); | 874 LayoutObject* layoutObject = container->layoutObject(); |
875 if (!renderer || !renderer->isLayoutBlockFlow()) | 875 if (!layoutObject || !layoutObject->isLayoutBlockFlow()) |
876 return nullptr; | 876 return nullptr; |
877 | 877 |
878 // append the placeholder to make sure it follows | 878 // append the placeholder to make sure it follows |
879 // any unrendered blocks | 879 // any unrendered blocks |
880 LayoutBlockFlow* block = toLayoutBlockFlow(renderer); | 880 LayoutBlockFlow* block = toLayoutBlockFlow(layoutObject); |
881 if (block->size().height() == 0 || (block->isListItem() && toLayoutListItem(
block)->isEmpty())) | 881 if (block->size().height() == 0 || (block->isListItem() && toLayoutListItem(
block)->isEmpty())) |
882 return appendBlockPlaceholder(container); | 882 return appendBlockPlaceholder(container); |
883 | 883 |
884 return nullptr; | 884 return nullptr; |
885 } | 885 } |
886 | 886 |
887 // Assumes that the position is at a placeholder and does the removal without mu
ch checking. | 887 // Assumes that the position is at a placeholder and does the removal without mu
ch checking. |
888 void CompositeEditCommand::removePlaceholderAt(const Position& p) | 888 void CompositeEditCommand::removePlaceholderAt(const Position& p) |
889 { | 889 { |
890 ASSERT(lineBreakExistsAtPosition(p)); | 890 ASSERT(lineBreakExistsAtPosition(p)); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 } | 1498 } |
1499 | 1499 |
1500 DEFINE_TRACE(CompositeEditCommand) | 1500 DEFINE_TRACE(CompositeEditCommand) |
1501 { | 1501 { |
1502 visitor->trace(m_commands); | 1502 visitor->trace(m_commands); |
1503 visitor->trace(m_composition); | 1503 visitor->trace(m_composition); |
1504 EditCommand::trace(visitor); | 1504 EditCommand::trace(visitor); |
1505 } | 1505 } |
1506 | 1506 |
1507 } // namespace blink | 1507 } // namespace blink |
OLD | NEW |