Diff
Modified: trunk/Source/WebCore/ChangeLog (264246 => 264247)
--- trunk/Source/WebCore/ChangeLog 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/ChangeLog 2020-07-10 23:59:56 UTC (rev 264247)
@@ -1,3 +1,70 @@
+2020-07-08 Darin Adler <[email protected]>
+
+ Remove live ranges from Document.h, AlternativeTextController.h, DictionaryLookup.h, and WebPage.h
+ https://bugs.webkit.org/show_bug.cgi?id=214109
+
+ Reviewed by Sam Weinig.
+
+ * accessibility/AXObjectCache.cpp:
+ (WebCore::AXObjectCache::characterOffsetForPoint): Updated to call
+ caretPositionFromPoint, internal function, instead of caretRangeFromPoint,
+ public DOM function.
+
+ * dom/Document.cpp:
+ (WebCore::Document::Document): Changed documentClasses argument to DocumentClassFlags.
+ (WebCore::Document::caretRangeFromPoint): Refactored so this calls createLiveRange,
+ since it's a DOM function that returns a live range.
+ (WebCore::Document::caretPositionFromPoint): Renamed so this is not just an overload
+ and changed to return a BoundaryPoint rather than a live range.
+
+ * dom/Document.h: Simplified forward declarations by getting rid of all the conditionals.
+ Tweaked a few typedef things. Updated for the changes above.
+
+ * editing/AlternativeTextController.cpp:
+ (WebCore::AlternativeTextController::startAlternativeTextUITimer): Updated since
+ m_rangeWithAlternative is an Optional<SimpleRange>.
+ (WebCore::AlternativeTextController::stopAlternativeTextUITimer): Ditto.
+ (WebCore::AlternativeTextController::applyPendingCorrection): Ditto.
+ (WebCore::AlternativeTextController::hasPendingCorrection const): Ditto.
+ (WebCore::AlternativeTextController::isSpellingMarkerAllowed const): Take SimpleRange.
+ (WebCore::AlternativeTextController::show): Ditto.
+ (WebCore::AlternativeTextController::applyAutocorrectionBeforeTypingIfAppropriate):
+ Updated since m_rangeWithAlternative is an Optional<SimpleRange>.
+ (WebCore::AlternativeTextController::timerFired): Ditto.
+ (WebCore::AlternativeTextController::handleAlternativeTextUIResult): Ditto.
+ (WebCore::AlternativeTextController::markReversed): Take SimpleRange.
+ (WebCore::AlternativeTextController::markCorrection): Ditto.
+ (WebCore::AlternativeTextController::recordSpellcheckerResponseForModifiedCorrection): Ditto.
+ (WebCore::AlternativeTextController::processMarkersOnTextToBeReplacedByResult): Ditto.
+ (WebCore::AlternativeTextController::respondToMarkerAtEndOfWord): Use SimpleRange
+ instead of a live range.
+ (WebCore::AlternativeTextController::applyAlternativeTextToRange): Take SimpleRange.
+ * editing/AlternativeTextController.h: Use SimpleRange instead of live ranges.
+
+ * editing/cocoa/DictionaryLookup.mm:
+ (WebCore::DictionaryLookup::rangeForSelection): Return SimpleRange.
+ (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
+ (WebCore::showPopupOrCreateAnimationController): Renamed type from RevealView to CocoaView.
+ (WebCore::DictionaryLookup::showPopup): Ditto.
+ * editing/mac/DictionaryLookup.h: Simplified header since it is included only from
+ Objective-C files. Use SimpleRange instead of live ranges.
+
+ * editing/mac/DictionaryLookupLegacy.mm:
+ (WebCore::DictionaryLookup::rangeForSelection): Return SimpleRange.
+ (WebCore::DictionaryLookup::rangeAtHitTestResult): Ditto.
+
+ * page/mac/EventHandlerMac.mm:
+ (WebCore::EventHandler::selectClosestWordFromHitTestResultBasedOnLookup): Updated
+ since DictionaryLookup::rangeAtHitTestResult returns SimpleRange.
+ (WebCore::autoscrollAdjustmentFactorForScreenBoundaries): Use constexpr instead of
+ macros for constants.
+
+ * testing/Internals.mm:
+ (WebCore::Internals::rangeForDictionaryLookupAtLocation): Updated
+ since DictionaryLookup::rangeAtHitTestResult returns SimpleRange.
+ (WebCore::Internals::encodedPreferenceValue): Removed unneeded error local, and
+ fixed formatting.
+
2020-07-10 Brady Eidson <[email protected]>
GameController.framework gamepads should support Home buttons.
Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (264246 => 264247)
--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2020-07-10 23:59:56 UTC (rev 264247)
@@ -2862,21 +2862,22 @@
return absoluteBoundsForLocalCaretRect(caretPainter, localRect);
}
-CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint &point, AXCoreObject* obj)
+CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint& point, AXCoreObject* object)
{
- if (!obj)
- return CharacterOffset();
-
- auto boundary = makeBoundaryPoint(obj->visiblePositionForPoint(point));
+ if (!object)
+ return { };
+ auto boundary = makeBoundaryPoint(object->visiblePositionForPoint(point));
if (!boundary)
return { };
-
return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
}
-CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint &point)
+CharacterOffset AXObjectCache::characterOffsetForPoint(const IntPoint& point)
{
- return startOrEndCharacterOffsetForRange(*m_document.caretRangeFromPoint(LayoutPoint(point)), true);
+ auto boundary = m_document.caretPositionFromPoint(point);
+ if (!boundary)
+ return { };
+ return startOrEndCharacterOffsetForRange({ *boundary, *boundary }, true);
}
CharacterOffset AXObjectCache::characterOffsetForBounds(const IntRect& rect, bool first)
Modified: trunk/Source/WebCore/dom/Document.cpp (264246 => 264247)
--- trunk/Source/WebCore/dom/Document.cpp 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/dom/Document.cpp 2020-07-10 23:59:56 UTC (rev 264247)
@@ -536,7 +536,7 @@
return 0;
}
-Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsigned constructionFlags)
+Document::Document(Frame* frame, const URL& url, DocumentClassFlags documentClasses, unsigned constructionFlags)
: ContainerNode(*this, CreateDocument)
, TreeScope(*this)
, FrameDestructionObserver(frame)
@@ -1508,32 +1508,35 @@
RefPtr<Range> Document::caretRangeFromPoint(int x, int y)
{
- return caretRangeFromPoint(LayoutPoint(x, y));
+ auto boundary = caretPositionFromPoint(LayoutPoint(x, y));
+ if (!boundary)
+ return nullptr;
+ return createLiveRange({ *boundary, *boundary });
}
-RefPtr<Range> Document::caretRangeFromPoint(const LayoutPoint& clientPoint)
+Optional<BoundaryPoint> Document::caretPositionFromPoint(const LayoutPoint& clientPoint)
{
if (!hasLivingRenderTree())
- return nullptr;
+ return WTF::nullopt;
LayoutPoint localPoint;
auto node = nodeFromPoint(clientPoint, &localPoint);
if (!node)
- return nullptr;
+ return WTF::nullopt;
auto* renderer = node->renderer();
if (!renderer)
- return nullptr;
+ return WTF::nullopt;
auto rangeCompliantPosition = renderer->positionForPoint(localPoint).parentAnchoredEquivalent();
if (rangeCompliantPosition.isNull())
- return nullptr;
+ return WTF::nullopt;
- auto offset = rangeCompliantPosition.offsetInContainerNode();
+ unsigned offset = rangeCompliantPosition.offsetInContainerNode();
node = retargetToScope(*rangeCompliantPosition.containerNode());
if (node != rangeCompliantPosition.containerNode())
offset = 0;
- return Range::create(*this, node.get(), offset, node.get(), offset);
+ return { { *node, offset } };
}
bool Document::isBodyPotentiallyScrollable(HTMLBodyElement& body)
Modified: trunk/Source/WebCore/dom/Document.h (264246 => 264247)
--- trunk/Source/WebCore/dom/Document.h 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/dom/Document.h 2020-07-10 23:59:56 UTC (rev 264247)
@@ -115,6 +115,11 @@
class DOMWrapperWorld;
class Database;
class DatabaseThread;
+class DeviceMotionClient;
+class DeviceMotionController;
+class DeviceOrientationAndMotionAccessController;
+class DeviceOrientationClient;
+class DeviceOrientationController;
class DocumentFragment;
class DocumentLoader;
class DocumentMarkerController;
@@ -137,6 +142,7 @@
class FullscreenManager;
class GPUCanvasContext;
class HTMLAllCollection;
+class HTMLAttachmentElement;
class HTMLBodyElement;
class HTMLCanvasElement;
class HTMLCollection;
@@ -157,6 +163,7 @@
class IdleRequestCallback;
class ImageBitmapRenderingContext;
class IntPoint;
+class IntersectionObserver;
class JSNode;
class LayoutPoint;
class LayoutRect;
@@ -169,6 +176,7 @@
class MediaPlaybackTargetClient;
class MediaQueryList;
class MediaQueryMatcher;
+class MediaSession;
class MessagePortChannelProvider;
class MouseEventWithHitTestResults;
class NodeFilter;
@@ -183,6 +191,7 @@
class RenderTreeBuilder;
class RenderView;
class RequestAnimationFrameCallback;
+class ResizeObserver;
class SVGDocumentExtensions;
class SVGSVGElement;
class SVGUseElement;
@@ -202,8 +211,10 @@
class StyleSheetContents;
class StyleSheetList;
class Text;
+class TextAutoSizing;
class TextManipulationController;
class TextResourceDecoder;
+class TransformSource;
class TreeWalker;
class UndoManager;
class VisibilityChangeClient;
@@ -219,6 +230,9 @@
class XPathNSResolver;
class XPathResult;
+struct BoundaryPoint;
+struct IntersectionObserverData;
+
template<typename> class ExceptionOr;
enum CollectionType;
@@ -228,48 +242,12 @@
using PlatformDisplayID = uint32_t;
-#if ENABLE(XSLT)
-class TransformSource;
-#endif
-
-#if ENABLE(DEVICE_ORIENTATION) && PLATFORM(IOS_FAMILY)
-class DeviceMotionClient;
-class DeviceMotionController;
-class DeviceOrientationClient;
-class DeviceOrientationController;
-#endif
-
-#if ENABLE(DEVICE_ORIENTATION)
-class DeviceOrientationAndMotionAccessController;
-#endif
-
-#if ENABLE(TEXT_AUTOSIZING)
-class TextAutoSizing;
-#endif
-
-#if ENABLE(MEDIA_SESSION)
-class MediaSession;
-#endif
-
-#if ENABLE(ATTACHMENT_ELEMENT)
-class HTMLAttachmentElement;
-#endif
-
-#if ENABLE(INTERSECTION_OBSERVER)
-class IntersectionObserver;
-struct IntersectionObserverData;
-#endif
-
-#if ENABLE(RESIZE_OBSERVER)
-class ResizeObserver;
-#endif
-
namespace Style {
class Resolver;
class Scope;
-};
+}
-const uint64_t HTMLMediaElementInvalidID = 0;
+constexpr uint64_t HTMLMediaElementInvalidID = 0;
enum PageshowEventPersistence { PageshowEventNotPersisted, PageshowEventPersisted };
@@ -286,7 +264,7 @@
const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
enum class EventHandlerRemoval { One, All };
-typedef HashCountedSet<Node*> EventTargetSet;
+using EventTargetSet = HashCountedSet<Node*>;
enum DocumentClass {
DefaultDocumentClass = 0,
@@ -299,7 +277,7 @@
TextDocumentClass = 1 << 6,
XMLDocumentClass = 1 << 7,
};
-typedef unsigned char DocumentClassFlags;
+using DocumentClassFlags = unsigned char;
enum class DocumentCompatibilityMode : unsigned char {
NoQuirksMode = 1,
@@ -459,7 +437,7 @@
static CustomElementNameValidationStatus validateCustomElementName(const AtomString&);
WEBCORE_EXPORT RefPtr<Range> caretRangeFromPoint(int x, int y);
- RefPtr<Range> caretRangeFromPoint(const LayoutPoint& clientPoint);
+ Optional<BoundaryPoint> caretPositionFromPoint(const LayoutPoint& clientPoint);
WEBCORE_EXPORT Element* scrollingElementForAPI();
WEBCORE_EXPORT Element* scrollingElement();
@@ -1288,7 +1266,7 @@
bool hasWheelEventHandlers() const { return m_wheelEventTargets.get() ? m_wheelEventTargets->size() : false; }
const EventTargetSet* wheelEventTargets() const { return m_wheelEventTargets.get(); }
- typedef std::pair<Region, bool> RegionFixedPair;
+ using RegionFixedPair = std::pair<Region, bool>;
RegionFixedPair absoluteEventRegionForNode(Node&);
RegionFixedPair absoluteRegionForEventTargets(const EventTargetSet*);
@@ -1606,7 +1584,7 @@
protected:
enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
- Document(Frame*, const URL&, unsigned = DefaultDocumentClass, unsigned constructionFlags = 0);
+ Document(Frame*, const URL&, DocumentClassFlags = DefaultDocumentClass, unsigned constructionFlags = 0);
void clearXMLVersion() { m_xmlVersion = String(); }
@@ -1937,7 +1915,7 @@
std::unique_ptr<DocumentSharedObjectPool> m_sharedObjectPool;
- typedef HashMap<AtomString, std::unique_ptr<Locale>> LocaleIdentifierToLocaleMap;
+ using LocaleIdentifierToLocaleMap = HashMap<AtomString, std::unique_ptr<Locale>>;
LocaleIdentifierToLocaleMap m_localeCache;
RefPtr<Document> m_templateDocument;
Modified: trunk/Source/WebCore/editing/AlternativeTextController.cpp (264246 => 264247)
--- trunk/Source/WebCore/editing/AlternativeTextController.cpp 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/editing/AlternativeTextController.cpp 2020-07-10 23:59:56 UTC (rev 264247)
@@ -101,7 +101,7 @@
// If type is PanelTypeReversion, then the new range has been set. So we shouldn't clear it.
if (type == AlternativeTextTypeCorrection)
- m_rangeWithAlternative = nullptr;
+ m_rangeWithAlternative = WTF::nullopt;
m_type = type;
m_timer.startOneShot(correctionPanelTimerInterval);
}
@@ -109,7 +109,7 @@
void AlternativeTextController::stopAlternativeTextUITimer()
{
m_timer.stop();
- m_rangeWithAlternative = nullptr;
+ m_rangeWithAlternative = WTF::nullopt;
}
void AlternativeTextController::stopPendingCorrection(const VisibleSelection& oldSelection)
@@ -139,26 +139,26 @@
if (doApplyCorrection)
handleAlternativeTextUIResult(dismissSoon(ReasonForDismissingAlternativeTextAccepted));
else
- m_rangeWithAlternative = nullptr;
+ m_rangeWithAlternative = WTF::nullopt;
}
bool AlternativeTextController::hasPendingCorrection() const
{
- return m_rangeWithAlternative;
+ return m_rangeWithAlternative.hasValue();
}
-bool AlternativeTextController::isSpellingMarkerAllowed(Range& misspellingRange) const
+bool AlternativeTextController::isSpellingMarkerAllowed(const SimpleRange& misspellingRange) const
{
return !m_document.markers().hasMarkers(misspellingRange, DocumentMarker::SpellCheckingExemption);
}
-void AlternativeTextController::show(Range& rangeToReplace, const String& replacement)
+void AlternativeTextController::show(const SimpleRange& rangeToReplace, const String& replacement)
{
auto boundingBox = rootViewRectForRange(rangeToReplace);
if (boundingBox.isEmpty())
return;
m_originalText = plainText(rangeToReplace);
- m_rangeWithAlternative = &rangeToReplace;
+ m_rangeWithAlternative = rangeToReplace;
m_details = replacement;
m_isActive = true;
if (AlternativeTextClient* client = alternativeTextClient())
@@ -204,13 +204,13 @@
Position caretPosition = m_document.selection().selection().start();
- if (m_rangeWithAlternative->endPosition() == caretPosition) {
+ if (createLegacyEditingPosition(m_rangeWithAlternative->end) == caretPosition) {
handleAlternativeTextUIResult(dismissSoon(ReasonForDismissingAlternativeTextAccepted));
return true;
}
// Pending correction should always be where caret is. But in case this is not always true, we still want to dismiss the panel without accepting the correction.
- ASSERT(m_rangeWithAlternative->endPosition() == caretPosition);
+ ASSERT(createLegacyEditingPosition(m_rangeWithAlternative->end) == caretPosition);
dismiss(ReasonForDismissingAlternativeTextIgnored);
return false;
}
@@ -264,11 +264,11 @@
case AlternativeTextTypeSpellingSuggestions: {
if (!m_rangeWithAlternative || plainText(*m_rangeWithAlternative) != m_originalText)
break;
- String paragraphText = plainText(TextCheckingParagraph(*m_rangeWithAlternative).paragraphRange());
+ String paragraphText = plainText(TextCheckingParagraph(createLiveRange(*m_rangeWithAlternative)).paragraphRange());
Vector<String> suggestions;
textChecker()->getGuessesForWord(m_originalText, paragraphText, m_document.selection().selection(), suggestions);
if (suggestions.isEmpty()) {
- m_rangeWithAlternative = nullptr;
+ m_rangeWithAlternative = WTF::nullopt;
break;
}
String topSuggestion = suggestions.first();
@@ -303,11 +303,10 @@
void AlternativeTextController::handleAlternativeTextUIResult(const String& result)
{
- Range* rangeWithAlternative = m_rangeWithAlternative.get();
- if (!rangeWithAlternative || m_document != rangeWithAlternative->ownerDocument())
+ if (!m_rangeWithAlternative || &m_document != &m_rangeWithAlternative->start.document())
return;
- String currentWord = plainText(*rangeWithAlternative);
+ String currentWord = plainText(*m_rangeWithAlternative);
// Check to see if the word we are about to correct has been changed between timer firing and callback being triggered.
if (currentWord != m_originalText)
return;
@@ -317,22 +316,22 @@
switch (m_type) {
case AlternativeTextTypeCorrection:
if (result.length())
- applyAlternativeTextToRange(*rangeWithAlternative, result, m_type, markerTypesForAutocorrection());
+ applyAlternativeTextToRange(*m_rangeWithAlternative, result, m_type, markerTypesForAutocorrection());
else if (!m_isDismissedByEditing)
- rangeWithAlternative->startContainer().document().markers().addMarker(*rangeWithAlternative, DocumentMarker::RejectedCorrection, m_originalText);
+ m_rangeWithAlternative->startContainer().document().markers().addMarker(*m_rangeWithAlternative, DocumentMarker::RejectedCorrection, m_originalText);
break;
case AlternativeTextTypeReversion:
case AlternativeTextTypeSpellingSuggestions:
if (result.length())
- applyAlternativeTextToRange(*rangeWithAlternative, result, m_type, markerTypesForReplacement());
+ applyAlternativeTextToRange(*m_rangeWithAlternative, result, m_type, markerTypesForReplacement());
break;
case AlternativeTextTypeDictationAlternatives:
if (result.length())
- applyAlternativeTextToRange(*rangeWithAlternative, result, m_type, markerTypesForAppliedDictationAlternative());
+ applyAlternativeTextToRange(*m_rangeWithAlternative, result, m_type, markerTypesForAppliedDictationAlternative());
break;
}
- m_rangeWithAlternative = nullptr;
+ m_rangeWithAlternative = WTF::nullopt;
}
bool AlternativeTextController::isAutomaticSpellingCorrectionEnabled()
@@ -423,13 +422,13 @@
client->recordAutocorrectionResponse(response, replacedString, plainText(replacementRange));
}
-void AlternativeTextController::markReversed(Range& changedRange)
+void AlternativeTextController::markReversed(const SimpleRange& changedRange)
{
changedRange.startContainer().document().markers().removeMarkers(changedRange, DocumentMarker::Autocorrected, DocumentMarkerController::RemovePartiallyOverlappingMarker);
changedRange.startContainer().document().markers().addMarker(changedRange, DocumentMarker::SpellCheckingExemption);
}
-void AlternativeTextController::markCorrection(Range& replacedRange, const String& replacedString)
+void AlternativeTextController::markCorrection(const SimpleRange& replacedRange, const String& replacedString)
{
DocumentMarkerController& markers = replacedRange.startContainer().document().markers();
for (auto markerType : markerTypesForAutocorrection()) {
@@ -440,7 +439,7 @@
}
}
-void AlternativeTextController::recordSpellcheckerResponseForModifiedCorrection(Range& rangeOfCorrection, const String& corrected, const String& correction)
+void AlternativeTextController::recordSpellcheckerResponseForModifiedCorrection(const SimpleRange& rangeOfCorrection, const String& corrected, const String& correction)
{
DocumentMarkerController& markers = rangeOfCorrection.startContainer().document().markers();
Vector<RenderedDocumentMarker*> correctedOnceMarkers = markers.markersInRange(rangeOfCorrection, DocumentMarker::Autocorrected);
@@ -486,7 +485,7 @@
m_document.markers().addMarker(precedingCharacterRange, DocumentMarker::DeletedAutocorrection, m_originalStringForLastDeletedAutocorrection);
}
-bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult& result, Range& rangeWithAlternative, const String& stringToBeReplaced)
+bool AlternativeTextController::processMarkersOnTextToBeReplacedByResult(const TextCheckingResult& result, const SimpleRange& rangeWithAlternative, const String& stringToBeReplaced)
{
auto& markers = m_document.markers();
if (markers.hasMarkers(rangeWithAlternative, DocumentMarker::Replacement)) {
@@ -501,11 +500,9 @@
if (markers.hasMarkers(rangeWithAlternative, DocumentMarker::AcceptedCandidate))
return false;
- Position beginningOfRange = rangeWithAlternative.startPosition();
- Position precedingCharacterPosition = beginningOfRange.previous();
+ auto beforePrecedingCharacter = createLegacyEditingPosition(rangeWithAlternative.start).previous();
+ auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(beforePrecedingCharacter), rangeWithAlternative.start };
- auto precedingCharacterRange = SimpleRange { *makeBoundaryPoint(precedingCharacterPosition), *makeBoundaryPoint(beginningOfRange) };
-
for (auto& marker : markers.markersInRange(precedingCharacterRange, DocumentMarker::DeletedAutocorrection)) {
if (marker->description() == stringToBeReplaced)
return false;
@@ -524,7 +521,7 @@
if (!shouldStartTimerFor(marker, endOfWordPosition.offsetInContainerNode()))
return false;
Node* node = endOfWordPosition.containerNode();
- auto wordRange = Range::create(m_document, node, marker.startOffset(), node, marker.endOffset());
+ auto wordRange = SimpleRange { { *node, marker.startOffset() }, { *node, marker.endOffset() } };
String currentWord = plainText(wordRange);
if (!currentWord.length())
return false;
@@ -577,7 +574,7 @@
return emptyString();
}
-void AlternativeTextController::applyAlternativeTextToRange(const Range& range, const String& alternative, AlternativeTextType alternativeType, OptionSet<DocumentMarker::MarkerType> markerTypesToAdd)
+void AlternativeTextController::applyAlternativeTextToRange(const SimpleRange& range, const String& alternative, AlternativeTextType alternativeType, OptionSet<DocumentMarker::MarkerType> markerTypesToAdd)
{
// After we replace the word at range rangeWithAlternative, we need to add markers to that range.
// So before we carry out the replacement,store the start position relative to the start position
@@ -584,18 +581,15 @@
// of the containing paragraph.
// Take note of the location of autocorrection so that we can add marker after the replacement took place.
- auto correctionStartPosition = range.startPosition();
- auto correctionStart { makeBoundaryPoint(correctionStartPosition) };
- auto paragraphStart { makeBoundaryPoint(startOfParagraph(correctionStartPosition)) };
- if (!correctionStart || !paragraphStart)
+ auto paragraphStart = makeBoundaryPoint(startOfParagraph(createLegacyEditingPosition(range.start)));
+ if (!paragraphStart)
return;
- auto treeScopeRoot = makeRef(correctionStart->container->treeScope().rootNode());
+ auto treeScopeRoot = makeRef(range.start.container->treeScope().rootNode());
auto treeScopeStart = BoundaryPoint { treeScopeRoot.get(), 0 };
- auto correctionOffsetInParagraph = characterCount({ *paragraphStart, *correctionStart });
+ auto correctionOffsetInParagraph = characterCount({ *paragraphStart, range.start });
auto paragraphOffsetInTreeScope = characterCount({ treeScopeStart, *paragraphStart });
- // Clone the range, since the caller of may keep a refernece to the original range and modify it.
- SpellingCorrectionCommand::create(range.cloneRange(), alternative)->apply();
+ SpellingCorrectionCommand::create(createLiveRange(range), alternative)->apply();
// Recalculate pragraphRangeContainingCorrection, since SpellingCorrectionCommand modified the DOM, such that the original paragraphRangeContainingCorrection is no longer valid. Radar: 10305315 Bugzilla: 89526
auto updatedParagraphStartContainingCorrection = resolveCharacterLocation(makeRangeSelectingNodeContents(treeScopeRoot), paragraphOffsetInTreeScope);
Modified: trunk/Source/WebCore/editing/AlternativeTextController.h (264246 => 264247)
--- trunk/Source/WebCore/editing/AlternativeTextController.h 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/editing/AlternativeTextController.h 2020-07-10 23:59:56 UTC (rev 264247)
@@ -40,7 +40,6 @@
class EditCommandComposition;
class EditorClient;
class Event;
-class Range;
class TextCheckerClient;
class VisibleSelection;
@@ -68,7 +67,7 @@
void stopAlternativeTextUITimer() UNLESS_ENABLED({ })
void dismiss(ReasonForDismissingAlternativeText) UNLESS_ENABLED({ })
- void show(Range& rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); })
+ void show(const SimpleRange& rangeToReplace, const String& replacement) UNLESS_ENABLED({ UNUSED_PARAM(rangeToReplace); UNUSED_PARAM(replacement); })
// Return true if correction was applied, false otherwise.
bool applyAutocorrectionBeforeTypingIfAppropriate() UNLESS_ENABLED({ return false; })
@@ -85,16 +84,16 @@
void handleCancelOperation() UNLESS_ENABLED({ })
bool hasPendingCorrection() const UNLESS_ENABLED({ return false; })
- bool isSpellingMarkerAllowed(Range& misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; })
+ bool isSpellingMarkerAllowed(const SimpleRange& misspellingRange) const UNLESS_ENABLED({ UNUSED_PARAM(misspellingRange); return true; })
bool isAutomaticSpellingCorrectionEnabled() UNLESS_ENABLED({ return false; })
bool shouldRemoveMarkersUponEditing();
void recordAutocorrectionResponse(AutocorrectionResponse, const String& replacedString, const SimpleRange& replacementRange) UNLESS_ENABLED({ UNUSED_PARAM(replacedString); UNUSED_PARAM(replacementRange); })
- void markReversed(Range& changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); })
- void markCorrection(Range& replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); })
+ void markReversed(const SimpleRange& changedRange) UNLESS_ENABLED({ UNUSED_PARAM(changedRange); })
+ void markCorrection(const SimpleRange& replacedRange, const String& replacedString) UNLESS_ENABLED({ UNUSED_PARAM(replacedRange); UNUSED_PARAM(replacedString); })
// This function returns false if the replacement should not be carried out.
- bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult&, Range& rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; });
+ bool processMarkersOnTextToBeReplacedByResult(const TextCheckingResult&, const SimpleRange& rangeToBeReplaced, const String& stringToBeReplaced) UNLESS_ENABLED({ UNUSED_PARAM(rangeToBeReplaced); UNUSED_PARAM(stringToBeReplaced); return true; });
void deletedAutocorrectionAtPosition(const Position&, const String& originalString) UNLESS_ENABLED({ UNUSED_PARAM(originalString); })
bool insertDictatedText(const String&, const Vector<DictationAlternative>&, Event*);
@@ -107,7 +106,7 @@
using AutocorrectionReplacement = String;
struct AlternativeTextInfo {
- RefPtr<Range> rangeWithAlternative;
+ SimpleRange rangeWithAlternative;
bool isActive;
AlternativeTextType type;
String originalText;
@@ -116,7 +115,7 @@
String dismissSoon(ReasonForDismissingAlternativeText);
void timerFired();
- void recordSpellcheckerResponseForModifiedCorrection(Range& rangeOfCorrection, const String& corrected, const String& correction);
+ void recordSpellcheckerResponseForModifiedCorrection(const SimpleRange& rangeOfCorrection, const String& corrected, const String& correction);
bool shouldStartTimerFor(const DocumentMarker&, int endOffset) const;
bool respondToMarkerAtEndOfWord(const DocumentMarker&, const Position& endOfWordPosition);
@@ -128,7 +127,7 @@
void markPrecedingWhitespaceForDeletedAutocorrectionAfterCommand(EditCommand*);
Timer m_timer;
- RefPtr<Range> m_rangeWithAlternative;
+ Optional<SimpleRange> m_rangeWithAlternative;
bool m_isActive;
bool m_isDismissedByEditing;
AlternativeTextType m_type;
@@ -140,7 +139,7 @@
#endif
#if USE(DICTATION_ALTERNATIVES) || USE(AUTOCORRECTION_PANEL)
String markerDescriptionForAppliedAlternativeText(AlternativeTextType, DocumentMarker::MarkerType);
- void applyAlternativeTextToRange(const Range&, const String&, AlternativeTextType, OptionSet<DocumentMarker::MarkerType>);
+ void applyAlternativeTextToRange(const SimpleRange&, const String&, AlternativeTextType, OptionSet<DocumentMarker::MarkerType>);
AlternativeTextClient* alternativeTextClient();
#endif
Modified: trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm (264246 => 264247)
--- trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/editing/cocoa/DictionaryLookup.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -260,12 +260,12 @@
#if ENABLE(REVEAL)
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
+Optional<std::tuple<SimpleRange, NSDictionary *>> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
if (!RevealLibrary() || !RevealCoreLibrary() || !getRVItemClass())
- return { nullptr, nil };
+ return WTF::nullopt;
// Since we already have the range we want, we just need to grab the returned options.
auto selectionStart = selection.visibleStart();
@@ -275,7 +275,7 @@
auto paragraphStart = startOfParagraph(selectionStart);
auto paragraphEnd = endOfParagraph(selectionEnd);
if (paragraphStart.isNull() || paragraphEnd.isNull())
- return { nullptr, nil };
+ return WTF::nullopt;
auto lengthToSelectionStart = characterCount({ *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(selectionStart) });
auto selectionCharacterCount = characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) });
@@ -285,32 +285,32 @@
String itemString = plainText(*fullCharacterRange);
NSRange highlightRange = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:rangeToPass]).get().highlightRange;
- return { createLiveRange(resolveCharacterRange(*fullCharacterRange, highlightRange)), nil };
+ return { { resolveCharacterRange(*fullCharacterRange, highlightRange), nil } };
END_BLOCK_OBJC_EXCEPTIONS
- return { nullptr, nil };
+ return WTF::nullopt;
}
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
+Optional<std::tuple<SimpleRange, NSDictionary *>> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
if (!RevealLibrary() || !RevealCoreLibrary() || !getRVItemClass())
- return { nullptr, nil };
+ return WTF::nullopt;
auto* node = hitTestResult.innerNonSharedNode();
if (!node || !node->renderer())
- return { nullptr, nil };
+ return WTF::nullopt;
auto* frame = node->document().frame();
if (!frame)
- return { nullptr, nil };
+ return WTF::nullopt;
// Don't do anything if there is no character at the point.
auto framePoint = hitTestResult.roundedPointInInnerNodeFrame();
if (!frame->rangeForPoint(framePoint))
- return { nullptr, nil };
+ return WTF::nullopt;
auto position = frame->visiblePositionForPoint(framePoint);
if (position.isNull())
@@ -319,7 +319,7 @@
auto selection = frame->page()->focusController().focusedOrMainFrame().selection().selection();
NSRange selectionRange;
NSUInteger hitIndex;
- RefPtr<Range> fullCharacterRange;
+ Optional<SimpleRange> fullCharacterRange;
if (selection.selectionType() == VisibleSelection::RangeSelection) {
auto selectionStart = selection.visibleStart();
@@ -326,16 +326,15 @@
auto selectionEnd = selection.visibleEnd();
// As context, we are going to use the surrounding paragraphs of text.
- auto paragraphStart = startOfParagraph(selectionStart);
- auto paragraphEnd = endOfParagraph(selectionEnd);
-
- fullCharacterRange = makeRange(paragraphStart, paragraphEnd);
- if (!fullCharacterRange)
- return { nullptr, nil };
+ auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
+ auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
+ if (!paragraphStart || !paragraphEnd)
+ return WTF::nullopt;
- selectionRange = NSMakeRange(characterCount({ *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(selectionStart) }),
+ fullCharacterRange = { { *paragraphStart, *paragraphEnd } };
+ selectionRange = NSMakeRange(characterCount({ *paragraphStart, *makeBoundaryPoint(selectionStart) }),
characterCount({ *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) }));
- hitIndex = characterCount({ *makeBoundaryPoint(paragraphStart), *makeBoundaryPoint(position) });
+ hitIndex = characterCount({ *paragraphStart, *makeBoundaryPoint(position) });
} else {
VisibleSelection selectionAccountingForLineRules { position };
selectionAccountingForLineRules.expandUsingGranularity(TextGranularity::WordGranularity);
@@ -342,12 +341,14 @@
position = selectionAccountingForLineRules.start();
// As context, we are going to use 250 characters of text before and after the point.
- fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
- if (!fullCharacterRange)
- return { nullptr, nil };
+ auto expandedRange = rangeExpandedAroundPositionByCharacters(position, 250);
+ if (!expandedRange)
+ return WTF::nullopt;
+ fullCharacterRange = { *expandedRange };
+
selectionRange = NSMakeRange(NSNotFound, 0);
- hitIndex = characterCount({ *makeBoundaryPoint(fullCharacterRange->startPosition()), *makeBoundaryPoint(position) });
+ hitIndex = characterCount({ fullCharacterRange->start, *makeBoundaryPoint(position) });
}
NSRange selectedRange = [getRVSelectionClass() revealRangeAtIndex:hitIndex selectedRanges:@[[NSValue valueWithRange:selectionRange]] shouldUpdateSelection:nil];
@@ -356,13 +357,13 @@
auto highlightRange = adoptNS([allocRVItemInstance() initWithText:itemString selectedRange:selectedRange]).get().highlightRange;
if (highlightRange.location == NSNotFound || !highlightRange.length)
- return { nullptr, nil };
+ return WTF::nullopt;
- return { createLiveRange(resolveCharacterRange(*fullCharacterRange, highlightRange)), nil };
+ return { { resolveCharacterRange(*fullCharacterRange, highlightRange), nil } };
END_BLOCK_OBJC_EXCEPTIONS
- return { nullptr, nil };
+ return WTF::nullopt;
}
@@ -423,7 +424,7 @@
return { @"", nil };
}
-static WKRevealController showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, RevealView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+static WKRevealController showPopupOrCreateAnimationController(bool createAnimationController, const DictionaryPopupInfo& dictionaryPopupInfo, CocoaView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
@@ -513,7 +514,7 @@
}
-void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, RevealView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
+void DictionaryLookup::showPopup(const DictionaryPopupInfo& dictionaryPopupInfo, CocoaView *view, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback, WTF::Function<void()>&& clearTextIndicator)
{
showPopupOrCreateAnimationController(false, dictionaryPopupInfo, view, textIndicatorInstallationCallback, rootViewToViewConversionCallback, WTFMove(clearTextIndicator));
}
Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (264246 => 264247)
--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h 2020-07-10 23:59:56 UTC (rev 264247)
@@ -28,38 +28,40 @@
#if PLATFORM(COCOA)
#include "DictionaryPopupInfo.h"
+#include <wtf/Function.h>
+
#if PLATFORM(MAC)
#import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
-#endif // PLATFORM(MAC)
-#include <wtf/Function.h>
+#endif
-OBJC_CLASS NSView;
-OBJC_CLASS UIView;
-OBJC_CLASS PDFSelection;
+@class NSView;
+@class PDFSelection;
+@class UIView;
#if PLATFORM(MAC)
-typedef id <NSImmediateActionAnimationController> WKRevealController;
-using RevealView = NSView;
+using WKRevealController = id <NSImmediateActionAnimationController>;
+using CocoaView = NSView;
#else
-typedef id WKRevealController;
-using RevealView = UIView;
-#endif // PLATFORM(MAC)
+using WKRevealController = id;
+using CocoaView = UIView;
+#endif
namespace WebCore {
class HitTestResult;
-class Range;
class VisibleSelection;
+struct SimpleRange;
+
class DictionaryLookup {
public:
- WEBCORE_EXPORT static std::tuple<RefPtr<Range>, NSDictionary *> rangeForSelection(const VisibleSelection&);
- WEBCORE_EXPORT static std::tuple<RefPtr<Range>, NSDictionary *> rangeAtHitTestResult(const HitTestResult&);
+ WEBCORE_EXPORT static Optional<std::tuple<SimpleRange, NSDictionary *>> rangeForSelection(const VisibleSelection&);
+ WEBCORE_EXPORT static Optional<std::tuple<SimpleRange, NSDictionary *>> rangeAtHitTestResult(const HitTestResult&);
WEBCORE_EXPORT static std::tuple<NSString *, NSDictionary *> stringForPDFSelection(PDFSelection *);
// FIXME: Should move/unify dictionaryPopupInfoForRange here too.
- WEBCORE_EXPORT static void showPopup(const DictionaryPopupInfo&, RevealView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
+ WEBCORE_EXPORT static void showPopup(const DictionaryPopupInfo&, CocoaView *, const WTF::Function<void(TextIndicator&)>& textIndicatorInstallationCallback, const WTF::Function<FloatRect(FloatRect)>& rootViewToViewConversionCallback = nullptr, WTF::Function<void()>&& clearTextIndicator = nullptr);
WEBCORE_EXPORT static void hidePopup();
#if PLATFORM(MAC)
@@ -70,4 +72,4 @@
} // namespace WebCore
-#endif // PLATFORM(MAC)
+#endif
Modified: trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm (264246 => 264247)
--- trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookupLegacy.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -75,11 +75,11 @@
return createLiveRange(*selectedRange)->contains(position);
}
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
+Optional<std::tuple<SimpleRange, NSDictionary *>> DictionaryLookup::rangeForSelection(const VisibleSelection& selection)
{
auto selectedRange = selection.toNormalizedRange();
if (!selectedRange)
- return { nullptr, nil };
+ return WTF::nullopt;
// Since we already have the range we want, we just need to grab the returned options.
auto selectionStart = selection.visibleStart();
@@ -89,7 +89,7 @@
auto paragraphStart = makeBoundaryPoint(startOfParagraph(selectionStart));
auto paragraphEnd = makeBoundaryPoint(endOfParagraph(selectionEnd));
if (!paragraphStart || !paragraphEnd)
- return { nullptr, nil };
+ return WTF::nullopt;
auto selectionRange = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) };
auto paragraphRange = SimpleRange { *paragraphStart, *paragraphEnd };
@@ -97,23 +97,23 @@
NSDictionary *options = nil;
tokenRange(plainText(paragraphRange), characterRange(paragraphRange, selectionRange), &options);
- return { createLiveRange(*selectedRange), options };
+ return { { *selectedRange, options } };
}
-std::tuple<RefPtr<Range>, NSDictionary *> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
+Optional<std::tuple<SimpleRange, NSDictionary *>> DictionaryLookup::rangeAtHitTestResult(const HitTestResult& hitTestResult)
{
auto* node = hitTestResult.innerNonSharedNode();
if (!node || !node->renderer())
- return { nullptr, nil };
+ return WTF::nullopt;
auto* frame = node->document().frame();
if (!frame)
- return { nullptr, nil };
+ return WTF::nullopt;
// Don't do anything if there is no character at the point.
auto framePoint = hitTestResult.roundedPointInInnerNodeFrame();
if (!frame->rangeForPoint(framePoint))
- return { nullptr, nil };
+ return WTF::nullopt;
auto position = frame->visiblePositionForPoint(framePoint);
if (position.isNull())
@@ -131,12 +131,12 @@
// As context, we are going to use 250 characters of text before and after the point.
auto fullCharacterRange = rangeExpandedAroundPositionByCharacters(position, 250);
if (!fullCharacterRange)
- return { nullptr, nil };
+ return WTF::nullopt;
auto fullCharacterStart = makeBoundaryPoint(fullCharacterRange->startPosition());
auto positionBoundary = makeBoundaryPoint(position);
if (!fullCharacterStart || !positionBoundary)
- return { nullptr, nil };
+ return WTF::nullopt;
NSRange rangeToPass = NSMakeRange(characterCount({ *fullCharacterStart, *positionBoundary }), 0);
NSDictionary *options = nil;
@@ -145,9 +145,9 @@
// tokenRange sometimes returns {NSNotFound, 0} if it was unable to determine a good string.
// FIXME (159063): We shouldn't need to check for zero length here.
if (extractedRange.location == NSNotFound || !extractedRange.length)
- return { nullptr, nil };
+ return WTF::nullopt;
- return { createLiveRange(resolveCharacterRange(*fullCharacterRange, extractedRange)), options };
+ return { { resolveCharacterRange(*fullCharacterRange, extractedRange), options } };
}
static void expandSelectionByCharacters(PDFSelection *selection, NSInteger numberOfCharactersToExpand, NSInteger& charactersAddedBeforeStart, NSInteger& charactersAddedAfterEnd)
Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (264246 => 264247)
--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -1137,14 +1137,13 @@
VisibleSelection EventHandler::selectClosestWordFromHitTestResultBasedOnLookup(const HitTestResult& result)
{
if (!m_frame.editor().behavior().shouldSelectBasedOnDictionaryLookup())
- return VisibleSelection();
+ return { };
- RefPtr<Range> range;
- std::tie(range, std::ignore) = DictionaryLookup::rangeAtHitTestResult(result);
+ auto range = DictionaryLookup::rangeAtHitTestResult(result);
if (!range)
- return VisibleSelection();
+ return { };
- return VisibleSelection(*range);
+ return std::get<SimpleRange>(*range);
}
static IntSize autoscrollAdjustmentFactorForScreenBoundaries(const IntPoint& screenPoint, const FloatRect& screenRect)
@@ -1155,38 +1154,38 @@
// will occur as excpected. This function figures out just how much to adjust the autoscroll amount by
// in order to get autoscrolling to feel natural in this situation.
+ constexpr float edgeDistanceThreshold = 50;
+ constexpr float pixelsMultiplier = 20;
+
IntSize adjustmentFactor;
-#define EDGE_DISTANCE_THRESHOLD 50
-#define PIXELS_MULTIPLIER 20
-
float screenLeftEdge = screenRect.x();
- float insetScreenLeftEdge = screenLeftEdge + EDGE_DISTANCE_THRESHOLD;
+ float insetScreenLeftEdge = screenLeftEdge + edgeDistanceThreshold;
float screenRightEdge = screenRect.maxX();
- float insetScreenRightEdge = screenRightEdge - EDGE_DISTANCE_THRESHOLD;
+ float insetScreenRightEdge = screenRightEdge - edgeDistanceThreshold;
if (screenPoint.x() >= screenLeftEdge && screenPoint.x() < insetScreenLeftEdge) {
- float distanceFromEdge = screenPoint.x() - screenLeftEdge - EDGE_DISTANCE_THRESHOLD;
+ float distanceFromEdge = screenPoint.x() - screenLeftEdge - edgeDistanceThreshold;
if (distanceFromEdge < 0)
- adjustmentFactor.setWidth((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+ adjustmentFactor.setWidth((distanceFromEdge / edgeDistanceThreshold) * pixelsMultiplier);
} else if (screenPoint.x() >= insetScreenRightEdge && screenPoint.x() < screenRightEdge) {
- float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenRightEdge - screenPoint.x());
+ float distanceFromEdge = edgeDistanceThreshold - (screenRightEdge - screenPoint.x());
if (distanceFromEdge > 0)
- adjustmentFactor.setWidth((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+ adjustmentFactor.setWidth((distanceFromEdge / edgeDistanceThreshold) * pixelsMultiplier);
}
float screenTopEdge = screenRect.y();
- float insetScreenTopEdge = screenTopEdge + EDGE_DISTANCE_THRESHOLD;
+ float insetScreenTopEdge = screenTopEdge + edgeDistanceThreshold;
float screenBottomEdge = screenRect.maxY();
- float insetScreenBottomEdge = screenBottomEdge - EDGE_DISTANCE_THRESHOLD;
+ float insetScreenBottomEdge = screenBottomEdge - edgeDistanceThreshold;
if (screenPoint.y() >= screenTopEdge && screenPoint.y() < insetScreenTopEdge) {
- float distanceFromEdge = screenPoint.y() - screenTopEdge - EDGE_DISTANCE_THRESHOLD;
+ float distanceFromEdge = screenPoint.y() - screenTopEdge - edgeDistanceThreshold;
if (distanceFromEdge < 0)
- adjustmentFactor.setHeight((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+ adjustmentFactor.setHeight((distanceFromEdge / edgeDistanceThreshold) * pixelsMultiplier);
} else if (screenPoint.y() >= insetScreenBottomEdge && screenPoint.y() < screenBottomEdge) {
- float distanceFromEdge = EDGE_DISTANCE_THRESHOLD - (screenBottomEdge - screenPoint.y());
+ float distanceFromEdge = edgeDistanceThreshold - (screenBottomEdge - screenPoint.y());
if (distanceFromEdge > 0)
- adjustmentFactor.setHeight((distanceFromEdge / EDGE_DISTANCE_THRESHOLD) * PIXELS_MULTIPLIER);
+ adjustmentFactor.setHeight((distanceFromEdge / edgeDistanceThreshold) * pixelsMultiplier);
}
return adjustmentFactor;
Modified: trunk/Source/WebCore/testing/Internals.mm (264246 => 264247)
--- trunk/Source/WebCore/testing/Internals.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebCore/testing/Internals.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -35,6 +35,7 @@
#import "HitTestResult.h"
#import "MediaPlayerPrivate.h"
#import "Range.h"
+#import "SimpleRange.h"
#import "UTIUtilities.h"
#import <AVFoundation/AVPlayer.h>
#import <pal/spi/cocoa/NSAccessibilitySPI.h>
@@ -72,10 +73,12 @@
document->updateLayoutIgnorePendingStylesheets();
constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::DisallowUserAgentShadowContent, HitTestRequest::AllowChildFrameContent };
- HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y), hitType);
- RefPtr<Range> range;
- std::tie(range, std::ignore) = DictionaryLookup::rangeAtHitTestResult(result);
- return WTFMove(range);
+ auto result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y), hitType);
+ auto range = DictionaryLookup::rangeAtHitTestResult(result);
+ if (!range)
+ return nullptr;
+
+ return RefPtr<Range> { createLiveRange(std::get<SimpleRange>(*range)) };
}
#endif
@@ -95,13 +98,10 @@
String Internals::encodedPreferenceValue(const String& domain, const String& key)
{
- auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName: domain]);
- id value = [userDefaults.get() objectForKey:key];
- NSError *e = nil;
- auto data = "" archivedDataWithRootObject:value requiringSecureCoding:YES error:&e]);
- ASSERT(!e);
- auto encodedString = [data base64EncodedStringWithOptions:0];
- return encodedString;
+ auto userDefaults = adoptNS([[NSUserDefaults alloc] initWithSuiteName:domain]);
+ id value = [userDefaults objectForKey:key];
+ auto data = "" archivedDataWithRootObject:value requiringSecureCoding:YES error:nullptr]);
+ return [data base64EncodedStringWithOptions:0];
}
String Internals::getUTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI)
Modified: trunk/Source/WebKit/ChangeLog (264246 => 264247)
--- trunk/Source/WebKit/ChangeLog 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/ChangeLog 2020-07-10 23:59:56 UTC (rev 264247)
@@ -1,3 +1,43 @@
+2020-07-08 Darin Adler <[email protected]>
+
+ Remove live ranges from Document.h, AlternativeTextController.h, DictionaryLookup.h, and WebPage.h
+ https://bugs.webkit.org/show_bug.cgi?id=214109
+
+ Reviewed by Sam Weinig.
+
+ * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+ (-[WKWebProcessPlugInBrowserContextController selectedRange]): Updated since
+ WebPage::currentSelectionAsRange returns SimpleRange.
+
+ * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+ (WebKit::WebPage::performDictionaryLookupAtLocation): Updated since
+ DictionaryLookup::rangeAtHitTestResult returns SimpleRange.
+ (WebKit::WebPage::performDictionaryLookupForSelection): Updated since
+ DictionaryLookup::rangeForSelection returns SimpleRange.
+ (WebKit::WebPage::performDictionaryLookupForRange): Take SimpleRange.
+ (WebKit::WebPage::dictionaryPopupInfoForRange): Ditto.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::currentSelectionAsRange): Return SimpleRange.
+
+ * WebProcess/WebPage/WebPage.h: Use SimpleRange instead of live ranges.
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::selectWithGesture): Updated since m_startingGestureRange
+ is SimpleRange.
+ (WebKit::WebPage::clearSelection): Ditto.
+ (WebKit::WebPage::rangeForGranularityAtPoint): Return SimpleRange.
+ (WebKit::WebPage::selectTextWithGranularityAtPoint): Update since
+ rangeForGranularityAtPoint returns SimpleRange.
+ (WebKit::WebPage::updateSelectionWithExtentPointAndBoundary): Use
+ SimpleRange.
+ (WebKit::WebPage::updateSelectionWithExtentPoint): Use auto.
+
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performImmediateActionHitTestAtLocation): Update
+ since lookupTextAtLocation returns SimpleRange.
+ (WebKit::WebPage::lookupTextAtLocation): Return SimpleRange.
+
2020-07-10 Brady Eidson <[email protected]>
Limit MultiGamepadProvider to Catalina and Big Sur.
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -368,11 +368,11 @@
- (WKDOMRange *)selectedRange
{
- RefPtr<WebCore::Range> range = _page->currentSelectionAsRange();
+ auto range = _page->currentSelectionAsRange();
if (!range)
return nil;
- return WebKit::toWKDOMRange(range.get());
+ return WebKit::toWKDOMRange(createLiveRange(*range).ptr());
}
- (WKWebProcessPlugInFrame *)mainFrame
Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -52,6 +52,7 @@
#import <WebCore/PlatformMediaSessionManager.h>
#import <WebCore/Range.h>
#import <WebCore/RenderElement.h>
+#import <WebCore/TextIterator.h>
#if PLATFORM(IOS)
#import <WebCore/ParentalControlsContentFilter.h>
@@ -113,23 +114,28 @@
// Find the frame the point is over.
constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::DisallowUserAgentShadowContent, HitTestRequest::AllowChildFrameContent };
- HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)), hitType);
- auto [range, options] = DictionaryLookup::rangeAtHitTestResult(result);
- if (!range)
- return;
-
+ auto result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(roundedIntPoint(floatPoint)), hitType);
+
auto* frame = result.innerNonSharedNode() ? result.innerNonSharedNode()->document().frame() : &m_page->focusController().focusedOrMainFrame();
if (!frame)
return;
-
- performDictionaryLookupForRange(*frame, *range, options, TextIndicatorPresentationTransition::Bounce);
+
+ auto rangeResult = DictionaryLookup::rangeAtHitTestResult(result);
+ if (!rangeResult)
+ return;
+
+ auto [range, options] = WTFMove(*rangeResult);
+ performDictionaryLookupForRange(*frame, createLiveRange(range), options, TextIndicatorPresentationTransition::Bounce);
}
void WebPage::performDictionaryLookupForSelection(Frame& frame, const VisibleSelection& selection, TextIndicatorPresentationTransition presentationTransition)
{
- auto [selectedRange, options] = DictionaryLookup::rangeForSelection(selection);
- if (selectedRange)
- performDictionaryLookupForRange(frame, *selectedRange, options, presentationTransition);
+ auto result = DictionaryLookup::rangeForSelection(selection);
+ if (!result)
+ return;
+
+ auto [range, options] = WTFMove(*result);
+ performDictionaryLookupForRange(frame, createLiveRange(range), options, presentationTransition);
}
void WebPage::performDictionaryLookupOfCurrentSelection()
@@ -138,28 +144,30 @@
performDictionaryLookupForSelection(frame, frame.selection().selection(), TextIndicatorPresentationTransition::BounceAndCrossfade);
}
-void WebPage::performDictionaryLookupForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+void WebPage::performDictionaryLookupForRange(Frame& frame, const SimpleRange& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
{
send(Messages::WebPageProxy::DidPerformDictionaryLookup(dictionaryPopupInfoForRange(frame, range, options, presentationTransition)));
}
-DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, Range& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
+DictionaryPopupInfo WebPage::dictionaryPopupInfoForRange(Frame& frame, const SimpleRange& range, NSDictionary *options, TextIndicatorPresentationTransition presentationTransition)
{
Editor& editor = frame.editor();
editor.setIsGettingDictionaryPopupInfo(true);
- DictionaryPopupInfo dictionaryPopupInfo;
- if (range.text().stripWhiteSpace().isEmpty()) {
+ // FIXME: Inefficient to call stripWhiteSpace to detect whether a string has a non-whitespace character in it.
+ if (plainText(range).stripWhiteSpace().isEmpty()) {
editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
+ return { };
}
auto quads = RenderObject::absoluteTextQuads(range);
if (quads.isEmpty()) {
editor.setIsGettingDictionaryPopupInfo(false);
- return dictionaryPopupInfo;
+ return { };
}
+ DictionaryPopupInfo dictionaryPopupInfo;
+
IntRect rangeRect = frame.view()->contentsToWindow(quads[0].enclosingBoundingBox());
const RenderStyle* style = range.startContainer().renderStyle();
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2020-07-10 23:59:56 UTC (rev 264247)
@@ -6289,13 +6289,13 @@
#endif // ENABLE(PRIMARY_SNAPSHOTTED_PLUGIN_HEURISTIC)
-RefPtr<Range> WebPage::currentSelectionAsRange()
+Optional<SimpleRange> WebPage::currentSelectionAsRange()
{
auto* frame = frameWithSelection(m_page.get());
if (!frame)
- return nullptr;
+ return WTF::nullopt;
- return createLiveRange(frame->selection().selection().toNormalizedRange());
+ return frame->selection().selection().toNormalizedRange();
}
void WebPage::reportUsedFeatures()
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2020-07-10 23:59:56 UTC (rev 264247)
@@ -480,7 +480,7 @@
WebCore::Frame* mainFrame() const; // May return nullptr.
WebCore::FrameView* mainFrameView() const; // May return nullptr.
- RefPtr<WebCore::Range> currentSelectionAsRange();
+ Optional<WebCore::SimpleRange> currentSelectionAsRange();
#if ENABLE(NETSCAPE_PLUGIN_API)
RefPtr<Plugin> createPlugin(WebFrame*, WebCore::HTMLPlugInElement*, const Plugin::Parameters&, String& newMIMEType);
@@ -1381,7 +1381,7 @@
void completeSyntheticClick(WebCore::Node& nodeRespondingToClick, const WebCore::FloatPoint& location, OptionSet<WebKit::WebEvent::Modifier>, WebCore::SyntheticClickType, WebCore::PointerID = WebCore::mousePointerID);
void sendTapHighlightForNodeIfNecessary(uint64_t requestID, WebCore::Node*);
WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithFocusedElement);
- RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, WebCore::TextGranularity, bool isInteractingWithFocusedElement);
+ Optional<WebCore::SimpleRange> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, WebCore::TextGranularity, bool isInteractingWithFocusedElement);
void setFocusedFrameBeforeSelectingTextAtLocation(const WebCore::IntPoint&);
void dispatchSyntheticMouseEventsForSelectionGesture(SelectionTouch, const WebCore::IntPoint&);
@@ -1559,8 +1559,8 @@
#if PLATFORM(COCOA)
void performDictionaryLookupAtLocation(const WebCore::FloatPoint&);
void performDictionaryLookupOfCurrentSelection();
- void performDictionaryLookupForRange(WebCore::Frame&, WebCore::Range&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
- WebCore::DictionaryPopupInfo dictionaryPopupInfoForRange(WebCore::Frame&, WebCore::Range&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
+ void performDictionaryLookupForRange(WebCore::Frame&, const WebCore::SimpleRange&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
+ WebCore::DictionaryPopupInfo dictionaryPopupInfoForRange(WebCore::Frame&, const WebCore::SimpleRange&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
#if ENABLE(PDFKIT_PLUGIN)
WebCore::DictionaryPopupInfo dictionaryPopupInfoForSelectionInPDFPlugin(PDFSelection *, PDFPlugin&, NSDictionary *options, WebCore::TextIndicatorPresentationTransition);
#endif
@@ -1664,7 +1664,7 @@
#if PLATFORM(MAC)
void performImmediateActionHitTestAtLocation(WebCore::FloatPoint);
- std::tuple<RefPtr<WebCore::Range>, NSDictionary *> lookupTextAtLocation(WebCore::FloatPoint);
+ Optional<std::tuple<WebCore::SimpleRange, NSDictionary *>> lookupTextAtLocation(WebCore::FloatPoint);
void immediateActionDidUpdate();
void immediateActionDidCancel();
void immediateActionDidComplete();
@@ -1884,7 +1884,7 @@
#if PLATFORM(IOS_FAMILY)
bool m_allowsMediaDocumentInlinePlayback { false };
- RefPtr<WebCore::Range> m_startingGestureRange;
+ Optional<WebCore::SimpleRange> m_startingGestureRange;
#endif
#if ENABLE(FULLSCREEN_API)
@@ -1990,7 +1990,7 @@
#endif
#if PLATFORM(IOS_FAMILY)
- RefPtr<WebCore::Range> m_currentWordRange;
+ Optional<WebCore::SimpleRange> m_currentWordRange;
RefPtr<WebCore::Node> m_interactionNode;
WebCore::IntPoint m_lastInteractionLocation;
@@ -2018,7 +2018,7 @@
WebCore::FloatSize m_availableScreenSize;
WebCore::FloatSize m_overrideScreenSize;
- RefPtr<WebCore::Range> m_initialSelection;
+ Optional<WebCore::SimpleRange> m_initialSelection;
WebCore::VisibleSelection m_storedSelectionForAccessibility { WebCore::VisibleSelection() };
WebCore::FloatSize m_maximumUnobscuredSize;
int32_t m_deviceOrientation { 0 };
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -1408,20 +1408,23 @@
range = wordRangeFromPosition(position);
#else
switch (wkGestureState) {
- case GestureRecognizerState::Began:
- m_startingGestureRange = Range::create(*frame.document(), position, position);
+ case GestureRecognizerState::Began: {
+ auto boundary = *makeBoundaryPoint(position);
+ m_startingGestureRange = SimpleRange { boundary, boundary };
break;
+ }
case GestureRecognizerState::Changed:
if (m_startingGestureRange) {
- if (m_startingGestureRange->startPosition() < position)
- range = Range::create(*frame.document(), m_startingGestureRange->startPosition(), position);
+ auto start = createLegacyEditingPosition(m_startingGestureRange->start);
+ if (start < position)
+ range = Range::create(*frame.document(), start, position);
else
- range = Range::create(*frame.document(), position, m_startingGestureRange->startPosition());
+ range = Range::create(*frame.document(), position, start);
}
break;
case GestureRecognizerState::Ended:
case GestureRecognizerState::Cancelled:
- m_startingGestureRange = nullptr;
+ m_startingGestureRange = WTF::nullopt;
break;
case GestureRecognizerState::Failed:
case GestureRecognizerState::Possible:
@@ -1435,12 +1438,15 @@
switch (wkGestureState) {
case GestureRecognizerState::Began:
range = wordRangeFromPosition(position);
- m_currentWordRange = range ? RefPtr<Range>(Range::create(*frame.document(), range->startPosition(), range->endPosition())) : nullptr;
+ if (range)
+ m_currentWordRange = { { *range } };
+ else
+ m_currentWordRange = WTF::nullopt;
break;
case GestureRecognizerState::Changed:
if (!m_currentWordRange)
break;
- range = Range::create(*frame.document(), m_currentWordRange->startPosition(), m_currentWordRange->endPosition());
+ range = createLiveRange(*m_currentWordRange);
if (position < range->startPosition())
range->setStart(position.deepEquivalent());
if (position > range->endPosition())
@@ -1448,7 +1454,7 @@
break;
case GestureRecognizerState::Ended:
case GestureRecognizerState::Cancelled:
- m_currentWordRange = nullptr;
+ m_currentWordRange = WTF::nullopt;
break;
case GestureRecognizerState::Failed:
case GestureRecognizerState::Possible:
@@ -1656,7 +1662,7 @@
void WebPage::clearSelection()
{
- m_startingGestureRange = nullptr;
+ m_startingGestureRange = WTF::nullopt;
m_page->focusController().focusedOrMainFrame().selection().clear();
}
@@ -2088,32 +2094,51 @@
completionHandler();
}
-RefPtr<Range> WebPage::rangeForGranularityAtPoint(Frame& frame, const WebCore::IntPoint& point, WebCore::TextGranularity granularity, bool isInteractingWithFocusedElement)
+Optional<SimpleRange> WebPage::rangeForGranularityAtPoint(Frame& frame, const WebCore::IntPoint& point, WebCore::TextGranularity granularity, bool isInteractingWithFocusedElement)
{
- VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
-
- RefPtr<Range> range;
+ auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
switch (granularity) {
- case TextGranularity::CharacterGranularity:
- range = makeRange(position, position);
- break;
- case TextGranularity::WordGranularity:
- range = wordRangeFromPosition(position);
- break;
+ case TextGranularity::CharacterGranularity: {
+ auto boundary = makeBoundaryPoint(position);
+ if (!boundary)
+ return WTF::nullopt;
+ return { { *boundary, *boundary } };
+ }
+ case TextGranularity::WordGranularity: {
+ auto range = wordRangeFromPosition(position);
+ if (!range)
+ return WTF::nullopt;
+ return { *range };
+ }
case TextGranularity::SentenceGranularity:
- range = enclosingTextUnitOfGranularity(position, TextGranularity::SentenceGranularity, SelectionDirection::Forward);
- break;
- case TextGranularity::ParagraphGranularity:
- range = enclosingTextUnitOfGranularity(position, TextGranularity::ParagraphGranularity, SelectionDirection::Forward);
- break;
+ case TextGranularity::ParagraphGranularity: {
+ auto range = enclosingTextUnitOfGranularity(position, granularity, SelectionDirection::Forward);
+ if (!range)
+ return WTF::nullopt;
+ return { *range };
+ }
case TextGranularity::DocumentGranularity:
- // FIXME: It's not clear why this mutates the current selection and returns null.
+ // FIXME: Makes no sense that this mutates the current selection and returns null.
frame.selection().selectAll();
- break;
- default:
- break;
+ return WTF::nullopt;
+ case TextGranularity::LineGranularity:
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
+ case TextGranularity::LineBoundary:
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
+ case TextGranularity::SentenceBoundary:
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
+ case TextGranularity::ParagraphBoundary:
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
+ case TextGranularity::DocumentBoundary:
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
}
- return range;
+ ASSERT_NOT_REACHED();
+ return WTF::nullopt;
}
static inline bool rectIsTooBigForSelection(const IntRect& blockRect, const Frame& frame)
@@ -2138,7 +2163,7 @@
auto& frame = m_page->focusController().focusedOrMainFrame();
auto range = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
if (range)
- frame.selection().setSelectedRange(range.get(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
+ frame.selection().setSelectedRange(createLiveRange(*range).ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
m_initialSelection = range;
completionHandler();
}
@@ -2152,36 +2177,36 @@
void WebPage::updateSelectionWithExtentPointAndBoundary(const WebCore::IntPoint& point, WebCore::TextGranularity granularity, bool isInteractingWithFocusedElement, CallbackID callbackID)
{
auto& frame = m_page->focusController().focusedOrMainFrame();
- VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
- RefPtr<Range> newRange = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
+ auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
+ auto newRange = rangeForGranularityAtPoint(frame, point, granularity, isInteractingWithFocusedElement);
if (position.isNull() || !m_initialSelection || !newRange) {
send(Messages::WebPageProxy::UnsignedCallback(false, callbackID));
return;
}
-
- RefPtr<Range> range;
- VisiblePosition selectionStart = m_initialSelection->startPosition();
- VisiblePosition selectionEnd = m_initialSelection->endPosition();
- if (position > m_initialSelection->endPosition())
- selectionEnd = newRange->endPosition();
- else if (position < m_initialSelection->startPosition())
- selectionStart = newRange->startPosition();
-
- if (selectionStart.isNotNull() && selectionEnd.isNotNull())
- range = Range::create(*frame.document(), selectionStart, selectionEnd);
-
- if (range)
- frame.selection().setSelectedRange(range.get(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
-
- send(Messages::WebPageProxy::UnsignedCallback(selectionStart == m_initialSelection->startPosition(), callbackID));
+ auto initialSelectionStartPosition = createLegacyEditingPosition(m_initialSelection->start);
+ auto initialSelectionEndPosition = createLegacyEditingPosition(m_initialSelection->end);
+
+ VisiblePosition selectionStart = initialSelectionStartPosition;
+ VisiblePosition selectionEnd = initialSelectionEndPosition;
+ if (position > initialSelectionEndPosition)
+ selectionEnd = createLegacyEditingPosition(newRange->end);
+ else if (position < initialSelectionStartPosition)
+ selectionStart = createLegacyEditingPosition(newRange->start);
+
+ if (selectionStart.isNotNull() && selectionEnd.isNotNull()) {
+ auto range = SimpleRange { *makeBoundaryPoint(selectionStart), *makeBoundaryPoint(selectionEnd) };
+ frame.selection().setSelectedRange(createLiveRange(range).ptr(), UPSTREAM, WebCore::FrameSelection::ShouldCloseTyping::Yes, UserTriggered);
+ }
+
+ send(Messages::WebPageProxy::UnsignedCallback(selectionStart == initialSelectionStartPosition, callbackID));
}
void WebPage::updateSelectionWithExtentPoint(const WebCore::IntPoint& point, bool isInteractingWithFocusedElement, RespectSelectionAnchor respectSelectionAnchor, CallbackID callbackID)
{
auto& frame = m_page->focusController().focusedOrMainFrame();
- VisiblePosition position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
+ auto position = visiblePositionInFocusedNodeForPoint(frame, point, isInteractingWithFocusedElement);
if (position.isNull()) {
send(Messages::WebPageProxy::UnsignedCallback(false, callbackID));
Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (264246 => 264247)
--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -859,14 +859,12 @@
if (!absoluteLinkURL.isEmpty() && URLElement)
immediateActionResult.linkTextIndicator = TextIndicator::createWithRange(makeRangeSelectingNodeContents(*URLElement), { TextIndicatorOption::UseBoundingRectAndPaintAllContentForComplexRanges }, TextIndicatorPresentationTransition::FadeIn);
- auto lookupResult = lookupTextAtLocation(locationInViewCoordinates);
- if (auto* lookupRange = std::get<RefPtr<Range>>(lookupResult).get()) {
- immediateActionResult.lookupText = lookupRange->text();
+ if (auto lookupResult = lookupTextAtLocation(locationInViewCoordinates)) {
+ auto [lookupRange, options] = WTFMove(*lookupResult);
+ immediateActionResult.lookupText = plainText(lookupRange);
if (auto* node = hitTestResult.innerNode()) {
- if (auto* frame = node->document().frame()) {
- auto options = std::get<NSDictionary *>(lookupResult);
- immediateActionResult.dictionaryPopupInfo = dictionaryPopupInfoForRange(*frame, *lookupRange, options, TextIndicatorPresentationTransition::FadeIn);
- }
+ if (auto* frame = node->document().frame())
+ immediateActionResult.dictionaryPopupInfo = dictionaryPopupInfoForRange(*frame, lookupRange, options, TextIndicatorPresentationTransition::FadeIn);
}
}
@@ -936,11 +934,11 @@
send(Messages::WebPageProxy::DidPerformImmediateActionHitTest(immediateActionResult, immediateActionHitTestPreventsDefault, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
}
-std::tuple<RefPtr<WebCore::Range>, NSDictionary *> WebPage::lookupTextAtLocation(FloatPoint locationInViewCoordinates)
+Optional<std::tuple<WebCore::SimpleRange, NSDictionary *>> WebPage::lookupTextAtLocation(FloatPoint locationInViewCoordinates)
{
auto& mainFrame = corePage()->mainFrame();
if (!mainFrame.view() || !mainFrame.view()->renderView())
- return { nullptr, nil };
+ return WTF::nullopt;
auto point = roundedIntPoint(locationInViewCoordinates);
constexpr OptionSet<HitTestRequest::RequestType> hitType { HitTestRequest::ReadOnly, HitTestRequest::Active, HitTestRequest::DisallowUserAgentShadowContent, HitTestRequest::AllowChildFrameContent };
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (264246 => 264247)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2020-07-10 23:59:56 UTC (rev 264247)
@@ -1,3 +1,14 @@
+2020-07-08 Darin Adler <[email protected]>
+
+ Remove live ranges from Document.h, AlternativeTextController.h, DictionaryLookup.h, and WebPage.h
+ https://bugs.webkit.org/show_bug.cgi?id=214109
+
+ Reviewed by Sam Weinig.
+
+ * WebView/WebImmediateActionController.mm:
+ (-[WebImmediateActionController _animationControllerForText]): Update since
+ DictionaryLookup::rangeAtHitTestResult returns SimpleRange.
+
2020-07-09 Brian Burg <[email protected]>
REGRESSION(r217248): ASSERT_NOT_REACHED() in toWebFrameLoadType()
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm (264246 => 264247)
--- trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm 2020-07-10 23:34:44 UTC (rev 264246)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm 2020-07-10 23:59:56 UTC (rev 264247)
@@ -550,19 +550,20 @@
if (!PAL::getLULookupDefinitionModuleClass())
return nil;
- WebCore::Node* node = _hitTestResult.innerNode();
+ auto node = _hitTestResult.innerNode();
if (!node)
return nil;
- WebCore::Frame* frame = node->document().frame();
+ auto frame = node->document().frame();
if (!frame)
return nil;
- auto [dictionaryRange, options] = WebCore::DictionaryLookup::rangeAtHitTestResult(_hitTestResult);
- if (!dictionaryRange)
+ auto range = WebCore::DictionaryLookup::rangeAtHitTestResult(_hitTestResult);
+ if (!range)
return nil;
- auto dictionaryPopupInfo = [WebImmediateActionController _dictionaryPopupInfoForRange:*dictionaryRange inFrame:frame withLookupOptions:options indicatorOptions:{ } transition: WebCore::TextIndicatorPresentationTransition::FadeIn];
+ auto [dictionaryRange, options] = WTFMove(*range);
+ auto dictionaryPopupInfo = [WebImmediateActionController _dictionaryPopupInfoForRange:dictionaryRange inFrame:frame withLookupOptions:options indicatorOptions: { } transition: WebCore::TextIndicatorPresentationTransition::FadeIn];
if (!dictionaryPopupInfo.attributedString)
return nil;