Bug 143065

Summary: Implement iOS WebKit2 PDF Find-in-Page
Product: WebKit Reporter: Tim Horton <thorton>
Component: New BugsAssignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, commit-queue, mitz, sam, simon.fraser
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch none

Description Tim Horton 2015-03-25 16:46:01 PDT
Implement iOS WebKit2 PDF Find-in-Page
Comment 1 Tim Horton 2015-03-25 16:47:05 PDT
Created attachment 249444 [details]
Patch
Comment 2 WebKit Commit Bot 2015-03-25 16:49:24 PDT
Attachment 249444 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:478:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:526:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/API/Cocoa/_WKFindOptions.h:30:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 3 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Tim Horton 2015-03-26 17:45:10 PDT
Created attachment 249546 [details]
Patch
Comment 4 WebKit Commit Bot 2015-03-26 17:47:56 PDT
Attachment 249546 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:478:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:526:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/API/Cocoa/_WKFindOptions.h:30:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 3 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 mitz 2015-03-26 21:48:53 PDT
Comment on attachment 249546 [details]
Patch

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

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:402
> +- (NSStringCompareOptions)_stringCompareOptionsFromWKFindOptions:(_WKFindOptions)options
> +{
> +    NSStringCompareOptions findOptions = 0;
> +    if (options & _WKFindOptionsCaseInsensitive)
> +        findOptions |= NSCaseInsensitiveSearch;
> +    if (options & _WKFindOptionsBackwards)
> +        findOptions |= NSBackwardsSearch;
> +    return findOptions;
> +}

Seem like this can be a static function.

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:404
> +- (void)_computeMatchesForString:(NSString *)string options:(_WKFindOptions)options maxCount:(NSUInteger)maxCount completionHandler:(void (^)(bool success))completionHandler

Not BOOL?

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:411
> +    _WKFindOptions optionsAffectingResults = options & ~(_WKFindOptionsBackwards | _WKFindOptionsShowOverlay | _WKFindOptionsShowFindIndicator | _WKFindOptionsShowHighlight | _WKFindOptionsWrapAround | _WKFindOptionsDetermineMatchIndex);

Maybe this should be defined in _WKFindOptions.h so that when new options are added the person adding them can remember to update this value if needed.

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:432
> +    unsigned computeMatchesOperationID = _nextComputeMatchesOperationID++;

I’d ++_nextComputedMatchesOperationID here…(*)

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:437
> +    dispatch_async(_findQueue, ^{

I think we prefer lambdas with explicit captures to blocks in C++ code.

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:440
> +        for (unsigned pageIndex = 0; pageIndex < pages.size(); pageIndex++) {

post++!

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:448
> +                if (_nextComputeMatchesOperationID > computeMatchesOperationID + 1) {

* …and do a simple != here.

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:460
> +            if (_nextComputeMatchesOperationID > computeMatchesOperationID + 1)

and here.

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:496
> +            CGRect zoomRect = [pageInfo.view convertRectFromPDFPageSpace:[match bounds]];

.bounds

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:517
> +            NSUInteger location = [_currentFindSelection startIndex];

Can this be zero?

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:518
> +            previousFindSelection = adoptNS([[UIPDFSelection alloc] initWithPage:[_currentFindSelection page] fromIndex:location - 1 toIndex:location]);

What if location is zero?

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:531
> +        for (unsigned i = 0; i < _pages.size(); i++) {

post++ again?

> Source/WebKit2/UIProcess/ios/WKPDFView.mm:532
> +            UIPDFSelection *match = [_pages[pageIndex].page findString:string fromSelection:(pageIndex == previousFindPageIndex ? previousFindSelection.get() : nullptr) options:findOptions];

nil
Comment 6 Tim Horton 2015-03-27 12:26:25 PDT
(In reply to comment #5)
> Comment on attachment 249546 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=249546&action=review
> > Source/WebKit2/UIProcess/ios/WKPDFView.mm:411
> > +    _WKFindOptions optionsAffectingResults = options & ~(_WKFindOptionsBackwards | _WKFindOptionsShowOverlay | _WKFindOptionsShowFindIndicator | _WKFindOptionsShowHighlight | _WKFindOptionsWrapAround | _WKFindOptionsDetermineMatchIndex);
> 
> Maybe this should be defined in _WKFindOptions.h so that when new options
> are added the person adding them can remember to update this value if needed.

I'm not sure, because whether "Backwards" affects results or not depends on what you're doing. I do agree that it would be unfortunate if new options were added and not added to this list, though. Maybe _WKFindOptions.h can have the list except Backwards and we can add Backwards in?
Comment 7 Tim Horton 2015-03-27 14:47:54 PDT
Created attachment 249609 [details]
Patch
Comment 8 WebKit Commit Bot 2015-03-27 14:50:39 PDT
Attachment 249609 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:487:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/ios/WKPDFView.mm:536:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
ERROR: Source/WebKit2/UIProcess/API/Cocoa/_WKFindOptions.h:30:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 3 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Tim Horton 2015-03-27 15:04:34 PDT
Created attachment 249611 [details]
Patch
Comment 10 Tim Horton 2015-03-27 15:05:56 PDT
http://trac.webkit.org/changeset/182085