Changeset 230591 in webkit


Ignore:
Timestamp:
Apr 12, 2018 12:57:30 PM (6 years ago)
Author:
Megan Gardner
Message:

Remove block selection code
https://bugs.webkit.org/show_bug.cgi?id=184470

Reviewed by Timothy Hatcher.

Remove block selection code that isn't run and is currently not even used.
Had to put this back in for a bug in the mid-year release, but we're past that
so it's time for this to go away.

  • Platform/spi/ios/UIKitSPI.h:
  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/ios/PageClientImplIOS.h:
  • UIProcess/ios/PageClientImplIOS.mm:

(WebKit::PageClientImpl::stopAssistingNode):
(WebKit::PageClientImpl::didUpdateBlockSelectionWithTouch): Deleted.

  • UIProcess/ios/WKContentViewInteraction.h:
  • UIProcess/ios/WKContentViewInteraction.mm:

(toSelectionHandlePosition): Deleted.
(-[WKContentView _didUpdateBlockSelectionWithTouch:withFlags:growThreshold:shrinkThreshold:]): Deleted.
(-[WKContentView changeSelectionWithTouchAt:withSelectionTouch:baseIsStart:]): Deleted.
(-[WKContentView changeBlockSelectionWithTouchAt:withSelectionTouch:forHandle:]): Deleted.

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::saveImageToLibrary):
(WebKit::WebPageProxy::updateBlockSelectionWithTouch): Deleted.
(WebKit::WebPageProxy::didUpdateBlockSelectionWithTouch): Deleted.

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::rangeAtWordBoundaryForPosition):
(WebKit::distanceBetweenRectsForPosition): Deleted.
(WebKit::rectsEssentiallyTheSame): Deleted.
(WebKit::unionDOMRanges): Deleted.
(WebKit::computeEdgeCenter): Deleted.
(WebKit::WebPage::expandedRangeFromHandle): Deleted.
(WebKit::WebPage::contractedRangeFromHandle): Deleted.
(WebKit::WebPage::computeExpandAndShrinkThresholdsForHandle): Deleted.
(WebKit::WebPage::rangeForBlockAtPoint): Deleted.
(WebKit::shouldExpand): Deleted.
(WebKit::WebPage::changeBlockSelection): Deleted.
(WebKit::WebPage::updateBlockSelectionWithTouch): Deleted.

Location:
trunk/Source/WebKit
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r230588 r230591  
     12018-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       
    1462018-04-12  Megan Gardner  <megan_gardner@apple.com>
    247
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r230526 r230591  
    541541
    542542@interface UIWKSelectionAssistant ()
    543 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    544 - (void)blockSelectionChangedWithTouch:(UIWKSelectionTouch)touch withFlags:(UIWKSelectionFlags)flags growThreshold:(CGFloat)grow shrinkThreshold:(CGFloat)shrink;
    545 #endif
    546543- (BOOL)shouldHandleSingleTapAtPoint:(CGPoint)point;
    547544- (void)selectionChangedWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)gestureState withFlags:(UIWKSelectionFlags)flags;
     
    593590@end
    594591
    595 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    596 typedef NS_ENUM(NSInteger, UIWKHandlePosition) {
    597     UIWKHandleTop = 0,
    598     UIWKHandleRight = 1,
    599     UIWKHandleBottom = 2,
    600     UIWKHandleLeft = 3,
    601 };
    602 #endif
    603 
    604592@protocol UIWKInteractionViewProtocol
    605593- (void)changeSelectionWithGestureAt:(CGPoint)point withGesture:(UIWKGestureType)gestureType withState:(UIGestureRecognizerState)state;
     
    626614
    627615@optional
    628 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    629 - (void)changeBlockSelectionWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch forHandle:(UIWKHandlePosition)handle;
    630 #endif
    631 
    632616- (void)clearSelection;
    633617- (void)replaceDictatedText:(NSString *)oldText withText:(NSString *)newText;
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r230526 r230591  
    296296    virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0;
    297297    virtual void saveImageToLibrary(Ref<WebCore::SharedBuffer>&&) = 0;
    298 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    299     virtual void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) = 0;
    300 #endif
    301298    virtual void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect) = 0;
    302299    virtual void disableDoubleTapGesturesDuringTapIfNecessary(uint64_t requestID) = 0;
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r230526 r230591  
    555555    void updateSelectionWithTouches(const WebCore::IntPoint, uint32_t touches, bool baseIsStart, WTF::Function<void (const WebCore::IntPoint&, uint32_t, uint32_t, CallbackBase::Error)>&&);
    556556    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 < 120000
    558     void updateBlockSelectionWithTouch(const WebCore::IntPoint, uint32_t touch, uint32_t handlePosition);
    559 #endif
    560557    void extendSelection(WebCore::TextGranularity);
    561558    void selectWordBackward();
     
    582579    void performActionOnElement(uint32_t action);
    583580    void saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize);
    584 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    585     void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold);
    586 #endif
    587581    void focusNextAssistedNode(bool isForward, WTF::Function<void (CallbackBase::Error)>&& = [] (auto) { });
    588582    void setAssistedNodeValue(const String&);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r230526 r230591  
    185185    InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled)
    186186    DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information)
    187 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    188     DidUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)
    189 #endif
    190187    SaveImageToLibrary(WebKit::SharedMemory::Handle handle, uint64_t size)
    191188    ShowPlaybackTargetPicker(bool hasVideo, WebCore::IntRect elementRect)
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.h

    r230526 r230591  
    133133    void positionInformationDidChange(const InteractionInformationAtPosition&) override;
    134134    void saveImageToLibrary(Ref<WebCore::SharedBuffer>&&) override;
    135 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    136     void didUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold) override;
    137 #endif
    138135    void showPlaybackTargetPicker(bool hasVideo, const WebCore::IntRect& elementRect) override;
    139136
  • trunk/Source/WebKit/UIProcess/ios/PageClientImplIOS.mm

    r230526 r230591  
    562562    [m_contentView _stopAssistingNode];
    563563}
    564    
    565 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    566 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 #endif
    571    
    572564
    573565void PageClientImpl::showPlaybackTargetPicker(bool hasVideo, const IntRect& elementRect)
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h

    r230547 r230591  
    311311- (void)_overflowScrollingWillBegin;
    312312- (void)_overflowScrollingDidEnd;
    313 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    314 - (void)_didUpdateBlockSelectionWithTouch:(WebKit::SelectionTouch)touch withFlags:(WebKit::SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold;
    315 #endif
    316313- (void)_showPlaybackTargetPicker:(BOOL)hasVideo fromRect:(const WebCore::IntRect&)elementRect;
    317314- (void)_showRunOpenPanel:(API::OpenPanelParameters*)parameters resultListener:(WebKit::WebOpenPanelResultListenerProxy*)listener;
  • trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

    r230588 r230591  
    26362636}
    26372637
    2638 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    2639 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 #endif
    2653 
    26542638static inline WebCore::TextGranularity toWKTextGranularity(UITextGranularity granularity)
    26552639{
     
    27102694}
    27112695
    2712 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    2713 - (void)_didUpdateBlockSelectionWithTouch:(SelectionTouch)touch withFlags:(SelectionFlags)flags growThreshold:(CGFloat)growThreshold shrinkThreshold:(CGFloat)shrinkThreshold
    2714 {
    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 #endif
    2720 
    27212696- (BOOL)_isInteractingWithAssistedNode
    27222697{
     
    27652740    });
    27662741}
    2767 
    2768 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    2769 - (void)changeBlockSelectionWithTouchAt:(CGPoint)point withSelectionTouch:(UIWKSelectionTouch)touch forHandle:(UIWKHandlePosition)handle
    2770 {
    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 functions
    2774     // 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 #endif
    27802742
    27812743- (void)moveByOffset:(NSInteger)offset
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r230526 r230591  
    674674    m_pageClient.saveImageToLibrary(WTFMove(buffer));
    675675}
    676    
    677 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    678 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 #endif
    688676
    689677void WebPageProxy::applicationDidEnterBackground()
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r230526 r230591  
    581581    void selectWithGesture(const WebCore::IntPoint&, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, CallbackID);
    582582    void updateSelectionWithTouches(const WebCore::IntPoint&, uint32_t touches, bool baseIsStart, CallbackID);
    583 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    584     void updateBlockSelectionWithTouch(const WebCore::IntPoint&, uint32_t touch, uint32_t handlePosition);
    585 #endif
    586583    void selectWithTwoTouches(const WebCore::IntPoint& from, const WebCore::IntPoint& to, uint32_t gestureType, uint32_t gestureState, CallbackID);
    587584    void extendSelection(uint32_t granularity);
     
    11081105    static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector<WebCore::SelectionRect>&);
    11091106    RefPtr<WebCore::Range> rangeForWebSelectionAtPosition(const WebCore::IntPoint&, const WebCore::VisiblePosition&, SelectionFlags&);
    1110 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    1111     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 #endif
    11161107    void getAssistedNodeInformation(AssistedNodeInformation&);
    11171108    void platformInitializeAccessibility();
     
    11221113    WebCore::VisiblePosition visiblePositionInFocusedNodeForPoint(const WebCore::Frame&, const WebCore::IntPoint&, bool isInteractingWithAssistedNode);
    11231114    RefPtr<WebCore::Range> rangeForGranularityAtPoint(WebCore::Frame&, const WebCore::IntPoint&, uint32_t granularity, bool isInteractingWithAssistedNode);
    1124 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    1125     RefPtr<WebCore::Range> changeBlockSelection(const WebCore::IntPoint&, SelectionHandlePosition, float& growThreshold, float& shrinkThreshold, SelectionFlags&);
    1126 #endif
    11271115#endif
    11281116
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r230526 r230591  
    5858    SelectWithGesture(WebCore::IntPoint point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, WebKit::CallbackID callbackID)
    5959    UpdateSelectionWithTouches(WebCore::IntPoint point, uint32_t touches, bool baseIsStart, WebKit::CallbackID callbackID)
    60 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    61     UpdateBlockSelectionWithTouch(WebCore::IntPoint point, uint32_t touch, uint32_t handlePosition)
    62 #endif
    6360    SelectWithTwoTouches(WebCore::IntPoint from, WebCore::IntPoint to, uint32_t gestureType, uint32_t gestureState, WebKit::CallbackID callbackID)
    6461    ExtendSelection(uint32_t granularity)
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r230527 r230591  
    10761076}
    10771077
    1078 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    1079 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(&currentRange);
    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 || &currentRange.ownerDocument() != &rangeAtPosition->ownerDocument())
    1189             continue;
    1190        
    1191         if (rangeAtPosition->contains(currentRange))
    1192             newRange = rangeAtPosition;
    1193         else if (currentRange.contains(*rangeAtPosition.get()))
    1194             newRange = &currentRange;
    1195         else
    1196             newRange = unionDOMRanges(&currentRange, 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(&currentRange);
    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() != &currentRange.ownerDocument())
    1308             continue;
    1309        
    1310         if (handlePosition == SelectionHandlePosition::Top || handlePosition == SelectionHandlePosition::Left)
    1311             newRange = Range::create(newRange->startContainer().document(), newRange->endPosition(), currentRange.endPosition());
    1312         else
    1313             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 point
    1318             // 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(), &currentRange);
    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 = &currentRange;
    1358    
    1359     // If we can shrink down to text only, the only reason we wouldn't is that
    1360     // there are multiple sub-element blocks beneath us. If we didn't find
    1361     // 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 #endif
    1435 
    14361078void WebPage::selectWithGesture(const IntPoint& point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, bool isInteractingWithAssistedNode, CallbackID callbackID)
    14371079{
     
    16481290    return (base < extent) ? Range::create(*frame->document(), base, extent) : Range::create(*frame->document(), extent, base);
    16491291}
    1650    
    1651 #if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000
    1652 
    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 #endif
    17331292
    17341293void WebPage::clearSelection(){
Note: See TracChangeset for help on using the changeset viewer.