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

Changeset 276191 in webkit


Ignore:
Timestamp:
Apr 16, 2021, 7:32:54 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

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

Reviewed by Wenson Hsieh.

Source/WebCore:

Deployed smart pointers in WebCore::Editor.

Also deployed ScriptDisallowedScope around the code which accesses the render tree.

  • dom/Position.cpp:

(WebCore::Position::containerOrParentElement const): Added.

  • dom/Position.h:
  • editing/Editor.cpp:

(WebCore::Editor::selectionForCommand):
(WebCore::Editor::pasteAsPlainText):
(WebCore::Editor::pasteAsFragment):
(WebCore::Editor::shouldInsertFragment):
(WebCore::Editor::replaceSelectionWithFragment):
(WebCore::Editor::respondToChangedContents):
(WebCore::Editor::hasBidiSelection const):
(WebCore::Editor::selectionUnorderedListState const):
(WebCore::Editor::selectionOrderedListState const):
(WebCore::Editor::findEventTargetFrom const):
(WebCore::Editor::findEventTargetFromSelection const):
(WebCore::notifyTextFromControls):
(WebCore::Editor::willApplyEditing const):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::performCutOrCopy):
(WebCore::Editor::simplifyMarkup): Replaced the manual tree traversal by treeOrder(~).
(WebCore::Editor::copyImage):
(WebCore::Editor::setBaseWritingDirection):
(WebCore::Editor::baseWritingDirectionForSelectionStart const):
(WebCore::Editor::setComposition):
(WebCore::Editor::advanceToNextMisspelling):
(WebCore::Editor::markMisspellingsAfterTypingToWord): Use containerOrParentElement.
(WebCore::Editor::isSpellCheckingEnabledFor const):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::markAndReplaceFor):
(WebCore::scanForTelephoneNumbers):
(WebCore::Editor::scanSelectionForTelephoneNumbers): Restrucuted the code with makeScopeExit
to exit early instead of nesting if's.
(WebCore::findFirstMarkable):
(WebCore::Editor::selectionStartHasMarkerFor const):
(WebCore::Editor::resolveTextCheckingTypeMask):
(WebCore::Editor::stringForCandidateRequest const):
(WebCore::Editor::fontAttributesAtSelectionStart):
(WebCore::Editor::promisedAttachmentInfo):
(WebCore::Editor::styleForSelectionStart):
(WebCore::Editor::fontForSelection):

  • editing/Editor.h:
  • page/DragController.cpp:

(WebCore::DragController::dispatchTextInputEventFor):

Source/WebKit:

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::editorState const):

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::requestAutocorrectionData):

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::fontAtSelection):

Source/WebKitLegacy/mac:

  • WebView/WebFrame.mm:

(-[WebFrame fontForSelection:]):

  • WebView/WebHTMLView.mm:

(-[WebHTMLView _updateFontPanel]):

  • WebView/WebView.mm:

(-[WebView updateTextTouchBar]):

Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r276187 r276191  
     12021-04-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy Ref/RefPtr in Editor
     4        https://bugs.webkit.org/show_bug.cgi?id=224708
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Deployed smart pointers in WebCore::Editor.
     9
     10        Also deployed ScriptDisallowedScope around the code which accesses the render tree.
     11
     12        * dom/Position.cpp:
     13        (WebCore::Position::containerOrParentElement const): Added.
     14        * dom/Position.h:
     15        * editing/Editor.cpp:
     16        (WebCore::Editor::selectionForCommand):
     17        (WebCore::Editor::pasteAsPlainText):
     18        (WebCore::Editor::pasteAsFragment):
     19        (WebCore::Editor::shouldInsertFragment):
     20        (WebCore::Editor::replaceSelectionWithFragment):
     21        (WebCore::Editor::respondToChangedContents):
     22        (WebCore::Editor::hasBidiSelection const):
     23        (WebCore::Editor::selectionUnorderedListState const):
     24        (WebCore::Editor::selectionOrderedListState const):
     25        (WebCore::Editor::findEventTargetFrom const):
     26        (WebCore::Editor::findEventTargetFromSelection const):
     27        (WebCore::notifyTextFromControls):
     28        (WebCore::Editor::willApplyEditing const):
     29        (WebCore::Editor::appliedEditing):
     30        (WebCore::Editor::insertTextWithoutSendingTextEvent):
     31        (WebCore::Editor::performCutOrCopy):
     32        (WebCore::Editor::simplifyMarkup): Replaced the manual tree traversal by treeOrder(~).
     33        (WebCore::Editor::copyImage):
     34        (WebCore::Editor::setBaseWritingDirection):
     35        (WebCore::Editor::baseWritingDirectionForSelectionStart const):
     36        (WebCore::Editor::setComposition):
     37        (WebCore::Editor::advanceToNextMisspelling):
     38        (WebCore::Editor::markMisspellingsAfterTypingToWord): Use containerOrParentElement.
     39        (WebCore::Editor::isSpellCheckingEnabledFor const):
     40        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
     41        (WebCore::Editor::markAndReplaceFor):
     42        (WebCore::scanForTelephoneNumbers):
     43        (WebCore::Editor::scanSelectionForTelephoneNumbers): Restrucuted the code with makeScopeExit
     44        to exit early instead of nesting if's.
     45        (WebCore::findFirstMarkable):
     46        (WebCore::Editor::selectionStartHasMarkerFor const):
     47        (WebCore::Editor::resolveTextCheckingTypeMask):
     48        (WebCore::Editor::stringForCandidateRequest const):
     49        (WebCore::Editor::fontAttributesAtSelectionStart):
     50        (WebCore::Editor::promisedAttachmentInfo):
     51        (WebCore::Editor::styleForSelectionStart):
     52        (WebCore::Editor::fontForSelection):
     53        * editing/Editor.h:
     54        * page/DragController.cpp:
     55        (WebCore::DragController::dispatchTextInputEventFor):
     56
    1572021-04-16  Darin Adler  <darin@apple.com>
    258
  • trunk/Source/WebCore/dom/Position.cpp

    r275320 r276191  
    198198}
    199199
     200Element* Position::containerOrParentElement() const
     201{
     202    auto* container = containerNode();
     203    if (!container)
     204        return nullptr;
     205    if (is<Element>(container))
     206        return downcast<Element>(container);
     207    return container->parentElement();
     208}
     209
    200210int Position::computeOffsetInContainerNode() const
    201211{
  • trunk/Source/WebCore/dom/Position.h

    r271705 r276191  
    8484    WEBCORE_EXPORT Node* containerNode() const; // null for a before/after position anchored to a node with no parent
    8585    Text* containerText() const;
     86    Element* containerOrParentElement() const;
    8687
    8788    int computeOffsetInContainerNode() const;  // O(n) for before/after-anchored positions, O(1) for parent-anchored positions
  • trunk/Source/WebCore/editing/Editor.cpp

    r274796 r276191  
    9797#include "ReplaceSelectionCommand.h"
    9898#include "RuntimeEnabledFeatures.h"
     99#include "ScriptDisallowedScope.h"
    99100#include "SerializedAttachmentData.h"
    100101#include "Settings.h"
     
    121122#include <pal/FileSizeFormatter.h>
    122123#include <pal/text/KillRing.h>
     124#include <wtf/Scope.h>
    123125#include <wtf/SetForScope.h>
    124126#include <wtf/unicode/CharacterNames.h>
     
    274276    // If the target is a text control, and the current selection is outside of its shadow tree,
    275277    // then use the saved selection for that text control.
    276     if (is<Element>(event->target()) && downcast<Element>(*event->target()).isTextField()) {
    277         auto& target = downcast<HTMLTextFormControlElement>(*event->target());
     278    if (auto target = makeRefPtr(event->target()); is<HTMLTextFormControlElement>(target) && downcast<Element>(*target).isTextField()) {
    278279        auto start = selection.start();
    279         if (start.isNull() || &target != enclosingTextFormControl(start)) {
    280             if (auto range = target.selection())
     280        if (start.isNull() || target != enclosingTextFormControl(start)) {
     281            if (auto range = downcast<HTMLTextFormControlElement>(*target).selection())
    281282                return { *range, Affinity::Downstream, selection.isDirectional() };
    282283        }
     
    609610void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
    610611{
    611     Element* target = findEventTargetFromSelection();
     612    auto target = findEventTargetFromSelection();
    612613    if (!target)
    613614        return;
     
    617618void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
    618619{
    619     Element* target = findEventTargetFromSelection();
     620    auto target = findEventTargetFromSelection();
    620621    if (!target)
    621622        return;
     
    661662        return false;
    662663   
    663     auto* child = fragment.firstChild();
     664    auto child = makeRefPtr(fragment.firstChild());
    664665    if (is<CharacterData>(child) && fragment.lastChild() == child)
    665666        return client()->shouldInsertText(downcast<CharacterData>(*child).data(), replacingDOMRange, givenAction);
     
    717718        return;
    718719
    719     Node* nodeToCheck = selection.rootEditableElement();
     720    auto nodeToCheck = makeRefPtr(selection.rootEditableElement());
    720721    if (!nodeToCheck)
    721722        return;
     
    772773{
    773774    if (AXObjectCache::accessibilityEnabled()) {
    774         Node* node = endingSelection.start().deprecatedNode();
     775        auto node = makeRefPtr(endingSelection.start().deprecatedNode());
    775776        if (AXObjectCache* cache = document().existingAXObjectCache())
    776             cache->postNotification(node, AXObjectCache::AXValueChanged, PostTarget::ObservableParent);
     777            cache->postNotification(node.get(), AXObjectCache::AXValueChanged, PostTarget::ObservableParent);
    777778    }
    778779
     
    788789        return false;
    789790
    790     Node* startNode;
     791    RefPtr<Node> startNode;
    791792    if (m_document.selection().isRange()) {
    792793        startNode = m_document.selection().selection().start().downstream().deprecatedNode();
    793         Node* endNode = m_document.selection().selection().end().upstream().deprecatedNode();
    794         if (enclosingBlock(startNode) != enclosingBlock(endNode))
     794        auto endNode = makeRefPtr(m_document.selection().selection().end().upstream().deprecatedNode());
     795        if (enclosingBlock(startNode.get()) != enclosingBlock(endNode.get()))
    795796            return false;
    796797    } else
     
    799800    if (!startNode)
    800801        return false;
     802
     803    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
    801804
    802805    auto renderer = startNode->renderer();
     
    819822            return TriState::True;
    820823    } else if (m_document.selection().isRange()) {
    821         auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), ulTag);
    822         auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), ulTag);
     824        auto startNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().start(), ulTag));
     825        auto endNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().end(), ulTag));
    823826        if (startNode && endNode && startNode == endNode)
    824827            return TriState::True;
     
    834837            return TriState::True;
    835838    } else if (m_document.selection().isRange()) {
    836         auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), olTag);
    837         auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), olTag);
     839        auto startNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().start(), olTag));
     840        auto endNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().end(), olTag));
    838841        if (startNode && endNode && startNode == endNode)
    839842            return TriState::True;
     
    922925}
    923926
    924 Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const
    925 {
    926     Element* target = selection.start().element();
     927RefPtr<Element> Editor::findEventTargetFrom(const VisibleSelection& selection) const
     928{
     929    auto target = makeRefPtr(selection.start().element());
    927930    if (!target)
    928931        target = document().bodyOrFrameset();
     
    933936}
    934937
    935 Element* Editor::findEventTargetFromSelection() const
     938RefPtr<Element> Editor::findEventTargetFromSelection() const
    936939{
    937940    return findEventTargetFrom(m_document.selection().selection());
     
    10691072static void notifyTextFromControls(Element* startRoot, Element* endRoot)
    10701073{
    1071     HTMLTextFormControlElement* startingTextControl = enclosingTextFormControl(firstPositionInOrBeforeNode(startRoot));
    1072     HTMLTextFormControlElement* endingTextControl = enclosingTextFormControl(firstPositionInOrBeforeNode(endRoot));
     1074    auto startingTextControl =  makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(startRoot)));
     1075    auto endingTextControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(endRoot)));
    10731076    if (startingTextControl)
    10741077        startingTextControl->didEditInnerTextValue();
     
    11001103        return true;
    11011104
    1102     auto* composition = command.composition();
     1105    auto composition = makeRefPtr(command.composition());
    11031106    if (!composition)
    11041107        return true;
     
    11181121
    11191122    ASSERT(command.composition());
    1120     auto& composition = *command.composition();
     1123    auto composition = makeRef(*command.composition());
    11211124    VisibleSelection newSelection(command.endingSelection());
    11221125
    1123     notifyTextFromControls(composition.startingRootEditableElement(), composition.endingRootEditableElement());
     1126    notifyTextFromControls(composition->startingRootEditableElement(), composition->endingRootEditableElement());
    11241127
    11251128    if (command.isTopLevelCommand()) {
     
    11331136
    11341137    if (command.shouldDispatchInputEvents())
    1135         dispatchInputEvents(composition.startingRootEditableElement(), composition.endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), command.inputEventDataTransfer());
     1138        dispatchInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), command.inputEventDataTransfer());
    11361139
    11371140    if (command.isTopLevelCommand()) {
     
    12911294    selection = selectionForCommand(triggeringEvent);
    12921295    if (selection.isContentEditable()) {
    1293         if (Node* selectionStart = selection.start().deprecatedNode()) {
     1296        if (auto selectionStart = makeRefPtr(selection.start().deprecatedNode())) {
    12941297            Ref<Document> document(selectionStart->document());
    12951298
     
    14201423        Pasteboard::createForCopyAndPaste(PagePasteboardContext::create(m_document.pageID()))->writePlainText(selectedTextForDataTransfer(), canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
    14211424    else {
    1422         HTMLImageElement* imageElement = nullptr;
     1425        RefPtr<HTMLImageElement> imageElement;
    14231426        if (action == CopyAction)
    14241427            imageElement = imageElementFromImageDocument(document());
     
    15461549    if (!startNode)
    15471550        return;
     1551
     1552    RefPtr<Node> pastEndNode;
    15481553    if (endNode) {
    1549         if (&startNode->document() != &endNode->document())
     1554        if (!is_lt(treeOrder(*startNode, *endNode)))
    15501555            return;
    1551         // check if start node is before endNode
    1552         Node* node = startNode;
    1553         while (node && node != endNode)
    1554             node = NodeTraversal::next(*node);
    1555         if (!node)
    1556             return;
     1556        pastEndNode = NodeTraversal::next(*endNode);
    15571557    }
    15581558   
    1559     SimplifyMarkupCommand::create(document(), startNode, endNode ? NodeTraversal::next(*endNode) : nullptr)->apply();
     1559    SimplifyMarkupCommand::create(document(), startNode, pastEndNode.get())->apply();
    15601560}
    15611561
     
    15951595void Editor::copyImage(const HitTestResult& result)
    15961596{
    1597     Element* element = result.innerNonSharedElement();
     1597    auto element = makeRefPtr(result.innerNonSharedElement());
    15981598    if (!element)
    15991599        return;
     
    18771877        return;
    18781878#endif
    1879        
    1880     Element* focusedElement = document().focusedElement();
     1879
     1880    auto focusedElement = makeRefPtr(document().focusedElement());
    18811881    if (focusedElement && focusedElement->isTextField()) {
    18821882        if (direction == WritingDirection::Natural)
     
    19051905
    19061906    Position pos = m_document.selection().selection().visibleStart().deepEquivalent();
    1907     Node* node = pos.deprecatedNode();
     1907    auto node = makeRefPtr(pos.deprecatedNode());
    19081908    if (!node)
    19091909        return result;
     1910
     1911    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
    19101912
    19111913    auto renderer = node->renderer();
     
    20762078#endif
    20772079
    2078     Element* target = document().focusedElement();
     2080    auto target = makeRefPtr(document().focusedElement());
    20792081    if (target) {
    20802082        // Dispatch an appropriate composition event to the focused node.
     
    21262128        Position base = m_document.selection().selection().base().downstream();
    21272129        Position extent = m_document.selection().selection().extent();
    2128         Node* baseNode = base.deprecatedNode();
     2130        auto baseNode = makeRefPtr(base.deprecatedNode());
    21292131        unsigned baseOffset = base.deprecatedEditingOffset();
    2130         Node* extentNode = extent.deprecatedNode();
     2132        auto extentNode = makeRefPtr(extent.deprecatedNode());
    21312133        unsigned extentOffset = extent.deprecatedEditingOffset();
    21322134
    21332135        if (is<Text>(baseNode) && baseNode == extentNode && baseOffset + text.length() == extentOffset) {
    2134             m_compositionNode = downcast<Text>(baseNode);
     2136            m_compositionNode = static_pointer_cast<Text>(baseNode);
    21352137            m_compositionStart = baseOffset;
    21362138            m_compositionEnd = extentOffset;
     
    22402242
    22412243    // topNode defines the whole range we want to operate on
    2242     auto* topNode = highestEditableRoot(position);
     2244    auto topNode = makeRefPtr(highestEditableRoot(position));
    22432245    if (topNode)
    22442246        spellingSearchRange.end = makeBoundaryPointAfterNodeContents(*topNode);
     
    25522554                break;
    25532555
    2554             auto* container = nextPosition.deepEquivalent().upstream().containerNode();
    2555             if (auto* containerElement = is<Element>(container) ? downcast<Element>(container) : container->parentElement()) {
     2556            if (auto containerElement = makeRefPtr(nextPosition.deepEquivalent().upstream().containerOrParentElement())) {
    25562557                if (!containerElement->isSpellCheckingEnabled())
    25572558                    break;
     
    26622663    if (!node)
    26632664        return false;
    2664     Element* element = is<Element>(*node) ? downcast<Element>(node) : node->parentElement();
     2665    auto element = makeRefPtr(is<Element>(*node) ? downcast<Element>(node) : node->parentElement());
    26652666    if (!element)
    26662667        return false;
    26672668    if (element->isInUserAgentShadowTree()) {
    2668         if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(firstPositionInOrBeforeNode(element)))
     2669        if (auto textControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(element.get()))))
    26692670            return textControl->isSpellCheckingEnabled();
    26702671    }
     
    27052706
    27062707    // If we're not in an editable node, bail.
    2707     Node& editableNode = spellingRange->startContainer();
    2708     if (!editableNode.hasEditableStyle())
    2709         return;
    2710 
    2711     if (!isSpellCheckingEnabledFor(&editableNode))
     2708    auto editableNode = makeRef(spellingRange->startContainer());
     2709    if (!editableNode->hasEditableStyle())
     2710        return;
     2711
     2712    if (!isSpellCheckingEnabledFor(editableNode.ptr()))
    27122713        return;
    27132714
     
    29012902
    29022903                if (AXObjectCache* cache = document().existingAXObjectCache()) {
    2903                     if (Element* root = m_document.selection().selection().rootEditableElement())
    2904                         cache->postNotification(root, AXObjectCache::AXAutocorrectionOccured);
     2904                    if (auto root = makeRefPtr(m_document.selection().selection().rootEditableElement()))
     2905                        cache->postNotification(root.get(), AXObjectCache::AXAutocorrectionOccured);
    29052906                }
    29062907
     
    36713672{
    36723673    // Don't scan for phone numbers inside editable regions.
    3673     auto& startNode = range.startContainer();
    3674     if (startNode.hasEditableStyle())
     3674    if (auto startNode = makeRef(range.startContainer()); startNode->hasEditableStyle())
    36753675        return { };
    36763676    auto text = plainText(range);
     
    37073707
    37083708    m_detectedTelephoneNumberRanges.clear();
    3709 
    3710     auto& selection = m_document.selection();
    3711     if (selection.isRange()) {
    3712         if (auto selectedRange = selection.selection().firstRange()) {
    3713             // Extend the range a few characters in each direction to detect incompletely selected phone numbers.
    3714             constexpr unsigned charactersToExtend = 15;
    3715             if (auto extendedRange = extendSelection(*selectedRange, charactersToExtend)) {
    3716                 for (auto& range : scanForTelephoneNumbers(*extendedRange)) {
    3717                     // FIXME: Why do we do this unconditionally instead of when only when it overlaps the selection?
    3718                     addMarker(range, DocumentMarker::TelephoneNumber);
    3719 
    3720                     // Only consider ranges with a detected telephone number if they overlap with the selection.
    3721                     if (intersects<ComposedTree>(range, *selectedRange))
    3722                         m_detectedTelephoneNumberRanges.append(range);
    3723                 }
    3724             }
    3725         }
    3726     }
    3727 
    3728     if (auto* page = m_document.page())
    3729         page->servicesOverlayController().selectedTelephoneNumberRangesChanged();
     3709   
     3710    auto notifyController = makeScopeExit([&] {
     3711        if (auto* page = m_document.page())
     3712            page->servicesOverlayController().selectedTelephoneNumberRangesChanged();
     3713    });
     3714
     3715    auto selection = m_document.selection().selection();
     3716    if (!selection.isRange())
     3717        return;
     3718
     3719    auto selectedRange = selection.firstRange();
     3720    if (!selectedRange)
     3721        return;
     3722
     3723    // Extend the range a few characters in each direction to detect incompletely selected phone numbers.
     3724    constexpr unsigned charactersToExtend = 15;
     3725    auto extendedRange = extendSelection(*selectedRange, charactersToExtend);
     3726    if (!extendedRange)
     3727        return;
     3728
     3729    for (auto& range : scanForTelephoneNumbers(*extendedRange)) {
     3730        // FIXME: Why do we do this unconditionally instead of when only when it overlaps the selection?
     3731        addMarker(range, DocumentMarker::TelephoneNumber);
     3732
     3733        // Only consider ranges with a detected telephone number if they overlap with the selection.
     3734        if (intersects<ComposedTree>(range, *selectedRange))
     3735            m_detectedTelephoneNumberRanges.append(range);
     3736    }
    37303737}
    37313738
     
    38133820}
    38143821
    3815 static Node* findFirstMarkable(Node* node)
    3816 {
     3822static RefPtr<Node> findFirstMarkable(Node* startingNode)
     3823{
     3824    auto node = makeRefPtr(startingNode);
    38173825    while (node) {
    3818         if (!node->renderer())
    3819             return nullptr;
    3820         if (node->renderer()->isTextOrLineBreak())
    3821             return node;
    3822         if (is<Element>(*node) && downcast<Element>(*node).isTextField())
     3826        {
     3827            ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     3828            if (!node->renderer())
     3829                return nullptr;
     3830            if (node->renderer()->isTextOrLineBreak())
     3831                return node;
     3832        }
     3833        if (is<HTMLTextFormControlElement>(*node) && downcast<Element>(*node).isTextField())
    38233834            node = downcast<HTMLTextFormControlElement>(*node).visiblePositionForIndex(1).deepEquivalent().deprecatedNode();
    38243835        else if (node->firstChild())
     
    38333844bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
    38343845{
    3835     Node* node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());
     3846    auto node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());
    38363847    if (!node)
    38373848        return false;
     
    38523863#if USE(AUTOMATIC_TEXT_REPLACEMENT) && !PLATFORM(IOS_FAMILY)
    38533864    bool onlyAllowsTextReplacement = false;
    3854     if (auto* host = rootEditableElement.shadowHost())
     3865    if (auto host = makeRefPtr(rootEditableElement.shadowHost()))
    38553866        onlyAllowsTextReplacement = is<HTMLInputElement>(host) && downcast<HTMLInputElement>(*host).isSpellcheckDisabledExceptTextReplacement();
    38563867    if (onlyAllowsTextReplacement)
     
    39123923{
    39133924    auto& selection = m_document.selection().selection();
    3914     auto range = selection.isCaret()
    3915         ? wordRangeFromPosition(selection.start())
    3916         : selection.toNormalizedRange();
     3925    auto range = selection.isCaret() ? wordRangeFromPosition(selection.start()) : selection.toNormalizedRange();
    39173926    if (!range)
    39183927        return { };
     
    39903999}
    39914000
    3992 FontAttributes Editor::fontAttributesAtSelectionStart() const
    3993 {
    3994     FontAttributes attributes;
    3995     Node* nodeToRemove = nullptr;
    3996     auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove);
    3997     if (!style) {
     4001FontAttributes Editor::fontAttributesAtSelectionStart()
     4002{
     4003    RefPtr<Node> nodeToRemove;
     4004    auto nodeRemovalScope = WTF::makeScopeExit([&nodeToRemove]() {
    39984005        if (nodeToRemove)
    39994006            nodeToRemove->remove();
    4000         return attributes;
    4001     }
    4002 
     4007    });
     4008
     4009    auto* style = styleForSelectionStart(nodeToRemove);
     4010    if (!style)
     4011        return { };
     4012
     4013    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     4014
     4015    FontAttributes attributes;
    40034016    platformFontAttributesAtSelectionStart(attributes, *style);
    40044017
     
    40824095    }
    40834096
    4084     if (nodeToRemove)
    4085         nodeToRemove->remove();
    4086 
    40874097    return attributes;
    40884098}
     
    41114121#endif
    41124122
    4113     if (auto* file = attachment->file())
     4123    if (auto file = makeRefPtr(attachment->file()))
    41144124        return { file->url(), platformContentTypeForBlobType(file->type()), file->name(), { }, WTFMove(additionalTypes), WTFMove(additionalData) };
    41154125
     
    42544264
    42554265// FIXME: This figures out the current style by inserting a <span>!
    4256 const RenderStyle* Editor::styleForSelectionStart(Frame* frame, Node*& nodeToRemove)
     4266const RenderStyle* Editor::styleForSelectionStart(RefPtr<Node>& nodeToRemove)
    42574267{
    42584268    nodeToRemove = nullptr;
    42594269
    4260     if (frame->selection().isNone())
     4270    if (document().selection().isNone())
    42614271        return nullptr;
    42624272
    4263     Position position = adjustedSelectionStartForStyleComputation(frame->selection().selection());
     4273    Position position = adjustedSelectionStartForStyleComputation(document().selection().selection());
    42644274    if (!position.isCandidate() || position.isNull())
    42654275        return nullptr;
    42664276
    4267     RefPtr<EditingStyle> typingStyle = frame->selection().typingStyle();
     4277    auto typingStyle = makeRefPtr(document().selection().typingStyle());
    42684278    if (!typingStyle || !typingStyle->style())
    42694279        return &position.deprecatedNode()->renderer()->style();
    42704280
    4271     auto styleElement = HTMLSpanElement::create(*frame->document());
     4281    auto styleElement = HTMLSpanElement::create(document());
    42724282
    42734283    String styleText = typingStyle->style()->asText() + " display: inline";
    42744284    styleElement->setAttribute(HTMLNames::styleAttr, styleText);
    42754285
    4276     styleElement->appendChild(frame->document()->createEditingTextNode(emptyString()));
     4286    styleElement->appendChild(document().createEditingTextNode(emptyString()));
    42774287
    42784288    auto positionNode = position.deprecatedNode();
    4279     if (!positionNode || !positionNode->parentNode() || positionNode->parentNode()->appendChild(styleElement).hasException())
     4289    ASSERT(positionNode);
     4290    auto parent = makeRefPtr(positionNode->parentNode());
     4291    if (!parent || parent->appendChild(styleElement.get()).hasException())
    42804292        return nullptr;
    42814293
    42824294    nodeToRemove = styleElement.ptr();
    4283    
    4284     frame->document()->updateStyleIfNeeded();
     4295
     4296    document().updateStyleIfNeeded();
    42854297    return styleElement->renderer() ? &styleElement->renderer()->style() : nullptr;
    42864298}
    42874299
    4288 const Font* Editor::fontForSelection(bool& hasMultipleFonts) const
     4300RefPtr<Font> Editor::fontForSelection(bool& hasMultipleFonts)
    42894301{
    42904302    hasMultipleFonts = false;
    42914303
    42924304    if (!m_document.selection().isRange()) {
    4293         Node* nodeToRemove;
    4294         auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove); // sets nodeToRemove
    4295 
    4296         const Font* font = nullptr;
    4297         if (style) {
    4298             font = &style->fontCascade().primaryFont();
    4299             if (nodeToRemove)
    4300                 nodeToRemove->remove();
     4305        RefPtr<Node> nodeToRemove;
     4306        RefPtr<Font> font;
     4307        {
     4308            auto* style = styleForSelectionStart(nodeToRemove);
     4309            if (!style)
     4310                return nullptr;
     4311            ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     4312            font = const_cast<Font*>(&style->fontCascade().primaryFont());
    43014313        }
     4314
     4315        if (nodeToRemove)
     4316            nodeToRemove->remove();
    43024317
    43034318        return font;
     
    43144329    range->start = *adjustedStart;
    43154330
    4316     const Font* font = nullptr;
     4331    ScriptDisallowedScope::InMainThread scriptDisallowedScope;
     4332
     4333    RefPtr<Font> font;
    43174334    for (auto& node : intersectingNodes(*range)) {
    43184335        auto renderer = node.renderer();
     
    43214338        auto& primaryFont = renderer->style().fontCascade().primaryFont();
    43224339        if (!font)
    4323             font = &primaryFont;
     4340            font = const_cast<Font*>(&primaryFont);
    43244341        else if (font != &primaryFont) {
    43254342            hasMultipleFonts = true;
  • trunk/Source/WebCore/editing/Editor.h

    r273298 r276191  
    443443    void markMisspellingsAndBadGrammar(const VisibleSelection&);
    444444
    445     Element* findEventTargetFrom(const VisibleSelection& selection) const;
     445    RefPtr<Element> findEventTargetFrom(const VisibleSelection&) const;
    446446
    447447    WEBCORE_EXPORT String selectedText() const;
     
    517517    RefPtr<DocumentFragment> webContentFromPasteboard(Pasteboard&, const SimpleRange& context, bool allowPlainText, bool& chosePlainText);
    518518
    519     WEBCORE_EXPORT const Font* fontForSelection(bool& hasMultipleFonts) const;
    520     WEBCORE_EXPORT static const RenderStyle* styleForSelectionStart(Frame* , Node *&nodeToRemove);
    521     WEBCORE_EXPORT FontAttributes fontAttributesAtSelectionStart() const;
     519    WEBCORE_EXPORT RefPtr<Font> fontForSelection(bool& hasMultipleFonts);
     520    WEBCORE_EXPORT const RenderStyle* styleForSelectionStart(RefPtr<Node>& nodeToRemove);
     521    WEBCORE_EXPORT FontAttributes fontAttributesAtSelectionStart();
    522522
    523523#if PLATFORM(COCOA)
     
    606606    void editorUIUpdateTimerFired();
    607607
    608     Element* findEventTargetFromSelection() const;
     608    RefPtr<Element> findEventTargetFromSelection() const;
    609609
    610610    bool unifiedTextCheckerEnabled() const;
  • trunk/Source/WebCore/page/DragController.cpp

    r275988 r276191  
    527527    ASSERT(m_page.dragCaretController().hasCaret());
    528528    String text = m_page.dragCaretController().isContentRichlyEditable() ? emptyString() : dragData.asPlainText();
    529     Element* target = innerFrame->editor().findEventTargetFrom(m_page.dragCaretController().caretPosition());
     529    auto target = innerFrame->editor().findEventTargetFrom(m_page.dragCaretController().caretPosition());
    530530    // FIXME: What guarantees target is not null?
    531531    auto event = TextEvent::createForDrop(&innerFrame->windowProxy(), text);
  • trunk/Source/WebKit/ChangeLog

    r276189 r276191  
     12021-04-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy Ref/RefPtr in Editor
     4        https://bugs.webkit.org/show_bug.cgi?id=224708
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebProcess/WebPage/WebPage.cpp:
     9        (WebKit::WebPage::editorState const):
     10        * WebProcess/WebPage/ios/WebPageIOS.mm:
     11        (WebKit::WebPage::requestAutocorrectionData):
     12        * WebProcess/WebPage/mac/WebPageMac.mm:
     13        (WebKit::WebPage::fontAtSelection):
     14
    1152021-04-16  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r276181 r276191  
    11941194
    11951195    const VisibleSelection& selection = frame->selection().selection();
    1196     const Editor& editor = frame->editor();
     1196    auto& editor = frame->editor();
    11971197
    11981198    result.transactionID = m_lastEditorStateTransactionID.increment();
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r275988 r276191  
    23492349    bool multipleFonts = false;
    23502350    CTFontRef font = nil;
    2351     if (auto* coreFont = frame.editor().fontForSelection(multipleFonts))
     2351    if (auto coreFont = frame.editor().fontForSelection(multipleFonts))
    23522352        font = coreFont->getCTFont();
    23532353
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r276177 r276191  
    385385    }
    386386
    387     auto* font = frame.editor().fontForSelection(selectionHasMultipleFonts);
     387    auto font = frame.editor().fontForSelection(selectionHasMultipleFonts);
    388388    if (!font) {
    389389        completionHandler({ }, 0, false);
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r276181 r276191  
     12021-04-16  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Deploy Ref/RefPtr in Editor
     4        https://bugs.webkit.org/show_bug.cgi?id=224708
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebView/WebFrame.mm:
     9        (-[WebFrame fontForSelection:]):
     10        * WebView/WebHTMLView.mm:
     11        (-[WebHTMLView _updateFontPanel]):
     12        * WebView/WebView.mm:
     13        (-[WebView updateTextTouchBar]):
     14
    1152021-04-16  Wenson Hsieh  <wenson_hsieh@apple.com>
    216
  • trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm

    r276085 r276191  
    18261826    CTFontRef font = nil;
    18271827    if (_private->coreFrame) {
    1828         const WebCore::Font* fd = _private->coreFrame->editor().fontForSelection(multipleFonts);
    1829         if (fd)
    1830             font = fd->getCTFont();
     1828        if (auto coreFont = _private->coreFrame->editor().fontForSelection(multipleFonts))
     1829            font = coreFont->getCTFont();
    18311830    }
    18321831   
  • trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

    r274148 r276191  
    57425742    RetainPtr<NSDictionary> attributes;
    57435743    if (auto* coreFrame = core([self _frame])) {
    5744         if (const WebCore::Font* fd = coreFrame->editor().fontForSelection(multipleFonts))
    5745             font = (NSFont *)fd->platformData().registeredFont();
     5744        if (auto coreFont = coreFrame->editor().fontForSelection(multipleFonts))
     5745            font = (NSFont *)coreFont->platformData().registeredFont();
    57465746        attributes = coreFrame->editor().fontAttributesAtSelectionStart().createDictionary();
    57475747    }
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r276181 r276191  
    94789478        const VisibleSelection& selection = coreFrame->selection().selection();
    94799479        if (!selection.isNone()) {
    9480             Node* nodeToRemove;
    9481             if (auto* style = Editor::styleForSelectionStart(coreFrame, nodeToRemove)) {
     9480            RefPtr<Node> nodeToRemove;
     9481            if (auto* style = coreFrame->editor().styleForSelectionStart(nodeToRemove)) {
    94829482                [_private->_textTouchBarItemController setTextIsBold:isFontWeightBold(style->fontCascade().weight())];
    94839483                [_private->_textTouchBarItemController setTextIsItalic:isItalic(style->fontCascade().italic())];
     
    94969496                [_private->_textTouchBarItemController setCurrentTextAlignment:nsTextAlignmentFromRenderStyle(style)];
    94979497
    9498                 HTMLElement* enclosingListElement = enclosingList(selection.start().deprecatedNode());
     9498                auto enclosingListElement = makeRefPtr(enclosingList(selection.start().deprecatedNode()));
    94999499                if (enclosingListElement) {
    95009500                    if (is<HTMLUListElement>(*enclosingListElement))
Note: See TracChangeset for help on using the changeset viewer.