Commit 11202650 authored by aroben's avatar aroben

Reviewed by Beth.

        Fix <rdar://problem/4942294> REGRESSION: "Spelling and Grammar",
        "Font", "Speech", and "Writing Direction" are missing from contextual
        menu

        * WebCoreSupport/WebContextMenuClient.mm:
        (fixMenusForOldClients): Change our new SPI tags to
        WebMenuItemTagOther because old clients aren't expecting the new tags.
        (fixMenusFromOldClients): Use each menu item's title to figure out its
        correct tag again.
        (WebContextMenuClient::getCustomMenuFromDefaultItems): Call
        fixMenusForOldClients before calling up to the delegate.
        * WebView/WebUIDelegatePrivate.h: Define WEBMENUITEMTAG_SPI_START so
        that we can use it in WebContextMenuClient.



git-svn-id: svn://svn.chromium.org/blink/trunk@18995 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b7f98995
2007-01-19 Adam Roben <aroben@apple.com>
Reviewed by Beth.
Fix <rdar://problem/4942294> REGRESSION: "Spelling and Grammar",
"Font", "Speech", and "Writing Direction" are missing from contextual
menu
* WebCoreSupport/WebContextMenuClient.mm:
(fixMenusForOldClients): Change our new SPI tags to
WebMenuItemTagOther because old clients aren't expecting the new tags.
(fixMenusFromOldClients): Use each menu item's title to figure out its
correct tag again.
(WebContextMenuClient::getCustomMenuFromDefaultItems): Call
fixMenusForOldClients before calling up to the delegate.
* WebView/WebUIDelegatePrivate.h: Define WEBMENUITEMTAG_SPI_START so
that we can use it in WebContextMenuClient.
2007-01-19 John Sullivan <sullivan@apple.com>
Reviewed by Darin
......
......@@ -37,6 +37,7 @@
#import "WebUIDelegate.h"
#import "WebUIDelegatePrivate.h"
#import "WebView.h"
#import "WebViewFactory.h"
#import "WebViewInternal.h"
#import <WebCore/ContextMenu.h>
#import <WebCore/KURL.h>
......@@ -57,7 +58,22 @@ void WebContextMenuClient::contextMenuDestroyed()
delete this;
}
static NSMutableArray* fixMenusFromOldApps(NSMutableArray *newMenuItems, NSMutableArray *defaultMenuItems)
static NSMutableArray *fixMenusForOldClients(NSMutableArray *defaultMenuItems)
{
// Here we change all SPI tags listed in WebUIDelegatePrivate.h to WebMenuItemTagOther
// to match our old WebKit context menu behavior.
unsigned defaultItemsCount = [defaultMenuItems count];
for (unsigned i = 0; i < defaultItemsCount; ++i) {
NSMenuItem *item = [defaultMenuItems objectAtIndex:i];
if ([item tag] >= WEBMENUITEMTAG_SPI_START)
[item setTag:WebMenuItemTagOther];
}
return defaultMenuItems;
}
static NSMutableArray *fixMenusFromOldClients(NSMutableArray *newMenuItems, NSMutableArray *defaultMenuItems)
{
// The WebMenuItemTag enum has changed since Tiger, so clients built against Tiger WebKit might reference incorrect values for tags.
// Here we fix up Tiger Mail and Tiger Safari.
......@@ -91,7 +107,60 @@ static NSMutableArray* fixMenusFromOldApps(NSMutableArray *newMenuItems, NSMutab
}
}
// Nothing needs to be done
unsigned defaultItemsCount = [defaultMenuItems count];
for (unsigned i = 0; i < defaultItemsCount; ++i) {
NSMenuItem *item = [defaultMenuItems objectAtIndex:i];
if ([item tag] != WebMenuItemTagOther)
continue;
NSString *title = [item title];
if (title == [[WebViewFactory sharedFactory] contextMenuItemTagOpenLink])
[item setTag:WebMenuItemTagOpenLink];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagIgnoreGrammar])
[item setTag:WebMenuItemTagIgnoreGrammar];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagSpellingMenu])
[item setTag:WebMenuItemTagSpellingMenu];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagShowSpellingPanel:true]
|| title == [[WebViewFactory sharedFactory] contextMenuItemTagShowSpellingPanel:false])
[item setTag:WebMenuItemTagShowSpellingPanel];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagCheckSpelling])
[item setTag:WebMenuItemTagCheckSpelling];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagCheckSpellingWhileTyping])
[item setTag:WebMenuItemTagCheckSpellingWhileTyping];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagCheckGrammarWithSpelling])
[item setTag:WebMenuItemTagCheckGrammarWithSpelling];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagFontMenu])
[item setTag:WebMenuItemTagFontMenu];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagShowFonts])
[item setTag:WebMenuItemTagShowFonts];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagBold])
[item setTag:WebMenuItemTagBold];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagItalic])
[item setTag:WebMenuItemTagItalic];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagUnderline])
[item setTag:WebMenuItemTagUnderline];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagOutline])
[item setTag:WebMenuItemTagOutline];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagStyles])
[item setTag:WebMenuItemTagStyles];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagShowColors])
[item setTag:WebMenuItemTagShowColors];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagSpeechMenu])
[item setTag:WebMenuItemTagSpeechMenu];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagStartSpeaking])
[item setTag:WebMenuItemTagStartSpeaking];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagStopSpeaking])
[item setTag:WebMenuItemTagStopSpeaking];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagWritingDirectionMenu])
[item setTag:WebMenuItemTagWritingDirectionMenu];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagDefaultDirection])
[item setTag:WebMenuItemTagDefaultDirection];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagLeftToRight])
[item setTag:WebMenuItemTagLeftToRight];
else if (title == [[WebViewFactory sharedFactory] contextMenuItemTagRightToLeft])
[item setTag:WebMenuItemTagRightToLeft];
}
return [newMenuItems autorelease];
}
......@@ -102,10 +171,10 @@ NSMutableArray* WebContextMenuClient::getCustomMenuFromDefaultItems(ContextMenu*
return nil;
NSDictionary *element = [[[WebElementDictionary alloc] initWithHitTestResult:defaultMenu->hitTestResult()] autorelease];
NSMutableArray *defaultMenuItems = defaultMenu->platformDescription();
NSMutableArray *defaultMenuItems = fixMenusForOldClients(defaultMenu->platformDescription());
NSMutableArray *newMenuItems = [[delegate webView:m_webView contextMenuItemsForElement:element defaultMenuItems:defaultMenuItems] mutableCopy];
return fixMenusFromOldApps(newMenuItems, defaultMenuItems);
return fixMenusFromOldClients(newMenuItems, defaultMenuItems);
}
void WebContextMenuClient::contextMenuItemSelected(ContextMenuItem* item, const ContextMenu* parentMenu)
......
......@@ -29,8 +29,9 @@
#import <WebKit/WebUIDelegate.h>
// FIXME: These should move to WebUIDelegate.h as part of the WebMenuItemTag enum there, when we're not in API freeze
#define WEBMENUITEMTAG_SPI_START 1000
enum {
WebMenuItemTagOpenLink = 1000,
WebMenuItemTagOpenLink = WEBMENUITEMTAG_SPI_START,
WebMenuItemTagIgnoreGrammar,
WebMenuItemTagSpellingMenu,
WebMenuItemTagShowSpellingPanel,
......
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