Two more files I forgot to svn add for search fields.
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Dec 2006 10:18:53 +0000 (10:18 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Dec 2006 10:18:53 +0000 (10:18 +0000)
        * platform/SearchPopupMenu.h: Added.
        (WebCore::SearchPopupMenu::create):
        * platform/mac/SearchPopupMenuMac.mm: Added.
        (WebCore::SearchPopupMenu::SearchPopupMenu):
        (WebCore::autosaveKey):
        (WebCore::SearchPopupMenu::saveRecentSearches):
        (WebCore::SearchPopupMenu::loadRecentSearches):

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

WebCore/ChangeLog
WebCore/platform/SearchPopupMenu.h [new file with mode: 0644]
WebCore/platform/mac/SearchPopupMenuMac.mm [new file with mode: 0644]

index 74f5246..3ee7230 100644 (file)
@@ -1,5 +1,17 @@
 2006-12-16  Adele Peterson  <adele@apple.com>
 
+        Two more files I forgot to svn add for search fields.
+
+        * platform/SearchPopupMenu.h: Added.
+        (WebCore::SearchPopupMenu::create):
+        * platform/mac/SearchPopupMenuMac.mm: Added.
+        (WebCore::SearchPopupMenu::SearchPopupMenu):
+        (WebCore::autosaveKey):
+        (WebCore::SearchPopupMenu::saveRecentSearches):
+        (WebCore::SearchPopupMenu::loadRecentSearches):
+
+2006-12-16  Adele Peterson  <adele@apple.com>
+
         Reviewed by Adam.
 
         * platform/PopupMenuClient.h: Added. Broken out of PopupMenu class.
diff --git a/WebCore/platform/SearchPopupMenu.h b/WebCore/platform/SearchPopupMenu.h
new file mode 100644 (file)
index 0000000..fe3ec0b
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef SEARCHPOPUPMENU_H
+#define SEARCHPOPUPMENU_H
+
+#include "PopupMenu.h"
+#include <wtf/Forward.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class AtomicString;
+
+class SearchPopupMenu : public PopupMenu {
+public:
+    static PassRefPtr<SearchPopupMenu> create(PopupMenuClient* client) { return new SearchPopupMenu(client); }
+
+    void saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems);
+    void loadRecentSearches(const AtomicString& name, Vector<String>& searchItems);
+    
+protected:
+    SearchPopupMenu(PopupMenuClient* client);
+
+};
+
+}
+
+#endif
diff --git a/WebCore/platform/mac/SearchPopupMenuMac.mm b/WebCore/platform/mac/SearchPopupMenuMac.mm
new file mode 100644 (file)
index 0000000..dd111c7
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#import "config.h"
+#import "SearchPopupMenu.h"
+
+#import "AtomicString.h"
+
+namespace WebCore {
+
+SearchPopupMenu::SearchPopupMenu(PopupMenuClient* client)
+    : PopupMenu(client)
+{
+}
+
+static NSString* autosaveKey(const String& name)
+{
+    return [@"com.apple.WebKit.searchField:" stringByAppendingString:name];
+}
+
+void SearchPopupMenu::saveRecentSearches(const AtomicString& name, const Vector<String>& searchItems)
+{
+    if (name.isEmpty())
+        return;
+
+    size_t size = searchItems.size();
+    if (size == 0)
+        [[NSUserDefaults standardUserDefaults] removeObjectForKey:autosaveKey(name)];
+    else {
+        NSMutableArray* items = [[NSMutableArray alloc] initWithCapacity:size];
+        for (size_t i = 0; i < size; ++i)
+            [items addObject:searchItems[i]];
+        [[NSUserDefaults standardUserDefaults] setObject:items forKey:autosaveKey(name)];
+        [items release];
+    }
+}
+
+void SearchPopupMenu::loadRecentSearches(const AtomicString& name, Vector<String>& searchItems)
+{
+    if (name.isEmpty())
+        return;
+
+    searchItems.clear();
+    NSArray* items = [[NSUserDefaults standardUserDefaults] arrayForKey:autosaveKey(name)];
+    size_t size = [items count];
+    for (size_t i = 0; i < size; ++i) {
+        NSString* item = [items objectAtIndex:i];
+        if ([item isKindOfClass:[NSString class]])
+            searchItems.append(item);
+    }
+}
+
+}