WebCore:
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Nov 2006 22:07:17 +0000 (22:07 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Nov 2006 22:07:17 +0000 (22:07 +0000)
        Reviewed by Beth.

        Store ContextMenu's NSMutableArray inside a RetainPtr so that we
        will retain/release it correctly.

        * WebCore.exp:
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::populate): Added a FIXME.
        * platform/ContextMenu.h:
        * platform/mac/ContextMenuMac.mm:
        (WebCore::ContextMenu::ContextMenu):
        (WebCore::ContextMenu::~ContextMenu):
        (WebCore::getNSMenuItem):
        (WebCore::ContextMenu::appendItem):
        (WebCore::ContextMenu::itemCount):
        (WebCore::ContextMenu::insertItem):
        (WebCore::ContextMenu::setPlatformDescription):
        (WebCore::ContextMenu::platformDescription):

WebKit:

        Reviewed by Beth.

        Put code in place to use WebCore context menus when they are turned
        on.

        * WebView/WebHTMLView.m:
        (-[NSArray menuForEvent:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17948 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/platform/ContextMenu.cpp
WebCore/platform/ContextMenu.h
WebCore/platform/mac/ContextMenuMac.mm
WebKit/ChangeLog
WebKit/WebView/WebHTMLView.m

index ed0d62af10eb12226e670ca829dda18f35547c9e..33d84eeda52f1d094d729fff7f177691b4d21e22 100644 (file)
@@ -1,3 +1,24 @@
+2006-11-30  Adam Roben  <aroben@apple.com>
+
+        Reviewed by Beth.
+
+        Store ContextMenu's NSMutableArray inside a RetainPtr so that we
+        will retain/release it correctly.
+
+        * WebCore.exp:
+        * platform/ContextMenu.cpp:
+        (WebCore::ContextMenu::populate): Added a FIXME.
+        * platform/ContextMenu.h:
+        * platform/mac/ContextMenuMac.mm: 
+        (WebCore::ContextMenu::ContextMenu):
+        (WebCore::ContextMenu::~ContextMenu):
+        (WebCore::getNSMenuItem):
+        (WebCore::ContextMenu::appendItem):
+        (WebCore::ContextMenu::itemCount):
+        (WebCore::ContextMenu::insertItem):
+        (WebCore::ContextMenu::setPlatformDescription):
+        (WebCore::ContextMenu::platformDescription):
+
 2006-11-30  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Eric. Rubber stamped by Oliver.
index 975d9e5f7a07bdbc55ac3d906ce8fe678a5ff63f..3a52a01f40d6fc31fd316e0bffcbcffc0eae78f2 100644 (file)
@@ -305,6 +305,7 @@ __ZN7WebCore9TimerBaseC2Ev
 __ZN7WebCore9TimerBaseD2Ev
 __ZNK7WebCore10StringImplcvP8NSStringEv
 __ZNK7WebCore11CachedImage5imageEv
+__ZNK7WebCore11ContextMenu19platformDescriptionEv
 __ZNK7WebCore11FrameLoader14documentLoaderEv
 __ZNK7WebCore11FrameLoader15containsPluginsEv
 __ZNK7WebCore11FrameLoader15firstLayoutDoneEv
index efb92fd2fbea262488e95afab05af8c9edf5fa15..249240d6448a1b5f9f6506891ba925180b21fef7 100644 (file)
@@ -105,7 +105,7 @@ void ContextMenu::populate()
 
             appendItem(OpenImageInNewWindowItem);
             appendItem(DownloadImageToDiskItem);
-            if (imageURL.isLocalFile())
+            if (imageURL.isLocalFile()) // FIXME: Should be checking if the image is local or we have a file wrapper for it
                 appendItem(CopyImageToClipboardItem);
         }
 
index 903bbf1667ce56e4af489c0151a7b5ca0bc0f759..7d76ade10b84900cb1c315d2404b348a1db608bc 100644 (file)
@@ -31,6 +31,7 @@
 #include "ContextMenuItem.h"
 #include "HitTestResult.h"
 #include "PlatformString.h"
+#include "RetainPtr.h"
 
 #if PLATFORM(MAC)
 #ifdef __OBJC__
@@ -77,12 +78,18 @@ namespace WebCore {
         HitTestResult hitTestResult() const { return m_hitTestResult; }
         ContextMenuController* controller() const;
 
-        PlatformMenuDescription platformDescription() const { return m_platformDescription; }
+        PlatformMenuDescription platformDescription() const;
         void setPlatformDescription(PlatformMenuDescription);
 
     private:
         HitTestResult m_hitTestResult;
+        
+#if PLATFORM(MAC)
+        // Keep this in sync with the PlatformMenuDescription typedef
+        RetainPtr<NSMutableArray> m_platformDescription;
+#else
         PlatformMenuDescription m_platformDescription;
+#endif
     };
 
 }
index e69f585f1329f41852756be87ee80cfe75c83269..ce421200e19d0a79bc8e55764d253c85274bf4a9 100644 (file)
@@ -72,13 +72,14 @@ static MenuTarget* target;
 
 ContextMenu::ContextMenu(const HitTestResult& result)
     : m_hitTestResult(result)
-    , m_platformDescription([NSMutableArray array])
 {
+    NSMutableArray* array = [[NSMutableArray alloc] init];
+    m_platformDescription = array;
+    [array release];    
 }
 
 ContextMenu::~ContextMenu()
 {
-    [m_platformDescription release];
 }
  
 static NSMenuItem* getNSMenuItem(ContextMenu* menu, const ContextMenuItem& item)
@@ -102,7 +103,7 @@ static NSMenuItem* getNSMenuItem(ContextMenu* menu, const ContextMenuItem& item)
             [menuItem setAction:@selector(forwardContextMenuAction:)];
             break;
         case SeparatorType:
-            menuItem = [NSMenuItem separatorItem];
+            menuItem = [[NSMenuItem separatorItem] retain];
             break;
         default:
             ASSERT_NOT_REACHED();
@@ -117,14 +118,14 @@ void ContextMenu::appendItem(const ContextMenuItem& item)
     NSMenuItem* menuItem = getNSMenuItem(this, item);
     if (!menuItem)
         return;
-        
-    [m_platformDescription addObject:menuItem];
+
+    [m_platformDescription.get() addObject:menuItem];
     [menuItem release];
 }
 
 unsigned ContextMenu::itemCount() const
 {
-    return [m_platformDescription count];
+    return [m_platformDescription.get() count];
 }
 
 void ContextMenu::insertItem(unsigned position, const ContextMenuItem& item)
@@ -132,18 +133,20 @@ void ContextMenu::insertItem(unsigned position, const ContextMenuItem& item)
     NSMenuItem* menuItem = getNSMenuItem(this, item);
     if (!menuItem)
         return;
-        
-    [m_platformDescription insertObject:menuItem atIndex:position];
+
+    [m_platformDescription.get() insertObject:menuItem atIndex:position];
     [menuItem release];
 }
 
 void ContextMenu::setPlatformDescription(NSMutableArray* menu)
 {
-    if (menu == m_platformDescription)
-        return;
-    
-    [m_platformDescription release]; 
-    m_platformDescription = [menu retain];
+    if (m_platformDescription.get() != menu)
+        m_platformDescription = menu;
+}
+
+NSMutableArray* ContextMenu::platformDescription() const
+{
+    return m_platformDescription.get();
 }
 
 void ContextMenu::show()
index 55a6a2f1d1403d4816f1b71df8bf7c92d2004c57..9f56d80d21dd12dfb1b69ccb68c0e4c877a042bd 100644 (file)
@@ -1,3 +1,13 @@
+2006-11-30  Adam Roben  <aroben@apple.com>
+
+        Reviewed by Beth.
+
+        Put code in place to use WebCore context menus when they are turned
+        on.
+
+        * WebView/WebHTMLView.m:
+        (-[NSArray menuForEvent:]):
+
 2006-11-29  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Oliver.
index c74fb7d7722d38be83d67a8ad18194b6f4c64b85..bbc7acecfbc5f05129bf6b0cca446d3a34553140 100644 (file)
@@ -69,6 +69,7 @@
 #import "WebViewInternal.h"
 #import <AppKit/NSAccessibility.h>
 #import <ApplicationServices/ApplicationServices.h>
+#import <WebCore/ContextMenuController.h>
 #import <WebCore/Document.h>
 #import <WebCore/Editor.h>
 #import <WebCore/EventHandler.h>
@@ -76,6 +77,7 @@
 #import <WebCore/FloatRect.h>
 #import <WebCore/FrameMac.h>
 #import <WebCore/HitTestResult.h>
+#import <WebCore/Page.h>
 #import <WebCore/Range.h>
 #import <WebCore/SelectionController.h>
 #import <WebCore/WebCoreTextRenderer.h>
@@ -2644,8 +2646,25 @@ static WebHTMLView *lastHitView = nil;
     _private->handlingMouseDownEvent = YES;
     BOOL handledEvent = core([self _frame])->eventHandler()->sendContextMenuEvent(event);
     _private->handlingMouseDownEvent = NO;
-    if (handledEvent)
+    
+    if (handledEvent) {
+#ifdef WEBCORE_CONTEXT_MENUS
+        if (Page* page = core([self _frame])->page()) {
+            NSArray* menuItems = page->contextMenuController()->contextMenu()->platformDescription();
+            NSMenu* menu = nil;
+            if (menuItems && [menuItems count] > 0) {
+                menu = [[NSMenu alloc] init];
+                
+                unsigned i;
+                for (i = 0; i < [menuItems count]; i++)
+                    [menu addItem:[menuItems objectAtIndex:i]];
+            }
+            return [menu autorelease];
+        }
+#else
         return nil;
+#endif
+    }
 
     NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
     NSDictionary *element = [self elementAtPoint:point];