Diff
Modified: trunk/Source/WebCore/ChangeLog (259932 => 259933)
--- trunk/Source/WebCore/ChangeLog 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/ChangeLog 2020-04-11 19:36:43 UTC (rev 259933)
@@ -1,3 +1,51 @@
+2020-04-10 Darin Adler <[email protected]>
+
+ Move more from live range to SimpleRange: callers of absoluteTextRects
+ https://bugs.webkit.org/show_bug.cgi?id=210369
+
+ Reviewed by Anders Carlsson.
+
+ * dom/Node.cpp:
+ (WebCore::Node::textRects const): Deleted.
+ * dom/Node.h: Updated for the above.
+
+ * dom/Range.cpp:
+ (WebCore::Range::absoluteBoundingBox const): Updated since absoluteTextRects
+ no longer has a RangeInFixedPosition* argument.
+ (WebCore::Range::absoluteTextRects const): Removed the unused RangeInFixedPosition*
+ argument.
+ * dom/Range.h: Got rid of unused RangeInFixedPosition type and also removed
+ RangeInFixedPosition* argument from the absoluteTextRects function. Later will
+ remove absoluteTextRects entirely.
+
+ * editing/Editor.cpp:
+ (WebCore::Editor::firstRectForRange const): Use RenderObject::absoluteTextQuads
+ and unitedBoundingBoxes rather than using RenderObject::absoluteBoundingBoxRectForRange.
+
+ * editing/cocoa/DataDetection.mm:
+ (WebCore::DataDetection::detectContentInRange): Use SimpleRange rather than
+ live ranges.
+
+ * html/HTMLTextFormControlElement.cpp:
+ (WebCore::setContainerAndOffsetForRange): Moved from int to unsigned.
+ (WebCore::HTMLTextFormControlElement::selection const): Return Optional<SimpleRange>
+ rather than a live range.
+ * html/HTMLTextFormControlElement.h: Updated for the change above.
+
+ * page/TextIndicator.cpp:
+ (WebCore::initializeIndicator): Updated since absoluteTextRects no longer takes
+ a RangeInFixedPosition* argument.
+
+ * rendering/HighlightData.h: Removed stray obsolete declaration.
+
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::absoluteBoundingBoxRectForRange): Deleted. Callers can
+ use absoluteTextQuads directly. We need to cut down on the number of separate
+ functions that are not really separate concepts, and this was used in only one place.
+ (WebCore::RenderObject::absoluteTextRects): Added. Replaces Range::absoluteTextRects
+ for all callers outside the live range class and will eventually replace it entirely.
+ * rendering/RenderObject.h: Updated for the above.
+
2020-04-11 Devin Rousso <[email protected]>
REGRESSION (Safari 13.1?): Web Inspector: Debugger hang at breakpoint when using Keyboard Maestro
Modified: trunk/Source/WebCore/dom/Node.cpp (259932 => 259933)
--- trunk/Source/WebCore/dom/Node.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/dom/Node.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -2554,13 +2554,6 @@
delete this;
}
-void Node::textRects(Vector<IntRect>& rects) const
-{
- auto range = Range::create(document());
- range->selectNodeContents(const_cast<Node&>(*this));
- range->absoluteTextRects(rects);
-}
-
unsigned Node::connectedSubframeCount() const
{
return hasRareData() ? rareData()->connectedSubframeCount() : 0;
Modified: trunk/Source/WebCore/dom/Node.h (259932 => 259933)
--- trunk/Source/WebCore/dom/Node.h 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/dom/Node.h 2020-04-11 19:36:43 UTC (rev 259933)
@@ -493,8 +493,6 @@
void unregisterTransientMutationObserver(MutationObserverRegistration&);
void notifyMutationObserversNodeWillDetach();
- WEBCORE_EXPORT void textRects(Vector<IntRect>&) const;
-
unsigned connectedSubframeCount() const;
void incrementConnectedSubframeCount(unsigned amount = 1);
void decrementConnectedSubframeCount(unsigned amount = 1);
Modified: trunk/Source/WebCore/dom/Range.cpp (259932 => 259933)
--- trunk/Source/WebCore/dom/Range.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/dom/Range.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -1145,11 +1145,9 @@
IntRect Range::absoluteBoundingBox(OptionSet<BoundingRectBehavior> rectOptions) const
{
+ Vector<IntRect> rects;
+ absoluteTextRects(rects, false, rectOptions);
IntRect result;
- Vector<IntRect> rects;
- bool useSelectionHeight = false;
- RangeInFixedPosition* inFixed = nullptr;
- absoluteTextRects(rects, useSelectionHeight, inFixed, rectOptions);
for (auto& rect : rects)
result.unite(rect);
return result;
@@ -1180,7 +1178,7 @@
return boundingBoxes(textQuads);
}
-void Range::absoluteTextRects(Vector<IntRect>& rects, bool useSelectionHeight, RangeInFixedPosition* inFixed, OptionSet<BoundingRectBehavior> rectOptions) const
+void Range::absoluteTextRects(Vector<IntRect>& rects, bool useSelectionHeight, OptionSet<BoundingRectBehavior> rectOptions) const
{
// FIXME: This function should probably return FloatRects.
@@ -1204,9 +1202,6 @@
allFixed &= isFixed;
someFixed |= isFixed;
}
-
- if (inFixed)
- *inFixed = allFixed ? EntirelyFixedPosition : (someFixed ? PartiallyFixedPosition : NotFixedPosition);
}
#if PLATFORM(IOS_FAMILY)
Modified: trunk/Source/WebCore/dom/Range.h (259932 => 259933)
--- trunk/Source/WebCore/dom/Range.h 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/dom/Range.h 2020-04-11 19:36:43 UTC (rev 259933)
@@ -107,12 +107,6 @@
ShadowRoot* shadowRoot() const;
- enum RangeInFixedPosition {
- NotFixedPosition,
- PartiallyFixedPosition,
- EntirelyFixedPosition
- };
-
enum class BoundingRectBehavior : uint8_t {
RespectClipping = 1 << 0,
UseVisibleBounds = 1 << 1,
@@ -121,7 +115,7 @@
};
// Not transform-friendly
- WEBCORE_EXPORT void absoluteTextRects(Vector<IntRect>&, bool useSelectionHeight = false, RangeInFixedPosition* = nullptr, OptionSet<BoundingRectBehavior> = { }) const;
+ WEBCORE_EXPORT void absoluteTextRects(Vector<IntRect>&, bool useSelectionHeight = false, OptionSet<BoundingRectBehavior> = { }) const;
WEBCORE_EXPORT IntRect absoluteBoundingBox(OptionSet<BoundingRectBehavior> = { }) const;
// Transform-friendly
Modified: trunk/Source/WebCore/editing/Editor.cpp (259932 => 259933)
--- trunk/Source/WebCore/editing/Editor.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/editing/Editor.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -3365,6 +3365,8 @@
IntRect Editor::firstRectForRange(Range* range) const
{
+ range->ownerDocument().updateLayout();
+
VisiblePosition startVisiblePosition(range->startPosition(), DOWNSTREAM);
if (range->collapsed()) {
@@ -3378,7 +3380,7 @@
VisiblePosition endVisiblePosition(range->endPosition(), UPSTREAM);
if (inSameLine(startVisiblePosition, endVisiblePosition))
- return enclosingIntRect(RenderObject::absoluteBoundingBoxRectForRange(range));
+ return enclosingIntRect(unitedBoundingBoxes(RenderObject::absoluteTextQuads(*range)));
LayoutUnit extraWidthToEndOfLine;
IntRect startCaretRect = RenderedPosition(startVisiblePosition).absoluteRect(&extraWidthToEndOfLine);
Modified: trunk/Source/WebCore/editing/cocoa/DataDetection.mm (259932 => 259933)
--- trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/editing/cocoa/DataDetection.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -490,7 +490,7 @@
currentTopLevelIndex++;
}
- Vector<Vector<RefPtr<Range>>> allResultRanges;
+ Vector<Vector<SimpleRange>> allResultRanges;
TextIterator iterator(*contextRange);
CFIndex iteratorCount = 0;
@@ -503,19 +503,17 @@
for (; iteratorCount < iteratorTargetAdvanceCount; ++iteratorCount)
iterator.advance();
- Vector<RefPtr<Range>> fragmentRanges;
- RefPtr<Range> currentRange = createLiveRange(iterator.range());
+ Vector<SimpleRange> fragmentRanges;
CFIndex fragmentIndex = queryRange.start.queryIndex;
if (fragmentIndex == queryRange.end.queryIndex) {
CharacterRange fragmentRange;
fragmentRange.location = queryRange.start.offset;
fragmentRange.length = queryRange.end.offset - queryRange.start.offset;
- fragmentRanges.append(createLiveRange(resolveCharacterRange(*currentRange, fragmentRange)));
+ fragmentRanges.append(resolveCharacterRange(iterator.range(), fragmentRange));
} else {
- if (!queryRange.start.offset)
- fragmentRanges.append(currentRange);
- else
- fragmentRanges.append(Range::create(currentRange->ownerDocument(), ¤tRange->startContainer(), currentRange->startOffset() + queryRange.start.offset, ¤tRange->endContainer(), currentRange->endOffset()));
+ auto range = iterator.range();
+ range.start.offset += queryRange.start.offset;
+ fragmentRanges.append(range);
}
while (fragmentIndex < queryRange.end.queryIndex) {
@@ -524,18 +522,18 @@
for (; iteratorCount < iteratorTargetAdvanceCount; ++iteratorCount)
iterator.advance();
- currentRange = createLiveRange(iterator.range());
- RefPtr<Range> fragmentRange = (fragmentIndex == queryRange.end.queryIndex) ? Range::create(currentRange->ownerDocument(), ¤tRange->startContainer(), currentRange->startOffset(), ¤tRange->endContainer(), currentRange->startOffset() + queryRange.end.offset) : currentRange;
- RefPtr<Range> previousRange = fragmentRanges.last();
- if (&previousRange->startContainer() == &fragmentRange->startContainer()) {
- fragmentRange = Range::create(currentRange->ownerDocument(), &previousRange->startContainer(), previousRange->startOffset(), &fragmentRange->endContainer(), fragmentRange->endOffset());
- fragmentRanges.last() = fragmentRange;
- } else
+ auto fragmentRange = iterator.range();
+ if (fragmentIndex == queryRange.end.queryIndex)
+ fragmentRange.end.offset = fragmentRange.start.offset + queryRange.end.offset;
+ auto& previousRange = fragmentRanges.last();
+ if (previousRange.start.container.ptr() == fragmentRange.start.container.ptr())
+ previousRange.end = fragmentRange.end;
+ else
fragmentRanges.append(fragmentRange);
}
allResultRanges.append(WTFMove(fragmentRanges));
}
-
+
auto tz = adoptCF(CFTimeZoneCopyDefault());
NSDate *referenceDate = [context objectForKey:getkDataDetectorsReferenceDateKey()] ?: [NSDate date];
Text* lastTextNodeToUpdate = nullptr;
@@ -565,13 +563,13 @@
Vector<std::pair<Position, Position>> rangeBoundaries;
rangeBoundaries.reserveInitialCapacity(resultRanges.size());
for (auto& range : resultRanges)
- rangeBoundaries.uncheckedAppend({ range->startPosition(), range->endPosition() });
+ rangeBoundaries.uncheckedAppend({ createLegacyEditingPosition(range.start), createLegacyEditingPosition(range.end) });
NSString *identifier = dataDetectorStringForPath(indexPaths[resultIndex].get());
NSString *correspondingURL = constructURLStringForResult(coreResult, identifier, referenceDate, (NSTimeZone *)tz.get(), types);
bool didModifyDOM = false;
- if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first()->startContainer(), resultRanges.last()->endContainer(), didModifyDOM))
+ if (!correspondingURL || searchForLinkRemovingExistingDDLinks(resultRanges.first().start.container, resultRanges.last().end.container, didModifyDOM))
continue;
if (didModifyDOM) {
@@ -587,14 +585,14 @@
BOOL shouldUseLightLinks = softLink_DataDetectorsCore_DDShouldUseLightLinksForResult(coreResult, [indexPaths[resultIndex] length] > 1);
for (auto& range : resultRanges) {
- auto* parentNode = range->startContainer().parentNode();
+ auto* parentNode = range.start.container->parentNode();
if (!parentNode)
continue;
- if (!is<Text>(range->startContainer()))
+ if (!is<Text>(range.start.container))
continue;
- auto& currentTextNode = downcast<Text>(range->startContainer());
+ auto& currentTextNode = downcast<Text>(range.start.container.get());
Document& document = currentTextNode.document();
String textNodeData;
@@ -602,18 +600,18 @@
if (lastTextNodeToUpdate)
lastTextNodeToUpdate->setData(lastNodeContent);
contentOffset = 0;
- if (range->startOffset() > 0)
- textNodeData = currentTextNode.data().substring(0, range->startOffset());
+ if (range.start.offset > 0)
+ textNodeData = currentTextNode.data().substring(0, range.start.offset);
} else
- textNodeData = currentTextNode.data().substring(contentOffset, range->startOffset() - contentOffset);
+ textNodeData = currentTextNode.data().substring(contentOffset, range.start.offset - contentOffset);
if (!textNodeData.isEmpty()) {
parentNode->insertBefore(Text::create(document, textNodeData), ¤tTextNode);
- contentOffset = range->startOffset();
+ contentOffset = range.start.offset;
}
// Create the actual anchor node and insert it before the current node.
- textNodeData = currentTextNode.data().substring(range->startOffset(), range->endOffset() - range->startOffset());
+ textNodeData = currentTextNode.data().substring(range.start.offset, range.end.offset - range.start.offset);
Ref<Text> newTextNode = Text::create(document, textNodeData);
parentNode->insertBefore(newTextNode.copyRef(), ¤tTextNode);
@@ -652,9 +650,9 @@
parentNode->insertBefore(WTFMove(anchorElement), ¤tTextNode);
- contentOffset = range->endOffset();
+ contentOffset = range.end.offset;
- lastNodeContent = currentTextNode.data().substring(range->endOffset(), currentTextNode.length() - range->endOffset());
+ lastNodeContent = currentTextNode.data().substring(range.end.offset, currentTextNode.length() - range.end.offset);
lastTextNodeToUpdate = ¤tTextNode;
}
}
Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (259932 => 259933)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -435,7 +435,7 @@
return selection.isDirectional() ? (selection.isBaseFirst() ? SelectionHasForwardDirection : SelectionHasBackwardDirection) : SelectionHasNoDirection;
}
-static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer)
+static void setContainerAndOffsetForRange(Node* node, unsigned offset, Node*& containerNode, unsigned& offsetInContainer)
{
if (node->isTextNode()) {
containerNode = node;
@@ -446,30 +446,31 @@
}
}
-RefPtr<Range> HTMLTextFormControlElement::selection() const
+Optional<SimpleRange> HTMLTextFormControlElement::selection() const
{
if (!renderer() || !isTextField() || !hasCachedSelection())
- return nullptr;
+ return WTF::nullopt;
- int start = m_cachedSelectionStart;
- int end = m_cachedSelectionEnd;
+ unsigned start = m_cachedSelectionStart;
+ unsigned end = m_cachedSelectionEnd;
ASSERT(start <= end);
auto innerText = innerTextElement();
if (!innerText)
- return nullptr;
+ return WTF::nullopt;
if (!innerText->firstChild())
- return Range::create(document(), innerText, 0, innerText, 0);
+ return SimpleRange { { *innerText, 0 }, { *innerText, 0 } };
- int offset = 0;
+ unsigned offset = 0;
Node* startNode = nullptr;
Node* endNode = nullptr;
for (RefPtr<Node> node = innerText->firstChild(); node; node = NodeTraversal::next(*node, innerText.get())) {
ASSERT(!node->firstChild());
ASSERT(node->isTextNode() || node->hasTagName(brTag));
- int length = is<Text>(*node) ? downcast<Text>(*node).length() : 1;
+ unsigned length = is<Text>(*node) ? downcast<Text>(*node).length() : 1;
+
if (offset <= start && start <= offset + length)
setContainerAndOffsetForRange(node.get(), start - offset, startNode, start);
@@ -482,9 +483,9 @@
}
if (!startNode || !endNode)
- return nullptr;
+ return WTF::nullopt;
- return Range::create(document(), startNode, start, endNode, end);
+ return SimpleRange { { *startNode, start }, { *endNode, end } };
}
void HTMLTextFormControlElement::restoreCachedSelection(SelectionRevealMode revealMode, const AXTextStateChangeIntent& intent)
Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.h (259932 => 259933)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2020-04-11 19:36:43 UTC (rev 259933)
@@ -33,6 +33,8 @@
class TextControlInnerTextElement;
class VisiblePosition;
+struct SimpleRange;
+
enum class AutoFillButtonType : uint8_t { None, Credentials, Contacts, StrongPassword, CreditCard };
enum TextFieldSelectionDirection { SelectionHasNoDirection, SelectionHasForwardDirection, SelectionHasBackwardDirection };
enum TextFieldEventBehavior { DispatchNoEvent, DispatchChangeEvent, DispatchInputAndChangeEvent };
@@ -78,7 +80,8 @@
WEBCORE_EXPORT virtual ExceptionOr<void> setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode);
void setSelectionRange(int start, int end, const String& direction, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
WEBCORE_EXPORT void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection, SelectionRevealMode = SelectionRevealMode::DoNotReveal, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
- RefPtr<Range> selection() const;
+
+ Optional<SimpleRange> selection() const;
String selectedText() const;
void dispatchFormControlChangeEvent() final;
Modified: trunk/Source/WebCore/page/TextIndicator.cpp (259932 => 259933)
--- trunk/Source/WebCore/page/TextIndicator.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/page/TextIndicator.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -337,7 +337,7 @@
#endif
else {
Vector<IntRect> absoluteTextRects;
- range.absoluteTextRects(absoluteTextRects, textRectHeight == FrameSelection::TextRectangleHeight::SelectionHeight, nullptr, Range::BoundingRectBehavior::RespectClipping);
+ range.absoluteTextRects(absoluteTextRects, textRectHeight == FrameSelection::TextRectangleHeight::SelectionHeight, Range::BoundingRectBehavior::RespectClipping);
textRects.reserveInitialCapacity(absoluteTextRects.size());
for (auto& rect : absoluteTextRects)
Modified: trunk/Source/WebCore/rendering/HighlightData.h (259932 => 259933)
--- trunk/Source/WebCore/rendering/HighlightData.h 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/rendering/HighlightData.h 2020-04-11 19:36:43 UTC (rev 259933)
@@ -37,8 +37,6 @@
#endif
namespace WebCore {
-
-struct OldSelectionData;
class HighlightData {
public:
Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (259932 => 259933)
--- trunk/Source/WebCore/rendering/RenderObject.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -746,14 +746,6 @@
}
}
-FloatRect RenderObject::absoluteBoundingBoxRectForRange(const Range* range)
-{
- if (!range)
- return { };
- range->ownerDocument().updateLayout();
- return unitedBoundingBoxes(absoluteTextQuads(*range));
-}
-
void RenderObject::addAbsoluteRectForLayer(LayoutRect& result)
{
if (hasLayer())
@@ -1902,6 +1894,22 @@
return quads;
}
+Vector<IntRect> RenderObject::absoluteTextRects(const SimpleRange& range, bool useSelectionHeight)
+{
+ Vector<IntRect> rects;
+ for (auto& node : intersectingNodes(range)) {
+ auto renderer = node.renderer();
+ if (renderer && renderer->isBR())
+ renderer->absoluteRects(rects, flooredLayoutPoint(renderer->localToAbsolute()));
+ else if (is<RenderText>(renderer)) {
+ auto offsetRange = characterDataOffsetRange(range, downcast<CharacterData>(node));
+ for (auto& quad : downcast<RenderText>(*renderer).absoluteQuadsForRange(offsetRange.start, offsetRange.end, useSelectionHeight))
+ rects.append(quad.enclosingBoundingBox());
+ }
+ }
+ return rects;
+}
+
String RenderObject::debugDescription() const
{
StringBuilder builder;
Modified: trunk/Source/WebCore/rendering/RenderObject.h (259932 => 259933)
--- trunk/Source/WebCore/rendering/RenderObject.h 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebCore/rendering/RenderObject.h 2020-04-11 19:36:43 UTC (rev 259933)
@@ -558,7 +558,7 @@
virtual void absoluteFocusRingQuads(Vector<FloatQuad>&);
WEBCORE_EXPORT static Vector<FloatQuad> absoluteTextQuads(const SimpleRange&, bool useSelectionHeight = false);
- static FloatRect absoluteBoundingBoxRectForRange(const Range*);
+ WEBCORE_EXPORT static Vector<IntRect> absoluteTextRects(const SimpleRange&, bool useSelectionHeight = false);
// the rect that will be painted if this object is passed as the paintingRoot
WEBCORE_EXPORT LayoutRect paintingRootRect(LayoutRect& topLevelRect);
Modified: trunk/Source/WebKit/ChangeLog (259932 => 259933)
--- trunk/Source/WebKit/ChangeLog 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKit/ChangeLog 2020-04-11 19:36:43 UTC (rev 259933)
@@ -1,3 +1,24 @@
+2020-04-10 Darin Adler <[email protected]>
+
+ Move more from live range to SimpleRange: callers of absoluteTextRects
+ https://bugs.webkit.org/show_bug.cgi?id=210369
+
+ Reviewed by Anders Carlsson.
+
+ * WebProcess/InjectedBundle/API/mac/WKDOMNode.mm:
+ (-[WKDOMNode textRects]): Moved implementation here. There's no reason for Node
+ to have a textRects function, since it's a layout/rendering operation and a
+ single node is also an unusual special case, but for now at least we will keep
+ this legacy method.
+ * WebProcess/InjectedBundle/API/mac/WKDOMRange.mm:
+ (-[WKDOMRange textRects]): Changed to call RenderObject::absoluteTextRects
+ instead of Range::absoluteTextRects.
+
+ * WebProcess/WebPage/FindController.cpp:
+ (WebKit::FindController::updateFindUIAfterPageScroll): Use
+ RenderObject::absoluteTextRects instead of Range::absoluteRectRects.
+ (WebKit::FindController::findStringMatches): Ditto.
+
2020-04-10 Pablo Saavedra <[email protected]>
[GTK][WPE] Replace fopen/fclose by fopen/fseek functions in MemoryPressureMonitor
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMNode.mm (259932 => 259933)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMNode.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMNode.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -30,6 +30,8 @@
#import "WKBundleAPICast.h"
#import "WKDOMInternals.h"
#import <WebCore/Document.h>
+#import <WebCore/RenderObject.h>
+#import <WebCore/SimpleRange.h>
#import <wtf/cocoa/VectorCocoa.h>
@implementation WKDOMNode
@@ -111,9 +113,7 @@
_impl->document().updateLayoutIgnorePendingStylesheets();
if (!_impl->renderer())
return nil;
- Vector<WebCore::IntRect> rects;
- _impl->textRects(rects);
- return createNSArray(rects).autorelease();
+ return createNSArray(WebCore::RenderObject::absoluteTextRects(WebCore::makeRangeSelectingNodeContents(*_impl))).autorelease();
}
@end
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm (259932 => 259933)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMRange.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -129,9 +129,7 @@
- (NSArray *)textRects
{
_impl->ownerDocument().updateLayoutIgnorePendingStylesheets();
- Vector<WebCore::IntRect> rects;
- _impl->absoluteTextRects(rects);
- return createNSArray(rects).autorelease();
+ return createNSArray(WebCore::RenderObject::absoluteTextRects(*_impl)).autorelease();
}
- (WKDOMRange *)rangeByExpandingToWordBoundaryByCharacters:(NSUInteger)characters inDirection:(WKDOMRangeDirection)direction
Modified: trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp (259932 => 259933)
--- trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp 2020-04-11 19:36:43 UTC (rev 259933)
@@ -202,10 +202,9 @@
m_findMatches.clear();
Vector<IntRect> matchRects;
if (auto range = m_webPage->corePage()->selection().firstRange()) {
- range->absoluteTextRects(matchRects);
- m_findMatches.append(range);
+ matchRects = RenderObject::absoluteTextRects(*range);
+ m_findMatches.append(WTFMove(range));
}
-
m_webPage->send(Messages::WebPageProxy::DidFindString(string, matchRects, matchCount, m_foundStringMatchIndex, didWrap == DidWrap::Yes));
}
}
@@ -292,11 +291,8 @@
m_webPage->corePage()->findStringMatchingRanges(string, core(options), maxMatchCount, m_findMatches, indexForSelection);
Vector<Vector<IntRect>> matchRects;
- for (size_t i = 0; i < m_findMatches.size(); ++i) {
- Vector<IntRect> rects;
- m_findMatches[i]->absoluteTextRects(rects);
- matchRects.append(WTFMove(rects));
- }
+ for (auto& range : m_findMatches)
+ matchRects.append(RenderObject::absoluteTextRects(*range));
m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
Modified: trunk/Source/WebKitLegacy/ios/ChangeLog (259932 => 259933)
--- trunk/Source/WebKitLegacy/ios/ChangeLog 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKitLegacy/ios/ChangeLog 2020-04-11 19:36:43 UTC (rev 259933)
@@ -1,3 +1,16 @@
+2020-04-10 Darin Adler <[email protected]>
+
+ Move more from live range to SimpleRange: callers of absoluteTextRects
+ https://bugs.webkit.org/show_bug.cgi?id=210369
+
+ Reviewed by Anders Carlsson.
+
+ * WebCoreSupport/WebFrameIOS.mm:
+ (-[WebFrame closestCaretRectInMarkedTextRangeForPoint:]): Use
+ RenderObject::absoluteTextRects instead of Range::absoluteTextRects.
+ Also added some missing null checks and reorganized the function a
+ bit to make it more direct and slightly cleaerer.
+
2020-04-08 Darin Adler <[email protected]>
[Cocoa] Simplify NSArray, NSDictionary, and NSNumber idioms throughout WebKit
Modified: trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebFrameIOS.mm (259932 => 259933)
--- trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebFrameIOS.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKitLegacy/ios/WebCoreSupport/WebFrameIOS.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -133,52 +133,52 @@
- (CGRect)closestCaretRectInMarkedTextRangeForPoint:(CGPoint)point
{
- Frame *frame = [self coreFrame];
- Range *markedTextRange = frame->editor().compositionRange().get();
- VisibleSelection markedTextRangeSelection = markedTextRange ? VisibleSelection(*markedTextRange) : VisibleSelection();
+ auto frame = [self coreFrame];
+ if (!frame)
+ return { };
- IntRect result;
+ auto document = frame->document();
+ if (!document)
+ return { };
- if (markedTextRangeSelection.isRange()) {
- VisiblePosition start(markedTextRangeSelection.start());
- VisiblePosition end(markedTextRangeSelection.end());
+ document->updateLayout();
- // Adjust pos and give it an appropriate affinity.
- VisiblePosition pos;
- Vector<IntRect> intRects;
- markedTextRange->absoluteTextRects(intRects, NO);
- unsigned size = intRects.size();
- CGRect firstRect = intRects[0];
- CGRect lastRect = intRects[size-1];
- if (point.y < firstRect.origin.y) {
- point.y = firstRect.origin.y;
- pos = [self visiblePositionForPoint:point];
- pos.setAffinity(UPSTREAM);
- }
- else if (point.y >= lastRect.origin.y) {
- point.y = lastRect.origin.y;
- pos = [self visiblePositionForPoint:point];
- pos.setAffinity(DOWNSTREAM);
- }
- else {
- pos = [self visiblePositionForPoint:point];
- }
-
- if (pos == start || pos < start) {
- start.setAffinity(UPSTREAM);
- result = start.absoluteCaretBounds();
- } else if (pos > end) {
- end.setAffinity(DOWNSTREAM);
- result = end.absoluteCaretBounds();
- } else {
- result = pos.absoluteCaretBounds();
- }
+ auto markedTextRange = frame->editor().compositionRange().get();
+ auto markedTextRangeSelection = markedTextRange ? VisibleSelection(*markedTextRange) : VisibleSelection();
+
+ if (!markedTextRangeSelection.isRange())
+ return [self visiblePositionForPoint:point].absoluteCaretBounds();
+
+ auto intRects = RenderObject::absoluteTextRects(*markedTextRange);
+ CGRect firstRect = intRects.first();
+ CGRect lastRect = intRects.last();
+
+ VisiblePosition start = markedTextRangeSelection.start();
+ VisiblePosition end = markedTextRangeSelection.end();
+ VisiblePosition position;
+
+ // Adjust position and give it an appropriate affinity.
+ if (point.y < firstRect.origin.y) {
+ point.y = firstRect.origin.y;
+ position = [self visiblePositionForPoint:point];
+ position.setAffinity(UPSTREAM);
+ } else if (point.y >= lastRect.origin.y) {
+ point.y = lastRect.origin.y;
+ position = [self visiblePositionForPoint:point];
+ position.setAffinity(DOWNSTREAM);
} else {
- VisiblePosition pos = [self visiblePositionForPoint:point];
- result = pos.absoluteCaretBounds();
+ position = [self visiblePositionForPoint:point];
}
-
- return (CGRect) result;
+
+ if (position == start || position < start) {
+ start.setAffinity(UPSTREAM);
+ return start.absoluteCaretBounds();
+ }
+ if (position > end) {
+ end.setAffinity(DOWNSTREAM);
+ return end.absoluteCaretBounds();
+ }
+ return position.absoluteCaretBounds();
}
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (259932 => 259933)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2020-04-11 19:36:43 UTC (rev 259933)
@@ -1,3 +1,23 @@
+2020-04-10 Darin Adler <[email protected]>
+
+ Move more from live range to SimpleRange: callers of absoluteTextRects
+ https://bugs.webkit.org/show_bug.cgi?id=210369
+
+ Reviewed by Anders Carlsson.
+
+ * DOM/DOM.mm:
+ (-[DOMNode textRects]): Moved implementation here. There's no reason for Node
+ to have a textRects function, since it's a layout/rendering operation and a
+ single node is also an unusual special case, but for now we will keep this
+ legacy method for compatibility with old clients.
+ (-[DOMRange textRects]): Changed to call RenderObject::absoluteTextRects
+ instead of Range::absoluteTextRects.
+
+ * WebView/WebFrame.mm:
+ (-[WebFrame _rectsForRange:]): Changed to call -[DOMRange textRects] instead
+ of Range::absoluteTextRects. Don't really need two identical methods but
+ probably need to keep this around for compatiblitiy.
+
2020-04-08 Darin Adler <[email protected]>
[Cocoa] Simplify NSArray, NSDictionary, and NSNumber idioms throughout WebKit
Modified: trunk/Source/WebKitLegacy/mac/DOM/DOM.mm (259932 => 259933)
--- trunk/Source/WebKitLegacy/mac/DOM/DOM.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKitLegacy/mac/DOM/DOM.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -74,9 +74,6 @@
using namespace JSC;
using namespace WebCore;
-// FIXME: These methods should move into the implementation files of the DOM classes
-// and this file should be eliminated.
-
//------------------------------------------------------------------------------------------
// DOMNode
@@ -505,9 +502,7 @@
node.document().updateLayoutIgnorePendingStylesheets();
if (!node.renderer())
return nil;
- Vector<WebCore::IntRect> rects;
- node.textRects(rects);
- return createNSArray(rects).autorelease();
+ return createNSArray(RenderObject::absoluteTextRects(makeRangeSelectingNodeContents(node))).autorelease();
}
@end
@@ -625,10 +620,8 @@
- (NSArray *)textRects
{
auto& range = *core(self);
- Vector<WebCore::IntRect> rects;
range.ownerDocument().updateLayoutIgnorePendingStylesheets();
- range.absoluteTextRects(rects);
- return createNSArray(rects).autorelease();
+ return createNSArray(RenderObject::absoluteTextRects(range)).autorelease();
}
- (NSArray *)lineBoxRects
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm (259932 => 259933)
--- trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm 2020-04-11 18:46:51 UTC (rev 259932)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm 2020-04-11 19:36:43 UTC (rev 259933)
@@ -34,6 +34,7 @@
#import "DOMElementInternal.h"
#import "DOMHTMLElementInternal.h"
#import "DOMNodeInternal.h"
+#import "DOMPrivate.h"
#import "DOMRangeInternal.h"
#import "WebArchiveInternal.h"
#import "WebChromeClient.h"
@@ -1109,14 +1110,9 @@
return _private->coreFrame->loader().loadsSynchronously();
}
-- (NSArray *)_rectsForRange:(DOMRange *)domRange
+- (NSArray *)_rectsForRange:(DOMRange *)range
{
- auto* range = core(domRange);
- if (!range)
- return @[];
- Vector<WebCore::IntRect> intRects;
- range->absoluteTextRects(intRects, NO);
- return createNSArray(intRects).autorelease();
+ return range ? range.textRects : @[];
}
- (DOMRange *)_selectionRangeForFirstPoint:(CGPoint)first secondPoint:(CGPoint)second