Bug 67230 - [mac] Add text search API for getting the DOM range of a text match
Summary: [mac] Add text search API for getting the DOM range of a text match
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac Unspecified
: P2 Normal
Assignee: mitz
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2011-08-30 14:27 PDT by mitz
Modified: 2011-08-30 16:36 PDT (History)
2 users (show)

See Also:


Attachments
Add -[WebView DOMRangeOfString:relativeTo:options:] (25.86 KB, patch)
2011-08-30 14:40 PDT, mitz
no flags Details | Formatted Diff | Diff
Add -[WebView DOMRangeOfString:relativeTo:options:] (28.03 KB, patch)
2011-08-30 16:27 PDT, mitz
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description mitz 2011-08-30 14:27:10 PDT
Add text search API for getting the DOM range of a text match
Comment 1 mitz 2011-08-30 14:27:46 PDT
<rdar://problem/9281695>
Comment 2 mitz 2011-08-30 14:40:31 PDT
Created attachment 105701 [details]
Add -[WebView DOMRangeOfString:relativeTo:options:]
Comment 3 WebKit Review Bot 2011-08-30 14:43:39 PDT
Attachment 105701 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1

Source/WebKit/mac/WebView/WebViewInternal.h:60:  The parameter name "options" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 14 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Darin Adler 2011-08-30 14:53:15 PDT
Comment on attachment 105701 [details]
Add -[WebView DOMRangeOfString:relativeTo:options:]

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

> Source/WebCore/editing/Editor.cpp:2928
> +PassRefPtr<Range> Editor::findString(const String& target, Range* referenceRange, FindOptions options)

I think it’s confusing that both functions are named findString, but one modifies the selection and the other does not. I would prefer that the two functions have different names rather than be differentiated only by overloading.

> Source/WebCore/editing/Editor.cpp:2945
> +            searchRange->setStart(startInReferenceRange ? referenceRange->startPosition() : referenceRange->endPosition(), ec);

You can just call setStart without passing (ec) now. It will assert if the range is detached. It’s the new hotness!

> Source/WebCore/editing/Editor.cpp:2947
> +            searchRange->setEnd(startInReferenceRange ? referenceRange->endPosition() : referenceRange->startPosition(), ec);

You can just call setEnd without passing (ec) now. It will assert if the range is detached. It’s the new hotness!

> Source/WebCore/editing/Editor.cpp:2965
> +            searchRange->setStart(referenceRange->endPosition(), ec);

Ditto.

> Source/WebCore/editing/Editor.cpp:2967
> +            searchRange->setEnd(referenceRange->startPosition(), ec);

Ditto.

> Source/WebCore/editing/Editor.cpp:2980
> +    if (resultRange->collapsed(ec) && shadowTreeRoot) {

You can just call collapsed without passing (ec) now. It will assert if the range is detached. It’s the new hotness!

> Source/WebCore/editing/Editor.cpp:2985
> -            searchRange->setStartAfter(shadowTreeRoot->shadowAncestorNode(), exception);
> +            searchRange->setStartAfter(shadowTreeRoot->shadowAncestorNode(), ec);
>          else
> -            searchRange->setEndBefore(shadowTreeRoot->shadowAncestorNode(), exception);
> +            searchRange->setEndBefore(shadowTreeRoot->shadowAncestorNode(), ec);

If you wanted you could implement the ASSERT_NO_EXCEPTION thing for setStartAfter and setEndBefore too. While it would require modifying Range.h it would be forward looking and cool.

> Source/WebCore/editing/Editor.cpp:2998
> +    if (resultRange->collapsed(ec) && options & WrapAround) {

Ditto.

> Source/WebCore/editing/Editor.cpp:3006
> +    return resultRange->collapsed(ec) ? 0 : resultRange.release();

Same here.

> Source/WebCore/page/Page.cpp:521
> +    // We cheat a bit and just research with wrap on

Probably need to spell it re-search so it’s not confused with the word research.

Sentence needs a period.
Comment 5 mitz 2011-08-30 15:04:22 PDT
Comment on attachment 105701 [details]
Add -[WebView DOMRangeOfString:relativeTo:options:]

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

Thanks for the review! I am going to switch to the ExceptionCode-less variants and if there are no complications even add new ones.

>> Source/WebCore/editing/Editor.cpp:2928
>> +PassRefPtr<Range> Editor::findString(const String& target, Range* referenceRange, FindOptions options)
> 
> I think it’s confusing that both functions are named findString, but one modifies the selection and the other does not. I would prefer that the two functions have different names rather than be differentiated only by overloading.

I’m going to use a different name here and in the Page class.
Comment 6 mitz 2011-08-30 16:27:11 PDT
Created attachment 105718 [details]
Add -[WebView DOMRangeOfString:relativeTo:options:]
Comment 7 Darin Adler 2011-08-30 16:29:37 PDT
Comment on attachment 105718 [details]
Add -[WebView DOMRangeOfString:relativeTo:options:]

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

> Source/WebCore/dom/Range.h:107
> -    void setStart(const Position&, ExceptionCode&);
> -    void setEnd(const Position&, ExceptionCode&);
> +    void setStart(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION);
> +    void setEnd(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION);

I think that these should not even take ExceptionCode& since they are internal functions, not DOM API. ExceptionCode& is ugly for internal use, except where it's intended to be used for helper functions that in turn are used implement DOM API functions. ASSERT_NO_EXCEPTION is OK for now, but later we should just get rid of that.
Comment 8 WebKit Review Bot 2011-08-30 16:30:40 PDT
Attachment 105718 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1

Source/WebKit/mac/WebView/WebViewInternal.h:60:  The parameter name "options" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 15 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 mitz 2011-08-30 16:36:09 PDT
Added in <http://trac.webkit.org/r94124>.