Commit 590b5aaa authored by aroben's avatar aroben

WebCore:

        Reviewed by Beth.

        More WebCore context menu work (still not turned on, however).

        Split ContextMenuItem into its own files and make it a class.

        * WebCore.exp: Updated symbols.
        * WebCore.xcodeproj/project.pbxproj: Added new ContextMenuItem files.
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::populate): Code cleanup.
        * platform/ContextMenu.h: Split ContextMenuItem into a separate file,
        removed redundant "Menu" part of platformMenuDescription(),
        setPlatformMenuDescription().
        (WebCore::ContextMenu::ContextMenu):
        (WebCore::ContextMenu::hitTestResult):
        (WebCore::ContextMenu::platformDescription):
        * platform/ContextMenuItem.h: Added. Made ContextMenuItem a
        full-fledged class.
        (WebCore::):
        (WebCore::ContextMenuItem::ContextMenuItem):
        (WebCore::ContextMenuItem::menu):
        (WebCore::ContextMenuItem::platformDescription):
        (WebCore::ContextMenuItem::type):
        (WebCore::ContextMenuItem::action):
        (WebCore::ContextMenuItem::title):
        * platform/mac/ContextMenuItemMac.mm: Added.
        (WebCore::ContextMenuItem::ContextMenuItem):
        * platform/mac/ContextMenuMac.mm: Updated for ContextMenuItem changes.
        (-[MenuTarget forwardContextMenuAction:]):
        (getNSMenuItem): Handle separator items.
        (ContextMenu::appendItem):
        (ContextMenu::itemCount):
        (ContextMenu::insertItem):
        (ContextMenu::setPlatformDescription):
        * page/ContextMenuController.h: Updated declaration, added getter.
        (WebCore::ContextMenuController::contextMenu):

        Added some more context menu plumbing.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::defaultEventHandler): Added code to call the
        ContextMenuController when a context menu event is received.
        * page/ContextMenuClient.h: New client method declaration.
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::handleContextMenuEvent): Set the event
        defaultHandled after handling it.
        (WebCore::ContextMenuController::contextMenuItemSelected): Take a
        ContextMenuItem instead of a separate action and title.

        Changed event-handling methods to return bools to signify whether the
        event was handled or not. This is needed so we can know whether to hand
        the event off to the OS. Also restructured some code to use early
        returns instead of nesting ifs.

        * page/EventHandler.cpp:
        (WebCore::EventHandler::handleMousePressEventDoubleClick):
        (WebCore::EventHandler::handleMousePressEventTripleClick):
        (WebCore::EventHandler::handleMousePressEventSingleClick):
        (WebCore::EventHandler::handleMousePressEvent):
        (WebCore::EventHandler::handleMouseMoveEvent):
        (WebCore::EventHandler::handleMouseReleaseEvent):
        (WebCore::EventHandler::handleMouseDoubleClickEvent):
        (WebCore::EventHandler::handleWheelEvent):
        (WebCore::EventHandler::canMouseDownStartSelect):
        * page/EventHandler.h:
        * page/FrameView.cpp:
        (WebCore::FrameView::handleMouseMoveEvent):
        (WebCore::FrameView::handleMouseReleaseEvent):
        * page/FrameView.h:
        * platform/ScrollBar.h: More bool return values.
        (WebCore::Scrollbar::handleMouseMoveEvent):
        (WebCore::Scrollbar::handleMouseOutEvent):
        * platform/Widget.h: Ditto.
        (WebCore::Widget::handleMouseMoveEvent):
        (WebCore::Widget::handleMouseReleaseEvent):

        Reverted the changes made in r17805 so that we can have fewer header
        #includes.

        * page/Page.cpp:
        (WebCore::Page::Page):
        * page/Page.h: Ditto.
        (WebCore::Page::dragCaretController):
        (WebCore::Page::chrome):
        (WebCore::Page::contextMenuController):

WebKit:

        Reviewed by Beth.

        More WebCore context menu work.

        * DefaultDelegates/WebDefaultUIDelegate.m: New stub delegate method implementation.
        (-[NSApplication webView:contextMenuItemSelected:forElement:]):
        * WebCoreSupport/WebContextMenuClient.h: Updated to match ContextMenuClient.h changes.
        * WebCoreSupport/WebContextMenuClient.mm:
        (WebContextMenuClient::addCustomContextMenuItems): Updated for method name changes.
        (WebContextMenuClient::contextMenuItemSelected): Added new client method.
        * WebView/WebUIDelegatePrivate.h: New private delegate method declaration.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17910 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 68b1393a
2006-11-28 Adam Roben <aroben@apple.com>
Reviewed by Beth.
More WebCore context menu work (still not turned on, however).
Split ContextMenuItem into its own files and make it a class.
* WebCore.exp: Updated symbols.
* WebCore.xcodeproj/project.pbxproj: Added new ContextMenuItem files.
* platform/ContextMenu.cpp:
(WebCore::ContextMenu::populate): Code cleanup.
* platform/ContextMenu.h: Split ContextMenuItem into a separate file,
removed redundant "Menu" part of platformMenuDescription(),
setPlatformMenuDescription().
(WebCore::ContextMenu::ContextMenu):
(WebCore::ContextMenu::hitTestResult):
(WebCore::ContextMenu::platformDescription):
* platform/ContextMenuItem.h: Added. Made ContextMenuItem a
full-fledged class.
(WebCore::):
(WebCore::ContextMenuItem::ContextMenuItem):
(WebCore::ContextMenuItem::menu):
(WebCore::ContextMenuItem::platformDescription):
(WebCore::ContextMenuItem::type):
(WebCore::ContextMenuItem::action):
(WebCore::ContextMenuItem::title):
* platform/mac/ContextMenuItemMac.mm: Added.
(WebCore::ContextMenuItem::ContextMenuItem):
* platform/mac/ContextMenuMac.mm: Updated for ContextMenuItem changes.
(-[MenuTarget forwardContextMenuAction:]):
(getNSMenuItem): Handle separator items.
(ContextMenu::appendItem):
(ContextMenu::itemCount):
(ContextMenu::insertItem):
(ContextMenu::setPlatformDescription):
* page/ContextMenuController.h: Updated declaration, added getter.
(WebCore::ContextMenuController::contextMenu):
Added some more context menu plumbing.
* dom/EventTargetNode.cpp:
(WebCore::EventTargetNode::defaultEventHandler): Added code to call the
ContextMenuController when a context menu event is received.
* page/ContextMenuClient.h: New client method declaration.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::handleContextMenuEvent): Set the event
defaultHandled after handling it.
(WebCore::ContextMenuController::contextMenuItemSelected): Take a
ContextMenuItem instead of a separate action and title.
Changed event-handling methods to return bools to signify whether the
event was handled or not. This is needed so we can know whether to hand
the event off to the OS. Also restructured some code to use early
returns instead of nesting ifs.
* page/EventHandler.cpp:
(WebCore::EventHandler::handleMousePressEventDoubleClick):
(WebCore::EventHandler::handleMousePressEventTripleClick):
(WebCore::EventHandler::handleMousePressEventSingleClick):
(WebCore::EventHandler::handleMousePressEvent):
(WebCore::EventHandler::handleMouseMoveEvent):
(WebCore::EventHandler::handleMouseReleaseEvent):
(WebCore::EventHandler::handleMouseDoubleClickEvent):
(WebCore::EventHandler::handleWheelEvent):
(WebCore::EventHandler::canMouseDownStartSelect):
* page/EventHandler.h:
* page/FrameView.cpp:
(WebCore::FrameView::handleMouseMoveEvent):
(WebCore::FrameView::handleMouseReleaseEvent):
* page/FrameView.h:
* platform/ScrollBar.h: More bool return values.
(WebCore::Scrollbar::handleMouseMoveEvent):
(WebCore::Scrollbar::handleMouseOutEvent):
* platform/Widget.h: Ditto.
(WebCore::Widget::handleMouseMoveEvent):
(WebCore::Widget::handleMouseReleaseEvent):
Reverted the changes made in r17805 so that we can have fewer header
#includes.
* page/Page.cpp:
(WebCore::Page::Page):
* page/Page.h: Ditto.
(WebCore::Page::dragCaretController):
(WebCore::Page::chrome):
(WebCore::Page::contextMenuController):
2006-11-28 Alice Liu <alice.liu@apple.com>
Reviewed by Justin and Adam.
......@@ -131,7 +131,7 @@ __ZN7WebCore10EventNames10clickEventE
__ZN7WebCore10EventNames12keydownEventE
__ZN7WebCore10MouseEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowEiiiiibbbbtPNS_15EventTargetNodeEPNS_9ClipboardEb
__ZN7WebCore10StringImplD1Ev
__ZN7WebCore11ContextMenu26setPlatformMenuDescriptionEP14NSMutableArray
__ZN7WebCore11ContextMenu22setPlatformDescriptionEP14NSMutableArray
__ZN7WebCore11EditCommand7reapplyEv
__ZN7WebCore11EditCommand7unapplyEv
__ZN7WebCore11FrameLoader11completeURLERKNS_6StringE
......
......@@ -21,6 +21,8 @@
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
06027CAD0B1CBFC000884B2D /* ContextMenuItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
06027CB30B1CC03D00884B2D /* ContextMenuItemMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */; };
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 */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -2988,6 +2990,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ContextMenuItem.h; sourceTree = "<group>"; };
06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuItemMac.mm; sourceTree = "<group>"; };
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>"; };
......@@ -6590,6 +6594,7 @@
6582A14809999D6C00BEEB6D /* mac */ = {
isa = PBXGroup;
children = (
06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */,
65A640F00533BB1F0085E777 /* BlockExceptions.h */,
65F80697054D9F86008BF776 /* BlockExceptions.mm */,
2D90660B0665D937006B6F1A /* ClipboardMac.h */,
......@@ -8817,6 +8822,7 @@
BCC8CFCA0986CD2400140BF2 /* ColorData.gperf */,
93B6A0E70B0BCA6700F5027A /* ContextMenu.cpp */,
93B6A0E50B0BCA5C00F5027A /* ContextMenu.h */,
06027CAC0B1CBFC000884B2D /* ContextMenuItem.h */,
9352088109BD45E900F2038D /* CookieJar.h */,
1A98955A0AA78149005EF5EF /* CString.cpp */,
1A98955B0AA78149005EF5EF /* CString.h */,
......@@ -10834,6 +10840,7 @@
B2D87C820B124E7300B0DE1E /* SVGPaintServerSolid.h in Headers */,
A7352C1A0B1BB89D00A986D0 /* RenderSVGBlock.h in Headers */,
4B8AF4AA0B1CE02B00687690 /* ClipboardAccessPolicy.h in Headers */,
06027CAD0B1CBFC000884B2D /* ContextMenuItem.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -10871,7 +10878,6 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
knownRegions = (
English,
......@@ -10886,7 +10892,6 @@
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
projectRoot = "";
shouldCheckCompatibility = 1;
targets = (
93F198A508245E59001E9ABC /* WebCore */,
DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
......@@ -12150,6 +12155,7 @@
B2D87C890B124E9500B0DE1E /* SVGPaintServerPatternCg.cpp in Sources */,
B2D87C8A0B124E9500B0DE1E /* SVGPaintServerSolidCg.cpp in Sources */,
A7352C190B1BB89D00A986D0 /* RenderSVGBlock.cpp in Sources */,
06027CB30B1CC03D00884B2D /* ContextMenuItemMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -26,6 +26,7 @@
#include "config.h"
#include "EventTargetNode.h"
#include "ContextMenuController.h"
#include "Document.h"
#include "Element.h"
#include "Event.h"
......@@ -39,6 +40,7 @@
#include "KeyboardEvent.h"
#include "MouseEvent.h"
#include "MutationEvent.h"
#include "Page.h"
#include "PlatformMouseEvent.h"
#include "PlatformWheelEvent.h"
#include "RegisteredEventListener.h"
......@@ -534,6 +536,13 @@ void EventTargetNode::defaultEventHandler(Event* event)
event->setDefaultHandled();
}
}
#ifdef WEBCORE_CONTEXT_MENUS
else if (event->type() == contextmenuEvent) {
if (Frame* frame = document()->frame())
if (Page* page = frame->page())
page->contextMenuController()->handleContextMenuEvent(event);
}
#endif
}
#ifndef NDEBUG
......
......@@ -28,6 +28,7 @@
namespace WebCore {
class ContextMenu;
class ContextMenuItem;
class Frame;
class HitTestResult;
class KURL;
......@@ -38,6 +39,7 @@ namespace WebCore {
virtual void contextMenuDestroyed() = 0;
virtual void addCustomContextMenuItems(ContextMenu*) = 0;
virtual void contextMenuItemSelected(ContextMenuItem*) = 0;
virtual void copyLinkToClipboard(HitTestResult) = 0;
virtual void downloadURL(KURL url) = 0;
......
......@@ -26,6 +26,7 @@
#include "config.h"
#include "ContextMenuController.h"
#include "Chrome.h"
#include "ContextMenu.h"
#include "ContextMenuClient.h"
#include "Document.h"
......@@ -48,6 +49,7 @@
#include "RenderObject.h"
#include "ReplaceSelectionCommand.h"
#include "ResourceRequest.h"
#include "SelectionController.h"
#include "markup.h"
namespace WebCore {
......@@ -70,10 +72,10 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
{
ASSERT(event->type() == contextmenuEvent);
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
HitTestResult result(IntPoint(mouseEvent->x(), mouseEvent->y()));
HitTestResult result(IntPoint(mouseEvent->pageX(), mouseEvent->pageY()));
if (RenderObject* renderer = event->target()->renderer())
if (RenderLayer* layer = renderer->layer())
if (RenderLayer* layer = renderer->enclosingLayer())
layer->hitTest(HitTestRequest(false, true), result);
if (!result.innerNonSharedNode())
......@@ -83,6 +85,8 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
m_contextMenu->populate();
m_client->addCustomContextMenuItems(m_contextMenu.get());
m_contextMenu->show();
event->setDefaultHandled();
}
static String makeGoogleSearchURL(String searchString)
......@@ -97,14 +101,22 @@ static String makeGoogleSearchURL(String searchString)
return url;
}
void ContextMenuController::contextMenuActionSelected(ContextMenuAction action, String title)
void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
{
ASSERT(item->menu() == contextMenu());
ASSERT(item->type() == ActionType);
if (item->action() >= ContextMenuItemBaseApplicationTag) {
m_client->contextMenuItemSelected(item);
return;
}
Frame* frame = m_contextMenu->hitTestResult().innerNonSharedNode()->document()->frame();
if (!frame)
return;
ASSERT(m_page == frame->page());
switch (action) {
switch (item->action()) {
case ContextMenuItemTagOpenLinkInNewWindow: {
ResourceRequest request = ResourceRequest(m_contextMenu->hitTestResult().absoluteLinkURL());
String referrer = frame->loader()->referrer();
......@@ -172,10 +184,10 @@ void ContextMenuController::contextMenuActionSelected(ContextMenuAction action,
frame->editor()->paste();
break;
case ContextMenuItemTagSpellingGuess:
ASSERT(frame->selectedText().length() != 0);
if (frame->editor()->shouldInsertText(title, frame->selectionController()->toRange().get(), EditorInsertActionPasted)) {
ASSERT(frame->selectedText().length());
if (frame->editor()->shouldInsertText(item->title(), frame->selectionController()->toRange().get(), EditorInsertActionPasted)) {
Document* document = frame->document();
applyCommand(new ReplaceSelectionCommand(document, createFragmentFromMarkup(document, title, ""),
applyCommand(new ReplaceSelectionCommand(document, createFragmentFromMarkup(document, item->title(), ""),
true, false, true));
frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
......
......@@ -47,8 +47,10 @@ namespace WebCore {
ContextMenuClient* client() { return m_client; }
ContextMenu* contextMenu() const { return m_contextMenu.get(); }
void handleContextMenuEvent(Event*);
void contextMenuActionSelected(ContextMenuAction, String);
void contextMenuItemSelected(ContextMenuItem*);
private:
Page* m_page;
......
This diff is collapsed.
......@@ -112,10 +112,10 @@ public:
bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
bool inputManagerHasMarkedText() const;
void handleMousePressEvent(const PlatformMouseEvent&);
void handleMouseMoveEvent(const PlatformMouseEvent&);
void handleMouseReleaseEvent(const PlatformMouseEvent&);
void handleWheelEvent(PlatformWheelEvent&);
bool handleMousePressEvent(const PlatformMouseEvent&);
bool handleMouseMoveEvent(const PlatformMouseEvent&);
bool handleMouseReleaseEvent(const PlatformMouseEvent&);
bool handleWheelEvent(PlatformWheelEvent&);
bool sendContextMenuEvent(PlatformMouseEvent);
......@@ -152,14 +152,14 @@ public:
private:
void selectClosestWordFromMouseEvent(const PlatformMouseEvent&, Node* innerNode);
void handleMouseDoubleClickEvent(const PlatformMouseEvent&);
bool handleMouseDoubleClickEvent(const PlatformMouseEvent&);
void handleMousePressEvent(const MouseEventWithHitTestResults&);
void handleMousePressEventSingleClick(const MouseEventWithHitTestResults&);
void handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
void handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
void handleMouseMoveEvent(const MouseEventWithHitTestResults&);
void handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
bool handleMousePressEvent(const MouseEventWithHitTestResults&);
bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&);
bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
bool handleMouseMoveEvent(const MouseEventWithHitTestResults&);
bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
void hoverTimerFired(Timer<EventHandler>*);
......
......@@ -844,14 +844,14 @@ IntRect FrameView::windowClipRectForLayer(const RenderLayer* layer, bool clipToL
return intersection(clipRect, windowClipRect());
}
void FrameView::handleMouseMoveEvent(const PlatformMouseEvent& event)
bool FrameView::handleMouseMoveEvent(const PlatformMouseEvent& event)
{
m_frame->eventHandler()->handleMouseMoveEvent(event);
return m_frame->eventHandler()->handleMouseMoveEvent(event);
}
void FrameView::handleMouseReleaseEvent(const PlatformMouseEvent& event)
bool FrameView::handleMouseReleaseEvent(const PlatformMouseEvent& event)
{
m_frame->eventHandler()->handleMouseReleaseEvent(event);
return m_frame->eventHandler()->handleMouseReleaseEvent(event);
}
}
......@@ -129,8 +129,8 @@ public:
void setMediaType(const String&);
virtual void handleMouseMoveEvent(const PlatformMouseEvent&);
virtual void handleMouseReleaseEvent(const PlatformMouseEvent&);
virtual bool handleMouseMoveEvent(const PlatformMouseEvent&);
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&);
void scheduleEvent(PassRefPtr<Event>, PassRefPtr<EventTargetNode>, bool tempEvent);
......
......@@ -21,12 +21,15 @@
#include "config.h"
#include "Page.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "ContextMenuClient.h"
#include "ContextMenuController.h"
#include "EditorClient.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "SelectionController.h"
#include "StringHash.h"
#include "Widget.h"
#include <kjs/collector.h>
......@@ -41,9 +44,9 @@ static HashSet<Page*>* allPages;
static HashMap<String, HashSet<Page*>*>* frameNamespaces;
Page::Page(ChromeClient* chromeClient, ContextMenuClient* contextMenuClient, EditorClient* editorClient)
: m_dragCaretController(0, true)
, m_chrome(this, chromeClient)
, m_contextMenuController(this, contextMenuClient)
: m_dragCaretController(new SelectionController(0, true))
, m_chrome(new Chrome(this, chromeClient))
, m_contextMenuController(new ContextMenuController(this, contextMenuClient))
, m_editorClient(editorClient)
, m_frameCount(0)
, m_defersLoading(false)
......
......@@ -21,10 +21,7 @@
#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>
......@@ -34,12 +31,15 @@ typedef struct HINSTANCE__* HINSTANCE;
namespace WebCore {
class Chrome;
class ChromeClient;
class ContextMenuClient;
class ContextMenuController;
class EditorClient;
class Frame;
class FrameNamespace;
class FloatRect;
class SelectionController;
class Settings;
class Widget;
......@@ -66,9 +66,9 @@ namespace WebCore {
static void setNeedsReapplyStyles();
static void setNeedsReapplyStylesForSettingsChange(Settings*);
SelectionController* dragCaretController() { return &m_dragCaretController; }
Chrome* chrome() { return &m_chrome; }
ContextMenuController* contextMenuController() { return &m_contextMenuController; }
SelectionController* dragCaretController() { return m_dragCaretController.get(); }
Chrome* chrome() { return m_chrome.get(); }
ContextMenuController* contextMenuController() { return m_contextMenuController.get(); }
void setDefersLoading(bool);
bool defersLoading() const { return m_defersLoading; }
......@@ -80,9 +80,9 @@ namespace WebCore {
#endif
private:
SelectionController m_dragCaretController;
Chrome m_chrome;
ContextMenuController m_contextMenuController;
OwnPtr<SelectionController> m_dragCaretController;
OwnPtr<Chrome> m_chrome;
OwnPtr<ContextMenuController> m_contextMenuController;
EditorClient* m_editorClient;
RefPtr<Frame> m_mainFrame;
......
......@@ -51,6 +51,8 @@ ContextMenuController* ContextMenu::controller() const
void ContextMenu::populate()
{
static ContextMenuItem SeparatorItem(SeparatorType, ContextMenuItemTagNoAction, String());
MENU_ACTION_ITEM(OpenLinkInNewWindow, "Open Link in New Window");
MENU_ACTION_ITEM(DownloadLinkToDisk, "Download Linked File");
MENU_ACTION_ITEM(CopyLinkToClipboard, "Copy Link");
......@@ -69,14 +71,13 @@ void ContextMenu::populate()
MENU_ACTION_ITEM(NoGuessesFound, "No Guesses Found");
MENU_ACTION_ITEM(IgnoreSpelling, "Ignore Spelling");
MENU_ACTION_ITEM(LearnSpelling, "Learn Spelling");
#if PLATFORM(MAC)
#if PLATFORM(MAC)
MENU_ACTION_ITEM(SearchInSpotlight, "Search in Spotlight");
#endif
#endif
MENU_ACTION_ITEM(SearchWeb, "Search in Google");
MENU_ACTION_ITEM(LookUpInDictionary, "Look Up in Dictionary");
// FIXME: Add PDF action items
ContextMenuItem SeparatorItem(SeparatorType, ContextMenuItemTagNoAction, String());
HitTestResult result = hitTestResult();
Node* node = m_hitTestResult.innerNonSharedNode();
......@@ -110,9 +111,9 @@ void ContextMenu::populate()
if (imageURL.isEmpty() && linkURL.isEmpty()) {
if (result.isSelected()) {
#if PLATFORM(MAC)
#if PLATFORM(MAC)
appendItem(SearchInSpotlightItem);
#endif
#endif
appendItem(SearchWebItem);
appendItem(SeparatorItem);
appendItem(LookUpInDictionaryItem);
......@@ -147,8 +148,10 @@ void ContextMenu::populate()
else {
for (unsigned i = 0; i < size; i++) {
String guess = guesses[i];
if (!guess.isNull())
appendItem(ContextMenuItem(ActionType, ContextMenuItemTagSpellingGuess, guess));
if (!guess.isNull()) {
ContextMenuItem item(ActionType, ContextMenuItemTagSpellingGuess, guess);
appendItem(item);
}
}
}
......@@ -159,9 +162,9 @@ void ContextMenu::populate()
}
if (result.isSelected() && !inPasswordField) {
#if PLATFORM(MAC)
#if PLATFORM(MAC)
appendItem(SearchInSpotlightItem);
#endif
#endif
appendItem(SearchWebItem);
appendItem(SeparatorItem);
......@@ -172,9 +175,8 @@ void ContextMenu::populate()
appendItem(CutItem);
appendItem(CopyItem);
appendItem(PasteItem);
appendItem(SeparatorItem);
// FIXME: Add "Spelling [and Grammar, on Leopard]", "Font", "Speech", "Writing Direction" submenus here.
// FIXME: Add a separator, then "Spelling [and Grammar, on Leopard]", "Font", "Speech", "Writing Direction" submenus here.
}
}
......
......@@ -26,6 +26,9 @@
#ifndef ContextMenu_h
#define ContextMenu_h
#include <wtf/Noncopyable.h>
#include "ContextMenuItem.h"
#include "HitTestResult.h"
#include "PlatformString.h"
......@@ -43,111 +46,47 @@ 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
ContextMenuItemTagOpenLinkInNewWindow=1,
ContextMenuItemTagDownloadLinkToDisk,
ContextMenuItemTagCopyLinkToClipboard,
ContextMenuItemTagOpenImageInNewWindow,
ContextMenuItemTagDownloadImageToDisk,
ContextMenuItemTagCopyImageToClipboard,
ContextMenuItemTagOpenFrameInNewWindow,
ContextMenuItemTagCopy,
ContextMenuItemTagGoBack,
ContextMenuItemTagGoForward,
ContextMenuItemTagStop,
ContextMenuItemTagReload,
ContextMenuItemTagCut,
ContextMenuItemTagPaste,
ContextMenuItemTagSpellingGuess,
ContextMenuItemTagNoGuessesFound,
ContextMenuItemTagIgnoreSpelling,
ContextMenuItemTagLearnSpelling,
ContextMenuItemTagOther,
ContextMenuItemTagSearchInSpotlight,
ContextMenuItemTagSearchWeb,
ContextMenuItemTagLookUpInDictionary,
ContextMenuItemTagOpenWithDefaultApplication,
ContextMenuItemPDFActualSize,
ContextMenuItemPDFZoomIn,
ContextMenuItemPDFZoomOut,
ContextMenuItemPDFAutoSize,
ContextMenuItemPDFSinglePage,
ContextMenuItemPDFFacingPages,
ContextMenuItemPDFContinuous,
ContextMenuItemPDFNextPage,
ContextMenuItemPDFPreviousPage,
};
enum ContextMenuItemType {
ActionType,
SeparatorType,
SubmenuType
};
struct ContextMenuItem {
ContextMenuItem()
: type(SeparatorType)
, action(ContextMenuItemTagNoAction)
, 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;
};
class ContextMenuController;
#if PLATFORM(MAC)
typedef NSMutableArray* PlatformMenuDescription;
typedef NSMutableArray* PlatformMenuDescription;
#elif PLATFORM(WIN)
typedef HMENU PlatformMenuDescription;
typedef HMENU PlatformMenuDescription;
#elif PLATFORM(QT)
typedef QMenu* PlatformMenuDescription;
typedef QMenu* PlatformMenuDescription;
#endif
class ContextMenu : Noncopyable
{
public:
ContextMenu(HitTestResult result)
: m_hitTestResult(result)
, m_menu(0)
class ContextMenu : Noncopyable
{
}
public:
ContextMenu(HitTestResult result)
: m_hitTestResult(result)
, m_menu(0)
{
}
void populate();
void populate();
void show();
void hide();
void show();
void hide();
void insertItem(unsigned position, ContextMenuItem);
void appendItem(ContextMenuItem item);
void insertItem(unsigned position, const ContextMenuItem&);
void appendItem(const ContextMenuItem&);
ContextMenuItem at(unsigned index);
unsigned itemCount();
unsigned itemCount() const;
HitTestResult hitTestResult() const { return m_hitTestResult; }
ContextMenuController* controller() const;
HitTestResult hitTestResult() const { return m_hitTestResult; }
ContextMenuController* controller() const;
PlatformMenuDescription platformMenuDescription() { return m_menu; }
void setPlatformMenuDescription(PlatformMenuDescription menu);
PlatformMenuDescription platformDescription() const { return m_menu; }
void setPlatformDescription(PlatformMenuDescription menu);
private:
HitTestResult m_hitTestResult;
PlatformMenuDescription m_menu;
};
private:
HitTestResult m_hitTestResult;
PlatformMenuDescription m_menu;
};
}
......
/*
* 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