Commit 769ddd85 authored by aroben's avatar aroben

WebCore:

        Reviewed by Anders.

        Add new ContextMenuController and ContextMenuClient classes, and move
        context menu responsibilities from Chrome and ChromeClient to them.

        * WebCore.exp:
        * WebCore.xcodeproj/project.pbxproj: Add new files to project, and
        alphabetize some others.
        * page/Chrome.cpp: Remove context menu-related code.
        * page/Chrome.h: Ditto.
        * page/ChromeClient.h:
        * page/ContextMenuClient.h: Added.
        * page/ContextMenuController.cpp: Added.
        (WebCore::ContextMenuController::ContextMenuController):
        (WebCore::ContextMenuController::~ContextMenuController):
        (WebCore::ContextMenuController::handleContextMenuEvent):
        (WebCore::ContextMenuController::contextMenuActionSelected):
        * page/ContextMenuController.h: Added.
        (WebCore::ContextMenuController::client):
        * page/Page.cpp: Every Page now has a ContextMenuController.
        (WebCore::Page::Page):
        * page/Page.h: Made m_dragCaretController and m_chrome objects instead
        of pointers to objects.
        (WebCore::Page::contextMenuController):
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::populate): Removed the call to Chrome to ask the
        delegate to add its menu items, and moved the code from the static
        addDefaultItems function into this method.
        * platform/ContextMenu.h:
        (WebCore::ContextMenu::show): Added an empty method body since this
        method is now called from ContextMenuController (although no one calls
        into ContextMenuController yet, so it's OK for this to be empty).
        (WebCore::ContextMenu::hide): Ditto.

WebKit:

        Reviewed by Anders.

        Added new WebContextMenuClient class to act as WebCore's ChromeClient,
        and moved context menu-related code there from WebChromeClient.

        * WebCoreSupport/WebChromeClient.h:
        * WebCoreSupport/WebChromeClient.mm:
        * WebCoreSupport/WebContextMenuClient.h: Added.
        (WebContextMenuClient::webView):
        * WebCoreSupport/WebContextMenuClient.mm: Added.
        (WebContextMenuClient::create):
        (WebContextMenuClient::WebContextMenuClient):
        (WebContextMenuClient::ref):
        (WebContextMenuClient::deref):
        (WebContextMenuClient::addCustomContextMenuItems):
        * WebKit.xcodeproj/project.pbxproj: Added new files.
        * WebView/WebView.mm:
        (-[WebView _commonInitializationWithFrameName:groupName:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17805 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2bfb171a
2006-11-15 Adam Roben <aroben@apple.com>
Reviewed by Anders.
Add new ContextMenuController and ContextMenuClient classes, and move
context menu responsibilities from Chrome and ChromeClient to them.
* WebCore.exp:
* WebCore.xcodeproj/project.pbxproj: Add new files to project, and
alphabetize some others.
* page/Chrome.cpp: Remove context menu-related code.
* page/Chrome.h: Ditto.
* page/ChromeClient.h:
* page/ContextMenuClient.h: Added.
* page/ContextMenuController.cpp: Added.
(WebCore::ContextMenuController::ContextMenuController):
(WebCore::ContextMenuController::~ContextMenuController):
(WebCore::ContextMenuController::handleContextMenuEvent):
(WebCore::ContextMenuController::contextMenuActionSelected):
* page/ContextMenuController.h: Added.
(WebCore::ContextMenuController::client):
* page/Page.cpp: Every Page now has a ContextMenuController.
(WebCore::Page::Page):
* page/Page.h: Made m_dragCaretController and m_chrome objects instead
of pointers to objects.
(WebCore::Page::contextMenuController):
* platform/ContextMenu.cpp:
(WebCore::ContextMenu::populate): Removed the call to Chrome to ask the
delegate to add its menu items, and moved the code from the static
addDefaultItems function into this method.
* platform/ContextMenu.h:
(WebCore::ContextMenu::show): Added an empty method body since this
method is now called from ContextMenuController (although no one calls
into ContextMenuController yet, so it's OK for this to be empty).
(WebCore::ContextMenu::hide): Ditto.
2006-11-15 Anders Carlsson <acarlsson@apple.com>
Reviewed by Darin.
......@@ -231,7 +231,7 @@ __ZN7WebCore4KURLC1EP5NSURL
__ZN7WebCore4KURLC1ERKNS_16DeprecatedStringE
__ZN7WebCore4Page12setGroupNameERKNS_6StringE
__ZN7WebCore4Page16setDefersLoadingEb
__ZN7WebCore4PageC1EN3WTF10PassRefPtrINS_12ChromeClientEEE
__ZN7WebCore4PageC1EN3WTF10PassRefPtrINS_12ChromeClientEEENS2_INS_17ContextMenuClientEEE
__ZN7WebCore4PageD1Ev
__ZN7WebCore5Frame11setSettingsEPNS_8SettingsE
__ZN7WebCore5Frame12ownerElementEv
......
......@@ -21,6 +21,9 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
065AD4F50B0C2EDA005A2B1D /* ContextMenuClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 065AD4F20B0C2EDA005A2B1D /* ContextMenuClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
065AD4F60B0C2EDA005A2B1D /* ContextMenuController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 065AD4F30B0C2EDA005A2B1D /* ContextMenuController.cpp */; };
065AD4F70B0C2EDA005A2B1D /* ContextMenuController.h in Headers */ = {isa = PBXBuildFile; fileRef = 065AD4F40B0C2EDA005A2B1D /* ContextMenuController.h */; };
0668E18B0ADD9624004128E0 /* PopupMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 0668E1890ADD9624004128E0 /* PopupMenu.h */; };
0668E1900ADD9640004128E0 /* PopupMenuMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0668E18E0ADD9640004128E0 /* PopupMenuMac.mm */; };
066C772B0AB603B700238CC4 /* FileChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = 066C772A0AB603B700238CC4 /* FileChooser.h */; };
......@@ -2915,6 +2918,9 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
065AD4F20B0C2EDA005A2B1D /* ContextMenuClient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContextMenuClient.h; sourceTree = "<group>"; };
065AD4F30B0C2EDA005A2B1D /* ContextMenuController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = ContextMenuController.cpp; sourceTree = "<group>"; };
065AD4F40B0C2EDA005A2B1D /* ContextMenuController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContextMenuController.h; sourceTree = "<group>"; };
0668E1890ADD9624004128E0 /* PopupMenu.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PopupMenu.h; sourceTree = "<group>"; };
0668E18E0ADD9640004128E0 /* PopupMenuMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = PopupMenuMac.mm; sourceTree = "<group>"; };
066C772A0AB603B700238CC4 /* FileChooser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FileChooser.h; sourceTree = "<group>"; };
......@@ -6513,6 +6519,9 @@
8538F0000AD71770006A81D1 /* AbstractView.idl */,
14D8238A0AF92DF60004F057 /* Chrome.cpp */,
14D823500AF92A790004F057 /* Chrome.h */,
065AD4F20B0C2EDA005A2B1D /* ContextMenuClient.h */,
065AD4F30B0C2EDA005A2B1D /* ContextMenuController.cpp */,
065AD4F40B0C2EDA005A2B1D /* ContextMenuController.h */,
14D824060AF93AEB0004F057 /* ChromeClient.h */,
1403B99609EB13AF00797C7F /* DOMWindow.cpp */,
1403B99509EB13AF00797C7F /* DOMWindow.h */,
......@@ -8348,9 +8357,11 @@
B2A015910AF6CD53006BCE0E /* graphics */ = {
isa = PBXGroup;
children = (
B27535290B053814002CE64F /* cg */,
B27535490B053814002CE64F /* mac */,
B2A015960AF6CD53006BCE0E /* svg */,
B27535270B053814002CE64F /* AffineTransform.cpp */,
B27535280B053814002CE64F /* AffineTransform.h */,
B27535290B053814002CE64F /* cg */,
B27535380B053814002CE64F /* Color.cpp */,
B27535390B053814002CE64F /* Color.h */,
B275353A0B053814002CE64F /* FloatPoint.cpp */,
......@@ -8359,6 +8370,10 @@
B275353D0B053814002CE64F /* FloatRect.h */,
B275353E0B053814002CE64F /* FloatSize.cpp */,
B275353F0B053814002CE64F /* FloatSize.h */,
B2A015920AF6CD53006BCE0E /* GraphicsContext.cpp */,
B2A015930AF6CD53006BCE0E /* GraphicsContext.h */,
B2A015940AF6CD53006BCE0E /* GraphicsTypes.cpp */,
B2A015950AF6CD53006BCE0E /* GraphicsTypes.h */,
B27535400B053814002CE64F /* Icon.h */,
B27535410B053814002CE64F /* Image.cpp */,
B27535420B053814002CE64F /* Image.h */,
......@@ -8368,16 +8383,10 @@
B27535460B053814002CE64F /* IntRect.h */,
B27535470B053814002CE64F /* IntSize.h */,
B27535480B053814002CE64F /* IntSizeHash.h */,
B27535490B053814002CE64F /* mac */,
B27535520B053814002CE64F /* Path.cpp */,
B27535530B053814002CE64F /* Path.h */,
B27535540B053814002CE64F /* Pen.cpp */,
B27535550B053814002CE64F /* Pen.h */,
B2A015920AF6CD53006BCE0E /* GraphicsContext.cpp */,
B2A015930AF6CD53006BCE0E /* GraphicsContext.h */,
B2A015940AF6CD53006BCE0E /* GraphicsTypes.cpp */,
B2A015950AF6CD53006BCE0E /* GraphicsTypes.h */,
B2A015960AF6CD53006BCE0E /* svg */,
);
path = graphics;
sourceTree = "<group>";
......@@ -10579,6 +10588,8 @@
93C09A530B064DB3005ABD4D /* EventHandler.h in Headers */,
93C09C860B0657AA005ABD4D /* ScrollTypes.h in Headers */,
93B6A0E60B0BCA5C00F5027A /* ContextMenu.h in Headers */,
065AD4F50B0C2EDA005A2B1D /* ContextMenuClient.h in Headers */,
065AD4F70B0C2EDA005A2B1D /* ContextMenuController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -11850,6 +11861,7 @@
93C09A810B064F00005ABD4D /* EventHandler.cpp in Sources */,
93B6A0E80B0BCA6700F5027A /* ContextMenu.cpp in Sources */,
93B6A0EA0B0BCA8400F5027A /* ContextMenuMac.mm in Sources */,
065AD4F60B0C2EDA005A2B1D /* ContextMenuController.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -170,10 +170,5 @@ void Chrome::setResizable(bool b) const
m_client->setResizable(b);
}
void Chrome::addCustomContextMenuItems(ContextMenu* defaultMenu) const
{
m_client->addCustomContextMenuItems(defaultMenu);
}
} // namespace WebCore
......@@ -70,8 +70,6 @@ namespace WebCore {
void setResizable(bool) const;
void addCustomContextMenuItems(ContextMenu*) const;
private:
Page* m_page;
RefPtr<ChromeClient> m_client;
......
......@@ -25,7 +25,6 @@
namespace WebCore {
class ContextMenu;
class FloatRect;
class Page;
......@@ -63,8 +62,6 @@ namespace WebCore {
virtual bool menubarVisible() = 0;
virtual void setResizable(bool) = 0;
virtual void addCustomContextMenuItems(ContextMenu*) = 0;
};
}
......
/*
* 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 ContextMenuClient_h
#define ContextMenuClient_h
#include "AbstractShared.h"
namespace WebCore {
class ContextMenu;
class ContextMenuClient : public AbstractShared {
public:
virtual void addCustomContextMenuItems(ContextMenu*) = 0;
};
}
#endif
/*
* 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 "ContextMenuController.h"
#include "ContextMenu.h"
#include "ContextMenuClient.h"
#include "Event.h"
#include "EventNames.h"
#include "HitTestRequest.h"
#include "HitTestResult.h"
#include "MouseEvent.h"
#include "Node.h"
#include "RenderLayer.h"
#include "RenderObject.h"
namespace WebCore {
using namespace EventNames;
ContextMenuController::ContextMenuController(Page* page, PassRefPtr<ContextMenuClient> client)
: m_page(page)
, m_client(client)
, m_contextMenu(0)
{
}
ContextMenuController::~ContextMenuController()
{
}
void ContextMenuController::handleContextMenuEvent(Event* event)
{
ASSERT(event->type() == contextmenuEvent);
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
HitTestResult result(IntPoint(mouseEvent->x(), mouseEvent->y()));
if (RenderObject* renderer = event->target()->renderer())
if (RenderLayer* layer = renderer->layer())
layer->hitTest(HitTestRequest(false, true), result);
if (!result.innerNonSharedNode())
return;
m_contextMenu = new ContextMenu(result);
m_contextMenu->populate();
m_client->addCustomContextMenuItems(m_contextMenu.get());
m_contextMenu->show();
}
void ContextMenuController::contextMenuActionSelected(ContextMenuAction action)
{
// FIXME: Implement this
}
} // namespace WebCore
/*
* 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 ContextMenuController_h
#define ContextMenuController_h
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
#include "ContextMenu.h"
namespace WebCore {
class ContextMenuClient;
class Event;
class Node;
class Page;
class ContextMenuController : Noncopyable
{
public:
ContextMenuController(Page*, PassRefPtr<ContextMenuClient>);
~ContextMenuController();
ContextMenuClient* client() { return m_client.get(); }
void handleContextMenuEvent(Event*);
void contextMenuActionSelected(ContextMenuAction);
private:
Page* m_page;
RefPtr<ContextMenuClient> m_client;
std::auto_ptr<ContextMenu> m_contextMenu;
};
}
#endif
......@@ -21,12 +21,11 @@
#include "config.h"
#include "Page.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "ContextMenuClient.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "SelectionController.h"
#include "StringHash.h"
#include "Widget.h"
#include <kjs/collector.h>
......@@ -40,9 +39,10 @@ namespace WebCore {
static HashSet<Page*>* allPages;
static HashMap<String, HashSet<Page*>*>* frameNamespaces;
Page::Page(PassRefPtr<ChromeClient> chromeClient)
: m_dragCaretController(new SelectionController(0, true))
, m_chrome(new Chrome(this, chromeClient))
Page::Page(PassRefPtr<ChromeClient> chromeClient, PassRefPtr<ContextMenuClient> contextMenuClient)
: m_dragCaretController(0, true)
, m_chrome(this, chromeClient)
, m_contextMenuController(this, contextMenuClient)
, m_frameCount(0)
, m_defersLoading(false)
{
......@@ -72,9 +72,6 @@ Page::~Page()
Collector::collect();
#endif
}
delete m_dragCaretController;
delete m_chrome;
}
void Page::setMainFrame(PassRefPtr<Frame> mainFrame)
......
......@@ -21,8 +21,12 @@
#ifndef Page_h
#define Page_h
#include "Chrome.h"
#include "ContextMenuController.h"
#include "PlatformString.h"
#include "SelectionController.h"
#include <wtf/HashSet.h>
#include <wtf/OwnPtr.h>
#if PLATFORM(WIN)
typedef struct HINSTANCE__* HINSTANCE;
......@@ -30,18 +34,17 @@ typedef struct HINSTANCE__* HINSTANCE;
namespace WebCore {
class Chrome;
class ChromeClient;
class ContextMenuClient;
class Frame;
class FrameNamespace;
class FloatRect;
class Settings;
class SelectionController;
class Widget;
class Page : Noncopyable {
public:
Page(PassRefPtr<ChromeClient>);
Page(PassRefPtr<ChromeClient>, PassRefPtr<ContextMenuClient>);
~Page();
void setMainFrame(PassRefPtr<Frame>);
......@@ -60,8 +63,9 @@ namespace WebCore {
static void setNeedsReapplyStyles();
static void setNeedsReapplyStylesForSettingsChange(Settings*);
SelectionController* dragCaretController() { return m_dragCaretController; }
Chrome* chrome() { return m_chrome; }
SelectionController* dragCaretController() { return &m_dragCaretController; }
Chrome* chrome() { return &m_chrome; }
ContextMenuController* contextMenuController() { return &m_contextMenuController; }
void setDefersLoading(bool);
bool defersLoading() const { return m_defersLoading; }
......@@ -73,8 +77,9 @@ namespace WebCore {
#endif
private:
SelectionController* m_dragCaretController;
Chrome* m_chrome;
SelectionController m_dragCaretController;
Chrome m_chrome;
ContextMenuController m_contextMenuController;
RefPtr<Frame> m_mainFrame;
int m_frameCount;
......
......@@ -26,7 +26,7 @@
#include "config.h"
#include "ContextMenu.h"
#include "Chrome.h"
#include "ContextMenuController.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
......@@ -39,7 +39,7 @@ namespace WebCore {
#define MENU_ACTION_ITEM(action, title) static ContextMenuItem action##Item(ActionType, WebMenuItemTag##action, String(title))
static void addDefaultItems(ContextMenu* menu)
void ContextMenu::populate()
{
MENU_ACTION_ITEM(OpenLinkInNewWindow, "Open Link in New Window");
MENU_ACTION_ITEM(DownloadLinkToDisk, "Download Linked File");
......@@ -67,54 +67,54 @@ static void addDefaultItems(ContextMenu* menu)
// FIXME: Add PDF action items
ContextMenuItem SeparatorItem(SeparatorType, WebMenuItemTagNoAction, String());
HitTestResult result = menu->hitTestResult();
HitTestResult result = 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);
appendItem(OpenLinkInNewWindowItem);
appendItem(DownloadLinkToDiskItem);
}
menu->appendItem(CopyLinkToClipboardItem);
appendItem(CopyLinkToClipboardItem);
}
KURL imageURL = result.absoluteImageURL();
if (!imageURL.isEmpty()) {
if (!linkURL.isEmpty())
menu->appendItem(SeparatorItem);
appendItem(SeparatorItem);
menu->appendItem(OpenImageInNewWindowItem);
menu->appendItem(DownloadImageToDiskItem);
appendItem(OpenImageInNewWindowItem);
appendItem(DownloadImageToDiskItem);
if (imageURL.isLocalFile())
menu->appendItem(CopyImageToClipboardItem);
appendItem(CopyImageToClipboardItem);
}
if (imageURL.isEmpty() && linkURL.isEmpty()) {
if (result.isSelected()) {
#if PLATFORM(MAC)
menu->appendItem(SearchInSpotlightItem);
appendItem(SearchInSpotlightItem);
#endif
menu->appendItem(SearchWebItem);
menu->appendItem(SeparatorItem);
menu->appendItem(LookUpInDictionaryItem);
menu->appendItem(SeparatorItem);
menu->appendItem(CopyItem);
appendItem(SearchWebItem);
appendItem(SeparatorItem);
appendItem(LookUpInDictionaryItem);
appendItem(SeparatorItem);
appendItem(CopyItem);
} else {
FrameLoader* loader = result.innerNonSharedNode()->document()->frame()->loader();
if (loader->canGoBackOrForward(-1))
menu->appendItem(GoBackItem);
appendItem(GoBackItem);
if (loader->canGoBackOrForward(1))
menu->appendItem(GoForwardItem);
appendItem(GoForwardItem);
if (loader->isLoading())
menu->appendItem(StopItem);
appendItem(StopItem);
else
menu->appendItem(ReloadItem);
appendItem(ReloadItem);
if (result.innerNonSharedNode()->document()->frame() != result.innerNonSharedNode()->document()->frame()->page()->mainFrame())
menu->appendItem(OpenFrameInNewWindowItem);
appendItem(OpenFrameInNewWindowItem);
}
}
} else { // Make an editing context menu
......@@ -124,40 +124,32 @@ static void addDefaultItems(ContextMenu* menu)
// Add spelling-related context menu items.
if (true) { // FIXME: Should be (selectionController->isSelectionMisspelled() && !inPasswordField)
// FIXME: Add spelling guesses here
menu->appendItem(NoGuessesFoundItem);
appendItem(NoGuessesFoundItem);
menu->appendItem(SeparatorItem);
menu->appendItem(IgnoreSpellingItem);
menu->appendItem(LearnSpellingItem);
menu->appendItem(SeparatorItem);
appendItem(SeparatorItem);
appendItem(IgnoreSpellingItem);
appendItem(LearnSpellingItem);
appendItem(SeparatorItem);
}
if (result.isSelected() && !inPasswordField) {
#if PLATFORM(MAC)
menu->appendItem(SearchInSpotlightItem);
appendItem(SearchInSpotlightItem);
#endif
menu->appendItem(SearchWebItem);
menu->appendItem(SeparatorItem);
appendItem(SearchWebItem);
appendItem(SeparatorItem);
menu->appendItem(LookUpInDictionaryItem);
menu->appendItem(SeparatorItem);
appendItem(LookUpInDictionaryItem);
appendItem(SeparatorItem);
}
menu->appendItem(CutItem);
menu->appendItem(CopyItem);
menu->appendItem(PasteItem);
menu->appendItem(SeparatorItem);
appendItem(CutItem);
appendItem(CopyItem);
appendItem(PasteItem);
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);
}
}
......@@ -124,8 +124,9 @@ public:
void populate();
void show();
void hide();
// FIXME: Implement these
void show() {}
void hide() {}
void insertItem(unsigned position, ContextMenuItem);
void appendItem(ContextMenuItem item);
......
2006-11-15 Adam Roben <aroben@apple.com>
Reviewed by Anders.
Added new WebContextMenuClient class to act as WebCore's ChromeClient,
and moved context menu-related code there from WebChromeClient.
* WebCoreSupport/WebChromeClient.h:
* WebCoreSupport/WebChromeClient.mm:
* WebCoreSupport/WebContextMenuClient.h: Added.
(WebContextMenuClient::webView):
* WebCoreSupport/WebContextMenuClient.mm: Added.
(WebContextMenuClient::create):
(WebContextMenuClient::WebContextMenuClient):
(WebContextMenuClient::ref):
(WebContextMenuClient::deref):
(WebContextMenuClient::addCustomContextMenuItems):
* WebKit.xcodeproj/project.pbxproj: Added new files.
* WebView/WebView.mm:
(-[WebView _commonInitializationWithFrameName:groupName:]):
2006-11-15 Beth Dakin <bdakin@apple.com>
& Adam Roben <aroben@apple.com>
......
......@@ -72,8 +72,6 @@ public:
virtual void setResizable(bool);
virtual void addCustomContextMenuItems(WebCore::ContextMenu*);
private:
WebChromeClient(WebView *webView);
......
......@@ -29,14 +29,12 @@
#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>
......@@ -204,13 +202,3 @@ 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);
}
}
/*
* 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.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*