⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276133 in webkit


Ignore:
Timestamp:
Apr 16, 2021, 4:09:40 AM (5 years ago)
Author:
rniwa@webkit.org
Message:

Deploy Ref/RefPtr in ApplyStyleCommand
https://bugs.webkit.org/show_bug.cgi?id=224662

Reviewed by Antti Koivisto.

Deployed smart pointers in ApplyStyleCommand. Also deployed ScriptDisallowedScope around the code
which accesses the render tree in ApplyStyleCommand::applyInlineStyleToPushDown.

  • editing/ApplyStyleCommand.cpp:

(WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
(WebCore::dummySpanAncestorForNode):
(WebCore::ApplyStyleCommand::cleanupUnstyledAppleStyleSpans):
(WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
(WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
(WebCore::highestEmbeddingAncestor):
(WebCore::ApplyStyleCommand::applyInlineStyle):
(WebCore::ApplyStyleCommand::fixRangeAndApplyInlineStyle):
(WebCore::containsNonEditableRegion):
(WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
(WebCore::ApplyStyleCommand::shouldApplyInlineStyleToRun):
(WebCore::ApplyStyleCommand::highestAncestorWithConflictingInlineStyle):
(WebCore::ApplyStyleCommand::applyInlineStyleToPushDown):
(WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
(WebCore::ApplyStyleCommand::removeInlineStyle):
(WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
(WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical):
(WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
(WebCore::ApplyStyleCommand::applyInlineStyleChange):
(WebCore::ApplyStyleCommand::joinChildTextNodes):

  • editing/ApplyStyleCommand.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r276131 r276133  
     12021-04-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy Ref/RefPtr in ApplyStyleCommand
     4        https://bugs.webkit.org/show_bug.cgi?id=224662
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Deployed smart pointers in ApplyStyleCommand. Also deployed ScriptDisallowedScope around the code
     9        which accesses the render tree in ApplyStyleCommand::applyInlineStyleToPushDown.
     10
     11        * editing/ApplyStyleCommand.cpp:
     12        (WebCore::ApplyStyleCommand::applyRelativeFontStyleChange):
     13        (WebCore::dummySpanAncestorForNode):
     14        (WebCore::ApplyStyleCommand::cleanupUnstyledAppleStyleSpans):
     15        (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi):
     16        (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock):
     17        (WebCore::highestEmbeddingAncestor):
     18        (WebCore::ApplyStyleCommand::applyInlineStyle):
     19        (WebCore::ApplyStyleCommand::fixRangeAndApplyInlineStyle):
     20        (WebCore::containsNonEditableRegion):
     21        (WebCore::ApplyStyleCommand::applyInlineStyleToNodeRange):
     22        (WebCore::ApplyStyleCommand::shouldApplyInlineStyleToRun):
     23        (WebCore::ApplyStyleCommand::highestAncestorWithConflictingInlineStyle):
     24        (WebCore::ApplyStyleCommand::applyInlineStyleToPushDown):
     25        (WebCore::ApplyStyleCommand::pushDownInlineStyleAroundNode):
     26        (WebCore::ApplyStyleCommand::removeInlineStyle):
     27        (WebCore::ApplyStyleCommand::mergeStartWithPreviousIfIdentical):
     28        (WebCore::ApplyStyleCommand::mergeEndWithNextIfIdentical):
     29        (WebCore::ApplyStyleCommand::surroundNodeRangeWithElement):
     30        (WebCore::ApplyStyleCommand::applyInlineStyleChange):
     31        (WebCore::ApplyStyleCommand::joinChildTextNodes):
     32        * editing/ApplyStyleCommand.h:
     33
    1342021-04-16  Ryosuke Niwa  <rniwa@webkit.org>
    235
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r274865 r276133  
    4444#include "RenderObject.h"
    4545#include "RenderText.h"
     46#include "ScriptDisallowedScope.h"
    4647#include "StyleProperties.h"
    4748#include "StyleResolver.h"
     
    345346    // If the end node is before the start node (can only happen if the end node is
    346347    // an ancestor of the start node), we gather nodes up to the next sibling of the end node
    347     Node* beyondEnd;
     348    RefPtr<Node> beyondEnd;
    348349    ASSERT(start.deprecatedNode());
    349350    ASSERT(end.deprecatedNode());
     
    354355   
    355356    start = start.upstream(); // Move upstream to ensure we do not add redundant spans.
    356     Node* startNode = start.deprecatedNode();
     357    auto startNode = makeRefPtr(start.deprecatedNode());
    357358
    358359    // Make sure we're not already at the end or the next NodeTraversal::next() will traverse past it.
     
    369370    // Store away font size before making any changes to the document.
    370371    // This ensures that changes to one node won't effect another.
    371     HashMap<Node*, float> startingFontSizes;
    372     for (Node* node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
     372    HashMap<Ref<Node>, float> startingFontSizes;
     373    for (auto node = startNode; node != beyondEnd; node = NodeTraversal::next(*node)) {
    373374        ASSERT(node);
    374         startingFontSizes.set(node, computedFontSize(node));
     375        startingFontSizes.set(*node, computedFontSize(node.get()));
    375376    }
    376377
    377378    // These spans were added by us. If empty after font size changes, they can be removed.
    378379    Vector<Ref<HTMLElement>> unstyledSpans;
    379    
    380     Node* lastStyledNode = nullptr;
     380
     381    RefPtr<Node> lastStyledNode;
    381382    bool reachedEnd = false;
    382     for (auto node = makeRefPtr(startNode); node != beyondEnd && !reachedEnd; node = NodeTraversal::next(*node)) {
     383    for (auto node = startNode; node != beyondEnd && !reachedEnd; node = NodeTraversal::next(*node)) {
    383384        ASSERT(node);
    384385        RefPtr<HTMLElement> element;
     
    392393            // text node. To make this possible, add a style span to surround this text node.
    393394            auto span = createStyleSpanElement(document());
    394             if (!surroundNodeRangeWithElement(*node, *node, span.copyRef()))
     395            if (!surroundNodeRangeWithElement(*node, *node, span))
    395396                continue;
    396             reachedEnd = node->isDescendantOf(beyondEnd);
     397            reachedEnd = node->isDescendantOf(beyondEnd.get());
    397398            element = WTFMove(span);
    398399        }  else {
     
    400401            continue;
    401402        }
    402         lastStyledNode = node.get();
     403        lastStyledNode = node;
    403404
    404405        RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element->inlineStyle());
     
    425426}
    426427
    427 static ContainerNode* dummySpanAncestorForNode(const Node* node)
    428 {
    429     while (node && (!is<Element>(*node) || !isStyleSpanOrSpanWithOnlyStyleAttribute(downcast<Element>(*node))))
    430         node = node->parentNode();
    431    
    432     return node ? node->parentNode() : nullptr;
     428static ContainerNode* dummySpanAncestorForNode(Node* node)
     429{
     430    RefPtr<Node> currentNode = node;
     431    while (currentNode && (!is<Element>(*currentNode) || !isStyleSpanOrSpanWithOnlyStyleAttribute(downcast<Element>(*currentNode))))
     432        currentNode = currentNode->parentNode();
     433    return currentNode ? currentNode->parentNode() : nullptr;
    433434}
    434435
     
    443444    // all the children of the dummy's parent
    444445
    445     Vector<Element*> toRemove;
     446    Vector<Ref<Element>> toRemove;
    446447    for (auto& child : childrenOfType<Element>(*dummySpanAncestor)) {
    447448        if (isSpanWithoutAttributesOrUnstyledStyleSpan(child))
    448             toRemove.append(&child);
     449            toRemove.append(child);
    449450    }
    450451
    451452    for (auto& element : toRemove)
    452         removeNodePreservingChildren(*element);
    453 }
    454 
    455 HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, WritingDirection allowedDirection)
     453        removeNodePreservingChildren(element.get());
     454}
     455
     456RefPtr<HTMLElement> ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, WritingDirection allowedDirection)
    456457{
    457458    // We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection.
    458459    // In that case, we return the unsplit ancestor. Otherwise, we return 0.
    459     Element* block = enclosingBlock(node);
     460    auto block = makeRefPtr(enclosingBlock(node));
    460461    if (!block || block == node)
    461         return 0;
    462 
    463     Node* highestAncestorWithUnicodeBidi = nullptr;
    464     Node* nextHighestAncestorWithUnicodeBidi = nullptr;
     462        return nullptr;
     463
     464    RefPtr<Node> highestAncestorWithUnicodeBidi;
     465    RefPtr<Node> nextHighestAncestorWithUnicodeBidi;
    465466    int highestAncestorUnicodeBidi = 0;
    466     for (Node* n = node->parentNode(); n != block; n = n->parentNode()) {
    467         int unicodeBidi = toIdentifier(ComputedStyleExtractor(n).propertyValue(CSSPropertyUnicodeBidi));
     467    for (auto ancestor = makeRefPtr(node->parentNode()); ancestor != block; ancestor = ancestor->parentNode()) {
     468        int unicodeBidi = toIdentifier(ComputedStyleExtractor(ancestor.get()).propertyValue(CSSPropertyUnicodeBidi));
    468469        if (unicodeBidi && unicodeBidi != CSSValueNormal) {
    469470            highestAncestorUnicodeBidi = unicodeBidi;
    470471            nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi;
    471             highestAncestorWithUnicodeBidi = n;
     472            highestAncestorWithUnicodeBidi = ancestor;
    472473        }
    473474    }
    474475
    475476    if (!highestAncestorWithUnicodeBidi)
    476         return 0;
    477 
    478     HTMLElement* unsplitAncestor = nullptr;
     477        return nullptr;
     478
     479    RefPtr<HTMLElement> unsplitAncestor;
    479480
    480481    if (allowedDirection != WritingDirection::Natural && highestAncestorUnicodeBidi != CSSValueBidiOverride && is<HTMLElement>(*highestAncestorWithUnicodeBidi)) {
    481         auto highestAncestorDirection = EditingStyle::create(highestAncestorWithUnicodeBidi, EditingStyle::AllProperties)->textDirection();
     482        auto highestAncestorDirection = EditingStyle::create(highestAncestorWithUnicodeBidi.get(), EditingStyle::AllProperties)->textDirection();
    482483        if (highestAncestorDirection && *highestAncestorDirection == allowedDirection) {
    483484            if (!nextHighestAncestorWithUnicodeBidi)
    484                 return downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
    485 
    486             unsplitAncestor = downcast<HTMLElement>(highestAncestorWithUnicodeBidi);
     485                return static_pointer_cast<HTMLElement>(WTFMove(highestAncestorWithUnicodeBidi));
     486
     487            unsplitAncestor = static_pointer_cast<HTMLElement>(highestAncestorWithUnicodeBidi);
    487488            highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi;
    488489        }
     
    499500        currentNode = parent;
    500501    }
     502
    501503    return unsplitAncestor;
    502504}
     
    504506void ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor)
    505507{
    506     Element* block = enclosingBlock(node);
     508    auto block = makeRefPtr(enclosingBlock(node));
    507509    if (!block || block == node)
    508510        return;
    509511
    510     Node* parent = nullptr;
    511     for (Node* ancestor = node->parentNode(); ancestor != block && ancestor != unsplitAncestor; ancestor = parent) {
     512    for (RefPtr<Node> ancestor = node->parentNode(), parent; ancestor != block && ancestor != unsplitAncestor; ancestor = parent) {
    512513        parent = ancestor->parentNode();
    513514        if (!is<StyledElement>(*ancestor))
     
    528529            removeNodeAttribute(element, dirAttr);
    529530        } else {
    530             RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
     531            auto inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
    531532            inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
    532533            inlineStyle->removeProperty(CSSPropertyDirection);
     
    538539}
    539540
    540 static Node* highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
    541 {
    542     for (Node* n = startNode; n && n != enclosingNode; n = n->parentNode()) {
    543         if (n->isHTMLElement() && toIdentifier(ComputedStyleExtractor(n).propertyValue(CSSPropertyUnicodeBidi)) == CSSValueEmbed)
    544             return n;
    545     }
    546 
    547     return 0;
     541static RefPtr<Node> highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
     542{
     543    for (auto currentNode = makeRefPtr(startNode); currentNode && currentNode != enclosingNode; currentNode = currentNode->parentNode()) {
     544        if (currentNode->isHTMLElement() && toIdentifier(ComputedStyleExtractor(currentNode.get()).propertyValue(CSSPropertyUnicodeBidi)) == CSSValueEmbed)
     545            return currentNode;
     546    }
     547
     548    return nullptr;
    548549}
    549550
     
    602603    if (textDirection.hasValue()) {
    603604        // Leave alone an ancestor that provides the desired single level embedding, if there is one.
    604         auto* startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, *textDirection);
    605         auto* endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, *textDirection);
    606         removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAncestor);
    607         removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncestor);
     605        auto startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.deprecatedNode(), true, *textDirection);
     606        auto endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.deprecatedNode(), false, *textDirection);
     607        removeEmbeddingUpToEnclosingBlock(start.deprecatedNode(), startUnsplitAncestor.get());
     608        removeEmbeddingUpToEnclosingBlock(end.deprecatedNode(), endUnsplitAncestor.get());
    608609
    609610        // Avoid removing the dir attribute and the unicode-bidi and direction properties from the unsplit ancestors.
    610611        Position embeddingRemoveStart = removeStart;
    611612        if (startUnsplitAncestor && nodeFullySelected(*startUnsplitAncestor, removeStart, end))
    612             embeddingRemoveStart = positionInParentAfterNode(startUnsplitAncestor);
     613            embeddingRemoveStart = positionInParentAfterNode(startUnsplitAncestor.get());
    613614
    614615        Position embeddingRemoveEnd = end;
    615616        if (endUnsplitAncestor && nodeFullySelected(*endUnsplitAncestor, removeStart, end))
    616             embeddingRemoveEnd = positionInParentBeforeNode(endUnsplitAncestor).downstream();
     617            embeddingRemoveEnd = positionInParentBeforeNode(endUnsplitAncestor.get()).downstream();
    617618
    618619        if (embeddingRemoveEnd != removeStart || embeddingRemoveEnd != end) {
     
    653654    if (textDirection.hasValue()) {
    654655        // Avoid applying the unicode-bidi and direction properties beneath ancestors that already have them.
    655         Node* embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
    656         Node* embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
     656        auto embeddingStartNode = highestEmbeddingAncestor(start.deprecatedNode(), enclosingBlock(start.deprecatedNode()));
     657        auto embeddingEndNode = highestEmbeddingAncestor(end.deprecatedNode(), enclosingBlock(end.deprecatedNode()));
    657658
    658659        if (embeddingStartNode || embeddingEndNode) {
    659             Position embeddingApplyStart = embeddingStartNode ? positionInParentAfterNode(embeddingStartNode) : start;
    660             Position embeddingApplyEnd = embeddingEndNode ? positionInParentBeforeNode(embeddingEndNode) : end;
     660            Position embeddingApplyStart = embeddingStartNode ? positionInParentAfterNode(embeddingStartNode.get()) : start;
     661            Position embeddingApplyEnd = embeddingEndNode ? positionInParentBeforeNode(embeddingEndNode.get()) : end;
    661662            ASSERT(embeddingApplyStart.isNotNull() && embeddingApplyEnd.isNotNull());
    662663
     
    681682void ApplyStyleCommand::fixRangeAndApplyInlineStyle(EditingStyle& style, const Position& start, const Position& end)
    682683{
    683     Node* startNode = start.deprecatedNode();
     684    auto startNode = makeRefPtr(start.deprecatedNode());
    684685
    685686    if (start.deprecatedEditingOffset() >= caretMaxOffset(*startNode)) {
    686687        startNode = NodeTraversal::next(*startNode);
    687         if (!startNode || end < firstPositionInOrBeforeNode(startNode))
     688        if (!startNode || end < firstPositionInOrBeforeNode(startNode.get()))
    688689            return;
    689690    }
    690691
    691     Node* pastEndNode = end.deprecatedNode();
     692    auto pastEndNode = makeRefPtr(end.deprecatedNode());
    692693    if (end.deprecatedEditingOffset() >= caretMaxOffset(*pastEndNode))
    693694        pastEndNode = NodeTraversal::nextSkippingChildren(*pastEndNode);
     
    703704    // to generate <font color="blue" size="4">hello</font> instead of <font color="blue"><font size="4">hello</font></font>
    704705    auto range = *makeSimpleRange(start, end);
    705     auto* editableRoot = startNode->rootEditableElement();
     706    auto editableRoot = makeRefPtr(startNode->rootEditableElement());
    706707    if (startNode != editableRoot) {
    707708        while (editableRoot && startNode->parentNode() != editableRoot && isNodeVisiblyContainedWithin(*startNode->parentNode(), range))
     
    709710    }
    710711
    711     applyInlineStyleToNodeRange(style, *startNode, pastEndNode);
     712    applyInlineStyleToNodeRange(style, *startNode, pastEndNode.get());
    712713}
    713714
     
    717718        return true;
    718719
    719     Node* sibling = NodeTraversal::nextSkippingChildren(node);
    720     for (Node* descendant = node.firstChild(); descendant && descendant != sibling; descendant = NodeTraversal::next(*descendant)) {
     720    auto sibling = makeRefPtr(NodeTraversal::nextSkippingChildren(node));
     721    for (auto descendant = makeRefPtr(node.firstChild()); descendant && descendant != sibling; descendant = NodeTraversal::next(*descendant)) {
    721722        if (!descendant->hasEditableStyle())
    722723            return true;
     
    772773            HTMLElement& element = downcast<HTMLElement>(*node);
    773774            RefPtr<MutableStyleProperties> inlineStyle = copyStyleOrCreateEmpty(element.inlineStyle());
    774             if (MutableStyleProperties* otherStyle = style.style())
     775            if (auto otherStyle = makeRefPtr(style.style()))
    775776                inlineStyle->mergeAndOverrideOnConflict(*otherStyle);
    776777            setNodeAttribute(element, styleAttr, inlineStyle->asText());
     
    791792        }
    792793
    793         Node* runStart = node.get();
    794         Node* runEnd = node.get();
    795         Node* sibling = node->nextSibling();
    796         while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNode) && (!isBlock(sibling) || sibling->hasTagName(brTag)) && !containsNonEditableRegion(*sibling)) {
     794        auto runStart = node;
     795        auto runEnd = node;
     796        auto sibling = makeRefPtr(node->nextSibling());
     797        while (sibling && sibling != pastEndNode && !sibling->contains(pastEndNode) && (!isBlock(sibling.get()) || sibling->hasTagName(brTag)) && !containsNonEditableRegion(*sibling)) {
    797798            runEnd = sibling;
    798799            sibling = runEnd->nextSibling();
     
    800801        next = NodeTraversal::nextSkippingChildren(*runEnd);
    801802
    802         Node* pastEndNode = NodeTraversal::nextSkippingChildren(*runEnd);
    803         if (!shouldApplyInlineStyleToRun(style, runStart, pastEndNode))
     803        auto pastEndNode = makeRefPtr(NodeTraversal::nextSkippingChildren(*runEnd));
     804        if (!shouldApplyInlineStyleToRun(style, runStart.get(), pastEndNode.get()))
    804805            continue;
    805806
    806         runs.append(InlineRunToApplyStyle(runStart, runEnd, pastEndNode));
     807        runs.append(InlineRunToApplyStyle(runStart.get(), runEnd.get(), pastEndNode.get()));
    807808    }
    808809
     
    836837    ASSERT(runStart);
    837838
    838     for (Node* node = runStart; node && node != pastEndNode; node = NodeTraversal::next(*node)) {
     839    for (auto node = makeRefPtr(runStart); node && node != pastEndNode; node = NodeTraversal::next(*node)) {
    839840        if (node->hasChildNodes())
    840841            continue;
     
    842843        if (!style.styleIsPresentInComputedStyleOfNode(*node))
    843844            return true;
    844         if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode(node), m_styledInlineElement->tagQName()))
     845        if (m_styledInlineElement && !enclosingElementWithTag(positionBeforeNode(node.get()), m_styledInlineElement->tagQName()))
    845846            return true;
    846847    }
     
    962963}
    963964
    964 HTMLElement* ApplyStyleCommand::highestAncestorWithConflictingInlineStyle(EditingStyle& style, Node* node)
     965RefPtr<HTMLElement> ApplyStyleCommand::highestAncestorWithConflictingInlineStyle(EditingStyle& style, Node* node)
    965966{
    966967    if (!node)
    967968        return nullptr;
    968969
    969     HTMLElement* result = nullptr;
    970     Node* unsplittableElement = unsplittableElementForPosition(firstPositionInOrBeforeNode(node));
    971 
    972     for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
     970    RefPtr<HTMLElement> result;
     971    auto unsplittableElement = makeRefPtr(unsplittableElementForPosition(firstPositionInOrBeforeNode(node)));
     972
     973    for (auto ancestor = makeRefPtr(node); ancestor; ancestor = ancestor->parentNode()) {
    973974        if (is<HTMLElement>(*ancestor) && shouldRemoveInlineStyleFromElement(style, downcast<HTMLElement>(*ancestor)))
    974             result = downcast<HTMLElement>(ancestor);
     975            result = static_pointer_cast<HTMLElement>(ancestor);
    975976        // Should stop at the editable root (cannot cross editing boundary) and
    976977        // also stop at the unsplittable element to be consistent with other UAs
     
    10021003    }
    10031004
    1004     if (node.renderer()->isText() && static_cast<RenderText*>(node.renderer())->isAllCollapsibleWhitespace())
    1005         return;
    1006     if (node.renderer()->isBR() && !node.renderer()->style().preserveNewline())
    1007         return;
     1005    {
     1006        ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     1007
     1008        if (node.renderer()->isText() && static_cast<RenderText*>(node.renderer())->isAllCollapsibleWhitespace())
     1009            return;
     1010        if (node.renderer()->isBR() && !node.renderer()->style().preserveNewline())
     1011            return;
     1012    }
    10081013
    10091014    // We can't wrap node with the styled element here because new styled element will never be removed if we did.
     
    10151020void ApplyStyleCommand::pushDownInlineStyleAroundNode(EditingStyle& style, Node* targetNode)
    10161021{
    1017     HTMLElement* highestAncestor = highestAncestorWithConflictingInlineStyle(style, targetNode);
     1022    auto highestAncestor = highestAncestorWithConflictingInlineStyle(style, targetNode);
    10181023    if (!highestAncestor)
    10191024        return;
     
    10771082    // Move it to the next deep quivalent position to avoid removing the style from this node.
    10781083    // e.g. if pushDownStart was at Position("hello", 5) in <b>hello<div>world</div></b>, we want Position("world", 0) instead.
    1079     auto* pushDownStartContainer = pushDownStart.containerNode();
     1084    auto pushDownStartContainer = makeRefPtr(pushDownStart.containerNode());
    10801085    if (is<Text>(pushDownStartContainer) && static_cast<unsigned>(pushDownStart.computeOffsetInContainerNode()) == downcast<Text>(*pushDownStartContainer).length())
    10811086        pushDownStart = nextVisuallyDistinctCandidate(pushDownStart);
     
    10831088    // Move it to the previous deep equivalent position to avoid removing the style from this node.
    10841089    Position pushDownEnd = end.upstream();
    1085     auto* pushDownEndContainer = pushDownEnd.containerNode();
     1090    auto pushDownEndContainer = makeRefPtr(pushDownEnd.containerNode());
    10861091    if (is<Text>(pushDownEndContainer) && !pushDownEnd.computeOffsetInContainerNode())
    10871092        pushDownEnd = previousVisuallyDistinctCandidate(pushDownEnd);
     
    12441249bool ApplyStyleCommand::mergeStartWithPreviousIfIdentical(const Position& start, const Position& end)
    12451250{
    1246     auto* startNode = start.containerNode();
     1251    auto startNode = makeRefPtr(start.containerNode());
    12471252    if (start.computeOffsetInContainerNode())
    12481253        return false;
    12491254
    1250     if (isAtomicNode(startNode)) {
     1255    if (isAtomicNode(startNode.get())) {
    12511256        // note: prior siblings could be unrendered elements. it's silly to miss the
    12521257        // merge opportunity just for that.
     
    12571262    }
    12581263
    1259     auto* previousSibling = startNode->previousSibling();
     1264    auto previousSibling = makeRefPtr(startNode->previousSibling());
    12601265    if (!previousSibling || !areIdenticalElements(*startNode, *previousSibling))
    12611266        return false;
     
    12701275    unsigned startOffset = startChild->computeNodeIndex();
    12711276    unsigned endOffset = end.deprecatedEditingOffset() + (startNode == end.deprecatedNode() ? startOffset : 0);
    1272     updateStartEnd({ startNode, startOffset, Position::PositionIsOffsetInAnchor },
     1277    updateStartEnd({ startNode.get(), startOffset, Position::PositionIsOffsetInAnchor },
    12731278        { end.deprecatedNode(), endOffset, Position::PositionIsOffsetInAnchor });
    12741279    return true;
     
    12771282bool ApplyStyleCommand::mergeEndWithNextIfIdentical(const Position& start, const Position& end)
    12781283{
    1279     Node* endNode = end.containerNode();
    1280 
    1281     if (isAtomicNode(endNode)) {
     1284    auto endNode = makeRefPtr(end.containerNode());
     1285
     1286    if (isAtomicNode(endNode.get())) {
    12821287        int endOffset = end.computeOffsetInContainerNode();
    1283         if (offsetIsBeforeLastNodeOffset(endOffset, endNode) || end.deprecatedNode()->nextSibling())
     1288        if (offsetIsBeforeLastNodeOffset(endOffset, endNode.get()) || end.deprecatedNode()->nextSibling())
    12841289            return false;
    12851290
     
    12901295        return false;
    12911296
    1292     Node* nextSibling = endNode->nextSibling();
     1297    auto nextSibling = makeRefPtr(endNode->nextSibling());
    12931298    if (!nextSibling || !areIdenticalElements(*endNode, *nextSibling))
    12941299        return false;
     
    13371342
    13381343    if (is<Element>(previousSibling) && previousSibling->hasEditableStyle()) {
    1339         auto* mergedElement = previousSibling->nextSibling();
     1344        auto mergedElement = makeRefPtr(previousSibling->nextSibling());
    13401345        ASSERT(mergedElement);
    13411346        if (mergedElement->hasEditableStyle() && areIdenticalElements(*previousSibling, *mergedElement))
     
    14001405
    14011406    // Find appropriate font and span elements top-down.
    1402     HTMLFontElement* fontContainer = nullptr;
    1403     HTMLElement* styleContainer = nullptr;
     1407    RefPtr<HTMLFontElement> fontContainer;
     1408    RefPtr<HTMLElement> styleContainer;
    14041409    while (startNode == endNode) {
    14051410        if (is<HTMLElement>(*startNode)) {
     
    14981503
    14991504    for (auto& childText : textNodes) {
    1500         Node* next = childText->nextSibling();
     1505        auto next = makeRefPtr(childText->nextSibling());
    15011506        if (!is<Text>(next))
    15021507            continue;
  • trunk/Source/WebCore/editing/ApplyStyleCommand.h

    r274865 r276133  
    8383    bool removeImplicitlyStyledElement(EditingStyle&, HTMLElement&, InlineStyleRemovalMode, EditingStyle* extractedStyle);
    8484    bool removeCSSStyle(EditingStyle&, HTMLElement&, InlineStyleRemovalMode = RemoveIfNeeded, EditingStyle* extractedStyle = nullptr);
    85     HTMLElement* highestAncestorWithConflictingInlineStyle(EditingStyle&, Node*);
     85    RefPtr<HTMLElement> highestAncestorWithConflictingInlineStyle(EditingStyle&, Node*);
    8686    void applyInlineStyleToPushDown(Node&, EditingStyle*);
    8787    void pushDownInlineStyleAroundNode(EditingStyle&, Node*);
     
    114114    void joinChildTextNodes(Node*, const Position& start, const Position& end);
    115115
    116     HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, WritingDirection allowedDirection);
     116    RefPtr<HTMLElement> splitAncestorsWithUnicodeBidi(Node*, bool before, WritingDirection allowedDirection);
    117117    void removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor);
    118118
Note: See TracChangeset for help on using the changeset viewer.