Changeset 73337 in webkit


Ignore:
Timestamp:
Dec 4, 2010 7:21:16 PM (13 years ago)
Author:
mitz@apple.com
Message:

2010-12-04 Dan Bernstein <mitz@apple.com>

Reviewed by Sam Weinig.

WebKit part of <rdar://problem/8145955> Add text search API for counting/marking/highlighting matches in a range
https://bugs.webkit.org/show_bug.cgi?id=50530

  • WebView/WebDocumentInternal.h: Added a DOMRange parameter to -countMatchesForText:options:limit:markMatches:
  • WebView/WebHTMLView.mm: (-[WebHTMLView countMatchesForText:inDOMRange:options:limit:markMatches:]): Added DOMRange parameter, which is passed through to WebCore.
  • WebView/WebPDFView.mm: (isFrameInRange): Added this helper function. (-[WebPDFView countMatchesForText:inDOMRange:options:limit:markMatches:]): Added DOMRange parameter and a check if the frame is in the range.
  • WebView/WebView.mm: (-[WebView countMatchesForText:options:highlight:limit:markMatches:]): Now calls the inDOMRange: version. (-[WebView countMatchesForText:inDOMRange:options:highlight:limit:markMatches:]): Added DOMRange parameter, which is passed to document views' -countMatchesForText:inDOMRange:options:limit:markMatches:.
  • WebView/WebViewPrivate.h:

2010-12-04 Dan Bernstein <mitz@apple.com>

Reviewed by Sam Weinig.

WebCore part of <rdar://problem/8145955> Add text search API for counting/marking/highlighting matches in a range
https://bugs.webkit.org/show_bug.cgi?id=50530

  • WebCore.exp.in: Export Range version of countMatchesForText().
  • editing/Editor.cpp: (WebCore::isFrameInRange): Added this helper method. (WebCore::Editor::countMatchesForText): Added a Range parameter and restricted the result to matches that occur in the range.
  • editing/Editor.h:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73335 r73337  
     12010-12-04  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        WebCore part of <rdar://problem/8145955> Add text search API for counting/marking/highlighting matches in a range
     6        https://bugs.webkit.org/show_bug.cgi?id=50530
     7
     8        * WebCore.exp.in: Export Range version of countMatchesForText().
     9        * editing/Editor.cpp:
     10        (WebCore::isFrameInRange): Added this helper method.
     11        (WebCore::Editor::countMatchesForText): Added a Range parameter and restricted the result to
     12        matches that occur in the range.
     13        * editing/Editor.h:
     14
    1152010-12-04  Gavin Peters  <gavinp@chromium.org>
    216
  • trunk/WebCore/WebCore.exp.in

    r73281 r73337  
    677677__ZN7WebCore6Editor18confirmCompositionERKN3WTF6StringE
    678678__ZN7WebCore6Editor18confirmCompositionEv
    679 __ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEjjb
     679__ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEPNS_5RangeEjjb
    680680__ZN7WebCore6Editor19deleteWithDirectionENS_19SelectionController10EDirectionENS_15TextGranularityEbb
    681681__ZN7WebCore6Editor19insertUnorderedListEv
  • trunk/WebCore/editing/Editor.cpp

    r73287 r73337  
    5252#include "FrameTree.h"
    5353#include "FrameView.h"
     54#include "HTMLFrameOwnerElement.h"
    5455#include "HTMLInputElement.h"
    5556#include "HTMLTextAreaElement.h"
     
    33503351}
    33513352
     3353static bool isFrameInRange(Frame* frame, Range* range)
     3354{
     3355    bool inRange = false;
     3356    for (HTMLFrameOwnerElement* ownerElement = frame->ownerElement(); ownerElement; ownerElement = ownerElement->document()->ownerElement()) {
     3357        if (ownerElement->document() == range->ownerDocument()) {
     3358            ExceptionCode ec = 0;
     3359            inRange = range->intersectsNode(ownerElement, ec);
     3360            break;
     3361        }
     3362    }
     3363    return inRange;
     3364}
     3365
    33523366unsigned Editor::countMatchesForText(const String& target, FindOptions options, unsigned limit, bool markMatches)
     3367{
     3368    return countMatchesForText(target, 0, options, limit, markMatches);
     3369}
     3370
     3371unsigned Editor::countMatchesForText(const String& target, Range* range, FindOptions options, unsigned limit, bool markMatches)
    33533372{
    33543373    if (target.isEmpty())
    33553374        return 0;
    33563375
    3357     RefPtr<Range> searchRange(rangeOfContents(m_frame->document()));
     3376    RefPtr<Range> originalSearchRange;
     3377    if (range) {
     3378        if (range->ownerDocument() == m_frame->document())
     3379            originalSearchRange = range;
     3380        else if (!isFrameInRange(m_frame, range))
     3381            return 0;
     3382    }
     3383    if (!originalSearchRange)
     3384        originalSearchRange = rangeOfContents(m_frame->document());
     3385
     3386    RefPtr<Range> searchRange(originalSearchRange);
    33583387
    33593388    ExceptionCode exception = 0;
     
    33653394                break;
    33663395
    3367             searchRange = rangeOfContents(m_frame->document());
     3396            searchRange = originalSearchRange;
    33683397            searchRange->setStartAfter(resultRange->startContainer()->shadowAncestorNode(), exception);
    33693398            continue;
  • trunk/WebCore/editing/Editor.h

    r73287 r73337  
    349349
    350350    unsigned countMatchesForText(const String&, FindOptions, unsigned limit, bool markMatches);
     351    unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches);
    351352    bool markedTextMatchesAreHighlighted() const;
    352353    void setMarkedTextMatchesAreHighlighted(bool);
  • trunk/WebKit/mac/ChangeLog

    r73312 r73337  
     12010-12-04  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        WebKit part of <rdar://problem/8145955> Add text search API for counting/marking/highlighting matches in a range
     6        https://bugs.webkit.org/show_bug.cgi?id=50530
     7
     8        * WebView/WebDocumentInternal.h: Added a DOMRange parameter to -countMatchesForText:options:limit:markMatches:
     9        * WebView/WebHTMLView.mm:
     10        (-[WebHTMLView countMatchesForText:inDOMRange:options:limit:markMatches:]): Added DOMRange parameter,
     11        which is passed through to WebCore.
     12        * WebView/WebPDFView.mm:
     13        (isFrameInRange): Added this helper function.
     14        (-[WebPDFView countMatchesForText:inDOMRange:options:limit:markMatches:]): Added DOMRange parameter and
     15        a check if the frame is in the range.
     16        * WebView/WebView.mm:
     17        (-[WebView countMatchesForText:options:highlight:limit:markMatches:]): Now calls the inDOMRange: version.
     18        (-[WebView countMatchesForText:inDOMRange:options:highlight:limit:markMatches:]): Added DOMRange
     19        parameter, which is passed to document views' -countMatchesForText:inDOMRange:options:limit:markMatches:.
     20        * WebView/WebViewPrivate.h:
     21
    1222010-12-03  Sam Weinig  <sam@webkit.org>
    223
  • trunk/WebKit/mac/WebView/WebDocumentInternal.h

    r72887 r73337  
    6363- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue;
    6464- (BOOL)markedTextMatchesAreHighlighted;
    65 - (WebNSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
     65- (WebNSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
    6666- (void)unmarkAllTextMatches;
    6767- (NSArray *)rectsForTextMatches;
  • trunk/WebKit/mac/WebView/WebHTMLView.mm

    r72887 r73337  
    62296229}
    62306230
    6231 - (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
     6231- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
    62326232{
    62336233    Frame* coreFrame = core([self _frame]);
    62346234    if (!coreFrame)
    62356235        return 0;
    6236     return coreFrame->editor()->countMatchesForText(string, coreOptions(options), limit, markMatches);
     6236
     6237    return coreFrame->editor()->countMatchesForText(string, core(range), coreOptions(options), limit, markMatches);
    62376238}
    62386239
  • trunk/WebKit/mac/WebView/WebPDFView.mm

    r72887 r73337  
    2929#import "WebPDFView.h"
    3030
     31#import "DOMNodeInternal.h"
     32#import "DOMRangeInternal.h"
    3133#import "WebDataSourceInternal.h"
    3234#import "WebDelegateImplementationCaching.h"
     
    5456#import <WebCore/FrameLoader.h>
    5557#import <WebCore/HTMLFormElement.h>
     58#import <WebCore/HTMLFrameOwnerElement.h>
    5659#import <WebCore/KURL.h>
    5760#import <WebCore/KeyboardEvent.h>
     
    627630}
    628631
    629 - (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
    630 {
     632static BOOL isFrameInRange(WebFrame *frame, DOMRange *range)
     633{
     634    BOOL inRange = NO;
     635    for (HTMLFrameOwnerElement* ownerElement = core(frame)->ownerElement(); ownerElement; ownerElement = ownerElement->document()->frame()->ownerElement()) {
     636        if (ownerElement->document() == core(range)->ownerDocument()) {
     637            inRange = [range intersectsNode:kit(ownerElement)];
     638            break;
     639        }
     640    }
     641    return inRange;
     642}
     643
     644- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
     645{
     646    if (range && !isFrameInRange([dataSource webFrame], range))
     647        return 0;
     648
    631649    PDFSelection *previousMatch = nil;
    632650    NSMutableArray *matches = [[NSMutableArray alloc] initWithCapacity:limit];
  • trunk/WebKit/mac/WebView/WebView.mm

    r72887 r73337  
    45194519- (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options highlight:(BOOL)highlight limit:(NSUInteger)limit markMatches:(BOOL)markMatches
    45204520{
     4521    return [self countMatchesForText:string inDOMRange:nil options:options highlight:highlight limit:limit markMatches:markMatches];
     4522}
     4523
     4524- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options highlight:(BOOL)highlight limit:(NSUInteger)limit markMatches:(BOOL)markMatches
     4525{
    45214526    if (_private->closed)
    45224527        return 0;
     
    45314536       
    45324537            ASSERT(limit == 0 || matchCount < limit);
    4533             matchCount += [(NSView <WebMultipleTextMatches>*)view countMatchesForText:string options:options limit:(limit == 0 ? 0 : limit - matchCount) markMatches:markMatches];
     4538            matchCount += [(NSView <WebMultipleTextMatches>*)view countMatchesForText:string inDOMRange:range options:options limit:(limit == 0 ? 0 : limit - matchCount) markMatches:markMatches];
    45344539
    45354540            // Stop looking if we've reached the limit. A limit of 0 means no limit.
  • trunk/WebKit/mac/WebView/WebViewPrivate.h

    r72887 r73337  
    183183- (BOOL)canMarkAllTextMatches;
    184184- (WebNSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options highlight:(BOOL)highlight limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
     185- (WebNSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options highlight:(BOOL)highlight limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
    185186- (void)unmarkAllTextMatches;
    186187- (NSArray *)rectsForTextMatches;
Note: See TracChangeset for help on using the changeset viewer.