WebCore:
authorbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2006 06:26:51 +0000 (06:26 +0000)
committerbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2006 06:26:51 +0000 (06:26 +0000)
        Reviewed by Adam.

        Getting rid of some of the critical FIXMEs in ContextMenu.cpp.

        * bridge/mac/FrameMac.h: Two new spell checker functions from
        WebKit. (We will be able to delete the WebKit versions once we
        switch over to WebCore context menus.)
        * bridge/mac/FrameMac.mm:
        (WebCore::FrameMac::isSelectionMisspelled):
        (WebCore::core): Convert from NSArray of Strings to a Vector of
        Strings.
        (WebCore::FrameMac::guessesForMisspelledSelection):
        * loader/FrameLoader.cpp:
        (WebCore::FrameLoader::canHandleRequest):
        * loader/FrameLoader.h: Make canHandleRequest available through the
        FrameLoader.
        * loader/FrameLoaderClient.h: canHandleRequest takes a
        ResourceRequest instead of an NSURLRequest.
        * loader/mac/FrameLoaderMac.mm:
        (WebCore::FrameLoader::continueAfterNavigationPolicy): Same
        * page/Frame.h: New spell checker functions moved to Frame. These
        should be moved some place better some day, but FrameMac currently
        seems to be the place to be for spell checker stuff.
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::populate): Use new FrameLoader and spell
        checking functionality to get rid of two if (true) statements. Also
        add spelling guesses to the editing context menus.

WebKit:
        Reviewed by Adam.

        WebKit half of getting rid of the FixMes in ContextMenu.cpp

        * WebCoreSupport/WebFrameLoaderClient.h: canHandleRequest takes a
        ResourceRequest now.
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::canHandleRequest): Same.
        * WebView/WebHTMLView.m:
        (-[WebHTMLView _isSelectionMisspelled]): Call into WebCore.

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

13 files changed:
WebCore/ChangeLog
WebCore/bridge/mac/FrameMac.h
WebCore/bridge/mac/FrameMac.mm
WebCore/loader/FrameLoader.cpp
WebCore/loader/FrameLoader.h
WebCore/loader/FrameLoaderClient.h
WebCore/loader/mac/FrameLoaderMac.mm
WebCore/page/Frame.h
WebCore/platform/ContextMenu.cpp
WebKit/ChangeLog
WebKit/WebCoreSupport/WebFrameLoaderClient.h
WebKit/WebCoreSupport/WebFrameLoaderClient.mm
WebKit/WebView/WebHTMLView.m

index 186b55f156252967629d18460c1d2b8b3087d97a..182e9227654dd0ef2fcd4b52586d3628f636b9be 100644 (file)
@@ -1,3 +1,33 @@
+2006-11-27  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Adam.
+
+        Getting rid of some of the critical FIXMEs in ContextMenu.cpp.
+
+        * bridge/mac/FrameMac.h: Two new spell checker functions from 
+        WebKit. (We will be able to delete the WebKit versions once we 
+        switch over to WebCore context menus.)
+        * bridge/mac/FrameMac.mm:
+        (WebCore::FrameMac::isSelectionMisspelled):
+        (WebCore::core): Convert from NSArray of Strings to a Vector of 
+        Strings.
+        (WebCore::FrameMac::guessesForMisspelledSelection):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::canHandleRequest):
+        * loader/FrameLoader.h: Make canHandleRequest available through the 
+        FrameLoader.
+        * loader/FrameLoaderClient.h: canHandleRequest takes a 
+        ResourceRequest instead of an NSURLRequest.
+        * loader/mac/FrameLoaderMac.mm:
+        (WebCore::FrameLoader::continueAfterNavigationPolicy): Same
+        * page/Frame.h: New spell checker functions moved to Frame. These 
+        should be moved some place better some day, but FrameMac currently 
+        seems to be the place to be for spell checker stuff.
+        * platform/ContextMenu.cpp:
+        (WebCore::ContextMenu::populate): Use new FrameLoader and spell 
+        checking functionality to get rid of two if (true) statements. Also 
+        add spelling guesses to the editing context menus.
+
 2006-11-27  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Hyatt.
index c1dc6c2e9aca20870f40665bfee8ef6b02b8b8e2..44b6f95121f351f2235fadc550071fe21a897449 100644 (file)
@@ -166,6 +166,8 @@ public:
 
     virtual void ignoreSpelling();
     virtual void learnSpelling();
+    virtual bool isSelectionMisspelled();
+    virtual Vector<String> guessesForMisspelledSelection();
     virtual void markMisspellingsInAdjacentWords(const VisiblePosition&);
     virtual void markMisspellings(const Selection&);
 
index f2cd311d0654f1ade36ed1f18c9fd2656db96ea3..07dcd333748087ce7b2554c7d66019ed6d32f2ca 100644 (file)
@@ -1156,6 +1156,41 @@ void FrameMac::learnSpelling()
     [[NSSpellChecker sharedSpellChecker] learnWord:text];
 }
 
+bool FrameMac::isSelectionMisspelled()
+{
+    String selectedString = selectedText();
+    unsigned length = selectedString.length();
+    if (length == 0)
+        return false;
+    NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:selectedString
+                                                                    startingAt:0
+                                                                      language:nil
+                                                                          wrap:NO 
+                                                        inSpellDocumentWithTag:editor()->client()->spellCheckerDocumentTag() 
+                                                                     wordCount:NULL];
+    return range.length == length;
+}
+
+static Vector<String> core(NSArray* stringsArray)
+{
+    Vector<String> stringsVector = Vector<String>();
+    unsigned count = [stringsArray count];
+    if (count > 0) {
+        NSEnumerator* enumerator = [stringsArray objectEnumerator];
+        NSString* string;
+        while ((string = [enumerator nextObject]) != nil)
+            stringsVector.append(string);
+    }
+    return stringsVector;
+}
+
+Vector<String> FrameMac::guessesForMisspelledSelection()
+{
+    String selectedString = selectedText();
+    ASSERT(selectedString.length() != 0);
+    return core([[NSSpellChecker sharedSpellChecker] guessesForWord:selectedString]);
+}
+
 void FrameMac::markMisspellingsInAdjacentWords(const VisiblePosition &p)
 {
     if (!editor()->client()->isContinuousSpellCheckingEnabled())
index 6ed964152bd7d419e608bd08c27305d1a42d0132..8e113e41462408e70922e38e655df7e07d394ba2 100644 (file)
@@ -310,6 +310,11 @@ Frame* FrameLoader::createWindow(const FrameLoadRequest& request, const WindowFe
     return frame;
 }
 
+bool FrameLoader::canHandleRequest(const ResourceRequest& request)
+{
+    return m_client->canHandleRequest(request);
+}
+
 void FrameLoader::changeLocation(const String& URL, const String& referrer, bool lockHistory, bool userGesture)
 {
     if (URL.find("javascript:", 0, false) == 0) {
index 20c3b5ecf0d8380881858f3d0695a07fd0e678a4..c0fc7f334a94296d216ffbbcc1a3e6da4a51628d 100644 (file)
@@ -193,6 +193,8 @@ namespace WebCore {
         Frame* createWindow(const FrameLoadRequest&, const WindowFeatures&);
 
         void loadResourceSynchronously(const ResourceRequest& request, Vector<char>& data, ResourceResponse& r);
+        
+        bool canHandleRequest(const ResourceRequest&);
 
         // Also not cool.
         void stopLoadingPlugIns();
index 4ac1e55afc7c8501e9a431652897b11d17033422..d9e90073b124057e7f567c649b76815789334da4 100644 (file)
@@ -52,6 +52,7 @@ namespace WebCore {
     class NavigationAction;
     class String;
     class ResourceLoader;
+    class ResourceRequest;
 
     struct LoadErrorResetToken;
 
@@ -205,9 +206,7 @@ namespace WebCore {
         virtual void cancelPendingArchiveLoad(ResourceLoader*) = 0;
         virtual void clearArchivedResources() = 0;
 
-#if PLATFORM(MAC)
-        virtual bool canHandleRequest(NSURLRequest *) const = 0;
-#endif
+        virtual bool canHandleRequest(const ResourceRequest&) const = 0;
         virtual bool canShowMIMEType(const String& MIMEType) const = 0;
         virtual bool representationExistsForURLScheme(const String& URLScheme) const = 0;
         virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const = 0;
index b67dcf81aa9225bb8d8efc4a88ac776f3f7c7b48..d07c512041ccea892c3f287d83536164e0f0d419 100644 (file)
@@ -55,6 +55,8 @@
 #import "Page.h"
 #import "PageState.h"
 #import "Plugin.h"
+#import "ResourceRequest.h"
+#import "ResourceRequestMac.h"
 #import "ResourceResponse.h"
 #import "ResourceResponseMac.h"
 #import "SubresourceLoader.h"
@@ -802,12 +804,15 @@ void FrameLoader::continueAfterNavigationPolicy(PolicyAction policy)
             m_client->startDownload(check.request());
             check.clearRequest();
             break;
-        case PolicyUse:
-            if (!m_client->canHandleRequest(check.request())) {
+        case PolicyUse: {
+            ResourceRequest request;
+            getResourceRequest(request, check.request());
+            if (!m_client->canHandleRequest(request)) {
                 handleUnimplementablePolicy(m_client->cannotShowURLError(check.request()));
                 check.clearRequest();
             }
             break;
+        }
     }
 
     check.call();
index 276ca9783b59f2f7dd07dc8687307f7c0a26d7db..54009fd979c55e645f9cea65a4021a88f213b6de 100644 (file)
@@ -258,6 +258,8 @@ public:
 
     virtual void ignoreSpelling() = 0;
     virtual void learnSpelling() = 0;
+    virtual bool isSelectionMisspelled() = 0;
+    virtual Vector<String> guessesForMisspelledSelection() = 0;
     virtual void markMisspellingsInAdjacentWords(const VisiblePosition&) = 0;
     virtual void markMisspellings(const Selection&) = 0;
     virtual Range* markedTextRange() const = 0;
index b92a665e23e348862bbc06d5540a5d026a8a5c94..782dc6b8f534fc2ebd3c3d237540bd0488844e73 100644 (file)
@@ -33,6 +33,7 @@
 #include "KURL.h"
 #include "Node.h"
 #include "Page.h"
+#include "ResourceRequest.h"
 #include "SelectionController.h"
 
 namespace WebCore {
@@ -77,11 +78,19 @@ void ContextMenu::populate()
 
     ContextMenuItem SeparatorItem(SeparatorType, ContextMenuItemTagNoAction, String());
     HitTestResult result = hitTestResult();
+    
+    Node* node = m_hitTestResult.innerNonSharedNode();
+    if (!node)
+        return;
+    Frame* frame = node->document()->frame();
+    if (!frame)
+        return;
 
     if (!result.isContentEditable()) {
+        FrameLoader* loader = frame->loader();
         KURL linkURL = result.absoluteLinkURL();
         if (!linkURL.isEmpty()) {
-            if (true) { // FIXME: if FrameLoaderClient can handle the request
+            if (loader->canHandleRequest(ResourceRequest(linkURL))) {
                 appendItem(OpenLinkInNewWindowItem);
                 appendItem(DownloadLinkToDiskItem);
             }
@@ -110,7 +119,6 @@ void ContextMenu::populate()
                 appendItem(SeparatorItem);
                 appendItem(CopyItem);
             } else {
-                FrameLoader* loader = result.innerNonSharedNode()->document()->frame()->loader();
                 if (loader->canGoBackOrForward(-1))
                     appendItem(GoBackItem);
 
@@ -122,18 +130,27 @@ void ContextMenu::populate()
                 else
                     appendItem(ReloadItem);
 
-                if (result.innerNonSharedNode()->document()->frame() != result.innerNonSharedNode()->document()->frame()->page()->mainFrame())
+                if (frame->page() && frame != frame->page()->mainFrame())
                     appendItem(OpenFrameInNewWindowItem);
             }
         }
     } else { // Make an editing context menu
-        SelectionController* selectionController = result.innerNonSharedNode()->document()->frame()->selectionController();
+        SelectionController* selectionController = frame->selectionController();
         bool inPasswordField = selectionController->isInPasswordField();
 
         // Add spelling-related context menu items.
-        if (true) { // FIXME: Should be (selectionController->isSelectionMisspelled() && !inPasswordField)
-            // FIXME: Add spelling guesses here
-            appendItem(NoGuessesFoundItem);
+        if (frame->isSelectionMisspelled() && !inPasswordField) {
+            Vector<String> guesses = frame->guessesForMisspelledSelection();
+            unsigned size = guesses.size();
+            if (size == 0)
+                appendItem(NoGuessesFoundItem);
+            else {
+                for (unsigned i = 0; i < size; i++) {
+                    String guess = guesses[i];
+                    if (!guess.isNull())
+                        appendItem(ContextMenuItem(ActionType, ContextMenuItemTagSpellingGuess, guess));
+                }
+            }                
 
             appendItem(SeparatorItem);
             appendItem(IgnoreSpellingItem);
index a6cce4f9eabf32bbd69666eecdf0ef5bfca176f0..1bcfd4961eb4c0ed21afce9a2602465f47686787 100644 (file)
@@ -1,3 +1,16 @@
+2006-11-27  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Adam.
+
+        WebKit half of getting rid of the FixMes in ContextMenu.cpp
+
+        * WebCoreSupport/WebFrameLoaderClient.h: canHandleRequest takes a 
+        ResourceRequest now.
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::canHandleRequest): Same.
+        * WebView/WebHTMLView.m:
+        (-[WebHTMLView _isSelectionMisspelled]): Call into WebCore.
+
 2006-11-27  Ada Chan  <adachan@apple.com>
 
         Reviewed by Adam.
index 67f40139a101a615e510e3f40cd95849a5e365ff..a2b2297114c84b7b9d7d61f5edfb341826a5bcc6 100644 (file)
@@ -41,6 +41,7 @@
 namespace WebCore {
     class String;
     class ResourceLoader;
+    class ResourceRequest;
 }
 
 typedef HashMap<RefPtr<WebCore::ResourceLoader>, WebCore::RetainPtr<WebResource> > ResourceMap;
@@ -186,7 +187,7 @@ private:
     virtual void cancelPendingArchiveLoad(WebCore::ResourceLoader*);
     virtual void clearArchivedResources();
 
-    virtual bool canHandleRequest(NSURLRequest *) const;
+    virtual bool canHandleRequest(const WebCore::ResourceRequest&) const;
     virtual bool canShowMIMEType(const WebCore::String& MIMEType) const;
     virtual bool representationExistsForURLScheme(const WebCore::String& URLScheme) const;
     virtual WebCore::String generatedMIMETypeForURLScheme(const WebCore::String& URLScheme) const;
index 850c3f8e088020feadae15deff2cad1423585ed1..982ac3ccaf7a7ec7e7e78db9691dd057268c71e7 100644 (file)
@@ -78,6 +78,7 @@
 #import <WebCore/PageState.h>
 #import <WebCore/PlatformString.h>
 #import <WebCore/ResourceLoader.h>
+#import <WebCore/ResourceRequestMac.h>
 #import <WebCore/WebCoreFrameBridge.h>
 #import <WebCore/WebCorePageState.h>
 #import <WebCore/WebDataProtocol.h>
@@ -901,9 +902,9 @@ void WebFrameLoaderClient::clearArchivedResources()
     m_archivedResourcesDeliveryTimer.stop();
 }
 
-bool WebFrameLoaderClient::canHandleRequest(NSURLRequest *request) const
+bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest& request) const
 {
-    return [WebView _canHandleRequest:request];
+    return [WebView _canHandleRequest:nsURLRequest(request)];
 }
 
 bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
index f91885a610c4b16d62c4d025ba55b0b3b9ec8ed1..4bd34fc2e1bca4c1d4befcc1be65ff5116a1dda9 100644 (file)
@@ -1743,18 +1743,9 @@ static WebHTMLView *lastHitView = nil;
 
 - (BOOL)_isSelectionMisspelled
 {
-    NSString *selectedString = [self selectedString];
-    unsigned length = [selectedString length];
-    if (length == 0) {
-        return NO;
-    }
-    NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:selectedString
-                                                                    startingAt:0
-                                                                      language:nil
-                                                                          wrap:NO
-                                                        inSpellDocumentWithTag:[[self _webView] spellCheckerDocumentTag]
-                                                                     wordCount:NULL];
-    return range.length == length;
+    if (Frame* coreFrame = core([self _frame]))
+        coreFrame->isSelectionMisspelled();
+    return NO;
 }
 
 - (NSArray *)_guessesForMisspelledSelection