WebCore:
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Mar 2004 01:34:14 +0000 (01:34 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Mar 2004 01:34:14 +0000 (01:34 +0000)
Implement the rest of the search field.  Make it work with form submission.  Implement onscroll at
the document level.

        Reviewed by darin

        * khtml/html/html_formimpl.cpp:
        (HTMLFormElementImpl::submit):
        * khtml/rendering/render_form.cpp:
        (RenderLineEdit::addSearchResult):
        * khtml/rendering/render_form.h:
        * kwq/KWQKHTMLPart.h:
        * kwq/KWQKHTMLPart.mm:
        (KWQKHTMLPart::sendScrollEvent):
        * kwq/KWQLineEdit.h:
        * kwq/KWQLineEdit.mm:
        (QLineEdit::setMaxResults):
        (QLineEdit::setPlaceholderString):
        (QLineEdit::addSearchResult):
        * kwq/WebCoreBridge.h:
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge sendScrollEvent]):
        * kwq/WebCoreViewFactory.h:

WebKit:

Implement the rest of the search field.

Implement onscroll at the document level.

        Reviewed by darin

        * English.lproj/Localizable.strings:
        * WebCoreSupport.subproj/WebBridge.m:
        * WebCoreSupport.subproj/WebViewFactory.m:
        (-[NSMenu addItemWithTitle:action:tag:]):
        (-[WebViewFactory submitButtonDefaultLabel]):
        (-[WebViewFactory cellMenuForSearchField]):
        * WebView.subproj/WebHTMLView.m:
        (-[WebHTMLView _frameOrBoundsChanged]):
        (-[WebHTMLView viewDidMoveToWindow]):
        * WebView.subproj/WebHTMLViewPrivate.h:

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

17 files changed:
WebCore/ChangeLog-2005-08-23
WebCore/khtml/html/html_formimpl.cpp
WebCore/khtml/rendering/render_form.cpp
WebCore/khtml/rendering/render_form.h
WebCore/kwq/KWQKHTMLPart.h
WebCore/kwq/KWQKHTMLPart.mm
WebCore/kwq/KWQLineEdit.h
WebCore/kwq/KWQLineEdit.mm
WebCore/kwq/WebCoreBridge.h
WebCore/kwq/WebCoreBridge.mm
WebCore/kwq/WebCoreViewFactory.h
WebKit/ChangeLog
WebKit/English.lproj/Localizable.strings
WebKit/WebCoreSupport.subproj/WebBridge.m
WebKit/WebCoreSupport.subproj/WebViewFactory.m
WebKit/WebView.subproj/WebHTMLView.m
WebKit/WebView.subproj/WebHTMLViewPrivate.h

index 76243e611bade9844eb19d34f11852c80b9fb233..57fea04b21e9ffbab98c876575cd1c6c0e85aec1 100644 (file)
@@ -1,3 +1,28 @@
+2004-03-25  David Hyatt  <hyatt@apple.com>
+
+       Implement the rest of the search field.  Make it work with form submission.  Implement onscroll at
+       the document level.
+       
+        Reviewed by darin
+
+        * khtml/html/html_formimpl.cpp:
+        (HTMLFormElementImpl::submit):
+        * khtml/rendering/render_form.cpp:
+        (RenderLineEdit::addSearchResult):
+        * khtml/rendering/render_form.h:
+        * kwq/KWQKHTMLPart.h:
+        * kwq/KWQKHTMLPart.mm:
+        (KWQKHTMLPart::sendScrollEvent):
+        * kwq/KWQLineEdit.h:
+        * kwq/KWQLineEdit.mm:
+        (QLineEdit::setMaxResults):
+        (QLineEdit::setPlaceholderString):
+        (QLineEdit::addSearchResult):
+        * kwq/WebCoreBridge.h:
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge sendScrollEvent]):
+        * kwq/WebCoreViewFactory.h:
+
 2004-03-25  David Hyatt  <hyatt@apple.com>
 
        Fix for 3570700, crash in inlineBox::isDirty.  Make sure line boxes null out parent pointers when those
index 0441acaa4152d3d54fc4d3537c158c43a0109279..7c8758e73b56cd3c9ed02aba7b5e5a738bf11c80 100644 (file)
@@ -521,9 +521,12 @@ void HTMLFormElementImpl::submit( bool activateSubmitButton )
         if (current->id() == ID_INPUT) {
             HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(current);
             if (input->inputType() == HTMLInputElementImpl::TEXT
-                || input->inputType() ==  HTMLInputElementImpl::PASSWORD)
+                || input->inputType() ==  HTMLInputElementImpl::PASSWORD
+                || input->inputType() == HTMLInputElementImpl::SEARCH)
             {
                 KWQ(part)->recordFormValue(input->name().string(), input->value().string(), this);
+                if (input->renderer() && input->inputType() == HTMLInputElementImpl::SEARCH)
+                    static_cast<RenderLineEdit*>(input->renderer())->addSearchResult();
             }
         }
 #else
index 4c38619a3542da72fb54bd2abae1e42ded953c40..5117da338a730358f7dbdb01939ccba525db2fbd 100644 (file)
@@ -598,6 +598,12 @@ void RenderLineEdit::slotPerformSearch()
     // Fire the "search" DOM event.
     element()->dispatchHTMLEvent(EventImpl::SEARCH_EVENT, true, false);
 }
+
+void RenderLineEdit::addSearchResult()
+{
+    if (widget())
+        widget()->addSearchResult();
+}
 #endif
 
 void RenderLineEdit::handleFocusOut()
index cc600b9762e79d0da69ca7f7e43fc76d1fc13c96..fee2595292cdc3ac36f0e7d203594bed8c069d03 100644 (file)
@@ -265,6 +265,8 @@ public slots:
     void slotTextChanged(const QString &string);
 #if APPLE_CHANGES
     void slotPerformSearch();
+public:
+    void addSearchResult();
 #endif
 
 protected:
index e65833b5ef62a9225b40ee96ad0a6499fbf7158b..ef7feeb11b071765eeae93e91bf42d39feccef28 100644 (file)
@@ -181,6 +181,7 @@ public:
     void forceLayout();
     void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth);
     void sendResizeEvent();
+    void sendScrollEvent();
     void paint(QPainter *, const QRect &);
     void paintSelectionOnly(QPainter *p, const QRect &rect);
 
index 38b83f1f6bd91cab0e61dd9ff89665cff92fb534..9861a8c90bcad7e0472c9033a3c922ca6801ea7b 100644 (file)
@@ -1468,6 +1468,17 @@ void KWQKHTMLPart::sendResizeEvent()
     }
 }
 
+void KWQKHTMLPart::sendScrollEvent()
+{
+    KHTMLView *v = d->m_view;
+    if (v) {
+        DocumentImpl *doc = xmlDocImpl();
+        if (!doc)
+            return;
+        doc->dispatchHTMLEvent(EventImpl::SCROLL_EVENT, true, false);
+    }
+}
+
 void KWQKHTMLPart::runJavaScriptAlert(const QString &message)
 {
     QString text = message;
index fbbea62a4138dac158e93b820acbd97d5a9c6d87..ceef6b6af66164039a87ea81d85d047f346a4a96 100644 (file)
@@ -81,6 +81,7 @@ public:
     void setAutoSaveName(const QString& name);
     void setMaxResults(int maxResults);
     void setPlaceholderString(const QString& placeholder);
+    void addSearchResult();
 
 private:
     KWQSignal m_returnPressed;
index 92204fc64170eb91af83a340a0fb8a708fe01e3b..6d32b3aa4afa3e780111d01a012c988a9962c5c2 100644 (file)
 #import "KWQTextField.h"
 #import "WebCoreTextRenderer.h"
 #import "WebCoreTextRendererFactory.h"
+#import "WebCoreViewFactory.h"
+
+@interface NSSearchField (SearchFieldSecrets)
+- (void) _addStringToRecentSearches:(NSString*)string;
+@end
 
 QLineEdit::QLineEdit(Type type)
     : m_returnPressed(this, SIGNAL(returnPressed()))
@@ -285,12 +290,21 @@ void QLineEdit::setMaxResults(int maxResults)
         return;
     
     NSSearchField *searchField = (NSSearchField *)getView();
-    if (!maxResults)
-        [[searchField cell] setSearchButtonCell:nil];
-    else
-        [[searchField cell] resetSearchButtonCell];
-
-    [[searchField cell] setMaximumRecents:maxResults];
+    id searchCell = [searchField cell];
+    if (!maxResults) {
+        [searchCell setSearchButtonCell:nil];
+        [searchCell setSearchMenuTemplate:nil];
+    }
+    else {
+        NSMenu* cellMenu = [searchCell searchMenuTemplate];
+        NSButtonCell* buttonCell = [searchCell searchButtonCell];
+        if (!buttonCell)
+            [searchCell resetSearchButtonCell];
+        if (!cellMenu)
+            [searchCell setSearchMenuTemplate:[[WebCoreViewFactory sharedFactory] cellMenuForSearchField]];
+    }
+    
+    [searchCell setMaximumRecents:maxResults];
 }
 
 void QLineEdit::setPlaceholderString(const QString& placeholder)
@@ -302,3 +316,12 @@ void QLineEdit::setPlaceholderString(const QString& placeholder)
     [[searchField cell] setPlaceholderString:placeholder.getNSString()];
 }
 
+void QLineEdit::addSearchResult()
+{
+    if (m_type != Search)
+        return;
+    
+    NSSearchField *searchField = (NSSearchField *)getView();
+    [[searchField cell] _addStringToRecentSearches:[searchField stringValue]];
+}
+
index c53630afedda5334a73d3894095ff9157234ee95..b3dd52ac86ea3eb7c390f8eab52f486aed3e990f 100644 (file)
@@ -170,6 +170,7 @@ typedef enum {
 - (void)forceLayoutAdjustingViewSize:(BOOL)adjustSizeFlag;
 - (void)forceLayoutWithMinimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)adjustSizeFlag;
 - (void)sendResizeEvent;
+- (void)sendScrollEvent;
 - (BOOL)needsLayout;
 - (void)setNeedsLayout;
 - (void)drawRect:(NSRect)rect;
index bbcf1ca6e3f7d23b041af3655a3cb614cb308894..a8fb8df10641c155fd2cc342ed61406530fad11b 100644 (file)
@@ -585,6 +585,11 @@ static BOOL nowPrinting(WebCoreBridge *self)
     _part->sendResizeEvent();
 }
 
+- (void)sendScrollEvent
+{
+    _part->sendScrollEvent();
+}
+
 - (void)drawRect:(NSRect)rect withPainter:(QPainter *)p
 {
     [self _setupRootForPrinting:YES];
index 1ce6faa5a6f9c274aff8ad660949a8f0b905eb08..b869a69287466760b1951fcbffef182ffc7328d5 100644 (file)
@@ -39,6 +39,8 @@
 - (NSString *)searchableIndexIntroduction;
 - (NSString *)submitButtonDefaultLabel;
 
+- (NSMenu *)cellMenuForSearchField;
+
 - (NSString *)defaultLanguageCode;
 
 - (WebCoreBridge *)bridgeForView:(NSView *)aView;
index 5b3ac2500eff39a1f3933cecf0e6a7cf19f132d3..29afed09751c33a1f7e50f824fbbf70e6338fc3e 100644 (file)
@@ -1,3 +1,22 @@
+2004-03-25  David Hyatt  <hyatt@apple.com>
+
+       Implement the rest of the search field.
+
+       Implement onscroll at the document level.
+       
+        Reviewed by darin
+
+        * English.lproj/Localizable.strings:
+        * WebCoreSupport.subproj/WebBridge.m:
+        * WebCoreSupport.subproj/WebViewFactory.m:
+        (-[NSMenu addItemWithTitle:action:tag:]):
+        (-[WebViewFactory submitButtonDefaultLabel]):
+        (-[WebViewFactory cellMenuForSearchField]):
+        * WebView.subproj/WebHTMLView.m:
+        (-[WebHTMLView _frameOrBoundsChanged]):
+        (-[WebHTMLView viewDidMoveToWindow]):
+        * WebView.subproj/WebHTMLViewPrivate.h:
+
 2004-03-25  Richard Williamson   <rjw@apple.com>
 
        Netscape plugin API header cleanup.
index 2081b351f80036526671ff2bf8586f5ca20e8d0d..628c542e11eca355b7146a7b0d3234e303926950 100644 (file)
Binary files a/WebKit/English.lproj/Localizable.strings and b/WebKit/English.lproj/Localizable.strings differ
index 4df9d22197c2991c4886b1fab7616a876035b541..080a03098b6b3262c23da663dccd32907acdfaeb 100644 (file)
@@ -74,7 +74,6 @@
 - (jobject)pollForAppletInWindow: (NSWindow *)window;
 @end
 
-
 @implementation WebBridge
 
 - (id)initWithWebFrame:(WebFrame *)webFrame
index fe2c2159f714cca76eb80198c71b2448b799becd..91408f7ad46bc7373f10e107bcb601a8cbb057bf 100644 (file)
 
 #import <WebKit/WebPluginDatabase.h>
 
+@interface NSMenu (BrowserMenuAdditions)
+- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag;
+@end
+
+@implementation NSMenu (BrowserMenuAdditions)
+- (NSMenuItem *)addItemWithTitle:(NSString *)title action:(SEL)action tag:(int)tag
+{
+    NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:action keyEquivalent:@""] autorelease];
+    [item setTag:tag];
+    [self addItem:item];
+    return item;
+}
+@end
+
 @implementation WebViewFactory
 
 + (void)createSharedFactory;
     return UI_STRING("Submit", "default label for Submit buttons in forms on web pages");
 }
 
+- (NSMenu *)cellMenuForSearchField
+{
+    NSMenu* cellMenu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
+    [cellMenu addItemWithTitle:UI_STRING("Recent Searches", "label for first item in the menu that appears when clicking on the search field image, used as embedded menu title")
+                        action:NULL tag:NSSearchFieldRecentsTitleMenuItemTag];
+    [cellMenu addItemWithTitle:@"" action:NULL tag:NSSearchFieldRecentsMenuItemTag];
+    NSMenuItem *separator = [NSMenuItem separatorItem];
+    [separator setTag:NSSearchFieldRecentsTitleMenuItemTag];
+    [cellMenu addItem:separator];
+    [cellMenu addItemWithTitle:UI_STRING("Clear Recent Searches", "menu item in Recent Searches menu that empties menu's contents")
+                        action:NULL tag:NSSearchFieldClearRecentsMenuItemTag];
+    [cellMenu addItemWithTitle:UI_STRING("No recent searches", "Label for only item in menu that appears when clicking on the search field image, when no searches have been performed")
+                        action:NULL tag:NSSearchFieldNoRecentsMenuItemTag];
+    return cellMenu;
+}
+
 - (NSString *)defaultLanguageCode
 {
     // FIXME: Need implementation. Defaults gives us a list of languages, but by name, not code.
index 9c30b8d3c6717ebcd42c425943ce9af02adf7fee..456e0bc39c37a10b3bff465b4fd89d1ceada7dd0 100644 (file)
@@ -197,6 +197,11 @@ static BOOL forceRealHitTest = NO;
         [self setNeedsDisplay:YES];
     }
 
+    NSPoint origin = [[self superview] bounds].origin;
+    if (!NSEqualPoints(_private->lastScrollPosition, origin))
+        [[self _bridge] sendScrollEvent];
+    _private->lastScrollPosition = origin;
+
     SEL selector = @selector(_updateMouseoverWithFakeEvent);
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:selector object:nil];
     [self performSelector:selector withObject:nil afterDelay:0];
@@ -1183,6 +1188,7 @@ static WebHTMLView *lastHitView = nil;
     if (_private) {
         [self _stopAutoscrollTimer];
         if ([self window]) {
+            _private->lastScrollPosition = [[self superview] bounds].origin;
             [self addWindowObservers];
             [self addSuperviewObservers];
             [self addMouseMovedObserver];
@@ -1190,6 +1196,8 @@ static WebHTMLView *lastHitView = nil;
     
             [[self _pluginController] startAllPlugins];
     
+            _private->lastScrollPosition = NSZeroPoint;
+            
             _private->inWindow = YES;
         } else {
             // Reset when we are moved out of a window after being moved into one.
index ccab175a209dccf98277192bc7782b9c03c95409..e41e5b20e880b78452c333da844e8a3e16ab9796 100644 (file)
@@ -35,6 +35,8 @@
     NSSize lastLayoutFrameSize;
     BOOL laidOutAtLeastOnce;
     
+    NSPoint lastScrollPosition;
+
     WebPluginController *pluginController;
     
     NSString *toolTip;