Reviewed by Ada.
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2006 04:19:21 +0000 (04:19 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2006 04:19:21 +0000 (04:19 +0000)
        Add platform-specific constructor/destructor to ContextMenu so we can
        properly retain/release the platform menu description.

        * platform/ContextMenu.h:
        (WebCore::ContextMenu::platformDescription):
        * platform/mac/ContextMenuMac.mm:
        (WebCore::ContextMenu::ContextMenu):
        (WebCore::ContextMenu::~ContextMenu):
        (WebCore::getNSMenuItem):
        (WebCore::ContextMenu::appendItem):
        (WebCore::ContextMenu::itemCount):
        (WebCore::ContextMenu::insertItem):
        (WebCore::ContextMenu::setPlatformDescription):

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

WebCore/ChangeLog
WebCore/platform/ContextMenu.h
WebCore/platform/mac/ContextMenuMac.mm

index 19c8c5263a5f4c5439bdb6af0e4f143325fab57b..337c948f99109d56cdf2e4f0e1febd6fa112cd67 100644 (file)
@@ -1,3 +1,21 @@
+2006-11-28  Adam Roben  <aroben@apple.com>
+
+        Reviewed by Ada.
+
+        Add platform-specific constructor/destructor to ContextMenu so we can
+        properly retain/release the platform menu description.
+
+        * platform/ContextMenu.h:
+        (WebCore::ContextMenu::platformDescription):
+        * platform/mac/ContextMenuMac.mm:
+        (WebCore::ContextMenu::ContextMenu):
+        (WebCore::ContextMenu::~ContextMenu):
+        (WebCore::getNSMenuItem):
+        (WebCore::ContextMenu::appendItem):
+        (WebCore::ContextMenu::itemCount):
+        (WebCore::ContextMenu::insertItem):
+        (WebCore::ContextMenu::setPlatformDescription):
+
 2006-11-28  Adam Roben  <aroben@apple.com>
 
         Build fix.
index 6538febc5b377a76a9ed22bec5dca233ab15c36f..903bbf1667ce56e4af489c0151a7b5ca0bc0f759 100644 (file)
@@ -59,11 +59,8 @@ namespace WebCore {
     class ContextMenu : Noncopyable
     {
     public:
-        ContextMenu(HitTestResult result)
-            : m_hitTestResult(result)
-            , m_menu(0)
-        {
-        }
+        ContextMenu(const HitTestResult&);
+        ~ContextMenu();
 
         void populate();
 
@@ -80,12 +77,12 @@ namespace WebCore {
         HitTestResult hitTestResult() const { return m_hitTestResult; }
         ContextMenuController* controller() const;
 
-        PlatformMenuDescription platformDescription() const { return m_menu; }
-        void setPlatformDescription(PlatformMenuDescription menu);
+        PlatformMenuDescription platformDescription() const { return m_platformDescription; }
+        void setPlatformDescription(PlatformMenuDescription);
 
     private:
         HitTestResult m_hitTestResult;
-        PlatformMenuDescription m_menu;
+        PlatformMenuDescription m_platformDescription;
     };
 
 }
index 5b221658245cbcc553c75c5ce0863c37ff068a77..e69f585f1329f41852756be87ee80cfe75c83269 100644 (file)
 
 @end
 
-using namespace WebCore;
+namespace WebCore {
 
 static MenuTarget* target;
+
+ContextMenu::ContextMenu(const HitTestResult& result)
+    : m_hitTestResult(result)
+    , m_platformDescription([NSMutableArray array])
+{
+}
+
+ContextMenu::~ContextMenu()
+{
+    [m_platformDescription release];
+}
  
 static NSMenuItem* getNSMenuItem(ContextMenu* menu, const ContextMenuItem& item)
 {
     if (!menu->platformDescription())
-        menu->setPlatformDescription([[[NSMutableArray alloc] init] autorelease]);
+        return 0;
     
     ContextMenuController* currentController = menu->controller();
     if (!target)
@@ -104,29 +115,35 @@ static NSMenuItem* getNSMenuItem(ContextMenu* menu, const ContextMenuItem& item)
 void ContextMenu::appendItem(const ContextMenuItem& item)
 {
     NSMenuItem* menuItem = getNSMenuItem(this, item);
-    [m_menu addObject:menuItem];
+    if (!menuItem)
+        return;
+        
+    [m_platformDescription addObject:menuItem];
     [menuItem release];
 }
 
 unsigned ContextMenu::itemCount() const
 {
-    return [m_menu count];
+    return [m_platformDescription count];
 }
 
 void ContextMenu::insertItem(unsigned position, const ContextMenuItem& item)
 {
     NSMenuItem* menuItem = getNSMenuItem(this, item);
-    [m_menu insertObject:menuItem atIndex:position];
+    if (!menuItem)
+        return;
+        
+    [m_platformDescription insertObject:menuItem atIndex:position];
     [menuItem release];
 }
 
 void ContextMenu::setPlatformDescription(NSMutableArray* menu)
 {
-    if (menu == m_menu)
+    if (menu == m_platformDescription)
         return;
     
-    [m_menu release]; 
-    m_menu = [menu retain];
+    [m_platformDescription release]; 
+    m_platformDescription = [menu retain];
 }
 
 void ContextMenu::show()
@@ -136,3 +153,5 @@ void ContextMenu::show()
 void ContextMenu::hide()
 {
 }
+
+}