Changeset 165759 in webkit


Ignore:
Timestamp:
Mar 17, 2014 2:31:33 PM (10 years ago)
Author:
ap@apple.com
Message:

[Mac] Standardize on start/length in text input IPC methods
https://bugs.webkit.org/show_bug.cgi?id=130359

Reviewed by Anders Carlsson.

Some IPC methods used start/length, and others use start/end. This was confusing.

While here, changed WebPageMac.mm to not use NSMakeRange where we don't need it
(I want to move this code to WebPage.cpp, where it could be shared with iOS and
other platforms, as it doesn't depend on Foundation much).

  • UIProcess/API/mac/WKView.mm:

(-[WKView insertText:replacementRange:]):
(-[WKView setMarkedText:selectedRange:replacementRange:]):
(-[WKView attributedSubstringForProposedRange:actualRange:]):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::internalShowContextMenu):

  • UIProcess/WebPageProxy.h:
  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::setComposition):
(WebKit::WebPageProxy::insertText):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::setComposition):
(WebKit::WebPageProxy::insertText):
(WebKit::WebPageProxy::insertDictatedText):
(WebKit::WebPageProxy::getAttributedSubstringFromRange):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::setComposition):

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

(WebKit::WebPage::setComposition):
(WebKit::WebPage::insertText):

  • WebProcess/WebPage/mac/WebPageMac.mm:

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

Location:
trunk/Source/WebKit2
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r165758 r165759  
     12014-03-17  Alexey Proskuryakov  <ap@apple.com>
     2
     3        [Mac] Standardize on start/length in text input IPC methods
     4        https://bugs.webkit.org/show_bug.cgi?id=130359
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Some IPC methods used start/length, and others use start/end. This was confusing.
     9
     10        While here, changed WebPageMac.mm to not use NSMakeRange where we don't need it
     11        (I want to move this code to WebPage.cpp, where it could be shared with iOS and
     12        other platforms, as it doesn't depend on Foundation much).
     13
     14        * UIProcess/API/mac/WKView.mm:
     15        (-[WKView insertText:replacementRange:]):
     16        (-[WKView setMarkedText:selectedRange:replacementRange:]):
     17        (-[WKView attributedSubstringForProposedRange:actualRange:]):
     18        * UIProcess/WebPageProxy.cpp:
     19        (WebKit::WebPageProxy::internalShowContextMenu):
     20        * UIProcess/WebPageProxy.h:
     21        * UIProcess/ios/WebPageProxyIOS.mm:
     22        (WebKit::WebPageProxy::setComposition):
     23        (WebKit::WebPageProxy::insertText):
     24        * UIProcess/mac/WebPageProxyMac.mm:
     25        (WebKit::WebPageProxy::setComposition):
     26        (WebKit::WebPageProxy::insertText):
     27        (WebKit::WebPageProxy::insertDictatedText):
     28        (WebKit::WebPageProxy::getAttributedSubstringFromRange):
     29        * WebProcess/WebPage/WebPage.cpp:
     30        (WebKit::WebPage::setComposition):
     31        * WebProcess/WebPage/WebPage.h:
     32        * WebProcess/WebPage/WebPage.messages.in:
     33        * WebProcess/WebPage/ios/WebPageIOS.mm:
     34        (WebKit::WebPage::setComposition):
     35        (WebKit::WebPage::insertText):
     36        * WebProcess/WebPage/mac/WebPageMac.mm:
     37        (WebKit::WebPage::setComposition):
     38        (WebKit::WebPage::insertText):
     39        (WebKit::WebPage::insertDictatedText):
     40        (WebKit::WebPage::getAttributedSubstringFromRange):
     41        (WebKit::convertToRange):
     42        (WebKit::WebPage::firstRectForCharacterRange):
     43
    1442014-03-17  Tim Horton  <timothy_horton@apple.com>
    245
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r165758 r165759  
    12901290    bool eventHandled;
    12911291    if (!dictationAlternatives.isEmpty())
    1292         eventHandled = _data->_page->insertDictatedText(eventText, replacementRange.location, NSMaxRange(replacementRange), dictationAlternatives);
     1292        eventHandled = _data->_page->insertDictatedText(eventText, replacementRange.location, replacementRange.length, dictationAlternatives);
    12931293    else
    1294         eventHandled = _data->_page->insertText(eventText, replacementRange.location, NSMaxRange(replacementRange));
     1294        eventHandled = _data->_page->insertText(eventText, replacementRange.location, replacementRange.length);
    12951295
    12961296    if (parameters)
     
    16091609        [self _notifyInputContextAboutDiscardedComposition];
    16101610        if ([text length] == 1 && [[text decomposedStringWithCanonicalMapping] characterAtIndex:0] < 0x80) {
    1611             _data->_page->insertText(text, replacementRange.location, NSMaxRange(replacementRange));
     1611            _data->_page->insertText(text, replacementRange.location, replacementRange.length);
    16121612        } else
    16131613            NSBeep();
     
    16151615    }
    16161616
    1617     _data->_page->setComposition(text, underlines, newSelRange.location, NSMaxRange(newSelRange), replacementRange.location, NSMaxRange(replacementRange));
     1617    _data->_page->setComposition(text, underlines, newSelRange.location, newSelRange.length, replacementRange.location, replacementRange.length);
    16181618}
    16191619
     
    16431643
    16441644    AttributedString result;
    1645     _data->_page->getAttributedSubstringFromRange(nsRange.location, NSMaxRange(nsRange), result);
     1645    _data->_page->getAttributedSubstringFromRange(nsRange.location, nsRange.length, result);
    16461646
    16471647    if (actualRange) {
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r165748 r165759  
    44834483
    44844484#if PLATFORM(GTK)
    4485 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     4485void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRange)
    44864486{
    44874487    // FIXME: We need to find out how to proper handle the crashes case.
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r165750 r165759  
    526526    void setMainFrameIsScrollable(bool);
    527527
    528     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
     528    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
    529529    void confirmComposition();
    530530    void cancelComposition();
    531     bool insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
    532     bool insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives);
     531    bool insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
     532    bool insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives);
    533533    void getMarkedRange(uint64_t& location, uint64_t& length);
    534534    void getSelectedRange(uint64_t& location, uint64_t& length);
    535     void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeEnd, AttributedString&);
     535    void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString&);
    536536    uint64_t characterIndexForPoint(const WebCore::IntPoint);
    537537    WebCore::IntRect firstRectForCharacterRange(uint64_t, uint64_t);
  • trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

    r165577 r165759  
    9999}
    100100
    101 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underline, uint64_t selectionStart, uint64_t selectionEnd, uint64_t, uint64_t)
     101void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underline, uint64_t selectionStart, uint64_t selectionLength, uint64_t, uint64_t)
    102102{
    103103    if (!isValid())
    104104        return;
    105105
    106     process().send(Messages::WebPage::SetComposition(text, underline, selectionStart, selectionEnd), m_pageID);
     106    process().send(Messages::WebPage::SetComposition(text, underline, selectionStart, selectionLength), m_pageID);
    107107}
    108108
     
    121121}
    122122
    123 bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     123bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    124124{
    125125    if (!isValid())
    126126        return true;
    127127   
    128     process().send(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeEnd), m_pageID);
     128    process().send(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeLength), m_pageID);
    129129    return true;
    130130}
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r165750 r165759  
    152152}
    153153
    154 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     154void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    155155{
    156156    if (!isValid()) {
     
    160160    }
    161161
    162     process().sendSync(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionEnd, replacementRangeStart, replacementRangeEnd), Messages::WebPage::SetComposition::Reply(m_editorState), m_pageID);
     162    process().sendSync(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionLength, replacementRangeStart, replacementRangeLength), Messages::WebPage::SetComposition::Reply(m_editorState), m_pageID);
    163163}
    164164
     
    179179}
    180180
    181 bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     181bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    182182{
    183183    if (!isValid())
     
    185185
    186186    bool handled = true;
    187     process().sendSync(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeEnd), Messages::WebPage::InsertText::Reply(handled, m_editorState), m_pageID);
     187    process().sendSync(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeLength), Messages::WebPage::InsertText::Reply(handled, m_editorState), m_pageID);
    188188    m_temporarilyClosedComposition = false;
    189189
     
    191191}
    192192
    193 bool WebPageProxy::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange)
     193bool WebPageProxy::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange)
    194194{
    195195#if USE(DICTATION_ALTERNATIVES)
    196196    if (dictationAlternativesWithRange.isEmpty())
    197         return insertText(text, replacementRangeStart, replacementRangeEnd);
     197        return insertText(text, replacementRangeStart, replacementRangeLength);
    198198
    199199    if (!isValid())
     
    210210
    211211    if (dictationAlternatives.isEmpty())
    212         return insertText(text, replacementRangeStart, replacementRangeEnd);
     212        return insertText(text, replacementRangeStart, replacementRangeLength);
    213213
    214214    bool handled = true;
    215     process().sendSync(Messages::WebPage::InsertDictatedText(text, replacementRangeStart, replacementRangeEnd, dictationAlternatives), Messages::WebPage::InsertDictatedText::Reply(handled, m_editorState), m_pageID);
     215    process().sendSync(Messages::WebPage::InsertDictatedText(text, replacementRangeStart, replacementRangeLength, dictationAlternatives), Messages::WebPage::InsertDictatedText::Reply(handled, m_editorState), m_pageID);
    216216    return handled;
    217217#else
    218     return insertText(text, replacementRangeStart, replacementRangeEnd);
     218    return insertText(text, replacementRangeStart, replacementRangeLength);
    219219#endif
    220220}
     
    242242}
    243243
    244 void WebPageProxy::getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeEnd, AttributedString& result)
    245 {
    246     if (!isValid())
    247         return;
    248     process().sendSync(Messages::WebPage::GetAttributedSubstringFromRange(rangeStart, rangeEnd), Messages::WebPage::GetAttributedSubstringFromRange::Reply(result), m_pageID);
     244void WebPageProxy::getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString& result)
     245{
     246    if (!isValid())
     247        return;
     248    process().sendSync(Messages::WebPage::GetAttributedSubstringFromRange(rangeStart, rangeLength), Messages::WebPage::GetAttributedSubstringFromRange::Reply(result), m_pageID);
    249249}
    250250
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r165753 r165759  
    39103910}
    39113911
    3912 void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementStart, uint64_t replacementLength)
     3912void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementStart, uint64_t replacementLength)
    39133913{
    39143914    Frame* targetFrame = targetFrameForEditing(this);
     
    39293929    }
    39303930
    3931     targetFrame->editor().setComposition(text, underlines, selectionStart, selectionEnd);
     3931    targetFrame->editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
    39323932    send(Messages::WebPageProxy::EditorStateChanged(editorState()));
    39333933}
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r165750 r165759  
    456456    void requestAutocorrectionContext(uint64_t callbackID);
    457457    void getAutocorrectionContext(String& beforeText, String& markedText, String& selectedText, String& afterText, uint64_t& location, uint64_t& length);
    458     void insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
    459     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd);
     458    void insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
     459    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength);
    460460    void confirmComposition();
    461461    void getPositionInformation(const WebCore::IntPoint&, InteractionInformationAtPosition&);
     
    522522
    523523#if PLATFORM(GTK)
    524     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd);
     524    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
    525525    void confirmComposition(const String& text, int64_t selectionStart, int64_t selectionLength);
    526526    void cancelComposition();
     
    539539    void cancelComposition(EditorState& newState);
    540540#if !PLATFORM(IOS)
    541     void insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, bool& handled, EditorState& newState);
    542     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, EditorState& newState);
     541    void insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, bool& handled, EditorState& newState);
     542    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength, EditorState& newState);
    543543    void confirmComposition(EditorState& newState);
    544544#endif
    545545    void getMarkedRange(uint64_t& location, uint64_t& length);
    546546    void getSelectedRange(uint64_t& location, uint64_t& length);
    547     void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeEnd, AttributedString&);
     547    void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString&);
    548548    void characterIndexForPoint(const WebCore::IntPoint point, uint64_t& result);
    549549    void firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect);
     
    555555    void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, bool& result);
    556556    bool performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*);
    557     void insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState);
     557    void insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState);
    558558#elif PLATFORM(EFL)
    559559    void confirmComposition(const String& compositionString);
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r165750 r165759  
    5757    RequestAutocorrectionContext(uint64_t callbackID)
    5858    GetAutocorrectionContext() -> (String beforeContext, String markedText, String selectedText, String afterContext, uint64_t location, uint64_t length)
    59     InsertText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
    60     SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd)
     59    InsertText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
     60    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength)
    6161    ConfirmComposition()
    6262    GetPositionInformation(WebCore::IntPoint point) -> (WebKit::InteractionInformationAtPosition information)
     
    275275
    276276#if PLATFORM(GTK)
    277     SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     277    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    278278    ConfirmComposition(String text, int64_t selectionStart, int64_t selectionLength)
    279279    CancelComposition()
     
    295295    GetMarkedRange() -> (uint64_t location, uint64_t length)
    296296    GetSelectedRange() -> (uint64_t location, uint64_t length)
    297     GetAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeEnd) -> (WebKit::AttributedString result)
     297    GetAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength) -> (WebKit::AttributedString result)
    298298    CharacterIndexForPoint(WebCore::IntPoint point) -> (uint64_t result)
    299299    FirstRectForCharacterRange(uint64_t location, uint64_t length) -> (WebCore::IntRect resultRect)
     
    301301    ShouldDelayWindowOrderingEvent(WebKit::WebMouseEvent event) -> (bool result)
    302302    AcceptsFirstMouse(int eventNumber, WebKit::WebMouseEvent event) -> (bool result)
    303     InsertDictatedText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, Vector<WebCore::DictationAlternative> dictationAlternatives) -> (bool handled, WebKit::EditorState newState)
     303    InsertDictatedText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, Vector<WebCore::DictationAlternative> dictationAlternatives) -> (bool handled, WebKit::EditorState newState)
    304304#endif
    305305#if PLATFORM(MAC)
    306     InsertText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd) -> (bool handled, WebKit::EditorState newState)
    307     SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd) -> (WebKit::EditorState newState)
     306    InsertText(String text, uint64_t replacementRangeStart, uint64_t replacementRangeLength) -> (bool handled, WebKit::EditorState newState)
     307    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength) -> (WebKit::EditorState newState)
    308308    ConfirmComposition() -> (WebKit::EditorState newState)
    309309#endif
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r165577 r165759  
    167167}
    168168
    169 void WebPage::setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd)
     169void WebPage::setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength)
    170170{
    171171    Frame& frame = m_page->focusController().focusedOrMainFrame();
    172172
    173173    if (frame.selection().selection().isContentEditable())
    174         frame.editor().setComposition(text, underlines, selectionStart, selectionEnd);
     174        frame.editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
    175175}
    176176
     
    202202}
    203203
    204 void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd)
     204void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
    205205{
    206206    Frame& frame = m_page->focusController().focusedOrMainFrame();
    207207   
    208208    if (replacementRangeStart != NSNotFound) {
    209         RefPtr<Range> replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeEnd - replacementRangeStart));
     209        RefPtr<Range> replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeLength));
    210210        if (replacementRange)
    211211            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r165750 r165759  
    7777namespace WebKit {
    7878
    79 static PassRefPtr<Range> convertToRange(Frame*, NSRange);
     79static PassRefPtr<Range> convertToRange(Frame*, uint64_t location, uint64_t length);
    8080
    8181void WebPage::platformInitialize()
     
    248248}
    249249
    250 void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionEnd, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, EditorState& newState)
     250void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength, EditorState& newState)
    251251{
    252252    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    255255        RefPtr<Range> replacementRange;
    256256        if (replacementRangeStart != NSNotFound) {
    257             replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeEnd - replacementRangeStart));
     257            replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
    258258            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
    259259        }
    260260
    261         frame.editor().setComposition(text, underlines, selectionStart, selectionEnd);
     261        frame.editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
    262262    }
    263263
     
    279279}
    280280
    281 void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, bool& handled, EditorState& newState)
     281void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, bool& handled, EditorState& newState)
    282282{
    283283    Frame& frame = m_page->focusController().focusedOrMainFrame();
    284284
    285285    if (replacementRangeStart != NSNotFound) {
    286         RefPtr<Range> replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeEnd - replacementRangeStart));
     286        RefPtr<Range> replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
    287287        if (replacementRange)
    288288            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    301301}
    302302
    303 void WebPage::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeEnd, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState)
     303void WebPage::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState)
    304304{
    305305    Frame& frame = m_page->focusController().focusedOrMainFrame();
    306306
    307307    if (replacementRangeStart != NSNotFound) {
    308         RefPtr<Range> replacementRange = convertToRange(&frame, NSMakeRange(replacementRangeStart, replacementRangeEnd - replacementRangeStart));
     308        RefPtr<Range> replacementRange = convertToRange(&frame, replacementRangeStart, replacementRangeLength);
    309309        if (replacementRange)
    310310            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    348348}
    349349
    350 void WebPage::getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeEnd, AttributedString& result)
     350void WebPage::getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString& result)
    351351{
    352352    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    356356        return;
    357357
    358     NSRange nsRange = NSMakeRange(rangeStart, rangeEnd - rangeStart);
    359     RefPtr<Range> range = convertToRange(&frame, nsRange);
     358    RefPtr<Range> range = convertToRange(&frame, rangeStart, rangeLength);
    360359    if (!range)
    361360        return;
     
    367366    // whitespace at the end of the string which breaks the ATOK input method.  <rdar://problem/5400551>
    368367    // To work around this we truncate the resultant string to the correct length.
    369     if ([attributedString length] > nsRange.length) {
    370         ASSERT([attributedString length] == nsRange.length + 1);
    371         ASSERT([[attributedString string] characterAtIndex:nsRange.length] == '\n' || [[attributedString string] characterAtIndex:nsRange.length] == ' ');
    372         result.string = [attributedString attributedSubstringFromRange:NSMakeRange(0, nsRange.length)];
     368    if ([attributedString length] > rangeLength) {
     369        ASSERT([attributedString length] == rangeLength + 1);
     370        ASSERT([[attributedString string] characterAtIndex:rangeLength] == '\n' || [[attributedString string] characterAtIndex:rangeLength] == ' ');
     371        result.string = [attributedString attributedSubstringFromRange:NSMakeRange(0, rangeLength)];
    373372    }
    374373}
     
    391390}
    392391
    393 PassRefPtr<Range> convertToRange(Frame* frame, NSRange nsrange)
    394 {
    395     if (nsrange.location > INT_MAX)
     392PassRefPtr<Range> convertToRange(Frame* frame, uint64_t location, uint64_t length)
     393{
     394    if (location > INT_MAX)
    396395        return 0;
    397     if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
    398         nsrange.length = INT_MAX - nsrange.location;
     396    if (length > INT_MAX || location + length > INT_MAX)
     397        length = INT_MAX - location;
    399398       
    400399    // our critical assumption is that we are only called by input methods that
     
    404403    // to use the root editable element of the selection start as the positional base.
    405404    // That fits with AppKit's idea of an input context.
    406     return TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), nsrange.location, nsrange.length);
     405    return TextIterator::rangeFromLocationAndLength(frame->selection().rootEditableElementOrDocumentElement(), location, length);
    407406}
    408407   
     
    413412    resultRect.setSize(IntSize(0, 0));
    414413   
    415     RefPtr<Range> range = convertToRange(&frame, NSMakeRange(location, length));
     414    RefPtr<Range> range = convertToRange(&frame, location, length);
    416415    if (!range)
    417416        return;
Note: See TracChangeset for help on using the changeset viewer.