Bug 99438 - [WK2][WTR] Text input controller needs selectedRange implementation
Summary: [WK2][WTR] Text input controller needs selectedRange implementation
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 42337 100219
  Show dependency treegraph
 
Reported: 2012-10-16 02:03 PDT by Mariusz Grzegorczyk
Modified: 2014-04-16 10:25 PDT (History)
17 users (show)

See Also:


Attachments
patch (10.40 KB, patch)
2012-10-25 01:41 PDT, Mariusz Grzegorczyk
no flags Details | Formatted Diff | Diff
use getSelectedRange from WebPage's Mac port (12.79 KB, patch)
2012-10-26 06:36 PDT, Mariusz Grzegorczyk
buildbot: commit-queue-
Details | Formatted Diff | Diff
Applied Kenneth's comments (13.51 KB, patch)
2012-10-29 02:59 PDT, Mariusz Grzegorczyk
no flags Details | Formatted Diff | Diff
Rebase and extend function to UIProcess (17.26 KB, patch)
2012-11-28 09:49 PST, Mariusz Grzegorczyk
no flags Details | Formatted Diff | Diff
Rebased, added comment about moving mac implementation to common part (17.32 KB, patch)
2012-12-12 01:09 PST, Mariusz Grzegorczyk
sam: review-
Details | Formatted Diff | Diff
Rebased, make asynchronous (18.12 KB, patch)
2013-03-06 10:07 PST, Mariusz Grzegorczyk
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mariusz Grzegorczyk 2012-10-16 02:03:03 PDT
Because of missing selectedRange() implementation following test doesn't pass:
editing/selection/mixed-editability-10.html
Comment 1 Mariusz Grzegorczyk 2012-10-22 09:58:05 PDT
Tests which uses textInputController.selectedRange:
editing/selection/5825350-1.html
editing/selection/5825350-2.html
editing/selection/extend-by-sentence-002.html
editing/selection/mixed-editability-10.html
editing/selection/move-left-right.html
platform/mac/editing/input/text-input-controller.html
Comment 2 Mariusz Grzegorczyk 2012-10-25 01:41:24 PDT
Created attachment 170588 [details]
patch
Comment 3 Chris Dumez 2012-10-25 03:13:00 PDT
Comment on attachment 170588 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=170588&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3334
> +    WebCore::ExceptionCode ec;

Shouldn't we handle error case?
Comment 4 Jussi Kukkonen (jku) 2012-10-25 06:24:22 PDT
Comment on attachment 170588 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=170588&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3314
> +bool WebPage::selectedRangeForTesting(int* start, int* length)

Is there a reason for not just moving WebPage::getSelectedRange() from WebPageMac.mm to here?
Comment 5 Mariusz Grzegorczyk 2012-10-26 03:24:09 PDT
(In reply to comment #4)
> (From update of attachment 170588 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=170588&action=review
> 
> > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3314
> > +bool WebPage::selectedRangeForTesting(int* start, int* length)
> 
> Is there a reason for not just moving WebPage::getSelectedRange() from WebPageMac.mm to here?

I'm afraid of NSRange usage in Mac port. There failure is marked as location = NSNotFound
Comment 6 Jussi Kukkonen (jku) 2012-10-26 03:44:25 PDT
(In reply to comment #5)
> > > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3314
> > > +bool WebPage::selectedRangeForTesting(int* start, int* length)
> > 
> > Is there a reason for not just moving WebPage::getSelectedRange() from WebPageMac.mm to here?
> 
> I'm afraid of NSRange usage in Mac port. There failure is marked as location = NSNotFound

There's only one user for this function:
  WKView selectedRange
so assuming you modified getSelectedRange to return a boolean like your new function and not set NSNotFound, wouldn't something like this work?

diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
index 0f221c6..d0fda59 100644
--- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
+++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
@@ -1427 +1427,2 @@ static const short kIOHIDEventTypeScroll = 6;
-    _data->_page->getSelectedRange(selectionStart, selectionLength);
+    if (!_data->_page->getSelectedRange(selectionStart, selectionLength))
+        selectionStart = NSNotFound;
Comment 7 Mariusz Grzegorczyk 2012-10-26 05:02:37 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > > > Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3314
> > > > +bool WebPage::selectedRangeForTesting(int* start, int* length)
> > > 
> > > Is there a reason for not just moving WebPage::getSelectedRange() from WebPageMac.mm to here?
> > 
> > I'm afraid of NSRange usage in Mac port. There failure is marked as location = NSNotFound
> 
> There's only one user for this function:
>   WKView selectedRange
> so assuming you modified getSelectedRange to return a boolean like your new function and not set NSNotFound, wouldn't something like this work?
> 
> diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm
> index 0f221c6..d0fda59 100644
> --- a/Source/WebKit2/UIProcess/API/mac/WKView.mm
> +++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm
> @@ -1427 +1427,2 @@ static const short kIOHIDEventTypeScroll = 6;
> -    _data->_page->getSelectedRange(selectionStart, selectionLength);
> +    if (!_data->_page->getSelectedRange(selectionStart, selectionLength))
> +        selectionStart = NSNotFound;

Ok, I'll try this. Will see what Mac developers say.
Comment 8 Mariusz Grzegorczyk 2012-10-26 06:36:12 PDT
Created attachment 170910 [details]
use getSelectedRange from WebPage's Mac port
Comment 9 Build Bot 2012-10-26 06:51:52 PDT
Comment on attachment 170910 [details]
use getSelectedRange from WebPage's Mac port

Attachment 170910 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/14551020
Comment 10 Jussi Kukkonen (jku) 2012-10-26 06:52:48 PDT
Comment on attachment 170910 [details]
use getSelectedRange from WebPage's Mac port

View in context: https://bugs.webkit.org/attachment.cgi?id=170910&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3346
> +    if (range && TextIterator::getLocationAndLengthFromRange(frame->selection()->rootEditableElementOrDocumentElement(), range.get(), locationSize, lengthSize)) {
> +        location = static_cast<uint64_t>(locationSize);
> +        length = static_cast<uint64_t>(lengthSize);
> +    }

Need to return false if the test here is not true, to reproduce the original mac version behaviour.
Comment 11 Kenneth Rohde Christiansen 2012-10-26 07:38:18 PDT
Comment on attachment 170910 [details]
use getSelectedRange from WebPage's Mac port

View in context: https://bugs.webkit.org/attachment.cgi?id=170910&action=review

> Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h:70
> +WK_EXPORT bool WKBundlePageSelectedRange(WKBundlePageRef pageRef, uint64_t& location, uint64_t& length);

I'm not sure other C-WK-API methods return a bool for getters. Maybe making location = -1 makes more sense?

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:3334
> +{

location = WTF::notFound ?
Comment 12 Mariusz Grzegorczyk 2012-10-29 02:59:42 PDT
Created attachment 171187 [details]
Applied Kenneth's comments
Comment 13 Jussi Kukkonen (jku) 2012-10-30 01:16:50 PDT
(In reply to comment #12)
> Created an attachment (id=171187) [details]
> Applied Kenneth's comments

Looks good to me at least.
Comment 14 Mariusz Grzegorczyk 2012-11-12 06:15:16 PST
(In reply to comment #13)
> (In reply to comment #12)
> > Created an attachment (id=171187) [details] [details]
> > Applied Kenneth's comments
> 
> Looks good to me at least.

I'm wondering if all these functions should be exported to API. If mac is testing such api in the future maybe all ports will do same. See https://bugs.webkit.org/show_bug.cgi?id=100219 comments.
Comment 15 Mariusz Grzegorczyk 2012-11-28 09:49:11 PST
Created attachment 176500 [details]
Rebase and extend function to UIProcess
Comment 16 Mariusz Grzegorczyk 2012-11-29 01:56:41 PST
Adding chromium and qt reviewers since this change affects all ports.
Comment 17 Gyuyoung Kim 2012-11-29 02:13:42 PST
Comment on attachment 176500 [details]
Rebase and extend function to UIProcess

View in context: https://bugs.webkit.org/attachment.cgi?id=176500&action=review

> Source/WebKit2/ChangeLog:8
> +        Implementation of getting selected range from webpage.

IMO, it would be good if you say this patch moves the implementation of mac port to common place for all ports.
Comment 18 Tony Chang 2012-11-29 10:39:24 PST
(In reply to comment #16)
> Adding chromium and qt reviewers since this change affects all ports.

This doesn't affect Chromium since Chromium doesn't use WebKit2 or WTR.
Comment 19 Mariusz Grzegorczyk 2012-12-12 01:09:59 PST
Created attachment 178994 [details]
Rebased, added comment about moving mac implementation to common part
Comment 20 Ryosuke Niwa 2012-12-12 01:50:55 PST
Comment on attachment 178994 [details]
Rebased, added comment about moving mac implementation to common part

View in context: https://bugs.webkit.org/attachment.cgi?id=178994&action=review

> Source/WebKit2/UIProcess/API/mac/WKView.mm:1431
>      NSRange result = NSMakeRange(selectionStart, selectionLength);
> -    if (result.location == NSNotFound)
> -        LOG(TextInput, "selectedRange -> (NSNotFound, %u)", result.length);
> +    if (result.location == WTF::notFound)
> +        LOG(TextInput, "selectedRange -> (notFound, %u)", result.length);

Don't we need to pass in NSNotFound to NSMakeRange?
Comment 21 Mariusz Grzegorczyk 2012-12-12 03:05:41 PST
(In reply to comment #20)
> (From update of attachment 178994 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=178994&action=review
> 
> > Source/WebKit2/UIProcess/API/mac/WKView.mm:1431
> >      NSRange result = NSMakeRange(selectionStart, selectionLength);
> > -    if (result.location == NSNotFound)
> > -        LOG(TextInput, "selectedRange -> (NSNotFound, %u)", result.length);
> > +    if (result.location == WTF::notFound)
> > +        LOG(TextInput, "selectedRange -> (notFound, %u)", result.length);
> 
> Don't we need to pass in NSNotFound to NSMakeRange?

In my opinion: no. NSMakeRange just fills structure with passed arguments. Because of common implementation getSelectedRange returns WTF::notFound instead of NSNotFound.
I suppose you are asking about following change:

...getSelectedRange(selectionStart, selectionLength);
+if (selectionStart == WTF::notFound)
+    selectionStart = NSNotFound;
if (result.location == NSNotFound)
   LOG(TextInput, "selectedRange -> (NSNotFound, %u)", result.length);
Comment 22 Gyuyoung Kim 2012-12-18 00:04:42 PST
Comment on attachment 178994 [details]
Rebased, added comment about moving mac implementation to common part

Looks good to me in terms of sharing port implementation. But, I think mac port reviewer or WK2 reviewer needs to have a final review.
Comment 23 Gyuyoung Kim 2012-12-27 23:00:15 PST
(In reply to comment #22)
> (From update of attachment 178994 [details])
> Looks good to me in terms of sharing port implementation. But, I think mac port reviewer or WK2 reviewer needs to have a final review.

If there is no comment or objection by next week, I'd like to land this patch. And, happy new year !!
Comment 24 Gyuyoung Kim 2013-01-06 18:21:15 PST
Comment on attachment 178994 [details]
Rebased, added comment about moving mac implementation to common part

LGTM. But, someone might wanna have a final look.
Comment 25 Sam Weinig 2013-01-06 18:32:36 PST
Comment on attachment 178994 [details]
Rebased, added comment about moving mac implementation to common part

This codifies a sync message to the WebProcess, something we need to eliminate and which is a huge no-no, in API.  r-.  Please find another way to do
Comment 26 Mariusz Grzegorczyk 2013-01-07 02:13:39 PST
(In reply to comment #25)
> (From update of attachment 178994 [details])
> This codifies a sync message to the WebProcess, something we need to eliminate and which is a huge no-no, in API.  r-.  Please find another way to do

Code is only shared between all ports and was moved from existing mac's implementation.
Comment 27 Gyuyoung Kim 2013-01-07 04:56:01 PST
(In reply to comment #25)
> > (From update of attachment 178994 [details] [details])
> > This codifies a sync message to the WebProcess, something we need to eliminate and which is a huge no-no, in API.  r-.  Please find another way to do

Sam, thank you for your review. But, we don't understand what is your point well. I also thought this patch is just share mac implementation with other ports. Could you let us know what something we missed in more detail ?
Comment 28 Sam Weinig 2013-01-07 10:54:43 PST
The Mac port does a bad thing here, it does a synchronous call to the WebProcess.  This is something that should be fixed, not extended to all the other ports.  By moving it into shared code and adding API, it makes it much harder to fix.
Comment 29 Mariusz Grzegorczyk 2013-01-08 02:07:13 PST
(In reply to comment #28)
> The Mac port does a bad thing here, it does a synchronous call to the WebProcess.  This is something that should be fixed, not extended to all the other ports.  By moving it into shared code and adding API, it makes it much harder to fix.

Are you proposing to make it using callbacks? What about changing API in mac? Who is using selectedRange there?
Comment 30 Mariusz Grzegorczyk 2013-03-06 10:07:52 PST
Created attachment 191781 [details]
Rebased, make asynchronous
Comment 31 Kenneth Rohde Christiansen 2013-03-07 03:05:33 PST
Comment on attachment 191781 [details]
Rebased, make asynchronous

View in context: https://bugs.webkit.org/attachment.cgi?id=191781&action=review

> Source/WebKit2/UIProcess/WebPageProxy.cpp:1014
> +void WebPageProxy::getSelectedRange(PassRefPtr<DataCallback> prpCallback)

what is a prp callback? pass ref ptr... no, please don't name like this!
Comment 32 Kenneth Rohde Christiansen 2013-03-07 03:06:05 PST
Benjamin, can you look at this?
Comment 33 Mariusz Grzegorczyk 2013-03-07 05:30:44 PST
Comment on attachment 191781 [details]
Rebased, make asynchronous

View in context: https://bugs.webkit.org/attachment.cgi?id=191781&action=review

>> Source/WebKit2/UIProcess/WebPageProxy.cpp:1014
>> +void WebPageProxy::getSelectedRange(PassRefPtr<DataCallback> prpCallback)
> 
> what is a prp callback? pass ref ptr... no, please don't name like this!

All callbacks are named in this file in this manner.
Comment 34 Andreas Kling 2014-02-05 11:19:23 PST
Comment on attachment 191781 [details]
Rebased, make asynchronous

Clearing review flag on patches from before 2014. If this patch is still relevant, please reset the r? flag.