[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

trey trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:37:06 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 050c506825cc5cd76b8f80b05d44b9153f21e2b7
Author: trey <trey at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 15 17:25:23 2003 +0000

    WebCore:
    
    	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
    	3051546 - Find on Page doesn't work for frameset pages
    	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
    	3097498 - Find Previous continues to "Find Next" until end of paragraph
    	3097507 - Find Next searches from previous find hit instead of current selection
    
    	And a commented out fix for:
    
    	3121828 - scrollToVisible on find cuts off the left part of the view due to needless horiz. scroll
    
    	Various missing pieces are implemented to support better finding.  The fix for
    	3121828 is left out until 3228511 is dealt with.
    
            Reviewed by Maciej.
    
            * WebCore.pbproj/project.pbxproj:
            * khtml/khtml_part.cpp:
            (KHTMLPart::findTextBegin):  Added args to allow starting a find at an arbitrary
    	places, such as the current selection.
            (KHTMLPart::findTextNext):  Implement reverse search - only the param was there.
    	Don't do lame scrolling selection to visible here, do better ourselves later.
            * khtml/khtml_part.h:
            * kwq/KWQKHTMLPart.h:
            * kwq/KWQKHTMLPart.mm:
            (KWQKHTMLPart::jumpToSelection):  Make whole selection rect visible, and only scroll
    	anything if needed.  ***Commented out in lieu of 3228511.
            (KWQKHTMLPart::findString):  Implement find starting at the right place relative to
    	the selection, forwards and backwards, and wraparound.  This is just setup around
    	calling findTextNext.  Also scroll the result to be visible.
            * kwq/WebCoreBridge.h:
            * kwq/WebCoreBridge.mm:
    	(-[WebCoreBridge deselectAll]):  Call part instead of doc so its state isn't out of sync.
            (-[WebCoreBridge searchFor:direction:caseSensitive:wrap:]):  Pass extra wrap arg.
            * kwq/WebCoreDOMNode.mm:
            (+[WebCoreDOMNode nodeWithImpl:DOM::]):
    	Return a nil for a null element instead of croaking.
            (-[WebCoreDOMNode initWithImpl:DOM::]):  Ditto.
    
    WebKit:
    
    	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
    	3051546 - Find on Page doesn't work for frameset pages
    	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
    	3097498 - Find Previous continues to "Find Next" until end of paragraph
    	3097507 - Find Next searches from previous find hit instead of current selection
    	Primary changes here:  I added a wrap flag to the searchFor method, which is needed to
    	control how we search as we traverse the frame tree.  A new method is added to WebView
    	that knows about traversing the frame tree as we search.  HTMLView and TextView both
    	clear their selections when they lose first responder (see 3228554 for possible
    	improvements to that change).
    
            Reviewed by Maciej.
    
            * Misc.subproj/WebSearchableTextView.m:
    	Added wrap flag, pass on to TextView.
    	Ensure we do some searching when we would previous get a zero range to search in.
            * WebView.subproj/WebDocument.h:
            * WebView.subproj/WebFramePrivate.h:
            * WebView.subproj/WebFramePrivate.m:
    	These are all basic methods to support forwards and backwards traversal of
    	the frame tree.  Modeled after same methods we have for traversing the DOM.
            (-[WebFrame _nextSibling]):
            (-[WebFrame _previousSibling]):
            (-[WebFrame _lastChild]):
            (-[WebFrame _nextFrameWithWrap:]):
            (-[WebFrame _previousFrameWithWrap:]):
            * WebView.subproj/WebHTMLView.m:
            (-[WebHTMLView searchFor:direction:caseSensitive:wrap:]):  Added wrap flag,
    	pass it to bridge.
            (-[WebHTMLView resignFirstResponder]):  Clear selection when we lose firstResp.
            * WebView.subproj/WebTextView.m:
            (-[WebTextView resignFirstResponder]):  Clear selection when we lose firstResp.
            * WebView.subproj/WebView.m:
            (-[WebView _currentFrame]):  Return the frame holding the first responder.
            (-[WebView _searchFor:direction:caseSensitive:wrap:]):  Main work:  traverse the
    	frame tree and drive the overall find.
            * WebView.subproj/WebViewPrivate.h:
    
    WebBrowser:
    
    	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
    	3051546 - Find on Page doesn't work for frameset pages
    	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
    	3097498 - Find Previous continues to "Find Next" until end of paragraph
    	3097507 - Find Next searches from previous find hit instead of current selection
    
    	Primary change here is that we use a new WK method that is hip to searching across
    	frames.  There is an open issue in 3228520 for getting that into the API.
    
            Reviewed by Maciej.
    
    	* BrowserWindowController.h:
            * BookmarksViewController.m:
    	Added wrap: argument to searchFor:direction:caseSensitive: method.
            * FindPanelController.m:
            (-[FindPanelController _searchTarget]):  Hacked to return a WebView if possible
    	instead of always a WebDocumentSearching.
            (-[FindPanelController _doSearchForString:direction:caseSensitive:inTarget:]):
    	New method that knows to call new WK method for searching across frames in the
    	special case of us about to search within a WebView.
            (-[FindPanelController _findWithDirection:caseSensitive:]):
    	Call above new method instead of going straight to the search target using the
    	WebDocumentSearching method.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4105 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 1435248..db5e152 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,43 @@
+2003-04-14  Trey Matteson  <trey at apple.com>
+
+	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
+	3051546 - Find on Page doesn't work for frameset pages
+	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
+	3097498 - Find Previous continues to "Find Next" until end of paragraph	
+	3097507 - Find Next searches from previous find hit instead of current selection
+
+	And a commented out fix for:
+
+	3121828 - scrollToVisible on find cuts off the left part of the view due to needless horiz. scroll
+
+	Various missing pieces are implemented to support better finding.  The fix for
+	3121828 is left out until 3228511 is dealt with.
+
+        Reviewed by Maciej.
+
+        * WebCore.pbproj/project.pbxproj:
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::findTextBegin):  Added args to allow starting a find at an arbitrary
+	places, such as the current selection.
+        (KHTMLPart::findTextNext):  Implement reverse search - only the param was there.
+	Don't do lame scrolling selection to visible here, do better ourselves later.
+        * khtml/khtml_part.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::jumpToSelection):  Make whole selection rect visible, and only scroll
+	anything if needed.  ***Commented out in lieu of 3228511.
+        (KWQKHTMLPart::findString):  Implement find starting at the right place relative to
+	the selection, forwards and backwards, and wraparound.  This is just setup around
+	calling findTextNext.  Also scroll the result to be visible.
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+	(-[WebCoreBridge deselectAll]):  Call part instead of doc so its state isn't out of sync.
+        (-[WebCoreBridge searchFor:direction:caseSensitive:wrap:]):  Pass extra wrap arg.
+        * kwq/WebCoreDOMNode.mm:
+        (+[WebCoreDOMNode nodeWithImpl:DOM::]):
+	Return a nil for a null element instead of croaking.
+        (-[WebCoreDOMNode initWithImpl:DOM::]):  Ditto.
+
 2003-04-14  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Trey.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 1435248..db5e152 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,43 @@
+2003-04-14  Trey Matteson  <trey at apple.com>
+
+	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
+	3051546 - Find on Page doesn't work for frameset pages
+	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
+	3097498 - Find Previous continues to "Find Next" until end of paragraph	
+	3097507 - Find Next searches from previous find hit instead of current selection
+
+	And a commented out fix for:
+
+	3121828 - scrollToVisible on find cuts off the left part of the view due to needless horiz. scroll
+
+	Various missing pieces are implemented to support better finding.  The fix for
+	3121828 is left out until 3228511 is dealt with.
+
+        Reviewed by Maciej.
+
+        * WebCore.pbproj/project.pbxproj:
+        * khtml/khtml_part.cpp:
+        (KHTMLPart::findTextBegin):  Added args to allow starting a find at an arbitrary
+	places, such as the current selection.
+        (KHTMLPart::findTextNext):  Implement reverse search - only the param was there.
+	Don't do lame scrolling selection to visible here, do better ourselves later.
+        * khtml/khtml_part.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::jumpToSelection):  Make whole selection rect visible, and only scroll
+	anything if needed.  ***Commented out in lieu of 3228511.
+        (KWQKHTMLPart::findString):  Implement find starting at the right place relative to
+	the selection, forwards and backwards, and wraparound.  This is just setup around
+	calling findTextNext.  Also scroll the result to be visible.
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+	(-[WebCoreBridge deselectAll]):  Call part instead of doc so its state isn't out of sync.
+        (-[WebCoreBridge searchFor:direction:caseSensitive:wrap:]):  Pass extra wrap arg.
+        * kwq/WebCoreDOMNode.mm:
+        (+[WebCoreDOMNode nodeWithImpl:DOM::]):
+	Return a nil for a null element instead of croaking.
+        (-[WebCoreDOMNode initWithImpl:DOM::]):  Ditto.
+
 2003-04-14  Maciej Stachowiak  <mjs at apple.com>
 
         Reviewed by Trey.
diff --git a/WebCore/WebCore.pbproj/project.pbxproj b/WebCore/WebCore.pbproj/project.pbxproj
index d2aace0..cede2fd 100644
--- a/WebCore/WebCore.pbproj/project.pbxproj
+++ b/WebCore/WebCore.pbproj/project.pbxproj
@@ -178,7 +178,6 @@
 </dict>
 </plist>
 ";
-			shouldUseHeadermap = 0;
 		};
 		0867D69DFE84028FC02AAC07 = {
 			buildActionMask = 2147483647;
diff --git a/WebCore/khtml/khtml_part.cpp b/WebCore/khtml/khtml_part.cpp
index 116eda3..e6fc427 100644
--- a/WebCore/khtml/khtml_part.cpp
+++ b/WebCore/khtml/khtml_part.cpp
@@ -2016,10 +2016,10 @@ void KHTMLPart::setOnlyLocalReferences(bool enable)
   d->m_onlyLocalReferences = enable;
 }
 
-void KHTMLPart::findTextBegin()
+void KHTMLPart::findTextBegin(NodeImpl *startNode, int startPos)
 {
-  d->m_findPos = -1;
-  d->m_findNode = 0;
+    d->m_findPos = startPos;
+    d->m_findNode = startNode;
 }
 
 bool KHTMLPart::findTextNext( const QString &str, bool forward, bool caseSensitive, bool isRegExp )
@@ -2067,16 +2067,30 @@ bool KHTMLPart::findTextNext( const QString &str, bool forward, bool caseSensiti
               matchLen = str.length();
             }
 #else
-            d->m_findPos = s.string().find(str, d->m_findPos+1, caseSensitive);
+            if (forward) {
+                d->m_findPos = s.string().find(str, d->m_findPos+1, caseSensitive);
+            } else {
+                if (d->m_findPos == -1) {
+                    // search from end of node
+                    d->m_findPos = s.string().findRev(str, -1, caseSensitive);
+                } else if (d->m_findPos != 0) {
+                    d->m_findPos = s.string().findRev(str, d->m_findPos-1, caseSensitive);
+                } else {
+                    // already at start of this node, on to the next node
+                    d->m_findPos = -1;
+                }
+            }
             matchLen = str.length();
 #endif
 
             if(d->m_findPos != -1)
             {
+#if !APPLE_CHANGES
                 int x = 0, y = 0;
                 static_cast<khtml::RenderText *>(d->m_findNode->renderer())
                   ->posOfChar(d->m_findPos, x, y);
                 d->m_view->setContentsPos(x-50, y-50);
+#endif
 
                 d->m_selectionStart = d->m_findNode;
                 d->m_startOffset = d->m_findPos;
diff --git a/WebCore/khtml/khtml_part.h b/WebCore/khtml/khtml_part.h
index 903b2e8..2ecb226 100644
--- a/WebCore/khtml/khtml_part.h
+++ b/WebCore/khtml/khtml_part.h
@@ -522,7 +522,7 @@ public:
   /**
    * Initiates a text search.
    */
-  void findTextBegin();
+  void findTextBegin(DOM::NodeImpl *startNode = 0, int startPos = -1);
 
   /**
    * Finds the next occurrence of the string or expression.
diff --git a/WebCore/kwq/KWQKHTMLPart.h b/WebCore/kwq/KWQKHTMLPart.h
index 35d33b7..6798331 100644
--- a/WebCore/kwq/KWQKHTMLPart.h
+++ b/WebCore/kwq/KWQKHTMLPart.h
@@ -195,6 +195,8 @@ public:
     NSString *searchForLabelsBeforeElement(NSArray *labels, DOM::ElementImpl *element);
     NSString *matchLabelsAgainstElement(NSArray *labels, DOM::ElementImpl *element);
 
+    bool findString(NSString *str, bool forward, bool caseFlag, bool wrapFlag);
+
     void setSettings(KHTMLSettings *);
 
     KWQWindowWidget *topLevelWidget();
diff --git a/WebCore/kwq/KWQKHTMLPart.mm b/WebCore/kwq/KWQKHTMLPart.mm
index 09fc2cb..42a10d5 100644
--- a/WebCore/kwq/KWQKHTMLPart.mm
+++ b/WebCore/kwq/KWQKHTMLPart.mm
@@ -427,6 +427,51 @@ NSString *KWQKHTMLPart::matchLabelsAgainstElement(NSArray *labels, ElementImpl *
     }
 }
 
+// Search from the end of the currently selected location if we are first responder, or from
+// the beginning of the document if nothing is selected or we're not first responder.
+bool KWQKHTMLPart::findString(NSString *string, bool forward, bool caseFlag, bool wrapFlag)
+{
+    QString target = QString::fromNSString(string);
+    bool result;
+    // start on the correct edge of the selection, search to end
+    NodeImpl *selStart = selectionStart();
+    int selStartOffset = selectionStartOffset();
+    NodeImpl *selEnd = selectionEnd();
+    int selEndOffset = selectionEndOffset();
+    if (selStart) {
+        if (forward) {
+            // point to last char of selection, find will start right afterwards
+            findTextBegin(selEnd, selEndOffset-1);
+        } else {
+            // point to first char of selection, find will start right before
+            findTextBegin(selStart, selStartOffset);
+        }
+    } else {
+        findTextBegin();
+    }
+    result = findTextNext(target, forward, caseFlag, FALSE);
+    if (!result && wrapFlag) {
+        // start back at the other end, search the rest
+        findTextBegin();
+        result = findTextNext(target, forward, caseFlag, FALSE);
+        // if we got back to the same place we started, that doesn't count as success
+        if (result
+            && selStart == selectionStart()
+            && selStartOffset == selectionStartOffset())
+        {
+            result = false;
+        }
+    }
+
+    // khtml took care of moving the selection, but we need to move first responder too,
+    // so the selection is primary.  We also need to make the selection visible, since we
+    // cut the implementation of this in khtml_part.
+    if (result) {
+        jumpToSelection();
+    }
+    return result;
+}
+
 void KWQKHTMLPart::clearRecordedFormValues()
 {
     [_formValuesAboutToBeSubmitted release];
@@ -631,8 +676,24 @@ void KWQKHTMLPart::jumpToSelection()
             rt->posOfChar(d->m_startOffset, x, y);
             // The -50 offset is copied from KHTMLPart::findTextNext, which sets the contents position
             // after finding a matched text string.
-            d->m_view->setContentsPos(x - 50, y - 50);
+           d->m_view->setContentsPos(x - 50, y - 50);
+        }
+/*
+        I think this would be a better way to do this, to avoid needless horizontal scrolling,
+        but it is not feasible until selectionRect() returns a tighter rect around the
+        selected text.  Right now it works at element granularity.
+ 
+        NSView *docView = d->m_view->getDocumentView();
+
+        NSRect selRect = NSRect(selectionRect());
+        NSRect visRect = [docView visibleRect];
+        if (!NSContainsRect(visRect, selRect)) {
+            // pad a bit so we overscroll slightly
+            selRect = NSInsetRect(selRect, -10.0, -10.0);
+            selRect = NSIntersectionRect(selRect, [docView bounds]);
+            [docView scrollRectToVisible:selRect];
         }
+*/
     }
 }
 
diff --git a/WebCore/kwq/WebCoreBridge.h b/WebCore/kwq/WebCoreBridge.h
index f2f489c..7aaea39 100644
--- a/WebCore/kwq/WebCoreBridge.h
+++ b/WebCore/kwq/WebCoreBridge.h
@@ -175,7 +175,7 @@ enum FrameBorderStyle {
 - (NSString *)searchForLabels:(NSArray *)labels beforeElement:(id <WebDOMElement>)element;
 - (NSString *)matchLabels:(NSArray *)labels againstElement:(id <WebDOMElement>)element;
 
-- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag;
+- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;
 - (void)jumpToSelection;
 
 - (void)setTextSizeMultiplier:(float)multiplier;
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 711d5da..c8d4043 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -307,7 +307,7 @@ static bool initializedObjectCacheSize = FALSE;
 
 - (void)deselectAll
 {
-    _part->xmlDocImpl()->clearSelection();
+    _part->slotClearSelection();
 }
 
 - (BOOL)isFrameSet
@@ -708,9 +708,9 @@ static HTMLFormElementImpl *formElementFromDOMElement(id <WebDOMElement>element)
     return element;
 }
 
-- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag
+- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag
 {
-    return _part->findTextNext(QString::fromNSString(string), forward, caseFlag, FALSE);
+    return _part->findString(string, forward, caseFlag, wrapFlag);
 }
 
 - (void)jumpToSelection
diff --git a/WebCore/kwq/WebCoreDOMNode.mm b/WebCore/kwq/WebCoreDOMNode.mm
index 00537c7..d22fd6c 100644
--- a/WebCore/kwq/WebCoreDOMNode.mm
+++ b/WebCore/kwq/WebCoreDOMNode.mm
@@ -64,15 +64,23 @@ DOM::ProcessingInstruction DOM::ProcessingInstructionImpl::createInstance(Proces
 
 + (WebCoreDOMNode *)nodeWithImpl: (DOM::NodeImpl *)_impl
 {
+    if (!_impl) {
+        return nil;
+    }
     return [[(WebCoreDOMNode *)[[self class] alloc] initWithImpl: _impl] autorelease];
 }
 
 - initWithImpl:(DOM::NodeImpl *)coreImpl
 {
     [super init];
-    impl = coreImpl;
-    impl->ref();        
-    return self;
+    if (coreImpl) {
+        impl = coreImpl;
+        impl->ref();
+        return self;
+    } else {
+        [self release];
+        return nil;
+    }
 }
 
 - (BOOL)isEqual:(id)other
diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index a680e37..e37485b 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,43 @@
+2003-04-14  Trey Matteson  <trey at apple.com>
+
+	3009051 - Find on Page stops (once) at end of page, should wrap automatically	WebKit
+	3051546 - Find on Page doesn't work for frameset pages
+	3058437 - can have a selection in two frames at the same time (problem for finding in frames)
+	3097498 - Find Previous continues to "Find Next" until end of paragraph	
+	3097507 - Find Next searches from previous find hit instead of current selection	
+	Primary changes here:  I added a wrap flag to the searchFor method, which is needed to
+	control how we search as we traverse the frame tree.  A new method is added to WebView
+	that knows about traversing the frame tree as we search.  HTMLView and TextView both
+	clear their selections when they lose first responder (see 3228554 for possible
+	improvements to that change).
+
+        Reviewed by Maciej.
+
+        * Misc.subproj/WebSearchableTextView.m:
+	Added wrap flag, pass on to TextView.
+	Ensure we do some searching when we would previous get a zero range to search in.
+        * WebView.subproj/WebDocument.h:
+        * WebView.subproj/WebFramePrivate.h:
+        * WebView.subproj/WebFramePrivate.m:
+	These are all basic methods to support forwards and backwards traversal of
+	the frame tree.  Modeled after same methods we have for traversing the DOM.
+        (-[WebFrame _nextSibling]):
+        (-[WebFrame _previousSibling]):
+        (-[WebFrame _lastChild]):
+        (-[WebFrame _nextFrameWithWrap:]):
+        (-[WebFrame _previousFrameWithWrap:]):
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView searchFor:direction:caseSensitive:wrap:]):  Added wrap flag,
+	pass it to bridge.
+        (-[WebHTMLView resignFirstResponder]):  Clear selection when we lose firstResp.
+        * WebView.subproj/WebTextView.m:
+        (-[WebTextView resignFirstResponder]):  Clear selection when we lose firstResp.
+        * WebView.subproj/WebView.m:
+        (-[WebView _currentFrame]):  Return the frame holding the first responder.
+        (-[WebView _searchFor:direction:caseSensitive:wrap:]):  Main work:  traverse the
+	frame tree and drive the overall find.
+        * WebView.subproj/WebViewPrivate.h:
+
 2003-04-14  Chris Blumenberg  <cblu at apple.com>
 
 	Log time spent loading each plug-in.
diff --git a/WebKit/Misc.subproj/WebSearchableTextView.m b/WebKit/Misc.subproj/WebSearchableTextView.m
index b6f7649..5905155 100644
--- a/WebKit/Misc.subproj/WebSearchableTextView.m
+++ b/WebKit/Misc.subproj/WebSearchableTextView.m
@@ -15,7 +15,7 @@
 
 @implementation WebSearchableTextView
 
-- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag
+- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag wrap: (BOOL)wrapFlag;
 {
     BOOL lastFindWasSuccessful = NO;
     NSString *textContents = [self string];
@@ -31,7 +31,7 @@
         if (!caseFlag)
             options |= NSCaseInsensitiveSearch;
 
-        range = [textContents findString:string selectedRange:[self selectedRange] options:options wrap:YES];
+        range = [textContents findString:string selectedRange:[self selectedRange] options:options wrap:wrapFlag];
         if (range.length) {
             [self setSelectedRange:range];
             [self scrollRangeToVisible:range];
@@ -68,7 +68,7 @@
     NSRange searchRange, range;
 
     if (forwards) {
-        searchRange.location = NSMaxRange(selectedRange);
+        searchRange.location = selectedRange.length > 0 ? NSMaxRange(selectedRange) : 0;
         searchRange.length = length - searchRange.location;
         range = [self rangeOfString:string options:options range:searchRange];
         if ((range.length == 0) && wrap) {	/* If not found look at the first part of the string */
@@ -78,7 +78,7 @@
         }
     } else {
         searchRange.location = 0;
-        searchRange.length = selectedRange.location;
+        searchRange.length = selectedRange.length > 0 ? selectedRange.location : length;
         range = [self rangeOfString:string options:options range:searchRange];
         if ((range.length == 0) && wrap) {
             searchRange.location = NSMaxRange(selectedRange);
diff --git a/WebKit/WebView.subproj/WebDocument.h b/WebKit/WebView.subproj/WebDocument.h
index c19850c..050448a 100644
--- a/WebKit/WebView.subproj/WebDocument.h
+++ b/WebKit/WebView.subproj/WebDocument.h
@@ -72,7 +72,7 @@
     @param caseFlag YES to for case-sensitive search, NO for case-insensitive search.
     @result YES if found, NO if not found.
 */
-- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag;
+- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag wrap: (BOOL)wrapFlag;
 @end
 
 
diff --git a/WebKit/WebView.subproj/WebFramePrivate.h b/WebKit/WebView.subproj/WebFramePrivate.h
index e136055..f20ea7d 100644
--- a/WebKit/WebView.subproj/WebFramePrivate.h
+++ b/WebKit/WebView.subproj/WebFramePrivate.h
@@ -179,4 +179,7 @@ typedef enum {
 // used to decide to use loadType=Same
 - (BOOL)_shouldTreatURLAsSameAsCurrent:(NSURL *)URL;
 
+- (WebFrame *)_nextFrameWithWrap:(BOOL)wrapFlag;
+- (WebFrame *)_previousFrameWithWrap:(BOOL)wrapFlag;
+
 @end
diff --git a/WebKit/WebView.subproj/WebFramePrivate.m b/WebKit/WebView.subproj/WebFramePrivate.m
index 8798fd5..bd7eaf4 100644
--- a/WebKit/WebView.subproj/WebFramePrivate.m
+++ b/WebKit/WebView.subproj/WebFramePrivate.m
@@ -2064,6 +2064,85 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
     [self _checkNewWindowPolicyForRequest:request action:(NSDictionary *)action frameName:frameName formState:nil andCall:self withSelector:@selector(_continueLoadRequestAfterNewWindowPolicy:frameName:formState:)];
 }
 
+// Returns the next frame in our parent's children array, or nil
+- (WebFrame *)_nextSibling
+{
+    if (_private->parent) {
+        NSArray *parentsKids = _private->parent->_private->children;
+        unsigned selfIndex = [parentsKids indexOfObjectIdenticalTo:self];
+        ASSERT(selfIndex != NSNotFound);
+        if (selfIndex < [parentsKids count]-1) {
+            return [parentsKids objectAtIndex:selfIndex+1];
+        }
+    }
+    return nil;		// no parent, or no more later siblings
+}
+
+// Returns the previous frame in our parent's children array, or nil
+- (WebFrame *)_previousSibling
+{
+    if (_private->parent) {
+        NSArray *parentsKids = _private->parent->_private->children;
+        unsigned selfIndex = [parentsKids indexOfObjectIdenticalTo:self];
+        ASSERT(selfIndex != NSNotFound);
+        if (selfIndex > 0) {
+            return [parentsKids objectAtIndex:selfIndex-1];
+        }
+    }
+    return nil;		// no parent, or no more earlier siblings
+}
+
+// Returns the last child of us and any children, or nil
+- (WebFrame *)_lastChild
+{
+    if (_private->children && [_private->children count]) {
+        WebFrame *ourLastKid = [_private->children lastObject];
+        WebFrame *kidsLastKid = [ourLastKid _lastChild];
+        return kidsLastKid ? kidsLastKid : ourLastKid;
+    }
+    return nil;		// no kids
+}
+
+// Return next frame to be traversed, visiting children after parent
+- (WebFrame *)_nextFrameWithWrap:(BOOL)wrapFlag
+{
+    if (_private->children && [_private->children count]) {
+        return [_private->children objectAtIndex:0];
+    } else if (_private->parent) {
+        WebFrame *frame;
+        for (frame = self; frame->_private->parent; frame = frame->_private->parent) {
+            WebFrame *nextSibling = [frame _nextSibling];
+            if (nextSibling) {
+                return nextSibling;
+            }
+        }
+        return wrapFlag ? frame : nil;		// made it all the way to the top
+    } else {
+        return wrapFlag ? self : nil;		// self is the top and we have no kids
+    }
+}
+
+// Return previous frame to be traversed, exact reverse order of _nextFrame
+- (WebFrame *)_previousFrameWithWrap:(BOOL)wrapFlag
+{
+    WebFrame *prevSibling = [self _previousSibling];
+    if (prevSibling) {
+        WebFrame *prevSiblingLastChild = [prevSibling _lastChild];
+        return prevSiblingLastChild ? prevSiblingLastChild : prevSibling;
+    } else if (_private->parent) {
+        return _private->parent;
+    } else {
+        // no siblings, no parent, self==top
+        if (wrapFlag) {
+            WebFrame *selfLastChild = [self _lastChild];
+            return selfLastChild ? selfLastChild : self;
+        } else {
+            // top view is always the last one in this ordering, so prev is nil without wrap
+            return nil;
+        }
+    }
+}
+
 @end
 
 @implementation WebFormState : NSObject
diff --git a/WebKit/WebView.subproj/WebHTMLView.m b/WebKit/WebView.subproj/WebHTMLView.m
index 2f0d184..7411511 100644
--- a/WebKit/WebView.subproj/WebHTMLView.m
+++ b/WebKit/WebView.subproj/WebHTMLView.m
@@ -341,9 +341,9 @@
 
 // Search from the end of the currently selected location, or from the beginning of the
 // document if nothing is selected.
-- (BOOL)searchFor: (NSString *)string direction: (BOOL)forward caseSensitive: (BOOL)caseFlag
+- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;
 {
-    return [[self _bridge] searchFor: string direction: forward caseSensitive: caseFlag];
+    return [[self _bridge] searchFor:string direction:forward caseSensitive:caseFlag wrap:wrapFlag];
 }
 
 - (NSString *)string
@@ -758,6 +758,16 @@
     return YES;
 }
 
+// This approach could be relaxed when dealing with 3228554
+- (BOOL)resignFirstResponder
+{
+    BOOL resign = [super resignFirstResponder];
+    if (resign) {
+        [self deselectAll];
+    }
+    return resign;
+}
+
 //------------------------------------------------------------------------------------
 // WebDocumentView protocol
 //------------------------------------------------------------------------------------
diff --git a/WebKit/WebView.subproj/WebTextView.m b/WebKit/WebView.subproj/WebTextView.m
index 49978de..5c969c4 100644
--- a/WebKit/WebView.subproj/WebTextView.m
+++ b/WebKit/WebView.subproj/WebTextView.m
@@ -194,4 +194,14 @@
     return [controller _menuForElement:element];
 }
 
+// This approach could be relaxed when dealing with 3228554
+- (BOOL)resignFirstResponder
+{
+    BOOL resign = [super resignFirstResponder];
+    if (resign) {
+        [self setSelectedRange:NSMakeRange(0,0)];
+    }
+    return resign;
+}
+
 @end
diff --git a/WebKit/WebView.subproj/WebView.m b/WebKit/WebView.subproj/WebView.m
index 3bf62f4..d2bb5d7 100644
--- a/WebKit/WebView.subproj/WebView.m
+++ b/WebKit/WebView.subproj/WebView.m
@@ -16,8 +16,10 @@
 #import <WebKit/WebFrameViewPrivate.h>
 #import <WebKit/WebHistoryItem.h>
 #import <WebKit/WebHistoryItemPrivate.h>
+#import <WebKit/WebHTMLView.h>
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitStatisticsPrivate.h>
+#import <WebKit/WebNSViewExtras.h>
 #import <WebKit/WebPluginDatabase.h>
 #import <WebKit/WebPolicyDelegate.h>
 #import <WebKit/WebPreferences.h>
@@ -474,6 +476,81 @@ NSString *WebElementLinkTitleKey = 		@"WebElementLinkTitle";
     return YES;
 }
 
+// Return the frame holding first responder
+- (WebFrame *)_currentFrame
+{
+    // Find the frame holding the first responder, or holding the first form in the doc
+    NSResponder *resp = [[self window] firstResponder];
+    if (!resp || ![resp isKindOfClass:[NSView class]] || ![(NSView *)resp isDescendantOf:self]) {
+        return nil;	// first responder outside our view tree
+    } else {
+        WebFrameView *frameView = (WebFrameView *)[(NSView *)resp _web_superviewOfClass:[WebFrameView class]];
+        return [frameView webFrame];
+    }
+}
+
+static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
+{
+    return forward ? [curr _nextFrameWithWrap:wrapFlag]
+                   : [curr _previousFrameWithWrap:wrapFlag];
+}
+
+// I think this should become public - see 3228520
+
+// Search from the end of the currently selected location, or from the beginning of the
+// document if nothing is selected.  Deals with subframes.
+- (BOOL)_searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag
+{
+    // Get the frame holding the selection, or start with the main frame
+    WebFrame *startFrame = [self _currentFrame];
+    if (!startFrame) {
+        startFrame = [self mainFrame];
+    }
+
+    // Search the first frame, then all the other frames, in order
+    id <WebDocumentSearching> startSearchView = nil;
+    BOOL startHasSelection = NO;
+    WebFrame *frame = startFrame;
+    do {
+        id <WebDocumentView> view = [[frame frameView] documentView];
+        if ([view conformsToProtocol:@protocol(WebDocumentSearching)]) {
+            id <WebDocumentSearching> searchView = (id <WebDocumentSearching>)view;
+
+            // first time through
+            if (frame == startFrame) {
+                // Remember if start even has a selection, to know if we need to search more later
+                if ([searchView isKindOfClass:[WebHTMLView class]]) {
+                    // optimization for the common case, to avoid making giant string for selection
+                    startHasSelection = [[startFrame _bridge] selectionStart] != nil;
+                } else if ([searchView conformsToProtocol:@protocol(WebDocumentText)]) {
+                    startHasSelection = [(id <WebDocumentText>)searchView selectedString] != nil;
+                }
+                startSearchView = (id <WebDocumentSearching>)searchView;
+            }
+            
+            // Note at this point we are assuming the search will be done top-to-bottom,
+            // not starting at any selection that exists.  See 3228554.
+            BOOL success = [searchView searchFor:string direction:forward caseSensitive:caseFlag wrap:NO];
+            if (success) {
+                [[self window] makeFirstResponder:searchView];
+                return YES;
+            }
+        }
+        frame = incrementFrame(frame, forward, wrapFlag);
+    } while (frame != startFrame);
+
+    // Search contents of startFrame, on the other side of the selection that we did earlier.
+    // We cheat a bit and just research with wrap on
+    if (startHasSelection && startSearchView) {
+        BOOL success = [startSearchView searchFor:string direction:forward caseSensitive:caseFlag wrap:YES];
+        if (success) {
+            [[self window] makeFirstResponder:startSearchView];
+            return YES;
+        }
+    }
+    return NO;
+}
+
 @end
 
 
diff --git a/WebKit/WebView.subproj/WebViewPrivate.h b/WebKit/WebView.subproj/WebViewPrivate.h
index f849f7c..a729bf5 100644
--- a/WebKit/WebView.subproj/WebViewPrivate.h
+++ b/WebKit/WebView.subproj/WebViewPrivate.h
@@ -70,6 +70,11 @@ typedef struct _WebResourceDelegateImplementationCache {
 }
 @end
 
+ at interface WebView (WebPrivateToBePublic)
+// I think this should become public - see 3228520
+- (BOOL)_searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag;
+ at end
+
 @interface WebView (WebPrivate)
 
 /*!
@@ -106,7 +111,6 @@ typedef struct _WebResourceDelegateImplementationCache {
      */
 - (WebFrame *)_frameForView: (WebFrameView *)aView;
 
-
 - (WebFrame *)_createFrameNamed:(NSString *)name inParent:(WebFrame *)parent allowsScrolling:(BOOL)allowsScrolling;
 
 - (void)_finishedLoadingResourceFromDataSource:(WebDataSource *)dataSource;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list