Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (224067 => 224068)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2017-10-26 23:41:23 UTC (rev 224067)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2017-10-26 23:42:37 UTC (rev 224068)
@@ -1023,10 +1023,6 @@
static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector<WebCore::SelectionRect>&);
RefPtr<WebCore::Range> rangeForWebSelectionAtPosition(const WebCore::IntPoint&, const WebCore::VisiblePosition&, SelectionFlags&);
- RefPtr<WebCore::Range> rangeForBlockAtPoint(const WebCore::IntPoint&);
- void computeExpandAndShrinkThresholdsForHandle(const WebCore::IntPoint&, SelectionHandlePosition, float& growThreshold, float& shrinkThreshold);
- Ref<WebCore::Range> expandedRangeFromHandle(WebCore::Range&, SelectionHandlePosition);
- Ref<WebCore::Range> contractedRangeFromHandle(WebCore::Range& currentRange, SelectionHandlePosition, SelectionFlags&);
void getAssistedNodeInformation(AssistedNodeInformation&);
void platformInitializeAccessibility();
void handleSyntheticClick(WebCore::Node* nodeRespondingToClick, const WebCore::FloatPoint& location);
@@ -1035,8 +1031,6 @@
void resetTextAutosizing();
WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithAssistedNode);
RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithAssistedNode);
- bool shouldSwitchToBlockModeForHandle(const WebCore::IntPoint& handlePoint, SelectionHandlePosition);
- RefPtr<WebCore::Range> switchToBlockSelectionAtPoint(const WebCore::IntPoint&, SelectionHandlePosition);
#if ENABLE(DATA_INTERACTION)
void requestStartDataInteraction(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
void requestAdditionalItemsForDragSession(const WebCore::IntPoint& clientPosition, const WebCore::IntPoint& globalPosition);
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (224067 => 224068)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2017-10-26 23:41:23 UTC (rev 224067)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2017-10-26 23:42:37 UTC (rev 224068)
@@ -983,13 +983,6 @@
return renderer && renderer->childrenInline() && (is<RenderBlock>(*renderer) && !downcast<RenderBlock>(*renderer).inlineElementContinuation()) && !renderer->isTable();
}
-static bool canShrinkToTextSelection(Range& range)
-{
- if (range.startContainer().isTextNode() && range.endContainer().isTextNode())
- return true;
- return canShrinkToTextSelection(range.commonAncestorContainer());
-}
-
static bool hasCustomLineHeight(Node& node)
{
auto* renderer = node.renderer();
@@ -1068,30 +1061,6 @@
return range->collapsed() ? nullptr : range;
}
-RefPtr<Range> WebPage::rangeForBlockAtPoint(const IntPoint& point)
-{
- HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowUserAgentShadowContent | HitTestRequest::IgnoreClipping);
-
- Node* currentNode = result.innerNode();
- RefPtr<Range> range;
-
- if (currentNode->isTextNode()) {
- range = enclosingTextUnitOfGranularity(m_page->focusController().focusedOrMainFrame().visiblePositionForPoint(point), ParagraphGranularity, DirectionForward);
- if (range && !range->collapsed())
- return range;
- }
-
- if (!currentNode->isElementNode())
- currentNode = currentNode->parentElement();
-
- if (!currentNode)
- return nullptr;
-
- range = Range::create(currentNode->document());
- range->selectNodeContents(*currentNode);
- return range;
-}
-
void WebPage::selectWithGesture(const IntPoint& point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, CallbackID callbackID)
{
auto& frame = m_page->focusController().focusedOrMainFrame();
@@ -1307,357 +1276,6 @@
return (base < extent) ? Range::create(*frame->document(), base, extent) : Range::create(*frame->document(), extent, base);
}
-static const int maxHitTests = 10;
-
-static inline float distanceBetweenRectsForPosition(IntRect& first, IntRect& second, SelectionHandlePosition handlePosition)
-{
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- return abs(first.y() - second.y());
- case SelectionHandlePosition::Right:
- return abs(first.maxX() - second.maxX());
- case SelectionHandlePosition::Bottom:
- return abs(first.maxY() - second.maxY());
- case SelectionHandlePosition::Left:
- return abs(first.x() - second.x());
- }
-}
-
-static inline bool rectsEssentiallyTheSame(IntRect& first, IntRect& second, float allowablePercentDifference)
-{
- const float minMagnitudeRatio = 1.0 - allowablePercentDifference;
- const float maxDisplacementRatio = allowablePercentDifference;
-
- float xOriginShiftRatio = abs(first.x() - second.x())/std::min(first.width(), second.width());
- float yOriginShiftRatio = abs(first.y() - second.y())/std::min(first.height(), second.height());
-
- float widthRatio = std::min(first.width() / second.width(), second.width() / first.width());
- float heightRatio = std::min(first.height() / second.height(), second.height() / first.height());
- return ((widthRatio > minMagnitudeRatio && xOriginShiftRatio < maxDisplacementRatio)
- && (heightRatio > minMagnitudeRatio && yOriginShiftRatio < maxDisplacementRatio));
-}
-
-static inline RefPtr<Range> unionDOMRanges(Range* rangeA, Range* rangeB)
-{
- if (!rangeB)
- return rangeA;
- if (!rangeA)
- return rangeB;
-
- auto startToStartComparison = rangeA->compareBoundaryPoints(Range::START_TO_START, *rangeB);
- if (startToStartComparison.hasException())
- return nullptr;
-
- auto endToEndComparison = rangeA->compareBoundaryPoints(Range::END_TO_END, *rangeB);
- if (endToEndComparison.hasException())
- return nullptr;
-
- auto* start = startToStartComparison.releaseReturnValue() <= 0 ? rangeA : rangeB;
- auto* end = endToEndComparison.releaseReturnValue() <= 0 ? rangeB : rangeA;
-
- return Range::create(rangeA->ownerDocument(), &start->startContainer(), start->startOffset(), &end->endContainer(), end->endOffset());
-}
-
-static inline IntPoint computeEdgeCenter(const IntRect& box, SelectionHandlePosition handlePosition)
-{
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- return IntPoint(box.x() + box.width() / 2, box.y());
- case SelectionHandlePosition::Right:
- return IntPoint(box.maxX(), box.y() + box.height() / 2);
- case SelectionHandlePosition::Bottom:
- return IntPoint(box.x() + box.width() / 2, box.maxY());
- case SelectionHandlePosition::Left:
- return IntPoint(box.x(), box.y() + box.height() / 2);
- }
-}
-
-Ref<Range> WebPage::expandedRangeFromHandle(Range& currentRange, SelectionHandlePosition handlePosition)
-{
- IntRect currentBox = selectionBoxForRange(¤tRange);
- IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);
- static const float maxDistance = 1000;
- const float multiple = powf(maxDistance, 1.0/(maxHitTests - 1));
- float distance = 1;
-
- RefPtr<Range> bestRange;
- IntRect bestRect;
-
- while (distance < maxDistance) {
- if (bestRange) {
- if (distanceBetweenRectsForPosition(bestRect, currentBox, handlePosition) < distance) {
- // Break early, we're unlikely to do any better.
- break;
- }
- }
-
- IntPoint testPoint = edgeCenter;
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- testPoint.move(0, -distance);
- break;
- case SelectionHandlePosition::Right:
- testPoint.move(distance, 0);
- break;
- case SelectionHandlePosition::Bottom:
- testPoint.move(0, distance);
- break;
- case SelectionHandlePosition::Left:
- testPoint.move(-distance, 0);
- break;
- }
-
- distance = ceilf(distance * multiple);
-
- RefPtr<Range> newRange;
- RefPtr<Range> rangeAtPosition = rangeForBlockAtPoint(testPoint);
- if (!rangeAtPosition || ¤tRange.ownerDocument() != &rangeAtPosition->ownerDocument())
- continue;
-
- if (rangeAtPosition->contains(currentRange))
- newRange = rangeAtPosition;
- else if (currentRange.contains(*rangeAtPosition.get()))
- newRange = ¤tRange;
- else
- newRange = unionDOMRanges(¤tRange, rangeAtPosition.get());
-
- IntRect copyRect = selectionBoxForRange(newRange.get());
-
- // Is it different and bigger than the current?
- bool isBetterChoice = !(rectsEssentiallyTheSame(copyRect, currentBox, .05));
- if (isBetterChoice) {
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- isBetterChoice = (copyRect.height() > currentBox.height());
- break;
- case SelectionHandlePosition::Right:
- case SelectionHandlePosition::Left:
- isBetterChoice = (copyRect.width() > currentBox.width());
- break;
- }
-
- }
-
- if (bestRange && isBetterChoice) {
- // Furtherore, is it smaller than the best we've found so far?
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- isBetterChoice = (copyRect.height() < bestRect.height());
- break;
- case SelectionHandlePosition::Right:
- case SelectionHandlePosition::Left:
- isBetterChoice = (copyRect.width() < bestRect.width());
- break;
- }
- }
-
- if (isBetterChoice) {
- bestRange = newRange;
- bestRect = copyRect;
- }
- }
-
- if (bestRange)
- return bestRange.releaseNonNull();
-
- return currentRange;
-}
-
-Ref<Range> WebPage::contractedRangeFromHandle(Range& currentRange, SelectionHandlePosition handlePosition, SelectionFlags& flags)
-{
- // Shrinking with a base and extent will always give better results. If we only have a single element,
- // see if we can break that down to a base and extent. Shrinking base and extent is comparatively straightforward.
- // Shrinking down to another element is unlikely to move just one edge, but we can try that as a fallback.
-
- IntRect currentBox = selectionBoxForRange(¤tRange);
- IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);
-
- float maxDistance;
-
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- maxDistance = currentBox.height();
- break;
- case SelectionHandlePosition::Right:
- case SelectionHandlePosition::Left:
- maxDistance = currentBox.width();
- break;
- }
-
- const float multiple = powf(maxDistance - 1, 1.0/(maxHitTests - 1));
- float distance = 1;
- RefPtr<Range> bestRange;
- IntRect bestRect;
-
- while (distance < maxDistance) {
- if (bestRange) {
- float shrankDistance;
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- shrankDistance = abs(currentBox.height() - bestRect.height());
- break;
- case SelectionHandlePosition::Right:
- case SelectionHandlePosition::Left:
- shrankDistance = abs(currentBox.width() - bestRect.width());
- break;
- }
- if (shrankDistance > distance) {
- // Certainly not going to do any better than that.
- break;
- }
- }
-
- IntPoint testPoint = edgeCenter;
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- testPoint.move(0, distance);
- break;
- case SelectionHandlePosition::Right:
- testPoint.move(-distance, 0);
- break;
- case SelectionHandlePosition::Bottom:
- testPoint.move(0, -distance);
- break;
- case SelectionHandlePosition::Left:
- testPoint.move(distance, 0);
- break;
- }
-
- distance *= multiple;
-
- RefPtr<Range> newRange = rangeForBlockAtPoint(testPoint);
- if (!newRange || &newRange->ownerDocument() != ¤tRange.ownerDocument())
- continue;
-
- if (handlePosition == SelectionHandlePosition::Top || handlePosition == SelectionHandlePosition::Left)
- newRange = Range::create(newRange->startContainer().document(), newRange->endPosition(), currentRange.endPosition());
- else
- newRange = Range::create(newRange->startContainer().document(), currentRange.startPosition(), newRange->startPosition());
-
- IntRect copyRect = selectionBoxForRange(newRange.get());
- if (copyRect.isEmpty()) {
- // If the new range is an empty rectangle, we try the block at the current point
- // and see if that has a rectangle that is a better choice.
- newRange = rangeForBlockAtPoint(testPoint);
- copyRect = selectionBoxForRange(newRange.get());
- }
- bool isBetterChoice;
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- isBetterChoice = (copyRect.height() < currentBox.height());
- if (copyRect.height() == currentBox.height())
- isBetterChoice = canShrinkToTextSelection(*newRange.get());
- break;
- case SelectionHandlePosition::Left:
- case SelectionHandlePosition::Right:
- isBetterChoice = (copyRect.width() > bestRect.width());
- break;
- }
-
- isBetterChoice = isBetterChoice && !areRangesEqual(newRange.get(), ¤tRange);
- if (bestRange && isBetterChoice) {
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- case SelectionHandlePosition::Bottom:
- isBetterChoice = (copyRect.height() > bestRect.height());
- break;
- case SelectionHandlePosition::Left:
- case SelectionHandlePosition::Right:
- isBetterChoice = (copyRect.width() > bestRect.width());
- break;
- }
- }
- if (isBetterChoice) {
- bestRange = newRange;
- bestRect = copyRect;
- }
-
- }
-
- if (!bestRange)
- bestRange = ¤tRange;
-
- // If we can shrink down to text only, the only reason we wouldn't is that
- // there are multiple sub-element blocks beneath us. If we didn't find
- // multiple sub-element blocks, don't shrink to a sub-element block.
-
- if (canShrinkToTextSelection(*bestRange.get()))
- flags = None;
-
- return bestRange.releaseNonNull();
-}
-
-void WebPage::computeExpandAndShrinkThresholdsForHandle(const IntPoint& point, SelectionHandlePosition handlePosition, float& growThreshold, float& shrinkThreshold)
-{
- Frame& frame = m_page->focusController().focusedOrMainFrame();
- RefPtr<Range> currentRange = m_currentBlockSelection ? m_currentBlockSelection.get() : frame.selection().selection().toNormalizedRange();
-
- if (!currentRange)
- return;
-
- Ref<Range> expandedRange = expandedRangeFromHandle(*currentRange, handlePosition);
- SelectionFlags flags;
- RefPtr<Range> contractedRange = contractedRangeFromHandle(*currentRange, handlePosition, flags);
-
- IntRect currentBounds = selectionBoxForRange(currentRange.get());
- IntRect expandedBounds = selectionBoxForRange(expandedRange.ptr());
- IntRect contractedBounds = selectionBoxForRange(contractedRange.get());
-
- float current;
- float expanded;
- float contracted;
- float maxThreshold;
- float minThreshold;
-
- switch (handlePosition) {
- case SelectionHandlePosition::Top: {
- current = currentBounds.y();
- expanded = expandedBounds.y();
- contracted = contractedBounds.y();
- maxThreshold = FLT_MIN;
- minThreshold = FLT_MAX;
- break;
- }
- case SelectionHandlePosition::Right: {
- current = currentBounds.maxX();
- expanded = expandedBounds.maxX();
- contracted = contractedBounds.maxX();
- maxThreshold = FLT_MAX;
- minThreshold = FLT_MIN;
- break;
- }
- case SelectionHandlePosition::Bottom: {
- current = currentBounds.maxY();
- expanded = expandedBounds.maxY();
- contracted = contractedBounds.maxY();
- maxThreshold = FLT_MAX;
- minThreshold = FLT_MIN;
- break;
- }
- case SelectionHandlePosition::Left: {
- current = currentBounds.x();
- expanded = expandedBounds.x();
- contracted = contractedBounds.x();
- maxThreshold = FLT_MIN;
- minThreshold = FLT_MAX;
- break;
- }
- }
-
- static const float fractionToGrow = 0.3;
-
- growThreshold = current + (expanded - current) * fractionToGrow;
- shrinkThreshold = current + (contracted - current) * (1 - fractionToGrow);
- if (areRangesEqual(expandedRange.ptr(), currentRange.get()))
- growThreshold = maxThreshold;
-
-}
-
void WebPage::clearSelection()
{
m_currentBlockSelection = nullptr;
@@ -1664,49 +1282,6 @@
m_page->focusController().focusedOrMainFrame().selection().clear();
}
-RefPtr<Range> WebPage::switchToBlockSelectionAtPoint(const IntPoint& point, SelectionHandlePosition handlePosition)
-{
- Frame& frame = m_page->focusController().focusedOrMainFrame();
- RefPtr<Range> newRange;
- RefPtr<Range> currentRange = frame.selection().selection().toNormalizedRange();
- if (currentRange) {
- Node* currentNode = ¤tRange->startContainer();
- if (currentNode->isTextNode()) {
- newRange = enclosingTextUnitOfGranularity(currentRange->startPosition(), ParagraphGranularity, DirectionBackward);
- if (newRange && newRange->collapsed())
- newRange = nullptr;
- }
-
- if (!newRange && !currentNode->isElementNode())
- currentNode = currentNode->parentElement();
-
- if (!newRange && currentNode) {
- newRange = Range::create(currentNode->document());
- newRange->selectNodeContents(*currentNode);
- }
- }
- return newRange;
-}
-
-bool WebPage::shouldSwitchToBlockModeForHandle(const IntPoint& handlePoint, SelectionHandlePosition handlePosition)
-{
- if (!m_allowsBlockSelection)
- return false;
-
- if (!m_blockRectForTextSelection.height())
- return false;
- switch (handlePosition) {
- case SelectionHandlePosition::Top:
- return handlePoint.y() < m_blockRectForTextSelection.y();
- case SelectionHandlePosition::Right:
- return handlePoint.x() > m_blockRectForTextSelection.maxX();
- case SelectionHandlePosition::Bottom:
- return handlePoint.y() > m_blockRectForTextSelection.maxY();
- case SelectionHandlePosition::Left:
- return handlePoint.x() < m_blockRectForTextSelection.x();
- }
-}
-
void WebPage::updateSelectionWithTouches(const IntPoint& point, uint32_t touches, bool baseIsStart, CallbackID callbackID)
{
Frame& frame = m_page->focusController().focusedOrMainFrame();
@@ -1720,7 +1295,6 @@
RefPtr<Range> range;
VisiblePosition result;
SelectionFlags flags = None;
- SelectionHandlePosition handlePosition = baseIsStart ? SelectionHandlePosition::Bottom : SelectionHandlePosition::Top;
switch (static_cast<SelectionTouch>(touches)) {
case SelectionTouch::Started:
@@ -1745,10 +1319,7 @@
break;
case SelectionTouch::Moved:
- if (shouldSwitchToBlockModeForHandle(pointInDocument, handlePosition)) {
- range = switchToBlockSelectionAtPoint(pointInDocument, handlePosition);
- } else
- range = rangeForPosition(&frame, position, baseIsStart);
+ range = rangeForPosition(&frame, position, baseIsStart);
break;
}
if (range)