Changeset 17855 in webkit


Ignore:
Timestamp:
Nov 19, 2006 5:21:56 PM (17 years ago)
Author:
bdakin
Message:

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
Location:
trunk
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r17853 r17855  
     12006-11-19  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Adam.
     4
     5        Implementation of actions for the new context menus.
     6
     7        * WebCore.exp:
     8        * WebCore.xcodeproj/project.pbxproj:
     9        * bridge/EditorClient.h: Declaration of shouldInsertText.
     10        * bridge/mac/FrameMac.h: Two new spelling functions.
     11        * bridge/mac/FrameMac.mm:
     12        (WebCore::FrameMac::ignoreSpelling):
     13        (WebCore::FrameMac::learnSpelling):
     14        * editing/Editor.cpp:
     15        (WebCore::Editor::shouldInsertText): Call into the client.
     16        * editing/Editor.h:
     17        * editing/EditorInsertAction.h: Added.
     18        (WebCore::): The WebCore equivalent of WebViewInsertAction. This is
     19        defined in its own header so that we can use it from Editor.h and
     20        EditorClient.h without having one of the above include the other.
     21        * page/ContextMenuClient.h: A few currently WebKit-implemented
     22        function needed for menu actions.
     23        * page/ContextMenuController.cpp:
     24        (WebCore::makeGoogleSearchURL):
     25        (WebCore::ContextMenuController::contextMenuActionSelected): The
     26        actions!
     27        * page/ContextMenuController.h:
     28        * page/Frame.h: New pure-virtual spelling functions.
     29        * platform/ContextMenu.cpp:
     30        (WebCore::ContextMenu::controller): Get the controller from the
     31        menu.
     32        * platform/ContextMenu.h:
     33        * platform/mac/ContextMenuMac.mm:
     34        (-[MenuTarget
     35        forwardContextMenuAction:initWithContextMenuController:WebCore::]):
     36        Use the controller instead of the menu
     37        (-[MenuTarget WebCore::]):
     38        (-[MenuTarget setMenuController:WebCore::]):
     39        (-[MenuTarget forwardContextMenuAction:]):
     40        (getNSMenuItem):
     41        (ContextMenu::show):
     42        (ContextMenu::hide):
     43
    1442006-11-19  Simon Hausmann  <hausmann@kde.org>
    245
  • trunk/WebCore/WebCore.exp

    r17805 r17855  
    395395__ZNK7WebCore8FrameMac14selectionImageEb
    396396__ZNK7WebCore8FrameMac31fontAttributesForSelectionStartEv
    397 __ZNK7WebCore8IntPointcv8_NSPointEv
    398397__ZNK7WebCore9FloatRectcv7_NSRectEv
    399398__ZNK7WebCore9FrameTree12traverseNextEPKNS_5FrameE
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r17850 r17855  
    16221622                93F19B1708245E59001E9ABC /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F1D31A0558CC5C00821BC0 /* libicucore.dylib */; };
    16231623                93F19B1808245E59001E9ABC /* libxslt.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 840633070731A77200DB1FD1 /* libxslt.dylib */; };
     1624                93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FDAFC90B11307400E2746F /* EditorInsertAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16241625                A70023FD0B02BEAB00170215 /* MimeTypeRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70023FB0B02BEAB00170215 /* MimeTypeRegistry.cpp */; };
    16251626                A70023FE0B02BEAB00170215 /* MimeTypeRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = A70023FC0B02BEAB00170215 /* MimeTypeRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    45314532                93F8B3070A300FEA00F61AB8 /* generate-bindings.pl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = "generate-bindings.pl"; path = "scripts/generate-bindings.pl"; sourceTree = "<group>"; };
    45324533                93F8B3080A300FEA00F61AB8 /* IDLStructure.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = IDLStructure.pm; path = scripts/IDLStructure.pm; sourceTree = "<group>"; };
     4534                93FDAFC90B11307400E2746F /* EditorInsertAction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorInsertAction.h; sourceTree = "<group>"; };
    45334535                A70023FB0B02BEAB00170215 /* MimeTypeRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MimeTypeRegistry.cpp; sourceTree = "<group>"; };
    45344536                A70023FC0B02BEAB00170215 /* MimeTypeRegistry.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MimeTypeRegistry.h; sourceTree = "<group>"; };
     
    75977599                                4B3043CA0AE0373B00A82647 /* Editor.cpp */,
    75987600                                4B3043CB0AE0373B00A82647 /* Editor.h */,
     7601                                93FDAFC90B11307400E2746F /* EditorInsertAction.h */,
    75997602                                93309D98099E64910056E581 /* htmlediting.cpp */,
    76007603                                93309D99099E64910056E581 /* htmlediting.h */,
     
    1079910802                                B2E27C9C0B0F2AE600F17C7B /* SVGSpotLightSource.h in Headers */,
    1080010803                                B2E27CA00B0F2B0900F17C7B /* FloatPoint3D.h in Headers */,
     10804                                93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */,
    1080110805                        );
    1080210806                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/bridge/EditorClient.h

    r17777 r17855  
    3030#include "AbstractShared.h"
    3131
     32#include "EditorInsertAction.h"
     33
    3234namespace WebCore {
    3335
     
    3537class EditCommand;
    3638class HTMLElement;
     39class String;
    3740class Range;
    3841
     
    5255    virtual bool shouldEndEditing(Range*) = 0;
    5356//  virtual bool shouldInsertNode(Node*, Range* replacingRange, WebViewInsertAction) = 0;
    54 //  virtual bool shouldInsertText(NSString*, Range *replacingRange, WebViewInsertAction) = 0;
     57    virtual bool shouldInsertText(String, Range*, EditorInsertAction) = 0;
    5558//  virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, NSSelectionAffinity, bool stillSelecting) = 0;
    5659    virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) = 0;
  • trunk/WebCore/bridge/mac/FrameMac.h

    r17770 r17855  
    167167    NSWritingDirection baseWritingDirectionForSelectionStart() const;
    168168
     169    virtual void ignoreSpelling();
     170    virtual void learnSpelling();
    169171    virtual void markMisspellingsInAdjacentWords(const VisiblePosition&);
    170172    virtual void markMisspellings(const Selection&);
  • trunk/WebCore/bridge/mac/FrameMac.mm

    r17818 r17855  
    106106#endif
    107107
     108@interface NSSpellChecker (CurrentlyPrivateForTextView)
     109- (void)learnWord:(NSString *)word;
     110@end
     111
    108112using namespace std;
    109113using namespace KJS::Bindings;
     
    11481152}
    11491153
     1154void FrameMac::ignoreSpelling()
     1155{
     1156    String text = selectedText();
     1157    ASSERT(text.length() != 0);
     1158    [[NSSpellChecker sharedSpellChecker] ignoreWord:text
     1159        inSpellDocumentWithTag:editor()->client()->spellCheckerDocumentTag()];
     1160}
     1161
     1162void FrameMac::learnSpelling()
     1163{
     1164    String text = selectedText();
     1165    ASSERT(text.length() != 0);
     1166    [[NSSpellChecker sharedSpellChecker] learnWord:text];
     1167}
     1168
    11501169void FrameMac::markMisspellingsInAdjacentWords(const VisiblePosition &p)
    11511170{
  • trunk/WebCore/editing/Editor.cpp

    r17777 r17855  
    187187void Editor::writeSelectionToPasteboard(Pasteboard pasteboard)
    188188{
     189}
     190
     191bool Editor::shouldInsertText(String text, Range* range, EditorInsertAction action) const
     192{
     193    return m_client->shouldInsertText(text, range, action);
    189194}
    190195
  • trunk/WebCore/editing/Editor.h

    r17777 r17855  
    2727#define Editor_h
    2828
     29#include "EditorInsertAction.h"
    2930#include "Frame.h"
    3031#include <wtf/Forward.h>
     
    7172    void outdent();
    7273
     74    bool shouldInsertText(String, Range*, EditorInsertAction) const;
    7375    bool shouldShowDeleteInterface(HTMLElement*) const;
    7476    bool shouldDeleteRange(Range*) const;
  • trunk/WebCore/page/ContextMenuClient.h

    r17805 r17855  
    3131namespace WebCore {
    3232    class ContextMenu;
     33    class Frame;
     34    class HitTestResult;
     35    class KURL;
    3336
    3437    class ContextMenuClient : public AbstractShared {
    3538    public:
    3639        virtual void addCustomContextMenuItems(ContextMenu*) = 0;
     40
     41        virtual void copyLinkToClipboard(HitTestResult) = 0;
     42        virtual void downloadURL(KURL url) = 0;
     43        virtual void copyImageToClipboard(HitTestResult) = 0;
     44        virtual void lookUpInDictionary(Frame*) = 0;
     45
     46#if PLATFORM(MAC)
     47        virtual void searchWithSpotlight() = 0;
     48#endif
    3749    };
    3850}
  • trunk/WebCore/page/ContextMenuController.cpp

    r17806 r17855  
    2929#include "ContextMenu.h"
    3030#include "ContextMenuClient.h"
     31#include "Document.h"
     32#include "DocumentFragment.h"
     33#include "DocumentLoader.h"
     34#include "Editor.h"
     35#include "EditorClient.h"
    3136#include "Event.h"
    3237#include "EventNames.h"
     38#include "Frame.h"
     39#include "FrameLoader.h"
     40#include "FrameLoadRequest.h"
    3341#include "HitTestRequest.h"
    3442#include "HitTestResult.h"
     43#include "KURL.h"
    3544#include "MouseEvent.h"
    3645#include "Node.h"
     46#include "Page.h"
    3747#include "RenderLayer.h"
    3848#include "RenderObject.h"
     49#include "ReplaceSelectionCommand.h"
     50#include "ResourceRequest.h"
     51#include "markup.h"
    3952
    4053namespace WebCore {
     
    7285}
    7386
    74 void ContextMenuController::contextMenuActionSelected(ContextMenuAction action)
    75 {
    76     // FIXME: Implement this
     87static String makeGoogleSearchURL(String searchString)
     88{
     89    searchString.stripWhiteSpace();
     90    DeprecatedString encoded = KURL::encode_string(searchString.deprecatedString());
     91    encoded.replace(DeprecatedString("%20"), DeprecatedString("+"));
     92   
     93    String url("http://www.google.com/search?client=safari&q=");
     94    url.append(String(encoded));
     95    url.append("&ie=UTF-8&oe=UTF-8");
     96    return url;
     97}
     98
     99void ContextMenuController::contextMenuActionSelected(ContextMenuAction action, String title)
     100{
     101    Frame* frame = m_contextMenu->hitTestResult().innerNonSharedNode()->document()->frame();
     102    if (!frame)
     103        return;
     104    ASSERT(m_page == frame->page());
     105   
     106    switch (action) {
     107        case ContextMenuItemTagOpenLinkInNewWindow: {
     108            ResourceRequest request = ResourceRequest(m_contextMenu->hitTestResult().absoluteLinkURL());
     109            String referrer = frame->loader()->referrer();
     110            m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
     111            break;
     112        }
     113        case ContextMenuItemTagDownloadLinkToDisk:
     114            // FIXME: Some day we should be able to do this from within WebCore.
     115            m_client->downloadURL(m_contextMenu->hitTestResult().absoluteLinkURL());
     116            break;
     117        case ContextMenuItemTagCopyLinkToClipboard:
     118            // FIXME: The Pasteboard class is not written yet. This is what we should be able to do some day:
     119            // generalPasteboard()->copy(m_contextMenu->hitTestResult().absoluteLinkURL(),
     120            //      m_contextMenu->hitTestResult.textContent());
     121            // For now, call into the client. This is temporary!
     122            m_client->copyLinkToClipboard(m_contextMenu->hitTestResult());
     123            break;
     124        case ContextMenuItemTagOpenImageInNewWindow: {
     125            ResourceRequest request = ResourceRequest(m_contextMenu->hitTestResult().absoluteImageURL());
     126            String referrer = frame->loader()->referrer();
     127            m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
     128            break;
     129        }
     130        case ContextMenuItemTagDownloadImageToDisk:
     131            // FIXME: Some day we should be able to do this from within WebCore.
     132            m_client->downloadURL(m_contextMenu->hitTestResult().absoluteImageURL());
     133            break;
     134        case ContextMenuItemTagCopyImageToClipboard:
     135            // FIXME: The Pasteboard class is not written yet
     136            // For now, call into the client. This is temporary!
     137            m_client->copyImageToClipboard(m_contextMenu->hitTestResult());
     138            break;
     139        case ContextMenuItemTagOpenFrameInNewWindow: {
     140            // FIXME: The DocumentLoader is all-Mac right now
     141#if PLATFORM(MAC)
     142            KURL unreachableURL = frame->loader()->documentLoader()->unreachableURL();
     143            if (frame && unreachableURL.isEmpty())
     144                unreachableURL = frame->loader()->documentLoader()->URL();
     145            ResourceRequest request = ResourceRequest(unreachableURL);
     146            String referrer = frame->loader()->referrer();
     147            if (m_page)
     148                m_page->chrome()->createWindow(FrameLoadRequest(request, referrer));
     149#endif
     150            break;
     151        }
     152        case ContextMenuItemTagCopy:
     153            frame->editor()->copy();
     154            break;
     155        case ContextMenuItemTagGoBack:
     156            frame->loader()->goBackOrForward(-1);
     157            break;
     158        case ContextMenuItemTagGoForward:
     159            frame->loader()->goBackOrForward(1);
     160            break;
     161        case ContextMenuItemTagStop:
     162            frame->loader()->stop();
     163            break;
     164        case ContextMenuItemTagReload:
     165            frame->loader()->reload();
     166            break;
     167        case ContextMenuItemTagCut:
     168            frame->editor()->cut();
     169            break;
     170        case ContextMenuItemTagPaste:
     171            frame->editor()->paste();
     172            break;
     173        case ContextMenuItemTagSpellingGuess:
     174            ASSERT(frame->selectedText().length() != 0);
     175            if (frame->editor()->shouldInsertText(title, frame->selectionController()->toRange().get(), EditorInsertActionPasted)) {
     176                Document* document = frame->document();
     177                applyCommand(new ReplaceSelectionCommand(document, createFragmentFromMarkup(document, title, ""),
     178                    true, false, true));
     179                frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     180            }
     181            break;
     182        case ContextMenuItemTagIgnoreSpelling:
     183            frame->ignoreSpelling();
     184            break;
     185        case ContextMenuItemTagLearnSpelling:
     186            frame->learnSpelling();
     187            break;
     188        case ContextMenuItemTagSearchInSpotlight:
     189#if PLATFORM(MAC)
     190            m_client->searchWithSpotlight();
     191#endif
     192            break;
     193        case ContextMenuItemTagSearchWeb: {
     194            String url = makeGoogleSearchURL(frame->selectedText());
     195            ResourceRequest request = ResourceRequest(url);
     196            frame->loader()->urlSelected(FrameLoadRequest(request), new Event());
     197            break;
     198        }
     199        case ContextMenuItemTagLookUpInDictionary:
     200            // FIXME: Some day we may be able to do this from within WebCore.
     201            m_client->lookUpInDictionary(frame);
     202            break;
     203        // PDF actions. Let's take care of this later.
     204        case ContextMenuItemTagOpenWithDefaultApplication:
     205        case ContextMenuItemPDFActualSize:
     206        case ContextMenuItemPDFZoomIn:
     207        case ContextMenuItemPDFZoomOut:
     208        case ContextMenuItemPDFAutoSize:
     209        case ContextMenuItemPDFSinglePage:
     210        case ContextMenuItemPDFFacingPages:
     211        case ContextMenuItemPDFContinuous:
     212        case ContextMenuItemPDFNextPage:
     213        case ContextMenuItemPDFPreviousPage:
     214        default:
     215            break;
     216    }
    77217}
    78218
  • trunk/WebCore/page/ContextMenuController.h

    r17806 r17855  
    4949
    5050        void handleContextMenuEvent(Event*);
    51         void contextMenuActionSelected(ContextMenuAction);
     51        void contextMenuActionSelected(ContextMenuAction, String);
    5252
    5353    private:
  • trunk/WebCore/page/Frame.h

    r17770 r17855  
    259259    void removeEditingStyleFromElement(Element*) const;
    260260
     261    virtual void ignoreSpelling() = 0;
     262    virtual void learnSpelling() = 0;
    261263    virtual void markMisspellingsInAdjacentWords(const VisiblePosition&) = 0;
    262264    virtual void markMisspellings(const Selection&) = 0;
  • trunk/WebCore/platform/ContextMenu.cpp

    r17807 r17855  
    3939
    4040#define MENU_ACTION_ITEM(action, title) static ContextMenuItem action##Item(ActionType, ContextMenuItemTag##action, String(title))
     41
     42ContextMenuController* ContextMenu::controller() const
     43{
     44    if (Node* node = m_hitTestResult.innerNonSharedNode())
     45        if (Frame* frame = node->document()->frame())
     46            if (Page* page = frame->page())
     47                return page->contextMenuController();
     48    return 0;
     49}
    4150
    4251void ContextMenu::populate()
  • trunk/WebCore/platform/ContextMenu.h

    r17827 r17855  
    4343
    4444namespace WebCore {
     45
     46class ContextMenuController;
    4547
    4648// This enum needs to be in sync with WebMenuItemTag, which is defined in WebUIDelegate.h
     
    129131    void populate();
    130132
    131     // FIXME: Implement these
    132     void show() {}
    133     void hide() {}
     133    void show();
     134    void hide();
    134135
    135136    void insertItem(unsigned position, ContextMenuItem);
     
    139140
    140141    HitTestResult hitTestResult() const { return m_hitTestResult; }
     142    ContextMenuController* controller() const;
    141143
    142144    PlatformMenuDescription platformMenuDescription() { return m_menu; }
  • trunk/WebCore/platform/mac/ContextMenuMac.mm

    r17797 r17855  
    2626#include "config.h"
    2727#include "ContextMenu.h"
     28
     29#include "ContextMenuController.h"
    2830 
    2931@interface MenuTarget : NSObject {
    30     WebCore::ContextMenu* _menu;
     32    WebCore::ContextMenuController* _menuController;
    3133}
    32 - (WebCore::ContextMenu*)menu;
    33 - (void)setMenu:(WebCore::ContextMenu*)menu;
     34- (WebCore::ContextMenuController*)menuController;
     35- (void)setMenuController:(WebCore::ContextMenuController*)menuController;
    3436- (void)forwardContextMenuAction:(id)sender;
    3537@end
     
    3739@implementation MenuTarget
    3840
    39 - (id)initWithContextMenu:(WebCore::ContextMenu*)menu
     41- (id)initWithContextMenuController:(WebCore::ContextMenuController*)menuController
    4042{
    4143    self = [super init];
     
    4345        return nil;
    4446   
    45     _menu = menu;
     47    _menuController = menuController;
    4648    return self;
    4749}
    4850
    49 - (WebCore::ContextMenu*)menu
     51- (WebCore::ContextMenuController*)menuController
    5052{
    51     return _menu;
     53    return _menuController;
    5254}
    5355
    54 - (void)setMenu:(WebCore::ContextMenu*)menu
     56- (void)setMenuController:(WebCore::ContextMenuController*)menuController
    5557{
    56     _menu = menu;
     58    _menuController = menuController;
    5759}
    5860
    5961- (void)forwardContextMenuAction:(id)sender
    6062{
     63    WebCore::ContextMenuAction action = static_cast<WebCore::ContextMenuAction>([sender tag]);
     64    _menuController->contextMenuActionSelected(action, [sender title]);
    6165}
    6266
     
    7276        menu->setPlatformMenuDescription([[[NSMutableArray alloc] init] autorelease]);
    7377   
     78    ContextMenuController* currentController = menu->controller();
    7479    if (!target)
    75         target = [[MenuTarget alloc] initWithContextMenu:menu];
    76     else if (menu != [target menu])
    77         [target setMenu:menu];
     80        target = [[MenuTarget alloc] initWithContextMenuController:currentController];
     81    else if (currentController != [target menuController])
     82        [target setMenuController:currentController];
    7883   
    7984    NSMenuItem* menuItem = [[[NSMenuItem alloc] init] autorelease];
     
    107112    m_menu = menu;
    108113}
     114
     115void ContextMenu::show()
     116{
     117}
     118
     119void ContextMenu::hide()
     120{
     121}
  • trunk/WebKit/ChangeLog

    r17847 r17855  
     12006-11-19  Beth Dakin  <bdakin@apple.com>
     2
     3        Reviewed by Adam.
     4
     5        WebKit side of new context menu actions.
     6
     7        * WebCoreSupport/WebContextMenuClient.h: These are for the
     8        currently-WebKit-dependent menu actions.
     9        * WebCoreSupport/WebContextMenuClient.mm:
     10        (WebContextMenuClient::copyLinkToClipboard):
     11        (WebContextMenuClient::downloadURL):
     12        (WebContextMenuClient::copyImageToClipboard):
     13        (WebContextMenuClient::searchWithSpotlight):
     14        (WebContextMenuClient::lookUpInDictionary):
     15        * WebCoreSupport/WebEditorClient.h:
     16        * WebCoreSupport/WebEditorClient.mm:
     17        (core): These are to convert between WebViewInsertAction and
     18        EditorInsertAction.
     19        (kit):
     20        (WebEditorClient::shouldInsertText): Added implementation for
     21        shouldInsertText.
     22        * WebKit.xcodeproj/project.pbxproj:
     23        * WebView/WebHTMLView.m:
     24        (-[WebHTMLView _lookUpInDictionaryFromMenu:]): Moved
     25        _lookUpInDictionary to be within the implementation of WebHTMLView
     26        internal.
     27        * WebView/WebHTMLViewInternal.h: Add _lookUpInDictionaryFromMenu
     28        * WebView/WebViewInternal.h: Add _searchWithSpotlightFromMenu
     29
    1302006-11-18  Don Gibson  <dgibson77@gmail.com>
    231
  • trunk/WebKit/WebCoreSupport/WebContextMenuClient.h

    r17805 r17855  
    4141   
    4242    virtual void addCustomContextMenuItems(WebCore::ContextMenu* menu);
     43   
     44    virtual void copyLinkToClipboard(WebCore::HitTestResult);
     45    virtual void downloadURL(WebCore::KURL url);
     46    virtual void copyImageToClipboard(WebCore::HitTestResult);
     47    virtual void searchWithSpotlight();
     48    virtual void lookUpInDictionary(WebCore::Frame*);
    4349
    4450    WebView *webView() { return m_webView; }
  • trunk/WebKit/WebCoreSupport/WebContextMenuClient.mm

    r17805 r17855  
    3131#import "WebElementDictionary.h"
    3232#import "WebFrame.h"
     33#import "WebFrameInternal.h"
     34#import "WebHTMLView.h"
     35#import "WebHTMLViewInternal.h"
     36#import "WebNSPasteboardExtras.h"
    3337#import "WebUIDelegate.h"
    3438#import "WebView.h"
     39#import "WebViewInternal.h"
    3540#import <WebCore/ContextMenu.h>
     41#import <WebCore/KURL.h>
    3642
    3743using namespace WebCore;
     
    6672    }
    6773}
     74
     75void WebContextMenuClient::copyLinkToClipboard(HitTestResult hitTestResult)
     76{
     77    NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];
     78    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
     79    NSArray *types = [NSPasteboard _web_writableTypesForURL];
     80    [m_webView _writeLinkElement:element withPasteboardTypes:types toPasteboard:pasteboard];
     81}
     82
     83void WebContextMenuClient::downloadURL(KURL url)
     84{
     85    [m_webView _downloadURL:url.getNSURL()];
     86}
     87
     88void WebContextMenuClient::copyImageToClipboard(HitTestResult hitTestResult)
     89{
     90    NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:hitTestResult] autorelease];
     91    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
     92    NSArray *types = [NSPasteboard _web_writableTypesForImageIncludingArchive:(hitTestResult.innerNonSharedNode() != 0)];
     93    [[[element objectForKey:WebElementFrameKey] webView] _writeImageForElement:element
     94                                                           withPasteboardTypes:types
     95                                                                  toPasteboard:pasteboard];
     96}
     97
     98void WebContextMenuClient::searchWithSpotlight()
     99{
     100    [m_webView _searchWithSpotlightFromMenu:nil];
     101}
     102
     103void WebContextMenuClient::lookUpInDictionary(Frame* frame)
     104{
     105    WebHTMLView* htmlView = (WebHTMLView*)[[kit(frame) frameView] documentView];
     106    if(![htmlView isKindOfClass:[WebHTMLView class]])
     107        return;
     108    [htmlView _lookUpInDictionaryFromMenu:nil];
     109}
  • trunk/WebKit/WebCoreSupport/WebEditorClient.h

    r17777 r17855  
    5757    bool shouldBeginEditing(WebCore::Range*);
    5858    bool shouldEndEditing(WebCore::Range*);
     59    bool shouldInsertText(WebCore::String, WebCore::Range*, WebCore::EditorInsertAction);
    5960
    6061    bool shouldApplyStyle(WebCore::CSSStyleDeclaration*, WebCore::Range*);
  • trunk/WebKit/WebCoreSupport/WebEditorClient.mm

    r17777 r17855  
    4242using namespace WebCore;
    4343
     44EditorInsertAction core(WebViewInsertAction);
     45WebViewInsertAction kit(EditorInsertAction);
     46
     47EditorInsertAction core(WebViewInsertAction kitAction)
     48{
     49    return static_cast<EditorInsertAction>(kitAction);
     50}
     51
     52WebViewInsertAction kit(EditorInsertAction coreAction)
     53{
     54    return static_cast<WebViewInsertAction>(coreAction);
     55}
     56
    4457@interface WebEditCommand : NSObject
    4558{
     
    203216    return [[[m_webFrame webView] _editingDelegateForwarder] webView:[m_webFrame webView]
    204217                             shouldEndEditingInDOMRange:kit(range)];
     218}
     219
     220bool WebEditorClient::shouldInsertText(String text, Range* range, EditorInsertAction action)
     221{
     222    WebView* webView = [m_webFrame webView];
     223    return [[webView _editingDelegateForwarder] webView:webView shouldInsertText:text replacingDOMRange:kit(range) givenAction:kit(action)];
    205224}
    206225
  • trunk/WebKit/WebKit.xcodeproj/project.pbxproj

    r17831 r17855  
    4242                22E42A9A0A5BA4D00003275B /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E42A990A5BA4D00003275B /* AGL.framework */; };
    4343                22F219CC08D236730030E078 /* WebBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 22F219CB08D236730030E078 /* WebBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    44                 4BF99F900AE050BC00815C2B /* WebEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BF99F8E0AE050BC00815C2B /* WebEditorClient.h */; };
     44                4BF99F900AE050BC00815C2B /* WebEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BF99F8E0AE050BC00815C2B /* WebEditorClient.h */; settings = {ATTRIBUTES = (); }; };
    4545                4BF99F910AE050BC00815C2B /* WebEditorClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BF99F8F0AE050BC00815C2B /* WebEditorClient.mm */; };
    4646                51B2A1000ADB15D0002A9BEE /* WebIconDatabaseDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 51B2A0FF0ADB15D0002A9BEE /* WebIconDatabaseDelegate.h */; };
     
    12531253                        isa = PBXProject;
    12541254                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
    1255                         compatibilityVersion = "Xcode 2.4";
    12561255                        hasScannedForEncodings = 1;
    12571256                        knownRegions = (
     
    12671266                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
    12681267                        projectDirPath = "";
    1269                         projectRoot = "";
    1270                         shouldCheckCompatibility = 1;
    12711268                        targets = (
    12721269                                9398100A0824BF01008DF038 /* WebKit */,
  • trunk/WebKit/WebView/WebHTMLView.m

    r17788 r17855  
    17611761}
    17621762
    1763 - (void)_lookUpInDictionaryFromMenu:(id)sender
    1764 {
    1765     // This should only be called when there's a selection, but play it safe.
    1766     if (![self _hasSelection])
    1767         return;
    1768    
    1769     // Soft link to dictionary-display function to avoid linking another framework (ApplicationServices/LangAnalysis)
    1770     static bool lookedForFunction = false;
    1771     typedef OSStatus (*ServiceWindowShowFunction)(id inWordString, NSRect inWordBoundary, UInt16 inLineDirection);
    1772     static ServiceWindowShowFunction dictionaryServiceWindowShow;
    1773     if (!lookedForFunction) {
    1774         const struct mach_header *frameworkImageHeader = 0;
    1775         dictionaryServiceWindowShow = reinterpret_cast<ServiceWindowShowFunction>(
    1776             _NSSoftLinkingGetFrameworkFuncPtr(@"ApplicationServices", @"LangAnalysis", "_DCMDictionaryServiceWindowShow", &frameworkImageHeader));
    1777         lookedForFunction = true;
    1778     }
    1779     if (!dictionaryServiceWindowShow) {
    1780         LOG_ERROR("Couldn't find _DCMDictionaryServiceWindowShow");
    1781         return;
    1782     }
    1783 
    1784     // FIXME: must check for right-to-left here
    1785     NSWritingDirection writingDirection = NSWritingDirectionLeftToRight;
    1786 
    1787     NSAttributedString *attrString = [self selectedAttributedString];
    1788     // FIXME: the dictionary API expects the rect for the first line of selection. Passing
    1789     // the rect for the entire selection, as we do here, positions the pop-up window near
    1790     // the bottom of the selection rather than at the selected word.
    1791     NSRect rect = [self convertRect:core([self _frame])->visibleSelectionRect() toView:nil];
    1792     rect.origin = [[self window] convertBaseToScreen:rect.origin];
    1793     NSData *data = [attrString RTFFromRange:NSMakeRange(0, [attrString length]) documentAttributes:nil];
    1794     dictionaryServiceWindowShow(data, rect, (writingDirection == NSWritingDirectionRightToLeft) ? 1 : 0);
    1795 }
    1796 
    17971763- (BOOL)_transparentBackground
    17981764{
     
    52635229#endif /* !BUILDING_ON_TIGER */
    52645230
     5231- (void)_lookUpInDictionaryFromMenu:(id)sender
     5232{
     5233    // This should only be called when there's a selection, but play it safe.
     5234    if (![self _hasSelection])
     5235        return;
     5236   
     5237    // Soft link to dictionary-display function to avoid linking another framework (ApplicationServices/LangAnalysis)
     5238    static bool lookedForFunction = false;
     5239    typedef OSStatus (*ServiceWindowShowFunction)(id inWordString, NSRect inWordBoundary, UInt16 inLineDirection);
     5240    static ServiceWindowShowFunction dictionaryServiceWindowShow;
     5241    if (!lookedForFunction) {
     5242        const struct mach_header *frameworkImageHeader = 0;
     5243        dictionaryServiceWindowShow = reinterpret_cast<ServiceWindowShowFunction>(
     5244            _NSSoftLinkingGetFrameworkFuncPtr(@"ApplicationServices", @"LangAnalysis", "_DCMDictionaryServiceWindowShow", &frameworkImageHeader));
     5245        lookedForFunction = true;
     5246    }
     5247    if (!dictionaryServiceWindowShow) {
     5248        LOG_ERROR("Couldn't find _DCMDictionaryServiceWindowShow");
     5249        return;
     5250    }
     5251
     5252    // FIXME: must check for right-to-left here
     5253    NSWritingDirection writingDirection = NSWritingDirectionLeftToRight;
     5254
     5255    NSAttributedString *attrString = [self selectedAttributedString];
     5256    // FIXME: the dictionary API expects the rect for the first line of selection. Passing
     5257    // the rect for the entire selection, as we do here, positions the pop-up window near
     5258    // the bottom of the selection rather than at the selected word.
     5259    NSRect rect = [self convertRect:core([self _frame])->visibleSelectionRect() toView:nil];
     5260    rect.origin = [[self window] convertBaseToScreen:rect.origin];
     5261    NSData *data = [attrString RTFFromRange:NSMakeRange(0, [attrString length]) documentAttributes:nil];
     5262    dictionaryServiceWindowShow(data, rect, (writingDirection == NSWritingDirectionRightToLeft) ? 1 : 0);
     5263}
     5264
    52655265@end
    52665266
  • trunk/WebKit/WebView/WebHTMLViewInternal.h

    r17760 r17855  
    115115- (void)paste:(id)sender;
    116116- (void)pasteAsPlainText:(id)sender;
     117- (void)_lookUpInDictionaryFromMenu:(id)sender;
    117118#if !BUILDING_ON_TIGER
    118119- (BOOL)isGrammarCheckingEnabled;
  • trunk/WebKit/WebView/WebViewInternal.h

    r17670 r17855  
    9898- (void)_writeImageForElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
    9999- (void)_writeLinkElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard;
     100- (void)_searchWithSpotlightFromMenu:(id)sender;
    100101- (void)_progressCompleted:(WebFrame *)frame;
    101102- (void)_didCommitLoadForFrame:(WebFrame *)frame;
Note: See TracChangeset for help on using the changeset viewer.