Changeset 165767 in webkit


Ignore:
Timestamp:
Mar 17, 2014 3:28:25 PM (10 years ago)
Author:
ap@apple.com
Message:

Move convertToRange() helper to cross-platform WebPage.cpp
https://bugs.webkit.org/show_bug.cgi?id=130365

Reviewed by Tim Horton.

Also renamed it to rangeFromEditingLocationAndLength().

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::rangeFromEditingLocationAndLength):

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

(WebKit::WebPage::insertText):

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::setComposition):
(WebKit::WebPage::insertText):
(WebKit::WebPage::insertDictatedText):
(WebKit::WebPage::getAttributedSubstringFromRange):
(WebKit::WebPage::characterIndexForPoint):
(WebKit::WebPage::firstRectForCharacterRange):

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r165766 r165767  
     12014-03-17  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Move convertToRange() helper to cross-platform WebPage.cpp
     4        https://bugs.webkit.org/show_bug.cgi?id=130365
     5
     6        Reviewed by Tim Horton.
     7
     8        Also renamed it to rangeFromEditingLocationAndLength().
     9
     10        * WebProcess/WebPage/WebPage.cpp:
     11        (WebKit::WebPage::rangeFromEditingLocationAndLength):
     12        * WebProcess/WebPage/WebPage.h:
     13        * WebProcess/WebPage/ios/WebPageIOS.mm:
     14        (WebKit::WebPage::insertText):
     15        * WebProcess/WebPage/mac/WebPageMac.mm:
     16        (WebKit::WebPage::setComposition):
     17        (WebKit::WebPage::insertText):
     18        (WebKit::WebPage::insertDictatedText):
     19        (WebKit::WebPage::getAttributedSubstringFromRange):
     20        (WebKit::WebPage::characterIndexForPoint):
     21        (WebKit::WebPage::firstRectForCharacterRange):
     22
    1232014-03-17  Anders Carlsson  <andersca@apple.com>
    224
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r165759 r165767  
    43374337}
    43384338
     4339PassRefPtr<Range> WebPage::rangeFromEditingLocationAndLength(Frame& frame, uint64_t location, uint64_t length)
     4340{
     4341    // Sanitize the input, because TextIterator::rangeFromLocationAndLength takes signed integers.
     4342    if (location > INT_MAX)
     4343        return 0;
     4344    if (length > INT_MAX || location + length > INT_MAX)
     4345        length = INT_MAX - location;
     4346
     4347    // Our critical assumption is that we are only called by input methods that
     4348    // concentrate on a given area containing the selection.
     4349    // We have to do this because of text fields and textareas. The DOM for those is not
     4350    // directly in the document DOM, so serialization is problematic. Our solution is
     4351    // to use the root editable element of the selection start as the positional base.
     4352    // That fits with AppKit's idea of an input context.
     4353    return TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), location, length);
     4354}
     4355
    43394356} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r165759 r165767  
    928928    static PluginView* pluginViewForFrame(WebCore::Frame*);
    929929
     930    PassRefPtr<WebCore::Range> rangeFromEditingLocationAndLength(WebCore::Frame&, uint64_t location, uint64_t length);
     931
    930932    void reportUsedFeatures();
    931933
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r165759 r165767  
    186186}
    187187
    188 static PassRefPtr<Range> convertToRange(Frame* frame, NSRange nsrange)
    189 {
    190     if (nsrange.location > INT_MAX)
    191         return 0;
    192     if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
    193         nsrange.length = INT_MAX - nsrange.location;
    194    
    195     // our critical assumption is that we are only called by input methods that
    196     // concentrate on a given area containing the selection
    197     // We have to do this because of text fields and textareas. The DOM for those is not
    198     // directly in the document DOM, so serialization is problematic. Our solution is
    199     // to use the root editable element of the selection start as the positional base.
    200     // That fits with AppKit's idea of an input context.
    201     return TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), nsrange.location, nsrange.length);
    202 }
    203 
    204188void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    205189{
     
    207191   
    208192    if (replacementRangeStart != NSNotFound) {
    209         RefPtr<Range> replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeLength));
     193        RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
    210194        if (replacementRange)
    211195            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r165759 r165767  
    7777namespace WebKit {
    7878
    79 static PassRefPtr<Range> convertToRange(Frame*, uint64_t location, uint64_t length);
    80 
    8179void WebPage::platformInitialize()
    8280{
     
    255253        RefPtr<Range> replacementRange;
    256254        if (replacementRangeStart != NSNotFound) {
    257             replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
     255            replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
    258256            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
    259257        }
     
    284282
    285283    if (replacementRangeStart != NSNotFound) {
    286         RefPtr<Range> replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
     284        RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
    287285        if (replacementRange)
    288286            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    306304
    307305    if (replacementRangeStart != NSNotFound) {
    308         RefPtr<Range> replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
     306        RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
    309307        if (replacementRange)
    310308            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    356354        return;
    357355
    358     RefPtr<Range> range = convertToRange(&frame, rangeStart, rangeLength);
     356    RefPtr<Range> range = rangeFromEditingLocationAndLength(frame, rangeStart, rangeLength);
    359357    if (!range)
    360358        return;
     
    389387        index = static_cast<uint64_t>(location);
    390388}
    391 
    392 PassRefPtr<Range> convertToRange(Frame* frame, uint64_t location, uint64_t length)
    393 {
    394     if (location > INT_MAX)
    395         return 0;
    396     if (length > INT_MAX || location + length > INT_MAX)
    397         length = INT_MAX - location;
    398        
    399     // our critical assumption is that we are only called by input methods that
    400     // concentrate on a given area containing the selection
    401     // We have to do this because of text fields and textareas. The DOM for those is not
    402     // directly in the document DOM, so serialization is problematic. Our solution is
    403     // to use the root editable element of the selection start as the positional base.
    404     // That fits with AppKit's idea of an input context.
    405     return TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), location, length);
    406 }
    407389   
    408390void WebPage::firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect)
     
    412394    resultRect.setSize(IntSize(0, 0));
    413395   
    414     RefPtr<Range> range = convertToRange(&frame, location, length);
     396    RefPtr<Range> range = rangeFromEditingLocationAndLength(frame, location, length);
    415397    if (!range)
    416398        return;
Note: See TracChangeset for help on using the changeset viewer.