Commit 77c4276e authored by bdakin's avatar bdakin

WebCore:

        Reviewed by Adam.

        Turn on WebCore context menus.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::defaultEventHandler): Turn on WebCore 
        menus.
        * page/ContextMenuClient.h: Name change and have the 
        former getCustomMenuFromDefaultItems function return the 
        PlatformMenuDescription since it feels funny to have the client set 
        the new platform description.
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::handleContextMenuEvent): Above 
        name change.
        (WebCore::ContextMenuController::contextMenuItemSelected): Use 
        local variable.
        * platform/ContextMenu.cpp:
        (WebCore::createAndAppendSpeechSubMenu): Fix silly mistake -- make 
        "Stop speaking" actually stop speaking.
        * platform/graphics/svg/SVGImageEmptyClients.h: Name change and 
        have the former getCustomMenuFromDefaultItems function return the 
        PlatformMenuDescription since it feels funny to have the client set 
        the new platform description.
       (WebCore::SVGEmptyContextMenuClient::getCustomMenuFromDefaultItems):

WebKit:
        Reviewed by Adam.

        Turn on WebCore context menus. Delete a bunch of WebKit context 
        menu code that is no longer needed.

        * DefaultDelegates/WebDefaultContextMenuDelegate.m: Removed a lot 
        of code from this class. This class only still needs to exist for 
        PDF context menus, so we only need to deal with the menu items that 
        might possibly be added to a PDF context menu.
        (-[WebDefaultUIDelegate 
        menuItemWithTag:target:representedObject:]): Same.
        (-[WebDefaultUIDelegate 
        webView:contextMenuItemsForElement:defaultMenuItems:]): Same.
        * WebCoreSupport/WebContextMenuClient.h: Name change and have the 
        former getCustomMenuFromDefaultItems function return the 
        PlatformMenuDescription since it feels funny to have the client set 
        the new platform description.
        * WebCoreSupport/WebContextMenuClient.mm: Same.
        (WebContextMenuClient::getCustomMenuFromDefaultItems): Same. Also 
        move in some code that used to be in _menuForElement.
        * WebView/WebHTMLView.m: Deleted a bunch of un-used functions
        (-[WebHTMLView menuForEvent:]): Turn on menus, and append the 
        Inspect Element item. 
        * WebView/WebHTMLViewPrivate.h: Deleted a bunch of un-used 
        functions.
        * WebView/WebView.mm:
        (-[WebView _menuForElement:defaultItems:]): Removed a lot of code 
        from _menuForElement that now makes more sense elsewhere. Only PDF 
        context menus use this function now. Hopefully we can just get rid 
        of it soon, too.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18592 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 94c9d590
2007-01-04 Beth Dakin <bdakin@apple.com>
Reviewed by Adam.
Turn on WebCore context menus.
* dom/EventTargetNode.cpp:
(WebCore::EventTargetNode::defaultEventHandler): Turn on WebCore
menus.
* page/ContextMenuClient.h: Name change and have the
former getCustomMenuFromDefaultItems function return the
PlatformMenuDescription since it feels funny to have the client set
the new platform description.
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::handleContextMenuEvent): Above
name change.
(WebCore::ContextMenuController::contextMenuItemSelected): Use
local variable.
* platform/ContextMenu.cpp:
(WebCore::createAndAppendSpeechSubMenu): Fix silly mistake -- make
"Stop speaking" actually stop speaking.
* platform/graphics/svg/SVGImageEmptyClients.h: Name change and
have the former getCustomMenuFromDefaultItems function return the
PlatformMenuDescription since it feels funny to have the client set
the new platform description.
(WebCore::SVGEmptyContextMenuClient::getCustomMenuFromDefaultItems):
2007-01-04 Mitz Pettel <mitz@webkit.org>
Reviewed and landed by Brady
......
......@@ -569,14 +569,11 @@ void EventTargetNode::defaultEventHandler(Event* event)
} else if (eventType == clickEvent) {
int detail = event->isUIEvent() ? static_cast<UIEvent*>(event)->detail() : 0;
dispatchUIEvent(DOMActivateEvent, detail, event);
}
#ifdef WEBCORE_CONTEXT_MENUS
else if (eventType == contextmenuEvent) {
} else if (eventType == contextmenuEvent) {
if (Frame* frame = document()->frame())
if (Page* page = frame->page())
page->contextMenuController()->handleContextMenuEvent(event);
}
#endif
}
#ifndef NDEBUG
......
......@@ -26,6 +26,8 @@
#ifndef ContextMenuClient_h
#define ContextMenuClient_h
#include "PlatformMenuDescription.h"
namespace WebCore {
class ContextMenu;
class ContextMenuItem;
......@@ -39,7 +41,7 @@ namespace WebCore {
virtual ~ContextMenuClient() { }
virtual void contextMenuDestroyed() = 0;
virtual void addCustomContextMenuItems(ContextMenu*) = 0;
virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*) = 0;
virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) = 0;
virtual void downloadURL(const KURL& url) = 0;
......
......@@ -83,7 +83,8 @@ void ContextMenuController::handleContextMenuEvent(Event* event)
m_contextMenu.set(new ContextMenu(result));
m_contextMenu->populate();
m_client->addCustomContextMenuItems(m_contextMenu.get());
PlatformMenuDescription customMenu = m_client->getCustomMenuFromDefaultItems(m_contextMenu.get());
m_contextMenu->setPlatformDescription(customMenu);
m_contextMenu->show();
event->setDefaultHandled();
......@@ -133,7 +134,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
m_client->downloadURL(result.absoluteLinkURL());
break;
case ContextMenuItemTagCopyLinkToClipboard:
frame->editor()->copyURL(m_contextMenu->hitTestResult().absoluteLinkURL(), m_contextMenu->hitTestResult().textContent());
frame->editor()->copyURL(result.absoluteLinkURL(), result.textContent());
break;
case ContextMenuItemTagOpenImageInNewWindow:
openNewWindow(result.absoluteImageURL(), frame);
......
......@@ -134,7 +134,7 @@ static void createAndAppendSpeechSubMenu(const HitTestResult& result, ContextMen
{
ContextMenu* speechMenu = new ContextMenu(result);
ContextMenuItem start(ActionType, ContextMenuItemTagStartSpeaking, contextMenuItemTagStartSpeaking());
ContextMenuItem stop(ActionType, ContextMenuItemTagStartSpeaking, contextMenuItemTagStartSpeaking());
ContextMenuItem stop(ActionType, ContextMenuItemTagStopSpeaking, contextMenuItemTagStopSpeaking());
speechMenu->appendItem(start);
speechMenu->appendItem(stop);
......
......@@ -324,7 +324,7 @@ public:
virtual ~SVGEmptyContextMenuClient() { }
virtual void contextMenuDestroyed() { }
virtual void addCustomContextMenuItems(ContextMenu*) { }
virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*) { return 0; }
virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) { }
virtual void downloadURL(const KURL& url) { }
......
2007-01-04 Beth Dakin <bdakin@apple.com>
Reviewed by Adam.
Turn on WebCore context menus. Delete a bunch of WebKit context
menu code that is no longer needed.
* DefaultDelegates/WebDefaultContextMenuDelegate.m: Removed a lot
of code from this class. This class only still needs to exist for
PDF context menus, so we only need to deal with the menu items that
might possibly be added to a PDF context menu.
(-[WebDefaultUIDelegate
menuItemWithTag:target:representedObject:]): Same.
(-[WebDefaultUIDelegate
webView:contextMenuItemsForElement:defaultMenuItems:]): Same.
* WebCoreSupport/WebContextMenuClient.h: Name change and have the
former getCustomMenuFromDefaultItems function return the
PlatformMenuDescription since it feels funny to have the client set
the new platform description.
* WebCoreSupport/WebContextMenuClient.mm: Same.
(WebContextMenuClient::getCustomMenuFromDefaultItems): Same. Also
move in some code that used to be in _menuForElement.
* WebView/WebHTMLView.m: Deleted a bunch of un-used functions
(-[WebHTMLView menuForEvent:]): Turn on menus, and append the
Inspect Element item.
* WebView/WebHTMLViewPrivate.h: Deleted a bunch of un-used
functions.
* WebView/WebView.mm:
(-[WebView _menuForElement:defaultItems:]): Removed a lot of code
from _menuForElement that now makes more sense elsewhere. Only PDF
context menus use this function now. Hopefully we can just get rid
of it soon, too.
2007-01-04 Anders Carlsson <acarlsson@apple.com>
Reviewed by Brady.
......
......@@ -38,7 +38,7 @@ public:
virtual void contextMenuDestroyed();
virtual void addCustomContextMenuItems(WebCore::ContextMenu*);
virtual NSMutableArray* getCustomMenuFromDefaultItems(WebCore::ContextMenu*);
virtual void contextMenuItemSelected(WebCore::ContextMenuItem*, const WebCore::ContextMenu*);
virtual void downloadURL(const WebCore::KURL&);
......
......@@ -57,14 +57,35 @@ void WebContextMenuClient::contextMenuDestroyed()
delete this;
}
void WebContextMenuClient::addCustomContextMenuItems(ContextMenu* menu)
NSMutableArray* WebContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu* defaultMenu)
{
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->platformDescription()];
menu->setPlatformDescription(newMenu);
NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:defaultMenu->hitTestResult()] autorelease];
NSMutableArray *defaultMenuItems = defaultMenu->platformDescription();
NSMutableArray *newMenuItems = [[delegate webView:m_webView contextMenuItemsForElement:element defaultMenuItems:defaultMenuItems] mutableCopy];
// Versions of Mail compiled with older WebKits will end up without three context menu items,
// though with the separators between them. Here we check for that problem and reinsert the
// three missing items. This shouldn't affect any clients other than Mail since the tags for
// the three items were not public API. We can remove this code when we no longer support
// previously-built versions of Mail on Tiger. See 4498606 for more details.
if ([newMenuItems count] &&
([[defaultMenuItems objectAtIndex:0] tag] == WebMenuItemTagSearchInSpotlight) &&
([[newMenuItems objectAtIndex:0] isSeparatorItem])) {
ASSERT([[newMenuItems objectAtIndex:1] isSeparatorItem]);
ASSERT([[defaultMenuItems objectAtIndex:1] tag] == WebMenuItemTagSearchWeb);
ASSERT([[defaultMenuItems objectAtIndex:2] isSeparatorItem]);
ASSERT([[defaultMenuItems objectAtIndex:3] tag] == WebMenuItemTagLookUpInDictionary);
ASSERT([[defaultMenuItems objectAtIndex:4] isSeparatorItem]);
[newMenuItems insertObject:[defaultMenuItems objectAtIndex:0] atIndex:0];
[newMenuItems insertObject:[defaultMenuItems objectAtIndex:1] atIndex:1];
[newMenuItems insertObject:[defaultMenuItems objectAtIndex:3] atIndex:3];
}
return [newMenuItems autorelease];
}
return nil;
}
void WebContextMenuClient::contextMenuItemSelected(ContextMenuItem* item, const ContextMenu* parentMenu)
......
......@@ -1633,60 +1633,6 @@ - (BOOL)_isEditable
return coreFrame->selectionController()->isContentEditable();
}
- (BOOL)_isSelectionInPasswordField
{
Frame* coreFrame = core([self _frame]);
if (!coreFrame)
return NO;
return coreFrame->selectionController()->isInPasswordField();
}
- (BOOL)_isSelectionUngrammatical
{
if (Frame* coreFrame = core([self _frame]))
return coreFrame->editor()->isSelectionUngrammatical();
return NO;
}
- (BOOL)_isSelectionMisspelled
{
if (Frame* coreFrame = core([self _frame]))
return coreFrame->editor()->isSelectionMisspelled();
return NO;
}
- (NSArray *)_guessesForMisspelledSelection
{
ASSERT([[self selectedString] length] != 0);
return [[NSSpellChecker sharedSpellChecker] guessesForWord:[self selectedString]];
}
- (void)_changeSpellingFromMenu:(id)sender
{
ASSERT([[self selectedString] length] != 0);
if ([self _shouldReplaceSelectionWithText:[sender title] givenAction:WebViewInsertActionPasted]) {
[[self _bridge] replaceSelectionWithText:[sender title] selectReplacement:YES smartReplace:NO];
}
}
- (void)_ignoreSpellingFromMenu:(id)sender
{
ASSERT([[self selectedString] length] != 0);
[[NSSpellChecker sharedSpellChecker] ignoreWord:[self selectedString] inSpellDocumentWithTag:[[self _webView] spellCheckerDocumentTag]];
}
- (void)_ignoreGrammarFromMenu:(id)sender
{
// NSSpellChecker uses the same API for ignoring grammar as for ignoring spelling
[self _ignoreSpellingFromMenu:(id)sender];
}
- (void)_learnSpellingFromMenu:(id)sender
{
ASSERT([[self selectedString] length] != 0);
[[NSSpellChecker sharedSpellChecker] learnWord:[self selectedString]];
}
- (BOOL)_transparentBackground
{
return _private->transparentBackground;
......@@ -2594,7 +2540,6 @@ - (NSMenu *)menuForEvent:(NSEvent *)event
_private->handlingMouseDownEvent = NO;
if (handledEvent && coreframe) {
#ifdef WEBCORE_CONTEXT_MENUS
if (Page* page = coreframe->page()) {
NSArray* menuItems = page->contextMenuController()->contextMenu()->platformDescription();
NSMenu* menu = nil;
......@@ -2604,16 +2549,26 @@ - (NSMenu *)menuForEvent:(NSEvent *)event
for (unsigned i = 0; i < [menuItems count]; i++)
[menu addItem:[menuItems objectAtIndex:i]];
}
// Add the Inspect Element menu item if the preference is set or if this is a debug build
if ([WebView _developerExtrasEnabled]) {
if (!menu)
menu = [[NSMenu alloc] init];
else if ([menu numberOfItems])
[menu addItem:[NSMenuItem separatorItem]];
NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease];
[menuItem setAction:@selector(_inspectElement:)];
[menuItem setTitle:UI_STRING("Inspect Element", "Inspect Element context menu item")];
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
[menuItem setRepresentedObject:[self elementAtPoint:point]];
[menu addItem:menuItem];
}
return [menu autorelease];
}
#else
return nil;
#endif
}
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
NSDictionary *element = [self elementAtPoint:point];
return [[self _webView] _menuForElement:element defaultItems:nil];
return nil;
}
- (BOOL)searchFor:(NSString *)string direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag
......
......@@ -89,11 +89,6 @@
- (BOOL)_hasSelectionOrInsertionPoint;
- (BOOL)_isEditable;
- (BOOL)_isSelectionInPasswordField;
- (BOOL)_isSelectionUngrammatical;
- (BOOL)_isSelectionMisspelled;
- (NSArray *)_guessesForMisspelledSelection;
- (BOOL)_transparentBackground;
- (void)_setTransparentBackground:(BOOL)f;
......
......@@ -737,34 +737,8 @@ static bool debugWidget = true;
NSMenu *menu = nil;
unsigned i;
DOMNode* node = [element objectForKey:WebElementDOMNodeKey];
BOOL elementIsTextField = [node isKindOfClass:[DOMHTMLInputElement class]] && [(DOMHTMLInputElement*)node _isTextField];
BOOL elementIsTextArea = [node isKindOfClass:[DOMHTMLTextAreaElement class]];
if (_private->UIDelegate && !elementIsTextField && !elementIsTextArea) {
id cd = _private->UIDelegate;
if ([cd respondsToSelector:@selector(webView:contextMenuItemsForElement:defaultMenuItems:)]) {
menuItems = [cd webView:self contextMenuItemsForElement:element defaultMenuItems:defaultMenuItems];
// Versions of Mail compiled with older WebKits will end up without three context menu items, though
// with the separators between them. Here we check for that problem and reinsert the three missing
// items. This shouldn't affect any clients other than Mail since the tags for the three items
// were not public API. We can remove this code when we no longer support previously-built versions
// of Mail on Tiger. See 4498606 for more details.
if ([menuItems count] && ([[defaultMenuItems objectAtIndex:0] tag] == WebMenuItemTagSearchInSpotlight) && ([[menuItems objectAtIndex:0] isSeparatorItem])) {
ASSERT([[menuItems objectAtIndex:1] isSeparatorItem]);
ASSERT([[defaultMenuItems objectAtIndex:1] tag] == WebMenuItemTagSearchWeb);
ASSERT([[defaultMenuItems objectAtIndex:2] isSeparatorItem]);
ASSERT([[defaultMenuItems objectAtIndex:3] tag] == WebMenuItemTagLookUpInDictionary);
ASSERT([[defaultMenuItems objectAtIndex:4] isSeparatorItem]);
NSMutableArray *mutableMenuItems = [NSMutableArray arrayWithArray:menuItems];
[mutableMenuItems insertObject:[defaultMenuItems objectAtIndex:0] atIndex:0];
[mutableMenuItems insertObject:[defaultMenuItems objectAtIndex:1] atIndex:1];
[mutableMenuItems insertObject:[defaultMenuItems objectAtIndex:3] atIndex:3];
menuItems = mutableMenuItems;
}
}
}
if ([_private->UIDelegate respondsToSelector:@selector(webView:contextMenuItemsForElement:defaultMenuItems:)])
menuItems = [_private->UIDelegate webView:self contextMenuItemsForElement:element defaultMenuItems:defaultMenuItems];
if (menuItems && [menuItems count] > 0) {
menu = [[[NSMenu alloc] init] autorelease];
......@@ -774,21 +748,6 @@ static bool debugWidget = true;
}
}
// optionally add the Inspect Element menu item it if preference is set or in debug builds
// and only showing the menu item if we are working with a WebHTMLView
WebFrame *webFrame = [element objectForKey:WebElementFrameKey];
if ([WebView _developerExtrasEnabled] && [[[webFrame frameView] documentView] isKindOfClass:[WebHTMLView class]]) {
if (!menu)
menu = [[[NSMenu alloc] init] autorelease];
else if ([menu numberOfItems])
[menu addItem:[NSMenuItem separatorItem]];
NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease];
[menuItem setAction:@selector(_inspectElement:)];
[menuItem setTitle:UI_STRING("Inspect Element", "Inspect Element context menu item")];
[menuItem setRepresentedObject:element];
[menu addItem:menuItem];
}
return menu;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment