WebCore:
authorbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Nov 2006 01:27:16 +0000 (01:27 +0000)
committerbdakin <bdakin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Nov 2006 01:27:16 +0000 (01:27 +0000)
        Reviewed by Adam and Beth.

        Initial cut at pushing Context Menus into WebCore. Nobody actually
        calls this code just yet.

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * page/Chrome.cpp:
        (WebCore::Chrome::addCustomContextMenuItems): Use the chrome to
        call into addContextMenuItems on the UIDelegate.
        * page/Chrome.h:
        * page/ChromeClient.h:
        * platform/ContextMenu.cpp: Added.
        (WebCore::addDefaultItems):
        (WebCore::ContextMenu::populate):
        * platform/ContextMenu.h: Added.
        (WebCore::):
        (WebCore::ContextMenuItem::ContextMenuItem):
        (WebCore::ContextMenu::ContextMenu):
        (WebCore::ContextMenu::hitTestResult):
        (WebCore::ContextMenu::platformMenuDescription):

WebKit:
        Reviewed by Adam & Beth.

        WebKit side of first cut at engine context menus. Use the client to
        call into the UIDelegate.

        * WebCoreSupport/WebChromeClient.h:
        * WebCoreSupport/WebChromeClient.mm:
        (WebChromeClient::addCustomContextMenuItems):
        * WebKit.xcodeproj/project.pbxproj:

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

12 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/page/Chrome.cpp
WebCore/page/Chrome.h
WebCore/page/ChromeClient.h
WebCore/platform/ContextMenu.cpp [new file with mode: 0644]
WebCore/platform/ContextMenu.h [new file with mode: 0644]
WebKit/ChangeLog
WebKit/WebCoreSupport/WebChromeClient.h
WebKit/WebCoreSupport/WebChromeClient.mm
WebKit/WebKit.xcodeproj/project.pbxproj

index d373066..5fb49bb 100644 (file)
@@ -1,3 +1,28 @@
+2006-11-15  Beth Dakin  <bdakin@apple.com>
+        &   Adam Roben  <aroben@apple.com>
+
+        Reviewed by Adam and Beth.
+
+        Initial cut at pushing Context Menus into WebCore. Nobody actually 
+        calls this code just yet.
+
+        * WebCore.exp:
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/Chrome.cpp:
+        (WebCore::Chrome::addCustomContextMenuItems): Use the chrome to 
+        call into addContextMenuItems on the UIDelegate.
+        * page/Chrome.h:
+        * page/ChromeClient.h:
+        * platform/ContextMenu.cpp: Added.
+        (WebCore::addDefaultItems):
+        (WebCore::ContextMenu::populate):
+        * platform/ContextMenu.h: Added.
+        (WebCore::):
+        (WebCore::ContextMenuItem::ContextMenuItem):
+        (WebCore::ContextMenu::ContextMenu):
+        (WebCore::ContextMenu::hitTestResult):
+        (WebCore::ContextMenu::platformMenuDescription):
+
 2006-11-15  Adele Peterson  <adele@apple.com>
 
         Reviewed by Hyatt.
index dab7297..e148003 100644 (file)
@@ -132,6 +132,7 @@ __ZN7WebCore10EventNames10clickEventE
 __ZN7WebCore10EventNames12keydownEventE
 __ZN7WebCore10MouseEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowEiiiiibbbbtPNS_15EventTargetNodeEPNS_9ClipboardEb
 __ZN7WebCore10StringImplD1Ev
+__ZN7WebCore11ContextMenu26setPlatformMenuDescriptionEP14NSMutableArray
 __ZN7WebCore11EditCommand7reapplyEv
 __ZN7WebCore11EditCommand7unapplyEv
 __ZN7WebCore11FrameLoader11completeURLERKNS_6StringE
@@ -393,6 +394,7 @@ __ZNK7WebCore7IntRectcv7_NSRectEv
 __ZNK7WebCore8Document5frameEv
 __ZNK7WebCore8FrameMac14selectionImageEb
 __ZNK7WebCore8FrameMac31fontAttributesForSelectionStartEv
+__ZNK7WebCore8IntPointcv8_NSPointEv
 __ZNK7WebCore9FloatRectcv7_NSRectEv
 __ZNK7WebCore9FrameTree12traverseNextEPKNS_5FrameE
 __ZNK7WebCore9FrameTree14isDescendantOfEPKNS_5FrameE
index 7a8a8a7..a4ddc0d 100644 (file)
                93AE23210AAB521B00CD8A35 /* TextEncodingRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93AE23200AAB521B00CD8A35 /* TextEncodingRegistry.cpp */; };
                93B0FD8A0A759BED0080AD44 /* StringImplMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93B0FD880A759BED0080AD44 /* StringImplMac.mm */; };
                93B0FD8B0A759BED0080AD44 /* StringMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93B0FD890A759BED0080AD44 /* StringMac.mm */; };
+               93B6A0E60B0BCA5C00F5027A /* ContextMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               93B6A0E80B0BCA6700F5027A /* ContextMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B6A0E70B0BCA6700F5027A /* ContextMenu.cpp */; };
+               93B6A0EA0B0BCA8400F5027A /* ContextMenuMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93B6A0E90B0BCA8400F5027A /* ContextMenuMac.mm */; };
                93B70D5D09EB0C7C009D8468 /* JSXMLHttpRequest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D4109EB0C7C009D8468 /* JSXMLHttpRequest.cpp */; };
                93B70D5E09EB0C7C009D8468 /* JSXMLHttpRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B70D4209EB0C7C009D8468 /* JSXMLHttpRequest.h */; };
                93B70D6109EB0C7C009D8468 /* JSXSLTProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93B70D4509EB0C7C009D8468 /* JSXSLTProcessor.cpp */; };
                93AE23200AAB521B00CD8A35 /* TextEncodingRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingRegistry.cpp; sourceTree = "<group>"; };
                93B0FD880A759BED0080AD44 /* StringImplMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringImplMac.mm; sourceTree = "<group>"; };
                93B0FD890A759BED0080AD44 /* StringMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = StringMac.mm; sourceTree = "<group>"; };
+               93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContextMenu.h; sourceTree = "<group>"; };
+               93B6A0E70B0BCA6700F5027A /* ContextMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ContextMenu.cpp; sourceTree = "<group>"; };
+               93B6A0E90B0BCA8400F5027A /* ContextMenuMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuMac.mm; sourceTree = "<group>"; };
                93B70D4109EB0C7C009D8468 /* JSXMLHttpRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSXMLHttpRequest.cpp; sourceTree = "<group>"; };
                93B70D4209EB0C7C009D8468 /* JSXMLHttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSXMLHttpRequest.h; sourceTree = "<group>"; };
                93B70D4509EB0C7C009D8468 /* JSXSLTProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSXSLTProcessor.cpp; sourceTree = "<group>"; };
                                9305001F0AF025D300FFF491 /* ClipboardAccessPolicy.h */,
                                2D90660B0665D937006B6F1A /* ClipboardMac.h */,
                                2D90660C0665D937006B6F1A /* ClipboardMac.mm */,
+                               93B6A0E90B0BCA8400F5027A /* ContextMenuMac.mm */,
                                9352087609BD453400F2038D /* CookieJar.mm */,
                                F58784F002DE375901EA4122 /* CursorMac.mm */,
                                651B4D8E09AC859F0029F1EF /* DeprecatedStringListMac.mm */,
                                65F5382009B2B55700F3DC4A /* character-sets.txt */,
                                9326DC0A09DAD5BE00AFC847 /* CharsetData.h */,
                                BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
+                               93B6A0E70B0BCA6700F5027A /* ContextMenu.cpp */,
+                               93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */,
                                9352088109BD45E900F2038D /* CookieJar.h */,
                                1A98955A0AA78149005EF5EF /* CString.cpp */,
                                1A98955B0AA78149005EF5EF /* CString.h */,
                                B27535820B053814002CE64F /* Pen.h in Headers */,
                                93C09A530B064DB3005ABD4D /* EventHandler.h in Headers */,
                                93C09C860B0657AA005ABD4D /* ScrollTypes.h in Headers */,
+                               93B6A0E60B0BCA5C00F5027A /* ContextMenu.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
-                       projectRoot = "";
-                       shouldCheckCompatibility = 1;
                        targets = (
                                93F198A508245E59001E9ABC /* WebCore */,
                                DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
                                B275358E0B053A66002CE64F /* IconMac.mm in Sources */,
                                93C09A7F0B064EEF005ABD4D /* EventHandlerMac.mm in Sources */,
                                93C09A810B064F00005ABD4D /* EventHandler.cpp in Sources */,
+                               93B6A0E80B0BCA6700F5027A /* ContextMenu.cpp in Sources */,
+                               93B6A0EA0B0BCA8400F5027A /* ContextMenuMac.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 0920e06..91cd295 100644 (file)
@@ -170,5 +170,10 @@ void Chrome::setResizable(bool b) const
     m_client->setResizable(b);
 }
 
+void Chrome::addCustomContextMenuItems(ContextMenu* defaultMenu) const
+{
+    m_client->addCustomContextMenuItems(defaultMenu);
+}
+
 } // namespace WebCore
 
index 05d17a6..55643a2 100644 (file)
@@ -27,6 +27,7 @@
 namespace WebCore {
 
     class ChromeClient;
+    class ContextMenu;
     class FloatRect;
     class Page;
     struct FrameLoadRequest;
@@ -69,6 +70,8 @@ namespace WebCore {
         
         void setResizable(bool) const;
 
+        void addCustomContextMenuItems(ContextMenu*) const;
+
     private:
         Page* m_page;
         RefPtr<ChromeClient> m_client;
index 387a4ae..09ae2d0 100644 (file)
 
 namespace WebCore {
 
+    class ContextMenu;
     class FloatRect;
     class Page;
+
     struct FrameLoadRequest;
     
     class ChromeClient : public AbstractShared {
@@ -61,6 +63,8 @@ namespace WebCore {
         virtual bool menubarVisible() = 0;
 
         virtual void setResizable(bool) = 0;
+
+        virtual void addCustomContextMenuItems(ContextMenu*) = 0;
 };
 
 }
diff --git a/WebCore/platform/ContextMenu.cpp b/WebCore/platform/ContextMenu.cpp
new file mode 100644 (file)
index 0000000..3e05feb
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "ContextMenu.h"
+
+#include "Chrome.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "KURL.h"
+#include "Node.h"
+#include "Page.h"
+#include "SelectionController.h"
+
+namespace WebCore {
+
+#define MENU_ACTION_ITEM(action, title) static ContextMenuItem action##Item(ActionType, WebMenuItemTag##action, String(title))
+
+static void addDefaultItems(ContextMenu* menu)
+{
+    MENU_ACTION_ITEM(OpenLinkInNewWindow, "Open Link in New Window");
+    MENU_ACTION_ITEM(DownloadLinkToDisk, "Download Linked File");
+    MENU_ACTION_ITEM(CopyLinkToClipboard, "Copy Link");
+    MENU_ACTION_ITEM(OpenImageInNewWindow, "Open Image in New Window");
+    MENU_ACTION_ITEM(DownloadImageToDisk, "Download Image");
+    MENU_ACTION_ITEM(CopyImageToClipboard, "Copy Image");
+    MENU_ACTION_ITEM(OpenFrameInNewWindow, "Open Frame in New Window");
+    MENU_ACTION_ITEM(Copy, "Copy");
+    MENU_ACTION_ITEM(GoBack, "Back");
+    MENU_ACTION_ITEM(GoForward, "Forward");
+    MENU_ACTION_ITEM(Stop, "Stop");
+    MENU_ACTION_ITEM(Reload, "Reload");
+    MENU_ACTION_ITEM(Cut, "Cut");
+    MENU_ACTION_ITEM(Paste, "Paste");
+    MENU_ACTION_ITEM(SpellingGuess, "");
+    MENU_ACTION_ITEM(NoGuessesFound, "No Guesses Found");
+    MENU_ACTION_ITEM(IgnoreSpelling, "Ignore Spelling");
+    MENU_ACTION_ITEM(LearnSpelling, "Learn Spelling");
+    #if PLATFORM(MAC)
+    MENU_ACTION_ITEM(SearchInSpotlight, "Search in Spotlight");
+    #endif
+    MENU_ACTION_ITEM(SearchWeb, "Search in Google");
+    MENU_ACTION_ITEM(LookUpInDictionary, "Look Up in Dictionary");
+    // FIXME: Add PDF action items
+
+    ContextMenuItem SeparatorItem(SeparatorType, WebMenuItemTagNoAction, String());
+    HitTestResult result = menu->hitTestResult();
+
+    if (!result.isContentEditable()) {
+        KURL linkURL = result.absoluteLinkURL();
+        if (!linkURL.isEmpty()) {
+            if (true) { // FIXME: if FrameLoaderClient can handle the request
+                menu->appendItem(OpenLinkInNewWindowItem);
+                menu->appendItem(DownloadLinkToDiskItem);
+            }
+            menu->appendItem(CopyLinkToClipboardItem);
+        }
+
+        KURL imageURL = result.absoluteImageURL();
+        if (!imageURL.isEmpty()) {
+            if (!linkURL.isEmpty())
+                menu->appendItem(SeparatorItem);
+
+            menu->appendItem(OpenImageInNewWindowItem);
+            menu->appendItem(DownloadImageToDiskItem);
+            if (imageURL.isLocalFile())
+                menu->appendItem(CopyImageToClipboardItem);
+        }
+
+        if (imageURL.isEmpty() && linkURL.isEmpty()) {
+            if (result.isSelected()) {
+    #if PLATFORM(MAC)
+                menu->appendItem(SearchInSpotlightItem);
+    #endif
+                menu->appendItem(SearchWebItem);
+                menu->appendItem(SeparatorItem);
+                menu->appendItem(LookUpInDictionaryItem);
+                menu->appendItem(SeparatorItem);
+                menu->appendItem(CopyItem);
+            } else {
+                FrameLoader* loader = result.innerNonSharedNode()->document()->frame()->loader();
+                if (loader->canGoBackOrForward(-1))
+                    menu->appendItem(GoBackItem);
+
+                if (loader->canGoBackOrForward(1))
+                    menu->appendItem(GoForwardItem);
+                
+                if (loader->isLoading())
+                    menu->appendItem(StopItem);
+                else
+                    menu->appendItem(ReloadItem);
+
+                if (result.innerNonSharedNode()->document()->frame() != result.innerNonSharedNode()->document()->frame()->page()->mainFrame())
+                    menu->appendItem(OpenFrameInNewWindowItem);
+            }
+        }
+    } else { // Make an editing context menu
+        SelectionController* selectionController = result.innerNonSharedNode()->document()->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
+            menu->appendItem(NoGuessesFoundItem);
+
+            menu->appendItem(SeparatorItem);
+            menu->appendItem(IgnoreSpellingItem);
+            menu->appendItem(LearnSpellingItem);
+            menu->appendItem(SeparatorItem);
+        }
+
+        if (result.isSelected() && !inPasswordField) {
+    #if PLATFORM(MAC)
+            menu->appendItem(SearchInSpotlightItem);
+    #endif
+            menu->appendItem(SearchWebItem);
+            menu->appendItem(SeparatorItem);
+     
+            menu->appendItem(LookUpInDictionaryItem);
+            menu->appendItem(SeparatorItem);
+        }
+        
+        menu->appendItem(CutItem);
+        menu->appendItem(CopyItem);
+        menu->appendItem(PasteItem);
+        menu->appendItem(SeparatorItem);
+
+        // FIXME: Add "Spelling [and Grammar, on Leopard]", "Font", "Speech", "Writing Direction" submenus here.
+    }
+}
+
+void ContextMenu::populate()
+{
+    addDefaultItems(this);
+    if (Frame* frame = m_hitTestResult.innerNonSharedNode()->document()->frame())
+        if (Page* page = frame->page())
+            page->chrome()->addCustomContextMenuItems(this);
+}
+
+}
diff --git a/WebCore/platform/ContextMenu.h b/WebCore/platform/ContextMenu.h
new file mode 100644 (file)
index 0000000..0db930e
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef ContextMenu_h
+#define ContextMenu_h
+
+#include "HitTestResult.h"
+#include "PlatformString.h"
+
+#if PLATFORM(MAC)
+#ifdef __OBJC__
+@class NSMutableArray;
+#else
+class NSMutableArray;
+#endif
+#elif PLATFORM(WIN)
+typedef struct HMENU__* HMENU;
+#endif
+
+namespace WebCore {
+
+// This enum needs to be in sync with WebMenuItemTag, which is defined in WebUIDelegate.h
+enum ContextMenuAction {
+    WebMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
+    WebMenuItemTagOpenLinkInNewWindow=1,
+    WebMenuItemTagDownloadLinkToDisk,
+    WebMenuItemTagCopyLinkToClipboard,
+    WebMenuItemTagOpenImageInNewWindow,
+    WebMenuItemTagDownloadImageToDisk,
+    WebMenuItemTagCopyImageToClipboard,
+    WebMenuItemTagOpenFrameInNewWindow,
+    WebMenuItemTagCopy,
+    WebMenuItemTagGoBack,
+    WebMenuItemTagGoForward,
+    WebMenuItemTagStop,
+    WebMenuItemTagReload,
+    WebMenuItemTagCut,
+    WebMenuItemTagPaste,
+    WebMenuItemTagSpellingGuess,
+    WebMenuItemTagNoGuessesFound,
+    WebMenuItemTagIgnoreSpelling,
+    WebMenuItemTagLearnSpelling,
+    WebMenuItemTagOther,
+    WebMenuItemTagSearchInSpotlight,
+    WebMenuItemTagSearchWeb,
+    WebMenuItemTagLookUpInDictionary,
+    WebMenuItemTagOpenWithDefaultApplication,
+    WebMenuItemPDFActualSize,
+    WebMenuItemPDFZoomIn,
+    WebMenuItemPDFZoomOut,
+    WebMenuItemPDFAutoSize,
+    WebMenuItemPDFSinglePage,
+    WebMenuItemPDFFacingPages,
+    WebMenuItemPDFContinuous,
+    WebMenuItemPDFNextPage,
+    WebMenuItemPDFPreviousPage,
+};
+
+enum ContextMenuItemType {
+    ActionType,
+    SeparatorType,
+    SubmenuType
+};
+
+struct ContextMenuItem {
+    ContextMenuItem()
+        : type(SeparatorType)
+        , action(WebMenuItemTagNoAction)
+        , title(String())
+    {
+    }
+
+    ContextMenuItem(ContextMenuItemType theType, ContextMenuAction theAction, const String& theTitle)
+        : type(theType)
+        , action(theAction)
+        , title(theTitle)
+    {
+    }
+
+    // FIXME: Need to support submenus (perhaps a Vector<ContextMenuItem>*?)
+    // FIXME: Do we need a keyboard accelerator here?
+
+    ContextMenuItemType type;
+    ContextMenuAction action;
+    String title;
+};
+
+#if PLATFORM(MAC)
+typedef NSMutableArray* PlatformMenuDescription;
+#elif PLATFORM(WIN)
+typedef HMENU PlatformMenuDescription;
+#endif
+
+class ContextMenu : Noncopyable
+{
+public:
+    ContextMenu(HitTestResult result)
+        : m_hitTestResult(result)
+        , m_menu(0)
+    {
+    }
+
+    void populate();
+
+    void show();
+    void hide();
+
+    void insertItem(unsigned position, ContextMenuItem);
+    void appendItem(ContextMenuItem item);
+
+    unsigned itemCount();
+
+    HitTestResult hitTestResult() const { return m_hitTestResult; }
+
+    PlatformMenuDescription platformMenuDescription() { return m_menu; }
+    void setPlatformMenuDescription(PlatformMenuDescription menu);
+
+private:
+    HitTestResult m_hitTestResult;
+    PlatformMenuDescription m_menu;
+};
+
+}
+
+#endif // ContextMenu_h
index a374a25..fbbb333 100644 (file)
@@ -1,3 +1,16 @@
+2006-11-15  Beth Dakin  <bdakin@apple.com>
+        &   Adam Roben  <aroben@apple.com>
+
+        Reviewed by Adam & Beth.
+
+        WebKit side of first cut at engine context menus. Use the client to 
+        call into the UIDelegate.
+
+        * WebCoreSupport/WebChromeClient.h:
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::addCustomContextMenuItems):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2006-11-15  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Maciej
index 2e1572f..237fac7 100644 (file)
@@ -71,6 +71,8 @@ public:
     virtual bool menubarVisible();
     
     virtual void setResizable(bool);
+    
+    virtual void addCustomContextMenuItems(WebCore::ContextMenu*);
 
 private:
     WebChromeClient(WebView *webView);
index 9e9bd57..1e8e9c8 100644 (file)
 #import "WebChromeClient.h"
 
 #import "WebDefaultUIDelegate.h"
+#import "WebElementDictionary.h"
 #import "WebFrameInternal.h"
 #import "WebFrameView.h"
 #import "WebNSURLRequestExtras.h"
 #import "WebUIDelegate.h"
 #import "WebView.h"
 #import "WebViewInternal.h"
+#import <WebCore/ContextMenu.h>
 #import <WebCore/FloatRect.h>
 #import <WebCore/FrameLoadRequest.h>
 #import <WebCore/ResourceRequestMac.h>
@@ -201,3 +203,14 @@ void WebChromeClient::setResizable(bool b)
 {
     [[m_webView _UIDelegateForwarder] webView:m_webView setResizable:b];
 }
+
+void WebChromeClient::addCustomContextMenuItems(ContextMenu* menu)
+{
+    id delegate = [m_webView UIDelegate];
+    if ([delegate respondsToSelector:@selector(webView:contextMenuItemsForElement:defaultMenuItems:)]) {
+        NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:menu->hitTestResult()] autorelease];
+        NSArray *newMenu = [delegate webView:m_webView contextMenuItemsForElement:element defaultMenuItems:menu->platformMenuDescription()];
+        menu->setPlatformMenuDescription(newMenu);
+    }
+}
+
index 0310b81..b5e66a3 100644 (file)
                        mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
-                       projectRoot = "";
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );