Bug 155532 - Provide NSSpellChecker spellChecking methods with the current insertion point
Summary: Provide NSSpellChecker spellChecking methods with the current insertion point
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-15 22:06 PDT by Beth Dakin
Modified: 2016-03-25 16:50 PDT (History)
5 users (show)

See Also:


Attachments
Patch (41.93 KB, patch)
2016-03-15 22:17 PDT, Beth Dakin
no flags Details | Formatted Diff | Diff
Patch (42.00 KB, patch)
2016-03-16 11:52 PDT, Beth Dakin
no flags Details | Formatted Diff | Diff
Patch (44.06 KB, patch)
2016-03-16 12:06 PDT, Beth Dakin
no flags Details | Formatted Diff | Diff
Patch (46.23 KB, patch)
2016-03-16 12:19 PDT, Beth Dakin
no flags Details | Formatted Diff | Diff
Patch (47.98 KB, patch)
2016-03-16 13:29 PDT, Beth Dakin
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Beth Dakin 2016-03-15 22:06:50 PDT
Provide NSSpellChecker spellChecking methods with the current insertion point

rdar://problem/24066952
Comment 1 Beth Dakin 2016-03-15 22:17:04 PDT
Created attachment 274172 [details]
Patch
Comment 2 WebKit Commit Bot 2016-03-15 22:17:54 PDT
Attachment 274172 [details] did not pass style-queue:


ERROR: Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1102:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 1 in 24 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Beth Dakin 2016-03-16 11:52:56 PDT
Created attachment 274203 [details]
Patch
Comment 4 Beth Dakin 2016-03-16 12:06:34 PDT
Created attachment 274206 [details]
Patch
Comment 5 Beth Dakin 2016-03-16 12:19:48 PDT
Created attachment 274208 [details]
Patch
Comment 6 Beth Dakin 2016-03-16 13:29:42 PDT
Created attachment 274216 [details]
Patch
Comment 7 Darin Adler 2016-03-16 15:17:32 PDT
Comment on attachment 274216 [details]
Patch

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

Since text checker is defined in terms of string views, not the DOM, seems the right architecture would be to convert the selection to offsets within the string at the call sites, rather than actually passing the VisibleSelection object down. Is there a straightforward way to do it that way instead?

> Source/WebCore/ChangeLog:10
> +        Pass the Frameâs section to a handful of spelling checking methods that call 

Frame's selection, not Frame's section
Comment 8 Simon Fraser (smfr) 2016-03-16 15:28:45 PDT
Comment on attachment 274216 [details]
Patch

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

>> Source/WebCore/ChangeLog:10
>> +        Pass the Frameâs section to a handful of spelling checking methods that call 
> 
> Frame's selection, not Frame's section

Is there any way to test this? API test perhaps?

> Source/WebKit2/UIProcess/TextChecker.h:75
> +    static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t insertionPoint, uint64_t checkingTypes);

I find it a bit odd that the insertionPoint is a uint64_t. Does WebCore handle 64-bit offsets?

> Source/WebKit2/UIProcess/mac/TextCheckerMac.mm:301
> +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPoint], NSTextCheckingInsertionPointKey, nil];

You should use literals here: @{} etc.

> Source/WebKit2/UIProcess/mac/TextCheckerMac.mm:440
> +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPoint], NSTextCheckingInsertionPointKey, nil];

Literals.

> Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1066
> +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];

literals.

> Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1112
> +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];

ditto.

> Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1300
> +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];

ditto. Maybe we should just wrap -checkString and -requestCheckingOfString: to avoid the repetition?
Comment 9 Beth Dakin 2016-03-16 16:06:31 PDT
(In reply to comment #8)
> Comment on attachment 274216 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=274216&action=review
> 
> >> Source/WebCore/ChangeLog:10
> >> +        Pass the Frameâs section to a handful of spelling checking methods that call 
> > 
> > Frame's selection, not Frame's section
> 
> Is there any way to test this? API test perhaps?
> 

Hmmmmmm. I don't think so, but I will give this more thought.

> > Source/WebKit2/UIProcess/TextChecker.h:75
> > +    static Vector<WebCore::TextCheckingResult> checkTextOfParagraph(int64_t spellDocumentTag, StringView text, uint64_t insertionPoint, uint64_t checkingTypes);
> 
> I find it a bit odd that the insertionPoint is a uint64_t. Does WebCore
> handle 64-bit offsets?
> 

I think you're right, and int_32t would be more appropriate here given the underlying WebCore types.

> > Source/WebKit2/UIProcess/mac/TextCheckerMac.mm:301
> > +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPoint], NSTextCheckingInsertionPointKey, nil];
> 
> You should use literals here: @{} etc.
> 

Okay!

> > Source/WebKit2/UIProcess/mac/TextCheckerMac.mm:440
> > +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPoint], NSTextCheckingInsertionPointKey, nil];
> 
> Literals.
> 

Will fix.

> > Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1066
> > +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];
> 
> literals.
> 

Will fix.

> > Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1112
> > +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];
> 
> ditto.
> 

Will fix.

> > Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm:1300
> > +    options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInteger:insertionPointFromCurrentSelection(currentSelection)], NSTextCheckingInsertionPointKey, nil];
> 
> ditto. Maybe we should just wrap -checkString and -requestCheckingOfString:
> to avoid the repetition?

Hmm, I'm not sure I follow. How would this help?
Comment 10 Beth Dakin 2016-03-16 16:11:39 PDT
(In reply to comment #7)
> Comment on attachment 274216 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=274216&action=review
> 
> Since text checker is defined in terms of string views, not the DOM, seems
> the right architecture would be to convert the selection to offsets within
> the string at the call sites, rather than actually passing the
> VisibleSelection object down. Is there a straightforward way to do it that
> way instead?
> 

I chose to pass a VisibleSelection around WebCore, and then convert it to the offset up in WebKit (we end up passing around the offset on its own in WK2 to get it to the UIProcess) because there has been talk of possibly adding some additional keys to this NSSpellChecker dictionary, and that would cover information that could also be extracted from the VisibleSelection. So I chose to do it this way because I thought it would pave the way for some more straightforward patches in the future.

That being said, I do not have a great understanding of any architectural decisions guiding these WebCore classes. So if you think it's a better/cleaner architecture here to stick to the offset, then I would be happy to do that. Do you think that's better even if I add some additional parameters in the future?
Comment 11 Beth Dakin 2016-03-16 16:25:42 PDT
http://trac.webkit.org/changeset/198306 I will follow-up with Darin to see if a follow-up patch is in order.
Comment 12 Darin Adler 2016-03-17 08:51:14 PDT
(In reply to comment #10)
> That being said, I do not have a great understanding of any architectural
> decisions guiding these WebCore classes. So if you think it's a
> better/cleaner architecture here to stick to the offset, then I would be
> happy to do that. Do you think that's better even if I add some additional
> parameters in the future?

This is really a layering question.

Before this change, these functions were an abstract interface to spell checking that was independent of the DOM. After the change, they are hooks for spell checking that are not independent of the DOM.

I don’t have a strong feeling about which design is better, but I don’t like place we have landed with the division of responsibilities where extracting the text to spell check is a job for the caller, but interpreting the selection position is a job for the spell checking functions. I’d prefer that the work of extracting the text to spell check and the other contextual information needed to correctly check from the DOM was either done entirely by the caller or entirely by the spell checking functions.

This is not an urgent issue but nice to resolve in the longer term. We can talk in person about this at some point.
Comment 13 Beth Dakin 2016-03-17 10:50:23 PDT
(In reply to comment #12)
> (In reply to comment #10)
> > That being said, I do not have a great understanding of any architectural
> > decisions guiding these WebCore classes. So if you think it's a
> > better/cleaner architecture here to stick to the offset, then I would be
> > happy to do that. Do you think that's better even if I add some additional
> > parameters in the future?
> 
> This is really a layering question.
> 
> Before this change, these functions were an abstract interface to spell
> checking that was independent of the DOM. After the change, they are hooks
> for spell checking that are not independent of the DOM.
> 
> I don’t have a strong feeling about which design is better, but I don’t like
> place we have landed with the division of responsibilities where extracting
> the text to spell check is a job for the caller, but interpreting the
> selection position is a job for the spell checking functions. I’d prefer
> that the work of extracting the text to spell check and the other contextual
> information needed to correctly check from the DOM was either done entirely
> by the caller or entirely by the spell checking functions.
> 
> This is not an urgent issue but nice to resolve in the longer term. We can
> talk in person about this at some point.

Sounds good! I'm happy to get this in a better place. Thanks for your input!
Comment 14 Beth Dakin 2016-03-25 16:50:15 PDT
(In reply to comment #13)
> (In reply to comment #12)
> > (In reply to comment #10)
> > > That being said, I do not have a great understanding of any architectural
> > > decisions guiding these WebCore classes. So if you think it's a
> > > better/cleaner architecture here to stick to the offset, then I would be
> > > happy to do that. Do you think that's better even if I add some additional
> > > parameters in the future?
> > 
> > This is really a layering question.
> > 
> > Before this change, these functions were an abstract interface to spell
> > checking that was independent of the DOM. After the change, they are hooks
> > for spell checking that are not independent of the DOM.
> > 
> > I don’t have a strong feeling about which design is better, but I don’t like
> > place we have landed with the division of responsibilities where extracting
> > the text to spell check is a job for the caller, but interpreting the
> > selection position is a job for the spell checking functions. I’d prefer
> > that the work of extracting the text to spell check and the other contextual
> > information needed to correctly check from the DOM was either done entirely
> > by the caller or entirely by the spell checking functions.
> > 
> > This is not an urgent issue but nice to resolve in the longer term. We can
> > talk in person about this at some point.
> 
> Sounds good! I'm happy to get this in a better place. Thanks for your input!

I posted a patch to address this: https://bugs.webkit.org/show_bug.cgi?id=155908