Commit 1506e874 authored by mitz@apple.com's avatar mitz@apple.com

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:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73337 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a347556a
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:
2010-12-04 Gavin Peters <gavinp@chromium.org>
Reviewed by Adam Barth.
......@@ -676,7 +676,7 @@ __ZN7WebCore6Editor16pasteAsPlainTextEv
__ZN7WebCore6Editor17insertOrderedListEv
__ZN7WebCore6Editor18confirmCompositionERKN3WTF6StringE
__ZN7WebCore6Editor18confirmCompositionEv
__ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEjjb
__ZN7WebCore6Editor19countMatchesForTextERKN3WTF6StringEPNS_5RangeEjjb
__ZN7WebCore6Editor19deleteWithDirectionENS_19SelectionController10EDirectionENS_15TextGranularityEbb
__ZN7WebCore6Editor19insertUnorderedListEv
__ZN7WebCore6Editor21applyStyleToSelectionEPNS_19CSSStyleDeclarationENS_10EditActionE
......
......@@ -51,6 +51,7 @@
#include "Frame.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLInputElement.h"
#include "HTMLTextAreaElement.h"
#include "HitTestResult.h"
......@@ -3349,12 +3350,40 @@ bool Editor::findString(const String& target, FindOptions options)
return true;
}
static bool isFrameInRange(Frame* frame, Range* range)
{
bool inRange = false;
for (HTMLFrameOwnerElement* ownerElement = frame->ownerElement(); ownerElement; ownerElement = ownerElement->document()->ownerElement()) {
if (ownerElement->document() == range->ownerDocument()) {
ExceptionCode ec = 0;
inRange = range->intersectsNode(ownerElement, ec);
break;
}
}
return inRange;
}
unsigned Editor::countMatchesForText(const String& target, FindOptions options, unsigned limit, bool markMatches)
{
return countMatchesForText(target, 0, options, limit, markMatches);
}
unsigned Editor::countMatchesForText(const String& target, Range* range, FindOptions options, unsigned limit, bool markMatches)
{
if (target.isEmpty())
return 0;
RefPtr<Range> searchRange(rangeOfContents(m_frame->document()));
RefPtr<Range> originalSearchRange;
if (range) {
if (range->ownerDocument() == m_frame->document())
originalSearchRange = range;
else if (!isFrameInRange(m_frame, range))
return 0;
}
if (!originalSearchRange)
originalSearchRange = rangeOfContents(m_frame->document());
RefPtr<Range> searchRange(originalSearchRange);
ExceptionCode exception = 0;
unsigned matchCount = 0;
......@@ -3364,7 +3393,7 @@ unsigned Editor::countMatchesForText(const String& target, FindOptions options,
if (!resultRange->startContainer()->isInShadowTree())
break;
searchRange = rangeOfContents(m_frame->document());
searchRange = originalSearchRange;
searchRange->setStartAfter(resultRange->startContainer()->shadowAncestorNode(), exception);
continue;
}
......
......@@ -348,6 +348,7 @@ public:
RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
unsigned countMatchesForText(const String&, FindOptions, unsigned limit, bool markMatches);
unsigned countMatchesForText(const String&, Range*, FindOptions, unsigned limit, bool markMatches);
bool markedTextMatchesAreHighlighted() const;
void setMarkedTextMatchesAreHighlighted(bool);
......
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-03 Sam Weinig <sam@webkit.org>
Reviewed by Maciej Stachowiak.
......
......@@ -62,7 +62,7 @@
@protocol WebMultipleTextMatches <NSObject>
- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue;
- (BOOL)markedTextMatchesAreHighlighted;
- (WebNSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
- (WebNSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
- (void)unmarkAllTextMatches;
- (NSArray *)rectsForTextMatches;
@end
......
......@@ -6228,12 +6228,13 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
return [[[WebElementDictionary alloc] initWithHitTestResult:coreFrame->eventHandler()->hitTestResultAtPoint(IntPoint(point), allow)] autorelease];
}
- (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
{
Frame* coreFrame = core([self _frame]);
if (!coreFrame)
return 0;
return coreFrame->editor()->countMatchesForText(string, coreOptions(options), limit, markMatches);
return coreFrame->editor()->countMatchesForText(string, core(range), coreOptions(options), limit, markMatches);
}
- (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue
......
......@@ -28,6 +28,8 @@
#import "WebPDFView.h"
#import "DOMNodeInternal.h"
#import "DOMRangeInternal.h"
#import "WebDataSourceInternal.h"
#import "WebDelegateImplementationCaching.h"
#import "WebDocumentInternal.h"
......@@ -53,6 +55,7 @@
#import <WebCore/FrameLoadRequest.h>
#import <WebCore/FrameLoader.h>
#import <WebCore/HTMLFormElement.h>
#import <WebCore/HTMLFrameOwnerElement.h>
#import <WebCore/KURL.h>
#import <WebCore/KeyboardEvent.h>
#import <WebCore/MouseEvent.h>
......@@ -626,8 +629,23 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
return NO;
}
- (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
static BOOL isFrameInRange(WebFrame *frame, DOMRange *range)
{
BOOL inRange = NO;
for (HTMLFrameOwnerElement* ownerElement = core(frame)->ownerElement(); ownerElement; ownerElement = ownerElement->document()->frame()->ownerElement()) {
if (ownerElement->document() == core(range)->ownerDocument()) {
inRange = [range intersectsNode:kit(ownerElement)];
break;
}
}
return inRange;
}
- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options limit:(NSUInteger)limit markMatches:(BOOL)markMatches
{
if (range && !isFrameInRange([dataSource webFrame], range))
return 0;
PDFSelection *previousMatch = nil;
NSMutableArray *matches = [[NSMutableArray alloc] initWithCapacity:limit];
......
......@@ -4517,6 +4517,11 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue jsValu
}
- (NSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options highlight:(BOOL)highlight limit:(NSUInteger)limit markMatches:(BOOL)markMatches
{
return [self countMatchesForText:string inDOMRange:nil options:options highlight:highlight limit:limit markMatches:markMatches];
}
- (NSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options highlight:(BOOL)highlight limit:(NSUInteger)limit markMatches:(BOOL)markMatches
{
if (_private->closed)
return 0;
......@@ -4530,7 +4535,7 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue jsValu
[(NSView <WebMultipleTextMatches>*)view setMarkedTextMatchesAreHighlighted:highlight];
ASSERT(limit == 0 || matchCount < limit);
matchCount += [(NSView <WebMultipleTextMatches>*)view countMatchesForText:string options:options limit:(limit == 0 ? 0 : limit - matchCount) markMatches:markMatches];
matchCount += [(NSView <WebMultipleTextMatches>*)view countMatchesForText:string inDOMRange:range options:options limit:(limit == 0 ? 0 : limit - matchCount) markMatches:markMatches];
// Stop looking if we've reached the limit. A limit of 0 means no limit.
if (limit > 0 && matchCount >= limit)
......
......@@ -182,6 +182,7 @@ typedef NSUInteger WebFindOptions;
// These methods are still in flux; don't rely on them yet.
- (BOOL)canMarkAllTextMatches;
- (WebNSUInteger)countMatchesForText:(NSString *)string options:(WebFindOptions)options highlight:(BOOL)highlight limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
- (WebNSUInteger)countMatchesForText:(NSString *)string inDOMRange:(DOMRange *)range options:(WebFindOptions)options highlight:(BOOL)highlight limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
- (void)unmarkAllTextMatches;
- (NSArray *)rectsForTextMatches;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment