Changeset 230591 in webkit
- Timestamp:
- Apr 12, 2018 12:57:30 PM (6 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r230588 r230591 1 2018-04-12 Megan Gardner <megan_gardner@apple.com> 2 3 Remove block selection code 4 https://bugs.webkit.org/show_bug.cgi?id=184470 5 6 Reviewed by Timothy Hatcher. 7 8 Remove block selection code that isn't run and is currently not even used. 9 Had to put this back in for a bug in the mid-year release, but we're past that 10 so it's time for this to go away. 11 12 * Platform/spi/ios/UIKitSPI.h: 13 * UIProcess/PageClient.h: 14 * UIProcess/WebPageProxy.h: 15 * UIProcess/WebPageProxy.messages.in: 16 * UIProcess/ios/PageClientImplIOS.h: 17 * UIProcess/ios/PageClientImplIOS.mm: 18 (WebKit::PageClientImpl::stopAssistingNode): 19 (WebKit::PageClientImpl::didUpdateBlockSelectionWithTouch): Deleted. 20 * UIProcess/ios/WKContentViewInteraction.h: 21 * UIProcess/ios/WKContentViewInteraction.mm: 22 (toSelectionHandlePosition): Deleted. 23 (-[WKContentView _didUpdateBlockSelectionWithTouch:withFlags:growThreshold:shrinkThreshold:]): Deleted. 24 (-[WKContentView changeSelectionWithTouchAt:withSelectionTouch:baseIsStart:]): Deleted. 25 (-[WKContentView changeBlockSelectionWithTouchAt:withSelectionTouch:forHandle:]): Deleted. 26 * UIProcess/ios/WebPageProxyIOS.mm: 27 (WebKit::WebPageProxy::saveImageToLibrary): 28 (WebKit::WebPageProxy::updateBlockSelectionWithTouch): Deleted. 29 (WebKit::WebPageProxy::didUpdateBlockSelectionWithTouch): Deleted. 30 * WebProcess/WebPage/WebPage.h: 31 * WebProcess/WebPage/WebPage.messages.in: 32 * WebProcess/WebPage/ios/WebPageIOS.mm: 33 (WebKit::rangeAtWordBoundaryForPosition): 34 (WebKit::distanceBetweenRectsForPosition): Deleted. 35 (WebKit::rectsEssentiallyTheSame): Deleted. 36 (WebKit::unionDOMRanges): Deleted. 37 (WebKit::computeEdgeCenter): Deleted. 38 (WebKit::WebPage::expandedRangeFromHandle): Deleted. 39 (WebKit::WebPage::contractedRangeFromHandle): Deleted. 40 (WebKit::WebPage::computeExpandAndShrinkThresholdsForHandle): Deleted. 41 (WebKit::WebPage::rangeForBlockAtPoint): Deleted. 42 (WebKit::shouldExpand): Deleted. 43 (WebKit::WebPage::changeBlockSelection): Deleted. 44 (WebKit::WebPage::updateBlockSelectionWithTouch): Deleted. 45 1 46 2018-04-12 Megan Gardner <megan_gardner@apple.com> 2 47 -
trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h
r230526 r230591 541 541 542 542 @interface UIWKSelectionAssistant () 543 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000544 - (void)blockSelectionChangedWithTouch:(UIWKSelectionTouch)touch withFlags:(UIWKSelectionFlags)flags growThreshold:(CGFloat)grow shrinkThreshold:(CGFloat)shrink;545 #endif546 543 - (BOOL)shouldHandleSingleTapAtPoint:(CGPoint)point; 547 544 - (void)selectionChangedWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)gestureState withFlags:(UIWKSelectionFlags)flags; … … 593 590 @end 594 591 595 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000596 typedef NS_ENUM(NSInteger, UIWKHandlePosition) {597 UIWKHandleTop = 0,598 UIWKHandleRight = 1,599 UIWKHandleBottom = 2,600 UIWKHandleLeft = 3,601 };602 #endif603 604 592 @protocol UIWKInteractionViewProtocol 605 593 - (void)changeSelectionWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)state; … … 626 614 627 615 @optional 628 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000629 - (void)changeBlockSelectionWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch forHandle:(UIWKHandlePosition)handle;630 #endif631 632 616 - (void)clearSelection; 633 617 - (void)replaceDictatedText:(NSString *)oldText withText:(NSString *)newText; -
trunk/Source/WebKit/UIProcess/PageClient.h
r230526 r230591 296 296 virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0; 297 297 virtual void saveImageToLibrary(Ref<WebCore::SharedBuffer>&&) = 0; 298 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000299 virtual void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) = 0;300 #endif301 298 virtual void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect) = 0; 302 299 virtual void disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID) = 0; -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r230526 r230591 555 555 void updateSelectionWithTouches(const WebCore::IntPoint, uint32_t touches, bool baseIsStart, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, CallbackBase::Error)>&&); 556 556 void selectWithTwoTouches(const WebCore::IntPoint from, const WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, uint32_t, CallbackBase::Error)>&&); 557 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000558 void updateBlockSelectionWithTouch(const WebCore::IntPoint, uint32_t touch, uint32_t handlePosition);559 #endif560 557 void extendSelection(WebCore::TextGranularity); 561 558 void selectWordBackward(); … … 582 579 void performActionOnElement(uint32_t action); 583 580 void saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize); 584 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000585 void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold);586 #endif587 581 void focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& = [] (auto) { }); 588 582 void setAssistedNodeValue(const String&); -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r230526 r230591 185 185 InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled) 186 186 DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information) 187 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000188 DidUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)189 #endif190 187 SaveImageToLibrary(WebKit::SharedMemory::Handle handle, uint64_t size) 191 188 ShowPlaybackTargetPicker(bool hasVideo, WebCore::IntRect elementRect) -
trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h
r230526 r230591 133 133 void positionInformationDidChange(const InteractionInformationAtPosition&) override; 134 134 void saveImageToLibrary(Ref<WebCore::SharedBuffer>&&) override; 135 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000136 void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) override;137 #endif138 135 void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect) override; 139 136 -
trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm
r230526 r230591 562 562 [m_contentView _stopAssistingNode]; 563 563 } 564 565 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000566 void PageClientImpl::didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)567 {568 [m_contentView _didUpdateBlockSelectionWithTouch:(SelectionTouch)touch withFlags:(SelectionFlags)flags growThreshold:growThreshold shrinkThreshold:shrinkThreshold];569 }570 #endif571 572 564 573 565 void PageClientImpl::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect) -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
r230547 r230591 311 311 - (void)_overflowScrollingWillBegin; 312 312 - (void)_overflowScrollingDidEnd; 313 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000314 - (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold;315 #endif316 313 - (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect; 317 314 - (void)_showRunOpenPanel:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener; -
trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
r230588 r230591 2636 2636 } 2637 2637 2638 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200002639 static inline SelectionHandlePosition toSelectionHandlePosition(UIWKHandlePosition position)2640 {2641 switch (position) {2642 case UIWKHandleTop:2643 return SelectionHandlePosition::Top;2644 case UIWKHandleRight:2645 return SelectionHandlePosition::Right;2646 case UIWKHandleBottom:2647 return SelectionHandlePosition::Bottom;2648 case UIWKHandleLeft:2649 return SelectionHandlePosition::Left;2650 }2651 }2652 #endif2653 2654 2638 static inline WebCore::TextGranularity toWKTextGranularity(UITextGranularity granularity) 2655 2639 { … … 2710 2694 } 2711 2695 2712 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200002713 - (void)_didUpdateBlockSelectionWithTouch:(SelectionTouch)touch withFlags:(SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold2714 {2715 [_webSelectionAssistant blockSelectionChangedWithTouch:toUIWKSelectionTouch(touch) withFlags:toUIWKSelectionFlags(flags) growThreshold:growThreshold shrinkThreshold:shrinkThreshold];2716 if (touch != SelectionTouch::Started && touch != SelectionTouch::Moved)2717 _usingGestureForSelection = NO;2718 }2719 #endif2720 2721 2696 - (BOOL)_isInteractingWithAssistedNode 2722 2697 { … … 2765 2740 }); 2766 2741 } 2767 2768 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200002769 - (void)changeBlockSelectionWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch forHandle:(UIWKHandlePosition)handle2770 {2771 // This was only readded to avoid a crash due to incompatibilities with certain version of UIKit.2772 // This should be removed ASAP.2773 // The selection will be properly updated with the next update, selection still functions2774 // without this function doing anything.2775 2776 _usingGestureForSelection = YES;2777 _page->updateBlockSelectionWithTouch(WebCore::IntPoint(point), static_cast<uint32_t>(toSelectionTouch(touch)), static_cast<uint32_t>(toSelectionHandlePosition(handle)));2778 }2779 #endif2780 2742 2781 2743 - (void)moveByOffset:(NSInteger)offset -
trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
r230526 r230591 674 674 m_pageClient.saveImageToLibrary(WTFMove(buffer)); 675 675 } 676 677 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000678 void WebPageProxy::updateBlockSelectionWithTouch(const WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)679 {680 m_process->send(Messages::WebPage::UpdateBlockSelectionWithTouch(point, touch, handlePosition), m_pageID);681 }682 683 void WebPageProxy::didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)684 {685 m_pageClient.didUpdateBlockSelectionWithTouch(touch, flags, growThreshold, shrinkThreshold);686 }687 #endif688 676 689 677 void WebPageProxy::applicationDidEnterBackground() -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r230526 r230591 581 581 void selectWithGesture(const WebCore::IntPoint&, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, CallbackID); 582 582 void updateSelectionWithTouches(const WebCore::IntPoint&, uint32_t touches, bool baseIsStart, CallbackID); 583 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000584 void updateBlockSelectionWithTouch(const WebCore::IntPoint&, uint32_t touch, uint32_t handlePosition);585 #endif586 583 void selectWithTwoTouches(const WebCore::IntPoint& from, const WebCore::IntPoint& to, uint32_t gestureType, uint32_t gestureState, CallbackID); 587 584 void extendSelection(uint32_t granularity); … … 1108 1105 static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector<WebCore::SelectionRect>&); 1109 1106 RefPtr<WebCore::Range> rangeForWebSelectionAtPosition(const WebCore::IntPoint&, const WebCore::VisiblePosition&, SelectionFlags&); 1110 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200001111 RefPtr<WebCore::Range> rangeForBlockAtPoint(const WebCore::IntPoint&);1112 void computeExpandAndShrinkThresholdsForHandle(const WebCore::IntPoint&, SelectionHandlePosition, float& growThreshold, float& shrinkThreshold);1113 Ref<WebCore::Range> expandedRangeFromHandle(WebCore::Range&, SelectionHandlePosition);1114 Ref<WebCore::Range> contractedRangeFromHandle(WebCore::Range& currentRange, SelectionHandlePosition, SelectionFlags&);1115 #endif1116 1107 void getAssistedNodeInformation(AssistedNodeInformation&); 1117 1108 void platformInitializeAccessibility(); … … 1122 1113 WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithAssistedNode); 1123 1114 RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithAssistedNode); 1124 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200001125 RefPtr<WebCore::Range> changeBlockSelection(const WebCore::IntPoint&, SelectionHandlePosition, float& growThreshold, float& shrinkThreshold, SelectionFlags&);1126 #endif1127 1115 #endif 1128 1116 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r230526 r230591 58 58 SelectWithGesture(WebCore::IntPoint point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, WebKit::CallbackID callbackID) 59 59 UpdateSelectionWithTouches(WebCore::IntPoint point, uint32_t touches, bool baseIsStart, WebKit::CallbackID callbackID) 60 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 12000061 UpdateBlockSelectionWithTouch(WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)62 #endif63 60 SelectWithTwoTouches(WebCore::IntPoint from, WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, WebKit::CallbackID callbackID) 64 61 ExtendSelection(uint32_t granularity) -
trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
r230527 r230591 1076 1076 } 1077 1077 1078 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200001079 static bool canShrinkToTextSelection(Range& range)1080 {1081 if (range.startContainer().isTextNode() && range.endContainer().isTextNode())1082 return true;1083 return canShrinkToTextSelection(range.commonAncestorContainer());1084 }1085 static const int maxHitTests = 10;1086 1087 static inline float distanceBetweenRectsForPosition(IntRect& first, IntRect& second, SelectionHandlePosition handlePosition)1088 {1089 switch (handlePosition) {1090 case SelectionHandlePosition::Top:1091 return abs(first.y() - second.y());1092 case SelectionHandlePosition::Right:1093 return abs(first.maxX() - second.maxX());1094 case SelectionHandlePosition::Bottom:1095 return abs(first.maxY() - second.maxY());1096 case SelectionHandlePosition::Left:1097 return abs(first.x() - second.x());1098 }1099 }1100 1101 static inline bool rectsEssentiallyTheSame(IntRect& first, IntRect& second, float allowablePercentDifference)1102 {1103 const float minMagnitudeRatio = 1.0 - allowablePercentDifference;1104 const float maxDisplacementRatio = allowablePercentDifference;1105 1106 float xOriginShiftRatio = abs(first.x() - second.x()) / std::min(first.width(), second.width());1107 float yOriginShiftRatio = abs(first.y() - second.y()) / std::min(first.height(), second.height());1108 1109 float widthRatio = std::min(first.width() / second.width(), second.width() / first.width());1110 float heightRatio = std::min(first.height() / second.height(), second.height() / first.height());1111 return ((widthRatio > minMagnitudeRatio && xOriginShiftRatio < maxDisplacementRatio) && (heightRatio > minMagnitudeRatio && yOriginShiftRatio < maxDisplacementRatio));1112 }1113 1114 static inline RefPtr<Range> unionDOMRanges(Range* rangeA, Range* rangeB)1115 {1116 if (!rangeB)1117 return rangeA;1118 if (!rangeA)1119 return rangeB;1120 1121 auto startToStartComparison = rangeA->compareBoundaryPoints(Range::START_TO_START, *rangeB);1122 if (startToStartComparison.hasException())1123 return nullptr;1124 1125 auto endToEndComparison = rangeA->compareBoundaryPoints(Range::END_TO_END, *rangeB);1126 if (endToEndComparison.hasException())1127 return nullptr;1128 1129 auto* start = startToStartComparison.releaseReturnValue() <= 0 ? rangeA : rangeB;1130 auto* end = endToEndComparison.releaseReturnValue() <= 0 ? rangeB : rangeA;1131 1132 return Range::create(rangeA->ownerDocument(), &start->startContainer(), start->startOffset(), &end->endContainer(), end->endOffset());1133 }1134 1135 static inline IntPoint computeEdgeCenter(const IntRect& box, SelectionHandlePosition handlePosition)1136 {1137 switch (handlePosition) {1138 case SelectionHandlePosition::Top:1139 return IntPoint(box.x() + box.width() / 2, box.y());1140 case SelectionHandlePosition::Right:1141 return IntPoint(box.maxX(), box.y() + box.height() / 2);1142 case SelectionHandlePosition::Bottom:1143 return IntPoint(box.x() + box.width() / 2, box.maxY());1144 case SelectionHandlePosition::Left:1145 return IntPoint(box.x(), box.y() + box.height() / 2);1146 }1147 }1148 1149 Ref<Range> WebPage::expandedRangeFromHandle(Range& currentRange, SelectionHandlePosition handlePosition)1150 {1151 IntRect currentBox = selectionBoxForRange(¤tRange);1152 IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);1153 static const float maxDistance = 1000;1154 const float multiple = powf(maxDistance, 1.0 / (maxHitTests - 1));1155 float distance = 1;1156 1157 RefPtr<Range> bestRange;1158 IntRect bestRect;1159 1160 while (distance < maxDistance) {1161 if (bestRange) {1162 if (distanceBetweenRectsForPosition(bestRect, currentBox, handlePosition) < distance) {1163 // Break early, we're unlikely to do any better.1164 break;1165 }1166 }1167 1168 IntPoint testPoint = edgeCenter;1169 switch (handlePosition) {1170 case SelectionHandlePosition::Top:1171 testPoint.move(0, -distance);1172 break;1173 case SelectionHandlePosition::Right:1174 testPoint.move(distance, 0);1175 break;1176 case SelectionHandlePosition::Bottom:1177 testPoint.move(0, distance);1178 break;1179 case SelectionHandlePosition::Left:1180 testPoint.move(-distance, 0);1181 break;1182 }1183 1184 distance = ceilf(distance * multiple);1185 1186 RefPtr<Range> newRange;1187 RefPtr<Range> rangeAtPosition = rangeForBlockAtPoint(testPoint);1188 if (!rangeAtPosition || ¤tRange.ownerDocument() != &rangeAtPosition->ownerDocument())1189 continue;1190 1191 if (rangeAtPosition->contains(currentRange))1192 newRange = rangeAtPosition;1193 else if (currentRange.contains(*rangeAtPosition.get()))1194 newRange = ¤tRange;1195 else1196 newRange = unionDOMRanges(¤tRange, rangeAtPosition.get());1197 1198 IntRect copyRect = selectionBoxForRange(newRange.get());1199 1200 // Is it different and bigger than the current?1201 bool isBetterChoice = !(rectsEssentiallyTheSame(copyRect, currentBox, .05));1202 if (isBetterChoice) {1203 switch (handlePosition) {1204 case SelectionHandlePosition::Top:1205 case SelectionHandlePosition::Bottom:1206 isBetterChoice = (copyRect.height() > currentBox.height());1207 break;1208 case SelectionHandlePosition::Right:1209 case SelectionHandlePosition::Left:1210 isBetterChoice = (copyRect.width() > currentBox.width());1211 break;1212 }1213 1214 }1215 1216 if (bestRange && isBetterChoice) {1217 // Furtherore, is it smaller than the best we've found so far?1218 switch (handlePosition) {1219 case SelectionHandlePosition::Top:1220 case SelectionHandlePosition::Bottom:1221 isBetterChoice = (copyRect.height() < bestRect.height());1222 break;1223 case SelectionHandlePosition::Right:1224 case SelectionHandlePosition::Left:1225 isBetterChoice = (copyRect.width() < bestRect.width());1226 break;1227 }1228 }1229 1230 if (isBetterChoice) {1231 bestRange = newRange;1232 bestRect = copyRect;1233 }1234 }1235 1236 if (bestRange)1237 return bestRange.releaseNonNull();1238 1239 return currentRange;1240 }1241 1242 Ref<Range> WebPage::contractedRangeFromHandle(Range& currentRange, SelectionHandlePosition handlePosition, SelectionFlags& flags)1243 {1244 // Shrinking with a base and extent will always give better results. If we only have a single element,1245 // see if we can break that down to a base and extent. Shrinking base and extent is comparatively straightforward.1246 // Shrinking down to another element is unlikely to move just one edge, but we can try that as a fallback.1247 1248 IntRect currentBox = selectionBoxForRange(¤tRange);1249 IntPoint edgeCenter = computeEdgeCenter(currentBox, handlePosition);1250 1251 float maxDistance;1252 1253 switch (handlePosition) {1254 case SelectionHandlePosition::Top:1255 case SelectionHandlePosition::Bottom:1256 maxDistance = currentBox.height();1257 break;1258 case SelectionHandlePosition::Right:1259 case SelectionHandlePosition::Left:1260 maxDistance = currentBox.width();1261 break;1262 }1263 1264 const float multiple = powf(maxDistance - 1, 1.0 / (maxHitTests - 1));1265 float distance = 1;1266 RefPtr<Range> bestRange;1267 IntRect bestRect;1268 1269 while (distance < maxDistance) {1270 if (bestRange) {1271 float shrankDistance;1272 switch (handlePosition) {1273 case SelectionHandlePosition::Top:1274 case SelectionHandlePosition::Bottom:1275 shrankDistance = abs(currentBox.height() - bestRect.height());1276 break;1277 case SelectionHandlePosition::Right:1278 case SelectionHandlePosition::Left:1279 shrankDistance = abs(currentBox.width() - bestRect.width());1280 break;1281 }1282 if (shrankDistance > distance) {1283 // Certainly not going to do any better than that.1284 break;1285 }1286 }1287 1288 IntPoint testPoint = edgeCenter;1289 switch (handlePosition) {1290 case SelectionHandlePosition::Top:1291 testPoint.move(0, distance);1292 break;1293 case SelectionHandlePosition::Right:1294 testPoint.move(-distance, 0);1295 break;1296 case SelectionHandlePosition::Bottom:1297 testPoint.move(0, -distance);1298 break;1299 case SelectionHandlePosition::Left:1300 testPoint.move(distance, 0);1301 break;1302 }1303 1304 distance *= multiple;1305 1306 RefPtr<Range> newRange = rangeForBlockAtPoint(testPoint);1307 if (!newRange || &newRange->ownerDocument() != ¤tRange.ownerDocument())1308 continue;1309 1310 if (handlePosition == SelectionHandlePosition::Top || handlePosition == SelectionHandlePosition::Left)1311 newRange = Range::create(newRange->startContainer().document(), newRange->endPosition(), currentRange.endPosition());1312 else1313 newRange = Range::create(newRange->startContainer().document(), currentRange.startPosition(), newRange->startPosition());1314 1315 IntRect copyRect = selectionBoxForRange(newRange.get());1316 if (copyRect.isEmpty()) {1317 // If the new range is an empty rectangle, we try the block at the current point1318 // and see if that has a rectangle that is a better choice.1319 newRange = rangeForBlockAtPoint(testPoint);1320 copyRect = selectionBoxForRange(newRange.get());1321 }1322 bool isBetterChoice;1323 switch (handlePosition) {1324 case SelectionHandlePosition::Top:1325 case SelectionHandlePosition::Bottom:1326 isBetterChoice = (copyRect.height() < currentBox.height());1327 if (copyRect.height() == currentBox.height())1328 isBetterChoice = canShrinkToTextSelection(*newRange.get());1329 break;1330 case SelectionHandlePosition::Left:1331 case SelectionHandlePosition::Right:1332 isBetterChoice = (copyRect.width() > bestRect.width());1333 break;1334 }1335 1336 isBetterChoice = isBetterChoice && !areRangesEqual(newRange.get(), ¤tRange);1337 if (bestRange && isBetterChoice) {1338 switch (handlePosition) {1339 case SelectionHandlePosition::Top:1340 case SelectionHandlePosition::Bottom:1341 isBetterChoice = (copyRect.height() > bestRect.height());1342 break;1343 case SelectionHandlePosition::Left:1344 case SelectionHandlePosition::Right:1345 isBetterChoice = (copyRect.width() > bestRect.width());1346 break;1347 }1348 }1349 if (isBetterChoice) {1350 bestRange = newRange;1351 bestRect = copyRect;1352 }1353 1354 }1355 1356 if (!bestRange)1357 bestRange = ¤tRange;1358 1359 // If we can shrink down to text only, the only reason we wouldn't is that1360 // there are multiple sub-element blocks beneath us. If we didn't find1361 // multiple sub-element blocks, don't shrink to a sub-element block.1362 1363 if (canShrinkToTextSelection(*bestRange.get()))1364 flags = None;1365 1366 return bestRange.releaseNonNull();1367 }1368 1369 void WebPage::computeExpandAndShrinkThresholdsForHandle(const IntPoint& point, SelectionHandlePosition handlePosition, float& growThreshold, float& shrinkThreshold)1370 {1371 Frame& frame = m_page->focusController().focusedOrMainFrame();1372 RefPtr<Range> currentRange = m_currentBlockSelection ? m_currentBlockSelection.get() : frame.selection().selection().toNormalizedRange();1373 1374 if (!currentRange)1375 return;1376 1377 Ref<Range> expandedRange = expandedRangeFromHandle(*currentRange, handlePosition);1378 SelectionFlags flags;1379 RefPtr<Range> contractedRange = contractedRangeFromHandle(*currentRange, handlePosition, flags);1380 1381 IntRect currentBounds = selectionBoxForRange(currentRange.get());1382 IntRect expandedBounds = selectionBoxForRange(expandedRange.ptr());1383 IntRect contractedBounds = selectionBoxForRange(contractedRange.get());1384 1385 float current;1386 float expanded;1387 float contracted;1388 float maxThreshold;1389 float minThreshold;1390 1391 switch (handlePosition) {1392 case SelectionHandlePosition::Top: {1393 current = currentBounds.y();1394 expanded = expandedBounds.y();1395 contracted = contractedBounds.y();1396 maxThreshold = FLT_MIN;1397 minThreshold = FLT_MAX;1398 break;1399 }1400 case SelectionHandlePosition::Right: {1401 current = currentBounds.maxX();1402 expanded = expandedBounds.maxX();1403 contracted = contractedBounds.maxX();1404 maxThreshold = FLT_MAX;1405 minThreshold = FLT_MIN;1406 break;1407 }1408 case SelectionHandlePosition::Bottom: {1409 current = currentBounds.maxY();1410 expanded = expandedBounds.maxY();1411 contracted = contractedBounds.maxY();1412 maxThreshold = FLT_MAX;1413 minThreshold = FLT_MIN;1414 break;1415 }1416 case SelectionHandlePosition::Left: {1417 current = currentBounds.x();1418 expanded = expandedBounds.x();1419 contracted = contractedBounds.x();1420 maxThreshold = FLT_MIN;1421 minThreshold = FLT_MAX;1422 break;1423 }1424 }1425 1426 static const float fractionToGrow = 0.3;1427 1428 growThreshold = current + (expanded - current) * fractionToGrow;1429 shrinkThreshold = current + (contracted - current) * (1 - fractionToGrow);1430 if (areRangesEqual(expandedRange.ptr(), currentRange.get()))1431 growThreshold = maxThreshold;1432 1433 }1434 #endif1435 1436 1078 void WebPage::selectWithGesture(const IntPoint& point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, CallbackID callbackID) 1437 1079 { … … 1648 1290 return (base < extent) ? Range::create(*frame->document(), base, extent) : Range::create(*frame->document(), extent, base); 1649 1291 } 1650 1651 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 1200001652 1653 RefPtr<Range> WebPage::rangeForBlockAtPoint(const IntPoint& point)1654 {1655 HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowUserAgentShadowContent | HitTestRequest::IgnoreClipping);1656 1657 Node* currentNode = result.innerNode();1658 RefPtr<Range> range;1659 1660 if (currentNode->isTextNode()) {1661 range = enclosingTextUnitOfGranularity(m_page->focusController().focusedOrMainFrame().visiblePositionForPoint(point), ParagraphGranularity, DirectionForward);1662 if (range && !range->collapsed())1663 return range;1664 }1665 1666 if (!currentNode->isElementNode())1667 currentNode = currentNode->parentElement();1668 1669 if (!currentNode)1670 return nullptr;1671 1672 range = Range::create(currentNode->document());1673 range->selectNodeContents(*currentNode);1674 return range;1675 }1676 1677 static inline bool shouldExpand(SelectionHandlePosition handlePosition, const IntRect& rect, const IntPoint& point)1678 {1679 switch (handlePosition) {1680 case SelectionHandlePosition::Top:1681 return (point.y() < rect.y());1682 case SelectionHandlePosition::Left:1683 return (point.x() < rect.x());1684 case SelectionHandlePosition::Right:1685 return (point.x() > rect.maxX());1686 case SelectionHandlePosition::Bottom:1687 return (point.y() > rect.maxY());1688 }1689 }1690 1691 RefPtr<WebCore::Range> WebPage::changeBlockSelection(const IntPoint& point, SelectionHandlePosition handlePosition, float& growThreshold, float& shrinkThreshold, SelectionFlags& flags)1692 {1693 Frame& frame = m_page->focusController().focusedOrMainFrame();1694 RefPtr<Range> currentRange = m_currentBlockSelection ? m_currentBlockSelection.get() : frame.selection().selection().toNormalizedRange();1695 if (!currentRange)1696 return nullptr;1697 RefPtr<Range> newRange = shouldExpand(handlePosition, selectionBoxForRange(currentRange.get()), point) ? expandedRangeFromHandle(*currentRange, handlePosition) : contractedRangeFromHandle(*currentRange, handlePosition, flags);1698 1699 if (newRange) {1700 m_currentBlockSelection = newRange;1701 frame.selection().setSelectedRange(newRange.get(), VP_DEFAULT_AFFINITY, true, UserTriggered);1702 }1703 1704 computeExpandAndShrinkThresholdsForHandle(point, handlePosition, growThreshold, shrinkThreshold);1705 return newRange;1706 }1707 1708 void WebPage::updateBlockSelectionWithTouch(const IntPoint& point, uint32_t touch, uint32_t handlePosition)1709 {1710 Frame& frame = m_page->focusController().focusedOrMainFrame();1711 IntPoint adjustedPoint = frame.view()->rootViewToContents(point);1712 1713 float growThreshold = 0;1714 float shrinkThreshold = 0;1715 SelectionFlags flags = None;1716 1717 switch (static_cast<SelectionTouch>(touch)) {1718 case SelectionTouch::Started:1719 computeExpandAndShrinkThresholdsForHandle(adjustedPoint, static_cast<SelectionHandlePosition>(handlePosition), growThreshold, shrinkThreshold);1720 break;1721 case SelectionTouch::Ended:1722 break;1723 case SelectionTouch::Moved:1724 changeBlockSelection(adjustedPoint, static_cast<SelectionHandlePosition>(handlePosition), growThreshold, shrinkThreshold, flags);1725 break;1726 default:1727 return;1728 }1729 1730 send(Messages::WebPageProxy::DidUpdateBlockSelectionWithTouch(touch, static_cast<uint32_t>(flags), growThreshold, shrinkThreshold));1731 }1732 #endif1733 1292 1734 1293 void WebPage::clearSelection(){
Note: See TracChangeset
for help on using the changeset viewer.