Changeset 165823 in webkit


Ignore:
Timestamp:
Mar 18, 2014 11:13:44 AM (10 years ago)
Author:
ap@apple.com
Message:

[WK2] Pass ranges over IPC in a cross-platform manner
https://bugs.webkit.org/show_bug.cgi?id=130376

Reviewed by Anders Carlsson.

Added an EditingRange class for IPC, which automatically converts to and from
NSRanges, knowing the difference between notFound and NSNotFound.

Manually applied the same fix to characterIndexForPoint.

  • Scripts/webkit2/messages.py:

(struct_or_class):

  • Shared/EditingRange.h: Added.

(WebKit::EditingRange::EditingRange):
(WebKit::EditingRange::isValid):
(WebKit::EditingRange::operator NSRange):

  • UIProcess/API/mac/WKView.mm:

(-[WKView insertText:replacementRange:]):
(-[WKView selectedRange]):
(-[WKView hasMarkedText]):
(-[WKView setMarkedText:selectedRange:replacementRange:]):
(-[WKView markedRange]):
(-[WKView attributedSubstringForProposedRange:actualRange:]):
(-[WKView characterIndexForPoint:]):
(-[WKView firstRectForCharacterRange:actualRange:]):

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

(-[WKContentView setMarkedText:selectedRange:]):
(-[WKContentView insertText:]):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::setComposition):
(WebKit::WebPageProxy::insertText):
(WebKit::WebPageProxy::insertDictatedText):
(WebKit::WebPageProxy::getMarkedRange):
(WebKit::WebPageProxy::getSelectedRange):
(WebKit::WebPageProxy::getAttributedSubstringFromRange):
(WebKit::WebPageProxy::firstRectForCharacterRange):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::setComposition):
(WebKit::WebPageProxy::insertText):
(WebKit::WebPageProxy::insertDictatedText):
(WebKit::WebPageProxy::getMarkedRange):
(WebKit::WebPageProxy::getSelectedRange):
(WebKit::WebPageProxy::getAttributedSubstringFromRange):
(WebKit::WebPageProxy::firstRectForCharacterRange):

  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::rangeFromEditingRange):

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

(WebKit::WebPage::setComposition):
(WebKit::WebPage::insertText):
(WebKit::WebPage::insertDictatedText):
(WebKit::WebPage::getMarkedRange):
(WebKit::WebPage::getSelectedRange):
(WebKit::WebPage::getAttributedSubstringFromRange):
(WebKit::WebPage::firstRectForCharacterRange):

  • WebProcess/WebPage/mac/WebPageMac.mm:

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

Location:
trunk/Source/WebKit2
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r165818 r165823  
     12014-03-17  Alexey Proskuryakov  <ap@apple.com>
     2
     3        [WK2] Pass ranges over IPC in a cross-platform manner
     4        https://bugs.webkit.org/show_bug.cgi?id=130376
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Added an EditingRange class for IPC, which automatically converts to and from
     9        NSRanges, knowing the difference between notFound and NSNotFound.
     10
     11        Manually applied the same fix to characterIndexForPoint.
     12
     13        * Scripts/webkit2/messages.py:
     14        (struct_or_class):
     15        * Shared/EditingRange.h: Added.
     16        (WebKit::EditingRange::EditingRange):
     17        (WebKit::EditingRange::isValid):
     18        (WebKit::EditingRange::operator NSRange):
     19        * UIProcess/API/mac/WKView.mm:
     20        (-[WKView insertText:replacementRange:]):
     21        (-[WKView selectedRange]):
     22        (-[WKView hasMarkedText]):
     23        (-[WKView setMarkedText:selectedRange:replacementRange:]):
     24        (-[WKView markedRange]):
     25        (-[WKView attributedSubstringForProposedRange:actualRange:]):
     26        (-[WKView characterIndexForPoint:]):
     27        (-[WKView firstRectForCharacterRange:actualRange:]):
     28        * UIProcess/WebPageProxy.h:
     29        * UIProcess/ios/WKContentViewInteraction.mm:
     30        (-[WKContentView setMarkedText:selectedRange:]):
     31        (-[WKContentView insertText:]):
     32        * UIProcess/ios/WebPageProxyIOS.mm:
     33        (WebKit::WebPageProxy::setComposition):
     34        (WebKit::WebPageProxy::insertText):
     35        (WebKit::WebPageProxy::insertDictatedText):
     36        (WebKit::WebPageProxy::getMarkedRange):
     37        (WebKit::WebPageProxy::getSelectedRange):
     38        (WebKit::WebPageProxy::getAttributedSubstringFromRange):
     39        (WebKit::WebPageProxy::firstRectForCharacterRange):
     40        * UIProcess/mac/WebPageProxyMac.mm:
     41        (WebKit::WebPageProxy::setComposition):
     42        (WebKit::WebPageProxy::insertText):
     43        (WebKit::WebPageProxy::insertDictatedText):
     44        (WebKit::WebPageProxy::getMarkedRange):
     45        (WebKit::WebPageProxy::getSelectedRange):
     46        (WebKit::WebPageProxy::getAttributedSubstringFromRange):
     47        (WebKit::WebPageProxy::firstRectForCharacterRange):
     48        * WebKit2.xcodeproj/project.pbxproj:
     49        * WebProcess/WebPage/WebPage.cpp:
     50        (WebKit::WebPage::rangeFromEditingRange):
     51        * WebProcess/WebPage/WebPage.h:
     52        * WebProcess/WebPage/WebPage.messages.in:
     53        * WebProcess/WebPage/ios/WebPageIOS.mm:
     54        (WebKit::WebPage::setComposition):
     55        (WebKit::WebPage::insertText):
     56        (WebKit::WebPage::insertDictatedText):
     57        (WebKit::WebPage::getMarkedRange):
     58        (WebKit::WebPage::getSelectedRange):
     59        (WebKit::WebPage::getAttributedSubstringFromRange):
     60        (WebKit::WebPage::firstRectForCharacterRange):
     61        * WebProcess/WebPage/mac/WebPageMac.mm:
     62        (WebKit::WebPage::setComposition):
     63        (WebKit::WebPage::insertText):
     64        (WebKit::WebPage::insertDictatedText):
     65        (WebKit::WebPage::getMarkedRange):
     66        (WebKit::WebPage::getSelectedRange):
     67        (WebKit::WebPage::getAttributedSubstringFromRange):
     68        (WebKit::WebPage::characterIndexForPoint):
     69        (WebKit::WebPage::firstRectForCharacterRange):
     70
    1712014-03-17  Filip Pizlo  <fpizlo@apple.com>
    272
  • trunk/Source/WebKit2/Scripts/webkit2/messages.py

    r164955 r165823  
    212212        'WebKit::DictionaryPopupInfo',
    213213        'WebKit::DrawingAreaInfo',
     214        'WebKit::EditingRange',
    214215        'WebKit::EditorState',
    215216        'WebKit::InteractionInformationAtPosition',
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r165759 r165823  
    3737#import "ColorSpaceData.h"
    3838#import "DataReference.h"
     39#import "EditingRange.h"
    3940#import "EditorState.h"
    4041#import "FindIndicator.h"
     
    12901291    bool eventHandled;
    12911292    if (!dictationAlternatives.isEmpty())
    1292         eventHandled = _data->_page->insertDictatedText(eventText, replacementRange.location, replacementRange.length, dictationAlternatives);
     1293        eventHandled = _data->_page->insertDictatedText(eventText, replacementRange, dictationAlternatives);
    12931294    else
    1294         eventHandled = _data->_page->insertText(eventText, replacementRange.location, replacementRange.length);
     1295        eventHandled = _data->_page->insertText(eventText, replacementRange);
    12951296
    12961297    if (parameters)
     
    14811482    [self _executeSavedKeypressCommands];
    14821483
    1483     uint64_t selectionStart;
    1484     uint64_t selectionLength;
    1485     _data->_page->getSelectedRange(selectionStart, selectionLength);
    1486 
    1487     NSRange result = NSMakeRange(selectionStart, selectionLength);
     1484    EditingRange selectedRange;
     1485    _data->_page->getSelectedRange(selectedRange);
     1486
     1487    NSRange result = selectedRange;
    14881488    if (result.location == NSNotFound)
    14891489        LOG(TextInput, "selectedRange -> (NSNotFound, %u)", result.length);
     
    15071507        }
    15081508    } else {
    1509         uint64_t location;
    1510         uint64_t length;
    1511         _data->_page->getMarkedRange(location, length);
    1512         result = location != NSNotFound;
     1509        EditingRange markedRange;
     1510        _data->_page->getMarkedRange(markedRange);
     1511        result = markedRange.location != notFound;
    15131512    }
    15141513
     
    15761575}
    15771576
    1578 - (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange replacementRange:(NSRange)replacementRange
     1577- (void)setMarkedText:(id)string selectedRange:(NSRange)newSelectedRange replacementRange:(NSRange)replacementRange
    15791578{
    15801579    [self _executeSavedKeypressCommands];
     
    15831582    ASSERT(isAttributedString || [string isKindOfClass:[NSString class]]);
    15841583
    1585     LOG(TextInput, "setMarkedText:\"%@\" selectedRange:(%u, %u)", isAttributedString ? [string string] : string, newSelRange.location, newSelRange.length);
     1584    LOG(TextInput, "setMarkedText:\"%@\" selectedRange:(%u, %u)", isAttributedString ? [string string] : string, newSelectedRange.location, newSelectedRange.length);
    15861585
    15871586    // Use pointer to get parameters passed to us by the caller of interpretKeyEvents.
     
    16091608        [self _notifyInputContextAboutDiscardedComposition];
    16101609        if ([text length] == 1 && [[text decomposedStringWithCanonicalMapping] characterAtIndex:0] < 0x80) {
    1611             _data->_page->insertText(text, replacementRange.location, replacementRange.length);
     1610            _data->_page->insertText(text, replacementRange);
    16121611        } else
    16131612            NSBeep();
     
    16151614    }
    16161615
    1617     _data->_page->setComposition(text, underlines, newSelRange.location, newSelRange.length, replacementRange.location, replacementRange.length);
     1616    _data->_page->setComposition(text, underlines, newSelectedRange, replacementRange);
    16181617}
    16191618
     
    16221621    [self _executeSavedKeypressCommands];
    16231622
    1624     uint64_t location;
    1625     uint64_t length;
    1626     _data->_page->getMarkedRange(location, length);
    1627 
    1628     LOG(TextInput, "markedRange -> (%u, %u)", location, length);
    1629     return NSMakeRange(location, length);
     1623    EditingRange markedRange;
     1624    _data->_page->getMarkedRange(markedRange);
     1625
     1626    NSRange result = markedRange;
     1627    if (result.location == NSNotFound)
     1628        LOG(TextInput, "markedRange -> (NSNotFound, %u)", result.length);
     1629    else
     1630        LOG(TextInput, "markedRange -> (%u, %u)", result.location, result.length);
     1631
     1632    return result;
    16301633}
    16311634
     
    16431646
    16441647    AttributedString result;
    1645     _data->_page->getAttributedSubstringFromRange(nsRange.location, nsRange.length, result);
     1648    _data->_page->getAttributedSubstringFromRange(nsRange, result);
    16461649
    16471650    if (actualRange) {
     
    16681671   
    16691672    uint64_t result = _data->_page->characterIndexForPoint(IntPoint(thePoint));
     1673    if (result == notFound)
     1674        result = NSNotFound;
    16701675    LOG(TextInput, "characterIndexForPoint:(%f, %f) -> %u", thePoint.x, thePoint.y, result);
    16711676    return result;
     
    16821687        theRange.length = 0;
    16831688   
    1684     NSRect resultRect = _data->_page->firstRectForCharacterRange(theRange.location, theRange.length);
     1689    NSRect resultRect = _data->_page->firstRectForCharacterRange(theRange);
    16851690    resultRect = [self convertRect:resultRect toView:nil];
    16861691    resultRect = [self.window convertRectToScreen:resultRect];
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r165759 r165823  
    161161struct ColorSpaceData;
    162162struct DictionaryPopupInfo;
     163struct EditingRange;
    163164struct EditorState;
    164165struct PlatformPopupMenuData;
     
    526527    void setMainFrameIsScrollable(bool);
    527528
    528     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength);
     529    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementRange);
    529530    void confirmComposition();
    530531    void cancelComposition();
    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);
    533     void getMarkedRange(uint64_t& location, uint64_t& length);
    534     void getSelectedRange(uint64_t& location, uint64_t& length);
    535     void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString&);
     532    bool insertText(const String& text, const EditingRange& replacementRange);
     533    bool insertDictatedText(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives);
     534    void getMarkedRange(EditingRange&);
     535    void getSelectedRange(EditingRange&);
     536    void getAttributedSubstringFromRange(const EditingRange&, AttributedString&);
    536537    uint64_t characterIndexForPoint(const WebCore::IntPoint);
    537     WebCore::IntRect firstRectForCharacterRange(uint64_t, uint64_t);
     538    WebCore::IntRect firstRectForCharacterRange(const EditingRange&);
    538539    bool executeKeypressCommands(const Vector<WebCore::KeypressCommand>&);
    539540
  • trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

    r165572 r165823  
    2929#if PLATFORM(IOS)
    3030
     31#import "EditingRange.h"
    3132#import "NativeWebKeyboardEvent.h"
    3233#import "NativeWebTouchEvent.h"
     
    14101411{
    14111412    _markedText = markedText;
    1412     _page->setComposition(markedText, Vector<WebCore::CompositionUnderline>(), selectedRange.location, selectedRange.length, 0, 0);
     1413    _page->setComposition(markedText, Vector<WebCore::CompositionUnderline>(), selectedRange, EditingRange());
    14131414}
    14141415
     
    15071508- (void)insertText:(NSString *)aStringValue
    15081509{
    1509     _page->insertText(aStringValue, NSNotFound, 0);
     1510    _page->insertText(aStringValue, EditingRange());
    15101511}
    15111512
  • trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm

    r165759 r165823  
    3030
    3131#import "DataReference.h"
     32#import "EditingRange.h"
    3233#import "NativeWebKeyboardEvent.h"
    3334#import "PageClient.h"
     
    99100}
    100101
    101 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underline, uint64_t selectionStart, uint64_t selectionLength, uint64_t, uint64_t)
     102void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underline, const EditingRange& selectionRange, const EditingRange&)
    102103{
    103104    if (!isValid())
    104105        return;
    105106
    106     process().send(Messages::WebPage::SetComposition(text, underline, selectionStart, selectionLength), m_pageID);
     107    process().send(Messages::WebPage::SetComposition(text, underline, selectionRange), m_pageID);
    107108}
    108109
     
    121122}
    122123
    123 bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
     124bool WebPageProxy::insertText(const String& text, const EditingRange& replacementRange)
    124125{
    125126    if (!isValid())
    126127        return true;
    127128   
    128     process().send(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeLength), m_pageID);
     129    process().send(Messages::WebPage::InsertText(text, replacementRange), m_pageID);
    129130    return true;
    130131}
    131132
    132 bool WebPageProxy::insertDictatedText(const String&, uint64_t, uint64_t, const Vector<WebCore::TextAlternativeWithRange>&)
     133bool WebPageProxy::insertDictatedText(const String&, const EditingRange&, const Vector<WebCore::TextAlternativeWithRange>&)
    133134{
    134135    notImplemented();
     
    136137}
    137138
    138 void WebPageProxy::getMarkedRange(uint64_t&, uint64_t&)
    139 {
    140     notImplemented();
    141 }
    142 
    143 void WebPageProxy::getSelectedRange(uint64_t&, uint64_t&)
    144 {
    145     notImplemented();
    146 }
    147 
    148 void WebPageProxy::getAttributedSubstringFromRange(uint64_t, uint64_t, AttributedString&)
     139void WebPageProxy::getMarkedRange(EditingRange&)
     140{
     141    notImplemented();
     142}
     143
     144void WebPageProxy::getSelectedRange(EditingRange&)
     145{
     146    notImplemented();
     147}
     148
     149void WebPageProxy::getAttributedSubstringFromRange(const EditingRange&, AttributedString&)
    149150{
    150151    notImplemented();
     
    157158}
    158159
    159 IntRect WebPageProxy::firstRectForCharacterRange(uint64_t, uint64_t)
     160IntRect WebPageProxy::firstRectForCharacterRange(const EditingRange&)
    160161{
    161162    notImplemented();
  • trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm

    r165759 r165823  
    3434#import "DataReference.h"
    3535#import "DictionaryPopupInfo.h"
     36#import "EditingRange.h"
    3637#import "EditorState.h"
    3738#import "NativeWebKeyboardEvent.h"
     
    152153}
    153154
    154 void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
     155void WebPageProxy::setComposition(const String& text, Vector<CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementRange)
    155156{
    156157    if (!isValid()) {
     
    160161    }
    161162
    162     process().sendSync(Messages::WebPage::SetComposition(text, underlines, selectionStart, selectionLength, replacementRangeStart, replacementRangeLength), Messages::WebPage::SetComposition::Reply(m_editorState), m_pageID);
     163    process().sendSync(Messages::WebPage::SetComposition(text, underlines, selectionRange, replacementRange), Messages::WebPage::SetComposition::Reply(m_editorState), m_pageID);
    163164}
    164165
     
    179180}
    180181
    181 bool WebPageProxy::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
     182bool WebPageProxy::insertText(const String& text, const EditingRange& replacementRange)
    182183{
    183184    if (!isValid())
     
    185186
    186187    bool handled = true;
    187     process().sendSync(Messages::WebPage::InsertText(text, replacementRangeStart, replacementRangeLength), Messages::WebPage::InsertText::Reply(handled, m_editorState), m_pageID);
     188    process().sendSync(Messages::WebPage::InsertText(text, replacementRange), Messages::WebPage::InsertText::Reply(handled, m_editorState), m_pageID);
    188189    m_temporarilyClosedComposition = false;
    189190
     
    191192}
    192193
    193 bool WebPageProxy::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange)
     194bool WebPageProxy::insertDictatedText(const String& text, const EditingRange& replacementRange, const Vector<TextAlternativeWithRange>& dictationAlternativesWithRange)
    194195{
    195196#if USE(DICTATION_ALTERNATIVES)
    196197    if (dictationAlternativesWithRange.isEmpty())
    197         return insertText(text, replacementRangeStart, replacementRangeLength);
     198        return insertText(text, replacementRange);
    198199
    199200    if (!isValid())
     
    210211
    211212    if (dictationAlternatives.isEmpty())
    212         return insertText(text, replacementRangeStart, replacementRangeLength);
     213        return insertText(text, replacementRange);
    213214
    214215    bool handled = true;
    215     process().sendSync(Messages::WebPage::InsertDictatedText(text, replacementRangeStart, replacementRangeLength, dictationAlternatives), Messages::WebPage::InsertDictatedText::Reply(handled, m_editorState), m_pageID);
     216    process().sendSync(Messages::WebPage::InsertDictatedText(text, replacementRange, dictationAlternatives), Messages::WebPage::InsertDictatedText::Reply(handled, m_editorState), m_pageID);
    216217    return handled;
    217218#else
    218     return insertText(text, replacementRangeStart, replacementRangeLength);
     219    return insertText(text, replacementRange);
    219220#endif
    220221}
    221222
    222 void WebPageProxy::getMarkedRange(uint64_t& location, uint64_t& length)
    223 {
    224     location = NSNotFound;
    225     length = 0;
    226 
    227     if (!isValid())
    228         return;
    229 
    230     process().sendSync(Messages::WebPage::GetMarkedRange(), Messages::WebPage::GetMarkedRange::Reply(location, length), m_pageID);
    231 }
    232 
    233 void WebPageProxy::getSelectedRange(uint64_t& location, uint64_t& length)
    234 {
    235     location = NSNotFound;
    236     length = 0;
    237 
    238     if (!isValid())
    239         return;
    240 
    241     process().sendSync(Messages::WebPage::GetSelectedRange(), Messages::WebPage::GetSelectedRange::Reply(location, length), m_pageID);
    242 }
    243 
    244 void 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);
     223void WebPageProxy::getMarkedRange(EditingRange& result)
     224{
     225    result = EditingRange();
     226
     227    if (!isValid())
     228        return;
     229
     230    process().sendSync(Messages::WebPage::GetMarkedRange(), Messages::WebPage::GetMarkedRange::Reply(result), m_pageID);
     231    MESSAGE_CHECK(result.isValid());
     232}
     233
     234void WebPageProxy::getSelectedRange(EditingRange& result)
     235{
     236    result = EditingRange();
     237
     238    if (!isValid())
     239        return;
     240
     241    process().sendSync(Messages::WebPage::GetSelectedRange(), Messages::WebPage::GetSelectedRange::Reply(result), m_pageID);
     242    MESSAGE_CHECK(result.isValid());
     243}
     244
     245void WebPageProxy::getAttributedSubstringFromRange(const EditingRange& range, AttributedString& result)
     246{
     247    if (!isValid())
     248        return;
     249    process().sendSync(Messages::WebPage::GetAttributedSubstringFromRange(range), Messages::WebPage::GetAttributedSubstringFromRange::Reply(result), m_pageID);
    249250}
    250251
     
    259260}
    260261
    261 IntRect WebPageProxy::firstRectForCharacterRange(uint64_t location, uint64_t length)
     262IntRect WebPageProxy::firstRectForCharacterRange(const EditingRange& range)
    262263{
    263264    if (!isValid())
     
    265266
    266267    IntRect resultRect;
    267     process().sendSync(Messages::WebPage::FirstRectForCharacterRange(location, length), Messages::WebPage::FirstRectForCharacterRange::Reply(resultRect), m_pageID);
     268    process().sendSync(Messages::WebPage::FirstRectForCharacterRange(range), Messages::WebPage::FirstRectForCharacterRange::Reply(resultRect), m_pageID);
    268269    return resultRect;
    269270}
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r165758 r165823  
    14611461                D3B9484911FF4B6500032B39 /* WebSearchPopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B9484511FF4B6500032B39 /* WebSearchPopupMenu.h */; };
    14621462                DF58C6361371ACA000F9A37C /* NativeWebWheelEventMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = DF58C6351371ACA000F9A37C /* NativeWebWheelEventMac.mm */; };
     1463                E105FE5418D7B9DE008F57A8 /* EditingRange.h in Headers */ = {isa = PBXBuildFile; fileRef = E105FE5318D7B9DE008F57A8 /* EditingRange.h */; };
    14631464                E11D35AE16B63D1B006D23D7 /* com.apple.WebProcess.sb in Resources */ = {isa = PBXBuildFile; fileRef = E1967E37150AB5E200C73169 /* com.apple.WebProcess.sb */; };
    14641465                E133FD8A1423DD7F00FC7BFB /* WebKit.icns in Resources */ = {isa = PBXBuildFile; fileRef = E133FD891423DD7F00FC7BFB /* WebKit.icns */; };
     
    33233324                DF58C6311371AC5800F9A37C /* NativeWebWheelEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NativeWebWheelEvent.h; sourceTree = "<group>"; };
    33243325                DF58C6351371ACA000F9A37C /* NativeWebWheelEventMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NativeWebWheelEventMac.mm; sourceTree = "<group>"; };
     3326                E105FE5318D7B9DE008F57A8 /* EditingRange.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditingRange.h; sourceTree = "<group>"; };
    33253327                E133FD891423DD7F00FC7BFB /* WebKit.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = WebKit.icns; path = Resources/WebKit.icns; sourceTree = "<group>"; };
    33263328                E13833EB189C33C8001E2350 /* LocalStorageDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalStorageDetails.h; sourceTree = "<group>"; };
     
    39953997                                C517388012DF8F4F00EE3F47 /* DragControllerAction.h */,
    39963998                                0FB659221208B4DB0044816C /* DrawingAreaInfo.h */,
     3999                                E105FE5318D7B9DE008F57A8 /* EditingRange.h */,
    39974000                                8CFECE931490F140002AAA32 /* EditorState.cpp */,
    39984001                                1AA41AB412C02EC4002BE67B /* EditorState.h */,
     
    65686571                                BCE81D8D1319F7EF00241910 /* FontInfo.h in Headers */,
    65696572                                1ABC3DFC1899F51C004F0626 /* WKNavigationDelegate.h in Headers */,
     6573                                E105FE5418D7B9DE008F57A8 /* EditingRange.h in Headers */,
    65706574                                BC17753F118BABF0007D9E9A /* GenericCallback.h in Headers */,
    65716575                                379A873618BBFA4300588AF2 /* _WKActivatedElementInfoInternal.h in Headers */,
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r165767 r165823  
    3535#include "DrawingArea.h"
    3636#include "DrawingAreaMessages.h"
     37#include "EditingRange.h"
    3738#include "EditorState.h"
    3839#include "EventDispatcher.h"
     
    43374338}
    43384339
    4339 PassRefPtr<Range> WebPage::rangeFromEditingLocationAndLength(Frame& frame, uint64_t location, uint64_t length)
    4340 {
     4340PassRefPtr<WebCore::Range> WebPage::rangeFromEditingRange(WebCore::Frame& frame, const EditingRange& range)
     4341{
     4342    ASSERT(range.location != notFound);
     4343
    43414344    // Sanitize the input, because TextIterator::rangeFromLocationAndLength takes signed integers.
    4342     if (location > INT_MAX)
     4345    if (range.location > INT_MAX)
    43434346        return 0;
    4344     if (length > INT_MAX || location + length > INT_MAX)
    4345         length = INT_MAX - location;
     4347    int length;
     4348    if (range.length <= INT_MAX && range.location + range.length <= INT_MAX)
     4349        length = static_cast<int>(range.length);
     4350    else
     4351        length = INT_MAX - range.location;
    43464352
    43474353    // Our critical assumption is that we are only called by input methods that
     
    43514357    // to use the root editable element of the selection start as the positional base.
    43524358    // That fits with AppKit's idea of an input context.
    4353     return TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), location, length);
    4354 }
     4359    return TextIterator::rangeFromLocationAndLength(frame.selection().rootEditableElementOrDocumentElement(), static_cast<int>(range.location), length);
     4360}
     4361
    43554362
    43564363} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r165767 r165823  
    164164struct AssistedNodeInformation;
    165165struct AttributedString;
     166struct EditingRange;
    166167struct EditorState;
    167168struct InteractionInformationAtPosition;
     
    456457    void requestAutocorrectionContext(uint64_t callbackID);
    457458    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 replacementRangeLength);
    459     void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength);
     459    void insertText(const String& text, const EditingRange& replacementRange);
     460    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, const EditingRange& selectionRange);
    460461    void confirmComposition();
    461462    void getPositionInformation(const WebCore::IntPoint&, InteractionInformationAtPosition&);
     
    539540    void cancelComposition(EditorState& newState);
    540541#if !PLATFORM(IOS)
    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);
     542    void insertText(const String& text, const EditingRange& replacementRange, bool& handled, EditorState& newState);
     543    void setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementRange, EditorState& newState);
    543544    void confirmComposition(EditorState& newState);
    544545#endif
    545     void getMarkedRange(uint64_t& location, uint64_t& length);
    546     void getSelectedRange(uint64_t& location, uint64_t& length);
    547     void getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString&);
     546    void getMarkedRange(EditingRange&);
     547    void getSelectedRange(EditingRange&);
     548    void getAttributedSubstringFromRange(const EditingRange&, AttributedString&);
    548549    void characterIndexForPoint(const WebCore::IntPoint point, uint64_t& result);
    549     void firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect);
     550    void firstRectForCharacterRange(const EditingRange&, WebCore::IntRect& resultRect);
    550551    void executeKeypressCommands(const Vector<WebCore::KeypressCommand>&, bool& handled, EditorState& newState);
    551552    void readSelectionFromPasteboard(const WTF::String& pasteboardName, bool& result);
     
    555556    void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, bool& result);
    556557    bool performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*);
    557     void insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState);
     558    void insertDictatedText(const String& text, const EditingRange& replacementRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState);
    558559#elif PLATFORM(EFL)
    559560    void confirmComposition(const String& compositionString);
     
    928929    static PluginView* pluginViewForFrame(WebCore::Frame*);
    929930
    930     PassRefPtr<WebCore::Range> rangeFromEditingLocationAndLength(WebCore::Frame&, uint64_t location, uint64_t length);
     931    static PassRefPtr<WebCore::Range> rangeFromEditingRange(WebCore::Frame&, const EditingRange&);
    931932
    932933    void reportUsedFeatures();
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

    r165769 r165823  
    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 replacementRangeLength)
    60     SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength)
     59    InsertText(String text, WebKit::EditingRange replacementRange)
     60    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, WebKit::EditingRange selectionRange)
    6161    ConfirmComposition()
    6262    GetPositionInformation(WebCore::IntPoint point) -> (WebKit::InteractionInformationAtPosition information)
     
    293293    # Text input.
    294294    CancelComposition() -> (WebKit::EditorState newState)
    295     GetMarkedRange() -> (uint64_t location, uint64_t length)
    296     GetSelectedRange() -> (uint64_t location, uint64_t length)
    297     GetAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength) -> (WebKit::AttributedString result)
     295    GetMarkedRange() -> (WebKit::EditingRange range)
     296    GetSelectedRange() -> (WebKit::EditingRange range)
     297    GetAttributedSubstringFromRange(WebKit::EditingRange range) -> (WebKit::AttributedString result)
    298298    CharacterIndexForPoint(WebCore::IntPoint point) -> (uint64_t result)
    299     FirstRectForCharacterRange(uint64_t location, uint64_t length) -> (WebCore::IntRect resultRect)
     299    FirstRectForCharacterRange(WebKit::EditingRange range) -> (WebCore::IntRect resultRect)
    300300    ExecuteKeypressCommands(Vector<WebCore::KeypressCommand> savedCommands) -> (bool handled, WebKit::EditorState newState)
    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 replacementRangeLength, Vector<WebCore::DictationAlternative> dictationAlternatives) -> (bool handled, WebKit::EditorState newState)
     303    InsertDictatedText(String text, WebKit::EditingRange replacementRange, Vector<WebCore::DictationAlternative> dictationAlternatives) -> (bool handled, WebKit::EditorState newState)
    304304#endif
    305305#if PLATFORM(MAC)
    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)
     306    InsertText(String text, WebKit::EditingRange replacementRange) -> (bool handled, WebKit::EditorState newState)
     307    SetComposition(String text, Vector<WebCore::CompositionUnderline> underlines, WebKit::EditingRange selectionRange, WebKit::EditingRange replacementRange) -> (WebKit::EditorState newState)
    308308    ConfirmComposition() -> (WebKit::EditorState newState)
    309309#endif
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r165767 r165823  
    3131#import "AssistedNodeInformation.h"
    3232#import "DataReference.h"
     33#import "EditingRange.h"
    3334#import "EditorState.h"
    3435#import "InteractionInformationAtPosition.h"
     
    167168}
    168169
    169 void WebPage::setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength)
     170void WebPage::setComposition(const String& text, Vector<WebCore::CompositionUnderline> underlines, const EditingRange& selectionRange)
    170171{
    171172    Frame& frame = m_page->focusController().focusedOrMainFrame();
    172173
    173174    if (frame.selection().selection().isContentEditable())
    174         frame.editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
     175        frame.editor().setComposition(text, underlines, selectionRange.location, selectionRange.location + selectionRange.length);
    175176}
    176177
     
    186187}
    187188
    188 void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength)
     189void WebPage::insertText(const String& text, const EditingRange& replacementEditingRange)
    189190{
    190191    Frame& frame = m_page->focusController().focusedOrMainFrame();
    191192   
    192     if (replacementRangeStart != NSNotFound) {
    193         RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
     193    if (replacementEditingRange.location != notFound) {
     194        RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange);
    194195        if (replacementRange)
    195196            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    204205}
    205206
    206 void WebPage::insertDictatedText(const String&, uint64_t, uint64_t, const Vector<WebCore::DictationAlternative>&, bool&, EditorState&)
    207 {
    208     notImplemented();
    209 }
    210 
    211 void WebPage::getMarkedRange(uint64_t&, uint64_t&)
    212 {
    213     notImplemented();
    214 }
    215 
    216 void WebPage::getSelectedRange(uint64_t&, uint64_t&)
    217 {
    218     notImplemented();
    219 }
    220 
    221 void WebPage::getAttributedSubstringFromRange(uint64_t, uint64_t, AttributedString&)
     207void WebPage::insertDictatedText(const String&, const EditingRange&, const Vector<WebCore::DictationAlternative>&, bool&, EditorState&)
     208{
     209    notImplemented();
     210}
     211
     212void WebPage::getMarkedRange(EditingRange&)
     213{
     214    notImplemented();
     215}
     216
     217void WebPage::getSelectedRange(EditingRange&)
     218{
     219    notImplemented();
     220}
     221
     222void WebPage::getAttributedSubstringFromRange(const EditingRange&, AttributedString&)
    222223{
    223224    notImplemented();
     
    229230}
    230231
    231 void WebPage::firstRectForCharacterRange(uint64_t, uint64_t, WebCore::IntRect&)
     232void WebPage::firstRectForCharacterRange(const EditingRange&, WebCore::IntRect&)
    232233{
    233234    notImplemented();
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

    r165767 r165823  
    3131#import "AttributedString.h"
    3232#import "DataReference.h"
     33#import "EditingRange.h"
    3334#import "EditorState.h"
    3435#import "PDFKitImports.h"
     
    246247}
    247248
    248 void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, uint64_t selectionStart, uint64_t selectionLength, uint64_t replacementRangeStart, uint64_t replacementRangeLength, EditorState& newState)
     249void WebPage::setComposition(const String& text, Vector<CompositionUnderline> underlines, const EditingRange& selectionRange, const EditingRange& replacementEditingRange, EditorState& newState)
    249250{
    250251    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    252253    if (frame.selection().selection().isContentEditable()) {
    253254        RefPtr<Range> replacementRange;
    254         if (replacementRangeStart != NSNotFound) {
    255             replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
     255        if (replacementEditingRange.location != notFound) {
     256            replacementRange = rangeFromEditingRange(frame, replacementEditingRange);
    256257            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
    257258        }
    258259
    259         frame.editor().setComposition(text, underlines, selectionStart, selectionStart + selectionLength);
     260        frame.editor().setComposition(text, underlines, selectionRange.location, selectionRange.location + selectionRange.length);
    260261    }
    261262
     
    277278}
    278279
    279 void WebPage::insertText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, bool& handled, EditorState& newState)
    280 {
    281     Frame& frame = m_page->focusController().focusedOrMainFrame();
    282 
    283     if (replacementRangeStart != NSNotFound) {
    284         RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
     280void WebPage::insertText(const String& text, const EditingRange& replacementEditingRange, bool& handled, EditorState& newState)
     281{
     282    Frame& frame = m_page->focusController().focusedOrMainFrame();
     283
     284    if (replacementEditingRange.location != notFound) {
     285        RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange);
    285286        if (replacementRange)
    286287            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    299300}
    300301
    301 void WebPage::insertDictatedText(const String& text, uint64_t replacementRangeStart, uint64_t replacementRangeLength, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState)
    302 {
    303     Frame& frame = m_page->focusController().focusedOrMainFrame();
    304 
    305     if (replacementRangeStart != NSNotFound) {
    306         RefPtr<Range> replacementRange = rangeFromEditingLocationAndLength(frame, replacementRangeStart, replacementRangeLength);
     302void WebPage::insertDictatedText(const String& text, const EditingRange& replacementEditingRange, const Vector<WebCore::DictationAlternative>& dictationAlternativeLocations, bool& handled, EditorState& newState)
     303{
     304    Frame& frame = m_page->focusController().focusedOrMainFrame();
     305
     306    if (replacementEditingRange.location != notFound) {
     307        RefPtr<Range> replacementRange = rangeFromEditingRange(frame, replacementEditingRange);
    307308        if (replacementRange)
    308309            frame.selection().setSelection(VisibleSelection(replacementRange.get(), SEL_DEFAULT_AFFINITY));
     
    314315}
    315316
    316 void WebPage::getMarkedRange(uint64_t& location, uint64_t& length)
     317void WebPage::getMarkedRange(EditingRange& result)
    317318{
    318319    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    321322    size_t locationSize;
    322323    size_t lengthSize;
    323     if (range && TextIterator::getLocationAndLengthFromRange(frame.selection().rootEditableElementOrDocumentElement(), range.get(), locationSize, lengthSize)) {
    324         location = static_cast<uint64_t>(locationSize);
    325         length = static_cast<uint64_t>(lengthSize);
    326     } else {
    327         location = NSNotFound;
    328         length = 0;
    329     }
    330 }
    331 
    332 void WebPage::getSelectedRange(uint64_t& location, uint64_t& length)
     324    if (range && TextIterator::getLocationAndLengthFromRange(frame.selection().rootEditableElementOrDocumentElement(), range.get(), locationSize, lengthSize))
     325        result = EditingRange(static_cast<uint64_t>(locationSize), static_cast<uint64_t>(lengthSize));
     326    else
     327        result = EditingRange();
     328}
     329
     330void WebPage::getSelectedRange(EditingRange& result)
    333331{
    334332    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    337335    size_t lengthSize;
    338336    RefPtr<Range> range = frame.selection().toNormalizedRange();
    339     if (range && TextIterator::getLocationAndLengthFromRange(frame.selection().rootEditableElementOrDocumentElement(), range.get(), locationSize, lengthSize)) {
    340         location = static_cast<uint64_t>(locationSize);
    341         length = static_cast<uint64_t>(lengthSize);
    342     } else {
    343         location = NSNotFound;
    344         length = 0;
    345     }
    346 }
    347 
    348 void WebPage::getAttributedSubstringFromRange(uint64_t rangeStart, uint64_t rangeLength, AttributedString& result)
     337    if (range && TextIterator::getLocationAndLengthFromRange(frame.selection().rootEditableElementOrDocumentElement(), range.get(), locationSize, lengthSize))
     338        result = EditingRange(static_cast<uint64_t>(locationSize), static_cast<uint64_t>(lengthSize));
     339    else
     340        result = EditingRange();
     341}
     342
     343void WebPage::getAttributedSubstringFromRange(const EditingRange& editingRange, AttributedString& result)
    349344{
    350345    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    354349        return;
    355350
    356     RefPtr<Range> range = rangeFromEditingLocationAndLength(frame, rangeStart, rangeLength);
     351    RefPtr<Range> range = rangeFromEditingRange(frame, editingRange);
    357352    if (!range)
    358353        return;
     
    364359    // whitespace at the end of the string which breaks the ATOK input method.  <rdar://problem/5400551>
    365360    // To work around this we truncate the resultant string to the correct length.
    366     if ([attributedString length] > rangeLength) {
    367         ASSERT([attributedString length] == rangeLength + 1);
    368         ASSERT([[attributedString string] characterAtIndex:rangeLength] == '\n' || [[attributedString string] characterAtIndex:rangeLength] == ' ');
    369         result.string = [attributedString attributedSubstringFromRange:NSMakeRange(0, rangeLength)];
     361    if ([attributedString length] > editingRange.length) {
     362        ASSERT([attributedString length] == editingRange.length + 1);
     363        ASSERT([[attributedString string] characterAtIndex:editingRange.length] == '\n' || [[attributedString string] characterAtIndex:editingRange.length] == ' ');
     364        result.string = [attributedString attributedSubstringFromRange:NSMakeRange(0, editingRange.length)];
    370365    }
    371366}
     
    373368void WebPage::characterIndexForPoint(IntPoint point, uint64_t& index)
    374369{
    375     index = NSNotFound;
     370    index = notFound;
    376371
    377372    HitTestResult result = m_page->mainFrame().eventHandler().hitTestResultAtPoint(point);
     
    388383}
    389384   
    390 void WebPage::firstRectForCharacterRange(uint64_t location, uint64_t length, WebCore::IntRect& resultRect)
     385void WebPage::firstRectForCharacterRange(const EditingRange& editingRange, WebCore::IntRect& resultRect)
    391386{
    392387    Frame& frame = m_page->focusController().focusedOrMainFrame();
     
    394389    resultRect.setSize(IntSize(0, 0));
    395390   
    396     RefPtr<Range> range = rangeFromEditingLocationAndLength(frame, location, length);
     391    RefPtr<Range> range = rangeFromEditingRange(frame, editingRange);
    397392    if (!range)
    398393        return;
Note: See TracChangeset for help on using the changeset viewer.