Commit 8254b19d authored by bdakin's avatar bdakin

WebCore:

        Reviewed by Adam.

        Implementation of actions for the new context menus.

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj:
        * bridge/EditorClient.h: Declaration of shouldInsertText.
        * bridge/mac/FrameMac.h: Two new spelling functions.
        * bridge/mac/FrameMac.mm:
        (WebCore::FrameMac::ignoreSpelling):
        (WebCore::FrameMac::learnSpelling):
        * editing/Editor.cpp:
        (WebCore::Editor::shouldInsertText): Call into the client.
        * editing/Editor.h:
        * editing/EditorInsertAction.h: Added.
        (WebCore::): The WebCore equivalent of WebViewInsertAction. This is 
        defined in its own header so that we can use it from Editor.h and 
        EditorClient.h without having one of the above include the other.
        * page/ContextMenuClient.h: A few currently WebKit-implemented 
        function needed for menu actions.
        * page/ContextMenuController.cpp:
        (WebCore::makeGoogleSearchURL):
        (WebCore::ContextMenuController::contextMenuActionSelected): The 
        actions!
        * page/ContextMenuController.h:
        * page/Frame.h: New pure-virtual spelling functions.
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::controller): Get the controller from the 
        menu.
        * platform/ContextMenu.h:
        * platform/mac/ContextMenuMac.mm:
        (-[MenuTarget 
        forwardContextMenuAction:initWithContextMenuController:WebCore::]): 
        Use the controller instead of the menu
        (-[MenuTarget WebCore::]):
        (-[MenuTarget setMenuController:WebCore::]):
        (-[MenuTarget forwardContextMenuAction:]):
        (getNSMenuItem):
        (ContextMenu::show):
        (ContextMenu::hide):

WebKit:
        Reviewed by Adam.

        WebKit side of new context menu actions.

        * WebCoreSupport/WebContextMenuClient.h: These are for the 
        currently-WebKit-dependent menu actions.
        * WebCoreSupport/WebContextMenuClient.mm:
        (WebContextMenuClient::copyLinkToClipboard):
        (WebContextMenuClient::downloadURL):
        (WebContextMenuClient::copyImageToClipboard):
        (WebContextMenuClient::searchWithSpotlight):
        (WebContextMenuClient::lookUpInDictionary):
        * WebCoreSupport/WebEditorClient.h:
        * WebCoreSupport/WebEditorClient.mm:
        (core): These are to convert between WebViewInsertAction and 
        EditorInsertAction.
        (kit):
        (WebEditorClient::shouldInsertText): Added implementation for 
        shouldInsertText.
        * WebKit.xcodeproj/project.pbxproj:
        * WebView/WebHTMLView.m:
        (-[WebHTMLView _lookUpInDictionaryFromMenu:]): Moved 
        _lookUpInDictionary to be within the implementation of WebHTMLView 
        internal.
        * WebView/WebHTMLViewInternal.h: Add _lookUpInDictionaryFromMenu
        * WebView/WebViewInternal.h: Add _searchWithSpotlightFromMenu


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17855 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e71d1ae9
2006-11-19 Beth Dakin <bdakin@apple.com>
Reviewed by Adam.
Implementation of actions for the new context menus.
* WebCore.exp:
* WebCore.xcodeproj/project.pbxproj:
* bridge/EditorClient.h: Declaration of shouldInsertText.
* bridge/mac/FrameMac.h: Two new spelling functions.
* bridge/mac/FrameMac.mm:
(WebCore::FrameMac::ignoreSpelling):
(WebCore::FrameMac::learnSpelling):
* editing/Editor.cpp:
(WebCore::Editor::shouldInsertText): Call into the client.
* editing/Editor.h:
* editing/EditorInsertAction.h: Added.
(WebCore::): The WebCore equivalent of WebViewInsertAction. This is
defined in its own header so that we can use it from Editor.h and
EditorClient.h without having one of the above include the other.
* page/ContextMenuClient.h: A few currently WebKit-implemented
function needed for menu actions.
* page/ContextMenuController.cpp:
(WebCore::makeGoogleSearchURL):
(WebCore::ContextMenuController::contextMenuActionSelected): The
actions!
* page/ContextMenuController.h:
* page/Frame.h: New pure-virtual spelling functions.
* platform/ContextMenu.cpp:
(WebCore::ContextMenu::controller): Get the controller from the
menu.
* platform/ContextMenu.h:
* platform/mac/ContextMenuMac.mm:
(-[MenuTarget
forwardContextMenuAction:initWithContextMenuController:WebCore::]):
Use the controller instead of the menu
(-[MenuTarget WebCore::]):
(-[MenuTarget setMenuController:WebCore::]):
(-[MenuTarget forwardContextMenuAction:]):
(getNSMenuItem):
(ContextMenu::show):
(ContextMenu::hide):
2006-11-19 Simon Hausmann <hausmann@kde.org>
Reviewed by Zack.
......@@ -394,7 +394,6 @@ __ZNK7WebCore7IntRectcv7_NSRectEv
__ZNK7WebCore8Document5frameEv
__ZNK7WebCore8FrameMac14selectionImageEb
__ZNK7WebCore8FrameMac31fontAttributesForSelectionStartEv
__ZNK7WebCore8IntPointcv8_NSPointEv
__ZNK7WebCore9FloatRectcv7_NSRectEv
__ZNK7WebCore9FrameTree12traverseNextEPKNS_5FrameE
__ZNK7WebCore9FrameTree14isDescendantOfEPKNS_5FrameE
......
......@@ -1621,6 +1621,7 @@
93F19B1608245E59001E9ABC /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* JavaScriptCore.framework */; };
93F19B1708245E59001E9ABC /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F1D31A0558CC5C00821BC0 /* libicucore.dylib */; };
93F19B1808245E59001E9ABC /* libxslt.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 840633070731A77200DB1FD1 /* libxslt.dylib */; };
93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FDAFC90B11307400E2746F /* EditorInsertAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
A70023FD0B02BEAB00170215 /* MimeTypeRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70023FB0B02BEAB00170215 /* MimeTypeRegistry.cpp */; };
A70023FE0B02BEAB00170215 /* MimeTypeRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = A70023FC0B02BEAB00170215 /* MimeTypeRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
A70024000B02BECC00170215 /* MimeTypeRegistryMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A70023FF0B02BECC00170215 /* MimeTypeRegistryMac.mm */; };
......@@ -4530,6 +4531,7 @@
93F8B3060A300FEA00F61AB8 /* CodeGeneratorJS.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = CodeGeneratorJS.pm; path = ../scripts/CodeGeneratorJS.pm; sourceTree = "<group>"; };
93F8B3070A300FEA00F61AB8 /* generate-bindings.pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = "generate-bindings.pl"; path = "scripts/generate-bindings.pl"; sourceTree = "<group>"; };
93F8B3080A300FEA00F61AB8 /* IDLStructure.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = IDLStructure.pm; path = scripts/IDLStructure.pm; sourceTree = "<group>"; };
93FDAFC90B11307400E2746F /* EditorInsertAction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorInsertAction.h; sourceTree = "<group>"; };
A70023FB0B02BEAB00170215 /* MimeTypeRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MimeTypeRegistry.cpp; sourceTree = "<group>"; };
A70023FC0B02BEAB00170215 /* MimeTypeRegistry.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MimeTypeRegistry.h; sourceTree = "<group>"; };
A70023FF0B02BECC00170215 /* MimeTypeRegistryMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = MimeTypeRegistryMac.mm; sourceTree = "<group>"; };
......@@ -7596,6 +7598,7 @@
93309D95099E64910056E581 /* EditCommand.h */,
4B3043CA0AE0373B00A82647 /* Editor.cpp */,
4B3043CB0AE0373B00A82647 /* Editor.h */,
93FDAFC90B11307400E2746F /* EditorInsertAction.h */,
93309D98099E64910056E581 /* htmlediting.cpp */,
93309D99099E64910056E581 /* htmlediting.h */,
93309D96099E64910056E581 /* HTMLInterchange.cpp */,
......@@ -10798,6 +10801,7 @@
B2E27C9B0B0F2AE600F17C7B /* SVGPointLightSource.h in Headers */,
B2E27C9C0B0F2AE600F17C7B /* SVGSpotLightSource.h in Headers */,
B2E27CA00B0F2B0900F17C7B /* FloatPoint3D.h in Headers */,
93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -29,11 +29,14 @@
#include <wtf/Forward.h>
#include "AbstractShared.h"
#include "EditorInsertAction.h"
namespace WebCore {
class CSSStyleDeclaration;
class EditCommand;
class HTMLElement;
class String;
class Range;
class EditorClient : public AbstractShared {
......@@ -51,7 +54,7 @@ public:
virtual bool shouldBeginEditing(Range*) = 0;
virtual bool shouldEndEditing(Range*) = 0;
// virtual bool shouldInsertNode(Node*, Range* replacingRange, WebViewInsertAction) = 0;
// virtual bool shouldInsertText(NSString*, Range *replacingRange, WebViewInsertAction) = 0;
virtual bool shouldInsertText(String, Range*, EditorInsertAction) = 0;
// virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, NSSelectionAffinity, bool stillSelecting) = 0;
virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) = 0;
// virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle) = 0;
......
......@@ -166,6 +166,8 @@ public:
NSWritingDirection baseWritingDirectionForSelectionStart() const;
virtual void ignoreSpelling();
virtual void learnSpelling();
virtual void markMisspellingsInAdjacentWords(const VisiblePosition&);
virtual void markMisspellings(const Selection&);
......
......@@ -105,6 +105,10 @@
@end
#endif
@interface NSSpellChecker (CurrentlyPrivateForTextView)
- (void)learnWord:(NSString *)word;
@end
using namespace std;
using namespace KJS::Bindings;
......@@ -1147,6 +1151,21 @@ void FrameMac::issueTransposeCommand()
[_bridge issueTransposeCommand];
}
void FrameMac::ignoreSpelling()
{
String text = selectedText();
ASSERT(text.length() != 0);
[[NSSpellChecker sharedSpellChecker] ignoreWord:text
inSpellDocumentWithTag:editor()->client()->spellCheckerDocumentTag()];
}
void FrameMac::learnSpelling()
{
String text = selectedText();
ASSERT(text.length() != 0);
[[NSSpellChecker sharedSpellChecker] learnWord:text];
}
void FrameMac::markMisspellingsInAdjacentWords(const VisiblePosition &p)
{
if (!editor()->client()->isContinuousSpellCheckingEnabled())
......
......@@ -188,6 +188,11 @@ void Editor::writeSelectionToPasteboard(Pasteboard pasteboard)
{
}
bool Editor::shouldInsertText(String text, Range* range, EditorInsertAction action) const
{
return m_client->shouldInsertText(text, range, action);
}
bool Editor::shouldShowDeleteInterface(HTMLElement* element) const
{
return m_client->shouldShowDeleteInterface(element);
......
......@@ -26,6 +26,7 @@
#ifndef Editor_h
#define Editor_h
#include "EditorInsertAction.h"
#include "Frame.h"
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
......@@ -70,6 +71,7 @@ public:
void indent();
void outdent();
bool shouldInsertText(String, Range*, EditorInsertAction) const;
bool shouldShowDeleteInterface(HTMLElement*) const;
bool shouldDeleteRange(Range*) const;
......
/*
* 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 EditorInsertAction_h
#define EditorInsertAction_h
namespace WebCore {
// This must be kept in sync with WebViewInsertAction defined in WebEditingDelegate.h
enum EditorInsertAction {
EditorInsertActionTyped,
EditorInsertActionPasted,
EditorInsertActionDropped,
};
} // namespace
#endif
......@@ -30,10 +30,22 @@
namespace WebCore {
class ContextMenu;
class Frame;
class HitTestResult;
class KURL;
class ContextMenuClient : public AbstractShared {
public:
virtual void addCustomContextMenuItems(ContextMenu*) = 0;
virtual void copyLinkToClipboard(HitTestResult) = 0;
virtual void downloadURL(KURL url) = 0;
virtual void copyImageToClipboard(HitTestResult) = 0;
virtual void lookUpInDictionary(Frame*) = 0;
#if PLATFORM(MAC)
virtual void searchWithSpotlight() = 0;
#endif
};
}
......
......@@ -28,14 +28,27 @@
#include "ContextMenu.h"
#include "ContextMenuClient.h"
#include "Document.h"
#include "DocumentFragment.h"
#include "DocumentLoader.h"
#include "Editor.h"
#include "EditorClient.h"
#include "Event.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoadRequest.h"
#include "HitTestRequest.h"
#include "HitTestResult.h"
#include "KURL.h"
#include "MouseEvent.h"
#include "Node.h"
#include "Page.h"
#include "RenderLayer.h"
#include "RenderObject.h"
#include "ReplaceSelectionCommand.h"
#include "ResourceRequest.h"
#include "markup.h"
namespace WebCore {
......@@ -71,9 +84,136 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
m_contextMenu->show();
}
void ContextMenuController::contextMenuActionSelected(ContextMenuAction action)
static String makeGoogleSearchURL(String searchString)
{
// FIXME: Implement this
searchString.stripWhiteSpace();
DeprecatedString encoded = KURL::encode_string(searchString.deprecatedString());
encoded.replace(DeprecatedString("%20"), DeprecatedString("+"));
String url("http://www.google.com/search?client=safari&q=");
url.append(String(encoded));
url.append("&ie=UTF-8&oe=UTF-8");
return url;
}
void ContextMenuController::contextMenuActionSelected(ContextMenuAction action, String title)
{
Frame* frame = m_contextMenu->hitTestResult().innerNonSharedNode()->document()->frame();
if (!frame)
return;
ASSERT(m_page == frame->page());
switch (action) {
case ContextMenuItemTagOpenLinkInNewWindow: {
ResourceRequest request = ResourceRequest(m_contextMenu->hitTestResult().absoluteLinkURL());
String referrer = frame->loader()->referrer();
m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
break;
}
case ContextMenuItemTagDownloadLinkToDisk:
// FIXME: Some day we should be able to do this from within WebCore.
m_client->downloadURL(m_contextMenu->hitTestResult().absoluteLinkURL());
break;
case ContextMenuItemTagCopyLinkToClipboard:
// FIXME: The Pasteboard class is not written yet. This is what we should be able to do some day:
// generalPasteboard()->copy(m_contextMenu->hitTestResult().absoluteLinkURL(),
// m_contextMenu->hitTestResult.textContent());
// For now, call into the client. This is temporary!
m_client->copyLinkToClipboard(m_contextMenu->hitTestResult());
break;
case ContextMenuItemTagOpenImageInNewWindow: {
ResourceRequest request = ResourceRequest(m_contextMenu->hitTestResult().absoluteImageURL());
String referrer = frame->loader()->referrer();
m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
break;
}
case ContextMenuItemTagDownloadImageToDisk:
// FIXME: Some day we should be able to do this from within WebCore.
m_client->downloadURL(m_contextMenu->hitTestResult().absoluteImageURL());
break;
case ContextMenuItemTagCopyImageToClipboard:
// FIXME: The Pasteboard class is not written yet
// For now, call into the client. This is temporary!
m_client->copyImageToClipboard(m_contextMenu->hitTestResult());
break;
case ContextMenuItemTagOpenFrameInNewWindow: {
// FIXME: The DocumentLoader is all-Mac right now
#if PLATFORM(MAC)
KURL unreachableURL = frame->loader()->documentLoader()->unreachableURL();
if (frame && unreachableURL.isEmpty())
unreachableURL = frame->loader()->documentLoader()->URL();
ResourceRequest request = ResourceRequest(unreachableURL);
String referrer = frame->loader()->referrer();
if (m_page)
m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
#endif
break;
}
case ContextMenuItemTagCopy:
frame->editor()->copy();
break;
case ContextMenuItemTagGoBack:
frame->loader()->goBackOrForward(-1);
break;
case ContextMenuItemTagGoForward:
frame->loader()->goBackOrForward(1);
break;
case ContextMenuItemTagStop:
frame->loader()->stop();
break;
case ContextMenuItemTagReload:
frame->loader()->reload();
break;
case ContextMenuItemTagCut:
frame->editor()->cut();
break;
case ContextMenuItemTagPaste:
frame->editor()->paste();
break;
case ContextMenuItemTagSpellingGuess:
ASSERT(frame->selectedText().length() != 0);
if (frame->editor()->shouldInsertText(title, frame->selectionController()->toRange().get(), EditorInsertActionPasted)) {
Document* document = frame->document();
applyCommand(new ReplaceSelectionCommand(document, createFragmentFromMarkup(document, title, ""),
true, false, true));
frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
break;
case ContextMenuItemTagIgnoreSpelling:
frame->ignoreSpelling();
break;
case ContextMenuItemTagLearnSpelling:
frame->learnSpelling();
break;
case ContextMenuItemTagSearchInSpotlight:
#if PLATFORM(MAC)
m_client->searchWithSpotlight();
#endif
break;
case ContextMenuItemTagSearchWeb: {
String url = makeGoogleSearchURL(frame->selectedText());
ResourceRequest request = ResourceRequest(url);
frame->loader()->urlSelected(FrameLoadRequest(request), new Event());
break;
}
case ContextMenuItemTagLookUpInDictionary:
// FIXME: Some day we may be able to do this from within WebCore.
m_client->lookUpInDictionary(frame);
break;
// PDF actions. Let's take care of this later.
case ContextMenuItemTagOpenWithDefaultApplication:
case ContextMenuItemPDFActualSize:
case ContextMenuItemPDFZoomIn:
case ContextMenuItemPDFZoomOut:
case ContextMenuItemPDFAutoSize:
case ContextMenuItemPDFSinglePage:
case ContextMenuItemPDFFacingPages:
case ContextMenuItemPDFContinuous:
case ContextMenuItemPDFNextPage:
case ContextMenuItemPDFPreviousPage:
default:
break;
}
}
} // namespace WebCore
......
......@@ -48,7 +48,7 @@ namespace WebCore {
ContextMenuClient* client() { return m_client.get(); }
void handleContextMenuEvent(Event*);
void contextMenuActionSelected(ContextMenuAction);
void contextMenuActionSelected(ContextMenuAction, String);
private:
Page* m_page;
......
......@@ -258,6 +258,8 @@ public:
void applyEditingStyleToElement(Element*) const;
void removeEditingStyleFromElement(Element*) const;
virtual void ignoreSpelling() = 0;
virtual void learnSpelling() = 0;
virtual void markMisspellingsInAdjacentWords(const VisiblePosition&) = 0;
virtual void markMisspellings(const Selection&) = 0;
virtual Range* markedTextRange() const = 0;
......
......@@ -39,6 +39,15 @@ namespace WebCore {
#define MENU_ACTION_ITEM(action, title) static ContextMenuItem action##Item(ActionType, ContextMenuItemTag##action, String(title))
ContextMenuController* ContextMenu::controller() const
{
if (Node* node = m_hitTestResult.innerNonSharedNode())
if (Frame* frame = node->document()->frame())
if (Page* page = frame->page())
return page->contextMenuController();
return 0;
}
void ContextMenu::populate()
{
MENU_ACTION_ITEM(OpenLinkInNewWindow, "Open Link in New Window");
......
......@@ -43,6 +43,8 @@ class QMenu;
namespace WebCore {
class ContextMenuController;
// This enum needs to be in sync with WebMenuItemTag, which is defined in WebUIDelegate.h
enum ContextMenuAction {
ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
......@@ -128,9 +130,8 @@ public:
void populate();
// FIXME: Implement these
void show() {}
void hide() {}
void show();
void hide();
void insertItem(unsigned position, ContextMenuItem);
void appendItem(ContextMenuItem item);
......@@ -138,6 +139,7 @@ public:
unsigned itemCount();
HitTestResult hitTestResult() const { return m_hitTestResult; }
ContextMenuController* controller() const;
PlatformMenuDescription platformMenuDescription() { return m_menu; }
void setPlatformMenuDescription(PlatformMenuDescription menu);
......
......@@ -25,39 +25,43 @@
#include "config.h"
#include "ContextMenu.h"
#include "ContextMenuController.h"
@interface MenuTarget : NSObject {
WebCore::ContextMenu* _menu;
WebCore::ContextMenuController* _menuController;
}
- (WebCore::ContextMenu*)menu;
- (void)setMenu:(WebCore::ContextMenu*)menu;
- (WebCore::ContextMenuController*)menuController;
- (void)setMenuController:(WebCore::ContextMenuController*)menuController;
- (void)forwardContextMenuAction:(id)sender;
@end
@implementation MenuTarget
- (id)initWithContextMenu:(WebCore::ContextMenu*)menu
- (id)initWithContextMenuController:(WebCore::ContextMenuController*)menuController
{
self = [super init];
if (!self)
return nil;
_menu = menu;
_menuController = menuController;
return self;
}
- (WebCore::ContextMenu*)menu
- (WebCore::ContextMenuController*)menuController
{
return _menu;
return _menuController;
}
- (void)setMenu:(WebCore::ContextMenu*)menu
- (void)setMenuController:(WebCore::ContextMenuController*)menuController
{
_menu = menu;
_menuController = menuController;
}
- (void)forwardContextMenuAction:(id)sender
{
WebCore::ContextMenuAction action = static_cast<WebCore::ContextMenuAction>([sender tag]);
_menuController->contextMenuActionSelected(action, [sender title]);
}
@end
......@@ -71,10 +75,11 @@ static NSMenuItem* getNSMenuItem(ContextMenu* menu, ContextMenuItem item)
if (!menu->platformMenuDescription())
menu->setPlatformMenuDescription([[[NSMutableArray alloc] init] autorelease]);
ContextMenuController* currentController = menu->controller();
if (!target)
target = [[MenuTarget alloc] initWithContextMenu:menu];
else if (menu != [target menu])
[target setMenu:menu];
target = [[MenuTarget alloc] initWithContextMenuController:currentController];
else if (currentController != [target menuController])
[target setMenuController:currentController];
NSMenuItem* menuItem = [[[NSMenuItem alloc] init] autorelease];
[menuItem setTag: item.action];
......@@ -106,3 +111,11 @@ void ContextMenu::setPlatformMenuDescription(NSMutableArray* menu)
{
m_menu = menu;
}
void ContextMenu::show()
{
}
void ContextMenu::hide()
{
}
2006-11-19 Beth Dakin <bdakin@apple.com>
Reviewed by Adam.
WebKit side of new context menu actions.
* WebCoreSupport/WebContextMenuClient.h: These are for the
currently-WebKit-dependent menu actions.
* WebCoreSupport/WebContextMenuClient.mm:
(WebContextMenuClient::copyLinkToClipboard):
(WebContextMenuClient::downloadURL):
(WebContextMenuClient::copyImageToClipboard):
(WebContextMenuClient::searchWithSpotlight):
(WebContextMenuClient::lookUpInDictionary):
* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(core): These are to convert between WebViewInsertAction and
EditorInsertAction.
(kit):
(WebEditorClient::shouldInsertText): Added implementation for
shouldInsertText.
* WebKit.xcodeproj/project.pbxproj:
* WebView/WebHTMLView.m:
(-[WebHTMLView _lookUpInDictionaryFromMenu:]): Moved
_lookUpInDictionary to be within the implementation of WebHTMLView
internal.
* WebView/WebHTMLViewInternal.h: Add _lookUpInDictionaryFromMenu
* WebView/WebViewInternal.h: Add _searchWithSpotlightFromMenu
2006-11-18 Don Gibson <dgibson77@gmail.com>
Reviewed by Sam Weinig.
......
......@@ -40,6 +40,12 @@ public:
virtual void deref();
virtual void addCustomContextMenuItems(WebCore::ContextMenu* menu);
virtual void copyLinkToClipboard(WebCore::HitTestResult);
virtual void downloadURL(WebCore::KURL url);
virtual void copyImageToClipboard(WebCore::HitTestResult);
virtual void searchWithSpotlight();
virtual void lookUpInDictionary(WebCore::Frame*);
WebView *webView() { return m_webView; }
......
......@@ -30,9 +30,15 @@
#import "WebElementDictionary.h"
#import "WebFrame.h"
#import "WebFrameInternal.h"
#import "WebHTMLView.h"
#import "WebHTMLViewInternal.h"
#import "WebNSPasteboardExtras.h"
#import "WebUIDelegate.h"
#import "WebView.h"
#import "WebViewInternal.h"
#import <WebCore/ContextMenu.h>
#import <WebCore/KURL.h>
using namespace WebCore;
......@@ -65,3 +71,39 @@ void WebContextMenuClient::addCustomContextMenuItems(ContextMenu* menu)
menu->setPlatformMenuDescription(newMenu);
}
}
void WebContextMenuClient::copyLinkToClipboard(HitTestResult hitTestResult)
{
NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *types = [NSPasteboard _web_writableTypesForURL];
[m_webView _writeLinkElement:element withPasteboardTypes:types toPasteboard:pasteboard];
}
void WebContextMenuClient::downloadURL(KURL url)
{
[m_webView _downloadURL:url.getNSURL()];
}
void WebContextMenuClient::copyImageToClipboard(HitTestResult hitTestResult)
{
NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *types = [NSPasteboard _web_writableTypesForImageIncludingArchive:(hitTestResult.innerNonSharedNode() != 0)];
[[[element objectForKey:WebElementFrameKey] webView] _writeImageForElement:element
withPasteboardTypes:types
toPasteboard:pasteboard];
}
void WebContextMenuClient::searchWithSpotlight()
{
[m_webView _searchWithSpotlightFromMenu:nil];
}
void WebContextMenuClient::lookUpInDictionary(Frame* frame)
{
WebHTMLView* htmlView = (WebHTMLView*)[[kit(frame) frameView] documentView];
if(![htmlView isKindOfClass:[WebHTMLView class]])
return;
[htmlView _lookUpInDictionaryFromMenu:nil];
}
......@@ -56,6 +56,7 @@ public:
bool shouldBeginEditing(WebCore::Range*);
bool shouldEndEditing(WebCore::Range*);
bool shouldInsertText(WebCore::String, WebCore::Range*, WebCore::EditorInsertAction);
bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
......
......@@ -41,6 +41,19 @@
using namespace WebCore;