Modified: trunk/Source/WebCore/editing/Editor.cpp (276190 => 276191)
--- trunk/Source/WebCore/editing/Editor.cpp 2021-04-17 02:06:15 UTC (rev 276190)
+++ trunk/Source/WebCore/editing/Editor.cpp 2021-04-17 02:32:54 UTC (rev 276191)
@@ -96,6 +96,7 @@
#include "ReplaceRangeWithTextCommand.h"
#include "ReplaceSelectionCommand.h"
#include "RuntimeEnabledFeatures.h"
+#include "ScriptDisallowedScope.h"
#include "SerializedAttachmentData.h"
#include "Settings.h"
#include "ShadowRoot.h"
@@ -120,6 +121,7 @@
#include "markup.h"
#include <pal/FileSizeFormatter.h>
#include <pal/text/KillRing.h>
+#include <wtf/Scope.h>
#include <wtf/SetForScope.h>
#include <wtf/unicode/CharacterNames.h>
@@ -273,11 +275,10 @@
return selection;
// If the target is a text control, and the current selection is outside of its shadow tree,
// then use the saved selection for that text control.
- if (is<Element>(event->target()) && downcast<Element>(*event->target()).isTextField()) {
- auto& target = downcast<HTMLTextFormControlElement>(*event->target());
+ if (auto target = makeRefPtr(event->target()); is<HTMLTextFormControlElement>(target) && downcast<Element>(*target).isTextField()) {
auto start = selection.start();
- if (start.isNull() || &target != enclosingTextFormControl(start)) {
- if (auto range = target.selection())
+ if (start.isNull() || target != enclosingTextFormControl(start)) {
+ if (auto range = downcast<HTMLTextFormControlElement>(*target).selection())
return { *range, Affinity::Downstream, selection.isDirectional() };
}
}
@@ -608,7 +609,7 @@
void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace)
{
- Element* target = findEventTargetFromSelection();
+ auto target = findEventTargetFromSelection();
if (!target)
return;
target->dispatchEvent(TextEvent::createForPlainTextPaste(document().windowProxy(), pastingText, smartReplace));
@@ -616,7 +617,7 @@
void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
{
- Element* target = findEventTargetFromSelection();
+ auto target = findEventTargetFromSelection();
if (!target)
return;
target->dispatchEvent(TextEvent::createForFragmentPaste(document().windowProxy(), WTFMove(pastingFragment), smartReplace, matchStyle, respectsMailBlockquote));
@@ -660,7 +661,7 @@
if (!client())
return false;
- auto* child = fragment.firstChild();
+ auto child = makeRefPtr(fragment.firstChild());
if (is<CharacterData>(child) && fragment.lastChild() == child)
return client()->shouldInsertText(downcast<CharacterData>(*child).data(), replacingDOMRange, givenAction);
@@ -716,7 +717,7 @@
if (!isContinuousSpellCheckingEnabled())
return;
- Node* nodeToCheck = selection.rootEditableElement();
+ auto nodeToCheck = makeRefPtr(selection.rootEditableElement());
if (!nodeToCheck)
return;
@@ -771,9 +772,9 @@
void Editor::respondToChangedContents(const VisibleSelection& endingSelection)
{
if (AXObjectCache::accessibilityEnabled()) {
- Node* node = endingSelection.start().deprecatedNode();
+ auto node = makeRefPtr(endingSelection.start().deprecatedNode());
if (AXObjectCache* cache = document().existingAXObjectCache())
- cache->postNotification(node, AXObjectCache::AXValueChanged, PostTarget::ObservableParent);
+ cache->postNotification(node.get(), AXObjectCache::AXValueChanged, PostTarget::ObservableParent);
}
updateMarkersForWordsAffectedByEditing(true);
@@ -787,11 +788,11 @@
if (m_document.selection().isNone())
return false;
- Node* startNode;
+ RefPtr<Node> startNode;
if (m_document.selection().isRange()) {
startNode = m_document.selection().selection().start().downstream().deprecatedNode();
- Node* endNode = m_document.selection().selection().end().upstream().deprecatedNode();
- if (enclosingBlock(startNode) != enclosingBlock(endNode))
+ auto endNode = makeRefPtr(m_document.selection().selection().end().upstream().deprecatedNode());
+ if (enclosingBlock(startNode.get()) != enclosingBlock(endNode.get()))
return false;
} else
startNode = m_document.selection().selection().visibleStart().deepEquivalent().deprecatedNode();
@@ -799,6 +800,8 @@
if (!startNode)
return false;
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
auto renderer = startNode->renderer();
while (renderer && !is<RenderBlockFlow>(*renderer))
renderer = renderer->parent();
@@ -818,8 +821,8 @@
if (enclosingElementWithTag(m_document.selection().selection().start(), ulTag))
return TriState::True;
} else if (m_document.selection().isRange()) {
- auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), ulTag);
- auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), ulTag);
+ auto startNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().start(), ulTag));
+ auto endNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().end(), ulTag));
if (startNode && endNode && startNode == endNode)
return TriState::True;
}
@@ -833,8 +836,8 @@
if (enclosingElementWithTag(m_document.selection().selection().start(), olTag))
return TriState::True;
} else if (m_document.selection().isRange()) {
- auto* startNode = enclosingElementWithTag(m_document.selection().selection().start(), olTag);
- auto* endNode = enclosingElementWithTag(m_document.selection().selection().end(), olTag);
+ auto startNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().start(), olTag));
+ auto endNode = makeRefPtr(enclosingElementWithTag(m_document.selection().selection().end(), olTag));
if (startNode && endNode && startNode == endNode)
return TriState::True;
}
@@ -921,9 +924,9 @@
m_lastEditCommand = nullptr;
}
-Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const
+RefPtr<Element> Editor::findEventTargetFrom(const VisibleSelection& selection) const
{
- Element* target = selection.start().element();
+ auto target = makeRefPtr(selection.start().element());
if (!target)
target = document().bodyOrFrameset();
if (!target)
@@ -932,7 +935,7 @@
return target;
}
-Element* Editor::findEventTargetFromSelection() const
+RefPtr<Element> Editor::findEventTargetFromSelection() const
{
return findEventTargetFrom(m_document.selection().selection());
}
@@ -1068,8 +1071,8 @@
static void notifyTextFromControls(Element* startRoot, Element* endRoot)
{
- HTMLTextFormControlElement* startingTextControl = enclosingTextFormControl(firstPositionInOrBeforeNode(startRoot));
- HTMLTextFormControlElement* endingTextControl = enclosingTextFormControl(firstPositionInOrBeforeNode(endRoot));
+ auto startingTextControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(startRoot)));
+ auto endingTextControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(endRoot)));
if (startingTextControl)
startingTextControl->didEditInnerTextValue();
if (endingTextControl && startingTextControl != endingTextControl)
@@ -1099,7 +1102,7 @@
if (!command.shouldDispatchInputEvents())
return true;
- auto* composition = command.composition();
+ auto composition = makeRefPtr(command.composition());
if (!composition)
return true;
@@ -1117,10 +1120,10 @@
document().updateLayout();
ASSERT(command.composition());
- auto& composition = *command.composition();
+ auto composition = makeRef(*command.composition());
VisibleSelection newSelection(command.endingSelection());
- notifyTextFromControls(composition.startingRootEditableElement(), composition.endingRootEditableElement());
+ notifyTextFromControls(composition->startingRootEditableElement(), composition->endingRootEditableElement());
if (command.isTopLevelCommand()) {
// Don't clear the typing style with this selection change. We do those things elsewhere if necessary.
@@ -1132,7 +1135,7 @@
}
if (command.shouldDispatchInputEvents())
- dispatchInputEvents(composition.startingRootEditableElement(), composition.endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), command.inputEventDataTransfer());
+ dispatchInputEvents(composition->startingRootEditableElement(), composition->endingRootEditableElement(), command.inputEventTypeName(), command.inputEventData(), command.inputEventDataTransfer());
if (command.isTopLevelCommand()) {
updateEditorUINowIfScheduled();
@@ -1290,7 +1293,7 @@
// that is contained in the event target.
selection = selectionForCommand(triggeringEvent);
if (selection.isContentEditable()) {
- if (Node* selectionStart = selection.start().deprecatedNode()) {
+ if (auto selectionStart = makeRefPtr(selection.start().deprecatedNode())) {
Ref<Document> document(selectionStart->document());
// Insert the text
@@ -1419,7 +1422,7 @@
if (enclosingTextFormControl(m_document.selection().selection().start()) || (selection && HTMLElement::isInsideImageOverlay(*selection)))
Pasteboard::createForCopyAndPaste(PagePasteboardContext::create(m_document.pageID()))->writePlainText(selectedTextForDataTransfer(), canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::CannotSmartReplace);
else {
- HTMLImageElement* imageElement = nullptr;
+ RefPtr<HTMLImageElement> imageElement;
if (action == CopyAction)
imageElement = imageElementFromImageDocument(document());
@@ -1545,18 +1548,15 @@
{
if (!startNode)
return;
+
+ RefPtr<Node> pastEndNode;
if (endNode) {
- if (&startNode->document() != &endNode->document())
+ if (!is_lt(treeOrder(*startNode, *endNode)))
return;
- // check if start node is before endNode
- Node* node = startNode;
- while (node && node != endNode)
- node = NodeTraversal::next(*node);
- if (!node)
- return;
+ pastEndNode = NodeTraversal::next(*endNode);
}
- SimplifyMarkupCommand::create(document(), startNode, endNode ? NodeTraversal::next(*endNode) : nullptr)->apply();
+ SimplifyMarkupCommand::create(document(), startNode, pastEndNode.get())->apply();
}
void Editor::copyURL(const URL& url, const String& title)
@@ -1594,7 +1594,7 @@
void Editor::copyImage(const HitTestResult& result)
{
- Element* element = result.innerNonSharedElement();
+ auto element = makeRefPtr(result.innerNonSharedElement());
if (!element)
return;
@@ -1876,8 +1876,8 @@
&& baseWritingDirectionForSelectionStart() == direction)
return;
#endif
-
- Element* focusedElement = document().focusedElement();
+
+ auto focusedElement = makeRefPtr(document().focusedElement());
if (focusedElement && focusedElement->isTextField()) {
if (direction == WritingDirection::Natural)
return;
@@ -1904,10 +1904,12 @@
auto result = WritingDirection::LeftToRight;
Position pos = m_document.selection().selection().visibleStart().deepEquivalent();
- Node* node = pos.deprecatedNode();
+ auto node = makeRefPtr(pos.deprecatedNode());
if (!node)
return result;
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
auto renderer = node->renderer();
if (!renderer)
return result;
@@ -2075,7 +2077,7 @@
client()->startDelayingAndCoalescingContentChangeNotifications();
#endif
- Element* target = document().focusedElement();
+ auto target = makeRefPtr(document().focusedElement());
if (target) {
// Dispatch an appropriate composition event to the focused node.
// We check the composition status and choose an appropriate composition event since this
@@ -2125,13 +2127,13 @@
// Find out what node has the composition now.
Position base = m_document.selection().selection().base().downstream();
Position extent = m_document.selection().selection().extent();
- Node* baseNode = base.deprecatedNode();
+ auto baseNode = makeRefPtr(base.deprecatedNode());
unsigned baseOffset = base.deprecatedEditingOffset();
- Node* extentNode = extent.deprecatedNode();
+ auto extentNode = makeRefPtr(extent.deprecatedNode());
unsigned extentOffset = extent.deprecatedEditingOffset();
if (is<Text>(baseNode) && baseNode == extentNode && baseOffset + text.length() == extentOffset) {
- m_compositionNode = downcast<Text>(baseNode);
+ m_compositionNode = static_pointer_cast<Text>(baseNode);
m_compositionStart = baseOffset;
m_compositionEnd = extentOffset;
m_customCompositionUnderlines = underlines;
@@ -2239,7 +2241,7 @@
}
// topNode defines the whole range we want to operate on
- auto* topNode = highestEditableRoot(position);
+ auto topNode = makeRefPtr(highestEditableRoot(position));
if (topNode)
spellingSearchRange.end = makeBoundaryPointAfterNodeContents(*topNode);
@@ -2551,8 +2553,7 @@
if (nextPosition.isNull() || nextPosition == spellCheckingEnd)
break;
- auto* container = nextPosition.deepEquivalent().upstream().containerNode();
- if (auto* containerElement = is<Element>(container) ? downcast<Element>(container) : container->parentElement()) {
+ if (auto containerElement = makeRefPtr(nextPosition.deepEquivalent().upstream().containerOrParentElement())) {
if (!containerElement->isSpellCheckingEnabled())
break;
}
@@ -2661,11 +2662,11 @@
{
if (!node)
return false;
- Element* element = is<Element>(*node) ? downcast<Element>(node) : node->parentElement();
+ auto element = makeRefPtr(is<Element>(*node) ? downcast<Element>(node) : node->parentElement());
if (!element)
return false;
if (element->isInUserAgentShadowTree()) {
- if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(firstPositionInOrBeforeNode(element)))
+ if (auto textControl = makeRefPtr(enclosingTextFormControl(firstPositionInOrBeforeNode(element.get()))))
return textControl->isSpellCheckingEnabled();
}
return element->isSpellCheckingEnabled();
@@ -2704,11 +2705,11 @@
return;
// If we're not in an editable node, bail.
- Node& editableNode = spellingRange->startContainer();
- if (!editableNode.hasEditableStyle())
+ auto editableNode = makeRef(spellingRange->startContainer());
+ if (!editableNode->hasEditableStyle())
return;
- if (!isSpellCheckingEnabledFor(&editableNode))
+ if (!isSpellCheckingEnabledFor(editableNode.ptr()))
return;
auto& rangeToCheck = shouldMarkGrammar ? *grammarRange : *spellingRange;
@@ -2900,8 +2901,8 @@
correctSpellcheckingPreservingTextCheckingParagraph(paragraph, rangeToReplace, replacement, { resultLocation, resultLength });
if (AXObjectCache* cache = document().existingAXObjectCache()) {
- if (Element* root = m_document.selection().selection().rootEditableElement())
- cache->postNotification(root, AXObjectCache::AXAutocorrectionOccured);
+ if (auto root = makeRefPtr(m_document.selection().selection().rootEditableElement()))
+ cache->postNotification(root.get(), AXObjectCache::AXAutocorrectionOccured);
}
// Skip all other results for the replaced text.
@@ -3670,8 +3671,7 @@
static Vector<SimpleRange> scanForTelephoneNumbers(const SimpleRange& range)
{
// Don't scan for phone numbers inside editable regions.
- auto& startNode = range.startContainer();
- if (startNode.hasEditableStyle())
+ if (auto startNode = makeRef(range.startContainer()); startNode->hasEditableStyle())
return { };
auto text = plainText(range);
Vector<SimpleRange> result;
@@ -3706,27 +3706,34 @@
return;
m_detectedTelephoneNumberRanges.clear();
+
+ auto notifyController = makeScopeExit([&] {
+ if (auto* page = m_document.page())
+ page->servicesOverlayController().selectedTelephoneNumberRangesChanged();
+ });
- auto& selection = m_document.selection();
- if (selection.isRange()) {
- if (auto selectedRange = selection.selection().firstRange()) {
- // Extend the range a few characters in each direction to detect incompletely selected phone numbers.
- constexpr unsigned charactersToExtend = 15;
- if (auto extendedRange = extendSelection(*selectedRange, charactersToExtend)) {
- for (auto& range : scanForTelephoneNumbers(*extendedRange)) {
- // FIXME: Why do we do this unconditionally instead of when only when it overlaps the selection?
- addMarker(range, DocumentMarker::TelephoneNumber);
+ auto selection = m_document.selection().selection();
+ if (!selection.isRange())
+ return;
- // Only consider ranges with a detected telephone number if they overlap with the selection.
- if (intersects<ComposedTree>(range, *selectedRange))
- m_detectedTelephoneNumberRanges.append(range);
- }
- }
- }
+ auto selectedRange = selection.firstRange();
+ if (!selectedRange)
+ return;
+
+ // Extend the range a few characters in each direction to detect incompletely selected phone numbers.
+ constexpr unsigned charactersToExtend = 15;
+ auto extendedRange = extendSelection(*selectedRange, charactersToExtend);
+ if (!extendedRange)
+ return;
+
+ for (auto& range : scanForTelephoneNumbers(*extendedRange)) {
+ // FIXME: Why do we do this unconditionally instead of when only when it overlaps the selection?
+ addMarker(range, DocumentMarker::TelephoneNumber);
+
+ // Only consider ranges with a detected telephone number if they overlap with the selection.
+ if (intersects<ComposedTree>(range, *selectedRange))
+ m_detectedTelephoneNumberRanges.append(range);
}
-
- if (auto* page = m_document.page())
- page->servicesOverlayController().selectedTelephoneNumberRangesChanged();
}
#endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && !PLATFORM(IOS_FAMILY)
@@ -3812,14 +3819,18 @@
#endif
}
-static Node* findFirstMarkable(Node* node)
+static RefPtr<Node> findFirstMarkable(Node* startingNode)
{
+ auto node = makeRefPtr(startingNode);
while (node) {
- if (!node->renderer())
- return nullptr;
- if (node->renderer()->isTextOrLineBreak())
- return node;
- if (is<Element>(*node) && downcast<Element>(*node).isTextField())
+ {
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+ if (!node->renderer())
+ return nullptr;
+ if (node->renderer()->isTextOrLineBreak())
+ return node;
+ }
+ if (is<HTMLTextFormControlElement>(*node) && downcast<Element>(*node).isTextField())
node = downcast<HTMLTextFormControlElement>(*node).visiblePositionForIndex(1).deepEquivalent().deprecatedNode();
else if (node->firstChild())
node = node->firstChild();
@@ -3832,7 +3843,7 @@
bool Editor::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
{
- Node* node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());
+ auto node = findFirstMarkable(m_document.selection().selection().start().deprecatedNode());
if (!node)
return false;
@@ -3851,7 +3862,7 @@
{
#if USE(AUTOMATIC_TEXT_REPLACEMENT) && !PLATFORM(IOS_FAMILY)
bool _onlyAllowsTextReplacement_ = false;
- if (auto* host = rootEditableElement.shadowHost())
+ if (auto host = makeRefPtr(rootEditableElement.shadowHost()))
_onlyAllowsTextReplacement_ = is<HTMLInputElement>(host) && downcast<HTMLInputElement>(*host).isSpellcheckDisabledExceptTextReplacement();
if (onlyAllowsTextReplacement)
textCheckingOptions = textCheckingOptions & TextCheckingType::Replacement;
@@ -3911,9 +3922,7 @@
String Editor::stringForCandidateRequest() const
{
auto& selection = m_document.selection().selection();
- auto range = selection.isCaret()
- ? wordRangeFromPosition(selection.start())
- : selection.toNormalizedRange();
+ auto range = selection.isCaret() ? wordRangeFromPosition(selection.start()) : selection.toNormalizedRange();
if (!range)
return { };
if (!candidateWouldReplaceText(selection))
@@ -3989,17 +3998,21 @@
return textLists;
}
-FontAttributes Editor::fontAttributesAtSelectionStart() const
+FontAttributes Editor::fontAttributesAtSelectionStart()
{
- FontAttributes attributes;
- Node* nodeToRemove = nullptr;
- auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove);
- if (!style) {
+ RefPtr<Node> nodeToRemove;
+ auto nodeRemovalScope = WTF::makeScopeExit([&nodeToRemove]() {
if (nodeToRemove)
nodeToRemove->remove();
- return attributes;
- }
+ });
+ auto* style = styleForSelectionStart(nodeToRemove);
+ if (!style)
+ return { };
+
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
+ FontAttributes attributes;
platformFontAttributesAtSelectionStart(attributes, *style);
// FIXME: for now, always report the colors after applying -apple-color-filter. In future not all clients
@@ -4081,9 +4094,6 @@
attributes.hasUnderline = true;
}
- if (nodeToRemove)
- nodeToRemove->remove();
-
return attributes;
}
@@ -4110,7 +4120,7 @@
getPasteboardTypesAndDataForAttachment(element, additionalTypes, additionalData);
#endif
- if (auto* file = attachment->file())
+ if (auto file = makeRefPtr(attachment->file()))
return { file->url(), platformContentTypeForBlobType(file->type()), file->name(), { }, WTFMove(additionalTypes), WTFMove(additionalData) };
return { { }, { }, { }, attachment->uniqueIdentifier(), WTFMove(additionalTypes), WTFMove(additionalData) };
@@ -4253,53 +4263,58 @@
}
// FIXME: This figures out the current style by inserting a <span>!
-const RenderStyle* Editor::styleForSelectionStart(Frame* frame, Node*& nodeToRemove)
+const RenderStyle* Editor::styleForSelectionStart(RefPtr<Node>& nodeToRemove)
{
nodeToRemove = nullptr;
- if (frame->selection().isNone())
+ if (document().selection().isNone())
return nullptr;
- Position position = adjustedSelectionStartForStyleComputation(frame->selection().selection());
+ Position position = adjustedSelectionStartForStyleComputation(document().selection().selection());
if (!position.isCandidate() || position.isNull())
return nullptr;
- RefPtr<EditingStyle> typingStyle = frame->selection().typingStyle();
+ auto typingStyle = makeRefPtr(document().selection().typingStyle());
if (!typingStyle || !typingStyle->style())
return &position.deprecatedNode()->renderer()->style();
- auto styleElement = HTMLSpanElement::create(*frame->document());
+ auto styleElement = HTMLSpanElement::create(document());
String styleText = typingStyle->style()->asText() + " display: inline";
styleElement->setAttribute(HTMLNames::styleAttr, styleText);
- styleElement->appendChild(frame->document()->createEditingTextNode(emptyString()));
+ styleElement->appendChild(document().createEditingTextNode(emptyString()));
auto positionNode = position.deprecatedNode();
- if (!positionNode || !positionNode->parentNode() || positionNode->parentNode()->appendChild(styleElement).hasException())
+ ASSERT(positionNode);
+ auto parent = makeRefPtr(positionNode->parentNode());
+ if (!parent || parent->appendChild(styleElement.get()).hasException())
return nullptr;
nodeToRemove = styleElement.ptr();
-
- frame->document()->updateStyleIfNeeded();
+
+ document().updateStyleIfNeeded();
return styleElement->renderer() ? &styleElement->renderer()->style() : nullptr;
}
-const Font* Editor::fontForSelection(bool& hasMultipleFonts) const
+RefPtr<Font> Editor::fontForSelection(bool& hasMultipleFonts)
{
hasMultipleFonts = false;
if (!m_document.selection().isRange()) {
- Node* nodeToRemove;
- auto* style = styleForSelectionStart(m_document.frame(), nodeToRemove); // sets nodeToRemove
-
- const Font* font = nullptr;
- if (style) {
- font = &style->fontCascade().primaryFont();
- if (nodeToRemove)
- nodeToRemove->remove();
+ RefPtr<Node> nodeToRemove;
+ RefPtr<Font> font;
+ {
+ auto* style = styleForSelectionStart(nodeToRemove);
+ if (!style)
+ return nullptr;
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+ font = const_cast<Font*>(&style->fontCascade().primaryFont());
}
+ if (nodeToRemove)
+ nodeToRemove->remove();
+
return font;
}
@@ -4313,7 +4328,9 @@
return nullptr;
range->start = *adjustedStart;
- const Font* font = nullptr;
+ ScriptDisallowedScope::InMainThread scriptDisallowedScope;
+
+ RefPtr<Font> font;
for (auto& node : intersectingNodes(*range)) {
auto renderer = node.renderer();
if (!renderer)
@@ -4320,7 +4337,7 @@
continue;
auto& primaryFont = renderer->style().fontCascade().primaryFont();
if (!font)
- font = &primaryFont;
+ font = const_cast<Font*>(&primaryFont);
else if (font != &primaryFont) {
hasMultipleFonts = true;
break;