Add ability to count text matches without marking
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Aug 2010 22:10:10 +0000 (22:10 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Aug 2010 22:10:10 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=43996

Reviewed by Darin Adler.

WebCore:

Safari needs to be able to count text matches without triggering lots of repainting.
Rename markAllMatchesForText() to countMatchesForText() and add a markMatches parameter.

* WebCore.exp.in:
* page/Frame.cpp:
(WebCore::Frame::countMatchesForText):
* page/Frame.h:
* page/Page.cpp:
(WebCore::Page::markAllMatchesForText):

WebKit/efl:

* ewk/ewk_frame.cpp:
(ewk_frame_text_matches_mark): Switched to call
countMatchesForText() instead of markAllMatchesForText().

WebKit/mac:

Safari needs to be able to count text matches without triggering lots of repainting.
Rename markAllMatchesForText: to countMatchesForText: and add a markMatches:
parameter.  For backwards compatibility markAllMatchesForText: calls
countMatchesForText: and passes YES for markMatches:.

* WebView/WebDocumentInternal.h:
* WebView/WebHTMLView.mm:
(-[WebHTMLView markAllMatchesForText:caseSensitive:limit:]):
(-[WebHTMLView countMatchesForText:caseSensitive:limit:markMatches:]):
* WebView/WebPDFView.mm:
(-[WebPDFView markAllMatchesForText:caseSensitive:limit:]):
(-[WebPDFView countMatchesForText:caseSensitive:limit:markMatches:]):
* WebView/WebView.mm:
(-[WebView markAllMatchesForText:caseSensitive:highlight:limit:]):
(-[WebView countMatchesForText:caseSensitive:highlight:limit:markMatches:]):
* WebView/WebViewPrivate.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@66544 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp.in
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebCore/page/Page.cpp
WebKit/efl/ChangeLog
WebKit/efl/ewk/ewk_frame.cpp
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebDocumentInternal.h
WebKit/mac/WebView/WebHTMLView.mm
WebKit/mac/WebView/WebPDFView.mm
WebKit/mac/WebView/WebView.mm
WebKit/mac/WebView/WebViewPrivate.h

index 78770d9..0f0c623 100644 (file)
@@ -1,3 +1,20 @@
+2010-08-31  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Add ability to count text matches without marking
+        https://bugs.webkit.org/show_bug.cgi?id=43996
+
+        Safari needs to be able to count text matches without triggering lots of repainting.
+        Rename markAllMatchesForText() to countMatchesForText() and add a markMatches parameter.
+
+        * WebCore.exp.in:
+        * page/Frame.cpp:
+        (WebCore::Frame::countMatchesForText):
+        * page/Frame.h:
+        * page/Page.cpp:
+        (WebCore::Page::markAllMatchesForText):
+
 2010-08-31  Eric Carlson  <eric.carlson@apple.com>
 
         Reviewed by Darin Adler.
index ff14785..8d3ca91 100644 (file)
@@ -581,8 +581,8 @@ __ZN7WebCore5Frame10findStringERKN3WTF6StringEbbbb
 __ZN7WebCore5Frame13reapplyStylesEv
 __ZN7WebCore5Frame14frameForWidgetEPKNS_6WidgetE
 __ZN7WebCore5Frame15revealSelectionERKNS_15ScrollAlignmentEb
+__ZN7WebCore5Frame19countMatchesForTextERKN3WTF6StringEbjb
 __ZN7WebCore5Frame20setSelectionFromNoneEv
-__ZN7WebCore5Frame21markAllMatchesForTextERKN3WTF6StringEbj
 __ZN7WebCore5Frame23visiblePositionForPointERKNS_8IntPointE
 __ZN7WebCore5Frame24computeAndSetTypingStyleEPNS_19CSSStyleDeclarationENS_10EditActionE
 __ZN7WebCore5Frame25matchLabelsAgainstElementEP7NSArrayPNS_7ElementE
index 614d85a..3f2a5f5 100644 (file)
@@ -1240,7 +1240,7 @@ bool Frame::findString(const String& target, bool forward, bool caseFlag, bool w
     return true;
 }
 
-unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsigned limit)
+unsigned Frame::countMatchesForText(const String& target, bool caseFlag, unsigned limit, bool markMatches)
 {
     if (target.isEmpty())
         return 0;
@@ -1263,7 +1263,8 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
         // Only treat the result as a match if it is visible
         if (editor()->insideVisibleArea(resultRange.get())) {
             ++matchCount;
-            document()->markers()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
+            if (markMatches)
+                document()->markers()->addMarker(resultRange.get(), DocumentMarker::TextMatch);
         }
 
         // Stop looking if we hit the specified limit. A limit of 0 means no limit.
@@ -1281,16 +1282,16 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
             searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->childNodeCount(), exception);
     } while (true);
 
-    // Do a "fake" paint in order to execute the code that computes the rendered rect for
-    // each text match.
-    Document* doc = document();
-    if (m_view && contentRenderer()) {
-        doc->updateLayout(); // Ensure layout is up to date.
-        IntRect visibleRect = m_view->visibleContentRect();
-        if (!visibleRect.isEmpty()) {
-            GraphicsContext context((PlatformGraphicsContext*)0);
-            context.setPaintingDisabled(true);
-            m_view->paintContents(&context, visibleRect);
+    if (markMatches) {
+        // Do a "fake" paint in order to execute the code that computes the rendered rect for each text match.
+        if (m_view && contentRenderer()) {
+            document()->updateLayout(); // Ensure layout is up to date.
+            IntRect visibleRect = m_view->visibleContentRect();
+            if (!visibleRect.isEmpty()) {
+                GraphicsContext context((PlatformGraphicsContext*)0);
+                context.setPaintingDisabled(true);
+                m_view->paintContents(&context, visibleRect);
+            }
         }
     }
 
index 58520a6..198e2e7 100644 (file)
@@ -207,7 +207,7 @@ namespace WebCore {
 
         RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
 
-        unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
+        unsigned countMatchesForText(const String&, bool caseFlag, unsigned limit, bool markMatches);
         bool markedTextMatchesAreHighlighted() const;
         void setMarkedTextMatchesAreHighlighted(bool flag);
 
index f692cb9..bb6fa50 100644 (file)
@@ -526,7 +526,7 @@ unsigned int Page::markAllMatchesForText(const String& target, TextCaseSensitivi
     Frame* frame = mainFrame();
     do {
         frame->setMarkedTextMatchesAreHighlighted(shouldHighlight);
-        matches += frame->markAllMatchesForText(target, caseSensitivity == TextCaseSensitive, (limit == 0) ? 0 : (limit - matches));
+        matches += frame->countMatchesForText(target, caseSensitivity == TextCaseSensitive, (limit == 0) ? 0 : (limit - matches), true);
         frame = incrementFrame(frame, true, false);
     } while (frame);
 
index 3f9bb54..538d464 100644 (file)
@@ -1,3 +1,14 @@
+2010-08-31  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Add ability to count text matches without marking
+        https://bugs.webkit.org/show_bug.cgi?id=43996
+
+        * ewk/ewk_frame.cpp:
+        (ewk_frame_text_matches_mark): Switched to call
+        countMatchesForText() instead of markAllMatchesForText().
+
 2010-08-31  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Unreviewed build fix.
index d37d7ba..a7ce1ff 100644 (file)
@@ -772,7 +772,7 @@ unsigned int ewk_frame_text_matches_mark(Evas_Object* o, const char* string, Ein
     EINA_SAFETY_ON_NULL_RETURN_VAL(string, 0);
 
     sd->frame->setMarkedTextMatchesAreHighlighted(highlight);
-    return sd->frame->markAllMatchesForText(WTF::String::fromUTF8(string), case_sensitive, limit);
+    return sd->frame->countMatchesForText(WTF::String::fromUTF8(string), case_sensitive, limit, true);
 }
 
 /**
index e0f007d..1bfdb6d 100644 (file)
@@ -1,3 +1,27 @@
+2010-08-31  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Add ability to count text matches without marking
+        https://bugs.webkit.org/show_bug.cgi?id=43996
+
+        Safari needs to be able to count text matches without triggering lots of repainting.
+        Rename markAllMatchesForText: to countMatchesForText: and add a markMatches:
+        parameter.  For backwards compatibility markAllMatchesForText: calls
+        countMatchesForText: and passes YES for markMatches:.
+
+        * WebView/WebDocumentInternal.h:
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView markAllMatchesForText:caseSensitive:limit:]):
+        (-[WebHTMLView countMatchesForText:caseSensitive:limit:markMatches:]):
+        * WebView/WebPDFView.mm:
+        (-[WebPDFView markAllMatchesForText:caseSensitive:limit:]):
+        (-[WebPDFView countMatchesForText:caseSensitive:limit:markMatches:]):
+        * WebView/WebView.mm:
+        (-[WebView markAllMatchesForText:caseSensitive:highlight:limit:]):
+        (-[WebView countMatchesForText:caseSensitive:highlight:limit:markMatches:]):
+        * WebView/WebViewPrivate.h:
+
 2010-08-31  Darin Adler  <darin@apple.com>
 
         Reviewed by Anders Carlsson.
index 191264b..0f63d75 100644 (file)
@@ -62,6 +62,7 @@
 - (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue;
 - (BOOL)markedTextMatchesAreHighlighted;
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(WebNSUInteger)limit;
+- (WebNSUInteger)countMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
 - (void)unmarkAllTextMatches;
 - (NSArray *)rectsForTextMatches;
 @end
index a619f18..8edff95 100644 (file)
@@ -6202,10 +6202,15 @@ static void extractUnderlines(NSAttributedString *string, Vector<CompositionUnde
 
 - (NSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(NSUInteger)limit
 {
+    return [self countMatchesForText:string caseSensitive:caseFlag limit:limit markMatches:YES];
+}
+
+- (NSUInteger)countMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(NSUInteger)limit markMatches:(BOOL)markMatches
+{
     Frame* coreFrame = core([self _frame]);
     if (!coreFrame)
         return 0;
-    return coreFrame->markAllMatchesForText(string, caseFlag, limit);
+    return coreFrame->countMatchesForText(string, caseFlag, limit, markMatches);
 }
 
 - (void)setMarkedTextMatchesAreHighlighted:(BOOL)newValue
index 5e7b73c..70fceb6 100644 (file)
@@ -628,6 +628,11 @@ static BOOL _PDFSelectionsAreEqual(PDFSelection *selectionA, PDFSelection *selec
 
 - (NSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(NSUInteger)limit
 {
+    return [self countMatchesForText:string caseSensitive:caseFlag limit:limit markMatches:YES];
+}
+
+- (NSUInteger)countMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag limit:(NSUInteger)limit markMatches:(BOOL)markMatches
+{
     PDFSelection *previousMatch = nil;
     PDFSelection *nextMatch = nil;
     NSMutableArray *matches = [[NSMutableArray alloc] initWithCapacity:limit];
index a8c405c..b4f17e4 100644 (file)
@@ -4375,15 +4375,21 @@ static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSValue jsValu
 
 - (NSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(NSUInteger)limit
 {
+    return [self countMatchesForText:string caseSensitive:caseFlag highlight:highlight limit:limit markMatches:YES];
+}
+
+- (NSUInteger)countMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(NSUInteger)limit markMatches:(BOOL)markMatches
+{
     WebFrame *frame = [self mainFrame];
     unsigned matchCount = 0;
     do {
         id <WebDocumentView> view = [[frame frameView] documentView];
         if ([view conformsToProtocol:@protocol(WebMultipleTextMatches)]) {
-            [(NSView <WebMultipleTextMatches>*)view  setMarkedTextMatchesAreHighlighted:highlight];
+            if (markMatches)
+                [(NSView <WebMultipleTextMatches>*)view setMarkedTextMatchesAreHighlighted:highlight];
         
             ASSERT(limit == 0 || matchCount < limit);
-            matchCount += [(NSView <WebMultipleTextMatches>*)view markAllMatchesForText:string caseSensitive:caseFlag limit:limit == 0 ? 0 : limit - matchCount];
+            matchCount += [(NSView <WebMultipleTextMatches>*)view countMatchesForText:string caseSensitive:caseFlag 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)
index 9d47a4d..28348cc 100644 (file)
@@ -180,6 +180,7 @@ typedef enum {
 // These methods are still in flux; don't rely on them yet.
 - (BOOL)canMarkAllTextMatches;
 - (WebNSUInteger)markAllMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit;
+- (WebNSUInteger)countMatchesForText:(NSString *)string caseSensitive:(BOOL)caseFlag highlight:(BOOL)highlight limit:(WebNSUInteger)limit markMatches:(BOOL)markMatches;
 - (void)unmarkAllTextMatches;
 - (NSArray *)rectsForTextMatches;