Changeset 276191 in webkit
- Timestamp:
- Apr 16, 2021, 7:32:54 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 14 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/dom/Position.cpp (modified) (1 diff)
-
WebCore/dom/Position.h (modified) (1 diff)
-
WebCore/editing/Editor.cpp (modified) (43 diffs)
-
WebCore/editing/Editor.h (modified) (3 diffs)
-
WebCore/page/DragController.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/mac/WebPageMac.mm (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebFrame.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebHTMLView.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebView.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r276187 r276191 1 2021-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 1 57 2021-04-16 Darin Adler <darin@apple.com> 2 58 -
trunk/Source/WebCore/dom/Position.cpp
r275320 r276191 198 198 } 199 199 200 Element* 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 200 210 int Position::computeOffsetInContainerNode() const 201 211 { -
trunk/Source/WebCore/dom/Position.h
r271705 r276191 84 84 WEBCORE_EXPORT Node* containerNode() const; // null for a before/after position anchored to a node with no parent 85 85 Text* containerText() const; 86 Element* containerOrParentElement() const; 86 87 87 88 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions -
trunk/Source/WebCore/editing/Editor.cpp
r274796 r276191 97 97 #include "ReplaceSelectionCommand.h" 98 98 #include "RuntimeEnabledFeatures.h" 99 #include "ScriptDisallowedScope.h" 99 100 #include "SerializedAttachmentData.h" 100 101 #include "Settings.h" … … 121 122 #include <pal/FileSizeFormatter.h> 122 123 #include <pal/text/KillRing.h> 124 #include <wtf/Scope.h> 123 125 #include <wtf/SetForScope.h> 124 126 #include <wtf/unicode/CharacterNames.h> … … 274 276 // If the target is a text control, and the current selection is outside of its shadow tree, 275 277 // 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()) { 278 279 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()) 281 282 return { *range, Affinity::Downstream, selection.isDirectional() }; 282 283 } … … 609 610 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) 610 611 { 611 Element*target = findEventTargetFromSelection();612 auto target = findEventTargetFromSelection(); 612 613 if (!target) 613 614 return; … … 617 618 void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote) 618 619 { 619 Element*target = findEventTargetFromSelection();620 auto target = findEventTargetFromSelection(); 620 621 if (!target) 621 622 return; … … 661 662 return false; 662 663 663 auto * child = fragment.firstChild();664 auto child = makeRefPtr(fragment.firstChild()); 664 665 if (is<CharacterData>(child) && fragment.lastChild() == child) 665 666 return client()->shouldInsertText(downcast<CharacterData>(*child).data(), replacingDOMRange, givenAction); … … 717 718 return; 718 719 719 Node* nodeToCheck = selection.rootEditableElement();720 auto nodeToCheck = makeRefPtr(selection.rootEditableElement()); 720 721 if (!nodeToCheck) 721 722 return; … … 772 773 { 773 774 if (AXObjectCache::accessibilityEnabled()) { 774 Node* node = endingSelection.start().deprecatedNode();775 auto node = makeRefPtr(endingSelection.start().deprecatedNode()); 775 776 if (AXObjectCache* cache = document().existingAXObjectCache()) 776 cache->postNotification(node , AXObjectCache::AXValueChanged, PostTarget::ObservableParent);777 cache->postNotification(node.get(), AXObjectCache::AXValueChanged, PostTarget::ObservableParent); 777 778 } 778 779 … … 788 789 return false; 789 790 790 Node*startNode;791 RefPtr<Node> startNode; 791 792 if (m_document.selection().isRange()) { 792 793 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())) 795 796 return false; 796 797 } else … … 799 800 if (!startNode) 800 801 return false; 802 803 ScriptDisallowedScope::InMainThread scriptDisallowedScope; 801 804 802 805 auto renderer = startNode->renderer(); … … 819 822 return TriState::True; 820 823 } 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)); 823 826 if (startNode && endNode && startNode == endNode) 824 827 return TriState::True; … … 834 837 return TriState::True; 835 838 } 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)); 838 841 if (startNode && endNode && startNode == endNode) 839 842 return TriState::True; … … 922 925 } 923 926 924 Element*Editor::findEventTargetFrom(const VisibleSelection& selection) const925 { 926 Element* target = selection.start().element();927 RefPtr<Element> Editor::findEventTargetFrom(const VisibleSelection& selection) const 928 { 929 auto target = makeRefPtr(selection.start().element()); 927 930 if (!target) 928 931 target = document().bodyOrFrameset(); … … 933 936 } 934 937 935 Element*Editor::findEventTargetFromSelection() const938 RefPtr<Element> Editor::findEventTargetFromSelection() const 936 939 { 937 940 return findEventTargetFrom(m_document.selection().selection()); … … 1069 1072 static void notifyTextFromControls(Element* startRoot, Element* endRoot) 1070 1073 { 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))); 1073 1076 if (startingTextControl) 1074 1077 startingTextControl->didEditInnerTextValue(); … … 1100 1103 return true; 1101 1104 1102 auto * composition = command.composition();1105 auto composition = makeRefPtr(command.composition()); 1103 1106 if (!composition) 1104 1107 return true; … … 1118 1121 1119 1122 ASSERT(command.composition()); 1120 auto & composition = *command.composition();1123 auto composition = makeRef(*command.composition()); 1121 1124 VisibleSelection newSelection(command.endingSelection()); 1122 1125 1123 notifyTextFromControls(composition .startingRootEditableElement(), composition.endingRootEditableElement());1126 notifyTextFromControls(composition->startingRootEditableElement(), composition->endingRootEditableElement()); 1124 1127 1125 1128 if (command.isTopLevelCommand()) { … … 1133 1136 1134 1137 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()); 1136 1139 1137 1140 if (command.isTopLevelCommand()) { … … 1291 1294 selection = selectionForCommand(triggeringEvent); 1292 1295 if (selection.isContentEditable()) { 1293 if ( Node* selectionStart = selection.start().deprecatedNode()) {1296 if (auto selectionStart = makeRefPtr(selection.start().deprecatedNode())) { 1294 1297 Ref<Document> document(selectionStart->document()); 1295 1298 … … 1420 1423 Pasteboard::createForCopyAndPaste(PagePasteboardContext::create(m_document.pageID()))->writePlainText(selectedTextForDataTransfer(), canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace); 1421 1424 else { 1422 HTMLImageElement* imageElement = nullptr;1425 RefPtr<HTMLImageElement> imageElement; 1423 1426 if (action == CopyAction) 1424 1427 imageElement = imageElementFromImageDocument(document()); … … 1546 1549 if (!startNode) 1547 1550 return; 1551 1552 RefPtr<Node> pastEndNode; 1548 1553 if (endNode) { 1549 if ( &startNode->document() != &endNode->document())1554 if (!is_lt(treeOrder(*startNode, *endNode))) 1550 1555 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); 1557 1557 } 1558 1558 1559 SimplifyMarkupCommand::create(document(), startNode, endNode ? NodeTraversal::next(*endNode) : nullptr)->apply();1559 SimplifyMarkupCommand::create(document(), startNode, pastEndNode.get())->apply(); 1560 1560 } 1561 1561 … … 1595 1595 void Editor::copyImage(const HitTestResult& result) 1596 1596 { 1597 Element* element = result.innerNonSharedElement();1597 auto element = makeRefPtr(result.innerNonSharedElement()); 1598 1598 if (!element) 1599 1599 return; … … 1877 1877 return; 1878 1878 #endif 1879 1880 Element* focusedElement = document().focusedElement();1879 1880 auto focusedElement = makeRefPtr(document().focusedElement()); 1881 1881 if (focusedElement && focusedElement->isTextField()) { 1882 1882 if (direction == WritingDirection::Natural) … … 1905 1905 1906 1906 Position pos = m_document.selection().selection().visibleStart().deepEquivalent(); 1907 Node* node = pos.deprecatedNode();1907 auto node = makeRefPtr(pos.deprecatedNode()); 1908 1908 if (!node) 1909 1909 return result; 1910 1911 ScriptDisallowedScope::InMainThread scriptDisallowedScope; 1910 1912 1911 1913 auto renderer = node->renderer(); … … 2076 2078 #endif 2077 2079 2078 Element* target = document().focusedElement();2080 auto target = makeRefPtr(document().focusedElement()); 2079 2081 if (target) { 2080 2082 // Dispatch an appropriate composition event to the focused node. … … 2126 2128 Position base = m_document.selection().selection().base().downstream(); 2127 2129 Position extent = m_document.selection().selection().extent(); 2128 Node* baseNode = base.deprecatedNode();2130 auto baseNode = makeRefPtr(base.deprecatedNode()); 2129 2131 unsigned baseOffset = base.deprecatedEditingOffset(); 2130 Node* extentNode = extent.deprecatedNode();2132 auto extentNode = makeRefPtr(extent.deprecatedNode()); 2131 2133 unsigned extentOffset = extent.deprecatedEditingOffset(); 2132 2134 2133 2135 if (is<Text>(baseNode) && baseNode == extentNode && baseOffset + text.length() == extentOffset) { 2134 m_compositionNode = downcast<Text>(baseNode);2136 m_compositionNode = static_pointer_cast<Text>(baseNode); 2135 2137 m_compositionStart = baseOffset; 2136 2138 m_compositionEnd = extentOffset; … … 2240 2242 2241 2243 // topNode defines the whole range we want to operate on 2242 auto * topNode = highestEditableRoot(position);2244 auto topNode = makeRefPtr(highestEditableRoot(position)); 2243 2245 if (topNode) 2244 2246 spellingSearchRange.end = makeBoundaryPointAfterNodeContents(*topNode); … … 2552 2554 break; 2553 2555 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())) { 2556 2557 if (!containerElement->isSpellCheckingEnabled()) 2557 2558 break; … … 2662 2663 if (!node) 2663 2664 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()); 2665 2666 if (!element) 2666 2667 return false; 2667 2668 if (element->isInUserAgentShadowTree()) { 2668 if ( HTMLTextFormControlElement* textControl = enclosingTextFormControl(firstPositionInOrBeforeNode(element)))2669 if (auto textControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(element.get())))) 2669 2670 return textControl->isSpellCheckingEnabled(); 2670 2671 } … … 2705 2706 2706 2707 // 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())) 2712 2713 return; 2713 2714 … … 2901 2902 2902 2903 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); 2905 2906 } 2906 2907 … … 3671 3672 { 3672 3673 // 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()) 3675 3675 return { }; 3676 3676 auto text = plainText(range); … … 3707 3707 3708 3708 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 } 3730 3737 } 3731 3738 … … 3813 3820 } 3814 3821 3815 static Node* findFirstMarkable(Node* node) 3816 { 3822 static RefPtr<Node> findFirstMarkable(Node* startingNode) 3823 { 3824 auto node = makeRefPtr(startingNode); 3817 3825 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()) 3823 3834 node = downcast<HTMLTextFormControlElement>(*node).visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); 3824 3835 else if (node->firstChild()) … … 3833 3844 bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const 3834 3845 { 3835 Node*node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());3846 auto node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode()); 3836 3847 if (!node) 3837 3848 return false; … … 3852 3863 #if USE(AUTOMATIC_TEXT_REPLACEMENT) && !PLATFORM(IOS_FAMILY) 3853 3864 bool onlyAllowsTextReplacement = false; 3854 if (auto * host = rootEditableElement.shadowHost())3865 if (auto host = makeRefPtr(rootEditableElement.shadowHost())) 3855 3866 onlyAllowsTextReplacement = is<HTMLInputElement>(host) && downcast<HTMLInputElement>(*host).isSpellcheckDisabledExceptTextReplacement(); 3856 3867 if (onlyAllowsTextReplacement) … … 3912 3923 { 3913 3924 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(); 3917 3926 if (!range) 3918 3927 return { }; … … 3990 3999 } 3991 4000 3992 FontAttributes Editor::fontAttributesAtSelectionStart() const 3993 { 3994 FontAttributes attributes; 3995 Node* nodeToRemove = nullptr; 3996 auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove); 3997 if (!style) { 4001 FontAttributes Editor::fontAttributesAtSelectionStart() 4002 { 4003 RefPtr<Node> nodeToRemove; 4004 auto nodeRemovalScope = WTF::makeScopeExit([&nodeToRemove]() { 3998 4005 if (nodeToRemove) 3999 4006 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; 4003 4016 platformFontAttributesAtSelectionStart(attributes, *style); 4004 4017 … … 4082 4095 } 4083 4096 4084 if (nodeToRemove)4085 nodeToRemove->remove();4086 4087 4097 return attributes; 4088 4098 } … … 4111 4121 #endif 4112 4122 4113 if (auto * file = attachment->file())4123 if (auto file = makeRefPtr(attachment->file())) 4114 4124 return { file->url(), platformContentTypeForBlobType(file->type()), file->name(), { }, WTFMove(additionalTypes), WTFMove(additionalData) }; 4115 4125 … … 4254 4264 4255 4265 // FIXME: This figures out the current style by inserting a <span>! 4256 const RenderStyle* Editor::styleForSelectionStart( Frame* frame, Node*& nodeToRemove)4266 const RenderStyle* Editor::styleForSelectionStart(RefPtr<Node>& nodeToRemove) 4257 4267 { 4258 4268 nodeToRemove = nullptr; 4259 4269 4260 if ( frame->selection().isNone())4270 if (document().selection().isNone()) 4261 4271 return nullptr; 4262 4272 4263 Position position = adjustedSelectionStartForStyleComputation( frame->selection().selection());4273 Position position = adjustedSelectionStartForStyleComputation(document().selection().selection()); 4264 4274 if (!position.isCandidate() || position.isNull()) 4265 4275 return nullptr; 4266 4276 4267 RefPtr<EditingStyle> typingStyle = frame->selection().typingStyle();4277 auto typingStyle = makeRefPtr(document().selection().typingStyle()); 4268 4278 if (!typingStyle || !typingStyle->style()) 4269 4279 return &position.deprecatedNode()->renderer()->style(); 4270 4280 4271 auto styleElement = HTMLSpanElement::create( *frame->document());4281 auto styleElement = HTMLSpanElement::create(document()); 4272 4282 4273 4283 String styleText = typingStyle->style()->asText() + " display: inline"; 4274 4284 styleElement->setAttribute(HTMLNames::styleAttr, styleText); 4275 4285 4276 styleElement->appendChild( frame->document()->createEditingTextNode(emptyString()));4286 styleElement->appendChild(document().createEditingTextNode(emptyString())); 4277 4287 4278 4288 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()) 4280 4292 return nullptr; 4281 4293 4282 4294 nodeToRemove = styleElement.ptr(); 4283 4284 frame->document()->updateStyleIfNeeded();4295 4296 document().updateStyleIfNeeded(); 4285 4297 return styleElement->renderer() ? &styleElement->renderer()->style() : nullptr; 4286 4298 } 4287 4299 4288 const Font* Editor::fontForSelection(bool& hasMultipleFonts) const 4300 RefPtr<Font> Editor::fontForSelection(bool& hasMultipleFonts) 4289 4301 { 4290 4302 hasMultipleFonts = false; 4291 4303 4292 4304 if (!m_document.selection().isRange()) { 4293 Node*nodeToRemove;4294 auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove); // sets nodeToRemove4295 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()); 4301 4313 } 4314 4315 if (nodeToRemove) 4316 nodeToRemove->remove(); 4302 4317 4303 4318 return font; … … 4314 4329 range->start = *adjustedStart; 4315 4330 4316 const Font* font = nullptr; 4331 ScriptDisallowedScope::InMainThread scriptDisallowedScope; 4332 4333 RefPtr<Font> font; 4317 4334 for (auto& node : intersectingNodes(*range)) { 4318 4335 auto renderer = node.renderer(); … … 4321 4338 auto& primaryFont = renderer->style().fontCascade().primaryFont(); 4322 4339 if (!font) 4323 font = &primaryFont;4340 font = const_cast<Font*>(&primaryFont); 4324 4341 else if (font != &primaryFont) { 4325 4342 hasMultipleFonts = true; -
trunk/Source/WebCore/editing/Editor.h
r273298 r276191 443 443 void markMisspellingsAndBadGrammar(const VisibleSelection&); 444 444 445 Element* findEventTargetFrom(const VisibleSelection& selection) const;445 RefPtr<Element> findEventTargetFrom(const VisibleSelection&) const; 446 446 447 447 WEBCORE_EXPORT String selectedText() const; … … 517 517 RefPtr<DocumentFragment> webContentFromPasteboard(Pasteboard&, const SimpleRange& context, bool allowPlainText, bool& chosePlainText); 518 518 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(); 522 522 523 523 #if PLATFORM(COCOA) … … 606 606 void editorUIUpdateTimerFired(); 607 607 608 Element*findEventTargetFromSelection() const;608 RefPtr<Element> findEventTargetFromSelection() const; 609 609 610 610 bool unifiedTextCheckerEnabled() const; -
trunk/Source/WebCore/page/DragController.cpp
r275988 r276191 527 527 ASSERT(m_page.dragCaretController().hasCaret()); 528 528 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()); 530 530 // FIXME: What guarantees target is not null? 531 531 auto event = TextEvent::createForDrop(&innerFrame->windowProxy(), text); -
trunk/Source/WebKit/ChangeLog
r276189 r276191 1 2021-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 1 15 2021-04-16 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r276181 r276191 1194 1194 1195 1195 const VisibleSelection& selection = frame->selection().selection(); 1196 const Editor& editor = frame->editor();1196 auto& editor = frame->editor(); 1197 1197 1198 1198 result.transactionID = m_lastEditorStateTransactionID.increment(); -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r275988 r276191 2349 2349 bool multipleFonts = false; 2350 2350 CTFontRef font = nil; 2351 if (auto *coreFont = frame.editor().fontForSelection(multipleFonts))2351 if (auto coreFont = frame.editor().fontForSelection(multipleFonts)) 2352 2352 font = coreFont->getCTFont(); 2353 2353 -
trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm
r276177 r276191 385 385 } 386 386 387 auto *font = frame.editor().fontForSelection(selectionHasMultipleFonts);387 auto font = frame.editor().fontForSelection(selectionHasMultipleFonts); 388 388 if (!font) { 389 389 completionHandler({ }, 0, false); -
trunk/Source/WebKitLegacy/mac/ChangeLog
r276181 r276191 1 2021-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 1 15 2021-04-16 Wenson Hsieh <wenson_hsieh@apple.com> 2 16 -
trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm
r276085 r276191 1826 1826 CTFontRef font = nil; 1827 1827 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(); 1831 1830 } 1832 1831 -
trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
r274148 r276191 5742 5742 RetainPtr<NSDictionary> attributes; 5743 5743 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(); 5746 5746 attributes = coreFrame->editor().fontAttributesAtSelectionStart().createDictionary(); 5747 5747 } -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r276181 r276191 9478 9478 const VisibleSelection& selection = coreFrame->selection().selection(); 9479 9479 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)) { 9482 9482 [_private->_textTouchBarItemController setTextIsBold:isFontWeightBold(style->fontCascade().weight())]; 9483 9483 [_private->_textTouchBarItemController setTextIsItalic:isItalic(style->fontCascade().italic())]; … … 9496 9496 [_private->_textTouchBarItemController setCurrentTextAlignment:nsTextAlignmentFromRenderStyle(style)]; 9497 9497 9498 HTMLElement* enclosingListElement = enclosingList(selection.start().deprecatedNode());9498 auto enclosingListElement = makeRefPtr(enclosingList(selection.start().deprecatedNode())); 9499 9499 if (enclosingListElement) { 9500 9500 if (is<HTMLUListElement>(*enclosingListElement))
Note:
See TracChangeset
for help on using the changeset viewer.